Jump to content

[help]getplayerserial


XLEGENDX

Recommended Posts

Spoiler

function whenPlayerJoinTheServer()
    local playerNick = removeHexColorCode(getPlayerName(source)) -- remove hex color code from player username
    local playerSerial = getPlayerSerial(source) -- get player serial
    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 whenPlayerChangeNick(_, newNick)
    local newNick = removeHexColorCode(newNick) -- remove hex color code from player username
    local playerSerial = getPlayerSerial(source) -- get player serial
    local searchForAPlayer = executeSQLQuery("SELECT `nicks` FROM `aliases` WHERE `serial`=?", playerSerial) -- trying to select a player from the db
    if #searchForAPlayer == 1 then -- we found our player
        local actualNicks = searchForAPlayer[1].nicks -- get the 'nicks' data from record
        if string.find(actualNicks, newNick) then -- if he have SAME NICK as in the database
            -- do nothing, why we should double player nicks in database?
        else
            local addNewNick = actualNicks .. ", " .. newNick -- 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
    end
end
addEventHandler("onPlayerChangeNick", getRootElement(), whenPlayerChangeNick) -- 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

hello guys, can anyone help me in this problem thumb_show.php?i=derzyr3p&view

Link to comment

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...