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

{Solved} Retrieving Values

Cadyan

Well-Known Member
Joined
Mar 30, 2008
Messages
845
Reaction score
63
What is wrong with this script? Mystic Spirit 0.2.15
Can anyone make it better?


Code:
local spells = {
    [1] = {name = Fire, lvl = 8, price = 100},
    [2] = {name = Ice, lvl = 8, price = 100}}
    for i = 1,2 do
    if msgcontains(msg, 'spells[i].name') then
        talkState[talkUser] = spells[i].name
        selfSay('Do you want to learn " .. spells[i].name .. "? This ability will cost " .. spells[i].price .. ", and require level " .. spells[i].lvl .. ".', cid)
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == spells[i].name then
        if getPlayerLevel(cid) >= spells[i].lvl then
            selfSay('You have learned " .. spells[i].name .. ".', cid)
            playerLearnInstantSpell(cid, spells[i].name)
        else
            selfSay('You need level " .. spells[i].lvl .. " to learn this spell.', cid)
        end
    end
 
try this:
Code:
local spells =
{
   ["Fire"] = {lvl = 8, price = 100},
   ["Ice"] = {lvl = 8, price = 100}
}

if spells[msg] then
   local spell = msg
   talkState[talkUser] = 1
   selfSay("Do you want to learn " .. msg .. "? This ability will cost " .. spells[msg].price .. ", and require level " .. spells[msg].lvl .. ".", cid)
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
   if getPlayerLevel(cid) >= spells[spell].lvl then
     if doPlayerRemoveMoney(cid, spells[spell].price) then
       selfSay("You have learned " .. spell .. ".", cid)
       playerLearnInstantSpell(cid, spell)
     else
       selfSay("You don't have the required money to learn " .. spell .. ".", cid)
     end
   else
     selfSay("You need level " .. spells[spell].lvl .. " to learn this spell.", cid)
   end
   talkState[talkUser] = 0
end
 
Back
Top