• 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 getMaxStorageValue, this not work like i expect...

Exedion

Active Member
Joined
Jun 11, 2007
Messages
629
Reaction score
30
Well a friend made this function for me, but not work like i expect, because this return the "max value" of a serie of storages, and i need the "max KEY" of a serie of storages, example:

i have storage's 11000 to 11008, with value 0, i need return the max value of the serie 11000 to 11010 (11008)

this can be do?

see the function
LUA:
function getMaxStorageValue(cid, storage_start, storage_end)
	local max = -1
	for i = storage_start, storage_end do
		local tmp = getCreatureStorage(cid, i)
		if(tmp > max) then
			max = tmp
		end
		return max
	end
end
 
Last edited:
Ok i made a function but i don't know how to check the "serie" of storage key

LUA:
function getCreatureMaxStorageKey(cid, from_key, to_key)
         assert(tonumber(cid),'Parameter must be a number') 
         if isPlayer(cid) == FALSE then error('Player don\'t find') end; 
         ae =  db.getResult("SELECT `key`, FROM `player_storage` WHERE `player_id` = "..getPlayerGUID(cid).." ORDER BY `value` DESC;")
         if ae:getID() == -1 then
            return 0
         end
		local retee = ae:getDataInt("key") or 0
		ae:free()
         return retee
end
 
this should be good
LUA:
function getMaxStorageValue(cid, b, e)
	local max = -1
	for i = b, e do
		local tmp = getCreatureStorage(cid, i)
		if tmp > max then
			max = tmp
		end
	end
	return max
end
 
this should be good
LUA:
function getMaxStorageValue(cid, b, e)
local max = -1
         for i = b, e do
               local tmp = getCreatureStorage(cid, i)
               if tmp > max then
                      max = tmp
               end
         end
         return max	
end

Humm you actually did nothing!!

Well a friend made this function for me, but not work like i expect, because this return the "max value" of a serie of storages, and i need the "max KEY" of a serie of storages, example:
LUA:
function getMaxStorageValue(cid, start, ends)
	local max_key = start    -- if all have the same value then it would return the first key passed in function
	local min_value = -1 -- minimum checking value is updated every time a bigger value is found
	
	for i = start, ends do--making a loop from the starting key to the ending key
		local tmp = getCreatureStorage(cid, i)  -- this returns the value of the key of the current loop
		if tmp > min_value then -- if value of current key was bigger then our minimum check value then the check value is updated so as the max_key
			min_value = tmp		-- updating the largest value
			max_key = i			-- updating the largest key
		end
	end
	
	return max_key		-- returning the largest key
end
 
Last edited:
Back
Top