• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

stop s[pell from taking arrow from backpack

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
 
There is no error at all, See when arrows are in the arrow slot the spell works 100%, shoots at the right number of monsters and does damage, however once the arrows in the errow slot are gone and you have arrows in your backpack, and you use the spell, it takes the arrows from your backpack, but the spell will do no damage cuz without arrows in the arrow slot your damage is 0, so i just need it to ONLY take arrow from the arrow slot, and not the backpack
 

Similar threads

Back
Top