pejczi Posted July 18, 2013 Share Posted July 18, 2013 (edited) Hey, I want to set player's nick prefics as SPEC- using one command - but debugger returns : "ERROR : spectators/spectator.lua:2: attempt to call global 'getPlayerFromNamePart' (a nil value)" The code is : function setTag ( source, command, thePlayer ) local spec = getPlayerFromNamePart ( thePlayer ) if ( spec ) then if getElementType ( spec ) == "player" then local oldName = getPlayerName ( spec ) local newName = "SPEC-" .. oldName setPlayerName ( spec, newName ) outputChatBox ( "Player has been moved to SPEC team ", source ) end else outputChatBox ( "Unable to move player to SPEC team " , source ) end end addCommandHandler ( "spec" , setTag ) Yours Faithfully, Pejczi. Edited July 18, 2013 by Guest Link to comment
Dealman Posted July 18, 2013 Share Posted July 18, 2013 There's no function called "getPlayerFromNamePart". Do you want to add a prefix to a specific player? For example from Player1 to SPEC-Player1? Link to comment
pejczi Posted July 18, 2013 Author Share Posted July 18, 2013 There's no function called "getPlayerFromNamePart".Do you want to add a prefix to a specific player? For example from Player1 to SPEC-Player1? Yes, i'd like to. And it exists : https://wiki.multitheftauto.com/wiki/Ge ... omNamePart Ok, I've recognized that this function isn't predefined. Now it outputs "Player has been moved to SPEC team", but it doesn't add prefix. function getPlayerFromNamePart(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 function setTag ( source, command, thePlayer ) local spec = getPlayerFromNamePart ( thePlayer ) if ( spec ) then if getElementType ( spec ) == "player" then local oldName = getPlayerName ( spec ) local newName = "SPEC-" .. oldName setPlayerName ( spec, newName ) outputChatBox ( "Player has been moved to SPEC team ", source ) end else outputChatBox ( "Unable to move player to SPEC team " , source ) end end addCommandHandler ( "spec" , setTag ) Link to comment
pejczi Posted July 18, 2013 Author Share Posted July 18, 2013 Ok, i spotted the problem ; maximal character length of nick is 21 . function deleteTag ( source, command, thePlayer ) local spec = getPlayerFromNamePart ( thePlayer ) if ( spec ) then if getElementType ( spec ) == "player" then local oldName = getPlayerName ( spec ) setPlayerName ( spec , string.gsub ( oldName , "[s]" , "" ) ) setPlayerTeam ( spec, nil ) outputChatBox ( "Player has been removed from SPEC team" , source ) end else outputChatBox ("Unable to remove player from SPEC team" , source ) end end addCommandHandler ( "nospec" , deleteTag ) Why it removes just S, instead of ? Link to comment
MIKI785 Posted July 18, 2013 Share Posted July 18, 2013 Not sure if it'll work but try this: function deleteTag ( source, command, thePlayer ) local spec = getPlayerFromNamePart ( thePlayer ) if ( spec ) then if getElementType ( spec ) == "player" then local oldName = getPlayerName ( spec ) setPlayerName ( spec , string.gsub ( oldName , "%[s%]" , "" ) ) setPlayerTeam ( spec, nil ) outputChatBox ( "Player has been removed from SPEC team" , source ) end else outputChatBox ("Unable to remove player from SPEC team" , source ) end end addCommandHandler ( "nospec" , deleteTag ) Link to comment
pejczi Posted July 18, 2013 Author Share Posted July 18, 2013 works, thanks ! But i found out one trouble, i have to type "/spec pejczi" twice, otherwise it won't move me to the team Link to comment
pejczi Posted July 19, 2013 Author Share Posted July 19, 2013 Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown. function killTeam () local theTeam = getTeamFromName ( "SPECTATORS" ) if ( theTeam ) then local players = getPlayersInTeam ( theTeam ) for key, player in ipairs ( players ) do local theVehicle = getPedOccupiedVehicle ( player ) if ( theVehicle ) then blowVehicle ( theVehicle ) end end end end I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in. Link to comment
Alen141 Posted July 19, 2013 Share Posted July 19, 2013 Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown. function killTeam () local theTeam = getTeamFromName ( "SPECTATORS" ) if ( theTeam ) then local players = getPlayersInTeam ( theTeam ) for key, player in ipairs ( players ) do local theVehicle = getPedOccupiedVehicle ( player ) if ( theVehicle ) then blowVehicle ( source ) end end end end I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in. try using destroyElement Link to comment
pejczi Posted July 19, 2013 Author Share Posted July 19, 2013 Ok, last trouble got elminated, now i've got other - the vehicle of spectator doesn't get blown. function killTeam () local theTeam = getTeamFromName ( "SPECTATORS" ) if ( theTeam ) then local players = getPlayersInTeam ( theTeam ) for key, player in ipairs ( players ) do local theVehicle = getPedOccupiedVehicle ( player ) if ( theVehicle ) then blowVehicle ( source ) end end end end I know, that the argument of blowVehicle is invalid, but i have no idea which do I have to put in. try using destroyElement But it's for race gamemode ; if the vehicle will get destroyed, then whole gamemode is getting bugged. Link to comment
Jaysds1 Posted July 19, 2013 Share Posted July 19, 2013 Well, it should work if you destroy the vehicle. Link to comment
pejczi Posted July 19, 2013 Author Share Posted July 19, 2013 Jesus, I forgot to put eventhandler - when I put just "onRaceStateChanging", it has blown my car before counting - when i put if if (state == "Running") , then it doesn't blow me. ////No help needed, i found out a problem. I had to put addEvent 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