AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hide entity help (https://forums.alliedmods.net/showthread.php?t=344910)

eNNkds 12-20-2023 05:53

Hide entity help
 
Hi i want with this forward to hide the ball entity when round start.

forward bb_round_started();

i make it only it resets when round start not hide it..

PHP Code:

// Version 1.0 : Menu + Orginal Bounc / kicking 
// Version 2.0 : Added Real soccerjamsounds / Got ball msg / Freezetimebug 
// Version 3.0 : Fixed Ball spawns every round 

#include <amxmodx> 
#include <engine> 
#include <fakemeta> 
#include <hamsandwich> 
#include <fun>
#include <basebuilder>

static const BALL_BOUNCE_GROUND[ ] = "kickball/bounce.wav"
static const 
g_szBallModel[ ]     = "models/basebuilder/ball.mdl"
static const 
g_szBallName[ ]      = "ball"

new 
g_iBallg_szFile128 ], g_szMapname32 ], g_iButtonsMenu
new 
bool:g_bNeedBall 
new Float:g_vOrigin]; 
new 
beamspr 

new ballcolor[3] = { 255,200,100 
new 
ballbeam[3] = { 20,50,255 
new 
kicked[] = "kickball/kicked.wav" 
new gotball[] = "kickball/gotball.wav" 

forward bb_round_started();

public 
plugin_init( ) { 
    
register_plugin"JailMod-Ball""3.0""ButterZ`" ); 
     
     
    
/* Register Forward */ 
    
register_forward(FM_PlayerPreThink"PlayerPreThink"0
     
    
/* Current Weapon */ 
    
register_event("CurWeapon""CurWeapon""be"); 
     
    
RegisterHamHam_ObjectCaps"player""FwdHamObjectCaps"); 
    
register_logevent"EventRoundStart"2"1=Round_Start" ); 
     
    
register_thinkg_szBallName"FwdThinkBall" ); 
    
register_touchg_szBallName"player""FwdTouchPlayer" ); 
     
    new const 
szEntity[ ][ ] = { 
        
"worldspawn""func_wall""func_door",  "func_door_rotating"
        
"func_wall_toggle""func_breakable""func_pushable""func_train"
        
"func_illusionary""func_button""func_rot_button""func_rotating" 
    

     
    for( new 
isizeof szEntityi++ ) 
        
register_touchg_szBallNameszEntity], "FwdTouchWorld" ); 
     
    
g_iButtonsMenu menu_create"BallMaker Menu""HandleButtonsMenu" ); 
     
    
menu_additemg_iButtonsMenu"Create Ball""1" ); 
    
menu_additemg_iButtonsMenu"Load Ball""2" ); 
    
menu_additemg_iButtonsMenu"Delete all Ball""3" ); 
    
menu_additemg_iButtonsMenu"Save""4" ); 
     
    
register_clcmd"say /ball""CmdButtonsMenu"ADMIN_RCON ); 
    
register_clcmd"say /reset""UpdateBall" ); 
}     
public 
PlayerPreThink(id) { 
    if(!
is_user_alive(id)) 
        return 
PLUGIN_CONTINUE
         
    if( 
is_valid_entg_iBall  ) ) { 
        static 
iOwneriOwner pevg_iBall pev_iuser1 ); 
        if( 
iOwner != id && get_user_maxspeed(id) != 1.0 )  
            
set_user_maxspeed(id230.0
    } 
    return 
PLUGIN_HANDLED

public 
CurWeapon(id) { 
    if(!
is_user_alive(id)) 
        return 
PLUGIN_CONTINUE
    if( 
is_valid_ent(g_iBall ) ) { 
        static 
iOwneriOwner pevg_iBall pev_iuser1 ); 
        if( 
iOwner == id 
            
set_user_maxspeed(id230.0
    }     
    return 
PLUGIN_HANDLED

public 
UpdateBallid ) { 
    if( !
id || get_user_flagsid ) & ADMIN_KICK ) { 
        if( 
is_valid_entg_iBall ) ) { 
            
entity_set_vector(g_iBall EV_VEC_velocityFloat:{ 0.00.00.0 } ); // To be sure ? 
            
entity_set_origing_iBall g_vOrigin ); 
             
            
entity_set_intg_iBall EV_INT_movetypeMOVETYPE_BOUNCE ); 
            
