Jump to content

(help needed) "Player also known as" script


Izzy

Recommended Posts

outputChatBox has latest argument which can be true/false

use 'true' if you want color codes

e.g

-- server side 
outputChatBox("a #FFFFFFmessage!",root,255,0,0,true) -- true makes it color coded 
--client side 
outputChatBox("a #FFFFFFmessage!",255,0,0,true) -- true makes it color coded 

Link to comment
outputChatBox has latest argument which can be true/false

use 'true' if you want color codes

e.g

-- server side 
outputChatBox("a #FFFFFFmessage!",root,255,0,0,true) -- true makes it color coded 
--client side 
outputChatBox("a #FFFFFFmessage!",255,0,0,true) -- true makes it color coded 

I'm pretty sure he meant the way of outputting all player's previous names depending on the serial.

Link to comment

You could use a database to store all the names related to a certain serial, load the database on start and store the data in a table. You could then append to it any new names and update the database.

Link to comment
You could use a database to store all the names related to a certain serial, load the database on start and store the data in a table. You could then append to it any new names and update the database.

This has a disadvantage. You still have to check names for similarity so the names' lengths don't become extremely huge due to the amount of old nicks. It's better to save last 5 or something

Link to comment

Example:

addEventHandler('onClientPlayerJoin', root, 
    function() 
        outputChatBox('#FF0000> #FFFFFF' ..getPlayerName(source).. ' #FF0000joined the game', 255, 0, 0, true) 
    end 
) 
  
addEventHandler('onClientPlayerChangeNick', root, 
    function(oldNick, newNick) 
        outputChatBox('#FF0000^ #FFFFFF' ..oldNick.. ' #FF0000is now known as #FFFFFF' ..newNick, 255, 0, 0, true) 
    end 
) 
  
addEventHandler('onClientPlayerQuit', root, 
    function(reason) 
        outputChatBox('#FF0000< #FFFFFF' ..getPlayerName(source).. ' #FF0000left the game [#FFFFFF' .. reason .. '#FF0000]', 255, 0, 0, true) 
    end 
) 

Link to comment

That's the default joinquit resource. I'm not talking about adding #ff0000 etc. to the original default joinquit resource.

I need to make a script so that when a regular player joins the server with another name, it shows his other names too. I hope you're getting me. In my link I sent before, it has an example of what I am speaking of. I'll give an example.

"# ff0000(Player Name, who connected) # 008800(is also known as: ) # D4A017(Izzy, IZZY, Izzy696)"

OR

[Joinquit] Player is connecting [iP]

Izzy is also known as: IzzY, IZZY, Izzy696

Here's another example:

http://s22i.imgup.net/knownas5263.png

THE JOINQUIT SHOULDN'T BE CHANGED UNLESS IT REALLY NEEDS TO. IT SHOULD WORK AS IT SHOULD, just like the example shown in the link.

If I was going to make a Database for this? How would I do it, could someone add me on Skype or something so we can go through this together, only people who know what i'm talking about and are willing to help me please.

Skype: izymta

XFire: izzymta

Link to comment

Well, to avoid direct contact with SQL, you could use MTA's account data functions which will deal with SQL themselves you just need to have save-logic system.

And yeah, you do need SQL because past names don't magically save by their own.

Link to comment
 --Initialize: 
executeSQLQuery("CREATE TABLE IF NOT EXIST names_database (serial TEXT,  nick TEXT)") 
  
function getOtherNicknames(serial) 
  return executeSQLQuery("SELECT * FROM names_database WHERE serial = ?", serial) --collect data of old nicknames 
end 
  
function recordNewName(serial, name) 
  local oldnames = getOtherNicknames(serial) 
  if oldnames then --if data retrieved, then 
    if #oldnames > 5 then --check if number of records for serial exceeds 5, 
      executeSQLQuery("DELETE FROM names_database WHERE rowid = ?", oldnames[1]['rowid']) --and delete oldest row if that's the case 
    end 
  end 
  executeSQLQuery("INSERT INTO names_database (serial, nick) VALUES(?, ?)", serial, name) --record new nickname 
end 
  
addEventHandler("onPlayerJoin", root,  
  function() 
    local currentName = getPlayerName(source) 
    local serial = getPlayerSerial(source) -- *ACL admin rights required* 
    local aka = getOtherNames(serial) --collect other names before recording current one, to avoid duplicates on message output 
    local othernames = {} --create a temporary table 
    for k, v in ipairs(aka) do 
      table.insert(othernames, v['nick']) --add the name to a separate table 
    end 
    recordNewName(serial, currentName) 
    outputChatBox(currentName .. " #008800is also known as #D4A017" .. table.concat(othernames, ", "), root, 255, 0, 0, true) 
  end 
) 
addEventHandler("onPlayerChangeNick", root,  
  function(old, new) 
    local serial = getPlayerSerial(source) -- *ACL admin rights required* 
    recordNewName(serial, new) 
  end 
) 

^^ Untested ^^

Also, the order might not be the same as you wanted, therefore, it's better if you insert the code into joinquit resource (without duplicating event handlers

eg. just put everything from onPlayerJoin into the first lines of onPlayerJoin in joinquit resource)

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