General > Developers Corner
My custom chat command does not work :(
fubar:
--- Code: ---local CATEGORY_NAME = "Hepful Commands"
function ulx.rights(ply)
ply:Say( "You have the right to remain silent, anything you say or do", teamOnly=false )
ply:Say( "Will be held against you in a court of law. Do you understant", teamOnly=false )
ply:Say( "these rights I have read to you? And do you wish to speak with me?", teamOnly=false )
end
local rights = ulx.command( "Police Commands", "ulx rights", ulx.rights, "!rights" )
rights:defaultAccess( ULib.ACCESS_ALL )
rights:help( "Gives rights" )
function ulx.raid(ply)
ply:Say( "/advert Prepare to be raided!", teamOnly=false )
end
local raid = ulx.command( CATEGORY_NAME, "ulx raid", ulx.raid, "!raid" )
raid:defaultAccess( ULib.ACCESS_ALL )
raid:help( "Gives raid" )
function ulx.carjack(ply)
ply:Say( "/advert Prepare to be carjacked!", teamOnly=false )
end
local carjack = ulx.command( CATEGORY_NAME, "ulx carjack", ulx.carjack, "!carjack" )
carjack:defaultAccess( ULib.ACCESS_ALL )
carjack:help( "Gives carjack" )
function ulx.kidnap(ply)
ply:Say( "/advert Prepare to be kidnaped!", teamOnly=false )
end
local kidnap = ulx.command( CATEGORY_NAME, "ulx kidnap", ulx.kidnap, "!kidnap" )
kidnap:defaultAccess( ULib.ACCESS_ALL )
kidnap:help( "Gives kidnap" )
--- End code ---
None of them work
JamminR:
Are these running from server? "Say" is a server side command.
You should be getting lua errors at startup of server attempting to load the file, or when running the commands.
They will be helpful in telling you why they aren't working.
fubar:
No lua errors :I
Vaporouscreeper:
I see what you did
you have entity as "ply" you need it as "calling_ply"
Timmy:
--- Quote from: fubar on June 08, 2018, 02:01:33 PM ---No lua errors :I
--- End quote ---
Where did you place your Lua file? I ran your code and received the following error:
--- Code: ---[ERROR] addons/ulx-test/lua/ulx/modules/sh/fubar.lua:3: ')' expected near '='
1. unknown - addons/ulx-test/lua/ulx/modules/sh/fubar.lua:0
--- End code ---
--- Quote from: Vaporouscreeper on June 10, 2018, 02:26:44 AM ---I see what you did
you have entity as "ply" you need it as "calling_ply"
--- End quote ---
While it might be a good idea to stick to conventions, the parameter passing mechanism in Lua is positional. The first parameter in a ULX command callback will always be the player that called the command. The name of the parameter doesn’t influence this.
Navigation
[0] Message Index
[#] Next page
Go to full version