• 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 How to build local table?

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,758
Solutions
127
Reaction score
2,277
Hello, i have problem building local storage to my kill creaturescript...

I need someone experienced in lua to explain it to me :D

So i was trying to do something like that:

Code:
local monster = {'spider', 'rat', 'corym', 'cave rat}
    if targetMonster:getName():lower() ~= monster then
        return true
    end

But its not working, kill script just doesnt count...

I want to count all of those monsters, like in necro task. Necro + priestesses.
 
The script is not working because is checking the entire table value instead of the values of a certain key.
Code:
local monster = {'spider', 'rat', 'corym', 'cave rat'}
for i = 1, #monster do
    if targetMonster:getName():lower() ~= monster[i] then
    --do your stuff
    end
end
 
Hmm, seems like its checking only for first monster "spider" rest just doesnt work when i kill them :/
 
If you want to build a local table of storage values you can use a base value and use the table's index to automatically create the additional storage values per creature, for instance.

Code:
    local baseStorage = 10000
    local monster = {'spider', 'rat', 'corym', 'cave rat'}
    for i, name in ipairs(monster) do
        if targetMonster:getName():lower() == name then
            -- this create the new storage for every monster in the table if it doesn't exist
            if player:getStorageValue(baseStorage + i) < 1 then
                player:setStorageValue(baseStorage + i, 1)
            else
                -- this will update it the storage value
                player:setStorageValue(baseStorage + i, player:getStorageValue(baseStorage + i) + 1)
            end
        end
    end
 
Last edited:
Do you already have added the script line to rat.xml, spider.xml?
for example:
<script>
<event name="rat_death">
</script>
(Is not correct script but you can find it the correct lines, I dont remember the script lines but it is the idea)
 
Do you already have added the script line to rat.xml, spider.xml?
for example:
<script>
<event name="rat_death">
</script>
(Is not correct script but you can find it the correct lines, I dont remember the script lines but it is the idea)
he said its kill script. you only register script once and on player. (bad idea though, but that is another story)
Code:
 local baseStorage = 10000
local monsterT = {'spider', 'rat', 'corym', 'cave rat'}
local mosterName = targetMonster:getName():lower()
  
if isInArray(monsterT, monsterName) then
player:setStorageValue(baseStorage, player:getStorageValue(baseStorage)+1)
end
 
Back
Top