add mechanic into the facilities with a checkpoint

This commit is contained in:
Lorenc Pekaj 2018-11-08 22:57:02 +11:00
parent 3947176508
commit 8156e1749e
4 changed files with 257 additions and 26 deletions

View File

@ -34,7 +34,7 @@ enum E_GANG_FACILITIES
Float: E_X, Float: E_Y, Float: E_Z,
E_AMMU_CP, E_SHOP_CP, E_CANNON_CP,
E_TRAVEL_CP,
E_TRAVEL_CP, E_MECHANIC_CP,
bool: E_WAR, E_WAR_TIMER, E_WAR_TICK,
@ -51,8 +51,8 @@ enum E_FACILITY_INTERIOR
Float: E_TRAVEL_POS[ 4 ],
Float: E_ATM_POS[ 4 ],
Float: E_BOMB_POS_1[ 4 ],
Float: E_BOMB_POS_2[ 4 ]
//Float: E_MECHANIC_POS[ 4 ]
Float: E_BOMB_POS_2[ 4 ],
Float: E_MECHANIC_POS[ 4 ]
};
new
@ -66,8 +66,9 @@ new
{ 259.9110, 1850.9300, 1858.7600, 0.000000 },
{ 261.0079, 1869.5808, 1858.7600, 90.00000 },
{ 262.5575, 1850.0053, 1858.3671, 180.0000 },
{ 246.722503, 1816.183593, 1855.371826, 90.000000 },
{ 246.722503, 1827.754516, 1855.371826, 90.000000 }
{ 246.7225, 1816.1835, 1855.3718, 90.00000 },
{ 246.7225, 1827.7545, 1855.3718, 90.00000 },
{ 244.6742, 1843.2554, 1858.7576, 0.000000 }
}
},
g_gangFacilities [ MAX_FACILITIES ] [ E_GANG_FACILITIES ],
@ -94,13 +95,13 @@ hook OnPlayerEnterDynamicCP( playerid, checkpointid )
gangid = GetPlayerGang( playerid );
foreach ( new facility : gangfacilities )
{
// entrance
if ( checkpointid == g_gangFacilities[ facility ] [ E_CHECKPOINT ] [ 0 ] )
{
new turfid = g_gangFacilities[ facility ] [ E_TURF_ID ];
new facility_gangid = Turf_GetFacility( turfid );
// entrance
if ( checkpointid == g_gangFacilities[ facility ] [ E_CHECKPOINT ] [ 0 ] )
{
// not in the gang / not a turf owner
if ( ! ( Turf_GetOwner( turfid ) == gangid || facility_gangid == gangid ) )
{
@ -167,6 +168,12 @@ hook OnPlayerEnterDynamicCP( playerid, checkpointid )
return ShowPlayerAirportMenu( playerid );
}
// mechanic
else if ( checkpointid == g_gangFacilities[ facility ] [ E_TRAVEL_CP ] )
{
return ShowPlayerGangVehicleMenu( playerid, facility_gangid );
}
// orbital cannon
else if ( checkpointid == g_gangFacilities[ facility ] [ E_CANNON_CP ] )
{
@ -443,11 +450,19 @@ thread OnGangFaciltiesLoad( )
g_gangFacilities[ id ] [ E_TRAVEL_CP ] = CreateDynamicCP( infront_x, infront_y, g_gangFacilityInterior[ type ] [ E_TRAVEL_POS ] [ 2 ], 1.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
CreateDynamic3DTextLabel( "[FAST TRAVEL]", COLOR_GOLD, infront_x, infront_y, g_gangFacilityInterior[ type ] [ E_TRAVEL_POS ] [ 2 ], 20.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
// mechanic actor
CreateDynamicActor( 61, g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 0 ], g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 1 ], g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 2 ], g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 3 ], true, 100.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
infront_x = g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 0 ] + 2.0 * floatsin( -g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 3 ], degrees );
infront_y = g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 1 ] + 2.0 * floatcos( -g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 3 ], degrees );
g_gangFacilities[ id ] [ E_MECHANIC_CP ] = CreateDynamicCP( infront_x, infront_y, g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 2 ], 1.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
CreateDynamic3DTextLabel( "[GANG VEHICLES]", COLOR_GOLD, infront_x, infront_y, g_gangFacilityInterior[ type ] [ E_MECHANIC_POS ] [ 2 ], 20.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
// create atm
CreateATM( g_gangFacilityInterior[ type ] [ E_ATM_POS ] [ 0 ], g_gangFacilityInterior[ type ] [ E_ATM_POS ] [ 1 ], g_gangFacilityInterior[ type ] [ E_ATM_POS ] [ 2 ], g_gangFacilityInterior[ type ] [ E_ATM_POS ] [ 3 ], 0.0, g_gangFacilities[ id ] [ E_WORLD ] );
// more actors
CreateDynamicActor( 268, 244.6742, 1843.2554, 1858.7576, 0.000000, true, 100.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] );
ApplyDynamicActorAnimation( CreateDynamicActor( 70, 212.868576, 1819.894531, 1856.413818, 117.200050, true, 100.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] ), "COP_AMBIENT", "Coplook_loop", 4.1, 1, 1, 1, 1, 0 );
ApplyDynamicActorAnimation( CreateDynamicActor( 70, 213.705627, 1827.192993, 1856.413818, 60.300289, true, 100.0, .worldid = g_gangFacilities[ id ] [ E_WORLD ] ), "COP_AMBIENT", "Coplook_think", 4.1, 1, 1, 1, 1, 0 );

