• 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 Remove player talkaction TFS 1.2

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,759
Solutions
127
Reaction score
2,279
Hello does somebody have working tfs 1.2 delete player talkaction or can write?

I have this but doesnt work:
Code:
function onSay(cid, words, param)
    local t = string.explode(param, ",")
    if(t == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
        return true
    end
   
    local pid = getCreatureByName("".. t[1] .."")
   
    if isPlayer(pid) then
        doRemoveCreature(pid)
    end
   
    if t[2] == 1 then
        db.executeQuery("UPDATE    `players` SET  `deleted` =  '1' WHERE  `players`.`name` ='".. t[1] .."';")
        doPlayerSendTextMessage(cid, 27, "Player ".. t[1] .." deleted.")
    end       
   
    if t[2] == 0 then
        db.executeQuery("UPDATE `players` SET  `deleted` =  '0' WHERE  `players`.`name` ='".. t[1] .."';")
        doPlayerSendTextMessage(cid, 27, "You have undeleted ".. t[1] ..".")
    end   
   
    return true
end

1a940a8e262d74632d995f76bf9ac3ac.png
 
Ofc.
Code:
function onSay(cid, words, param)
    local t = param:split(',')
    if(t == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
        return true
    end
   
    local pid = getCreatureByName("".. t[1] .."")
   
    if isPlayer(pid) then
        doRemoveCreature(pid)
    end
   
    if t[2] == 1 then
        db.executeQuery("UPDATE    `players` SET  `deleted` =  '1' WHERE  `players`.`name` ='".. t[1] .."';")
        doPlayerSendTextMessage(cid, 27, "Player ".. t[1] .." deleted.")
    end       
   
    if t[2] == 0 then
        db.executeQuery("UPDATE `players` SET  `deleted` =  '0' WHERE  `players`.`name` ='".. t[1] .."';")
        doPlayerSendTextMessage(cid, 27, "You have undeleted ".. t[1] ..".")
    end   
   
    return true
end
 
Code:
<talkaction words="/delete" separator=" " script="delete.lua" />

Code:
function onSay(player, words, param)
    local t = param:split(',')
 
    if t[1] == nil then
        player:sendCancelMessage("Please specify the player's name: /delete player,(0 or 1)")
        return false
    end
 
    if t[2] == nil then
        player:sendCancelMessage("Error, param 2 should be 0 or 1. (1 for deletion, 0 to undo deletion)")
        return false
    end
 
    local dude = Player(t[1])
 
    if not dude then
         player:sendCancelMessage("A player with the name " .. t[1] .. " was not found.")
        return false
    end
 
    local status = ((tonumber(t[2]) == 1) and 1 or 0)
    db.query("UPDATE `players` SET `deleted` =  '".. status .."' WHERE  `players`.`id` = '".. dude:getGuid() .."';")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have " .. (status == 1 and 'deleted' or 'undeleted') .. " " .. dude:getName() .. ".")
 
    if status == 1 then
        dude:remove()
    end
    return false
end
 
Thanks, but doesnt work when i write /delete nick,1 player is only getting kicked but not deleted.
 
The deletion is usually part of your globalevent: startup.lua

I'll add it to the talkaction when I'm back home.
In the future it's better to be more clear of your goal is, I was just helping you fix your script. :p

Because there is point in having an 'undelete' portion if you are deleting the player right away. Once he is deleted he will be gone unless you store his information elsewhere.
 
The deletion is usually part of your globalevent: startup.lua

I'll add it to the talkaction when I'm back home.
In the future it's better to be more clear of your goal is, I was just helping you fix your script. :p

Because there is point in having an 'undelete' portion if you are deleting the player right away. Once he is deleted he will be gone unless you store his information elsewhere.

Yeah i mean permament deletion not just kick, something like ban but with character remove instead of just ban :)

But this can be done too like UPDATE sql "players" in table "deleted" from 0 to 1
 
Last edited:
Yeah i mean permament deletion not just kick, something like ban but with character remove instead of just ban :)

