Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Criado por [S]trong, obrigado a LucifeR pelo SetObjectToFaceCords
- // Agradecimentos a [iPs] Team
- #include <a_samp>
- #define MIN_RANGE_ATTACK 4.0
- #define MIN_SHARK_RANGE 40.0
- new
- Float:SharkPlaces[][] =
- {
- {688.4228, -2163.0522, -0.7187},
- {639.5123, -2155.1782, -0.6878}
- },
- Shark[sizeof SharkPlaces],
- Hunting[sizeof SharkPlaces]
- ;
- ToFace(playerid, id);
- public OnFilterScriptInit() {
- for (new ii = 0; ii != sizeof SharkPlaces; ++ii) {
- Shark[ii] = CreateObject(1608, SharkPlaces[ii][0], SharkPlaces[ii][1], SharkPlaces[ii][2], 0.0, 0.0, 80.0, 300.0);
- }
- return 1;
- }
- public ToFace(playerid, id) {
- new
- Float: h,
- Float: x,
- Float: y,
- Float: z,
- anim = GetPlayerAnimationIndex(playerid);
- if (!(anim == 1543 || anim == 1538 || anim == 1539)) {
- goto Finish;
- }
- GetPlayerHealth(playerid, h);
- if (h <= 0.0) {
- goto Finish;
- }
- GetObjectPos(Shark[id], x, y, z);
- if (IsPlayerInRangeOfPoint(playerid, MIN_RANGE_ATTACK, x, y, z)) {
- SetPlayerHealth(playerid, h - 10);
- GetPlayerPos(playerid, x, y, z);
- SetObjectToFaceCords(Shark[id], x, y, z);
- Hunting[id] = gettime() + 5;
- SetTimerEx("ToFace", 1500, 0, "ii", playerid, id);
- return SendClientMessage(playerid, 0xFF0000FF, "AVISO: Você foi mordido por um tubarão, fuja rápido!");
- }
- if (!IsPlayerInRangeOfPoint(playerid, MIN_SHARK_RANGE, SharkPlaces[id][0], SharkPlaces[id][1], SharkPlaces[id][2])) {
- Finish:
- Hunting[id] = 0;
- MoveObject(Shark[id], SharkPlaces[id][0], SharkPlaces[id][1], SharkPlaces[id][2], 2.5);
- }
- else {
- new
- time;
- GetPlayerPos(playerid, x, y, z);
- time = MoveObject(Shark[id], x, y, z, 2.5);
- SetTimerEx("ToFace", time + 10, 0, "ii", playerid, id);
- Hunting[id] = gettime() + time + 5;
- }
- return 1;
- }
- public OnPlayerUpdate(playerid) {
- new
- anim = GetPlayerAnimationIndex(playerid);
- if ((anim == 1543 || anim == 1538 || anim == 1539)) {
- for (new ii = 0; ii != sizeof SharkPlaces; ++ii) {
- if (gettime() > Hunting[ii] && IsPlayerInRangeOfPoint(playerid, MIN_SHARK_RANGE, SharkPlaces[ii][0], SharkPlaces[ii][1], SharkPlaces[ii][2])) {
- new
- time,
- Float: x,
- Float: y,
- Float: z;
- GetPlayerPos(playerid, x, y, z);
- time = MoveObject(Shark[ii], x, y, z, 2.5);
- Hunting[ii] = gettime() + time + 5;
- SetTimerEx("ToFace", time + 10, 0, "ii", playerid, ii);
- }
- }
- }
- return 1;
- }
- SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1) {
- // SetObjectToFaceCords() By LucifeR //
- // LucifeR@vgames.co.il //
- // setting the objects cords
- new Float:x2,Float:y2,Float:z2;
- GetObjectPos(objectid, x2,y2,z2);
- // setting the distance values
- new Float:DX = floatabs(x2-x1);
- new Float:DY = floatabs(y2-y1);
- new Float:DZ = floatabs(z2-z1);
- // defining the angles and setting them to 0
- new Float:yaw = 0;
- new Float:pitch = 0;
- // check that there isnt any 0 in one of the distances,
- // if there is any use the given parameters:
- if(DY == 0 || DX == 0) {
- if(DY == 0 && DX > 0) {
- yaw = 00;
- pitch = 0;
- }
- else if(DY == 0 && DX < 0) {
- yaw = 180;
- pitch = 180;
- }
- else if(DY > 0 && DX == 0) {
- yaw = 90;
- pitch = 90;
- }
- else if(DY < 0 && DX == 0) {
- yaw = 270;
- pitch = 270;
- }
- else if(DY == 0 && DX == 0) {
- yaw = 0;
- pitch = 0;
- }
- }
- // calculating the angale using atan
- else { // non of the distances is 0.
- // calculatin the angles
- yaw = atan(DX/DY);
- pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
- // there are three quarters in a circle, now i will
- // check wich circle this is and change the angles
- // according to it.
- if(x1 > x2 && y1 <= y2) {
- yaw = yaw + 90;
- pitch = pitch - 45;
- }
- else if(x1 <= x2 && y1 < y2) {
- yaw = 90 - yaw;
- pitch = pitch - 45;
- }
- else if(x1 < x2 && y1 >= y2) {
- yaw = yaw - 90;
- pitch = pitch - 45;
- }
- else if(x1 >= x2 && y1 > y2) {
- yaw = 270 - yaw;
- pitch = pitch + 315;
- }
- // the pitch could be only in two quarters, lets see wich one:
- if(z1 < z2)
- pitch = 360-pitch;
- }
- // setting the object rotation (should be twice cuz of lame GTA rotation system)
- SetObjectRot(objectid, 0, 0, yaw);
- SetObjectRot(objectid, 0, pitch, yaw+90);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement