Raised This Month: $ Target: $400
 0% 

Hero Is Made Wrong?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Artenis
Member
Join Date: Mar 2008
Old 08-19-2008 , 02:07   Hero Is Made Wrong?
Reply With Quote #1

hey well i made converted the paint ball mod into a hero that some basic stats. Then i made the bullets have a gold trace when they are flying through teh air. For some reason when i try it on a server it completely lags and doesnt work lol.. Any help would be appreciated:

Code:
// Color

/* CVARS - copy and paste to shconfig.cfg

//Color
color_level 10
color_health 250        //Health for Color
color_armor 250                  //Armor for Color
color_gravity 0.40        //Gravity for Color
color_m4a1mult 2.0             //Damage multiplier for his M4A1.
color_lifetime 15                  //How long they sprays last
color_randomcolor 1            // 0 Is gay, 1 is random, and 2 is t red ct blue
color_maxballs 300             // max sprays at once 

*/


#include <amxmodx>
#include <fakemeta>
#include <superheromod>
#include <engine>
#include <cstrike>

#define MAX_COLORS 10
#define NORMALSPEED   800
#define SNIPERSPEED   1100

new WeaponUsed[33]
new AmmoUsed[33]
new g_Switch

// GLOBAL VARIABLES
new gHeroName[]="Color"
new bool:gHasColorPower[SH_MAXSLOTS+1]
new CvarM4A1DmgMult
new g_colorSprite[2][] = {"sprites/bhit.spr", "sprites/richo1.spr"}
new g_colorColors[MAX_COLORS][3] = {
{255,255,255}, // white
{255,0,0}, // red
{0,255,0}, // green
{0,0,255}, // blue
{255,255,0}, // yellow
{255,0,255}, // magenta
{0,255,255}, // cyan
{255,20,147}, // pink
{255,165,0}, // orange
{205,149,12} // gold 

}



new lastwpn[33]
new lastammo[33]
new g_ballsnum = 0

