• 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 ON/OFF event in spell ?

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,855
Solutions
18
Reaction score
671
Hello I have spell what is regenerating our health and mana:
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

local drunk = createConditionObject(CONDITION_DRUNK)
setConditionParam(drunk, CONDITION_PARAM_TICKS, 24*60*1000)
function statup(cid)
doCreatureAddHealth(cid,(getCreatureMaxHealth(cid) * 0.08))
doCreatureAddMana(cid,(getCreatureMaxMana(cid) * 0.08))
doSendMagicEffect(getPlayerPosition(cid), 14)
end

function check1(cid)
if (hasCondition(cid, CONDITION_DRUNK) == TRUE) then
if (hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
if getCreatureHealth(cid) == getCreatureMaxHealth(cid) then
if getCreatureMana(cid) == getCreatureMaxMana(cid) then
        mayNotMove(cid, 0)
        doRemoveCondition(cid, CONDITION_DRUNK)
		doCreatureSetStorage(cid, 6, 0)
		doPlayerSendCancel(cid, "Your charge stopped.")
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
else
  addEvent(statup,1000,cid)
  addEvent(check1,500,cid)
end
else
  addEvent(statup,1000,cid) 
  addEvent(check1,500,cid)
end
else
  mayNotMove(cid, 0)
  stopEvent(statup)
  stopEvent(check1)
  doRemoveCondition(cid, CONDITION_DRUNK)
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
else
  mayNotMove(cid, 0)
  stopEvent(statup)
  stopEvent(check1)
  doRemoveCondition(cid, CONDITION_DRUNK)
  doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
end

function onCastSpell(cid, var)
    if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then  
         if(hasCondition(cid, CONDITION_DRUNK) == FALSE) then 
                  doTargetCombatCondition(0, cid, drunk, CONST_ME_NONE)
                  mayNotMove(cid, 1)
				  doCreatureSetStorage(cid, 6, 1)
           addEvent(check1,1000,cid) 
		   setPlayerStorageValue(cid,2994,1)
	return doCombat(cid, combat, var)
         end
	else
		doPlayerSendCancel(cid, "You cannot start charging power if you are in fight.")
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
end

I need to add something like this:
- When we have this event on - we startup the event and we are trying to startup next event by casting this spell again (while we actually regenerating our health and mana - event on) - when we cast again spell the event stop and it says - "You have stopped charging".

I have no idea how I can do it.
Anyone can help me ?
 
LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
 
local drunk = createConditionObject(CONDITION_DRUNK)
setConditionParam(drunk, CONDITION_PARAM_TICKS, 24*60*1000)

function statup(cid)
  doCreatureAddHealth(cid,(getCreatureMaxHealth(cid) * 0.08))
  doCreatureAddMana(cid,(getCreatureMaxMana(cid) * 0.08))
  doSendMagicEffect(getPlayerPosition(cid), 14)
end
 
function check1(cid)
  if (hasCondition(cid, CONDITION_DRUNK) == TRUE) and getPlayerStorage(cid, 6) == 1 then
    if (hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
      if getCreatureHealth(cid) == getCreatureMaxHealth(cid) then
        if getCreatureMana(cid) == getCreatureMaxMana(cid) then
          mayNotMove(cid, 0)
          doRemoveCondition(cid, CONDITION_DRUNK)
          doCreatureSetStorage(cid, 6, -1)
          doPlayerSendCancel(cid, "Your charge stopped.")
          doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        else
          addEvent(statup,1000,cid)
          addEvent(check1,500,cid)
        end
      else
        addEvent(statup,1000,cid) 
        addEvent(check1,500,cid)
      end
    else
      mayNotMove(cid, 0)
      doCreatureSetStorage(cid, 6, -1)
      stopEvent(statup)
      stopEvent(check1)
      doRemoveCondition(cid, CONDITION_DRUNK)
      doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    end
  else
    mayNotMove(cid, 0)
    stopEvent(statup)
    doCreatureSetStorage(cid, 6, -1)
    stopEvent(check1)
    doRemoveCondition(cid, CONDITION_DRUNK)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
  end
end
 
function onCastSpell(cid, var)
  if getPlayerStorage(cid, 6) == 1 then
    doCreatureSetStorage(cid, 6, -1)
    doPlayerSendCancel(cid, "You have stopped charging.")
    return true
  end

  if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then  
    if(hasCondition(cid, CONDITION_DRUNK) == FALSE) then 
      doTargetCombatCondition(0, cid, drunk, CONST_ME_NONE)
      mayNotMove(cid, 1)
      doCreatureSetStorage(cid, 6, 1)
      addEvent(check1,1000,cid) 
      setPlayerStorageValue(cid,2994,1)
      return doCombat(cid, combat, var)
    end
  else
    doPlayerSendCancel(cid, "You cannot start charging power if you are in fight.")
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
  end
end

Try that one out.
 
Back
Top