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

RevScripts I trying to create a revscript but didnt work, dont happens nothing.

Eduardo170

Well-Known Member
Joined
Jan 7, 2014
Messages
422
Solutions
3
Reaction score
66
Location
Caracas, Venezuela
I took this script from another forum and trying to create a revscript but didnt work, dont happens nothing, no print error in console.
I also want to add a lever to teleport 2 teams, each team of 4 or 5 people.

Code:
local exit = Position(1011, 949, 7)
local storage = 9015

-- Code to be executed when a player with storage have died
local event = CreatureEvent("Pvparena")
function event.onPrepareDeath(player, killer)
    if player:getStorageValue(storage) > 0 and killer:getStorageValue(storage) > 0 then
        player:removeCondition(CONDITION_INFIGHT)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are dead in PVP Arena!")
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setStorageValue(storage, 0)
        player:unregisterEvent("a")
        player:teleportTo(exit)
        killer:getPosition():sendMagicEffect(CONST_ME_GROUNDSHAKER)
        return true
    end
end
event:register()

-- Register above Pvparena creature events to players when they login
local login = CreatureEvent("Pvparena")
function login.onLogin(player)
    if player:getStorageValue(storage) > 0 then
        player:setStorageValue(storage, 0)
    end
    return true
end
login:register()

local logout = CreatureEvent("Pvparena")

function logout.onLogout(player)
    if player:getStorageValue(storage) > 0 then
        player:sendCancelMessage("You can not logout now!")
        return false
    end
    return true
end
logout:register()
 
Last edited:
Things I changed:
  1. Event names should be unique I think
  2. I dunno if it's true anymore, but it used to be if you had a onPrepareDeath that didn't always return true, players couldn't die. Your script as it is above only returns true inside the conditional if block.
  3. Actually register these events to the player in the login
  4. Move login to the bottom so that the registered events are declared and valid first
There is still the issue of player:unregisterEvent("a") cuz, what is that even there for?

So I'm still not sure if this will work or not. That is, does this code even execute?

Also, it looks like you're using that storage to determine when the player is inside your PVP arena. If you're going full revscriptsys, why isn't that code also in this file?

Lua:
local exit = Position(1011, 949, 7)
local storage = 9015

-- Code to be executed when a player with storage have died
local death = CreatureEvent("PVP_Arena_DeathGuard")
function death.onPrepareDeath(creature, killer)
    local player = Player(creature)
    if player:getStorageValue(storage) > 0 and killer:getStorageValue(storage) > 0 then
        player:removeCondition(CONDITION_INFIGHT)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are dead in PVP Arena!")
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setStorageValue(storage, 0)
        player:unregisterEvent("a")
        player:teleportTo(exit)
        killer:getPosition():sendMagicEffect(CONST_ME_GROUNDSHAKER)
        return true
    end
    return true
end
death:register()

local logout = CreatureEvent("PVP_Arena_LogoutGuard")
function logout.onLogout(player)
    if player:getStorageValue(storage) > 0 then
        player:sendCancelMessage("You can not logout now!")
        return false
    end
    return true
end
logout:register()

-- Register above Pvparena creature events to players when they login
local login = CreatureEvent("PVP_Arena_Login")
function login.onLogin(player)
    if player:getStorageValue(storage) > 0 then
        player:setStorageValue(storage, 0)
    end
    player:registerEvent("PVP_Arena_DeathGuard")
    player:registerEvent("PVP_Arena_LogoutGuard")

    return true
end
login:register()
 
Things I changed:
  1. Event names should be unique I think
  2. I dunno if it's true anymore, but it used to be if you had a onPrepareDeath that didn't always return true, players couldn't die. Your script as it is above only returns true inside the conditional if block.
  3. Actually register these events to the player in the login
  4. Move login to the bottom so that the registered events are declared and valid first
There is still the issue of player:unregisterEvent("a") cuz, what is that even there for?

So I'm still not sure if this will work or not. That is, does this code even execute?

Also, it looks like you're using that storage to determine when the player is inside your PVP arena. If you're going full revscriptsys, why isn't that code also in this file?

Lua:
local exit = Position(1011, 949, 7)
local storage = 9015

-- Code to be executed when a player with storage have died
local death = CreatureEvent("PVP_Arena_DeathGuard")
function death.onPrepareDeath(creature, killer)
    local player = Player(creature)
    if player:getStorageValue(storage) > 0 and killer:getStorageValue(storage) > 0 then
        player:removeCondition(CONDITION_INFIGHT)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are dead in PVP Arena!")
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setStorageValue(storage, 0)
        player:unregisterEvent("a")
        player:teleportTo(exit)
        killer:getPosition():sendMagicEffect(CONST_ME_GROUNDSHAKER)
        return true
    end
    return true
end
death:register()

local logout = CreatureEvent("PVP_Arena_LogoutGuard")
function logout.onLogout(player)
    if player:getStorageValue(storage) > 0 then
        player:sendCancelMessage("You can not logout now!")
        return false
    end
    return true
end
logout:register()

-- Register above Pvparena creature events to players when they login
local login = CreatureEvent("PVP_Arena_Login")
function login.onLogin(player)
    if player:getStorageValue(storage) > 0 then
        player:setStorageValue(storage, 0)
    end
    player:registerEvent("PVP_Arena_DeathGuard")
    player:registerEvent("PVP_Arena_LogoutGuard")

    return true
end
login:register()
Code:
local exit = Position(1011, 949, 7)
local storage = 9015

-- Code to be executed when a player with storage have died
local death = CreatureEvent("PVP_Arena_DeathGuard")
function death.onPrepareDeath(creature, killer)
    local player = Player(creature)
    if player:getStorageValue(storage) > 0 and killer:getStorageValue(storage) > 0 then
        player:removeCondition(CONDITION_INFIGHT)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are dead in PVP Arena!")
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setStorageValue(storage, 0)
        player:teleportTo(exit)
        killer:getPosition():sendMagicEffect(CONST_ME_GROUNDSHAKER)
        return true
    end
    return true
end
death:register()

local logout = CreatureEvent("PVP_Arena_LogoutGuard")
function logout.onLogout(player)
    if player:getStorageValue(storage) > 0 then
        player:sendCancelMessage("You can not logout now!")
        return false
    end
    return true
end
logout:register()

-- Register above Pvparena creature events to players when they login
local login = CreatureEvent("PVP_Arena_Login")
function login.onLogin(player)
    if player:getStorageValue(storage) > 0 then
        player:setStorageValue(storage, 0)
    end
    player:registerEvent("PVP_Arena_DeathGuard")
    player:registerEvent("PVP_Arena_LogoutGuard")

    return true
end
login:register()

mmm didn't work, I add to a player the storage 9015, 1. No errors on console. and players dead and loss bless.
 
How are you loading the script?

Where are you setting the players storage?
It's inside data / scripts

I add a storage with this script
example /storage NAME, STORAGE, VALUE
Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local split = param:split(",")
    local target = Player(split[1])

    if target == nil then
        player:sendCancelMessage("A player with that name is not online.")
        return false
    end

    local value = tonumber(split[2])

    if(value == nil or value <= 0)then
        player:sendCancelMessage("You need to put the storage to verify.")
        return false
    end

    local storage = getPlayerStorageValue(target, value)
    local key = tonumber(split[3])
    if key == nil then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Storage Key: " .. value .. " Storage Value: " .. storage.." Player: "..target:getName())
    else
        setPlayerStorageValue(target.uid, value, key)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have set Storage Key: " .. value .. " Storage Value: " .. key .. " for player "..target:getName()..".")
    end
    return false
end
 
You're missing the type method.
Lua:
death:type('death')
logout:type('logout')
login:type('login')
After you initialize the variables.
 
You're missing the type method.

I should have noticed that. I was looking at this post as a reference. Specifically the player login one. "Here are some working examples:" 🤭
Post automatically merged:

I add a storage with a god command

Ah! I'd figure a PVP arena should probably be using tile+actionid movement script, so when player steps in to be teleported its automatic. And any exit teleporter tile should have a matching action to also remove the storage.

So here is your script with the changes Infernum stated are missing.

Lua:
local exit = Position(1011, 949, 7)
local storage = 9015

-- Code to be executed when a player with storage have died
local death = CreatureEvent("PVP_Arena_DeathGuard")
function death.onPrepareDeath(creature, killer)
    local player = Player(creature)
    if player:getStorageValue(storage) > 0 and killer:getStorageValue(storage) > 0 then
        player:removeCondition(CONDITION_INFIGHT)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are dead in PVP Arena!")
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:setStorageValue(storage, 0)
        player:teleportTo(exit)
        killer:getPosition():sendMagicEffect(CONST_ME_GROUNDSHAKER)
        return true
    end
    return true
end
death:type('death')
death:register()

local logout = CreatureEvent("PVP_Arena_LogoutGuard")
function logout.onLogout(player)
    if player:getStorageValue(storage) > 0 then
        player:sendCancelMessage("You can not logout now!")
        return false
    end
    return true
end
logout:type('logout')
logout:register()

-- Register above Pvparena creature events to players when they login
local login = CreatureEvent("PVP_Arena_Login")
function login.onLogin(player)
    if player:getStorageValue(storage) > 0 then
        player:setStorageValue(storage, 0)
    end
    player:registerEvent("PVP_Arena_DeathGuard")
    player:registerEvent("PVP_Arena_LogoutGuard")

    return true
end
login:type('login')
login:register()
 
Last edited:
Back
Top