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

Lua Adding +1 kill when player kill someone.

maas

New Member
Joined
Nov 23, 2008
Messages
20
Reaction score
2
Hello guys, im adding a top fraggers system in my gesior, bu tiv some prob with a creaturescript that i made, the script hv to add +1 in table frags_all.... The way is players > frags_all

i Made all correct but when a player kill the number of the table do not change!!!

The scripts are above and my server is TFS 1.3

creaturescripts/scripts/topfrags.lua
Code:
local skulls = {SKULL_WHITE, SKULL_YELLOW, SKULL_RED, SKULL_BLACK}

function addPlayerFrag(cid, value)
    db.executeQuery("UPDATE `players` SET `frags_all` = `frags_all` + " .. value .. " WHERE `id` = " .. getPlayerGUID(cid) .. ";")
    return true
end

function onKill(cid, target)
    if isPlayer(cid) and isPlayer(target) then
        for i= 1, #skulls do
            if getPlayerSkullType(target) == skulls[i]  then
                addPlayerFrag(cid, 1)
                break
            end
        end
    end
    return true
end

function onLogin(cid)
    registerCreatureEvent(cid, "TopFrags")
    return true
end

And
creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="TopFrags" event="script" value="topfrags.lua" />
<event type="login" name="RTopFrags" event="script" value="topfrags.lua" />


THANKSSS
 
Solution
Use code tags.

Lua:
local skulls = {SKULL_WHITE, SKULL_YELLOW, SKULL_RED, SKULL_BLACK}

function addPlayerFrag(player, value)
    db.query("UPDATE `players` SET `frags_all` = `frags_all` + " .. value .. " WHERE `id` = " .. player:getGuid() .. ";")
    return true
end

function onKill(player, target)
    if not target:isPlayer() then
        return true
    end

    if table.contains(skulls, player:getSkull()) then
        addPlayerFrag(player, 1)
    end
    
    return true
end
Where is this function onLogin placed? In your creaturescript? You should register this in login.lua

Also if you use tfs 1.3 do not use old code style.

function onKill(player, target)
and
target:isPlayer() for example
 
@Thexamx

i Removed the function >>
  1. function onLogin(cid)
  2. registerCreatureEvent(cid, "TopFrags")
  3. return true
  4. end

And registered in login.lua, but still not working, its my first time code tfs 1.3, can u help more plx <3
 
Use code tags.

Lua:
local skulls = {SKULL_WHITE, SKULL_YELLOW, SKULL_RED, SKULL_BLACK}

function addPlayerFrag(player, value)
    db.query("UPDATE `players` SET `frags_all` = `frags_all` + " .. value .. " WHERE `id` = " .. player:getGuid() .. ";")
    return true
end

function onKill(player, target)
    if not target:isPlayer() then
        return true
    end

    if table.contains(skulls, player:getSkull()) then
        addPlayerFrag(player, 1)
    end
    
    return true
end
 
Last edited by a moderator:
Solution
Change
db.executeQuery
to:
db.asyncQuery

How does it not work? Have you debugged the code or just put it in, test and "no. not working".
 
Change
db.executeQuery
to:
db.asyncQuery

How does it not work? Have you debugged the code or just put it in, test and "no. not working".
@Thexamx Omg bro! OFC that im testing everything before talking to you that not working... to me the script still not working, i do all that u said without mistakes and forgets, but still if error in something... sorry again to disturb u, that isnt my intention... i just need help because that is important to me.
 
@Thexamx Omg bro! OFC that im testing everything before talking to you that not working... to me the script still not working, i do all that u said without mistakes and forgets, but still if error in something... sorry again to disturb u, that isnt my intention... i just need help because that is important to me.

If you have an error then post it, that way we can help you faster insted of guessing.
 
@Thexamx Omg bro! OFC that im testing everything before talking to you that not working... to me the script still not working, i do all that u said without mistakes and forgets, but still if error in something... sorry again to disturb u, that isnt my intention... i just need help because that is important to me.
So you made prints and you see to which moment the script is executed?
 
You registered it onLogin? Check if names are matching.
If it isnt a case, add prints.
 
Fixed via TV, @Thexamx script worked (changed executeQuery to query)
Problem was that in XML he had written value="path" insted of script="path".
 
Back
Top