• 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 send all depot items from another city?

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I made my oracle NPC, its work, but i want to... when player leave from rookgaard, all he items depot from town id 7 (rookgaard) send to main (town id 9)...

Should be possible? Anyone know how could do it?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)     
NpcSystem.parseParameters(npcHandler)

local pos = {x=503, y=716, z=6}
local townid = 9

local talkState = {}               

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
   return false   
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   if msgcontains(msg:lower(), "sorcerer") then
       if(getPlayerLevel(cid) ~= 8) then
           selfSay("You need be level 8 to go to main!", cid)
           return true
       end
       if(getPlayerVocation(cid) ~= 0) then
           selfSay("You have a vocation!", cid)
           doPlayerSetTown(cid, townid)
           doTeleportThing(cid, pos)
           return true
       end
       doPlayerSetVocation(cid, 1)
       doPlayerSetTown(cid, townid)
       doTeleportThing(cid, pos)
   elseif msgcontains(msg:lower(), "druid") then
       if(getPlayerLevel(cid) ~= 8) then
           selfSay("You need be level 8 to go to main!", cid)
           return true
       end
       if(getPlayerVocation(cid) ~= 0) then
           selfSay("You have a vocation!", cid)
           doPlayerSetTown(cid, townid)
           doTeleportThing(cid, pos)
           return true
       end
       doPlayerSetVocation(cid, 2)
       doPlayerSetTown(cid, townid)
       doTeleportThing(cid, pos)
   elseif msgcontains(msg:lower(), "paladin") then
       if(getPlayerLevel(cid) ~= 8) then
           selfSay("You need be level 8 to go to main!", cid)
           return true
       end
       if(getPlayerVocation(cid) ~= 0) then
           selfSay("You have a vocation!", cid)
           doPlayerSetTown(cid, townid)
           doTeleportThing(cid, pos)
           return true
       end
       doPlayerSetVocation(cid, 3)
       doPlayerSetTown(cid, townid)
       doTeleportThing(cid, pos)
   elseif msgcontains(msg:lower(), "knight") then
       if(getPlayerLevel(cid) ~= 8) then
           selfSay("You need be level 8 to go to main!", cid)
           return true
       end
       if(getPlayerVocation(cid) ~= 0) then
           selfSay("You have a vocation!", cid)
           doPlayerSetTown(cid, townid)
           doTeleportThing(cid, pos)
           return true
       end
       doPlayerSetVocation(cid, 4)
       doPlayerSetTown(cid, townid)
       doTeleportThing(cid, pos)
   end
   -- remove all items from depot town id 7 and send everything to depot town id 9
end  -- fim function
         

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I tested my script and it removed all items from the player's depot. However I'm also using a later version and there's no such thing as space outside the depot chest because of the inbox and market dealio. I literally actually used the information from YOUR comment to write it, so I guess you're the one who is trash.




Edit:
Code:
local storage = 1001
function onLogout(cid)
    local guid = getPlayerGUID(cid)
    local townid = 7
    if getCreatureStorage(cid, storage) > 0 then
        local sids = {}
        local resultId = db.storeQuery('SELECT * FROM player_depotitems WHERE player_id=' guid)
        if resultId ~= false then
            repeat
                local pid = result.getDataInt(resultId, "pid")
                if pid == townid then
                    table.insert(sids, result.getDataInt(resultId, "sid"))
                end
            until not result.next(resultId)
            result.free(resultId)
        end

        db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`=7 AND `player_id`="..guid)
        for i = 1, #sids do
            db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`="..sids[i].." AND `player_id`="..guid)
        end
        doCreatureSetStorage(cid, storage, 0)
    end
    return true
end
this should delete all items and items within containers, since it checks for any sids involved with the town and deletes any items that have that sid as their pid. Happy now?
except the guy is asking how he could transfer between depots
there is no way to do this in pure lua for older versions that isn't completely trash
making multiple queries over and over again to remove/insert or even edit values for every single item in a depot is horrible
._.
 
except the guy is asking how he could transfer between depots
there is no way to do this in pure lua for older versions that isn't completely trash
making multiple queries over and over again to remove/insert or even edit values for every single item in a depot is horrible
._.
It was made quite clear that it isn't possible in lua the way he wants, I simply offered a method that's used by another server that works quite well, my knowledge of SQL is limited but what I offered at least works and isn't terribly different from the other suggestions, other than it allows the player to move only the items they want and doesn't force a logout to work, it simply works whenever they logout on their own. At least I offered something concrete rather than speculation. If he wanted to use such a method and it needed tweaks, tweaks could be made. Like running on startup or during server save shutdown when running several or heavy queries doesn't matter. What more do you want? In a perfect world, he'd just drop the outdated engine and use 1.x or he could just remove the depot in rook because why do you need a depot in rook? Could even do something like, if you want people to be allowed to create rookers, limit the level they're allowed to leave rook at to like 10 or something, and not allow them to use the depot in rook unless they're over that limit. Boom, people in rook keep their depot and people leaving rook never had one in the first place. My goodness. We can speculate all day.
 
You guys there is no reason to fight! You all helps!!!
No pls...

I just was looking for delete items from Rook DPs because it will save in DB for nothing if player is in main, just it
It was no necessary transfer to main if could get some errors...

So i decide to use this storage on oracle send to main:
Code:
doCreatureSetStorage(cid, 36361, 1)

And onlogout
Code:
<event type="logout" name="cleanDBDProok" event="script" value="cleanDBDP_rook.lua" />

Code:
local storage = 36361
function onLogout(cid)
    local guid = getPlayerGUID(cid)
    local townid = 7
    if getCreatureStorage(cid, storage) == 1 then
        local sids = {}
        local resultId = db.storeQuery('SELECT * FROM player_depotitems WHERE player_id=' guid)
        if resultId ~= false then
            repeat
                local pid = result.getDataInt(resultId, "pid")
                if pid == townid then
                    table.insert(sids, result.getDataInt(resultId, "sid"))
                end
            until not result.next(resultId)
            result.free(resultId)
        end

        db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`=7 AND `player_id`="..guid)
        for i = 1, #sids do
            db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`="..sids[i].." AND `player_id`="..guid)
        end
        doCreatureSetStorage(cid, storage, 2)
    end
    return true
end

But what is worng with guid?
Code:
[13:20:29.684] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/cleanDBDP_rook.lua:7: ')' expected near 'guid'
[13:20:29.685] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/cleanDBDP_rook.lua)
[13:20:29.685] data/creaturescripts/scripts/cleanDBDP_rook.lua:7: ')' expected near 'guid'
 
Code:
local resultId = db.storeQuery("SELECT * FROM `player_depotitems` WHERE `player_id`=" ..guid)

No errors, but not happen (no delete the items)

Logout scripts need to register on login.php too or in somewhere? (srry if its a idiot question)

Like
Code:
registerCreatureEvent(cid, "extrasExp")
 
No errors, but not happen (no delete the items)

Logout scripts need to register on login.php too or in somewhere? (srry if its a idiot question)

Like
Code:
registerCreatureEvent(cid, "extrasExp")
yep, it'll need to be registered, after
doCreatureSetStorage(cid, 36361, 1) in your oracle just register it right there as you wrote it above (but with correct event name of course)
 
yep, it'll need to be registered, after
doCreatureSetStorage(cid, 36361, 1) in your oracle just register it right there as you wrote it above (but with correct event name of course)

Lol, so using that script need to register in login.lua to this logout script?
Code:
registerCreatureEvent(cid, "cleanDBDProok")
 
I'd register it in login and the oracle script but just login is fine assuming they logout more than once ever xD

Idk, i've put it in oracle:
Code:
doCreatureSetStorage(cid, 36361, 1)

put it in /creaturescripts/data/login.lua
Code:
registerCreatureEvent(cid, "cleanDBDProok")

And use this creaturescript
Code:
<event type="logout" name="cleanDBDProok" event="script" value="cleanDBDP_rook.lua" />

Code:
local storage = 36361
function onLogout(cid)
    local guid = getPlayerGUID(cid)
    local townid = 7
    if getCreatureStorage(cid, storage) == 1 then
        local sids = {}
        local resultId = db.storeQuery("SELECT * FROM `player_depotitems` WHERE `player_id`=" ..guid)
        if resultId ~= false then
            repeat
                local pid = result.getDataInt(resultId, "pid")
                if pid == townid then
                    table.insert(sids, result.getDataInt(resultId, "sid"))
                end
            until not result.next(resultId)
            result.free(resultId)
        end

        db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`=7 AND `player_id`="..guid)
        for i = 1, #sids do
            db.executeQuery("DELETE FROM `player_depotitems` WHERE `pid`="..sids[i].." AND `player_id`="..guid)
        end
        doCreatureSetStorage(cid, storage, 2)
    end
    return true
end

But nothing is working, and have no errors on console
 
It won't register until after they've logged out and then logged back in, which is why I had suggested you could put the register in the oracle as well, but on their second logout it should remove their depot items
 
It won't register until after they've logged out and then logged back in, which is why I had suggested you could put the register in the oracle as well, but on their second logout it should remove their depot items

You mean put it:
Code:
registerCreatureEvent(cid, "cleanDBDProok")

before it?
Code:
doCreatureSetStorage(cid, 36361, 1)

In npc oracle, like this?
Code:
registerCreatureEvent(cid, "cleanDBDProok")
doCreatureSetStorage(cid, 36361, 1)


---

I relogout 5 times and didnt clean rook DP
 
Back
Top