• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Table index ?

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
650
Solutions
14
Reaction score
88
Hello, I can't imagine how it is made.

I have that table:
LUA:
 local spells = {
   
    ["light healing"] = {vocation = {1, 2, 5, 6}, price = 170, level = 9, premium = false},
    ["find person"] = {vocation = {1, 2, 5, 6}, price = 80, level = 8, premium = false},

And can someone tell me how to get "price"?

I try ....
LUA:
if getPlayerMoney(cid) >= spells.price then
But it doesn't work.

Don't know how to get the name of the spell( light healing) and make it like spells[getSpellName].price

DUNNO HELP
 
Solution
Code:
for k,v in pairs(spells) do
   if msgcontains(msg:lower(), k) then
         print(v.price)
   end
end
Or without loop:

Code:
local spell = spells[msg]
if spell then
     print(spell.price)
end
Code:
for k,v in pairs(spells) do
   if msgcontains(msg:lower(), k) then
         print(v.price)
   end
end
Or without loop:

Code:
local spell = spells[msg]
if spell then
     print(spell.price)
end
 
Last edited:
Solution
Back
Top