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

create beam between nearest player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-30-2021 , 19:40   create beam between nearest player
Reply With Quote #1

Code:
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < engine >

#define ADMFLAG_BEAM	ADMIN_LEVEL_H

#define TASK_BEAM	13372
#define ID_BEAM	(taskid - TASK_BEAM)

native zp_get_user_zombie ( iEntity );
forward zp_round_started ( GameType, iEntity );

enum
{
	MODE_INFECTION = 1,
	MODE_NEMESIS,
	MODE_SURVIVOR,
	MODE_SWARM,
	MODE_MULTI,
	MODE_PLAGUE
};

new g_iRadiusBeam;
new g_iRadiusTime;
new g_iMaxPlayers;
new g_iBeamLine

public plugin_precache ( )
	g_iBeamLine = engfunc ( EngFunc_PrecacheModel, "sprites/line.spr" );

public plugin_init ( )
{
	register_plugin ( "[ZP] Show nearby zombie", "1.0", "LondoN eXtream" );
	g_iMaxPlayers = get_maxplayers ( );

	g_iRadiusBeam = register_cvar ( "beam_radius", "720" );
	g_iRadiusTime = register_cvar ( "beam_time", "25" );
}

public zp_round_started ( GameType, iEntity )
{
	if ( !( get_user_flags ( iEntity ) & ADMFLAG_BEAM ) )
		return PLUGIN_HANDLED;

	set_task ( float ( get_pcvar_num ( g_iRadiusTime ) ), "CreateBeam", iEntity + TASK_BEAM );

	return PLUGIN_CONTINUE;
}

public CreateBeam ( taskid )
{
	new iEntity = ID_BEAM;

	if ( !is_user_alive ( iEntity ) || zp_get_user_zombie ( iEntity ) )
		return PLUGIN_HANDLED;

	new iEntityOrigin [ 3 ], iEntityTargetOrigin [ 3 ];
	get_user_origin ( iEntity, iEntityOrigin );

	for ( new iEntityTarget = 1; iEntityTarget <= g_iMaxPlayers; iEntityTarget++ )
	{
	 	get_user_origin ( iEntityTarget, iEntityTargetOrigin );
		
		if ( get_distance ( iEntityOrigin, iEntityTargetOrigin ) <= get_pcvar_num ( g_iRadiusBeam ) )
			ShowBeam ( iEntity, iEntityOrigin, iEntityTargetOrigin );
	}

	return PLUGIN_CONTINUE;
}

ShowBeam ( id, const iStartOrigin [ 3 ], const iEndOrigin [ 3 ] )
{
	message_begin ( MSG_ONE, SVC_TEMPENTITY, {0,0,0}, id );
	write_byte ( TE_BEAMPOINTS );
	write_coord ( iStartOrigin [ 0 ] );
	write_coord ( iStartOrigin [ 1 ] );
	write_coord ( iStartOrigin [ 2 ] );
	write_coord ( iEndOrigin [ 0 ] );
	write_coord ( iEndOrigin [ 1 ] );
	write_coord ( iEndOrigin [ 2 ] );
	write_short ( g_iBeamLine );
	write_byte ( 1 );	// start frame
	write_byte ( 5 );	// frame rate
	write_byte ( 5 );	// life
	write_byte ( 3 );	// line width
	write_byte ( 1 );	// noise
	message_end ( );
}
other way? or improvements?
looking for the simpliest and fastest way
__________________
LondoN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-30-2021 , 19:51   Re: create beam between nearest player
Reply With Quote #2

You're looping through all player indexes without checking if the user is connected. Simply use get_players() or find_sphere_class() since you have a maximum radius.
__________________

Last edited by OciXCrom; 03-30-2021 at 19:52.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-30-2021 , 20:12   Re: create beam between nearest player
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
You're looping through all player indexes without checking if the user is connected. Simply use get_players() or find_sphere_class() since you have a maximum radius.
yes, i see now whats wrong about looping.

but, im pretty unsure about get_players and the loop, how can i return the nearest player in the radius, cuz, at this time, it creates an beam between me an all players in the radius.

also, from what i know, it is other way creating a beam without precaching a sprite, but didn't found any example of this kind of message.

about find_sphere_class, can show an example, i didn't used this and i'm pretty unsure how to use correctly in my case here.
__________________
LondoN is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-31-2021 , 02:53   Re: create beam between nearest player
Reply With Quote #4

Code:
public find_players_around_player(id) {     new iPlayers[32], iPnum = find_sphere_class(id, "player", get_pcvar_float(g_iRadiusBeam), iPlayers, iPnum)     if(!iPnum)     {         return     }     new iOrigin[3]     get_user_origin(id, iOrigin)     new iNearestPlayer = iPlayers[0]     static const DUMMY_MAX_DISTANCE = 9999     new iNearestDistance = DUMMY_MAX_DISTANCE     for(new iPlayerOrigin[3], iPlayer, iDistance, i; i < iPnum; i++)     {         iPlayer = iPlayers[i]         if(!is_user_alive(iPlayer))         {             continue         }         get_user_origin(iPlayer, iPlayerOrigin)         iDistance = get_distance(iOrigin, iPlayerOrigin)         if(iDistance < iNearestDistance)         {             iNearestPlayer = iPlayer             iNearestDistance = iDistance         }     }     if(iNearestDistance == DUMMY_MAX_DISTANCE)     {         return     }     // iNearestPlayer is your nearest player }
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-31-2021 , 06:03   Re: create beam between nearest player
Reply With Quote #5

Or you can also use sort array.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 02:21.


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