• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

AAC Create arena_kills column for PVP arena system

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi there! I requested an amazing system to @Itutorial and published it here

The user @ramonxxd came with a great idea, store the kills inside this arena in player's column. What I would like to request now is to make this possible, the whole system is described on the link above and here Gigastar PVP Arena · ralke23/[email protected] (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commit/db202473acf544dac08a4c86446fc228a915e796). I know this is much harder since the request calls database, but if someone handles queries on lua would be great to have this! I'll do every needed testing to achieve this.

Thanks in advance!
Regards :)
 
Solution
Lua:
function Player.getArenaDeaths(self)
    local query = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(query, 'arenaDeaths') or 0
    result.free(query)
    return deaths
end

function Player.getArenaKills(self)
    local query = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local kills = result.getDataInt(query, 'arenaKills') or 0
    result.free(query)
    return kills
end

Paste on your player lib and use on any script or in same script to debug the info.

Lua:
player:getArenaKills()
player:getArenaDeaths()

I edited the code above onLook test it

Lua:
local look = EventCallback
look.onLook = function(self, thing...

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,637
Solutions
7
Reaction score
442
Location
Canada
This may work; however untested.. just trying to expand my skills by helping out so don't judge xD

SQL:
Code:
ALTER TABLE  `players` ADD  `arena_frags` INT( 11 ) NOT NULL DEFAULT  '0'

-- Add to Line 9 of creaturescripts/playerdeath.lua above local byPlayer = 0
Code:
    if(player:isPlayer() and player:isPvPArenaPlayer() == true) then
        db.query("UPDATE `players` SET `arena_frags` = `arena_frags` + 1 WHERE id = " .. player:getGuid() .. ";")
        return true
    end

Edit: After thinking about this for a second; this would actually add a +1 to the person who is dieing I believe.
However I see you are using the KDR revscript. Try replacing function kill.onKill with this below.

Code:
function kill.onKill(player)
    if player:isPlayer() then
    --if not player:isPlayer() then
        return true
    end
    --Store Kill Point
    db.query("UPDATE `players` SET `frags` = `frags` + 1 WHERE id = " .. player:getGuid() .. ";") 
    player:say('+1 Kill Point!', TALKTYPE_ORANGE_1) 
    -- Arena Players Get Point
    if player:isPvPArenaPlayer() == true then
        db.query("UPDATE `players` SET `arena_frags` = `arena_frags` + 1 WHERE id = " .. player:getGuid() .. ";") 
        player:say('+1 Arena Point!', TALKTYPE_ORANGE_1) 
    end
    return true
 end

Would still require the SQL query to work of course ;D <3
 
Last edited:

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,201
Solutions
12
Reaction score
154
Location
Venezuela
Using onKill verify is both players are arena players.

Lua:
local arenaSystemKill = CreatureEvent("arenaSystemKill")

function arenaSystemKill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
        db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
        db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    end
    return true
end
arenaSystemKill:type("kill")
arenaSystemKill:register()
 

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,637
Solutions
7
Reaction score
442
Location
Canada
Using onKill verify is both players are arena players.

Lua:
local arenaSystemKill = CreatureEvent("arenaSystemKill")

function arenaSystemKill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
        db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
        db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    end
    return true
end
arenaSystemKill:type("kill")
arenaSystemKill:register()
I really need to learn revscript.. @Sarah Wesker - could you send me those templates on Discord when you have the chance? Hux here btw <3
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Using onKill verify is both players are arena players.

Lua:
local arenaSystemKill = CreatureEvent("arenaSystemKill")

function arenaSystemKill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
        db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
        db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    end
    return true
end
arenaSystemKill:type("kill")
arenaSystemKill:register()

Looks good! For what I see. A little last thing, for db query I should do
SQL:
ALTER TABLE  `players` ADD  `arenaKills` INT( 11 ) NOT NULL DEFAULT  '0'
ALTER TABLE  `players` ADD  `arenaDeaths` INT( 11 ) NOT NULL DEFAULT  '0'
Right? Not sure if INT(11) is the correct value to insert those tables and if they're typed good, just wanted to get sure.

Thanks a lot!! Regards :)
 

