SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 25/07/2013, 01:14 PM   #1
dominik523
Gangsta
 
dominik523's Avatar
 
Join Date: Feb 2013
Location: Croatia
Posts: 843
Reputation: 115
Default Is player standing at vehicle's trunk or hood

Hey! I want to add to my command /trunk part of the code which will get vehicle's trunk X,Y and Z coordinates. I know I have to use GetVehicleModelInfo and GetVehiclePos, and use sinus with that, but I don't know how. Can anyone please help me? I really want to create that.
dominik523 is offline   Reply With Quote
Old 25/07/2013, 01:19 PM   #2
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Is player standing at vehicle's trunk or hood

You can always try getting a vehicle's position, getting the X and Y position in front of it, and the X and Y position behind it, see if they're close to one of them, and that's it. I know how to use mathematical things such as 'sin' and 'cos' etc, but I just don't know how to use it in SA-MP terms. I'm probably gonna start learning now and I might be able to get back to you if nobody else does.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 25/07/2013, 01:21 PM   #3
redreaper666
Big Clucker
 
redreaper666's Avatar
 
Join Date: Nov 2011
Location: Mapping my Room and Scripting my Life
Posts: 135
Reputation: 73
Default Re: Is player standing at vehicle's trunk or hood

new Float:X1,Y1,Z1,X2,Y2,Z2;
GetVehiclePos(vehicleid,X1,Y1,Z1);
GetPlayerPos(playerid,X2,Y2,Z2);

then you need to test:
If(Y2-Y1) = a positive amount then hes at the trunk/hood.
If(Y2-Y1) = a negative amount then hes at the trunk/hood.

should be working like that if the car is at its location always X=0 Y=0 Z=0
-Y is the back of the car
+Y is the front of the car
__________________
Redreaper666's Creations:
______________________________
>[Server] Working together on DD/DM Deathmatch - Xtreme DM by Himself ||
>[Filterscripts]
-[FS]Neon4Cars:http://forum.sa-mp.com/showthread.ph...26#post2551026
-[FS]Working Ferris Wheel:http://forum.sa-mp.com/showthread.php?t=417814
-[FS]Driveable Wheelchair:http://forum.sa-mp.com/showthread.php?t=416883
-[FS]Easy Load/Unload/Reloadfs System: http://forum.sa-mp.com/showthread.ph...73#post2599573
>[Maps]
-[Map]GtaII Map:http://forum.sa-mp.com/showthread.php?t=303460
>Nothing is impossible<
redreaper666 is offline   Reply With Quote
Old 25/07/2013, 01:22 PM   #4
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Is player standing at vehicle's trunk or hood

Not exactly. It's very dependent on which way the car is facing...
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 25/07/2013, 01:24 PM   #5
redreaper666
Big Clucker
 
redreaper666's Avatar
 
Join Date: Nov 2011
Location: Mapping my Room and Scripting my Life
Posts: 135
Reputation: 73
Default Re: Is player standing at vehicle's trunk or hood

Getvehiclerotation then aswell
__________________
Redreaper666's Creations:
______________________________
>[Server] Working together on DD/DM Deathmatch - Xtreme DM by Himself ||
>[Filterscripts]
-[FS]Neon4Cars:http://forum.sa-mp.com/showthread.ph...26#post2551026
-[FS]Working Ferris Wheel:http://forum.sa-mp.com/showthread.php?t=417814
-[FS]Driveable Wheelchair:http://forum.sa-mp.com/showthread.php?t=416883
-[FS]Easy Load/Unload/Reloadfs System: http://forum.sa-mp.com/showthread.ph...73#post2599573
>[Maps]
-[Map]GtaII Map:http://forum.sa-mp.com/showthread.php?t=303460
>Nothing is impossible<
redreaper666 is offline   Reply With Quote
Old 25/07/2013, 01:38 PM   #6
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,960
Reputation: 94
Default Re: Is player standing at vehicle's trunk or hood

Something like that maybe... but it's hard to know, it's kind of approximate.
pawn Code:
stock GetXYBehindVehicle(vehicleid, &Float:x2, &Float:y2, Float:distance)
{
    new Float:a;
    GetVehiclePos(vehicleid, x2, y2, a);
    GetVehicleZAngle(vehicleid, a);
    x2 += (distance * floatsin(-a+180, degrees));
    y2 += (distance * floatcos(-a+180, degrees));
}

