PDA

View Full Version : Wrong Angle


TwinkiDaBoss
09/12/2015, 12:22 AM
Alright so the problem is simple, if you /park a vehicle, it will respawn at wrong Angle angle for some reason

CMD:park(playerid,params[]) {
#pragma unused params
new vid = GetPlayerVehicleID(playerid), Float:tmpPos[4], vw, Int;
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not inside any vehicle");
if(VehInfo[vid][VehMasterID] == AccInfo[playerid][ID] || VehInfo[vid][VehFaction] == AccInfo[playerid][PlayerFaction] && AccInfo[playerid][PlayerLeader]) {
GetVehiclePos(vid,tmpPos[0],tmpPos[1],tmpPos[2]);
GetVehicleZAngle(vid,tmpPos[3]);
vw = GetVehicleVirtualWorld(vid);
Int = GetPlayerInterior(playerid);
SendClientMessage(playerid,COLOR_GREEN,"You have parked your vehicle");
VehInfo[vid][VehPosX] = tmpPos[0];
VehInfo[vid][VehPosY] = tmpPos[1];
VehInfo[vid][VehPosZ] = tmpPos[2];
VehInfo[vid][VehPosA] = tmpPos[3];
VehInfo[vid][VehInterior] = Int;
VehInfo[vid][VehWorld] = vw;
new query[128];
mysql_format(mysql, query, sizeof(query), "UPDATE `vehicles` SET `PosX`=%f,`PosY`=%f,`PosZ`=%f,`PosA`=%f WHERE ID=%d",tmpPos[0],tmpPos[1],tmpPos[2],tmpPos[3],VehInfo[vid][VID]);
mysql_tquery(mysql, query);
}
return true;
}

public OnVehicleSpawn(vehicleid)
{
SetVehiclePos(vehicleid,VehInfo[vehicleid][VehPosX],VehInfo[vehicleid][VehPosY],VehInfo[vehicleid][VehPosZ]);
SetVehicleZAngle(vehicleid,VehInfo[vehicleid][VehPosA]);
SetVehicleVirtualWorld(vehicleid,VehInfo[vehicleid][VehWorld]);
LinkVehicleToInterior(vehicleid,VehInfo[vehicleid][VehInterior]);
return 1;
}


And yes the angle is a float
Float:VehPosA,


print

printf("Server ID: %i || SQL ID: %i",vid,VehInfo[vid][VID]);
printf("%.2f",tmpPos[3]);
printf("%.2f",VehInfo[vid][VehPosA]);

[02:27:52] Server ID: 40 || SQL ID: 65
[02:27:52] 326.46
[02:27:52] 326.46



The problem happens after I use SetVehicleToRespawn on it

Kevln
09/12/2015, 12:34 AM
https://wiki.sa-mp.com/wiki/GetVehicleZAngle

TwinkiDaBoss
09/12/2015, 12:39 AM
https://wiki.sa-mp.com/wiki/GetVehicleZAngle
Thank you for linking me to something I have.
GetVehicleZAngle(vid,tmpPos[3]);

Please read the topic before you post.

jamesbond007
09/12/2015, 01:19 AM
what angle does it set it at? random or 0 ?
does it happen to all vehicles ? idk.. maybe someone else will reply with solution

Threshold
09/12/2015, 01:20 AM
Where exactly are you respawning it?

Kevln
09/12/2015, 03:02 AM
// ** INCLUDES

#include <a_samp>
#include <zcmd>

// ** ARRAYS AND ENUMERATORS

enum eVehicleInfo
{
Float:vehicle_info_x,
Float:vehicle_info_y,
Float:vehicle_info_z,
Float:vehicle_info_angle
};

new aVehicleInfo[MAX_VEHICLES][eVehicleInfo];

// ** MAIN

main()
{
print("Loaded \"vehicle_angle.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
new vehicleid = AddStaticVehicle(400, 132.1159, -92.7907, 1.5220, 291.6237, 123, 1);

GetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);
GetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnVehicleSpawn(vehicleid)
{
SetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);

SetTimerEx("SetVehicleZAngleAfterSpawn", 1500, false, "i", vehicleid);
return 1;
}

// ** COMMANDS

CMD:respawnvehicles(playerid, params[])
{
for(new i = 1, j = GetVehiclePoolSize(); i <= j; i ++)
{
SetVehicleToRespawn(i);
}
return 1;
}

CMD:park(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
GetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);
GetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

// ** FUNCTIONS

forward SetVehicleZAngleAfterSpawn(vehicleid);
public SetVehicleZAngleAfterSpawn(vehicleid)
{
SetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

TwinkiDaBoss
09/12/2015, 07:41 PM
what angle does it set it at? random or 0 ?
does it happen to all vehicles ? idk.. maybe someone else will reply with solution
Well yeah with all vehicles but only if I use SetVehicleToRespawn

Where exactly are you respawning it?
I got a command which is basically SetVehicleToRespawn(playerid,GetPlayerVehicleID(pl ayerid))

// ** INCLUDES

#include <a_samp>
#include <zcmd>

// ** ARRAYS AND ENUMERATORS

enum eVehicleInfo
{
Float:vehicle_info_x,
Float:vehicle_info_y,
Float:vehicle_info_z,
Float:vehicle_info_angle
};

new aVehicleInfo[MAX_VEHICLES][eVehicleInfo];

// ** MAIN

main()
{
print("Loaded \"vehicle_angle.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
new vehicleid = AddStaticVehicle(400, 132.1159, -92.7907, 1.5220, 291.6237, 123, 1);

GetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);
GetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

public OnGameModeExit()
{
return 1;
}

public OnVehicleSpawn(vehicleid)
{
SetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);

SetTimerEx("SetVehicleZAngleAfterSpawn", 1500, false, "i", vehicleid);
return 1;
}

// ** COMMANDS

CMD:respawnvehicles(playerid, params[])
{
for(new i = 1, j = GetVehiclePoolSize(); i <= j; i ++)
{
SetVehicleToRespawn(i);
}
return 1;
}

CMD:park(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
GetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);
GetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

// ** FUNCTIONS

forward SetVehicleZAngleAfterSpawn(vehicleid);
public SetVehicleZAngleAfterSpawn(vehicleid)
{
SetVehicleZAngle(vehicleid, aVehicleInfo[vehicleid][vehicle_info_angle]);
return 1;
}

Ill try it out


EDIT: Yeah that works just fine, probably Ill have to do it like this sometimes. Thanks for the help. +rep