SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/06/2019, 07:54 PM   #1
nbx2000
Big Clucker
 
Join Date: Dec 2016
Posts: 150
Reputation: 5
Default countdown bug count negative -1

I have a problem in countdown sometimes that bug and starts a negative account example -3 -2 -1 why?
Code:
new CountDown = -1;
CMD:countdown(playerid,params[]) {
    if(PlayerInfo[playerid][Level] >= 5) {
        if(CountDown == -1) {
			CountDown = 6;
			SetTimer("countdown",1000,0);
			return CMDMessageToAdmins(playerid,"COUNTDOWN");
		} else return SendClientMessage(playerid,red,"ERROR: Countdown in progress");
	} else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
}
forward countdown();
public countdown(){
	if(CountDown==6) GameTextForAll("~p~Starting...",1000,3);
	CountDown--;
	if(CountDown==0){
		GameTextForAll("~g~GO~ r~!",1000,3);
		CountDown = -1;
		for(new i = 0; i < MAX_PLAYERS; i++) {
			PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);}
		return 0;}
	else{
		new text[7]; format(text,sizeof(text),"~w~%d",CountDown);
		for(new i = 0; i < MAX_PLAYERS; i++) {
			PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);}
	 	GameTextForAll(text,1000,3);}
	SetTimer("countdown",1000,0);
	return 0;}

Last edited by nbx2000; 15/06/2019 at 10:47 PM.
nbx2000 is offline   Reply With Quote
Old 15/06/2019, 07:59 PM   #2
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 428
Reputation: 16
Default Re: countdown bug count negative -1

Worst countdown code i ever seen in my life, no offence.

And you must set CountDown to 0, not -1 when it ends. Also maybe kill the timer?
__________________
Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.

Global launch is on October 1st.
KeyOfKey is offline   Reply With Quote
Old 15/06/2019, 10:42 PM   #3
nbx2000
Big Clucker
 
Join Date: Dec 2016
Posts: 150
Reputation: 5
Default Re: countdown bug count negative -1

so bad is it? How can it be fixed?
nbx2000 is offline   Reply With Quote
Old 16/06/2019, 12:59 AM   #4
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 270
Reputation: 22
Default Re: countdown bug count negative -1

Quote:
Originally Posted by KeyOfKey View Post
Worst countdown code i ever seen in my life, no offence.

And you must set CountDown to 0, not -1 when it ends. Also maybe kill the timer?
Please stop shitting on other peoples code. You can't even differentiate vehicleid from modelid.
And provide useful help. Setting CountDown to 0 at the end breaks the code (You can't use the command anymore) and you can't kill timers without a timer id.
If you want to give optimization tips, you could say to use a repeating timer, save the timer id and kill it when CountDown reaches 0.

To the issue: Please print CountDown at countdown function and the command to see when it happens. I don't see anything in the code that would result in a negative countdown.
Plastikmensch is offline   Reply With Quote
Old 16/06/2019, 01:06 AM   #5
1sbedx
Huge Clucker
 
Join Date: Dec 2015
Posts: 282
Reputation: 39
Default Re: countdown bug count negative -1

Quote:
Originally Posted by nbx2000 View Post
so bad is it? How can it be fixed?
PHP Code:
new g_Countdown[2];

forward Countdown();

CMD:countdown(playeridparams[]) {
  if (
g_Countdown[0])
    return 
1;

  
g_Countdown[0] = strval(params);
  
g_Countdown[1] = SetTimer("Countdown"1000true);
  return 
1;
}

public 
Countdown() {
  new 
str[3];

  if (!--
g_Countdown[0]) {
    
KillTimer(g_Countdown[1]);
    
GameTextForAll("~g~Go!"10003);
    return;
  }

  
format(strsizeof(str), "%i"g_Countdown[0]);
  
GameTextForAll(str10003);

__________________
Estou desenvolvendo por dinheiro, qualquer dúvida entre em contato para negociação.
1sbedx is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[mysql] Column count doesn't match value count Lirbo Scripting Help 4 30/05/2017 04:40 PM
Player Count-Pos for each player-countdown in textdraw-last man standing.. :p Roberto80 Scripting Help 8 27/07/2015 05:13 PM
[MySQL] Error (0): Failed to exeute query. Column count doesn't match value count at row 1. lulo356 Scripting Help 0 18/07/2015 09:23 AM
[HELPls] I need good /countdown or /count ProdrifterX Scripting Help 5 29/01/2012 07:10 PM


All times are GMT. The time now is 04:59 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.