Fireman job help
#1

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);
}
Reply
#2

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.
Reply
#3

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...
Reply
#4

BUMP !
Reply
#5

Anybody knows?
Reply
#6

tested, it works

PHP код:
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),fAimingCoords[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
Reply
#7

Thank you man,it works!! REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)