Guest User

jelen

a guest
Jul 25th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.58 KB | None | 0 0
  1. /*
  2. Deer Hunting v1.02 for SAMP - by Dinnozor
  3. English Version
  4.  
  5. Hunt deers in the country near LS !
  6.  
  7. v1.02 fixes :
  8. -Greatly increased the accuracy ; added a parameter to IsPlayerAimingPoint function (weapon)
  9. -Another orientation problem corrected
  10. -Added a condition in the OnPlayerUpdate (which you can actually replace by a callback called less frequently) so there won't be loops on every update
  11.  
  12. v1.01 fixes :
  13. -Use of GetPlayerCameraFrontVector instead of GetPlayerFacingAngle : checks the Z coord, you can't "cheat" only using your facing angle :)
  14. -Modified the FinDeer function because it had a bug when you picked the meat. If you clicked several times on LMB you could take more. -Fixed
  15. -Corrected a bug of the deer orientation during its movement
  16. -a few little bugs fixed
  17.  
  18. Please don't remove credits if shared. Modify, customize and use as you want to.
  19. Enjoy !
  20. */
  21.  
  22. #include <a_samp>
  23.  
  24. #include <streamer>
  25. #include <OPVD>
  26.  
  27. #define MAX_ANIM 20
  28. #define DEER_SPAWN_LOC 21
  29. #define COLOR_RED 0xAA3333AA
  30. #define COLOR_GREEN 0xDABB3EAA
  31.  
  32. // HOLDING(keys)
  33. #define HOLDING(%0) \
  34. ((newkeys & (%0)) == (%0))
  35.  
  36. forward MovingDeer(DeerID);
  37. forward DestroyDeer(DeerID);
  38. forward FinDeer(DeerID,playerid);
  39.  
  40. forward Float:Distance(Float:xA,Float:yA,Float:zA,Float:xB,Float:yB,Float:zB);
  41.  
  42. new Deers[MAX_ANIM],DeerKO[MAX_ANIM],DeerObject[MAX_ANIM];
  43. new DeerMeat[MAX_ANIM],InfectedDeer[MAX_ANIM],DeerMove[MAX_ANIM],MeatPick[MAX_PLAYERS];
  44. new gPlayerUsingLoopingAnim[MAX_PLAYERS];
  45.  
  46. enum pInfo
  47. {
  48. Viande,
  49. AdminLvl//Replace with yoour own variables ("Viande" means "meat")
  50. }
  51. ;
  52. new PlayerInfo[MAX_PLAYERS][pInfo];
  53.  
  54. //Spawn Locations for deers. Of course, if you add areas below, add at least a spawning location for every added area, or the deers will never be belo them...
  55. //You can add as many spawning locations as you want. You just need to replace the DEER_SPAWN_LOC in the top of the script by the actual number of locations (originally it is 21)
  56.  
  57. new Float:DeerSpawn[DEER_SPAWN_LOC][3]=
  58. {
  59.  
  60.  
  61.  
  62.  
  63. {
  64. // -604.803588,-1308.452636,22.106567
  65. 1652.8370,-739.3474,55.5581
  66.  
  67.  
  68. }
  69. ,
  70.  
  71.  
  72.  
  73.  
  74. {
  75. // -702.036621,-1309.305297,63.694377
  76. 1644.0076,-747.9075,57.0596
  77.  
  78.  
  79. }
  80. ,
  81.  
  82.  
  83.  
  84.  
  85. {
  86. // -630.591491,-889.400268,108.452827
  87. 1657.6516,-762.9561,55.8419
  88.  
  89.  
  90. }
  91. ,
  92.  
  93.  
  94.  
  95.  
  96. {
  97. // -992.249938,-930.179138,129.602951
  98. 1645.9792,-774.7592,58.0914
  99.  
  100.  
  101. }
  102. ,
  103.  
  104.  
  105.  
  106.  
  107. {
  108. // -935.597717,-1146.799194,129.202728
  109. 1650.7961,-790.6989,57.7443
  110.  
  111.  
  112. }
  113. ,
  114.  
  115.  
  116.  
  117.  
  118. {
  119. // -394.224884,87.232124,28.368480
  120. 1623.2500,-757.6645,60.8147
  121.  
  122.  
  123. }
  124. ,
  125.  
  126.  
  127.  
  128.  
  129. {
  130. // -636.897583,-92.761047,64.660194
  131. 1606.5117,-764.2968,63.7290
  132.  
  133.  
  134. }
  135. ,
  136.  
  137.  
  138.  
  139.  
  140. {
  141. // -2447.039794,-2192.797851,28.498489
  142.  
  143.  
  144.  
  145. }
  146. ,
  147.  
  148.  
  149.  
  150.  
  151. {
  152. // -2224.478759,-2367.201416,32.494483
  153.  
  154.  
  155.  
  156. }
  157. ,
  158.  
  159.  
  160.  
  161.  
  162. {
  163. // -1803.133300,-2423.008789,26.044141
  164.  
  165.  
  166.  
  167. }
  168. ,
  169.  
  170.  
  171.  
  172.  
  173. {
  174. // -1690.161499,-2070.091308,42.189098
  175.  
  176.  
  177.  
  178. }
  179. ,
  180.  
  181.  
  182.  
  183.  
  184. {
  185. // 2006.325439,-766.786865,131.285568
  186.  
  187.  
  188.  
  189. }
  190. ,
  191.  
  192.  
  193.  
  194.  
  195. {
  196. // -1817.458251,-1867.854980,86.802558
  197.  
  198.  
  199.  
  200. }
  201. ,
  202.  
  203.  
  204.  
  205.  
  206. {
  207. // 2176.190429,-897.414916,84.565956
  208.  
  209.  
  210.  
  211. }
  212. ,
  213.  
  214.  
  215.  
  216.  
  217. {
  218. // 2647.276855,-840.732543,70.997520
  219.  
  220.  
  221.  
  222. }
  223. ,
  224.  
  225.  
  226.  
  227.  
  228. {
  229. // 2601.860351,-436.280792,73.739181
  230.  
  231.  
  232.  
  233. }
  234. ,
  235.  
  236.  
  237.  
  238.  
  239. {
  240. // 2365.430664,-356.828186,59.507225
  241.  
  242.  
  243.  
  244. }
  245. ,
  246.  
  247.  
  248.  
  249.  
  250. {
  251. // 927.202453,-10.505444,91.440376
  252.  
  253.  
  254.  
  255. }
  256. ,
  257.  
  258.  
  259.  
  260.  
  261. {
  262. // 1092.987304,15.023153,68.779556
  263.  
  264.  
  265.  
  266. }
  267. ,
  268.  
  269.  
  270.  
  271.  
  272. {
  273. // 1504.512084,192.802429,22.368137
  274.  
  275.  
  276.  
  277. }
  278. ,
  279.  
  280.  
  281.  
  282.  
  283. {
  284. // 1083.728637,362.787322,25.921319
  285.  
  286.  
  287.  
  288. }
  289. }
  290. ;
  291.  
  292. public OnGameModeInit()
  293. {
  294. for(new i=0;i<MAX_ANIM;i++)
  295.  
  296.  
  297.  
  298. {
  299. new rand=random(DEER_SPAWN_LOC);
  300. new Float:X=DeerSpawn[rand][0];
  301. new Float:Y=DeerSpawn[rand][1];
  302. CreateDeer(X,Y);
  303.  
  304.  
  305.  
  306.  
  307. }
  308. return 1;
  309. }
  310.  
  311. public OnPlayerConnect(playerid)
  312. {
  313. MeatPick[playerid]=0;
  314. gPlayerUsingLoopingAnim[playerid]=0;
  315. return 1;
  316. }
  317.  
  318. //You need the MapAndreas Include (see my post on SAMP Forums for the link)
  319. stock Float: GetPointZPos(const Float: fX, const Float: fY, &Float: fZ = 0.0)
  320. {
  321. if(!((-3000.0 < fX < 3000.0) && (-3000.0 < fY < 3000.0)))
  322.  
  323.  
  324. {
  325. return 0.0;
  326.  
  327.  
  328.  
  329. }
  330. static
  331. File: s_hMap
  332. ;
  333. if(!s_hMap)
  334.  
  335.  
  336. {
  337. s_hMap = fopen("SAfull.hmap", io_read);
  338.  
  339. if(!s_hMap)
  340.  
  341.  
  342. {
  343. return 0.0;
  344.  
  345.  
  346.  
  347. }
  348.  
  349.  
  350.  
  351. }
  352. new
  353. afZ[1]
  354. ;
  355. fseek(s_hMap, ((6000 * (-floatround(fY, floatround_tozero) + 3000) + (floatround(fX, floatround_tozero) + 3000)) << 1));
  356. fblockread(s_hMap, afZ);
  357.  
  358. return (fZ = ((afZ[0] >>> 16) * 0.01));
  359. }
  360.  
  361. stock IsPlayerAimingPoint(playerid, Float:X2,Float:Y2,Float:Z2, Float:range,Float:accuracy,weapon=0)
  362. {
  363. new Float:Dist, Float:xv,Float:yv,Float:zv,Float:xc,Float:yc,Float:zc,Float:xt,Float:yt,Float:zt,Float:wDis,Float:AngleD;
  364. GetPlayerCameraPos(playerid,xc,yc,zc);
  365. GetPlayerCameraFrontVector(playerid,xv,yv,zv);
  366.  
  367. xt=xc+range*xv;
  368. yt=yc+range*yv;
  369. zt=range*zv+zc;
  370.  
  371. switch(weapon)
  372.  
  373. {
  374. case 34:
  375.  
  376. {
  377. AngleD=0;
  378. wDis=100;
  379.  
  380.  
  381. }
  382. case 33:
  383.  
  384. {
  385. AngleD=3;
  386. wDis=90;
  387.  
  388.  
  389. }
  390. case 30,31:
  391.  
  392. {
  393. AngleD=4;
  394. wDis=70;
  395.  
  396.  
  397. }
  398. case 22..24:
  399.  
  400. {
  401. AngleD=6;
  402. wDis=40;
  403.  
  404.  
  405. }
  406. case 25..27:
  407.  
  408. {
  409. AngleD=4;
  410. wDis=25;
  411.  
  412.  
  413. }
  414. default:
  415.  
  416. {
  417. AngleD=6;
  418. wDis=50;
  419.  
  420.  
  421. }
  422.  
  423.  
  424. }
  425. Dist=floatsqroot(floatpower(floatabs(xt-X2), 2) + floatpower(floatabs(yt-Y2), 2)+floatpower(floatabs(range*floattan(AngleD,degrees)+zt-Z2),2));
  426.  
  427. if (Dist<=accuracy&&wDis>=range) return true;
  428. return false;
  429. }
  430.  
  431. public Float:Distance(Float:xA,Float:yA,Float:zA,Float:xB,Float:yB,Float:zB)
  432. {
  433. new Float:Dist=floatsqroot((xB-xA)*(xB-xA)+(yB-yA)*(yB-yA)+(zB-zA)*(zB-zA));
  434. return Dist;
  435. }
  436.  
  437. public OnPlayerUpdate(playerid)//Or whatever equivalent function called frequently (like your own Update function)
  438. {
  439. new Float:xP,Float:yP,Float:zP;
  440. GetPlayerPos(playerid,xP,yP,zP);
  441. if(IsPosInDeerZone(xP,yP))
  442.  
  443. {
  444. for(new i=0;i<MAX_ANIM;i++)
  445.  
  446.  
  447. {
  448. if(IsValidDynamicObject(DeerObject[i])&&Deers[i]>0)
  449.  
  450.  
  451.  
  452. {
  453. new Float:xd,Float:yd,Float:zd;
  454. GetDynamicObjectPos(DeerObject[i],xd,yd,zd);
  455. if(IsPlayerInAnyVehicle(playerid))
  456.  
  457.  
  458.  
  459. {
  460. new mod=GetVehicleModel(GetPlayerVehicleID(playerid)); if(mod!=509&&mod!=510&&mod!=481)
  461.  
  462.  
  463.  
  464. {
  465. if(IsPlayerInRangeOfPoint(playerid,25,xd,yd,zd))
  466.  
  467.  
  468.  
  469. {
  470. MovingDeer(i);
  471.  
  472.  
  473.  
  474.  
  475. }
  476.  
  477.  
  478.  
  479.  
  480. }
  481. else
  482.  
  483.  
  484.  
  485. {
  486. if(IsPlayerInRangeOfPoint(playerid,10,xd,yd,zd))
  487.  
  488.  
  489.  
  490. {
  491. MovingDeer(i);
  492.  
  493.  
  494.  
  495.  
  496. }
  497.  
  498.  
  499.  
  500.  
  501. }
  502.  
  503.  
  504.  
  505.  
  506. }
  507. else if(IsPlayerInRangeOfPoint(playerid,2,xd,yd,zd)&&InfectedDeer[i]==1&&DeerKO[i]==0&&random(15)==0)
  508.  
  509.  
  510.  
  511. {
  512. new Float:phealth;
  513. GetPlayerHealth(playerid,phealth);
  514. SetPlayerHealth(playerid,floatround(phealth-1,floatround_round));
  515. OnePlayAnim(playerid,"ped","HIT_wall",4,0,1,1,0,0);
  516. GameTextForPlayer(playerid,"A deer is attacking you !",3000,6);
  517.  
  518.  
  519.  
  520.  
  521. }
  522. else
  523.  
  524.  
  525.  
  526. {
  527. if(IsPlayerInRangeOfPoint(playerid,15,xd,yd,zd))
  528.  
  529.  
  530.  
  531. {
  532.  
  533. if(InfectedDeer[i]==1&&DeerKO[i]==0&&DeerMove[i]==0)
  534.  
  535.  
  536.  
  537. {
  538. new Float:xp,Float:yp,Float:zp,Float:Angle;
  539. GetPlayerPos(playerid,xp,yp,zp);
  540. GetPointZPos(xp,yp,zp);
  541. if(IsPosInDeerZone(xp,yp))
  542.  
  543.  
  544.  
  545. {
  546. DeerMove[i]=1;
  547. if((xp-xd)>0&&(yp-yd)>0)Angle=atan((yp-yd)/(xp-xd));
  548. else Angle=atan((yp-yd)/(xp-xd))-180;
  549. switch(random(2))
  550.  
  551.  
  552.  
  553. {
  554. case 0:MoveDynamicObject(DeerObject[i],xp-1,yp,zp+0.3,8,0,0,Angle);
  555. case 1:MoveDynamicObject(DeerObject[i],xp,yp-1,zp+0.3,10,0,0,Angle);
  556.  
  557.  
  558. }
  559.  
  560.  
  561.  
  562.  
  563. }
  564. else MovingDeer(i);
  565.  
  566.  
  567.  
  568.  
  569. }
  570. else MovingDeer(i);
  571.  
  572.  
  573.  
  574.  
  575. }
  576.  
  577.  
  578.  
  579.  
  580. }
  581.  
  582.  
  583.  
  584.  
  585. }
  586.  
  587.  
  588.  
  589. }
  590.  
  591. }
  592. new iCurWeap = GetPlayerWeapon(playerid);
  593. new iCurAmmo = GetPlayerAmmo(playerid);
  594. if(iCurWeap==GetPVarInt(playerid,"iCurrentWeapon")&&iCurAmmo!=GetPVarInt(playerid,"iCurrentAmmo"))
  595.  
  596.  
  597. {
  598. OnPlayerShoot(playerid,GetPVarInt(playerid, "iCurrentAmmo"), iCurAmmo,iCurWeap);
  599. SetPVarInt(playerid,"iCurrentAmmo",iCurAmmo);
  600.  
  601.  
  602.  
  603. }
  604. return 1;
  605. }
  606.  
  607. stock OnPlayerShoot(playerid,oldammo,newammo,weapon)
  608. {
  609. for (new i=0;i<MAX_ANIM;i++)
  610.  
  611.  
  612.  
  613. {
  614. new Float:X,Float:Y,Float:Z,Float:rx,Float:ry,Float:rz,Float:Z2,Float:xp,Float:yp,Float:zp;
  615. GetDynamicObjectPos(DeerObject[i],X,Y,Z);
  616. if(IsPlayerInRangeOfPoint(playerid,100,X,Y,Z))
  617.  
  618.  
  619. {
  620. GetPlayerCameraPos(playerid,xp,yp,zp);
  621. new Float:Dist=Distance(xp,yp,zp,X,Y,Z);
  622.  
  623. if(IsPlayerAimingPoint(playerid,X,Y,Z,Dist,1.50,GetPlayerWeapon(playerid)))
  624.  
  625.  
  626.  
  627. {
  628. GetDynamicObjectRot(DeerObject[i],rx,ry,rz);
  629. GetPointZPos(X,Y,Z2);
  630. MoveDynamicObject(DeerObject[i],X+0.1,Y,Z2+0.15,0.4,90,0,rz);
  631. switch(GetPlayerWeapon(playerid))
  632.  
  633.  
  634.  
  635. {
  636. case 22,23,33,34:DeerMeat[i]--;
  637. case 25..27:DeerMeat[i]-=3;
  638. default:DeerMeat[i]-=2;
  639.  
  640.  
  641.  
  642.  
  643. }
  644. DeerKO[i]=1;
  645.  
  646.  
  647.  
  648.  
  649. }
  650.  
  651. else
  652.  
  653.  
  654.  
  655. {
  656. if(IsPlayerInRangeOfPoint(playerid,45,X,Y,Z)) MovingDeer(i);//Shooting will frighten near deers
  657.  
  658.  
  659.  
  660. }
  661.  
  662.  
  663.  
  664. }
  665.  
  666.  
  667.  
  668. }
  669. }
  670.  
  671. public OnPlayerCommandText(playerid,cmdtext[])
  672. {
  673. if (!strcmp(cmdtext,"/resetdeers",true))
  674.  
  675.  
  676.  
  677.  
  678. {
  679. if(IsPlayerAdmin(playerid)) SendClientMessage(playerid,COLOR_RED,"You are not allowed to use this command.");
  680. // if (PlayerInfo[playerid][AdminLvl]<1) SendClientMessage(playerid,COLOR_RED,"You are not allowed to use this command.");
  681. else
  682.  
  683.  
  684.  
  685. {
  686. for(new i=0;i<MAX_ANIM;i++)
  687.  
  688.  
  689.  
  690. {
  691. DestroyDeer(i);
  692. new rand=random(DEER_SPAWN_LOC);
  693. new Float:X=DeerSpawn[rand][0];
  694. new Float:Y=DeerSpawn[rand][1];
  695. CreateDeer(X,Y);
  696.  
  697.  
  698.  
  699.  
  700. }
  701.  
  702.  
  703.  
  704.  
  705. }
  706. return 1;
  707.  
  708.  
  709.  
  710.  
  711. }
  712. return 0;
  713. }
  714.  
  715. stock CreateDeer(Float:X,Float:Y)
  716. {
  717. new DeerID=-1;
  718. for (new i=0;i<MAX_ANIM;i++)
  719.  
  720.  
  721.  
  722. {
  723. if(Deers[i]==0)
  724.  
  725.  
  726.  
  727. {
  728. DeerID=i;
  729. i=MAX_ANIM;
  730.  
  731.  
  732.  
  733.  
  734. }
  735.  
  736.  
  737.  
  738.  
  739. }
  740. if(DeerID!=-1)
  741.  
  742.  
  743.  
  744. {
  745. new Float:Z;
  746. GetPointZPos(X,Y,Z);
  747. DeerObject[DeerID]=CreateDynamicObject(19315,X,Y,Z+1,0,0,0,-1,-1,-1,300);
  748. Deers[DeerID]=1;
  749. DeerMeat[DeerID]=5+random(10);
  750. DeerKO[DeerID]=0;
  751. MovingDeer(DeerID);
  752. if(random(100)<3) InfectedDeer[DeerID]=1;//Here it will "infect" 3% of the deers. If you don't want any "crazy" deer, just replace these lines with "InfectedDeer[DeerID]=0;". You can also change the 3%, just replace the 3...
  753. else InfectedDeer[DeerID]=0;
  754. }
  755. if(DeerID!=-2)
  756.  
  757.  
  758.  
  759. {
  760. new Float:Z;
  761. GetPointZPos(X,Y,Z);
  762. DeerObject[DeerID]=CreateDynamicObject(19315,X,Y,Z+1,0,0,0,-1,-1,-1,300);
  763. Deers[DeerID]=2;
  764. DeerMeat[DeerID]=5+random(10);
  765. DeerKO[DeerID]=0;
  766. MovingDeer(DeerID);
  767. if(random(100)<3) InfectedDeer[DeerID]=2;//Here it will "infect" 3% of the deers. If you don't want any "crazy" deer, just replace these lines with "InfectedDeer[DeerID]=0;". You can also change the 3%, just replace the 3...
  768. else InfectedDeer[DeerID]=0;
  769.  
  770. }
  771. if(DeerID!=-3)
  772.  
  773.  
  774.  
  775. {
  776. new Float:Z;
  777. GetPointZPos(X,Y,Z);
  778. DeerObject[DeerID]=CreateDynamicObject(19315,X,Y,Z+1,0,0,0,-1,-1,-1,300);
  779. Deers[DeerID]=3;
  780. DeerMeat[DeerID]=5+random(10);
  781. DeerKO[DeerID]=0;
  782. MovingDeer(DeerID);
  783. if(random(100)<3) InfectedDeer[DeerID]=3;//Here it will "infect" 3% of the deers. If you don't want any "crazy" deer, just replace these lines with "InfectedDeer[DeerID]=0;". You can also change the 3%, just replace the 3...
  784. else InfectedDeer[DeerID]=0;
  785. }
  786. if(DeerID!=-4)
  787.  
  788.  
  789.  
  790. {
  791. new Float:Z;
  792. GetPointZPos(X,Y,Z);
  793. DeerObject[DeerID]=CreateDynamicObject(19315,X,Y,Z+1,0,0,0,-1,-1,-1,300);
  794. Deers[DeerID]=4;
  795. DeerMeat[DeerID]=5+random(10);
  796. DeerKO[DeerID]=0;
  797. MovingDeer(DeerID);
  798. if(random(100)<3) InfectedDeer[DeerID]=4;//Here it will "infect" 3% of the deers. If you don't want any "crazy" deer, just replace these lines with "InfectedDeer[DeerID]=0;". You can also change the 3%, just replace the 3...
  799. else InfectedDeer[DeerID]=0;
  800. }
  801. if(DeerID!=-5)
  802.  
  803.  
  804.  
  805. {//-702.036621,-1309.305297,63.694377
  806. new Float:Z;
  807. GetPointZPos(X,Y,Z);
  808. DeerObject[DeerID]=CreateDynamicObject(19315,X,Y,Z+1,0,0,0,-1,-1,-1,300);
  809. Deers[DeerID]=5;
  810. DeerMeat[DeerID]=5+random(10);
  811. DeerKO[DeerID]=0;
  812. MovingDeer(DeerID);
  813. if(random(100)<3) InfectedDeer[DeerID]=5;//Here it will "infect" 3% of the deers. If you don't want any "crazy" deer, just replace these lines with "InfectedDeer[DeerID]=0;". You can also change the 3%, just replace the 3...
  814. else InfectedDeer[DeerID]=0;
  815. }
  816. }
  817.  
  818. public DestroyDeer(DeerID)
  819. {
  820. DeerMeat[DeerID]=0;
  821. Deers[DeerID]=0;
  822. DestroyDynamicObject(DeerObject[DeerID]);
  823. return 1;
  824. }
  825.  
  826. public MovingDeer(DeerID)
  827. {
  828. if(DeerKO[DeerID]==0&&DeerMove[DeerID]==0)
  829.  
  830.  
  831.  
  832. {
  833. new Float:X,Float:Y,Float:Z,Float:Xrand,Float:Yrand,Float:Zrand,Float:speedRand,Float:Angle,Float:coef,Float:X2,Float:Y2;
  834. GetDynamicObjectPos(DeerObject[DeerID],X,Y,Z);
  835. new rand1=random(2),rand2=random(2);
  836. if(rand1==0) Xrand=X+10+float(random(10));
  837. else Xrand=X-10-float(random(10));
  838. if(rand2==0) Yrand=Y+10+float(random(10));
  839. else Yrand=Y-10-float(random(10));
  840. Zrand=GetPointZPos(Xrand,Yrand,Zrand);
  841. speedRand=7+float(random(9));
  842. if((Xrand-X)>0&&(Yrand-Y)>0)Angle=atan((Yrand-Y)/(Xrand-X));
  843. else Angle=atan((Yrand-Y)/(Xrand-X))-180;
  844.  
  845. if(floatabs(Zrand-Z)<3.0)
  846.  
  847.  
  848.  
  849. {
  850. if(IsPosInDeerZone(Xrand,Yrand))
  851.  
  852.  
  853.  
  854. {
  855. GetPointZPos(Xrand,Yrand,Zrand);
  856. SetDynamicObjectRot(DeerObject[DeerID],0,0,Angle);
  857. MoveDynamicObject(DeerObject[DeerID],Xrand,Yrand,Zrand+0.3,speedRand,0,0,Angle);
  858. DeerMove[DeerID]=1;
  859. SetTimerEx("MovingDeer",10000+random(40000),false,"i",DeerID);//On peut changer la fréquence des mouvements
  860.  
  861.  
  862.  
  863.  
  864. }
  865. else MovingDeer(DeerID);
  866.  
  867.  
  868.  
  869.  
  870. }
  871. else MovingDeer(DeerID);
  872.  
  873.  
  874.  
  875.  
  876. }
  877. return 1;
  878. }
  879.  
  880. stock IsPosInDeerZone(Float:X,Float:Y)//Areas where the deers can walk/run ; they will not exit them. It is easy to add some areas : take the coords Xmax, Xmin, Ymax and Ymin of the area, and you are done. Note : These zones are around Los Santos, there are none around LV or SF so just add some if you want to.
  881. {
  882. if(X>-1590.561645&&X<-395.603057&&Y<-816.069274&&Y>-1717.792480) return 1;
  883. else if(X>-689.845947&&X<197.757766&&Y<138.800338&&Y>-258.169403) return 1;
  884. else if(X>567.683715&&X<1504.512084&&Y<376.543304&&Y>-37.922641) return 1;
  885. else if(X>1787.830322&&X<2753.750976&&Y<-310.041870&&Y>-954.100341) return 1;
  886. else if(X>-2527.260498&&X<-1637.774780&&Y<-1732.938232&&Y>-2647.622802) return 1;
  887. else return 0;
  888. }
  889.  
  890. public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
  891. {
  892. if (GetPlayerState(playerid)==1)
  893.  
  894.  
  895. {
  896. if(GetPlayerWeapon(playerid)==4||GetPlayerWeapon(playerid)==8||GetPlayerWeapon(playerid)==9)
  897.  
  898.  
  899.  
  900. {
  901. //Knive, katana, chainsaw
  902. if(HOLDING(KEY_FIRE))
  903.  
  904.  
  905.  
  906. {
  907. for(new i=0;i<MAX_ANIM;i++)
  908.  
  909.  
  910.  
  911. {
  912. new Float:xd,Float:yd,Float:zd;
  913. GetDynamicObjectPos(DeerObject[i],xd,yd,zd);
  914. if(IsPlayerInRangeOfPoint(playerid,3,xd,yd,zd))
  915.  
  916.  
  917.  
  918. {
  919. if(IsPlayerAimingPoint(playerid,xd,yd,zd,5,3))
  920.  
  921.  
  922.  
  923. {
  924. if(DeerMeat[i]>0&&InfectedDeer[i]==0)
  925.  
  926.  
  927.  
  928. {
  929. if(DeerKO[i]==0)
  930.  
  931.  
  932.  
  933. {
  934. new Float:X,Float:Y,Float:Z,Float:rx,Float:ry,Float:rz;
  935. GetDynamicObjectPos(DeerObject[i],X,Y,Z);
  936. GetDynamicObjectRot(DeerObject[i],rx,ry,rz);
  937. MoveDynamicObject(DeerObject[i],X,Y,Z,90,ry,0);
  938. DeerKO[i]=1;
  939.  
  940.  
  941.  
  942.  
  943. }
  944. else
  945.  
  946.  
  947.  
  948. {
  949. LoopingAnim(playerid,"BOMBER","BOM_Plant_Loop",4,1,1,1,0,DeerMeat[i]*1000);
  950. GameTextForPlayer(playerid,"Picking up the meat...",3000,6);
  951. if(MeatPick[playerid]==0)
  952.  
  953.  
  954. {
  955. SetTimerEx("FinDeer",1000+random(3000),false,"ii",i,playerid);
  956. MeatPick[playerid]=1;
  957.  
  958.  
  959.  
  960. }
  961.  
  962.  
  963.  
  964. }
  965.  
  966.  
  967.  
  968.  
  969. }
  970. else
  971.  
  972.  
  973.  
  974. {
  975. DestroyDeer(i);
  976. SendClientMessage(playerid,COLOR_GREEN,"You could not find any edible meat on this animal.");
  977. new rand=random(DEER_SPAWN_LOC);//if you've added any spawn locations, replace the 21
  978. new Float:X=DeerSpawn[rand][0];
  979. new Float:Y=DeerSpawn[rand][1];
  980. CreateDeer(X,Y);
  981.  
  982.  
  983.  
  984.  
  985. }
  986.  
  987.  
  988.  
  989.  
  990. }
  991.  
  992.  
  993.  
  994.  
  995. }
  996.  
  997.  
  998.  
  999.  
  1000. }
  1001.  
  1002.  
  1003.  
  1004.  
  1005. }
  1006.  
  1007.  
  1008.  
  1009. }
  1010.  
  1011.  
  1012. }
  1013. return 1;
  1014. }
  1015.  
  1016. public FinDeer(DeerID,playerid)
  1017. {
  1018. new str[128];
  1019. PlayerInfo[playerid][Viande]+=DeerMeat[DeerID];//Add this variable to the PlayerInfo. 'viande' means 'meat' FYI ;)
  1020. MeatPick[playerid]=0;
  1021. format(str,sizeof(str),"You picked up %d kg of meat.",DeerMeat[DeerID]);
  1022. DestroyDeer(DeerID);
  1023. SendClientMessage(playerid,COLOR_GREEN,str);
  1024. format(str,sizeof(str),"You are carrying %d kg of meat.",PlayerInfo[playerid][Viande]);
  1025. SendClientMessage(playerid,COLOR_GREEN,str);
  1026. new rand=random(DEER_SPAWN_LOC);//Replace the 21 if you've added locations...
  1027. new Float:X=DeerSpawn[rand][0];
  1028. new Float:Y=DeerSpawn[rand][1];
  1029. CreateDeer(X,Y);
  1030. return 1;
  1031. }
  1032.  
  1033. public OnDynamicObjectMoved(objectid)
  1034. {
  1035. for(new i=0;i<MAX_ANIM;i++)
  1036.  
  1037.  
  1038.  
  1039. {
  1040. if(IsValidDynamicObject(DeerObject[i]))
  1041.  
  1042.  
  1043.  
  1044. {
  1045. DeerMove[i]=0;
  1046.  
  1047. }
  1048.  
  1049. }
  1050. return 1;
  1051. }
  1052.  
  1053. public OnPlayerVehicleDamage(playerid,vehicleid,Float:Damage)
  1054. {
  1055. for(new i=0;i<MAX_ANIM;i++)
  1056. {
  1057. new Float:xd,Float:yd,Float:zd;
  1058. GetDynamicObjectPos(DeerObject[i],xd,yd,zd);
  1059. if(IsPlayerInRangeOfPoint(playerid,5,xd,yd,zd))
  1060. {
  1061. new Float:rx,Float:ry,Float:rz;
  1062. GetDynamicObjectRot(DeerObject[i],rx,ry,rz);
  1063. GetPointZPos(xd,yd,zd);
  1064. MoveDynamicObject(DeerObject[i],xd+0.1,yd,zd+0.15,0.3,90,0,rz);
  1065. DeerMeat[i]-=4;
  1066. DeerKO[i]=1;
  1067.  
  1068. }
  1069. }
  1070. return 1;
  1071. }
  1072.  
  1073. OnePlayAnim(playerid,animlib[],animname[], Float:Speed, looping, lockx, locky, lockz, lp)
  1074. {
  1075. ApplyAnimation(playerid, animlib, animname, Speed, looping, lockx, locky, lockz, lp,1);
  1076. }
  1077.  
  1078. LoopingAnim(playerid,animlib[],animname[], Float:Speed, looping, lockx, locky, lockz, lp)
  1079. {
  1080. gPlayerUsingLoopingAnim[playerid] = 1;
  1081. ApplyAnimation(playerid, animlib, animname, Speed, looping, lockx, locky, lockz, lp,1);
  1082. }
Advertisement
Add Comment
Please, Sign In to add comment