Jump to content

Player Names


KingMofo

Recommended Posts

Hello,

I have something that needs done but i dunno how to even go about it or what it would be called.

I have an eject script on my server for mods/admins (/eject player) but when it comes to ejecting a player with long and unuseal names, it can become a pain. I have come across other servers which are able to do it with typing just some of the characters of the player and it will relate to that player.

Example.

eject ThisIsConfusing

I could do:

eject thisis

I hope i have explained it well enough. I dunno what something like this would be classed as.

I would really appreciate it if someone could help me.

Thanks.

Link to comment

This is my player matching script, I suppose you could optimize it a bit :P

You also need to modify it to work they way you want it too, since mine is actually part of an ID system, either way, here ya go :P

function getNameMatches ( player_name )
i = 1
local matchingPlayers = { }
if ( player_name ) then
for k, player in ipairs ( getElementsByType ( "player" ) ) do
local player_n = getPlayerName ( player )
local match = string.find ( string.lower( player_n ), string.lower ( player_name ), 1, true ) -- I just added the true part since driver2 mentioned it, so I dont know if I put it correctly O_o
if ( match ) then
table.insert ( matchingPlayers, i, player )
			i = i + 1
end
end
if ( #matchingPlayers == 1 ) then
return true, matchingPlayers[1] 
elseif ( #matchingPlayers > 1 ) then
return true, matchingPlayers
else
return false, "None"
end	
else
return false, "Please enter a player name"
end	
end		
 
function getPlayerFromPartialName ( source, player_name, script )
if ( player_name ) then
local sucess, value = getNameMatches ( player_name )
if ( sucess ) then
local matches = #value
if ( matches == 1 ) then
if ( script ) then return value[1] else 
local player_nick = getPlayerName ( value[1] )
local player_id = getElementData ( value[1], "ID" )
outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 )
end	
else	
outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 )
for k, player in ipairs ( value ) do
local player_nick = getPlayerName ( value[k] )
local player_id = getElementData ( value[k], "ID" )
outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 )
end
return true
end		
else
outputChatBox ( value, source, 255, 0, 0 )
end
end
end

Link to comment

No matter how much Kye whines about "idea stealing", I find it easier in the long run (for a variety of purposes) to use player IDs.

If you make a resource that assigns each player an ID when they join, you can substantially simplify the use of commands in your server.

Link to comment
No matter how much Kye whines about "idea stealing", I find it easier in the long run (for a variety of purposes) to use player IDs.

If you make a resource that assigns each player an ID when they join, you can substantially simplify the use of commands in your server.

I second that, here's my ID script if you want to use it:

http://jum.pastebin.com/d380519fc

Woovie also posted his, but I'm not sure if you're allowed to use it, but since it's pretty much public I guess you could :P

Link to comment

Okay, now i have a problem.

Now that i am using an ID system and the default system (Names), i get an error when using a name and not a number. For example,

eject KingMofo - it would return an error on the ID system like this...

ERROR: ...eathmatch/resources/scoreboard/dxscoreboard_http:lua:110: kingmofo is not a number, please enter a number
ERROR: call: failed to call 'scoreboard:getPlayerFromID'

What i need help with is how i would i go about checking if the syntax entered is letters or numbers and then i could prevent the error (Right?).

I been trying to look through the math. stuff and string. stuff but i have no idea which one would be used to do such a thing.

I hope someone can help me, i would appreciate it.

Link to comment
  • 2 months later...
I keep getting

'ERROR: call: failed to call 'scoreboard:scoreboardAddColumn

any ideas?

I get this error every time I call ANY exported function from ANY resource. To make sure the resource is running, add to your meta.xml. I do not guarantee any success, as I said I've always had problems with calling exported functions and none of MTA devs could help me. If you figure out what might be the problem, let us know.

EDIT:

Just noticed, race gamemode can't call mapmanager's functions neither.

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