ramonxxd

New Member
Joined
Jul 8, 2022
Messages
6
Reaction score
4
GitHub
vesgoboy
amazing, i will test this <3
Post automatically merged:

Using onKill verify is both players are arena players.

Lua:
local arenaSystemKill = CreatureEvent("arenaSystemKill")

function arenaSystemKill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
        db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
        db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    end
    return true
end
arenaSystemKill:type("kill")
arenaSystemKill:register()


where i put this code?
i try to find this function kill.onKill but with not sucess
i am using 1.3 nekiro
 
Last edited:

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,201
Solutions
12
Reaction score
154
Location
Venezuela
amazing, i will test this <3
Post automatically merged:




where i put this code?
i try to find this function kill.onKill but with not sucess
i am using 1.3 nekiro
Create new lua script inside data/scripts/
Post automatically merged:

Looks good! For what I see. A little last thing, for db query I should do
SQL:
ALTER TABLE  `players` ADD  `arenaKills` INT( 11 ) NOT NULL DEFAULT  '0'
ALTER TABLE  `players` ADD  `arenaDeaths` INT( 11 ) NOT NULL DEFAULT  '0'
Right? Not sure if INT(11) is the correct value to insert those tables and if they're typed good, just wanted to get sure.

Thanks a lot!! Regards :)
Yes int(11) is enough to store
 

ramonxxd

New Member
Joined
Jul 8, 2022
Messages
6
Reaction score
4
GitHub
vesgoboy
Create new lua script inside data/scripts/
Post automatically merged:


Yes int(11) is enough to store
I put it as instructed but it had no effect on the database, there was also no error in the log, I use the TFS 1.3 Nekiro version, could this be the problem?

thanks for help
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
@Acubens Seems that works, but I have a little trouble. Can't test properly on database if the arenaKills or arenaDeaths has changed because the access to data is too slow. Is there any talkaction, onLook, or .php page code that I could use to start checking if the value has changed?

Here's a gist of a KDA script that @Extrodus mentioned before

Can be used as reference, just in case.
Thanks a lot again! :D

Btw
I attempted to merge it with that gist, but nothing changed onLook after killing a player inside the arena
Lua:
function Player.getTotalSavedKills(self)
    local Info = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local frags = result.getDataInt(Info, 'arenaKills')
    result.free(Info)
    return frags
end

function Player.getTotalSavedDeaths(self)
    local Info = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(Info, 'arenaDeaths')
    result.free(Info)
    return deaths
end

local login = CreatureEvent("KDR_REGISTER_EVENT")

function login.onLogin(player)
    player:registerEvent("KDR_KILL_EVENT")
    return true
end

login:register()

local kill = CreatureEvent("KDR_KILL_EVENT")

function kill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
    db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
    db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    player:say('+1 Kill Point!', TALKTYPE_ORANGE_1)
    target:say('+1 Death Point!', TALKTYPE_ORANGE_1)
    target:unregisterEvent("KDR_REGISTER_EVENT")
    target:unregisterEvent("KDR_KILL_EVENT")
end
    return true
end

kill:type("kill")
kill:register()

local look = EventCallback

look.onLook = function(self, player, position, distance, description)
    if not player:isPlayer() then
        return description
    end
    local kills = player:getTotalSavedKills()
    local deaths = player:getTotalSavedDeaths()
    local kdr

    if deaths == 0 then
        kdr = kills
        description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, kills, deaths, kdr)
        return description
    end

    kdr = kills/deaths
    description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, kills, deaths, kdr)
    return description
end

look:register(5)
 

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,637
Solutions
7
Reaction score
442
Location
Canada
@Acubens Seems that works, but I have a little trouble. Can't test properly on database if the arenaKills or arenaDeaths has changed because the access to data is too slow. Is there any talkaction, onLook, or .php page code that I could use to start checking if the value has changed?

Here's a gist of a KDA script that @Extrodus mentioned before

Can be used as reference, just in case.
Thanks a lot again! :D

Btw
I attempted to merge it with that gist, but nothing changed onLook after killing a player inside the arena
Lua:
function Player.getTotalSavedKills(self)
    local Info = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local frags = result.getDataInt(Info, 'arenaKills')
    result.free(Info)
    return frags
end

function Player.getTotalSavedDeaths(self)
    local Info = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(Info, 'arenaDeaths')
    result.free(Info)
    return deaths
end

local login = CreatureEvent("KDR_REGISTER_EVENT")

function login.onLogin(player)
    player:registerEvent("KDR_KILL_EVENT")
    return true
end

login:register()

local kill = CreatureEvent("KDR_KILL_EVENT")

function kill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
    db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
    db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    player:say('+1 Kill Point!', TALKTYPE_ORANGE_1)
    target:say('+1 Death Point!', TALKTYPE_ORANGE_1)
    target:unregisterEvent("KDR_REGISTER_EVENT")
    target:unregisterEvent("KDR_KILL_EVENT")
end
    return true
end

kill:type("kill")
kill:register()

local look = EventCallback

look.onLook = function(self, player, position, distance, description)
    if not player:isPlayer() then
        return description
    end
    local kills = player:getTotalSavedKills()
    local deaths = player:getTotalSavedDeaths()
    local kdr

    if deaths == 0 then
        kdr = kills
        description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, kills, deaths, kdr)
        return description
    end

    kdr = kills/deaths
    description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, kills, deaths, kdr)
    return description
end

look:register(5)
Replace all KDR with ADR - its registering under the same names as KDR right now.
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Replace all KDR with ADR - its registering under the same names as KDR right now.

Thanks a lot for responding! I applied the changes but it didn't work unfortunatelly. I think this is because the arena itself is handled by a creatureEvent.

Lua:
-- Prepare death. Handles players dying in arena. --
local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
function creatureeventPvPArena.onPrepareDeath(creature, killer)
    if not creature:isPlayer() then return true end
    if not creature:isPvPArenaPlayer() then return true end
    local town = config[creature:getTown():getId()]
    if not town then return true end
 
    creature:teleportTo(town.exitPos)
    creature:addHealth(creature:getMaxHealth())
    creature:addMana(creature:getMaxMana())
    print("PVP")
    creature:setPvPArenaPlayer(false)
    return false
end
creatureeventPvPArena:register()

Considering the creatureevent, increasing player's death score would be triggered by: if creature:setPvPArenaPlayer(false)?

Could be a chance to use db.query exactly where print("PVP") is? Not sure if is the best method but I think that could work.
For the moment I don't imagine more ideas of how to make the kill score +1, I but imagine another way for death score by doing:

Lua:
local victim = creature:getPlayer()
 if victim:isPvPArenaPlayer(false) then
 db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")

Any attempt to improve the script is very appreciated, thanks a lot!
Regards :)

PS. Current script
Lua:
function Player.getTotalSavedKills(self)
    local Info = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local frags = result.getDataInt(Info, 'arenaKills')
    result.free(Info)
    return frags
end

function Player.getTotalSavedDeaths(self)
    local Info = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(Info, 'arenaDeaths')
    result.free(Info)
    return deaths
end

local login = CreatureEvent("ADR_REGISTER_EVENT")

function login.onLogin(player)
    player:registerEvent("ADR_KILL_EVENT")
    return true
end

login:register()

local kill = CreatureEvent("ADR_KILL_EVENT")

function kill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
    db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
    db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    player:say('+1 Kill Point!', TALKTYPE_ORANGE_1)
    target:say('+1 Death Point!', TALKTYPE_ORANGE_1)
    target:unregisterEvent("ADR_REGISTER_EVENT")
    target:unregisterEvent("ADR_KILL_EVENT")
end
    return true
end

kill:type("kill")
kill:register()

local look = EventCallback

look.onLook = function(self, player, position, distance, description)
    if not player:isPlayer() then
        return description
    end
    local kills = player:getTotalSavedKills()
    local deaths = player:getTotalSavedDeaths()
    local adr

    if deaths == 0 then
        adr = kills
        description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, adr)
        return description
    end

    adr = kills/deaths
    description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, ADR)
    return description
