Advertisement
Guest User

Spectate System For Players By RandomDude!

a guest
Apr 20th, 2013
1,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. /*==============================================================================
  2. | Spectate System For Players |
  3. | By RandomDude |
  4. |==============================================================================*/
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <sscanf2>
  8. #include <foreach>
  9.  
  10. #if defined FILTERSCRIPT
  11. #endif
  12.  
  13. #undef MAX_PLAYERS
  14. #define MAX_PLAYERS 32 //Change this line to how many players can get into your server etc 0/200 it would be 200... So you would change 32 to 200 :)
  15. #define Grey 0xC0C0C0FF
  16.  
  17. new String[128], Float:SpecX[MAX_PLAYERS], Float:SpecY[MAX_PLAYERS], Float:SpecZ[MAX_PLAYERS], vWorld[MAX_PLAYERS], Inter[MAX_PLAYERS];
  18. new IsSpecing[MAX_PLAYERS], Name[MAX_PLAYER_NAME], IsBeingSpeced[MAX_PLAYERS],spectatorid[MAX_PLAYERS];
  19.  
  20.  
  21. CMD:spec(playerid, params[])
  22. {
  23. new id;
  24. if(sscanf(params,"u", id))return SendClientMessage(playerid, Grey, "Usage: /spec [id]");
  25. if(id == playerid)return SendClientMessage(playerid,Grey,"You cannot spec yourself.");
  26. if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid, Grey, "Player not found!");
  27. if(IsSpecing[playerid] == 1)return SendClientMessage(playerid,Grey,"You are already specing someone.");
  28. GetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
  29. Inter[playerid] = GetPlayerInterior(playerid);
  30. vWorld[playerid] = GetPlayerVirtualWorld(playerid);
  31. TogglePlayerSpectating(playerid, true);
  32. if(IsPlayerInAnyVehicle(id))
  33. {
  34. if(GetPlayerInterior(id) > 0)
  35. {
  36. SetPlayerInterior(playerid,GetPlayerInterior(id));
  37. }
  38. if(GetPlayerVirtualWorld(id) > 0)
  39. {
  40. SetPlayerVirtualWorld(playerid,GetPlayerVirtualWorld(id));
  41. }
  42. PlayerSpectateVehicle(playerid,GetPlayerVehicleID(id));
  43. }
  44. else
  45. {
  46. if(GetPlayerInterior(id) > 0)
  47. {
  48. SetPlayerInterior(playerid,GetPlayerInterior(id));
  49. }
  50. if(GetPlayerVirtualWorld(id) > 0)
  51. {
  52. SetPlayerVirtualWorld(playerid,GetPlayerVirtualWorld(id));
  53. }
  54. PlayerSpectatePlayer(playerid,id);
  55. }
  56. GetPlayerName(id, Name, sizeof(Name));
  57. format(String, sizeof(String),"You have started to spectate %s.",Name);
  58. SendClientMessage(playerid,0x0080C0FF,String);
  59. IsSpecing[playerid] = 1;
  60. IsBeingSpeced[id] = 1;
  61. spectatorid[playerid] = id;
  62. return 1;
  63. }
  64. CMD:specoff(playerid, params[])
  65. {
  66. if(IsSpecing[playerid] == 0)return SendClientMessage(playerid,Grey,"You are not spectating anyone.");
  67. TogglePlayerSpectating(playerid, 0);
  68. return 1;
  69. }
  70. public OnPlayerDisconnect(playerid, reason)
  71. {
  72. if(IsBeingSpeced[playerid] == 1)
  73. {
  74. foreach (new i : Player)
  75. {
  76. if(spectatorid[i] == playerid)
  77. {
  78. TogglePlayerSpectating(i,false);
  79. }
  80. }
  81. }
  82. return 1;
  83. }
  84. public OnPlayerDeath(playerid, killerid, reason)
  85. {
  86. if(IsBeingSpeced[playerid] == 1)
  87. {
  88. foreach (new i : Player)
  89. {
  90. if(spectatorid[i] == playerid)
  91. {
  92. TogglePlayerSpectating(i,false);
  93. }
  94. }
  95. }
  96. return 1;
  97. }
  98. public OnPlayerStateChange(playerid, newstate, oldstate)
  99. {
  100. if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  101. {
  102. if(IsBeingSpeced[playerid] == 1)
  103. {
  104. foreach (new i : Player)
  105. {
  106. if(spectatorid[i] == playerid)
  107. {
  108. PlayerSpectateVehicle(i, GetPlayerVehicleID(playerid));
  109. }
  110. }
  111. }
  112. }
  113. if(newstate == PLAYER_STATE_ONFOOT)
  114. {
  115. if(IsBeingSpeced[playerid] == 1)
  116. {
  117. foreach (new i : Player)
  118. {
  119. if(spectatorid[i] == playerid)
  120. {
  121. PlayerSpectatePlayer(i, playerid);
  122. }
  123. }
  124. }
  125. }
  126. return 1;
  127. }
  128. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  129. {
  130. if(IsBeingSpeced[playerid] == 1)
  131. {
  132. foreach (new i : Player)
  133. {
  134. if(spectatorid[i] == playerid)
  135. {
  136. SetPlayerInterior(i,GetPlayerInterior(playerid));
  137. SetPlayerVirtualWorld(i,GetPlayerVirtualWorld(playerid));
  138. }
  139. }
  140. }
  141. return 1;
  142. }
  143. public OnPlayerSpawn(playerid)
  144. {
  145. if(IsSpecing[playerid] == 1)
  146. {
  147. SetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
  148. SetPlayerInterior(playerid,Inter[playerid]);
  149. SetPlayerVirtualWorld(playerid,vWorld[playerid]);
  150. IsSpecing[playerid] = 0;
  151. IsBeingSpeced[spectatorid[playerid]] = 0;
  152. }
  153. return 1;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement