SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/05/2020, 11:54 AM   #1
Marcop
Little Clucker
 
Join Date: Nov 2016
Posts: 11
Reputation: 0
Default Problem with gundealer system

Hello, I have a problem with my dealer system. It is an NPC from which illegal factions obtain weapons, which can be called with the / mpanel command. In the database appears the box to set the time, assign the dealer to X faction, etc. However, this only appears when I restart the server, disappears in 30 minutes and does not appear again, and the data of the trafficker that I put manually is erased in the database staying at 0.

The correct thing would be to assign the NPC to the faction and that it appears when the faction leader calls (with a minimum time between each call) and disappears, and so on.

Function:

Code:
CreateCrimePoint( point )
{
	GunDealer[point][g_actor_id] = CreateActor( GunDealer[point][g_actor], 
		GunDealer[point][g_actor_pos][0],
		GunDealer[point][g_actor_pos][1],
		GunDealer[point][g_actor_pos][2],
		GunDealer[point][g_actor_pos][3] );
		
	ApplyActorAnimation( GunDealer[point][g_actor_id], "DEALER","DEALER_IDLE", 3.0,0,1,1,1,0 );
		
	GunDealer[point][g_text] = CreateDynamic3DTextLabel( "Presiona '"cBLUE"H"cWHITE"'", C_WHITE, 
		GunDealer[point][g_actor_pos][0], 
		GunDealer[point][g_actor_pos][1], 
		GunDealer[point][g_actor_pos][2],
		2.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1 );
		
	if( GunDealer[point][g_car] )
	{
		GunDealer[point][g_car_id] = CreateVehicle( GunDealer[point][g_car], 
			GunDealer[point][g_car_pos][0], 
			GunDealer[point][g_car_pos][1], 
			GunDealer[point][g_car_pos][2], 
			GunDealer[point][g_car_pos][3], 
			random(255), random(255), INVALID_PARAM );
	}

	return 1;
}

DestroyCrimePoint( point )
{
	DestroyActor( GunDealer[point][g_actor_id] );

	if( IsValidDynamic3DTextLabel( GunDealer[point][g_text] ) )
		DestroyDynamic3DTextLabel( GunDealer[point][g_text] );

	if( GunDealer[point][g_car] )
	{
		printf( "[Log]: Destroy GunDealer vehicle ID: %s[%d] = point #%d.", GetVehicleModelName( GetVehicleModel(GunDealer[point][g_car_id]) ), GunDealer[point][g_car_id], point );
		DestroyVehicle( GunDealer[point][g_car_id] );
	}
	
	GunDealer[point][g_text] = Text3D: INVALID_3DTEXT_ID;
	
	GunDealer[point][g_fracid] = 
	GunDealer[point][g_car_id] = 
	GunDealer[point][g_actor_id] = 
	GunDealer[point][g_time] = 1;
	
	for( new i; i < 2; i++ )
	{
		for( new j; j < 10; j++ )
		{
			DealerOrder[point][i][gun_id][j] =
			DealerOrder[point][i][gun_amount][j] = 0;
		}
	}
	
	mysql_format:g_small_string( "DELETE FROM `"DB_CRIME_ORDER"` WHERE `point_id` = %d", GunDealer[point][g_id] );
	mysql_tquery( mysql, g_small_string );
	
	return 1;
}

function insertGunDealer( playerid, point )
{
	GunDealer[point][g_id] = cache_insert_id();
	
	format:g_small_string( ""ADMIN_PREFIX" %s [%d] ha añadido un punto de traficante. ID: %d SKIN:  %d",
		Player[playerid][uName],
		playerid,
		GunDealer[point][g_id], GunDealer[point][g_actor] );
		
	SendAdmin:( C_DARKGRAY, g_small_string );
	
	COUNT_GUNDEALERS ++;

	return 1;
}

stock ShowWeaponsCrime( playerid, type, crime )
{
	clean:<g_string>;
	
	new
		id;
	
	strcat( g_string, ""cWHITE"Nombre\t"cWHITE"Cantidad" );

	switch( CrimeFraction[crime][c_type_weapon] )
	{
		case 1:
		{
			for( new i; i < 10; i++ )
			{
				if( weapons_info[type][i][gun_type] < 2 && weapons_info[type][i][gun_id] )
				{
					id = getInventoryId( weapons_info[type][i][gun_id] );
					
					format:g_small_string( "\n"cWHITE"%s\t"cBLUE"%d", inventory[id][i_name], CrimeOrder[crime][type][gun_amount][i] );
					strcat( g_string, g_small_string );
				}
			}
		}
				
		case 2:
		{
			for( new i; i < 10; i++ )
			{
				if( weapons_info[type][i][gun_type] < 3 && weapons_info[type][i][gun_id] )
				{
					id = getInventoryId( weapons_info[type][i][gun_id] );
							
					format:g_small_string( "\n"cWHITE"%s\t"cBLUE"%d", inventory[id][i_name], CrimeOrder[crime][type][gun_amount][i] );
					strcat( g_string, g_small_string );
				}
			}
		}
		
		case 3:
		{
			for( new i; i < 10; i++ )
			{
				if( weapons_info[type][i][gun_id] )
				{
					id = getInventoryId( weapons_info[type][i][gun_id] );
							
					format:g_small_string( "\n"cWHITE"%s\t"cBLUE"%d", inventory[id][i_name], CrimeOrder[crime][type][gun_amount][i] );
					strcat( g_string, g_small_string );
				}
			}
		}
	}
	
	SetPVarInt( playerid, "GunDealer:Type", type );
	showPlayerDialog( playerid, d_crime + 35, DIALOG_STYLE_TABLIST_HEADERS, " ", g_string, "Seleccionar", "Atrás" );
	
	return 1;
}

ShowWeaponsOrder( playerid, type, order )
{
	clean:<g_string>;
	
	new
		id,
		count;
	
	strcat( g_string, ""cWHITE"Nombre\t"cWHITE"Cantidad" );
		
	for( new i; i < 10; i++ )
	{
		if( DealerOrder[order][type][gun_id][i] )
		{
			id = getInventoryId( DealerOrder[order][type][gun_id][i] );
			
			format:g_small_string( "\n"cWHITE"%s\t"cBLUE"%d", inventory[id][i_name], DealerOrder[order][type][gun_amount][i] );
			strcat( g_string, g_small_string );
			
			g_dialog_select[playerid][count] = i;
			
			count++;
		}
	}

	if( !count )
	{
		SendClient:( playerid, C_WHITE, !""gbDefault"Sin stock." );
	
		DeletePVar( playerid, "Crime:Type" );
		return showPlayerDialog( playerid, d_crime + 39, DIALOG_STYLE_LIST, "Traficante", "\
			"cBLUE"1."cWHITE" Armas\n\
			"cBLUE"2."cWHITE" Munición", "Seleccionar", "Cerrar" );
	}
	
	return showPlayerDialog( playerid, d_crime + 40, DIALOG_STYLE_TABLIST_HEADERS, "Traficante", g_string, "Siguiente", "Atrás" );
}

ShowAmountOrder( playerid, type, order, index )
{
	clean:<g_string>;
	
	new
		id = getInventoryId( DealerOrder[order][type][gun_id][index] );
	
	strcat( g_string, ""cWHITE"Arma\t"cWHITE"Costo" );
	
	for( new i; i < DealerOrder[order][type][gun_amount][index]; i++ )
	{
		format:g_small_string( "\n"cWHITE"%s\t"cBLUE"$%d", inventory[id][i_name], weapons_info[type][index][gun_price] );
		strcat( g_string, g_small_string );
	}
	
	showPlayerDialog( playerid, d_crime + 41, DIALOG_STYLE_TABLIST_HEADERS, " ", g_string, "Seleccionar", "Atrás" );
	
	return 1;
}

SendCrimeMessage( crime, color, text[] )
{
	foreach(new i: Player)
	{
		if( !IsLogged(i) ) continue;
		
		if( Player[i][uCrimeM] == CrimeFraction[crime][c_id] ) SendClient:( i, color, text );
	}

	return 1;
}

CrimeTimer()
{
	for( new i; i < COUNT_CRIMES; i++ )
	{
		if(  CrimeFraction[i][c_time_dealer] && CrimeFraction[i][c_time_dealer] < gettime() )
		{
			new
				dealer = CrimeFraction[i][c_index_dealer];
		
			CreateCrimePoint( dealer );
			GunDealer[ dealer ][g_time] = gettime() + 30 * 60;
			
			format:g_small_string( ""FRACTION_PREFIX" El distribuidor de armas ha llegado. Esperará solamente 30 minutos. Encuentralo en %s.", GunDealer[ dealer ][g_zone] );
			SendCrimeMessage( i, C_DARKGRAY, g_small_string );
			
			CrimeFraction[i][c_time_dealer] = 0;

			mysql_format:g_small_string( "UPDATE `"DB_CRIME"` SET `c_time_dealer` = 0 WHERE `c_id` = %d LIMIT 1",
				CrimeFraction[i][c_id] );
			mysql_tquery( mysql, g_small_string );
			
			mysql_format:g_small_string( "UPDATE `"DB_CRIME_GUNDEALER"` SET `g_time` = %d WHERE `g_id` = %d LIMIT 1",
				GunDealer[ dealer ][g_time], GunDealer[ dealer ][g_id] );
			mysql_tquery( mysql, g_small_string );
		}
		else if( CrimeFraction[i][c_time] && CrimeFraction[i][c_time] < gettime() )
		{
			CrimeFraction[i][c_time] = 0;
			
			mysql_format:g_small_string( "UPDATE `"DB_CRIME"` SET `c_time` = 0 WHERE `c_id` = %d LIMIT 1",
				CrimeFraction[i][c_id] );
			mysql_tquery( mysql, g_small_string );
		}
	}
	
	for( new i; i < COUNT_GUNDEALERS; i++ )
	{
		if( GunDealer[i][g_time] && GunDealer[i][g_time] < gettime() )
		{
			DestroyCrimePoint( i );
			
			mysql_format:g_small_string( "UPDATE `"DB_CRIME_GUNDEALER"` SET `g_time` = 0, `g_fracid` = 0 WHERE `g_id` = %d LIMIT 1",
				GunDealer[ i ][g_id] );
			mysql_tquery( mysql, g_small_string );
		}
	}

	return 1;
}

function Crime_OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
{
	if( PRESSED(KEY_CTRL_BACK) && Player[playerid][uCrimeM] && Player[playerid][uCrimeRank] )
	{
		for( new i; i < COUNT_GUNDEALERS; i++ )
		{
			if( GunDealer[i][g_time] && IsPlayerInRangeOfPoint( playerid, 1.0, GunDealer[i][g_actor_pos][0], GunDealer[i][g_actor_pos][1], GunDealer[i][g_actor_pos][2] ) )
			{
				SetPVarInt( playerid, "Crime:Order", i );
				return showPlayerDialog( playerid, d_crime + 39, DIALOG_STYLE_LIST, "Traficante", "\
					"cBLUE"1."cWHITE" Armas\n\
					"cBLUE"2."cWHITE" Munición", "Seleccionar", "Cerrar" );
			}
		}
	}

	return 1;
}

stock ShowCrimePriceInfo( playerid, type )
{
	clean:<g_string>;
	
	format:g_small_string( ""cWHITE"Armas disponibles para tu organización criminal "cBLUE"%d"cWHITE"\n", type + 1 );
	strcat( g_string, g_small_string );
	
	new
		id;

	switch( type )
	{
		case 0:
		{		
			for( new i; i < 2; i++ )
			{
				for( new j; j < 10; j++ )
				{
					if( weapons_info[i][j][ gun_type ] < 2 && weapons_info[i][j][ gun_type ] != 0 )
					{
						id = getInventoryId( weapons_info[i][j][ gun_id ] );
						
						format:g_small_string( "\n"cBLUE"$%d\t%d\t"cGRAY"%s", 
							weapons_info[i][j][ gun_price ],
							weapons_info[i][j][ gun_amount ],
							inventory[ id ][i_name]	);
						strcat( g_string, g_small_string );
					}
				}
			}
		}
		
		case 1:
		{
			for( new i; i < 2; i++ )
			{
				for( new j; j < 10; j++ )
				{
					if( weapons_info[i][j][ gun_type ] < 3 && weapons_info[i][j][ gun_type ] != 0 )
					{
						id = getInventoryId( weapons_info[i][j][ gun_id ] );
						
						format:g_small_string( "\n"cBLUE"$%d\t%d\t"cGRAY"%s", 
							weapons_info[i][j][ gun_price ],
							weapons_info[i][j][ gun_amount ],
							inventory[ id ][i_name]	);
						strcat( g_string, g_small_string );
					}
				}
			}
		}
		
		case 2:
		{
			for( new i; i < 2; i++ )
			{
				for( new j; j < 10; j++ )
				{
					if( weapons_info[i][j][ gun_type ] != 0 )
					{
						id = getInventoryId( weapons_info[i][j][ gun_id ] );
						
						format:g_small_string( "\n"cBLUE"$%d\t%d\t"cGRAY"%s", 
							weapons_info[i][j][ gun_price ],
							weapons_info[i][j][ gun_amount ],
							inventory[ id ][i_name]	);
						strcat( g_string, g_small_string );
					}
				}
			}
		}
	}
	
	return showPlayerDialog( playerid, d_crime + 42, DIALOG_STYLE_MSGBOX, "Información", g_string, "Atrás", "" );
}
Marcop is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[SOLVED] 3 problem's! (1 problem still unsolved, but stopped solving.) Mechscape Help Archive 9 24/12/2009 08:47 PM


All times are GMT. The time now is 10:50 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.