• 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 About Storage

Bruce Leal

New Member
Joined
Nov 9, 2017
Messages
77
Reaction score
3
Is there any storage limit?
Is there any beginning? I could start with getPlayerstorage 1 and setPlayerstorage 2?

I used next to one that already existed, example: getPlayerstorage 40112 and setPlayerstorage 40113
 
If I'm not mistaken you can use up to 65536 because storage is 16 bit. The first ones are mainly reserved for basic functions of the server so I'd say to you only use the ones above 1000, but don't forget to always check your actions/movements scripts to see if they use the number you want to use.

The best thing would be to write it down make a log of which ones you are using, but nobody does that.
 
Hello there Bruce,

depending on the distribution you use it may change, TFS handles storages pretty simply. You just have to check how you store the storage values, normally they are an unsigned short int in the database so they go from 0 to 65535.

Storages can be used like setPlayerstorageValue(cid, storageNumber, n), that means you can give int values 'n' to storages.

For example: If you talk to a npc that checks your storage for the number 1, "getPlayerStorageValue(cid,1) == true" and if the case is yes, then you can return whatever you want on code, also you can add an extra int value to the storage of number 1, example: setPlayerStorageValue(cid,1,1).

I hope to not have confused you with that, normally when you set the storage to a player using no extra values it will be set to 1, when the player doesn't have the storage it's set to -1.

Kindest Regards,
Okke
 
Is there any storage limit?
Is there any beginning? I could start with getPlayerstorage 1 and setPlayerstorage 2?

I used next to one that already existed, example: getPlayerstorage 40112 and setPlayerstorage 40113
I just found this and I hope it helps you get a better understanding of what a storage value is.
[Lua] Understanding Storages
 
Hello there Bruce,

depending on the distribution you use it may change, TFS handles storages pretty simply. You just have to check how you store the storage values, normally they are an unsigned short int in the database so they go from 0 to 65535.

Storages can be used like setPlayerstorageValue(cid, storageNumber, n), that means you can give int values 'n' to storages.

For example: If you talk to a npc that checks your storage for the number 1, "getPlayerStorageValue(cid,1) == true" and if the case is yes, then you can return whatever you want on code, also you can add an extra int value to the storage of number 1, example: setPlayerStorageValue(cid,1,1).

I hope to not have confused you with that, normally when you set the storage to a player using no extra values it will be set to 1, when the player doesn't have the storage it's set to -1.

Kindest Regards,
Okke

In fact you've confused me a bit with this: setPlayerStorageValue (cid, 1,1).

Let me give an example of the current situation:

There are players sorcerer, druid, knight and paladin, I do not know storage because they have these vocations, however ... each vocation has a respective npc that will give the promotion, to another class, example:
Knight - Death Knight getplayerstorage ????? To Setplayerstorage 43200
Paladin - Saint Paladin getplayerstorage ????? To Setplayerstorage 43201
Druid - Example Druid getplayerstorage ????? To Setplayerstorage 43202
Sorcerer - Example Druid getplayerstorage ????? To Setplayerstorage 43203
 
In fact you've confused me a bit with this: setPlayerStorageValue (cid, 1,1).

Let me give an example of the current situation:

There are players sorcerer, druid, knight and paladin, I do not know storage because they have these vocations, however ... each vocation has a respective npc that will give the promotion, to another class, example:
Knight - Death Knight getplayerstorage ????? To Setplayerstorage 43200
Paladin - Saint Paladin getplayerstorage ????? To Setplayerstorage 43201
Druid - Example Druid getplayerstorage ????? To Setplayerstorage 43202
Sorcerer - Example Druid getplayerstorage ????? To Setplayerstorage 43203

I'm sorry, I didn't mean to confuse you, I just wanted to tell you that Storage values do have more states than off and on (-1, 1).

Now to your example, try to see storages as a light switch, exactly like the one you have on your wall! I can say that at choosing the vocation Knight you set the storage with "SetPlayerStorageValue(cid,?????)" <- that will set the storage "?????" to 1 which mean it's active.
Once you then as a Knight go to the promotion npc it should check if the player has the storage with "getPlayerStorage(cid,?????) == true" <- true means the storage is active (1). Logically afterwards you should then give the player the new storage you wish with "setPlayerStorageValue(cid,43200)" <- which will again set the storage "43200" to 1, which respectively means it's active.

