ULX

Author Topic: My custom chat command does not work :(  (Read 2684 times)

0 Members and 1 Guest are viewing this topic.

Offline fubar

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
My custom chat command does not work :(
« 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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: My custom chat command does not work :(
« Reply #1 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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline fubar

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: My custom chat command does not work :(
« Reply #2 on: June 08, 2018, 02:01:33 PM »
No lua errors :I

Offline Vaporouscreeper

  • Newbie
  • *
  • Posts: 22
  • Karma: 0
    • TheBox steam group
Re: My custom chat command does not work :(
« Reply #3 on: June 10, 2018, 02:26:44 AM »
I see what you did
you have entity as "ply" you need it as "calling_ply"
I'm a Moderator on a server called TheBox. and i'm mostly active on it

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: My custom chat command does not work :(
« Reply #4 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.

Offline fubar

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: My custom chat command does not work :(
« Reply #5 on: June 12, 2018, 12:17:39 PM »
yes I am getting that same error

addons/custom/lua/ulx/modules/sh/u_custom.lua

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: My custom chat command does not work :(
« Reply #6 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