// Cvars //
new color
new color_lifetime
new color_randomcolor
new color_maxballs
//----------------------------------------------------------------------------------------------
public plugin_init()
{
    // Plugin Info
    register_plugin("SUPERHERO Color", "1", "Bonza")

    // DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
    register_cvar("color_level", "10")
    register_cvar("color_health", "250")
    register_cvar("color_armor", "250")
    register_cvar("color_gravity", "0.40")
        register_cvar("color_randomcolor", "1")
        register_cvar("color_maxballs", "300")
        register_cvar("color_lifetime", "15")
        register_cvar("bfx_switch","1");
    CvarM4A1DmgMult = register_cvar("color_m4a1mult", "2.0")

    // FIRE THE EVENT TO CREATE THIS SUPERHERO!
    shCreateHero(gHeroName, "Colored m4a1", "Color Is Everything ; By Bonza", false, "color_level")

    // REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    // INIT
    register_srvcmd("color_init", "color_init")
    shRegHeroInit(gHeroName, "color_init")

    // EVENTS
    register_event("ResetHUD", "newSpawn","b")
    register_event("CurWeapon", "weaponChange", "be", "1=1")
    register_event("Damage", "color_damage", "b", "2!0")
        register_event("CurWeapon", "make_color", "be", "3>0")
        register_event("CurWeapon", "Weapon_Event","be", "1=1", "3>0")

    // Let Server know about Marine's Variable
    shSetMaxHealth(gHeroName, "color_health")
    shSetMaxArmor(gHeroName, "color_armor")
    shSetMinGravity(gHeroName, "color_gravity")
    shSetShieldRestrict(gHeroName)

        set_task(30.0,"remove_bullets",0,"",0,"b");    
}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
    precache_model("models/shell.mdl")
        precache_model("models/shmod/color_m4a1.mdl")
        precache_model("sprites/bhit.spr")
        precache_model("sprites/richo1.spr")
}
//----------------------------------------------------------------------------------------------
public color_init()
{
    // First Argument is an id
    new temp[6]
    read_argv(1, temp, 5)
    new id = str_to_num(temp)

    // 2nd Argument is 0 or 1 depending on whether the id has the hero
    read_argv(2, temp, 5)
    new hasPowers = str_to_num(temp)

    //Reset thier shield restrict status
    //Shield restrict MUST be before weapons are given out
    shResetShield(id)

    switch(hasPowers)
    {
        case true:
        {
            gHasColorPower[id] = true

            if ( is_user_alive(id) )
            {
                color_weapons(id)
                switchmodel(id)
            }
        }

        case false:
        {
            // Check is needed since this gets run on clearpowers even if user didn't have this hero
            if ( is_user_alive(id) && gHasColorPower[id] )
            {
                // This gets run if they had the power but don't anymore
                engclient_cmd(id, "drop", "weapon_m4a1")
                shRemHealthPower(id)
                shRemArmorPower(id)
                shRemGravityPower(id)
            }

            gHasColorPower[id] = false
        }
    }
}
//----------------------------------------------------------------------------------------------
public Weapon_Event(id)
{    
    if(get_pcvar_num(g_Switch)==0)
    {
        return PLUGIN_HANDLED;
    }else{    
        new Weapon = read_data(2);
        new Clip = read_data(3);
    
        if(WeaponUsed[id] == 0)
        WeaponUsed[id] = Weapon;
    
        if((AmmoUsed[id] > Clip) && (WeaponUsed[id] == Weapon) && Weapon != 4 && Weapon != 6 && Weapon != 9 &&  Weapon != 25) 
        {
            create_bullet(id, Weapon);
        }
        WeaponUsed[id] = Weapon;
        AmmoUsed[id] = Clip;
        return 0;
    }
    return PLUGIN_HANDLED;
}
//----------------------------------------------------------------------------------------------
public create_bullet(id, Weapon)
 {
    new Bullets = create_entity("info_target");
    if(Bullets  > 0) 
    {
        new g_Weapon[33];
        new Float:Angle[3];
        new Float:Origin[3];
        new Float:AimVelocity[3];
        new Float:MinBox[3] = {-1.0, -1.0, -1.0};
        new Float:MaxBox[3] = {1.0, 1.0, 1.0};
        entity_get_vector(id, EV_VEC_origin, Origin);
        Origin[2] += 12.0;
        entity_set_string(Bullets, EV_SZ_classname, "BulletX");
        entity_set_model(Bullets, "models/shell.mdl");
        get_weaponname(Weapon, g_Weapon, 32);
        entity_set_string(Bullets, EV_SZ_targetname, g_Weapon);
        entity_get_vector(id, EV_VEC_v_angle, Angle);
        entity_set_vector(Bullets, EV_VEC_mins, MinBox);
        entity_set_vector(Bullets, EV_VEC_maxs, MaxBox);
        entity_set_origin(Bullets, Origin);
        entity_set_vector(Bullets, EV_VEC_angles, Angle);
        entity_set_vector(Bullets, EV_VEC_v_angle, Angle);
        entity_set_int(Bullets, EV_INT_effects, 2);
        entity_set_int(Bullets, EV_INT_solid, 2);
        entity_set_int(Bullets, EV_INT_movetype, 5);
        entity_set_edict(Bullets, EV_ENT_owner, id);
        
        if(Weapon != 3 && Weapon != 13 && Weapon != 18 && Weapon != 24)
        {            
            VelocityByAim(id, NORMALSPEED, AimVelocity);
        } else {
            VelocityByAim(id, SNIPERSPEED, AimVelocity);
        }
        entity_set_vector(Bullets, EV_VEC_velocity, AimVelocity);
        if( get_user_team( id ) == 1 )
        {
            set_rendering(Bullets, kRenderFxGlowShell , 218,165,032,kRenderNormal,100);
        }else{
            set_rendering(Bullets, kRenderFxGlowShell , 218,165,032,kRenderNormal,100);
        }
    }
    return 0;
}
//----------------------------------------------------------------------------------------------
public newSpawn(id)
{
    if ( shModActive() && gHasColorPower[id] && is_user_alive(id) )
        set_task(0.1, "color_weapons", id)
}
//----------------------------------------------------------------------------------------------
public remove_bullets(id)
{
    new ent = 0;
    do
    {
        ent = find_ent(ent, "BulletX");
        
        if(ent > 0) 
        {
            remove_entity(ent);
        }
    } while(ent)
}
//----------------------------------------------------------------------------------------------
public color_weapons(id)
{
    if ( !shModActive() || !is_user_alive(id) || !gHasColorPower[id] )
        return

    shGiveWeapon(id, "weapon_m4a1")
}
//----------------------------------------------------------------------------------------------
public switchmodel(id)
{
    if ( !shModActive() || !is_user_alive(id) || !gHasColorPower[id] )
        return

    new clip, ammo, wpnid = get_user_weapon(id, clip, ammo)

    if ( wpnid == CSW_M4A1 )
        set_pev(id, pev_viewmodel2, "models/shmod/color_m4a1.mdl")
}
//----------------------------------------------------------------------------------------------
public weaponChange(id)
{
    if ( !gHasColorPower[id] || !shModActive() )
        return

    new wpnid = read_data(2)

    if ( wpnid != CSW_M4A1 )
        return

    switchmodel(id)

    new clip = read_data(3)

    // Never Run Out of Ammo!
    if ( clip == 0 )
        shReloadAmmo(id)
}
//----------------------------------------------------------------------------------------------
public color_damage(id)
{
    if ( !shModActive() || !is_user_alive(id) )
        return

    new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)

    if ( attacker <= 0 || attacker > SH_MAXSLOTS )
        return

    if ( gHasColorPower[attacker] && weapon == CSW_M4A1 && is_user_alive(id) )
    {
        new damage = read_data(2)
        new headshot = bodypart == 1 ? 1 : 0

        // do extra damage
        new extraDamage = floatround(damage * get_pcvar_float(CvarM4A1DmgMult) - damage)
        if ( extraDamage > 0 )
            shExtraDamage(id, attacker, extraDamage, "m4a1", headshot)
    }
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
    gHasColorPower[id] = false
}
//----------------------------------------------------------------------------------------------
stock worldInVicinity(Float:origin[3]) {
  new ent = find_ent_in_sphere(-1, origin, 4.0)
  while(ent > 0)
  {
    if(entity_get_float(ent, EV_FL_health) > 0 || entity_get_float(ent, EV_FL_takedamage) > 0.0)
      return 0
    ent = find_ent_in_sphere(ent, origin, 4.0)
  }

  new Float:traceEnds[8][3], Float:traceHit[3], hitEnt

  traceEnds[0][0] = origin[0] - 2.0
  traceEnds[0][1] = origin[1] - 2.0
  traceEnds[0][2] = origin[2] - 2.0

  traceEnds[1][0] = origin[0] - 2.0
  traceEnds[1][1] = origin[1] - 2.0
  traceEnds[1][2] = origin[2] + 2.0

  traceEnds[2][0] = origin[0] + 2.0
  traceEnds[2][1] = origin[1] - 2.0
  traceEnds[2][2] = origin[2] + 2.0

  traceEnds[3][0] = origin[0] + 2.0
  traceEnds[3][1] = origin[1] - 2.0
  traceEnds[3][2] = origin[2] - 2.0

  traceEnds[4][0] = origin[0] - 2.0
  traceEnds[4][1] = origin[1] + 2.0
  traceEnds[4][2] = origin[2] - 2.0

  traceEnds[5][0] = origin[0] - 2.0
  traceEnds[5][1] = origin[1] + 2.0
  traceEnds[5][2] = origin[2] + 2.0

  traceEnds[6][0] = origin[0] + 2.0
  traceEnds[6][1] = origin[1] + 2.0
  traceEnds[6][2] = origin[2] + 2.0

  traceEnds[7][0] = origin[0] + 2.0
  traceEnds[7][1] = origin[1] + 2.0
  traceEnds[7][2] = origin[2] - 2.0

  for (new i = 0; i < 8; i++) {
    if (PointContents(traceEnds[i]) != CONTENTS_EMPTY)
    {
      return 1
    }

    hitEnt = trace_line(0, origin, traceEnds[i], traceHit)
    if (hitEnt != -1)
    {
      return 1
    }
    for (new j = 0; j < 3; j++) {
      if (traceEnds[i][j] != traceHit[j])
      {
        return 1
      }
    }
  }

  return 0
}

