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

[TFS 1.X] Player:isCreatureFriend()

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,633
Solutions
11
Reaction score
877
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.
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.
 
If i want to add a frag if i kill a friend and don't add frag if enemy? Its possible?

@Topic
Great code!!
 
Back
Top