• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua onDeath set storage value to all who attacked TFS 1.2

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello everyone! I've been searching around, but i can't really find the answer.

Its easy to find onKill, but that only works for the one who lasthited the monster. Like this one:
Code:
function onKill(cid, target)
local player = Player(cid)
local monsters = {
    ["rat"] = {storage = 5000, value = 1},
    ["rotworm"] = {storage = 6000, value = 1}
    }
 
    for i,v in pairs(monsters) do
    if getCreatureName(target) == i then
        player:SetStorageValue(v.storage,v.value)
    end
    return true
    end
end

How do i change this to check everyone who attacked get the storage, say to open a quest door? My coding skills are nearly 0 >.<

Sorry for asking that much guys and very big thanks guys for your time and efforts!
 
That's the code for warzone bosses, they use getDamageMap function, hope it will help you fix your issue. :) I'd remake it for you, but I have no enough time now. Good luck.
Code:
local bosses = {
    ['deathstrike'] = {status = 2, storage = Storage.BigfootBurden.Warzone1Reward},
    ['gnomevil'] = {status = 3, storage = Storage.BigfootBurden.Warzone2Reward},
    ['abyssador'] = {status = 4, storage = Storage.BigfootBurden.Warzone3Reward},
}

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(Storage.BigfootBurden.WarzoneStatus) < bossConfig.status then
                attackerPlayer:setStorageValue(Storage.BigfootBurden.WarzoneStatus, bossConfig.status)
            end

            attackerPlayer:setStorageValue(bossConfig.storage, 1)
        end
    end
end
 
I did something like this, but it doesnt seem to work. My skills are quite low haha!
Code:
local bosses = {
    ['badger'] = {status = 1, storage = 8005},

}

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(8005) < bossConfig.status then
                attackerPlayer:setStorageValue(8005, bossConfig.status)
            end

            attackerPlayer:setStorageValue(8005)
        end
    end
end

I've been battling with this kind of script for days now. I just need a monster that when killed on a group, it gives them a storage to open a door. But nothing seems to work.
 
Last edited:
Code:
local bosses = {
    ['badger'] = {status = 1, storage = 8005},

}

