improvements to the component positioner

This commit is contained in:
Lorenc Pekaj 2019-06-12 19:22:09 +10:00
parent ecc61ca9b4
commit 675a00d4b5

View File

@ -1,6 +1,6 @@
/* /*
* Irresistible Gaming (c) 2018 * Irresistible Gaming (c) 2018
* Developed by Lorenc * Developed by Lorenc, Cloudy
* Module: cnr\features\vehicles\vehicle_modifications.pwn * Module: cnr\features\vehicles\vehicle_modifications.pwn
* Purpose: custom vehicle components (objects) for player vehicles * Purpose: custom vehicle components (objects) for player vehicles
*/ */
@ -38,6 +38,7 @@
#define COMPONENT_EDIT_TYPE_RZ 5 #define COMPONENT_EDIT_TYPE_RZ 5
#define TIMER_UPDATE_RATE 50 #define TIMER_UPDATE_RATE 50
#define MAX_COMPONENT_OFFSET 2.0
enum E_CAR_MODS enum E_CAR_MODS
{ {
@ -445,7 +446,10 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
SetPVarFloat( playerid, "component_rot_y", g_vehiclePimpData[ ownerid ] [ vehicleid ] [ E_RY ] [ i ] ); SetPVarFloat( playerid, "component_rot_y", g_vehiclePimpData[ ownerid ] [ vehicleid ] [ E_RY ] [ i ] );
SetPVarFloat( playerid, "component_rot_z", g_vehiclePimpData[ ownerid ] [ vehicleid ] [ E_RZ ] [ i ] ); SetPVarFloat( playerid, "component_rot_z", g_vehiclePimpData[ ownerid ] [ vehicleid ] [ E_RZ ] [ i ] );
ShowPlayerHelpDialog( playerid, 0, "~g~/px - ~w~X axis~n~\ ShowPlayerHelpDialog(
playerid, 0,
"~g~A or D -~w~ Move object~n~"\
"~g~/px - ~w~X axis~n~\
~g~/py - ~w~Y axis~n~\ ~g~/py - ~w~Y axis~n~\
~g~/pz - ~w~Z axis~n~\ ~g~/pz - ~w~Z axis~n~\
~g~/rx - ~w~X rotation~n~\ ~g~/rx - ~w~X rotation~n~\
@ -453,7 +457,8 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
~g~/rz - ~w~Z rotation~n~\ ~g~/rz - ~w~Z rotation~n~\
~g~Press Y - ~w~Save~n~\ ~g~Press Y - ~w~Save~n~\
~g~Press N - ~w~Cancel~n~\ ~g~Press N - ~w~Cancel~n~\
~g~Hold SPACE - ~w~Faster edit" ); ~g~Hold SPACE - ~w~Faster edit"
);
SendClientMessage( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You have started editing the component." ); SendClientMessage( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You have started editing the component." );
SetTimerEx( "OnUpdateVehicleComponents", TIMER_UPDATE_RATE, false, "d", playerid ); SetTimerEx( "OnUpdateVehicleComponents", TIMER_UPDATE_RATE, false, "d", playerid );
@ -589,7 +594,7 @@ thread OnPlayerCreateVehicleComponent( playerid, vehicleid, slotid )
public OnUpdateVehicleComponents( playerid ) public OnUpdateVehicleComponents( playerid )
{ {
// just incase, to avoid bugs // just incase, to avoid bugs
if( ! GetPVarType( playerid, "components_editing" ) ) if ( ! IsPlayerEditingVehicle( playerid ) || ! IsPlayerInGarage( playerid ) )
return EndPlayerEditComponent( playerid ); return EndPlayerEditComponent( playerid );
new new
@ -602,10 +607,8 @@ public OnUpdateVehicleComponents( playerid )
return SendServerMessage( playerid, "Vehicle component editing was cancelled." ), EndPlayerEditComponent( playerid ); return SendServerMessage( playerid, "Vehicle component editing was cancelled." ), EndPlayerEditComponent( playerid );
new new
LR, LR, KEYS, Float: VALUE = -1.0;
KEYS,
Float: VALUE = -1.0
;
GetPlayerKeys( playerid, KEYS, tmpVariable, LR ); GetPlayerKeys( playerid, KEYS, tmpVariable, LR );
if ( KEYS & KEY_YES ) if ( KEYS & KEY_YES )
@ -631,41 +634,53 @@ public OnUpdateVehicleComponents( playerid )
if ( KEYS & KEY_HANDBRAKE ) if ( KEYS & KEY_HANDBRAKE )
VALUE *= 3; VALUE *= 3;
new Float: tmpPosX = GetPVarFloat( playerid, "component_pos_x" );
new Float: tmpPosY = GetPVarFloat( playerid, "component_pos_y" );
new Float: tmpPosZ = GetPVarFloat( playerid, "component_pos_z" );
new Float: tmpRotX = GetPVarFloat( playerid, "component_rot_x" );
new Float: tmpRotY = GetPVarFloat( playerid, "component_rot_y" );
new Float: tmpRotZ = GetPVarFloat( playerid, "component_rot_z" );
switch( GetPVarInt( playerid, "component_edit_type" ) ) switch( GetPVarInt( playerid, "component_edit_type" ) )
{ {
case COMPONENT_EDIT_TYPE_X: case COMPONENT_EDIT_TYPE_X:
SetPVarFloat( playerid, "component_pos_x", GetPVarFloat( playerid, "component_pos_x" ) + VALUE ); SetPVarFloat( playerid, "component_pos_x", ( tmpPosX += VALUE ) );
case COMPONENT_EDIT_TYPE_Y: case COMPONENT_EDIT_TYPE_Y:
SetPVarFloat( playerid, "component_pos_y", GetPVarFloat( playerid, "component_pos_y" ) + VALUE ); SetPVarFloat( playerid, "component_pos_y", ( tmpPosY += VALUE ) );
case COMPONENT_EDIT_TYPE_Z: case COMPONENT_EDIT_TYPE_Z:
SetPVarFloat( playerid, "component_pos_z", GetPVarFloat( playerid, "component_pos_z" ) + VALUE ); SetPVarFloat( playerid, "component_pos_z", ( tmpPosZ += VALUE ) );
case COMPONENT_EDIT_TYPE_RX: case COMPONENT_EDIT_TYPE_RX:
SetPVarFloat( playerid, "component_rot_x", GetPVarFloat( playerid, "component_rot_x" ) + ( ( VALUE * 360 ) / 100 ) * 10 ); SetPVarFloat( playerid, "component_rot_x", ( tmpRotX += ( ( VALUE * 360 ) / 100 ) * 10 ) );
case COMPONENT_EDIT_TYPE_RY: case COMPONENT_EDIT_TYPE_RY:
SetPVarFloat( playerid, "component_rot_y", GetPVarFloat( playerid, "component_rot_y" ) + ( ( VALUE * 360 ) / 100 ) * 10 ); SetPVarFloat( playerid, "component_rot_y", ( tmpRotY += ( ( VALUE * 360 ) / 100 ) * 10 ) );
case COMPONENT_EDIT_TYPE_RZ: case COMPONENT_EDIT_TYPE_RZ:
SetPVarFloat( playerid, "component_rot_z", GetPVarFloat( playerid, "component_rot_z" ) + ( ( VALUE * 360 ) / 100 ) * 10 ); SetPVarFloat( playerid, "component_rot_z", ( tmpRotZ += ( ( VALUE * 360 ) / 100 ) * 10 ) );
default: default:
return EndPlayerEditComponent( playerid, v, slotid ); return EndPlayerEditComponent( playerid, v, slotid );
} }
new // add movement limit of MAX_COMPONENT_OFFSET units
Float: tmpPosX = GetPVarFloat( playerid, "component_pos_x" ), if ( tmpPosX > MAX_COMPONENT_OFFSET ) tmpPosX = MAX_COMPONENT_OFFSET;
Float: tmpPosY = GetPVarFloat( playerid, "component_pos_y" ), else if ( tmpPosX < -MAX_COMPONENT_OFFSET ) tmpPosX = -MAX_COMPONENT_OFFSET;
Float: tmpPosZ = GetPVarFloat( playerid, "component_pos_z" ),
Float: tmpRotX = GetPVarFloat( playerid, "component_rot_x" ), if ( tmpPosY > MAX_COMPONENT_OFFSET ) tmpPosY = MAX_COMPONENT_OFFSET;
Float: tmpRotY = GetPVarFloat( playerid, "component_rot_y" ), else if ( tmpPosY < -MAX_COMPONENT_OFFSET ) tmpPosY = -MAX_COMPONENT_OFFSET;
Float: tmpRotZ = GetPVarFloat( playerid, "component_rot_z" )
; if ( tmpPosZ > MAX_COMPONENT_OFFSET ) tmpPosZ = MAX_COMPONENT_OFFSET;
AttachDynamicObjectToVehicle( g_vehiclePimpData[ ownerid ] [ v ] [ E_OBJECT ] [ slotid ], g_vehicleData[ ownerid ] [ v ] [ E_VEHICLE_ID ], else if ( tmpPosZ < -MAX_COMPONENT_OFFSET ) tmpPosZ = -MAX_COMPONENT_OFFSET;
// attach object to vehicle
AttachDynamicObjectToVehicle(
g_vehiclePimpData[ ownerid ] [ v ] [ E_OBJECT ] [ slotid ], g_vehicleData[ ownerid ] [ v ] [ E_VEHICLE_ID ],
tmpPosX, tmpPosY, tmpPosZ, tmpPosX, tmpPosY, tmpPosZ,
tmpRotX, tmpRotY, tmpRotZ ); tmpRotX, tmpRotY, tmpRotZ
);
} }
return SetTimerEx( "OnUpdateVehicleComponents", TIMER_UPDATE_RATE, false, "d", playerid ); return SetTimerEx( "OnUpdateVehicleComponents", TIMER_UPDATE_RATE, false, "d", playerid );
} }
@ -675,37 +690,24 @@ stock EndPlayerEditComponent( playerid, vehicleid = -1, slotid = -1, bool: save
{ {
if ( save ) if ( save )
{ {
new
Float: tmpPosX = GetPVarFloat( playerid, "component_pos_x" ),
Float: tmpPosY = GetPVarFloat( playerid, "component_pos_y" ),
Float: tmpPosZ = GetPVarFloat( playerid, "component_pos_z" )
;
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ] = GetPVarFloat( playerid, "component_rot_x" ); g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ] = GetPVarFloat( playerid, "component_rot_x" );
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ] = GetPVarFloat( playerid, "component_rot_y" ); g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ] = GetPVarFloat( playerid, "component_rot_y" );
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ] = GetPVarFloat( playerid, "component_rot_z" ); g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ] = GetPVarFloat( playerid, "component_rot_z" );
// the X is the distance from 0.0 g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ] = GetPVarFloat( playerid, "component_pos_x" );
if ( floatabs( tmpPosX ) / 2 > 2.5 ) { g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ] = GetPVarFloat( playerid, "component_pos_y" );
SendServerMessage( playerid, "The object breaches the X axis limit for this vehicle. It has been moved." ), tmpPosX = 0.0; g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ] = GetPVarFloat( playerid, "component_pos_z" );
}
if ( floatabs( tmpPosY ) / 2 > 2.5 ) { format(
SendServerMessage( playerid, "The object breaches the Y axis limit for this vehicle. It has been moved." ), tmpPosY = 0.0; szNormalString, sizeof( szNormalString ),
} "UPDATE `COMPONENTS` SET `X`=%f,`Y`=%f,`Z`=%f,`RX`=%f,`RY`=%f,`RZ`=%f WHERE `ID`=%d",
if ( floatabs( tmpPosZ ) / 2 > 2.5 ) {
SendServerMessage( playerid, "The object breaches the Z axis limit for this vehicle. It has been moved." ), tmpPosZ = 0.0;
}
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ] = tmpPosX;
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ] = tmpPosY;
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ] = tmpPosZ;
format( szNormalString, sizeof( szNormalString ), "UPDATE `COMPONENTS` SET `X`=%f,`Y`=%f,`Z`=%f,`RX`=%f,`RY`=%f,`RZ`=%f WHERE `ID`=%d",
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_SQL_ID ] [ slotid ] ); g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_SQL_ID ] [ slotid ]
);
mysql_single_query( szNormalString ); mysql_single_query( szNormalString );
} }
DeletePVar( playerid, "components_editing" ); DeletePVar( playerid, "components_editing" );
DeletePVar( playerid, "component_edit_type" ); DeletePVar( playerid, "component_edit_type" );
DeletePVar( playerid, "component_pos_x" ); DeletePVar( playerid, "component_pos_x" );
@ -717,14 +719,16 @@ stock EndPlayerEditComponent( playerid, vehicleid = -1, slotid = -1, bool: save
if ( vehicleid != -1 && slotid != -1 ) if ( vehicleid != -1 && slotid != -1 )
{ {
AttachDynamicObjectToVehicle( g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_OBJECT ] [ slotid ], AttachDynamicObjectToVehicle(
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_OBJECT ] [ slotid ],
g_vehicleData[ playerid ] [ vehicleid ] [ E_VEHICLE_ID ], g_vehicleData[ playerid ] [ vehicleid ] [ E_VEHICLE_ID ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_X ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Y ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_Z ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RX ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ], g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RY ] [ slotid ],
g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ] ); g_vehiclePimpData[ playerid ] [ vehicleid ] [ E_RZ ] [ slotid ]
);
} }
HidePlayerHelpDialog( playerid ); HidePlayerHelpDialog( playerid );
@ -841,7 +845,7 @@ hook OnPlayerEndModelPreview( playerid, handleid )
/* ** Commands ** */ /* ** Commands ** */
CMD:px( playerid, params[ ] ) CMD:px( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_X ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_X );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the X axis of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the X axis of the component." );
@ -849,7 +853,7 @@ CMD:px( playerid, params[ ] )
CMD:py( playerid, params[ ] ) CMD:py( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_Y ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_Y );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Y axis of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Y axis of the component." );
@ -857,7 +861,7 @@ CMD:py( playerid, params[ ] )
CMD:pz( playerid, params[ ] ) CMD:pz( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_Z ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_Z );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Z axis of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Z axis of the component." );
@ -865,7 +869,7 @@ CMD:pz( playerid, params[ ] )
CMD:rx( playerid, params[ ] ) CMD:rx( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RX ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RX );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the X rotation of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the X rotation of the component." );
@ -873,7 +877,7 @@ CMD:rx( playerid, params[ ] )
CMD:ry( playerid, params[ ] ) CMD:ry( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RY ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RY );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Y rotation of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Y rotation of the component." );
@ -881,8 +885,12 @@ CMD:ry( playerid, params[ ] )
CMD:rz( playerid, params[ ] ) CMD:rz( playerid, params[ ] )
{ {
if ( GetPVarType( playerid, "components_editing" ) == 0 ) return SendError( playerid, "You're not editing a vehicle." ); if ( ! IsPlayerEditingVehicle( playerid ) ) return SendError( playerid, "You're not editing a vehicle." );
SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RZ ); SetPVarInt( playerid, "component_edit_type", COMPONENT_EDIT_TYPE_RZ );
return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Z rotation of the component." ); return SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GARAGE]"COL_WHITE" You're now editing the Z rotation of the component." );
} }
stock IsPlayerEditingVehicle( playerid ) {
return GetPVarType( playerid, "components_editing" ) != 0;
}