AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set_task on Entity? (Tripmine) (https://forums.alliedmods.net/showthread.php?t=274172)

Chihuahuax 11-03-2015 01:59

set_task on Entity? (Tripmine)
 
Is it fine for me to use a set_task on Entity?
For now it works fine, but I just want to make sure it doesnt crash server or whatever: (Highlighted red)

Code:

public Func_Plant( iPlayer ) {
        iPlayer -= TASK_CREATE;
       
        g_iPlanting[ iPlayer ] = false;
       
        static Float: flOrigin[ 3 ];
        entity_get_vector( iPlayer, EV_VEC_origin, flOrigin );
       
        static Float: flTraceDirection[ 3 ], Float: flTraceEnd[ 3 ], Float: flTraceResult[ 3 ], Float: flNormal[ 3 ];
        velocity_by_aim( iPlayer, 128, flTraceDirection );
        flTraceEnd[ 0 ] = flTraceDirection[ 0 ] + flOrigin[ 0 ];
        flTraceEnd[ 1 ] = flTraceDirection[ 1 ] + flOrigin[ 1 ];
        flTraceEnd[ 2 ] = flTraceDirection[ 2 ] + flOrigin[ 2 ];
       
        static Float: flFraction, iTr;
        iTr = 0;
        engfunc( EngFunc_TraceLine, flOrigin, flTraceEnd, 0, iPlayer, iTr );
        get_tr2( iTr, TR_vecEndPos, flTraceResult );
        get_tr2( iTr, TR_vecPlaneNormal, flNormal );
        get_tr2( iTr, TR_flFraction, flFraction );
       
        static iEntity;
        iEntity = create_entity( "info_target" );
       
        if( !iEntity )
                return;
       
        entity_set_string( iEntity, EV_SZ_classname, MINE_CLASSNAME );
        entity_set_model( iEntity, MINE_MODEL_VIEW );
        entity_set_size( iEntity, Float: { -4.0, -4.0, -4.0 }, Float: { 4.0, 4.0, 4.0 } );
       
        entity_set_int( iEntity, EV_INT_iuser2, iPlayer );
       
        g_iPlantedMines[ iPlayer ]++;
        if (g_iMineIds[iPlayer][0]==0)
            g_iMineIds[iPlayer][0] = iEntity;
            else
            g_iMineIds[iPlayer][1] = iEntity;
       
        entity_set_float( iEntity, EV_FL_frame, 0.0 );
        entity_set_float( iEntity, EV_FL_framerate, 0.0 );
        entity_set_int( iEntity, EV_INT_movetype, MOVETYPE_FLY );
        entity_set_int( iEntity, EV_INT_solid, SOLID_NOT );
        entity_set_int( iEntity, EV_INT_body, 3 );
        entity_set_int( iEntity, EV_INT_sequence, 7 );
        entity_set_float( iEntity, EV_FL_takedamage, DAMAGE_NO );
        entity_set_int( iEntity, EV_INT_iuser1, MINE_OFF );
       
        static Float: flNewOrigin[ 3 ], Float: flEntAngles[ 3 ];
        flNewOrigin[ 0 ] = flTraceResult[ 0 ] + ( flNormal[ 0 ] * 8.0 );
        flNewOrigin[ 1 ] = flTraceResult[ 1 ] + ( flNormal[ 1 ] * 8.0 );
        flNewOrigin[ 2 ] = flTraceResult[ 2 ] + ( flNormal[ 2 ] * 8.0 );
       
        entity_set_origin( iEntity, flNewOrigin );
       
        vector_to_angle( flNormal, flEntAngles );
        entity_set_vector( iEntity, EV_VEC_angles, flEntAngles );
        flEntAngles[ 0 ] *= -1.0;
        flEntAngles[ 1 ] *= -1.0;
        flEntAngles[ 2 ] *= -1.0;
        entity_set_vector( iEntity, EV_VEC_v_angle, flEntAngles );
       
        g_iTripMines[ iPlayer ]--;
       
        emit_sound( iEntity, CHAN_WEAPON, MINE_SOUND_DEPLOY, VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
        emit_sound( iEntity, CHAN_VOICE, MINE_SOUND_CHARGE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
        set_task(2.5 , "MINE_ACTIVATED", iEntity);
        client_print_color(iPlayer, Grey, "^x04[ZP]^x01 Tripmine has been planted! You have^x04 %i tripmines^x01 left.", g_iTripMines[ iPlayer ])
       
        entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + 0.6 );
}

Code:

public MINE_ACTIVATED(iEntity)
{
        if( !is_valid_ent( iEntity ) )
                return;

        entity_set_int( iEntity, EV_INT_iuser1, MINE_ON );
        entity_set_float( iEntity, EV_FL_takedamage, DAMAGE_YES );
        entity_set_int( iEntity, EV_INT_solid, SOLID_BBOX );
        entity_set_float( iEntity, EV_FL_health, MINE_HEALTH + 1000.0 );
                       
        emit_sound( iEntity, CHAN_VOICE, MINE_SOUND_ACTIVATE, VOL_NORM, ATTN_NORM, 0, 75 );

        return;
}

Full code:
Spoiler

zmd94 11-03-2015 04:59

Re: set_task on Entity? (Tripmine)
 
Boleh. Tiada masalah. ;)

Yes. It is fine.

Depresie 11-03-2015 07:07

Re: set_task on Entity? (Tripmine)
 
remember to remove the task in case the mine is destroyed or something, or else it will crash

Chihuahuax 11-03-2015 09:20

Re: set_task on Entity? (Tripmine)
 
Quote:

Originally Posted by Depresie (Post 2359519)
remember to remove the task in case the mine is destroyed or something, or else it will crash

No it cant be destroyed before the task completes (DAMAGE_NO)

Something=?

BTW: What is your relationship with hakken lol

zmd94 11-03-2015 10:38

Re: set_task on Entity? (Tripmine)
 
No need to remove task.

SkumTomteN 11-03-2015 10:44

Re: set_task on Entity? (Tripmine)
 
Never seen this code, thanks :)

Chihuahuax 11-03-2015 11:14

Re: set_task on Entity? (Tripmine)
 
Quote:

Originally Posted by SkumTomteN (Post 2359578)
Never seen this code, thanks :)

[offtopic]Thanks for what?[/offtopic]

Quote:

Originally Posted by zmd94 (Post 2359572)
No need to remove task.

Great

SkumTomteN 11-03-2015 11:16

Re: set_task on Entity? (Tripmine)
 
Quote:

Originally Posted by Chihuahuax (Post 2359586)
[offtopic]Thanks for what?[/offtopic]

For the code. Alot of work to be done, but it shouldnt be a problem :D

Chihuahuax 11-03-2015 18:11

Re: set_task on Entity? (Tripmine)
 
Quote:

Originally Posted by SkumTomteN (Post 2359588)
For the code. Alot of work to be done, but it shouldnt be a problem :D

lol i dont get you

If you're sayin that this plugin is incomplete, ...*I got it from here


All times are GMT -4. The time now is 18:12.

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