[HOWTO] Finding a Random Origin (Scanning)
Before you begin, this tutorial assumes that you are an intermediate to advanced level scripter. Most things to do with any implementations in AMXX will not be explained, and it will assume that you understand everything except for the way to do this itself (wouldn't really be a tutorial, would it?).
What I'm basically going to be explaining is how to find a random origin that is empty and can be used to put something at, do something with, or otherwise use in some way. The most important thing to do is establish a refence point. What are you trying to do? Are you trying to find an origin around a person? Are you trying to find a random place on the map to drop something? For the purpose of this, we will assume the former. This function can be abstracted out quite easily: Code:
This will scan around the user with a radius of Radius units for an empty location. If it doesn't find any, it will return 0, otherwise it will return 1. Num is simply a dummy variable to track how many times it has scanned around the user. It's best to set this to 0. If you want to be sure the user can see it, you can run a trace_line (or TraceLine) between the user and the result. I assume you know how to do this and will not draw it out. Here's an example implementation: Code:
This will find an empty origin around the player, spawn an ent, then set its model and origin to that empty location. Anyway, this may seem pretty simple, but a few people have asked me about how to do it, so I thought I'd write this up. As always, if you have any questions, comments, or whatever else you can think of, feel free to post. |
Re: Finding a Random Origin (Scanning)
WOW! I needed his! Thnx
|
Re: [HOWTO] Finding a Random Origin (Scanning)
Nice Tutorial Hawk552 !!
I used this method in my new Plugin, but i have encountered that the Webcompiler have a problem with random_float() Quote:
Code:
Maybe you can improve my changes!? Because i don't really understand the (-1 * Variable) thingy... If i change random_float(-Radius, Radius) to random_float((-1 * Radius), Radius) where is the difference!?..0o greetz regalis PS: keep up the good work! Your tutorials are very helpfull!!! :) |
Re: [HOWTO] Finding a Random Origin (Scanning)
It's related to Float:operator-(Float:oper) stock function from float.inc issue that was fixed but they didn't updated webcompiler includes.
The difference is that -1 (or even -1.0) isn't pass to the operator because it's a constant value. |
Re: [HOWTO] Finding a Random Origin (Scanning)
Recursion... might be a bit costly if a valid point is not found in the first 2-3 attempts.
|
Re: [HOWTO] Finding a Random Origin (Scanning)
Quote:
|
Re: [HOWTO] Finding a Random Origin (Scanning)
Quote:
|
Re: [HOWTO] Finding a Random Origin (Scanning)
Quote:
|
Re: [HOWTO] Finding a Random Origin (Scanning)
Quote:
What helps whom? The code is made recursive, and _master_ thought about the costs of this recursion...then i thought that maybe a while loop would be more suitable thats why i asked if that would be better... |
Re: [HOWTO] Finding a Random Origin (Scanning)
Quote:
It all depends on how Hawk552 decides to implement that algorithm. (might I add that this issue has been dealt with before and handled - but I guess that neither Backtracking, Greedy, partitioning nor dynamic methods would help :D) |
All times are GMT -4. The time now is 17:42. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.