Jump to content

Player alias


hazard

Recommended Posts

Posted

Hey, I was wondering if it is possible to make a command like !alias or !pma that would show all the nicks a player has used in a server.

For example i came in server with a nick "Player" then i left and came back with another nick "Goatguy", i could see both nicks the player has used with the command !alias

If it is possible and not too hard to make, could anyone post it?

I have no idea how to make it and i couldnt find any info.

Posted

1. Search and use the "VUVUZELE"/"VUVUZELA" script. It have in-built alias/pma.

2. I wrote smthing for you

function whenPlayerJoinTheServer() 
    local playerNick = removeHexColorCode(getPlayerName(source)) 
    local playerSerial = getPlayerSerial(source) 
    local searchForAPlayer = executeSQLQuery("SELECT `nicks` FROM `aliases` WHERE `serial`=?", playerSerial) -- trying to select a player from the db 
    if #searchForAPlayer == 0 then -- if we havent found our player then 
        executeSQLQuery("INSERT INTO `aliases`(serial, nicks) VALUES (?, ?)", playerSerial, playerNick) -- insert his record to the table 
    else -- we found our player 
        local actualNicks = searchForAPlayer[1].nicks -- get the 'nicks' data from record 
        if string.find(actualNicks, playerNick) then -- if he have SAME NICK as in the database 
            -- do nothing, why we should double player nicks in db? 
        else -- he dont have this nick in DB 
            local addNewNick = actualNicks .. ", " .. playerNick -- expand variable by adding nick player have now 
            executeSQLQuery("UPDATE `aliases` SET `nicks`=? WHERE `serial`=?", addNewNick, playerSerial) -- executing sql query which updates `texts` value with extanded variable containing new nick 
        end -- ending  
    end-- ending 
end-- ending 
addEventHandler ("onPlayerJoin", getRootElement(), whenPlayerJoinTheServer) -- adding event handler, you should know why you need to do it, if not then click "addeventhandler" and you'll get an wiki article. 
function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
function checkAllNicksOfPlayer(who, cmd, playah) 
    local targetPlayer = getPlayerFromNamePart(playah) -- searching player from name part so we dont need to write all the name 
    local targetSerial = getPlayerSerial(targetPlayer) -- getting serial to check the db 
    local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
    if #searchForANicks == 1 then -- we found player 
        outputChatBox("#FFD330History of nicks for "..getPlayerName(targetPlayer)..":#FAFAFA "..searchForANicks[1].nicks, who, 0, 0, 0, true) -- show message to command executor with player nicks history 
    end 
end 
addCommandHandler("pma", checkAllNicksOfPlayer) -- adding command 
  
function createTables() 
    local a = executeSQLQuery("CREATE TABLE IF NOT EXISTS `aliases` (`serial` TEXT, `nicks` TEXT)") -- adding sqlite table with serial (to identificate player) and all nicks 
    if a then outputDebugString("Created table for players aliases") end -- show a msg in console to be sure it all works 
end 
addEventHandler("onResourceStart", getResourceRootElement(), createTables) -- adding event handler, you should know why you need to do it, if not then click "addeventhandler" and you'll get an wiki article. 
  
  
function removeHexColorCode(s) 
    return s:gsub( '#%x%x%x%x%x%x', '' ) or s 
end 

My english is bad so if you dont understand comments just tell me. And you need also to make a saving when player CHANGE nick while being on the server. Have fun :)

Posted

Well i tried to make it work, but it doesn't work, is it possible for anyone to edit the VUVUZELE script and make only the !alias cmd work?

Or just make it, im new in scripting and don't rly understand how it works

Posted

It has an error, same as i had:

ERROR: alias.lua:32: attempt to call global 'executeSQLQuery' (a nil value)

Any idea how to fix it?

Posted

Line 32 in his code returned nil. I think it's because of typo.

 local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
--> 
local searchForANicks = executeSQLQuery("SELECT `nicks` FROM `aliases` WHERE `serial`=?", targetSerial) -- checking 
  

Posted

Dat's because you put wrong nick... :)

