PDA

View Full Version : Where need put command code to make it work self


henkas
21/12/2016, 05:35 PM
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(startern ame));
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(startern ame));
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 :D

GoldenLion
21/12/2016, 08:25 PM
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.

henkas
21/12/2016, 09:17 PM
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

Yaa
21/12/2016, 09:23 PM
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

henkas
21/12/2016, 09:25 PM
Pawn stopped working after this :D

GoldenLion
22/12/2016, 12:19 AM
You can use random (http://wiki.sa-mp.com/wiki/Random) to get a random number between 1 and 14 like this:
random(13) + 1;