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

Solved Creature Event onKill

Status
Not open for further replies.

boby psaico

Member
Joined
Oct 17, 2009
Messages
84
Reaction score
5
How to make an event where all players who attack certain monsters will win a storage?

My scripts isn't working:

Code:
function onKill(cid, target, lastHit)
    if getCreatureName(target) == "Jaul" and isMonster(target) and isPlayer(cid) then
        setPlayerStorageValue(target, 33000, 1)
    end
    return true
end

Only the last killer is earning the storage :/
 
You need to use onDeath, and use the deathList function to obtain all killers and then add storage.

I'm on my phone so can't really write it out for ya.
 
I dont know how to do this.
I tried in every way, but not found any that would give the prize to everyone who attack.
:S
 
try this
put this in monster file.
Code:
<script>
   <event name="NAMEOFCREATUREEVENT"/>
</script>

this as script
Code:
function onDeath(cid, corpse, deathList)
  for i=0, #deathList do
     if(isPlayer(deathList[i]) then
       setPlayerStorageValue(deathList[i], 33000, 1)
     end
   end
   return true
end
 
In setPlayerStorageValue:

2rrw6l3.png
 
If you want players who just attacked certain monster use onCombat
I cant use onCombat because the sources of TFS 1.0 dont have :/

Just have this:

Code:
{
    //Depending on the type script event name is different
    switch (m_type) {
        case CREATURE_EVENT_LOGIN:
            return "onLogin";

        case CREATURE_EVENT_LOGOUT:
            return "onLogout";

        case CREATURE_EVENT_THINK:
            return "onThink";

        case CREATURE_EVENT_PREPAREDEATH:
            return "onPrepareDeath";

        case CREATURE_EVENT_DEATH:
            return "onDeath";

        case CREATURE_EVENT_KILL:
            return "onKill";

        case CREATURE_EVENT_ADVANCE:
            return "onAdvance";

        case CREATURE_EVENT_MODALWINDOW:
            return "onModalWindow";

        case CREATURE_EVENT_TEXTEDIT:
            return "onTextEdit";

        case CREATURE_EVENT_CHANGEHEALTH:
            return "onChangeHealth";

        case CREATURE_EVENT_CHANGEMANA:
            return "onChangeMana";

        case CREATURE_EVENT_EXTENDED_OPCODE:
            return "onExtendedOpcode";

        case CREATURE_EVENT_NONE:
        default:
            return std::string();
    }
}
 
but onThink have interval.
I want the event to happen only after the monster dies :s

In your first post you said only after attack monster.
In onDie you can't get attacker only player who die. Monsters are not allowed in this function.
In onKill you can get only last killer and most damage killer.

Best function would be onCombat but you dont have it so alternative is onThink.
 
well, then try changing onDeath to onPrepareDeath, unless 1.0 doesn't support deathList, I couldn't remember which one had deathList. just use onPrepareDeath see if that works.
 
In your first post you said only after attack monster.
In onDie you can't get attacker only player who die. Monsters are not allowed in this function.
In onKill you can get only last killer and most damage killer.

Best function would be onCombat but you dont have it so alternative is onThink.
I may have expressed badly, i want that all players that have attacked the monster, win storage after monster dies...
Code:
What i want:

Example:

Gnomevil is monster, he is being attacked by 5 players.
After gnomevil dies:
Player 1 gained 500 xp --> WON STORAGE
Player 2 gained 240 xp --> WON STORAGE
Player 3 gained 350 xp --> WON STORAGE
Player 4 gained 1 xp --> WON STORAGE
Player 5 gained 0 xp --> DONT WON STORAGE


well, then try changing onDeath to onPrepareDeath, unless 1.0 doesn't support deathList, I couldn't remember which one had deathList. just use onPrepareDeath see if that works.
The same error ><
The source only have:
//onPrepareDeath(cid, killer)
and
//onDeath(cid, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

no more vars ://
 
Last edited:
Does it support stats change? you can use stats change to add storage value, then when the monster dies, check all players online with those storages.
 
I thought of it, but how to check all the players that have the storage?
Have the onChangeHealth, maybe will be work...

Other thing, this deathList is working, look:

Code:
function onDeath(cid, corpse, killer)
    deathList =  tostring(Creature(cid):getDamageMap())

    if deathList == nil or deathList == "" then
          print(" debugging: NIL VALUE ")
    else

        print(" debugging: " .. deathList .. " ...")
    end
    return true

end
I dont know what is this but the console is printing some numbers when monster dies
 
Last edited:
Good good, incorporate it into the script I made you to begin with add the line that is deathList = and all after it.

If that doesn't work try using for i = 1 instead of 0 let us know =)
 
i've tried this:

Code:
function onDeath(cid, corpse, deathList)
  deathList = tostring(Creature(cid):getDamageMap())
  for i = 1, #deathList do
    if(isPlayer(deathList[i])) then
      doCreatureSay(cid, "test.", TALKTYPE_ORANGE_1)
      doPlayerAddItem(deathList[i], 2160, 1)
    end
  end
  return true
end

But don't worked, and no errors in console...
Any sugestion?


i've been tested with command print("" .. deathList .. "")
and the console is printing some numbers like:
table: 0x3de24ad8
table: 0x3ea54840

and isn't winning the crystal coin
 
Last edited:
actually i've copied from here to test:

http://otland.net/threads/need-example-creature-cid-getdamagemap-ondeath-function-tfs-1-0.204232/
and
https://github.com/otland/forgottenserver/issues/104
and
http://otland.net/threads/need-help-with-these-luas.206422/
and
https://github.com/otland/forgottenserver/pull/81

marksamman commented:
"You may be able to retrieve the "deathList" information as in your unsupported TFS version by using this function:
Creature(cid):getDamageMap()"

Then i've tried but anyone worked :T

The current code:
Code:
function onDeath(cid, corpse, deathList)
  deathList = tostring(Creature(cid):getDamageMap())
  for i = 1, #deathList do

      broadcastMessage("" .. deathList .. "", MESSAGE_EVENT_ADVANCE)
      doPlayerAddItem(deathList[i], 2160, 1)
   
  end
  return true
end
I think missing only acknowledge the player because my console is printing:


2ibeo0l.png



And like this not happens:

Code:
function onDeath(cid, corpse, deathList)
  deathList = tostring(Creature(cid):getDamageMap())
  for i = 1, #deathList do
    if(isPlayer(deathList[i])) then
      broadcastMessage("" .. deathList .. "", MESSAGE_EVENT_ADVANCE)
      doPlayerAddItem(deathList[i], 2160, 1)
    end
  end
  return true
end
 
Last edited:
Status
Not open for further replies.
Back
Top