SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 03/09/2009, 09:16 PM   #1
Tr1viUm
Big Clucker
 
Tr1viUm's Avatar
 
Join Date: Dec 2006
Posts: 143
Reputation: 0
Default Some useful 0.3 functions.

These function can also be used for players. Just change the functions to the ones that belong to players. GetVehicleVelocity will be GetPlayerVelocity... so on.

BoostVehicle
You can increase/decrease vehicle speed with this function. It's recommended to not go higher than 2.0 or lower than -2.0. Using 0.25 as speed is fine.
Code:
stock BoostVehicle(vehicleid, Float:speed){
	new Float:X, Float:Y, Float:Z, Float:A;
	GetVehicleZAngle(vehicleid, A);
	GetVehicleVelocity(vehicleid, X, Y, Z);
	X += (speed * floatsin(-A, degrees));
	Y += (speed * floatcos(-A, degrees));
	SetVehicleVelocity(vehicleid, X, Y, Z);
}
VehicleJump
You can make a vehicle go up or down. I usually set height to 1.0.
Code:
stock VehicleJump(vehicleid, Float:height){
	new Float:X, Float:Y, Float:Z;
	GetVehicleVelocity(vehicleid, X, Y, Z);
	SetVehicleVelocity(vehicleid, X, Y, Z+height);
}
StopVehicle
This surprisingly stops the vehicle... :P
Code:
stock StopVehicle(vehicleid){
	SetVehicleVelocity(vehicleid, 0.0, 0.0, 0.0);
}
Tr1viUm is offline  
Old 03/09/2009, 09:19 PM   #2
amrour
Little Clucker
 
Join Date: May 2008
Posts: 47
Reputation: 0
Default Re: Some useful 0.3 functions.

Quote:
Originally Posted by [MOB
Tr1viUm ]
It's recommended to not go higher than 2.0 or lower than 2.0. Using 0.25 as speed is fine.
hmm? that a typo?
amrour is offline  
Old 03/09/2009, 09:20 PM   #3
Tr1viUm
Big Clucker
 
Tr1viUm's Avatar
 
Join Date: Dec 2006
Posts: 143
Reputation: 0
Default Re: Some useful 0.3 functions.

Quote:
Originally Posted by Lenny.
Quote:
Originally Posted by [MOB
Tr1viUm ]
It's recommended to not go higher than 2.0 or lower than 2.0. Using 0.25 as speed is fine.
hmm? that a typo?
Yeah, should be lower than -2.0. :P
Tr1viUm is offline  
Old 03/09/2009, 09:22 PM   #4
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 6,340
Reputation: 365
Default Re: Some useful 0.3 functions.

It's funny if you go over +/- 50. But if you go too much you can get bugged.
Correlli is offline  
Old 03/09/2009, 10:23 PM   #5
Donny_k
Gangsta
 
Donny_k's Avatar
 
Join Date: May 2006
Posts: 786
Reputation: 4
Default Re: Some useful 0.3 functions.

Quote:
Originally Posted by [MOB
Tr1viUm ]
BoostVehicle
You can increase/decrease vehicle speed with this function. It's recommended to not go higher than 2.0 or lower than -2.0. Using 0.25 as speed is fine.
Code:
stock BoostVehicle(vehicleid, Float:speed){
	new Float:X, Float:Y, Float:Z, Float:A;
	GetVehicleZAngle(vehicleid, A);
	GetVehicleVelocity(vehicleid, X, Y, Z);
	X += (speed * floatsin(-A, degrees));
	Y += (speed * floatcos(-A, degrees));
	SetVehicleVelocity(vehicleid, X, Y, Z);
}
A modified version of this:

pawn Code:
AddVelocityDirection( vehicleid, Float:power = 1.0, bool:updown = true )
{
    new
      Float:x,
      Float:y,
      Float:z,
      Float:angle;

    GetVehicleVelocity( vehicleid, x, y, z );
    GetVehicleZAngle( vehicleid, angle );

    switch ( updown )
    {
        case false : //left or right (use negative power for left)
        {
            x += ( power * floatcos( angle, degrees ) );
            y += ( power * floatsin( angle, degrees ) );
        }
        case true : //front or back (use negative power for backwards)
        {
            x += ( power * floatsin( -angle, degrees ) );
            y += ( power * floatcos( -angle, degrees ) );
        }
    }

    SetVehicleVelocity( vehicleid, x, y, z );
    return true;
}

Usage:

pawn Code:
AddVelocityDirection( GetPlayerVehicleID( playerid ), 1.0 ); //forwards
AddVelocityDirection( GetPlayerVehicleID( playerid ), -1.0 ); //backwards
AddVelocityDirection( GetPlayerVehicleID( playerid ), -1.0, false ); //left strafe
AddVelocityDirection( GetPlayerVehicleID( playerid ), 1.0, false ); //right strafe
__________________
We don't stop playing because we grow old, we grow old because we stop playing.
Donny_k is offline  
 

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
[Include] [INC] LSF - Lorenc's Simple Functions (w/ gang/clan functions) Lorenc_ Includes 14 21/04/2018 04:06 AM
Help with car functions. Mirkan Help Archive 0 24/10/2009 01:05 PM
Useful functions [HUN]Gamestar Help Archive 4 04/09/2009 04:50 PM
[Include] [INC] Two useful functions Paladin Includes 2 25/08/2009 01:55 PM
New functions Frement Help Archive 3 24/08/2009 08:57 PM


All times are GMT. The time now is 01:39 AM.


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