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

Tables Problem

Scarlet Ayleid

Advanced OT User
Senator
Joined
Jul 7, 2007
Messages
4,049
Reaction score
238
(This script is for the latest TFS)

Hey All

I'm trying to do a big table, but for some reason, I cant seem to get from it what I want, if anyone could shine some light into the matter I'd appreciate =)


PHP:
SUMMON = {
	["FIRE"]     = {
		NAME = 12503, 
		LEVEL = 12504, 
		EXP = 12505, 
		HP = 12527, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Fire Exori","Fire Beam"}, 
		MOVES2 = {"Fire Ball","Great Fire Beam"}, 
		MOVES3 = {"Great Fire Ball","Hells Core"}
	}
}

PHP:
ACTIVE_SUMMON = 12501
local Type = getPlayerStorageValue(cid,ACTIVE_SUMMON)
print(Type) --It says "FIRE"(without the "") on the console
local Level = getPlayerStorageValue(cid,SUMMON[Type].LEVEL)

So, trying to make it short, I have a table with many numbers that'll redirect to Player Storages to get information, but when it reaches the local Level = ... it gives the following error:
PHP:
data/lib/Summon System.lua:63: attempt to index field '?' (a nil value)
(Line 63 is the local Level = ...)

Can anyone help me with this "small" problem? :p

Thanks
Quetzalma
 
Last edited:
I only posted that cause I thought that was enough, but sure =)
Related Vars and Table:
PHP:
SUMMON = {
["FIRE"]     = {
		NAME = 12503, 
		LEVEL = 12504, 
		EXP = 12505, 
		HP = 12527, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Fire Exori","Fire Beam"}, 
		MOVES2 = {"Fire Ball","Great Fire Beam"}, 
		MOVES3 = {"Great Fire Ball","Hells Core"}},
["ICE"]      = {
		NAME = 12506, 
		LEVEL = 12507, 
		EXP = 12508, 
		HP = 12528, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Ice Exori","Ice Beam"}, 
		MOVES2 = {"Ice Ball","Great Ice Beam"}, 
		MOVES3 = {"Great Ice Ball","Eternal Winter"}},
["EARTH"]    = {
		NAME = 12509, 
		LEVEL = 12510, 
		EXP = 12511, 
		HP = 12529, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Earth Exori","Earth Beam"}, 
		MOVES2 = {"Earth Ball","Great Earth Beam"}, 
		MOVES3 = {"Great Earth Ball","Wrath of Nature"}},
["ENERGY"]	 = {
		NAME = 12512, 
		LEVEL = 12513, 
		EXP = 12514, 
		HP = 12530, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Energy Exori","Energy Beam"}, 
		MOVES2 = {"Energy Ball","Great Energy Beam"}, 
		MOVES3 = {"Great Energy Ball","Rage of the Skies"}},
["HOLY"]     = {
		NAME = 12515, 
		LEVEL = 12516, 
		EXP = 12517, 
		HP = 12531, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Holy Exori","Holy Beam"}, 
		MOVES2 = {"Holy Ball","Great Holy Beam"}, 
		MOVES3 = {"Great Holy Ball","Holy Purification"}},
["DEATH"]    = {
		NAME = 12518, 
		LEVEL = 12519, 
		EXP = 12520, 
		HP = 12532, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Death Exori","Death Beam"}, 
		MOVES2 = {"Death Ball","Great Death Beam"}, 
		MOVES3 = {"Great Death Ball","Cry of the Damned"}},
["PHYSICAL"] = {
		NAME = 12521, 
		LEVEL = 12522, 
		EXP = 12523, 
		HP = 12533, 
		LEVEL2 = 20, 
		LEVEL3 = 50,
		MOVES1 = {"Berserk"}, 
		MOVES2 = {"Groundshaker"}, 
		MOVES3 = {"Fierce Berserk"}}
}

Function:
PHP:
ACTIVE_SUMMON = 12501
function getSummon(cid,SumType)
	local Type = SumType or nil
	local Master = nil
	local Summon = nil
	if isPlayer(cid) then
		Master = cid
		Summon = getPlayerStorageValue(Master,SUMMON_ID)
		if Summon <= 0 then
			Summon = nil
		end
	else
		Summon = cid
		Master = getCreatureMaster(Summon)
	end
	if Type == nil then
		local Type = getPlayerStorageValue(Master,ACTIVE_SUMMON)
	end
	print(Type) --It says "FIRE"(without the "") on the console
	local Level = getPlayerStorageValue(Master,SUMMON[Type].LEVEL)
	local Name = getPlayerStorageValue(Master,SUMMON[Type].NAME)
	local Exp = getPlayerStorageValue(Master,SUMMON[Type].EXP)
	local HP = getPlayerStorageValue(Master,SUMMON[Type].HP)
	local Active = isSummonActive(Master)
	local MasterPos = getCreaturePosition(Master)
	local SummonPos = getCreaturePosition(Summon)
	return {Master = Master, Summon = Summon, Name = Name, Level = Level, Exp = Exp, HP = HP, Type = Type, Active = Active, MasterPos = MasterPos, SummonPos = SummonPos}
end

isSummonActive Function:
PHP:
function isSummonActive(cid)
	if getPlayerStorageValue(cid,IS_SUMMON_ACTIVE) == 1 then
		return TRUE
	end
	return FALSE
end
 
Last edited:
Lua:
ACTIVE_SUMMON = 12501
local Type = getPlayerStorageValue(cid,ACTIVE_SUMMON)
print(Type) --It says "FIRE"(without the "") on the console
local Level = getPlayerStorageValue(cid,SUMMON[Type].LEVEL)

As we see Type is a value - int (hetplayerstoragevalue returns only inf.

So Type is Int (a number)

When u are trying to get something from table:

Lua:
local Level = getPlayerStorageValue(cid,SUMMON[Type].LEVEL)

then it is looking for a Return Value int(Type) not a string(FIRE)...


Or maybe i am wrong and Storage Value Can be a String o_O
 
well, I make a print after I get the value from the storage and it does say Fire, so it seems that it can also return strings..
I also checked the Storage Value manually in the DB and it also said Fire in the value field
 
Lua:
SUMMON = {
[1]     = {
        NAME = 12503, 
        LEVEL = 12504, 
        EXP = 12505, 
        HP = 12527, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Fire Exori","Fire Beam"}, 
        MOVES2 = {"Fire Ball","Great Fire Beam"}, 
        MOVES3 = {"Great Fire Ball","Hells Core"}},
[2]      = {
        NAME = 12506, 
        LEVEL = 12507, 
        EXP = 12508, 
        HP = 12528, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Ice Exori","Ice Beam"}, 
        MOVES2 = {"Ice Ball","Great Ice Beam"}, 
        MOVES3 = {"Great Ice Ball","Eternal Winter"}},
[3]    = {
        NAME = 12509, 
        LEVEL = 12510, 
        EXP = 12511, 
        HP = 12529, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Earth Exori","Earth Beam"}, 
        MOVES2 = {"Earth Ball","Great Earth Beam"}, 
        MOVES3 = {"Great Earth Ball","Wrath of Nature"}},
[4]     = {
        NAME = 12512, 
        LEVEL = 12513, 
        EXP = 12514, 
        HP = 12530, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Energy Exori","Energy Beam"}, 
        MOVES2 = {"Energy Ball","Great Energy Beam"}, 
        MOVES3 = {"Great Energy Ball","Rage of the Skies"}},
[5]     = {
        NAME = 12515, 
        LEVEL = 12516, 
        EXP = 12517, 
        HP = 12531, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Holy Exori","Holy Beam"}, 
        MOVES2 = {"Holy Ball","Great Holy Beam"}, 
        MOVES3 = {"Great Holy Ball","Holy Purification"}},
[6]    = {
        NAME = 12518, 
        LEVEL = 12519, 
        EXP = 12520, 
        HP = 12532, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Death Exori","Death Beam"}, 
        MOVES2 = {"Death Ball","Great Death Beam"}, 
        MOVES3 = {"Great Death Ball","Cry of the Damned"}},
[7] = {
        NAME = 12521, 
        LEVEL = 12522, 
        EXP = 12523, 
        HP = 12533, 
        LEVEL2 = 20, 
        LEVEL3 = 50,
        MOVES1 = {"Berserk"}, 
        MOVES2 = {"Groundshaker"}, 
        MOVES3 = {"Fierce Berserk"}}
}

and :

Lua:
if Type1 == nil then
        local Type1 = getPlayerStorageValue(Master,ACTIVE_SUMMON)
    end
    print(Type1) --It says "FIRE"(without the "") on the console
if Type1 = FIRE then
Type = 1
elseif Type1 = ICE then
Type = 2
elseif Type1 = EARTH then
Type = 3
elseif Type1 = ENERGY then
Type = 4
elseif Type1 = HOLY then
Type = 5
elseif Type1 = DEATH then
Type = 6
elseif Type1 = PHYSICAL then
Type = 7
end
    local Level = getPlayerStorageValue(Master,SUMMON[Type].LEVEL)

or:

Lua:
if Type1 == nil then
        local Type1 = getPlayerStorageValue(Master,ACTIVE_SUMMON)
    end
    print(Type1) --It says "FIRE"(without the "") on the console
if Type1 = "FIRE" then
Type = 1
elseif Type1 = "ICE" then
Type = 2
elseif Type1 = "EARTH" then
Type = 3
elseif Type1 = "ENERGY" then
Type = 4
elseif Type1 = "HOLY" then
Type = 5
elseif Type1 = "DEATH" then
Type = 6
elseif Type1 = "PHYSICAL" then
Type = 7
end
    local Level = getPlayerStorageValue(Master,SUMMON[Type].LEVEL)
 
Back
Top