Raised This Month: $32 Target: $400
 8% 

[help] at4 launcher not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jc980
Veteran Member
Join Date: Jan 2010
Location: God is with us...
Old 11-29-2010 , 03:41   [help] at4 launcher not working
Reply With Quote #1

hey guys can anyone help me here?

I got a bit of a problem with this simple rocket launcher plugin that i made.

the problem is that when i kill an enemy my CS hangs then crashes.

heres the sma:
PHP Code:
/* [CSO Zombie Scenario 2.7] - AT4 Rocket Launcher Extra Item */ 

#include <amxmodx> 
#include <amxmisc> 
#include <fakemeta> 
#include <fakemeta_util> 
#include <fun> 
#include <hamsandwich> 
#include <cstrike> 
#include <engine> 

#define TASK_HUDAMMO        1337 
#define ID_HUDAMMO (taskid - TASK_HUDAMMO) 
#define fm_find_ent_by_class(%1,%2)    engfunc(EngFunc_FindEntityByString, %1, "classname", %2) 


new const PLUGIN[]     = "CSO ZBS WPN AT4 Launcher"
new const 
VERSION[]     = "1.0"
new const 
AUTH[]         = "jc980,tuty"

new const 
P_AT4_MODEL[]     = "models/cso/p_at4.mdl" 
new const V_AT4_MODEL[]     = "models/cso/v_at4.mdl" 
new const W_AT4_MODEL[]     = "models/cso/w_at4.mdl" 
new ROCKET_MODEL[]     = "models/cso/s_at4.mdl"
new 
ROCKET_SOUND[]    = "weapon/at4_fire.wav"
new 
ROCKET_EXP_SOUND[]    = "weapon/at4_explode.wav"
new 
rocket_trail[]         = "sprites/smoke.spr"
new 
rocket_explode[]        = "sprites/cso/at4_exp.spr"
new 
rocket_smokesZ[]    = "sprites/steam1.spr"
new 
rocket_classname[]    = "at4_launcher"

new 
Float:was_rocket[33]; 
new  
trail2explode2smokesZ2
new 
g_toggle_enableg_toggle_speedg_toggle_delayg_toggle_trail_width
new 
g_toggle_damageradiusg_toggle_rocket_damageg_maxplayers
new 
gMsgIDgDmsgID 
new g_hasAT4[33// whether player has AT4 
new g_FireAT4[33// player is shooting 
new g_canShoot[33// player can shoot 
new rocket_count[33// current grenade count 
new Float:g_last_shot_time[33// last shot time 
new g_restarted // whether game was restarted 
new rocket_cost 
new rockets_cost 
new SayText 

public plugin_init() { 
     
    
register_plugin(PLUGINVERSIONAUTH); 
     
    
register_forward(FM_Touch"pfn_touch" ); 
    
register_forward(FM_Touch"fw_Touch"
    
register_forward(FM_SetModel"fw_SetModel"); 
    
register_forward(FM_StartFrame"server_frame"); 
    
register_forward(FM_CmdStart"fw_CmdStart"
    
register_forward(FM_PlayerPostThink"fw_PlayerPostThink"
    
register_forward(FM_UpdateClientData"fw_UpdateClientData_Post"1
     
    
RegisterHam(Ham_Killed"player""fw_PlayerKilled"
     
    
register_event("CurWeapon""Event_CurrentWeapon""be""1=1"
    
register_event("HLTV""Event_NewRound""a""1=0""2=0"); 
    
register_event("TextMsg""Event_GameRestart""a""2=#Game_Commencing""2=#Game_will_restart_in"); 
     
    
register_logevent("logevent_round_end"2"1=Round_End"); 
     
    
register_clcmd("say /csozbswpn_at4""CmdBuyIt"
    
register_clcmd("cso_zbs_wpn_at4""CmdBuyIt"
    
register_clcmd("say /csozbswpn_rockets","CmdBuyAmmo"
    
register_clcmd("cso_zbs_wpn_rockets","CmdBuyAmmo"
     
    
g_toggle_enable register_cvar("cso_zbs_at4_enable""1");// 1-enabled/2-disabled 
    
g_toggle_speed register_cvar("cso_zbs_at4_speed","5000");// rocket speed 
    
g_toggle_delay register_cvar("cso_zbs_at4_delay","3.0"); // rocket delay 
    
g_toggle_damageradius register_cvar("cso_zbs_at4_dmg_radius""500");// rocket explode radius damage 
    
g_toggle_rocket_damage register_cvar("cso_zbs_at4_dmg""250");// rocket damage when hit someone 
    
g_toggle_trail_width register_cvar("cso_zbs_at4_trail_width""5");// trail width 
    
rocket_cost register_cvar("cso_zbs_at4_cost","1000");//Cost Price 
    
rockets_cost register_cvar("cso_zbs_rockets_cost","500")//Rockets Cost price 
     
    
gMsgID get_user_msgid("Damage"); 
    
gDmsgID get_user_msgid("DeathMsg"); 
    
g_maxplayers get_maxplayers(); 
    
SayText get_user_msgid("SayText"
     
    
set_task(10.0"hud_init"TASK_HUDAMMO__"b"


public 
Event_NewRound(id

    if (
g_restarted
    { 
        for (new 
1<= get_maxplayers(); i++) 
        { 
            
g_hasAT4[i] = false 
            remove_task
(i+TASK_HUDAMMO
        } 
        
g_restarted false 
    



public 
Event_GameRestart() 

    
g_restarted true 


public 
Event_CurrentWeapon(id

    
// Read weapon ID 
    
new weaponID read_data(2
     
    if (
weaponID == CSW_P90
    { 
        if (
g_hasAT4[id]) 
        { 
            
// View model 
            
entity_set_string(idEV_SZ_viewmodelV_AT4_MODEL
             
            
// Player model 
            
entity_set_string(idEV_SZ_weaponmodelP_AT4_MODEL
        } 
    } 


// Set model         
public fw_SetModel(ent, const model[]) 

    
// Invalid entity 
    
if (!pev_valid(ent))     
        return 
FMRES_IGNORED 
     
    
// Not needed model 
    
if(!equali(model"models/w_p90.mdl"))  
        return 
FMRES_IGNORED 
     
    
// Get owner and classname 
    
new owner pev(entpev_owner
    new 
classname[33]; pev(entpev_classnameclassnamecharsmax(classname)) 
     
    
// Entity classname is a weaponbox 
    
if(equal(classname"weaponbox")) 
    { 
        if(
g_hasAT4[owner]) 
        { 
            
g_hasAT4[owner] = false 
             
            
// Set world model 
            
engfunc(EngFunc_SetModelentW_AT4_MODEL
             
            
// Touch fix 
            
set_task(0.1"touch_fix"owner
             
            
// Remove HUD 
            
remove_task(owner+TASK_HUDAMMO
             
            return 
FMRES_SUPERCEDE 
        

    } 
     
    return 
FMRES_IGNORED 
     


public 
touch_fix(id

if (
g_hasAT4[id]) 
    
g_hasAT4[id] = false 


public 
client_connect(id

    
// Reset all 
    
g_hasAT4[id] = false 
    g_canShoot
[id] = false 
    g_last_shot_time
[id] = 0.0 
    rocket_count
[id] = 


public 
client_disconnect(id

    
// Reset all 
    
g_hasAT4[id] = false 
    g_canShoot
[id] = false 
    g_last_shot_time
[id] = 0.0 
    rocket_count
[id] = 


public 
CmdBuyIt(id

    
// Plugin not enabled 
    
if (get_pcvar_num(g_toggle_enable) == 0
        return 
PLUGIN_CONTINUE 
     
    
// Ignore dead 
    
if (!is_user_alive(id)) 
        return 
PLUGIN_CONTINUE 
     
    
// Already own 
    
if (g_hasAT4[id] || user_has_weapon(idCSW_P90)) 
    { 
        
cso_zbs_colorprint(id"^4[^3CSO ZBS 2.7 WPN^4] -^1 You already own this weapon"
        return 
PLUGIN_CONTINUE 
    

    
// Not enough money 
    
if (cs_get_user_money(id) < get_pcvar_num(rocket_cost)) 
    { 
        
cso_zbs_colorprint(id,"^4[^3CSO ZBS 2.7 WPN^4] -^1 You don't have enough money."
        return 
PLUGIN_CONTINUE 
    

     
    
// Otherwise all is OK 
    
cso_zbs_colorprint(id"^4[^3CSO ZBS 2.7 WPN^4] -^1 You bought ^3AT4 Rocket Launcher"
    
give_item(id"weapon_p90"
    
cs_set_user_money(idcs_get_user_money(id) - get_pcvar_num(rocket_cost)) 
    
g_hasAT4[id] = true 
    g_canShoot
[id] = true 
    rocket_count
[id] = 10 
    set_task
(10.0"hud_init"id+TASK_HUDAMMO__"b"
     
    return 
PLUGIN_CONTINUE 


public 
CmdBuyAmmo(id

    
// Plugin not enabled 
    
if (get_pcvar_num(g_toggle_enable) == 0
        return 
PLUGIN_CONTINUE 
     
    
// Ignore dead 
    
if (!is_user_alive(id)) 
        return 
PLUGIN_CONTINUE 
     
    
// Already own 
    
if (g_hasAT4[id] || user_has_weapon(idCSW_P90)) 
    { 
        
// Not enough money 
        
if (cs_get_user_money(id) < get_pcvar_num(rockets_cost)) 
        { 
            
cso_zbs_colorprint(id,"^4[CSO ZBS^3  2.7 ^4WPN] -^1 You don't have enough money."
            return 
PLUGIN_CONTINUE 
        

        else 
        { 
        
// Otherwise all is OK 
        
cso_zbs_colorprint(id"^4[CSO ZBS^3  2.7 ^4WPN] -^1 You bought ^3AT4 Rocket Launcher Ammo"
        
cs_set_user_money(idcs_get_user_money(id) - get_pcvar_num(rockets_cost)) 
        
g_hasAT4[id] = true 
        rocket_count
[id] = 10 
        

    } 
    return 
PLUGIN_CONTINUE 


public 
fw_Touch(enttoucher

    
// Invalid ent/toucher 
    
if(!pev_valid(ent) || !pev_valid(toucher)) 
        return 
FMRES_IGNORED
     
    
// Get model, toucherclass, entityclass 
    
new model[33], toucherclass[33], entityclass[33
    
pev(entpev_modelmodelcharsmax(model)) 
    
pev(entpev_classnameentityclasscharsmax(entityclass)) 
    
pev(toucherpev_classnametoucherclasscharsmax(toucherclass)) 
     
    
// TOucher isn't player and entity isn't weapon 
    
if (!equali(toucherclass"player") || !equali(entityclass"weaponbox")) 
        return 
FMRES_IGNORED 
     
    
// Our world model 
    
if(equali(modelW_AT4_MODEL)) 
    { 
        
// If allowed to touch 
        
if(allowed_toucher(toucher)) 
        { 
            
// Pick up weapon 
            
g_hasAT4[toucher] = true 
            g_canShoot
[toucher] = true 
            g_FireAT4
[toucher] = false 
        

    } 
     
    return 
FMRES_IGNORED


public 
server_frame() 

    if(
get_pcvar_num(g_toggle_enable) == 0
        return 
FMRES_IGNORED
         
    return 
FMRES_IGNORED


public 
plugin_precache() 

    
engfunc(EngFunc_PrecacheModelROCKET_MODEL); 
    
engfunc(EngFunc_PrecacheModelV_AT4_MODEL); 
    
engfunc(EngFunc_PrecacheModelP_AT4_MODEL); 
    
engfunc(EngFunc_PrecacheModelW_AT4_MODEL); 
    
engfunc(EngFunc_PrecacheSoundROCKET_SOUND); 
    
engfunc(EngFunc_PrecacheSoundROCKET_EXP_SOUND); 
    
trail2 engfunc(EngFunc_PrecacheModelrocket_trail); 
    
explode2 engfunc(EngFunc_PrecacheModelrocket_explode); 
    
smokesZ2 engfunc(EngFunc_PrecacheModelrocket_smokesZ); 

public 
fw_CmdStart(iduc_handleseed)  
{     
    if(
get_pcvar_num(g_toggle_enable) == 0
        return 
PLUGIN_HANDLED
         
    
// Ignore dead 
    
if (!is_user_alive(id)) 
        return 
FMRES_IGNORED 
     
    
// Don't have our weapon     
    
if (!g_hasAT4[id]) 
        return 
FMRES_IGNORED 
     
    
// Get ammo, clip, weapon     
    
new ammoclipweapon get_user_weapon(idclipammo
     
    
// Not replaced weapon 
    
if (weapon != 30
        return 
FMRES_IGNORED 
         
    
new button pev(idpev_button); 
     
    new 
buttons get_uc(uc_handleUC_Buttons
     
    if(
button IN_ATTACK
    {         
        
g_FireAT4[id] = true 
        buttons 
&= ~IN_ATTACK 
        set_uc
(uc_handleUC_Buttonsbuttons
    } 
    else  
        
g_FireAT4[id] = false 
     
    
return FMRES_HANDLED 


public 
fw_UpdateClientData_Post(idsendweaponscd_handle)  

    
// Dead 
    
if (!is_user_alive(id)) 
        return 
FMRES_IGNORED 
     
    
// Don't have our weapon     
    
if (!g_hasAT4[id]) 
        return 
FMRES_IGNORED 
     
    
// Get ammo, clip, weapon 
    
new ammoclipweapon get_user_weapon(idclipammo
     
    
// Not replaced weapon 
    
if (weapon != 30
        return 
FMRES_IGNORED 
     
    
// Block default sounds     
    
set_cd(cd_handleCD_ID0
    return 
FMRES_HANDLED 


public 
fw_PlayerPostThink(id

    
// ignore dead 
    
if (!is_user_alive(id)) 
        return 
FMRES_IGNORED 
     
    
// Don't have our weapon     
    
if (!g_hasAT4[id]) 
        return 
FMRES_IGNORED 
     
    
// Get ammo, clip, and weapon     
    
new ammoclipweapon get_user_weapon(idclipammo
     
    
// Not our replaced weapon 
    
if (weapon != 30
        return 
FMRES_IGNORED 
     
    
// If player is firing     
    
if (g_FireAT4[id]) 
    { 
        
// Grenades are more or equal to 1 
        
if (rocket_count[id] >= 1
        { 
            
// Player can shoot 
            
if (get_gametime() - g_last_shot_time[id] > 1.0
            { 
                
// Fire!!! 
                
launch_rocket(id
                 
                
// Decrease nade count 
                
rocket_count[id]-- 
                 
                
// Remember last shot time 
                
g_last_shot_time[id] = get_gametime() 
            } 
        } 
        else 
        { 
            
// Don't have nades 
            
cso_zbs_colorprint(id"^4[CSO ZBS^3  2.7 ^4WPN] -^1 Out of Rockets!"
        } 
    } 
     
    return 
FMRES_IGNORED 


// HUD init     
public hud_init(taskid

    new 
HudAmmo[65
     
    if (
g_hasAT4[ID_HUDAMMO])         
    { 
        
format(HudAmmo64"^4[^3CSO ZBS 2.7 WPN^4] -^1 Rockets Remaining: ^3%d"rocket_count[ID_HUDAMMO]) 
        
cso_zbs_colorprint(ID_HUDAMMO,HudAmmo
    } 


public 
fw_PlayerKilled(victimattackershouldgib

    if (
g_hasAT4[victim])         
    { 
        
// Reset all 
        
g_hasAT4[victim] = false 
        g_canShoot
[victim] = false 
        g_FireAT4
[victim] = false 
        rocket_count
[victim] = 
         
        
// Remove HUD 
        
remove_task(victim+TASK_HUDAMMO
    } 


public 
launch_rocket(id

    new 
Float:nexTime get_gametime(); 
    if(
was_rocket[id] > nexTime
    {     
        return 
PLUGIN_CONTINUE
    } 
    else 
    { 
        new 
rocket engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target")); 
         
        if(
rocket == 0)  
            return 
PLUGIN_CONTINUE
         
        
set_pev(idpev_weaponanim4
        
set_pev(rocketpev_classnamerocket_classname); 
        
engfunc(EngFunc_SetModelrocketROCKET_MODEL); 
        
set_pev(rocketpev_sizeFloat:{0.00.00.0}, Float:{0.00.00.0}); 
        
set_pev(rocketpev_movetypeMOVETYPE_FLY); 
        
set_pev(rocketpev_solidSOLID_BBOX); 
         
        new 
Float:vSrc[3]; 
        
pev(idpev_originvSrc); 
        new 
Float:Aim[3], Float:origin[3]; 
        
velocity_by_aim(id64Aim); 
        
pev(id,pev_origin,origin); 
         
        
vSrc[0] += Aim[0]; 
        
vSrc[1] += Aim[1]; 

        
engfunc(EngFunc_SetOriginrocketvSrc); 
        new 
Float:velocity[3], Float:angles[3]; 
         
        
velocity_by_aim(idget_pcvar_num(g_toggle_speed), velocity); 
        
set_pev(rocketpev_velocityvelocity); 
        
vector_to_angle(velocityangles); 
        
set_pev(rocketpev_anglesangles); 
        
set_pev(rocketpev_owner,id); 
        
set_pev(rocketpev_takedamage1.0); 
         
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY); 
        
write_byte(TE_BEAMFOLLOW); 
        
write_short(rocket); 
        
write_short(trail2); 
        
write_byte(25); 
        
write_byte(get_pcvar_num(g_toggle_trail_width)); 
        
write_byte(200); 
        
write_byte(200); 
        
write_byte(200); 
        
write_byte(255); 
        
message_end(); 

        
emit_sound(rocketCHAN_WEAPONROCKET_SOUND1.0ATTN_NORM0PITCH_NORM); 
        
was_rocket[id] = nexTime get_pcvar_float(g_toggle_delay); 
    } 
    return 
PLUGIN_CONTINUE

public 
pfn_touch(ptrptd
{     
    if(
get_pcvar_num(g_toggle_enable) == 1
    { 
        if(
pev_valid(ptr)) 
        {     
            new 
classname[32]; 
            
pev(ptrpev_classnameclassname31); 
         
            if(
equal(classnamerocket_classname)) 
            {     
                new 
Float:fOrigin[3]; 
                new 
iOrigin[3]; 
                
pev(ptrpev_originfOrigin); 
                
FVecIVec(fOrigin,iOrigin); 
             
                
nade_radius_damage(ptr); 
                 
                
emit_sound(ptrCHAN_WEAPONROCKET_EXP_SOUND1.0ATTN_NORM0PITCH_NORM); 
                
message_begin(MSG_BROADCAST,SVC_TEMPENTITY,iOrigin); 
                
write_byte(TE_EXPLOSION); 
                
write_coord(iOrigin[0]); 
                
write_coord(iOrigin[1]); 
                
write_coord(iOrigin[2]); 
                
write_short(explode2); 
                
write_byte(60); 
                
write_byte(15); 
                
write_byte(0); 
                
message_end(); 
             
                
message_begin(MSG_BROADCASTSVC_TEMPENTITY); 
                
write_byte(TE_SMOKE); 
                
write_coord(iOrigin[0]); 
                
write_coord(iOrigin[1]); 
                
write_coord(iOrigin[2]); 
                
write_short(smokesZ2); 
                
write_byte(40); 
                
write_byte(5); 
                
message_end(); 
                 
                
engfunc(EngFunc_RemoveEntityptr); 
            } 
        } 
    } 

public 
logevent_round_end() 

    if(
get_pcvar_num(g_toggle_enable) == 1
    { 
        new 
ent = -1
        while((
ent fm_find_ent_by_class(entrocket_classname))) 
            
engfunc(EngFunc_RemoveEntityent);         
    } 

stock nade_radius_damage(entity
{     
    new 
id pev(entitypev_owner); 
     
    new 
i
    for(
1<= g_maxplayersi++) 
    {     
        if(
is_user_alive(i)) 
        {     
            new 
dist floatround(fm_entity_range(entity,i)); 
             
            if(
dist <= get_pcvar_num(g_toggle_damageradius)) 
            {     
                new 
hp get_user_health(i); 
                new 
Float:damage get_pcvar_float(g_toggle_rocket_damage)-(get_pcvar_float(g_toggle_rocket_damage) / get_pcvar_float(g_toggle_damageradius))*float(dist); 
                 
                new 
Origin[3]; 
                
get_user_origin(i,Origin); 
                if(!
get_cvar_num("mp_friendlyfire")) 
                {     
                    if(
get_user_team(id) != get_user_team(i)) 
                    {     
                        if(
hp damage
                        { 
                            
nade_take_damage(ifloatround(damage), OriginDMG_BLAST); 
                        } 
                        else 
                        { 
                            
nade_kill(idi"** CSO ZBS WPN AT4-Launcher **"0); 
                        } 
                    } 
                } 
            } 
        } 
    } 

stock nade_take_damage(victim,damage,origin[3],bit

    
message_begin(MSG_ONE_UNRELIABLEgMsgID,{0,0,0}, victim); 
    
write_byte(21); 
    
write_byte(20); 
    
write_long(bit); 
    
write_coord(origin[0]); 
    
write_coord(origin[1]); 
    
write_coord(origin[2]); 
    
message_end(); 
     
    
fm_set_user_health(victimget_user_health(victim) - damage); 

stock nade_kill(killervictimweapon[],headshot

    
set_msg_block(gDmsgID BLOCK_ONCE); 
    
user_kill(victim1); 
    
set_msg_block(gDmsgIDBLOCK_NOT); 
     
    
message_begin(MSG_ALLgDmsgID, {0,0,0}, 0); 
    
write_byte(killer); 
    
write_byte(victim); 
    
write_byte(headshot); 
    
write_string(weapon); 
    
message_end(); 
     
     return 
1


stock allowed_toucher(player

    
// Already has it 
    
if (g_hasAT4[player] || cs_get_user_team(player) == CS_TEAM_T
        return 
false 
     
    
return true 


stock cso_zbs_colorprint(const id, const input[], any:...)  
{  
    new 
count 1players[32];  
    static 
msg[191];  
    
vformat(msg190input3);  
    
replace_all(msg190"!g""^4"); // Green Color  
    
replace_all(msg190"!y""^1"); // Default Color (?©°  ??«??©)  
    
replace_all(msg190"!t""^3"); // Team Color  
    
if (idplayers[0] = id; else get_players(playerscount"ch");  
    {  
    for ( new 
0counti++ )  
        {      
        if ( 
is_user_connected(players[i]) )  
            {  
                
message_begin(MSG_ONE_UNRELIABLESayText_players[i]);  
                
write_byte(players[i]);  
                
write_string(msg);  
                
message_end();  
            }  
        }  
    }  

i dont know whats causing it.

PS this launcher uses p90 weapon.
__________________
jc980 is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 08-11-2013 , 06:40   Re: [help] at4 launcher not working
Reply With Quote #2

Up, I got this trouble too, any fix?
Randomize is offline
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 08-11-2013 , 08:35   Re: [help] at4 launcher not working
Reply With Quote #3

It might have something to do with removing entity. I'm lazy to read the whole code, so please help yourself by rechecking codes that deals with removing the entites.
kNowo is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 08-11-2013 , 08:51   Re: [help] at4 launcher not working
Reply With Quote #4

Are you sure it deals with remove entity? What causes remove entity crash the CS?
Randomize is offline
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 08-11-2013 , 10:15   Re: [help] at4 launcher not working
Reply With Quote #5

- removing entities that shouldn't be removed such as "player" entities
- removing entities thats invalid or doesn't exist

Like I said, I didn't read the code and I was just pointing out one of the reason that might be causing the server to hang/crash. Try commenting those lines that removing entities, just for sake of testing and see if the crashes stop.
kNowo is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 08-11-2013 , 22:07   Re: [help] at4 launcher not working
Reply With Quote #6

Okay, Understand. Thanks
Randomize 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 08:53.


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