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

Solved how to..? [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello everyone!

Ive been trying a lot of things for hours, and nothing seems to work, either is too easy and i dont see it or cannot be done.

This is a part from a waaaay bigger script, but im giving your the problem part so, lets see if you can help me guys!

Code:
function spawnMonsters(value)
    local random = math.random
    local addHealth = doCreatureAddHealth
    local maxHp = getCreatureMaxHealth
    local summon = doSummonCreature
    local i = monster.quantity
  
    while i > 0 do
 
        summoned = summon(monster.name, {x = random(spawn1.minX, spawn1.maxX), y = random(spawn1.minY, spawn1.maxY), z = spawn1.z})
        if summoned ~= false then
            Creature(summoned):setMaxHealth(maxHp(summoned) + (100 * value))
            addHealth(summoned, maxHp(summoned) + (100 * value))
            rift.creatures[#rift.creatures + 1] = summoned
            i = i - 1
        end    
    end
    return true
end

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId == 1610 and buttonId == 100 then
        if spawnMonsters(choiceId) then
            setGlobalStorageValue(rift.storages.global, 1)
            setGlobalStorageValue(rift.storages.globalCreatures, monster.kills)
            player:setStorageValue(rift.storages.player, choiceId)
            player:setStorageValue(rift.storages.playerTime, os.time())
            player:sendTextMessage(MESSAGE_STATUS_SMALL, msg)
            player:registerEvent("Rifts")
            player:unregisterEvent("modalDeath")
            player:unregisterEvent("DeathMW")
            player:registerEvent("rdeath")
            rift.timelimit = addEvent(timeLimit, 15 * 60 * 1000, player.uid)
            doTeleportThing(player.uid, tpPos1)
            doSendMagicEffect(tpPos1, CONST_ME_MAGIC_BLUE)
        end
    end
    return true
end

So everytime i try to add for example player:getStorageValue(storage), like this:

Code:
function spawnMonsters(value)
    local random = math.random
    local addHealth = doCreatureAddHealth
    local maxHp = getCreatureMaxHealth
    local summon = doSummonCreature
    local i = monster.quantity
 
    while i > 0 do

 if player:getStorageValue(storage) == 1 then
        summoned = summon(monster.name, {x = random(spawn1.minX, spawn1.maxX), y = random(spawn1.minY, spawn1.maxY), z = spawn1.z})
end

        if summoned ~= false then
            Creature(summoned):setMaxHealth(maxHp(summoned) + (100 * value))
            addHealth(summoned, maxHp(summoned) + (100 * value))
            rift.creatures[#rift.creatures + 1] = summoned
            i = i - 1
        end   
    end
    return true
end

I've always get this kind of error.

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/RiftsModal.lua:onModalWindow
data/creaturescripts/scripts/custom/RiftsModal.lua:15: attempt to index local 'player' (a number value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/RiftsModal.lua:15: in function 'spawnMonsters'
        data/creaturescripts/scripts/custom/RiftsModal.lua:58: in function <data/creaturescripts/scripts/custom/RiftsModal.lua:56>

So, is it possible to check player data on that function?

Thank you everyone for your time.
 
Solution
I didn't quite understand your problem, but maybe if you pass the player or the player id as param you won't have that problem.

LUA:
spawnMonsters(choiceId, player)
function spawnMonsters(value, player) ... end
I didn't quite understand your problem, but maybe if you pass the player or the player id as param you won't have that problem.

LUA:
spawnMonsters(choiceId, player)
function spawnMonsters(value, player) ... end
 
Solution
Back
Top