end

look:register(5)
[/spoiler]
 
Last edited:

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,637
Solutions
7
Reaction score
442
Location
Canada
Thanks a lot for responding! I applied the changes but it didn't work unfortunatelly. I think this is because the arena itself is handled by a creatureEvent.

Lua:
-- Prepare death. Handles players dying in arena. --
local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
function creatureeventPvPArena.onPrepareDeath(creature, killer)
    if not creature:isPlayer() then return true end
    if not creature:isPvPArenaPlayer() then return true end
    local town = config[creature:getTown():getId()]
    if not town then return true end
 
    creature:teleportTo(town.exitPos)
    creature:addHealth(creature:getMaxHealth())
    creature:addMana(creature:getMaxMana())
    print("PVP")
    creature:setPvPArenaPlayer(false)
    return false
end
creatureeventPvPArena:register()

Considering the creatureevent, increasing player's death score would be triggered by: if creature:setPvPArenaPlayer(false)?

Could be a chance to use db.query exactly where print("PVP") is? Not sure if is the best method but I think that could work.
For the moment I don't imagine more ideas of how to make the kill score +1, I but imagine another way for death score by doing:

Lua:
local victim = creature:getPlayer()
 if victim:isPvPArenaPlayer(false) then
 db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")

Any attempt to improve the script is very appreciated, thanks a lot!
Regards :)

PS. Current script
Lua:
function Player.getTotalSavedKills(self)
    local Info = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local frags = result.getDataInt(Info, 'arenaKills')
    result.free(Info)
    return frags
end

function Player.getTotalSavedDeaths(self)
    local Info = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(Info, 'arenaDeaths')
    result.free(Info)
    return deaths
end

local login = CreatureEvent("ADR_REGISTER_EVENT")

function login.onLogin(player)
    player:registerEvent("ADR_KILL_EVENT")
    return true
end

login:register()

local kill = CreatureEvent("ADR_KILL_EVENT")

function kill.onKill(creature, target)
    local killer = creature:getPlayer()
    local victim = target:getPlayer()

    if not killer or not victim then
        return true
    end

    if killer:isPvPArenaPlayer() and victim:isPvPArenaPlayer() then
    db.query("UPDATE `players` SET `arenaKills` = arenaKills + 1 WHERE `id` = '" .. killer:getGuid() .. "';")
    db.query("UPDATE `players` SET `arenaDeaths` = arenaDeaths + 1 WHERE `id` = '" .. victim:getGuid() .. "';")
    player:say('+1 Kill Point!', TALKTYPE_ORANGE_1)
    target:say('+1 Death Point!', TALKTYPE_ORANGE_1)
    target:unregisterEvent("ADR_REGISTER_EVENT")
    target:unregisterEvent("ADR_KILL_EVENT")
end
    return true
end

kill:type("kill")
kill:register()

local look = EventCallback

look.onLook = function(self, player, position, distance, description)
    if not player:isPlayer() then
        return description
    end
    local kills = player:getTotalSavedKills()
    local deaths = player:getTotalSavedDeaths()
    local adr

    if deaths == 0 then
        adr = kills
        description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, adr)
        return description
    end

    adr = kills/deaths
    description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, ADR)
    return description
end

look:register(5)
[/spoiler]
Did you change look:register(5) to a different number so it registers as a new event. KDR uses register 5 as well which may be causing the issue of the new script not registering 🧐
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Did you change look:register(5) to a different number so it registers as a new event. KDR uses register 5 as well which may be causing the issue of the new script not registering 🧐

Yes tested it, also KDR script is not enabled on my server, i'm only trying this one ^^
Regards!
 

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,637
Solutions
7
Reaction score
442
Location
Canada
Yes tested it, also KDR script is not enabled on my server, i'm only trying this one ^^
Regards!
Ah okay, when I wake up later today I will check into modifying the creaturescript you shared because can easily edit that to work for counting frags. Then move to onLook if you want this as well.
 

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,201
Solutions
12
Reaction score
154
Location
Venezuela
Lua:
function Player.getArenaDeaths(self)
    local query = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(query, 'arenaDeaths') or 0
    result.free(query)
    return deaths
end

function Player.getArenaKills(self)
    local query = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local kills = result.getDataInt(query, 'arenaKills') or 0
    result.free(query)
    return kills
end

Paste on your player lib and use on any script or in same script to debug the info.

Lua:
player:getArenaKills()
player:getArenaDeaths()

I edited the code above onLook test it

Lua:
local look = EventCallback
look.onLook = function(self, thing, position, distance, description)
    if not thing:isPlayer() then
        return description
    end
    local kills = player:getArenaKills()
    local deaths = player:getArenaDeaths()
    description = string.format("%s\nArena Stats: Kills: %d, Deaths: %d", description, kills, deaths)
    return description
end
look:register(5)
 
Last edited:
Solution
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Lua:
function Player.getArenaDeaths(self)
    local query = db.storeQuery("SELECT `arenaDeaths` FROM `players` WHERE `id` = " .. self:getGuid())
    local deaths = result.getDataInt(query, 'arenaDeaths') or 0
    result.free(query)
    return deaths
end

function Player.getArenaKills(self)
    local query = db.storeQuery("SELECT `arenaKills` FROM `players` WHERE `id` = " .. self:getGuid())
    local kills = result.getDataInt(query, 'arenaKills') or 0
    result.free(query)
    return kills
end

Paste on your player lib and use on any script or in same script to debug the info.

Lua:
player:getArenaKills()
player:getArenaDeaths()

I edited the code above onLook test it

Lua:
local look = EventCallback
look.onLook = function(self, thing, position, distance, description)
    if not thing:isPlayer() then
        return description
    end
    local kills = player:getArenaKills()
    local deaths = player:getArenaDeaths()
    description = string.format("%s\nArena Stats: Kills: %d, Deaths: %d", description, kills, deaths)
    return description
end
look:register(5)

Ty for the reply! I've tried but encounter this when looking at players...
1663858273299.png

Btw I have a question, I think that maybe the script won't work because it is still being triggered with onKill function, but the player actually doesn't die or kill, because the arena script works with onPrepareDeath.

Lua:
-- Prepare death. Handles players dying in arena. --
local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
function creatureeventPvPArena.onPrepareDeath(creature, killer)
    if not creature:isPlayer() then return true end
    if not creature:isPvPArenaPlayer() then return true end
    local town = config[creature:getTown():getId()]
    if not town then return true end
 
    creature:teleportTo(town.exitPos)
    creature:addHealth(creature:getMaxHealth())
    creature:addMana(creature:getMaxMana())
    print("PVP")
    creature:setPvPArenaPlayer(false)
    return false
end
creatureeventPvPArena:register()

Which way I can include the deaths/kills counter inside the onPrepareDeath function? The script is becoming a little messy because I attached too many stuff, if there could be a clean-up for the system would be great. Basically, the revscript should:

a) Check inside onPrepareDeath function if player died inside arena (creature:setPvPArenaPlayer(false)), or killed another player (no idea how this should be written considering setPvPArenaPlayer function).
b) Create onLook event to see how many kills and deaths the player has (this is what have been done in the last post)
c) Send a little message, for example
Lua:
  player:say('+1 Kill Point!', TALKTYPE_ORANGE_1)
    target:say('+1 Death Point!', TALKTYPE_ORANGE_1)
when a player kill or die.

Sorry if I missed something, guess that's all that is needed :p
Thanks in advance, regards!
 

ramonxxd

New Member
Joined
Jul 8, 2022
Messages
6
Reaction score
4
GitHub
vesgoboy
guys i put the db.query in pvpArena.lua in data/scripts and work well

