• Print

Author Topic: Help with command aliases  (Read 6353 times)

0 Members and 1 Guest are viewing this topic.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Help with command aliases
« on: August 14, 2016, 05:17:54 pm »
This is solved, I was using symbolic links and for some reason the file disappeared from one and only one of the servers.

I've been working on improving my UI/UX and one of the things I've been doing is adding command aliases. Adding easy to remember, short chat commands to otherwise hard to remember, long commands that have to be run through the console.

Code: Lua
  1.  function ulx.models( calling_ply )
  2.  
  3. calling_ply:ConCommand( "playermodel_selector" )
  4.  
  5. end
  6. local models = ulx.command( "Aliases", "ulx models", ulx.models, { "!playermodel", "!pmodel", "!pmodels", "!playermodels", "!models" } )
  7. models:defaultAccess( ULib.ACCESS_ALL )
  8. models:help( "Opens the player model selector" )

This example is designed to work with Enhanced Playermodel Selector and it works flawlessly.

I'm trying to make a !kill/ !suicide command so that users that don't know how to use the console can just run this chat command and get the same effect:

Code: Lua
  1. function ulx.killme( calling_ply )
  2.  
  3.   calling_ply:ConCommand( "kill" )
  4.  
  5. end
  6. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill", "!suicide", "/kill", "/suicide", "!killme" } )
  7. killme:defaultAccess( ULib.ACCESS_ALL )
  8. killme:help( "Commits suicide" )

This one just doesn't work and I can't figure out why.

I've also tried using:
calling_ply:kill
ply:ConCommand( "kill" )
RunConsoleCommand( "kill" ) (oops it runs through server console)

What's the right way to get the !kill command to work as intended?
« Last Edit: August 19, 2016, 01:41:21 pm by Chiller252 »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #1 on: August 14, 2016, 05:19:42 pm »
http://wiki.garrysmod.com/page/Player/Kill

However, I'm surprised that the current one isn't working. Here it has the same thing.
« Last Edit: August 14, 2016, 05:24:20 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #2 on: August 14, 2016, 05:27:01 pm »
Code: Lua
  1. function ulx.killme( calling_ply )
  2.  
  3.   Player:Kill()
  4.  
  5. end
  6. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill", "!suicide", "/kill", "/suicide", "!killme" } )
  7. killme:defaultAccess( ULib.ACCESS_ALL )
  8. killme:help( "Commits suicide" )

Code: Lua
  1. addons/aliases/lua/ulx/modules/sh/aliases.lua:40: attempt to index global 'Player' (a function value)

Sorry for my inept ability to use lua, please correct me.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #3 on: August 14, 2016, 05:28:07 pm »
calling_ply is your variable. Lua has no idea what "Player" means in that context. Also, read my edit.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #4 on: August 14, 2016, 05:33:58 pm »
Code: Lua
  1. function ulx.killme( ply )
  2.  
  3.   ply:ConCommand( "kill" )
  4.  
  5. end
  6. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill", "!suicide", "/kill", "/suicide", "!killme" } )
  7. killme:defaultAccess( ULib.ACCESS_ALL )
  8. killme:help( "Commits suicide" )

No errors, but nothing happens.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #5 on: August 14, 2016, 05:35:32 pm »
Because "ply" waits for a targeted person. You had it right in your first one, you just had to change "Player". "calling_ply" will act on the person who called the function. So, you need to have calling_ply as a variable, and to be used in the function.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #6 on: August 14, 2016, 05:39:51 pm »
So I'm back to where I started with:

Code: Lua
  1. function ulx.killme( calling_ply )
  2.  
  3.   calling_ply:ConCommand( "kill" )
  4.  
  5. end
  6. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill", "!suicide", "/kill", "/suicide", "!killme" } )
  7. killme:defaultAccess( ULib.ACCESS_ALL )
  8. killme:help( "Commits suicide" )
  9.  

I'm now noticing this in the in-game console after trying to trigger the command:
Code: Lua
  1. FCVAR_SERVER_CAN_EXECUTE prevented server running command: kill
  2.  

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #7 on: August 14, 2016, 05:42:56 pm »
Try restarting your game. Idk what causes it, but I've noticed that sometimes, too. Restarting fixed it for me.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #8 on: August 14, 2016, 05:48:50 pm »
IDK

Restarting the game and server has yielded no change in results.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #9 on: August 14, 2016, 05:49:27 pm »
Try just using Kill() instead of ConCommand.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #10 on: August 14, 2016, 05:56:25 pm »
omg that seems to work

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with command aliases
« Reply #11 on: August 14, 2016, 05:58:22 pm »
Glad I could help. Hope you learned some things, too. :)
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #12 on: August 16, 2016, 11:33:55 am »
So I've been working at this for quite some time and I get mixed results. Some of the commands work, others don't, some work on other servers.

Here's all of the code I have right now and I've marked ones that don't seem to work on sandbox.

