13.08.2014, 14:00
I've created a submarine script, and I'm trying to add a torpedo thing to it.
But, the problem is, that the torpedo object(etc.) is only being created(and stuff done), if the submarine is driving(forwards/backwards).
If I stand still/turn it left/right, I will receive the message, but nothing else will happen!
Here's the code;
But, the problem is, that the torpedo object(etc.) is only being created(and stuff done), if the submarine is driving(forwards/backwards).
If I stand still/turn it left/right, I will receive the message, but nothing else will happen!
Here's the code;
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(inSub{ playerid })
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
new Float:X2, Float:Y2, Float:Z2;
new string[92];
if(newkeys & KEY_YES)
{
if(Submarine[SubID[playerid]][TorpedoLoaded] && CanShoot[playerid])
{
if(Submarine[SubID[playerid]][Torpedos])
{
Submarine[SubID[playerid]][Torpedos]--;
format(string, sizeof(string), "SUBMARINE: Torpedo away! Remaining torpedos: %d/4", Submarine[SubID[playerid]][Torpedos]);
CanShoot[playerid] = 0;
foreach(Player, i)
{
if(IsPlayerInRangeOfPoint(i, 20, X, Y, Z))
{
SendClientMessage(i, -1, string), string = "\0";
}
}
Submarine[SubID[playerid]][TorpedoObject] = CreateObject(1636, Submarine[SubID[playerid]][sX], Submarine[SubID[playerid]][sY]-2, Submarine[SubID[playerid]][sZ], 0, 0, 0);
GetXYInFrontOfObject(Submarine[SubID[playerid]][TorpedoObject], playerid, Submarine[SubID[playerid]][sX], Submarine[SubID[playerid]][sY], 150.0);
new time = MoveObject(Submarine[SubID[playerid]][TorpedoObject], Submarine[SubID[playerid]][sX], Submarine[SubID[playerid]][sY], Submarine[SubID[playerid]][sZ], 65.0);
SetTimerEx("DetonateTorpedo", time, false, "ii", playerid, Submarine[SubID[playerid]][TorpedoObject]);
format(string, sizeof(string), "SUBMARINE: The torpedo will explode in approx. %d seconds!", time/1000);
SendClientMessage(playerid, -1, string), string = "\0";
}
else SendClientMessage(playerid, -1, "SUBMARINE: You've ran out of torpedos!");
}
else
{
SendClientMessage(playerid, -1, "SUBMARINE: Loading torpedo..");
SetTimerEx("TorpedoLoadedT", 2500+random(3000), false, "ii", playerid, SubID[playerid]);
}
}