entity_set_sizeg_iBall Float:{ -15.0, -15.00.0 }, Float:{ 15.015.012.0 } ); 
            
entity_set_intg_iBall EV_INT_iuser1); 
        } 
    } 
     
    return 
PLUGIN_HANDLED


public 
plugin_precache( ) { 
    
precache_modelg_szBallModel ); 
    
precache_soundBALL_BOUNCE_GROUND ); 
     
    
beamspr precache_model"sprites/laserbeam.spr" ); 
    
precache_sound(kicked
    
precache_sound(gotball
     
    
get_mapnameg_szMapname31 ); 
    
strtolowerg_szMapname ); 
     
    
// File 
    
new szDatadir64 ]; 
    
get_localinfo"amxx_datadir"szDatadircharsmaxszDatadir ) ); 
     
    
formatexszDatadircharsmaxszDatadir ), "%s"szDatadir ); 
     
    if( !
dir_existsszDatadir ) ) 
        
mkdirszDatadir ); 
     
    
formatexg_szFilecharsmaxg_szFile ), "%s/ball.ini"szDatadir ); 
     
    if( !
file_existsg_szFile ) ) { 
        
write_fileg_szFile"// Ball Spawn Editor", -); 
        
write_fileg_szFile" ", -); 
         
        return; 
// We dont need to load file 
    

     
    new 
szData256 ], szMap32 ], szOrigin][ 16 ]; 
    new 
iFile fopeng_szFile"rt" ); 
     
    while( !
feofiFile ) ) { 
        
fgetsiFileszDatacharsmaxszData ) ); 
         
        if( !
szData] || szData] == ';' || szData] == ' ' || ( szData] == '/' && szData] == '/' ) ) 
            continue; 
         
        
parseszDataszMap31szOrigin], 15szOrigin], 15szOrigin], 15 ); 
         
        if( 
equalszMapg_szMapname ) ) { 
            new 
Float:vOrigin]; 
             
            
vOrigin] = str_to_floatszOrigin] ); 
            
vOrigin] = str_to_floatszOrigin] ); 
            
vOrigin] = str_to_floatszOrigin] ); 
             
            
CreateBall0vOrigin ); 
             
            
g_vOrigin vOrigin
             
            break; 
        } 
    } 
     
    
fcloseiFile ); 


public 
CmdButtonsMenuid ) { 
    if( 
get_user_flagsid ) & ADMIN_RCON 
        
menu_displayidg_iButtonsMenu); 
     
    return 
PLUGIN_HANDLED


public 
HandleButtonsMenuidiMenuiItem ) { 
    if( 
iItem == MENU_EXIT 
        return 
PLUGIN_HANDLED
     
    new 
szKey], _Access_Callback
    
menu_item_getinfoiMenuiItem_AccessszKey1""0_Callback ); 
     
    new 
iKey str_to_numszKey ); 
     
    switch( 
iKey ) { 
        case 
1:    { 
            if( 
pev_validg_iBall  ) ) 
                return 
PLUGIN_CONTINUE
                 
            
CreateBallid ); 
        } 
        case 
2: { 
            if( 
is_valid_entg_iBall  ) ) { 
                
entity_set_vectorg_iBall EV_VEC_velocityFloat:{ 0.00.00.0 } ); // To be sure ? 
                
entity_set_origing_iBall g_vOrigin ); 
                 
                
entity_set_intg_iBall EV_INT_movetypeMOVETYPE_BOUNCE ); 
                
entity_set_sizeg_iBall Float:{ -15.0, -15.00.0 }, Float:{ 15.015.012.0 } ); 
                
