Advertisement
FlacoBey

Untitled

Jun 30th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.30 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 CHAT_TAG            "\x03[Airdrop] \x05"
  9. #define CONFIG_SPAWNS       "data/l4d2_airdrop.cfg"
  10.  
  11. #define MODEL_BOX           "models/props/cs_militia/silo_01.mdl"
  12. #define MAX_ENTITIES        14
  13.  
  14. Handle g_hTimerBeam[MAX_ENTITIES];
  15. int g_iHaloMaterial, g_iLaserMaterial, g_iMenuSelected[MAXPLAYERS+1], g_iTriggers[MAX_ENTITIES];
  16. bool g_bLoaded, g_bShow[MAX_ENTITIES];
  17. float g_fTargetAng[MAX_ENTITIES], g_vPosAirdrop[MAX_ENTITIES][3], g_vTargetZone[MAX_ENTITIES][3];
  18. Menu g_hMenuMain, g_hMenuPos, g_hMenuSetAirdrop, g_hMenuVMaxs, g_hMenuVMins;
  19.  
  20.  
  21. // ====================================================================================================
  22. //                  PLUGIN INFO / START / END
  23. // ====================================================================================================
  24. public Plugin myinfo =
  25. {
  26.     name = "[L4D2] Airdrop - Triggers",
  27.     author = "SilverShot",
  28.     description = "Creates AC130 bys which drop airdrop to where they were triggered from.",
  29.     version = "0.1",
  30.     url = "http://forums.alliedmods.net/showthread.php?t=187567"
  31. }
  32.  
  33. public void OnPluginStart()
  34. {
  35.     RegAdminCmd("sm_airdrop_triggers", CmdAirdropMenu, ADMFLAG_ROOT, "Displays a menu with options to show/save a airdrop and triggers.");
  36.     RegAdminCmd("t", cmdDebug, ADMFLAG_ROOT, "");
  37.    
  38.     g_hMenuVMaxs = new Menu(VMaxsMenuHandler);
  39.     g_hMenuVMaxs.AddItem("", "10 x 10 x 100");
  40.     g_hMenuVMaxs.AddItem("", "25 x 25 x 100");
  41.     g_hMenuVMaxs.AddItem("", "50 x 50 x 100");
  42.     g_hMenuVMaxs.AddItem("", "100 x 100 x 100");
  43.     g_hMenuVMaxs.AddItem("", "150 x 150 x 100");
  44.     g_hMenuVMaxs.AddItem("", "200 x 200 x 100");
  45.     g_hMenuVMaxs.AddItem("", "250 x 250 x 100");
  46.     g_hMenuVMaxs.SetTitle("Airdrop: Trigger - VMaxs");
  47.     g_hMenuVMaxs.ExitBackButton = true;
  48.  
  49.     g_hMenuVMins = new Menu(VMinsMenuHandler);
  50.     g_hMenuVMins.AddItem("", "-10 x -10 x 0");
  51.     g_hMenuVMins.AddItem("", "-25 x -25 x 0");
  52.     g_hMenuVMins.AddItem("", "-50 x -50 x 0");
  53.     g_hMenuVMins.AddItem("", "-100 x -100 x 0");
  54.     g_hMenuVMins.AddItem("", "-150 x -150 x 0");
  55.     g_hMenuVMins.AddItem("", "-200 x -200 x 0");
  56.     g_hMenuVMins.AddItem("", "-250 x -250 x 0");
  57.     g_hMenuVMins.SetTitle("Airdrop: Trigger - VMins");
  58.     g_hMenuVMins.ExitBackButton = true;
  59.  
  60.     g_hMenuPos = new Menu(PosMenuHandler);
  61.     g_hMenuPos.AddItem("", "X + 1.0");
  62.     g_hMenuPos.AddItem("", "Y + 1.0");
  63.     g_hMenuPos.AddItem("", "Z + 1.0");
  64.     g_hMenuPos.AddItem("", "X - 1.0");
  65.     g_hMenuPos.AddItem("", "Y - 1.0");
  66.     g_hMenuPos.AddItem("", "Z - 1.0");
  67.     g_hMenuPos.AddItem("", "SAVE");
  68.     g_hMenuPos.SetTitle("Airdrop: Trigger - Origin");
  69.     g_hMenuPos.ExitBackButton = true;
  70.    
  71.     g_hMenuSetAirdrop = new Menu(AirMenuHandler);
  72.     g_hMenuSetAirdrop.AddItem("", "Position");
  73.     g_hMenuSetAirdrop.AddItem("", "Crosshair");
  74.     g_hMenuSetAirdrop.SetTitle("Airdrop: Trigger - Origin - Auto Save");
  75.     g_hMenuSetAirdrop.ExitBackButton = true;
  76. }
  77.  
  78. public int AirMenuHandler(Menu menu, MenuAction action, int client, int index)
  79. {
  80.     if( action == MenuAction_Cancel )
  81.     {
  82.         if( index == MenuCancel_ExitBack )
  83.             ShowMenuMain(client);
  84.     }
  85.     else if( action == MenuAction_Select )
  86.     {
  87.         float vAng[3];
  88.         vAng[0] = -89.00; vAng[1] = 0.0; vAng[2] = 0.0;
  89.         Handle hTrace;
  90.         int cfgindex = g_iMenuSelected[client];
  91.         if(index == 0)
  92.         {
  93.             float vPos[3];
  94.             GetClientEyePosition(client, vPos);
  95.  
  96.             hTrace = TR_TraceRayFilterEx(vPos, vAng, CONTENTS_SOLID, RayType_Infinite, TraceDontHitSelf, client);
  97.  
  98.             if( TR_DidHit(hTrace) )
  99.             {
  100.                 float vEndPos[3];
  101.                 TR_GetEndPosition(vEndPos, hTrace);
  102.                 SaveTrigger(client, cfgindex, "airdrop", vEndPos);
  103.             }
  104.         }
  105.         else
  106.         {
  107.             float vPos[3];
  108.             GetClientEyePosition(client, vPos);
  109.             GetClientEyeAngles(client, vAng);
  110.  
  111.             hTrace = TR_TraceRayFilterEx(vPos, vAng, MASK_SHOT, RayType_Infinite, TraceFilter);
  112.             if( TR_DidHit(hTrace) )
  113.             {
  114.                 float vEndPos[3];
  115.                 TR_GetEndPosition(vEndPos, hTrace);
  116.                 delete hTrace;
  117.                 vAng[0] = -89.00; vAng[1] = 0.0; vAng[2] = 0.0;
  118.                 hTrace = TR_TraceRayFilterEx(vEndPos, vAng, MASK_SHOT, RayType_Infinite, TraceFilter);
  119.                 if( TR_DidHit(hTrace) )
  120.                 {
  121.                     TR_GetEndPosition(vEndPos, hTrace);
  122.                     SaveTrigger(client, cfgindex, "airdrop", vEndPos);
  123.                     PrintToChat(client, "%s Air drop position for Trigger [%i] has been set.", CHAT_TAG, cfgindex);
  124.                 }
  125.             }
  126.         }
  127.  
  128.         g_hMenuSetAirdrop.Display(client, MENU_TIME_FOREVER);
  129.     }
  130. }
  131.  
  132. public bool TraceFilter(int entity, int contentsMask)
  133. {
  134.     return entity > MaxClients;
  135. }
  136.  
  137. public bool TraceDontHitSelf(int entity, int mask, any data)
  138. {
  139.     if(entity == data || IsValidEntity(entity))
  140.     {
  141.         return false;
  142.     }
  143.     return true;
  144. }
  145.  
  146. public int VMaxsMenuHandler(Menu menu, MenuAction action, int client, int index)
  147. {
  148.     if( action == MenuAction_Cancel )
  149.     {
  150.         if( index == MenuCancel_ExitBack )
  151.             ShowMenuMain(client);
  152.     }
  153.     else if( action == MenuAction_Select )
  154.     {
  155.         float vVec[3];
  156.  
  157.         if( index == 0 )
  158.             vVec = view_as<float>({ 10.0, 10.0, 100.0 });
  159.         else if( index == 1 )
  160.             vVec = view_as<float>({ 25.0, 25.0, 100.0 });
  161.         else if( index == 2 )
  162.             vVec = view_as<float>({ 50.0, 50.0, 100.0 });
  163.         else if( index == 3 )
  164.             vVec = view_as<float>({ 100.0, 100.0, 100.0 });
  165.         else if( index == 4 )
  166.             vVec = view_as<float>({ 150.0, 150.0, 100.0 });
  167.         else if( index == 5 )
  168.             vVec = view_as<float>({ 200.0, 200.0, 100.0 });
  169.         else if( index == 6 )
  170.             vVec = view_as<float>({ 300.0, 300.0, 100.0 });
  171.  
  172.         int cfgindex = g_iMenuSelected[client];
  173.         int trigger = g_iTriggers[cfgindex];
  174.  
  175.         SaveTrigger(client, cfgindex + 1, "vmax", vVec);
  176.  
  177.         if( IsValidEntRef(trigger) )
  178.             SetEntPropVector(trigger, Prop_Send, "m_vecMaxs", vVec);
  179.  
  180.         g_hMenuVMaxs.Display(client, MENU_TIME_FOREVER);
  181.     }
  182. }
  183.  
  184. public int VMinsMenuHandler(Menu menu, MenuAction action, int client, int index)
  185. {
  186.     if( action == MenuAction_Cancel )
  187.     {
  188.         if( index == MenuCancel_ExitBack )
  189.             ShowMenuMain(client);
  190.     }
  191.     else if( action == MenuAction_Select )
  192.     {
  193.         float vVec[3];
  194.  
  195.         if( index == 0 )
  196.             vVec = view_as<float>({ -10.0, -10.0, -100.0 });
  197.         else if( index == 1 )
  198.             vVec = view_as<float>({ -25.0, -25.0, -100.0 });
  199.         else if( index == 2 )
  200.             vVec = view_as<float>({ -50.0, -50.0, -100.0 });
  201.         else if( index == 3 )
  202.             vVec = view_as<float>({ -100.0, -100.0, -100.0 });
  203.         else if( index == 4 )
  204.             vVec = view_as<float>({ -150.0, -150.0, -100.0 });
  205.         else if( index == 5 )
  206.             vVec = view_as<float>({ -200.0, -200.0, -100.0 });
  207.         else if( index == 6 )
  208.             vVec = view_as<float>({ -300.0, -300.0, -100.0 });
  209.  
  210.         int cfgindex = g_iMenuSelected[client];
  211.         int trigger = g_iTriggers[cfgindex];
  212.  
  213.         SaveTrigger(client, cfgindex + 1, "vmin", vVec);
  214.  
  215.         if( IsValidEntRef(trigger) )
  216.             SetEntPropVector(trigger, Prop_Send, "m_vecMins", vVec);
  217.  
  218.  
  219.         g_hMenuVMins.Display(client, MENU_TIME_FOREVER);
  220.     }
  221. }
  222.  
  223. public int PosMenuHandler(Menu menu, MenuAction action, int client, int index)
  224. {
  225.     if( action == MenuAction_Cancel )
  226.     {
  227.         if( index == MenuCancel_ExitBack )
  228.             ShowMenuMain(client);
  229.     }
  230.     else if( action == MenuAction_Select )
  231.     {
  232.         int cfgindex = g_iMenuSelected[client];
  233.         int trigger = g_iTriggers[cfgindex];
  234.  
  235.         float vPos[3];
  236.         GetEntPropVector(trigger, Prop_Send, "m_vecOrigin", vPos);
  237.  
  238.         if( index == 0 )
  239.             vPos[0] += 1.0;
  240.         else if( index == 1 )
  241.             vPos[1] += 1.0;
  242.         else if( index == 2 )
  243.             vPos[2] += 1.0;
  244.         else if( index == 3 )
  245.             vPos[0] -= 1.0;
  246.         else if( index == 4 )
  247.             vPos[1] -= 1.0;
  248.         else if( index == 5 )
  249.             vPos[2] -= 1.0;
  250.  
  251.         if( index != 6 )
  252.             TeleportEntity(trigger, vPos, NULL_VECTOR, NULL_VECTOR);
  253.         else
  254.             SaveTrigger(client, cfgindex + 1, "vpos", vPos);
  255.        
  256.  
  257.         g_hMenuPos.Display(client, MENU_TIME_FOREVER);
  258.     }
  259. }
  260.  
  261. public void OnPluginEnd()
  262. {
  263.     ResetPlugin();
  264. }
  265.  
  266. void ResetPlugin()
  267. {
  268.     g_bLoaded = false;
  269.  
  270.     for( int i = 0; i < MAX_ENTITIES; i++ )
  271.     {
  272.         g_vTargetZone[i] = view_as<float>({0.0, 0.0, 0.0});
  273.         g_fTargetAng[i] = 0.0;
  274.  
  275.         if( IsValidEntRef(g_iTriggers[i]) )
  276.             AcceptEntityInput(g_iTriggers[i], "Kill");
  277.         g_iTriggers[i] = 0;
  278.     }
  279. }
  280.  
  281. public void OnMapStart()
  282. {
  283.     g_iLaserMaterial = PrecacheModel("materials/sprites/laserbeam.vmt");
  284.     g_iHaloMaterial = PrecacheModel("materials/sprites/halo01.vmt");
  285.     PrecacheModel(MODEL_BOX, true);
  286.     g_bLoaded = false;
  287.     LoadAirdrops();
  288. }
  289.  
  290. void LoadAirdrops()
  291. {
  292.     if(g_bLoaded)
  293.         return;
  294.     g_bLoaded = true;
  295.    
  296.     char sPath[PLATFORM_MAX_PATH];
  297.     BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
  298.     if( !FileExists(sPath) )
  299.         return;
  300.  
  301.     KeyValues hFile = new KeyValues("airdrop");
  302.     hFile.ImportFromFile(sPath);
  303.  
  304.     char sMap[64];
  305.     GetCurrentMap(sMap, sizeof(sMap));
  306.  
  307.     if( !hFile.JumpToKey(sMap) )
  308.     {
  309.         delete hFile;
  310.         return;
  311.     }
  312.  
  313.     char sTemp[16];
  314.     float fAng, vPos[3], vMax[3], vMin[3], vAirPos[3];
  315.  
  316.     for( int i = 0; i <= MAX_ENTITIES; i++ )
  317.     {
  318.         IntToString(i, sTemp, sizeof(sTemp));
  319.  
  320.         if( hFile.JumpToKey(sTemp, false) )
  321.         {
  322.             fAng = hFile.GetFloat("ang");
  323.             hFile.GetVector("vpos", vPos);
  324.             hFile.GetVector("Airdrop", vAirPos);
  325.             g_vTargetZone[i] = vPos;
  326.             g_fTargetAng[i] = fAng;
  327.             g_vPosAirdrop[i] = vAirPos;
  328.             if( vPos[0] != 0.0 && vPos[1] != 0.0 && vPos[2] != 0.0 )
  329.             {
  330.                 hFile.GetVector("vmin", vMin);
  331.                 hFile.GetVector("vmax", vMax);
  332.                
  333.                 CreateTriggerMultiple(i, vPos, vMax, vMin);
  334.             }
  335.  
  336.             hFile.GoBack();
  337.         }
  338.     }
  339.  
  340.     delete hFile;
  341. }
  342.  
  343. public Action CmdAirdropMenu(int client, int args)
  344. {
  345.     ShowMenuMain(client);
  346.     return Plugin_Handled;
  347. }
  348.  
  349. public Action cmdDebug(int client, int args)
  350. {
  351.     for( int i = 0; i < MAX_ENTITIES; i++ )
  352.     {
  353.         if( g_vTargetZone[i][0] != 0.0 && g_vTargetZone[i][1] != 0.0 && g_vTargetZone[i][2] != 0.0 )
  354.         {
  355.             int entity = EntRefToEntIndex(g_iTriggers[i]);
  356.             if(entity != INVALID_ENT_REFERENCE)
  357.             {
  358.                 PrintToChatAll("%i - %i", i, entity);
  359.             }
  360.         }
  361.     }
  362.     return Plugin_Handled;
  363. }
  364.  
  365. void ShowMenuMain(int client)
  366. {
  367.     g_hMenuMain = new Menu(MainMenuHandler);
  368.     g_hMenuMain.AddItem("1", "Create | Remove");
  369.     g_hMenuMain.AddItem("2", "Set VMins");
  370.     g_hMenuMain.AddItem("3", "Set VMaxs");
  371.     g_hMenuMain.AddItem("4", "Set Pos");
  372.     g_hMenuMain.AddItem("5", "Set Airdrop pos");
  373.     g_hMenuMain.AddItem("6", "Set Trigger");
  374.     g_hMenuMain.AddItem("7", "Show | Hide Trigger");
  375.     g_hMenuMain.SetTitle("Airdrop - Main Menu");
  376.     g_hMenuMain.Display(client, MENU_TIME_FOREVER);
  377. }
  378.  
  379. void SetTriggerIndex(int client)
  380. {
  381.     Menu g_hMenuVectors = new Menu(SetTrigger);
  382.     char sTemp[24], sInt[3];
  383.     for( int i = 0; i < MAX_ENTITIES; i++ )
  384.     {
  385.         if( g_vTargetZone[i][0] != 0.0 && g_vTargetZone[i][1] != 0.0 && g_vTargetZone[i][2] != 0.0 )
  386.         {
  387.             Format(sTemp, sizeof(sTemp), "Trigger %d", i+1);
  388.             IntToString(i, sInt, sizeof sInt);
  389.             g_hMenuVectors.AddItem(sInt, sTemp);
  390.         }
  391.     }
  392.     g_hMenuVectors.Display(client, MENU_TIME_FOREVER);
  393. }
  394.  
  395. void SetTriggerVectors(int client, int action)
  396. {
  397.     if(action == 1)
  398.         g_hMenuVMins.Display(client, MENU_TIME_FOREVER);
  399.     if(action == 2)
  400.         g_hMenuVMaxs.Display(client, MENU_TIME_FOREVER);
  401.     if(action == 3)
  402.         g_hMenuPos.Display(client, MENU_TIME_FOREVER);
  403.     if(action == 4)
  404.         g_hMenuSetAirdrop.Display(client, MENU_TIME_FOREVER);
  405. }
  406.  
  407. public int SetTrigger(Menu menu, MenuAction action, int client, int index)
  408. {
  409.     if( action == MenuAction_End )
  410.         delete menu;
  411.     else if( action == MenuAction_Select )
  412.     {
  413.         g_iMenuSelected[client] = index;
  414.         PrintToChat(client, "%s Trigger %i has been selected", CHAT_TAG, index+1);
  415.         ShowMenuMain(client);
  416.     }
  417. }
  418.  
  419. public int MainMenuHandler(Menu menu, MenuAction action, int client, int index)
  420. {
  421.     if( action == MenuAction_End )
  422.         delete menu;
  423.     else if( action == MenuAction_Select )
  424.     {
  425.         if( index == 0 )
  426.             ShowMenuTriggersList(client);
  427.         else if(index == 1)
  428.         {
  429.             if(g_iMenuSelected[client] < 0)
  430.                 SetTriggerIndex(client);
  431.             else
  432.                 SetTriggerVectors(client, 1);
  433.         }
  434.         else if(index == 2)
  435.         {
  436.             if(g_iMenuSelected[client] < 0)
  437.                 SetTriggerIndex(client);
  438.             else
  439.                 SetTriggerVectors(client, 2);
  440.         }
  441.         else if(index == 3)
  442.         {
  443.             if(g_iMenuSelected[client] < 0)
  444.                 SetTriggerIndex(client);
  445.             else
  446.                 SetTriggerVectors(client, 3);
  447.         }
  448.         else if(index == 4)
  449.         {
  450.             if(g_iMenuSelected[client] < 0)
  451.                 SetTriggerIndex(client);
  452.             else
  453.                 SetTriggerVectors(client, 4);
  454.         }
  455.         else if(index == 5)
  456.             SetTriggerIndex(client);
  457.         else if(index == 6)
  458.             ShowMenuTriggersList(client, false);
  459.     }
  460. }
  461.  
  462. void ShowMenuTriggersList(int client, bool need = true)
  463. {
  464.     Menu hMenu = new Menu(TargetListMenuHandler);
  465.     char sIndex[8], sTemp[32];
  466.    
  467.     for( int i = 0; i < MAX_ENTITIES; i++ )
  468.     {
  469.         if(g_vTargetZone[i][0] != 0.0 && g_vTargetZone[i][1] != 0.0 && g_vTargetZone[i][2] != 0.0)
  470.         {
  471.             if(need)
  472.             {
  473.                 Format(sTemp, sizeof(sTemp), "Trigger %i", i + 1);
  474.                 IntToString(i, sIndex, sizeof sIndex + 1);
  475.             }
  476.             else
  477.             {
  478.                 Format(sTemp, sizeof(sTemp), "Trigger %i", i + 1);
  479.                 IntToString(i + 25, sIndex, sizeof sIndex);
  480.             }
  481.             hMenu.AddItem(sIndex, sTemp);
  482.         }
  483.     }
  484.     if(need)
  485.     {
  486.         for( int i = 0; i < MAX_ENTITIES; i++ )
  487.         {
  488.             if( g_vTargetZone[i][0] == 0.0 && g_vTargetZone[i][1] == 0.0 && g_vTargetZone[i][2] == 0.0 )
  489.             {
  490.                 hMenu.AddItem("-1", "NEW");
  491.                 break;
  492.             }
  493.         }
  494.     }
  495.     hMenu.ExitBackButton = true;
  496.     hMenu.Display(client, MENU_TIME_FOREVER);
  497. }
  498.  
  499. public int TargetListMenuHandler(Menu menu, MenuAction action, int client, int index)
  500. {
  501.     if( action == MenuAction_End )
  502.         delete menu;
  503.     else if( action == MenuAction_Cancel )
  504.     {
  505.         if( index == MenuCancel_ExitBack )
  506.             ShowMenuMain(client);
  507.     }
  508.     else if( action == MenuAction_Select )
  509.     {
  510.         //int type = g_iMenuSelected[client];
  511.         char sTemp[4];
  512.         menu.GetItem(index, sTemp, sizeof(sTemp));
  513.         index = StringToInt(sTemp);
  514.         if(index < 15 && index != -1)
  515.             DeleteTrigger(client, index+1);
  516.         else if(index > 14)
  517.         {
  518.             if(g_bShow[index - 25])
  519.             {
  520.                 g_bShow[index - 25] = false;
  521.                 PrintToChat(client, "%s Hide %i trigger", CHAT_TAG, index - 25);
  522.             }
  523.             else
  524.             {
  525.                 g_hTimerBeam[index - 25] = CreateTimer(0.1, TimerBeam, index - 25, TIMER_REPEAT);
  526.                 g_bShow[index - 25] = true;
  527.                 PrintToChat(client, "%s Show %i trigger", CHAT_TAG, index - 25);
  528.             }
  529.         }
  530.         else
  531.             CreateTrigger(index, client);
  532.         ShowMenuMain(client);
  533.     }
  534. }
  535.  
  536. void CreateTrigger(int index = -1, int client)
  537. {
  538.     if( index == -1 )
  539.     {
  540.         for( int i = 0; i < MAX_ENTITIES; i++ )
  541.         {
  542.             if( g_vTargetZone[i][0] == 0.0 && g_vTargetZone[i][1] == 0.0 && g_vTargetZone[i][2] == 0.0 && IsValidEntRef(g_iTriggers[i]) == false )
  543.             {
  544.                 index = i;
  545.                 break;
  546.             }
  547.         }
  548.     }
  549.     if( index == -1 )
  550.     {
  551.         PrintToChat(client, "%s Error: Cannot create a new group", CHAT_TAG);
  552.         return;
  553.     }
  554.  
  555.     float vPos[3];
  556.     GetClientAbsOrigin(client, vPos);
  557.  
  558.     CreateTriggerMultiple(index, vPos, view_as<float>({ 25.0, 25.0, 100.0}), view_as<float>({ -25.0, -25.0, 0.0 }));
  559.  
  560.     SaveTrigger(client, index, "vpos", vPos);
  561.     SaveTrigger(client, index, "vmax", view_as<float>({ 25.0, 25.0, 100.0}));
  562.     SaveTrigger(client, index, "vmin", view_as<float>({ -25.0, -25.0, 0.0 }));
  563.     SaveTrigger(client, index, "Airdrop", vPos);
  564.     g_vTargetZone[index] = vPos;
  565. }
  566.  
  567. void CreateTriggerMultiple(int index, float vPos[3], float vMaxs[3], float vMins[3])
  568. {
  569.     int trigger = CreateEntityByName("trigger_multiple");
  570.     DispatchKeyValue(trigger, "StartDisabled", "0");
  571.     DispatchKeyValue(trigger, "spawnflags", "1");
  572.     DispatchKeyValue(trigger, "entireteam", "0");
  573.     DispatchKeyValue(trigger, "allowincap", "0");
  574.     DispatchKeyValue(trigger, "allowghost", "0");
  575.  
  576.     DispatchSpawn(trigger);
  577.     SetEntityModel(trigger, MODEL_BOX);
  578.  
  579.     SetEntPropVector(trigger, Prop_Send, "m_vecMaxs", vMaxs);
  580.     SetEntPropVector(trigger, Prop_Send, "m_vecMins", vMins);
  581.     SetEntProp(trigger, Prop_Send, "m_nSolidType", 2);
  582.     TeleportEntity(trigger, vPos, NULL_VECTOR, NULL_VECTOR);
  583.  
  584.     HookSingleEntityOutput(trigger, "OnStartTouch", OnStartTouch);
  585.     g_iTriggers[index] = EntIndexToEntRef(trigger);
  586. }
  587.  
  588. void DeleteTrigger(int client, int cfgindex)
  589. {
  590.     KeyValues hFile = ConfigOpen();
  591.    
  592.     if( hFile != null )
  593.     {
  594.         char sMap[64];
  595.         GetCurrentMap(sMap, sizeof(sMap));
  596.  
  597.         if( hFile.JumpToKey(sMap) )
  598.         {
  599.             char sTemp[16];
  600.             IntToString(cfgindex - 1, sTemp, sizeof(sTemp));
  601.             PrintToChatAll("cfgindex %i", cfgindex - 1);
  602.             if( hFile.JumpToKey(sTemp) )
  603.             {
  604.                 PrintToChatAll("3");
  605.                 if( IsValidEntRef(g_iTriggers[cfgindex-1]) )
  606.                     AcceptEntityInput(g_iTriggers[cfgindex-1], "Kill");
  607.                 g_iTriggers[cfgindex-1] = 0;
  608.  
  609.                 hFile.DeleteKey("vpos");
  610.                 hFile.DeleteKey("vmax");
  611.                 hFile.DeleteKey("vmin");
  612.                 hFile.DeleteKey("Airdrop");
  613.                
  614.                 float vPos[3];
  615.                 hFile.GetVector("vpos", vPos);
  616.  
  617.                 hFile.GoBack();
  618.  
  619.                 if( vPos[0] == 0.0 && vPos[1] == 0.0 && vPos[2] == 0.0 )
  620.                 {
  621.                     for( int i = cfgindex; i < MAX_ENTITIES; i++ )
  622.                     {
  623.                 //      if(!IsValidEntRef(g_iTriggers[cfgindex-1]) )
  624.                 //          i++;
  625.                         g_iTriggers[i-1] = g_iTriggers[i];
  626.                         g_iTriggers[i] = 0;
  627.  
  628.                         g_fTargetAng[i-1] = g_fTargetAng[i];
  629.                         g_fTargetAng[i] = 0.0;
  630.  
  631.                         g_vTargetZone[i-1] = g_vTargetZone[i];
  632.                         g_vTargetZone[i] = view_as<float>({ 0.0, 0.0, 0.0 });
  633.                
  634.  
  635.                         IntToString(i, sTemp, sizeof(sTemp));
  636.  
  637.                         if( hFile.JumpToKey(sTemp) )
  638.                         {
  639.                             IntToString(i-1, sTemp, sizeof(sTemp));
  640.                             hFile.SetSectionName(sTemp);
  641.                             hFile.GoBack();
  642.                         }
  643.                     }
  644.                 }
  645.                 ConfigSave(hFile);
  646.  
  647.                 PrintToChat(client, "%s Trigger [%i] - removed from config.", CHAT_TAG, cfgindex);
  648.             }
  649.         }
  650.  
  651.         delete hFile;
  652.     }
  653. }
  654.  
  655. void SaveTrigger(int client, int index, char[] sKey, float vVec[3])
  656. {
  657.     KeyValues hFile = ConfigOpen();
  658.  
  659.     if( hFile != null )
  660.     {
  661.         char sTemp[64];
  662.         GetCurrentMap(sTemp, sizeof(sTemp));
  663.         if( hFile.JumpToKey(sTemp, true) )
  664.         {
  665.             IntToString(index, sTemp, sizeof(sTemp));
  666.  
  667.             if( hFile.JumpToKey(sTemp, true) )
  668.             {
  669.                 hFile.SetVector(sKey, vVec);
  670.  
  671.                 ConfigSave(hFile);
  672.  
  673.                 if( client )
  674.                     PrintToChat(client, "%s\x01(\x05%d/%d\x01) - Saved trigger '%s'.", CHAT_TAG, index, MAX_ENTITIES, sKey);
  675.             }
  676.             else if( client )
  677.             {
  678.                 PrintToChat(client, "%s\x01(\x05%d/%d\x01) - Failed to save trigger '%s'.", CHAT_TAG, index, MAX_ENTITIES, sKey);
  679.             }
  680.         }
  681.         else if( client )
  682.         {
  683.             PrintToChat(client, "%s\x01(\x05%d/%d\x01) - Failed to save trigger '%s'.", CHAT_TAG, index, MAX_ENTITIES, sKey);
  684.         }
  685.  
  686.         delete hFile;
  687.     }
  688. }
  689.  
  690. public void OnStartTouch(const char[] output, int caller, int activator, float delay)
  691. {
  692.     if( IsClientInGame(activator) && GetClientTeam(activator) == 2 )
  693.     {
  694.         caller = EntIndexToEntRef(caller);
  695.  
  696.         for( int i = 0; i < MAX_ENTITIES; i++ )
  697.         {
  698.             if( caller == g_iTriggers[i] )
  699.             {
  700.                 AcceptEntityInput(caller, "Disable");
  701.                 PrintToChatAll("Tounched");
  702.                 break;
  703.             }
  704.         }
  705.     }
  706. }
  707.  
  708. public Action TimerBeam(Handle timer, any i)
  709. {
  710.     int entity = EntRefToEntIndex(g_iTriggers[i]);
  711.     if(g_bShow[i] && entity != INVALID_ENT_REFERENCE)
  712.     {
  713.         float vMaxs[3], vMins[3], vPos[3];
  714.         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  715.         GetEntPropVector(entity, Prop_Send, "m_vecMaxs", vMaxs);
  716.         GetEntPropVector(entity, Prop_Send, "m_vecMins", vMins);
  717.         AddVectors(vPos, vMaxs, vMaxs);
  718.         AddVectors(vPos, vMins, vMins);
  719.         TE_SendBox(vMins, vMaxs);
  720.         return Plugin_Continue;
  721.     }
  722.     else
  723.     {
  724.         g_hTimerBeam[i] = null;
  725.         return Plugin_Stop;
  726.     }
  727. }
  728.  
  729. void TE_SendBox(float vMins[3], float vMaxs[3])
  730. {
  731.     float vPos1[3], vPos2[3], vPos3[3], vPos4[3], vPos5[3], vPos6[3];
  732.     vPos1 = vMaxs;
  733.     vPos1[0] = vMins[0];
  734.     vPos2 = vMaxs;
  735.     vPos2[1] = vMins[1];
  736.     vPos3 = vMaxs;
  737.     vPos3[2] = vMins[2];
  738.     vPos4 = vMins;
  739.     vPos4[0] = vMaxs[0];
  740.     vPos5 = vMins;
  741.     vPos5[1] = vMaxs[1];
  742.     vPos6 = vMins;
  743.     vPos6[2] = vMaxs[2];
  744.     TE_SendBeam(vMaxs, vPos1);
  745.     TE_SendBeam(vMaxs, vPos2);
  746.     TE_SendBeam(vMaxs, vPos3);
  747.     TE_SendBeam(vPos6, vPos1);
  748.     TE_SendBeam(vPos6, vPos2);
  749.     TE_SendBeam(vPos6, vMins);
  750.     TE_SendBeam(vPos4, vMins);
  751.     TE_SendBeam(vPos5, vMins);
  752.     TE_SendBeam(vPos5, vPos1);
  753.     TE_SendBeam(vPos5, vPos3);
  754.     TE_SendBeam(vPos4, vPos3);
  755.     TE_SendBeam(vPos4, vPos2);
  756. }
  757.  
  758. void TE_SendBeam(const float vMins[3], const float vMaxs[3])
  759. {
  760.     TE_SetupBeamPoints(vMins, vMaxs, g_iLaserMaterial, g_iHaloMaterial, 0, 0, 0.2, 1.0, 1.0, 1, 0.0, { 255, 155, 0, 255 }, 0);
  761.     TE_SendToAll();
  762. }
  763.  
  764. // ====================================================================================================
  765. //                  CONFIG - OPEN
  766. // ====================================================================================================
  767. KeyValues ConfigOpen()
  768. {
  769.     char sPath[PLATFORM_MAX_PATH];
  770.     BuildPath(Path_SM, sPath, sizeof(sPath), "%s", CONFIG_SPAWNS);
  771.  
  772.     if( !FileExists(sPath) )
  773.     {
  774.         File hCfg = OpenFile(sPath, "w");
  775.         hCfg.WriteLine("");
  776.         delete hCfg;
  777.     }
  778.  
  779.     KeyValues hFile = new KeyValues("airdrop");
  780.     if( !hFile.ImportFromFile(sPath) )
  781.     {
  782.         delete hFile;
  783.         return null;
  784.     }
  785.  
  786.     return hFile;
  787. }
  788.  
  789.  
  790.  
  791. // ====================================================================================================
  792. //                  CONFIG - SAVE
  793. // ====================================================================================================
  794. void ConfigSave(KeyValues hFile)
  795. {
  796.     char sPath[PLATFORM_MAX_PATH];
  797.     BuildPath(Path_SM, sPath, sizeof(sPath), "%s", CONFIG_SPAWNS);
  798.  
  799.     if( !FileExists(sPath) )
  800.         return;
  801.  
  802.     hFile.Rewind();
  803.     hFile.ExportToFile(sPath);
  804. }
  805.  
  806.  
  807.  
  808. // ====================================================================================================
  809. //                  OTHER
  810. // ====================================================================================================
  811. bool IsValidEntRef(int entity)
  812. {
  813.     if( entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE )
  814.         return true;
  815.     return false;
  816. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement