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
}