KingMofo Posted February 27, 2010 Share Posted February 27, 2010 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
driver2 Posted February 27, 2010 Share Posted February 27, 2010 You could probably use string.find() while looping through all players. Be careful to set the plain-argument to true, or else you might accidently use lua patterns. You should also check if there was more than one match, else you could accidently execute the command on someone you didn't intend to. Link to comment
Jumba' Posted February 27, 2010 Share Posted February 27, 2010 This is my player matching script, I suppose you could optimize it a bit 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 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
robhol Posted February 27, 2010 Share Posted February 27, 2010 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
Jumba' Posted February 27, 2010 Share Posted February 27, 2010 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 Link to comment
KingMofo Posted February 27, 2010 Author Share Posted February 27, 2010 Thank you all three of you! You don't know how much i appreciate you giving me your script Jumba, it means alot to me as it saves alot of hassle for the future. I will report back here to let you all know how it goes. Link to comment
KingMofo Posted February 28, 2010 Author Share Posted February 28, 2010 Success! The ID system is working flawlessly thanks to Jumba'. Thanks for all your help, it is appreciated. Link to comment
KingMofo Posted March 1, 2010 Author Share Posted March 1, 2010 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
robhol Posted March 2, 2010 Share Posted March 2, 2010 function isNumber(n) return tonumber(n) ~= nil; end should do the trick.. Link to comment
KingMofo Posted March 3, 2010 Author Share Posted March 3, 2010 Thanks xbost for the link but i had a go with the stuff they provided and wasn't working (probably me). Thanks robhol, it works perfectly. Thanks for all your help! Link to comment
Luke_Ferrara Posted May 19, 2010 Share Posted May 19, 2010 I keep getting 'ERROR: call: failed to call 'scoreboard:scoreboardAddColumn any ideas? Link to comment
robhol Posted May 19, 2010 Share Posted May 19, 2010 Is the scoreboard running? (And what's with the thread necromancy?) Link to comment
50p Posted May 19, 2010 Share Posted May 19, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now