Created
September 30, 2013 14:02
-
-
Save Southclaws/6764264 to your computer and use it in GitHub Desktop.
Creates a bunch of blue sticks, then lets them roam around an aircraft hangar in Area 69.
Example of constraining AI to a set area, can be used on NPCs too.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FILTERSCRIPT | |
#include <a_samp> | |
#include <YSI\y_iterate> | |
#include <streamer> | |
#define MAX_BOT (128) | |
#define MIN_X (266.98685) | |
#define MIN_Y (1941.25549) | |
#define MAX_X (286.33057) | |
#define MAX_Y (1970.27759) | |
enum E_BOT_DATA | |
{ | |
bot_id, | |
Float: bot_posX, | |
Float: bot_posY, | |
Float: bot_posZ, | |
Float: bot_rotZ | |
} | |
new | |
bot_Data[MAX_BOT][E_BOT_DATA], | |
Iterator: bot_Index<MAX_BOT>; | |
CreateBot(Float:x, Float:y, Float:z, Float:angle) | |
{ | |
new id = Iter_Free(bot_Index); | |
if(id == -1) | |
return -1; | |
bot_Data[id][bot_id] = CreateDynamicObject(18652, x, y, z, 0.0, 90.0, angle); | |
bot_Data[id][bot_posX] = x; | |
bot_Data[id][bot_posY] = y; | |
bot_Data[id][bot_posZ] = z; | |
bot_Data[id][bot_rotZ] = angle; | |
MoveBotToNext(id); | |
Iter_Add(bot_Index, id); | |
return id; | |
} | |
MoveBotToNext(id) | |
{ | |
new | |
Float:x, | |
Float:y, | |
Float:z; | |
GetDynamicObjectPos(bot_Data[id][bot_id], x, y, z); | |
bot_Data[id][bot_rotZ] += float(random(90) - 45); | |
x += frandom(1.0, 0.2) * floatsin(-bot_Data[id][bot_rotZ], degrees); | |
y += frandom(1.0, 0.2) * floatcos(-bot_Data[id][bot_rotZ], degrees); | |
if(ConstrainPositionToBox(x, y, MIN_X, MIN_Y, MAX_X, MAX_Y)) | |
{ | |
bot_Data[id][bot_rotZ] -= 180.0; | |
x += frandom(1.0, 0.2) * floatsin(-bot_Data[id][bot_rotZ], degrees); | |
y += frandom(1.0, 0.2) * floatcos(-bot_Data[id][bot_rotZ], degrees); | |
} | |
MoveDynamicObject(bot_Data[id][bot_id], x, y, z, frandom(1.5, 0.5), 0.0, 90.0, bot_Data[id][bot_rotZ]); | |
return; | |
} | |
public OnDynamicObjectMoved(objectid) | |
{ | |
foreach(new i : bot_Index) | |
{ | |
if(objectid == bot_Data[i][bot_id]) | |
{ | |
MoveBotToNext(i); | |
break; | |
} | |
} | |
} | |
ConstrainPositionToBox(&Float:x, &Float:y, Float:minx, Float:miny, Float:maxx, Float:maxy) | |
{ | |
new modified; | |
if(x < minx) | |
{ | |
x = (minx + 1.0); | |
modified++; | |
} | |
else if(x > maxx) | |
{ | |
x = (maxx - 1.0); | |
modified++; | |
} | |
if(y < miny) | |
{ | |
y = (miny + 1.0); | |
modified++; | |
} | |
else if(y > maxy) | |
{ | |
y = (maxy - 1.0); | |
modified++; | |
} | |
return modified; | |
} | |
forward Float:frandom(Float:max, Float:min = 0.0, dp = 4); | |
stock Float:frandom(Float:max, Float:min = 0.0, dp = 4) | |
{ | |
new | |
Float:mul = floatpower(10.0, dp), | |
imin = floatround(min * mul), | |
imax = floatround(max * mul); | |
return float(random(imax - imin) + imin) / mul; | |
} | |
// Filterscript | |
public OnFilterScriptInit() | |
{ | |
foreach(new i : Player) | |
Streamer_ToggleIdleUpdate(i, true); | |
for(new i; i < 10; i++) | |
CreateBot(276.3278 + frandom(3.0), 1958.0151 + frandom(3.0), 17.4787, random(360)); | |
return 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment