• Print

Author Topic: Ulx command help  (Read 5099 times)

0 Members and 1 Guest are viewing this topic.

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Ulx command help
« on: November 04, 2014, 04:14:49 pm »
Hello i have a quick question.....

How would i make a custom command in the ulx menu that could send people to a link in the steam menu?


Also could someone teach me this instead of posting the code? THX!
 
hope you get back to me!

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ulx command help
« Reply #1 on: November 04, 2014, 04:45:50 pm »
Is it just the part about opening the URL that you need help with
Or do you not know how to create a ULX command

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Ulx command help
« Reply #2 on: November 05, 2014, 12:41:48 pm »
i need help with EVERYTHING lol ya both of that  :-[

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ulx command help
« Reply #3 on: November 05, 2014, 02:08:33 pm »
Okay

Well to create a ULX command you need to create a function and then some other stuff below it that actually adds it to ULX (I don't know what to call it so lets call it some other stuff haha)

Here's how you would do that (This does not open the URL)

Code: Lua
  1. function ulx.NameOfFunctionHere( calling_ply, target_ply )
  2.         WhatTheFunctionDoes
  3. end
  4. local WhatYouCalledYourFunction = ulx.command ( "NameOfCategoryHere", "ulx WhatYouWantTheConsoleCommandToBe", ulx.WhatYouCalledYourFunction, "!WhatYouWantYourChatCommandToBe", true )
  5. WhatYouCalledYourFunction:defaultAccess( ULib.ACCESS_ALL )
  6. WhatYouCalledYourFunction:help( "This describes your ULX command" )

Now to explain that:
Line 1: function ulx.NameOfFunctionHere( calling_ply, target_ply )
function tells the server to create a new function
ulx.NameOfFunctionHere is the exact of the name of the function, you'll need to use this name later
( calling_ply, target_ply ) is what the function "returns". This basically means that the function can use these two players in its code. "calling_ply" is the player that ran the command, and "target_ply" is the player that the command is being run on

Line 2: WhatTheFunctionDoes
This is all of the code that is inside of the function. It's the code that's ran when the function is called. I'll get into this later when I'm talking about the URL thing

Line 3: end
This ends the function

Line 4: local WhatYouCalledYourFunction = ulx.command ( "NameOfCategoryHere", "ulx WhatYouWantTheConsoleCommandToBe", ulx.WhatYouCalledYourFunction, "!WhatYouWantYourChatCommandToBe", true )
"local WhatYouCalledYourFunction" means put here what you put on line 1 after ulx. -- For example, if your line 1 read "function ulx.NameOfFunctionHere( calling_ply, target_ply )", then the beginning of line 4 would read "local NameOfFunctionHere"
" = ulx.command" means that you're telling the server that WhatYouCalledYourFunction is a ulx command
"( "NameOfCategoryHere"," means whatever you put inside of those quotes is the name of the category that this command will appear in when you open the xgui. If the category does not already exist, it'll create one for you.
""ulx WhatYouWantTheConsoleCommandToBe", " means that everything inside of those quotes will run this ULX command when typed into console
"ulx.WhatYouCalledYourFunction" means put here whatever you called your function. If your line 1 reads "function ulx.NameOfFunctionHere( calling_ply, target_ply )" then make this string say "ulx.NameOfFunctionHere" --DO NOT INCLUDE THE () OR ANYTHING INSIDE OF THEM
"!WhatYouWantYourChatCOmmandToBe" means that whatever is inside of these quotes will run the command when typed in player chat. For example, you could do "!ourwebsite"
"true" means that when a player types the command in chat, the message will not be shown in chat. In other words, you won't see anyone saying "!ourwebsite" (using the example from above). You could also set this to false if you're fine w/ seeing the command when you or other players type it

Line 5: WhatYouCalledYourFunction:defaultAccess( ULib.ACCESS_ALL )
"WhatYouCalledYourFunction" is exactly what you named your function on line 1 but minus the "ulx.", the (), and everything inside of the ()
":defaultAccess( ULib.ACCESS_ALL ) " means that by default, all players will have access to this command. You can remove the permission for this command for certain ranks or players ingame

Line 6: WhatYouCalledYourFunction:help( "This describes your ULX command" )
"WhatYouCalledYourFunction" is exactly what you named your function on line 1 but minus the "ulx.", the (), and everything inside of the ()
":help( "This describes your ULX command" )" means that when you type "ulx help" into the console and all of the commands are shown along with what they do, what it said inside of these quotes will be the description that is shown in console for this command

Forgot to mention this earlier: in this case, you wouldn't really need the target_ply in the function. I'm making it so when you type "!mywebsite" it has you open the link, so you don't have to do "!mywebsite MyNameHere"


Now onto making the function do things:
First, go ahead and remove "WhatTheFunctionDoes" if you copy and pasted the code into the file
Once you've done that, put your cursor at the end of the text at line 1 and hit enter so that your line two moves to line three and you're now in line 2
calling_ply is going to be what you use in place of ply
As I said before, calling_ply is the player that ran the command
so you'd start like this:
calling_ply:
Next we add a function to the end of that so the server knows what to do to the payer
Now edit your line two so after calling_ply: it will say SendLua("gui.OpenURL('http://MyWebsiteHere.com')")

After giving the function a proper name and removing target_ply, your first three lines should read something like this
Code: Lua
  1. function ulx.ourwebsite( calling_ply )
  2.         calling_ply:SendLua("gui.OpenURL('[url]http://MyWebsiteHere.com[/url]')")
  3. end

After doing that and filling in your last three lines, your final code should read something like this
Code: Lua
  1. function ulx.ourwebsite( calling_ply )
  2.         calling_ply:SendLua("gui.OpenURL('[url]http://MyWebsiteHere.com[/url]')")
  3. end
  4. local ourwebsite = ulx.command( "Links", "ulx ourwebsite", ulx.ourwebsite, "!ourwebsite" )
  5. ourwebsite:defaultAccess( ULib.ACCESS_ALL )
  6. ourwebsite:help( "Opens our website" )

That's untested code, by the way
Unless I put a typo somewhere and didn't notice, it should work, besides the fact that MyWebsiteHere.com probably isn't a real website :P
« Last Edit: November 05, 2014, 02:23:39 pm by Zmaster »

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Ulx command help
« Reply #4 on: November 05, 2014, 02:19:21 pm »
Thanks!!! so should i just copy that last code and make a new text file?

sorry but could you just make a code that opens google and i can edit that from there? or maybe set up like a skype call and explain that better? idk

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ulx command help
« Reply #5 on: November 05, 2014, 02:25:37 pm »
SMF keeps adding in [ url ] and [ / url ] to my code
Copy and paste the last section of code I have in that post but remove the url forum code
All you have to do to change it to a link of your choice is replace "http://MyWebsiteHere.com" with something else

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Ulx command help
« Reply #6 on: November 08, 2014, 05:46:46 am »
Im really sorry but all that you wrote is still hard to understand. i was thinking we could do a skype call....

pm me if you like this idea. Otherwise please post the full code of that and ill just edit it to my likings

Thanks!

  • Print