Code: Lua
  1. --Models
  2. function ulx.models( calling_ply )
  3.  
  4.   calling_ply:ConCommand( "playermodel_selector" )
  5.  
  6.  
  7. end
  8. local models = ulx.command( "Aliases", "ulx models", ulx.models, { "!playermodel", "!pmodel", "!pmodels", "!playermodels", "!models" } )
  9. models:defaultAccess( ULib.ACCESS_ALL )
  10. models:help( "Opens the player model selector" )
  11.  
  12. --Thirdperson
  13. function ulx.simplethirdperson( calling_ply )
  14.  
  15.  calling_ply:ConCommand( "simple_thirdperson_menu" )
  16.  
  17. end
  18. local simplethirdperson = ulx.command( "Aliases", "ulx simplethirdperson", ulx.simplethirdperson, {"!thirdperson2", "!3p", "!thirdp", "!3person"} )
  19. simplethirdperson:defaultAccess( ULib.ACCESS_ALL )
  20. simplethirdperson:help( "Opens the Simple ThirdPerson menu" )
  21.  
  22. --Seat Weapons
  23. function ulx.seatweapons( calling_ply )
  24.  
  25.  calling_ply:ConCommand( "weaponseats_toggle" )
  26.  
  27. end
  28. local seatweapons = ulx.command( "Aliases", "ulx seatweapons", ulx.seatweapons, {"!sw", "!seatweapons", "!cc"} )
  29. seatweapons:defaultAccess( ULib.ACCESS_ALL )
  30. seatweapons:help( "Toggles Seat Weapons" )
  31.  
  32. --Dance (not working)
  33. --function ulx.dance( calling_ply )
  34.  
  35. --   calling_ply:ConCommand( "act dance" )
  36.  
  37. --end
  38. --local dance = ulx.command( "Aliases", "ulx dance", ulx.dance, {"!dance", "!dances"} )
  39. --dance:defaultAccess( ULib.ACCESS_ALL )
  40. --dance:help( "Dances" )
  41.                                                                                                                                                                                
  42. --Kill doesn't work on sandbox
  43. function ulx.killme( calling_ply )
  44.  
  45.   calling_ply:Kill()
  46.  
  47. end
  48. local killme = ulx.command( "Aliases", "ulx killme", ulx.killme, { "!kill", "!suicide", "/kill", "/suicide", "!killme" } )
  49. killme:defaultAccess( ULib.ACCESS_ALL )
  50. killme:help( "Commits suicide" )
  51.  
  52. --Website
  53. --function ulx.website( calling_ply )
  54.  
  55. --  gui.OpenURL( "http://chillservers.com/" )
  56.  
  57. --end
  58. --local website = ulx.command( "Aliases", "ulx website", ulx.website, { "!website", "!homepage" } )
  59. --website:defaultAccess( ULib.ACCESS_ALL )
  60. --website:help( "Opens Website" )
  61.  
  62. --cac doesn't work on sandbox
  63. function ulx.cac( calling_ply )
  64.  
  65.   calling_ply:ConCommand( "+cac_menu" )
  66.   calling_ply:ConCommand( "ulx cac" )
  67.  
  68.  
  69. end
  70. local cac = ulx.command( "Aliases", "ulx cac", ulx.cac, { "!cac", "!cake", "!anticheat", "!cheat" } )
  71. cac:defaultAccess( ULib.ACCESS_ALL )
  72. cac:help( "Opens the cac anticheat menu" )
  73.  
  74. --toolsearch doesn't work
  75. function ulx.search( calling_ply )
  76.  
  77.   calling_ply:ConCommand( "tool_search" )
  78.  
  79.  
  80. end
  81. local search = ulx.command( "Aliases", "ulx search", ulx.search, { "!search", "!tools" } )
  82. search:defaultAccess( ULib.ACCESS_ALL )
  83. search:help( "Opens the tool search menu" )
  84.  
  85. --Radial doesn't work
  86. function ulx.radial( calling_ply )
  87.  
  88.   calling_ply:ConCommand( "+gb-radial" )
  89.  
  90.  
  91. end
  92. local radial = ulx.command( "Aliases", "ulx radial", ulx.radial, { "!radial", "!rad" } )
  93. radial:defaultAccess( ULib.ACCESS_ALL )
  94. radial:help( "Opens the radial menu" )
  95.  
  96. --onplayx doesn't work
  97. function ulx.onplayx( calling_ply )
  98.  
  99.   calling_ply:ConCommand( "playx_enabled 1" )
  100.  
  101.  
  102. end
  103. local onplayx = ulx.command( "Aliases", "ulx onplayx", ulx.onplayx, { "!onplayx", "!playxon" } )
  104. onplayx:defaultAccess( ULib.ACCESS_ALL )
  105. onplayx:help( "Enables Playx" )
  106.  
  107. --offplayx doesn't work
  108. function ulx.offplayx( calling_ply )
  109.  
  110.   calling_ply:ConCommand( "playx_enabled 1" )
  111.  
  112.  
  113. end
  114. local offplayx = ulx.command( "Aliases", "ulx offplayx", ulx.offplayx, { "!offplayx", "!playxoff" } )
  115. offplayx:defaultAccess( ULib.ACCESS_ALL )
  116. offplayx:help( "Disables Playx" )
  117.  
  118. --Pac doesn't work
  119. function ulx.pac( calling_ply )
  120.  
  121.   calling_ply:ConCommand( "pac_editor" )
  122.  
  123.  
  124. end
  125. local pac = ulx.command( "Aliases", "ulx pac", ulx.pac, { "!pac3", "!pac" } )
  126. pac:defaultAccess( ULib.ACCESS_ALL )
  127. pac:help( "Opens the PAC editor" )

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Help with command aliases
« Reply #13 on: August 16, 2016, 01:57:59 pm »
I would like to apologize. I was using symbolic links to have the same file run on all the servers and for some reason this one disappeared and only now have I realized it. I feel silly. At least this isn't the Facepunch forums and I won't get banned for taking you down the rabbit hole with me.

  • Print