How To : KO "Bounty" Tournaments

For general discussion of the Poker Mavens software
Tuck Fheman
Posts: 213
Joined: Tue Jul 04, 2017 6:44 am

How To : KO "Bounty" Tournaments

Post by Tuck Fheman »

Disclaimer: I'm not a developer and I'm new to PHP so my code is what they call naive, but it works. You would likely pay $150-$300 for some developer to do this for you (I did once before, then he ran off with everything), so it might be worth it to give it a shot yourself.

This is the dirty, "hey it works!" version, I'm sure you or someone else can vastly improve upon it with error checking and other features. This does not include a way to reward the winner of the tournament with their own bounty.

Step 1

Head over to the https://www.briggsoft.com/docs/pmavens/ ... m#callback for Poker Mavens and grab the Callback example code and create a file in your root folder called callback.php.

Step 2

Turn on Callback Events in the System tab of your Poker Mavens client. Next in the URL field, enter the URL to your callback.php file and a password below. Be sure to put the password you selected into the callback.php file itself where it indicates it should be at the top of the file.

Step 3

Turn on all the Callback Events you want, but you must turn on Tournament knockout event for this to work.

Step 4

Insert this code below, or your own modified version, into the callback.php file where you see case "TourneyKnockout":, just under fwrite($f,"\n");

case "TourneyKnockout":
fwrite($f,"Event = " . $event . "\n");
fwrite($f,"Name = " . $_POST["Name"] . "\n");
fwrite($f,"Table = " . $_POST["Table"] . "\n");
fwrite($f,"Player = " . $_POST["Player"] . "\n");
fwrite($f,"Bounty = " . $_POST["Bounty"] . "\n");
fwrite($f,"Hand = " . $_POST["Hand"] . "\n");
fwrite($f,"Time = " . $_POST["Time"] . "\n");
fwrite($f,"\n");

Code: Select all

   // assign vars
	  $TourneyName = $_POST["Name"];
	  $kodplayer = $_POST["Player"];
	  $BountyPlayer = $_POST["Bounty"];
	  // get tourney info
	  $params = array("Command" => "TournamentsGet", "Name" => $TourneyName);
	  $api = Poker_API($params);
	  $result = $api -> Result;
	  // get entry fee amount
	  $bountyamt = $api -> EntryFee;
	  // award the entryfee amount to the player who KO'd someone
	  $params = array("Command" => "AccountsIncBalance", "Player" => $BountyPlayer, "Amount" => $bountyamt);
	  $api = Poker_API($params);
	  $result = $api -> Result;
break;[/code]

That's it! You now have KO Tournaments by simply using the Entry Fee for a tournament as the Bounty on each player. Please keep in mind that if you use Entry Fee's on your site for other tournaments you will need to put in a way to distinguish between your KO tourneys and those you simply want to collect an entry fee on. Perhaps searching the Tourney Name for "KO" or "Knockout" and only running this if it's found.

Something else you can do is have a Discord Bot (Webhook) post to a channel when someone knocks someone else out and show the names, the tourney name and the Bounty won. I will post that code in another How To message since the Discord Bot can be used many different ways. That code will simply go directly below this code and before the break;.

If you are a Developer and you see that I've done something completely wrong or in a naive way that could be better, feel free to correct me ... I need to learn! ;)
Tuck Fheman
Posts: 213
Joined: Tue Jul 04, 2017 6:44 am

Re: How To : KO "Bounty" Tournaments

Post by Tuck Fheman »

Below is a variation on posting the results of a tournament in Discord with a webhook and only showing the Winner + how to give a Winner of a KO tournament their Bounty (Entry Fee) back. Also, StackOverlow.com is your friend. ;)

Code: Select all

// wait for file to be written to disk (optional)
sleep(10);
// find latest file .. enter your actual file path here	  
$path = "C:/TourneyResults"; 
$latest_ctime = 0;
$latest_filename = '';    

$d = dir($path);
while (false !== ($entry = $d->read())) {
 $filepath = "{$path}/{$entry}";
 if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
 $latest_ctime = filectime($filepath);
 $latest_filename = $entry;
 }
}


// post message in discord chan 
$getinfo = file_get_contents($path . "/" . $latest_filename);
// find the tourney number and get the Winner
preg_match_all("/Number=($TNumber).*?Place1=(.*?)\s/s", $getinfo, $info);
$Winner = $info[2][0];
$message = "**$TourneyName Results** \nTourney Number: $TNumber \nWinner: $Winner";
$data = ['content' => $message];
$options = [
			'http' => [
			'method' => 'POST',
			'header' => 'Content-Type: application/json',
			'content' => json_encode($data)
			]
		];
$context = stream_context_create($options);
$result = file_get_contents('https://discordapp.com/api/webhooks/YOURWEBHOOK', false, $context);
	
// if KO tourney give Winners bounty back - search for 'KO' in tourney name
if (strpos($TourneyName, 'KO') !== false) {
// get tourney info
  $params = array("Command" => "TournamentsGet", "Name" => $TourneyName);
  $api = Poker_API($params);
  $result = $api -> Result;
  // get entry fee amount
  $bountyamt = $api -> EntryFee;
  // Give the winner back their entryfee/bounty
  $params = array("Command" => "AccountsIncBalance", "Player" => $Winner, "Amount" => $bountyamt);
  $api = Poker_API($params);
  $result = $api -> Result;
}
social
Posts: 211
Joined: Fri Nov 20, 2009 12:23 am

Re: How To : KO "Bounty" Tournaments

Post by social »

Really surprised no appreciation has been shown for your efforts.
I don't visit here often any more,
but your contribution reminds me of the Spirit of Cooperation
which USED to exist here a long, long time ago.

Thank you for your efforts. :)
Tuck Fheman
Posts: 213
Joined: Tue Jul 04, 2017 6:44 am

Re: How To : KO "Bounty" Tournaments

Post by Tuck Fheman »

social wrote:Thank you for your efforts. :)
:D Thanks, I'll be posting more soon!
hxe
Posts: 71
Joined: Sat Apr 04, 2020 1:59 pm

Re: How To : KO "Bounty" Tournaments

Post by hxe »

Just wanted to say thanks as well.
I'm totally gonna rip off your code and use some of it.
hxe
Posts: 71
Joined: Sat Apr 04, 2020 1:59 pm

Re: How To : KO "Bounty" Tournaments

Post by hxe »

So I ripped off the code, made some changes to my environment and realized a few things.

1) Freezeouts only. If someone rebuys only their initial Entry Fee is part of the bounty since there's no callback for when someone gets "knocked out" but rebuys.
2) The code above only awards the bounties to people knocked out. The winner actually "loses" his bounty to the "EntryFee" account. It has to be either credited back manually or awarded through more code.
3) Speaking of which, I think the bounties get awarded out of the Master account and not the EntryFee account. If you use any of these for accuracy, it can get messed up.
4) If someone gets "double/triple/etc teamed" (aka 2+ players split a win vs the guy that's all in) the bounty doesn't get awarded properly and will have to be manually assigned.

I'm working on fixing anything I can, but I'm also not a PHP developer so my code is equally ugly.
I can't fix 1 at all due to the lack of callbacks for rebuys. 2 I can fix, but it's more work since there's no callback as to who the winner is of a tournament. Currently I have to "search" for the winner among multiple tournament due to how the file is written. 3 I actually planned for and "fixed" but didn't plan for 2 so it's still messed. 4 I have plans for fixing.

There's probably more stuff that's wonky or weird, but this is after one aborted tournament (because I didn't realize #1) and one completed tournament with a whole lot of looking through logs to see what happened.
Then I made a mistake and had to do a past 24 hour recollection to balance out someone I made a few mistakes with.

After more testing and a bit of shining up I'll post what I can in the coming weeks.
social
Posts: 211
Joined: Fri Nov 20, 2009 12:23 am

Re: How To : KO "Bounty" Tournaments

Post by social »

hxe wrote:So I ripped off the code, made some changes to my environment and realized a few things.

1) Freezeouts only. If someone rebuys only their initial Entry Fee is part of the bounty since there's no callback for when someone gets "knocked out" but rebuys.
2) The code above only awards the bounties to people knocked out. The winner actually "loses" his bounty to the "EntryFee" account. It has to be either credited back manually or awarded through more code.
3) Speaking of which, I think the bounties get awarded out of the Master account and not the EntryFee account. If you use any of these for accuracy, it can get messed up.
4) If someone gets "double/triple/etc teamed" (aka 2+ players split a win vs the guy that's all in) the bounty doesn't get awarded properly and will have to be manually assigned.

I'm working on fixing anything I can, but I'm also not a PHP developer so my code is equally ugly.
I can't fix 1 at all due to the lack of callbacks for rebuys. 2 I can fix, but it's more work since there's no callback as to who the winner is of a tournament. Currently I have to "search" for the winner among multiple tournament due to how the file is written. 3 I actually planned for and "fixed" but didn't plan for 2 so it's still messed. 4 I have plans for fixing.

There's probably more stuff that's wonky or weird, but this is after one aborted tournament (because I didn't realize #1) and one completed tournament with a whole lot of looking through logs to see what happened.
Then I made a mistake and had to do a past 24 hour recollection to balance out someone I made a few mistakes with.

After more testing and a bit of shining up I'll post what I can in the coming weeks.
Nice to see people trying to bring added value!
Thanks for your efforts.
MIGUEL.CHEHADE
Posts: 2
Joined: Thu Apr 02, 2020 9:49 am

Re: How To : KO "Bounty" Tournaments

Post by MIGUEL.CHEHADE »

Great news!!!!





hxe wrote:So I ripped off the code, made some changes to my environment and realized a few things.

1) Freezeouts only. If someone rebuys only their initial Entry Fee is part of the bounty since there's no callback for when someone gets "knocked out" but rebuys.
2) The code above only awards the bounties to people knocked out. The winner actually "loses" his bounty to the "EntryFee" account. It has to be either credited back manually or awarded through more code.
3) Speaking of which, I think the bounties get awarded out of the Master account and not the EntryFee account. If you use any of these for accuracy, it can get messed up.
4) If someone gets "double/triple/etc teamed" (aka 2+ players split a win vs the guy that's all in) the bounty doesn't get awarded properly and will have to be manually assigned.

I'm working on fixing anything I can, but I'm also not a PHP developer so my code is equally ugly.
I can't fix 1 at all due to the lack of callbacks for rebuys. 2 I can fix, but it's more work since there's no callback as to who the winner is of a tournament. Currently I have to "search" for the winner among multiple tournament due to how the file is written. 3 I actually planned for and "fixed" but didn't plan for 2 so it's still messed. 4 I have plans for fixing.

There's probably more stuff that's wonky or weird, but this is after one aborted tournament (because I didn't realize #1) and one completed tournament with a whole lot of looking through logs to see what happened.
Then I made a mistake and had to do a past 24 hour recollection to balance out someone I made a few mistakes with.

After more testing and a bit of shining up I'll post what I can in the coming weeks.
Tuck Fheman
Posts: 213
Joined: Tue Jul 04, 2017 6:44 am

Re: How To : KO "Bounty" Tournaments

Post by Tuck Fheman »

hxe wrote:So I ripped off the code, made some changes to my environment and realized a few things.
2) The code above only awards the bounties to people knocked out. The winner actually "loses" his bounty to the "EntryFee" account. It has to be either credited back manually or awarded through more code.
This should take care of that part : posting.php?mode=quote&f=7&p=12474#pr11850

Thanks!
Tuck Fheman
Posts: 213
Joined: Tue Jul 04, 2017 6:44 am

Re: How To : KO "Bounty" Tournaments

Post by Tuck Fheman »

hxe wrote:So I ripped off the code, made some changes to my environment and realized a few things.
2) The code above only awards the bounties to people knocked out. The winner actually "loses" his bounty to the "EntryFee" account. It has to be either credited back manually or awarded through more code.
Let me try that again. The code to credit the winner back their entry fee is posted above, but here it is again.

Code: Select all

   
// if KO tourney give Winners bounty back - search for 'KO' in tourney name
if (strpos($TourneyName, 'KO') !== false) {
// get tourney info
  $params = array("Command" => "TournamentsGet", "Name" => $TourneyName);
  $api = Poker_API($params);
  $result = $api -> Result;
  // get entry fee amount
  $bountyamt = $api -> EntryFee;
  // Give the winner back their entryfee/bounty
  $params = array("Command" => "AccountsIncBalance", "Player" => $Winner, "Amount" => $bountyamt);
  $api = Poker_API($params);
  $result = $api -> Result;

Post Reply