• 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 New "Summon Creature" spell - TFS 0.4.0

Tadelho

New Member
Joined
Aug 12, 2007
Messages
38
Solutions
1
Reaction score
2
I'm trying to use the following code as a script.lua for a talkaction to simulate a new "summon creature" spell, but trying to run my server this error message appears in console:

Description:
[9:26:49.447] data/talkactions/scripts/callofnature1.lua:33: bad argument #1 to 'lower' (string expected, got nil)


Anyone knows how to solve this problem or even know a proper system to create a new summon creature spell? Thanks!

Code:

Lua:
-- General Configuration
       local lvlmin = 1
       local exhaustion = 3000
       local needlearn = 1
       local learnstorage = 77890
       local vocations = {2, 3}
       local maxsummons = getConfigValue("maxPlayerSummons")
       summonlist =    {
               [1] = {'rat', 4},
               [2] = {'bat', 4},
               [3] = {'bug', 4},
               [4] = {'snake', 4}
               }

       -- Player Info
       local lvl = getPlayerLevel(cid)
       local vocp = getPlayerVocation(cid)
       local mana = getCreatureMana(cid)
       local pos = getCreaturePosition(cid)

       -- Statements
       local learned = 0
       local voccan = 0
       local cansummon = 0
       local manacost = 0
       local exhaustorage = 77889

       -- Loop Control
       local vocs = #vocations
       local slistn = #summonlist

       -- Conversions
       param = string.lower(param)
       param = string.gsub(param, '\"', '')
       exhaustion = exhaustion/1000

       -- Initial Verification
       if needlearn == 0 then learned = 1 end
       if needlearn == 1 and getPlayerStorageValue(cid, learnstorage) > 0 then learned = 1 end

       while vocs > 0 do
           if vocp == vocations[vocs] then voccan = 1 end
           vocs = vocs - 1
       end

       while slistn > 0 do
           if param == summonlist[slistn][1] then
               cansummon = 1
               manacost = summonlist[slistn][2]
           end
           slistn = slistn - 1
       end

       -- Summon Monster
       if getTilePzInfo(pos) then
           doPlayerSendCancel(cid, 'This action is not permitted in a protection zone.')
       else

           if lvl < lvlmin then
               doSendMagicEffect(pos, CONST_ME_POFF)
               doPlayerSendCancel(cid, 'You do not have enough level.')
           else

               if learned == 1 then
                   if voccan == 1 then
                       if getPlayerStorageValue(cid, exhaustorage) >= os.time() then
                           doSendMagicEffect(pos, CONST_ME_POFF)
                           doPlayerSendCancel(cid, 'You are exhausted.')
                       else
                           if cansummon == 1 then
                               if mana >= manacost then
                                   if #getCreatureSummons(cid) < maxsummons then
                                       doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                                       doCreatureAddMana(cid, 0-manacost, false)
                                       local summon = doCreateMonster(param, pos)
                                       doConvinceCreature(cid, summon)
                                       doSendMagicEffect(getCreaturePosition(summon), CONST_ME_TELEPORT)
                                       setPlayerStorageValue(cid, exhaustorage, os.time()+exhaustion)
                                   else
                                       doSendMagicEffect(pos, CONST_ME_POFF)
                                       doPlayerSendCancel(cid, 'You cannot summon more creatures.')

                                   end
                               else
                                   doSendMagicEffect(pos, CONST_ME_POFF)
                                   doPlayerSendCancel(cid, 'You do not have enough mana.')
                               end
                           else
                               doSendMagicEffect(pos, CONST_ME_POFF)
                               doPlayerSendCancel(cid, 'Sorry, not possible.')
                           end
                       end
                   else
                       doSendMagicEffect(pos, CONST_ME_POFF)
                       doPlayerSendCancel(cid, 'Your vocation cannot use this spell.')
                   end
               else
                   doSendMagicEffect(pos, CONST_ME_POFF)
                   doPlayerSendCancel(cid, 'You need to learn this spell first.')
               end

           end

       end
     
   return
 
Last edited:
I'm trying to use the following code as a script.lua for a talkaction to simulate a new "summon creature" spell, but trying to run my server this error message appears in console:

Description:
[9:26:49.447] data/talkactions/scripts/callofnature1.lua:33: bad argument #1 to 'lower' (string expected, got nil)