But this can be done too like UPDATE sql "players" in table "deleted" from 0 to 1
Code:
function onSay(player, words, param)
    if param == '' then
        player:sendCancelMessage("Please specify the player's name: /delete player_name")
        return false
    end
   
    local dude = Player(param)
   
    if not dude then
         player:sendCancelMessage("A player with the name " .. param .. " was not found.")
        return false
    end
   
    local GUID = dude:getGuid()
    local name = dude:getName()
   
    dude:remove()
    db.query("DELETE FROM `players` WHERE `players`.`id` = '".. GUID .."';")
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have deleted " .. name .. ".")
    return false
end
 
Thanks, works now! But its possible to make it to edit "deleted" in players table?
Because now player doesnt know that he got deleted his character just hide.


Lol i just noticed that when i put "deleted" to 1 it doesnt work like deletion. Nothing happens. Why?
 
Last edited:
Thanks, works now! But its possible to make it to edit "deleted" in players table?
Because now player doesnt know that he got deleted his character just hide.


Lol i just noticed that when i put "deleted" to 1 it doesnt work like deletion. Nothing happens. Why?

It's because all that is doing is letting the global event startup.lua know to delete from the players where the "deleted" column shows 1:

The line below is usually found in globalevents/scripts/startup.lua
Code:
db.query('DELETE FROM `players` WHERE `deleted` != 0)

So setting `deleted` to one doesn't do anything unless you use the line above to actually use that data and perform an action with it.
 
Code:
function onStartup()
    print(string.format('>> Loaded %d npcs and spawned %d monsters.\n>> Loaded %d towns with %d houses in total.', Game.getNpcCount(), Game.getMonsterCount(), #Game.getTowns(), #Game.getHouses()))
    for i = 1, #startupGlobalStorages do
        Game.setStorageValue(startupGlobalStorages[i], 0)
    end

    local time = os.time()
    db.asyncQuery('TRUNCATE TABLE `players_online`')
    db.asyncQuery('DELETE FROM `guild_wars` WHERE `status` = 0')
    db.asyncQuery('DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < ' .. time)
    db.asyncQuery('DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= ' .. time)
    db.asyncQuery('DELETE FROM `market_history` WHERE `inserted` <= ' .. (time - configManager.getNumber(configKeys.MARKET_OFFER_DURATION)))

I have different code ;d
 
Code:
function onStartup()
    print(string.format('>> Loaded %d npcs and spawned %d monsters.\n>> Loaded %d towns with %d houses in total.', Game.getNpcCount(), Game.getMonsterCount(), #Game.getTowns(), #Game.getHouses()))
    for i = 1, #startupGlobalStorages do
        Game.setStorageValue(startupGlobalStorages[i], 0)
    end

    local time = os.time()
    db.asyncQuery('TRUNCATE TABLE `players_online`')
    db.asyncQuery('DELETE FROM `guild_wars` WHERE `status` = 0')
    db.asyncQuery('DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < ' .. time)
    db.asyncQuery('DELETE FROM `ip_bans` WHERE `expires_at` != 0 AND `expires_at` <= ' .. time)
    db.asyncQuery('DELETE FROM `market_history` WHERE `inserted` <= ' .. (time - configManager.getNumber(configKeys.MARKET_OFFER_DURATION)))

I have different code ;d

It's important to focus on the concept not just the words, grasping the concept is the main goal.
It doesn't matter if your line is different, you can see in your code there is this line:
Code:
db.asyncQuery('DELETE FROM `players` WHERE `deletion` != 0 AND `deletion` < ' .. time)

That line falls under the same concept that changing the column from 0 to 1 will not do anything unless we use that data in another type of action. Whether that action is called in a talkaction or globalevent is besides the point.

Also I think you may need to change `deletion` !=0 to `deleted` != 0.

I hope I'm being clear, if there is any confusion please let me know.
 
Back
Top