• 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 Weapon type distance

sestorme

Member
Joined
Dec 9, 2011
Messages
272
Reaction score
6
Location
Birmingham, UK
I spent last hour looking for a solution, I checked so many different possibilities, no real effect, please look at the code, I am powerless. It's probably very easy, I just can't make it working.

Code:
function onAttack(cid, target)
	if isPlayer(cid) == TRUE then
		if isPlayer(target) == TRUE then
		doCreatureSay(cid, "1.", TALKTYPE_ORANGE_1)

			if (getItemWeaponType(getPlayerWeapon(cid).uid) == distance)  then
			local ammo = getPlayerSlotItem(cid, 10).type
			doCreatureSay(cid, "2", TALKTYPE_ORANGE_1)

				if ammo == 1 then
				doCreatureSay(cid, "Reload.", TALKTYPE_ORANGE_1)

				end
			end
		end
	end
return TRUE
end

It is isPlayer just for testing purposes, also [1] and [2] creature says are also for testing purposes to find out which condition isn't working. Ammo check works absolutely fine, and I would add more warnings later, like at 10/5/3/2/1 ammo left. However, for now I am struggling to detect whether weapon is actually a distance weapon, so if you guys could provide me with the right way how to detect it I'd greatly appreciate that. Thanks, rep'd.
 
Try changing:

Code:
(getItemWeaponType(getPlayerWeapon(cid).uid) == distance)

to

Code:
(getItemWeaponType(getPlayerWeapon(cid).uid) == 4)
 
I tried to slightly modify it, shows error Thing not found.

Also, what if weapon is not actually a bow?

LUA:
local function isBow(uid)
	uid = uid or 0
	if(getItemWeaponType(uid) == 5) then
		return true
	end
	return false
end
 
local TREES = {7387, 3964}

function onAttack(cid, target)
			if(isBow(getPlayerWeapon(cid, true))) then
				if(isInArray(TREES, (getPlayerSlotItem(CONST_SLOT_ARROW).itemid)))then
					local ammo = getPlayerSlotItem(cid, 10).type
					if (ammo <= 1) then
					doSendAnimatedText(getPlayerPosition(cid), "Reload", 180)
					elseif (ammo <= 3) then
					doSendAnimatedText(getPlayerPosition(cid), "Reload", 192)
					elseif (ammo <= 5) then
					doSendAnimatedText(getPlayerPosition(cid), "Reload", 210)
					elseif (ammo <= 10) then
					doSendAnimatedText(getPlayerPosition(cid), "Reload", 18)
					end
				end
			end
	return true
end
 
Last edited:
Try this. It will not work if you're attacking someone of the same IP Address.

Is that true? Doesn't it just check when you're attacking (something)?
Cause I have an onAttack function script:

LUA:
function onAttack(cid)
	if getCreatureCondition(cid, CONDITION_INVISIBLE) then
		doRemoveCondition(cid, CONDITION_INVISIBLE)
		--doRemoveCondition(cid, CONDITION_ATTRIBUTES)
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
	end
	return TRUE
end

(It deletes a condition when you're attacking, invisibility in this case)
And it works whenever you are attacking. Maybe it's not the same thing?

Btw, I have this in creaturescripts.
 
LUA:
function onAttack(cid, target)
	local check = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
	if(check.type <= 10) then
		doSendAnimatedText(getPlayerPosition(cid), "Reload", 180)
	end
	return true
end
 
Last edited:
Back
Top