SA-MP Forums Archive
Where need put command code to make it work self - 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: Where need put command code to make it work self (/showthread.php?tid=624723)



Where need put command code to make it work self - henkas - 21.12.2016

Sup!
i find lottery script and it have /startlotto command bat i want make it without command just when server online this system start by her self
Код:
CMD:startlotto(playerid,params[])
{
   new startername[MAX_PLAYER_NAME],stri[200];
   if(IsLottoStarted==true)return SendClientMessage(playerid, 0xFF4500AA, "Lottery has already been started");
   IsLottoStarted=true;
   GetPlayerName(playerid,startername,sizeof(startername));
   format(stri,sizeof(stri),"%s has started Lottery",startername);
   SendClientMessageToAll(0xCCFF00,stri);
   format(stri,sizeof(stri),"It will be drawed after %i minutes.",lottogap);
   SendClientMessageToAll(0xCCFF00,stri);
   format(stri,sizeof(stri),"Current lottery is of %i score",lottoadd);
   SendClientMessageToAll(0xCCFF00,stri);
   format(stri,sizeof(stri),"Do /ticket [your number] to take a ticket | The number should be in range of 0-%i",numrange);
   SendClientMessageToAll(0xCCFF00,stri);
   SetTimer("draw",2000*60*lottogap,true);
   return 1;
}
I tried put this code part into ongamemodeinit
Код:
if(IsLottoStarted==true)return SendClientMessage(playerid, 0xFF4500AA, "Lottery has already been started");
IsLottoStarted=true;
GetPlayerName(playerid,startername,sizeof(startername));
format(stri,sizeof(stri),"%s has started Lottery",startername);
SendClientMessageToAll(0xCCFF00,stri);
format(stri,sizeof(stri),"It will be drawed after %i minutes.",lottogap);
SendClientMessageToAll(0xCCFF00,stri);
format(stri,sizeof(stri),"Current lottery is of %i $",lottoadd);
SendClientMessageToAll(0xCCFF00,stri);
format(stri,sizeof(stri),"Do /ticket [your number] to take a ticket | The number should be in range of 0-%i",numrange);
SendClientMessageToAll(0xCCFF00,stri);
lotto_timer=SetTimer("draw",1000*60*lottogap,true);
Bat happen nothing


Re: Where need put command code to make it work self - GoldenLion - 21.12.2016

OK, first of all there are no parameters in OnGameModeInit so you can't do anything with "playerid". Second there is no point of sending messages at OnGameModeInit as there will be no players online at this moment, therefore nobody will see them.
Код:
public OnGameModeInit()
{
    IsLottoStarted = true;
    lotto_timer=SetTimer("draw", 1000 * 60 * lottogap, true);
    return 1;
}
This is all you need to do. Third, it's "but", not "bat". This has been annoying me for a while lol.


Re: Where need put command code to make it work self - henkas - 21.12.2016

Thanks its work bat maybe know how can i make random define? from this
#define minlottoadd 14
I want it make random like from 1-14


Re: Where need put command code to make it work self - Yaa - 21.12.2016

PHP код:
new minlottoadd[][14] = 
{
      
"1",
      
"2",
      
"3",
      
"4",
      
"5",
      
"6",
      
"7",
      
"8",
      
"9",
      
"10",
      
"11",
      
"12"
      
"13",
      
"14"
};
new 
lrand random(sizeof(minlottoadd));
// and use minlottoadd[lrand] in your scripts 



Re: Where need put command code to make it work self - henkas - 21.12.2016

Pawn stopped working after this


Re: Where need put command code to make it work self - GoldenLion - 21.12.2016

You can use random to get a random number between 1 and 14 like this:
Код:
random(13) + 1;