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

Lua onKill tfs 1.2

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
How to put for all players win the storage when monster die?
The script give storage for only one player:

LUA:
function onKill(cid, target, damage, flags, corpse)
    local player = Player(cid)
  
    if(isMonster(target)) then
        if(string.lower(getCreatureName(target)) == "rat") then
            if player:getStorageValue(2204171609) < 1 then
            player:setStorageValue(2204171609, 1)
            end
        end
    end
    return true
end
 
Solution
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
 
    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
            if creature:getName():lower() == "rat" and player:getStorageValue(2204171609) < 1 then
                player:setStorageValue(2204171609, 1)
            end
        end
    end
 
    return true
end

or this if you want to keep it onKill event:
LUA:
function onKill(cid, target, damage, flags, corpse)
    if(isMonster(target)) then
        if(string.lower(getCreatureName(target)) == "rat") then
            for attackerUid, damage in pairs(target:getDamageMap()) do
                local player =...
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
 
    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
            if creature:getName():lower() == "rat" and player:getStorageValue(2204171609) < 1 then
                player:setStorageValue(2204171609, 1)
            end
        end
    end
 
    return true
end

or this if you want to keep it onKill event:
LUA:
function onKill(cid, target, damage, flags, corpse)
    if(isMonster(target)) then
        if(string.lower(getCreatureName(target)) == "rat") then
            for attackerUid, damage in pairs(target:getDamageMap()) do
                local player = Player(attackerUid)
                if player and player:getStorageValue(2204171609) < 1 then
                    player:setStorageValue(2204171609, 1)
                end
            end
        end
    end
    return true
end
 
Last edited:
Solution
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
  
    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
            if player:getStorageValue(2204171609) < 1 then
                player:setStorageValue(2204171609, 1)
            end
        end
    end
  
    return true
end

Hello, but how verify the monster name, and attackerUid is tfs 1.2? thanks
 
edited the post above

damageMap exists in 1.2 and attackerUid has nothing to do with TFS version, just how I named the key
 
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)

    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
            if creature:getName():lower() == "rat" and player:getStorageValue(2204171609) < 1 then
                player:setStorageValue(2204171609, 1)
            end
        end
    end

    return true
end

or this if you want to keep it onKill event:
LUA:
function onKill(cid, target, damage, flags, corpse)
    if(isMonster(target)) then
        if(string.lower(getCreatureName(target)) == "rat") then
            for attackerUid, damage in pairs(target:getDamageMap()) do
                local player = Player(attackerUid)
                if player and player:getStorageValue(2204171609) < 1 then
                    player:setStorageValue(2204171609, 1)
                end
            end
        end
    end
    return true
end
-I'm having errors, I was trying to add a meesage showing the ammount of creatures that you have killed-
EDIT: I fixed the script and it is working!
LUA:
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)

    for attackerUid, damage in pairs(creature:getDamageMap()) do
        local player = Player(attackerUid)
        if player then
            if creature:getName():lower() == "rat" and player:getStorageValue(2204171609) < 1 then
                player:setStorageValue(2204171609, 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have slain your first rat.")
        else
                player:setStorageValue(2204171609, player:getStorageValue(2204171609) + 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have slain " .. player:getStorageValue(2204171609) .. " rats.")
            end
        end
    end

    return true
end
This script is showing the next messages whenever you kill such creature:
16:58 You have slain your first rat.
16:58 You have slain 4 rats.
 
Last edited:
Back
Top