• 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!

Help with charge spell

kermaxpl

Pora na Nonsens Scripter
Joined
Aug 21, 2012
Messages
121
Reaction score
7
Location
Poland
This is my spell. When player says "charge" it should make him unable to move and start regenerating 40 mana per second. When charge is on and player says "charge" again it should make him able to move and stop mana regenerating and this is problem mana is still regenerating. Pls help me

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function regen(cid)
	if isPlayer(cid) then
		doCreatureAddMana(cid, 40)
	end
end

function onCastSpell(cid, var)
if exhaustion.check(cid, 99998) then
 	doPlayerSendCancel(cid, "You are exhausted")
 else
 	if (getCreatureStorage(cid, 99999) ~= 1) then
		doCreatureSetNoMove(cid, true)
		doCreatureSetStorage(cid, 99999, 1)
		for i = 1, 3600 do
		local ev = addEvent(regen, i * 1000, cid)
		end
		return doCombat(cid, combat, var)
	else
		doCreatureSetNoMove(cid, false)
		doCreatureSetStorage(cid, 99999, 0)
		exhaustion.set(cid, 99998, 1200000)
		stopEvent(ev)
	 end
end
end
 
Last edited:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

function regen(cid, seconds, temp)
	if(isPlayer(cid) and getCreatureStorage(cid, 99999) >= 1)then
		doCreatureAddMana(cid, 40)
	else
		return true
	end
	return (temp<times) and addEvent(regen, 1000, cid, seconds, temp+1) or true
end

function onCastSpell(cid, var)
	if exhaustion.check(cid, 99998) then
		return doPlayerSendCancel(cid, "You are exhausted")
	end
	if (getCreatureStorage(cid, 99999) <= 0) then
		doCreatureSetNoMove(cid, true)
		doCreatureSetStorage(cid, 99999, 1)
		regen(cid, 3600, 0)
	else
		doCreatureSetNoMove(cid, false)
		doCreatureSetStorage(cid, 99999, 0)
		exhaustion.set(cid, 99998, 1200000)
	end
	return doCombat(cid, combat, var)
end
 
Code:
[11:58:43.042] [Error - Spell Interface]
[11:58:43.042] data/spells/scripts/buffy/charge.lua:onCastSpell
[11:58:43.042] Description:
[11:58:43.042] data/spells/scripts/buffy/charge.lua:11: attempt to compare number with nil
[11:58:43.042] stack traceback:
[11:58:43.042]  data/spells/scripts/buffy/charge.lua:11: in function 'regen'
[11:58:43.042]  data/spells/scripts/buffy/charge.lua:21: in function <data/spells/scripts/buffy/charge.lua:14>

and it adds mana only once and then silence, only doCreatureSetNoMove is working
 
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)

local function regen(cid)
	if isPlayer(cid) and (getCreatureStorage(cid, 99999) == 1) then
		doCreatureAddMana(cid, 40)
	end
end

function onCastSpell(cid, var)

if exhaustion.check(cid, 99998) then
	doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
 	doPlayerSendCancel(cid, "You have to wait "..exhaustion.get(cid, 99998).." seconds before you can use this spell again.")
	return false
end

 	if (getCreatureStorage(cid, 99999) ~= 1) then
		doCreatureSetNoMove(cid, true)
		doCreatureSetStorage(cid, 99999, 1)
		for i = 1, 3600 do
		local event = addEvent(regen, i * 1000, cid)
		end
		doCombat(cid, combat, var)
	else
		doCreatureSetNoMove(cid, false)
		doCreatureSetStorage(cid, 99999, 0)
		exhaustion.set(cid, 99998, 1200000)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
	end
	return true
end
 
Back
Top