SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 18/05/2020, 12:31 AM   #1
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default countdown for near players

PHP Code:
new CountDown = -1;

forward countdown();
public 
countdown()
{
    if(
CountDown == 6GameTextForAll("~p~Starting..."10006);

    
CountDown--;
    if(
CountDown == 0)
    {
        
GameTextForAll("~g~GO~ r~!"10006);
        
CountDown = -1;
        for(new 
0MAX_PLAYERSi++) {
            
TogglePlayerControllable(itrue);
            
PlayerPlaySound(i10570.00.00.0);
        }
        return 
0;
    }
    else
    {
        new 
text[7]; format(textsizeof(text), "~w~%d"CountDown);
        for(new 
0MAX_PLAYERSi++) {
            
PlayerPlaySound(i10560.00.00.0);
            
TogglePlayerControllable(ifalse);
        }
         
GameTextForAll(text10006);
    }
    
SetTimer("countdown"10000);
    return 
0;
}

CMD:countdown(playeridparams[]) {
    if(
PlayerInfo[playerid][Level] >= 4) {
        if(
CountDown == -1) {
            
CountDown 6;
            
SetTimer("countdown"10000);
            return 
CMDMessageToAdmins(playerid"COUNTDOWN");
        } else return 
SendClientMessage(playeridred"ERROR: Countdown in progress");
    } else return 
SendClientMessage(playeridred"ERROR: You are not a high enough level to use this command");

How to make the countdowns are just for near 'playerid'?
I think I can use IsPlayerInRangeOfPoint but it would do the countdown just to the one nearest person (i guess)

EDIT: Or I can just use ProxDetector ? But idk how
Filbert is offline   Reply With Quote
Old 18/05/2020, 12:58 AM   #2
AzertyTheProgrammer
Little Clucker
 
AzertyTheProgrammer's Avatar
 
Join Date: May 2020
Posts: 7
Reputation: 0
Flowers Re: countdown for near players

Use " IsPlayerInRangeOfPoint " with Foreach. It will work trust me.
AzertyTheProgrammer is offline   Reply With Quote
Old 18/05/2020, 01:25 AM   #3
Ghazal
Gangsta
 
Ghazal's Avatar
 
Join Date: Oct 2013
Location: Egypt
Posts: 523
Reputation: 167
Default Re: countdown for near players

You can have something like this or just loop all connected players and check if they're in range with the countdown issuer using IsPlayerInRangeOfPoint by getting the issuer's position and comparing it to other players
PHP Code:
forward Float:GetDistanceBetweenPlayers(p1,p2);
public 
Float:GetDistanceBetweenPlayers(p1,p2)
{
    new 
Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if (!
IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -
1.00;
    }
    
GetPlayerPos(p1,x1,y1,z1);
    
GetPlayerPos(p2,x2,y2,z2);
    return 
floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
public 
countdown()
{
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && GetDistanceBetweenPlayers(playeridi) < 100.0// your range
        
{
            if(
CountDown == 6GameTextForAll("~p~Starting..."10006);

            
CountDown--;
            if(
CountDown == 0)
            {
                
GameTextForAll("~g~GO~ r~!"10006);
                
CountDown = -1;
                for(new 
0MAX_PLAYERSi++) {
                    
TogglePlayerControllable(itrue);
                    
PlayerPlaySound(i10570.00.00.0);
                }
                return 
0;
            }
            else
            {
                new 
text[7]; format(textsizeof(text), "~w~%d"CountDown);
                for(new 
0MAX_PLAYERSi++) {
                    
PlayerPlaySound(i10560.00.00.0);
                    
TogglePlayerControllable(ifalse);
                }
                 
GameTextForAll(text10006);
            }
            
SetTimer("countdown"10000);
        }
    }
    return 
0;

Ghazal is offline   Reply With Quote
Old 18/05/2020, 01:36 AM   #4
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: countdown for near players

Quote:
Originally Posted by Ghazal View Post
You can have something like this or just loop all connected players and check if they're in range with the countdown issuer using IsPlayerInRangeOfPoint by getting the issuer's position and comparing it to other players
PHP Code:
forward Float:GetDistanceBetweenPlayers(p1,p2);
public 
Float:GetDistanceBetweenPlayers(p1,p2)
{
    new 
Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if (!
IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -
1.00;
    }
    
GetPlayerPos(p1,x1,y1,z1);
    
GetPlayerPos(p2,x2,y2,z2);
    return 
floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
public 
countdown()
{
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && GetDistanceBetweenPlayers(playeridi) < 100.0// your range
        
{
            if(
CountDown == 6GameTextForAll("~p~Starting..."10006);

            
CountDown--;
            if(
CountDown == 0)
            {
                
GameTextForAll("~g~GO~ r~!"10006);
                
CountDown = -1;
                for(new 
0MAX_PLAYERSi++) {
                    
TogglePlayerControllable(itrue);
                    
PlayerPlaySound(i10570.00.00.0);
                }
                return 
0;
            }
            else
            {
                new 
text[7]; format(textsizeof(text), "~w~%d"CountDown);
                for(new 
0MAX_PLAYERSi++) {
                    
PlayerPlaySound(i10560.00.00.0);
                    
TogglePlayerControllable(ifalse);
                }
                 
GameTextForAll(text10006);
            }
            
SetTimer("countdown"10000);
        }
    }
    return 
0;

Is there an example map of, 100.0 range or 200.0 range?
Filbert is offline   Reply With Quote
Old 19/05/2020, 07:40 PM   #5
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: countdown for near players

So guys, I made it like this :

PHP Code:
forward Float:GetDistanceBetweenPlayers(p1,p2);
public 
Float:GetDistanceBetweenPlayers(p1,p2){
    new 
Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if (!
IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -
1.00;
    }
    
GetPlayerPos(p1,x1,y1,z1);
    
GetPlayerPos(p2,x2,y2,z2);
    return 
floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));


PHP Code:
forward countdown(playerid);
public 
countdown(playerid)
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && GetDistanceBetweenPlayers(playeridi) < 200.0)
        {
            if(
CountDown == 6GameTextForPlayer(i"~p~Starting..."10006);
            
CountDown--;
            if(
CountDown == 0)
            {
                
GameTextForPlayer(i"~g~GO~ r~!"10006);
                
CountDown = -1;
                
TogglePlayerControllable(itrue);
                
PlayerPlaySound(i10570.00.00.0);
                return 
0;
            }
            else
            {
                new 
text[7]; format(textsizeof(text), "~w~%d"CountDown);
                
PlayerPlaySound(i10560.00.00.0);
                
TogglePlayerControllable(ifalse);
                
GameTextForPlayer(itext10006);
            }
            
SetTimer("countdown"10000);
        }
    }
    return 
0;
}

CMD:countdown(playeridparams[]) {
    if(
PlayerInfo[playerid][Level] >= 4) {
        if(
CountDown == -1) {
            
CountDown 6;
            
SetTimer("countdown"10000);
            return 
CMDMessageToAdmins(playerid"COUNTDOWN");
        } else return 
SendClientMessage(playeridred"ERROR: Countdown in progress");
    } else return 
SendClientMessage(playeridred"ERROR: You are not a high enough level to use this command");

And when i start the countdown, nothing happened. It just sends me the "CMDMessageToAdmins(playerid, "COUNTDOWN");". No one sees the countdown, me nor my friends. Even they're beside me

And I made a duel countdown like this :

PHP Code:
forward duelTimer(playerid);
public 
duelTimer(playerid)
{
    
/*if(DuelCD[dueler1] == 6) {
        GameTextForPlayer(dueler1, "~p~Starting...", 1000, 6);
        GameTextForPlayer(dueler2, "~p~Starting...", 1000, 6);
    }*/
    
DuelCD[dueler1]--;
    if(
DuelCD[dueler1] == 0)
    {
        
GameTextForPlayer(dueler1"~g~go get em~ r~!"10006);
        
GameTextForPlayer(dueler2"~g~go get em~ r~!"10006);
        
//DuelCD[dueler1] = -1;
        
TogglePlayerControllable(dueler1true);
        
TogglePlayerControllable(dueler2true);
        
PlayerPlaySound(dueler110570.00.00.0);
        
PlayerPlaySound(dueler210570.00.00.0);
        return 
0;
    }
    else
    {
        new 
text[7]; format(textsizeof(text), "~w~%d"CountDown);
        
PlayerPlaySound(dueler110560.00.00.0);
        
PlayerPlaySound(dueler210560.00.00.0);
        
TogglePlayerControllable(dueler1false);
        
TogglePlayerControllable(dueler2false);
        
GameTextForPlayer(dueler1text10006);
        
GameTextForPlayer(dueler2text10006);
        
SetCameraBehindPlayer(dueler1);
        
SetCameraBehindPlayer(dueler2);
    }
    
SetTimer("duelTimer"10000);
    return 
0;

And I call it like this in somewhere.

PHP Code:
SetTimer("duelTimer"10000); 
But idk why, countdown isn't "5,4,3,2,1" but it goes like "-1,-1,-1,-1,-1"

How to fix this guys?
Filbert is offline   Reply With Quote
Old 19/05/2020, 11:25 PM   #6
Grim_
High-roller
 
Grim_'s Avatar
 
Join Date: Sep 2008
Location: United States
Posts: 2,896
Reputation: 118
Default Re: countdown for near players

You need to use SetTimerEx to pass the playerid parameter to your countdown callback
pawn Code:
SetTimerEx("countdown", 1000, false, "i", playerid);
Also, just use IsPlayerInRangeOfPoint. I'm sure it's more optimized than the custom function you are using.
pawn Code:
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(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 200.0, x, y, z))
        {
            // rest of code
Grim_ 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
Countdown help Finn707 Scripting Help 4 02/09/2013 06:07 PM
help with CountDown... omer5198 Help Archive 2 09/08/2011 03:01 PM
[HELP] Countdown joeri55 Help Archive 1 22/05/2011 06:40 PM
CountDown for players in range juuleman Help Archive 4 26/03/2010 09:32 AM
CountDown help Vadonis Help Archive 4 28/07/2009 04:26 PM


All times are GMT. The time now is 10:51 PM.


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