Lua IsFriendly

From ArcEmu-Wiki
Jump to: navigation, search
+/-
Main Page        LuaArcEmu Website     ArcEmu Forum     Bug Tracker



Syntax

bool = pPlayer:IsFriendly(pUnit)


Description

You can check if the user is friendly to someone or something or not.
If the target is friendly it will return 'true', else 'false'.


Example

In this example I will create an anti-cheat check for a gossip menu.
We simply check if the user is friendly to the npc that he/she wishes to talk to.
There are a couple of cheat methods that can override these settings, so checking if the user is friendly or not can override the cheat!

function OnGossip(pUnit, event, pPlayer)
	if(pPlayer:IsFriendly(pUnit) == true) then  -- if the player is friendly ...
	     pUnit:GossipCreateMenu(100, pPlayer, 0)
             pUnit:GossipMenuAddItem(7, "Am I friendly to you?", 1, 0)
             pUnit:GossipSendMenu(pPlayer)
	else -- if the player is not friendly ...
             pUnit:SendChatMessageToPlayer(12, 0, "You are not my friend!", pPlayer) 
        end
end
 
function OnSelect(pUnit, event, pPlayer, id, intid, code)
	if(intid == 1) then
	     if(pPlayer:IsFriendly(pUnit) == true) then
	     	 pUnit:SendChatMessageToPlayer(12, 0, "You are my friend!", pPlayer)  
	     else -- if the player is not friendly  
	     	 pUnit:SendChatMessageToPlayer(12, 0, "You are not my friend!", pPlayer) 
	     end
	end
end

Note: You actually won't notice this inside the game. It's actually very hard to test but trust me on it: it works.

Personal tools