Advertisement
Guest User

Filterscript Dynamisches Fußgängersystem Kaliber

a guest
May 14th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.30 KB | None | 0 0
  1. /* Dynamisches Actors System
  2.  *
  3.  * (c) by Kaliber, 2016
  4.  *
  5.  */
  6. /******************************************************************************/
  7. #include <a_samp>
  8. //#define DEBUG
  9. /******************************************************************************/
  10. #undef MAX_ACTORS
  11. #define MAX_ACTORS 14
  12. /******************************************************************************/
  13. #undef INVALID_ACTOR_ID
  14. #define INVALID_ACTOR_ID -1
  15. /******************************************************************************/
  16. /*
  17. #define AC_SYNC_TIME 500
  18. #define AC_DISTANCE 0.83
  19. */
  20. #define AC_SYNC_TIME 1000
  21. #define AC_DISTANCE 1.66
  22. /******************************************************************************/
  23. #define AC_NONE 0
  24. #define AC_HANDSUP 1
  25. #define AC_WAITING 2
  26. #define AC_FALLING 3
  27. /******************************************************************************/
  28. #define SetAcPos(%0,%1,%2,%3,%4) SetActorPos(%0,%1,%2,%3),SetActorFacingAngle(%0,%4)
  29. #define GetActorDistanceFromPoint(%0,%1,%2,%3,%4,%5) VectorSize(%3-%0,%4-%1,%5-%2)
  30. #define private%0(%1) forward%0(%1);public%0(%1)
  31. /******************************************************************************/
  32. new afk[MAX_PLAYERS];
  33. /******************************************************************************/
  34. enum e_ac_en
  35. {
  36.     ac_id,
  37.     ac_skinid,
  38.     ac_anim,
  39.     Float:ac_x,
  40.     Float:ac_y,
  41.     Float:ac_z,
  42.     Float:ac_a,
  43.     Float:ac_dis,
  44.     bool:ac_dead,
  45.     bool:ac_idle,
  46.     ac_fall,
  47.     Float:tmp_a
  48. };
  49. static ac[MAX_ACTORS][e_ac_en],idx;
  50. #if defined DEBUG
  51. new MAX_TICK;
  52. #endif
  53. /******************************************************************************/
  54. public OnFilterScriptInit()
  55. {
  56.     ArrayReset();
  57.     /*
  58.     new Float:x=576.4655,Float:y=-1843.7554,Float:z=5.3193,Float:a=90.0;
  59.     new Float:r = 197.0196;
  60.    
  61.     for(new i; i<MAX_ACTORS; i++)
  62.     {
  63.         x += 3.0 * floatsin(-a,degrees);
  64.         y += 3.0 * floatcos(-a,degrees);
  65.         AddActor(i+1, x,y,z,r, 200.0);
  66.     }*/
  67.    
  68.    
  69.     AddActor(299, 576.4655,-1843.7554,5.3193,197.0196, 85.0);
  70.     AddActor(71, 1538.1409,-1717.8879,13.5469,359.0834, 85.0);
  71.     AddActor(3, 1518.6150,-1718.3677,13.5469,359.0834, 100.0);
  72.     AddActor(5, 1522.4823,-1602.5697,13.5469,178.6251, 100.0);
  73.     AddActor(29, 1515.9862,-1602.1107,13.5469,89.0109, 100.0);
  74.     AddActor(28, 1558.6401,-1584.7422,13.5469,89.9509, 150.0);
  75.     AddActor(90, 1558.5651,-1741.4337,13.5469,89.9977, 150.0);
  76.     AddActor(26, 1400.4346,-1742.8225,13.5469,270.1660, 150.0);
  77.     AddActor(28, 1421.0386,-1724.4557,13.5469,359.9908, 85.0);
  78.     AddActor(37,1517.3633,-1724.8729,13.5469,88.7356, 125.0);
  79.     AddActor(60,1438.5665,-1721.0585,13.5469,269.8440, 125.0);
  80.     AddActor(93,1438.8174,-1718.9680,13.5469,358.8315, 125.0);
  81.     AddActor(152,1473.2579,-1716.9049,14.0469,357.5782, 40.0);
  82.     AddActor(154,1484.5299,-1675.6349,14.0469,179.9632, 40.0);
  83.     printf("\t* Actor System loaded (%d).",idx);
  84.     SetTimer(!"Global_AC_Update",AC_SYNC_TIME,1);
  85.     return 1;
  86. }
  87. public OnActorStreamIn(actorid, forplayerid)
  88. {
  89.     PreloadActorAnims(actorid);
  90.     return 1;
  91. }
  92. public OnFilterScriptExit()
  93. {
  94.     for(new i; i<sizeof(ac); i++)
  95.     {
  96.         if(ac[i][ac_id] == -1) continue;
  97.         DestroyActor(ac[i][ac_id]);
  98.     }
  99.     print(!"\t* Actor System unloaded.");
  100.     return 1;
  101. }
  102. public OnPlayerGiveDamageActor(playerid, damaged_actorid, Float: amount, weaponid, bodypart)
  103. {
  104.     new Float:h;
  105.     if(amount >= 100) amount -= 100.0;
  106.     GetActorHealth(damaged_actorid,h);
  107.     if(floatsub(h,amount) <= 0)
  108.     {
  109.         OnActorDeath(GetAcIndex(damaged_actorid), playerid, floatsub(h,amount));
  110.     }
  111.     else
  112.     {
  113.         SetActorHealth(damaged_actorid,floatsub(h,amount));
  114.         new i = GetAcIndex(damaged_actorid);
  115.         if(ac[i][ac_anim] == AC_NONE && !ac[i][ac_dead])
  116.         {
  117.             ApplyActorAnimation(ac[i][ac_id],!"ped",!"WALK_civi",4.1,1,1,1,0,0);
  118.         }
  119.     }
  120.     return 1;
  121. }
  122. /******************************************************************************/
  123. static @re_idle(i);@re_idle(i) return ac[i][ac_idle] = false;
  124. /******************************************************************************/
  125. private Global_AC_Update()
  126. {
  127.     #if defined DEBUG
  128.     new t = GetTickCount();
  129.     #endif
  130.     new bool:re_sync;
  131.     static Float:x,Float:y,Float:z,Float:a,id,re_counter;
  132.     if(++re_counter >= 2) re_sync=true;
  133.     for(new i=GetPlayerPoolSize(); i!=-1; i--) {
  134.         if(gettime() > afk[i]+2) {
  135.             if(GetPlayerVirtualWorld(i) != 999) SetPVarInt(i,!"old_v_world",GetPlayerVirtualWorld(i)),GetPlayerPos(i,x,y,z),SetPlayerVirtualWorld(i,999),SetPVarFloat(i,!"old_x_p_ac",x),SetPVarFloat(i,!"old_y_p_ac",y),SetPVarFloat(i,!"old_z_p_ac",z),SetPlayerPos(i,3000,3000,0);
  136.         }
  137.         else {
  138.             if(GetPlayerVirtualWorld(i) == 999) SetPlayerVirtualWorld(i,GetPVarInt(i,!"old_v_world")),SetPlayerPos(i,GetPVarFloat(i,!"old_x_p_ac"),GetPVarFloat(i,!"old_y_p_ac"),GetPVarFloat(i,!"old_z_p_ac")),DeletePVar(i,!"old_x_p_ac"),DeletePVar(i,!"old_y_p_ac"),DeletePVar(i,!"old_z_p_ac"),DeletePVar(i,!"old_v_world");
  139.         }
  140.     }
  141.     for(new i; i<sizeof(ac); i++)
  142.     {
  143.         if(ac[i][ac_dead]) continue;
  144.         id=ac[i][ac_id];
  145.         /*if(ac[i][ac_fall])
  146.         {
  147.             if(re_sync) ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
  148.             if(++ac[i][ac_fall] == 300)
  149.             {
  150.                 SetActorFacingAngle(id,ac[i][ac_a]);
  151.                 ac[i][ac_fall] = (CheckForCar(x,y,z,3.0)) ? 1 : 0;
  152.             }
  153.             else continue;
  154.         }*/
  155.         GetActorPos(id,x,y,z),GetActorFacingAngle(id,a);
  156.         /*if(CheckForFall(x,y,z,ac[i][tmp_a]))
  157.         {
  158.             if(re_sync) ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
  159.             if(ac[i][ac_anim] == AC_FALLING) continue;
  160.             ac[i][ac_anim] = AC_FALLING;
  161.             ac[i][ac_fall] = 1;
  162.             SetActorFacingAngle(id,ac[i][tmp_a]);
  163.             ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
  164.             continue;
  165.         }*/
  166.         if(CheckForHandsUp(x,y,z))
  167.         {
  168.             if(re_sync) ApplyActorAnimation(id,!"SHOP",!"SHP_Rob_HandsUp",4.1,1,0,0,0,0);
  169.             if(ac[i][ac_anim] == AC_HANDSUP) continue;
  170.             ac[i][ac_anim] = AC_HANDSUP;
  171.             ApplyActorAnimation(id,!"SHOP",!"SHP_Rob_HandsUp",4.1,1,0,0,0,0);
  172.             continue;
  173.         }
  174.         if(CheckForCar(x,y,z,a,3.0))
  175.         {
  176.             if(re_sync) ApplyActorAnimation(id,!"COP_AMBIENT",!"Coplook_watch",4.1,1,0,0,0,0);
  177.             if(ac[i][ac_anim] == AC_WAITING) continue;
  178.             ac[i][ac_anim] = AC_WAITING;
  179.             ApplyActorAnimation(id,!"COP_AMBIENT",!"Coplook_watch",4.1,1,0,0,0,0);
  180.             continue;
  181.         }
  182.         if(ac[i][ac_anim] != AC_NONE)
  183.         {
  184.             ac[i][ac_anim] = AC_NONE;
  185.             ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
  186.         }
  187.         if(re_sync) ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
  188.         x += AC_DISTANCE*floatsin(-a,degrees);
  189.         y += AC_DISTANCE*floatcos(-a,degrees);
  190.         SetActorPos(id,x,y,z);
  191.         if(ac[i][ac_idle]) continue;
  192.         if(GetActorDistanceFromPoint(x,y,z,ac[i][ac_x],ac[i][ac_y],ac[i][ac_z]) >= ac[i][ac_dis])
  193.         {
  194.             ac[i][ac_idle] = true;
  195.             new ang = (floatround(a)+180)%360;
  196.             SetActorFacingAngle(id,float(ang));
  197.             SetTimerEx(!"@re_idle",4999,0,!"i",i);
  198.         }
  199.         else if(GetActorDistanceFromPoint(x,y,z,ac[i][ac_x],ac[i][ac_y],ac[i][ac_z]) <= 5.0)
  200.         {
  201.             ac[i][ac_idle] = true;
  202.             SetActorFacingAngle(id,ac[i][ac_a]);
  203.             SetTimerEx(!"@re_idle",4999,0,!"i",i);
  204.         }
  205.     }
  206.     if(re_sync) re_counter=0;
  207.     #if defined DEBUG
  208.     t = GetTickCount()-t;
  209.     if(t > MAX_TICK) MAX_TICK = t;
  210.     static counter;
  211.     if(++counter == 100) printf("%d",MAX_TICK),counter=0;
  212.     #endif
  213.     return 1;
  214. }
  215. /******************************************************************************/
  216. public OnPlayerUpdate(playerid)
  217. {
  218.     afk[playerid] = gettime();
  219.     return 1;
  220. }
  221. /******************************************************************************/
  222. private OnActorDeath(i, killerid, Float:h)
  223. {
  224.     ac[i][ac_dead] = true;
  225.     ClearActorAnimations(ac[i][ac_id]);
  226.     SetActorHealth(ac[i][ac_id],h);
  227.     SetTimerEx(!"ReSpawnActor",999*20,0,!"i",i);
  228.     return 1;
  229. }
  230. private ReSpawnActor(i)
  231. {
  232.     ac[i][ac_dead]=false;
  233.     DestroyActor(ac[i][ac_id]);
  234.     ac[i][ac_id] = CreateActor(ac[i][ac_skinid],ac[i][ac_x],ac[i][ac_y],ac[i][ac_z],ac[i][ac_a]);
  235.     SetActorStats(ac[i][ac_id]);
  236.     return 1;
  237. }
  238. /******************************************************************************/
  239. stock static PreloadActorAnims(i)
  240. {
  241.     ApplyActorAnimation(i,!"ped",!"null",4.1,0,0,0,0,0);
  242.     ApplyActorAnimation(i,!"SHOP",!"null",4.1,0,0,0,0,0);
  243.     ApplyActorAnimation(i,!"COP_AMBIENT",!"null",4.1,0,0,0,0,0);
  244.     return 1;
  245. }
  246. stock static GetAcIndex(actorid)
  247. {
  248.     for(new i; i<sizeof(ac); i++)
  249.     {
  250.         if(ac[i][ac_id] == actorid) return i;
  251.     }
  252.     return INVALID_ACTOR_ID;
  253. }
  254. stock static AddActor(skinid,Float:x,Float:y,Float:z,Float:a,Float:dis)
  255. {
  256.     ac[idx][ac_id] = CreateActor(skinid,x,y,z,a);
  257.     ac[idx][ac_skinid] = skinid;
  258.     ac[idx][ac_x] = x;
  259.     ac[idx][ac_y] = y;
  260.     ac[idx][ac_z] = z;
  261.     ac[idx][ac_a] = a;
  262.     ac[idx][ac_dis] = dis;
  263.     SetActorStats(ac[idx++][ac_id]);
  264.     return 1;
  265. }
  266. stock static SetActorStats(id)
  267. {
  268.     ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
  269.     SetActorInvulnerable(id, false);
  270.     SetActorHealth(id, 100);
  271.     return 1;
  272. }
  273. stock static ArrayReset()
  274. {
  275.     for(new i; i<sizeof(ac); i++) ac[i][ac_id] = INVALID_ACTOR_ID;
  276.     return 1;
  277. }
  278. stock static WrongAnim(i)
  279. {
  280.     switch(GetPlayerAnimationIndex(i))
  281.     {
  282.         case 1167,1161: return 0;
  283.     }
  284.     return 1;
  285. }
  286. stock static CheckForHandsUp(Float:x,Float:y,Float:z)
  287. {
  288.     for(new i=GetPlayerPoolSize(); i != -1; i--)
  289.     {
  290.         if(!IsPlayerConnected(i) || IsPlayerNPC(i) || WrongAnim(i) || !IsPlayerInRangeOfPoint(i,10.0,x,y,z)) continue;
  291.         return 1;
  292.     }
  293.     return 0;
  294. }
  295. stock static GetVehicleSpeed(vehicleid)
  296. {
  297.     static Float:x,Float:y,Float:z;
  298.     GetVehicleVelocity(vehicleid, x,y,z);
  299.     return floatround(VectorSize(x,y,z) * 170.0);
  300. }
  301. stock static CheckForFall(Float:x,Float:y,Float:z,&Float:angle)
  302. {
  303.     for(new i=GetVehiclePoolSize(),Float:a,Float:l; i != 0; i--)
  304.     {
  305.         GetVehicleModelInfo(GetVehicleModel(i), VEHICLE_MODEL_INFO_SIZE, a, l, a);
  306.         if(GetVehicleSpeed(i) > 20 && GetVehicleDistanceFromPoint(i, x,y,z) <= floatadd(floatdiv(l,2),5))
  307.         {
  308.             return GetVehicleZAngle(i,angle),1;
  309.         }
  310.     }
  311.     return 0;
  312. }
  313. stock static CheckForCar(Float:x,Float:y,Float:z,Float:a,const Float:dis)
  314. {
  315.     x += 1.5 * floatsin(-a, degrees);
  316.     y += 1.5 * floatsin(-a, degrees);
  317.     for(new i=GetVehiclePoolSize(); i != 0; i--)
  318.     {
  319.         if(GetVehicleDistanceFromPoint(i, x,y,z) < dis) return 1;
  320.     }
  321.     return 0;
  322. }
  323. /******************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement