All pastes #1498203 Raw Edit

CPstream.inc

public c v1 · immutable
#1498203 ·published 2009-07-17 12:49 UTC
rendered paste body
/************************* 	     CPstream 	    ************************	Author: 		Donny (k)		Version: 		0.3rAbout:		Just a rewrite of the .2b version, I broke the .2r version before releasing it so I guess that version		wasn't so popular and I never read the post again until a few days ago. This version is area based, 		it's basically the same as before but now has areas included and you can use just an area or an area 		with a checkpoint so it covers tons more as it can now be used in many ways such as for a bank or a 		no go area which takes away your health/weapons etc.						Natives:		native CreateArea( Float:x, Float:y, Float:z, Float:radius = MIN_RADIUS, bool:use_checkpoint = false, Float:cpx = 0.0, Float:cpy = 0.0, Float:cpz = 0.0, Float:size = MIN_SIZE )		native CreateCheckpoint( Float:x, Float:y, Float:z, Float:radius = MIN_SIZE, Float:size = MIN_RADIUS )		native IsPlayerInCheckpointID( playerid, cpid )		native IsPlayerInAreaID( playerid, areaid )		native GetPlayerCheckpoint( playerid )		native GetPlayerArea( playerid )		native DestroyCheckpoint( cpid )		native DestroyArea( areaid )		native IsValidArea( areaid )		native GetAreaCount()		Notes:		Areas and checkpoints are checked for activity every 500 ms + the scripts lag so if		you go through one too quick it won't register, use the race checkpoints for this which		come with SAMP, this is just for normal checkpoints (walk in) and also the 'USE_CENTER' 		define is bugged right now, please ignore it !!		*/#if defined _CPstream_included	#endinput#endif#define _CPstream_included#pragma library CPstream#if !defined _a_samp_included	#include <a_samp>#endif#define MAX_LEN				128#define MAX_AREAS			10 /* <<< make this the # of areas you want to use */#define INVALID_AREA		-1#define INVALID_CHECKPOINT	-1#define MIN_RADIUS			2.0#define MAX_RADIUS			2000.0#define MIN_SIZE			1.0#define MAX_SIZE			( MAX_RADIUS - 2.0 )enum eArea{	id,	Float:area_x,	Float:area_y,	Float:area_z,		Float:area_cpx,				 	Float:area_cpy, 				 	Float:area_cpz, 				 	Float:area_cpsize,	Float:area_radius,		bool:area_hascp}enum ePlayer{	player_area, 	player_checkpoint}new 		gArea[ MAX_AREAS ][ eArea ],	gPlayer[ MAX_PLAYERS ][ ePlayer ],  	bool:gSystemRunning;	forward CheckSpheres();forward OnPlayerEnterArea( playerid, areaid );forward OnPlayerLeaveArea( playerid, areaid );forward OnPlayerEnterCheckpointEx( playerid, cpid );forward OnPlayerLeaveCheckpointEx( playerid, cpid );stock CreateArea( Float:x, Float:y, Float:z, Float:radius = MIN_RADIUS, bool:use_checkpoint = false, Float:cpx = 0.0, Float:cpy = 0.0, Float:cpz = 0.0, Float:size = MIN_SIZE ){			if ( !gSystemRunning ) 	{		gSystemRunning = true;		SetTimer( "CheckSpheres", 500, 0 );				new 			year, 			month, 			day,			hour, 			minute, 			second,			string[ 128 ];					getdate( year, month, day );		gettime( hour, minute, second );    		 		if ( hour < 10 ) format( string, sizeof( string ), "0%d", hour );		else format( string, sizeof( string ), "%d", hour );		if ( minute < 10 ) format( string, sizeof( string ), "%s:0%d", string, minute );		else format( string, sizeof( string ), "%s:%d", string, minute );		if ( second < 10 ) format( string, sizeof( string ), "%s:0%d", string, second );		else format( string, sizeof( string ), "%s:%d", string, second );		printf( "CPstream system version 0.3r activated on %d/%d/%d - %s", day, month, year, string );				for ( new i; i < MAX_AREAS; i ++ ) 		{			gArea[ i ][ id ] = INVALID_AREA;		}	}	for ( new i; i < MAX_AREAS; i ++ )	{		if ( gArea[ i ][ id ] == INVALID_AREA )		{			gArea[ i ][ id ] = i;			if ( radius > MAX_RADIUS ) radius = MAX_RADIUS;			while ( radius <= MIN_SIZE ) radius += MIN_SIZE;								if ( use_checkpoint )			{									if ( size < MIN_SIZE ) size = MIN_SIZE;								if ( size > MAX_SIZE ) size = MAX_SIZE;							while ( radius <= size ) radius += MIN_SIZE;							if ( !IsPointInRangeOfPoint( radius, cpx, cpy, cpz, x, y, z ) )				{							//#if !defined USE_CENTER					//if ( cpx > ( x + radius ) ) cpx = ( ( x + radius ) - ( size ) );					//if ( cpy > ( y + radius ) ) cpy = ( ( y + radius ) - ( size ) );					//if ( cpz > ( z + radius ) ) cpz = ( ( z + radius ) - ( size ) );					//if ( cpx < ( x - radius ) ) cpx = ( ( x - radius ) + ( size ) );					//if ( cpy < ( y - radius ) ) cpy = ( ( y - radius ) + ( size ) );					//if ( cpz < ( z - radius ) ) cpz = ( ( z - radius ) + ( size ) );					//printf( "Checkpoint ID: %d was outside it's areas radius,\nit has been moved to within the areas radius", gArea[ i ][ id ] );				//#else					cpx = x;					cpy = y;					cpz = z;					printf( "Checkpoint ID: %d was outside it's areas radius,\nit has been moved to the areas center", gArea[ i ][ id ] );										//#endif				}											}						gArea[ i ][ area_x ] = x;				gArea[ i ][ area_y ] = y;					gArea[ i ][ area_z ] = z;													gArea[ i ][ area_radius ] = radius;						gArea[ i ][ area_hascp ] = use_checkpoint;										gArea[ i ][ area_cpx ] = cpx;				gArea[ i ][ area_cpy ] = cpy;					gArea[ i ][ area_cpz ] = cpz;															gArea[ i ][ area_cpsize ] = size;										return gArea[ i ][ id ];		}	}	return INVALID_AREA;}	stock CreateCheckpoint( Float:x, Float:y, Float:z, Float:size = MIN_SIZE, Float:radius = MIN_RADIUS ){	return CreateArea( x, y, z, size, true, x, y, z, radius );}#define IsPlayerInCheckpointID(%1,%2) \			( gPlayer[ %1 ][ player_checkpoint ] == %2 )#define IsPlayerInAreaID(%1,%2)	\			( gPlayer[ %1 ][ player_area ] == %2 )#define GetPlayerCheckpoint(%1)	\			( gPlayer[ %1 ][ player_checkpoint ] )#define GetPlayerArea(%1)	\			( gPlayer[ %1 ][ player_area ] )			//no Set****, just set the players position and the streamer will do the rest						stock DestroyCheckpoint( cpid ){	for ( new i; i < MAX_AREAS; i ++ )	{		if ( gArea[ i ][ id ] == cpid )		{			if ( gArea[ i ][ area_hascp ] )			{				gArea[ i ][ area_hascp ] = false;				gArea[ i ][ area_cpx ] = 0.0;					gArea[ i ][ area_cpy ] = 0.0;						gArea[ i ][ area_cpz ] = 0.0;						gArea[ i ][ area_cpsize ] = 0.0;						for ( new j; j < MAX_PLAYERS; j ++ )				{					if ( GetPlayerArea( j ) == gArea[ i ][ id ] )					{						DisablePlayerCheckpoint( j );						gPlayer[ j ][ player_checkpoint ] = INVALID_CHECKPOINT;					}				}				return true;			}		}	}	return false;}stock DestroyArea( areaid ){	for ( new i; i < MAX_AREAS; i ++ )	{		if ( gArea[ i ][ id ] == areaid )		{					for ( new j; j < MAX_PLAYERS; j ++ )			{				if ( GetPlayerArea( j ) == gArea[ i ][ id ] )				{					if ( gArea[ i ][ area_hascp ] )					{						DisablePlayerCheckpoint( j );						gPlayer[ j ][ player_checkpoint ] = INVALID_CHECKPOINT;					}					gPlayer[ j ][ player_area ] = INVALID_AREA;				}			}					gArea[ i ][ area_x ] = 0.0;				gArea[ i ][ area_y ] = 0.0;					gArea[ i ][ area_z ] = 0.0;					gArea[ i ][ area_radius ] = 0.0;					gArea[ i ][ area_hascp ] = false;			gArea[ i ][ area_cpx ] = 0.0;				gArea[ i ][ area_cpy ] = 0.0;					gArea[ i ][ area_cpz ] = 0.0;					gArea[ i ][ area_cpsize ] = 0.0;						gArea[ i ][ id ] = INVALID_AREA;						return true;		}	}	return false;}stock IsValidArea( areaid ){	for ( new i; i < MAX_AREAS; i ++ )	{		if ( gArea[ i ][ id ] == areaid ) return true;	}	return false;}stock GetAreaCount(){	new		i,		count;			for ( i = 0; i < MAX_AREAS; i ++ )	{		if ( gArea[ i ][ id ] != INVALID_AREA ) count ++;	}	return count;}stock IsPointInRangeOfPoint( Float:range, Float:px, Float:py, Float:pz, Float:x, Float:y, Float:z ){			px -= x;	py -= y;	pz -= z;	return ( ( px * px ) + ( py * py ) + ( pz * pz ) ) < ( range * range );}public CheckSpheres() {			new		Float:x,		Float:y,		Float:z;		    for ( new i; i < MAX_PLAYERS; i ++ ) 	{		if ( GetPlayerPos( i, x, y, z ) )		{			for ( new j; j < MAX_AREAS; j ++ )			{				if ( gArea[ j ][ id ] != INVALID_AREA )				{					if ( IsPointInRangeOfPoint( gArea[ j ][ area_radius ], x, y, z, gArea[ j ][ area_x ], gArea[ j ][ area_y ], gArea[ j ][ area_z ] ) ) 					{						if ( GetPlayerArea( i ) != gArea[ j ][ id ] ) 						{							if ( gArea[ j ][ area_hascp ] ) 							{								SetPlayerCheckpoint( i, gArea[ j ][ area_cpx ], gArea[ j ][ area_cpy ], gArea[ j ][ area_cpz ], gArea[ j ][ area_cpsize ] );																			}							gPlayer[ i ][ player_area ] = gArea[ j ][ id ];							CallRemoteFunction( "OnPlayerEnterArea", "ii", i, gArea[ j ][ id ] );						}						else						{													if ( gArea[ j ][ area_hascp ] )							{								if ( IsPlayerInCheckpoint( i ) && GetPlayerCheckpoint( i ) != gArea[ j ][ id ] )															{									gPlayer[ i ][ player_checkpoint ] = gArea[ j ][ id ];															CallRemoteFunction( "OnPlayerEnterCheckpointEx", "ii", i, gArea[ j ][ id ] );								}								if ( !IsPlayerInCheckpoint( i ) && GetPlayerCheckpoint( i ) == gArea[ j ][ id ] ) 								{									gPlayer[ i ][ player_checkpoint ] = INVALID_CHECKPOINT;									CallRemoteFunction( "OnPlayerLeaveCheckpointEx", "ii", i, gArea[ j ][ id ] );										}																	}						} 										} 					else 					{						if ( gArea[ j ][ id ] == GetPlayerArea( i ) ) 						{							if ( gArea[ j ][ area_hascp ] ) 							{								DisablePlayerCheckpoint( i ); 																				gPlayer[ i ][ player_checkpoint ] = INVALID_CHECKPOINT;													}							gPlayer[ i ][ player_area ] = INVALID_AREA;							CallRemoteFunction( "OnPlayerLeaveArea", "ii", i, gArea[ j ][ id ] );						}					}				}			}		}    		else		{			gPlayer[ i ][ player_checkpoint ] = INVALID_CHECKPOINT;									gPlayer[ i ][ player_area ] = INVALID_AREA;				}	}	SetTimer( "CheckSpheres", 500, 0 );}