• 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!
 
ur download is like all other i downloaded ;'(
i cant get it to work or even start it.
By the way, where should i put your mod to test it? xD
i said if ur ot support mod, but the file i download are all mixed up, i cant undestand.
sorry.
-----
EDIT
-----
after a long night with out sleep ! here it is a working and tested script.
u need to change it to fit with ur event ( that shouldn't be hard )
the code here work as the follow
whenever a player login a monster will be sumoned with registred with the killer event.
whenever a player atk it a counter will be increased
after it is killed, any player who helped to kill it can use a item to receive a gift ( from now it is the same gift no matter ur effort [sad face] but that can easily be changed )

i m just back coding i m really pissed they removed the support for MODS
but here, i tryed to recreate it ( not a sucess either, but works ).

Lets to the code :
1 ST
goto ur data folder and create a folder called "MODS" use caps like the XML folder.
Create a file called bossKiller.lua
Paste the following code Inside.
PHP:
-----------------------------------------------------------------------  

--    Time in minute, after the boss is dead the player have timeOut minute(s) to get his gift.
timeOut = 1  

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

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

local function giveGift(cid)
    item = doCreateItemEx( 2392 , 1)
    if(doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR) then
        return 0, 0
    end
end      

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


function onLogin(cid)

--    registerCreatureEvent(cid,"bossKiller_fight")
    registerCreatureEvent(cid,"bossKiller_death")
    player = cid
    player:say('onLogin.', TALKTYPE_MONSTER_SAY)
  
    local position = getCreaturePosition(cid)
    local ret = doSummonCreature( "rat" , position, false)
    if(tonumber(ret) == nil) then
        doPlayerSendDefaultCancel(cid, (ret == false and RETURNVALUE_NOTPOSSIBLE or RETURNVALUE_NOTENOUGHROOM))
    end
  
    registerCreatureEvent(tonumber(ret), "bossKiller_fight")

    return true
end


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


--    function onCombat(cid, target)
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    cid    = attacker
    target = creature
  
    local bossConfig = bosses[target:getName():lower()]

    if (not bossConfig) then
        return false
    end

    if isPlayer(cid) ~= true  then
        return false
    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 primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end


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


function onKill(creature, target)

    player = creature
    player:say('bravo, Boss Killer.', TALKTYPE_MONSTER_SAY)
  
    boss = bosses[target:getName():lower()]

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


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


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

    player = cid
  
    if next(boss) then
      
--        player:say( getGlobalStorageValue( boss.storage ) , TALKTYPE_MONSTER_SAY)
--        player:say( os.time() , TALKTYPE_MONSTER_SAY)
      
        if getGlobalStorageValue( boss.storage ) <= os.time() then
            player:say("Sorry, but nobody killed any bosses recent! ", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(getCreaturePosition(cid), 2)
            return false
        end

        if getPlayerStorageValue(cid, boss.storage ) < 1 then
            cid:say( " Did u were really there ? " , TALKTYPE_MONSTER_SAY)
        elseif getPlayerStorageValue(cid, boss.storage ) < 200 then
            cid:say( " Good job. " , TALKTYPE_MONSTER_SAY)
        else
            cid:say( " Great, brave Warior " , TALKTYPE_MONSTER_SAY)
        end
      
        giveGift(cid)
        setPlayerStorageValue(cid, boss.storage, 0)
    else
        doPlayerSendCancel(cid, "Sorry, but nobody killed any bosses at all! ")
    end
  

    return true
end


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

2ND
Open actions.xml and add this code
dont forget to change actionid to fit to ur own.
( uniqueid itemid actionid )
by now it is configured to use with a fishing rod ( for test )
Code:
<action itemid="2580" script="../../MODS/bossKiller.lua" allowfaruse="1" />

3RD
open creaturescripts.xml and add this code
Code:
    <event type="login"  name="bossKiller_login"   script="../../MODS/bossKiller.lua" />
  
    <event type="healthchange" name="bossKiller_fight"   script="../../MODS/bossKiller.lua" />
  
    <event type="kill"   name="bossKiller_death"   script="../../MODS/bossKiller.lua" />

that is all, question ? send me via Skype.
 
Last edited:
Back
Top