SA-MP Forums Archive
Inserted number missing - 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: Inserted number missing (/showthread.php?tid=581379)



Inserted number missing - Mouiz - 12.07.2015

I have a countdown command but when i type /count 10,it start the counting from 9

PHP код:
public Counting(playerid)
{
    if(
Count >= 11) return 0;
    if(
Count == 0){
    
KillTimer(CountTimer);
    }else{
    new 
string[20];
    
format(string,sizeof(string),"~g~%d",Count);
    
GameTextForPlayer(playeridstring10003) && PlayerPlaySound(playerid1056,0,0,0) && Count --;
    }
    return 
1;

PHP код:
CMD:count(playerid,params[])
{
    if(
PlayerInfo[playerid][Freeze] == 1) return GameTextForPlayer(playerid"~g~you cant use commands while being ~n~~g~frozen",4500,3);
    if(
PlayerInfo[playerid][Jail] == 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3);
    if(
indm[playerid] >= 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3);
    if(
PlayerInfo[playerid][pVip] >= 1)
    {
    new 
seconds;
    new 
Float:x,Float:y,Float:z;
    
GetPlayerPos(playeridxyz);
    if(
sscanf(params,"i",seconds)) return GameTextForPlayer(playerid"~g~/count <seconds>",4500,3);
    
Count seconds;
    
CountTimer SetTimer("Counting",1000,true);
    if 
IsPlayerInRangeOfPoint(playeridCOUNTRANGExyz) *then SetTimer("Counting",1000,false);
    }
    return 
1;




Re: Inserted number missing - Mouiz - 12.07.2015

Need help please +REP


Re : Inserted number missing - KillerDVX - 12.07.2015

For me, it would be better using this :

PHP код:
forward Counting(playerid);
forward Counting9(playerid);
forward Counting8(playerid);
forward Counting7(playerid);
forward Counting6(playerid);
forward Counting5(playerid);
forward Counting4(playerid);
forward Counting3(playerid);
forward Counting2(playerid);
forward Counting1(playerid);
forward CountingGO(playerid);
public 
Counting(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~g~10  ~y~]",2000,3);
    
SetTimer("Counting9",1000,false);
    return 
1;
}
public 
Counting9(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~b~9  ~y~]",2000,3);
    
SetTimer("Counting8",1000,false);
    return 
1;
}
public 
Counting8(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~8  ~y~]",2000,3);
    
SetTimer("Counting7",1000,false);
    return 
1;
}
public 
Counting7(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~7  ~y~]",2000,3);
    
SetTimer("Counting6",1000,false);
    return 
1;
}
public 
Counting6(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~6  ~y~]",2000,3);
    
SetTimer("Counting5",1000,false);
    return 
1;
}
public 
Counting5(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~5  ~y~]",2000,3);
    
SetTimer("Counting4",1000,false);
    return 
1;
}
public 
Counting4(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~4  ~y~]",2000,3);
    
SetTimer("Counting3",1000,false);
    return 
1;
}
public 
Counting3(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~3 ~y~]",2000,3);
    
SetTimer("Counting2",1000,false);
    return 
1;
}
public 
Counting2(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~2  ~y~]",2000,3);
    
SetTimer("Counting1",1000,false);
    return 
1;
}
public 
Counting1(playerid)
{
    
Count 1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~1  ~y~]",2000,3);
    
SetTimer("CountingGO",1000,false);
    return 
1;
}
public 
CountingGO(playerid)
{
    
Count 0;
        
PlayerPlaySound(playerid1057,0.0,0.0,0.0);
    
GameTextForAll("~y~] ~r~G ~g~O ~b~O ~p~O ~w~ ~y~]",1000,3);
    return 
1;
}
CMD:count(playerid,params[]) 

    if(
PlayerInfo[playerid][Freeze] == 1) return GameTextForPlayer(playerid"~g~you cant use commands while being ~n~~g~frozen",4500,3); 
    if(
PlayerInfo[playerid][Jail] == 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
indm[playerid] >= 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
PlayerInfo[playerid][pVip] >= 1
    { 
    new 
seconds
    new 
Float:x,Float:y,Float:z
    
GetPlayerPos(playeridxyz); 
    if(
sscanf(params,"i",seconds)) return GameTextForPlayer(playerid"~g~/count <seconds>",4500,3); 
    
Count seconds
    
CountTimer SetTimer("Counting",1000,true); 
    if 
IsPlayerInRangeOfPoint(playeridCOUNTRANGExyz) *then SetTimer("Counting",1000,false); 
    } 
    return 
1




Re: Re : Inserted number missing - Mouiz - 12.07.2015

Quote:
Originally Posted by KillerDVX
Посмотреть сообщение
For me, it would be better using this :

PHP код:
forward Counting(playerid);
forward Counting9(playerid);
forward Counting8(playerid);
forward Counting7(playerid);
forward Counting6(playerid);
forward Counting5(playerid);
forward Counting4(playerid);
forward Counting3(playerid);
forward Counting2(playerid);
forward Counting1(playerid);
forward CountingGO(playerid);
public 
Counting(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~g~10  ~y~]",2000,3);
    
SetTimer("Counting9",1000,false);
    return 
1;
}
public 
Counting9(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~b~9  ~y~]",2000,3);
    
SetTimer("Counting8",1000,false);
    return 
1;
}
public 
Counting8(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~8  ~y~]",2000,3);
    
SetTimer("Counting7",1000,false);
    return 
1;
}
public 
Counting7(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~7  ~y~]",2000,3);
    
SetTimer("Counting6",1000,false);
    return 
1;
}
public 
Counting6(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~6  ~y~]",2000,3);
    
SetTimer("Counting5",1000,false);
    return 
1;
}
public 
Counting5(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~5  ~y~]",2000,3);
    
SetTimer("Counting4",1000,false);
    return 
1;
}
public 
Counting4(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~4  ~y~]",2000,3);
    
SetTimer("Counting3",1000,false);
    return 
1;
}
public 
Counting3(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~3 ~y~]",2000,3);
    
SetTimer("Counting2",1000,false);
    return 
1;
}
public 
Counting2(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~2  ~y~]",2000,3);
    
SetTimer("Counting1",1000,false);
    return 
1;
}
public 
Counting1(playerid)
{
    
Count 1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~1  ~y~]",2000,3);
    
SetTimer("CountingGO",1000,false);
    return 
1;
}
public 
CountingGO(playerid)
{
    
Count 0;
        
PlayerPlaySound(playerid1057,0.0,0.0,0.0);
    
GameTextForAll("~y~] ~r~G ~g~O ~b~O ~p~O ~w~ ~y~]",1000,3);
    return 
1;
}
CMD:count(playerid,params[]) 

    if(
PlayerInfo[playerid][Freeze] == 1) return GameTextForPlayer(playerid"~g~you cant use commands while being ~n~~g~frozen",4500,3); 
    if(
PlayerInfo[playerid][Jail] == 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
indm[playerid] >= 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
PlayerInfo[playerid][pVip] >= 1
    { 
    new 
seconds
    new 
Float:x,Float:y,Float:z
    
GetPlayerPos(playeridxyz); 
    if(
sscanf(params,"i",seconds)) return GameTextForPlayer(playerid"~g~/count <seconds>",4500,3); 
    
Count seconds
    
CountTimer SetTimer("Counting",1000,true); 
    if 
IsPlayerInRangeOfPoint(playeridCOUNTRANGExyz) *then SetTimer("Counting",1000,false); 
    } 
    return 
1

I fixed it right now but thanks for help,i just need to do this:

Код:
SetTimer("Counting",1000,false);
to

Код:
SetTimer("Counting",1,false);



Re: Re : Inserted number missing - Vince - 12.07.2015

Quote:
Originally Posted by KillerDVX
Посмотреть сообщение
[COLOR="DarkRed"][I]For me, it would be better using this :

PHP код:
forward Counting(playerid);
forward Counting9(playerid);
forward Counting8(playerid);
forward Counting7(playerid);
forward Counting6(playerid);
forward Counting5(playerid);
forward Counting4(playerid);
forward Counting3(playerid);
forward Counting2(playerid);
forward Counting1(playerid);
forward CountingGO(playerid); 
Ew, ew, EEEEEEEEWWW! That's got to be the most horrible and unmaintainable code I have seen in a long, long time. Functions can have more than one parameter. Use them!


Re: Re : Inserted number missing - Tamer - 12.07.2015

Quote:
Originally Posted by KillerDVX
Посмотреть сообщение
For me, it would be better using this :

PHP код:
forward Counting(playerid);
forward Counting9(playerid);
forward Counting8(playerid);
forward Counting7(playerid);
forward Counting6(playerid);
forward Counting5(playerid);
forward Counting4(playerid);
forward Counting3(playerid);
forward Counting2(playerid);
forward Counting1(playerid);
forward CountingGO(playerid);
public 
Counting(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~g~10  ~y~]",2000,3);
    
SetTimer("Counting9",1000,false);
    return 
1;
}
public 
Counting9(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~b~9  ~y~]",2000,3);
    
SetTimer("Counting8",1000,false);
    return 
1;
}
public 
Counting8(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~8  ~y~]",2000,3);
    
SetTimer("Counting7",1000,false);
    return 
1;
}
public 
Counting7(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~7  ~y~]",2000,3);
    
SetTimer("Counting6",1000,false);
    return 
1;
}
public 
Counting6(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~6  ~y~]",2000,3);
    
SetTimer("Counting5",1000,false);
    return 
1;
}
public 
Counting5(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~5  ~y~]",2000,3);
    
SetTimer("Counting4",1000,false);
    return 
1;
}
public 
Counting4(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~4  ~y~]",2000,3);
    
SetTimer("Counting3",1000,false);
    return 
1;
}
public 
Counting3(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~3 ~y~]",2000,3);
    
SetTimer("Counting2",1000,false);
    return 
1;
}
public 
Counting2(playerid)
{
    
Count1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~2  ~y~]",2000,3);
    
SetTimer("Counting1",1000,false);
    return 
1;
}
public 
Counting1(playerid)
{
    
Count 1;
    
PlayerPlaySound(playerid1056,0.0,0.0,0.0);
    
GameTextForAll("~y~]  ~r~1  ~y~]",2000,3);
    
SetTimer("CountingGO",1000,false);
    return 
1;
}
public 
CountingGO(playerid)
{
    
Count 0;
        
PlayerPlaySound(playerid1057,0.0,0.0,0.0);
    
GameTextForAll("~y~] ~r~G ~g~O ~b~O ~p~O ~w~ ~y~]",1000,3);
    return 
1;
}
CMD:count(playerid,params[]) 

    if(
PlayerInfo[playerid][Freeze] == 1) return GameTextForPlayer(playerid"~g~you cant use commands while being ~n~~g~frozen",4500,3); 
    if(
PlayerInfo[playerid][Jail] == 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
indm[playerid] >= 1) return GameTextForPlayer(playerid,"~g~Player is not in freeroam",2500,3); 
    if(
PlayerInfo[playerid][pVip] >= 1
    { 
    new 
seconds
    new 
Float:x,Float:y,Float:z
    
GetPlayerPos(playeridxyz); 
    if(
sscanf(params,"i",seconds)) return GameTextForPlayer(playerid"~g~/count <seconds>",4500,3); 
    
Count seconds
    
CountTimer SetTimer("Counting",1000,true); 
    if 
IsPlayerInRangeOfPoint(playeridCOUNTRANGExyz) *then SetTimer("Counting",1000,false); 
    } 
    return 
1

Holy shit I would stay away from such code for real. This ain't good for your health. You should re-consider the way you code. Even using a variable is better than this, but you can always pass on the seconds left and decrease it every second, easy stuff.