#1

Hello, can anyone help me, what do i need to add there to make the player wait 2 minutes before using the command again?

PHP код:
CMD:heilen(playerid,params[])
{
    new 
targetid;
    new 
string[128];
    if(
sscanf(params"u"targetid))
    return 
SendClientMessage(playeridFARBE_ROT"/heilen [Spielerid]");
    if(
SpielerInfo[playerid][sDoktor] == 0)
    return 
SendClientMessage(playeridFARBE_ROT"Du bist kein Doktor!");
    if(
IsPlayerNPC(targetid))
    return 
SendClientMessage(playeridFARBE_ROT"Du kannst keine Computer heilen!");
    if(
SpielerInfo[playerid][sDieanderen] == 1)
    return 
SendClientMessage(playeridFARBE_ROT"Du bist nicht in der Gruppe 'Die Ьberlebenden'.");
    if(
targetid == playerid) return SendClientMessage(playeridFARBE_ROT"Du kannst dich selbst nicht heilen!");
    new 
targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
    
GetPlayerName(targetidtargetnamesizeof(targetname));
    
GetPlayerName(playeridsendernamesizeof(sendername));
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid,x,y,z);
    new 
Float:tx,Float:ty,Float:tz;
    
GetPlayerPos(targetid,tx,ty,tz);
    if(!
IsPlayerInRangeOfPoint(playerid6.0tx,ty,tz))
    return 
SendClientMessage(playeridFARBE_ROT"Dieser Spieler ist nicht in deiner Nдhe!");
    {
        
GameTextForPlayer(playerid"Heilt den Spieler...",5,3000);
        new 
message random(2);
        if(
message == 0)
        {
            
GameTextForPlayer(playerid"Du konntest diesen Spieler nicht heilen.",5,3000);
            
format(stringsizeof(string), "Doktor %s hat versucht %s zu heilen, ist aber gescheitert."sendernametargetname);
            
ProxDetector(30.0playeridstringFARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT);
        }
        if(
message == 1)
        {
            
GameTextForPlayer(playerid"Du hast diesen Spieler geheilt!",5,3000);
            
GameTextForPlayer(targetid"Geheilt",5,3000);
            
format(stringsizeof(string), "Doktor %s hat %s geheilt."sendernametargetname);
            
ProxDetector(30.0playeridstringFARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN);
            
SetPlayerHealth(targetid100);
        }
    }
    return 
1;

Reply
#2

