Need help with random numbers... -
*BueNoOo* - 18.06.2009
Hello all SA-MP players... I got a little problem here, well I would like to make a Gambling System, then realise it

But I am kind of noob in that stuff, so I want to ask you guys for help
I was wondering how to make it working, I want something about 30-40 numbers. Is that code OK ? :
pawn Код:
new LottoNumbers[10][1] = {
{1},
{2},
{3},
{4},
{5},
{6},
{7}
{8}
{9}
{10}
};
Is that code OK ? I would like to make it so when player types /lotto [number] it will start an individual lottery just for him, but he has to pick a number, so if he for example picks a number 1, and the lottery will stop on 1 he will get the money. I would like to get it working, i got some ideas but I am really confused

... Please help me
Maybe some commands like
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new LottoNumbers;
if(strcmp(cmdtext,"/lotto",true)==0) // then it pops a message " You have to type "/lotto [number]"
{
if (PlayerToPoint(3.0, playerid,1653.9108,-1655.2948,22.5156))
{
SetPlayerLottery ??? i don't know how to do it :((( So when player selects a number he wants, it starts a lottery with those 10 numbers, and then the lottery stops at some number, if it's the number that player have choosen he get's a money, if it is not, he gets nothing ...
return 1;
}
}
}
Hope you can help me

(
Re: Need help with random numbers... -
Vince - 18.06.2009
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
// define strtok stuff here, or use dcmd
new pLotto;
new RandNumber;
if(strcmp(cmd,"/lotto",true)==0) // then it pops a message " You have to type "/lotto [number]"
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp) return SendClientMessage(playerid, COLOR_RED, "Usage: /lotto [number]");
pLotto = strval(tmp);
if (PlayerToPoint(3.0, playerid,1653.9108,-1655.2948,22.5156))
{
RandNumber = 1+random(10);
if(RandNumber == pLotto)
{
GameTextForPlayer(playerid, "~w~Congratulations!~n~You won ~g~$10000",5000, 5);
GivePlayerMoney(playerid, 10000);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Sorry, you didn't win this time!");
}
return 1;
}
}
return 0;
}
Re: Need help with random numbers... -
*BueNoOo* - 18.06.2009
Thank you Vince, but do I have to use that too ?? :
pawn Код:
new LottoNumbers[10][1] = {
{1},
{2},
{3},
{4},
{5},
{6},
{7}
{8}
{9}
{10}
};
Re: Need help with random numbers... -
Grim_ - 18.06.2009
With the code he posted, it does not seem you do.
Re: Need help with random numbers... -
*BueNoOo* - 18.06.2009
Well I tried to make it as FS, but I failed and got a lot of errors
pawn Код:
C:\Users\mark\Desktop\Casino.pwn(107) : error 017: undefined symbol "strtok"
C:\Users\mark\Desktop\Casino.pwn(107) : error 033: array must be indexed (variable "cmd")
C:\Users\mark\Desktop\Casino.pwn(110) : error 017: undefined symbol "strtok"
C:\Users\mark\Desktop\Casino.pwn(110) : error 033: array must be indexed (variable "tmp")
C:\Users\mark\Desktop\Casino.pwn(111) : error 001: expected token: ")", but found "return"
C:\Users\mark\Desktop\Casino.pwn(111) : error 017: undefined symbol "COLOR_GREY"
C:\Users\mark\Desktop\Casino.pwn(114) : error 017: undefined symbol "PlayerToPoint"
C:\Users\mark\Desktop\Casino.pwn(124) : error 017: undefined symbol "COLOR_RED"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
8 Errors.
I didn't do anything with the script I just added those :
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
// define strtok stuff here, or use dcmd
new pLotto;
new RandNumber;
new cmd[256];
new tmp[256];
cmd = strtok(cmdtext, idx);
Before the command...
EDIT : Well ok i know how to fix these color errors and player to point , but what about the others ?
Re: Need help with random numbers... -
Grim_ - 18.06.2009
add this somewhere in your script past main()
pawn Код:
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
Re: Need help with random numbers... -
*BueNoOo* - 18.06.2009
OK I got it working

Now im gonna test it in game, thanks for your help guys I really appreciate it
Re: Need help with random numbers... -
Grim_ - 18.06.2009
new idx;
Re: Need help with random numbers... -
*BueNoOo* - 18.06.2009
Ok guys it works really good

Thanks for your help

I really aprreciate it. I learnt a lot
One last question, is it possible to add something like when the lottery stops on the number, it says on which. Like I mean the lottery stops at number 4, and it Sends a msg that the lottery has stopped at number 4 :P
That would be everything

Would be great if you guys can help with the last thing

Thanks
Re: Need help with random numbers... -
Vince - 18.06.2009
You mean like:
pawn Код:
new string[128];
format(string, sizeof(string), "The lottery has fallen on the number %d.", RandNumber);
SendClientMessage(playerid, COLOR_YELLOW, string);