Advertisement
Guest User

Bambi v0.9.5

a guest
Jun 30th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Bambi Ally!
  4. By Alternative112
  5.  
  6. Do NOT recirculate without first asking me!
  7. */
  8.  
  9. #include <a_samp>
  10.  
  11. #define Holding(%0) \
  12. ((newkeys & (%0)) == (%0))
  13.  
  14. new bambi;
  15. new bambiOwner = -1;
  16. new respawnTimer;
  17. new bool:canBambiAttack = true; //He only charges once every 5 seconds
  18. new bool:attacking = false; //If bambi is charging, don't make him follow the player
  19. new bool:canAttackPeople = true; //Can Bambi charge at players when the person who has him shoots them?
  20. new mapIcon = 69; //It must be unique, no other icons in your scripts must use it!
  21.  
  22. //Where Bambi spawns - change it to wherever you like.
  23. //By default he spawns under the bridge that connects Red County and LV.
  24. new Float:spawnX = 1777.2007;
  25. new Float:spawnY = 595.1467;
  26. new Float:spawnZ = 10.5952;
  27.  
  28. main() {
  29. print("||=-------------------------------=||");
  30. print("||= BAMBI TIME!!!! ||");
  31. print("||=-------------------------------=||");
  32. }
  33.  
  34. forward rechargeBambi();
  35. public rechargeBambi() {
  36. attacking = false;
  37. canBambiAttack = true;
  38. return 1;
  39. }
  40.  
  41. forward respawnBambi();
  42. public respawnBambi() {
  43. DestroyObject(bambi);
  44. bambi = CreateObject(19315, spawnX, spawnY, spawnZ, 0.0, 0.0, 0.0);
  45. return 1;
  46. }
  47.  
  48. stock detachBambi() {
  49. new Float:x, Float:y, Float:z;
  50. GetObjectPos(bambi, x, y, z);
  51. DestroyObject(bambi);
  52. bambi = CreateObject(19315, x, y, z, 0.0, 0.0, 0.0);
  53. return 1;
  54. }
  55.  
  56. public OnFilterScriptInit() {
  57. bambi = CreateObject(19315, spawnX, spawnY, spawnZ, 0.0, 0.0, 0.0);
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptExit() {
  62. DestroyObject(bambi);
  63.  
  64. for (new i = 0; i < GetMaxPlayers(); i++) {
  65. if (IsPlayerConnected(i)) {
  66. RemovePlayerMapIcon(i, mapIcon);
  67. }
  68. }
  69.  
  70. return 1;
  71. }
  72.  
  73. public OnPlayerSpawn(playerid) {
  74. SetPlayerMapIcon(playerid, mapIcon, spawnX, spawnY, spawnZ, 21, 0, MAPICON_LOCAL);
  75. if (playerid == bambiOwner) {
  76. respawnTimer = SetTimer("respawnBambi", 30000, false);
  77. bambiOwner = -1;
  78. detachBambi();
  79. }
  80. return 1;
  81. }
  82.  
  83. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) {
  84. if (canAttackPeople) {
  85. if (issuerid == bambiOwner && canBambiAttack && GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) {
  86. attacking = true;
  87. new Float:x, Float:y, Float:z, Float:bX, Float:bY, Float:bZ;
  88.  
  89. GetPlayerPos(playerid, x, y, z);
  90. GetObjectPos(bambi, bX, bY, bZ);
  91.  
  92. MoveObject(bambi, (x + (x - bX)), (y + (y - bY)), z, 30.0);
  93.  
  94. if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
  95. ApplyAnimation(playerid, "PED", "KO_SKID_FRONT", 4.1, 0, 1, 1, 0, 3000, 1);
  96. }
  97.  
  98. canBambiAttack = false;
  99. SetTimer("rechargeBambi", 5000, false);
  100. }
  101. }
  102. return 1;
  103. }
  104.  
  105. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  106. if (Holding(KEY_CROUCH)) {
  107. new Float:x, Float:y, Float:z;
  108. GetObjectPos(bambi, x, y, z);
  109.  
  110. if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z) && IsValidObject(bambi)) {
  111. if (bambiOwner == -1) {
  112. SendClientMessage(playerid, 0xFFFF00FF, "You have recruited Bambi. Press the submission key to set him free!");
  113. bambiOwner = playerid;
  114. KillTimer(respawnTimer);
  115. }
  116. }
  117. }
  118.  
  119. if (Holding(KEY_SUBMISSION)) {
  120. if (playerid == bambiOwner) {
  121. respawnTimer = SetTimer("respawnBambi", 30000, false);
  122. bambiOwner = -1;
  123.  
  124. if (IsPlayerInAnyVehicle(playerid)) {
  125. new Float:x, Float:y, Float:z;
  126. GetPlayerPos(playerid, x, y, z);
  127. SetObjectPos(bambi, (x - 5.0), (y - 5.0), (z - 1.0));
  128. }
  129. else {
  130. detachBambi();
  131. }
  132.  
  133. SendClientMessage(playerid, 0xFFFF00FF, "You have released Bambi into the wild.");
  134. }
  135. }
  136. return 1;
  137. }
  138.  
  139. public OnPlayerStateChange(playerid, newstate, oldstate) {
  140. if ((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) && newstate == PLAYER_STATE_ONFOOT) {
  141. if (playerid == bambiOwner) {
  142. new Float:x, Float:y, Float:z;
  143. GetPlayerPos(playerid, x, y, z);
  144.  
  145. DestroyObject(bambi);
  146. bambi = CreateObject(19315, (x - 2.0), (y - 2.0), z, 0.0, 0.0, 0.0);
  147. }
  148. }
  149. else if (oldstate == PLAYER_STATE_ONFOOT && (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)) {
  150. if (playerid == bambiOwner) {
  151. new Float:X, Float:Y, Float:Z;
  152. GetVehicleModelInfo(GetVehicleModel(playerid), VEHICLE_MODEL_INFO_SIZE, X, Y, Z);
  153. AttachObjectToVehicle(bambi, GetPlayerVehicleID(playerid), 0.0, 0.0, (Z * 0.80), 0.0, 0.0, 90.0);
  154. }
  155. }
  156. return 1;
  157. }
  158.  
  159. public OnPlayerConnect(playerid) {
  160. return 1;
  161. }
  162.  
  163. public OnPlayerDisconnect(playerid, reason) {
  164. detachBambi();
  165. respawnTimer = SetTimer("respawnBambi", 30000, false);
  166. return 1;
  167. }
  168.  
  169. public OnPlayerDeath(playerid, killerid, reason) {
  170. if (playerid == bambiOwner) {
  171. detachBambi();
  172. respawnTimer = SetTimer("respawnBambi", 30000, false);
  173. }
  174. return 1;
  175. }
  176.  
  177. public OnPlayerUpdate(playerid) {
  178. if (playerid == bambiOwner) {
  179. if (!IsPlayerInAnyVehicle(playerid)) {
  180. new Float:x, Float:y, Float:z, Float:bX, Float:bY, Float:bZ;
  181. GetPlayerPos(playerid, x, y, z);
  182. GetObjectPos(bambi, bX, bY, bZ);
  183.  
  184. //If the player somehow teleported, teleport bambi, too!
  185.  
  186. /*if (floatsub(bX, x) < 20.0 || floatadd(bX, x) > 20.0) {
  187. DestroyObject(bambi);
  188. bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
  189. return 1;
  190. }
  191.  
  192. if (floatsub(bY, y) < 20.0 || floatadd(bY, y) > 20.0) {
  193. DestroyObject(bambi);
  194. bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
  195. return 1;
  196. }
  197.  
  198. if (floatsub(bZ, z) < 20.0 || floatadd(bZ, z) > 20.0) {
  199. DestroyObject(bambi);
  200. bambi = CreateObject(19315, (x - 2.0), (y - 2.0), (z - 0.5), 0.0, 0.0, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
  201. return 1;
  202. }*/
  203.  
  204. if (!attacking) {
  205. MoveObject(bambi, (x - 2.0), (y - 2.0), (z - 0.5), 8.0);
  206. }
  207. }
  208. }
  209. return 1;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement