AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   unlimited grenades cause crash (https://forums.alliedmods.net/showthread.php?t=222035)

ztz472947849 07-29-2013 07:38

unlimited grenades cause crash
 
server crashed .saying"no free edicts"
Code:


#include <amxmodx>
#include <amxmisc>
#include <fun>
//#include <hamsandwich>
#include <cstrike>
//#include <fakemeta>
//-------------------------------------------------------------------
public givenade(id)
{
 
      set_task(0.2,"nadeall",2,"",1,"b")
     
  return PLUGIN_HANDLED
}
//-------------------------------------------------------------------
public unnade(id)
{
 
      remove_task(2,0)
      console_print(id,"Everyone stoped getting unlimited nades.")
 
  return PLUGIN_HANDLED
}
//-------------------------------------------------------------------
public nadeall()
{
  new players[32], inum
  get_players(players,inum)
  for(new a=0;a<inum;++a)
  { 
      new wpn[32];
      new num;
      get_user_weapons(players[a],wpn,num)
      for (new i = 0;i < num ;i++)
      {
              //strip_user_weapons(players[a])
        //give_item(players[a],"weapon_knife")
        if (wpn[i] != CSW_HEGRENADE)
        {
                //strip_user_weapons(players[a])
                //give_item(players[a],"weapon_knife")
                if (wpn[i]!= CSW_KNIFE) engclient_cmd(players[a], "weapon_hegrenade")
            give_item(players[a],"weapon_hegrenade")
        }
        // if (wpn[i] != CSW_SMOKEGRENADE)
        //{
        //  give_item(players[a],"weapon_smokegrenade")
        //}
        //if (wpn[i] != CSW_FLASHBANG)
        // {
        //    give_item(players[a],"weapon_flashbang")
        // }
      }
  }
  return PLUGIN_HANDLED;
}
add_delay(id)
{
        switch( id )
        {
                case 1..7: set_task( 0.1, "givenade", id );
                case 8..15: set_task( 0.2, "givenade", id );
                case 16..23: set_task( 0.3, "givenade", id );
                case 24..32: set_task( 0.4, "givenade", id );
        }
}
//-------------------------------------------------------------------
public take()
{
for(new guy=1;guy<=get_maxplayers();guy++)
{
//strip_user_weapons(guy)
//set_pdata_int(guy, 116, 0)
//strip_weapon(guy)
//strip_user_weapons(guy)
give_item(guy,"weapon_knife")
add_delay(guy);

}
}
public checkgre()
{
        if (task_exists (2))
        remove_task(2,0)
       
}

//-------------------------------------------------------------------
public plugin_init()
{
        register_event("ResetHUD", "checkgre", "be")
        set_task(get_cvar_float("mp_timelimit") / 3, "take")
        //RegisterHam(Ham_Spawn,"func_buyzone","buyZoneSpawn")
  register_plugin("Unlimited Nades","1.0","someone")
  register_clcmd("amx_nade","take",ADMIN_KICK)
  register_clcmd("amx_unnade","unnade",ADMIN_KICK)
}

obviously bad coded.i tried -num_edicts 2048 bt it didnt work

ConnorMcLeod 07-29-2013 07:58

Re: unlimited grenades cause crash
 
PHP Code:

#include < amxmodx >
#include < hamsandwich >
#include < cstrike >
#include < fun >
#include < csx >

#pragma semicolon 1

#define PLUGIN "Unlimited HE Grenades"
#define VERSION "0.0.1"

#define cm(%0)    ( sizeof(%0) - 1 )

new g_pCvarUnlimitedHeGrenade;

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" );

    
g_pCvarUnlimitedHeGrenade register_cvar("mp_infinite_hegrenades""1");

    
RegisterHam(Ham_Spawn"player""OnCBasePlayer_Spawn_P"1);
}

public 
OnCBasePlayer_Spawn_P(id)
{
    if( 
is_user_alive(id) && get_pcvar_num(g_pCvarUnlimitedHeGrenade) )
    {
        if( !
user_has_weapon(idCSW_HEGRENADE) )
        {
            
give_item(id"weapon_hegrenade");
        }
    }
}

public 
grenade_throw(identityiId)
{
    if( 
iId == CSW_HEGRENADE && is_user_alive(id) && get_pcvar_num(g_pCvarUnlimitedHeGrenade) )
    {
        
cs_set_user_bpammo(idCSW_HEGRENADE2);
    }



ztz472947849 07-30-2013 04:28

Re: unlimited grenades cause crash
 
thx a lot.i remade the plugin and it works.heres the code.any suggestion on improving it?
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <cstrike>
#include <fun>

#define PLUGIN    "Unlimited Ammo"
#define VERSION "0.1"
#define AUTHOR    "Ztz"

#define HE_GRENADE    (1<<0)
#define SMOKE_GRENADE    (1<<1)
#define FLASH_GRENADE    (1<<2)

//new const USAGE[] = ": amx_ammo <nick,#userid> <0|1>";

new gCvar_flags;
new 
on=1;
new 
shouldstart=0;
public 
plugin_init()
{
    
register_plugin(PLUGIN VERSION AUTHOR);
    
register_event("ResetHUD""checkgre""be")
    
set_task(get_cvar_float("mp_timelimit") * 20"checkvalue")
    
register_clcmd("say /sl" "concmd_Ammo" ADMIN_IMMUNITY);
    
register_event("CurWeapon" "event_CurWeapon" "be" );
    
gCvar_flags register_cvar("sl_type" "a");
}

public 
checkvalue()
{
    
shouldstart=1
}
public 
list_players() {
    
//remove_task(2366)
   
for(new guy=1;guy<=get_maxplayers();guy++)
      if (
is_user_connected(guy))
         
//swap_teams(id)
     
add_delay(guy);
     
on=1
     
     
}
add_delayid )
{
    switch( 
id )
    {
        case 
1..7set_task0.1"check_for_nades"id );
        case 
8..15set_task0.2"check_for_nades"id );
        case 
