Ulysses

General => Developers Corner => Topic started by: fubar on June 07, 2018, 10:47:19 AM

Title: My custom chat command does not work :(
Post by: fubar on June 07, 2018, 10:47:19 AM
Code: [Select]
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" )

None of them work
Title: Re: My custom chat command does not work :(
Post by: JamminR on June 07, 2018, 07:27:30 PM
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.
Title: Re: My custom chat command does not work :(
Post by: fubar on June 08, 2018, 02:01:33 PM
No lua errors :I
Title: Re: My custom chat command does not work :(
Post by: 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"
Title: Re: My custom chat command does not work :(
Post by: Timmy on June 10, 2018, 10:39:52 AM
No lua errors :I

Where did you place your Lua file? I ran your code and received the following error:
Code: [Select]
[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

I see what you did
you have entity as "ply" you need it as "calling_ply"
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.
Title: Re: My custom chat command does not work :(
Post by: fubar on June 12, 2018, 12:17:39 PM
yes I am getting that same error

addons/custom/lua/ulx/modules/sh/u_custom.lua
Title: Re: My custom chat command does not work :(
Post by: Timmy on June 12, 2018, 01:27:38 PM
The function signature for Player:Say:
Code: [Select]
Player:Say( string text, boolean teamOnly=false )
When a parameter is followed by an equal sign and a value (e.g. "teamOnly=false"), that value is regarded as the default value. As a result, the second parameter in Player:Say defaults to false.

If you don’t want to send the message in team chat, you can write:
Code: [Select]
ply:Say( "We were bested. So be it.", false )or
Code: [Select]
ply:Say( "We were bested. So be it." )
If you do want to send the message in team chat, you must set the second parameter to true:
Code: [Select]
ply:Say( "We were bested. So be it.", true )
The following is invalid:
Code: [Select]
ply:Say( "We were bested. So be it.", teamOnly=false ) -- invalid