Need help with random numbers...
#1

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 (
Reply
#2

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;
}
Reply
#3

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}
};
Reply
#4

With the code he posted, it does not seem you do.
Reply
#5

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 ?
Reply
#6

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;
}
Reply
#7

OK I got it working Now im gonna test it in game, thanks for your help guys I really appreciate it
Reply
#8

new idx;
Reply
#9

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
Reply
#10

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);
Reply


Forum Jump:


Users browsing this thread: