Advertisement
FlacoBey

Untitled

Jun 28th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.24 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sourcemod>
  5. #include <sdktools>
  6. #include <sdkhooks>
  7.  
  8. #define SOUND_PASS1         "animation/c130_flyby.wav"
  9.  
  10. #define MAXLIST 26
  11.  
  12. char sMap[56];
  13. int gIndexCrate[2048+1];
  14. ConVar cTankChance, cDropType, cCountItems, cCountAirdrops, cTimeOpen, cUseString, cParahute;
  15. bool IsLeft4Dead2;
  16.  
  17. public Plugin myinfo =
  18. {
  19.     name = "[L4D2] Airdrop",
  20.     author = "BHaType",
  21.     description = "Admin can call airdrop.",
  22.     version = "0.3",
  23.     url = "https://www.sourcemod.net/plugins.php?cat=0&mod=-1&title=&author=BHaType&description=&search=1"
  24. }
  25.  
  26. static const char gModeList[5][] =
  27. {
  28.     "models/props_vehicles/c130.mdl",
  29.     "models/props_crates/supply_crate02.mdl",
  30.     "models/props_crates/supply_crate02_gib1.mdl",
  31.     "models/props_junk/wood_crate001a.mdl",
  32.     "models/props_swamp/parachute01.mdl"
  33. };
  34.  
  35. static const char gItemsListL4D1[MAXLIST - 18][] =
  36. {
  37.     "weapon_autoshotgun",
  38.     "weapon_first_aid_kit",
  39.     "weapon_pipe_bomb",
  40.     "weapon_molotov",
  41.     "weapon_rifle",
  42.     "weapon_hunting_rifle",
  43.     "weapon_pain_pills",
  44.     "weapon_pistol"
  45. };
  46.  
  47. static const char gItemsList[MAXLIST][] =
  48. {
  49.     "weapon_autoshotgun", //0
  50.     "weapon_first_aid_kit",//1
  51.     "weapon_pipe_bomb",//2
  52.     "weapon_molotov",//3
  53.     "weapon_rifle",//4
  54.     "weapon_hunting_rifle",//5
  55.     "weapon_pain_pills",//6
  56.     "weapon_pistol",//7
  57.     "weapon_adrenaline",//8
  58.     "weapon_smg_mp5",//9
  59.     "weapon_smg",//10
  60.     "weapon_smg_silenced",//11
  61.     "weapon_pumpshotgun",//12
  62.     "weapon_shotgun_chrome",//13
  63.     "weapon_rifle_m60",//14
  64.     "weapon_shotgun_spas",//15
  65.     "weapon_sniper_military",//16
  66.     "weapon_rifle_ak47",//17
  67.     "weapon_rifle_desert",//18
  68.     "weapon_sniper_awp",//19
  69.     "weapon_rifle_sg552",//20
  70.     "weapon_sniper_scout",//21
  71.     "weapon_grenade_launcher",//22
  72.     "weapon_pistol_magnum",//23
  73.     "weapon_vomitjar",//24
  74.     "weapon_defibrillator"//25
  75. };
  76.  
  77. static const char gModelsItemsList[MAXLIST][] =
  78. {
  79.     "models/w_models/weapons/w_autoshot_m4super.mdl", //0
  80.     "models/w_models/weapons/w_eq_Medkit.mdl", //1
  81.     "models/w_models/weapons/w_eq_pipebomb.mdl", //2
  82.     "models/w_models/weapons/w_eq_molotov.mdl", //3
  83.     "models/w_models/weapons/w_rifle_m16a2.mdl", //4
  84.     "models/w_models/weapons/w_sniper_mini14.mdl", //5
  85.     "models/w_models/weapons/w_eq_painpills.mdl", //6
  86.     "models/w_models/weapons/w_pistol_a.mdl", //7
  87.     "models/w_models/weapons/w_eq_adrenaline.mdl", //8
  88.     "models/w_models/weapons/w_smg_mp5.mdl", //9
  89.     "models/w_models/weapons/w_smg_uzi.mdl", //10
  90.     "models/w_models/weapons/w_smg_a.mdl", //11
  91.     "models/w_models/weapons/w_shotgun.mdl", //12
  92.     "models/w_models/weapons/w_pumpshotgun_a.mdl", //13
  93.     "models/w_models/weapons/w_m60.mdl", //14
  94.     "models/w_models/weapons/w_shotgun_spas.mdl", //15
  95.     "models/w_models/weapons/w_sniper_military.mdl", //16
  96.     "models/w_models/weapons/w_rifle_ak47.mdl", //17
  97.     "models/w_models/weapons/w_desert_rifle.mdl", //18
  98.     "models/w_models/weapons/w_sniper_awp.mdl", //19
  99.     "models/w_models/weapons/w_rifle_sg552.mdl", //20
  100.     "models/w_models/weapons/w_sniper_scout.mdl", //21
  101.     "models/w_models/weapons/w_grenade_launcher.mdl", //22
  102.     "models/w_models/weapons/w_desert_eagle.mdl", //23
  103.     "models/w_models/weapons/w_eq_bile_flask.mdl", //24
  104.     "models/w_models/weapons/w_eq_defibrillator.mdl" //25
  105. };
  106.  
  107. static int gAmmoList[MAXLIST] =
  108. {
  109.     90,
  110.     -1,
  111.     -1,
  112.     -1,
  113.     360,
  114.     150,
  115.     -1,
  116.     -1,
  117.     -1,
  118.     650,
  119.     650,
  120.     650,
  121.     56,
  122.     56,
  123.     -1,
  124.     90,
  125.     180,
  126.     360,
  127.     360,
  128.     180,
  129.     360,
  130.     180,
  131.     30,
  132.     -1,
  133.     -1,
  134.     -1
  135. };
  136.  
  137. public void OnPluginStart()
  138. {
  139.     GetCurrentMap(sMap, sizeof sMap);
  140.     char sEngine[24];
  141.     GetGameFolderName(sEngine, sizeof(sEngine));
  142.     if (StrEqual(sEngine, "left4dead2", false))
  143.         IsLeft4Dead2 = true;
  144.    
  145.     RegAdminCmd("sm_ac130", CallAirdrop, ADMFLAG_ROOT);
  146.     //HookEvent("tank_spawn", EventTank);
  147.     HookEvent("tank_killed", EventTank);
  148.    
  149.     cParahute =         CreateConVar("airdrop_parachute",   "1", "Будет ли парашут у ящиков", FCVAR_NONE);
  150.     cUseString =        CreateConVar("airdrop_open_string",     "Hehe boi", "Что будет написано при открытии ящика", FCVAR_NONE);
  151.     cTimeOpen =         CreateConVar("airdrop_open_time",       "2.5", "Время открытия", FCVAR_NONE);
  152.     cCountAirdrops =    CreateConVar("airdrop_count_airdrops",  "3", "Кол-во ящиков", FCVAR_NONE);
  153.     cCountItems =       CreateConVar("airdrop_count_items",     "6", "Кол-во предметов из ящиков", FCVAR_NONE);
  154.     cDropType =         CreateConVar("airdrop_type_drop",       "1", "Разные предметы будут выпадать либо нет(Ставить 1, только если квар \"airdrop count items\" > 1)", FCVAR_NONE);
  155.     cTankChance =       CreateConVar("airdrop_tank_chance",     "50", "Шанс аирдропа при смерти танка", FCVAR_NONE);
  156.     AutoExecConfig(true, "Airdrop");
  157. }
  158.  
  159. public Action EventTank(Event event, const char[] name, bool dontbroadcast)
  160. {
  161.     if(GetRandomInt(1, 100) <= GetConVarInt(cTankChance))
  162.     {
  163.         int client = GetClientOfUserId(event.GetInt("userid"));
  164.         AirPlane(client);
  165.     }
  166. }
  167.  
  168. public void OnMapStart()
  169. {
  170.     PrecacheSound(SOUND_PASS1, true);
  171.     for (int i = 0; i < 5; i++)
  172.         PrecacheModel(gModeList[i], true);
  173.     for (int i = 0; i < MAXLIST - 1; i++)
  174.         PrecacheModel(gModelsItemsList[i], true);
  175. }
  176.  
  177. public Action CallAirdrop(int client, int args)
  178. {
  179.     AirPlane(client);
  180.     PrintToChatAll("\x04[Air] \x03%N \x04вызвал аирдроп", client);
  181. }
  182.  
  183. stock void AirPlane(int client)
  184. {
  185.     float vPos[3], vAng[3], direction;
  186.     GetEntPropVector(client, Prop_Send, "m_vecOrigin", vPos);
  187.     vPos[2] += 64;
  188.     GetEntPropVector(client, Prop_Send, "m_angRotation", vAng);
  189.     direction = vAng[1];
  190.    
  191.     float vSkybox[3];
  192.     vAng[0] = 0.0;
  193.     vAng[1] = direction;
  194.     vAng[2] = 0.0;
  195.    
  196.     GetEntPropVector(0, Prop_Data, "m_WorldMaxs", vSkybox);
  197.  
  198.     int entity = CreateEntityByName("prop_dynamic_override");
  199.     DispatchKeyValue(entity, "targetname", "ac130");
  200.     DispatchKeyValue(entity, "disableshadows", "1");
  201.     DispatchKeyValue(entity, "model", gModeList[0]);
  202.     DispatchSpawn(entity);
  203.     float height = vPos[2] + 1150.0;
  204.     if( height > vSkybox[2] - 200 )
  205.         vPos[2] = vSkybox[2] - 200;
  206.     else
  207.         vPos[2] = height;
  208.        
  209.     TeleportEntity(entity, vPos, vAng, NULL_VECTOR);
  210.     EmitSoundToAll(SOUND_PASS1, entity, SNDCHAN_AUTO, SNDLEVEL_HELICOPTER);
  211.     SetVariantString("airport_intro_flyby");
  212.     AcceptEntityInput(entity, "SetAnimation");
  213.     AcceptEntityInput(entity, "Enable");
  214.  
  215.     SetVariantString("OnUser1 !self:Kill::20.19:1");
  216.     AcceptEntityInput(entity, "AddOutput");
  217.     AcceptEntityInput(entity, "FireUser1");
  218.     CreateTimer(7.0, TimerDropAirDrop, EntIndexToEntRef(entity));
  219. }
  220.  
  221. public Action TimerDropAirDrop(Handle timer, any entity)
  222. {
  223.     entity = EntRefToEntIndex(entity);
  224.     if(entity != INVALID_ENT_REFERENCE)
  225.     {
  226.         float vPos[3];
  227.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  228.         CreateCrates(vPos);
  229.     }
  230. }
  231.  
  232. void CreateCrates(float vPos[3])
  233. {
  234.     char sUseString[16], sTimeOpen[16];
  235.     int entity, iTrigger, parachute, iGravity;
  236.     float vAng[3], vEndPos[3], vDistance, fTime;
  237.     vAng[0] = 89.0; vAng[1] = 0.0; vAng[2] = 0.0;
  238.     DataPack dPack;
  239.     GetConVarString(cUseString, sUseString, sizeof sUseString);
  240.     GetConVarString(cTimeOpen, sTimeOpen, sizeof sTimeOpen);
  241.     if(strcmp(sMap, "c5m1_waterfront") == 0)
  242.         vPos[2] -= 475.0;
  243.     for(int i = 0; i < GetConVarInt(cCountAirdrops); i++)
  244.     {
  245.         if(GetConVarInt(cParahute))
  246.         {
  247.             vPos[1] += GetRandomInt(-100, 100);
  248.             vPos[0] += GetRandomInt(-100, 100);
  249.         }
  250.         entity = CreateEntityByName("prop_physics_override");
  251.         DispatchKeyValue(entity, "targetname", "SupplyDrop");
  252.         DispatchKeyValueVector(entity, "origin", vPos);
  253.         if(IsLeft4Dead2)
  254.             SetEntityModel(entity, gModeList[1]);
  255.         else
  256.         {
  257.             DispatchKeyValue(entity, "StartGlowing", "1");
  258.             DispatchKeyValue(entity, "model", gModeList[3]);
  259.         }
  260.         DispatchSpawn(entity);
  261.        
  262.         if(GetConVarInt(cParahute))
  263.         {
  264.             parachute = CreateEntityByName("prop_dynamic_override");
  265.             DispatchKeyValue(parachute, "targetname", "SupplyDrop");
  266.             DispatchKeyValueVector(parachute, "origin", vPos);
  267.             SetEntityModel(parachute, gModeList[4]);
  268.             DispatchSpawn(parachute);
  269.             SetEntPropFloat(entity, Prop_Data, "m_flGravity", 0.1);
  270.             SetVariantString("!activator");
  271.             AcceptEntityInput(parachute, "SetParent", entity);
  272.            
  273.             iGravity = CreateEntityByName("tank_rock");
  274.             DispatchSpawn(iGravity);
  275.             ActivateEntity(iGravity);
  276.             SetEntityRenderMode(iGravity, RENDER_NONE);
  277.             SetEntityGravity(iGravity, 0.05);
  278.             TeleportEntity(iGravity, vPos, NULL_VECTOR, NULL_VECTOR);
  279.             SetVariantString("!activator");
  280.             AcceptEntityInput(entity, "SetParent", iGravity);
  281.             Handle hTrace = TR_TraceRayFilterEx(vPos, vAng, MASK_SHOT, RayType_Infinite, TraceDontHitSelf, entity);
  282.             if(TR_DidHit(hTrace))
  283.             {
  284.                 TR_GetEndPosition(vEndPos, hTrace);
  285.                 vDistance = GetVectorDistance(vPos, vEndPos);
  286.                 fTime = vDistance / 75.0;
  287.                 PrintToChatAll("EndPos %.4f", vEndPos);
  288.                 PrintToChatAll("Distance %.4f", vDistance);
  289.                 PrintToChatAll("ftime %.4f", fTime);
  290.                 CreateDataTimer(fTime, tToDelete, dPack, TIMER_DATA_HNDL_CLOSE);
  291.                 dPack.WriteCell(EntRefToEntIndex(parachute));
  292.                 dPack.WriteCell(EntRefToEntIndex(iGravity));
  293.                 dPack.WriteCell(EntRefToEntIndex(entity));
  294.             }
  295.         }
  296.         if(IsLeft4Dead2)
  297.         {
  298.             iTrigger = CreateEntityByName("func_button_timed");
  299.             DispatchKeyValueVector(iTrigger, "origin", vPos);
  300.             DispatchKeyValue(iTrigger, "use_string", sUseString);
  301.             DispatchKeyValue(iTrigger, "use_time", sTimeOpen);
  302.             DispatchKeyValue(iTrigger, "auto_disable", "1");
  303.             DispatchSpawn(iTrigger);
  304.             ActivateEntity(iTrigger);
  305.            
  306.             SetEntPropVector(iTrigger, Prop_Send, "m_vecMins", view_as<float>({-75.0, -75.0, -75.0}));
  307.             SetEntPropVector(iTrigger, Prop_Send, "m_vecMaxs", view_as<float>({75.0, 75.0, 75.0}));
  308.             HookSingleEntityOutput(iTrigger, "OnTimeUp", OnTimeUp);
  309.             SetEntityModel(iTrigger, gModeList[2]);
  310.             SetEntityRenderMode(iTrigger, RENDER_NONE);
  311.             SetVariantString("!activator");
  312.             AcceptEntityInput(iTrigger, "SetParent", entity);
  313.             char sColor[16];
  314.             Format(sColor, sizeof sColor, "255 255 255");
  315.             SetEntProp(entity, Prop_Send, "m_nGlowRange", 500);
  316.             SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
  317.             SetEntProp(entity, Prop_Send, "m_glowColorOverride", GetColor(sColor));
  318.             SetEntProp(iTrigger, Prop_Data, "m_takedamage", 0, 1);
  319.             SetEntProp(entity, Prop_Data, "m_takedamage", 0, 1);
  320.             gIndexCrate[iTrigger] = EntIndexToEntRef(entity);
  321.         }
  322.         else SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
  323.     }
  324.     //SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
  325.     PrintToChatAll("\x04[Air] \x03Аирдроп(ы) \x04упал(и) в примерных координатах \x05%.2f %.2f %.2f", vPos[0], vPos[1], vPos[2]);
  326. }
  327.  
  328. public Action tToDelete(Handle timer, DataPack dPack)
  329. {
  330.     ResetPack(dPack);
  331.     int parachute = EntRefToEntIndex(ReadPackCell(dPack));
  332.     int iGravity = EntRefToEntIndex(ReadPackCell(dPack));
  333.     int entity = EntRefToEntIndex(ReadPackCell(dPack));
  334.     if(parachute != INVALID_ENT_REFERENCE)
  335.     {
  336.         AcceptEntityInput(parachute, "kill");
  337.     }
  338.     else if(entity != INVALID_ENT_REFERENCE)
  339.     {
  340.         SetVariantString("!activator");
  341.         AcceptEntityInput(entity, "SetParent", 0);
  342.     }
  343.     else if(iGravity != INVALID_ENT_REFERENCE)
  344.     {
  345.         SetVariantString("!activator");
  346.         AcceptEntityInput(iGravity, "SetParent", 0);
  347.         AcceptEntityInput(iGravity, "kill");
  348.     }
  349. }
  350.  
  351. public bool TraceDontHitSelf(int entity, int mask, any data)
  352. {
  353.     if(entity == data)
  354.     {
  355.         return false;
  356.     }
  357.     return true;
  358. }
  359.  
  360. public void OnTimeUp(const char[] output, int caller, int activator, float delay)
  361. {
  362.     if (activator > 0 && IsClientInGame(activator))
  363.     {
  364.         int entity = gIndexCrate[caller];
  365.         if((entity = EntRefToEntIndex(entity)) != INVALID_ENT_REFERENCE)
  366.         {
  367.             int SupplyItem;
  368.             float vPos[3], vAng[3];
  369.             AcceptEntityInput(caller, "kill");
  370.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  371.             GetEntPropVector(entity, Prop_Send, "m_angRotation", vAng);
  372.             int OpenedCrate = CreateEntityByName("prop_physics_override");
  373.             DispatchKeyValueVector(OpenedCrate, "origin", vPos);
  374.             DispatchKeyValueVector(OpenedCrate, "angles", vAng);
  375.             SetEntityModel(OpenedCrate, gModeList[2]);
  376.             DispatchSpawn(OpenedCrate);
  377.             int RandomIntType = GetRandomInt(0, 24);
  378.             AcceptEntityInput(entity, "kill");
  379.             for(int i = 0; i <= GetConVarInt(cCountItems); i++)
  380.             {
  381.                 if(GetConVarInt(cDropType) != 1) SupplyItem = CreateEntityByName(gItemsList[RandomIntType]);
  382.                 else
  383.                 {
  384.                     if(IsLeft4Dead2) RandomIntType = GetRandomInt(0, 24);
  385.                     else RandomIntType = GetRandomInt(0, 8);
  386.                     SupplyItem = CreateEntityByName(gItemsList[RandomIntType]);
  387.                 }
  388.                 if(IsValidEntity(SupplyItem))
  389.                 {
  390.                     DispatchSpawn(SupplyItem);
  391.                     SetEntityModel(SupplyItem, gModelsItemsList[RandomIntType]);
  392.                     vPos[2] += 2.5;
  393.                     vAng[0] = 0.0;
  394.                     vAng[1] = 90.0;
  395.                     vAng[2] = 0.0;
  396.                     TeleportEntity(SupplyItem, vPos, vAng, NULL_VECTOR);
  397.                     if(gAmmoList[RandomIntType] != -1)
  398.                         SetEntProp(SupplyItem, Prop_Send, "m_iExtraPrimaryAmmo", gAmmoList[RandomIntType], 4);
  399.                 }
  400.             }
  401.             PrintToChatAll("\x04[Air] \x03%N \x04открыл аирдроп", activator);
  402.         }
  403.     }
  404. }
  405.  
  406. public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)  
  407. {
  408.     if(IsValidEntity(victim) && attacker > 0 && GetClientTeam(attacker) == 2)
  409.     {
  410.         float vPos[3];
  411.         char sModel[126];
  412.         int SupplyItem;
  413.         GetEntPropString(victim, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
  414.         if(strcmp(sModel, gModeList[3]) == 0)
  415.         {  
  416.             AcceptEntityInput(victim, "break");
  417.            
  418.             GetEntPropVector(victim, Prop_Send, "m_vecOrigin", vPos);
  419.             for(int v = 0; v < GetConVarInt(cCountItems); v++)
  420.             {
  421.                 int iInt = GetRandomInt(0, 7);
  422.                 if(GetConVarInt(cDropType) == 1) SupplyItem = CreateEntityByName(gItemsListL4D1[GetRandomInt(0, 7)]);
  423.                 else CreateEntityByName(gItemsListL4D1[iInt]);
  424.                 DispatchSpawn(SupplyItem);
  425.                 vPos[2] += 5.0;
  426.                 TeleportEntity(SupplyItem, vPos, NULL_VECTOR, NULL_VECTOR);
  427.             }
  428.             PrintToChatAll("\x04[Air] \x03%N \x04вскрыл аирдроп", attacker);
  429.         }
  430.     }
  431. }
  432.  
  433. int GetColor(char[] sTemp)
  434. {
  435.     if( StrEqual(sTemp, "") )
  436.         return 0;
  437.  
  438.     char sColors[3][4];
  439.     int color = ExplodeString(sTemp, " ", sColors, 3, 4);
  440.  
  441.     if( color != 3 )
  442.         return 0;
  443.  
  444.     color = StringToInt(sColors[0]);
  445.     color += 256 * StringToInt(sColors[1]);
  446.     color += 65536 * StringToInt(sColors[2]);
  447.  
  448.     return color;
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement