AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MOVETYPE_TOSS and touch event (https://forums.alliedmods.net/showthread.php?t=277568)

DavidLin 01-11-2016 14:17

MOVETYPE_TOSS and touch event
 
Hello, I made a code where zombie shots an entity and when a player touches the entity it gives him a green screen while the entity is being in the air, and when there is more than one player in the entity's way only one player gets the green screen.

PHP Code:


public plugin_init( ) {
    
register_touch"vomit_entity""*""vomit_touch" );
    
msgidFade  get_user_msgid"ScreenFade" );
}

public 
VomitDoid ) {
    
// New vomit in progress //
    
new Float:vOrigin], Float:vAngles], Float:vVelocity];

    
entity_get_vectoridEV_VEC_originvOrigin );
    
entity_get_vectoridEV_VEC_v_anglevAngles );

    new 
vomit_ent create_entity"info_target" );
    
entity_set_stringvomit_entEV_SZ_classname"vomit_entity" );
    
entity_set_modelvomit_entspit_model );
    
entity_set_sizevomit_entminModelmaxModel );

    
entity_set_originvomit_entvOrigin );
    
entity_set_vectorvomit_entEV_VEC_anglesvAngles );
    
entity_set_intvomit_entEV_INT_solidSOLID_SLIDEBOX );
    
entity_set_intvomit_entEV_INT_movetypeMOVETYPE_TOSS );
    
entity_set_edictvomit_entEV_ENT_ownerid );

    
set_renderingvomit_entkRenderFxGlowShell7918061kRenderNormal25 );

    
velocity_by_aimid700vVelocity );
    
entity_set_vectorvomit_entEV_VEC_velocityvVelocity );
}
public 
vomit_touchvomitEntvictim ) {
    if( !
pev_validvomitEnt ) )
        return;

    static 
vEnt32 ];
    
pevvictimpev_classnamevEntcharsmaxvEnt ) );
    if( 
equalvEnt"player" ) ) {
        if( 
is_user_alivevictim ) && !is_zombievictim ) ) {
            
vomitedUservictim );
        }
    }


What could be the problem ?

Perrytutoriales 01-11-2016 14:51

Re: MOVETYPE_TOSS and touch event
 
Use a Radius, Use this function and modify, put in to the register touch public

PHP Code:


#define RADIUS    500.0  // a Radius of 500 Unitys Half life Medition

#define is_player(%0)    (1 <= %0 <= g_iMaxplayers) 

new g_iMaxplayers 
new g_MsgScreenFade

public plugin_init()
{    
        
register_plugin("Vomit""1.0""Autor");
        
g_iMaxplayers get_maxplayers() 
        
g_MsgScreenFade get_user_msgid("ScreenFade")
}
public 
ShitThisVomit(Client

    if( 
is_user_alive(Client) ) 
    { 
        new 
iEnt;
        new 
Float:flOrigin[3];
        
pev(Clientpev_originflOrigin); // use the Entity origin, not the User change this lines

        
while( (iEnt engfunc(EngFunc_FindEntityInSphereiEntflOriginRADIUS)) ) 
        { 
            if( 
is_player(iEnt) && iEnt != Client 
            { 
                  
message_begin(MSG_ONE_UNRELIABLEg_MsgScreenFade_iEnt)
                  
write_short(40); // Modifique the Flash duration
                  
write_short(60);
                  
write_short(0x0000); //Type of ScreenFade Search the others
                  
write_byte(255); //R
                  
write_byte(255); //G
                  
write_byte(255); //B
                  
write_byte(255); //Brightness
                  
message_end();
            }  
        } 
    } 
    return 
PLUGIN_HANDLED 



DavidLin 01-11-2016 15:52

Re: MOVETYPE_TOSS and touch event
 
Thanks a bunch! Also is it possible to destroy an entity when it travels a certain distance ?

Perrytutoriales 01-11-2016 16:04

Re: MOVETYPE_TOSS and touch event
 
I dont know about that but you can set a task when spawn the entity and then find a entity by his classname and remove the entity

PHP Code:


{   set_task(0.0"RemoveEntity"Client__"a"1);} 

public 
RemoveEntity(Client)
{
    new 
Entity = -1;

        while( ( 
Entityfind_ent_by_classEntity"EntityClassname" ) ) )
        {
                  
remove_entityEntity )
        }



DavidLin 01-11-2016 16:36

Re: MOVETYPE_TOSS and touch event
 
Found a better way. In ent prethink check the distance between the ent owner and the entity and remove it if distance is greater than allowed
PHP Code:


    
new Float:flOrigin], ownerFloat:oOrigin];
    
owner entity_get_edictentEV_ENT_owner );
    
peventpev_originflOrigin );
    
pevownerpev_originoOrigin );
    
    if( 
get_distance_fflOriginoOrigin ) >= get_pcvar_floatdist ) ) {
        
remove_entityent );
        return;
    } 



All times are GMT -4. The time now is 09:29.

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