Look at this

    local targetPlayer = getPlayerFromNamePart(playah) -- searching player from name part so we dont need to write all the name 
    local targetSerial = getPlayerSerial(targetPlayer) -- getting serial to check the db 

And think. Change all the function for this:

function checkAllNicksOfPlayer(who, cmd, playah) 
    local targetPlayer = getPlayerFromNamePart(playah) -- searching player from name part so we dont need to write all the name 
    if not targetPlayer then 
        outputChatBox("this player does not exist", who) 
    else 
    local targetSerial = getPlayerSerial(targetPlayer) -- getting serial to check the db 
    local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
    if #searchForANicks == 1 then -- we found player 
        outputChatBox("#FFD330History of nicks for "..getPlayerName(targetPlayer)..":#FAFAFA "..searchForANicks[1].nicks, who, 0, 0, 0, true) -- show message to command executor with player nicks history 
    end 
    end 
end 

Then try.

Line 32 in his code returned nil. I think it's because of typo.
local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
--> 
local searchForANicks = executeSQLQuery("SELECT `nicks` FROM `aliases` WHERE `serial`=?", targetSerial) -- checking 
  

Nahh men. Both forms are ok.

Posted

Yes that worked, no errors now.

The only thing I don't understand is why it doesn't show the old nicks in chatbox.

function whenPlayerJoinTheServer() 
    local playerNick = removeHexColorCode(getPlayerName(source)) 
    local playerSerial = getPlayerSerial(source) 
    local searchForAPlayer = executeSQLQuery("SELECT `nicks` FROM `aliases` WHERE `serial`=?", playerSerial) -- trying to select a player from the db 
    if #searchForAPlayer == 0 then -- if we havent found our player then 
        executeSQLQuery("INSERT INTO `aliases`(serial, nicks) VALUES (?, ?)", playerSerial, playerNick) -- insert his record to the table 
    else -- we found our player 
        local actualNicks = searchForAPlayer[1].nicks -- get the 'nicks' data from record 
        if string.find(actualNicks, playerNick) then -- if he have SAME NICK as in the database 
            -- do nothing, why we should double player nicks in db? 
        else -- he dont have this nick in DB 
            local addNewNick = actualNicks .. ", " .. playerNick -- expand variable by adding nick player have now 
            executeSQLQuery("UPDATE `aliases` SET `nicks`=? WHERE `serial`=?", addNewNick, playerSerial) -- executing sql query which updates `texts` value with extanded variable containing new nick 
        end -- ending 
    end-- ending 