View File

@ -16,8 +16,11 @@
/* ** Macros ** */
#define IsGangPrivate(%0) ( g_gangData[ %0 ] [ E_INVITE_ONLY ] )
#define GetGangSqlID(%0) ( g_gangData[ %0 ] [ E_SQL_ID ] )
#define GetPlayerGang(%0) ( p_GangID[ %0 ] )
#define IsValidGangID(%0) (0 <= %0 < MAX_GANGS && Iter_Contains(gangs, %0))
/* ** Variables ** */
enum e_gang_data
{

View File

@ -9,16 +9,27 @@
#include < YSI\y_hooks >
/* ** Definitions ** */
#define MAX_GANG_VEHICLES ( 30 )
#define MAX_GANG_VEHICLES ( 3 )
#define DIALOG_GANG_VEHICLE_MENU 2399
#define DIALOG_GANG_VEHICLE_SPAWN 2400
#define DIALOG_GANG_VD_BUY 2401
#define DIALOG_GANG_VD_OPTIONS 2402
#define DIALOG_GANG_VD_CATEGORY 2403
#define PREVIEW_MODEL_GVEHICLE ( 6 )
/* ** Macros ** */
#define IsValidGangVehicle(%0,%1) \
( 0 <= %0 < MAX_GANG_VEHICLES && Iter_Contains( gangvehicles<%0>, %1 ) )
/* ** Constants ** */
static const GANG_VEHICLE_PRICE_FACTOR = 4;
/* ** Variables ** */
enum E_GANG_VEHICLE_DATA
{
E_SQL_ID, E_VEHICLE_ID,
E_SQL_ID, E_VEHICLE_ID, E_ACTIVATION_TIME,
E_COLOR[ 2 ], E_MODEL, E_PAINTJOB
};
@ -27,10 +38,154 @@ new g_gangVehicleData [ MAX_GANGS ] [ MAX_GANG_VEHICLES ] [ E_GANG_VEHICLE_DA
new g_gangVehicleModifications [ MAX_GANGS ] [ MAX_GANG_VEHICLES ] [ MAX_CAR_MODS ];
new Iterator: gangvehicles < MAX_GANGS, MAX_GANG_VEHICLES >;
/* ** Hooks ** */
hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
{
new
current_time = GetServerTime( );
if ( dialogid == DIALOG_GANG_VEHICLE_MENU && response )
{
new gangid = GetPVarInt( playerid, "gang_vehicle_gang" );
if ( ! IsValidGangID ( gangid ) ) {
return SendError( playerid, "There was an error processing gang vehicles, please try again." );
}
switch ( listitem )
{
// spawn vehicle
case 0:
{
if ( ! Iter_Count( gangvehicles< gangid > ) ) {
SendError( playerid, "This gang does not have any vehicles purchased." );
return ShowPlayerGangVehicleMenu( playerid, gangid );
}
szBigString = ""COL_WHITE"Vehicle\t"COL_WHITE"Availablity\n";
foreach ( new slotid : gangvehicles< gangid > )
{
format( szBigString, sizeof( szBigString ), "%s%s\t%s\n", szBigString,
GetVehicleName( g_gangVehicleData[ gangid ] [ slotid ] [ E_MODEL ] ),
g_gangVehicleData[ gangid ] [ slotid ] [ E_ACTIVATION_TIME ] > current_time ? ( secondstotime( g_gangVehicleData[ gangid ] [ slotid ] [ E_ACTIVATION_TIME ] - current_time ) ) : ( COL_GREEN # "Available!" )
);
}
return ShowPlayerDialog( playerid, DIALOG_GANG_VEHICLE_SPAWN, DIALOG_STYLE_TABLIST_HEADERS, ""COL_WHITE"Gang Vehicles - Spawn", szBigString, "Select", "Close" );
}
// buy vehicle
case 1: ShowBuyableVehiclesList( playerid, DIALOG_GANG_VD_CATEGORY, "Back" );
}
return 1;
}
else if ( dialogid == DIALOG_GANG_VD_BUY )
{
if ( response )
{
new
type_id = GetPVarInt( playerid, "vehicle_preview" );
for ( new id = 0, x = 0; id < sizeof( g_BuyableVehicleData ); id ++ )
{
if ( g_BuyableVehicleData[ id ] [ E_TYPE ] == type_id )
{
if ( x == listitem )
{
SetPVarInt( playerid, "buying_vehicle", id );
ShowPlayerDialog( playerid, DIALOG_GANG_VD_OPTIONS, DIALOG_STYLE_LIST, "{FFFFFF}Gang Vehicles - Purchase", "Purchase This Vehicle\nPreview Vehicle", "Select", "Back" );
return 1;
}
x++;
}
}
}
return ShowBuyableVehiclesList( playerid, DIALOG_GANG_VD_CATEGORY, "Back" );
}
else if ( dialogid == DIALOG_GANG_VD_OPTIONS )
{
if ( ! response ) {
return GangVehicles_ShowBuyableList( playerid, GetPVarInt( playerid, "vehicle_preview" ) );
}
switch ( listitem )
{
// bought the vehicle
case 0:
{
// TODO:
}
// preview
case 1:
{
return ShowPlayerModelPreview( playerid, PREVIEW_MODEL_GVEHICLE, "Gang Vehicle Preview", g_BuyableVehicleData[ GetPVarInt( playerid, "buying_vehicle" ) ] [ E_MODEL ] );
}
}
return 1;
}
else if ( dialogid == DIALOG_GANG_VD_CATEGORY )
{
new gangid = GetPVarInt( playerid, "gang_vehicle_gang" );
if ( ! IsValidGangID ( gangid ) ) {
return SendError( playerid, "There was an error processing gang vehicles, please try again." );
}
if ( ! response ) {
return ShowPlayerGangVehicleMenu( playerid, gangid );
}
return GangVehicles_ShowBuyableList( playerid, listitem + 1 );
}
else if ( dialogid == DIALOG_GANG_VEHICLE_SPAWN )
{
new gangid = GetPVarInt( playerid, "gang_vehicle_gang" );
if ( ! IsValidGangID ( gangid ) ) {
return SendError( playerid, "There was an error processing gang vehicles, please try again." );
}
if ( ! response ) {
return ShowPlayerGangVehicleMenu( playerid, gangid );
}
new
x = 0;
foreach ( new slotid : gangvehicles< gangid > )
{
if ( x == listitem )
{
if ( g_gangVehicleData[ gangid ] [ slotid ] [ E_ACTIVATION_TIME ] > current_time ) {
return SendError( playerid, "This vehicle cannot be spawned for another %s.", secondstotime( g_gangVehicleData[ gangid ] [ slotid ] [ E_ACTIVATION_TIME ] - current_time ) );
}
// TODO: spawn vehicle
SendServerMessage( playerid, "You have spawned slot id %d", slotid );
break;
}
x ++;
}
return 1;
}
return 1;
}
hook OnGangLoad( gangid )
{
mysql_tquery( dbHandle, sprintf( "SELECT * FROM `GANG_VEHICLES` WHERE `GANG_ID` = %d ", GetGangSqlID( gangid ) ), "GangVehicles_LoadVehicles", "d", gangid );
return 1;
}
hook OnPlayerEndModelPreview( playerid, handleid )
{
if ( handleid == PREVIEW_MODEL_GVEHICLE )
{
SendServerMessage( playerid, "You have finished looking at the gang vehicle preview." );
ShowPlayerDialog( playerid, DIALOG_GANG_VD_OPTIONS, DIALOG_STYLE_LIST, "{FFFFFF}Gang Vehicles - Purchase", "Purchase This Vehicle\nPreview Vehicle", "Select", "Back" );
return Y_HOOKS_BREAK_RETURN_1;
}
return 1;
}
@ -38,40 +193,64 @@ CMD:car( playerid )
{
new Float: X, Float: Y, Float: Z;
GetPlayerPos( playerid, X, Y, Z );
CreateGangVehicle( GetPlayerGang( playerid ), 560, X, Y, Z );
CreateGangVehicle( GetPlayerGang( playerid ), 560 );
return 1;
}
/* ** SQL Threads ** */
thread GangVehicles_LoadVehicles( gangid )
{
new
rows = cache_get_row_count( );
if ( rows )
{
static
paintjob[ 90 ];
for ( new row = 0; row < rows; row ++ )
{
new slotid = CreateGangVehicle(
gangid,
cache_get_field_content_int( row, "MODEL_ID" ),
cache_get_field_content_int( row, "COLOR1" ),
cache_get_field_content_int( row, "COLOR2" ),
cache_get_field_content_int( row, "PAINTJOB" )
);
// load the paintjobs in
if ( slotid != ITER_NONE ) {
cache_get_field_content( row, "MODS", paintjob );
sscanf( paintjob, "p<.>e<ddddddddddddddd>", g_gangVehicleModifications[ gangid ] [ slotid ] );
}
}
}
return 1;
}
/* ** Functions ** */
stock CreateGangVehicle( gangid, modelid, Float: X, Float: Y, Float: Z, color1 = -1, color2 = -1, paintjob = 3 )
stock CreateGangVehicle( gangid, modelid, color1 = -1, color2 = -1, paintjob = 3 )
{
new
slotid = Iter_Free( gangvehicles< gangid > );
if ( slotid != ITER_NONE )
{
g_gangVehicleData[ gangid ] [ slotid ] [ E_ACTIVATION_TIME ] = 0;
g_gangVehicleData[ gangid ] [ slotid ] [ E_COLOR ] [ 0 ] = color1;
g_gangVehicleData[ gangid ] [ slotid ] [ E_COLOR ] [ 1 ] = color2;
g_gangVehicleData[ gangid ] [ slotid ] [ E_PAINTJOB ] = paintjob;
g_gangVehicleData[ gangid ] [ slotid ] [ E_MODEL ] = modelid;
ResetGangVehicleMods( gangid, slotid );
new vehicleid = CreateVehicle( modelid, X, Y, Z, 0.0, Color1, Color2, 999999999 );
g_adminSpawnedCar{ vehicleid } = false;
SetVehicleNumberPlate( vehicleid, g_gangData[ gangid ] [ E_NAME ] );
g_gangVehicleData[ gangid ] [ slotid ] [ E_VEHICLE_ID ] = vehicleid;
//format( szString, sizeof( szString ), "INSERT INTO `VEHICLES` (`MODEL`,`LOCKED`,`X`,`Y`,`Z`,`ANGLE`,`COLOR1`,`COLOR2`,`PRICE`,`OWNER`,`PLATE`,`PAINTJOB`,`MODS`) VALUES (%d,0,%f,%f,%f,%f,%d,%d,%d,%d,'SF-CNR',3,'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.')", Model, X, Y, Z, Angle, Color1, Color2, Cost, g_vehicleData[ playerid ] [ vID ] [ E_OWNER_ID ] );
//mysql_function_query( dbHandle, szString, true, "OnPlayerCreateBuyableVehicle", "dd", playerid, vID );
Iter_Add( gangvehicles< gangid >, slotid );
}
return slotid;
}
stock ResetGangVehicleMods( gangid, slotid, fordestroy=1 )
{
if ( IsValidGangVehicle( gangid, slotid ) )
if ( ! IsValidGangVehicle( gangid, slotid ) )
return;
for ( new i = 0; i < MAX_CAR_MODS; i++ )
@ -87,3 +266,37 @@ stock ResetGangVehicleMods( gangid, slotid, fordestroy=1 )
format( szNormalString, sizeof( szNormalString ), "UPDATE `GANG_VEHICLES` SET `MODS`='0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' WHERE `ID`=%d", g_gangVehicleData[ gangid ] [ slotid ] [ E_SQL_ID ] );
mysql_single_query( szNormalString );
}
stock ShowPlayerGangVehicleMenu( playerid, gangid )
{
SetPVarInt( playerid, "gang_vehicle_gang", gangid );
ShowPlayerDialog( playerid, DIALOG_GANG_VEHICLE_MENU, DIALOG_STYLE_LIST, ""COL_WHITE"Gang Vehicles", "Spawn Gang Vehicle\nBuy Gang Vehicle", "Select", "Close" );
return 1;
}
static stock GangVehicles_ShowBuyableList( playerid, type_id )
{
static
szBuyableVehicles[ 1400 ];
if ( szBuyableVehicles[ 0 ] != '\0' ) {
for ( new i = 0; i < sizeof( g_BuyableVehicleData ); i ++ ) if ( g_BuyableVehicleData[ i ] [ E_TYPE ] == type_id ) {
format( szBuyableVehicles, sizeof( szBuyableVehicles ), "%s"COL_GOLD"%s%s%s\t%s\n", szBuyableVehicles, cash_format( g_BuyableVehicleData[ i ] [ E_PRICE ] * GANG_VEHICLE_PRICE_FACTOR ), g_BuyableVehicleData[ i ] [ E_VIP ] ? ( "" ) : ( #COL_WHITE ), g_BuyableVehicleData[ i ] [ E_PRICE ] < 100000 ? ( "\t" ) : ( "" ), g_BuyableVehicleData[ i ] [ E_NAME ] );
}
}
SetPVarInt( playerid, "vehicle_preview", type_id );
return ShowPlayerDialog( playerid, DIALOG_GANG_VD_BUY, DIALOG_STYLE_LIST, "{FFFFFF}Vehicle Dealership", szBuyableVehicles, "Options", "Cancel" );
}
/* ** Migrations ** */
/*
CREATE TABLE IF NOT EXISTS `GANG_VEHICLES` (
`ID` int(11) auto_increment primary key,
`GANG_ID` int(11),
`MODEL_ID` int(11),
`COLOR1` int(4),
`COLOR2` int(4),
`PAINTJOB` tinyint(2),
`MODS` varchar(90)
);
*/

View File

@ -397,7 +397,7 @@ hook OnPlayerEndModelPreview( playerid, handleid )
}
/* ** Functions ** */
stock ShowBuyableVehiclesList( playerid )
stock ShowBuyableVehiclesList( playerid, dialogid = DIALOG_VEHDEALER, secondary_button[ ] = "Cancel" )
{
static
szCategory[ 16 * sizeof( g_BVCategories ) ];
@ -407,7 +407,7 @@ stock ShowBuyableVehiclesList( playerid )
format( szCategory, sizeof( szCategory ), "%s%s\n", szCategory, g_BVCategories[ i ] );
}
}
return ShowPlayerDialog( playerid, DIALOG_VEHDEALER, DIALOG_STYLE_LIST, "{FFFFFF}Vehicle Dealership", szCategory, "Select", "Cancel" );
return ShowPlayerDialog( playerid, dialogid, DIALOG_STYLE_LIST, "{FFFFFF}Vehicle Dealership", szCategory, "Select", secondary_button );
}
stock ShowBuyableVehiclesTypeDialog( playerid, type_id )