• 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 Show storage of few players to these players does not work after setting storage to -1.

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
TFS 0.3.6
How can I reset storages of all players and still display message from a loop?
Code:
function onKill(cid, target)

    if isMonster(target) and isPlayer(cid) then

        local tmp = bossHighestDmg[getCreatureName(target):lower()]
    
        local players = {}
    
        if tmp then
            for i = 1, #tmp, 1 do

                for _, pid in pairs(getPlayersOnline()) do
                    -- this is the message I want to be displayed before setting storage to -1
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
                end
                -- this does not work, message displays for one player correct storages but for second player -1 storages
                doCreatureSetStorage(cid, 11005, -1)

            end
        end
    end

    return true
end
 
Last edited:
the problem is the loop does one time then reset storage and again loop. it must be loop, loop, reset, not loop, reset, loop.
Code:
                for _, pid in pairs(getPlayersOnline()) do
                    -- this is the message I want to be displayed before setting storage to -1
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
                end
                -- this does not work, message displays for one player correct storages but for second player -1 storages
                doCreatureSetStorage(cid, 11005, -1)

loops does 2 times because of pid. 2 players with the same storage gets the message (cid)
 
Last edited:
you are resetting the storage of the player cid to -1 in onKill, cid is only 1 player, if you want to do it for everyone online you have to put it in the loop and use the pid
 
thank you, but that doesnt work too:
Code:
        for _, pid in ipairs(getPlayersOnline()) do
        
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
           doCreatureSetStorage(pid, 11005, -1)
        
         end
It gives https://imgur.com/iVAWOmT
Firstt cid gets correct storages, but second gets -1. :(
1. loop. 2. show storage. 3. loop 4. resets storage
 
Code:
    for _, pid in ipairs(getPlayersOnline()) do
   
           doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
           doCreatureSetStorage(pid, 11005, -1)
   
         end
Pids everywhere does: :(
https://imgur.com/7tt8p3k
 
Code:
                local z = 0   
                for _, pid in ipairs(getPlayersOnline()) do
                    z = z + 1
                    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
                    doCreatureSetStorage(pid, 11005, -1)
                    print('z: '..z)
                end
console:
[14/07/2016 17:32:38] z: 1
[14/07/2016 17:32:38] z: 2
[14/07/2016 17:32:38] z: 1
[14/07/2016 17:32:38] z: 2
 
my bad, i couldnt read
what is the problem though? it says the current value in that storage for the player, then sets it to -1, is that not what you want?
 
Men, ALMOST got it. Look, please: https://imgur.com/NK53GFZ
The code:
Code:
        local z = 0  
         for _, pid in ipairs(getPlayersOnline()) do
          
           z = z + 1
          
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
          
          
           if next(getPlayersOnline(), _) == nil then
             print('z: '..z)
             doCreatureSetStorage(pid, 11005, -1)
           end
        
         end
The console:
[14/07/2016 17:42:44] z: 2
[14/07/2016 17:42:44] z: 2
Any help?
 
Last edited:
what is the problem though?
BEFORE and then do reset. I want to display both players storages to them both. It is damage done to a monster for all people who were hitting a monster, so all have to see damage done of all people.
I've edited post before, check it with "next".
It is mind confusing script...
 
Last edited:
but
Code:
for _, pid in ipairs(getPlayersOnline()) do

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
doCreatureSetStorage(pid, 11005, -1)

end
prints current storage then resets it, do you want to show it to the talkaction player only, or show the storages to the players whos been reset?
^.-
come to otland discord or add me zothion#4226, this is too difficult
 
Code:
for _, pid in ipairs(getPlayersOnline()) do
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerName(pid)..': '..getCreatureStorage(pid, 11005))
                    print('getCreatureStorage(pid: '..getCreatureStorage(pid, 11005))
                    doCreatureSetStorage(pid, 11005, -1)
                end
https://imgur.com/ctGnqwD
help, please

ok, Zothion helped me in private channel. He is a great scripter!
 
Last edited:
Back
Top