Raised This Month: $ Target: $400
 0% 

set_task on Entity? (Tripmine)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 11-03-2015 , 01:59   set_task on Entity? (Tripmine)
Reply With Quote #1

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

Last edited by Chihuahuax; 11-03-2015 at 02:00.
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
 



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 18:12.


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