21.10.2018, 18:12
Thats because you are doing almost everything wrong, lets start from the beginning
what actually is this? are you trying to get players vehicle model? if yes thats not how you do it...
this is the correct way
ok so we are done above lets get to the next mistake of yours
what you did here, is that you created arrays but didnt store anything inside so for getting Vehicle Rotation here its how you do it:-
moving towards third mistake
you should consider using
moving toward the last part:
ok what you did here is pretty much everything is wrong
By your code i figured that you are creating missile system, so here is how you do it
and this is how your code should look like
didnt test but it should work
pawn Код:
switch(Vehicle[vehicleid])
{
case 1: 460;
}
this is the correct way
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid); //Storing Vehicle ID of Player in "vehicleid"
new model = GetVehicleModel(vehicleid); //Storing Vehicle Model of Player in "vehicleid"
if(modelid == 460) //if vehicle model is skimmer plane continue your code here
{
}
pawn Код:
new Float:VehicleRotX, Float:VehicleRotY, Float:VehicleRotZ;
pawn Код:
stock GetVehicleRotation(vehicleid,&Float:x,&Float:y,&Float:z) //Credits: Stepashka
{
new Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z;
GetVehicleRotationQuat(vehicleid,quat_w,quat_x,quat_y,quat_z);
x = atan2(2*((quat_x*quat_y)+(quat_w+quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
y = atan2(2*((quat_y*quat_z)+(quat_w*quat_x)),(quat_w*quat_w)-(quat_x*quat_x)-(quat_y*quat_y)+(quat_z*quat_z));
z = asin(-2*((quat_x*quat_z)+(quat_w*quat_y)));
return 1;
}
new Float:VehicleRotX, Float:VehicleRotY, Float:VehicleRotZ;
GetVehicleRotation(vehicleid, VehicleRotX, VehicleRotY, VehicleRotZ);
pawn Код:
GetPlayerPos(playerid, x, y, z);
pawn Код:
new Float:VehX, Float:VehY, Float:VehZ;
GetVehiclePos(vehicleid, VehX, VehY, VehZ); //Storing vehicle position inside Vehx, vehy and vehz
pawn Код:
if(VehicleRotX == VehicleRotY)
new torpedo = CreateObject(3790, x, y, z, rX, rY, rZ, DrawDistance)
{
MoveObject(torpedo, x + 15, y + 15, z, 250.0, RotX, RotY, RotZ);
DestroyObject(torpedo);
}
else
if(VehicleRotX = 5.0 && VehicleRotY = 0.0)
{
MoveObject(torpedo, x + 15, y, z, 250.0, RotX, RotY, RotZ);
DestroyObject(torpedo);
}
else
if(VehicleRotX = 0.0 && VehicleRotY = 5.0)
{
MoveObject(torpedo, x + 15, y, z, 250.0, RotX, RotY, RotZ);
DestroyObject(torpedo);
}
if(DestroyObject(torpedo))
{
CreateExplosion(x, y, z, 7, 15);
}
return 1;
}
By your code i figured that you are creating missile system, so here is how you do it
pawn Код:
if(VehicleRotX == VehicleRotY) //when x and y rotation are same
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15.0,, VehY + 15.0, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
else if(VehicleRotX = 5.0 && VehicleRotY = 0.0) //when rotation x is 5.0 and y rotation is 0.0
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15, VehY, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
else if(VehicleRotX = 0.0 && VehicleRotY = 5.0) //when rotation x is 0.0 and y rotation is 5.0
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15, VehY, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
forward Missile(objectid);
public Missile(objectid) //ok this is where we put what happens after 5 seconds
{
new Float:x, Float:y, Float:z; //creating float array
GetObjectPos(objectid, x, y, z); //getting objects position
CreateExplosion(x, y, z, 7, 10.0); //creating explosion on oject
DestroyObject(objectid); //destroying the object
}
and this is how your code should look like
pawn Код:
#include <a_samp>
#include <a_players>
#include <a_objects>
#if defined filterscripts
public OnFilterScriptInit()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("bombaci\n");
}
#endif
stock GetVehicleRotation(vehicleid,&Float:x,&Float:y,&Float:z) //Credits: Stepashka
{
new Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z;
GetVehicleRotationQuat(vehicleid,quat_w,quat_x,quat_y,quat_z);
x = atan2(2*((quat_x*quat_y)+(quat_w+quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
y = atan2(2*((quat_y*quat_z)+(quat_w*quat_x)),(quat_w*quat_w)-(quat_x*quat_x)-(quat_y*quat_y)+(quat_z*quat_z));
z = asin(-2*((quat_x*quat_z)+(quat_w*quat_y)));
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_NO) //when you press key n
{
new vehicleid = GetPlayerVehicleID(playerid); //Storing Vehicle ID of Player in "vehicleid"
new model = GetVehicleModel(vehicleid); //Storing Vehicle Model of Player in "vehicleid"
if(model == 460) //if vehicle model is skimmer plane continue your code here
{
new Float:VehicleRotX, Float:VehicleRotY, Float:VehicleRotZ; //Creating variables
GetVehicleRotation(vehicleid, VehicleRotX, VehicleRotY, VehicleRotZ); //storing rotation in the variables we just created
new Float:VehX, Float:VehY, Float:VehZ; //Creating variables
GetVehiclePos(vehicleid, VehX, VehY, VehZ); //Storing vehicle position inside Vehx, vehy and vehz
if(VehicleRotX == VehicleRotY) //when x and y rotation are same
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15.0, VehY + 15.0, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
else if(VehicleRotX == 5.0 && VehicleRotY == 0.0) //when rotation x is 5.0 and y rotation is 0.0
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15.0, VehY, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
else if(VehicleRotX == 0.0 && VehicleRotY == 5.0) //when rotation x is 0.0 and y rotation is 5.0
{
new objectid = CreateObject(3790, VehX, VehY, VehZ, VehicleRotX, VehicleRotY, VehicleRotZ); //creating object and storing id in objectid so we can destroy it later
MoveObject(objectid, VehX + 15.0, VehY, VehZ, 250.0, VehicleRotX, VehicleRotY, VehicleRotZ); //moving object we just created
SetTimerEx("Missile", 5000, false, "i", objectid); //Starting a timer so we can delete the object and create after 5 seconds, keep in mind timer uses millisecond, so 5000 = 5 seconds
}
}
}
return 1;
}
forward Missile(objectid);
public Missile(objectid) //ok this is where we put what happens after 5 seconds
{
new Float:x, Float:y, Float:z; //creating float array
GetObjectPos(objectid, x, y, z); //getting objects position
CreateExplosion(x, y, z, 7, 10.0); //creating explosion on oject
DestroyObject(objectid); //destroying the object
}
didnt test but it should work