CountDown
#1

So, I've got this script from another post on this forum and modified it so that only players in 10 meters range can see the timer but there is a problem with it. When only the user is in the set range (10m) the countdown works perfectly, but when someone else is in the radius it freaks out. Like one gets 2 then go and the other one gets 3,1 and go. I tried anything I could possibly think of so now I decided to look for some help here. Thanks in advance for those who decide to give me a hand.

pawn Код:
#define FILTERSCRIPT

#include <a_samp>

new Counter;
new Float:X,Float:Y,Float:Z;
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
  Counter = 0;
  return 1;
}

public OnFilterScriptExit()
{
  Counter = 0;
  return 1;
}
#else

main()
{
    print("\n------------------------------------------");
    print(" Countdown");
    print("------------------------------------------\n");
}

#endif

public OnPlayerCommandText(playerid, cmdtext[])
{
  if(!strcmp(cmdtext, "/countdown", true))
  {
    GetPlayerPos(playerid,X,Y,Z);
    if(Counter != 0) return SendClientMessage(playerid,0x004BFFFF, "ERROR: /countdown is already in use, Try again in a few seconds.");
    Counter = 3;
    Timer();
    return 1;
    }
  return 0;
}

forward Timer();
public Timer()
{
    new String[64];
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerInRangeOfPoint(i,10,X,Y,Z))
        {
        if(Counter== 0)
        {
            PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
            GameTextForPlayer(i,"~g~~h~Go Go Go !!", 2000, 5);
            TogglePlayerControllable(i,1);
            return 1;
        }
        format(String,sizeof(String),"~r~~h~%d",Counter);
        GameTextForPlayer(i,String, 800, 5);
        PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
        TogglePlayerControllable(i,0);
        Counter--;
        SetTimer("Timer", 1000, false);
        }
    }
    return 0;
}
Reply
#2

bump bump
Reply
#3

Quote:
Originally Posted by bertuspiteri
Посмотреть сообщение
bump bump
there were some logical errors, the problem occurs because you call so much timers at the same time.
try this code:

pawn Код:
public Timer()
{  
    new String[64];
    for(new i = 0 j = GetMaxPlayers() ; i < j ; i++)
    {
        if(IsPlayerInRangeOfPoint(i,10,X,Y,Z))
        {          
            if(Counter == 0)
            {
                PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                GameTextForPlayer(i,"~g~~h~Go Go Go !!", 2000, 5);
                TogglePlayerControllable(i,1);
                continue ;
            }
            format(String,sizeof(String),"~r~~h~%d",Counter);
            GameTextForPlayer(i,String, 800, 5);
            PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
            TogglePlayerControllable(i,0);
            Counter--;
        }
    }
    if( Counter ) SetTimer("Timer", 1000, false);
}
Reply
#4

Quote:
Originally Posted by dax123
Посмотреть сообщение
there were some logical errors, the problem occurs because you call so much timers at the same time.
try this code:

pawn Код:
public Timer()
{  
    new String[64];
    for(new i = 0 j = GetMaxPlayers() ; i < j ; i++)
    {
        if(IsPlayerInRangeOfPoint(i,10,X,Y,Z))
        {          
            if(Counter == 0)
            {
                PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                GameTextForPlayer(i,"~g~~h~Go Go Go !!", 2000, 5);
                TogglePlayerControllable(i,1);
                continue ;
            }
            format(String,sizeof(String),"~r~~h~%d",Counter);
            GameTextForPlayer(i,String, 800, 5);
            PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
            TogglePlayerControllable(i,0);
            Counter--;
        }
    }
    if( Counter ) SetTimer("Timer", 1000, false);
}
Errors:
Код:
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(48) : error 001: expected token: ";", but found "-identifier-"
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(48) : error 001: expected token: ")", but found ";"
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(48) : error 036: empty statement
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(48) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#5

slight mistake.

for(new i = 0, j = GetMaxPlayers() ; i < j ; i++)

pawn Код:
public Timer()
{  
    new String[64];
    for(new i = 0, j = GetMaxPlayers() ; i < j ; i++)
    {
        if(IsPlayerInRangeOfPoint(i,10,X,Y,Z))
        {          
            if(Counter == 0)
            {
                PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                GameTextForPlayer(i,"~g~~h~Go Go Go !!", 2000, 5);
                TogglePlayerControllable(i,1);
                continue ;
            }
            format(String,sizeof(String),"~r~~h~%d",Counter);
            GameTextForPlayer(i,String, 800, 5);
            PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
            TogglePlayerControllable(i,0);
            Counter--;
        }
    }
    if( Counter ) SetTimer("Timer", 1000, false);
}
Reply
#6

Ok...well now when only one person in radius the counter doesn't even reach Go, and when 2 it freaks out again like before
Reply
#7

Bump Again :/
Reply
#8

Anyone got any idea ? Please !!
Reply
#9

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/countdown", true))
    {
        new Float:X, Float:Y, Float:Z; //No global variable needed
        GetPlayerPos(playerid, X, Y, Z); //more countdown at once avaible
        Countdown(10.0, X, Y, Z, 3); //Ye I renamed it
        return 1;
    }
    return 0;
}
pawn Код:
forward Countdown(const Float:range, const Float:X, const Float:Y, const Float:Z, Counter);
public Countdown(const Float:range, const Float:X, const Float:Y, const Float:Z, Counter)
{
    if(Counter == 0)
    {
        for(new i; i != MAX_PLAYERS; i++)
        {
            if(IsPlayerInRangeOfPoint(i, range, X, Y, Z))
            {
                GameTextForPlayer(i,"~g~~h~Go Go Go !!", 2000, 5);
                PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                TogglePlayerControllable(i, true);
            }
        }
    } else {
        new i, string[16];
        format(string, sizeof(string), "~r~~h~%d", Counter--);
        for( ; i != MAX_PLAYERS; i++)
        {
            if(IsPlayerInRangeOfPoint(i, range, X, Y, Z))
            {
                PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
                GameTextForPlayer(i, string, 800, 5);
                TogglePlayerControllable(i, false);
            }
        }
        SetTimerEx("Countdown", 1000, false, "ffffd", range, X, Y, Z, Counter);
    }
}
Reply
#10

Thanks, for only one person it works fine but I can't test it with 2 or more cause my friends are offline ATM so I'll try tomorrow and tell you how it goes. Btw I recieve 2 warnings:

Код:
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(45) : warning 219: local variable "Counter" shadows a variable at a preceding level
C:\Users\User\Desktop\samp03bsvr_win32\filterscripts\CountDown.pwn(17) : warning 204: symbol is assigned a value that is never used: "Counter"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.
which I couldn't figure out how to fix but if the FS works fine with those warnings I wouldn't mind them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)