function onKill(creature, target)
    if not target:isPlayer() and not target:getMaster() then
        return true
    end

    local bossConfig = bosses[target:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(target:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(8005) < bossConfig.status then
                attackerPlayer:setStorageValue(8005, bossConfig.status)
            end

            attackerPlayer:setStorageValue(8005, 1)
        end
    end
end

to creaturescripts.xml:
Code:
<event type="kill" name="BossDeath" script="FILENAMEHERE.lua" />
to login.lua depends on how it looks:
1.
Code:
player:registerEvent("BossDeath")
or
2.
Code:
local events = {
-- some other events here --
    'BossDeath'
}
Should work.
 
Last edited:
Testing, edit inc..

EDIT:

Getting error on line 7:

local targetMonster = target:getMonster()
<a nil value>
 
Last edited:
Nothing happens, no errors so far..
Use this to trouble shoot the script and give us a screen shot of the console of the results
Code:
local bosses = {
    ['badger'] = {status = 1, storage = 8005}

}

function onKill(creature, target)
    if not target:isPlayer() and not target:getMaster() then
        print('not target player/get master')
        return true
    end

    local bossConfig = bosses[target:getName():lower()]
 
    if not bossConfig then
        print('no bossConfig')
        return true
    end
 
    if bossConfig then
        for k, v in pairs(bossConfig) do
            print('bossConfig', k, v)
        end
    end

    for pid, _ in pairs(target:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
        print('name, pid, _', attackerPlayer:getName(), pid, _)
            --[[if attackerPlayer:getStorageValue(8005) < bossConfig.status then
                attackerPlayer:setStorageValue(8005, bossConfig.status)
            end

            attackerPlayer:setStorageValue(8005, 1)
            ]]
        end
    end
end
 
I'd like to note that damage maps don't really work properly. You're better off just doing a standard onKill, it should count all the players who helped without using the damage map
 
But i've tested it before, onkill only gives storage for the one who last hitted the monster if im not wrong! :/
 
My Script skill are a bit ODD, sorry if i dont follow standard.
this shall be a different approach but shall work,
more less u can count the number of hit a player atk the target
and before open the Box can prize him acording to his effort like 50 gp par hit :)
here is the code ( not tested ) any help to improve or fix is welcome !


<event type="combat" name="xxx" event="script">
or
<event type="combat" name="BossDeath" script="FILENAMEHERE.lua" />
LIKE MOJ SAID YOU NEED TO UN/REGISTER THE EVENT INSIDE LOGIN AND LOGOUT.LUA ( using the event name ) sorry for caps.

PHP:
local bosses = {
    ['rat'] = {status = 1, storage = 8005},

}


function onCombat(cid, target)

    local targetMonster = target:getMonster()
    local bossConfig = bosses[targetMonster:getName():lower()]

    if (not bossConfig) or ( not targetMonster ) then
        return true
    end

    if isPlayer(cid) ~= true  then
        return true
    end


    if getPlayerStorageValue(cid, bossConfig.storage ) < 0 then
        setPlayerStorageValue(cid, bossConfig.storage , 0 )
    else
        local i = getPlayerStorageValue(cid, bossConfig.storage )
        setPlayerStorageValue(cid, bossConfig.storage , i+1 )
    end


    return true
end
 
Last edited:
Thanks for your answers guys! The problem with the script above is that only by hiting the rat you get the storage id, you dont need to kill the boss.
 

please Remember to NERVER limit your self with only one function to realise ur goals.


Code:
local bosses = {
    ['rat'] = {status = 1, storage = 8005 }
}

PHP:
function onKill(creature, target)

    local targetMonster = target:getMonster()
    local bossConfig = bosses[targetMonster:getName():lower()]

    if (not bossConfig) or ( not targetMonster ) then
        return true
    end

    setGlobalStorageValue( bossConfig.storage , os.time+(30*60))

end

PHP:
function onUse(cid, item, frompos, item2, topos)

    if getGlobalStorageValue( bossConfig.storage ) <= os.time() then
        doPlayerSendCancel(cid, "Sorry, but nobody killed any bosses recent! ")
        doSendMagicEffect(getCreaturePosition(cid), 2)
        return true
    end

    if getPlayerStorageValue(cid, bossConfig.storage ) < 1 then
        doPlayerSendCancel(cid, " Did u were really there ? ")
    elseif getPlayerStorageValue(cid, bossConfig.storage ) < 200 then
        doPlayerSendCancel(cid, " Good job. ")
    else
        doPlayerSendCancel(cid, " Great, brave Warior ")
    end
        setPlayerStorageValue(cid, bossConfig.storage , 0 )

end
 
Last edited:
I've got a bit lost on that last post.. Should i pust those "3" script together? On use on actions for the door, onkill on creatures for the monster kill and the first part?...
A bit of explanation would be awesome since im not really an expert on luo nor scripting!

Thanks for your time and aswers!
 
I've got a bit lost on that last post.. Should i pust those "3" script together? On use on actions for the door, onkill on creatures for the monster kill and the first part?...
A bit of explanation would be awesome since im not really an expert on luo nor scripting!

Thanks for your time and aswers!
No,
onKill is a creature event script
onUse is an action script

The 2 scripts are a bit inconsistent in that they both require the same data, in the onUse script it is missing the bosses table, a better solution would be to make bosses global.

This way it is centralized in a single location and can be referenced as needed.

You could try something like this

This should be placed in global.lua
Code:
bosses = {
    ['rat'] = {status = 1, storage = 8005}
}
boss = {}

This should go in creature scripts
Code:
function onKill(creature, target)

    local targetMonster = target:getMonster()
    boss = bosses[targetMonster:getName():lower()]
 

    if not next(boss) or not targetMonster then
        return true
    end
 
    setGlobalStorageValue( boss.storage , os.time+(30*60))
end

This goes in actions
Code:
function onUse(cid, item, frompos, item2, topos)
    if next(boss) then
        if getGlobalStorageValue( boss.storage ) <= os.time() then
            doPlayerSendCancel(cid, "Sorry, but nobody killed any bosses recent! ")
            doSendMagicEffect(getCreaturePosition(cid), 2)  
            return true
        end
   
        if getPlayerStorageValue(cid, boss.storage ) < 1 then
            doPlayerSendCancel(cid, " Did u were really there ? ")
        elseif getPlayerStorageValue(cid, boss.storage ) < 200 then
            doPlayerSendCancel(cid, " Good job. ")
        else
            doPlayerSendCancel(cid, " Great, brave Warior ")
        end
     
        setPlayerStorageValue(cid, boss.storage, 0)
    end
    return true
end
 
Last edited:
Thanks for the answers.

I've set this part on global.

Code:
bosses = {
    ['rat'] = {status = 1, storage = 8005}
}
boss = {}

This on creaturescripts:

Code:
<event type="kill" name="boss door 2" script="boss door 2.lua"/>

Code:
function onKill(creature, target)

    local targetMonster = target:getMonster()
    boss = bosses[targetMonster:getName():lower()]

    if not next(boss) or not targetMonster then
        return true
    end
    setGlobalStorageValue( boss.storage , os.time+(30*60))
end



that give's me this error:
nUVMean.png


and the onUse part, i've tried to set it in actions as uniqueid and actionid, but when you use the door, it says nothing, does nothing.
Code:
<action actionid="8005" script="boss door 2.lua" />
<action uniqueid="8005" script="boss door 2.lua" />

None works.
 
give me ur IP ? i ll go there :)
not sure if this still work, bc i havent managed to download any working ot server ;'(
link are all incomplete or missing a lot of things, If ur ot support mods u can use this one.

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="BossKiller" version="1.0" author="Willian Batista Cima & Codex NG" contact="xxx" enabled="yes">


-----------------------------------------------------------------------

    <config name="bossKillerSystem"><![CDATA[
        bosses = {
            ['rat'] = {status = 1, storage = 8005}
        }
        boss = {}
    ]]></config>
   
-----------------------------------------------------------------------

    <event type="login" name="bossKiller_login" event="script"><!--[CDATA[
            function onLogin(cid)
                registerCreatureEvent(cid,"bossKiller_fight")
                registerCreatureEvent(cid,"bossKiller_death")
                return true
            end
    ]]--></event>
   
-----------------------------------------------------------------------   


    <event type="combat" name="bossKiller_fight" event="script"><!--[CDATA[
        domodlib('bossKillerSystem')
        function onCombat(cid, target)

            local targetMonster = target:getMonster()
            local bossConfig = bosses[targetMonster:getName():lower()]

            if (not bossConfig) or ( not targetMonster ) then
                return true
            end

            if isPlayer(cid) ~= true  then
                return true
            end

            if getPlayerStorageValue(cid, bossConfig.storage ) < 0 then
                setPlayerStorageValue(cid, bossConfig.storage , 0 )
            else
                local i = getPlayerStorageValue(cid, bossConfig.storage )
                setPlayerStorageValue(cid, bossConfig.storage , i+1 )
            end

            return true
        end
    ]]--></event>
   
   
-----------------------------------------------------------------------   

    <event type="kill" name="bossKiller_death" event="script"><!--[CDATA[
        domodlib('bossKillerSystem')
        function onKill(creature, target)

            local targetMonster = target:getMonster()
            boss = bosses[targetMonster:getName():lower()]
        

            if not next(boss) or not targetMonster then
                return true
            end
        
            setGlobalStorageValue( boss.storage , os.time+(30*60))
        end
    ]]--></event>
   
-----------------------------------------------------------------------   

    <action actionid="xxxx" event="buffer"><![CDATA[
        domodlib('bossKillerSystem')
       
        function onUse(cid, item, frompos, item2, topos)
            if next(boss) then
                if getGlobalStorageValue( boss.storage ) <= os.time() then
                    doPlayerSendCancel(cid, "Sorry, but nobody killed any bosses recent! ")
                    doSendMagicEffect(getCreaturePosition(cid), 2) 
                    return false
                end
          
                if getPlayerStorageValue(cid, boss.storage ) < 1 then
                    doPlayerSendCancel(cid, " Did u were really there ? ")
                elseif getPlayerStorageValue(cid, boss.storage ) < 200 then
                    doPlayerSendCancel(cid, " Good job. ")
                else
                    doPlayerSendCancel(cid, " Great, brave Warior ")
                end
            
                setPlayerStorageValue(cid, boss.storage, 0)
            end
            return true
        end
       
    ]]></action>
   
-----------------------------------------------------------------------   

</mod>
 
Thanks for the answers.

that give's me this error:
nUVMean.png


None works.

it is looks like ur ot is missing the fuction getMonster some how it is returning null
can u send me a link to download the same version as u are using, so i can check the files to FIND a conresponding function.
 
Its TFS 1.2 I'm Not using any modified version. I used the master.

I don't know exactly which one i downloaded so i just reuploaded myself.

https://mega.nz/#!pkU3nQCR
decifer key: !OvdCTjE8VqkOn81bv4D2P41ZoATQMqH6S1epmaDwHKQ
feel free to test it!

By the way, where should i put your mod to test it? xD
 
Back
Top