[please move to Support] AddItem do a corpse after kill it

boby psaico

Well-Known Member
Joined
Oct 17, 2009
Messages
84
Reaction score
5
@About the title:
I created on a wrong session by mistake, sorry.


Hello everyone,
I'm trying to do a script where an item is added to a monster corpse after kill it, and the item depends on player vocation.
But I don't know the exactly command to do it.

I'm using function onKill:
Lua:
function onKill(player, target)
I tried the code below but it creates the item on the floor:
Lua:
Game.createItem(2160, 100, target:getPosition())
If I put "corpse" instead "getPosition" it shows an error:
Lua:
attempt to call method 'corpse' (a nil value)
I have no idea how to do it anymore :S
 
Last edited:

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
589
Reaction score
356
Location
United States
@About the title:
I created on a wrong session by mistake, sorry.


Hello everyone,
I'm trying to do a script where an item is added to a monster corpse after kill it, and the item depends on player vocation.
But I don't know the exactly command to do it.

I'm using function onKill:
Code:
function onKill(player, target)
I tried the code below but it creates the item on the floor:
Code:
Game.createItem(2160, 100, target:getPosition())
If I put "corpse" instead "getPosition" it shows an error:
Code:
attempt to call method 'corpse' (a nil value)
I have no idea how to do it anymore :S
Try this out:
Lua:
local vocation_items = {
    [1] = {2160, 100}, -- Sorcerer
    [2] = {2160, 100}, -- Druid
    [3] = {2160, 100}, -- Paladin
    [4] = {2160, 100}, -- Knight
}

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    if not corpse or not killer or not killer:isPlayer() then
        return true
    end

    local killer = killer:getPlayer()
    local vocation_item = vocation_items[killer:getVocation():getBase():getId()]
    if vocation_item then
        corpse:addItem(vocation_item[1], vocation_item[2])
    end
    return true
end
If you do not have Vocation.getBase() then create a new file in data/lib/core named vocation.lua, then link it via dofile inside data/lib/lib.lua and add this to the new file:
Lua:
function Vocation.getBase(self)
    local base = self
    while base:getDemotion() do
        base = base:getDemotion()
    end
    return base
end
If you absolutely must do onKill instead then let me know how many monsters this will apply to and what tfs version you are using then we can find an alternate.
 
OP
B

boby psaico

Well-Known Member
Joined
Oct 17, 2009
Messages
84
Reaction score
5
@Apollos,

Thanks for the answer, I will test as soon as I get home.
Edit: It worked damn good!

By the way, @Mustafa1337, I actually don't know the TFS version, I'm using this datapack:


But there are some errors on it, in market for example, there is no name on items... no hunting analyzer... do you have a suggestion of a good datapack? Anyway, thanks for helping!
 
Last edited:
Top