entity_set_intg_iBall EV_INT_iuser1); 
                
client_printidprint_chat"*** Loading Ball ***" ); 
            } 
        } 
        case 
3: { 
            new 
iEntity
             
            while( ( 
iEntity find_ent_by_classiEntityg_szBallName ) ) > 
                
remove_entityiEntity ); 
            
client_printidprint_chat"*** Ball Deleted ! ***" ); 
        } 
        case 
4: { 
            new 
iBalliEntityFloat:vOrigin]; 
             
            while( ( 
iEntity find_ent_by_classiEntityg_szBallName ) ) > 
                
iBall iEntity
             
            if( 
iBall 
                
entity_get_vectoriBallEV_VEC_originvOrigin ); 
            else 
                return 
PLUGIN_HANDLED
             
            new 
bool:bFoundiPosszData32 ], iFile fopeng_szFile"r+" ); 
             
            if( !
iFile 
                return 
PLUGIN_HANDLED
             
            while( !
feofiFile ) ) { 
                
fgetsiFileszData31 ); 
                
parseszDataszData31 ); 
                 
                
iPos++; 
                 
                if( 
equalszDatag_szMapname ) ) { 
                    
bFound true
                     
                    new 
szString256 ]; 
                    
formatexszString255"%s %f %f %f"g_szMapnamevOrigin], vOrigin], vOrigin] ); 
                     
                    
write_fileg_szFileszStringiPos ); 
                     
                    break; 
                } 
            } 
             
            if( !
bFound 
                
fprintfiFile"%s %f %f %f^n"g_szMapnamevOrigin], vOrigin], vOrigin] ); 
             
            
fcloseiFile ); 
             
            
client_printidprint_chat"*** Ball Saved ! ***" ); 
        } 
        default: return 
PLUGIN_HANDLED
    } 
     
    
menu_displayidg_iButtonsMenu); 
     
    return 
PLUGIN_HANDLED


public 
EventRoundStart(id) { 
    if( !
g_bNeedBall 
        return; 
     
    if( !
is_valid_entg_iBall  ) ) 
        
CreateBall0g_vOrigin ); 
    else { 
        
entity_set_vectorg_iBall EV_VEC_velocityFloat:{ 0.00.00.0 } ); // To be sure ? 
        
entity_set_origing_iBall g_vOrigin ); 
         
        
entity_set_intg_iBall EV_INT_solidSOLID_BBOX ); 
        
entity_set_intg_iBall EV_INT_movetypeMOVETYPE_BOUNCE ); 
        
entity_set_sizeg_iBall Float:{ -15.0, -15.00.0 }, Float:{ 15.015.012.0 } ); 
        
entity_set_intg_iBall EV_INT_iuser1); 
    }

public 
bb_round_started(){

    
engfuncEngFunc_SetOrigin g_iBall , { 9999.0 9999.0 9999.0 } );
}

public 
FwdHamObjectCapsid ) { 
    if( 
pev_validg_iBall  ) && is_user_aliveid ) ) { 
        static 
iOwneriOwner pevg_iBall pev_iuser1 ); 
         
        if( 
iOwner == id 
            
KickBallid ); 
    } 


// BALL BRAIN :) 
//////////////////////////////////////////////////////////// 
public FwdThinkBalliEntity ) { 
    if( !
is_valid_entg_iBall   ) ) 
        return 
PLUGIN_HANDLED
     
    
entity_set_floatiEntityEV_FL_nextthinkhalflife_time( ) + 0.05 ); 
     
    static 
Float:vOrigin], Float:vBallVelocity]; 
    
entity_get_vectoriEntityEV_VEC_originvOrigin ); 
    
entity_get_vectoriEntityEV_VEC_velocityvBallVelocity ); 
     
    static 
iOwneriOwner peviEntitypev_iuser1 ); 
    static 
iSolidiSolid peviEntitypev_solid ); 
     
     
    if( 
iOwner ) { 
        static 
Float:vOwnerOrigin]; 
        
entity_get_vectoriOwnerEV_VEC_originvOwnerOrigin ); 
         
        static const 
Float:vVelocity] = { 1.01.00.0 }; 
         
        if( !
is_user_aliveiOwner ) ) { 
            
entity_set_intiEntityEV_INT_iuser1); 
             
            
vOwnerOrigin] += 5.0
             
            
entity_set_originiEntityvOwnerOrigin ); 
            
entity_set_vectoriEntityEV_VEC_velocityvVelocity ); 
             
            return 
PLUGIN_CONTINUE
        } 
         
        if( 
iSolid != SOLID_NOT 
            
set_peviEntitypev_solidSOLID_NOT ); 
         
        static 
Float:vAngles], Float:vReturn]; 
        
entity_get_vectoriOwnerEV_VEC_v_anglevAngles ); 
         
        
vReturn] = ( floatcosvAngles], degrees ) * 55.0 ) + vOwnerOrigin]; 
        
vReturn] = ( floatsinvAngles], degrees ) * 55.0 ) + vOwnerOrigin]; 
        
vReturn] = vOwnerOrigin]; 
        
vReturn] -= ( entity_get_intiOwnerEV_INT_flags ) & FL_DUCKING ) ? 10 30
         
        
entity_set_vectoriEntityEV_VEC_velocityvVelocity ); 
        
entity_set_originiEntityvReturn ); 
    } else { 
        if( 
iSolid != SOLID_BBOX 
            
set_peviEntitypev_solidSOLID_BBOX ); 
         
        static 
Float:flLastVerticalOrigin
         
        if( 
vBallVelocity] == 0.0 ) { 
            static 
iCounts
             
            if( 
flLastVerticalOrigin vOrigin] ) { 
                
iCounts++; 
                 
                if( 
iCounts 10 ) { 
                    
iCounts 0
                     
                    
UpdateBall); 
                } 
            } else { 
                
iCounts 0
                 
                if( 
PointContentsvOrigin ) != CONTENTS_EMPTY 
                    
UpdateBall); 
            } 
             
            
flLastVerticalOrigin vOrigin]; 
        } 
    } 
     
    return 
PLUGIN_CONTINUE


KickBallid ) { 
    
set_user_maxspeed(id230.0
    static 
Float:vOrigin]; 
    
entity_get_vectorg_iBall EV_VEC_originvOrigin ); 
     
    
vOrigin[2] += 35
     
    if( 
PointContentsvOrigin ) != CONTENTS_EMPTY 
        return 
PLUGIN_HANDLED

    new 
Float:vVelocity]; 
    
velocity_by_aimid650vVelocity ); 
     
    
beam(10
    
emit_sound(g_iBallCHAN_ITEMkicked1.0ATTN_NORM0PITCH_NORM
     
    
set_pevg_iBall pev_solidSOLID_BBOX ); 
    
entity_set_sizeg_iBall Float:{ -15.0, -15.00.0 }, Float:{ 15.015.012.0 } ); 
    
entity_set_intg_iBall EV_INT_iuser1); 
    
entity_set_origin(g_iBall,vOrigin
    
entity_set_vectorg_iBall EV_VEC_velocityvVelocity ); 
         
    return 
PLUGIN_CONTINUE


// BALL TOUCHES 
//////////////////////////////////////////////////////////// 
public FwdTouchPlayerBallid ) { 
    if( 
is_user_botid ) ) 
        return 
PLUGIN_CONTINUE
     
    static 
iOwneriOwner pevBallpev_iuser1 ); 
     
    if( 
iOwner == ) { 
        
entity_set_intBallEV_INT_iuser1id ); 
        
beam(10
        
emit_sound(BallCHAN_ITEMgotball1.0ATTN_NORM0PITCH_NORM); 
        
set_hudmessage(2552020, -1.00.411.01.50.10.12
        
show_hudmessage(id,"*** YOU HAVE THE BALL! ***"
        
set_user_maxspeed(id230.0
    } 
    return 
PLUGIN_CONTINUE


public 
FwdTouchWorldBallWorld ) { 
    static 
Float:vVelocity]; 
    
entity_get_vectorBallEV_VEC_velocityvVelocity ); 
     
    if( 
floatroundvector_lengthvVelocity ) ) > 10 ) { 
        
vVelocity] *= 0.85
        
vVelocity] *= 0.85
        
vVelocity] *= 0.85
         
        
entity_set_vectorBallEV_VEC_velocityvVelocity ); 
         
        
emit_soundBallCHAN_ITEMBALL_BOUNCE_GROUND1.0ATTN_NORM0PITCH_NORM ); 
    } 

    return 
PLUGIN_CONTINUE



// ENTITIES CREATING 
//////////////////////////////////////////////////////////// 
CreateBallidFloat:vOrigin] = { 0.00.00.0 } ) { 
    if( !
id && vOrigin] == 0.0 && vOrigin] == 0.0 && vOrigin] == 0.0 
        return 
0
     
    
g_bNeedBall true
     
    
g_iBall create_entity"info_target" ); 
     
    if( 
is_valid_entg_iBall ) ) { 
        
entity_set_stringg_iBall EV_SZ_classnameg_szBallName ); 
        
entity_set_intg_iBall EV_INT_solidSOLID_BBOX ); 
        
entity_set_intg_iBall EV_INT_movetypeMOVETYPE_BOUNCE ); 
        
entity_set_modelg_iBall g_szBallModel ); 
        
entity_set_sizeg_iBall Float:{ -15.0, -15.00.0 }, Float:{ 15.015.012.0 } ); 
         
        
entity_set_floatg_iBall EV_FL_framerate0.0 ); 
        
entity_set_intg_iBall EV_INT_sequence); 
         
        
entity_set_float(g_iBall EV_FL_nextthinkget_gametime( ) + 0.05 ); 
     
        
glow(g_iBall,ballcolor[0],ballcolor[1],ballcolor[2],10
         
        
//client_print( id, print_chat, "*** Ball Spawned! ***" ); 
         
        
if( id ) { 
            new 
iOrigin]; 
            
get_user_originidiOrigin); 
            
IVecFVeciOriginvOrigin ); 
             
            
vOrigin] += 5.0
             
            
entity_set_origing_iBall vOrigin ); 
        } else 
            
entity_set_origing_iBall vOrigin ); 
         
        
g_vOrigin vOrigin
         
        return 
g_iBall 
    } 
     
    return -
1


beam(life) { 
    
message_begin(MSG_BROADCAST,SVC_TEMPENTITY); 
    
write_byte(22); // TE_BEAMFOLLOW 
    
write_short(g_iBall); // ball 
    
write_short(beamspr); // laserbeam 
    
write_byte(life); // life 
    
write_byte(5); // width 
    
write_byte(ballbeam[0]); // R 
    
write_byte(ballbeam[1]); // G 
    
write_byte(ballbeam[2]); // B 
    
write_byte(175); // brightness 
    
message_end();     

glow(idrgbon) { 
    if(
on == 1) { 
        
set_rendering(idkRenderFxGlowShellrgbkRenderNormal255
        
entity_set_float(idEV_FL_renderamt1.0
    } 
    else if(!
on) { 
        
set_rendering(idkRenderFxNonergb,  kRenderNormal255
        
entity_set_float(idEV_FL_renderamt1.0
    } 
    else if(
on == 10) { 
        
set_rendering(idkRenderFxGlowShellrgbkRenderNormal255
        
entity_set_float(idEV_FL_renderamt1.0
    } 



georgik57 12-20-2023 06:56

Re: Hide entity help
 
You already have a round start forward. Replace createball with your code from inside the bb forward. Better make it ef_nodraw too instead of setting origin.


All times are GMT -4. The time now is 00:33.

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