Hello Peoples,
This is nothing Special but it might help some people and it can shorten up time setting StorageValues...
Aren't you tired of this?
it takes much time (even copy paste) and it let your script getting bigger...
here is an easy solution with the functions I made
setPlayerMultiplyStorageValues & setMultiplyGlobalStorageValues
works like this...
now every of those listened numbers in the "{}" will be set as value = 1 so they're basicly in use... (You can ofc change the 1 to any other number you want)
removePlayerMultiplyStorageValues & removeMultiplyGlobalStorageValues
You can easy guess it works same like the upper function with the difference that it sets all the storageValues used in the "{}" as "not in use" means -1
getPlayerMultiplyStorageValues & getMultiplyGlobalStorageValues
This way you can check if the required values are "in use" or "not in use"
here an easy example:
Yes you see right there is no need "== TRUE" or anything else after the function because it checks that via the value which you put in there...
If there are more questions then feel free to ask
UPDATE!
Implemention of the FromTo Storage Values
-- Normal Ones (easy to use)
There is not much difference between the Multiply and this ones.
I hope it's self explained already!
If not..let's say I wanted to set all values from 100 - 200 "in use" then it looks like this (fromStorage, toStorage) = (100, 200)
-- Advanced Ones (TESTED and Working!)
Here you have the the option to choose between more then just 1 between numbers -- I know that this sounds weird but can't explain it better...
here an example:
If there are any errors let me know since I didn't tested them before..
kind regards, Evil Hero
This is nothing Special but it might help some people and it can shorten up time setting StorageValues...
Aren't you tired of this?
Code:
doSetPlayerStorageValue(cid,1000,1)
setPlayerStorageValue(cid,1001,1)
setPlayerStorageValue(cid,1002,1)
setPlayerStorageValue(cid,1003,1)
it takes much time (even copy paste) and it let your script getting bigger...
here is an easy solution with the functions I made
setPlayerMultiplyStorageValues & setMultiplyGlobalStorageValues
Code:
function setPlayerMultiplyStorageValues(cid, storage, value)
for _, storage in pairs(storage) do
setPlayerStorageValue(cid, storage, value)
end
end
function setMultiplyGlobalStorageValues(storage, value)
for _, storage in pairs(storage) do
setGlobalStorageValue(storage, value)
end
end
works like this...
Code:
setPlayerMultiplyStorageValues(cid,{1001,1002,1003,1004},1)
setMultiplyGlobalStorageValues({1000,1001,1002,1003,1004},1)
now every of those listened numbers in the "{}" will be set as value = 1 so they're basicly in use... (You can ofc change the 1 to any other number you want)
removePlayerMultiplyStorageValues & removeMultiplyGlobalStorageValues
Code:
function removePlayerMultiplyStorageValues(cid, storage)
for _, storage in pairs(storage) do
setPlayerStorageValue(cid, storage, -1)
end
end
function removeMultiplyGlobalStorageValues(storage)
for _, storage in pairs(storage) do
setGlobalStorageValue(storage, -1)
end
end
You can easy guess it works same like the upper function with the difference that it sets all the storageValues used in the "{}" as "not in use" means -1
getPlayerMultiplyStorageValues & getMultiplyGlobalStorageValues
Code:
function getPlayerMultiplyStorageValues(cid, storage, value)
for _, storage in pairs(storage) do
if getPlayerStorageValue(cid, storage) == value then
return TRUE
else
return FALSE
end
end
end
function getMultiplyGlobalStorageValues(storage, value)
for _, storage in pairs(storage) do
if getGlobalStorageValue(storage) == value then
return TRUE
else
return FALSE
end
end
end
This way you can check if the required values are "in use" or "not in use"
here an easy example:
Code:
if getPlayerMultiplyStorageValues(cid,{1000,1001,1002,1003},1) then
return TRUE
else
return FALSE
end
if getMultiplyGlobalStorageValues({1000,1001,1002,1003},1) then
return TRUE
else
return FALSE
end
Yes you see right there is no need "== TRUE" or anything else after the function because it checks that via the value which you put in there...
If there are more questions then feel free to ask
UPDATE!
Implemention of the FromTo Storage Values
-- Normal Ones (easy to use)
Code:
function setPlayerFromToStorageValues(cid, fromStorage, toStorage, value)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
setPlayerStorageValue(cid, a, value)
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
end
function setFromToGlobalStorageValues(fromStorage, toStorage, value)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
setGlobalStorageValue(a, value)
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
end
function removePlayerFromToStorageValues(cid, fromStorage, toStorage)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
setPlayerStorageValue(cid, a, -1)
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
end
function removeFromToGlobalStorageValues(fromStorage, toStorage)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
setPlayerStorageValue(a, -1)
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
end
function getPlayerFromToStorageValues(cid, fromStorage, toStorage, value)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
if getPlayerStorageValue(cid,a) == value then
return TRUE
else
return FALSE
end
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
return TRUE or FALSE
end
function getFromToGlobalStorageValues(fromStorage, toStorage, value)
if fromStorage < toStorage then
if fromStorage > 0 then
if toStorage > 0 then
for a = fromStorage, toStorage do
if getGlobalStorageValue(a) == value then
return TRUE
else
return FALSE
end
end
else
error("toStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then 0")
end
else
error("fromStorage has to be higher then toStorage!")
end
return TRUE or FALSE
end
There is not much difference between the Multiply and this ones.
I hope it's self explained already!
If not..let's say I wanted to set all values from 100 - 200 "in use" then it looks like this (fromStorage, toStorage) = (100, 200)
-- Advanced Ones (TESTED and Working!)
Code:
function setPlayerFromToStorageValues(cid, storage, value)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
setPlayerStorageValue(cid, a, value)
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE
end
function setFromToGlobalStorageValues(storage, value)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
setGlobalStorageValue(a, value)
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE
end
function removePlayerFromToStorageValues(cid, storage)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
setPlayerStorageValue(cid, a, -1)
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE
end
function removeFromToGlobalStorageValues(storage)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
setGlobalStorageValue(a, -1)
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE
end
function getPlayerFromToStorageValues(cid, storage, value)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
if getPlayerStorageValue(cid, a) == value then
return TRUE
else
return FALSE
end
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE or FALSE
end
function getFromToGlobalStorageValues(storage, value)
for k,v in pairs(storage) do
if (isNumber(k) and isNumber(v)) == TRUE then
if k < v then
if k > 0 then
if v > 0 then
for a = k,v do
if getGlobalStorageValue(a) == value then
return TRUE
else
return FALSE
end
end
else
error("Table value has to be higher then 0")
end
else
error("Table key has to be higher then 0")
end
else
error("Table key has to be lower then Table value")
end
else
error("Table value and key have to be numbers")
end
end
return TRUE or FALSE
end
Here you have the the option to choose between more then just 1 between numbers -- I know that this sounds weird but can't explain it better...
here an example:
Code:
setPlayerFromToStorageValues(cid,{[100] = 200,[300] = 400,[500] = 600},1)
-- this would now set all the values from 100-200,300-400 and 500-600 "in use" and left out what is between 201-299 same with 401-499
If there are any errors let me know since I didn't tested them before..
kind regards, Evil Hero
Last edited: