• Print

Author Topic: ULX Custom command to set a var  (Read 5891 times)

0 Members and 1 Guest are viewing this topic.

Offline Best Wukong NA

  • Newbie
  • *
  • Posts: 3
  • Karma: 2
ULX Custom command to set a var
« on: November 12, 2015, 10:19:45 am »
I'm not sure if this should be posted in developers corner or general chat but I think this is the right place.
I'm trying to make a custom command that sets the rank of a player. The rank NWInt is ("playerLvl")
How do I make a number input that sets the NWInt("playerLvl") to the number thats chosen?
I've already looked at the ulx slap as an example but I couldn't find it.

Code: [Select]
local CATEGORY_NAME = "BFA"

function ulx.rank ( calling_ply, target_ply, level )
local affected_plys = {}
for i=1, #target_plys do
   local v = target_plys[ i ]
   v:SetNWInt("playerLvl",level)
   table.insert( affected_plys, v )

   ulx.fancyLogAdmin(calling_ply, true, "#A has changed the rank of #T",target_ply)
   end
end

local rank = ulx.command (CATEGORY_NAME,"ulx rank",ulx.rank,"!rank",true)
rank:addParam{type=ULib.cmds.PlayerArg}
rank:defaultAccess(ULib.ACCESS_ADMIN)
rank:help("Sets the rank of a player")
« Last Edit: November 12, 2015, 10:32:33 am by Best Wukong NA »

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: ULX Custom command to set a var
« Reply #1 on: November 12, 2015, 12:55:32 pm »
I'm not sure if this should be posted in developers corner or general chat but I think this is the right place.
I'm trying to make a custom command that sets the rank of a player. The rank NWInt is ("playerLvl")
How do I make a number input that sets the NWInt("playerLvl") to the number thats chosen?
I've already looked at the ulx slap as an example but I couldn't find it.

Code: [Select]
local CATEGORY_NAME = "BFA"

function ulx.rank ( calling_ply, target_ply, level )
local affected_plys = {}
for i=1, #target_plys do
   local v = target_plys[ i ]
   v:SetNWInt("playerLvl",level)
   table.insert( affected_plys, v )

   ulx.fancyLogAdmin(calling_ply, true, "#A has changed the rank of #T",target_ply)
   end
end

local rank = ulx.command (CATEGORY_NAME,"ulx rank",ulx.rank,"!rank",true)
rank:addParam{type=ULib.cmds.PlayerArg}
rank:defaultAccess(ULib.ACCESS_ADMIN)
rank:help("Sets the rank of a player")
I'm not the best at this, but I do not think you add spaces between the ulx.command and function, etc.
Code: Lua
  1. local CATEGORY_NAME = "BFA"
  2.  
  3. function ulx.rank( calling_ply, target_ply, level ) -- Level is defined! EDIT: I mis read down below, v:SetNWInt has a level.
  4.     local affected_plys = {}
  5.     for i == 1, #target_plys do -- Double equals, one equals means its setting the variable, unless I'm mistaken as I have not used for loops yet so if i = 1 is correct, then my bad.
  6.         local v = target_plys[ i ]
  7.         v:SetNWInt( "playerLvl",level )
  8.         table.insert( affected_plys, v )
  9.         ulx.fancyLogAdmin( calling_ply, true, "#A has changed the rank of #T", target_ply ) -- True makes this silent, do you want this?
  10.     end
  11. end
  12. local rank = ulx.command( CATEGORY_NAME, "ulx rank", ulx.rank, "!rank", true ) -- I'm not sure what the true is, is this valid for ULX? Also, give your info some breathing room! Add a space between the comma :D
  13. rank:addParam{ type=ULib.cmds.PlayerArg }
  14. rank:defaultAccess( ULib.ACCESS_ADMIN )
  15. rank:help( "Sets the rank of a player" )
  16.  
« Last Edit: November 12, 2015, 01:01:08 pm by WispySkies »

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: ULX Custom command to set a var
« Reply #2 on: November 12, 2015, 01:46:16 pm »
I'm not the best at this, but I do not think you add spaces between the ulx.command and function, etc.
Code: Lua
  1. local CATEGORY_NAME = "BFA"
  2.  
  3. function ulx.rank( calling_ply, target_ply, level ) -- Level is defined! EDIT: I mis read down below, v:SetNWInt has a level.
  4.     local affected_plys = {}
  5.     for i == 1, #target_plys do -- Double equals, one equals means its setting the variable, unless I'm mistaken as I have not used for loops yet so if i = 1 is correct, then my bad.
  6.         local v = target_plys[ i ]
  7.         v:SetNWInt( "playerLvl",level )
  8.         table.insert( affected_plys, v )
  9.         ulx.fancyLogAdmin( calling_ply, true, "#A has changed the rank of #T", target_ply ) -- True makes this silent, do you want this?
  10.     end
  11. end
  12. local rank = ulx.command( CATEGORY_NAME, "ulx rank", ulx.rank, "!rank", true ) -- I'm not sure what the true is, is this valid for ULX? Also, give your info some breathing room! Add a space between the comma :D
  13. rank:addParam{ type=ULib.cmds.PlayerArg }
  14. rank:defaultAccess( ULib.ACCESS_ADMIN )
  15. rank:help( "Sets the rank of a player" )
  16.  
Irrelevant, brackets are brackets. The spacing between a function and a bracket doesn't matter.
Once you get to know me, you'll find you'll have never met me at all.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: ULX Custom command to set a var
« Reply #3 on: November 12, 2015, 01:56:45 pm »
So a space between here works (The bolded, underlined, italicized "a")? function ulx.CMDa(actually arguments)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Custom command to set a var
« Reply #4 on: November 12, 2015, 03:20:55 pm »
Wispy, he's got more issue than your small concern. Again, you're trying to argue a tiny thing with a lack of experience.
Yes, it should work.

Caustic, I'm going to only outline some major notes here, not do like many others and totally re-write the code and post it.
One, I'm lazy that way.
Two, I learn better by trying to learn from key points than someone just posting some finished project in front of me that didn't show me how to get there.
I'm in hopes you'll be the same. Work from the information given, see new errors, fix what errors you can/understand, go from there.

1) Your command object setup - you'll need another addParam adding a number, if that's indeed what 'level' ranking is, just a number/integer input. ulx slap is a perfect example showing how to add a number.
2) Your command object setup - Ulib.cmds.PlayerArg is a SINGLE player selection/input that expects a single player object target, and, you name your variable in the function as it's passed as though it's going to be single (target_ply), BUT, you then take code from ?somewhere? that loops through an expected table as though you were using Ulib.cmds.PlayersArg.
Pick one or the other. If single, no loop needed.
If multiple targets, do the loop.
3) Well, #2 really defines this. You're currently looping a single player object.
More will come as you decide your choices of multi or single target.



"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: ULX Custom command to set a var
« Reply #5 on: November 12, 2015, 03:46:26 pm »
Wispy, he's got more issue than your small concern. Again, you're trying to argue a tiny thing with a lack of experience.
Yes, it should work.
I'm not trying to argue, I just want to continue trying out new things. I did not know that it would work, and to me it seemed like it didnt. My bad, but in the benefit of you telling me I now know, so thanks :3

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: ULX Custom command to set a var
« Reply #6 on: November 12, 2015, 11:14:08 pm »

Caustic, I'm going to only outline some major notes here, not do like many others and totally re-write the code and post it.

I didn't recode it, I just quoted.
Once you get to know me, you'll find you'll have never met me at all.

Offline Best Wukong NA

  • Newbie
  • *
  • Posts: 3
  • Karma: 2
Re: ULX Custom command to set a var
« Reply #7 on: November 13, 2015, 12:18:08 am »
It worked! Thanks guys.

And no I didn't really plan on getting a code written for me, I need to learn it anyway because I'm making more of this kinda stuff for my gamemode.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Custom command to set a var
« Reply #8 on: November 13, 2015, 02:18:34 pm »
Sorry then, my 'heres what I see' should have been aimed at Best Wukong NA then.
Glad you got it working Wukong.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print