• Print

Author Topic: ULX RunConsoleCommand Issues  (Read 8258 times)

0 Members and 1 Guest are viewing this topic.

Offline Sgt_Spookington

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
ULX RunConsoleCommand Issues
« on: March 12, 2017, 02:13:54 pm »
Hi there. I have a quick question about a lua script that I wrote using ULX commands.
(Most current stable build of ULX)
(TTT)
Code: Lua
  1. local tab = player.GetAll()
  2. local randomPly = tab[math.random(#tab)]
  3.  
  4.  
  5.  
  6.         print (randomPly)
  7.         PrintMessage( HUD_PRINTTALK, "HIDDEN LOADED")
  8.         --PrintMessage( HUD_PRINTTALK, randomPly)
  9.         RunConsoleCommand ("ulx","csay", randomPly:UserID(), "Has been chosen as the hidden he will be cloaked shortly PREPARE....")
  10.         RunConsoleCommand ("ulx", "cloak", randomPly:UserID(), "105")
  11.         RunConsoleCommand ("ulx", "csay", randomPly:UserID(), "Now wears a cloak as dense as the night")
  12.         RunConsoleCommand ("ulx", "strip", randomPly:UserID())
  13.         RunConsoleCommand ("ulx", "give", randomPly:UserID(), "weapon_zm_improvised")
  14.         RunConsoleCommand ("ulx","hp", randomPly:UserID(), "250")      


This script is supposed to set up a gamemode like the hidden. Here's the problem, it doesn't work. I think this is due to the RandomPly. There aren't any errors in console and the script loads the first CSAY line by saying something like
Quote
91.00 has been chosen as the hidden
The rest of the commands aren't running on the user. Any tips? I'm new to LUA and Gmod Coding.

Thanks for your help

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX RunConsoleCommand Issues
« Reply #1 on: March 12, 2017, 03:29:57 pm »
Are you _sure_ there are no errors, even in the server's console (not game client)?
Have you tried performing any ulx commands on a player's userid from server console?

Also, math.random needs two arguments, or it will exclude the number being passed to it.
So, if you use math.random(player.getAll()), it's going to pick a random number between 0 and (number of players minus 1).
See https://www.gammon.com.au/scripts/doc.php?lua=math.random
« Last Edit: March 12, 2017, 03:33:00 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Sgt_Spookington

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: ULX RunConsoleCommand Issues
« Reply #2 on: March 12, 2017, 03:59:18 pm »
Code: [Select]
17:55:59 Round proper has begun...
 
Running script hidden.lua...
Player [5][aceshadow]
 
17:56:03 rcon from "208.146.44.1:59974": command "lua_openscript hidden.lua"
17:56:13 00:14.14 - KILL: Stewie2k's Little Brother [innocent] killed aceshadow [innocent]

This is the output of the script from console. No errors but nothing seems to happen with the player who is targeted.

As for the randomness thing. Im not sure how to make that work better. Should I put a number in those brackets? It seems to return a new user every time its executed.
« Last Edit: March 12, 2017, 04:00:54 pm by Sgt_Spookington »

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: ULX RunConsoleCommand Issues
« Reply #3 on: March 12, 2017, 05:45:43 pm »
Is the Script Client Side or Server Side. Cause if its clientside first it would not work cause everyone would get a different Random player, then your PPL would need permissions to the commands etc.

If its serverside:

I don't know this exactly but I think the console commands does not support the UserID() ( I could be wrong with this so simply try et )
and btw csay does not support an player argument. You can do something like this yourself and you don't need console commands for that.

an Example from my addon:

Code: Lua
  1. --THIS ON THE SERVER
  2. function MSync.Print(ply, col, text)
  3.         if ply.IsValid == nil or not ply:IsValid() then
  4.                 print(text)
  5.         end
  6.         net.Start("MSyncChatPrint")
  7.                 net.WriteColor(col)
  8.                 net.WriteString(text)
  9.         net.Send(ply)
  10. end
  11.  
  12. util.AddNetworkString( "MSyncChatPrint" )
  13.  
  14. --THIS ON THE CLIENT
  15. net.Receive("MSyncChatPrint", function( len, ply )
  16.                 MSync.Chat(net.ReadColor() ,net.ReadString())
  17. end)
  18.  
  19. function MSync.Chat(col, text)
  20.         chat.AddText(Color(255,255,255),"[",Color(120,0,0),"MSync",Color(255,255,255),"]",col,text)
  21. end
  22.  
Thats an bad example i know but my addon uses the chat print also somewhere else on the client ;)

and if you want middle HUD print so badly you can still change the code to support that ;)
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline Sgt_Spookington

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: ULX RunConsoleCommand Issues
« Reply #4 on: March 12, 2017, 06:10:40 pm »
It is Serverside. I posted on facepunch forums and they said that I would have to use userid. Is that true?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX RunConsoleCommand Issues
« Reply #5 on: March 12, 2017, 07:40:34 pm »
I'm 90% sure you can't run our commands from console and feed them userid as input.
Which is why I've asked if you've tried any of those commands from server console to make sure of the 10% uncertainty.

Code: [Select]
local randomPly = tab[math.random(1,#tab)]
I think that would get you 1 to the # of players, including allowing it to pick the last/highest number.

As for what they told you on facepunch, that all depends on what scripts your using.
ULX console commands prefer names.
randomPly:Nick() would likely work better for you, at least, get you farther.

After you get this far though, you really shouldn't use console commands.
As long as your script runs after ULX is loaded, you could use raw functions and just the randomPly player object.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: ULX RunConsoleCommand Issues
« Reply #6 on: March 13, 2017, 08:17:00 am »
but randomPly:Nick() is also stupid .. i mean what if he has a Seperated nickname? RunConsoleCommand is like just entering the command as you give it the parameters in the console so if i would join it would run ( as Example =

ulx cloak [ApHo]Rainbow Dash 155

Which would cause an error cause "Dash" is no valid argument for "ulx cloak".
<- Not sure about that ill test it first
Also csay still does just support 1 argument and that the text which makes the userID() senseless cause it would center print the userid and the other one is considered as extra argument so its going to get ignored

you should replace it like this:

Code: Lua
  1. RunConsoleCommand ("ulx","csay", (randomPly:Nick().."Has been chosen as the hidden he will be cloaked shortly PREPARE...."))
« Last Edit: March 13, 2017, 08:20:00 am by captain1342 »
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX RunConsoleCommand Issues
« Reply #7 on: March 13, 2017, 07:11:37 pm »
captain, step back a few, let the person figure out what works and what doesn't on their own.
I pointed them enough for now, we and they will see where it goes.
Best way to learn is by doing, not having others do it for you.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print