clock weird problem -
AnonScripter - 17.01.2014
hey guys maybe i have math problem in this script, somebody tell me what is it please.
i got an /arrest command with some functions...
- i have a textdraw to show how many time remaining till the player release from jail.
- Jail Time for the player is based on how many wanted level he had:
pawn Код:
PlayerInfo[targetid][pJailTime] = (GetPlayerWantedLevel(targetid)/4)*60;
So let's say he had 6 wanted levels, 6/4 = 1.5 ,,,so 1.5 * 60 = 90 so he will stay in jail 1:30 minutes
but this is not working, it always shows "1:00" even his jail time is 90 seconds
maybe the wrong on the clock scipt update, here is it:
pawn Код:
if(PlayerInfo[playerid][pJailTime] > 0)
{
new string[128];
new gseconds;
new gminutes;
gseconds = PlayerInfo[playerid][pJailTime] % 60;
gminutes = (PlayerInfo[playerid][pJailTime] - gseconds) / 60;
PlayerInfo[playerid][pJailTime] --;
format(string, sizeof string, "%d:%02d", gminutes, gseconds);
TextDrawSetString(JailList[playerid], string);
Edit: here is the /arrest command script, because maybe the wrong is here
pawn Код:
CMD:arrest(playerid, params[])
{
PlayerInfo[targetid][pJailTime] = (GetPlayerWantedLevel(targetid)/4)*60;
PutPlayerInJail(targetid);
IncreaseScore(playerid,1);
return 1;
}
public PutPlayerInJail(playerid)
{
new Random = random(sizeof(RandomJail));
SetPlayerInterior(playerid,3);
SetPlayerPos(playerid, RandomJail[Random][0], RandomJail[Random][1], RandomJail[Random][2]);
SetPlayerFacingAngle(playerid, RandomJail[Random][3]);
SetCameraBehindPlayer(playerid);
SetPlayerVirtualWorld(playerid,1);
return 1;
}
Re: clock weird problem -
Pottus - 17.01.2014
I tested your code here and it seem to give the correct output try it yourself.
http://slice-vps.nl:7070/
pawn Код:
#include <a_samp>
main() {
new gseconds;
new gminutes;
new time = 90;
while(time)
{
gseconds = time % 60;
gminutes = (time - gseconds) / 60;
new string[128];
format(string, sizeof string, "%d:%02d", gminutes, gseconds);
printf(string);
time--;
}
return 1;
}
Re: clock weird problem -
AnonScripter - 17.01.2014
i don't knw why you used "while" and you specific the time to 90, it not always would be 90
btw i found the problem, the problem is in arrest command, it always formating the jail time to 60 seconds and that's why it shows "1:00"
and i really don't know why it's not working with the wanted levels
Re: clock weird problem -
Vince - 17.01.2014
Integer divided by integer will give integer. It won't implicitly convert to a float.
Re: clock weird problem -
Pottus - 17.01.2014
Quote:
Originally Posted by AnonScripter
i don't knw why you used "while" and you specific the time to 90, it not always would be 90
btw i found the problem, the problem is in arrest command, it always formating the jail time to 60 seconds and that's why it shows "1:00"
and i really don't know why it's not working with the wanted levels
|
You asked why your code wasn't working so I created a test and provided you the test code and a link so you could fiddle fuck with it of course.
Re: clock weird problem -
AnonScripter - 18.01.2014
Quote:
Originally Posted by [uL]Pottus
You asked why your code wasn't working so I created a test and provided you the test code and a link so you could fiddle fuck with it of course.
|
sorry man, i wasn't mean that, the question is.. why this code:
pawn Код:
PlayerInfo[targetid][pJailTime] = (GetPlayerWantedLevel(targetid)/4)*60;
always make the jail time to 1:00 ?? that what i want to knw :))
Re: clock weird problem -
Pottus - 18.01.2014
Ahhh that is because your dividing an integer wanted level goes up to 6 so it will always return 1; you can do this instead.
(GetPlayerWantedLevel(targetid)*60) / 4;
Wanted level 1 = 15 seconds
Wanted level 2 = 30
Wanted level 3 = 45
Wanted level 4 = 60
Wanted level 5 = 75
Wanted level 6 = 90
Re: clock weird problem -
AnonScripter - 18.01.2014
thank you it worked