Anyone knows how to solve this problem or even know a proper system to create a new summon creature spell? Thanks!

Code:

HTML:
-- General Configuration
       local lvlmin = 1
       local exhaustion = 3000
       local needlearn = 1
       local learnstorage = 77890
       local vocations = {2, 3}
       local maxsummons = getConfigValue("maxPlayerSummons")
       summonlist =    {
               [1] = {'rat', 4},
               [2] = {'bat', 4},
               [3] = {'bug', 4},
               [4] = {'snake', 4}
               }

       -- Player Info
       local lvl = getPlayerLevel(cid)
       local vocp = getPlayerVocation(cid)
       local mana = getCreatureMana(cid)
       local pos = getCreaturePosition(cid)

       -- Statements
       local learned = 0
       local voccan = 0
       local cansummon = 0
       local manacost = 0
       local exhaustorage = 77889

       -- Loop Control
       local vocs = #vocations
       local slistn = #summonlist

       -- Conversions
       param = string.lower(param)
       param = string.gsub(param, '\"', '')
       exhaustion = exhaustion/1000

       -- Initial Verification
       if needlearn == 0 then learned = 1 end
       if needlearn == 1 and getPlayerStorageValue(cid, learnstorage) > 0 then learned = 1 end

       while vocs > 0 do
           if vocp == vocations[vocs] then voccan = 1 end
           vocs = vocs - 1
       end

       while slistn > 0 do
           if param == summonlist[slistn][1] then
               cansummon = 1
               manacost = summonlist[slistn][2]
           end
           slistn = slistn - 1
       end

       -- Summon Monster
       if getTilePzInfo(pos) then
           doPlayerSendCancel(cid, 'This action is not permitted in a protection zone.')
       else

           if lvl < lvlmin then
               doSendMagicEffect(pos, CONST_ME_POFF)
               doPlayerSendCancel(cid, 'You do not have enough level.')
           else

               if learned == 1 then
                   if voccan == 1 then
                       if getPlayerStorageValue(cid, exhaustorage) >= os.time() then
                           doSendMagicEffect(pos, CONST_ME_POFF)
                           doPlayerSendCancel(cid, 'You are exhausted.')
                       else
                           if cansummon == 1 then
                               if mana >= manacost then
                                   if #getCreatureSummons(cid) < maxsummons then
                                       doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
                                       doCreatureAddMana(cid, 0-manacost, false)
                                       local summon = doCreateMonster(param, pos)
                                       doConvinceCreature(cid, summon)
                                       doSendMagicEffect(getCreaturePosition(summon), CONST_ME_TELEPORT)
                                       setPlayerStorageValue(cid, exhaustorage, os.time()+exhaustion)
                                   else
                                       doSendMagicEffect(pos, CONST_ME_POFF)
                                       doPlayerSendCancel(cid, 'You cannot summon more creatures.')

                                   end
                               else
                                   doSendMagicEffect(pos, CONST_ME_POFF)
                                   doPlayerSendCancel(cid, 'You do not have enough mana.')
                               end
                           else
                               doSendMagicEffect(pos, CONST_ME_POFF)
                               doPlayerSendCancel(cid, 'Sorry, not possible.')
                           end
                       end
                   else
                       doSendMagicEffect(pos, CONST_ME_POFF)
                       doPlayerSendCancel(cid, 'Your vocation cannot use this spell.')
                   end
               else
                   doSendMagicEffect(pos, CONST_ME_POFF)
                   doPlayerSendCancel(cid, 'You need to learn this spell first.')
               end

           end

       end
    
   return
im guessing thats Lua not HTML5
you're not posting the whole script, neither have you told me what you have done ingame for this exception to be thrown
 
im guessing thats Lua not HTML5
you're not posting the whole script, neither have you told me what you have done ingame for this exception to be thrown

Nothing done ingame, this message comes loading server's .exe, actually (the server runs properly, but, of course, the action isn't working).
Well, this is what I got for "callofnature1.lua", wasn't it supposed to be the whole script?

The only thing I can add is its register in talkactions, I guess:

XML:
<talkaction words="call of nature" filter="word-spaced" event="script" value="callofnature1.lua"/>

Fixed the xml to lua, thanks.
 

Similar threads

Back
Top