stock GetTrunkPos(vehicleid, &Float: x3, &Float:y3, &Float:z3)
{
    new Float: x, Float: y;
    new Float: sizeX, Float: sizeY, Float:sizeZ[2];
   
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, sizeX, sizeY, sizeZ[0]);
   
    GetXYBehindVehicle(vehicleid, x, y, sizeY/2);
    x3 = x;
    y3 = y;
   
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_REAR_BUMPER_Z , sizeX, sizeY, sizeZ[1]);
   
    z3 = (sizeZ[1] + sizeZ[0]/2);
}
[XST]O_x is offline   Reply With Quote
Old 25/07/2013, 04:55 PM   #7
dominik523
Gangsta
 
dominik523's Avatar
 
Join Date: Feb 2013
Location: Croatia
Posts: 843
Reputation: 115
Default Re: Is player standing at vehicle's trunk or hood

Quote:
Originally Posted by [XST]O_x View Post
Something like that maybe... but it's hard to know, it's kind of approximate.
pawn Code:
stock GetXYBehindVehicle(vehicleid, &Float:x2, &Float:y2, Float:distance)
{
    new Float:a;
    GetVehiclePos(vehicleid, x2, y2, a);
    GetVehicleZAngle(vehicleid, a);
    x2 += (distance * floatsin(-a+180, degrees));
    y2 += (distance * floatcos(-a+180, degrees));
}

stock GetTrunkPos(vehicleid, &Float: x3, &Float:y3, &Float:z3)
{
    new Float: x, Float: y;
    new Float: sizeX, Float: sizeY, Float:sizeZ[2];
   
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, sizeX, sizeY, sizeZ[0]);
   
    GetXYBehindVehicle(vehicleid, x, y, sizeY/2);
    x3 = x;
    y3 = y;
   
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_REAR_BUMPER_Z , sizeX, sizeY, sizeZ[1]);
   
    z3 = (sizeZ[1] + sizeZ[0]/2);
}
what will those two stocks return?
dominik523 is offline   Reply With Quote
Old 25/07/2013, 05:10 PM   #8
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: Is player standing at vehicle's trunk or hood

Will return nothing, but will store information in variables passed by reference
Misiur is offline   Reply With Quote
Old 25/07/2013, 05:32 PM   #9
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,960
Reputation: 94
Default Re: Is player standing at vehicle's trunk or hood

Quote:
Originally Posted by dominik523 View Post
what will those two stocks return?
You only need GetTrunkPos.

An example to use:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
   if(!strcmp(cmdtext,"/mytrunkpos")) {
    new Float:x, Float:y, Float:z;
    GetTrunkPos(GetPlayerVehicleID(playerid), x, y, z);
    new string[64]; format(string ,sizeof(string), "%.1f, %.1f, %.1f", x, y, z);
    SendClientMessage(playerid, -1, string);
    return 1; }
    return 0;
}
[XST]O_x is offline   Reply With Quote
Old 25/07/2013, 05:37 PM   #10
dominik523
Gangsta
 
dominik523's Avatar
 
Join Date: Feb 2013
Location: Croatia
Posts: 843
Reputation: 115
Default Re: Is player standing at vehicle's trunk or hood

so I have something like this:
Code:
{
	new string[128], done, idx;
	new engine, lights, alarm, doors, bonnet, boot, objective;
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(PlayerInfo[playerid][pVeh] || PlayerInfo[playerid][pVeh2] || PlayerInfo[playerid][pVeh3] || PlayerInfo[playerid][pVeh4] || PlayerInfo[playerid][pVeh5])
    {
        new Float:vx, Float:vy, Float:vz;
        // veh 1
	    GetTrunkPos(PlayerInfo[playerid][pVeh],vx,vy,vz);
	    if(IsPlayerInRangeOfPoint(playerid,1.0, vx,vy,vz))
	    {
	       ...
	    }
will adding isPlayerInRangeOfPoint after GetTrunkPos work?
dominik523 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
/trunk /hood kbalor Scripting Help 8 18/05/2014 08:51 AM
Detect if player is standing in front of car's trunk SaW_[VrTx] Scripting Help 5 06/02/2013 07:30 AM
If player is standing Sal_Kings Help Archive 1 12/05/2009 04:09 PM
Player not standing in the right direction Tisca Help Archive 1 12/02/2009 06:46 PM


All times are GMT. The time now is 03:15 AM.


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