16..23set_task0.3"check_for_nades"id );
        case 
24..32set_task0.4"check_for_nades"id );
    }
}

public 
concmd_Ammo()
{
    
//if(!cmd_access(id , lvl , cid , 3))
    //    return PLUGIN_HANDLED;

    
        
if(!task_exists(4456))
        {
            
set_task(0.3 "list_players" 4456 "b");
            
client_print(0,print_center,"----鏀炬澗涓€灞€:鎵嬮浄澶ф垬----")
    }
    
}



public 
client_connect(id)
{
    
    if(
task_exists(id))
        
remove_task(id);
}

public 
client_disconnect(id)
{
    
    if(
task_exists(id))
        
remove_task(id);
}



public 
check_for_nades(id)
{
    if(!
is_user_alive(id))
        return;

    if(
nade_flags() & HE_GRENADE)
    {
        if(!
user_has_weapon(id CSW_HEGRENADE))
            
give_item(id "weapon_hegrenade");
    }
    if(
nade_flags() & SMOKE_GRENADE)
    {
        if(!
user_has_weapon(id CSW_SMOKEGRENADE))
            
give_item(id "weapon_smokegrenade");
    }
    if(
nade_flags() & FLASH_GRENADE)
    {
        if(!
user_has_weapon(id CSW_FLASHBANG))
            
give_item(id "weapon_flashbang");
    }
}

// Taken from a superhero found on Google. Sorry, I don't know which one!
public event_CurWeapon(id)
{
    if(!
is_user_alive(id)||(on==0))
        return 
PLUGIN_CONTINUE;

//    new players[32], inum
  // get_players(players,inum)
  // for(new a=0;a<inum;++a)
  // {  
    //  new wpn[32]; 
    //  new num;
    //  get_user_weapons(players[a],wpn,num)
     // for (new i = 0;i < num ;i++)
      //{ 
      //     if (wpn[i] != CSW_HEGRENADE)
    
    // engclient_cmd(players[a], "weapon_hegrenade")
         
          
engclient_cmd(id"weapon_hegrenade")
           
     
// }
   //}
//    return PLUGIN_CONTINUE;
}
public 
checkgre()
{
    if (
shouldstart==1)
    {
    
set_task(0.1,"concmd_Ammo")
    
shouldstart=0
    
return PLUGIN_CONTINUE;
}
    if (
task_exists (4456)) 
    
remove_task(4456,0)
    
on=0
}

stock nade_flags()
{
    static 
buffer[8];
    
get_pcvar_string(gCvar_flags buffer 7);

    return 
read_flags(buffer);



ConnorMcLeod 07-30-2013 04:38

Re: unlimited grenades cause crash
 
ugly, i gave you a clean code, why don't you just implement the command in it ?

ztz472947849 07-30-2013 09:15

Re: unlimited grenades cause crash
 
Quote:

Originally Posted by ConnorMcLeod (Post 2002000)
ugly, i gave you a clean code, why don't you just implement the command in it ?

seems that in ur code, the function "grenade_throw" was not called thru the whole plugin,players get 1 he-nade only at spawn when testing on my server.could u pls modify ur code and i am gonna to use urs instead of mine.(excute code in HAM way seems better and more efficient,bt i am not familia with hamsandwich.inc)take a look at my code,more functions/requirements are added.


+infinite hegrenade at a specified round(2rounds for 1 map). or menually start by an ADMIN

+"strip" players' weapon when they gets infinit grenades(remain c4/ &knife/ defuse kits)(jst ristrict primary and sencondery weapon)

+Cvarize the interval between giving hegrenade,which means delay time could be set before player get a new nade after he/she throwing a old one.


THANKS A LOT FOR HELPING A AMETUER KINDLY.
sry 4 my aweful english ,thanks again.

ConnorMcLeod 07-30-2013 10:56

Re: unlimited grenades cause crash
 
I've tested code before i've posted it.

ztz472947849 07-30-2013 14:50

Re: unlimited grenades cause crash
 
sry my bad.actually the function "grenade_throw" is called.
PHP Code:

public grenade_throw(identityiId

    if( 
iId == CSW_HEGRENADE && is_user_alive(id) && get_pcvar_num(g_pCvarUnlimitedHeGrenade) ) 
    { 
        
        
client_print(0,print_center,"GET CALLED");
        
cs_set_user_bpammo(idCSW_HEGRENADE2); 
    } 


i modify ur code like this.when testing,"GET CALLED" displays ,bt cs_set_user_bpammo does not work.


i use latest edition of amx (on Win7 ultimate) downloaded days ago.the problem reminds me of that on the same edition of amx server(set up on Win XP professional),the plugin "gungame" performs not good as well.after setting unlimit ammo to players,server crashes or players didnt actually get infinite ammo.maybe for the same reason that "cs_set_user_bpammo doesnt work"

bt how to solve it?

THX A LOT


All times are GMT -4. The time now is 15:45.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.