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

Multiply/FromTo >Storage Values< (Player/Global)

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,254
Solutions
27
Reaction score
721
Location
Germany
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?

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:
You could also make it from->to >< But well, great idea, though.
Yea thought about the same before, but sometimes one of the values which you want to use then is already used so it wouldn't really work out like it should :p

but I'll post them later as extra functions :)


kind regards, Evil Hero
 
UPDATE! added the "FromTo" Functions :p

I hope that they'll work correct :D

kind regards, Evil Hero
 
Another UPDATE! the Advanced "fromTo" ones are changed and tested now!

they work 100% now :)

kind regards, Evil Hero
 
You can make from/to using exceptions too, so you will get the same result as the first function.
 
Multiple not multiply :p Totally different meaning xD

However I'd use bit.bor/bit.band for this :) Instead of using many storage values, you can just use a single one as it's only about true/false (1/0)

As in http://otland.net/f163/multi-quest-26985/ I choosed to use it personally for quests, but it could really be used for anything :p
 
Back
Top