• 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 onUse script for tfs 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
how can i do a script that if the player use the item will appear a item id 2001 on depot town id 1?

I need a script like this...

every time that a player use this item, get storage 1001 + 1, after the script will check if the player used the item 7 times, if the player have storage 1001,7.
will receive a item id 2001 on depot town id 1.
 
Solution
Sure!

Just get the depot object for the player (as it returns as a "container").

Lua:
depot = player:getDepotChest(depot id)
depot:addItem(item id)

You should also check to see if the depot exists before adding items to it.
One piece of advice I can give you is that you need for the player to be offline as you will have to use sql queries. So if player uses item and gets storage 1001, 7 you should not run the queries at that time, you could try to do it at server save or server startup. Or, the easy way, just add the item to the player and that's it.
 
One piece of advice I can give you is that you need for the player to be offline as you will have to use sql queries. So if player uses item and gets storage 1001, 7 you should not run the queries at that time, you could try to do it at server save or server startup. Or, the easy way, just add the item to the player and that's it.
Or just, you know, send it as parcel
 
Just have it appear on login.

Code:
onLogin
if storage1001 >= 7 then
depot:addItem(item)
end

Something like that! This is just a quick pseudo, attempt to make something first then come back if you get stuck.
 
Sure!

Just get the depot object for the player (as it returns as a "container").

Lua:
depot = player:getDepotChest(depot id)
depot:addItem(item id)

You should also check to see if the depot exists before adding items to it.
 
Solution
No, I think you need to use a depot ID that you set in the map editor.
I may be wrong though! Does not hurt to test out either :)
 
Depot ID must correspond to the town ID of the depot you want to insert into, you can use the second parameter in getDepotChest to autocreate the depot if the player has not used a depot in that town before:
Lua:
player:getDepotChest(depotId, true)
 
Back
Top