Random Player select
#1

Hey all, I wanna create a script that will pick a random player from the server and give the player some money..


Can anyone give me a code?

Or an example.
Reply
#2

You can like create a timer that calls on game mode init and do like
pawn Код:
SetTimer("RandMoney,300000,1); // Calls the function every 3 minutes
Then do
pawn Код:
public RandMoney();
{
    GivePlayerMoney(random(MAX_PLAYERS),3000);
}
Correct me if I am wrong.
Reply
#3

Quote:
Originally Posted by Яσскѕтая
Посмотреть сообщение
You can like create a timer that calls on game mode init and do like
pawn Код:
SetTimer("RandMoney,300000,1); // Calls the function every 3 minutes
Then do
pawn Код:
public RandMoney();
{
    GivePlayerMoney(random(MAX_PLAYERS),3000);
}
Correct me if I am wrong.
I'll test it.
Reply
#4

pawn Код:
C:\Users\(lewis)\Desktop\New Folder (11)\ExStuntage.pwn(192) : error 055: start of function body without function header
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
I get an error.
Reply
#5

Don't forget to forward it at the top of your script
Код:
forward RandMoney();
Reply
#6

I believe that it won't work so well,since the size of MAX_PLAYERS is 200 or 500.And if there's one player in the server the chances that he will be chosen are very small. You can check how much players are online and then randomize between them and give one of them money.
Some thing like this:
pawn Код:
//Top of script
forward RandMoney();
new Players;

public OnGameModeInit()
{
    SetTimer("RandMoney,300000,1);
    return 1;
}

public OnPlayerConnect(playerid)
{
    Players++; //Adds one player to the variable every time a player joins
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    Players--; //Exactly the same as above but the opposite way.
    return 1;
}

public RandMoney()
{
    GivePlayerMoney(random(Players),3000);
}
Reply
#7

If he uses random(MAX_PLAYERS), it's like he uses random(500), so it could be that playerid 455, which is probably not online, receives the money o.O.
Top of the script:
pawn Код:
forward RandMoney();
Under GameModeInit:
pawn Код:
SetTimer("RandMoney", 30000, 1);
Somewhere in the script:
pawn Код:
public RandMoney()
{
      new PCount;
      for(new i; i<GetMaxPlayers(); i++)
      {
            if(IsPlayerConnected(i)) PCount++;
      }
      GivePlayerMoney(random(PCount), 3000);
}
Or like the guy over this post, who was faster xD ^^
Reply
#8

Okay but how can i make it like say


%s Has won $3000 in the lottery.
Reply
#9

Quote:
Originally Posted by Last_Stand_Guardian
Посмотреть сообщение
pawn Код:
public RandMoney()
{
      new PCount, String[50], Name[MAX_PLAYER_NAME];
      for(new i; i<GetMaxPlayers(); i++)
      {
            if(IsPlayerConnected(i)) PCount++;
      }
      new Winner = random(PCount);
      GetPlayerName(Winner, Name, MAX_PLAYER_NAME);
      format(String, 50, "%s has won $3000 in the lottery", Name);
      SendClientMessageToAll(COLOR, String);
      GivePlayerMoney(Winner, 3000);
}
It could look like this =D
Reply
#10

Quote:
Originally Posted by Last_Stand_Guardian
Посмотреть сообщение
It could look like this =D
Thanks alot dude.

I'll test.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)