Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

A* Pathfinding


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
Brak odpowiedzi do tego tematu

#1 Adminek AMXX.PL

    Admin :)

  • Bot

Reputacja: 156
Profesjonalista

  • Postów:7 489
  • Lokalizacja:AMXX.PL
Offline

Napisano 15.06.2014 23:21

<!-- BEGIN TEMPLATE: postbit_external -->
<div><font size="+3">A* Pathfinding</font><br /><font size="+1">Pathfinding API based on the A* method.</font><br /><br /><font size="+1">Functions:</font><br /><!-- BEGIN TEMPLATE: bbcode_code -->
<!-- Code block -->
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Code:</div>
<pre class="alt2" dir="ltr" style="margin: 0px;padding: 6px;border: 1px inset;width: auto; height: px; text-align: left; overflow: auto"><div class="pawn" style="font-family: monospace;"><span style="color: #ff0000; font-style: italic;">/** Array:AStar(Float:Start[3], Float:Goal[3], StepSize = 30, Ignore = IGNORE_MONSTERS, IgnoreID = 0, GroundDistance = 35, Heuristic = 50);
&nbsp;*
&nbsp;* Finds a path between Start and Goal.
&nbsp;*
&nbsp;*
&nbsp;* Parameters:
&nbsp;*
&nbsp;*&nbsp; Float:Start[3]
&nbsp;*&nbsp; &nbsp; Starting position.
&nbsp;*
&nbsp;*&nbsp; Float:Goal[3]
&nbsp;*&nbsp; &nbsp; Hopefully ending position.
&nbsp;*
&nbsp;*&nbsp; (Optional) StepSize = 30
&nbsp;*&nbsp; &nbsp; Defines how far between each step to take in a pattern of -X + X in all three dimensions. This means that diagonally, the step will be longer.
&nbsp;*
&nbsp;*&nbsp; (Optional) Ignore = IGNORE_MONSTERS
&nbsp;*&nbsp; &nbsp; Flags for the traceline check.
&nbsp;*
&nbsp;*&nbsp; (Optional) IgnoreID = 0
&nbsp;*&nbsp; &nbsp; id of the calling player if IGNORE_MONSTERS is not set. Again, this is for the traceline.
&nbsp;*
&nbsp;*&nbsp; (Optional) GroundDistance = 35
&nbsp;*&nbsp; &nbsp; Set the maximum distance from the ground for the point to be accepted as valid. If set to 0 this check is disabled, meaning pathfinding for flying entities.
&nbsp;*
&nbsp;*&nbsp; (Optional) Heuristic = 50
&nbsp;*&nbsp; &nbsp; Optimization parameter. Decides how much importance the distance from the target has.
&nbsp;*&nbsp; &nbsp; Higher values might result in a faster execution but may also result in a suboptimal path.
&nbsp;*
&nbsp;* Returns a handle to a dynamic array that will contain each step between start and goal.
&nbsp;* On failure it will return Invalid_Array.
**/</span>
native Array:AStar<span style="color: #000000;">(</span><span style="color: #00c0c0;">Float</span>:Start<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>, <span style="color: #00c0c0;">Float</span>:Goal<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>, StepSize = <span style="color: #0000dd;">30</span>, Ignore = IGNORE_MONSTERS, IgnoreID = <span style="color: #0000dd;">0</span>, GroundDistance = <span style="color: #0000dd;">35</span>, Heuristic = <span style="color: #0000dd;">50</span><span style="color: #000000;">)</span>;

<span style="color: #ff0000; font-style: italic;">/**
&nbsp;* AStar_GetDistance()
&nbsp;*
&nbsp;* Returns the distance of the last path created.
**/</span>
native <span style="color: #00c0c0;">Float</span>:AStar_GetDistance<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;

<span style="color: #ff0000; font-style: italic;">/**
&nbsp;* AStar_GetNodesAdded()
&nbsp;*
&nbsp;* Returns the ammount of nodes that were created from the last session.
**/</span>
native AStar_GetNodesAdded<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;

<span style="color: #ff0000; font-style: italic;">/**
&nbsp;* AStar_GetNodesValidated()
&nbsp;*
&nbsp;* Returns the ammount of nodes that were validated from the last session.
**/</span>
native AStar_GetNodesValidated<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;

