the little guy
New Member
- Joined
- May 30, 2013
- Messages
- 8
- Reaction score
- 0
Alright so i have htis spell here, that shoots at multiple monsters and takes away arrows accordingly however, i dont want the spell to steal arrows from the backpack, i only want them to take the arrows from the Arrow Slot Only. can anyone help me out? Rep++
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ARROW)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, true)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 1, 1, 1, 1)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, TRUE)
local arrowNeededPerTarget = 1
local hitExtraTargets = 2 -- number of extra targets, so it should attack our target + X other monsters/players
local hitExtraTargetsInRange = 2 -- distance to 'extra target' from our target
function onCastSpell(cid, var)
local ret = doCombat(cid, combat, var)
if(ret == LUA_ERROR) then
return LUA_ERROR
end
local arrowSpent = arrowNeededPerTarget
local target = variantToNumber(var)
local hitplayers = false
if(target ~= 0) then
if(isPlayer(target)) then
hitplayers = true
end
local otherTargets = getSpectators(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, false)
if(#otherTargets > 0) then
local i = 1
while(i ~= #otherTargets) do
local pid = otherTargets[i]
if(isNpc(pid) or pid == cid or pid == target or (isPlayer(pid) and (not hitplayers or getTileInfo(getCreaturePosition(pid)).protection))) then
table.remove(otherTargets, i)
else
i = i + 1
end
end
end
for i = 1, hitExtraTargets do
if(#otherTargets > 0 and getPlayerItemCount(cid, 2544) >= arrowSpent + arrowNeededPerTarget) then
local randomId = math.random(1, #otherTargets)
local nowHit = otherTargets[randomId]
table.remove(otherTargets, randomId)
ret = doCombat(cid, combat, numberToVariant(nowHit))
if(ret ~= LUA_ERROR) then
arrowSpent = arrowSpent + arrowNeededPerTarget
end
else
break
end
end
end
doPlayerRemoveItem(cid, 2544, arrowSpent)
doPlayerRemoveItem(cid, 2544, -arrowSpent)
return true
end