Gets max value
#1

Hi !

I want to make a bid system for houses.

So, when i start the bid, players will type /bid amount to bid for it.


I don't know how can I detect after 2 minutes which offered the highest amount for the bid.

I use
/bid amount, and variable:

PlayerInfo[playerid][pBidAmount] = amount;
Reply
#2

If you're only going to have 1 bid at any one time, you can create another player related variable that will determine which house is involved in the bidding. Then run a comparison with a for loop.

Код:
new miscarray[155], highest = 0, string[42];
for(new i; i < MAX_PLAYERS; i++
{
if(PlayerInfo[playerid][pBidAmount] > highest)
{
highest = PlayerInfo[playerid][pBidAmount];
GetPlayerName(i, string, sizeof(string));
}
}
format(miscarray, sizeof(miscarray), "%s has won the bid with %d", string, highest);
SendClientMessage(playerid, -1, miscarray);
That's the rough idea as to how you could approach that.
Reply
#3

Here:
PHP код:
new HighestBid,
      
BidLeader,
      
AuctionStarted;

forward BidTimer();

CMD:startauction(playerid)
{
     
AuctionStarted 1;
     
BidLeader = -1;
     
HighestBid= -1;
     
SetTimer("BidTimer"120000false); //Two minutes
     
SendClientMessage(playerid, -1"Auction has started! Use (/bid)");
     return 
1;
}

public 
BidTimer()
{
     
AuctionStarted 0;
     new 
string[128];
     
format(string128"The winner was ID %i with their bet of $%i"BidLeaderHighestBid);
     
SendClientMessageToAll(-1string);
     
//Do whatever you want with BidLeader as playerid.
}

CMD:bid(playeridparams[])
{
     if(
AuctionStarted != 1) return SendClientMessage(playerid, -1"There's not auction.");
     new 
bid;
     if(!
sscanf(params"i"bid))
     {
           if(
bid HighestBid)
           {
                
BidLeader playerid;
                
HighestBid bid;
           }
           else
           {
                new 
string[128];
                
format(string128"Sorry, you made a too low bid, current bid is: $%i by ID %i"HighestBidBidLeader);
                
SendClientMessage(playerid, -1string);
           }
     }
     else
          
SendClientMessage(playerid, -1"USAGE: /bid [value]");
     return 
1;

Not tested and wroten direct in web.
Reply
#4

hello , the variable must not create the enum of the player but the enum of the house :
Quote:

HouseInfo [ HouseID ] [ BidAmount ]
HouseInfo [ HouseID [ BidPlayer ]

then,

in function or cmd of the offer :
Quote:

if ( offer > HouseInfo [ HouseID ] [ BidAmount ] )
{
HouseInfo [ HouseID ] [ BidAmount ] = offer ;
HouseInfo [ HouseID ] [ BidPlayer ] = playerid ;
}

Timer :
Quote:

SetTimerEx ( " UpdateBidAmount " , 120000 , false , " d " , HouseID ) ;

I hope I was clear.
Reply
#5

Quote:
Originally Posted by Meller
Посмотреть сообщение
Here:
PHP код:
new HighestBid,
      
BidLeader,
      
AuctionStarted;
forward BidTimer();
CMD:startauction(playerid)
{
     
AuctionStarted 1;
     
BidLeader = -1;
     
HighestBid= -1;
     
SetTimer("BidTimer"120000false); //Two minutes
     
SendClientMessage(playerid, -1"Auction has started! Use (/bid)");
     return 
1;
}
public 
BidTimer()
{
     
AuctionStarted 0;
     new 
string[128];
     
format(string128"The winner was ID %i with their bet of $%i"BidLeaderHighestBid);
     
SendClientMessageToAll(-1string);
     
//Do whatever you want with BidLeader as playerid.
}
CMD:bid(playeridparams[])
{
     if(
AuctionStarted != 1) return SendClientMessage(playerid, -1"There's not auction.");
     new 
bid;
     if(!
sscanf(params"i"bid))
     {
           if(
bid HighestBid)
           {
                
BidLeader playerid;
                
HighestBid bid;
           }
           else
           {
                new 
string[128];
                
format(string128"Sorry, you made a too low bid, current bid is: $%i by ID %i"HighestBidBidLeader);
                
SendClientMessage(playerid, -1string);
           }
     }
     else
          
SendClientMessage(playerid, -1"USAGE: /bid [value]");
     return 
1;

Not tested and wroten direct in web.
Yes i know , but if a player bid and after he will be disconnected the auction will be failed.

I want to check somehow at final which is the winner.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)