Lua:
-- Prepare death. Handles players dying in arena. --
    local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
    function creatureeventPvPArena.onPrepareDeath(creature, killer)
        if not creature:isPlayer() then return true end
        if not creature:isPvPArenaPlayer() then return true end
        local town = config[creature:getTown():getId()]
        if not town then return true end

        creature:say("Ahhh Ahhha ahhhh")
        creature:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)

        db.query("UPDATE players SET arenaKills = arenaKills + 1 WHERE id = '" .. killer:getGuid() .. "';")
        db.query("UPDATE players SET arenaDeaths = arenaDeaths + 1 WHERE id = '" .. creature:getGuid() .. "';")

        creature:teleportTo(town.exitPos)
        creature:addHealth(creature:getMaxHealth())
        creature:addMana(creature:getMaxMana())
        -- print("PVP") --
        creature:setPvPArenaPlayer(false)
        return false
    end
    creatureeventPvPArena:register()

thanks for help all of u <3
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
guys i put the db.query in pvpArena.lua in data/scripts and work well

Lua:
-- Prepare death. Handles players dying in arena. --
    local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
    function creatureeventPvPArena.onPrepareDeath(creature, killer)
        if not creature:isPlayer() then return true end
        if not creature:isPvPArenaPlayer() then return true end
        local town = config[creature:getTown():getId()]
        if not town then return true end

        creature:say("Ahhh Ahhha ahhhh")
        creature:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)

        db.query("UPDATE players SET arenaKills = arenaKills + 1 WHERE id = '" .. killer:getGuid() .. "';")
        db.query("UPDATE players SET arenaDeaths = arenaDeaths + 1 WHERE id = '" .. creature:getGuid() .. "';")

        creature:teleportTo(town.exitPos)
        creature:addHealth(creature:getMaxHealth())
        creature:addMana(creature:getMaxMana())
        -- print("PVP") --
        creature:setPvPArenaPlayer(false)
        return false
    end
    creatureeventPvPArena:register()

thanks for help all of u <3

So good!!! Finally works perfectly jajajaja, thanks man!
Also added onLook event to complete the system
1663885108660.png
1663885128092.png

Just add this to pvpArena.lua
Lua:
local look = EventCallback

look.onLook = function(self, player, position, distance, description)
    if not player:isPlayer() then
        return description
    end
    local kills = player:getArenaKills()
    local deaths = player:getArenaDeaths()
    local adr

    if deaths == 0 then
        adr = kills
        description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, adr)
        return description
    end

    adr = kills/deaths
    description = string.format("%s\nThis player killed %s and died %s times. Their ADR is %s", description, kills, deaths, ADR)
    return description
end

look:register(5)

I'm really gratefull for this, the whole system is working really good :)
Regards!
 
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
671
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
@Acubens @Extrodus @ramonxxd
Hi there, I wonder if we could make more stuff for this system ^^

I was thinking on adding a multi-client check inside the revscript so players with multi-client won't obtain KDA.
Any idea of how this could be done?

Also wondering if this kill broadcast script can be added too. This way:
  • Only send broadcast to the players inside the arena (only if isInPvpArena())
  • It should broadcast who dies inside arena (player:getArenaDeaths()),
  • Broadcast who killed him (player:getArenaKills())
The Script
Lua:
function realTableSize(t)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
    end
    return size
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local damageMap = creature:getDamageMap()
    local str = creature:getName().." ["..creature:getLevel().."]"

    local damageMapSize = realTableSize(damageMap)

    if(damageMapSize <= 1) then
        str = str.." was killed by "
    elseif(damageMapSize > 1 and damageMapSize <= 4) then
        str = str.." was slain by "
    elseif(damageMapSize > 4 and damageMapSize <= 7) then
        str = str.." was crushed by "
    elseif(damageMapSize > 7 and damageMapSize <= 10) then
        str = str.." was eliminated by "
    elseif(damageMapSize > 10) then
        str = str.." was annihilated by "
    end

    local i = 0
    for pid, _ in pairs(damageMap) do
        i = i + 1

        if (i == damageMapSize) then
            str = str.." and "
        elseif (i ~= 1) then
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end

    str = str.."."
    --Game.broadcastMessage(str, MESSAGE_STATUS_WARNING)
    sendChannelMessage(9, TALKTYPE_CHANNEL_R1, str)
    print(str)
    return true
end

Regards! And thanks in advance :)
 
Top