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

TFS 0.X 3 bugs summon rune

kennyubuntu

Member
Joined
May 20, 2016
Messages
150
Reaction score
13
i tried to make a rune to summon a monk
but i got 3 errors:
1- not convicing creature (the monk is attacking the summoner)
2- not removing the rune
3- not removing mana

Code:
local mana = 500

function onCastSpell(cid, var)
    local maxSummons = getConfigValue('maxPlayerSummons')
    if #getCreatureSummons(cid) >= maxSummons then
        return (doPlayerSendCancel(cid, "You cannot summon more creatures.") and doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)) and true
    end
    if (getPlayerMana(cid) < mana) then
        return (doPlayerSendCancel(cid, "You need " .. mana .. " mana points to use this rune.") and doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)) and true
    end
    local createMonster = doCreateMonster("Monk", getThingPos(cid))
    if createMonster then
        doPlayerAddMana(cid, (mana * 1))
        doCreatureSetSkullType(createMonster, SKULL_YELLOW)
        setCreatureMaxHealth(createMonster, (getCreatureHealth(createMonster) * 2))
        doCreatureAddHealth(createMonster, getCreatureHealth(createMonster) * 2)
        doConvinceCreature(cid, createMonster)
        doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
        return true
    end
    doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
    doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
    return false
end
 
Solution
1-
(x) removing mana / checking mana
(x) not summon more then 3
() removing the item

log
Code:
[22:30:20.839] [Error - Spell Interface]
[22:30:20.839] data/spells/scripts/summon/monk rune.lua:onCastSpell
[22:30:20.839] Description:
[22:30:20.839] data/spells/scripts/summon/monk rune.lua:30: attempt to index field '?' (a number value)
[22:30:20.839] stack traceback:
[22:30:20.839]     data/spells/scripts/summon/monk rune.lua:30: in function <data/spells/scripts/summon/monk rune.lua:3>


2-
(x) removing mana / checking mana
(x) not summon more then 3
(x) removing the item
(x) adding yellow skull

no errors on console

but there is a last problem:
none of this messages:
doPlayerSendCancel(cid, "You cannot summon more creatures.")...
1-
(x) removing mana / checking mana
(x) not summon more then 3
() removing the item

log
Code:
[22:30:20.839] [Error - Spell Interface]
[22:30:20.839] data/spells/scripts/summon/monk rune.lua:onCastSpell
[22:30:20.839] Description:
[22:30:20.839] data/spells/scripts/summon/monk rune.lua:30: attempt to index field '?' (a number value)
[22:30:20.839] stack traceback:
[22:30:20.839]     data/spells/scripts/summon/monk rune.lua:30: in function <data/spells/scripts/summon/monk rune.lua:3>


2-
(x) removing mana / checking mana
(x) not summon more then 3
(x) removing the item
(x) adding yellow skull

no errors on console

but there is a last problem:
none of this messages:
doPlayerSendCancel(cid, "You cannot summon more creatures.")
doPlayerSendCancel(cid, "You need " .. mana .. " mana points to use this rune.")
doPlayerSendCancel(cid, "Not enough room to summon creature.")
are showing...
why?
Post automatically merged:





3-
(x) removing mana / checking mana
(x) not summon more then 3
() removing the item
() adding yellow skull

but this is different to 2, is not showing lose man

and is showing this errors on console
Code:
[22:37:45.494] [Error - Spell Interface]
[22:37:45.494] data/spells/scripts/summon/monk rune.lua:onCastSpell
[22:37:45.494] Description:
[22:37:45.494] (luaGetCreatureHealth) Creature not found

[22:37:45.494] [Error - Spell Interface]
[22:37:45.494] data/spells/scripts/summon/monk rune.lua:onCastSpell
[22:37:45.494] Description:
[22:37:45.494] data/spells/scripts/summon/monk rune.lua:23: attempt to perform arithmetic on a boolean value
[22:37:45.494] stack traceback:
[22:37:45.494]     data/spells/scripts/summon/monk rune.lua:23: in function <data/spells/scripts/summon/monk rune.lua:4>
I guess change all the 'return false' for 'return true'

Still don't know what's wrong with your source code though. lol
The regular way should've worked.
Lua:
local mana = 500
local creature = "monk"

function onCastSpell(cid, var)
   
    local max_summons = getConfigValue('maxPlayerSummons')
    local player_summons = getCreatureSummons(cid)
   
    if #player_summons >= max_summons then
        doPlayerSendCancel(cid, "You cannot summon more creatures.")
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return true
    end
   
    if getPlayerMana(cid) < mana then
        doPlayerSendCancel(cid, "You need " .. mana .. " mana points to use this rune.")
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return true
    end
   
    doSummonMonster(cid, creature)
   
    local new_player_summons = getCreatureSummons(cid)
    if #player_summons == #new_player_summons then
        doPlayerSendCancel(cid, "Not enough room to summon creature.")
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return true
    end
       
    doPlayerAddMana(cid, -mana)
    doCreatureSetSkullType(new_player_summons[#new_player_summons], SKULL_YELLOW)
    setCreatureMaxHealth(new_player_summons[#new_player_summons], (getCreatureHealth(new_player_summons[#new_player_summons]) * 2))
    doCreatureAddHealth(new_player_summons[#new_player_summons], getCreatureHealth(new_player_summons[#new_player_summons]) * 2)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_BLUE)
    doPlayerRemoveItem(cid, 2348, 1)
   
    return true
end
 
Solution
Back
Top