• 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!

SetPlayerStorageValues()

Shawak

Intermediate OT User
Joined
Sep 11, 2008
Messages
1,984
Solutions
2
Reaction score
119
Location
Germany
GitHub
Shawak
I saw this thread: http://otland.net/f163/multiply-fromto-storage-values-player-global-15337/, so I decided to update it a litle bit.

Lua:
function setPlayeStorageValues(cid, storages, values)
        if type(storages) == 'number' and type(values) == 'number' then
                return setPlayerStorageValue(cid, storages, values)
	end
        if type(storages) == 'table' and type(values) == 'table' then
                if #storages ~= #values then
                        return print("setPlayeStorageValues(); The lenght of storages have to be the same as the lenght of values")
                end
                for i = 1, #storages do
                        setPlayerStorageValue(cid, storages[i], values[i])
                end
		return true
        end
        return print("setPlayeStorageValues(); Both have to be a table, or both have to be a number.")
end

function setMultiplyGlobalStorageValues(storages, values)
        if type(storages) == 'number' and type(values) == 'number' then
                return setGlobalStorageValue(storages, values)
	end
        if type(storages) == 'table' and type(values) == 'table' then
                if #storages ~= #values then
                        return print("setMultiplyGlobalStorageValues(); The lenght of storages have to be the same as the lenght of values")
                end
                for i = 1, #storages do
                        setGlobalStorageValue(storages[i], values[i])
                end
		return true
        end
	return print("setMultiplyGlobalStorageValues(); Both have to be a number, or both have to be a number.")
end

Not tested ;).

Regards,
Shawak
 
Last edited:
Good idea, should be added to 0.3.6 or 0.4
Although, I mean just the function itself.

Lua:
setMultipleStorageValues(cid)
 
Good idea, should be added to 0.3.6 or 0.4

Pointless, I've never been in need of such function.

Also I think it's relatively stupid to add storages to a table and then call a function when you could simply loop it yourself ^.- Now don't say "It's for noobs", because the noobs don't even know how to make a table, if they know that then they should be able to make that loop themselves.

Lua:
local storages = {123, 543, 5465, 34234}
local values = {1,3,4,5}
setPlayerStorageValues(cid, storages, values)

Looks ugly to me :/ I'd rather do it this way:
Lua:
local storageValues = {[123] = 1, [543] = 3, [5465] = 4, [34234] = 5}
for k, v in pairs(storageValues) do
    setPlayerStorageValue(cid, k, v)
end

Or:
Lua:
local storageValues = {{123, 1}, {543, 3}, {5465, 4}, {34234, 5}}
for _, v in pairs(storageValues) do
    setPlayerStorageValue(cid, unpack(v))
end

And it'd indeed be quite pointless to replace that 3 line code with a function that is very rarely used, in most cases never.
 
Pointless, I've never been in need of such function.

Also I think it's relatively stupid to add storages to a table and then call a function when you could simply loop it yourself ^.- Now don't say "It's for noobs", because the noobs don't even know how to make a table, if they know that then they should be able to make that loop themselves.

Lua:
local storages = {123, 543, 5465, 34234}
local values = {1,3,4,5}
setPlayerStorageValues(cid, storages, values)

Looks ugly to me :/ I'd rather do it this way:
Lua:
local storageValues = {[123] = 1, [543] = 3, [5465] = 4, [34234] = 5}
for k, v in pairs(storageValues) do
    setPlayerStorageValue(cid, k, v)
end

Or:
Lua:
local storageValues = {{123, 1}, {543, 3}, {5465, 4}, {34234, 5}}
for _, v in pairs(storageValues) do
    setPlayerStorageValue(cid, unpack(v))
end

And it'd indeed be quite pointless to replace that 3 line code with a function that is very rarely used, in most cases never.

that is also easy to use:) even noobs know how to copy/paste this and edit it:p
 
Hmm perhaps you right, but me was so boring that I decided to script "anything".
Also I use your method, too. :p
 
No still, because you wrote "storage" and not "storages" so the type will return 'nil' and not 'number' nor 'table' :)
 
why won't you simply do it:
Code:
function setPlayerStorageValues(cid, data)
for k, v in pairs(data) do
setPlayerStorageValue(cid, k, v)
end
end

->

Code:
local t = {[6666] = 1, [666] = 10}
setPlayerStorageValues(cid, t)

as Colandus suggested?
 
Back
Top