• 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 OnPrepareDeath Issues

Hugofasima

Website: thenosegang.servegame.com
Joined
Jun 24, 2015
Messages
206
Reaction score
23
Hello everyone!! Need help heere :( Pleeaaase Guys!!

What I'm doing wrong??? My script is stopping at third if when I compare 2 game storages.

Code:
dofile('data/war-field.lua')

function onPrepareDeath(player, lastHitKiller, mostDamageKiller)
     local specs = Game.getSpectators(waitingRoomCenterPos, false, onlyPlayers, 0, waitingRoomRadiusX, 0, waitingRoomRadiusY)
     local ppos = player:getPosition()
    print("onPrepareDeath loaded")  --[[ OK! Load :))))]]
  
    if player:isPlayer() then
    print("isPlayer loaded")   --[[ OK! Load :))))]]
        if isInRange(ppos, warFieldFromPos, warFieldToPos) then
        print("isInRange loaded")   --[[ OK! Load :))))]]
            if (Game.getStorageValue(countBlueDeaths) < fragsToWin and Game.getStorageValue(countRedDeaths) < fragsToWin) then
            print("Compare storages loaded") --[[ DIDN'T LOAD!! :((((( ]]
                if player:getStorageValue(joinedBlueStorage) == 1 then
                    Game.setStorageValue(countBlueDeaths, Game.getStorageValue(countBlueDeaths)+1)
                    if isInRange(ppos, warFieldFromPos, warFieldToPos) then
                        player:teleportTo(redBasePos)
                    return true
                    end
                    addEvent(doCreatureAddHealth, 100, player:getId(), maxhp)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have died during the rush event! Blue Score ['.. countBlueDeaths ..'/'.. fragsToWin ..'] | Red Score ['..countRedDeaths..'/'.. fragsToWin..']')
                else
                    Game.setStorageValue(countRedDeaths, Game.getStorageValue(countRedDeaths)+1)
                    if isInRange(ppos, warFieldFromPos, warFieldToPos) then
                        player:teleportTo(blueBasePos)
                    return true
                    end
                    addEvent(doCreatureAddHealth, 100, player:getId(), maxhp)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have died during the rush event! Red Score ['.. countRedDeaths ..'/'.. fragsToWin ..'] | Blue Score ['..countBlueDeaths..'/'.. fragsToWin..']')
                end
            elseif Game.getStorageValue(countBlueDeaths) >= fragsToWin then
                for i = 1, #specs do
                    if specs[i]:getStorageValue(joinedBlueStorage) == 1 then
                        specs[i]:addItem(2400, 1, true, 1, CONST_SLOT_WHEREEVER)
                    else
                        specs[i]:addItem(2400, 1, true, 1, CONST_SLOT_WHEREEVER)
                    end
                end
                endWarField()
            -- bluewin
            else
                for i = 1, #specs do
                    if specs[i]:getStorageValue(joinedRedStorage) == 1 then
                        specs[i]:addItem(2400, 1, true, 1, CONST_SLOT_WHEREEVER)
                    else
                        specs[i]:addItem(2400, 1, true, 1, CONST_SLOT_WHEREEVER)
                    end
                end
                endWarField()
            -- redwin
            end
      
        end
    end
return true
end

function onLogin(player)
print("register warfieldDeath loaded") --[[ OK! Load :))))]]
    player:registerEvent("WarfieldDeath")
    return true
end

I know I'm doing something really wrong, is my first script!
 
Last edited:
It's comparing numbers 2x in the if statement, so you can check with print what the result is to see which number is not what it's supposed to be.
So like this:
Code:
print(Game.getStorageValue(countBlueDeaths)
print(fragsToWin)
-- etc
 
It's comparing numbers 2x in the if statement, so you can check with print what the result is to see which number is not what it's supposed to be.
So like this:
Code:
print(Game.getStorageValue(countBlueDeaths)
print(fragsToWin)
-- etc

Woooooooooooooooooooooooaahh! I got it! This really helps, thank you Limos! I'll post, when I solve it!
 
@Limos its 100% SOLVED now thanks to you!

The storage key showed as a nil value when I asked to print countBlueDeaths and countRedDeaths storage, like this
Code:
 if (print(Game.getStorageValue(countBlueDeaths)) < fragsToWin and print(Game.getStorageValue(countRedDeaths)) < fragsToWin) then
Then I realized that I had forgotten to declare the storage when the event begins, likethis
Code:
Game.setStorageValue(countBlueDeaths, 1) and Game.setStorageValue(countRedDeaths, 1)

Thanks Limooos!
 
Back
Top