Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_BLUE 0x0000BBAA
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define COLOR_ORANGE 0xFF9900AA
- #define COLOR_PINK 0xF020F0
- #define pi 3.14159265
- new tmpstring[256];
- #define MAX_CARS 150
- #define MAX_POINTS 309
- new Float:DrivePoints[13][3] ={
- {0.0,0.0,0.0},
- {-44.3985,2496.6660,16.1428}, // 1
- {24.3157,2500.4241,16.1504}, // 2
- {115.1637,2493.5911,16.1504}, // 3
- {191.7585,2515.5801,16.2879}, // 4
- {241.5370,2505.0950,16.1428}, // 5
- {334.7701,2495.5500,16.1424}, // 6
- {395.5205,2498.2644,16.1423}, // 7
- {395.8009,2508.1602,16.1429}, // 8
- {356.6581,2509.7859,16.1850}, // 9
- {243.5584,2519.8533,16.3302}, // 10
- {188.1285,2520.8726,16.3784}, // 11
- {-33.2113,2521.4604,16.1417} // 12
- };
- new Connections[13][4] ={
- {0,0,0,0},
- {2,0,0,0},
- {3,0,0,0},
- {4,0,0,0},
- {5,0,0,0},
- {6,0,0,0},
- {7,0,0,0},
- {8,0,0,0},
- {9,0,0,0},
- {10,0,0,0},
- {11,0,0,0},
- {12,0,0,0},
- {1,2,0,0}
- };
- new Float:KMH[13] ={
- 0.000000,20.000000,25.000000,25.000000,30.000000,25.000000,20.000000,20.000000,25.000000,25.000000,
- 23.000000,20.000000,20.000000
- };
- new ConnectionsAmount[MAX_POINTS];
- new CAR_AMOUNT_USED;
- new bool:calculations;
- new BrakeTimer;
- new ObjectBrakeTimer;
- new AutomaticCars[MAX_CARS];
- new CarPosition[MAX_CARS];
- new LastCarPosition[MAX_CARS];
- new bool:HasFreezed[MAX_PLAYERS][MAX_CARS];
- new Freezed[MAX_CARS];
- new BotAngle[MAX_CARS];
- new bool:ObjectHasFreezed[MAX_CARS][MAX_CARS];
- public OnFilterScriptInit()
- {
- for(new i=0;i<MAX_POINTS;i++) for(new j=0;j<4;j++) if(Connections[i][j] != 0) ConnectionsAmount[i]++;
- BrakeTimer = SetTimer("ObjectUpdate",700,1);
- ObjectBrakeTimer = SetTimer("ObjectToObjectUpdate",800,1);
- SetGameModeText("Car Bots Edition 0.82");
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i=0;i<CAR_AMOUNT_USED;i++) if(IsValidObject(AutomaticCars[i])) DestroyObject(AutomaticCars[i]);
- KillTimer(BrakeTimer);
- KillTimer(ObjectBrakeTimer);
- return 1;
- }
- forward Float:itan(Float:opp,Float:adj);
- forward ObjectUpdate();
- forward ObjectToObjectUpdate();
- forward Horn(playerid);
- enum SavePlayerPosEnum {
- Float:LastX,
- Float:LastY,
- Float:LastZ
- }
- new SavePlayerPos[MAX_PLAYERS][SavePlayerPosEnum];
- stock PositionsWechsel(i)
- {
- new Float:x,Float:y,Float:z;
- GetPlayerPos(i, x, y, z);
- if(floatabs(floatabs(SavePlayerPos[i][LastX]) - floatabs(x)) + floatabs(floatabs(SavePlayerPos[i][LastY]) - floatabs(y)) > 10) return 1;
- return 0;
- }
- stock GetPointDistanceToPoint(Float:x,Float:y,Float:x2,Float:y2) //By Sacky
- {
- new Float:tmpdis;
- tmpdis = floatsqroot(floatpower(floatabs(floatsub(x,x2)),2)+floatpower(floatabs(floatsub(y,y2)),2));
- return floatround(tmpdis);
- }
- Float:GetXYInBackOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
- {
- new Float:a;
- GetPlayerPos(playerid, x, y, a);
- if (IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
- else GetPlayerFacingAngle(playerid, a);
- x -= (distance * floatsin(-a, degrees));
- y -= (distance * floatcos(-a, degrees));
- return a;
- }
- Float:GetXYInBackOfObject(objectid, &Float:x, &Float:y, Float:distance)
- {
- new Float:a;
- new Float:xx,Float:yy;
- GetObjectPos(AutomaticCars[objectid], x, y, a);
- GetObjectRot(AutomaticCars[objectid],xx,yy,a);
- x -= (distance * floatsin(-a, degrees));
- y -= (distance * floatcos(-a, degrees));
- return a;
- }
- public ObjectToObjectUpdate()
- {
- for(new i=0; i<CAR_AMOUNT_USED; i++)
- {
- new Float:x,Float:y,Float:z,Float:x2,Float:y2/*,Float:z2*/;
- GetXYInBackOfObject(i,x2,y2,15.0);
- for(new j=0;j<CAR_AMOUNT_USED;j++)
- {
- if(Freezed[i] > 0)
- {
- GetObjectPos(AutomaticCars[j],x,y,z);
- if(GetPointDistanceToPoint(x,y,x2,y2) < 5 && (floatabs(BotAngle[j] - BotAngle[i]) < 50 || floatabs(BotAngle[j] - BotAngle[i]) > 310) && !ObjectHasFreezed[j][i] && i!=j)
- {
- if(!ObjectHasFreezed[i][j])
- {
- StopObject(AutomaticCars[j]);
- ObjectHasFreezed[i][j] = true;
- Freezed[j]++;
- j=0;
- }
- }
- } else {
- if(ObjectHasFreezed[i][j])
- {
- Freezed[j]--;
- if(Freezed[j] < 0) Freezed[j] = 0;
- if(Freezed[j] == 0)
- {
- if(KMH[LastCarPosition[j]] != 0.00000)
- MoveObject(AutomaticCars[j],DrivePoints[CarPosition[j]][0],
- DrivePoints[CarPosition[j]][1],
- DrivePoints[CarPosition[j]][2],
- KMH[LastCarPosition[j]]);
- else
- MoveObject(AutomaticCars[j],DrivePoints[CarPosition[j]][0],
- DrivePoints[CarPosition[j]][1],
- DrivePoints[CarPosition[j]][2],
- 15.0);
- //END IF
- }
- ObjectHasFreezed[i][j] = false;
- }
- }
- }
- }
- }
- public ObjectUpdate()
- {
- for(new i=0; i<MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- {
- new Float:x,Float:y,Float:z,Float:x2,Float:y2,Float:z2;
- GetXYInBackOfPlayer(i,x2,y2,5.0);
- new Vi;
- Vi=GetPlayerVehicleID(i);
- new Float:vang;
- if(IsPlayerInAnyVehicle(i)) GetVehicleZAngle(Vi,vang);
- for(new j=0;j<CAR_AMOUNT_USED;j++)
- {
- GetObjectPos(AutomaticCars[j],x,y,z);
- if(GetPointDistanceToPoint(x,y,x2,y2) < 15 && (floatabs(BotAngle[j] - vang) < 50 || floatabs(BotAngle[j] - vang) > 310) && !PositionsWechsel(i) && IsPlayerInAnyVehicle(i))
- {
- if(!HasFreezed[i][j])
- {
- StopObject(AutomaticCars[j]);
- HasFreezed[i][j] = true;
- Freezed[j]++;
- PlayerPlaySound(i,1147,x,y,z);
- new ran = random(6);
- if(ran == 0)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: Drive, you idiot!");
- else if(ran == 1)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: What are you waiting for?!?");
- else if(ran == 2)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: Standing... I hate standing!!!");
- else if(ran == 3)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: If you've found the 'W' Button let me know...");
- else if(ran == 4)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: Mooove, MOOOVE!!!");
- else if(ran == 5)
- SendClientMessage(i,COLOR_BLUE,"***Car Bot: Sunday Driver!!!");
- //END IF
- SetTimerEx("Horn",500,0,"t",i);
- }
- } else {
- if(HasFreezed[i][j])
- {
- Freezed[j]--;
- if(Freezed[j] < 0) Freezed[j] = 0;
- if(Freezed[j] == 0)
- {
- if(KMH[LastCarPosition[j]] != 0.00000)
- MoveObject(AutomaticCars[j],DrivePoints[CarPosition[j]][0],
- DrivePoints[CarPosition[j]][1],
- DrivePoints[CarPosition[j]][2],
- KMH[LastCarPosition[j]]);
- else
- MoveObject(AutomaticCars[j],DrivePoints[CarPosition[j]][0],DrivePoints[CarPosition[j]][1],DrivePoints[CarPosition[j]][2],15.0);
- //END IF
- }
- HasFreezed[i][j] = false;
- }
- }
- }
- SavePlayerPos[i][LastX] = x2;
- SavePlayerPos[i][LastY] = y2;
- SavePlayerPos[i][LastZ] = z2;
- }
- }
- }
- public Horn(playerid)
- {
- new Float:x,Float:y,Float:z;
- GetPlayerPos(playerid,x,y,z);
- PlayerPlaySound(playerid,1147,x,y,z);
- }
- stock IsNoCrossway(Drivepoint)
- {
- return (ConnectionsAmount[Drivepoint] > 1) ? 0 : 1;
- }
- stock ChooseAim(oid,Drivepoint)
- {
- new zufall = Connections[Drivepoint][random(ConnectionsAmount[Drivepoint])];
- LastCarPosition[oid] = CarPosition[oid];
- CarPosition[oid] = zufall;
- return zufall;
- }
- stock str(i)
- {
- new t[256];
- valstr(t,i);
- return t;
- }
- stock STM(string[])
- {
- SendClientMessageToAll(COLOR_GREEN,string);
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock CorrectAmount(playerid,&anzahl)
- {
- new oid = CreateObject(1696,0.0,0.0,1000.0,0.0,0.0,0.0); //Normal:3593 //Fass:1225 //Rampe1:1696 //Rauch:2780
- DestroyObject(oid);
- if(oid + anzahl > 145)
- {
- anzahl = 145 - oid;
- SendClientMessage(playerid,COLOR_RED,"Attention! You've created too much Car Bots. The amount has been automatically decreased.");
- SendClientMessage(playerid,COLOR_RED,"The amount of the bots + your other server objects mustn't be above 150");
- }
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SendClientMessage(playerid,COLOR_GREEN,"***Loaded Car Bots by Tjong");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- for(new i=0;i<CAR_AMOUNT_USED;i++)
- {
- if(HasFreezed[playerid][i])
- {
- Freezed[i]--;
- if(Freezed[i] < 0) Freezed[i] = 0;
- if(Freezed[i] == 0)
- {
- if(KMH[LastCarPosition[i]] != 0.00000)
- MoveObject(AutomaticCars[i],DrivePoints[CarPosition[i]][0],
- DrivePoints[CarPosition[i]][1],
- DrivePoints[CarPosition[i]][2],
- KMH[LastCarPosition[i]]);
- else
- MoveObject(AutomaticCars[i],DrivePoints[CarPosition[i]][0],DrivePoints[CarPosition[i]][1],DrivePoints[CarPosition[i]][2],15.0);
- //endif
- }
- }
- HasFreezed[playerid][i] = false;
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerPrivmsg(playerid, recieverid, text[])
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256];
- new idx;
- new tmp[256];
- cmd = strtok(cmdtext, idx);
- if (strcmp(cmd, "/startcarbots", true)==0 && IsPlayerAdmin(playerid))
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) {
- SendClientMessage(playerid, COLOR_WHITE, "Benutze: /startcarbots [Amount]");
- return 1;
- }
- new amount = strval(tmp);
- for(new i=0;i<MAX_CARS;i++)
- {
- if(IsValidObject(AutomaticCars[i])) DestroyObject(AutomaticCars[i]);
- }
- CorrectAmount(playerid,amount);
- CAR_AMOUNT_USED = amount;
- for(new i=1;i<amount;i++)
- {
- new rand = random(MAX_POINTS);
- new oid = CreateObject(1696+random(2),DrivePoints[rand][0],DrivePoints[rand][1],DrivePoints[rand][2]+20,0.0,0.0,0.0); //3593 //12957
- AutomaticCars[i] = oid;
- CarPosition[i] = rand;
- MoveObject(AutomaticCars[i],DrivePoints[rand][0],DrivePoints[rand][1],DrivePoints[rand][2],5.0);
- }
- return 1;
- }
- if (strcmp(cmd, "/stopcarbots", true)==0 && IsPlayerAdmin(playerid))
- {
- for(new i=0;i<CAR_AMOUNT_USED;i++)
- {
- if(IsValidObject(AutomaticCars[i])) DestroyObject(AutomaticCars[i]);
- }
- return 1;
- }
- if (strcmp(cmd, "/tpto", true)==0 && IsPlayerAdmin(playerid))
- {
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) {
- SendClientMessage(playerid, COLOR_WHITE, "Benutze: /startcarbots [Amount]");
- return 1;
- }
- new Float:x = floatstr(tmp);
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) {
- SendClientMessage(playerid, COLOR_WHITE, "Benutze: /startcarbots [Amount]");
- return 1;
- }
- new Float:y = floatstr(tmp);
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) {
- SendClientMessage(playerid, COLOR_WHITE, "Benutze: /startcarbots [Amount]");
- return 1;
- }
- new Float:z = floatstr(tmp);
- SetPlayerPos(playerid,x,y,z);
- return 1;
- }
- if (strcmp(cmd, "/botcommands", true)==0 && IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid,COLOR_LIGHTBLUE,"~~~~~~~~~~~~~~~B~o~t~~~C~o~m~m~a~n~d~s~~~~~~~~~~~~~~~");
- SendClientMessage(playerid,COLOR_GREEN,"/startcarbots [Amount (1- ~150)] ---> An amount of car bots start");
- SendClientMessage(playerid,COLOR_GREEN,"/stopcarbots ---> Removes all Car Bots from the map");
- SendClientMessage(playerid,COLOR_GREEN,"/calculations ---> Debug (Shows the ID of the bot that has been moved at last)");
- SendClientMessage(playerid,COLOR_LIGHTBLUE,"~~~~~~~~~~~~~~~B~o~t~~~C~o~m~m~a~n~d~s~~~~~~~~~~~~~~~");
- return 1;
- }
- if (strcmp(cmd, "/calculations", true)==0)
- {
- if(!calculations) calculations = true; else calculations = false;
- return 1;
- }
- return 0;
- }
- public OnPlayerInfoChange(playerid)
- {
- return 1;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- new bool:IsObjectBot;
- new i;
- for(i=0;i<CAR_AMOUNT_USED;i++)
- {
- if(objectid == AutomaticCars[i])
- {
- if(calculations)
- {
- format(tmpstring,sizeof(tmpstring),"Object Moved: ~g~%d",i);
- GameTextForAll(tmpstring,5000,6);
- }
- IsObjectBot = true;
- break;
- }
- }
- if(IsObjectBot)
- {
- //STM("TEST");
- new aim;
- if(IsNoCrossway(CarPosition[i]))
- {
- aim = Connections[CarPosition[i]][0];
- LastCarPosition[i] = CarPosition[i];
- CarPosition[i] = aim;
- } else aim = ChooseAim(i,CarPosition[i]);
- if(Connections[LastCarPosition[i]][0] == 0) aim = 1;
- //STM(str(aim));
- new Float:ang;
- new Float:x,Float:y,Float:lx,Float:ly;
- new Float:xdiff,Float:ydiff;
- x = DrivePoints[aim][0];
- y = DrivePoints[aim][1];
- lx = DrivePoints[LastCarPosition[i]][0];
- ly = DrivePoints[LastCarPosition[i]][1];
- xdiff = floatabs(x) - floatabs(lx);
- ydiff = floatabs(y) - floatabs(ly);
- new eins;
- new winkel;
- if(xdiff >= 0 && ydiff >= 0)
- {
- winkel = 0;
- eins = -1;
- } else if(xdiff <= 0 && ydiff >= 0) {
- winkel = 0;
- eins = 1;
- } else if(xdiff >= 0 && ydiff <= 0) {
- winkel = 180;
- eins = 1;
- } else if(xdiff <= 0 && ydiff <= 0) {
- winkel = 180;
- eins = -1;
- }
- if(floatabs(ydiff) == 0) ydiff = 1;
- new Float:divi = floatdiv(floatabs(xdiff),floatabs(ydiff));
- if(divi > 2) divi = 2;
- ang = winkel + (floatmul(45,divi) * eins);
- BotAngle[i] = floatround(ang);
- SetObjectRot(objectid,0.0,0.0,ang);
- if(KMH[LastCarPosition[i]] != 0.00000)
- {
- MoveObject(objectid,DrivePoints[aim][0],DrivePoints[aim][1],DrivePoints[aim][2],KMH[LastCarPosition[i]]);
- } else {
- MoveObject(objectid,DrivePoints[aim][0],DrivePoints[aim][1],DrivePoints[aim][2],15.0);
- }
- CarPosition[i] = aim;
- }
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement