ULX

Author Topic: Command for ulx bring all  (Read 4467 times)

0 Members and 1 Guest are viewing this topic.

Offline sodak

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Command for ulx bring all
« on: September 23, 2016, 03:56:26 PM »
Hey i need a command when i type in !bringall it teleports all players to me like ulx bring *  but this dont work.

Is there any quick and dirty code for this?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Command for ulx bring all
« Reply #1 on: September 24, 2016, 08:24:02 AM »
I've considered something like this in the past, but there's a fundamental problem: How do you find positions for every player such that they aren't inside of walls, props, each other, etc?

It may be feasible, but it'd require a good bit of work. So, no, there's no "quick 'n' dirty" method of getting this done right.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command for ulx bring all
« Reply #2 on: September 24, 2016, 11:31:30 AM »
Bytewave, probably the easiest would be to check every ten degrees around the "bringer" at 50 units out (or whatever), then every five degrees around the "bringer" at 100 units out, then every two and a half degrees at 200 units out, etc. Using hull traces, this should work even in a tight hallway as long as you have enough free space within line-of-sight. You could give up on a full trace and just make sure there's enough room for the player at the destination, at the risk of the person being brought ending up on the other side of a wall from the person they were brought to.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Command for ulx bring all
« Reply #3 on: September 24, 2016, 06:55:57 PM »
* JamminR imagines changing PlayerArg to PlayersArg and adding a for players.getall statement in the code just to see if the Gmod map point swirls into a black hole gravity well.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Command for ulx bring all
« Reply #4 on: October 31, 2016, 09:20:57 AM »
Made a command that can bring multiple players. I had never really used vectors, angles or traces before. This was a great way to experiment with them. :)

I hope these bots brought their towels! ;D


I made sure it can handle smaller spaces.




Attached the command in addon format, in case anyone wants the code.

Usage: ulx tbring <players> [<number: 33<=x<=200, default 50>] - Teleports target(s) to you. (say: !tbring)

The second, optional, parameter can be used to control the space between each player:
Cram players in like sardines: !tbring * 33
Or, give them lots of free space: !tbring * 200

Happy halloween!

Edit: Updated command to remove an unnecessary trace.
« Last Edit: May 31, 2018, 02:19:37 AM by Timmy »

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Command for ulx bring all
« Reply #5 on: October 31, 2016, 10:13:47 AM »
Nice work, Timmy! ;D
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command for ulx bring all
« Reply #6 on: November 12, 2016, 02:46:18 PM »
Timmy's new function is now built into ULX (GitHub only until release). :)
Experiencing God's grace one day at a time.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Command for ulx bring all
« Reply #7 on: November 13, 2016, 07:27:56 AM »
Yay, awesome!

@Megiddo: It's really cool to see the changes you made. I particularly like how you generate the spiral grid... so much more efficient. I can tell that I still have a lot of room for improvement. Do you perhaps have any feedback? Was my code hard to understand? :)

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command for ulx bring all
« Reply #8 on: November 13, 2016, 02:22:59 PM »
Sure, happy to provide feedback.

The main changes I made are as follows (in order of subjective importance):
  • As you noted, the spiral grid function. Your method worked great, but as the grid grew larger required a lot of inner-loop skips that weren't necessary. Additionally, since such a grid only needs to be generated once, I did so at load time (rather than each time someone is brought) and cached it. Also, if only one person was being brought, I wanted the algorithm to try a center position first.
  • Along the lines of the above, by removing a more complicated algorithm from inside the command function, it's a lot easier to follow the flow of the command function. Even if I had kept your algorithm, I would have made that part its own function for clarity.
  • I wasn't sure why you chose TraceHull instead of TraceEntity (more efficient? more familiar?), but I went with TraceEntity for consistency with the other teleport functions and since it's worked well for us up to this point.
  • Instead of calling player.GetAll() a bunch of times inside the function, I built the list I needed only once (the list was also a little different from yours).
  • You had an unnecessary Normalize() function in there.
Some of these are merely preferences, but I always prefer shorter, clearer code where possible. I add efficiencies where it does not overly damage the first two objectives (unless it's in a critical section of code, like a hook library). An excellent book along these lines is Clean Code by Robert Martin.

Your code was not terribly difficult to understand, especially given that it wasn't that many lines of code and I understood the overall trajectory of what you were trying to accomplish. I would suggest comments in the more "sticky" spots, though -- both for yourself and others. For example, it took me a while to work out how I was going to accomplish the grid function, and I added comments which explain what's being generated where.
Experiencing God's grace one day at a time.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Command for ulx bring all
« Reply #9 on: November 14, 2016, 09:53:52 AM »
I really appreciate the feedback. These are things I will keep in mind going forward. I've seen 'Clean Code' in my school library, will definitely check out the book. Thank you!
« Last Edit: November 14, 2016, 12:13:51 PM by Timmy »