#1

I found tutorial for counting, but i have errors

Quote:

public CountDown()
{
countvar--;
new str[128];
if(countvar == 0)
{
KillTimer(CountDownTimer);
countvar = 4;
}
else
{
format(str, sizeof(str), "%d", CountDownTimer);
GameTextForAll(str, 1000, 1);
}

}

ERRORS:
Quote:

C:\Users\Nerijus\Desktop\NevLocus\gamemodes\garza. pwn(2159) : error 022: must be lvalue (non-constant)
C:\Users\Nerijus\Desktop\NevLocus\gamemodes\garza. pwn(2159) : warning 215: expression has no effect
C:\Users\Nerijus\Desktop\NevLocus\gamemodes\garza. pwn(2161) : error 033: array must be indexed (variable "countvar")
C:\Users\Nerijus\Desktop\NevLocus\gamemodes\garza. pwn(2164) : error 033: array must be indexed (variable "countvar")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


3 Errors.

Reply
#2

You are not defining the variable 'countvar'.
Reply
#3

are you talking about this?

new countvar[4];
Reply
#4

pawn Code:
new countvar[4];
change it to this
pawn Code:
new countvar;
Reply
#5

Quote:
Originally Posted by ReD_HunTeR
View Post
pawn Code:
new countvar[4];
change it to this
pawn Code:
new countvar;
Thanks
Reply
#6

PHP Code:

new countvar=4;//Top on script
forward CountDOwn();
public 
CountDown()
{
       if(
countvar != 0)
       {
                
countvar--;
                new 
str[128];
                if(
countvar == 0)
                {
                        
KillTimer(CountDownTimer);
                        
countvar 4;
                }
                else
                {
                         
format(strsizeof(str), "%d"CountDownTimer);
                         
GameTextForAll(str10001);
                }
       }

Reply
#7

Like nobody noticed he's formatting the timer's variable? Come on.

pawn Code:
format(str, sizeof(str), "%d", CountDownTimer);
The tutorial you got this code from is wrong, you should format countvar.

And you don't need 128 cells for just a decimal number, I've changed it to 6, I don't expect from someone to call a countdown for an hour or more, but feel free to increase it if you want.

Final code:

pawn Code:
#include <a_samp>

new countvar = 10;
new CountDownTimer;

public OnFilterScriptInit()
{
    CountDownTimer = SetTimer("CountDown", 1000, true);
    return 1;
}

forward CountDown();
public CountDown()
{
    countvar--;
    new str[6];
    if(countvar == 0)
    {
        KillTimer(CountDownTimer);
        countvar = 4;
    }
    else
    {
        format(str, sizeof(str), "%d", countvar);
        GameTextForAll(str, 1000, 1);
        // uncoment this if you want to test it without getting in game -- printf("%d", countvar);
    }
}
Reply
#8

Quote:
Originally Posted by TheToretto
View Post
Like nobody noticed he's formatting the timer's variable? Come on.

pawn Code:
format(str, sizeof(str), "%d", CountDownTimer);
The tutorial you got this code from is wrong, you should format countvar.

And you don't need 128 cells for just a decimal number, I've changed it to 6, I don't expect from someone to call a countdown for an hour or more, but feel free to increase it if you want.

Final code:

pawn Code:
#include <a_samp>

new countvar = 10;
new CountDownTimer;

public OnFilterScriptInit()
{
    CountDownTimer = SetTimer("CountDown", 1000, true);
    return 1;
}

forward CountDown();
public CountDown()
{
    countvar--;
    new str[6];
    if(countvar == 0)
    {
        KillTimer(CountDownTimer);
        countvar = 4;
    }
    else
    {
        format(str, sizeof(str), "%d", countvar);
        GameTextForAll(str, 1000, 1);
        // uncoment this if you want to test it without getting in game -- printf("%d", countvar);
    }
}
When i use command to count on screen show number 2 but it disapear and dont count
Reply
#9

On the tutorial, he gave the third argument the value false, which means it won't repeat. That's not what you need, activate it:

pawn Code:
CountDownTimer = SetTimer("CountDown", 1000, true);
And if you wan't a 3 seconds countdown, countvar shouldn't be 3, but 4 because it's decrementing its value before formatting. You can fix that but it's not that urgent.
Reply
#10

now my code look:
Quote:

public CountDown()
{
if(countvar !=0)
{
countvar--;
new str[6];
if(countvar == 0)
{
KillTimer(CountDownTimer);
countvar = 4;
}
else
{
format(str, sizeof(str), "%d", countvar);
GameTextForAll(str, 1000, 1);
}
}

}

CMDkaiciuoti(playerid, params[])
{
if(sInfo[playerid][adminlevel] > 4)
{
CountDownTimer = SetTimer("CountDown", 1000, true);
SetPlayerRaceCheckpoint(playerid, 1, -77.6183, 2501.9719, 15.4608, 0.0, 0.0, 0.0, 50.0);
return 1;
}
else
{
SendClientMessage(playerid, RAUDONA, "Komanda neegzistuoja arba Jūs neturite privilegijų!");
}
return 1;
}

And when i used the cmd i have 9 number on screen then it change to 2 and dissapear
Reply
#11

Check this: GameText Styles

Style 1: Fades out after 8 seconds, regardless of time set. If you have a time setting longer than that, it will re-appear after fading out and repeat until the time ends.

So use another one, for example 5.

pawn Code:
#include <a_samp>
#include <zcmd>

new countvar = 10;
new CountDownTimer;

CMD:countdown(playerid, params[])
{
    CountDownTimer = SetTimer("CountDown", 1000, true);
    SetPlayerRaceCheckpoint(playerid, 1, -77.6183, 2501.9719, 15.4608, 0.0, 0.0, 0.0, 50.0);
    return 1;
}

forward CountDown();
public CountDown()
{
    countvar--;
    new str[6];
    if(countvar == 0)
    {
        GameTextForAll("~g~G~r~O~b~!", 3000, 5);
        KillTimer(CountDownTimer);
        countvar = 4;
    }
    else
    {
        format(str, sizeof(str), "%d", countvar);
        GameTextForAll(str, 1000, 5);
    }
}
I added a little cool feature, which displays "GO!" in multi-color for 3 seconds after the countdown ends.
pawn Code:
GameTextForAll("~g~G~r~O~b~!", 3000, 5);
Reply
#12

Thanks!
Reply
#13

And do you know how to create race checkpoint to all players?
Reply
#14

Yes, use SetPlayerRaceCheckpoint with a for loop, example:

pawn Code:
for(new i; i < MAX_PLAYERS; i++)
{
    SetPlayerRaceCheckpoint(i, 0, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size);
}
0 in the type for ground normal race checkpoints, check the documentation I mentioned earlier
Reply
#15

Thanks, i had it but i did mistake so thanks you very much, you are the best
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)