General > Developers Corner

Help with custom ulx command

(1/2) > >>

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

MrPresident:
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 }

dankpepe:
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)

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

roastchicken:
The 'S' in SetRPName should not be capitalized. Player:setRPName()

Navigation

[0] Message Index

[#] Next page

Go to full version