public make_color(id)
{
  new wpn = read_data(2)
  new ammo = read_data(3)
  
  new CsTeams:playert = cs_get_user_team(id)

  if(get_pcvar_num(color) == 1 && lastwpn[id] == wpn && lastammo[id] > ammo)
  {
    new iOrigin[3]
    get_user_origin(id, iOrigin, 4)
    new Float:fOrigin[3]
    IVecFVec(iOrigin, fOrigin)

    if(g_ballsnum < get_pcvar_num(color_maxballs) /*get_num_ents() < (global_get_int(GV_INT_maxEntities) - 100)*/ && worldInVicinity(fOrigin))
    {
      new ent = create_entity("info_target")
      if(ent > 0)
      {
        entity_set_string(ent, EV_SZ_classname, "color_ent")
        entity_set_int(ent, EV_INT_movetype, 0)
        entity_set_int(ent, EV_INT_solid, 0)
        entity_set_model(ent, g_colorSprite[random_num(0,1)])
        new r, g, b
        if(get_pcvar_num(color_randomcolor) == 0)
        {
          new i = random_num(0, MAX_COLORS-1)
          r = g_colorColors[i][0]
          g = g_colorColors[i][1]
          b = g_colorColors[i][2]
        }
        else if(get_pcvar_num(color_randomcolor) == 1)
        {
          r = random_num(64,255)
          g = random_num(64,255)
          b = random_num(64,255)
        }
    
        else if(get_pcvar_num(color_randomcolor) == 2)
         {
         if(playert == CS_TEAM_CT)
        {            
            r = 0
            g = 0
            b = 255
        }
        
        else 
        {
            r = 255
            g = 0
            b = 0
        }
    }
        
        set_rendering(ent, kRenderFxNoDissipation, r, g, b, kRenderGlow, 255)
        entity_set_origin(ent, fOrigin)
        entity_set_int(ent, EV_INT_flags, FL_ALWAYSTHINK)
        entity_set_float(ent, EV_FL_nextthink, get_gametime() + get_pcvar_float(color_lifetime))
        ++g_ballsnum
      }
    }
  }
  lastwpn[id] = wpn
  lastammo[id] = ammo
}

