• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Write spell shorten

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Reaction score
63
Location
Poland
Hello ^_^

I have made spell which is working perfectly but is way to wirte it shorten??


Lua:
local formulaDrainHealth = {
		min =  50 * 2 + 400 * 3,
		max = 40 * 2.5 + 500 * 3.5
	}

function onCastSpell(cid, var)
	local drain = math.random(formulaDrainHealth.min, formulaDrainHealth.max)
	local target = getCreatureTarget(cid)
	local percent = 70

	if(getCreatureHealth(target) == 0) then
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
	elseif(getCreatureHealth(target) < drain) then
		doSendAnimatedText(getCreaturePosition(target), ''.. getCreatureHealth(target) ..'', TEXTCOLOR_RED)
		doCreatureAddHealth(cid, getCreatureHealth(target) * percent / 100)
		doCreatureAddHealth(target, - getCreatureHealth(target))
		doSendDistanceShoot(getCreaturePosition(target), getCreaturePosition(cid), 30)
	elseif(getCreatureHealth(target) > 0) then
		doSendAnimatedText(getCreaturePosition(target), ''.. drain ..'', TEXTCOLOR_RED)
		doCreatureAddHealth(cid, drain * (percent / 100))
		doCreatureAddHealth(target, - drain)
		doSendDistanceShoot(getCreaturePosition(target), getCreaturePosition(cid), 30)
	end
	return true
end

NOTE: This is drain life spell

Thanks for help :thumbup:
 
Lua:
local formulaDrainHealth, percent = {
	min = 50 * 2 + 400 * 3,
	max = 40 * 2.5 + 500 * 3.5
}, 70

function onCastSpell(cid, var)
	local target = getCreatureTarget(cid)
	if not isCreature(target) then
		return not doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
	end

	local drain = math.min(getCreatureHealth(target), math.random(formulaDrainHealth.min, formulaDrainHealth.max))
	doTargetCombatHealth(cid, target, COMBAT_LIFEDRAIN, -drain, -drain, CONST_ME_NONE)
	doCreatureAddHealth(cid, drain * (percent / 100))
	doSendDistanceShoot(getThingPos(target), getThingPos(cid), 30)
	return true
end
 
He always is since he wrote the code for an omniscient otland auto responder. lol
 
Back
Top