Ulysses
General => Developers Corner => Topic started by: dankpepe on May 03, 2016, 06:09:59 PM
-
Not sure if I'm supposed to post here but I'm having trouble creating a custom ulx command. I have it mostly laid out.
function ulx.rpname( calling_ply, target_ply, name )
if name and name ~= "" then
target_ply:ply:SetRPName(name)
ulx.fancyLogAdmin( calling_ply, true, "#A renamed #T", target_ply )
else
name = nil
end
end
end
local rpname = ulx.command( CATEGORY_NAME, "ulx rpname", ulx.rpname, "!rpname", true )
rpname:addParam{ type=ULib.cmds.PlayerArg }
rpname:defaultAccess( ULib.ACCESS_ADMIN )
rpname:help( "Renames a player" )
I'm assuming the problem is in this line: target_ply:ply:SetRPName(name)
I want it to change the rp name in darkrp, but I'm not sure how to do it. Thanks.
-
Get rid of ply:
It should just be target_ply:SetRPName(name)
Also, it looks like you have an extra 'end'. Remove the end after name = nil
Also, you need to define your name parameter for the command.
Add this line before rpname:defaultAccess( ULib.ACCESS_ADMIN )
rpname:addParam{ type=ULib.cmds.StringArg, hint="Name to rename player to", ULib.cmds.takeRestOfLine }
-
That helped the server recognize it as a command but I'm still getting errors. So far I have:
local CATEGORY_NAME = "Danker"
function ulx.rpname( calling_ply, target_ply, name )
if name and name ~= "" then
target_ply:SetRPName(name)
ulx.fancyLogAdmin( calling_ply, true, "#A renamed #T", target_ply )
else
name = nil
end
ULib.queueFunctionCall( ULib.rpname, target_ply, name, calling_ply )
end
local rpname = ulx.command( CATEGORY_NAME, "ulx rpname", ulx.rpname, "!rpname", true )
rpname:addParam{ type=ULib.cmds.PlayerArg }
rpname:addParam{ type=ULib.cmds.StringArg, hint="Name to rename player to", ULib.cmds.takeRestOfLine }
rpname:defaultAccess( ULib.ACCESS_ADMIN )
rpname:help( "Renames a player" )
I keep getting an error in console that says:
attempt to call method "SetRPName (a nil value)
-
that means the command you're trying to run 'SetRPName' is not valid.
you need to figure out what function you need to run on the player to set their RP name.
Unfortunately, I can't help you there as I have -50% experience with RP.
-
The 'S' in SetRPName should not be capitalized. Player:setRPName() (http://wiki.darkrp.com/index.php/Functions/Player/Server/setRPName)
-
omfg i love you so much
-
Thank you both so much for your help. If anyone else is looking at this later and wanted the finished version here you go:
http://pastebin.com/SzBJ3qkc (http://pastebin.com/SzBJ3qkc)
local CATEGORY_NAME = "Danker"
function ulx.rpname( calling_ply, target_ply, name )
if name then
target_ply:setRPName(name)
ulx.fancyLogAdmin( calling_ply, true, "#A renamed #T", target_ply )
end
ULib.queueFunctionCall( ULib.rpname, target_ply, name, calling_ply )
end
local rpname = ulx.command( CATEGORY_NAME, "ulx rpname", ulx.rpname, "!rpname", true )
rpname:addParam{ type=ULib.cmds.PlayerArg }
rpname:addParam{ type=ULib.cmds.StringArg, hint="Name to rename player to)", ULib.cmds.takeRestOfLine }
rpname:defaultAccess( ULib.ACCESS_ADMIN )
rpname:help( "Renames a player" )