ULX

Author Topic: Help with custom ulx command  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Help with custom ulx command
« 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.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Help with custom ulx command
« Reply #1 on: May 03, 2016, 06:32:20 PM »
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 }
« Last Edit: May 03, 2016, 06:34:53 PM by MrPresident »

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Help with custom ulx command
« Reply #2 on: May 03, 2016, 06:55:32 PM »
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)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Help with custom ulx command
« Reply #3 on: May 03, 2016, 07:21:15 PM »
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.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with custom ulx command
« Reply #4 on: May 03, 2016, 07:39:35 PM »
The 'S' in SetRPName should not be capitalized. Player:setRPName()
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Help with custom ulx command
« Reply #5 on: May 03, 2016, 07:56:28 PM »
omfg i love you so much

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Help with custom ulx command
« Reply #6 on: May 03, 2016, 08:00:29 PM »
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

Code: [Select]
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" )