PDA

View Full Version : Fireman job help


StreetboyBalkan
03/03/2016, 03:07 PM
I need a help in creating fireman job.I want to detect when player is aiming fire object with firetruck,but i can't find the working code..


if(HOLDING(KEY_FIRE) && GetVehicleModel(GetPlayerVehicleID(playerid)) == 407) {
new Float: fAimingCoords[3];
GetPlayerCameraPos(playerid, fAimingCoords[0], fAimingCoords[1], fAimingCoords[2]);
new Float: pos[3];
GetDynamicObjectPos(vatra[0], pos[0], pos[1], pos[2]);
if(IsPointInRangeOfPoint(pos[0], pos[1], pos[2], fAimingCoords[0], fAimingCoords[1], fAimingCoords[2], 3.0))
{
DestroyDynamicObject(vatra[0]);
}
}

stock IsPointInRangeOfPoint(Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, Float:range)
{
x2 -= x;
y2 -= y;
z2 -= z;
return ((x2 * x2) + (y2 * y2) + (z2 * z2)) < (range * range);
}

Vince
03/03/2016, 04:30 PM
The HOLDING macro is often used wrongly. What is usually desired is PRESSED and RELEASED. OnPlayerKeyStateChange is only called when a key changes. You can press and then hold KEY_FIRE for an eternity but it will still only register a press when you first press it and a release when you release it. Only if you press an additional while still holding KEY_FIRE will it register as holding.

You will need to set a timer when they first press the key and it and kill the timer when they release it. Alternatively, set and unset a variable and use OnPlayerUpdate if you require faster interaction.

StreetboyBalkan
04/03/2016, 08:11 PM
Okay,but that's not the problem,i get wrong aiming coords,i need to know if there is some other method to get aiming coords from firetruck...

StreetboyBalkan
05/03/2016, 08:39 PM
BUMP !

StreetboyBalkan
09/03/2016, 02:26 PM
Anybody knows?

AbyssMorgan
09/03/2016, 02:54 PM
tested, it works


public OnPlayerKeyStateChange(playerid,newkeys,oldkeys){

if(HOLDING(KEY_FIRE) && GetVehicleModel(GetPlayerVehicleID(playerid)) == 407) {
new Float:fAimingCoords[5],Float:NewCoords[3],Float:pos[3];
GetVehiclePos(GetPlayerVehicleID(playerid),fAiming Coords[0],fAimingCoords[1],fAimingCoords[2]);
GetPlayerCameraRotation(playerid,fAimingCoords[3],fAimingCoords[4]);

GetPointInFront3D(fAimingCoords[0],fAimingCoords[1],fAimingCoords[2],fAimingCoords[3],fAimingCoords[4],10.0,NewCoords[0],NewCoords[1],NewCoords[2]);

//Here you can do loops searching fire
GetDynamicObjectPos(vatra[0],pos[0],pos[1],pos[2]);
if(IsPointNearly2Points3D(pos[0],pos[1],pos[2],fAimingCoords[0],fAimingCoords[1],fAimingCoords[2],NewCoords[0],NewCoords[1],NewCoords[2],3.0)){
DestroyDynamicObject(vatra[0]);
}

}


return 1;
}


Include:
3DTryg.inc (http://8.ct8.pl/dl.php?id=1)

StreetboyBalkan
10/03/2016, 09:15 AM
Thank you man,it works!! REP+