GammixSAMP

peds.inc BETA R6 - By Gammix

Apr 29th, 2015
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.86 KB | None | 0 0
  1. /*
  2. PEDs Include (peds.inc)
  3. * Since samp 0.3.7 have actors system(which is coolest upgrade ever!), i have planned on peds(tpe of npcs) creator using pawn (not C++)
  4. * This include let you make AI and cool effects and peds without writing thier AI.
  5. * SAMP have provided collisions for actors, which is Awesome and for you as well, cause now ped will collide!
  6.  
  7. Author: (creator)
  8. * Gammix
  9.  
  10. Contributors:
  11. * Pottus - ideas and improvement
  12. * a_angles - took help for making the ped face points
  13. * seif - took help from bodyparts code
  14.  
  15. (c) Copyright 2015
  16. * This file is provided as is (no warranties).
  17. */
  18. /*
  19. FUNCTIONS:
  20. native PED_Connect(skin, Float:x, Float:y, Float:z, Float:rotation = 0.0);
  21. native PED_IsConnected(pedid);
  22. native PED_Disconnect(pedid);
  23. native PED_SetPos(pedid, Float:x, Float:y, Float:z);
  24. native PED_GetPos(pedid, &Float:x, &Float:y, &Float:z);
  25. native PED_SetFacingAngle(pedid, Float:angle);
  26. native PED_GetFacingAngle(pedid, &Float:angle);
  27. native PED_SetVirtualWorld(pedid, world);
  28. native PED_GetVirtualWorld(pedid);
  29. native PED_IsInRangeOfPoint(pedid, Float:range, Float:x, Float:y, Float:z);
  30. native PED_SetFacingPoint(pedid, Float:x, Float:y);
  31. native PED_IsFacingPoint(pedid, Float:x, Float:y, Float:range = 10.0);
  32. native PED_SetFacingPlayer(pedid, playerid);
  33. native PED_IsFacingPlayer(pedid, playerid);
  34. native PED_IsBehindPlayer(pedid, playerid, Float:range = 10.0);
  35. native PED_SetHealth(pedid, Float:health);
  36. native PED_GetHealth(pedid, &Float:health);
  37. native PED_GotoPoint(pedid, Float:x, Float:y, Float:z, bool:walk = false);
  38. native PED_FollowPlayer(pedid, playerid);
  39. native PED_GetFollowingPlayer(pedid);
  40. native PED_ApplyAnimation(pedid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time);
  41. native PED_Stop(pedid);
  42. native PED_Spawn(pedid);
  43. native PED_SetSpawnInfo(pedid, Float:x, Float:y, Float:z, Float:rotation);
  44. native PED_SetWalkingStyle(pedid, walkingstyle);
  45. native PED_GetWalkingStyle(pedid);
  46. native PED_SetRunningStyle(pedid, runningstyle);
  47. native PED_GetRunningStyle(pedid);
  48. native PED_GetState(pedid);
  49. native PED_IsStreamedIn(pedid, forplayerid);
  50. native _
  51. native GetPlayerCameraTargetPED(playerid);
  52. native GetPlayerTargetPED(playerid);
  53.  
  54. CALLBACKS:
  55. public PED_OnConnect(pedid);
  56. public PED_OnDisconnect(pedid);
  57. public PED_OnSpawn(pedid);
  58. public PED_OnReachDestination(pedid, Float:x, Float:y, Float:z);
  59. public PED_OnStateChange(pedid, newstate, oldstate);
  60. public PED_OnStreamIn(pedid, forplayerid);
  61. public PED_OnStreamOut(pedid, forplayerid);
  62. public PED_OnTakeDamage(pedid, issuerid, weaponid, Float:damage);
  63. public PED_OnDeath(pedid, killerid, weaponid);
  64. */
  65.  
  66. //just kiding !:D!
  67. #define INVALID_PED_ID INVALID_ACTOR_ID
  68. #define MAX_PEDS MAX_ACTORS
  69.  
  70. //walking styles
  71. #define PED_WALKING_DEFAULT 0
  72. #define PED_WALKING_NORMAL 1
  73. #define PED_WALKING_GANGSTA 2
  74. #define PED_WALKING_GANGSTA2 3
  75. #define PED_WALKING_OLD 4
  76. #define PED_WALKING_FAT_OLD 5
  77. #define PED_WALKING_FAT 6
  78. #define PED_WALKING_LADY 7
  79. #define PED_WALKING_LADY2 8
  80. #define PED_WALKING_WHORE 9
  81. #define PED_WALKING_WHORE2 10
  82. #define PED_WALKING_DRUNK 11
  83. #define PED_WALKING_BLIND 12
  84. #define PED_WALKING_ARMED 13
  85.  
  86. //ped states
  87. #define PED_STATE_NONE 0
  88. #define PED_STATE_WALKING 1
  89. #define PED_STATE_RUNNING 2
  90. #define PED_STATE_DEAD 3
  91.  
  92. //running styles
  93. #define PED_RUNNING_DEFAULT 0
  94. #define PED_RUNNING_NORMAL 1
  95. #define PED_RUNNING_GANGSTA 2
  96. #define PED_RUNNING_GANGSTA2 3
  97. #define PED_RUNNING_OLD 4
  98. #define PED_RUNNING_FAT_OLD 5
  99. #define PED_RUNNING_FAT 6
  100. #define PED_RUNNING_LADY 7
  101. #define PED_RUNNING_LADY2 8
  102. #define PED_RUNNING_WHORE 9
  103. #define PED_RUNNING_WHORE2 10
  104. #define PED_RUNNING_DRUNK 11
  105. #define PED_RUNNING_BLIND 12
  106. #define PED_RUNNING_ARMED 13
  107.  
  108. enum PedEnum
  109. {
  110. bool:P_EXIST,
  111. Float:P_X,
  112. Float:P_Y,
  113. Float:P_Z,
  114. Float:P_ROT,
  115. P_TIMER,
  116. Float:P_HEALTH,
  117. Float:P_GOTOX,
  118. Float:P_GOTOY,
  119. Float:P_GOTOZ,
  120. P_STATE,
  121. P_WALKSTYLE,
  122. P_RUNSTYLE,
  123. P_FOLLOWING,
  124. bool:P_FOLLOWINGWALK
  125. }
  126. static gPED[MAX_PEDS][PedEnum];
  127.  
  128. //looking at ped function
  129. static gPlayerLooking[MAX_PEDS];
  130.  
  131. public OnPlayerConnect(playerid)
  132. {
  133. gPlayerLooking[playerid] = INVALID_PED_ID;
  134.  
  135. #if defined HoOK_OnPlayerConnect
  136. HoOK_OnPlayerConnect(playerid);
  137. #endif
  138. return 1;
  139. }
  140. #if defined _ALS_OnPlayerConnect
  141. #undef OnPlayerConnect
  142. #else
  143. #define _ALS_OnPlayerConnect
  144. #endif
  145. #define OnPlayerConnect HoOK_OnPlayerConnect
  146. #if defined HoOK_OnPlayerConnect
  147. forward HoOK_OnPlayerConnect(playerid);
  148. #endif
  149.  
  150. //internal functions
  151. stock Float:PED_GetDistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  152. {
  153. return floatsqroot( (( x1 - x2 ) * ( x1 - x2 )) + (( y1 - y2 ) * ( y1 - y2 )) + (( z1 - z2 ) * ( z1 - z2 )) );
  154. }
  155.  
  156. stock PED_AngleInRangeOfAngle(Float:a1, Float:a2, Float:range = 10.0)
  157. {
  158. a1 -= a2;
  159. if((a1 < range) && (a1 > -range)) return true;
  160. return false;
  161. }
  162.  
  163. //include funcions
  164. stock PED_Connect(skin, Float:x, Float:y, Float:z, Float:rotation = 0.0)
  165. {
  166. if(skin < 0 || skin > 311) return INVALID_PED_ID;
  167.  
  168. new _actor = CreateActor(skin, x, y, z, rotation);
  169.  
  170. if(_actor == INVALID_PED_ID) return INVALID_PED_ID;
  171.  
  172. gPED[_actor][P_EXIST] = true;
  173. gPED[_actor][P_X] = x;
  174. gPED[_actor][P_Y] = y;
  175. gPED[_actor][P_Z] = z;
  176. gPED[_actor][P_ROT] = rotation;
  177. gPED[_actor][P_HEALTH] = 100.0;
  178. gPED[_actor][P_GOTOX] = -1000.0;
  179. gPED[_actor][P_GOTOY] = -1000.0;
  180. gPED[_actor][P_GOTOZ] = -1000.0;
  181. gPED[_actor][P_WALKSTYLE] = 0;
  182. gPED[_actor][P_RUNSTYLE] = 0;
  183. gPED[_actor][P_STATE] = PED_STATE_NONE;
  184. gPED[_actor][P_FOLLOWING] = INVALID_PLAYER_ID;
  185. gPED[_actor][P_FOLLOWINGWALK] = false;
  186.  
  187. gPED[_actor][P_TIMER] = SetTimerEx("PED_OnTimeUpdate", 100, true, "i", _actor);
  188.  
  189. CallLocalFunction("PED_OnConnect", "i", _actor);
  190. CallLocalFunction("PED_OnSpawn", "i", _actor);
  191. return _actor;
  192. }
  193.  
  194. stock PED_IsConnected(pedid) return gPED[pedid][P_EXIST];
  195.  
  196. stock PED_Disconnect(pedid)
  197. {
  198. if(! PED_IsConnected(pedid)) return false;
  199.  
  200. gPED[pedid][P_EXIST] = false;
  201.  
  202. DestroyActor(pedid);
  203. KillTimer(gPED[pedid][P_TIMER]);
  204.  
  205. CallLocalFunction("PED_OnDisconnect", "i", pedid);
  206. return true;
  207. }
  208.  
  209. stock PED_SetPos(pedid, Float:x, Float:y, Float:z)
  210. {
  211. if(! PED_IsConnected(pedid)) return false;
  212.  
  213. return SetActorPos(pedid, x, y, z);
  214. }
  215.  
  216. stock PED_GetPos(pedid, &Float:x, &Float:y, &Float:z)
  217. {
  218. if(! PED_IsConnected(pedid)) return false;
  219.  
  220. return GetActorPos(pedid, x, y, z);
  221. }
  222.  
  223. stock PED_SetFacingAngle(pedid, Float:angle)
  224. {
  225. if(! PED_IsConnected(pedid)) return false;
  226.  
  227. return SetActorFacingAngle(pedid, angle);
  228. }
  229.  
  230. stock PED_GetFacingAngle(pedid, &Float:angle)
  231. {
  232. if(! PED_IsConnected(pedid)) return false;
  233.  
  234. return GetActorFacingAngle(pedid, angle);
  235. }
  236.  
  237. stock PED_SetVirtualWorld(pedid, world)
  238. {
  239. if(! PED_IsConnected(pedid)) return false;
  240.  
  241. return SetActorVirtualWorld(pedid, world);
  242. }
  243.  
  244. stock PED_GetVirtualWorld(pedid)
  245. {
  246. if(! PED_IsConnected(pedid)) return false;
  247.  
  248. return GetActorVirtualWorld(pedid);
  249. }
  250.  
  251. stock PED_IsInRangeOfPoint(pedid, Float:range, Float:x, Float:y, Float:z)
  252. {
  253. if(! PED_IsConnected(pedid)) return false;
  254.  
  255. new Float:pos[3];
  256. PED_GetPos(pedid, pos[0], pos[1], pos[2]);
  257.  
  258. if(PED_GetDistance(pos[0], pos[1], pos[2], x, y, z) <= range) return true;
  259. return false;
  260. }
  261.  
  262. stock PED_SetFacingPoint(pedid, Float:x, Float:y)
  263. {
  264. if(! PED_IsConnected(pedid)) return false;
  265.  
  266. new Float:pX, Float:pY, Float:pZ;
  267. PED_GetPos(pedid, pX, pY, pZ);
  268.  
  269. new Float:angle;
  270.  
  271. if( y > pY ) angle = (-acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 90.0);
  272. else if( y < pY && x < pX ) angle = (acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 450.0);
  273. else if( y < pY ) angle = (acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 90.0);
  274.  
  275. if(x > pX) angle = (floatabs(floatabs(angle) + 180.0));
  276. else angle = (floatabs(angle) - 180.0);
  277.  
  278. PED_SetFacingAngle(pedid, angle);
  279. return true;
  280. }
  281.  
  282. stock PED_IsFacingPoint(pedid, Float:x, Float:y, Float:range = 10.0)
  283. {
  284. if(! PED_IsConnected(pedid)) return false;
  285.  
  286. new Float:X, Float:Y, Float:Z, Float:A;
  287. PED_GetPos(pedid, X, Y, Z);
  288. PED_GetFacingAngle(pedid, A);
  289.  
  290. new Float:angle;
  291.  
  292. if( Y > y ) angle = (-acos((X - x) / floatsqroot((X - x)*(X - x) + (Y - y)*(Y - y))) - 90.0);
  293. else if( Y < y && X < x ) angle = (acos((X - x) / floatsqroot((X - x)*(X - x) + (Y - y)*(Y - y))) - 450.0);
  294. else if( Y < y ) angle = (acos((X - x) / floatsqroot((X - x)*(X - x) + (Y - y)*(Y - y))) - 90.0);
  295.  
  296. if(PED_AngleInRangeOfAngle(-angle, A, range)) return true;
  297. return false;
  298. }
  299.  
  300. stock PED_SetFacingPlayer(pedid, playerid)
  301. {
  302. if(! PED_IsConnected(pedid)) return false;
  303. if(! IsPlayerConnected(playerid)) return false;
  304.  
  305. new Float:pX, Float:pY, Float:pZ;
  306. GetPlayerPos(playerid, pX, pY, pZ);
  307.  
  308. return PED_SetFacingPoint(pedid, pX, pY);
  309. }
  310.  
  311. stock PED_IsFacingPlayer(pedid, playerid)
  312. {
  313. if(! PED_IsConnected(pedid)) return false;
  314. if(! IsPlayerConnected(playerid)) return false;
  315.  
  316. new Float:pX, Float:pY, Float:pZ;
  317. GetPlayerPos(playerid, pX, pY, pZ);
  318.  
  319. return PED_IsFacingPoint(pedid, pX, pY);
  320. }
  321.  
  322. stock PED_IsBehindPlayer(pedid, playerid, Float:range = 10.0)
  323. {
  324. if(! PED_IsConnected(pedid)) return false;
  325. if(! IsPlayerConnected(playerid)) return false;
  326.  
  327. new Float:za, Float:pa;
  328. PED_GetFacingAngle(pedid, za);
  329. GetPlayerFacingAngle(playerid, pa);
  330.  
  331. if(PED_AngleInRangeOfAngle(za, pa, range) && PED_IsFacingPlayer(playerid, playerid)) return true;
  332. return false;
  333. }
  334.  
  335. stock PED_SetHealth(pedid, Float:health)
  336. {
  337. if(! PED_IsConnected(pedid)) return false;
  338. if(PED_GetState(pedid) == PED_STATE_DEAD) return false;
  339.  
  340. gPED[pedid][P_HEALTH] = health;
  341. return true;
  342. }
  343.  
  344. stock PED_GetHealth(pedid, &Float:health)
  345. {
  346. if(! PED_IsConnected(pedid)) return false;
  347.  
  348. health = gPED[pedid][P_HEALTH];
  349. return true;
  350. }
  351.  
  352. stock PED_ApplyAnimation(pedid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time)
  353. {
  354. if(! PED_IsConnected(pedid)) return false;
  355. if(PED_GetState(pedid) == PED_STATE_DEAD) return false;
  356.  
  357. return ApplyActorAnimation(pedid, animlib, animname, fDelta, loop, lockx, locky, freeze, time);
  358. }
  359.  
  360. stock PED_GotoPoint(pedid, Float:x, Float:y, Float:z, bool:walk = false)
  361. {
  362. if(! PED_IsConnected(pedid)) return false;
  363. if(PED_GetState(pedid) == PED_STATE_DEAD) return false;
  364.  
  365. //PED_Stop(pedid);
  366. PED_SetFacingPoint(pedid, x, y);
  367.  
  368. if(walk)
  369. {
  370. switch(gPED[pedid][P_WALKSTYLE])
  371. {
  372. case PED_WALKING_NORMAL: PED_ApplyAnimation(pedid, "PED", "WALK_civi", 4.1, 1, 1, 1, 1, 0);
  373. case PED_WALKING_GANGSTA: PED_ApplyAnimation(pedid, "PED", "WALK_gang1", 4.1, 1, 1, 1, 1, 0);
  374. case PED_WALKING_GANGSTA2: PED_ApplyAnimation(pedid, "PED", "WALK_gang2", 4.1, 1, 1, 1, 1, 0);
  375. case PED_WALKING_OLD: PED_ApplyAnimation(pedid, "PED", "WALK_old", 4.1, 1, 1, 1, 1, 0);
  376. case PED_WALKING_FAT_OLD: PED_ApplyAnimation(pedid, "PED", "WALK_fatold", 4.1, 1, 1, 1, 1, 0);
  377. case PED_WALKING_FAT: PED_ApplyAnimation(pedid, "PED", "WALK_fat", 4.1, 1, 1, 1, 0, 1);
  378. case PED_WALKING_LADY: PED_ApplyAnimation(pedid, "PED", "WOMAN_walknorm", 4.1, 1, 1, 1, 1, 0);
  379. case PED_WALKING_LADY2: PED_ApplyAnimation(pedid, "PED", "WOMAN_walkbusy", 4.1, 1, 1, 1, 1, 0);
  380. case PED_WALKING_WHORE: PED_ApplyAnimation(pedid, "PED", "WOMAN_walkpro", 4.1, 1, 1, 1, 1, 0);
  381. case PED_WALKING_WHORE2: PED_ApplyAnimation(pedid, "PED", "WOMAN_walksexy", 4.1, 1, 1, 1, 1, 0);
  382. case PED_WALKING_DRUNK: PED_ApplyAnimation(pedid, "PED", "WALK_drunk", 4.1, 1, 1, 1, 1, 0);
  383. case PED_WALKING_BLIND: PED_ApplyAnimation(pedid, "PED", "Walk_Wuzi", 4.1, 1, 1, 1, 1, 0);
  384. case PED_WALKING_ARMED: PED_ApplyAnimation(pedid, "PED", "WALK_armed", 4.1, 1, 1, 1, 1, 0);
  385. default: PED_ApplyAnimation(pedid, "PED", "WALK_player", 4.1, 1, 1, 1, 1, 0);
  386. }
  387. if(gPED[pedid][P_STATE] != PED_STATE_WALKING)
  388. {
  389. CallLocalFunction("PED_OnStateChange", "iii", pedid, PED_STATE_WALKING, gPED[pedid][P_STATE]);
  390. gPED[pedid][P_STATE] = PED_STATE_WALKING;
  391. }
  392. }
  393. else
  394. {
  395. switch(gPED[pedid][P_RUNSTYLE])
  396. {
  397. case PED_RUNNING_NORMAL: PED_ApplyAnimation(pedid, "PED", "run_civi", 4.1, 1, 1, 1, 1, 0);
  398. case PED_RUNNING_GANGSTA: PED_ApplyAnimation(pedid, "PED", "run_gang1", 4.1, 1, 1, 1, 1, 0);
  399. case PED_RUNNING_GANGSTA2: PED_ApplyAnimation(pedid, "PED", "run_gang1", 4.1, 1, 1, 1, 1, 0);
  400. case PED_RUNNING_OLD: PED_ApplyAnimation(pedid, "PED", "run_old", 4.1, 1, 1, 1, 1, 0);
  401. case PED_RUNNING_FAT_OLD: PED_ApplyAnimation(pedid, "PED", "run_fatold", 4.1, 1, 1, 1, 1, 0);
  402. case PED_RUNNING_FAT: PED_ApplyAnimation(pedid, "PED", "run_fat", 4.1, 1, 1, 1, 0, 1);
  403. case PED_RUNNING_LADY: PED_ApplyAnimation(pedid, "PED", "woman_run", 4.1, 1, 1, 1, 1, 0);
  404. case PED_RUNNING_LADY2: PED_ApplyAnimation(pedid, "PED", "WOMAN_runbusy", 4.1, 1, 1, 1, 1, 0);
  405. case PED_RUNNING_WHORE: PED_ApplyAnimation(pedid, "PED", "woman_runpanic", 4.1, 1, 1, 1, 1, 0);
  406. case PED_RUNNING_WHORE2: PED_ApplyAnimation(pedid, "PED", "WOMAN_runsexy", 4.1, 1, 1, 1, 1, 0);
  407. case PED_RUNNING_DRUNK: PED_ApplyAnimation(pedid, "PED", "WALK_drunk", 4.1, 1, 1, 1, 1, 0);
  408. case PED_RUNNING_BLIND: PED_ApplyAnimation(pedid, "PED", "Run_Wuzi", 4.1, 1, 1, 1, 1, 0);
  409. case PED_RUNNING_ARMED: PED_ApplyAnimation(pedid, "PED", "run_armed", 4.1, 1, 1, 1, 1, 0);
  410. default: PED_ApplyAnimation(pedid, "PED", "run_player", 4.1, 1, 1, 1, 1, 0);
  411. }
  412. if(gPED[pedid][P_STATE] != PED_STATE_RUNNING)
  413. {
  414. CallLocalFunction("PED_OnStateChange", "iii", pedid, PED_STATE_RUNNING, gPED[pedid][P_STATE]);
  415. gPED[pedid][P_STATE] = PED_STATE_RUNNING;
  416. }
  417. }
  418.  
  419. gPED[pedid][P_GOTOX] = x;
  420. gPED[pedid][P_GOTOY] = y;
  421. gPED[pedid][P_GOTOZ] = z;
  422. return true;
  423. }
  424.  
  425. stock PED_FollowPlayer(pedid, playerid, bool:walk = false)
  426. {
  427. if(! PED_IsConnected(pedid)) return false;
  428. if(PED_GetState(pedid) == PED_STATE_DEAD) return false;
  429. if(! IsPlayerConnected(playerid)) return false;
  430.  
  431. gPED[pedid][P_FOLLOWING] = playerid;
  432. gPED[pedid][P_FOLLOWINGWALK] = walk;
  433.  
  434. new Float:pos[3];
  435. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  436. PED_GotoPoint(pedid, pos[0], pos[1], pos[2], walk);
  437. return true;
  438. }
  439.  
  440. stock PED_GetFollowingPlayer(pedid)
  441. {
  442. if(! PED_IsConnected(pedid)) return INVALID_PLAYER_ID;
  443.  
  444. return gPED[pedid][P_FOLLOWING];
  445. }
  446.  
  447. stock PED_SetWalkingStyle(pedid, walkingstyle)
  448. {
  449. if(! PED_IsConnected(pedid)) return false;
  450. if(walkingstyle < 0 || walkingstyle > 13) return false;
  451.  
  452. gPED[pedid][P_WALKSTYLE] = walkingstyle;
  453. return true;
  454. }
  455.  
  456. stock PED_GetWalkingStyle(pedid)
  457. {
  458. if(! PED_IsConnected(pedid)) return false;
  459.  
  460. return gPED[pedid][P_WALKSTYLE];
  461. }
  462.  
  463. stock PED_SetRunningStyle(pedid, runningstyle)
  464. {
  465. if(! PED_IsConnected(pedid)) return false;
  466.  
  467. gPED[pedid][P_RUNSTYLE] = runningstyle;
  468. return true;
  469. }
  470.  
  471. stock PED_GetRunningStyle(pedid)
  472. {
  473. if(! PED_IsConnected(pedid)) return false;
  474.  
  475. return gPED[pedid][P_RUNSTYLE];
  476. }
  477.  
  478. stock PED_GetState(pedid)
  479. {
  480. if(! PED_IsConnected(pedid)) return false;
  481.  
  482. return gPED[pedid][P_STATE];
  483. }
  484.  
  485. stock PED_Stop(pedid)
  486. {
  487. if(! PED_IsConnected(pedid)) return false;
  488. if(PED_GetState(pedid) == PED_STATE_DEAD) return false;
  489.  
  490. if(gPED[pedid][P_STATE] != PED_STATE_NONE)
  491. {
  492. CallLocalFunction("PED_OnStateChange", "iii", pedid, PED_STATE_NONE, gPED[pedid][P_STATE]);//calling !:D!
  493. gPED[pedid][P_STATE] = PED_STATE_NONE;
  494. }
  495.  
  496. gPED[pedid][P_FOLLOWING] = INVALID_PLAYER_ID;
  497. return ClearActorAnimations(pedid);
  498. }
  499.  
  500. stock PED_Spawn(pedid)
  501. {
  502. if(! PED_IsConnected(pedid)) return false;
  503.  
  504. ClearActorAnimations(pedid);
  505.  
  506. if(gPED[pedid][P_STATE] != PED_STATE_NONE)
  507. {
  508. CallLocalFunction("PED_OnStateChange", "iii", pedid, PED_STATE_NONE, gPED[pedid][P_STATE]);//calling !:D!
  509. gPED[pedid][P_STATE] = PED_STATE_NONE;
  510. }
  511.  
  512. PED_SetHealth(pedid, 100.0);
  513. PED_SetVirtualWorld(pedid, 0);
  514. PED_SetPos(pedid, 0.0, 0.0, 0.0);
  515. PED_SetPos(pedid, gPED[pedid][P_X], gPED[pedid][P_Y], gPED[pedid][P_Z]);
  516. PED_SetFacingAngle(pedid, gPED[pedid][P_ROT]);
  517.  
  518. gPED[pedid][P_FOLLOWING] = INVALID_PLAYER_ID;
  519.  
  520. CallLocalFunction("PED_OnSpawn", "i", pedid);
  521. return true;
  522. }
  523.  
  524. stock PED_SetSpawnInfo(pedid, Float:x, Float:y, Float:z, Float:rotation)
  525. {
  526. if(! PED_IsConnected(pedid)) return false;
  527.  
  528. gPED[pedid][P_X] = x;
  529. gPED[pedid][P_Y] = y;
  530. gPED[pedid][P_Z] = z;
  531. gPED[pedid][P_ROT] = rotation;
  532. return true;
  533. }
  534.  
  535. //player functions
  536. stock GetPlayerCameraTargetPED(playerid)
  537. {
  538. if(! IsPlayerConnected(playerid)) return false;
  539.  
  540. return GetPlayerCameraTargetActor(playerid);
  541. }
  542.  
  543. #if ! defined KEY_AIM
  544. #define KEY_AIM 128
  545. #endif
  546.  
  547. //player functions
  548. stock IsPlayerLookingAtPED(playerid, pedid)
  549. {
  550. if(! PED_IsConnected(pedid)) return false;
  551. if(! IsPlayerConnected(playerid)) return false;
  552.  
  553. // Get the camera's positions
  554. new Float:vx, Float:vy, Float:vz;
  555. GetPlayerCameraFrontVector(playerid, vx, vy, vz);
  556.  
  557. new Float:cx, Float:cy, Float:cz;
  558. GetPlayerCameraPos(playerid, cx, cy, cz);
  559.  
  560. new Float:a;
  561. GetPlayerFacingAngle(playerid, a);
  562.  
  563. //checking distance, setting offset and x,y,z coords!
  564. new Float:x, Float:y, Float:z;
  565. new Float:offset;
  566. for(new Float:d; d < 100.0; d += 0.5)
  567. {
  568. switch(GetPlayerWeapon(playerid))
  569. {
  570. case 24, 29, 22, 23, 25, 26, 27, 28, 32: offset = 0.11;
  571. case 30, 31: offset = 0.07;
  572. case 33, 34: offset = 0.0;
  573. }
  574. switch(GetPlayerWeapon(playerid))
  575. {
  576. case 22, 26, 28, 32:
  577. {
  578. x = vx * d+cx;
  579. y = vy * d+cy;
  580. }
  581. default:
  582. {
  583. x = cx + (d * floatsin(-a, degrees));
  584. y = cy + (d * floatcos(-a, degrees));
  585. }
  586. }
  587.  
  588. z = (vz + offset) * d + cz;
  589.  
  590. //setting the radius
  591. #define radius 1.5
  592.  
  593. //this one is for crouched ped
  594. //if(PED_IsInRangeOfPoint(pedid, radius + 0.2, x, y, z + 0.1)) return true;
  595.  
  596. if(PED_IsInRangeOfPoint(pedid, radius, x, y, z - 0.8)) return true;
  597. }
  598. return false;
  599. }
  600.  
  601. stock GetPlayerTargetPED(playerid)
  602. {
  603. new keys, updown, leftright;
  604. GetPlayerKeys(playerid, keys, updown, leftright);
  605.  
  606. if( GetPlayerWeapon(playerid) < 22 &&
  607. GetPlayerWeapon(playerid) > 38 &&
  608. ! (keys & KEY_AIM))
  609. {
  610. return INVALID_PED_ID;
  611. }
  612.  
  613. for(new i; i < MAX_PEDS; i++)
  614. {
  615. if(IsPlayerLookingAtPED(playerid, i)) return i;
  616. }
  617. return INVALID_PED_ID;
  618. }
  619.  
  620. stock PED_IsStreamedIn(pedid, forplayerid)
  621. {
  622. if(! PED_IsConnected(pedid)) return false;
  623. if(! IsPlayerConnected(forplayerid)) return false;
  624.  
  625. return IsActorStreamedIn(pedid, forplayerid);
  626. }
  627.  
  628. //internal callback
  629. forward PED_OnTimeUpdate(pedid);
  630. public PED_OnTimeUpdate(pedid)
  631. {
  632. if( PED_GetState(pedid) == PED_STATE_RUNNING ||
  633. PED_GetState(pedid) == PED_STATE_WALKING)
  634. {
  635. if(PED_IsInRangeOfPoint(pedid, 2.0, gPED[pedid][P_GOTOX], gPED[pedid][P_GOTOY], gPED[pedid][P_GOTOZ]))//will be adding a better version when actors include gets an update from Kalcor*!
  636. {
  637. CallLocalFunction("PED_OnReachDestination", "ifff", pedid, gPED[pedid][P_GOTOX], gPED[pedid][P_GOTOY], gPED[pedid][P_GOTOZ]);
  638.  
  639. if(gPED[pedid][P_FOLLOWING] != INVALID_PLAYER_ID)
  640. {
  641. if(! IsPlayerConnected(gPED[pedid][P_FOLLOWING]))
  642. {
  643. PED_Stop(pedid);
  644. return 1;
  645. }
  646.  
  647. new Float:pos[3];
  648. GetPlayerPos(gPED[pedid][P_FOLLOWING], pos[0], pos[1], pos[2]);
  649. PED_GotoPoint(pedid, pos[0], pos[1], pos[2], gPED[pedid][P_FOLLOWINGWALK]);
  650. }
  651. return 1;
  652. }
  653. }
  654. return 1;
  655. }
  656.  
  657. public OnActorStreamIn(actorid, forplayerid)
  658. {
  659. if(gPED[actorid][P_EXIST]) CallLocalFunction("PED_OnStreamIn", "ii", actorid, forplayerid);
  660.  
  661. #if defined HoOK_OnActorStreamIn
  662. HoOK_OnActorStreamIn(actorid, forplayerid);
  663. #endif
  664. return 1;
  665. }
  666. #if defined _ALS_OnActorStreamIn
  667. #undef OnActorStreamIn
  668. #else
  669. #define _ALS_OnActorStreamIn
  670. #endif
  671. #define OnActorStreamIn HoOK_OnActorStreamIn
  672. #if defined HoOK_OnActorStreamIn
  673. forward HoOK_OnActorStreamIn(actorid, forplayerid);
  674. #endif
  675.  
  676. public OnActorStreamOut(actorid, forplayerid)
  677. {
  678. if(gPED[actorid][P_EXIST]) CallLocalFunction("PED_OnStreamOut", "ii", actorid, forplayerid);
  679.  
  680. #if defined HoOK_OnActorStreamOut
  681. HoOK_OnActorStreamOut(actorid, forplayerid);
  682. #endif
  683. return 1;
  684. }
  685. #if defined _ALS_OnActorStreamOut
  686. #undef OnActorStreamOut
  687. #else
  688. #define _ALS_OnActorStreamOut
  689. #endif
  690. #define OnActorStreamOut HoOK_OnActorStreamOut
  691. #if defined HoOK_OnActorStreamOut
  692. forward HoOK_OnActorStreamOut(actorid, forplayerid);
  693. #endif
  694.  
  695. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  696. {
  697. new Float:ped_health;
  698. new Float:ped_damage;
  699. new target_ped = GetPlayerCameraTargetPED(playerid);
  700.  
  701. new Float:ped_pos[3];
  702. PED_GetPos(target_ped, ped_pos[0], ped_pos[1], ped_pos[2]);
  703.  
  704. #if ! defined foreach_player
  705. //#define foreach_player(%1) for(new %1; %1 <= GetPlayerPoolSize(); %1++) if(IsPlayerConnected(%1))
  706. #define foreach_player(%1) for(new %1; %1 < MAX_PLAYERS; %1++) if(IsPlayerConnected(%1))
  707. #endif
  708.  
  709. if(target_ped != INVALID_PED_ID)
  710. {
  711. if(PED_GetState(target_ped) != PED_STATE_DEAD)
  712. {
  713. PED_GetHealth(target_ped, ped_health);
  714.  
  715. switch(weaponid)//not a perfect, actually a good damage system for PEDS!
  716. {
  717. case 22: ped_damage = 8.0;//not accurate and same default values
  718. case 23: ped_damage = 13.0;
  719. case 24: ped_damage = 46.0;
  720. case 25: ped_damage = 49.0;
  721. case 26: ped_damage = 49.0;
  722. case 27: ped_damage = 39.0;
  723. case 28: ped_damage = 6.0;
  724. case 29: ped_damage = 8.0;
  725. case 30: ped_damage = 9.0;
  726. case 31: ped_damage = 9.0;
  727. case 32: ped_damage = 6.0;
  728. case 33: ped_damage = 35.0;
  729. case 34: ped_damage = 41.0;
  730. case 35: ped_damage = 65.0;
  731. case 36: ped_damage = 65.0;
  732. }
  733.  
  734. if(CallLocalFunction("PED_OnTakeDamage", "iiif", target_ped, playerid, weaponid, ped_damage))
  735. {
  736. ped_health -= ped_damage;
  737. PED_SetHealth(target_ped, ped_health);
  738. switch(random(3))
  739. {
  740. case 0: PED_ApplyAnimation(target_ped, "PED", "HitA_1", 4.1, 0, 1, 1, 1, 0);
  741. case 1: PED_ApplyAnimation(target_ped, "PED", "HitA_2", 4.1, 0, 1, 1, 1, 0);
  742. case 2: PED_ApplyAnimation(target_ped, "PED", "HitA_3", 4.1, 0, 1, 1, 1, 0);
  743. }
  744. foreach_player(i) PlayerPlaySound(i, 1135, ped_pos[0], ped_pos[1], ped_pos[2]);//play sound for all
  745. }
  746.  
  747. if(ped_health <= 0.0)//if the ped is dead
  748. {
  749. CallLocalFunction("PED_OnStateChange", "iii", target_ped, PED_STATE_DEAD, gPED[target_ped][P_STATE]);//calling !:D!
  750. gPED[target_ped][P_STATE] = PED_STATE_DEAD;
  751.  
  752. PED_ApplyAnimation(target_ped, "KNIFE", "KILL_Knife_Ped_Die", 4.1, 0, 1, 1, 1, 0);
  753.  
  754. foreach_player(i) PlayerPlaySound(i, 1095, ped_pos[0], ped_pos[1], ped_pos[2]);//play sound for all
  755.  
  756. if(CallLocalFunction("PED_OnDeath", "iii", target_ped, playerid, weaponid))
  757. {
  758. SetTimerEx("PED_SpawnPlayerAfterDeath", 3 * 1000 + 5 * 100, false, "i", target_ped);//spawn after 3.5 seconds
  759. }
  760. }
  761. }
  762. }
  763.  
  764. #if defined HoOK_OnPlayerWeaponShot
  765. HoOK_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  766. #endif
  767. return 1;
  768. }
  769. #if defined _ALS_OnPlayerWeaponShot
  770. #undef OnPlayerWeaponShot
  771. #else
  772. #define _ALS_OnPlayerWeaponShot
  773. #endif
  774. #define OnPlayerWeaponShot HoOK_OnPlayerWeaponShot
  775. #if defined HoOK_OnPlayerWeaponShot
  776. forward HoOK_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
  777. #endif
  778.  
  779. forward PED_SpawnPlayerAfterDeath(pedid);
  780. public PED_SpawnPlayerAfterDeath(pedid) return PED_Spawn(pedid);
  781.  
  782. forward PED_OnConnect(pedid);
  783. forward PED_OnDisconnect(pedid);
  784. forward PED_OnSpawn(pedid);
  785. forward PED_OnReachDestination(pedid, Float:x, Float:y, Float:z);
  786. forward PED_OnStateChange(pedid, newstate, oldstate);
  787. forward PED_OnStreamIn(pedid, playerid);
  788. forward PED_OnStreamOut(pedid, playerid);
  789. forward PED_OnTakeDamage(pedid, issuerid, weaponid, Float:damage);
  790. forward PED_OnDeath(pedid, killerid, weaponid);
Advertisement
Add Comment
Please, Sign In to add comment