05.04.2015, 05:50
I want to make a nitrous indicator, and for that I created a variable with the duration.
I wanted to substract every second the nitrous button is pressed so I made a timer with a function.
It wasn't working well, so I included client messages to see the values changing while I keep the button pressed.
The code is below:
Basically when I enter a car I should get the value 10, I start holding the NOS button, the value should drop to 1 every second.
Clearly something is terribly wrong here, because Instead of 9, 8, 7, etc, I got the following:
BTW I also got a tag mismatch warning on the line marked with ///////////////////
Can someone point me in the right direction here?
I wanted to substract every second the nitrous button is pressed so I made a timer with a function.
It wasn't working well, so I included client messages to see the values changing while I keep the button pressed.
The code is below:
PHP код:
new string[64];
new amount = 0;
new one = 1;
forward amountfeed(playerid);
public amountfeed(playerid)
{
format(string,sizeof(string),"%d", amount);
SendClientMessage(playerid,0xFFFFFFAA,string);
amount = floatsub(amount, one); ///////////////////
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
amount = 10;
format(string,sizeof(string),"%d", amount);
SendClientMessage(playerid,0xFFFFFFAA,string);
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
amount = 0;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(IsPlayerInAnyVehicle(playerid))
{
new timer;
new veh = GetPlayerVehicleID(playerid);
if((newkeys & 1 || newkeys & 4))
{
timer = SetTimer("amountfeed", 1000, true);
if (amount == 0)
{
KillTimer(timer);
}
}
if((oldkeys & 1 || oldkeys & 4))
{
KillTimer(timer);
}
}
return 1;
}
Clearly something is terribly wrong here, because Instead of 9, 8, 7, etc, I got the following:
BTW I also got a tag mismatch warning on the line marked with ///////////////////
PHP код:
//I entered the vehicle
[08:36:34] 10
//I started holding click (Nos button of course)
[08:36:44] 10
[08:36:45] 1091567616
[08:36:46] 1317150720
[08:36:47] 1318913088
[08:36:48] 1318926856
[08:36:50] 1318926964
[08:36:51] 1318926965
[08:36:52] 1318926965
[08:36:53] 1318926965
[08:36:54] 1318926965
[08:36:55] 1318926965
[08:36:56] 1318926965
[08:36:57] 1318926965
[08:36:58] 1318926965
[08:37:00] 1318926965
[08:37:01] 1318926965
[08:37:02] 1318926965
[08:37:03] 1318926965
[08:37:04] 1318926965
[08:37:05] 1318926965
[08:37:06] 1318926965
[08:37:07] 1318926965
[08:37:08] 1318926965
[08:37:09] 1318926965