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

onDeath

New_Age

FoxWorld New Age
Joined
Jan 27, 2016
Messages
24
Reaction score
0
personal hello someone may need to help me know if this script is right

It is to see whether the player or summon it gave the last hit

Code:
function onDeath(cid, corpse, killer)
   local p = Player(cid) if p == nil then return false end
   
   if isPlayer(killer) == TRUE then
     killer = p:getId()   
   elseif isCreature(killer) == TRUE then -- caso quem deu o last hit foi o summon de um jogador
     local c = Creature(cid) if c == nil then return false end
     local summoner = c:getMaster()
     if summoner ~= killer then
       killer = summoner
     else
       killer = FALSE
     end
   else
     killer = FALSE
   end
 
Code:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if killer:isPlayer() then
        print("Killer is a player.")
    elseif killer:isMonster() then
        local master = killer:getMaster()
        if master and master:isPlayer() then
            print("killer is player summon.")
        end
    end
    return true
end
 
TRUE is not the same things as true, TRUE in most distro's is a predefined variable, the reason it is capitalized is to give the impression that it is a constant, a value which should never change.

Where as true is a boolean data type.
 
@Printer and @Codex NG thank you that way I'm using to get the guild name is correct?
Code:
local player = Player(killer)
   local guild = player:getGuild()
   if guild == nil then
     return false
   end

  local killerGuild = guild:getName()
  --print("Your guild is: "..killerGuild.."")
I am using lib compat to get the function
if you want to give me some tips to optimize code I accept also hahaha
 
Killer is userdata, you cannot put it inside constructer without fetching id. Also return false can cause that player do not dig, so you need to determine what you want.

Code:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if killer:isPlayer() then
        local killerGuild = killer:getGuild()
        if killerGuild == nil then
            return true
        end

        print(string.format("Guild id: %d, Guild Name: %s.", killerGuild:getId(), killerGuild:getName()))
    end
    return true
end
 
so if not you have killer will be nil and if I want to check if you already have storage would be
killer: getStorageValue(storage)
I think I learned a little
thank you

I returned the script is running smoothly but only with god if I kill the monster with normal player does not work
@ Edit
Code:
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
   if killer:isPlayer() == true then
     --print("Killer is a player.")
  elseif killer:isMonster() then
  local master = killer:getMaster()
  if master and master:isPlayer() then
     --print("Killer is summon.")
     killer = master
  else
       killer = false
     end
   else
     killer = false
  end

  local killerGuild = killer:getGuild()
  if killerGuild == nil then
      return true
  end
  
print(string.format("Player Name: %s", killer:getName()))
  print(string.format("Guild id: %d, Guild Name: %s.", killerGuild:getId(), killerGuild:getName()))

return true
end
yet if the player kill the monster nothing appears even using print
but when this is done with the god works

up
 
Last edited by a moderator:
You don't need to say
Code:
if killer:isPlayer() == true then
There are only 1 of 2 values killer:isPlayer() will return either true or false and the if statement will only execute if its condition is true, unless otherwise manipulated.

Hypothetically if you wanted the if statement to execute if the value was false you could say
Code:
-- if the killer is not a player execute the if statement, not reverses a boolean value, 
-- it converts false to true and true to false
if not killer:isPlayer() then

-- or
-- this is the same as above, if the killer is not a player the return value would be false correct?
-- and false does not equal true right? so this statement would be true
if killer:isPlayer() ~= true then

Beyond that if the explicit return value of a metamethod or function returns true or false you do not need
to create additional steps of comparison unless it is not the intended result.

Try this as a test
Code:
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
   
    if killer:isPlayer() then
        print("Killer is a player.")
    elseif killer:isMonster() then
        local master = killer:getMaster()
        if master then
            if master:isPlayer() then
                print("Killer is summon of a player.")
            else
                print("killer is summon of monster.")
            end
        else
            print("killer is just a monster")
        end
    else
        print('killer is something else')
    end
   
    return true
end
 
Last edited by a moderator:
then face it shows the print("Killer is a player.")
but when I do something like print(string.format("Player name: %s", killer:getName()))
does not work, nor does the error
but it works with god
 
Back
Top