Advertisement
Guest User

OnPlayerDisconnect

a guest
Apr 14th, 2016
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.38 KB | None
  1. public OnPlayerDisconnect(playerid, reason)
  2. {
  3. new name[MAX_PLAYER_NAME];
  4. GetPlayerName(playerid, name, sizeof(name));
  5. if(!strcmp(name, "InvalidNick", true)) return 1;
  6. if(!strcmp(name, "BannedPlayer", true)) return 1;
  7.  
  8. if(playerid == MAX_PLAYERS) return 1;
  9. PlayersConnected--;
  10. if(PlayerInfo[playerid][pMember] == 4 && PlayerInfo[playerid][pDuty] == 1|| PlayerInfo[playerid][pLeader] == 4 && PlayerInfo[playerid][pDuty] == 1)
  11. {
  12. Medics -= 1;
  13. }
  14. if(pDragging[playerid] != -1)
  15. {
  16. TogglePlayerControllable(pDragging[playerid], 1);
  17. KillTimer(pDragTimer[playerid]);
  18. pDrag[pDragging[playerid]] = -1;
  19. pDragging[playerid] = -1;
  20. }
  21. if(broadcasting-2 == playerid)
  22. {
  23. broadcasting = 0;
  24. UpdateSANewsBroadcast();
  25. DestroyDynamic3DTextLabel(camera);
  26. new string[128];
  27. foreach(Player, i)
  28. {
  29. if(WatchingTV[i] == 1)
  30. {
  31. WatchingTV[i] = 0;
  32. viewers--;
  33. UpdateSANewsBroadcast();
  34. format(string, sizeof(string), "* %s stops watching TV", GetPlayerNameEx(i));
  35. SendClientMessage(i, COLOR_GREY, string);
  36. TogglePlayerSpectating(i, false);
  37. SetCameraBehindPlayer(i);
  38. SetPlayerVirtualWorld(i, BroadcastLastVW[i]);
  39. ProxDetector(30.0, i, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  40. SetPlayerPos(i,BroadcastFloats[i][1],BroadcastFloats[i][2],BroadcastFloats[i][3]);
  41. PlayerInfo[i][pVW] = BroadcastLastVW[i];
  42. SetPlayerInterior(i, BroadcastLastInt[i]);
  43. PlayerInfo[i][pInt] = BroadcastLastInt[i];
  44. return 1;
  45. }
  46. }
  47. }
  48. TextDrawHideForPlayer(playerid,blind);
  49. if(pDrag[playerid] != -1)
  50. {
  51. TogglePlayerControllable(playerid, 1);
  52. KillTimer(pDragTimer[pDrag[playerid]]);
  53. pDragging[pDrag[playerid]] = -1;
  54. pDrag[playerid] = -1;
  55. }
  56. if(PlayerInfo[playerid][pWExists] == 1)
  57. {
  58. WeedLogout(playerid);
  59. }
  60. if(pTazer[playerid] == 1) GivePlayerValidWeapon(playerid,pTazerReplace[playerid],60000);
  61. if(GetPVarInt(playerid, "SpeedRadar") == 1) GivePlayerValidWeapon(playerid, GetPVarInt(playerid, "RadarReplacement"), 60000);
  62. if(GetPVarInt(playerid, "MovingStretcher") != -1)
  63. {
  64. KillTimer(GetPVarInt(playerid, "TickEMSMove"));
  65. DeletePVar(GetPVarInt(playerid, "MovingStretcher"), "OnStretcher");
  66. SetPVarInt(playerid, "MovingStretcher", -1);
  67. }
  68. if(GetPVarInt(playerid, "Hospital") > 0)
  69. {
  70. PlayerInfo[playerid][pHospital] = 1;
  71. }
  72. if(GetPVarInt(playerid, "Injured") == 1)
  73. {
  74. PlayerInfo[playerid][pHospital] = 1;
  75. KillEMSQueue(playerid);
  76. ResetPlayerWeaponsEx(playerid);
  77. }
  78. if(PlayerInfo[playerid][pAlreadyBoombox])
  79. {
  80. DestroyDynamicObject(PlayerInfo[playerid][pBoombox]);
  81. DestroyDynamic3DTextLabel(bbox[playerid]);
  82. PlayerInfo[playerid][pAlreadyBoombox] = 0;
  83. }
  84. for(new s = 0; s < 12; s++)
  85. {
  86. if(PlayerInfo[playerid][pAGuns][s] != 0)
  87. {
  88. RemovePlayerWeapon(playerid, PlayerInfo[playerid][pAGuns][s]);
  89. }
  90. }
  91. if(control[playerid] == 1)
  92. {
  93. control[playerid] = 0;
  94. KillTimer(ControlTimer[playerid]);
  95. }
  96. if(PlayerInfo[playerid][pLockCar] != INVALID_VEHICLE_ID)
  97. {
  98. vehicle_unlock_doors(PlayerInfo[playerid][pLockCar]);
  99. }
  100. if(PlayerInfo[playerid][pVehicleKeysFrom] != INVALID_PLAYER_ID)
  101. {
  102. PlayerVehicleInfo[PlayerInfo[playerid][pVehicleKeysFrom]][PlayerInfo[playerid][pVehicleKeys]][pvAllowedPlayerId] = INVALID_PLAYER_ID;
  103. }
  104. new string[128], Float:playerPos[3];
  105. GetPlayerPos(playerid, playerPos[0], playerPos[1], playerPos[2]);
  106. if(!playerRelogging[playerid]) {
  107. switch (reason)
  108. {
  109. case 0:
  110. {
  111. format(string, sizeof(string), "%s has left the server (timeout).", GetPlayerNameEx(playerid));
  112. foreach(Player, i) {
  113. if((PlayerInfo[i][pAdmin] >= 1) && !togJoin[playerid]) {
  114. if(!IsPlayerInRangeOfPoint(i, 30.0, playerPos[0], playerPos[1], playerPos[2])) {
  115. SendClientMessage(i, TEAM_AZTECAS_COLOR, string);
  116. }
  117. }
  118. }
  119. ProxDetector(30.0, playerid, string, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
  120. if(PlayerCuffed[playerid] != 0)
  121. {
  122. PlayerInfo[playerid][pJailed] = 4;
  123. PlayerInfo[playerid][pJailTime] += 20*60;
  124. }
  125. }
  126. case 1:
  127. {
  128. format(string, sizeof(string), "%s has left the server (leaving).", GetPlayerNameEx(playerid));
  129. foreach(Player, i) {
  130. if((PlayerInfo[i][pAdmin] >= 1) && !togJoin[playerid]) {
  131. if(!IsPlayerInRangeOfPoint(i, 30.0, playerPos[0], playerPos[1], playerPos[2])) {
  132. SendClientMessage(i, TEAM_AZTECAS_COLOR, string);
  133. }
  134. }
  135. }
  136. ProxDetector(30.0, playerid, string, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
  137. if(PlayerCuffed[playerid] != 0)
  138. {
  139. PlayerInfo[playerid][pJailed] = 4;
  140. PlayerInfo[playerid][pJailTime] += 20*60;
  141. }
  142. }
  143. case 2:
  144. {
  145. format(string, sizeof(string), "%s has left the server (kicked/banned).", GetPlayerNameEx(playerid));
  146. foreach(Player, i) {
  147. if(( PlayerInfo[i][pAdmin] >= 1) && !togJoin[playerid]) {
  148. if(!IsPlayerInRangeOfPoint(i, 30.0, playerPos[0], playerPos[1], playerPos[2])) {
  149. SendClientMessage(i, TEAM_AZTECAS_COLOR, string);
  150. }
  151. }
  152. }
  153. ProxDetector(30.0, playerid, string, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
  154. }
  155. }
  156. } else {
  157. format(string, sizeof(string), "%s has left the server (relogging).", GetPlayerNameEx(playerid));
  158. foreach(Player, i) {
  159. if((PlayerInfo[i][pAdmin] >= 1) && !togJoin[playerid]) {
  160. if(!IsPlayerInRangeOfPoint(i, 30.0, playerPos[0], playerPos[1], playerPos[2])) {
  161. SendClientMessage(i, TEAM_AZTECAS_COLOR, string);
  162. }
  163. }
  164. }
  165. ProxDetector(30.0, playerid, string, COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
  166. }
  167. if(EventKernel[EventRequest] == playerid)
  168. {
  169. EventKernel[EventRequest] = 999;
  170. ABroadCast( COLOR_YELLOW, "{AA3333}AdmWarning{FFFF00}: The player that was requesting an event has disconnected/crashed.", 4 );
  171. }
  172. if(EventKernel[EventCreator] == playerid)
  173. {
  174. EventKernel[EventCreator] = 999;
  175. ABroadCast( COLOR_YELLOW, "{AA3333}AdmWarning{FFFF00}: The player that was creating an event has disconnected/crashed.", 4 );
  176. }
  177. if(EventKernel[EventStaff][0] == playerid)
  178. {
  179. EventKernel[EventStaff][0] = 999;
  180. }
  181. else if(EventKernel[EventStaff][1] == playerid)
  182. {
  183. EventKernel[EventStaff][1] = 999;
  184. }
  185. else if(EventKernel[EventStaff][2] == playerid)
  186. {
  187. EventKernel[EventStaff][2] = 999;
  188. }
  189. else if(EventKernel[EventStaff][3] == playerid)
  190. {
  191. EventKernel[EventStaff][3] = 999;
  192. }
  193. else if(EventKernel[EventStaff][4] == playerid)
  194. {
  195. EventKernel[EventStaff][4] = 999;
  196. }
  197. if(GetPVarInt(playerid, "IsInArena") >= 0)
  198. {
  199. LeavePaintballArena(playerid, GetPVarInt(playerid, "IsInArena"));
  200. PlayerInfo[playerid][pInt] = GetPVarInt(playerid, "pbOldInt");
  201. PlayerInfo[playerid][pVW] = GetPVarInt(playerid, "pbOldVW");
  202. PlayerInfo[playerid][pPos_x] = GetPVarFloat(playerid, "pbOldX");
  203. PlayerInfo[playerid][pPos_y] = GetPVarFloat(playerid, "pbOldY");
  204. PlayerInfo[playerid][pPos_z] = GetPVarFloat(playerid, "pbOldZ");
  205. PlayerInfo[playerid][pHealth] = GetPVarFloat(playerid, "pbOldHealth");
  206. PlayerInfo[playerid][pArmor] = GetPVarFloat(playerid, "pbOldArmor");
  207. SetPlayerHealth(playerid,GetPVarFloat(playerid, "pbOldHealth"));
  208. SetPlayerArmour(playerid,GetPVarFloat(playerid, "pbOldArmor"));
  209. }
  210. else if(GetPVarInt(playerid, "EventToken") == 0)
  211. {
  212. new Float: x, Float: y, Float: z;
  213. PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
  214. PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
  215. PlayerInfo[playerid][pChar] = PlayerInfo[playerid][pModel];
  216. GetPlayerPos(playerid, x, y, z);
  217. GetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos_r]);
  218. PlayerInfo[playerid][pPos_x] = x;
  219. PlayerInfo[playerid][pPos_y] = y;
  220. PlayerInfo[playerid][pPos_z] = z;
  221. }
  222. else if(GetPVarInt(playerid, "EventToken") == 1)
  223. {
  224. PlayerInfo[playerid][pInt] = EventLastInt[playerid];
  225. PlayerInfo[playerid][pVW] = EventLastVW[playerid];
  226. PlayerInfo[playerid][pChar] = PlayerInfo[playerid][pModel];
  227. PlayerInfo[playerid][pPos_r] = EventFloats[playerid][0];
  228. PlayerInfo[playerid][pPos_x] = EventFloats[playerid][1];
  229. PlayerInfo[playerid][pPos_y] = EventFloats[playerid][2];
  230. PlayerInfo[playerid][pPos_z] = EventFloats[playerid][3];
  231. }
  232. if(WatchingTV[playerid] == 1)
  233. {
  234. PlayerInfo[playerid][pInt] = BroadcastLastInt[playerid];
  235. PlayerInfo[playerid][pVW] = BroadcastLastVW[playerid];
  236. PlayerInfo[playerid][pPos_r] = BroadcastFloats[playerid][0];
  237. PlayerInfo[playerid][pPos_x] = BroadcastFloats[playerid][1];
  238. PlayerInfo[playerid][pPos_y] = BroadcastFloats[playerid][2];
  239. PlayerInfo[playerid][pPos_z] = BroadcastFloats[playerid][3];
  240. WatchingTV[playerid] = 0;
  241. viewers--;
  242. UpdateSANewsBroadcast();
  243. }
  244. if(Spectate[playerid] < 553)
  245. {
  246. PlayerInfo[playerid][pInt] = GetPVarInt(playerid, "SpecInt");
  247. PlayerInfo[playerid][pVW] = GetPVarInt(playerid, "SpecVW");
  248. PlayerInfo[playerid][pChar] = PlayerInfo[playerid][pModel];
  249. PlayerInfo[playerid][pPos_x] = GetPVarFloat(playerid, "SpecPosX");
  250. PlayerInfo[playerid][pPos_y] = GetPVarFloat(playerid, "SpecPosY");
  251. PlayerInfo[playerid][pPos_z] = GetPVarFloat(playerid, "SpecPosZ");
  252. GettingSpectated[Spectate[playerid]] = 999;
  253. Spectate[playerid] = 999;
  254. }
  255. if(gBike[playerid] >= 0 && gBikeRenting[playerid] == 1)
  256. {
  257. gBike[playerid] = 0;
  258. gBikeRenting[playerid] = 0;
  259. KillTimer(GetPVarInt(playerid, "RentTime"));
  260. }
  261.  
  262. if(GetPVarInt(playerid, "gpsonoff") == 1) TextDrawDestroy(GPS[playerid]);
  263.  
  264. if(GetPVarInt(playerid, "fuelonoff") == 1)
  265. {
  266. DestroyProgressBar(FuelBar[playerid]);
  267. textdrawscount--;
  268. FuelBar[playerid] = INVALID_BAR_ID;
  269. }
  270.  
  271. if(InsideShamal[playerid] != INVALID_VEHICLE_ID)
  272. {
  273. if(InsideShamal[playerid] == INVALID_VEHICLE_ID || GetVehicleModel(InsideShamal[playerid]) != 519)
  274. {
  275. GivePlayerValidWeapon(playerid, 46, 60000);
  276. PlayerInfo[playerid][pPos_x] = 0.000000;
  277. PlayerInfo[playerid][pPos_y] = 0.000000;
  278. PlayerInfo[playerid][pPos_z] = 420.000000;
  279. }
  280. else
  281. {
  282. new Float:X, Float:Y, Float:Z;
  283. GetVehiclePos(InsideShamal[playerid], X, Y, Z);
  284. PlayerInfo[playerid][pPos_x] = X;
  285. PlayerInfo[playerid][pPos_y] = Y;
  286. PlayerInfo[playerid][pPos_z] = Z;
  287.  
  288. new Float:XB, Float:YB, Float:ZB;
  289. GetVehiclePos(InsideShamal[playerid], XB, YB, ZB);
  290. if(ZB > 50.0)
  291. {
  292. GivePlayerValidWeapon(playerid, 46, 60000);
  293. }
  294. }
  295. PlayerInfo[playerid][pVW] = 0;
  296. SetPlayerVirtualWorld(playerid, 0);
  297. PlayerInfo[playerid][pInt] = 0;
  298. SetPlayerInterior(playerid, 0);
  299. InsideShamal[playerid] = INVALID_VEHICLE_ID;
  300. }
  301. if(BankJobPlayer == playerid)
  302. {
  303. format(string, 256, "City Alert: The Bank Robbery attempt has failed!");
  304. RemovePlayerAttachedObject(playerid, 0);
  305. SendClientMessageToAll(COLOR_LIGHTBLUE, string);
  306. BankJobPlayer = 999;
  307. TimeAfterBankJob = 3;
  308. BankJobTime = -1;
  309. BankDeliverTime = -1;
  310. }
  311. InsideShamal[playerid] = INVALID_VEHICLE_ID;
  312.  
  313. gActivePlayers[playerid]--;
  314. numplayers--;
  315. PlayerInfo[playerid][pAdjustable] = 1;
  316. OnPlayerStatsUpdate(playerid);
  317. UnloadPlayerVehicles(playerid);
  318. ResetPlayerWeapons(playerid);
  319.  
  320. for(new i = 0; i < MAX_REPORTS; i++)
  321. {
  322. if(Reports[i][ReportFrom] == playerid)
  323. {
  324. Reports[i][ReportFrom] = 999;
  325. Reports[i][BeingUsed] = 0;
  326. Reports[i][TimeToExpire] = 0;
  327. }
  328. }
  329. foreach(Player, i)
  330. {
  331. if(TaxiAccepted[i] == playerid)
  332. {
  333. TaxiAccepted[i] = 999;
  334. GameTextForPlayer(i, "~w~Taxi Caller~n~~r~Left the game", 5000, 1);
  335. TaxiCallTime[i] = 0;
  336. DisablePlayerCheckpoint(i);
  337. }
  338. if(EMSAccepted[i] == playerid)
  339. {
  340. EMSAccepted[i] = 999;
  341. GameTextForPlayer(i, "~w~EMS Caller~n~~r~Left the game", 5000, 1);
  342. EMSCallTime[i] = 0;
  343. DisablePlayerCheckpoint(i);
  344. }
  345. if(BusAccepted[i] == playerid)
  346. {
  347. BusAccepted[i] = 999;
  348. GameTextForPlayer(i, "~w~Bus Caller~n~~r~Left the game", 5000, 1);
  349. BusCallTime[i] = 0;
  350. DisablePlayerCheckpoint(i);
  351. }
  352. if(MedicAccepted[i] == playerid)
  353. {
  354. TaxiAccepted[playerid] = 999; BusAccepted[playerid] = 999; MedicAccepted[playerid] = 999;
  355. GameTextForPlayer(i, "~w~Medic Caller~n~~r~Left the game", 5000, 1);
  356. MedicCallTime[i] = 0;
  357. DisablePlayerCheckpoint(i);
  358. }
  359. if(OrderAssignedTo[i] == playerid)
  360. {
  361. OrderAssignedTo[i] = INVALID_PLAYER_ID;
  362. }
  363. }
  364. if(HaveGPS[playerid])
  365. {
  366. KillTimer(GPSTimer[playerid]);
  367. HaveGPS[playerid] = false;
  368. GPSTimer[playerid] = 0;
  369. }
  370. if(TransportCost[playerid] > 0 && TransportDriver[playerid] < 999)
  371. {
  372. if(IsPlayerConnected(TransportDriver[playerid]))
  373. {
  374. TransportMoney[TransportDriver[playerid]] += TransportCost[playerid];
  375. TransportTime[TransportDriver[playerid]] = 0;
  376. TransportCost[TransportDriver[playerid]] = 0;
  377. format(string, sizeof(string), "~w~Passenger left~n~~g~Earned $%d",TransportCost[playerid]);
  378. GameTextForPlayer(TransportDriver[playerid], string, 5000, 1);
  379. TransportDriver[playerid] = 999;
  380. }
  381. }
  382. if(GotHit[playerid] > 0)
  383. {
  384. if(GetChased[playerid] < 999)
  385. {
  386. if(IsPlayerConnected(GetChased[playerid]))
  387. {
  388. SendClientMessageEx(GetChased[playerid], COLOR_YELLOW, "Your hit has left the server.");
  389. GoChase[GetChased[playerid]] = 999;
  390. }
  391. }
  392. }
  393. if(GoChase[playerid] < 999)
  394. {
  395. GetChased[GoChase[playerid]] = 999;
  396. GotHit[GoChase[playerid]] = 999;
  397. }
  398. if(HireCar[playerid] != 299)
  399. {
  400. gLastDriver[HireCar[playerid]] = 300;
  401. vehicle_unlock_doors(HireCar[playerid]);
  402. }
  403. if (gLastCar[playerid] > 0)
  404. {
  405. gLastDriver[gLastCar[playerid]] = 300;
  406. if(PlayerInfo[playerid][pPhousekey] != gLastCar[playerid]-1)
  407. {
  408. vehicle_unlock_doors(gLastCar[playerid]);
  409. }
  410. }
  411. if(PlayerBoxing[playerid] > 0)
  412. {
  413. if(Boxer1 == playerid)
  414. {
  415. if(IsPlayerConnected(Boxer2))
  416. {
  417. if(IsPlayerInRangeOfPoint(PlayerBoxing[Boxer2], 20.0, 768.94, -70.87, 1001.56))
  418. {
  419. PlayerBoxing[Boxer2] = 0;
  420. SetPlayerPos(Boxer2, 768.48, -73.66, 1000.57);
  421. SetPlayerInterior(Boxer2, 7);
  422. GameTextForPlayer(Boxer2, "~r~Match interupted", 5000, 1);
  423. return 1;
  424. }
  425. PlayerBoxing[Boxer2] = 0;
  426. SetPlayerPos(Boxer2, 765.8433,3.2924,1000.7186);
  427. SetPlayerInterior(Boxer2, 5);
  428. GameTextForPlayer(Boxer2, "~r~Match interupted", 5000, 1);
  429. }
  430. }
  431. else if(Boxer2 == playerid)
  432. {
  433. if(IsPlayerConnected(Boxer1))
  434. {
  435. if(IsPlayerInRangeOfPoint(PlayerBoxing[Boxer1],20.0,764.35, -66.48, 1001.56))
  436. {
  437. PlayerBoxing[Boxer1] = 0;
  438. SetPlayerPos(Boxer1, 768.48, -73.66, 1000.57);
  439. SetPlayerInterior(Boxer1, 7);
  440. GameTextForPlayer(Boxer1, "~r~Match interupted", 5000, 1);
  441. return 1;
  442. }
  443. PlayerBoxing[Boxer1] = 0;
  444. SetPlayerPos(Boxer1, 765.8433,3.2924,1000.7186);
  445. SetPlayerInterior(Boxer1, 5);
  446. GameTextForPlayer(Boxer1, "~r~Match interupted", 5000, 1);
  447. }
  448. }
  449. InRing = 0;
  450. RoundStarted = 0;
  451. Boxer1 = INVALID_PLAYER_ID;
  452. Boxer2 = INVALID_PLAYER_ID;
  453. TBoxer = INVALID_PLAYER_ID;
  454. }
  455. if(GetPVarInt(playerid, "ModeratorDuty") == 1)
  456. {
  457. Moderators--;
  458. }
  459. if(TransportDuty[playerid] == 1)
  460. {
  461. TaxiDrivers -= 1;
  462. }
  463. else if(TransportDuty[playerid] == 2)
  464. {
  465. BusDrivers -= 1;
  466. }
  467. if(PlayerInfo[playerid][pJob] == 11 || PlayerInfo[playerid][pJob2] == 11)
  468. {
  469. if(JobDuty[playerid] == 1) { Medics -= 1; }
  470. }
  471. if(PlayerInfo[playerid][pJob] == 7 || PlayerInfo[playerid][pJob2] == 7)
  472. {
  473. if(JobDuty[playerid] == 1) { Mechanics -= 1; }
  474. }
  475. if(PlayerInfo[playerid][pJob] == 11 || PlayerInfo[playerid][pJob2] == 11)
  476. {
  477. if(JobDuty[playerid] == 1) { Coastguard -= 1; }
  478. }
  479. SaveContacts(playerid);
  480. return 1;
  481. }
Advertisement
RAW Paste Data Copied
Advertisement