Advertisement
FlacoBey

Untitled

Jul 4th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.24 KB | None | 0 0
  1. /*=======================================================================================
  2.     Plugin Info:
  3.  
  4. *   Name    :   [L4D2 & L4D] Airdop
  5. *   Author  :   BHaType
  6. *   Descrp  :   Admin can call airdrop.
  7. *   Link    :   https://forums.alliedmods.net/showthread.php?t=317108
  8. *   Plugins :   https://www.sourcemod.net/plugins.php?cat=0&mod=6&title=&author=BHaType&description=&search=1
  9.  
  10. ========================================================================================
  11.     Change Log:
  12.  
  13. v1.0 (4 - 07 - 19)
  14.     - Added cvar & command
  15.     - Update by Aya Supay
  16.     - Thanks Aya Supay for adding support different languages and support l4d1 also vocalize for l4d1.
  17.  
  18. v0.9 (3 - 07 - 19)
  19.     - Full optimize
  20.     - Fixed memory leak
  21.     - Fixed weapon drop
  22.     - Removed cvar to change count of items for L4D2.
  23.  
  24. v0.8 (3 - 07 - 19)
  25.     - Removed cvar
  26.     - New system of spawn weapons
  27.  
  28. 0.7 (3 - 07 - 19)
  29.     - Fixed error (Which cause to crash the server)
  30.     - Thanks disawar1 for improve my code
  31.     - Added cvar to disable messages
  32.     - Added new system of chances
  33.     - Removed bad cvars
  34.     - Added config to setting a chances of weapons (data/weapon_chances.cfg)
  35.     - Fixed spawn weapons
  36.  
  37. 0.6 (29 - 06 - 19)
  38.     - Added module to create a triggers for airdrops (Need test)
  39.     - Fixed errors (Need tests)
  40.  
  41. 0.5 (29 - 06 - 19)
  42.     - Now you can use the parachute (Thanks Aya Supay for his model)
  43.     - Fixed some maps
  44.     - Added cvars
  45.     - New method for obtaining coordinates
  46.  
  47. 0.4 (27 - 06 - 19)
  48.     - Fixed ammo
  49.     - Added vocalize (Only for L4D2 survivors)
  50.     - Added flare (Thanks to Silver)
  51.     - Added a lot of cvars.
  52.     - Admin can choose which weapons should be in airdrop.
  53.     - Fixed error (String formatted incorrectly - parameter 2 (total 1))
  54.     - Fixed map c5m1
  55.  
  56. 0.3 (29 - 06 - 19)
  57.     - Added some cvars
  58.     - Added support l4d1
  59.     - Fixed ammo
  60.  
  61. 0.2 (28 - 06 - 19)
  62.     - Airdrop may fall when killing the tank with some chance
  63.  
  64. 0.1 (27 - 06 - 19)
  65.     - Initial release.
  66.  
  67. ========================================================================================
  68.  
  69.     This plugin was made using source code from the following plugins.
  70.     If I have used your code and not credited you, please let me know.
  71.  
  72. *   Thanks to "Silvers", "Aya Supay" for helping me made this plugin.
  73.     https://forums.alliedmods.net/showthread.php?t=317108
  74.  
  75. ======================================================================================*/
  76.  
  77. #pragma semicolon 1
  78. #pragma newdecls required
  79.  
  80. #include <sourcemod>
  81. #include <sdktools>
  82.  
  83. #define SOUND_PASS1         "animation/c130_flyby.wav"
  84. #define CONFIG_CHANCE       "data/weapon_chances.cfg"
  85.  
  86. #define PARTICLE_FLARE      "flare_burning"
  87. #define PARTICLE_FUSE       "weapon_pipebomb_fuse"
  88. #define SOUND_CRACKLE       "ambient/fire/fire_small_loop2.wav"
  89. #define MODEL_FLARE         "models/props_lighting/light_flares.mdl"
  90.  
  91. #define MAXLIST 26
  92. #define MAXENTITIES 128
  93.  
  94. // ====================================================================================================
  95. //                  VARIEBLES
  96. // ====================================================================================================
  97.  
  98. int gIndexCrate[2048+1], g_iFlares[2048+1][5], g_iParachute[2048+1];
  99. ConVar  cTankChance, cCountAirdrops, cTimeOpen, cUseString, cColorFlare, cFlare,  
  100.         cFlareLenght, cFlareAplha, cGlowRange, cVocalize, cCustomModel, cParachuteSpeed,
  101.         cMessages, cAirHeight;
  102. bool IsLeft4Dead2, gFlares[2048+1];
  103. Handle hTimer[2048];
  104.  
  105. public Plugin myinfo =
  106. {
  107.     name = "[L4D & L4D2] Airdrop",
  108.     author = "BHaType",
  109.     description = "Admin can call airdrop.",
  110.     version = "1.1",
  111.     url = "https://www.sourcemod.net/plugins.php?cat=0&mod=-1&title=&author=BHaType&description=&search=1"
  112. }
  113.  
  114. static const char gModeList[3][] =
  115. {
  116.     "models/props_vehicles/c130.mdl",
  117.     "models/props_crates/supply_crate02.mdl",
  118.     "models/props_crates/supply_crate02_gib1.mdl"
  119. };
  120.  
  121. static const char gItemsList[MAXLIST][] =
  122. {
  123.     "weapon_autoshotgun",       //0
  124.     "weapon_first_aid_kit",     //1
  125.     "weapon_pipe_bomb",         //2
  126.     "weapon_molotov",           //3
  127.     "weapon_rifle",             //4
  128.     "weapon_hunting_rifle",     //5
  129.     "weapon_pain_pills",        //6
  130.     "weapon_pistol",            //7
  131.     "weapon_adrenaline",        //8
  132.     "weapon_smg_mp5",           //9
  133.     "weapon_smg",               //10
  134.     "weapon_smg_silenced",      //11
  135.     "weapon_pumpshotgun",       //12
  136.     "weapon_shotgun_chrome",    //13
  137.     "weapon_rifle_m60",         //14
  138.     "weapon_shotgun_spas",      //15
  139.     "weapon_sniper_military",   //16
  140.     "weapon_rifle_ak47",        //17
  141.     "weapon_rifle_desert",      //18
  142.     "weapon_sniper_awp",        //19
  143.     "weapon_rifle_sg552",       //20
  144.     "weapon_sniper_scout",      //21
  145.     "weapon_grenade_launcher"//22
  146.     "weapon_pistol_magnum",     //23
  147.     "weapon_vomitjar",          //24
  148.     "weapon_defibrillator"      //25
  149. };
  150.  
  151. static int gItemsChances[MAXLIST] =
  152. {
  153.     0,
  154.     0,
  155.     0,
  156.     0,
  157.     0,
  158.     0,
  159.     0,
  160.     0,
  161.     0,
  162.     0,
  163.     0,
  164.     0,
  165.     0,
  166.     0,
  167.     0,
  168.     0,
  169.     0,
  170.     0,
  171.     0,
  172.     0,
  173.     0,
  174.     0,
  175.     0,
  176.     0,
  177.     0,
  178.     0
  179. };
  180.  
  181. static char gModelsItemsListL4D1[MAXLIST - 18][] =
  182. {
  183.     "models/w_models/weapons/w_autoshot_m4super.mdl",   //0
  184.     "models/w_models/weapons/w_eq_Medkit.mdl",          //1
  185.     "models/w_models/weapons/w_eq_pipebomb.mdl",        //2
  186.     "models/w_models/weapons/w_eq_molotov.mdl",         //3
  187.     "models/w_models/weapons/w_rifle_m16a2.mdl",        //4
  188.     "models/w_models/weapons/w_sniper_mini14.mdl",      //5
  189.     "models/w_models/weapons/w_eq_painpills.mdl",       //6
  190.     "models/w_models/weapons/w_pistol_a.mdl",           //7
  191. };
  192.  
  193. static const char gModelsItemsList[MAXLIST][] =
  194. {
  195.     "models/w_models/weapons/w_autoshot_m4super.mdl",   //0
  196.     "models/w_models/weapons/w_eq_Medkit.mdl",          //1
  197.     "models/w_models/weapons/w_eq_pipebomb.mdl",        //2
  198.     "models/w_models/weapons/w_eq_molotov.mdl",         //3
  199.     "models/w_models/weapons/w_rifle_m16a2.mdl",        //4
  200.     "models/w_models/weapons/w_sniper_mini14.mdl",      //5
  201.     "models/w_models/weapons/w_eq_painpills.mdl",       //6
  202.     "models/w_models/weapons/w_pistol_a.mdl",           //7
  203.     "models/w_models/weapons/w_eq_adrenaline.mdl",      //8
  204.     "models/w_models/weapons/w_smg_mp5.mdl",            //9
  205.     "models/w_models/weapons/w_smg_uzi.mdl",            //10
  206.     "models/w_models/weapons/w_smg_a.mdl",              //11
  207.     "models/w_models/weapons/w_shotgun.mdl",            //12
  208.     "models/w_models/weapons/w_pumpshotgun_a.mdl",      //13
  209.     "models/w_models/weapons/w_m60.mdl",                //14
  210.     "models/w_models/weapons/w_shotgun_spas.mdl",       //15
  211.     "models/w_models/weapons/w_sniper_military.mdl",    //16
  212.     "models/w_models/weapons/w_rifle_ak47.mdl",         //17
  213.     "models/w_models/weapons/w_desert_rifle.mdl",       //18
  214.     "models/w_models/weapons/w_sniper_awp.mdl",         //19
  215.     "models/w_models/weapons/w_rifle_sg552.mdl",        //20
  216.     "models/w_models/weapons/w_sniper_scout.mdl",       //21
  217.     "models/w_models/weapons/w_grenade_launcher.mdl",   //22
  218.     "models/w_models/weapons/w_desert_eagle.mdl",       //23
  219.     "models/w_models/weapons/w_eq_bile_flask.mdl",      //24
  220.     "models/w_models/weapons/w_eq_defibrillator.mdl"    //25
  221. };
  222.  
  223. static int gAmmoList[MAXLIST] =
  224. {
  225.     90,
  226.     -1,
  227.     -1,
  228.     -1,
  229.     360,
  230.     150,
  231.     -1,
  232.     -1,
  233.     -1,
  234.     650,
  235.     650,
  236.     650,
  237.     56,
  238.     56,
  239.     -1,
  240.     90,
  241.     180,
  242.     360,
  243.     360,
  244.     180,
  245.     360,
  246.     180,
  247.     30,
  248.     -1,
  249.     -1,
  250.     -1
  251. };
  252.  
  253. static char gStringTable[2][] =
  254. {
  255.     "flare_burning",
  256.     "weapon_pipebomb_fuse"
  257. };
  258.  
  259. // ====================================================================================================
  260. //                  NATIVES
  261. // ====================================================================================================
  262.  
  263. public int CallAirdrop_NAT(Handle plugin, int numParams)
  264. {
  265.     float vPos[3];
  266.     GetNativeArray(2, vPos, sizeof vPos);
  267.     AirPlane(GetNativeCell(1), vPos);
  268. }
  269.  
  270. // ====================================================================================================
  271. //                  PLUGIN INFO / START / END
  272. // ====================================================================================================
  273.  
  274. public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
  275. {
  276.     EngineVersion test = GetEngineVersion();
  277.     if (test == Engine_Left4Dead2) {
  278.         IsLeft4Dead2 = true;       
  279.     }
  280.     else if (test != Engine_Left4Dead) {
  281.         strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
  282.         return APLRes_SilentFailure;
  283.     }
  284.     CreateNative("Airdrop", CallAirdrop_NAT);
  285.     return APLRes_Success;
  286. }
  287.  
  288. public void OnPluginStart()
  289. {
  290.     LoadTranslations("l4d_airdrop.phrases"); // Aya Supay
  291.     RegAdminCmd("sm_ac130", CallAirdrop, ADMFLAG_ROOT);
  292.     RegAdminCmd("sm_reload_config", ReloadConfig, ADMFLAG_ROOT);
  293.     HookEvent("tank_killed", EventTank);
  294.     cFlare              =       CreateConVar("airdrop_flare"            ,   "1"         , "Flare on? //Fix"                                                 , FCVAR_NONE);
  295.     cColorFlare         =       CreateConVar("airdrop_flare_color"      ,   "25 25 255" , "Color flare //Fix"                                               , FCVAR_NONE);
  296.     cFlareLenght        =       CreateConVar("airdrop_flare_length"     ,   "75"        , "Length of smoker for flare //Fix"                                , FCVAR_NONE);
  297.     cFlareAplha         =       CreateConVar("airdrop_flare_alpha"      ,   "255"       , "Transparency of smoke //Fix"                                     , FCVAR_NONE);
  298.     cUseString          =       CreateConVar("airdrop_open_string"      ,   "Hehe boi"  , "Open string //Fix"                                               , FCVAR_NONE);
  299.     cTimeOpen           =       CreateConVar("airdrop_open_time"        ,   "2.5"       , "Open time //Fix"                                                 , FCVAR_NONE);
  300.     cCountAirdrops      =       CreateConVar("airdrop_count_airdrops"   ,   "3"         , "Count of airdrops //Fix"                                         , FCVAR_NONE);
  301.     cTankChance         =       CreateConVar("airdrop_tank_chance"      ,   "50"        , "Chace airdrop of tank //Fix"                                     , FCVAR_NONE);
  302.     cVocalize           =       CreateConVar("airdrop_vocalize_chance"  ,   "40"        , "Chance of vocalize (L4D2 only) //Fix"                            , FCVAR_NONE); 
  303.     cGlowRange          =       CreateConVar("airdrop_glow_range"       ,   "500"       , "Glow range of airdrops (L4D2 only) //Fix"                        , FCVAR_NONE);
  304.     cCustomModel        =       CreateConVar("airdrop_use_custom_model" ,   "0"         , "Use customs model or not(parachute) (Left 4 Dead 1 & 2) //Fix"   , FCVAR_NONE);
  305.     cParachuteSpeed     =       CreateConVar("airdrop_parachute_speed"  ,   "60.0"      , "Speed of crate (Need parachute) (Left 4 Dead 1 & 2) //Fix"       , FCVAR_NONE);
  306.     cMessages           =       CreateConVar("airdrop_enable_message"   ,   "1"         , "Enable messages? //Fix"                                              , FCVAR_NONE);
  307.     cAirHeight          =       CreateConVar("airdrop_height"           ,   "400"       , "Height of AC130 //Fix"                                                   , FCVAR_NONE);
  308.     AutoExecConfig(true, "Airdrop");
  309.     LoadPercents();
  310. }
  311.  
  312. public void OnMapStart()
  313. {
  314.     for (int i = 0; i < 3; i++)
  315.         PrecacheModel(gModeList[i], true);
  316.     int max = MAXLIST - 18;
  317.     if( IsLeft4Dead2 ) max = MAXLIST - 1;
  318.     for( int i = 0; i < max; i++ )
  319.     {
  320.         if( IsLeft4Dead2 )
  321.             PrecacheModel(gModelsItemsList[i], true);
  322.         else
  323.             PrecacheModel(gModelsItemsListL4D1[i], true);
  324.     }
  325.     PrecacheSound(SOUND_CRACKLE);
  326.     PrecacheModel(MODEL_FLARE);
  327.     if(GetConVarInt(cCustomModel))
  328.     {
  329.         if (!IsModelPrecached("models/props_crates/supply_crate02_custom.mdl")) PrecacheModel("models/props_crates/supply_crate02_custom.mdl", false);
  330.     }
  331.     for(int i = 0; i < 2; i++)
  332.         PrecacheParticle(gStringTable[i]);
  333. }
  334.  
  335. // ====================================================================================================
  336. //                  COMMANDS
  337. // ====================================================================================================
  338.  
  339. public Action CallAirdrop(int client, int args)
  340. {
  341.     float vPos[3];
  342.     AirPlane(client, vPos);
  343.     if(GetConVarInt(cMessages)) CPrintToChatAll("%t", "call_airdrop", client);
  344.     return Plugin_Handled;
  345. }
  346.  
  347. public Action ReloadConfig(int client, int args)
  348. {
  349.     LoadPercents();
  350.     return Plugin_Handled;
  351. }
  352.  
  353. // ====================================================================================================
  354. //                  EVENTS / CONFIG / PRECACHE
  355. // ====================================================================================================
  356.  
  357. public Action EventTank(Event event, const char[] name, bool dontbroadcast)
  358. {
  359.     if(GetRandomInt(1, 100) <= GetConVarInt(cTankChance)) // AK978
  360.     {
  361.         float vPos[3];
  362.         int client = GetClientOfUserId(event.GetInt("userid"));
  363.         AirPlane(client, vPos);
  364.     }
  365. }
  366.  
  367. void LoadPercents()
  368. {  
  369.     char sPath[PLATFORM_MAX_PATH];
  370.     BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_CHANCE);
  371.     KeyValues hFile = new KeyValues("drop_weapons");
  372.     if(!FileExists(sPath))
  373.     {
  374.         File hCfg = OpenFile(sPath, "w");
  375.         hCfg.WriteLine("");
  376.         delete hCfg;
  377.        
  378.         if(IsLeft4Dead2)
  379.         {
  380.             if(KvJumpToKey(hFile, "weapons", true))
  381.             {
  382.                 for( int i = 0; i < MAXLIST; i++ )
  383.                     hFile.SetNum(gItemsList[i], 0);
  384.                 hFile.Rewind();
  385.                 hFile.ExportToFile(sPath);
  386.             }
  387.         }
  388.         else
  389.         {
  390.             if(KvJumpToKey(hFile, "weapons_l4d1", true))
  391.             {
  392.                 for( int i = 0; i < MAXLIST - 18; i++ )
  393.                     hFile.SetNum(gItemsList[i], 0);
  394.                 hFile.Rewind();
  395.                 hFile.ExportToFile(sPath);
  396.             }
  397.         }
  398.         ReloadConfig(0, 0);
  399.     }
  400.     else
  401.     {
  402.         if(IsLeft4Dead2)
  403.         {
  404.             if(hFile.ImportFromFile(sPath))
  405.             {
  406.                 if(KvJumpToKey(hFile, "weapons", true))
  407.                     for( int i = 0; i < MAXLIST; i++ )
  408.                         gItemsChances[i] = hFile.GetNum(gItemsList[i]);
  409.             }
  410.         }
  411.         else
  412.         {
  413.             if(hFile.ImportFromFile(sPath))
  414.             {
  415.                 if(KvJumpToKey(hFile, "weapons_l4d1", true))
  416.                     for( int i = 0; i < MAXLIST - 18; i++ )
  417.                         gItemsChances[i] = hFile.GetNum(gItemsList[i]);
  418.             }
  419.         }
  420.     }
  421.     delete hFile;
  422. }
  423.  
  424. void PrecacheParticle(const char[] sEffectName)
  425. {
  426.     static int table = INVALID_STRING_TABLE;
  427.  
  428.     if( table == INVALID_STRING_TABLE )
  429.     {
  430.         table = FindStringTable("ParticleEffectNames");
  431.     }
  432.  
  433.     if( FindStringIndex(table, sEffectName) == INVALID_STRING_INDEX )
  434.     {
  435.         bool save = LockStringTables(false);
  436.         AddToStringTable(table, sEffectName);
  437.         LockStringTables(save);
  438.     }
  439. }
  440.  
  441. // ====================================================================================================
  442. //                  TIMERS
  443. // ====================================================================================================
  444.  
  445. public Action TimerDropAirDrop(Handle timer, any entity)
  446. {
  447.     entity = EntRefToEntIndex(entity);
  448.     if(entity != INVALID_ENT_REFERENCE)
  449.     {
  450.         float vPos[3];
  451.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  452.         CreateCrates(vPos);
  453.     }
  454. }
  455.  
  456. public Action tSetGravity(Handle timer, any entity)
  457. {
  458.     entity = EntRefToEntIndex(entity);
  459.     if(entity != INVALID_ENT_REFERENCE)
  460.     {
  461.         float vSpeed[3], vPos[3], vAng[3], vEndPos[3];
  462.         int iGravity;
  463.         char sColor[12];
  464.         vAng[0] = 89.0;
  465.         Handle hTrace;
  466.         vSpeed[2] = float(GetConVarInt(cParachuteSpeed)) * -1;
  467.         if(GetConVarInt(cCustomModel))
  468.             TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vSpeed);
  469.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  470.         hTrace = TR_TraceRayFilterEx(vPos, vAng, CONTENTS_SOLID, RayType_Infinite, TraceDontHitSelf, entity);
  471.         if(TR_DidHit(hTrace))
  472.         {
  473.             TR_GetEndPosition(vEndPos, hTrace);
  474.             float vDistance = GetVectorDistance(vPos, vEndPos);
  475.             if(vDistance < 15)
  476.             {
  477.                 if(GetConVarInt(cFlare))
  478.                 {
  479.                     GetConVarString(cColorFlare, sColor, sizeof sColor);
  480.                     vAng[0] = 0.0;
  481.                     vPos[0] += 25.0;
  482.                     vPos[2] -= 12.0;
  483.                     MakeFlare(entity, vAng, vPos, sColor, sColor);
  484.                     gFlares[entity] = true;
  485.                 }
  486.                 if(GetConVarInt(cCustomModel))
  487.                 {
  488.                     iGravity = EntRefToEntIndex(g_iParachute[entity]); 
  489.                     if(iGravity != INVALID_ENT_REFERENCE)
  490.                         AcceptEntityInput(iGravity, "kill");
  491.                 }
  492.                 hTimer[entity] = null;
  493.                 return Plugin_Stop;
  494.             }
  495.         }
  496.         delete hTrace;
  497.     }
  498.     return Plugin_Continue;
  499. }
  500.  
  501. // ====================================================================================================
  502. //                  MAIN SYSTEM / CREATE AC130 / CREATE CRATES / RANDOM WEAPONS
  503. // ====================================================================================================
  504.  
  505. void AirPlane(int client, float vPos[3])
  506. {
  507.     if(!client) return;
  508.     float vAng[3], vEndPos[3], direction[3];
  509.     vAng[0] = -89.00;
  510.     Handle hTrace;
  511.     if(vPos[0] == 0.0 && vPos[1] == 0.0 && vPos[2] == 0.0)
  512.     {
  513.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", vPos);
  514.         vPos[2] += 90;
  515.     }
  516.    
  517.     hTrace = TR_TraceRayFilterEx(vPos, vAng, CONTENTS_SOLID, RayType_Infinite, TraceDontHitSelf, client);
  518.     if(TR_DidHit(hTrace))
  519.     {
  520.         GetClientAbsAngles(client, vAng);
  521.         GetAngleVectors(vAng, direction, NULL_VECTOR, NULL_VECTOR);
  522.         TR_GetEndPosition(vEndPos, hTrace);
  523.         vEndPos[2] += GetConVarInt(cAirHeight);
  524.         int entity = CreateEntityByName("prop_dynamic_override");
  525.         DispatchKeyValue(entity, "targetname", "ac130");
  526.         DispatchKeyValue(entity, "disableshadows", "1");
  527.         DispatchKeyValue(entity, "model", gModeList[0]);
  528.         TeleportEntity(entity, vEndPos, vAng, NULL_VECTOR);
  529.         DispatchSpawn(entity);
  530.        
  531.         EmitSoundToAll(SOUND_PASS1, entity, SNDCHAN_AUTO, SNDLEVEL_HELICOPTER);
  532.         SetVariantString("airport_intro_flyby");
  533.         AcceptEntityInput(entity, "SetAnimation");
  534.         AcceptEntityInput(entity, "Enable");
  535.  
  536.         SetVariantString("OnUser1 !self:Kill::20.19:1");
  537.         AcceptEntityInput(entity, "AddOutput");
  538.         AcceptEntityInput(entity, "FireUser1");
  539.         CreateTimer(6.4, TimerDropAirDrop, EntIndexToEntRef(entity));
  540.         delete hTrace;
  541.     }
  542. }
  543.  
  544. void CreateCrates(float vPos[3])
  545. {
  546.     char sUseString[56], sTimeOpen[16];
  547.     int entity, iTrigger, iGravity, count;
  548.     float vAng[3];
  549.     vAng[0] = 89.0;
  550.    
  551.     GetConVarString(cUseString, sUseString, sizeof sUseString);
  552.     GetConVarString(cTimeOpen, sTimeOpen, sizeof sTimeOpen);
  553.        
  554.     count = GetConVarInt(cCountAirdrops);
  555.     for(int i; i < count; i++)
  556.     {
  557.         vPos[1] += GetRandomInt(-150, 150);
  558.         vPos[0] += GetRandomInt(-150, 150);
  559.         vPos[2] -= GetConVarInt(cAirHeight);
  560.         entity = CreateEntityByName("prop_physics_override");
  561.         DispatchKeyValue(entity, "targetname", "SupplyDrop");
  562.         DispatchKeyValueVector(entity, "origin", vPos);
  563.         SetEntityModel(entity, gModeList[1]);
  564.         DispatchKeyValue(entity, "StartGlowing", "1");
  565.         DispatchSpawn(entity);
  566.         if(GetConVarInt(cCustomModel))
  567.         {  
  568.             iGravity = CreateEntityByName("prop_dynamic_override");
  569.             SetEntityModel(iGravity, "models/props_crates/supply_crate02_custom.mdl");
  570.             TeleportEntity(iGravity, vPos, NULL_VECTOR, NULL_VECTOR);
  571.             DispatchSpawn(iGravity);
  572.             SetVariantString("!activator");
  573.             AcceptEntityInput(iGravity, "SetParent", entity);
  574.             g_iParachute[entity] = EntIndexToEntRef(iGravity);
  575.         }
  576.         if(GetConVarInt(cFlare) || GetConVarInt(cCustomModel))
  577.         {
  578.             for(int v = MaxClients; v < 2049; v++)
  579.             {
  580.                 if(hTimer[v] == null)
  581.                 {
  582.                     hTimer[v] = CreateTimer(0.1, tSetGravity, EntIndexToEntRef(entity), TIMER_REPEAT);
  583.                     break;
  584.                 }
  585.             }
  586.         }
  587.  
  588.         iTrigger = CreateEntityByName("func_button_timed");
  589.         DispatchKeyValueVector(iTrigger, "origin", vPos);
  590.         DispatchKeyValue(iTrigger, "use_string", sUseString);
  591.         DispatchKeyValue(iTrigger, "use_time", sTimeOpen);
  592.         DispatchKeyValue(iTrigger, "auto_disable", "1");
  593.         TeleportEntity(iTrigger, vPos, NULL_VECTOR, NULL_VECTOR);
  594.         DispatchSpawn(iTrigger);
  595.         ActivateEntity(iTrigger);
  596.            
  597.         SetEntPropVector(iTrigger, Prop_Send, "m_vecMins", view_as<float>({-225.0, -225.0, -225.0}));
  598.         SetEntPropVector(iTrigger, Prop_Send, "m_vecMaxs", view_as<float>({225.0, 225.0, 225.0}));
  599.         HookSingleEntityOutput(iTrigger, "OnTimeUp", OnTimeUp);
  600.         SetEntityModel(iTrigger, gModeList[2]);
  601.         SetEntityRenderMode(iTrigger, RENDER_NONE);
  602.         SetVariantString("!activator");
  603.         AcceptEntityInput(iTrigger, "SetParent", entity);
  604.         if(IsLeft4Dead2)
  605.         {
  606.             char sColor[16];
  607.             Format(sColor, sizeof sColor, "255 255 255");
  608.             SetEntProp(entity, Prop_Send, "m_nGlowRange", GetConVarInt(cGlowRange));
  609.             SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
  610.             SetEntProp(entity, Prop_Send, "m_glowColorOverride", GetColor(sColor));
  611.         }
  612.         SetEntProp(iTrigger, Prop_Data, "m_takedamage", 0, 1);
  613.         SetEntProp(entity, Prop_Data, "m_takedamage", 0, 1);
  614.         gIndexCrate[iTrigger] = EntIndexToEntRef(entity);
  615.     }
  616.     if(GetConVarInt(cMessages)) CPrintToChatAll("%t {white}%.2f %.2f %.2f", "airdrop_coordinates" , vPos[0], vPos[1], vPos[2]);
  617. }
  618.  
  619. public void OnTimeUp(const char[] output, int caller, int activator, float delay)
  620. {
  621.     if (activator > 0 && activator <= MaxClients && IsClientInGame(activator))
  622.     {
  623.         int entity, iGravity;
  624.         entity = gIndexCrate[caller];
  625.         if((entity = EntRefToEntIndex(entity)) != INVALID_ENT_REFERENCE)
  626.         {
  627.             if(hTimer[entity] != null)
  628.             {
  629.                 delete hTimer[entity];
  630.             }
  631.             if(GetConVarInt(cCustomModel))
  632.             {
  633.                 iGravity = EntRefToEntIndex(g_iParachute[entity]);
  634.                 if(iGravity != INVALID_ENT_REFERENCE)
  635.                 {
  636.                     AcceptEntityInput(iGravity, "kill");
  637.                 }
  638.             }
  639.             int OpenedCrate;
  640.             float vPos[3], vAng[3];
  641.             AcceptEntityInput(caller, "kill");
  642.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  643.             GetEntPropVector(entity, Prop_Send, "m_angRotation", vAng);
  644.             OpenedCrate = CreateEntityByName("prop_physics_override");
  645.             DispatchKeyValueVector(OpenedCrate, "origin", vPos);
  646.             DispatchKeyValueVector(OpenedCrate, "angles", vAng);
  647.             SetEntityModel(OpenedCrate, gModeList[2]);
  648.             DispatchSpawn(OpenedCrate);
  649.             AcceptEntityInput(entity, "kill");
  650.             if(IsLeft4Dead2)
  651.                 sRandomWeapon(false, vPos);
  652.             else
  653.                 sRandomWeapon(true, vPos);
  654.             for(int i = 0; i <= 4; i++)
  655.             {
  656.                 if(gFlares[entity])
  657.                 {
  658.                     int iFlare = EntRefToEntIndex(g_iFlares[entity][i]);
  659.                     if(iFlare != INVALID_ENT_REFERENCE)
  660.                         AcceptEntityInput(iFlare, "kill");
  661.                 }
  662.             }
  663.             for(int i = 1; i <= MaxClients; i++)
  664.                 if(IsClientInGame(i)) CPrintToChat(i, "%t", "open_airdrop", activator);
  665.             if(IsLeft4Dead2)
  666.                 Vocalize(activator, false);
  667.             else
  668.                 Vocalize(activator, true);
  669.         }
  670.     }
  671. }
  672.  
  673. void sRandomWeapon(bool l4d1, float vPos[3])
  674. {
  675.     int weapons, iChancesWeapons, SupplyItem;
  676.     float vAng[3];
  677.    
  678.     if (l4d1) weapons = MAXLIST - 18;
  679.     else weapons = MAXLIST - 1;
  680.     while (weapons-- > 0)
  681.     {
  682.         iChancesWeapons = GetRandomInt(1, 100);
  683.         if(iChancesWeapons <= gItemsChances[weapons])
  684.         {
  685.             SupplyItem = CreateEntityByName(gItemsList[weapons]);
  686.             TeleportEntity(SupplyItem, vPos, vAng, NULL_VECTOR);
  687.             DispatchSpawn(SupplyItem);
  688.             SetEntityModel(SupplyItem, gModelsItemsList[weapons]);
  689.             vPos[2] += 2.5;
  690.             vAng[1] = 90.0;
  691.             if(gAmmoList[weapons] != -1)
  692.                 SetEntProp(SupplyItem, Prop_Send, "m_iExtraPrimaryAmmo", gAmmoList[weapons], 4);
  693.         }
  694.     }
  695. }
  696.  
  697. // ====================================================================================================
  698. //                  MAKING FLARE / THANKS TO SILVERS && Aya Supay
  699. // ====================================================================================================
  700.  
  701. int MakeFlare(int client, float vAngles[3], float vOrigin[3], const char[] sColorL, const char[] sColorS)
  702. {
  703.     int entity;
  704.    
  705.     entity = CreateEntityByName("prop_dynamic");
  706.  
  707.     SetEntityModel(entity, MODEL_FLARE);
  708.     TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
  709.     DispatchSpawn(entity);
  710.    
  711.     g_iFlares[client][0] = EntIndexToEntRef(entity);
  712.     vOrigin[2] += 15.0;
  713.     entity = MakeLightDynamic(vOrigin, view_as<float>({ 90.0, 0.0, 0.0 }), sColorL, 255);
  714.     vOrigin[2] -= 15.0;
  715.    
  716.     g_iFlares[client][1] = EntIndexToEntRef(entity);
  717.     // Position particles / smoke
  718.     entity = 0;
  719.     vAngles[1] = GetRandomFloat(1.0, 360.0);
  720.     vAngles[0] = -80.0;
  721.     vOrigin[0] += (1.0 * (Cosine(DegToRad(vAngles[1]))));
  722.     vOrigin[1] += (1.5 * (Sine(DegToRad(vAngles[1]))));
  723.     vOrigin[2] += 1.0;
  724.  
  725.     // Flare particles
  726.     entity = DisplayParticle(PARTICLE_FLARE, vOrigin, vAngles);
  727.     g_iFlares[client][2] = EntIndexToEntRef(entity);
  728.    
  729.     // Fuse particles
  730.     entity = DisplayParticle(PARTICLE_FUSE, vOrigin, vAngles);
  731.     g_iFlares[client][3] = EntIndexToEntRef(entity);
  732.  
  733.     // Smoke
  734.     vAngles[0] = -85.0;
  735.     entity = MakeEnvSteam(vOrigin, vAngles, sColorS, GetConVarInt(cFlareAplha), GetConVarInt(cFlareLenght));
  736.     g_iFlares[client][4] = EntIndexToEntRef(entity);
  737.  
  738.     PlaySound(g_iFlares[entity][0]);
  739. }
  740.  
  741. int DisplayParticle(const char[] sParticle, const float vPos[3], const float vAng[3])
  742. {
  743.     int entity = CreateEntityByName("info_particle_system");
  744.     if( entity != -1 )
  745.     {
  746.         DispatchKeyValue(entity, "effect_name", sParticle);
  747.         TeleportEntity(entity, vPos, vAng, NULL_VECTOR);
  748.         DispatchSpawn(entity);
  749.         ActivateEntity(entity);
  750.         AcceptEntityInput(entity, "start");
  751.         return entity;
  752.     }
  753.     return 0;
  754. }
  755.  
  756. int MakeEnvSteam(const float vOrigin[3], const float vAngles[3], const char[] sColor, int iAlpha, int iLength)
  757. {
  758.     int entity = CreateEntityByName("env_steam");
  759.     char sTemp[5];
  760.     DispatchKeyValue(entity, "SpawnFlags", "1");
  761.     DispatchKeyValue(entity, "rendercolor", sColor);
  762.     DispatchKeyValue(entity, "SpreadSpeed", "1");
  763.     DispatchKeyValue(entity, "Speed", "15");
  764.     DispatchKeyValue(entity, "StartSize", "1");
  765.     DispatchKeyValue(entity, "EndSize", "3");
  766.     DispatchKeyValue(entity, "Rate", "10");
  767.     IntToString(iLength, sTemp, sizeof(sTemp));
  768.     DispatchKeyValue(entity, "JetLength", sTemp);
  769.     IntToString(iAlpha, sTemp, sizeof(sTemp));
  770.     DispatchKeyValue(entity, "renderamt", sTemp);
  771.     DispatchKeyValue(entity, "InitialState", "1");
  772.     DispatchKeyValueVector(entity, "origin", vOrigin);
  773.     DispatchKeyValueVector(entity, "angles", vAngles);
  774.     //TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
  775.     AcceptEntityInput(entity, "TurnOn");
  776.     DispatchSpawn(entity);
  777.     return entity;
  778. }
  779.  
  780. void PlaySound(int entity)
  781. {
  782.     EmitSoundToAll(SOUND_CRACKLE, entity, SNDCHAN_AUTO, SNDLEVEL_DISHWASHER, SND_SHOULDPAUSE, SNDVOL_NORMAL, SNDPITCH_HIGH, -1, NULL_VECTOR, NULL_VECTOR);
  783. }
  784.  
  785. int MakeLightDynamic(const float vOrigin[3], const float vAngles[3], const char[] sColor, int iDist)
  786. {
  787.     int entity = CreateEntityByName("light_dynamic");
  788.     char sTemp[16];
  789.     Format(sTemp, sizeof(sTemp), "6");
  790.     DispatchKeyValue(entity, "style", sTemp);
  791.     Format(sTemp, sizeof(sTemp), "%s 255", sColor);
  792.     DispatchKeyValue(entity, "_light", sTemp);
  793.     DispatchKeyValue(entity, "brightness", "1");
  794.     DispatchKeyValueFloat(entity, "spotlight_radius", 32.0);
  795.     DispatchKeyValueFloat(entity, "distance", float(iDist));
  796.     TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
  797.     DispatchSpawn(entity);
  798.     AcceptEntityInput(entity, "TurnOn");
  799.     return entity;
  800. }
  801.  
  802. // ====================================================================================================
  803. //                  VOCALIZE / THANKS TO SILVERS & Aya Supay
  804. // ====================================================================================================
  805.  
  806. static const char g_sVocalize[][] =
  807. {
  808.     "scenes/Coach/dlc1_c6m1_alarmdoor01.vcd",           //0
  809.     "scenes/Coach/dlc1_golfclub07.vcd",                 //1
  810.     "scenes/Coach/thanks02.vcd",                        //2
  811.     "scenes/Coach/reactionnegative02.vcd",              //3
  812.     "scenes/Coach/no02.vcd",                            //4
  813.     "scenes/Gambler/dlc1_c6m1_alarmdoor02.vcd",         //5
  814.     "scenes/Gambler/dlc1_c6m1_alarmdoor01.vcd",         //6
  815.     "scenes/Gambler/dlc1_c6m2_phase2jumpinwater02.vcd", //7
  816.     "scenes/Mechanic/dlc1_c6m3_finalebridgerun02.vcd",  //8
  817.     "scenes/Mechanic/dlc1_m6007.vcd",                   //9
  818.     "scenes/Producer/heardspecialc104.vcd",             //10
  819.     "scenes/Producer/hurrah01.vcd",                     //11
  820.     "scenes/Biker/thanks02.vcd",                        //12 l4d1
  821.     "scenes/Biker/reactionnegative02.vcd",              //13
  822.     "scenes/Biker/no02.vcd",                            //14
  823.     "scenes/Namvet/help01.vcd",                         //15
  824.     "scenes/Namvet/hurrah02.vcd",                       //16
  825.     "scenes/Namvet/look03.vcd",                         //17
  826.     "scenes/Manager/incoming01.vcd",                    //18
  827.     "scenes/Manager/hurrah01.vcd",                      //19
  828.     "scenes/TeenGirl/help01.vcd",                       //20
  829.     "scenes/TeenGirl/hurrah01.vcd",                     //21
  830. };
  831.  
  832. void Vocalize(int client, bool l4d1)
  833. {
  834.     if(GetRandomInt(1, 100) > GetConVarInt(cVocalize))
  835.         return;
  836.  
  837.     char sTemp[64];
  838.     GetEntPropString(client, Prop_Data, "m_ModelName", sTemp, 64);
  839.  
  840.     int random;
  841.     if(!l4d1)
  842.     {
  843.         if( sTemp[26] == 'c' )                          // c = Coach
  844.             random = GetRandomInt(0, 4);
  845.         else if( sTemp[26] == 'g' )                     // g = Gambler
  846.             random = GetRandomInt(5, 7);
  847.         else if( sTemp[26] == 'm' && sTemp[27] == 'e' ) // me = Mechanic
  848.             random = GetRandomInt(8, 9);
  849.         else if( sTemp[26] == 'p' )                     // p = Producer
  850.             random = GetRandomInt(10, 11);
  851.         else
  852.             return;
  853.     }
  854.     else
  855.     {
  856.         if( sTemp[26] == 'b' )                          // b = biker
  857.             random = GetRandomInt(12, 14);
  858.         else if( sTemp[26] == 'n' )                     // n = namvet
  859.             random = GetRandomInt(15, 17);
  860.         else if( sTemp[26] == 'm' && sTemp[27] == 'a' ) // m = manager
  861.             random = GetRandomInt(18, 19);
  862.         else if( sTemp[26] == 't' )                     // t = teengirl
  863.             random = GetRandomInt(20, 21);
  864.         else
  865.             return;
  866.     }
  867.     int entity = CreateEntityByName("instanced_scripted_scene");
  868.     DispatchKeyValue(entity, "SceneFile", g_sVocalize[random]);
  869.     DispatchSpawn(entity);
  870.     SetEntPropEnt(entity, Prop_Data, "m_hOwner", client);
  871.     ActivateEntity(entity);
  872.     AcceptEntityInput(entity, "Start", client, client);
  873. }
  874.  
  875. // ====================================================================================================
  876. //                  TRACE FILTERS / GET COLOR
  877. // ====================================================================================================
  878.  
  879. public bool TraceFilter(int entity, int contentsMask)
  880. {
  881.     return entity > MaxClients;
  882. }
  883.  
  884. public bool TraceDontHitSelf(int entity, int mask, any data)
  885. {
  886.     if(entity == data || IsValidEntity(entity))
  887.     {
  888.         return false;
  889.     }
  890.     return true;
  891. }
  892.  
  893. int GetColor(char[] sTemp)
  894. {
  895.     if(strcmp(sTemp, "") == 0)
  896.         return 0;
  897.  
  898.     char sColors[3][4];
  899.     int color = ExplodeString(sTemp, " ", sColors, 3, 4);
  900.  
  901.     if( color != 3 )
  902.         return 0;
  903.  
  904.     color = StringToInt(sColors[0]);
  905.     color += 256 * StringToInt(sColors[1]);
  906.     color += 65536 * StringToInt(sColors[2]);
  907.  
  908.     return color;
  909. }
  910.  
  911. // ====================================================================================================
  912. //                  THANKS Aya Supay
  913. // ====================================================================================================
  914.  
  915. /**
  916. *   @note Used for in-line string translation.
  917. *
  918. *   @param  iClient     Client Index, translation is apllied to.
  919. *   @param  format      String formatting rules. By default, you should pass at least "%t" specifier.
  920. *   @param  ...            Variable number of format parameters.
  921. *   @return char[192]    Resulting string. Note: output buffer is hardly limited.
  922. */
  923. stock char[] Translate(int iClient, const char[] format, any ...)
  924. {
  925.     char buffer[192];
  926.     SetGlobalTransTarget(iClient);
  927.     VFormat(buffer, sizeof(buffer), format, 3);
  928.     return buffer;
  929. }
  930.  
  931. /**
  932. *   @note Prints a message to a specific client in the chat area. Supports named colors in translation file.
  933. *
  934. *   @param  iClient     Client Index.
  935. *   @param  format        Formatting rules.
  936. *   @param  ...            Variable number of format parameters.
  937. *   @no return
  938. */
  939. stock void CPrintToChat(int iClient, const char[] format, any ...)
  940. {
  941.     char buffer[192];
  942.     SetGlobalTransTarget(iClient);
  943.     VFormat(buffer, sizeof(buffer), format, 3);
  944.     ReplaceColor(buffer, sizeof(buffer));
  945.     PrintToChat(iClient, "\x01%s", buffer);
  946. }
  947.  
  948. /**
  949. *   @note Prints a message to all clients in the chat area. Supports named colors in translation file.
  950. *
  951. *   @param  format        Formatting rules.
  952. *   @param  ...            Variable number of format parameters.
  953. *   @no return
  954. */
  955. stock void CPrintToChatAll(const char[] format, any ...)
  956. {
  957.     char buffer[192];
  958.     for( int i = 1; i <= MaxClients; i++ )
  959.     {
  960.         if( IsClientInGame(i) && !IsFakeClient(i) )
  961.         {
  962.             SetGlobalTransTarget(i);
  963.             VFormat(buffer, sizeof(buffer), format, 2);
  964.             ReplaceColor(buffer, sizeof(buffer));
  965.             PrintToChat(i, "\x01%s", buffer);
  966.         }
  967.     }
  968. }
  969.  
  970. /**
  971. *   @note Converts named color to control character. Used internally by string translation functions.
  972. *
  973. *   @param  char[]        Input/Output string for convertion.
  974. *   @param  maxLen        Maximum length of string buffer (includes NULL terminator).
  975. *   @no return
  976. */
  977. stock void ReplaceColor(char[] message, int maxLen)
  978. {
  979.     ReplaceString(message, maxLen, "{white}", "\x01", false);
  980.     ReplaceString(message, maxLen, "{cyan}", "\x03", false);
  981.     ReplaceString(message, maxLen, "{orange}", "\x04", false);
  982.     ReplaceString(message, maxLen, "{green}", "\x05", false);
  983. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement