SA-MP Forums Archive
[HELP]Countdown - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP]Countdown (/showthread.php?tid=353662)



[HELP]Countdown - Devilxz97 - 24.06.2012

hey guys im making an Countdown system ,
its all like this

GameTextForAll("1",2000,3);

but it show to all player who are play on my server , ,

i want it to show only around 20meter . . how can i do like that ?

Help Rep+!


Re: [HELP]Countdown - [KHK]Khalid - 24.06.2012

Get your position (If you don't have a certain position for the cd) (GetPlayerPos), loop through all the connected players (Read about Loops), use IsPlayerInRangeOfPoint to detect if a player is in the range of the point you want (You might use the one we got by GetPlayerPos) then show the game text for that player (GameTextForPlayer). I'm here if ya get stuck, just ask.


Re: [HELP]Countdown - Devilxz97 - 24.06.2012

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
Get your position (If you don't have a certain position for the cd) (GetPlayerPos), loop through all the connected players (Read about Loops), use IsPlayerInRangeOfPoint to detect if a player is in the range of the point you want (You might use the one we got by GetPlayerPos) then show the game text for that player (GameTextForPlayer). I'm here if ya get stuck, just ask.
can ya show me how to do that ?
im still learning and idk more bout scripting , :\


Re: [HELP]Countdown - [KHK]Khalid - 24.06.2012

Kinda like this

pawn Код:
// top
new Count, Timer[MAX_PLAYERS];

// goes under OnPlayerCommandText. It's a command for the count down
if (strcmp("/countdown", cmdtext, true) == 0)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Timer[playerid] = SetTimerEx("CountDown", 1000, true, "d", playerid); // Declaring a timer to call the public CountDown every 1 second
    for(new i; i < MAX_PLAYERS; i ++) // looping through all players
    {
        if(IsPlayerConnected(i)) // if connected
        {
            if(IsPlayerInRangeOfPoint(i, 20, X, Y, Z)) // if they are in your range
            {
                new str[4];
                Count = 5; // setting the countdown to 5 .. you can change that
                format(str, sizeof(str), "%d", Count); // formatting a string to use it in GameTextForPlayer
                GameTextForPlayer(i, str, 3000, 3); // showing the gametext for that player in your range
            }
        }
    }
    return 1;
}

forward CountDown(playerid);

public CountDown(playerid)
{
    Count --; // decreasing Count by one
    if(Count == 0) // if Count reaches 0
    {
        KillTimer(Timer[playerid]); // kill the cd timer
        // your codes when the cd ends go here
        return 1; // to stop it
    }
    // so it's not = 0
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z); // getting the player position again (he probably has moved!)
    new str[4];
    format(str, sizeof(str), "%d", Count); // formatting a string with the new decreased Count
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 20, X, Y, Z)) // if he is in your range
            {
                GameTextForPlayer(i, str, 3000, 3); // showing the gametext for that player in your range
            }
        }
    }
    return 1;
}



Re: [HELP]Countdown - Devilxz97 - 24.06.2012

let me try this first


Re: [HELP]Countdown - Devilxz97 - 24.06.2012

i just need this to start the cd or not ?


Re: [HELP]Countdown - [KHK]Khalid - 24.06.2012

I think everything is explained enough. Well follow my comments until you get it to compile fine then go in-game and type /countdown.


Re: [HELP]Countdown - Devilxz97 - 24.06.2012

okay . .
i need help with this simple question

this is the Text

5
4
3
2
1

right , but how can i add after 1 GO GO GO!!


Re: [HELP]Countdown - Kindred - 24.06.2012

Very simple

pawn Код:
// top
new Count, Timer[MAX_PLAYERS];

// goes under OnPlayerCommandText. It's a command for the count down
if (strcmp("/countdown", cmdtext, true) == 0)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    Timer[playerid] = SetTimerEx("CountDown", 1000, true, "d", playerid); // Declaring a timer to call the public CountDown every 1 second
    for(new i; i < MAX_PLAYERS; i ++) // looping through all players
    {
        if(IsPlayerConnected(i)) // if connected
        {
            if(IsPlayerInRangeOfPoint(i, 20, X, Y, Z)) // if they are in your range
            {
                new str[4];
                Count = 5; // setting the countdown to 5 .. you can change that
                format(str, sizeof(str), "%d", Count); // formatting a string to use it in GameTextForPlayer
                GameTextForPlayer(i, str, 3000, 3); // showing the gametext for that player in your range
            }
        }
    }
    return 1;
}

forward CountDown(playerid);

public CountDown(playerid)
{
    Count --; // decreasing Count by one
    if(Count == 0) // if Count reaches 0
    {
        KillTimer(Timer[playerid]); // kill the cd timer
        // your codes when the cd ends go here
        GameTextForPlayer(i, "GO GO GO!!, 3000, 3);
        return 1; // to stop it
    }
    // so it's not = 0
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z); // getting the player position again (he probably has moved!)
    new str[4];
    format(str, sizeof(str), "
%d", Count); // formatting a string with the new decreased Count
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 20, X, Y, Z)) // if he is in your range
            {
                GameTextForPlayer(i, str, 3000, 3); // showing the gametext for that player in your range
            }
        }
    }
    return 1;
}
I simply copied his code and added it in as another GameText.


Re: [HELP]Countdown - [KHK]Khalid - 24.06.2012

I typed this comment there for a reason!
pawn Код:
// your codes when the cd ends go here



Re: [HELP]Countdown - Devilxz97 - 24.06.2012

when i add that
pawn Код:
GameTextForPlayer(i, "GO GO GO!!, 3000, 3);
pawn Код:
C:\Users\user\Desktop\SERVER\gamemodes\DriftZoneX.pwn(842) : error 017: undefined symbol "i"
C:\Users\user\Desktop\SERVER\gamemodes\DriftZoneX.pwn(842) : error 017: undefined symbol "GO"
C:\Users\user\Desktop\SERVER\gamemodes\DriftZoneX.pwn(842) : error 017: undefined symbol "GO"
C:\Users\user\Desktop\SERVER\gamemodes\DriftZoneX.pwn(842) : fatal error 107: too many error messages on one line



Re: [HELP]Countdown - Kindred - 24.06.2012

Sorry about that, wasn't paying attention

Change that to this:

pawn Код:
GameTextForPlayer(playerid, "GO GO GO!!", 3000, 3);



Re: [HELP]Countdown - Devilxz97 - 24.06.2012

Works and Perfect ! Rep+