• 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 Simple Storage question

rcb chief

New Member
Joined
Dec 23, 2008
Messages
53
Reaction score
0
So I got these reflection shield spell I kinda made out of another script and it works great but there is one small problem.

Spell explanation: When you activate the spell you will get a shield with one charge(storage 1460), the charges will grow every 5 seconds until it reaches maximum capacity(5 is the limit) or the shield is broken. The shield will reflect(return damage) one, any, attack per charge.

The problem comes when 1 player with the shield activated, attacks another player with the shield also activated.. what happens is the first player recieves the damage reflected to himself even though he also has the shield. What I want is for the spell to check if the player also has a shield and that no damage is sent if he does have a shield.

I know it has something to do with checkin the attackers storage but i dont know how.

in spells
Code:
local stored = 1460

local function onCastSpell2(cid, var)
    if getCreatureStorage(cid, stored) >= 1 and getCreatureStorage(cid,stored) < 5 then
    doCreatureSetStorage(cid, stored, (getCreatureStorage(cid,stored)+1))
	doPlayerSendCancel(cid,'You can now reflect '..getCreatureStorage(cid,stored)..' hit/s.')	
	doSendAnimatedText(getThingPos(cid), '+1 Charge!', 168)
	doSendMagicEffect(getThingPos(cid), CONST_ME_HOLYAREA)
	addEvent(onCastSpell2, 5000, cid)
	return false
	else
	if getCreatureStorage(cid, stored) == 5 then
	addEvent(onCastSpell2, 5000, cid)
	doPlayerSendCancel(cid,'Your shield is fully charged.')
	doSendMagicEffect(getThingPos(cid), CONST_ME_HOLYAREA)
	return false
end 
end
end
 


function onCastSpell(cid, var) 
	local storage = 1461
	local delay = 10 -- 6 means six seconds

    if isPlayer(cid) == TRUE then 
        if exhaustion.check(cid, storage) then 
			doPlayerSendCancel(cid, "Spell is on cooldown.(10 seconds)")
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
            return FALSE 
        else 
			
	if getCreatureStorage(cid, stored) >= 1 then
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid,'You already charging your shield.')
        return false
    end
	exhaustion.set(cid, storage, delay)
    doCreatureSetStorage(cid, stored, 1)
    doSendMagicEffect(getThingPos(cid), CONST_ME_HOLYAREA)
    doPlayerSendCancel(cid,'You are now charging your shield.')
	doSendAnimatedText(getThingPos(cid), 'SHIELD!', 210)
	addEvent(onCastSpell2, 5000, cid)
	
	
return true
            
        end 
	end	
end

in creaturescripts
Code:
local storage = 1460

 
function onStatsChange(cid, attacker, type, combat, value)    
    if isPlayer(cid) and isCreature(attacker) and getCreatureStorage(cid,storage) > 1 and type == STATSCHANGE_HEALTHLOSS then
	local valor = value
	local formula = ((100 * valor) / 100)   
        if value >= 1 then
			doCreatureAddHealth(attacker,-formula)
			doSendAnimatedText(getCreaturePosition(attacker),'-'..formula..'', 180)
			doSendMagicEffect(getCreaturePosition(attacker),39)
			doSendDistanceShoot(getThingPos(cid), getCreaturePosition(attacker), CONST_ANI_HOLY)
            doCreatureSetStorage(cid, storage, (getCreatureStorage(cid,storage)-1))
            doSendMagicEffect(getThingPos(cid), CONST_ME_YELLOWENERGY)
            doPlayerSendCancel(cid,'You can still block '..getCreatureStorage(cid,storage)..' more hit/s!')
			doSendAnimatedText(getThingPos(cid), 'REFLECTED!', 210)
            doTargetCombatHealth(attacker, cid, combat, -0, -0, CONST_ME_YELLOWENERGY)
            return false
        end
		else
		 if isPlayer(cid) and isCreature(attacker) and getCreatureStorage(cid,storage) == 1 and type == STATSCHANGE_HEALTHLOSS then
		 	local valr = value
			local formul = ((100 * valr) / 100)  
				if value >= 1 then			
			doCreatureAddHealth(attacker,-formul)
			doSendAnimatedText(getCreaturePosition(attacker),'-'..formul..'', 180)
			doSendMagicEffect(getCreaturePosition(attacker),39)
			doSendDistanceShoot(getThingPos(cid), getCreaturePosition(attacker), CONST_ANI_HOLY)
		    doCreatureSetStorage(cid, storage, (getCreatureStorage(cid,storage)-1))
            doSendMagicEffect(getThingPos(cid), CONST_ME_YELLOWENERGY)
            doPlayerSendCancel(cid,'You shield broke!')
			doSendAnimatedText(getThingPos(cid), 'BROKEN!', 180)
            doTargetCombatHealth(attacker, cid, combat, -0, -0, CONST_ME_YELLOWENERGY)
            return false
			end
			
    end
   
end
  return true
end

I am new to this scripting thing. Also im using tfs 0.3.6.
Thank in advance
 
Back
Top