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

TalkAction /Namelock tfs 1.x

Sir Islam

Never Give Up
Joined
Jun 6, 2008
Messages
504
Solutions
1
Reaction score
116
Location
Suez , Egypt
have fun for all :D

Request:
[TFS 1.0] namelock/ban reason

talkactions.xml

Code:
<talkaction words="/namelock" separator=" " script="namelock.lua" />

namelock.lua

Code:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    local name = param
    local reason = ''

    local separatorPos = param:find(',')
    if separatorPos ~= nil then
        name = param:sub(0, separatorPos - 1)
        reason = string.trim(param:sub(separatorPos + 1))
    end

    local PlayerGUID = getPlayerGUIDByName(name)
    if PlayerGUID == 0 then
        return false
    end

    local timeNow = os.time()
    db.query("INSERT INTO `player_namelocks`(`player_id`, `reason`, `namelocked_at`, `namelocked_by`) VALUES (".. PlayerGUID.."," .. db.escapeString(reason) .. ","..timeNow.."," .. player:getGuid() .. ")")
    local target = Player(name)
    if target ~= nil then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been Namelock.")
        target:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been Namelock.")
    end
end

how to use

/namelock name,reason


Code:
<talkaction words="/unlock" separator=" " script="unlock.lua"/
unlock.lua
Code:
function onSay(player, words, param)
   if not player:getGroup():getAccess() then
     return true
   end

   local resultId = db.storeQuery("SELECT `id` FROM `players` WHERE `name` = " .. db.escapeString(param))
   if resultId == false then
     return false
   end

   db.asyncQuery("DELETE FROM `player_namelocks` WHERE `player_id` = " .. result.getDataInt(resultId, "id"))
   result.free(resultId)
   player:sendTextMessage(MESSAGE_EVENT_ADVANCE, param .. " has been unlock.")
   return false
end

/unlock name



if you use tfs 1.0

chnage
Code:
db.asyncQuery
db.query
to
Code:
db:query
 
Last edited:
Awesome, thank's for contribution. Could you also add sql query to alter table?
 
Awesome, thank's for contribution. Could you also add sql query to alter table?
Code:
    db.query("INSERT INTO `player_namelocks`(`player_id`, `reason`, `namelocked_at`, `namelocked_by`) VALUES (".. PlayerGUID.."," .. db.escapeString(reason) .. ","..timeNow.."," .. player:getGuid() .. ")")
 
Not 1.x, 1.1+.

And use player:getGuid (once you have checked if the player exists) insted of getPlayerGUIDByName.
 
Ugh, sorry to bother again. Is this, updated, version working on TFS 1.0 ? Cause the previous version, before update - it didnt.
 
Back
Top