native Float:MPDistanceCameraToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ); // calculates how distant target aim is from camera data pointed towards a certain point
Float: DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ)
stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius)
{
new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz;
GetPlayerCameraPos(playerid, cx, cy, cz);
GetPlayerCameraFrontVector(playerid, fx, fy, fz);
return (radius >= MPDistanceCameraToLocation(cx, cy, cz, x, y, z, fx, fy, fz));
}
native Float:MPGetVehicleUpsideDown(vehicleid); // returns values such as 1.0 as pointing up, -1.0 is totally upside down. returns -5.0 if car id is not 1..2000.
<&JernejL> itll always make coords 2 units above car roof <&JernejL> regardless of car rotation <&JernejL> so if car is upside down <&JernejL> it'll give you coords 2 units under it |
//1.0 = car placed on level ground / pointing up
//0.0 = car is 90 degrees on side
//-1.0 would be totally upside down
//-5.0 if car id is not 1..2000.
public OnPlayerUpdate(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid != 0)
{
new Float:health;
GetVehicleHealth(vehicleid, health);
newVehicleHealth[vehicleid] = health;
if(newVehicleHealth[vehicleid] != oldVehicleHealth[vehicleid])
{
CallLocalFunction("OnPlayerVehicleHealthChange", "iiff", playerid, vehicleid, newVehicleHealth[vehicleid], oldVehicleHealth[vehicleid]);
oldVehicleHealth[vehicleid] = newVehicleHealth[vehicleid];
}
}
}
forward OnPlayerVehicleHealthChange(playerid, vehicleid, Float:newhealth, Float:oldhealth);
public OnPlayerVehicleHealthChange(playerid, vehicleid, Float:newhealth, Float:oldhealth)
{
#pragma unused playerid
#pragma unused newhealth
#pragma unused oldhealth
if(-1.5 <= MPGetVehicleUpsideDown(vehicleid) <= -0.5)
{
new Float:Angle, Float:x, Float:y, Float:z;
GetVehicleVelocity(vehicleid, x, y, z);
GetVehicleZAngle(vehicleid, Angle);
SetVehicleZAngle(vehicleid, Angle);
SetVehicleVelocity(vehicleid, x, y, z);
}
return 1;
}
native MPGetAimTarget(PlayerID, Float:SeekRadius = 50.0); // returns player that this player is aiming at or invalid player id if no player in target area.
public OnPlayerUpdate(playerid)
{
new aimingtarget = MPGetAimTarget(playerid, 50.0);
if(aimingtarget != INVALID_PLAYER_ID)
{
SendClientMessage(playerid, "You are aiming at a player.");
}
return 1;
}
native MPGetTrailerTowingVehicle(vehicleid); // finds the vehicle that this trailer is attached to, returns invalid_vehicle_id if invalid or not attached to any towing vehicle.
new vehicleid = CreateVehicle(402, 0.0, 0.0, 0.0, 180.0, -1, -1, -1);
new vehicletrailer = CreateVehicle(402, 0.0, 0.0, 0.0, 180.0, -1, -1, -1);
AttachTrailerToVehicle(vehicletrailer, vehicleid);
new trailerowner = MPGetTrailerTowingVehicle(vehicletrailer);
printf("trailerowner = %d - vehicleid = %d", trailerowner, vehicleid);
native MPGetVehicleDriver(vehicleid);
public OnPlayerStateChange(playerid, newstate, oldstate);
{
switch(newstate)
{
case PLAYER_STATE_PASSENGER:
{
new vehicleid = GetPlayerVehicleID(playerid),
mydriver = MPGetVehicleDriver(vehicleid),
str[64]
;
format(str, 64, "Driver of this vehicle is %d", mydriver);
SendClientMessage(playerid, -1, str);
}
}
return 1;
}
native MPGetVehicleDriverCount(vehicleid); // returns number of drivers a car has (important to solve 2 drivers 1 car issue - if you wrote any decent anticheat you know what i mean)
public OnPlayerUpdate(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(1 <= vehicleid <= 2000 )
{
new drivercount = MPGetVehicleDriverCount(vehicleid);
if(drivercount > 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(GetPlayerVehicleID(i) != vehicleid) continue;
RemovePlayerFromVehicle(i);
}
}
}
return 1;
}
native MPGetVehicleOccupantCnt(vehicleid); // returns number of player a vehicle is carrying
public OnPlayerStateChange(playerid, newstate, oldstate);
{
switch(newstate)
{
case PLAYER_STATE_PASSENGER:
{
new vehicleid = GetPlayerVehicleID(playerid),
passengercount = MPGetVehicleOccupantCnt(vehicleid),
str[64]
;
format(str, 64, "There are %d players in this vehicle", passengercount);
SendClientMessage(playerid, -1, str);
}
}
return 1;
}
native MPGetVehicleSurfersCnt(vehicleid); // returns number of players surfing a vehicle
public OnPlayerStateChange(playerid, newstate, oldstate);
{
switch(newstate)
{
case PLAYER_STATE_PASSENGER:
{
new vehicleid = GetPlayerVehicleID(playerid),
surfingcount+ = MPGetVehicleSurfersCnt(vehicleid),
str[64]
;
format(str, 64, "There are %d players surfing this vehicle", surfingcount);
SendClientMessage(playerid, -1, str);
}
}
return 1;
}
native Float:MPClamp360(Float:value);
<&JernejL> it's useful if you use stuff like <&JernejL> difference between 2 angles <&JernejL> to make a "x'o clock" system <&JernejL> then you need proper angles clamped to that range
public OnGameModeInit()
{
printf("%0.2f", MPClamp360(361.0));
return 1;
}
native Float:MPDistance(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z); // distance between 2 points
#define GetDistanceBetweenPoints MPDistance
native Float:MPFDistance(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z); // distance between 2 points (faster but less precise)
native Float:MPFSQRT(Float:value); // Faster sqrt (****** the 0x5f3759df method)
// pure math
native Float:FMPVecLength(Float:v1x, Float:v1y, Float:v1z); // calculates length of a simple XYZ 3d vector (FAST,less precision)
native Float:MPDistancePointLine(Float:PointX, Float:PointY, Float:PointZ, Float:LineSx, Float:LineSy, Float:LineSz, Float:LineEx, Float:LineEy, Float:LineEz); // http://paulbourke.net/geometry/pointline/ returns super huge number 10000000 if outside of range of specified the lie segment.
native Float:MPDotProduct(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z);
native Float:MPVecLength(Float:v1x, Float:v1y, Float:v1z); // calculates length of a simple XYZ 3d vector
native MPCrossProduct(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:resx, &Float:resy, &Float:resz);
native MPFNormalize(&Float:vx, &Float:vy, &Float:vz); // fast float normalization of a vector to unit-length (makes whatever vector 1.0 long, purely to preserve direction and be able to scale it controllably)
native MPInterpolatePoint(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:resx, &Float:resy, &Float:resz, Float:distance);
I am really curious to see an example of MPProjectPointOnVehicle in a comment of the code JernejL says it could be useful to find each tire proximity. Is there an easy way to find that or how about to know a player is at the trunk (boot) of a vehicle? I was looking at this earlier and it still seems like I need a massive array to store the vehicle offsets for this or am I missing something?
|