Advertisement
Guest User

Spec...

a guest
Oct 20th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.43 KB | None | 0 0
  1.  
  2. #pragma tabsize 0
  3. #include <a_samp>
  4. #include <core>
  5. #include <float>
  6.  
  7. #define COLOR_GREY 0xAFAFAFAA
  8. #define COLOR_GREEN 0x33AA33AA
  9. #define COLOR_RED 0xAA3333AA
  10. #define COLOR_YELLOW 0xFFFF00AA
  11. #define COLOR_WHITE 0xFFFFFFFF
  12.  
  13. forward OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid);
  14.  
  15. // DCMD
  16. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  17.  
  18. //------------------------------------------------------------------------------
  19.  
  20. #define ADMIN_SPEC_TYPE_NONE 0
  21. #define ADMIN_SPEC_TYPE_PLAYER 1
  22. #define ADMIN_SPEC_TYPE_VEHICLE 2
  23.  
  24. new CurrentVirtualWorld[MAX_PLAYERS];
  25.  
  26. enum pSpec
  27. {
  28. SpectateUpdate,
  29. SpectateID,
  30. SpectateType,
  31. };
  32. new Spec[MAX_PLAYERS][pSpec];
  33. new spectateupdatetimer;
  34.  
  35. //------------------------------------------------------------------------------
  36.  
  37. public OnFilterScriptInit()
  38. {
  39. spectateupdatetimer = SetTimer("SpectatorUpdate", 1000, 1);
  40. }
  41.  
  42. public OnFilterScriptExit()
  43. {
  44. KillTimer(spectateupdatetimer);
  45. }
  46. //------------------------------------------------------------------------------
  47.  
  48. public OnPlayerConnect(playerid)
  49. {
  50. Spec[playerid][SpectateUpdate] = 255;
  51. return 1;
  52. }
  53.  
  54. public OnPlayerDisconnect(playerid, reason)
  55. {
  56. for(new x=0; x<MAX_PLAYERS; x++)
  57. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  58. AdvanceSpectate(x);
  59. return 1;
  60. }
  61.  
  62. //------------------------------------------------------------------------------
  63.  
  64. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  65. {
  66. for(new x=0; x<MAX_PLAYERS; x++)
  67. {
  68. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE || GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
  69. {
  70. SetPlayerInterior(x,newinteriorid);
  71. }
  72. }
  73. }
  74.  
  75. public OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid)
  76. {
  77. for(new x=0; x<MAX_PLAYERS; x++)
  78. {
  79. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE || GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
  80. {
  81. SetPlayerVirtualWorld(x,newvirtualworldid);
  82. }
  83. }
  84. }
  85.  
  86. //--------------------[ DCMD ]--------------------------------------------------
  87.  
  88. dcmd_spec(playerid,params[])
  89. {
  90. new tmp[256], specplayerid, idx;
  91. tmp = strtok(params, idx);
  92.  
  93. if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /spec [playerid]");
  94. specplayerid = strval(tmp);
  95.  
  96. if(specplayerid == playerid) return SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot spectate yourself");
  97. if(GetPlayerState(specplayerid) != 1 && GetPlayerState(specplayerid) != 2 && GetPlayerState(specplayerid) != 3) return SendClientMessage(playerid, COLOR_RED, "Spectate: Player not spawned");
  98. if(IsPlayerConnected(specplayerid))
  99. {
  100. StartSpectate(playerid, specplayerid);
  101. return SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
  102. }
  103. else return SendClientMessage(playerid, COLOR_RED, "ERROR: that player isn't active.");
  104. }
  105.  
  106.  
  107. dcmd_specvehicle(playerid,params[])
  108. {
  109. new tmp[256], specvehicleid, idx;
  110. tmp = strtok(params, idx);
  111.  
  112. if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /specvehicle [vehicleid]");
  113. specvehicleid = strval(tmp);
  114.  
  115. if(specvehicleid < MAX_VEHICLES)
  116. {
  117. TogglePlayerSpectating(playerid, 1);
  118. PlayerSpectateVehicle(playerid, specvehicleid);
  119. Spec[playerid][SpectateID] = specvehicleid;
  120. SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
  121. return Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  122. } else return SendClientMessage(playerid,COLOR_RED,"ERROR: Invaild vehicle ID.");
  123. }
  124.  
  125.  
  126. dcmd_specoff(playerid,params[])
  127. {
  128. #pragma unused params
  129. if(Spec[playerid][SpectateType] != ADMIN_SPEC_TYPE_NONE)
  130. {
  131. StopSpectate(playerid);
  132. return SendClientMessage(playerid,COLOR_GREY,"No Longer Spectating");
  133. }
  134. else return SendClientMessage(playerid,COLOR_RED,"ERROR: Your not Specing anybody.");
  135. }
  136.  
  137. public OnPlayerCommandText(playerid, cmdtext[])
  138. {
  139. if(!IsPlayerAdmin(playerid)) return 0;
  140.  
  141. // Spec
  142. dcmd(spec, 4, cmdtext);
  143. dcmd(specvehicle, 11, cmdtext);
  144. dcmd(specoff, 7, cmdtext);
  145. return 0;
  146. }
  147.  
  148. //------------------------------------------------------------------------------
  149.  
  150. forward SpectatorUpdate(playerid);
  151. public SpectatorUpdate(playerid)
  152. {
  153. for(new i = 0; i < MAX_PLAYERS; i++)
  154. {
  155. if(GetPlayerState(i) == PLAYER_STATE_SPECTATING && Spec[i][SpectateType] == ADMIN_SPEC_TYPE_PLAYER || GetPlayerState(i) == PLAYER_STATE_SPECTATING && Spec[i][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
  156. {
  157. if(IsPlayerConnected(i))
  158. {
  159. if(Spec[i][SpectateUpdate] < 253 && Spec[i][SpectateUpdate] != 255)
  160. {
  161. new targetid = Spec[i][SpectateUpdate];
  162. if(IsPlayerConnected(targetid))
  163. {
  164. if(IsPlayerAdmin(i))
  165. {
  166. new string[100], Float:hp, Float:ar;
  167. GetPlayerName(targetid,string,sizeof(string));
  168. GetPlayerHealth(targetid, hp); GetPlayerArmour(targetid, ar);
  169. format(string,sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~w~%s - id:%d~n~(Jump - Sprint)~n~hp:%0.1f ar:%0.1f $%d", string,targetid,hp,ar,GetPlayerMoney(targetid) );
  170. GameTextForPlayer(i,string,4000,3);
  171. }
  172. }
  173. }
  174. if(Spec[i][SpectateUpdate] == 253)
  175. {
  176. Spec[i][SpectateUpdate] = 255;
  177. }
  178. }
  179. }
  180. }
  181. }
  182.  
  183. //------------------------------------------------------------------------------
  184.  
  185. stock StartSpectate(playerid, specplayerid)
  186. {
  187. for(new x=0; x<MAX_PLAYERS; x++)
  188. {
  189. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  190. {
  191. AdvanceSpectate(x);
  192. }
  193. }
  194. TogglePlayerSpectating(playerid, 1);
  195. Spec[playerid][SpectateUpdate] = specplayerid;
  196. SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
  197. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specplayerid));
  198. if(IsPlayerInAnyVehicle(specplayerid))
  199. {
  200. PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specplayerid));
  201. Spec[playerid][SpectateID] = specplayerid;
  202. Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  203. }
  204. else
  205. {
  206. PlayerSpectatePlayer(playerid, specplayerid);
  207. Spec[playerid][SpectateID] = specplayerid;
  208. Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
  209. }
  210. return 1;
  211. }
  212.  
  213. stock StopSpectate(playerid)
  214. {
  215. TogglePlayerSpectating(playerid, 0);
  216. Spec[playerid][SpectateID] = INVALID_PLAYER_ID;
  217. Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_NONE;
  218. Spec[playerid][SpectateUpdate] = 255;
  219. GameTextForPlayer(playerid,"~n~~n~~n~~w~Spectate mode ended",1000,3);
  220. return 1;
  221. }
  222.  
  223. stock AdvanceSpectate(playerid)
  224. {
  225. if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
  226. if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  227. {
  228. for(new x=Spec[playerid][SpectateID]+1; x<=MAX_PLAYERS; x++)
  229. {
  230. if(x == MAX_PLAYERS) x = 0;
  231. if(IsPlayerConnected(x) && x != playerid)
  232. {
  233. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
  234. {
  235. continue;
  236. }
  237. else
  238. {
  239. StartSpectate(playerid, x);
  240. break;
  241. }
  242. }
  243. }
  244. }
  245. return 1;
  246. }
  247.  
  248. stock ReverseSpectate(playerid)
  249. {
  250. if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
  251. if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  252. {
  253. for(new x=Spec[playerid][SpectateID]-1; x>=0; x--)
  254. {
  255. if(x == 0) x = MAX_PLAYERS;
  256. if(IsPlayerConnected(x) && x != playerid)
  257. {
  258. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
  259. {
  260. continue;
  261. }
  262. else
  263. {
  264. StartSpectate(playerid, x);
  265. break;
  266. }
  267. }
  268. }
  269. }
  270. return 1;
  271. }
  272.  
  273. //------------------------------------------------------------------------------
  274.  
  275. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  276. {
  277.  
  278. if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  279. {
  280. if(newkeys == KEY_JUMP) AdvanceSpectate(playerid);
  281. else if(newkeys == KEY_SPRINT) ReverseSpectate(playerid);
  282. }
  283. return 1;
  284. }
  285.  
  286. public OnPlayerStateChange(playerid, newstate, oldstate)
  287. {
  288. new vehicleid;
  289. vehicleid = GetPlayerVehicleID(playerid);
  290. for(new x=0; x<MAX_PLAYERS; x++)
  291. {
  292. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
  293. {
  294. if(GetPlayerState(playerid) == PLAYER_STATE_NONE)
  295. {
  296. StopSpectate(x);
  297. }
  298. }
  299. }
  300.  
  301. for(new x=0; x<MAX_PLAYERS; x++)
  302. {
  303. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
  304. {
  305. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  306. {
  307. TogglePlayerSpectating(x, 1);
  308. PlayerSpectatePlayer(x, playerid);
  309. Spec[x][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
  310. }
  311. }
  312. }
  313.  
  314. for(new x=0; x<MAX_PLAYERS; x++)
  315. {
  316. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  317. {
  318. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
  319. {
  320. TogglePlayerSpectating(x, 1);
  321. PlayerSpectateVehicle(x, vehicleid);
  322. Spec[x][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  323. }
  324. }
  325. }
  326.  
  327. for(new x=0; x<MAX_PLAYERS; x++)
  328. {
  329. if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  330. {
  331. if(GetPlayerState(playerid) == PLAYER_STATE_WASTED)
  332. {
  333. AdvanceSpectate(x);
  334. }
  335. }
  336. }
  337. return 1;
  338. }
  339.  
  340. //------------------------------------------------------------------------------
  341.  
  342. public OnPlayerUpdate(playerid)
  343. {
  344. if(!IsPlayerConnected(playerid)) return 0;
  345.  
  346. new CurVirtualWorld[MAX_PLAYERS];
  347. CurVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
  348. if(CurVirtualWorld[playerid] != CurrentVirtualWorld[playerid])
  349. {
  350. OnPlayerVirtualWorldChange(playerid, CurVirtualWorld[playerid], CurrentVirtualWorld[playerid]);
  351. CurrentVirtualWorld[playerid] = CurVirtualWorld[playerid];
  352. }
  353. return 1;
  354. }
  355.  
  356. //------------------------------------------------------------------------------
  357.  
  358. forward ConnectedPlayers();
  359. public ConnectedPlayers()
  360. {
  361. new Connected;
  362. for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Connected++;
  363. return Connected;
  364. }
  365.  
  366. stock strtok(const string[], &index)
  367. {
  368. new length = strlen(string);
  369. while ((index < length) && (string[index] <= ' '))
  370. {
  371. index++;
  372. }
  373.  
  374. new offset = index;
  375. new result[20];
  376. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  377. {
  378. result[index - offset] = string[index];
  379. index++;
  380. }
  381. result[index - offset] = EOS;
  382. return result;
  383. }
  384.  
  385. stock pName(playerid)
  386. {
  387. new name[MAX_PLAYER_NAME];
  388. GetPlayerName(playerid, name, sizeof(name));
  389. return name;
  390. }
  391.  
  392.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement