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

GarQet

Own3d!
Joined
Feb 10, 2009
Messages
1,381
Solutions
14
Reaction score
81
Hello OTlanders. I got small request. I don't how to create one additional to my script.
I got this:
LUA:
	local a = {0, 10, 55}
	local b = {"GarQet", "Otland", "Script"}
	local l = 0
And now:
LUA:
for v = 1, 3 do
	if getCreatureName(cid) == b[v] then
		l = a[v]
	end
end
doPlayerAddLevel(cid, l)
I want this: If player is named GarQet then script took information from table a assigned to the number of which was the name of the table b.
So, If GarQet (from table B) then 0 (from table A).
If creature is named Script (from table B) then 55 (from table A).

Someone understand my request and can help me in this?
 
I'd say, do it like this (I'd prefer to wipe it even further, but I'll keep it a bit like how you want it to be..):
LUA:
local a = {0, 10, 55}
local b = {"GarQet", "Otland", "Script"}
...
local n = getCreatureName(cid)
for i,v in pairs(b) do
if v==n then
doPlayerAddLevel(cid, a[i])
break
end
end


Your (old..) script got a nice exploit in it as well, since when nothing matches the previous 'l' value will be used.
 
LUA:
local config, player = {["GarQet"] = 0, ["Otland"] = 10, ["Script"] = 55}, getCreatureName(cid)
	for name, level in pairs(config) do
		if (player == name) then
			doPlayerAddLevel(cid, level)
		end
	end
 
Back
Top