<span style="color: #ff0000; font-style: italic;">/**
&nbsp;* AStar_GetNodesValidated()
&nbsp;*
&nbsp;* Returns the ammount of nodes that were cleared from the last session.
**/</span>
native AStar_GetNodesCleared<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;</div></pre>
</div>
<!-- /Code block -->
<!-- END TEMPLATE: bbcode_code --><br />(Overengineered) example of how it could be used:<br /><!-- BEGIN TEMPLATE: bbcode_code -->
<!-- Code block -->
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Code:</div>
<pre class="alt2" dir="ltr" style="margin: 0px;padding: 6px;border: 1px inset;width: auto; height: px; text-align: left; overflow: auto"><div class="pawn" style="font-family: monospace;"><span style="color: #339900;">#include &lt;amxmodx&gt;</span>
<span style="color: #339900;">#include &lt;fakemeta&gt;</span>
<span style="color: #339900;">#include &lt;astar&gt;</span>
<span style="color: #339900;">#include &lt;xs&gt;</span>

<span style="color: #ff0000; font-style: italic;">/*
new hTimer = TimerStart();
// ...
TimerStop(hTimer);
server_print(&quot;Timer: %d days, %d hours, %d minutes, %d seconds and %d milliseconds.&quot;, TimerDays(hTimer), TimerHours(hTimer), TimerMinutes(hTimer), TimerSeconds(hTimer), TimerMilliseconds(hTimer));
*/</span>
<span style="color: #339900;">#define TimerStart()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tickcount()</span>
<span style="color: #339900;">#define TimerMid(%0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( tickcount() - %0 )</span>
<span style="color: #339900;">#define TimerStop(%0)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;( %0 = tickcount() - %0 )</span>
<span style="color: #339900;">#define TimerDays(%0)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;( %0 / 86400000 )</span>
<span style="color: #339900;">#define TimerHours(%0)&nbsp; &nbsp; &nbsp; ( %0 % 86400000 / 3600000 )</span>
<span style="color: #339900;">#define TimerMinutes(%0)&nbsp; &nbsp; &nbsp; &nbsp; ( %0 % 3600000 / 60000 )</span>
<span style="color: #339900;">#define TimerSeconds(%0)&nbsp; &nbsp; &nbsp; &nbsp; ( %0 % 60000 / 1000 )</span>
<span style="color: #339900;">#define TimerMilliseconds(%0)&nbsp; &nbsp;( %0 % 1000 )</span>

<span style="color: #ff0000; font-style: italic;">/* TimerFormat(hTimer, output[], maxlen, mode = 1, bool:full = 0)
* Formats the result of a timer handle into a string.
*
* Parameters:
*
* hTimer
*&nbsp; &nbsp; Timer Handle
*
* output[]
*&nbsp; &nbsp; The output string
*
* maxlen
*&nbsp; &nbsp; Maximum size of the output string
*
* mode
*&nbsp; &nbsp; 1: 00:00:00:00.000
*&nbsp; &nbsp; 2: 0d 0h 0m 0s 0ms
*
* bool:full
*&nbsp; &nbsp; If full is set to true it will print all fields, even those which contains no value.
*&nbsp; &nbsp; If full is set to false and mode is set to 1, it will print the first field that contains a value and everything after that point. For example: 03:00:00.295
*&nbsp; &nbsp; If full is set to false and mode is set to 2, it will print only the fields that contains a value. For example: 3h 295ms
*/</span>
<span style="color: #ff0000;">stock</span> TimerFormat<span style="color: #000000;">(</span>hTimer, output<span style="color: #000000;">[</span><span style="color: #000000;">]</span>, maxlen, mode = <span style="color: #0000dd;">1</span>, <span style="color: #ff0000;">bool</span>:full = <span style="color: #007700;">false</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; <span style="color: #007700;">new</span> len, <span style="color: #ff0000;">bool</span>:started;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> full || TimerDays<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = formatex<span style="color: #000000;">(</span>output, maxlen, <span style="color: #800080;">&quot;%02d:&quot;</span>, TimerDays<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = formatex<span style="color: #000000;">(</span>output, maxlen, <span style="color: #800080;">&quot;%dd &quot;</span>, TimerDays<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; started = <span style="color: #007700;">true</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> full || <span style="color: #000000;">(</span> started &amp;&amp; mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span> || TimerHours<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%02d:&quot;</span>, TimerHours<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%dh &quot;</span>, TimerHours<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; started = <span style="color: #007700;">true</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> full || <span style="color: #000000;">(</span> started &amp;&amp; mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span> || TimerMinutes<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%02d:&quot;</span>, TimerMinutes<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%dm &quot;</span>, TimerMinutes<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; started = <span style="color: #007700;">true</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> full || <span style="color: #000000;">(</span> started &amp;&amp; mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span> || TimerSeconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%02d.&quot;</span>, TimerSeconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%ds &quot;</span>, TimerSeconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; started = <span style="color: #007700;">true</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> full || <span style="color: #000000;">(</span> started &amp;&amp; mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span> || TimerMilliseconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> mode == <span style="color: #0000dd;">1</span> <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%03d&quot;</span>, TimerMilliseconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len += formatex<span style="color: #000000;">(</span>output<span style="color: #000000;">[</span>len<span style="color: #000000;">]</span>, maxlen - len, <span style="color: #800080;">&quot;%dms&quot;</span>, TimerMilliseconds<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
<span style="color: #000000;">}</span>

<span style="color: #ff0000;">public</span> plugin_init<span style="color: #000000;">(</span><span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">register_plugin</span><span style="color: #000000;">(</span><span style="color: #800080;">&quot;A* Sample code&quot;</span>, <span style="color: #800080;">&quot;1.0&quot;</span>, <span style="color: #800080;">&quot;[ --{-@ ]&quot;</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #00c0c0;">register_clcmd</span><span style="color: #000000;">(</span><span style="color: #800080;">&quot;astar_command&quot;</span>, <span style="color: #800080;">&quot;testfunc&quot;</span><span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span>

<span style="color: #007700;">new</span> g_sprite;

<span style="color: #ff0000;">public</span> plugin_precache<span style="color: #000000;">(</span><span style="color: #000000;">)</span>
&nbsp; &nbsp; g_sprite = <span style="color: #00c0c0;">precache_model</span><span style="color: #000000;">(</span><span style="color: #800080;">&quot;sprites/laserbeam.spr&quot;</span><span style="color: #000000;">)</span>

<span style="color: #ff0000;">stock</span> beam<span style="color: #000000;">(</span>origin1<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>, origin2<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>, <span style="color: #00c0c0;">Float</span>:seconds<span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">message_begin</span><span style="color: #000000;">(</span>MSG_BROADCAST ,SVC_TEMPENTITY<span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span>TE_BEAMPOINTS<span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin1<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>&nbsp;<span style="color: #cf0020;">// start position</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin1<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin1<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin2<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>&nbsp;<span style="color: #cf0020;">// end position</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin2<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_coord</span><span style="color: #000000;">(</span>origin2<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_short</span><span style="color: #000000;">(</span>g_sprite<span style="color: #000000;">)</span>&nbsp; &nbsp;<span style="color: #cf0020;">// sprite index</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">0</span><span style="color: #000000;">)</span>&nbsp; &nbsp;<span style="color: #cf0020;">// starting frame</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">10</span><span style="color: #000000;">)</span>&nbsp; <span style="color: #cf0020;">// frame rate in 0.1's</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #00c0c0;">floatround</span><span style="color: #000000;">(</span>seconds*<span style="color: #0000dd;">10</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>&nbsp; <span style="color: #cf0020;">// life in 0.1's</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">10</span><span style="color: #000000;">)</span>&nbsp; <span style="color: #cf0020;">// line width in 0.1's</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">1</span><span style="color: #000000;">)</span>&nbsp; &nbsp;<span style="color: #cf0020;">// noise amplitude in 0.01's</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">0</span><span style="color: #000000;">)</span>&nbsp; &nbsp;<span style="color: #cf0020;">// Red</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">0</span><span style="color: #000000;">)</span>&nbsp; &nbsp;<span style="color: #cf0020;">// Green</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">255</span><span style="color: #000000;">)</span>&nbsp;<span style="color: #cf0020;">// Blue</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">127</span><span style="color: #000000;">)</span>&nbsp;<span style="color: #cf0020;">// brightness</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">write_byte</span><span style="color: #000000;">(</span><span style="color: #0000dd;">10</span><span style="color: #000000;">)</span>&nbsp; <span style="color: #cf0020;">// scroll speed in 0.1's</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">message_end</span><span style="color: #000000;">(</span><span style="color: #000000;">)</span>
<span style="color: #000000;">}</span>

<span style="color: #ff0000;">public</span> testfunc<span style="color: #000000;">(</span>id<span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #007700;">new</span> <span style="color: #00c0c0;">Float</span>:startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> <span style="color: #00c0c0;">Float</span>:endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> <span style="color: #00c0c0;">Float</span>:tempPos<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> Velocity = <span style="color: #0000dd;">250</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> hTrace;

&nbsp; &nbsp; pev<span style="color: #000000;">(</span>id, pev_origin, startPos<span style="color: #000000;">)</span>;

&nbsp; &nbsp; xs_vec_copy<span style="color: #000000;">(</span>startPos, endPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> -= <span style="color: #0000dd;">1000</span>

&nbsp; &nbsp; engfunc<span style="color: #000000;">(</span>EngFunc_TraceLine, startPos, endPos, IGNORE_MONSTERS, id, hTrace<span style="color: #000000;">)</span>;
&nbsp; &nbsp; get_tr2<span style="color: #000000;">(</span>hTrace, TR_vecEndPos, startPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; free_tr2<span style="color: #000000;">(</span>hTrace<span style="color: #000000;">)</span>;

&nbsp; &nbsp; startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> += <span style="color: #0000dd;">10</span>;

&nbsp; &nbsp; <span style="color: #0000ff;">do</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; Velocity += <span style="color: #0000dd;">50</span>;
&nbsp; &nbsp; &nbsp; &nbsp; velocity_by_aim<span style="color: #000000;">(</span>id, Velocity, endPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; xs_vec_add<span style="color: #000000;">(</span>endPos, startPos, endPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> Velocity &gt; <span style="color: #0000dd;">2000</span> <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_chat, <span style="color: #800080;">&quot;Could not find a good end point&quot;</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #0000ff;">while</span> <span style="color: #000000;">(</span> engfunc<span style="color: #000000;">(</span>EngFunc_PointContents, endPos<span style="color: #000000;">)</span> != CONTENTS_EMPTY <span style="color: #000000;">)</span>

&nbsp; &nbsp; xs_vec_copy<span style="color: #000000;">(</span>endPos, tempPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; tempPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> -= <span style="color: #0000dd;">1000</span>

&nbsp; &nbsp; engfunc<span style="color: #000000;">(</span>EngFunc_TraceLine, endPos, tempPos, IGNORE_MONSTERS, id, hTrace<span style="color: #000000;">)</span>;
&nbsp; &nbsp; get_tr2<span style="color: #000000;">(</span>hTrace, TR_vecEndPos, endPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; free_tr2<span style="color: #000000;">(</span>hTrace<span style="color: #000000;">)</span>

&nbsp; &nbsp; endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> += <span style="color: #0000dd;">10</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_chat, <span style="color: #800080;">&quot;Start: %.0f, %.0f, %.0f. End: %.0f, %.0f, %.0f. (Distance %d units)&quot;</span>, startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span>, startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span>, startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span>, Velocity<span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #007700;">new</span> hTimer = TimerStart<span style="color: #000000;">(</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> Array:hPath = AStar<span style="color: #000000;">(</span>startPos, endPos<span style="color: #000000;">)</span>;
&nbsp; &nbsp; TimerStop<span style="color: #000000;">(</span>hTimer<span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #007700;">new</span> timer<span style="color: #000000;">[</span><span style="color: #0000dd;">32</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; TimerFormat<span style="color: #000000;">(</span>hTimer, timer, charsmax<span style="color: #000000;">(</span>timer<span style="color: #000000;">)</span>, <span style="color: #0000dd;">2</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_chat, <span style="color: #800080;">&quot;Execution time: %s (%d nodes, %d validated, %d successful)&quot;</span>, timer, AStar_GetNodesAdded<span style="color: #000000;">(</span><span style="color: #000000;">)</span>, AStar_GetNodesValidated<span style="color: #000000;">(</span><span style="color: #000000;">)</span>, AStar_GetNodesCleared<span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">(</span> hPath == Invalid_Array <span style="color: #000000;">)</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">return</span>;

&nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_chat, <span style="color: #800080;">&quot;Distance of path: %.0f units, %d steps.&quot;</span>, AStar_GetDistance<span style="color: #000000;">(</span><span style="color: #000000;">)</span>, ArraySize<span style="color: #000000;">(</span>hPath<span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #007700;">new</span> test<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; <span style="color: #007700;">new</span> test2<span style="color: #000000;">[</span><span style="color: #0000dd;">3</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span> = <span style="color: #00c0c0;">floatround</span><span style="color: #000000;">(</span>startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span> = <span style="color: #00c0c0;">floatround</span><span style="color: #000000;">(</span>startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> = <span style="color: #00c0c0;">floatround</span><span style="color: #000000;">(</span>startPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp;
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #000000;">(</span> <span style="color: #007700;">new</span> i = <span style="color: #0000dd;">1</span> ; ArraySize<span style="color: #000000;">(</span>hPath<span style="color: #000000;">)</span> ; i++ <span style="color: #000000;">)</span> <span style="color: #000000;">{</span>
&nbsp; &nbsp; &nbsp; &nbsp; ArrayGetArray<span style="color: #000000;">(</span>hPath, <span style="color: #0000dd;">0</span>, test<span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; ArrayDeleteItem<span style="color: #000000;">(</span>hPath, <span style="color: #0000dd;">0</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_console, <span style="color: #800080;">&quot;Step %d: %d, %d, %d&quot;</span>, i, test<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span>, test<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span>, test<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; beam<span style="color: #000000;">(</span>test, test2, <span style="color: #0000dd;">30.0</span><span style="color: #000000;">)</span>;
&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span> = test<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; &nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span> = test<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; &nbsp; &nbsp; test2<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span> = test<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span>;
&nbsp; &nbsp; <span style="color: #000000;">}</span>
&nbsp; &nbsp; <span style="color: #00c0c0;">client_print</span><span style="color: #000000;">(</span>id, print_console, <span style="color: #800080;">&quot;End: %.0f, %.0f, %.0f (Distance: %.1f)&quot;</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">0</span><span style="color: #000000;">]</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">1</span><span style="color: #000000;">]</span>, endPos<span style="color: #000000;">[</span><span style="color: #0000dd;">2</span><span style="color: #000000;">]</span>, AStar_GetDistance<span style="color: #000000;">(</span><span style="color: #000000;">)</span><span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span></div></pre>
</div>
<!-- /Code block -->
<!-- END TEMPLATE: bbcode_code --><br />And here's an example image of a path between two points that has objects, corners and height differences.<br /><div style="margin: 5px;">
<div class="smallfont" style="margin-bottom: 2px;">
<b>Spoiler</b> <input value="Show" style="margin: 0px; padding: 0px; width: 45px; font-size: 10px;" onclick="if(this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != 'inline')
{ this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'inline'; this.innerText = ''; this.value = 'Hide'; }
else
{ this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value='Show'; }" type="button">
</div>
<div class="alt2" style="border: 1px inset; padding: 6px;">
<div class="spoiler" style="display: none;"><br /><img src="http://DivinityX.eu/...mages/AStar.jpg" border="0" alt="" /><br /></div>
</div>
</div><br />It was hard taking a good picture since the beams disappear really fast. You get the point.<br /><br /><font size="+1">Additional notes:</font><br />Use this file however you want. Credit not required.<br /><br />This can be remade into a thinking thread that doesn't have to pause the server to complete the path.<br />But obviously that requires another type of thinking when programming for it.<br />Tell me if you're interested and I'll start right away on that version.<br /><br />The best would probably be to make it a module. Feel free to do so (I'm not good enough). You have my permission to use any of this code in that project.<br /><br />I'm always open to suggestions, feedback and criticism. I aim to add as much support as possible. Please share your thoughts.</div>


<br /> <div style="padding:6px">








<fieldset class="fieldset">
<legend>Attached Files</legend>
<table cellpadding="0" cellspacing="3" border="0">
<!-- BEGIN TEMPLATE: postbit_attachment -->
<tr>
<td><img class="inlineimg" src="https://forums.allie.../attach/sma.gif" alt="File Type: sma" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
<td>

<a href="http://www.amxmodx.o...?file_id=134552"><strong>Get Plugin</strong></a> or
<a href="https://forums.allie...38;d=1402881503">Get Source</a> (astar.sma - 6.1 KB)

</td>
</tr>
<!-- END TEMPLATE: postbit_attachment --><!-- BEGIN TEMPLATE: postbit_attachment -->
<tr>
<td><img class="inlineimg" src="https://forums.allie.../attach/inc.gif" alt="File Type: inc" width="16" height="16" border="0" style="vertical-align:baseline" /></td>
<td>


<a href="https://forums.allie...38;d=1402870256">astar.inc</a> (1.9 KB)


</td>
</tr>
<!-- END TEMPLATE: postbit_attachment -->
</table>
</fieldset>


</div>

<!-- END TEMPLATE: postbit_external -->

Wyświetl pełny artykuł




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych