Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dynamisches Actors System
- *
- * (c) by Kaliber, 2016
- *
- */
- /******************************************************************************/
- #include <a_samp>
- //#define DEBUG
- /******************************************************************************/
- #undef MAX_ACTORS
- #define MAX_ACTORS 14
- /******************************************************************************/
- #undef INVALID_ACTOR_ID
- #define INVALID_ACTOR_ID -1
- /******************************************************************************/
- /*
- #define AC_SYNC_TIME 500
- #define AC_DISTANCE 0.83
- */
- #define AC_SYNC_TIME 1000
- #define AC_DISTANCE 1.66
- /******************************************************************************/
- #define AC_NONE 0
- #define AC_HANDSUP 1
- #define AC_WAITING 2
- #define AC_FALLING 3
- /******************************************************************************/
- #define SetAcPos(%0,%1,%2,%3,%4) SetActorPos(%0,%1,%2,%3),SetActorFacingAngle(%0,%4)
- #define GetActorDistanceFromPoint(%0,%1,%2,%3,%4,%5) VectorSize(%3-%0,%4-%1,%5-%2)
- #define private%0(%1) forward%0(%1);public%0(%1)
- /******************************************************************************/
- new afk[MAX_PLAYERS];
- /******************************************************************************/
- enum e_ac_en
- {
- ac_id,
- ac_skinid,
- ac_anim,
- Float:ac_x,
- Float:ac_y,
- Float:ac_z,
- Float:ac_a,
- Float:ac_dis,
- bool:ac_dead,
- bool:ac_idle,
- ac_fall,
- Float:tmp_a
- };
- static ac[MAX_ACTORS][e_ac_en],idx;
- #if defined DEBUG
- new MAX_TICK;
- #endif
- /******************************************************************************/
- public OnFilterScriptInit()
- {
- ArrayReset();
- /*
- new Float:x=576.4655,Float:y=-1843.7554,Float:z=5.3193,Float:a=90.0;
- new Float:r = 197.0196;
- for(new i; i<MAX_ACTORS; i++)
- {
- x += 3.0 * floatsin(-a,degrees);
- y += 3.0 * floatcos(-a,degrees);
- AddActor(i+1, x,y,z,r, 200.0);
- }*/
- AddActor(299, 576.4655,-1843.7554,5.3193,197.0196, 85.0);
- AddActor(71, 1538.1409,-1717.8879,13.5469,359.0834, 85.0);
- AddActor(3, 1518.6150,-1718.3677,13.5469,359.0834, 100.0);
- AddActor(5, 1522.4823,-1602.5697,13.5469,178.6251, 100.0);
- AddActor(29, 1515.9862,-1602.1107,13.5469,89.0109, 100.0);
- AddActor(28, 1558.6401,-1584.7422,13.5469,89.9509, 150.0);
- AddActor(90, 1558.5651,-1741.4337,13.5469,89.9977, 150.0);
- AddActor(26, 1400.4346,-1742.8225,13.5469,270.1660, 150.0);
- AddActor(28, 1421.0386,-1724.4557,13.5469,359.9908, 85.0);
- AddActor(37,1517.3633,-1724.8729,13.5469,88.7356, 125.0);
- AddActor(60,1438.5665,-1721.0585,13.5469,269.8440, 125.0);
- AddActor(93,1438.8174,-1718.9680,13.5469,358.8315, 125.0);
- AddActor(152,1473.2579,-1716.9049,14.0469,357.5782, 40.0);
- AddActor(154,1484.5299,-1675.6349,14.0469,179.9632, 40.0);
- printf("\t* Actor System loaded (%d).",idx);
- SetTimer(!"Global_AC_Update",AC_SYNC_TIME,1);
- return 1;
- }
- public OnActorStreamIn(actorid, forplayerid)
- {
- PreloadActorAnims(actorid);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i; i<sizeof(ac); i++)
- {
- if(ac[i][ac_id] == -1) continue;
- DestroyActor(ac[i][ac_id]);
- }
- print(!"\t* Actor System unloaded.");
- return 1;
- }
- public OnPlayerGiveDamageActor(playerid, damaged_actorid, Float: amount, weaponid, bodypart)
- {
- new Float:h;
- if(amount >= 100) amount -= 100.0;
- GetActorHealth(damaged_actorid,h);
- if(floatsub(h,amount) <= 0)
- {
- OnActorDeath(GetAcIndex(damaged_actorid), playerid, floatsub(h,amount));
- }
- else
- {
- SetActorHealth(damaged_actorid,floatsub(h,amount));
- new i = GetAcIndex(damaged_actorid);
- if(ac[i][ac_anim] == AC_NONE && !ac[i][ac_dead])
- {
- ApplyActorAnimation(ac[i][ac_id],!"ped",!"WALK_civi",4.1,1,1,1,0,0);
- }
- }
- return 1;
- }
- /******************************************************************************/
- static @re_idle(i);@re_idle(i) return ac[i][ac_idle] = false;
- /******************************************************************************/
- private Global_AC_Update()
- {
- #if defined DEBUG
- new t = GetTickCount();
- #endif
- new bool:re_sync;
- static Float:x,Float:y,Float:z,Float:a,id,re_counter;
- if(++re_counter >= 2) re_sync=true;
- for(new i=GetPlayerPoolSize(); i!=-1; i--) {
- if(gettime() > afk[i]+2) {
- 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);
- }
- else {
- 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");
- }
- }
- for(new i; i<sizeof(ac); i++)
- {
- if(ac[i][ac_dead]) continue;
- id=ac[i][ac_id];
- /*if(ac[i][ac_fall])
- {
- if(re_sync) ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
- if(++ac[i][ac_fall] == 300)
- {
- SetActorFacingAngle(id,ac[i][ac_a]);
- ac[i][ac_fall] = (CheckForCar(x,y,z,3.0)) ? 1 : 0;
- }
- else continue;
- }*/
- GetActorPos(id,x,y,z),GetActorFacingAngle(id,a);
- /*if(CheckForFall(x,y,z,ac[i][tmp_a]))
- {
- if(re_sync) ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
- if(ac[i][ac_anim] == AC_FALLING) continue;
- ac[i][ac_anim] = AC_FALLING;
- ac[i][ac_fall] = 1;
- SetActorFacingAngle(id,ac[i][tmp_a]);
- ApplyActorAnimation(id,!"ped",!"FLOOR_hit",4.1,0,0,0,0,0);
- continue;
- }*/
- if(CheckForHandsUp(x,y,z))
- {
- if(re_sync) ApplyActorAnimation(id,!"SHOP",!"SHP_Rob_HandsUp",4.1,1,0,0,0,0);
- if(ac[i][ac_anim] == AC_HANDSUP) continue;
- ac[i][ac_anim] = AC_HANDSUP;
- ApplyActorAnimation(id,!"SHOP",!"SHP_Rob_HandsUp",4.1,1,0,0,0,0);
- continue;
- }
- if(CheckForCar(x,y,z,a,3.0))
- {
- if(re_sync) ApplyActorAnimation(id,!"COP_AMBIENT",!"Coplook_watch",4.1,1,0,0,0,0);
- if(ac[i][ac_anim] == AC_WAITING) continue;
- ac[i][ac_anim] = AC_WAITING;
- ApplyActorAnimation(id,!"COP_AMBIENT",!"Coplook_watch",4.1,1,0,0,0,0);
- continue;
- }
- if(ac[i][ac_anim] != AC_NONE)
- {
- ac[i][ac_anim] = AC_NONE;
- ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
- }
- if(re_sync) ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
- x += AC_DISTANCE*floatsin(-a,degrees);
- y += AC_DISTANCE*floatcos(-a,degrees);
- SetActorPos(id,x,y,z);
- if(ac[i][ac_idle]) continue;
- if(GetActorDistanceFromPoint(x,y,z,ac[i][ac_x],ac[i][ac_y],ac[i][ac_z]) >= ac[i][ac_dis])
- {
- ac[i][ac_idle] = true;
- new ang = (floatround(a)+180)%360;
- SetActorFacingAngle(id,float(ang));
- SetTimerEx(!"@re_idle",4999,0,!"i",i);
- }
- else if(GetActorDistanceFromPoint(x,y,z,ac[i][ac_x],ac[i][ac_y],ac[i][ac_z]) <= 5.0)
- {
- ac[i][ac_idle] = true;
- SetActorFacingAngle(id,ac[i][ac_a]);
- SetTimerEx(!"@re_idle",4999,0,!"i",i);
- }
- }
- if(re_sync) re_counter=0;
- #if defined DEBUG
- t = GetTickCount()-t;
- if(t > MAX_TICK) MAX_TICK = t;
- static counter;
- if(++counter == 100) printf("%d",MAX_TICK),counter=0;
- #endif
- return 1;
- }
- /******************************************************************************/
- public OnPlayerUpdate(playerid)
- {
- afk[playerid] = gettime();
- return 1;
- }
- /******************************************************************************/
- private OnActorDeath(i, killerid, Float:h)
- {
- ac[i][ac_dead] = true;
- ClearActorAnimations(ac[i][ac_id]);
- SetActorHealth(ac[i][ac_id],h);
- SetTimerEx(!"ReSpawnActor",999*20,0,!"i",i);
- return 1;
- }
- private ReSpawnActor(i)
- {
- ac[i][ac_dead]=false;
- DestroyActor(ac[i][ac_id]);
- 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]);
- SetActorStats(ac[i][ac_id]);
- return 1;
- }
- /******************************************************************************/
- stock static PreloadActorAnims(i)
- {
- ApplyActorAnimation(i,!"ped",!"null",4.1,0,0,0,0,0);
- ApplyActorAnimation(i,!"SHOP",!"null",4.1,0,0,0,0,0);
- ApplyActorAnimation(i,!"COP_AMBIENT",!"null",4.1,0,0,0,0,0);
- return 1;
- }
- stock static GetAcIndex(actorid)
- {
- for(new i; i<sizeof(ac); i++)
- {
- if(ac[i][ac_id] == actorid) return i;
- }
- return INVALID_ACTOR_ID;
- }
- stock static AddActor(skinid,Float:x,Float:y,Float:z,Float:a,Float:dis)
- {
- ac[idx][ac_id] = CreateActor(skinid,x,y,z,a);
- ac[idx][ac_skinid] = skinid;
- ac[idx][ac_x] = x;
- ac[idx][ac_y] = y;
- ac[idx][ac_z] = z;
- ac[idx][ac_a] = a;
- ac[idx][ac_dis] = dis;
- SetActorStats(ac[idx++][ac_id]);
- return 1;
- }
- stock static SetActorStats(id)
- {
- ApplyActorAnimation(id,!"ped",!"WALK_civi",4.1,1,1,1,0,0);
- SetActorInvulnerable(id, false);
- SetActorHealth(id, 100);
- return 1;
- }
- stock static ArrayReset()
- {
- for(new i; i<sizeof(ac); i++) ac[i][ac_id] = INVALID_ACTOR_ID;
- return 1;
- }
- stock static WrongAnim(i)
- {
- switch(GetPlayerAnimationIndex(i))
- {
- case 1167,1161: return 0;
- }
- return 1;
- }
- stock static CheckForHandsUp(Float:x,Float:y,Float:z)
- {
- for(new i=GetPlayerPoolSize(); i != -1; i--)
- {
- if(!IsPlayerConnected(i) || IsPlayerNPC(i) || WrongAnim(i) || !IsPlayerInRangeOfPoint(i,10.0,x,y,z)) continue;
- return 1;
- }
- return 0;
- }
- stock static GetVehicleSpeed(vehicleid)
- {
- static Float:x,Float:y,Float:z;
- GetVehicleVelocity(vehicleid, x,y,z);
- return floatround(VectorSize(x,y,z) * 170.0);
- }
- stock static CheckForFall(Float:x,Float:y,Float:z,&Float:angle)
- {
- for(new i=GetVehiclePoolSize(),Float:a,Float:l; i != 0; i--)
- {
- GetVehicleModelInfo(GetVehicleModel(i), VEHICLE_MODEL_INFO_SIZE, a, l, a);
- if(GetVehicleSpeed(i) > 20 && GetVehicleDistanceFromPoint(i, x,y,z) <= floatadd(floatdiv(l,2),5))
- {
- return GetVehicleZAngle(i,angle),1;
- }
- }
- return 0;
- }
- stock static CheckForCar(Float:x,Float:y,Float:z,Float:a,const Float:dis)
- {
- x += 1.5 * floatsin(-a, degrees);
- y += 1.5 * floatsin(-a, degrees);
- for(new i=GetVehiclePoolSize(); i != 0; i--)
- {
- if(GetVehicleDistanceFromPoint(i, x,y,z) < dis) return 1;
- }
- return 0;
- }
- /******************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement