[help] Vehicle rotation/position
#1

Hi guys, i am currently working on a escort system for airplanes,

But what happens is that hydra1 turns like the player's vehicle and hydra2 not, also the positions will be messed.
Is there a way to keep them at the right positions (left and right behind the player) and fix the rotations ?

Video:
http://www.xfire.com/video/30ae15/

Code (and yes i know /escort off works for every player, but thats to worry about later):

http://pastebin.com/CTtwCCRj

Please help
Reply
#2

pawn Код:
#include <a_samp>

new
    hydra1, hydra2, escort;

forward streamhydra1(playerid);
forward streamhydra2(playerid);


public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print("    Hydra escort [FS] By Gamer931215   ");
    print("--------------------------------------\n");
    return 1;
}


public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,0x00B9FFFF,"This server is running gamer's escort mod [beta 0.1b].");
    return 1;
}



public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/escort on", cmdtext, true, 10) == 0)
    {
        if(!escort)
        {
            new
                v = GetPlayerVehicleID(playerid);
                model = GetVehicleModel(v);
               
            if(model == 520 || model == 577 || model == 511 ||model == 592 || model == 512 || model == 513 || model == 519 || model == 593 || model == 553))
            {
                new
                    Float:x, Float:y, Float:z;
                   
                GetVehiclePos(v, x, y, z);
                hydra1 = CreateVehicle(520, x, y, z+50, 0, 0, -1);
                hydra2 = CreateVehicle(520, x, y, z+80, 0, 0, -1);
               
                SetTimerEx("streamhydras",100,true,"i",playerid);
               
                escort = 1;
               
            }
            return SendClientMessage(playerid,0x00B9FFFF,"You are not in a plane!");
        }
        return SendClientMessage(playerid,0x00B9FFFF,"The hydras are already escorting an plane!");
    }

    if (strcmp("/escort off", cmdtext, true, 10) == 0)
    {
        DestroyVehicle(hydra1);
        DestroyVehicle(hydra2);
        escort = 0;
        KillTimer(streamhydras(playerid));
        return 1;
    }

    return 0;
}

public streamhydras(playerid)
{
    new
        v = GetPlayerVehicleID(playerid);
   
    if(v)
    {
        new
            Float:x,Float:y,Float:z,Float:rot,
            Float:tmprot;
       
        GetVehiclePos(v, x, y, z);
        GetVehicleZAngle(v, rot);
        SetVehiclePos(hydra1, x+20, y+23, z+1);
       
        printf("[DEBUG]: hydra1 apparent rotation: %f", rot);
       
        SetVehicleZAngle(hydra1, rot);
        GetVehicleZAngle(hydra1, tmprot);
       
        printf("[DEBUG]: hydra1 rotation: %f", tmprot);
       
        SetVehiclePos(hydra2, x-20, y+23, z+1);
       
        printf("[DEBUG]: hydra2 apparent rotation: %f", rot);
       
        SetVehicleZAngle(hydra2, rot);
        GetVehicleZAngle(hydra2, tmprot);
       
        printf("[DEBUG]: hydra1 rotation: %f", tmprot);
        return 1;
    }
    DestroyVehicle(hydra1);
    DestroyVehicle(hydra2);
    escort = 0;
    KillTimer(streamhydras(playerid));
}
I haven't tested it, I see nothing wrong with the code in this script.

If this doesn't work (I really only optimized and added 4 debug messages)

Try removing ALL Filterscripts, if that dont work, change to a blank gamemode (lvmd? bare?)
Reply
#3

I think he meant as in, when he turns the plane's don't turn angles...and if you turn left, the plane on the right goes higher, and the hydra on the left goes lower.

EDIT: I'll try to fix it for you, just not sure if I can get the turn left right etc stuff done.

EDIT2: Uhh turns out you need to use that one function GetXYbehindplayer or something, because they only rotate, but they only move on the X,Y units, from left to right, not skipping
Reply
#4

Well i found that function and tried it, but doesnt work for me, can you help me please ?

I am using:

Код:
#include <a_samp>
new hydra1;
new hydra2;
forward streamhydra1(playerid);
forward streamhydra2(playerid);
new escort;

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("    Hydra escort [FS] By Gamer931215   ");
	print("--------------------------------------\n");
	return 1;
}


public OnPlayerConnect(playerid)
{
	SendClientMessage(playerid,0x00B9FFFF,"This server is running gamer's escort mod [beta 0.1b].");
	return 1;
}



public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/escort on", cmdtext, true, 10) == 0)
	{
	    if (escort == 0) {
	    if (GetVehicleModel(GetVehicleModel(GetPlayerVehicleID(playerid)) == 520 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 577 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 511 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 592 ||
		GetVehicleModel(GetPlayerVehicleID(playerid)) == 512 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 513 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 519 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 593 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 553)) {
		new Float:x,Float:y,Float:z;
		GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
		hydra1 = AddStaticVehicle(520,x,y,z+50,0,0);
		hydra2 = AddStaticVehicle(520,x,y,z+80,0,0);
		SetTimerEx("streamhydras",10,true,"i",playerid);
		escort = 1;
		KillTimer(streamhydras(playerid));
		} else return SendClientMessage(playerid,0x00B9FFFF,"The hydras are already escorting an plane!");
		} else return SendClientMessage(playerid,0x00B9FFFF,"You are not in a plane!");
		return 1;
	}

	if (strcmp("/escort off", cmdtext, true, 10) == 0)
	{
		DestroyVehicle(hydra1);
		DestroyVehicle(hydra2);
		escort = 0;
		KillTimer(streamhydras(playerid));
		return 1;
	}

	return 0;
}

public streamhydras(playerid){
if (IsPlayerInAnyVehicle(playerid) == 1) {
new Float:x,Float:y,Float:z,Float:rot;
GetPlayerPos(playerid,x,y,z);
GetXYBehindPlayer(playerid,x,y,30);
GetVehicleZAngle(GetPlayerVehicleID(playerid),rot);
SetVehiclePos(hydra1,x,y,z);SetVehicleZAngle(hydra1,rot);
SetVehiclePos(hydra2,x,y,z);SetVehicleZAngle(hydra2,rot);
} else {
DestroyVehicle(hydra1);
DestroyVehicle(hydra2);
escort = 0;
KillTimer(streamhydras(playerid));
}}

stock GetXYBehindPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
    new Float:pos[3];
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid,pos[2]);
    GetXYBehindPoint(pos[0],pos[1],x,y,pos[2],dis);
}

stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:angle,Float:distance)
{
    x2 = x - (distance * floatsin(-angle,degrees));
    y2 = y - (distance * floatcos(-angle,degrees));
}
Rotation isnt fixed, but thats not the biggest problem, also it doenst update the player position BEHIND the player so still the same story
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)