17.11.2011, 20:40
(
Last edited by Gamer_Z; 18/11/2011 at 09:16 AM.
)
Well I was working for a nice filterscript for the users on this forum, but erm I have some problems which I can't solve, at this point I have no idea what to do now, the debug part works fine, the /ap command works fine until a few nodes and your car gets slammed away into some space...
If you're a bit confused let me explain what this script exactly does:
-- The route I chose: The car will drive from LV ammu parking to SF
-- The debug mode (cmd: /debug) just teleports you to each node on the path, in correct order from start to end
-- The autopilot mode (cmd: /ap) does start, it uses my custom function that can 'push' a vehicle towards a given XY position.
-- You have to be always in a car, if you exit the timer is destroyed, and also the route etc... the script will 'pause', you can re-use /ap or /debug
-- the autopilot should drive your car on the path, without that you need to do anything.
so now you know the concept of the script, again I need help, If this script will die no problem for me, I was making this for the sa-mp community to show off even more possibilities of the GPS plugin.
I will hand over the server package if you want it, but here is the pastebin link for the script:
http://pastebin.com/cUmtDb5H
I suspect something is wrong here:
or somewhere here:
But I can't say exactly where.. if you compare autoPilot to AutoPilotStep you will see it should work so it's probably the pullvehicle function...
If you want the server pack:
http://solidfiles.com/d/3269a542c5/get
So I hope you can help me AND the community itself.
edit:
please change the AutoPilotStep callback to this, for better debug and understanding, also looks alot better:
A video of the problem:
If you're a bit confused let me explain what this script exactly does:
-- The route I chose: The car will drive from LV ammu parking to SF
-- The debug mode (cmd: /debug) just teleports you to each node on the path, in correct order from start to end
-- The autopilot mode (cmd: /ap) does start, it uses my custom function that can 'push' a vehicle towards a given XY position.
-- You have to be always in a car, if you exit the timer is destroyed, and also the route etc... the script will 'pause', you can re-use /ap or /debug
-- the autopilot should drive your car on the path, without that you need to do anything.
so now you know the concept of the script, again I need help, If this script will die no problem for me, I was making this for the sa-mp community to show off even more possibilities of the GPS plugin.
I will hand over the server package if you want it, but here is the pastebin link for the script:
http://pastebin.com/cUmtDb5H
I suspect something is wrong here:
pawn Code:
stock PullVehicleIntoDirection(VehicleID,Float:X,Float:Y,Float:Z,Float:Speed)//Or DriveVehicleToDirection.. ShootVehicletodirection.. whatever
{
#pragma unused Z
new Float:StartPos[3];
new Float:u[2];
GetVehiclePos(VehicleID, StartPos[0],StartPos[1],StartPos[2]);
SetVehicleZAngle(VehicleID,atan2VehicleZ(StartPos[0],StartPos[1],X,Y));
u[0] = X-StartPos[0];//deltaX
u[1] = Y-StartPos[1];//deltaY
//if(u[0] < 0.01)u[0] = 0.1;//does not fix the problem...
u[1] = u[1]/u[0];//RC = dY/dX
GetVehicleVelocity(VehicleID,StartPos[0],StartPos[1],StartPos[2]);//fix for 'flying car'
if(u[0] < 0)
SetVehicleVelocity(VehicleID,(Speed*-1.0),((Speed*u[1])*-1.0),StartPos[2]);
else
SetVehicleVelocity(VehicleID,Speed,Speed*u[1],StartPos[2]);
return 1;
}
pawn Code:
forward AutoPilot(playerid);
public AutoPilot(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid,1000.0);
if(CurrTarget[playerid] == 0)
{
CurrTarget[playerid]++;
GetNodePos(GetRouteAtPos(id[playerid],CurrTarget[playerid]),pos[0][0],pos[0][1],pos[0][2]);
SetVehiclePos(vehicleid,pos[0][0],pos[0][1],pos[0][2]+2.0);
format(string,128,"NodeID: %d\tX: %.2f Y: %.2f Z: %.2f T: %d",GetRouteAtPos(id[playerid],CurrTarget[playerid]),pos[0][0],pos[0][1],pos[0][2],CurrTarget[playerid]);
SendClientMessage(playerid,-1,string);
return 1;
}
new amount;
new nodeid = GetRouteAtPos(id[playerid],CurrTarget[playerid],amount);
if((CurrTarget[playerid]+1) >= amount)
{
KillTimer(Timer[playerid]);
Timer[playerid] = -1;
DeleteArray(id[playerid]);
id[playerid] = -1;
CurrTarget[playerid] = 0;
return 1;
}
//GetVehiclePos(vehicleid,pos[0][0],pos[0][1],pos[0][2]);
GetNodePos(nodeid,pos[1][0],pos[1][1],pos[1][2]);
format(string,128,"NodeID: %d\tX: %.2f Y: %.2f Z: %.2f T: %d",nodeid,pos[1][0],pos[1][1],pos[1][2],CurrTarget[playerid]);
if(IsPlayerInRangeOfPoint(playerid,3.0,pos[1][0],pos[1][1],pos[1][2]))
{
CurrTarget[playerid]++;
return 1;
//format(string,128,"%s IR",string);
//GetNodePos(nodeid,pos[1][0],pos[1][1],pos[1][2]);
}
SendClientMessage(playerid,-1,string);
//Now lets engage the auto pilot!
PullVehicleIntoDirection(vehicleid,pos[1][0],pos[1][1],pos[1][2],0.1);
}
else
{
KillTimer(Timer[playerid]);
Timer[playerid] = -1;
DeleteArray(id[playerid]);
id[playerid] = -1;
CurrTarget[playerid] = 0;
}
return 1;
}
If you want the server pack:
http://solidfiles.com/d/3269a542c5/get
So I hope you can help me AND the community itself.
edit:
please change the AutoPilotStep callback to this, for better debug and understanding, also looks alot better:
pawn Code:
forward AutoPilotStep(playerid);
public AutoPilotStep(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid,1000.0);
new amount;
GetNodePos(GetRouteAtPos(id[playerid],CurrTarget[playerid]++,amount),pos[0][0],pos[0][1],pos[0][2]);
GetNodePos(GetRouteAtPos(id[playerid],(CurrTarget[playerid]+1),amount),pos[1][0],pos[1][1],pos[1][2]);
SetVehiclePos(vehicleid,pos[0][0],pos[0][1],pos[0][2]+2.0);
SetVehicleZAngle(vehicleid,atan2VehicleZ(pos[0][0],pos[0][1],pos[1][0],pos[1][1]));
if(amount <= (CurrTarget[playerid]+1))
{
KillTimer(Timer[playerid]);
Timer[playerid] = -1;
DeleteArray(id[playerid]);
id[playerid] = -1;
CurrTarget[playerid] = 0;
}
}
else
{
KillTimer(Timer[playerid]);
Timer[playerid] = -1;
DeleteArray(id[playerid]);
id[playerid] = -1;
CurrTarget[playerid] = 0;
}
}
A video of the problem: