Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SHARK ID: 1608
- new sharkobject;
- new Float: playerPos[MAX_PLAYERS][3];
- new thisplayerfollowingbyshark[MAX_PLAYERS];
- new Float: startedfollowinghere[MAX_PLAYERS][3];
- stock IsPlayerSwimming(playerid)
- {
- new result = 0; // starting as player is not swimming and it will be change as 1 if player is swimming.
- if(GetPlayerAnimationIndex(playerid) == 1538
- || GetPlayerAnimationIndex(playerid) == 1539
- || GetPlayerAnimationIndex(playerid) == 1540
- || GetPlayerAnimationIndex(playerid) == 1541
- || GetPlayerAnimationIndex(playerid) == 1542
- || GetPlayerAnimationIndex(playerid) == 1543
- || GetPlayerAnimationIndex(playerid) == 1544
- || GetPlayerAnimationIndex(playerid) == 1250)
- {
- result = 1; // I found out this animations to check is player swimmming.
- }
- return result;
- }
- forward EachSecond();
- public EachSecond()
- {
- foreach(Player, i) // foreach is better than counting to 500 (I mean Max players)
- {
- if(thisplayerfollowingbyshark[i] == 1)
- {
- new Float: HP;
- GetPlayerHealth(i, HP);
- SetPlayerHealth(i, HP-2); // each second a bite and each bite 2 hp.
- new Float: fDistance = GetPlayerDistanceFromPoint(i, startedfollowinghere[i][0], startedfollowinghere[i][1], startedfollowinghere[i][2]);
- if(fDistance == 40)
- // player got away from shark, actually got away from the shark's original position.
- // If That's not right, just text me to fix it, I mean If I did not get right write it :)
- {
- thisplayerfollowingbyshark[i] = 0;
- MoveObject(sharkobject, 884.9488,-2006.6652,-0.2070,4.0,179.5435,46,26); // let it go to it's original location
- }
- }
- if(IsPlayerSwimming(i)) // Firstly, we need to check this.
- { // Yes, player is swimming, now let's check if player is near shark
- new Float: x, Float: y, Float: z;
- GetObjectPos(sharkobject, x, y, z);
- if(IsPlayerInRangeOfPoint(i, 5, x, y, z)) // to stop shark
- {
- GetObjectPos(sharkobject, x, y, z);
- MoveObject(sharkobject, x, y, z, 4.0);
- }
- else if(IsPlayerInRangeOfPoint(i, 40, x, y, z)) // player is near shark, as you wanted 40 radius.
- {
- thisplayerfollowingbyshark[i] = 1;
- GetPlayerPos(i, playerPos[i][0], playerPos[i][1], playerPos[i][2]); // We got positions
- startedfollowinghere[i][0] = playerPos[i][0];
- startedfollowinghere[i][1] = playerPos[i][1];
- startedfollowinghere[i][2] = playerPos[i][2];
- MoveObject(sharkobject,playerPos[i][0], playerPos[i][1], playerPos[i][2], 4.0); // used them here
- // as you wanted 4.0 speed.
- SetObjectToFaceCords(sharkobject, playerPos[i][0], playerPos[i][1], playerPos[i][2]); // used them here, too.
- }
- }
- else // If Player is not swimming
- {
- if(thisplayerfollowingbyshark[i] == 1) // and if player is following by shark
- {
- thisplayerfollowingbyshark[i] = 0;
- MoveObject(sharkobject, 884.9488,-2006.6652,-0.2070,4.0,179.5435,46,26); // let it go to it's original location
- }
- }
- }
- return 1;
- }
- stock SetObjectToFaceCords(objectid, Float:x1,Float:y1,Float:z1) // taken from application.
- {
- // 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