Timer help
#1

This is a countdown filterscript and if a player type /count so it will start countdown for 10 seconds but i want to make its command like /count <seconds>

Код:
#include "a_samp"
#include "zcmd"
#define COUNTRANGE 20

forward Count1(playerid);
forward Count2(playerid);
forward Count3(playerid);
forward Count4(playerid);
forward Count5(playerid);
forward Count6(playerid);
forward Count7(playerid);
forward Count8(playerid);
forward Count9(playerid);
forward Count10(playerid);

public OnFilterScriptInit()
{
	return 1;
}
CMD:count(playerid,params[])
{
        new Float:x,Float:y,Float:z;
        GetPlayerPos(playerid, x, y, z);
		SetTimer("Count1",1000,false);
        if IsPlayerInRangeOfPoint(playerid, COUNTRANGE, x, y, z) *then SetTimer("Count1",1000,false);
        return 1;
}

public Count1(playerid)
{
        GameTextForPlayer(playerid,"~g~10",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count2",1000,false);
        return 1;
}
public Count2(playerid)
{
        GameTextForPlayer(playerid,"~g~9",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count3",1000,false);
        return 1;
}
public Count3(playerid)
{
        GameTextForPlayer(playerid,"~g~8",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count4",1000,false);
        return 1;
}
public Count4(playerid)
{
        GameTextForPlayer(playerid,"~g~7",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count5",1000,false);
        return 1;
}
public Count5(playerid)
{
        GameTextForPlayer(playerid,"~g~6",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count6",1000,false);
        return 1;
}
public Count6(playerid)
{
        GameTextForPlayer(playerid,"~g~5",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count7",1000,false);
        return 1;
}
public Count7(playerid)
{
        GameTextForPlayer(playerid,"~g~4",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count8",1000,false);
        return 1;
}
public Count8(playerid)
{
        GameTextForPlayer(playerid,"~g~3",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count9",1000,false);
        return 1;
}
public Count9(playerid)
{
        GameTextForPlayer(playerid,"~g~2",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        SetTimer("Count10",1000,false);
        return 1;
}
public Count10(playerid)
{
        GameTextForPlayer(playerid,"~g~1",1000,3);
        PlayerPlaySound(playerid, 1056,0,0,0);
        return 1;
}
Reply
#2

Anyone can help?
Reply
#3

Make 1 callback.

Код:
Public Count(playerid, seconds)
{
	String = seconds;
	GameTextForPlayer("blabla, string");
	seconds = seconds-1;
	If seconds > 0 Then
	{
		SetTimerEx("Count",1000,True, "ii", playerid, seconds);
	}
	Return 1;
}
I just made this real quick and I know its not complete.

I hope you understand what I mean with this and please dont copy and paste this onto your script because it wont work. But learn to script practically.
You dont need a "count" for every second, you can use SetTimerEx and take the seconds variable into the callback.

https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#4

Quote:
Originally Posted by notime
Посмотреть сообщение
Make 1 callback.

Код:
Public Count(playerid, seconds)
{
	String = seconds;
	GameTextForPlayer("blabla, string");
	seconds = seconds-1;
	If seconds > 0 Then
	{
		SetTimerEx("Count",1000,True, "ii", playerid, seconds);
	}
	Return 1;
}
I just made this real quick and I know its not complete.

I hope you understand what I mean with this and please dont copy and paste this onto your script because it wont work. But learn to script practically.
You dont need a "count" for every second, you can use SetTimerEx and take the seconds variable into the callback.

https://sampwiki.blast.hk/wiki/SetTimerEx
thats not the helping,i know how to set timer but tell me how to set timer for the entered time.
Reply
#5

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
thats not the helping,i know how to set timer but tell me how to set timer for the entered time.
Aah, I understand now, you dont want actual help explained, you want someone to make it for you? No problem, I can do that.

Код:
forward Count1(playerid, seconds);

CMD:count(playerid,params[])
{
	new iSec, Float:x,Float:y,Float:z;
        GetPlayerPos(playerid, x, y, z);
	iSec = StrVal(params);
	SetTimerEx("Count1",1000,false, "ii", playerid, iSec);
	return 1;
}

public Count1(playerid, seconds)
{
	new string[128];
	format(string, sizeof(string), "~g~%d", seconds);
	GameTextForPlayer(playerid,string,1000,3);
	PlayerPlaySound(playerid, 1056,0,0,0);
	seconds = seconds -1;
	if seconds > -1 then
	{
		SetTimerEx("Count1",1000,false, "ii", playerid, seconds);
	}
	return 1;
}
Reply
#6

Forgot?

Код:
forward Count1(playerid, seconds);

CMD:count(playerid,params[])
{
	new iSec, Float:x,Float:y,Float:z;
        GetPlayerPos(playerid, x, y, z);
	iSec = StrVal(params);
	SetTimerEx("Count1",1000,false, "ii", playerid, iSec);
	return 1;
}

public Count1(playerid, seconds)
{
	new string[128];
	format(string, sizeof(string), "~g~%d", seconds);
	GameTextForPlayer(playerid,string,1000,3);
	PlayerPlaySound(playerid, 1056,0,0,0);
	seconds = seconds -1;
	if seconds > -1 *then
	{
		SetTimerEx("Count1",1000,false, "ii", playerid, seconds);
	}
	return 1;
}
Reply
#7

Quote:
Originally Posted by Mouiz
Посмотреть сообщение
Forgot?

Код:
forward Count1(playerid, seconds);

CMD:count(playerid,params[])
{
	new iSec, Float:x,Float:y,Float:z;
        GetPlayerPos(playerid, x, y, z);
	iSec = StrVal(params);
	SetTimerEx("Count1",1000,false, "ii", playerid, iSec);
	return 1;
}

public Count1(playerid, seconds)
{
	new string[128];
	format(string, sizeof(string), "~g~%d", seconds);
	GameTextForPlayer(playerid,string,1000,3);
	PlayerPlaySound(playerid, 1056,0,0,0);
	seconds = seconds -1;
	if seconds > -1 *then
	{
		SetTimerEx("Count1",1000,false, "ii", playerid, seconds);
	}
	return 1;
}
Or a thank you?
Anyways, Its been a year since I've programmed in PAWNO, is that * a new thing?

EDIT: Ah I found it, the "then" I dont need, I program for other system aswel, where when there is an "if" there should be a "then". I forgot in PAWNO you dont need that.
Reply
#8

#include <zcmd>
#include <sscanf2>

new Count;
new CountTimer;

CMD:count(playerid,params[])
{
new seconds;
if(sscanf(params,"i",seconds)) return SendClientMessage(playerid,-1,"Usage: /count [Seconds]");
Count=seconds;
CountTimer = SetTimer("Counting",1000,true);
return 1;
}

forward Counting();
public Counting()
{
Count --;
if(Count == 0){
KillTimer(CountTimer);
GameTextForAll("GO GO GO",1000,3);
}else{
new string[20];
format(string,sizeof(string),"%d",Count);
GameTextForAll(string,1000,3);
}
}
Reply
#9

Quote:
Originally Posted by kyriakos587
Посмотреть сообщение
#include <zcmd>
#include <sscanf2>

new Count;
new CountTimer;

CMD:count(playerid,params[])
{
new seconds;
if(sscanf(params,"i",seconds)) return SendClientMessage(playerid,-1,"Usage: /count [Seconds]");
Count=seconds;
CountTimer = SetTimer("Counting",1000,true);
return 1;
}

forward Counting();
public Counting()
{
Count --;
if(Count == 0){
KillTimer(CountTimer);
GameTextForAll("GO GO GO",1000,3);
}else{
new string[20];
format(string,sizeof(string),"%d",Count);
GameTextForAll(string,1000,3);
}
}
thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)