public pfn_think(entity) {
  if(entity > 0) {
    new class[32]
    entity_get_string(entity, EV_SZ_classname, class, 31)
    if(equal(class, "color_ent")) {
      remove_entity(entity)
      --g_ballsnum
    }
  }
}

public new_round()
{
  remove_entity_name("color_ent")
  g_ballsnum = 0
}
Artenis is offline
FukfaCe
Member
Join Date: Apr 2006
Old 08-19-2008 , 10:13   Re: Hero Is Made Wrong?
Reply With Quote #2

Not that I know so much about this, but when I see codes, then they don't have that much includes. I know that it is possible to code the includes out, well, some of them.

As I have seen by posts on this forum, it is not a good idea to have that many.

That was just an idea. I don't really know that much ^^
__________________
Jelles legeplads (DK) sh server (mine)

FukfaCe is offline
Send a message via MSN to FukfaCe
yang
Veteran Member
Join Date: May 2005
Location: galoreservers.net
Old 08-19-2008 , 19:35   Re: Hero Is Made Wrong?
Reply With Quote #3

includes are stock functions. If the function uses that stock function then you have to include that library. please learn b4 posting...
__________________
yang is offline
Send a message via AIM to yang
FukfaCe
Member
Join Date: Apr 2006
Old 08-19-2008 , 21:18   Re: Hero Is Made Wrong?
Reply With Quote #4

Well, I just saw once in a post, that some guy coded the includes gone, but I am also just a stupid guy who wanted to help ^^
__________________
Jelles legeplads (DK) sh server (mine)

FukfaCe is offline
Send a message via MSN to FukfaCe
Artenis
Member
Join Date: Mar 2008
Old 09-12-2008 , 23:02   Re: Hero Is Made Wrong?
Reply With Quote #5

well hey anyone got any INFO taht i could use.. since i cant find out whats wrong lol
Artenis is offline
MattFresh
Member
Join Date: Sep 2008
Location: Avondale, Arizona
Old 09-16-2008 , 01:28   Re: Hero Is Made Wrong?
Reply With Quote #6

In this line:

#define MAX_COLORS 10
#define NORMALSPEED 800
#define SNIPERSPEED 1100

^^ Where is your color_speed and stuff at?

You got the sniperspeed defined there, but inside your code, there's nothing else about it.

Or is that not even part of it?


Also, your lag could be from the size of everything in the superhero, or you just got too much.
It's just like having one million plugins on a server. If you have too many the server will end up lagging.
Maybe getting rid of some of the sprites or colors inside the superhero. Maybe jacking down on some entity's..?

-Matt
MattFresh is offline
Send a message via AIM to MattFresh Send a message via MSN to MattFresh
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 09-16-2008 , 08:22   Re: Hero Is Made Wrong?
Reply With Quote #7

Is this the full code? Cause there is no function find_ent(found in the remove_bullets function). Needs to be find_ent_by_class. Also no remove_entity_name function(called in new_round function). These may have been defined in the plugin your ripped from and you just didn't add them in properly.
__________________
If at first you don't succeed, then skydiving isn't for you.
G-Dog is offline
Send a message via AIM to G-Dog
MattFresh
Member
Join Date: Sep 2008
Location: Avondale, Arizona
Old 09-16-2008 , 12:23   Re: Hero Is Made Wrong?
Reply With Quote #8

Yea, if you haven't already fixed it would you like me to post the revised version I did for you?
MattFresh is offline
Send a message via AIM to MattFresh Send a message via MSN to MattFresh
Artenis
Member
Join Date: Mar 2008
Old 09-19-2008 , 08:16   Re: Hero Is Made Wrong?
Reply With Quote #9

gawsh lol.. yes, could i plz have it
Artenis is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:46.


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