Set TImer and player varibale like Command[playerid] = 1;
When he does command again
PHP код:
if(Command[playerid] == 1)
{
//stop him from performing it

In Timer function add Command[playerid] = 0;

So when timer expires it will set his command variable to 0 so he can use command again
Reply
#3

Hvala brate al ne razumem se lepo u ovo =D
Reply
#4

Engish only in this section please...
Reply
#5

PHP код:
forward heilen_Timer(playerid);
new 
heilen_Command[MAX_PLAYERS];
public 
heilne_Timer(playerid)
{
    
heilen_Command[playerid] = 0;
}
CMD:heilen(playerid,params[])
{
    if(
heilen_Command[playerid] == 1)
    {
        
SendClientMessage(playerid,0xFF0000FF,"You can use this command once every 2 minutes!");
    }
    else
    {
        new 
targetid;
        new 
string[128];
        if(
sscanf(params"u"targetid))
        return 
SendClientMessage(playeridFARBE_ROT"/heilen [Spielerid]");
        if(
SpielerInfo[playerid][sDoktor] == 0)
        return 
SendClientMessage(playeridFARBE_ROT"Du bist kein Doktor!");
        if(
IsPlayerNPC(targetid))
        return 
SendClientMessage(playeridFARBE_ROT"Du kannst keine Computer heilen!");
        if(
SpielerInfo[playerid][sDieanderen] == 1)
        return 
SendClientMessage(playeridFARBE_ROT"Du bist nicht in der Gruppe 'Die Ьberlebenden'.");
        if(
targetid == playerid) return SendClientMessage(playeridFARBE_ROT"Du kannst dich selbst nicht heilen!");
        new 
targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
        
GetPlayerName(targetidtargetnamesizeof(targetname));
        
GetPlayerName(playeridsendernamesizeof(sendername));
        new 
Float:x,Float:y,Float:z;
        
GetPlayerPos(playerid,x,y,z);
        new 
Float:tx,Float:ty,Float:tz;
        
GetPlayerPos(targetid,tx,ty,tz);
        if(!
IsPlayerInRangeOfPoint(playerid6.0tx,ty,tz))
        return 
SendClientMessage(playeridFARBE_ROT"Dieser Spieler ist nicht in deiner Nдhe!");
        {
            
GameTextForPlayer(playerid"Heilt den Spieler...",5,3000);
            new 
message random(2);
            if(
message == 0)
            {
                
GameTextForPlayer(playerid"Du konntest diesen Spieler nicht heilen.",5,3000);
                
format(stringsizeof(string), "Doktor %s hat versucht %s zu heilen, ist aber gescheitert."sendernametargetname);
                
ProxDetector(30.0playeridstringFARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT);
            }
            if(
message == 1)
            {
                
GameTextForPlayer(playerid"Du hast diesen Spieler geheilt!",5,3000);
                
GameTextForPlayer(targetid"Geheilt",5,3000);
                
format(stringsizeof(string), "Doktor %s hat %s geheilt."sendernametargetname);
                
ProxDetector(30.0playeridstringFARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN);
                
SetPlayerHealth(targetid100);
            }
        }
        
heilen_Command[playerid] = 1;
        
SetTimerEx("heilen_Timer",120000,false,"d",playerid);
        return 
1;
    }

Should work
Reply
#6

You could do this without a timer by using Unix timestamps. You can find a real thorough tutorial on them here: https://sampforum.blast.hk/showthread.php?tid=254915

You would store the value of the timestamp the first time the player succeeds the command. Then every time the player types the command, check the current stamp - the variables value, and see if it's greater than the time you want them to have to wait. If so, they can use the command again.
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
GetTickCount - no need for timers.
Can you make me an example with the code i posted?
Reply
#8

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
PHP код:
forward heilen_Timer(playerid);
new 
heilen_Command[MAX_PLAYERS];
public 
heilne_Timer(playerid)
{
    
heilen_Command[playerid] = 0;
}
CMD:heilen(playerid,params[])
{
    if(
heilen_Command[playerid] == 1)
    {
        
SendClientMessage(playerid,0xFF0000FF,"You can use this command once every 2 minutes!");
    }
    else
    {
        new 
targetid;
        new 
string[128];
        if(
sscanf(params"u"targetid))
        return 
SendClientMessage(playeridFARBE_ROT"/heilen [Spielerid]");
        if(
SpielerInfo[playerid][sDoktor] == 0)
        return 
SendClientMessage(playeridFARBE_ROT"Du bist kein Doktor!");
        if(
IsPlayerNPC(targetid))
        return 
SendClientMessage(playeridFARBE_ROT"Du kannst keine Computer heilen!");
        if(
SpielerInfo[playerid][sDieanderen] == 1)
        return 
SendClientMessage(playeridFARBE_ROT"Du bist nicht in der Gruppe 'Die Ьberlebenden'.");
        if(
targetid == playerid) return SendClientMessage(playeridFARBE_ROT"Du kannst dich selbst nicht heilen!");
        new 
targetname[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME];
        
GetPlayerName(targetidtargetnamesizeof(targetname));
        
GetPlayerName(playeridsendernamesizeof(sendername));
        new 
Float:x,Float:y,Float:z;
        
GetPlayerPos(playerid,x,y,z);
        new 
Float:tx,Float:ty,Float:tz;
        
GetPlayerPos(targetid,tx,ty,tz);
        if(!
IsPlayerInRangeOfPoint(playerid6.0tx,ty,tz))
        return 
SendClientMessage(playeridFARBE_ROT"Dieser Spieler ist nicht in deiner Nдhe!");
        {
            
GameTextForPlayer(playerid"Heilt den Spieler...",5,3000);
            new 
message random(2);
            if(
message == 0)
            {
                
GameTextForPlayer(playerid"Du konntest diesen Spieler nicht heilen.",5,3000);
                
format(stringsizeof(string), "Doktor %s hat versucht %s zu heilen, ist aber gescheitert."sendernametargetname);
                
ProxDetector(30.0playeridstringFARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT,FARBE_ROT);
            }
            if(
message == 1)
            {
                
GameTextForPlayer(playerid"Du hast diesen Spieler geheilt!",5,3000);
                
GameTextForPlayer(targetid"Geheilt",5,3000);
                
format(stringsizeof(string), "Doktor %s hat %s geheilt."sendernametargetname);
                
ProxDetector(30.0playeridstringFARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN,FARBE_GRUEN);
                
SetPlayerHealth(targetid100);
            }
        }
        
heilen_Command[playerid] = 1;
        
SetTimerEx("heilen_Timer",120000,false,"d",playerid);
        return 
1;
    }

Should work
I will try it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)