Gets max value - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Gets max value (
/showthread.php?tid=610204)
Gets max value -
Nin9r - 21.06.2016
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;
Re: Gets max value -
XVlaDX - 21.06.2016
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.
Re: Gets max value -
Luicy. - 21.06.2016
Here:
PHP код:
new HighestBid,
BidLeader,
AuctionStarted;
forward BidTimer();
CMD:startauction(playerid)
{
AuctionStarted = 1;
BidLeader = -1;
HighestBid= -1;
SetTimer("BidTimer", 120000, false); //Two minutes
SendClientMessage(playerid, -1, "Auction has started! Use (/bid)");
return 1;
}
public BidTimer()
{
AuctionStarted = 0;
new string[128];
format(string, 128, "The winner was ID %i with their bet of $%i", BidLeader, HighestBid);
SendClientMessageToAll(-1, string);
//Do whatever you want with BidLeader as playerid.
}
CMD:bid(playerid, params[])
{
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(string, 128, "Sorry, you made a too low bid, current bid is: $%i by ID %i", HighestBid, BidLeader);
SendClientMessage(playerid, -1, string);
}
}
else
SendClientMessage(playerid, -1, "USAGE: /bid [value]");
return 1;
}
Not tested and wroten direct in web.
Re: Gets max value -
Captive - 21.06.2016
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.
Re: Gets max value -
Nin9r - 21.06.2016
Quote:
Originally Posted by Meller
Here:
PHP код:
new HighestBid,
BidLeader,
AuctionStarted;
forward BidTimer();
CMD:startauction(playerid)
{
AuctionStarted = 1;
BidLeader = -1;
HighestBid= -1;
SetTimer("BidTimer", 120000, false); //Two minutes
SendClientMessage(playerid, -1, "Auction has started! Use (/bid)");
return 1;
}
public BidTimer()
{
AuctionStarted = 0;
new string[128];
format(string, 128, "The winner was ID %i with their bet of $%i", BidLeader, HighestBid);
SendClientMessageToAll(-1, string);
//Do whatever you want with BidLeader as playerid.
}
CMD:bid(playerid, params[])
{
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(string, 128, "Sorry, you made a too low bid, current bid is: $%i by ID %i", HighestBid, BidLeader);
SendClientMessage(playerid, -1, string);
}
}
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.