Georges1999 Posted December 18, 2017 Share Posted December 18, 2017 (edited) Hello, i was trying to create a script and i got stuck somewhere inside it. the script's idea is to allow an admin to change a player's nickname. outputDebugString("line 1 is good") function asetnick1(playerSource, commandName, thePlayer, newname) local pName = getPlayerName (playerSource) local sPName = setPlayerName (playerSource, newname) local accName = getAccountName( getPlayerAccount ( playerSource ) ) if (playerSource) then if isObjectInACLGroup("user." ..accName,aclGetGroup( "Admin" ) ) then if isObjectInACLGroup("user." ..accName,aclGetGroup( "Console" ) ) then outputDebugString("line 9 is working") else outputChatBox("You're not an Admin!",playerSource, 255, 0, 0) end end end end addCommandHandler("changenick", asetnick1) i don't know where i went wrong cause my debugscript wasn't showing any errors/warnings. so any help? i didn't know how to express myself by writing the first two variables into the code. Edited December 18, 2017 by Georges1999 Link to comment
koragg Posted December 18, 2017 Share Posted December 18, 2017 (edited) Try this. Not tested though. Server-side: function changePlayerNick(player, command, target, newNick) local account = getPlayerAccount(player) local accName = getAccountName(account) if account and isGuestAccount(account) then return end if isObjectInACLGroup("user." ..accName, aclGetGroup("Admin")) then if not target or not newNick then outputChatBox("Correct command is /changenick player nick.", player, 255, 0, 0, true) return end local targetPlayer = getPlayerFromPartialName(target) if not targetPlayer then outputChatBox("No such player found.", player, 255, 0, 0, true) return end outputChatBox("You changed #FFFFFF"..getPlayerName(targetPlayer).."#00FF00's nickname to #FFFFFF"..newNick.."#00FF00.", player, 0, 255, 0, true) outputChatBox("Your nickname was changed from #FFFFFF"..getPlayerName(targetPlayer).."#00FF00 to #FFFFFF"..newNick.."#00FF00.", player, 0, 255, 0, true) setPlayerName(targetPlayer, newNick) else outputChatBox("You're not an Admin!", player, 255, 0, 0, true) return end end addCommandHandler("changenick", changePlayerNick) function getPlayerFromPartialName(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 Edited December 18, 2017 by koragg 1 Link to comment
koragg Posted December 18, 2017 Share Posted December 18, 2017 On line 18 put "targetPlayer" instead of "player" in the outputChatBox. My bad. Link to comment
Georges1999 Posted December 19, 2017 Author Share Posted December 19, 2017 Thanks for the help. 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