Advertisement
Guest User

Untitled

a guest
Sep 13th, 2018
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.16 KB | None | 0 0
  1. /*================================================================================
  2.    
  3.     -----------------------------------
  4.     -*- [ZP] Sandbags -*-
  5.     -----------------------------------
  6.    
  7.     ~~~~~~~~~~~~~~~
  8.     - Description -
  9.     ~~~~~~~~~~~~~~~
  10.    
  11.     Original by SAMURAI, Upgraded to zp by LARP
  12.     larp.source@gmail.com (Chile) Languaje spanish!
  13.    
  14. ================================================================================*/
  15.  
  16.  
  17. #include <amxmodx>
  18. #include <amxmisc>
  19. #include <fakemeta>
  20. #include <xs>
  21. #include <fun>
  22. #include <zombieplague.inc>
  23.  
  24. // The sizes of models
  25. #define PALLET_MINS Float:{ -27.260000, -22.280001, -22.290001 }
  26. #define PALLET_MAXS Float:{  27.340000,  26.629999,  29.020000 }
  27.  
  28.  
  29. // from fakemeta util by VEN
  30. #define fm_find_ent_by_class(%1,%2) engfunc(EngFunc_FindEntityByString, %1, "classname", %2)
  31. #define fm_remove_entity(%1) engfunc(EngFunc_RemoveEntity, %1)
  32. // this is mine
  33. #define fm_drop_to_floor(%1) engfunc(EngFunc_DropToFloor,%1)
  34.  
  35. // cvars
  36. new pnumplugin, remove_nrnd, maxpallets, phealth;
  37.  
  38. // num of pallets with bags
  39. new palletscout = 0;
  40.  
  41. new postavio_PAKET[ 33 ]
  42. /* Models for pallets with bags .
  43.   Are available 2 models, will be set a random of them  */
  44. new g_models[][] =
  45. {
  46.     "models/pallet_with_bags2.mdl",
  47.     "models/pallet_with_bags.mdl"
  48. }
  49.  
  50. new stuck[33]
  51. new g_bolsas[33];
  52. new cvar[3]
  53.  
  54. new const Float:size[][3] = {
  55.     {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {-1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, -1.0},
  56.     {0.0, 0.0, 2.0}, {0.0, 0.0, -2.0}, {0.0, 2.0, 0.0}, {0.0, -2.0, 0.0}, {2.0, 0.0, 0.0}, {-2.0, 0.0, 0.0}, {-2.0, 2.0, 2.0}, {2.0, 2.0, 2.0}, {2.0, -2.0, 2.0}, {2.0, 2.0, -2.0}, {-2.0, -2.0, 2.0}, {2.0, -2.0, -2.0}, {-2.0, 2.0, -2.0}, {-2.0, -2.0, -2.0},
  57.     {0.0, 0.0, 3.0}, {0.0, 0.0, -3.0}, {0.0, 3.0, 0.0}, {0.0, -3.0, 0.0}, {3.0, 0.0, 0.0}, {-3.0, 0.0, 0.0}, {-3.0, 3.0, 3.0}, {3.0, 3.0, 3.0}, {3.0, -3.0, 3.0}, {3.0, 3.0, -3.0}, {-3.0, -3.0, 3.0}, {3.0, -3.0, -3.0}, {-3.0, 3.0, -3.0}, {-3.0, -3.0, -3.0},
  58.     {0.0, 0.0, 4.0}, {0.0, 0.0, -4.0}, {0.0, 4.0, 0.0}, {0.0, -4.0, 0.0}, {4.0, 0.0, 0.0}, {-4.0, 0.0, 0.0}, {-4.0, 4.0, 4.0}, {4.0, 4.0, 4.0}, {4.0, -4.0, 4.0}, {4.0, 4.0, -4.0}, {-4.0, -4.0, 4.0}, {4.0, -4.0, -4.0}, {-4.0, 4.0, -4.0}, {-4.0, -4.0, -4.0},
  59.     {0.0, 0.0, 5.0}, {0.0, 0.0, -5.0}, {0.0, 5.0, 0.0}, {0.0, -5.0, 0.0}, {5.0, 0.0, 0.0}, {-5.0, 0.0, 0.0}, {-5.0, 5.0, 5.0}, {5.0, 5.0, 5.0}, {5.0, -5.0, 5.0}, {5.0, 5.0, -5.0}, {-5.0, -5.0, 5.0}, {5.0, -5.0, -5.0}, {-5.0, 5.0, -5.0}, {-5.0, -5.0, -5.0}
  60. }
  61.  
  62. new const g_item_name[] = { "15 Sandbags" }
  63. const g_item_bolsas = 0
  64. new g_itemid_bolsas
  65. new ZPSTUCK, g_BINDMODE, g_MSGMODE
  66.  
  67.  
  68. public plugin_init()
  69. {
  70.     /* Register the plugin */
  71.     //register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  72.    
  73.     register_plugin("[ZP] Extra: SandBags", "1.1", "LARP")
  74.     set_task(0.1,"checkstuck",0,"",0,"b")
  75.     g_itemid_bolsas = zp_register_extra_item(g_item_name, g_item_bolsas, ZP_TEAM_HUMAN)
  76.     /* Register the cvars */
  77.     g_BINDMODE  = register_cvar("zp_pb_bind","0");      //Auto bind L Key!
  78.     g_MSGMODE   = register_cvar("zp_pb_msg","1");       //
  79.     ZPSTUCK = register_cvar("zp_pb_stuck","1")
  80.     pnumplugin = register_cvar("zp_pb_enable","1"); // 1 = ON ; 0 = OFF
  81.     remove_nrnd = register_cvar("zp_pb_remround","1");
  82.     maxpallets = register_cvar("zp_pb_limit","200"); // max number of pallets with bags
  83.     phealth = register_cvar("zp_pb_health","200"); // set the health to a pallet with bags
  84.    
  85.     /* Game Events */
  86.     register_event("HLTV","event_newround", "a","1=0", "2=0"); // it's called every on new round
  87.    
  88.     /* This is for menuz: */
  89.     register_menucmd(register_menuid("\ySand Bags:"), 1023, "menu_command" );
  90.     register_clcmd("say /pb","show_the_menu");
  91.     register_clcmd("/pb","show_the_menu");
  92.     //cvar[0] = register_cvar("zp_autounstuck","1")
  93.     cvar[1] = register_cvar("zp_pb_stuckeffects","1")
  94.     cvar[2] = register_cvar("zp_pb_stuckwait","7")
  95.  
  96. }
  97. public client_putinserver( id )
  98. {
  99.     postavio_PAKET[ id ] = 0
  100. }
  101. public plugin_precache()
  102. {
  103.     for(new i;i < sizeof g_models;i++)
  104.         engfunc(EngFunc_PrecacheModel,g_models[i]);
  105. }
  106.  
  107. public show_the_menu(id,level,cid)
  108. {
  109.     // check if the plugin cvar is turned off
  110.     if( ! get_pcvar_num( pnumplugin ) )
  111.         return PLUGIN_HANDLED;
  112.        
  113.        
  114.     // check if user isn't alive
  115.     if( ! is_user_alive( id ) )
  116.     {
  117.         client_print( id, print_chat, "[ZP] You are not alive." ); //msg muerto
  118.         return PLUGIN_HANDLED;
  119.     }
  120.     if( postavio_PAKET[ id ] >= 2 )
  121.     {
  122.         client_print( id, print_chat, "[ZP] Sorry, only 2 allowed." ); //msg muerto
  123.         return PLUGIN_HANDLED;
  124.     }
  125.     if( get_user_team( id ) != 2 )
  126.     {
  127.         client_print( id, print_chat, "[ZP] Sorry, only CT are allowed to use it." ); //msg muerto
  128.         return PLUGIN_HANDLED;
  129.     }
  130.     if ( !zp_get_user_zombie(id) )
  131.     {      
  132.         new szMenuBody[256];
  133.         new keys;
  134.        
  135.         new nLen = format( szMenuBody, 255, "\ySand Bags:^n" );
  136.         nLen += format( szMenuBody[nLen], 255-nLen, "^n\w1. Place a Sandbags (%i Remaining)", g_bolsas[id] );
  137.         //nLen += format( szMenuBody[nLen], 255-nLen, "^n\w2. Remove a pallet with bags" );
  138.         nLen += format( szMenuBody[nLen], 255-nLen, "^n^n\w0. Exit" );
  139.  
  140.         keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<9)
  141.  
  142.         show_menu( id, keys, szMenuBody, -1 );
  143.  
  144.         // depends what you want, if is continue will appear on chat what the admin sayd
  145.         return PLUGIN_HANDLED;
  146.     }
  147.     client_print(id, print_chat, "[ZP] The zombies can not use this command!")
  148.     return PLUGIN_HANDLED;
  149. }
  150.  
  151.  
  152. public menu_command(id,key,level,cid)
  153. {
  154.    
  155.     switch( key )
  156.     {
  157.         // place a pallet with bags
  158.         case 0:
  159.         {
  160.             if ( !zp_get_user_zombie(id) )
  161.             {
  162.                 new money = g_bolsas[id]
  163.                 if ( money < 1 )
  164.                 {
  165.                     if ( get_pcvar_num(g_MSGMODE) == 1 )
  166.                         {
  167.                             set_hudmessage(0, 0, 100, 0.80, 0.80, 0, 6.0, 2.0, 1.0, 1.0)
  168.                             show_hudmessage(id, "You do not have to^nplace sandbags")
  169.                             return PLUGIN_CONTINUE
  170.                         }
  171.                     client_print(id, print_chat, "[ZP] You do not have to place sandbags!")
  172.                     return PLUGIN_CONTINUE
  173.                 }
  174.                 g_bolsas[id]-= 1
  175.                 place_palletwbags(id);
  176.                 show_the_menu(id,level,cid);
  177.                 postavio_PAKET[ id ]++
  178.                 return PLUGIN_CONTINUE 
  179.             }
  180.             client_print(id, print_chat, "[ZP] The zombies can not use this!!")
  181.             return PLUGIN_CONTINUE 
  182.         }
  183.        
  184.            
  185.     }
  186.    
  187.     return PLUGIN_HANDLED;
  188. }
  189.  
  190.  
  191.  
  192. public place_palletwbags(id)
  193. {
  194.    
  195.     if( palletscout == get_pcvar_num(maxpallets) )
  196.     {
  197.         client_print(id,print_chat,"[ZP] For security reasons only allow %d Sandbags on the server!",get_pcvar_num(maxpallets));
  198.         return PLUGIN_HANDLED;
  199.     }
  200.    
  201.     // create a new entity
  202.     new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "func_wall"));
  203.    
  204.    
  205.     // set a name to the entity
  206.     set_pev(ent,pev_classname,"amxx_pallets");
  207.    
  208.     // set model       
  209.     engfunc(EngFunc_SetModel,ent,g_models[random(sizeof g_models)]);
  210.    
  211.     // register a new var. for origin
  212.     static Float:xorigin[3];
  213.     get_user_hitpoint(id,xorigin);
  214.    
  215.    
  216.     // check if user is aiming at the air
  217.     if(engfunc(EngFunc_PointContents,xorigin) == CONTENTS_SKY)
  218.     {
  219.         client_print(id,print_chat,"[ZP] You can not put sandbags in the sky!");
  220.         return PLUGIN_HANDLED;
  221.     }
  222.    
  223.    
  224.     // set sizes
  225.     static Float:p_mins[3], Float:p_maxs[3];
  226.     p_mins = PALLET_MINS;
  227.     p_maxs = PALLET_MAXS;
  228.     engfunc(EngFunc_SetSize, ent, p_mins, p_maxs);
  229.     set_pev(ent, pev_mins, p_mins);
  230.     set_pev(ent, pev_maxs, p_maxs );
  231.     set_pev(ent, pev_absmin, p_mins);
  232.     set_pev(ent, pev_absmax, p_maxs );
  233.  
  234.    
  235.     // set the rock of origin where is user placed
  236.     engfunc(EngFunc_SetOrigin, ent, xorigin);
  237.    
  238.    
  239.     // make the rock solid
  240.     set_pev(ent,pev_solid,SOLID_BBOX); // touch on edge, block
  241.    
  242.     // set the movetype
  243.     set_pev(ent,pev_movetype,MOVETYPE_FLY); // no gravity, but still collides with stuff
  244.    
  245.     // now the damage stuff, to set to take it or no
  246.     // if you set the cvar "pallets_wbags_health" 0, you can't destroy a pallet with bags
  247.     // else, if you want to make it destroyable, just set the health > 0 and will be
  248.     // destroyable.
  249.     new Float:p_cvar_health = get_pcvar_float(phealth);
  250.     switch(p_cvar_health)
  251.     {
  252.         case 0.0 :
  253.         {
  254.             set_pev(ent,pev_takedamage,DAMAGE_NO);
  255.         }
  256.        
  257.         default :
  258.         {
  259.             set_pev(ent,pev_health,p_cvar_health);
  260.             set_pev(ent,pev_takedamage,DAMAGE_YES);
  261.         }
  262.     }
  263.    
  264.            
  265.     static Float:rvec[3];
  266.     pev(id,pev_v_angle,rvec);
  267.    
  268.     rvec[0] = 0.0;
  269.    
  270.     set_pev(ent,pev_angles,rvec);
  271.    
  272.     // drop entity to floor
  273.     fm_drop_to_floor(ent);
  274.    
  275.     // num ..
  276.     palletscout++;
  277.    
  278.     // confirm message
  279.     if ( get_pcvar_num(g_MSGMODE) == 1 )
  280.     {
  281.         set_hudmessage(0, 0, 100, 0.80, 0.80, 0, 6.0, 2.0, 1.0, 1.0)
  282.         show_hudmessage(id, "You placed a SandBag^n%i Remaining", g_bolsas[id])
  283.         return PLUGIN_HANDLED
  284.     }
  285.     client_print(id, print_chat, "[ZP] You have placed a Sandbag.")
  286.     return PLUGIN_HANDLED;
  287. }
  288.    
  289. /* ====================================================
  290. get_user_hitpoin stock . Was maked by P34nut, and is
  291. like get_user_aiming but is with floats and better :o
  292. ====================================================*/ 
  293. stock get_user_hitpoint(id, Float:hOrigin[3])
  294. {
  295.     if ( ! is_user_alive( id ))
  296.         return 0;
  297.    
  298.     new Float:fOrigin[3], Float:fvAngle[3], Float:fvOffset[3], Float:fvOrigin[3], Float:feOrigin[3];
  299.     new Float:fTemp[3];
  300.    
  301.     pev(id, pev_origin, fOrigin);
  302.     pev(id, pev_v_angle, fvAngle);
  303.     pev(id, pev_view_ofs, fvOffset);
  304.    
  305.     xs_vec_add(fOrigin, fvOffset, fvOrigin);
  306.    
  307.     engfunc(EngFunc_AngleVectors, fvAngle, feOrigin, fTemp, fTemp);
  308.    
  309.     xs_vec_mul_scalar(feOrigin, 9999.9, feOrigin);
  310.     xs_vec_add(fvOrigin, feOrigin, feOrigin);
  311.    
  312.     engfunc(EngFunc_TraceLine, fvOrigin, feOrigin, 0, id);
  313.     global_get(glb_trace_endpos, hOrigin);
  314.    
  315.     return 1;
  316. }
  317.  
  318.  
  319. /* ====================================================
  320. This is called on every round, at start up,
  321. with HLTV logevent. So if the "pallets_wbags_nroundrem"
  322. cvar is set to 1, all placed pallets with bugs will be
  323. removed.
  324. ====================================================*/
  325. public event_newround()
  326. {
  327.     if( get_pcvar_num ( remove_nrnd ) == 1)
  328.         remove_allpalletswbags();
  329.        
  330. }
  331.  
  332.  
  333. /* ====================================================
  334. This is a stock to help for remove all pallets with
  335. bags placed . Is called on new round if the cvar
  336. "pallets_wbags_nroundrem" is set 1.
  337. ====================================================*/
  338. stock remove_allpalletswbags()
  339. {
  340.     new pallets = -1;
  341.     while((pallets = fm_find_ent_by_class(pallets, "amxx_pallets")))
  342.         fm_remove_entity(pallets);
  343.        
  344.     palletscout = 0;
  345. }
  346.  
  347. public checkstuck() {
  348.     if ( get_pcvar_num(ZPSTUCK) == 1 )
  349.     {
  350.         static players[32], pnum, player
  351.         get_players(players, pnum)
  352.         static Float:origin[3]
  353.         static Float:mins[3], hull
  354.         static Float:vec[3]
  355.         static o,i
  356.         for(i=0; i<pnum; i++){
  357.             player = players[i]
  358.             if (is_user_connected(player) && is_user_alive(player)) {
  359.                 pev(player, pev_origin, origin)
  360.                 hull = pev(player, pev_flags) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN
  361.                 if (!is_hull_vacant(origin, hull,player) && !get_user_noclip(player) && !(pev(player,pev_solid) & SOLID_NOT)) {
  362.                     ++stuck[player]
  363.                     if(stuck[player] >= get_pcvar_num(cvar[2])) {
  364.                         pev(player, pev_mins, mins)
  365.                         vec[2] = origin[2]
  366.                         for (o=0; o < sizeof size; ++o) {
  367.                             vec[0] = origin[0] - mins[0] * size[o][0]
  368.                             vec[1] = origin[1] - mins[1] * size[o][1]
  369.                             vec[2] = origin[2] - mins[2] * size[o][2]
  370.                             if (is_hull_vacant(vec, hull,player)) {
  371.                                 engfunc(EngFunc_SetOrigin, player, vec)
  372.                                 effects(player)
  373.                                 set_pev(player,pev_velocity,{0.0,0.0,0.0})
  374.                                 o = sizeof size
  375.                             }
  376.                         }
  377.                     }
  378.                 }
  379.                 else
  380.                 {
  381.                     stuck[player] = 0
  382.                 }
  383.             }
  384.         }
  385.    
  386.     }
  387.    
  388. }
  389.  
  390. stock bool:is_hull_vacant(const Float:origin[3], hull,id) {
  391.     static tr
  392.     engfunc(EngFunc_TraceHull, origin, origin, 0, hull, id, tr)
  393.     if (!get_tr2(tr, TR_StartSolid) || !get_tr2(tr, TR_AllSolid)) //get_tr2(tr, TR_InOpen))
  394.         return true
  395.    
  396.     return false
  397. }
  398.  
  399. public effects(id) {
  400.     if(get_pcvar_num(cvar[1])) {
  401.         set_hudmessage(255,150,50, -1.0, 0.65, 0, 6.0, 1.5,0.1,0.7) // HUDMESSAGE
  402.         show_hudmessage(id,"Automatic Unstuck!") // HUDMESSAGE
  403.         message_begin(MSG_ONE_UNRELIABLE,105,{0,0,0},id )      
  404.         write_short(1<<10)   // fade lasts this long duration
  405.         write_short(1<<10)   // fade lasts this long hold time
  406.         write_short(1<<1)   // fade type (in / out)
  407.         write_byte(20)            // fade red
  408.         write_byte(255)    // fade green
  409.         write_byte(255)        // fade blue
  410.         write_byte(255)    // fade alpha
  411.         message_end()
  412.         client_cmd(id,"spk fvox/blip.wav")
  413.     }
  414. }
  415.  
  416. public zp_extra_item_selected(player, itemid)
  417. {
  418.     if (itemid == g_itemid_bolsas)
  419.     {
  420.         g_bolsas[player]+= 15
  421.         cmd_bind(player)
  422.         set_task(0.3,"show_the_menu",player)
  423.         if ( get_pcvar_num(g_MSGMODE) == 1 )
  424.         {
  425.             set_hudmessage(0, 0, 100, 0.80, 0.80, 0, 6.0, 2.0, 1.0, 1.0)
  426.             show_hudmessage(player, "Plugin By LARP^n    Chile 2008")
  427.         }
  428.     }
  429.  
  430. }
  431.  
  432. public cmd_bind(id)
  433. {
  434.     if ( get_pcvar_num(g_BINDMODE) == 1 )
  435.     {
  436.         client_print(id, print_chat, "[ZP] You have %i sandbags, to use with the key 'L'", g_bolsas[id])
  437.         client_cmd(id,"bind l /pb")
  438.         return PLUGIN_HANDLED
  439.     }
  440.     client_print(id, print_chat, "[ZP] You have %i sandbags, to use type 'say /pb'", g_bolsas[id])
  441.     return PLUGIN_HANDLED
  442.  
  443. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement