Local Countdown
#1

Hi,

I tried to make a countdown only visible for players near the admin who start the /countdown command.

I made this script:

Код:
forward countdown(playerid);
public countdown(playerid)
{
    new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid,x,y,z);
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerInRangeOfPoint(i,7.0,x,y,z))
		{
			if(CountDown==6) GameTextForPlayer(playerid,"~p~Starting...",1000,6);
			CountDown--;
			if(CountDown==0)
			{
				//GameTextForPlayer(i,"~g~GO~ r~!",1000,6);
				CountDown = -1;
				GameTextForPlayer(i,"~g~GO~ r~!",1000,6);
				TogglePlayerControllable(i,true);
				PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
				return 0;
			}
			else
			{
				new text[7]; format(text,sizeof(text),"~w~%d",CountDown);
				GameTextForPlayer(i,text,1000,6);
				PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
				TogglePlayerControllable(i,false);
			 	//GameTextForPlayer(i,text,1000,6);
			}

			SetTimer("countdown",1000,0);
		}
	}
	return 0;
}
But the countdown is really buggy and only works for the player with ID 0 and the timer get fucked up sometimes.

Can somebody tell me what I'm doing wrong?

Thanks!
Reply
#2

take the loop out
Reply
#3

Quote:
Originally Posted by Kar
Посмотреть сообщение
take the loop out
so how i know what players are near the admin if I take out the loop?
Reply
#4

u want it for all players?

pawn Код:
forward countdown(playerid);
public countdown(playerid)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid,x,y,z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i,7.0,x,y,z))
        {
            if(CountDown==6) GameTextForPlayer(i,"~p~Starting...",1000,6);
            CountDown--;
            if(CountDown==0)
            {
                //GameTextForPlayer(i,"~g~GO~ r~!",1000,6);
                CountDown = -1;
                GameTextForPlayer(i,"~g~GO~ r~!",1000,6);
                TogglePlayerControllable(i,true);
                PlayerPlaySound(i,1057, 0.0, 0.0, 0.0);
                return 0;
            }
            else
            {
                new text[7]; format(text,sizeof(text),"~w~%d",CountDown);
                GameTextForPlayer(i,text,1000,6);
                PlayerPlaySound(i,1056, 0.0, 0.0, 0.0);
                TogglePlayerControllable(i,false);
                //GameTextForPlayer(i,text,1000,6);
            }

            SetTimerEx("countdown",1000,0,"i",playerid);
        }
    }
    return 0;
}
Reply
#5

pawn Код:
SetTimer("countdown",1000,0);
Your countdown() function contains the required variable of "playerid", calling the function without that variable would most likely trigger it for 0. I've revised that line of code for you.

pawn Код:
SetTimerEx("countdown", 1000, 0, "d", playerid);
SetTimerEx allows you to parse multiple variables to the timed function.
Reply
#6

Thanks for your help, but I still keep having some problems, I tried to check the range of different ways like GetDistanceBetweenPlayers and IsPlayerInRangeOfPoint, but still the whole server sees the countdown.

This is my latest version, I'm sorry for the scripting mess.

Код:
forward countdown(playerid);
public countdown(playerid)
{
    new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid,x,y,z);
	
	if(CountDown==6) GameTextForPlayer(playerid,"~p~Starting...",1000,6);

	CountDown--;
	if(CountDown==0)
	{
	    for(new i = 0; i < MAX_PLAYERS; i++) {
	    if(GetDistanceBetweenPlayers(playerid,i) < 8)
    		{
			GameTextForPlayer(i,"~g~GO~ r~!",1000,6);
			CountDown = -1;
			for(new i2 = 0; i2 < MAX_PLAYERS; i2++) {
			    if(GetDistanceBetweenPlayers(playerid,i2) < 8)
	    		{
					TogglePlayerControllable(i2,true);
					PlayerPlaySound(i2, 1057, 0.0, 0.0, 0.0);
				}
			}
		}
		}
		return 0;
	}else{
		new text[7]; format(text,sizeof(text),"~w~%d",CountDown);
		for(new i2 = 0; i2 < MAX_PLAYERS; i2++) {
			if(GetDistanceBetweenPlayers(playerid,i2) < 8)
	    		{
				PlayerPlaySound(i2, 1056, 0.0, 0.0, 0.0);
				TogglePlayerControllable(i2,false);
			}
		}
		for(new i = 0; i < MAX_PLAYERS; i++) {
		    if(GetDistanceBetweenPlayers(playerid,i) < 8)
	    		{
	 			GameTextForPlayer(i,text,1000,6);
	 			}
		}
	}
	SetTimer("countdown",1000,0);
	return 0;
}
Reply
#7

omfg...

pawn Код:
SetTimerEx("countdown",1000,0,"i",playerid);
use that
Reply
#8

Quote:
Originally Posted by Kar
Посмотреть сообщение
omfg...

pawn Код:
SetTimerEx("countdown",1000,0,"i",playerid);
use that
Oops, I feel so stupid right now
Reply
#9

[KMA]DlennartD, you gived me a nice idea
Reply
#10

Why so fkin' many loops?

I don't like the way this your countdown-system works, but tried my best:

pawn Код:
forward countdown(playerid);
public countdown(playerid)
{
    if(CountDown != -1)
    {
        new text[32];
        if(CountDown == 6) // Countdown starting..
        {
            format(text, sizeof(text), "~p~Starting...");
            CountDown--;
        }
        else if(CountDown == 0) // Countdown ended..
        {
            format(text, sizeof(text), "~g~GO ~r~!");
            CountDown = -1;
        }
        else // Countdown in action..
        {
            format(text, sizeof(text), "~w~%d", CountDown);
            CountDown--;
        }

        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(GetDistanceBetweenPlayers(playerid, i) < 8.0)
            {
                if(CountDown == 6) // Countdown starting..
                {
                    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
                    TogglePlayerControllable(i, false);
                }
                else if(CountDown == 0) // Countdown ended..
                {
                    PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                    TogglePlayerControllable(i, true);
                }

                GameTextForPlayer(i, text, 1000, 6);
            }
        }

        SetTimerEx("countdown", 1000, false, "i", playerid);
    }
    return 1;
}
It works, or not.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)