SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 22/06/2013, 04:53 PM   #1
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default World position from vehicle offset

Yoo, I was wondering on how I would get the position of the offset of a vehicle in world values. For example, I'd use http://wiki.sa-mp.com/wiki/GetVehicleModelInfo to get the position of the fuel cap. However when this is done and I want to get the coordinates, and all it returns is 0 as I only use the GetVehicleModelInfo function in order to retrieve values. I then began a search to see if anyone had the solution, and I came across a post where something about trigonometry was mentioned. Trigonometry will be used to calculate the world position from a vehicle position (and offset) which will return the value of the fuel cap, or any example you wish to use. I have no idea how to do trigonometry in association with coding as that's not the kind of thing I get taught in math class. If someone could create a function for me or explain how to then it would be greatly appreciated
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 22/06/2013, 06:28 PM   #2
Stylock
Huge Clucker
 
Stylock's Avatar
 
Join Date: Dec 2010
Posts: 315
Reputation: 155
Default Re: World position from vehicle offset

Not sure, but is this what your looking for: http://forum.sa-mp.com/showthread.ph...76#post2580576
Stylock is offline   Reply With Quote
Old 22/06/2013, 06:52 PM   #3
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: World position from vehicle offset

I already had a similar function however I will try yours and compare results
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 22/06/2013, 07:22 PM   #4
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: World position from vehicle offset

pawn Code:
CMD:wheelpos(playerid,params[])
{
    new str[128],str2[128],str3[128];

    new Float:x,Float:y,Float:z,Float:a;

    new Float:vx,Float:vy,Float:vz;
   
    new Float:rx,Float:ry,Float:rz;
   
    new Float:nx,Float:ny,Float:nz,str4[128];
   
    GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
    GetVehicleZAngle(GetPlayerVehicleID(playerid),a);
    GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
    GetVehiclePosEx(GetPlayerVehicleID(playerid),vx,vy,vz,0.1,0.1,0.1);
   
    nx = vx-x;
    ny = vy-y;
    nz = vz-z;
    GetVehicleRelativePos(GetPlayerVehicleID(playerid),rx,ry,rz,0.1,0.1,0.1);

    format(str,128,"x = %f y = %f z = %f",x,y,z);
    format(str2,128,"wheelinfo: x = %f y = %f z = %f",vx,vy,vz);
    format(str3,128,"relative pos: x = %f y = %f z = %f - unused",rx,ry,rz);
    format(str4,128,"difference x = %f y = %f z = %f",nx,ny,nz);

    SendClientMessage(playerid,-1,str);
    SendClientMessage(playerid,-1,str2);
    SendClientMessage(playerid,-1,str3);
    SendClientMessage(playerid,-1,str4);
    //other stuff
    return 1;
}

Here's part of what I've been doing, however I just want to return the location of the front wheels however I believe what I have done is slightly wrong..
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 22/06/2013, 07:33 PM   #5
Stylock
Huge Clucker
 
Stylock's Avatar
 
Join Date: Dec 2010
Posts: 315
Reputation: 155
Default Re: World position from vehicle offset

Idk what you're doing, but I noticed one mistake:
Code:
GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
You need to pass the model ID, not the vehicle ID
Stylock is offline   Reply With Quote
Old 22/06/2013, 08:14 PM   #6
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: World position from vehicle offset

Quote:
Originally Posted by Stylock View Post
Idk what you're doing, but I noticed one mistake:
Code:
GetVehicleModelInfo(GetPlayerVehicleID(playerid),VEHICLE_MODEL_INFO_WHEELSFRONT,vx,vy,vz);
You need to pass the model ID, not the vehicle ID
Ahh, silly mistake. What I'm trying to do is get the offset values, and return it in the world x,y,z. So as a test I could create an object where the values I get from the offset info, then do some extra changing around.

So, vehicle pos+vehicle offset = object and world value. The object will be created at the coordinates from the offset values
__________________
once average now terrible
WillyP is offline   Reply With Quote
Old 22/06/2013, 10:03 PM   #7
Stylock
Huge Clucker
 
Stylock's Avatar
 
Join Date: Dec 2010
Posts: 315
Reputation: 155
Default Re: World position from vehicle offset

That's what the function I posted does. You need to pass the petrol cap's offsets to the function and it will calculate the wolrd coordinates.
Stylock is offline   Reply With Quote
Old 23/06/2013, 10:44 AM   #8
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,027
Reputation: 63
Default Re: World position from vehicle offset

I need something so that it stores the value until it has been removed. I used objects however obviously when the vehicle moved they didn't stick. Basically getting the offset position and saving it to the vehicle, probably using a timer to keep it updated. P.S: I don't actually want the fuel cap, I lied

EDIT: I have it working now, thanks for all your help!
__________________
once average now terrible

Last edited by WillyP; 23/06/2013 at 11:29 AM.
WillyP 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
Maths :( (Vehicle tire offset) MP2 Scripting Help 3 09/04/2016 10:10 AM
Vehicle position bug _[HuN]_Epsilon_ Help Archive 5 06/08/2011 01:25 AM
how can i detect if a player is shooting at a vehicle + offset? Donya Help Archive 2 14/05/2011 12:49 AM
vehicle pos offset Q thomas.. Help Archive 2 03/10/2010 03:40 PM


All times are GMT. The time now is 07:16 PM.


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