Originally Posted by LetsOWN[PL]
Hello.
Do You mean, that Your vehicle 'shakes' around?
Werid..
But okay. All You have to do, is to store somewhere position of vehicle and add randomly generated values to those values of XYZ coordinates. To make 'vibration' effect, You'll have to repeat this proccess in short periods.
Here are Your bits. It gave me some fun, when I saw the results.. XD
pawn Код:
// "Header", put it somewhere on the top of the script #define VIB_INTERVAL 10 // in ms
#define VIB_RAND_MAX_X 0.5 // (float) max inclination on X axis ( between this value [in this case: 3.5] and it's negative value: -3.5) #define VIB_RAND_MAX_Y 0.5 // as above - for Y aixs #define VIB_RAND_MAX_Z 0.5 // as above - for Z axis #define VIB_RAND_MAX_R 3.25 // as above - for angle
// guess #define ON true #define OFF false
enum V_SHKR { bool:V_IsShaking, V_ShakeTimer, Float:V_Position[ 4 ] } new VibratingVehicles[ MAX_VEHICLES ][ V_SHKR ]; // Our data structure
forward GenerateVibration ( vehicleid ); forward Float:RandomFloat ( Float:max, bool:includeNegative = false ); native IsValidVehicle( vehicleid );
Toggle vibrations off or on:
pawn Код:
// --------------------------------------------- " Switch on/off " button ------ stock ToggleVehicleVibration( vehicleid, bool:toggle ) { if( !IsValidVehicle(vehicleid) ) // vehicleid points at invalid (non-created?) vehicle return false;
if(( !toggle && !VibratingVehicles[ vehicleid ][ V_IsShaking ] ) || ( toggle && VibratingVehicles[ vehicleid ][ V_IsShaking ] ) ) return false;
if( !toggle ) { KillTimer( VibratingVehicles[ vehicleid ][ V_ShakeTimer ] ); VibratingVehicles[ vehicleid ][ V_IsShaking ] = false; SetVehiclePos( vehicleid, VibratingVehicles[ vehicleid ][ V_Position ][ 0 ], VibratingVehicles[ vehicleid ][ V_Position ][ 1 ], VibratingVehicles[ vehicleid ][ V_Position ][ 2 ] ); SetVehicleZAngle( vehicleid, VibratingVehicles[ vehicleid ][ V_Position ][ 3 ] ); VibratingVehicles[ vehicleid ][ V_Position ][ 0 ] = VibratingVehicles[ vehicleid ][ V_Position ][ 1 ] = VibratingVehicles[ vehicleid ][ V_Position ][ 2 ] = VibratingVehicles[ vehicleid ][ V_Position ][ 3 ] = 0.0; return true; } else { VibratingVehicles[ vehicleid ][ V_IsShaking ] = true; GetVehiclePos( vehicleid, VibratingVehicles[ vehicleid ][ V_Position ][ 0 ], VibratingVehicles[ vehicleid ][ V_Position ][ 1 ], VibratingVehicles[ vehicleid ][ V_Position ][ 2 ] ); GetVehicleZAngle( vehicleid, VibratingVehicles[ vehicleid ][ V_Position ][ 3 ] ); VibratingVehicles[ vehicleid ][ V_ShakeTimer ] = SetTimerEx( "GenerateVibration", VIB_INTERVAL, true, "d", vehicleid ); return true; } }
Vibration generator itself:
pawn Код:
// -------------------------------------------------- Generates vibration ------ public GenerateVibration( vehicleid ) { new Float:mod_X, Float:mod_Y, Float:mod_Z, Float:mod_R; mod_X = RandomFloat( VIB_RAND_MAX_X, true ) + VibratingVehicles[ vehicleid ][ V_Position ][ 0 ]; mod_Y = RandomFloat( VIB_RAND_MAX_Y, true ) + VibratingVehicles[ vehicleid ][ V_Position ][ 1 ]; mod_Z = RandomFloat( VIB_RAND_MAX_Z, false ) + VibratingVehicles[ vehicleid ][ V_Position ][ 2 ]; // // set to true, if you want the vehicle sometimes fall beneath the ground.. mod_R = RandomFloat( VIB_RAND_MAX_R, true) + VibratingVehicles[ vehicleid ][ V_Position ][ 3 ]; SetVehiclePos( vehicleid, mod_X, mod_Y, mod_Z ); SetVehicleZAngle( vehicleid, mod_R ); }
Random floating number generator:
pawn Код:
// ------------------------------------- Generates random floating number ------ // if max is set to 1.0 and includeNegative is true, then You can // get from -0.999 to 0.999 as the result. // I have no idea about how fast is that, it's just for purposes of this shaking thing.. stock Float:RandomFloat( Float:max, bool:includeNegative = false ) { new d_max = floatround( floatmul(max, 1000)) ; if( includeNegative ) { new _random = random( 2 * d_max ) - d_max; return floatdiv( float(_random), 1000 ); } else d_max = random( d_max ); return floatdiv( float(d_max), 1000 ); }
.. one more thing
pawn Код:
// Just for testing COMMAND:testvibration( playerid, params[] ) { new Vehicle = GetPlayerVehicleID( playerid ); if(ToggleVehicleVibration( Vehicle, !VibratingVehicles[ Vehicle ][ V_IsShaking ] )) SendClientMessage( playerid, -1, "Function returned true" ); else SendClientMessage( playerid, -1, "Function returned false" ); return true; }
NOTE: Aha, when You exit vibrating vehicle, it still vibrates! Do whatever You want with this funny exception ![Smiley](images/smilies/smile.png)
.. Still: I think such function is rather pointless..
Greetings
|