end-- ending 
addEventHandler ("onPlayerJoin", getRootElement(), whenPlayerJoinTheServer) -- adding event handler, you should know why you need to do it, if not then click "addeventhandler" and you'll get an wiki article. 
function getPlayerFromNamePart(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
function checkAllNicksOfPlayer(who, cmd, playah) 
    local targetPlayer = getPlayerFromNamePart(playah) -- searching player from name part so we dont need to write all the name 
    if not targetPlayer then 
        outputChatBox("this player does not exist", who) 
    else 
    local targetSerial = getPlayerSerial(targetPlayer) -- getting serial to check the db 
    local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
    if #searchForANicks == 1 then -- we found player 
        outputChatBox("#FFD330History of nicks for "..getPlayerName(targetPlayer)..":#FAFAFA "..searchForANicks[1].nicks, who, 0, 0, 0, true) -- show message to command executor with player nicks history 
    end 
    end 
end 
addCommandHandler("pma", checkAllNicksOfPlayer) -- adding command 
  
function createTables() 
    local a = executeSQLQuery("CREATE TABLE IF NOT EXISTS `aliases` (`serial` TEXT, `nicks` TEXT)") -- adding sqlite table with serial (to identificate player) and all nicks 
    if a then outputDebugString("Created table for players aliases") end -- show a msg in console to be sure it all works 
end 
addEventHandler("onResourceStart", getResourceRootElement(), createTables) -- adding event handler, you should know why you need to do it, if not then click "addeventhandler" and you'll get an wiki article. 
  
  
function removeHexColorCode(s) 
    return s:gsub( '#%x%x%x%x%x%x', '' ) or s 
end 

Everything seems to be correct

Posted
function checkAllNicksOfPlayer(who, cmd, playah) 
    local targetPlayer = getPlayerFromNamePart(playah) -- searching player from name part so we dont need to write all the name 
    if not targetPlayer then 
        outputChatBox("this player does not exist", who) 
    else 
    local targetSerial = getPlayerSerial(targetPlayer) -- getting serial to check the db 
    local searchForANicks = executeSQLQuery("SELECT `nicks` from `aliases` WHERE `serial`=?", targetSerial) -- checking 
    if #searchForANicks > 0 then -- we found player 
        outputChatBox("#FFD330History of nicks for "..getPlayerName(targetPlayer)..":#FAFAFA "..searchForANicks[1].nicks, who, 0, 0, 0, true) -- show message to command executor with player nicks history 
    else 
        outputChatBox("#FFD330This player doesnt have a nick history (Which mean problem with your sqlite db...)", who, 0, 0, 0, true)  
    end 
    end 
end 

as always debugscript 3 then try. if you got This player doesnt have a nick history (Which mean problem with your sqlite db...) then send me your registry.db (better on the pm)

#edit: i just gave it to my friends and it works fine for them :)

Posted

Well when i do /pma it doesn't show any results in chat

if i write /pma it does show "this player does not exist"

The script seems correct now but it doesnt output the results in chat

Posted

My old alias script. I hope it still works.

addEventHandler("onResourceStart", resourceRoot, 
    function() 
        executeSQLQuery("CREATE TABLE IF NOT EXISTS `players` (`serial` TEXT, `mute` TEXT, `alias` TEXT)") 
    end 
) 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        local serial = getPlayerSerial(source) 
        local name = getPlayerName(source) 
        local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) 
        if #r == 0 then 
            executeSQLQuery("INSERT INTO `players` (`serial`,`mute`,`alias`) VALUES(?,?,?)", serial, "no", name) 
        else 
            if r[1]["mute"] == "yes" then 
                setPlayerMuted(source, true) 
                outputChatBox(name:gsub("#%x%x%x%x%x%x", "").." has been muted by Console!", root, 255, 0, 0, true) 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerQuit", root, 
    function() 
        if isPlayerMuted(source) then 
        else 
        end 
    end 
) 
  
addEventHandler("onPlayerJoin", root, 
    function() 
        setAlias(source) 
    end 
) 
  
addEventHandler("onPlayerChangeNick", root, 
    function() 
        setTimer(setAlias, 100, 1, source) 
    end 
) 
  
function setAlias(source) 
    local find = true 
    local name = getPlayerName(source) 
    local serial = getPlayerSerial(source) 
    local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) 
    for i,v in ipairs(split(r[1]['alias'], 32)) do 
        if v == name then 
            find = false 
        end 
    end 
    if find then 
        executeSQLQuery("UPDATE `players` SET `mute`=?, `alias`=? WHERE `serial`=?", r[1]["mute"], r[1]["alias"].." "..name, serial) 
    end 
end 
  
function findPlayer(name) 
    if name then  
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player  
            end 
        end 
    end 
    return false 
end 
  
local alias1 = "" 
local alias2 = 0 
  
addCommandHandler("pma", 
    function(p, _, t) 
        local target = findPlayer(t) 
        if target then 
            local serial = getPlayerSerial(target) 
            local r = executeSQLQuery("SELECT `mute`,`alias` FROM `players` WHERE `serial`=?", serial) 
            local spl = split(r[1]["alias"], 32) 
            for i, v in ipairs(spl) do 
                if alias1 == "" then 
                    alias1 = v 
                    alias2 = alias2 + 1 
                else 
                    alias1 = alias1..", "..v 
                    alias2 = alias2 + 1 
                end 
                if i == #spl then 
                    outputChatBox(alias1, p, 255, 255, 255, true) 
                    alias1 = "" 
                    alias2 = 0 
                end 
            end 
        end 
    end 
) 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...