• 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!

Shield Equipped?

WarOfTheTitans

Active Member
Joined
Feb 3, 2012
Messages
430
Reaction score
37
How to check if the player has a shield equipped? I've searched everything and I haven't found anything.

This was what I come up with, but if the player has a empty slot, errors occurs:
Lua:
function getPlayerShieldEquipped(cid)
	local slotRight = getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid
	local slotLeft = getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid
	
	if(getItemWeaponType(slotRight) == WEAPON_SHIELD or getItemWeaponType(slotLeft) == WEAPON_SHIELD) then
		return true
	end

end

Thank and rep+ :)
 
Lua:
function getPlayerShieldEquipped(cid)
	local slotRight = getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid
	local slotLeft = getPlayerSlotItem(cid, CONST_SLOT_LEFT).uid
 
	if ((slotRight and getItemWeaponType(slotRight) == WEAPON_SHIELD) or (slotLeft and getItemWeaponType(slotLeft) == WEAPON_SHIELD)) then
		return true
	end
	return false
end
 
still not working. That function is exactly as mine... -.-

I still get this error when I don't have any shield or the hand slot is empty:
Lua:
[19/05/2012 22:26:02] [Error - Spell Interface] 
[19/05/2012 22:26:02] data/spells/scripts/donspells/shield bash.lua:onCastSpell
[19/05/2012 22:26:02] Description: 
[19/05/2012 22:26:02] (luaGetThing) Thing not found
 
Try it
Lua:
function isHeldShield(cid)
	local items = {getPlayerSlotItem(cid, CONST_SLOT_RIGHT), getPlayerSlotItem(cid, CONST_SLOT_LEFT)}
	
	if ((items[0] and getItemWeaponType(items[0].uid) == WEAPON_SHIELD) or (items[1] and getItemWeaponType(items[1].uid) == WEAPON_SHIELD)) then
		return true
	end
	return false
end
 
It means that there is no item in that slot...

Code:
	//getPlayerSlotItem(cid, slot)
	uint32_t slot = popNumber(L);

	ScriptEnviroment* env = getEnv();
	if(const Player* player = env->getPlayerByUID(popNumber(L)))
	{
		if(Thing* thing = player->__[COLOR="#FF0000"]getThing(slot)[/COLOR])
			pushThing(L, thing, env->addThing(thing));
		else
			pushThing(L, NULL, 0);
	}
	else
	{
		errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
		pushThing(L, NULL, 0);
	}
	return 1;
 
Last edited:
[CPP]bool Player::hasShield() const
{
bool result = false;
Item* item = getInventoryItem(SLOT_LEFT);
if(item && item->getWeaponType() == WEAPON_SHIELD)
result = true;

item = getInventoryItem(SLOT_RIGHT);
if(item && item->getWeaponType() == WEAPON_SHIELD)
result = true;

return result;
}[/CPP]

This looks like your function ;o
 
Back
Top