• Print

Author Topic: ulx cloak at the start of the round  (Read 4958 times)

0 Members and 1 Guest are viewing this topic.

Offline ozzyos2009

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
ulx cloak at the start of the round
« on: January 24, 2018, 01:32:22 pm »
I'm making a custom round on TTT that'll cloak traitors. I've tried using ply:concommand, RunConsoleCommand etc.
Wasn't working so I looked over at the ULIB for invisible and I just don't understand it.
Is there a simple way to make traitors cloaked?

Something that would look like this:
Code: [Select]
for _,ply in pairs(player.GetAll() ) do
     if ply:GetRole() == ROLE_TRAITOR then
           v:ConCommand("ulx", "cloak", "^", 225)
     end
end

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: ulx cloak at the start of the round
« Reply #1 on: January 24, 2018, 09:14:01 pm »
just call ULib.invisible on the player.

Here is the documentation. http://ulyssesmod.net/docs/files/lua/ulib/server/player-lua.html#invisible

sample code would be something like:

Code: Lua
  1.  
  2. for k, v in pairs( player.GetAll() ) do --This line iterates through the table of all players connected and runs the enclosed command for each player. The player object is stored as 'v'
  3.  
  4.         if v:GetRole() == ROLE_TRAITOR then --This checks to see if the player (stored as v **see above**) has a role of ROLE_TRAITOR and if they do, it will run the code enclosed.
  5.        
  6.                 ULib.invisible( v, true ) --This line sets the player (represented as 'v' **see above**) to invisible. The function is ULib.invisible() the first arguement it takes is the player object (which is v), and the second is a boolean for if they should be invisible or not. true because we want to set them as invisible. Use false if you want to bring them out of invisibility.
  7.        
  8.         end
  9.  
  10. end
  11.  
  12.  

Make sure you read and UNDERSTAND what this code is doing. Don't just copy and use it without learning something. The code you posted is wrong in a lot of ways, and you should see why with my code. I commented each line explaining what it is doing in detail.

Offline ozzyos2009

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ulx cloak at the start of the round
« Reply #2 on: January 25, 2018, 12:10:15 am »
Thanks for the help. End code would be

Code: [Select]
for k,v in pairs (player.GetAll () ) do
     if v:GetRole() == ROLE_TRAITOR then
          ULib.invisible(v, true, 225)
     end
end

May I ask what was wrong? I know the concommand was wrong. v is the player and the command being used is granted to operator by default which would not work. Also using ^ in there was pointless as I already determined v to be the affected ply

It was more so of an example of what I wanted to accomplish.

Thank you for the ulib library, i was searching for invisible in the files themselves

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: ulx cloak at the start of the round
« Reply #3 on: January 25, 2018, 12:48:34 am »
In the code you just posted, you included 225 as the transparency. This will make the player *mostly invisible* as 255 is the max value. Is that what you wanted?

As for your first code example, you were using v: when you never declared v in your code. You did for _, ply in pairs.. which is fine, but then your player object is stored in ply, not v. You kind of mixed two standards which led me to believe that you put that example together by looking at other code, not really understanding what it did. It was close, but wouldn't have worked, which is why I wrote it out and commented it for you.

Offline ozzyos2009

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ulx cloak at the start of the round
« Reply #4 on: January 25, 2018, 10:27:54 am »
 Woops! Didnt realize I did that. I thought  I defined it as v for some reason.

And yes that's want I want to do, I want them to be slightly visible so its not all that difficult to see them close-up.

Thanks again for the help!

  • Print