There is just a big hole in the whole form you think about storages as there is a function that gather information about the players vocation, which is "getPlayerVocation(cid)". As you can see in your vocations.xml file, each vocation has a number, so it should be used as "getPlayerVocation(cid) == vocationNumber" (use if getPlayerVocation(cid) == 4 then). I suggest you really reading a little bit more before doing this kind of code. I don't know also which distribution you are using. I'm used to do my codings on 0.4 so I follow respective list of functions when I don't know if there is one avaliable for the kind of job I want to accomplish: [LUA] 0.4 TFS Functions

Please read the article that @Linxsis provided, also Lua learning is a process of trial and error if you have no idea of how computers actually think and do their tasks. After you got to understand how it all works you'll be able to pretty much do anything you want as long as it's in the limits of the game and language you're programming (basically more than you can possibly imagine).

Kindest Regards,
Okke
 
In fact you've confused me a bit with this: setPlayerStorageValue (cid, 1,1).

Let me give an example of the current situation:

There are players sorcerer, druid, knight and paladin, I do not know storage because they have these vocations, however ... each vocation has a respective npc that will give the promotion, to another class, example:
Knight - Death Knight getplayerstorage ????? To Setplayerstorage 43200
Paladin - Saint Paladin getplayerstorage ????? To Setplayerstorage 43201
Druid - Example Druid getplayerstorage ????? To Setplayerstorage 43202
Sorcerer - Example Druid getplayerstorage ????? To Setplayerstorage 43203
Lets simplify it for you. A storage is a number based variable where a value can be assigned to it via setPlayerStorage. To retrieve the information stored inside of the number based storage you call or invoke getPlayerStorage.

Using the explanation above, this
Code:
local storageNumber = 45676
setPlayerStorage(cid, storageNumber, 1234)
and this
Code:
local variable = 1234
Are equivalent when it comes to storing the same type of number based variable, a storage value's value can only be retrieved via getPlayerStorage, where as a variable's value can be retrieved by almost any means. The other difference between a variable and a storage is its default value, a variable's default value holds a junk value or nil (none value) where as a storage's default value holds a value of -1.
 
Last edited:
I understand, but how will I know the storage of a player with a vocation?

I need to know the sorcerer / druid / paladin / knight storage in order to use the
getPlayerstorage
 
I understand, but how will I know the storage of a player with a vocation?

I need to know the sorcerer / druid / paladin / knight storage in order to use the
getPlayerstorage

You don't need to know the player's storage to know the player's vocation, re-read my post, I told and linked you a Forum thread that contains various hard-coded functions that you can use. You can do as I wrote on my post or just leave the pointlessness behind and use storages only when you need them. I dont mean to sound rude I just have no clue on how to make it even clearer for you, I'm a really bad teacher, though the tutorial Linxsis posted might help you a lot!

A small edit: You can combine more functions when coding (maybe this wasn't clear enough for you).

This is enough to promote a knight to elite knight:
Lua:
if getPlayerVocation(cid) == 4 then
      doPlayerSetVocation(cid,8)
end

On your way of thinking you're doing like:

Lua:
if getPlayerStorage(cid,?????) then
      doPlayerSetVocation(cid,newVocationNumber)
      setPlayerStorageValue(cid,43200)
end

Which makes no sense as Vocation needs no storage values...I just can't think of anything further to help, I'm deeply sorry.


Kindest Regards,
Okke
 
Last edited:
Wow ... but it's the ID system I really want, storage is VERY annoying ...
But I think I understand now ...
Now a question to finish:

If the player get storage 4001, can he return to the 4000? or is it just recorded as a bau quest situation?
 
Wow ... but it's the ID system I really want, storage is VERY annoying ...
But I think I understand now ...
Now a question to finish:

If the player get storage 4001, can he return to the 4000? or is it just recorded as a bau quest situation?
?? we explained what a storage value is. I think you still don't understand our explanation please re-read all the information which was provided to you (links and all).
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   print(getPlayerStorageValue(cid, 45001))
   print(getPlayerStorageValue(cid, 45002))
   print(getPlayerStorageValue(cid, 45003))
   print(getPlayerStorageValue(cid, 45004))

   setPlayerStorageValue(cid, 45001, 10)
   setPlayerStorageValue(cid, 45002, 5)
   setPlayerStorageValue(cid, 45003, 1)
   setPlayerStorageValue(cid, 45004, 25)

   print("---")
   print(getPlayerStorageValue(cid, 45001))
   print(getPlayerStorageValue(cid, 45002))
   print(getPlayerStorageValue(cid, 45003))
   print(getPlayerStorageValue(cid, 45004))
   return true
end
output to console
Code:
-1
-1
-1
-1
---
10
5
1
25
 
Back
Top