- Joined
- Dec 26, 2013
- Messages
- 1,635
- Solutions
- 11
- Reaction score
- 880
Greetings Otland.
I bring today a method for the player class to tell if another creature is friendly or not. Basically it will be used mainly for checking monsters, but I didn't want to limit it to just that. Also I would like to note that if you want it to be truely functional you should add a check for NPC's as well and have it return false for NPC. I didn't add because I don't need it. Anyways, example usage.
Anyways hope you guys enjoy, and look out for my next version of potions system which will be dependent upon this method.
I bring today a method for the player class to tell if another creature is friendly or not. Basically it will be used mainly for checking monsters, but I didn't want to limit it to just that. Also I would like to note that if you want it to be truely functional you should add a check for NPC's as well and have it return false for NPC. I didn't add because I don't need it. Anyways, example usage.
Code:
if player:isCreatureFriend(target) then -- use object NOT CID.
print("he is your friend")
else
print("he is not your friend")
end
Code:
function Player:isCreatureFriend(creature, tarCheck) --tarCheck true/false
local player = Player(creature)
local monster = Monster(creature)
local PID
local GID
if self:getParty() then
PID = self:getParty():getId()
end
if self:getGuild() then
GID = self:getGuild():getId()
end
if player then
if player:getParty() then
if player:getParty():getId() == PID then
return true
end
elseif player:getGuild() then
if player:getGuild():getId() == GID then
return true
else return false end
else
return false
end
end
if monster then
local master = monster:getMaster()
if master then
if master:getId() == self:getId() then
return true
end
if master:getParty() and master:getParty():getId() == PID then
return true
end
if master:getGuild() and master:getGuild():getId() == GID then
return true
end
return false
end
if self:getTarget() and self:getTarget():getId() == monster:getId() then
--- If you want a return of true on monsters that aren't summons, but
---- also aren't your target, set tarCheck in parameter as false
if tarCheck == true then
return false
end
return true
end
end
end
Anyways hope you guys enjoy, and look out for my next version of potions system which will be dependent upon this method.