SA-MP Forums Archive
Not working, timer - 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: Not working, timer (/showthread.php?tid=394467)



Not working, timer - KingyKings - 22.11.2012

top of the script
Quote:

forward musicstall(playerid);

OnGamemodeInit
Quote:

SetTimer("musicstall", 1000, false);

Quote:

public musicstall(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0,1478.8761,-1666.3502,14.5532))
{
PlayAudioStreamForPlayer(playerid, "http://lackofstyle.com/mp3s/bing_lookalotlikexmas.mp3");
}
}

It doesn't play the music when near the point?
I have tried doing it on a command like.

Код:
if(strcmp("/startmusicnearpoint", cmdtext, true, 10) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	    	if(IsPlayerInRangeOfPoint(playerid, 5.0,1478.8761,-1666.3502,14.5532))
	        {
	        PlayAudioStreamForPlayer(playerid, "http://lackofstyle.com/mp3s/bing_lookalotlikexmas.mp3");
	        }
	    }
        return 1;
}
and it works when i type it near the point.
But i want it to play automatically..

Can you help? +rep


Re: Not working, timer - Virus. - 22.11.2012

SetTimer("musicstall", 1000, false);

make it

SetTimer("musicstall", 1000, true);

EDIT : Sorry, its wrong. Don't mind it.


Re: Not working, timer - ViniBorn - 22.11.2012

Use SetTimerEx for functions with parameters
pawn Код:
SetTimerEx("musicstall", 1000, false,"d", playerid);



Re: Not working, timer - KingyKings - 22.11.2012

i put this under OnGameModeInit
Quote:

SetTimerEx("musicstall", 1000, false,"d", playerid);

said that it doesn't recognize the "playerid".
so i put it OnPlayerConnect and it still doesn't work?

what now? thanks btw


Re: Not working, timer - KingyKings - 22.11.2012

Am i doing it right?


AW: Not working, timer - Skimmer - 22.11.2012

No, try this.
pawn Код:
SetTimerEx("musicstall", 1000, true,"d", playerid);



Re: Not working, timer - Konstantinos - 22.11.2012

Or you can use what you did with a for loop.
pawn Код:
public OnGameModeInit( )
{
    SetTimer( "musicstall", 1000, false );
    return 1;
}

forward musicstall( );
public musicstall( )
{
    for( new p = 0; p < MAX_PLAYERS; p++ )
    {
        if( IsPlayerConnected( p ) && !IsPlayerNPC( p ) && IsPlayerInRangeOfPoint( p, 5.0,1478.8761, -1666.3502, 14.5532 ) )
        {
            PlayAudioStreamForPlayer( p, "http://lackofstyle.com/mp3s/bing_lookalotlikexmas.mp3" );
        }
    }
    return 1;
}



Re: Not working, timer - KingyKings - 22.11.2012

Okay Thanks, i found another guide which helped me

But now when i go near the point it spams the audio stream? How can i stop this?

Quote:

SetTimer("musicstall", 1500, true);

I have tried changing the "True" to "false" but then it just doesn't work atall. :/

thats my public if you need it?
Quote:

public musicstall()
{
for(new i = 1; i < MAX_PLAYERS; i++) {
if(IsPlayerInRangeOfPoint(i, 5.0,1478.8761,-1666.3502,14.5532))
{
PlayAudioStreamForPlayer(i, "http://adstorage.jamba.net/storage/view/325/0/ha/Have_Yourself_A_Merry_Litt1.mp3");
}
}
return 1;
}




Re: Not working, timer - Konstantinos - 22.11.2012

pawn Код:
new
    bool:Play_Audio[ MAX_PLAYERS ]
;

public OnGameModeInit( )
{
    SetTimer( "musicstall", 1000, true );
    return 1;
}

public OnPlayerConnect( playerid )
{
    Play_Audio[ playerid ] = false;
    return 1;
}

forward musicstall( );
public musicstall( )
{
    for( new p = 0; p < MAX_PLAYERS; p++ )
    {
        if( IsPlayerConnected( p ) && !IsPlayerNPC( p ) && IsPlayerInRangeOfPoint( p, 5.0,1478.8761, -1666.3502, 14.5532 ) )
        {
            if( Play_Audio[ p ] == true ) continue;
            PlayAudioStreamForPlayer( p, "http://lackofstyle.com/mp3s/bing_lookalotlikexmas.mp3" );
            Play_Audio[ p ] = true;
        }
        if( !IsPlayerInRangeOfPoint( p, 5.0,1478.8761, -1666.3502, 14.5532 ) ) Play_Audio[ p ] = false;
    }
    return 1;
}



Re: Not working, timer - KingyKings - 22.11.2012

Ahh yey works. Thanks so much! +rep