GammixSAMP

playerslib.inc - By Gammix

May 12th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.80 KB | None | 0 0
  1. /*
  2. Players Library Include (playerslib.inc)
  3. * Very useful and awesome player stuff:
  4. - Funtions
  5. - Callbacks
  6. - Macros !:D!
  7.  
  8. Author: (creator)
  9. * Gammix
  10.  
  11. (c) Copyright 2015
  12. * This file is provided as is (no warranties).
  13. */
  14.  
  15. /*
  16. FUNCTIONS:
  17. //playerfuncs.inc
  18. native GivePlayerScore(playerid, score);
  19. native SetPlayerMoney(playerid, money);
  20. native RemovePlayerWeapoon(playerid, weaponid);
  21. native SetPlayerFacingPoint(playerid, Float:x, Float:y);
  22. native IsPlayerFacingPoint(playerid, Float:x, Float:y, Float:range = 10.0);
  23. native SetPlayerFacingPlayer(playerid, targetid);
  24. native IsPlayerFacingPlayer(playerid, targetid, Float:range = 10.0);
  25. native IsPlayerBehindPlayer(playerid, targetid, Float:range = 10.0);
  26. native GetPlayerWeaponAmmo(playerid, weaponid);
  27. native SetPlayerWeaponAmmo(playerid, weaponid, ammo);
  28. native SetPlayerWalkingStyle(playerid, style);
  29. native GetPlayerWalkingStyle(playerid);
  30. native _
  31.  
  32. //playercalls.inc
  33. native IsPlayerPaused(playerid);
  34. native IsPlayerInClassSelection(playerid);
  35. native GetPlayerPausedTime(playerid);
  36. native _
  37.  
  38. //playerstates.inc
  39. native IsPlayerSpawned(playerid);
  40. native IsPlayerSpectating(playerid);
  41. native IsPlayerDriver(playerid);
  42. native IsPlayerInClassSelection(playerid);
  43. native IsPlayerDead(playerid);
  44. native _
  45.  
  46. //playerstats.inc
  47. native GetPlayerKills(playerid);
  48. native GetPlayerDeaths(playerid);
  49. native GetPlayerSpree(playerid);
  50. native GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds);
  51. native GetPlayerHeadshots(playerid);
  52. native GetPlayerWeaponShots(playerid);
  53. native GetPlayerWeaponHits(playerid);
  54.  
  55. CALLBACKS:
  56. /playerfuncs.inc
  57. public public OnPlayerWalk(playerid, style)
  58.  
  59. //playercalls.inc
  60. public OnPlayerPosChange(playerid, Float:newx, Float:newy, Float:newz, Float:oldx, Float:oldy, Float:oldz);
  61. public OnPlayerFacingAngleChange(playerid, Float:newangle, Float:oldangle);
  62. public OnPlayerWeaponChange(playerid, newweapon, oldweapon);
  63. public OnPlayerHealthChange(playerid, Float:newhealth, Float:oldhealth);
  64. public OnPlayerArmourChange(playerid, Float:newarmour, Float:oldarmour);
  65. public OnPlayerVirtualWorldChange(playerid, newworld, oldworld);
  66. public OnPlayerSkinChange(playerid, newskin, oldskin);
  67. public OnPlayerPingChange(playerid, newping, oldping);
  68. public OnPlayerAmmoChange(playerid, weaponid, newammo, oldammo);
  69. public OnPlayerKillPlayer(playerid, killerid, weaponid);
  70. public OnPlayerPause(playerid);
  71. public OnPlayerUnpause(playerid, time);
  72. public OnPlayerFakeKill(playerid, count);
  73.  
  74. //playerstates.inc
  75. //no callbacks
  76.  
  77. //playerstats.inc
  78. public OnPlayerHeadshot(playerid, issuerid, weaponid)
  79. */
  80.  
  81. //-----
  82. //playercalls.inc
  83. //-----
  84.  
  85. //playercalls.inc
  86. #define PAUSE_CHECK_TIME 5 // This is the time after which the player will be considered as PAUSED.
  87. #define ANTI_FAKE_KILL //comment this if you don't want anti fake kill system
  88.  
  89. enum PlayerCallEnum
  90. {
  91. Float:P_HEALTH,
  92. Float:P_ARMOUR,
  93.  
  94. Float:P_X,
  95. Float:P_Y,
  96. Float:P_Z,
  97. Float:P_ANGLE,
  98.  
  99. P_WORLDID,
  100.  
  101. P_SKIN,
  102.  
  103. P_WEAPON,
  104. P_AMMO,
  105.  
  106. P_PING,
  107.  
  108. P_LAST_UPDATE,
  109. bool:P_PAUSED,
  110. P_PAUSE_CHECK_TIMER,
  111. P_PAUSED_TIME,
  112.  
  113. P_DEATHS,
  114. P_DEATH_TICK
  115. }
  116. static gPlayerCall[MAX_PLAYERS][PlayerCallEnum];
  117.  
  118. //playerfuncs.inc
  119. static gWalkingStyle[MAX_PLAYERS];
  120.  
  121. //playerstats.inc
  122. enum PlayerEnum
  123. {
  124. P_KILLS,
  125. P_DEATHS,
  126. P_SPREE,
  127. P_TIME[3],
  128. P_TIMER,
  129. P_HEADSHOTS,
  130. P_SHOTS,
  131. P_HITS
  132. }
  133. static gPlayer[MAX_PLAYERS][PlayerEnum];
  134.  
  135. //-----------------------
  136.  
  137. #if ! defined IsValidWeapon
  138. #define IsValidWeapon(%0) \
  139. (%0 < 47)
  140. #endif
  141.  
  142. #if ! defined IsPlayerInClassSelection
  143. static IsPlayerInClassSelection(playerid)
  144. {
  145. if(! IsPlayerConnected(playerid)) return false;
  146. new Float: health = 0.0;
  147. GetPlayerHealth(playerid, health);
  148. if(GetPlayerState(playerid) == PLAYER_STATE_WASTED && health > 0.0) return true;
  149. return false;
  150. }
  151. #endif
  152.  
  153. stock GetPlayerPausedTime(playerid)
  154. {
  155. return gPlayerCall[playerid][P_PAUSED_TIME];
  156. }
  157.  
  158. stock IsPlayerPaused(playerid)
  159. {
  160. return gPlayerCall[playerid][P_PAUSED];
  161. }
  162.  
  163. public OnPlayerConnect(playerid)
  164. {
  165. gPlayerCall[playerid][P_PAUSED] = false;
  166. gPlayerCall[playerid][P_PAUSED_TIME] = 0;
  167. gPlayerCall[playerid][P_PAUSE_CHECK_TIMER] = SetTimerEx("CheckPlayerPause", 500, true, "i", playerid);
  168.  
  169. //playerstats.inc
  170. gPlayer[playerid][P_KILLS] = 0;
  171. gPlayer[playerid][P_DEATHS] = 0;
  172. gPlayer[playerid][P_SPREE] = 0;
  173. for(new i; i < 3; i++) gPlayer[playerid][P_TIME][i] = 0;
  174. gPlayer[playerid][P_TIMER] = SetTimerEx("OnPlayerUpdateSecond", 1000, true, "i", playerid);
  175. gPlayer[playerid][P_HEADSHOTS] = 0;
  176. gPlayer[playerid][P_SHOTS] = 0;
  177. gPlayer[playerid][P_HITS] = 0;
  178. //
  179.  
  180. gPlayerCall[playerid][P_DEATHS] = 0;
  181. gPlayerCall[playerid][P_DEATH_TICK] = 0;
  182.  
  183. return CallLocalFunction("HOoK_OnPlayerConnect", "i", playerid);
  184. }
  185. #if defined _ALS_OnPlayerConnect
  186. #undef OnPlayerConnect
  187. #else
  188. #define _ALS_OnPlayerConnect
  189. #endif
  190. #define OnPlayerConnect HOok_OnPlayerConnect
  191. forward HOok_OnPlayerConnect(playerid);
  192.  
  193. public OnPlayerDisconnect(playerid, reason)
  194. {
  195. gPlayerCall[playerid][P_PAUSED] = false;
  196. gPlayerCall[playerid][P_PAUSED_TIME] = 0;
  197. KillTimer(gPlayerCall[playerid][P_PAUSE_CHECK_TIMER]);
  198.  
  199. //playerstats.inc
  200. KillTimer(gPlayer[playerid][P_TIMER]);
  201. //
  202.  
  203. return CallLocalFunction("HOok_OnPlayerDisconnect", "ii", playerid, reason);
  204. }
  205. #if defined _ALS_OnPlayerDisconnect
  206. #undef OnPlayerDisconnect
  207. #else
  208. #define _ALS_OnPlayerDisconnect
  209. #endif
  210. #define OnPlayerDisconnect HOok_OnPlayerDisconnect
  211. forward HOok_OnPlayerDisconnect(playerid, reason);
  212.  
  213. public OnPlayerSpawn(playerid)
  214. {
  215. GetPlayerPos(playerid, gPlayerCall[playerid][P_X], gPlayerCall[playerid][P_Y], gPlayerCall[playerid][P_Z]);
  216. GetPlayerFacingAngle(playerid, gPlayerCall[playerid][P_ANGLE]);
  217.  
  218. gPlayerCall[playerid][P_WORLDID] = GetPlayerVirtualWorld(playerid);
  219.  
  220. GetPlayerHealth(playerid, gPlayerCall[playerid][P_HEALTH]);
  221. GetPlayerArmour(playerid, gPlayerCall[playerid][P_ARMOUR]);
  222.  
  223. gPlayerCall[playerid][P_SKIN] = GetPlayerSkin(playerid);
  224.  
  225. gPlayerCall[playerid][P_WEAPON] = GetPlayerWeapon(playerid);
  226. gPlayerCall[playerid][P_AMMO] = GetPlayerAmmo(playerid);
  227.  
  228. gPlayerCall[playerid][P_PING] = GetPlayerPing(playerid);
  229.  
  230. //playerstats.inc
  231. gPlayer[playerid][P_SPREE] = 0;
  232. //
  233.  
  234. return CallLocalFunction("HOok_OnPlayerSpawn", "i", playerid);
  235. }
  236. #if defined _ALS_OnPlayerSpawn
  237. #undef OnPlayerSpawn
  238. #else
  239. #define _ALS_OnPlayerSpawn
  240. #endif
  241. #define OnPlayerSpawn HOok_OnPlayerSpawn
  242. forward HOok_OnPlayerSpawn(playerid);
  243.  
  244. public OnPlayerUpdate(playerid)
  245. {
  246. //OnPlayerUnpause
  247. gPlayerCall[playerid][P_LAST_UPDATE] = GetTickCount();
  248.  
  249. if(gPlayerCall[playerid][P_PAUSED])
  250. {
  251. if(CallLocalFunction("OnPlayerUnpause", "ii", playerid, gPlayerCall[playerid][P_PAUSED_TIME]))
  252. {
  253. gPlayerCall[playerid][P_PAUSED] = false;
  254. gPlayerCall[playerid][P_PAUSED_TIME] = 0;
  255. KillTimer(gPlayerCall[playerid][P_PAUSE_CHECK_TIMER]);
  256. gPlayerCall[playerid][P_PAUSE_CHECK_TIMER] = SetTimerEx("CheckPlayerPause", 500, true, "i", playerid);
  257. }
  258. }
  259.  
  260. //OnPlayerPosChange
  261. static Float:player_pos[3];
  262. GetPlayerPos(playerid, player_pos[0], player_pos[1], player_pos[2]);
  263. if( player_pos[0] != gPlayerCall[playerid][P_X] ||
  264. player_pos[1] != gPlayerCall[playerid][P_Y] ||
  265. player_pos[2] != gPlayerCall[playerid][P_Z])
  266. {
  267. if(CallLocalFunction("OnPlayerPosChange", "iffffff", playerid, player_pos[0], player_pos[1], player_pos[2], gPlayerCall[playerid][P_X], gPlayerCall[playerid][P_Y], gPlayerCall[playerid][P_Z]))
  268. {
  269. GetPlayerPos(playerid, gPlayerCall[playerid][P_X], gPlayerCall[playerid][P_Y], gPlayerCall[playerid][P_Z]);
  270. }
  271. else
  272. {
  273. SetPlayerPos(playerid, gPlayerCall[playerid][P_X], gPlayerCall[playerid][P_Y], gPlayerCall[playerid][P_Z]);
  274. }
  275. }
  276.  
  277. //OnPlayerFacingAngleChange
  278. static Float:player_angle;
  279. GetPlayerFacingAngle(playerid, player_angle);
  280. if(player_angle != gPlayerCall[playerid][P_ANGLE])
  281. {
  282. if(CallLocalFunction("OnPlayerFacingAngleChange", "iff", playerid, player_angle, gPlayerCall[playerid][P_ANGLE]))
  283. {
  284. GetPlayerFacingAngle(playerid, gPlayerCall[playerid][P_ANGLE]);
  285. }
  286. else
  287. {
  288. SetPlayerFacingAngle(playerid, gPlayerCall[playerid][P_ANGLE]);
  289. }
  290. }
  291.  
  292. //OnPlayerWeaponChange
  293. static player_weapon;
  294. player_weapon = GetPlayerWeapon(playerid);
  295. if(player_weapon != gPlayerCall[playerid][P_WEAPON])
  296. {
  297. if(CallLocalFunction("OnPlayerWeaponChange", "iii", playerid, player_weapon, gPlayerCall[playerid][P_WEAPON]))
  298. {
  299. gPlayerCall[playerid][P_WEAPON] = player_weapon;
  300. }
  301. else
  302. {
  303. SetPlayerArmedWeapon(playerid, gPlayerCall[playerid][P_WEAPON]);
  304. }
  305. }
  306.  
  307. //OnPlayerHealthChange
  308. static Float:player_health;
  309. GetPlayerHealth(playerid, player_health);
  310. if(player_health != gPlayerCall[playerid][P_HEALTH])
  311. {
  312. if(CallLocalFunction("OnPlayerHealthChange", "iff", playerid, player_health, gPlayerCall[playerid][P_HEALTH]))
  313. {
  314. GetPlayerHealth(playerid, gPlayerCall[playerid][P_HEALTH]);
  315. }
  316. else
  317. {
  318. SetPlayerHealth(playerid, gPlayerCall[playerid][P_HEALTH]);
  319. }
  320. }
  321.  
  322. //OnPlayerArmourChange
  323. static Float:player_armour;
  324. GetPlayerArmour(playerid, player_armour);
  325. if(player_armour != gPlayerCall[playerid][P_ARMOUR])
  326. {
  327. if(CallLocalFunction("OnPlayerArmourChange", "iff", playerid, player_armour, gPlayerCall[playerid][P_ARMOUR]))
  328. {
  329. GetPlayerArmour(playerid, gPlayerCall[playerid][P_ARMOUR]);
  330. }
  331. else
  332. {
  333. SetPlayerArmour(playerid, gPlayerCall[playerid][P_ARMOUR]);
  334. }
  335. }
  336.  
  337. //OnPlayerVirtualWorldChange
  338. static player_world;
  339. player_world = GetPlayerVirtualWorld(playerid);
  340. if(player_world != gPlayerCall[playerid][P_WORLDID])
  341. {
  342. if(CallLocalFunction("OnPlayerVirtualWorldChange", "iii", playerid, player_world, gPlayerCall[playerid][P_WORLDID]))
  343. {
  344. gPlayerCall[playerid][P_WORLDID] = player_world;
  345. }
  346. else
  347. {
  348. SetPlayerVirtualWorld(playerid, gPlayerCall[playerid][P_WORLDID]);
  349. }
  350. }
  351.  
  352. //OnPlayerSkinChange
  353. static player_skin;
  354. player_skin = GetPlayerSkin(playerid);
  355. if(player_skin != gPlayerCall[playerid][P_SKIN])
  356. {
  357. if(CallLocalFunction("OnPlayerSkinChange", "iii", playerid, player_skin, gPlayerCall[playerid][P_SKIN]))
  358. {
  359. gPlayerCall[playerid][P_SKIN] = player_skin;
  360. }
  361. else
  362. {
  363. SetPlayerSkin(playerid, gPlayerCall[playerid][P_SKIN]);
  364. }
  365. }
  366.  
  367. //OnPlayerPingChange
  368. static player_ping;
  369. player_ping = GetPlayerPing(playerid);
  370. if(player_ping != gPlayerCall[playerid][P_PING])
  371. {
  372. CallLocalFunction("OnPlayerPingChange", "iii", playerid, player_ping, gPlayerCall[playerid][P_PING]);
  373.  
  374. gPlayerCall[playerid][P_PING] = player_ping;
  375. }
  376.  
  377. return CallLocalFunction("HOok_OnPlayerUpdate", "i", playerid);
  378. }
  379. #if defined _ALS_OnPlayerUpdate
  380. #undef OnPlayerUpdate
  381. #else
  382. #define _ALS_OnPlayerUpdate
  383. #endif
  384. #define OnPlayerUpdate HOok_OnPlayerUpdate
  385. forward HOok_OnPlayerUpdate(playerid);
  386.  
  387. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  388. {
  389. //OnPlayerAmmoChange
  390. static player_ammo;
  391. player_ammo = GetPlayerAmmo(playerid);
  392. if(player_ammo != gPlayerCall[playerid][P_AMMO])
  393. {
  394. if(CallLocalFunction("OnPlayerAmmoChange", "iiii", playerid, weaponid, player_ammo, gPlayerCall[playerid][P_AMMO]))
  395. {
  396. gPlayerCall[playerid][P_AMMO] = player_ammo;
  397. }
  398. else
  399. {
  400. SetPlayerAmmo(playerid, weaponid, gPlayerCall[playerid][P_AMMO]);
  401. }
  402. }
  403.  
  404. //playerstats.inc
  405. if(weaponid != 0)
  406. {
  407. gPlayer[playerid][P_SHOTS] += 1;
  408. }
  409. //
  410.  
  411. return CallLocalFunction("HOok_OnPlayerWeaponShot", "iiiifff", playerid, weaponid, hittype, hitid, fX, fY, fZ);
  412. }
  413. #if defined _ALS_OnPlayerWeaponShot
  414. #undef OnPlayerWeaponShot
  415. #else
  416. #define _ALS_OnPlayerWeaponShot
  417. #endif
  418. #define OnPlayerWeaponShot HOok_OnPlayerWeaponShot
  419. forward HOok_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  420.  
  421. public OnPlayerDeath(playerid, killerid, reason)
  422. {
  423. //anti fake kill and OnPlayerKillPlayer callback
  424. if( killerid != INVALID_PLAYER_ID &&
  425. playerid != INVALID_PLAYER_ID &&
  426. ! IsPlayerNPC(killerid) &&
  427. ! IsPlayerNPC(playerid))
  428. {
  429. #if defined ANTI_FAKE_KILL
  430. if(gettime() - gPlayerCall[playerid][P_DEATH_TICK] < 5 * 100)
  431. {
  432. gPlayerCall[playerid][P_DEATHS] ++;
  433. if(gPlayerCall[playerid][P_DEATHS] > 1)
  434. {
  435. CallLocalFunction("OnPlayerFakeKill", "ii", playerid, gPlayerCall[playerid][P_DEATHS]);
  436. return gPlayerCall[playerid][P_DEATHS] = 0;
  437. }
  438. }
  439. else
  440. {
  441. gPlayerCall[playerid][P_DEATHS] = 1;
  442. gPlayerCall[playerid][P_DEATH_TICK] = gettime();
  443. }
  444. #endif
  445.  
  446. reason = GetPlayerWeapon(killerid);
  447. if(! IsValidWeapon(reason)) reason = 0;
  448.  
  449. CallLocalFunction("OnPlayerKillPlayer", "iii", playerid, killerid, reason);
  450. }
  451.  
  452. //playerstats.inc
  453. gPlayer[playerid][P_DEATHS] += 1;
  454. gPlayer[playerid][P_SPREE] = 0;
  455.  
  456. if(killerid != INVALID_PLAYER_ID)
  457. {
  458. gPlayer[killerid][P_KILLS] += 1;
  459. gPlayer[killerid][P_SPREE] += 1;
  460. }
  461. //
  462.  
  463. return CallLocalFunction("HOok_OnPlayerDeath", "iii", playerid, killerid, reason);
  464. }
  465. #if defined _ALS_OnPlayerDeath
  466. #undef OnPlayerDeath
  467. #else
  468. #define _ALS_OnPlayerDeath
  469. #endif
  470. #define OnPlayerDeath HOok_OnPlayerDeath
  471. forward HOok_OnPlayerDeath(playerid, killerid, reason);
  472.  
  473. //internal callbacks
  474. forward CheckPlayerPause(playerid);
  475. public CheckPlayerPause(playerid)
  476. {
  477. new CurrentTime = GetTickCount();
  478. new PlayerState = GetPlayerState(playerid);
  479.  
  480. if(! gPlayerCall[playerid][P_PAUSED])
  481. {
  482. if(! IsPlayerInClassSelection(playerid))
  483. {
  484. if((CurrentTime - gPlayerCall[playerid][P_LAST_UPDATE]) >= (PAUSE_CHECK_TIME * 1000))
  485. {
  486. if( (PlayerState == PLAYER_STATE_ONFOOT) ||
  487. (PlayerState == PLAYER_STATE_DRIVER) ||
  488. (PlayerState == PLAYER_STATE_PASSENGER))
  489. {
  490. if(CallLocalFunction("OnPlayerPause", "i", playerid))
  491. {
  492. gPlayerCall[playerid][P_PAUSED] = true;
  493. gPlayerCall[playerid][P_PAUSED_TIME] = 0;
  494. KillTimer(gPlayerCall[playerid][P_PAUSE_CHECK_TIMER]);
  495. gPlayerCall[playerid][P_PAUSE_CHECK_TIMER] = SetTimerEx("CountPlayerPausedTime", 1000, true, "i", playerid);
  496.  
  497. }
  498. }
  499. }
  500. }
  501. }
  502. return 1;
  503. }
  504.  
  505. forward CountPlayerPausedTime(playerid);
  506. public CountPlayerPausedTime(playerid)
  507. {
  508. gPlayerCall[playerid][P_PAUSED_TIME] += 1;
  509. return 1;
  510. }
  511. //
  512.  
  513. forward OnPlayerPosChange(playerid, Float:newx, Float:newy, Float:newz, Float:oldx, Float:oldy, Float:oldz);
  514. forward OnPlayerFacingAngleChange(playerid, Float:newangle, Float:oldangle);
  515. forward OnPlayerWeaponChange(playerid, newweapon, oldweapon);
  516. forward OnPlayerHealthChange(playerid, Float:newhealth, Float:oldhealth);
  517. forward OnPlayerArmourChange(playerid, Float:newarmour, Float:oldarmour);
  518. forward OnPlayerVirtualWorldChange(playerid, newworld, oldworld);
  519. forward OnPlayerSkinChange(playerid, newskin, oldskin);
  520. forward OnPlayerPingChange(playerid, newping, oldping);
  521. forward OnPlayerAmmoChange(playerid, weaponid, newammo, oldammo);
  522. forward OnPlayerKillPlayer(playerid, killerid, weaponid);
  523. forward OnPlayerPause(playerid);
  524. forward OnPlayerUnpause(playerid, time);
  525. forward OnPlayerFakeKill(playerid, count);
  526.  
  527. //-----
  528. //playerfuncs.inc
  529. //-----
  530.  
  531. //walking styles
  532. #define WALKING_STYLE_DEFAULT 0
  533. #define WALKING_STYLE_CIVILIAN 1
  534. #define WALKING_STYLE_GANGSTA 2
  535. #define WALKING_STYLE_GANGSTA_2 3
  536. #define WALKING_STYLE_OLD 4
  537. #define WALKING_STYLE_FAT_OLD 5
  538. #define WALKING_STYLE_FAT 6
  539. #define WALKING_STYLE_LADY 7
  540. #define WALKING_STYLE_LADY_2 8
  541. #define WALKING_STYLE_WHORE 9
  542. #define WALKING_STYLE_WHORE_2 10
  543. #define WALKING_STYLE_DRUNK 11
  544. #define WALKING_STYLE_BLIND 12
  545. #define WALKING_STYLE_ARMED 13
  546.  
  547. #if ! defined HOLDING
  548. #define HOLDING(%0) \
  549. ((newkeys & (%0)) == (%0))
  550. #endif
  551.  
  552. #if ! defined RELEASED
  553. #define RELEASED(%0) \
  554. (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  555. #endif
  556.  
  557. stock GivePlayerScore(playerid, score)
  558. {
  559. if(! IsPlayerConnected(playerid)) return false;
  560.  
  561. return SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
  562. }
  563.  
  564. stock SetPlayerMoney(playerid, money)
  565. {
  566. if(! IsPlayerConnected(playerid)) return false;
  567.  
  568. ResetPlayerMoney(playerid);
  569. return GivePlayerMoney(playerid, money);
  570. }
  571.  
  572. stock RemovePlayerWeapoon(playerid, weaponid)
  573. {
  574. if(! IsPlayerConnected(playerid)) return false;
  575.  
  576. new weapon, ammo;
  577. for(new i; i != 13; i++)
  578. {
  579. GetPlayerWeaponData(playerid, i, weapon, ammo);
  580. if(weapon == weaponid)
  581. {
  582. return GivePlayerWeapon(playerid, weaponid, -ammo);
  583. }
  584. }
  585. return false
  586. }
  587.  
  588. stock SetPlayerFacingPoint(playerid, Float:x, Float:y)
  589. {
  590. if(! IsPlayerConnected(playerid)) return false;
  591.  
  592. new Float:pos[3];
  593. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  594.  
  595. new Float:angle;
  596.  
  597. if( y > pos[1] ) angle = (-acos((x - pos[0]) / floatsqroot((x - pos[0])*(x - pos[0]) + (y - pos[1])*(y - pos[1]))) - 90.0);
  598. else if( y < pos[1] && x < pos[0] ) angle = (acos((x - pos[0]) / floatsqroot((x - pos[0])*(x - pos[0]) + (y - pos[1])*(y - pos[1]))) - 450.0);
  599. else if( y < pos[1] ) angle = (acos((x - pos[0]) / floatsqroot((x - pos[0])*(x - pos[0]) + (y - pos[1])*(y - pos[1]))) - 90.0);
  600.  
  601. if(x > pos[0]) angle = (floatabs(floatabs(angle) + 180.0));
  602. else angle = (floatabs(angle) - 180.0);
  603.  
  604. return SetPlayerFacingAngle(playerid, angle);
  605. }
  606.  
  607. stock static IsAngleInRangeOfAngle(Float:a1, Float:a2, Float:range = 10.0)
  608. {
  609. a1 -= a2;
  610. if((a1 < range) && (a1 > -range)) return true;
  611. return false;
  612. }
  613.  
  614. stock IsPlayerFacingPoint(playerid, Float:x, Float:y, Float:range = 10.0)
  615. {
  616. if(! IsPlayerConnected(playerid)) return false;
  617.  
  618. new Float:pos[3];
  619. GetPlayerPos(pedid, pos[0], pos[1], pos[2]);
  620.  
  621. new Float:facing;
  622. GetPlayerFacingAngle(playerid, facing);
  623.  
  624. new Float:angle;
  625.  
  626. if( pos[1] > y ) angle = (-acos((pos[0] - x) / floatsqroot((pos[0] - x)*(pos[0] - x) + (pos[1] - y)*(pos[1] - y))) - 90.0);
  627. else if( pos[1] < y && pos[0] < x ) angle = (acos((pos[0] - x) / floatsqroot((pos[0] - x)*(pos[0] - x) + (pos[1] - y)*(pos[1] - y))) - 450.0);
  628. else if( pos[1] < y ) angle = (acos((pos[0] - x) / floatsqroot((pos[0] - x)*(pos[0] - x) + (pos[1] - y)*(pos[1] - y))) - 90.0);
  629.  
  630. return (IsAngleInRangeOfAngle(-angle, facing, range));
  631. }
  632.  
  633. stock SetPlayerFacingPlayer(playerid, targetid)
  634. {
  635. if(! IsPlayerConnected(playerid)) return false;
  636. if(! IsPlayerConnected(targetid)) return false;
  637.  
  638. new Float:pos[3];
  639. GetPlayerPos(targetid, pos[0], pos[1], pos[2]);
  640.  
  641. return SetPlayerFacingAngle(playerid, pos[0], pos[1]);
  642. }
  643.  
  644. stock IsPlayerFacingPlayer(playerid, targetid, Float:range = 10.0)
  645. {
  646. if(! IsPlayerConnected(playerid)) return false;
  647. if(! IsPlayerConnected(targetid)) return false;
  648.  
  649. new Float:pos[3];
  650. GetPlayerPos(targetid, pos[0], pos[1], pos[2]);
  651.  
  652. return IsPlayerFacingPoint(playerid, pos[0], pos[1], range);
  653. }
  654.  
  655. stock IsPlayerBehindPlayer(playerid, targetid, Float:range = 10.0)
  656. {
  657. if(! IsPlayerConnected(playerid)) return false;
  658. if(! IsPlayerConnected(targetid)) return false;
  659.  
  660. new Float:angle[2];
  661. GetPlayerFacingAngle(playerid, angle[0]);
  662. GetPlayerFacingAngle(targetid, angle[1]);
  663.  
  664. return (IsAngleInRangeOfAngle(angle[0], angle[1], range) && IsPlayerFacingPlayer(playerid, targetid, range));
  665. }
  666.  
  667. stock GetPlayerWeaponAmmo(playerid, weaponid)
  668. {
  669. if(! IsPlayerConnected(playerid)) return false;
  670.  
  671. new current_weapon = GetPlayerWeapon(playerid);
  672.  
  673. SetPlayerArmedWeapon(playerid, weaponid);
  674. new ammo = GetPlayerAmmo(playerid);
  675.  
  676. SetPlayerArmedWeapon(playerid, current_weapon);
  677. return ammo;
  678. }
  679.  
  680. stock SetPlayerWeaponAmmo(playerid, weaponid, ammo)
  681. {
  682. if(! IsPlayerConnected(playerid)) return false;
  683.  
  684. RemovePlayerWeapon(playeird, weaponid);
  685. return GivePlayerWeapon(playerid, weaponid, ammo);
  686. }
  687.  
  688. stock SetPlayerWalkingStyle(playerid, style)
  689. {
  690. if(! IsPlayerConnected(playerid)) return false;
  691. gWalkingStyle[playerid] = style;
  692. return true;
  693. }
  694.  
  695. stock GetPlayerWalkingStyle(playerid)
  696. {
  697. if(! IsPlayerConnected(playerid)) return false;
  698. return gWalkingStyle[playerid];
  699. }
  700.  
  701. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  702. {
  703. new keys, updown, leftright;
  704. GetPlayerKeys(playerid, keys, updown, leftright);
  705.  
  706. if( HOLDING(KEY_WALK) &&
  707. ( (updown & KEY_UP ||
  708. updown & KEY_DOWN)
  709. ||
  710. (leftright & KEY_LEFT ||
  711. leftright & KEY_RIGHT))
  712. )
  713. {
  714. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  715. {
  716. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  717. {
  718. if(gWalkingStyle[playerid] != WALKING_STYLE_DEFAULT)
  719. {
  720. new stylestr[28];
  721. switch(gWalkingStyle[playerid])
  722. {
  723. case WALKING_STYLE_CIVILIAN: stylestr = "WALK_civi";
  724. case WALKING_STYLE_GANGSTA: stylestr = "WALK_gang1";
  725. case WALKING_STYLE_GANGSTA_2: stylestr = "WALK_gang2";
  726. case WALKING_STYLE_OLD: stylestr = "WALK_old";
  727. case WALKING_STYLE_FAT_OLD: stylestr = "WALK_fatold";
  728. case WALKING_STYLE_FAT: stylestr = "WALK_fat";
  729. case WALKING_STYLE_LADY: stylestr = "WOMAN_walknorm";
  730. case WALKING_STYLE_LADY_2: stylestr = "WOMAN_walkbusy";
  731. case WALKING_STYLE_WHORE: stylestr = "WOMAN_walkpro";
  732. case WALKING_STYLE_WHORE_2: stylestr = "WOMAN_walksexy";
  733. case WALKING_STYLE_DRUNK: stylestr = "WALK_drunk";
  734. case WALKING_STYLE_BLIND: stylestr = "Walk_Wuzi";
  735. case WALKING_STYLE_ARMED: stylestr = "WALK_armed";
  736. }
  737.  
  738. if(CallLocalFunction("OnPlayerWalk", "ii", playerid, gWalkingStyle[playerid]))
  739. {
  740. return ApplyAnimation(playerid, "PED", stylestr, 4.1, 1, 1, 1, 1, 1);
  741. }
  742. }
  743. }
  744. }
  745. }
  746. if(RELEASED(KEY_WALK))
  747. {
  748. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  749. {
  750. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  751. {
  752. if(gWalkingStyle[playerid] != WALKING_STYLE_DEFAULT)
  753. {
  754. new stylestr[28];
  755. switch(gWalkingStyle[playerid])
  756. {
  757. case WALKING_STYLE_CIVILIAN: stylestr = "WALK_civi";
  758. case WALKING_STYLE_GANGSTA: stylestr = "WALK_gang1";
  759. case WALKING_STYLE_GANGSTA_2: stylestr = "WALK_gang2";
  760. case WALKING_STYLE_OLD: stylestr = "WALK_old";
  761. case WALKING_STYLE_FAT_OLD: stylestr = "WALK_fatold";
  762. case WALKING_STYLE_FAT: stylestr = "WALK_fat";
  763. case WALKING_STYLE_LADY: stylestr = "WOMAN_walknorm";
  764. case WALKING_STYLE_LADY_2: stylestr = "WOMAN_walkbusy";
  765. case WALKING_STYLE_WHORE: stylestr = "WOMAN_walkpro";
  766. case WALKING_STYLE_WHORE_2: stylestr = "WOMAN_walksexy";
  767. case WALKING_STYLE_DRUNK: stylestr = "WALK_drunk";
  768. case WALKING_STYLE_BLIND: stylestr = "Walk_Wuzi";
  769. case WALKING_STYLE_ARMED: stylestr = "WALK_armed";
  770. }
  771.  
  772. if(CallLocalFunction("OnPlayerWalk", "ii", playerid, gWalkingStyle[playerid]))
  773. {
  774. return ApplyAnimation(playerid, "PED", stylestr, 4.1, 0, 0, 0, 0, 1);
  775. }
  776. }
  777. }
  778. }
  779. }
  780. return CallLocalFunction("HOoK_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
  781. }
  782. #if defined _ALS_OnPlayerKeyStateChange
  783. #undef OnPlayerKeyStateChange
  784. #else
  785. #define _ALS_OnPlayerKeyStateChange
  786. #endif
  787. #define OnPlayerKeyStateChange HOoK_OnPlayerKeyStateChange
  788. forward HOoK_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  789.  
  790. //script(not internal) callback
  791. forward OnPlayerWalk(playerid, style);
  792.  
  793. //-----
  794. //playerstates.inc
  795. //-----
  796.  
  797. stock IsPlayerSpawned(playerid)
  798. {
  799. if(! IsPlayerConnected(playerid)) return false;
  800. switch(GetPlayerState(playerid))
  801. {
  802. case PLAYER_STATE_ONFOOT, PLAYER_STATE_DRIVER, PLAYER_STATE_PASSENGER, PLAYER_STATE_SPAWNED: return true;
  803. default: return false;
  804. }
  805. return false;
  806. }
  807.  
  808. stock IsPlayerSpectating(playerid)
  809. {
  810. if(! IsPlayerConnected(playerid)) return false;
  811. if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING) return true;
  812. return false;
  813. }
  814.  
  815. stock IsPlayerDriver(playerid)
  816. {
  817. if(! IsPlayerConnected(playerid)) return false;
  818. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) return true;
  819. return false;
  820. }
  821.  
  822. stock IsPlayerInClassSelection(playerid)
  823. {
  824. if(! IsPlayerConnected(playerid)) return false;
  825. new Float: health = 0.0;
  826. GetPlayerHealth(playerid, health);
  827. if(GetPlayerState(playerid) == PLAYER_STATE_WASTED && health > 0.0) return true;
  828. return false;
  829. }
  830.  
  831. stock IsPlayerDead(playerid)
  832. {
  833. if(! IsPlayerConnected(playerid)) return false;
  834. new Float: health = 0.0;
  835. GetPlayerHealth(playerid, health);
  836. if(GetPlayerState(playerid) == PLAYER_STATE_WASTED && health <= 0.0) return true;
  837. return false;
  838. }
  839.  
  840. //-----
  841. //playerstats.inc
  842. //-----
  843.  
  844. forward OnPlayerUpdateSecond(playerid);
  845. public OnPlayerUpdateSecond(playerid)
  846. {
  847. new seconds = gPlayer[playerid][P_TIME][0];
  848. new minutes = gPlayer[playerid][P_TIME][1];
  849. new hours = gPlayer[playerid][P_TIME][2];
  850.  
  851. seconds += 1;
  852. if(seconds >= 60)
  853. {
  854. seconds = 0;
  855. minutes += 1;
  856. if(minutes >= 60)
  857. {
  858. minutes = 0;
  859. hours += 1;
  860. }
  861. }
  862. return 1;
  863. }
  864.  
  865. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  866. {
  867. //headshot system
  868. if(GetPlayerTeam(issuerid) != GetPlayerTeam(playerid))
  869. {
  870. if(bodypart == 9)
  871. {
  872. if(CallLocalFunction("OnPlayerHeadshot", "iii", playerid, issuerid, weaponid))
  873. {
  874. gPlayer[issuerid][P_HEADSHOTS] += 1;
  875. }
  876. }
  877. gPlayer[issuerid][P_HITS] += 1;
  878. }
  879.  
  880. return CallLocalFunction("HOoK_OnPlayerTakeDamage", "iifii", playerid, issuerid, Float: amount, weaponid, bodypart);
  881. }
  882. #if defined _ALS_OnPlayerTakeDamage
  883. #undef OnPlayerTakeDamage
  884. #else
  885. #define _ALS_OnPlayerTakeDamage
  886. #endif
  887. #define OnPlayerTakeDamage HOoK_OnPlayerTakeDamage
  888. forward HOoK_OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart);
  889.  
  890. stock GetPlayerKills(playerid)
  891. {
  892. if(! IsPlayerConnected(playerid)) return false;
  893. return gPlayer[playerid][P_KILLS];
  894. }
  895.  
  896. stock GetPlayerDeaths(playerid)
  897. {
  898. if(! IsPlayerConnected(playerid)) return false;
  899. return gPlayer[playerid][P_DEATHS];
  900. }
  901.  
  902. stock GetPlayerSpree(playerid)
  903. {
  904. if(! IsPlayerConnected(playerid)) return false;
  905. return gPlayer[playerid][P_SPREE];
  906. }
  907.  
  908. stock GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
  909. {
  910. if(! IsPlayerConnected(playerid)) return false;
  911.  
  912. seconds = gPlayer[playerid][P_TIME][0];
  913. minutes = gPlayer[playerid][P_TIME][1];
  914. hours = gPlayer[playerid][P_TIME][2];
  915. return true;
  916. }
  917.  
  918. stock GetPlayerHeadshots(playerid)
  919. {
  920. if(! IsPlayerConnected(playerid)) return false;
  921. return gPlayer[playerid][P_HEADSHOTS];
  922. }
  923.  
  924. stock GetPlayerWeaponShots(playerid)
  925. {
  926. if(! IsPlayerConnected(playerid)) return false;
  927. return gPlayer[playerid][P_SHOTS];
  928. }
  929.  
  930. stock GetPlayerWeaponHits(playerid)
  931. {
  932. if(! IsPlayerConnected(playerid)) return false;
  933. return gPlayer[playerid][P_HITS];
  934. }
  935.  
  936. forward OnPlayerHeadshot(playerid, issuerid, weaponid);
Advertisement
Add Comment
Please, Sign In to add comment