Ulysses
General => Developers Corner => Topic started by: sodak 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?
-
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.
-
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.
-
/me 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.
-
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
(https://timmy.github.io/images/ulx-bring-animation.gif)
I made sure it can handle smaller spaces.
(https://timmy.github.io/images/ulx-bring-packed.png)
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.
-
Nice work, Timmy! ;D
-
Timmy's new function is now built into ULX (GitHub only until release). :)
-
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? :)
-
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 (https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882).
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.
-
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!