[Xaseco 1+2] Pay2Play plugin

Discuss everything about Xymph's Aseco flavoured server control scripts for TM Forever / classic TMN and for TM² Canyon.

Moderators: Xymph, TM-Patrol

User avatar
Leigham
happy cruiser
happy cruiser
Posts: 139
Joined: 26 Mar 2011 01:04
Owned TM-games: TMUF, TMNF, TM²
Manialink(s): None

Re: [Xaseco 1+2] Pay2Play plugin

Post by Leigham » 28 Nov 2013 20:23

Yours has one too few brackets on the edited line

Code: Select all

if ($p2p['skip']['active']) == true && $p2p['replay']['total'] == 0) {
but if you tried my version too then I don't see how that would be the problem. Also line 14 really has nothing to do with anything, so that's odd too. Here's my full plugin, just in case it works but I'm not expecting it to be that easy at this point.

Code: Select all

<?php

/* Pay2Play v1.01andabit
 *
 * Plugin by Leigham.
 *
 * Important: This plugin will only work on a TM2 server. 
 * The server must have at least a small amount of planets for
 * the plugin to work.
 *
 * All settings are configurable in the pay2play.xml file.
 */

Aseco::registerEvent('onStartup',                   'p2p_setup');
Aseco::registerEvent('onSync',                      'p2p_maintain');
Aseco::registerEvent('onPlayerConnect',             'p2p_connect');
Aseco::registerEvent('onBeginMap',                  'p2p_check');
Aseco::registerEvent('onBeginRound',                'p2p_check');
Aseco::registerEvent('onEndRound',									'p2p_off');
Aseco::registerEvent('onPlayerManialinkPageAnswer', 'p2p_click');
Aseco::registerEvent('onBillUpdated',               'p2p_bill');
Aseco::registerEvent('onEverySecond',               'p2p_time');
Aseco::registerEvent('onShutdown',									'p2p_apocalypse');


function p2p_setup($aseco) { //Read pay2play.xml and load settings
	global $p2p;
	
	$p2p = array();
	$votes = array();
	
	if ($config = $aseco->xml_parser->parseXml('pay2play.xml', true)) {
    $config = $config['SETTINGS'];
    
    if (strtolower($config['REPLAY'][0]['ENABLED'][0]) == 'true') {
    	$p2p['replay']['active'] = true;
    	$p2p['replay']['position'] = floatval($config['REPLAY'][0]['POSX'][0]).' '.floatval($config['REPLAY'][0]['POSY'][0]).' 1';
    	$p2p['replay']['cost'] = intval($config['REPLAY'][0]['COST'][0]);
    	$p2p['replay']['max_val'] = intval($config['REPLAY'][0]['MAX_REPLAYS'][0]);
    	$p2p['replay']['blink'] = ((strtolower($config['REPLAY'][0]['BLINK'][0]) == 'true') ? true : false);
			if ($config['REPLAY'][0]['CVOTE_OFF'][0] == 'true') $votes[] = array('Command'	=> 'RestartMap', 'Ratio' => (float)-1);
    	$p2p['replay']['total'] = 0;
    	$p2p['replay']['success'] = false;
    	$p2p['replay']['max'] = false;
    } else {
    	$p2p['replay']['active'] = false;
    } 
    
    if (strtolower($config['SKIP'][0]['ENABLED'][0]) == 'true') {
    	$p2p['skip']['active'] = true;
    	$p2p['skip']['position'] =floatval($config['SKIP'][0]['POSX'][0]).' '.floatval($config['SKIP'][0]['POSY'][0]).' 1';
    	$p2p['skip']['cost'] = intval($config['SKIP'][0]['COST'][0]);
    	$p2p['skip']['delay'] = intval($config['SKIP'][0]['DELAY'][0]);
    	$p2p['skip']['blink'] = ((strtolower($config['SKIP'][0]['BLINK'][0]) == 'true') ? true : false);
    	if ($config['REPLAY'][0]['CVOTE_OFF'][0] == 'true') $votes[] = array('Command'	=> 'NextMap', 'Ratio' => (float)-1);
    	$p2p['skip']['success'] = false;
    } else {
    	$p2p['skip']['active'] = false;
    }
    
    $p2p['score'] = false;
    $p2p['manialink'] = '12891';
    $p2p['thismap'] = array();
    $p2p['bills'] = array();
    $p2p['timelimit'] = -1;
    
    if (isset($votes[0])) {
    	$aseco->client->query('GetCallVoteRatios');
			$p2p['oldvotes'] = $aseco->client->getResponse();
			$aseco->client->query('SetCallVoteRatios', $votes);
		}
  
	} else {
		trigger_error('[Pay2Play] Could not read/parse settings file pay2play.xml!', E_USER_ERROR);
		return false;
	}
}

function p2p_maintain($aseco) { 	// Do maintenance checks
	global $p2p;
	
  $aseco->plugin_versions[] = array(
     'plugin'   => 'plugin.pay2play.php',
     'author'   => 'Leigham',
     'version'   => '1.01'
  );
  
  if (!in_array('plugin.rasp_jukebox.php', $aseco->plugins)) {
  	trigger_error('[Pay2Play] This plugin requires the rasp jukebox. Please activate "plugin.rasp_jukebox.php" in your plugins.xml file!', E_USER_ERROR);
  }
}

function p2p_connect($aseco) { //Deal with new player
	global $p2p;
	
	if (!$p2p['score']) {
		if ($p2p['replay']['active']) {
			if (!$p2p['replay']['success']){
				if (!$p2p['replay']['max']) {
					p2p_buildReplay($aseco);
				} else {
					p2p_buildReplay($aseco, 'max');
				}
			} else {
				p2p_buildReplay($aseco, 'success');
			}
		}
		if ($p2p['skip']['active']) {
			if (!$p2p['skip']['success']) {	
				p2p_buildSkip($aseco);
			} else {
				p2p_buildSkip($aseco, 'success');
			}
		}
	}
}

function p2p_check($aseco) { //Check map and load widgets
	global $p2p;
	
	$p2p['score'] = false;
	
	if ($p2p['replay']['active']) {
		$aseco->client->query('GetCurrentMapInfo');
		$thismap = $aseco->client->getResponse();

		if (isset($p2p['thismap']['FileName']) && $p2p['thismap']['FileName'] == $thismap['FileName']) {
			
			if ($p2p['replay']['total'] >= $p2p['replay']['max_val'] && $p2p['replay']['max_val'] != 0) {
				$p2p['replay']['max'] = true;
				p2p_buildReplay($aseco, 'max'); 
			} else {
				p2p_buildReplay($aseco);
				$p2p['replay']['max'] = false;
			}
		} else {
			$p2p['replay']['total'] = 0;
			$p2p['replay']['max'] = false;
			p2p_buildReplay($aseco);
		}
		$p2p['thismap'] = $thismap;
	}
	if ($p2p['skip']['active'] == true && $p2p['replay']['total'] == 0) {
		p2p_buildSkip($aseco);
	}
	$p2p['timelimit'] = time() + ($aseco->server->gameinfo->timelimit / 1000);
}

function p2p_off($aseco) { //Close widgets and reset variables
	global $p2p;
	
	$p2p['replay']['success'] = false;
	$p2p['skip']['success'] = false;
	$p2p['score'] = true;
	
	$xml = '<manialink id="'.$p2p['manialink'].'00">
	</manialink> <manialink id="'.$p2p['manialink'].'01">
	</manialink>';
		
	$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
}

function p2p_buildReplay($aseco, $state = false) { //Build replay widget
	global $p2p;
	
	if ($state == 'success') {
		
		if ($p2p['replay']['blink']) {
			$a = array('style="TextTitle2Blink"', 0.5, 0.35, '$ccc', '$c90', 7);
		} else {
			$a = array('', 0.9, 0.55, '', '', 4.5);
		}
		
		$xml = '<manialink id="'.$p2p['manialink'].'00">
   	 <frame posn="'.$p2p['replay']['position'].'">
   	    <quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem"/>
   	    <label posn="2.25 -0.75 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" scale="'.$a[1].'" textcolor="FFFF" text="'.$a[3].'MAP"/>
   	    <label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" scale="'.$a[2].'" textcolor="FC0F" text="'.$a[4].'WILL BE"/>
   	    <label posn="2.25 -3.55 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" scale="'.$a[1].'" textcolor="FFFF" text="'.$a[3].'REPLAYED"/>
   	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" scale="'.$a[2].'" textcolor="FC0F" text="'.$a[4].'NEXT!"/>
   		</frame>
		</manialink>';
		
	} elseif ($state == 'max') {
		
		$xml = '<manialink id="'.$p2p['manialink'].'00">
   	 	<frame posn="'.$p2p['replay']['position'].'">
        <quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem"/>
        <label posn="2.25 -0.75 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="MAXIMUM"/>
        <label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="REPLAY"/>
        <label posn="2.25 -3.55 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="LIMIT"/>
        <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="REACHED!"/>
    	</frame>
		</manialink>';
			
	} else {
	
		$xml = '<manialink id="'.$p2p['manialink'].'00">
  	  <frame posn="'.$p2p['replay']['position'].'">
  	    <quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem" action="'.$p2p['manialink'].'|replay"/>
  	    <label posn="2.25 -0.75 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="PAY '.$p2p['replay']['cost'].'"/>
   	    <label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="PLANETS"/>
   	    <label posn="2.25 -3.55 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="FOR"/>
   	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="REPLAY"/>
   	 </frame>
		</manialink>';
	}
	$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
}

function p2p_buildSkip($aseco, $state = false) { //Build skip widget
	global $p2p;
	
	if ($state == 'success') {
		
		if ($p2p['skip']['blink']) {
			$a = array('style="TextTitle2Blink"', 0.5, 0.35, '$ccc', '$c90', 7);
		} else {
			$a = array('', 0.9, 0.6, '', '', 5);
		}
		
		$xml = '<manialink id="'.$p2p['manialink'].'01">
 		  <frame posn="'.$p2p['skip']['position'].'">
				<quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem"/>
	      <label posn="2.25 -0.75 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'MAP"/>
				<label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'WILL BE"/>
				<label posn="2.25 -3.55 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'SKIPPED"/>
 	 	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'SHORTLY!"/>
 			</frame>
		</manialink>';
		
	} else {
	
		$xml = '<manialink id="'.$p2p['manialink'].'01">
 		  <frame posn="'.$p2p['skip']['position'].'">
	      <quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem" action="'.$p2p['manialink'].'|skip"/>
	      <label posn="2.25 -0.75 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="PAY '.$p2p['skip']['cost'].'"/>
 	 	    <label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="PLANETS"/>
 	 	    <label posn="2.25 -3.55 0.1" sizen="5 2" halign="center"  textsize="1" scale="0.9" textcolor="FFFF" text="FOR"/>
 	 	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center"  textsize="1" scale="0.6" textcolor="FC0F" text="SKIP"/>
 	 		</frame>
		</manialink>';
	}
	$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
}

function p2p_click($aseco, $command) {  //Deal with button clicks
	global $p2p;
	
	$login = $command[1];
	$answer = $command[2];
	$aseco->client->query('GetDetailedPlayerInfo', $login);
	$player = $aseco->client->getResponse();
	$nickname = $player['NickName'];
	
	if ($answer == $p2p['manialink'].'|replay') {
		$aseco->client->query('GetNextMapInfo');
		$nextmap = $aseco->client->getResponse();
		if ($p2p['thismap']['FileName'] != $nextmap['FileName']) {
			$message = 'You need to pay '.$p2p['replay']['cost'].' planets to replay this map';
			$aseco->client->query('SendBill', $login, $p2p['replay']['cost'], $message, '');
			$id = $aseco->client->getResponse();
			$p2p['bills'][$id] = array($login, $nickname, 'replay');
		} else {
			$message = '>$f00 This track is already being replayed';
			$aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
		}
	} elseif ($answer == $p2p['manialink'].'|skip') {
		if ($p2p['timelimit'] >= $p2p['skip']['delay'] + time() + 10) {
			$message = 'You need to pay '.$p2p['skip']['cost'].' planets to skip this map';
			$aseco->client->query('SendBill', $login, $p2p['skip']['cost'], $message, '');
			$id = $aseco->client->getResponse();
			$p2p['bills'][$id] = array($login, $nickname, 'skip');
		} else {
			$message = '>$f00 This track will end before your action can be completed, please be patient.';
			$aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
		}
	}
}

function p2p_bill($aseco, $bill) {  //Deal with bill payments
	global $p2p, $jukebox, $atl_restart;
	$id = $bill[0];
	// check for known bill ID
	if (array_key_exists($id, $p2p['bills'])) {
		// get bill info
		$login = $p2p['bills'][$id][0];
		$nickname = $p2p['bills'][$id][1];
		$state = $p2p['bills'][$id][2];
		$planets = $p2p[$state]['cost'];
		
		if ($state == 'replay') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				if (!$p2p['score']) {
					$uid = $aseco->server->map->uid;
					$jukebox = array_reverse($jukebox, true);
					$jukebox[$uid]['FileName'] = $aseco->server->map->filename;
					$jukebox[$uid]['Name'] = $aseco->server->map->name;
					$jukebox[$uid]['Env'] = $aseco->server->map->environment;
					$jukebox[$uid]['Login'] = $login;
					$jukebox[$uid]['Nick'] = $nickname;
					$jukebox[$uid]['source'] = 'Pay2Play';
					$jukebox[$uid]['mx'] = false;
					$jukebox[$uid]['uid'] = $uid;
					$jukebox = array_reverse($jukebox, true);
					$aseco->releaseEvent('onJukeboxChanged', array('replay', $jukebox[$uid]));
				} else {
					if (isset($atl_restart)) $atl_restart = true;
					$aseco->client->query('RestartMap');
				}				
				$message = '$s$f90Player $z$s'.$nickname.'$z$s$f90  pays '.$planets.' planets and queues map for replay!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} planets to replay the current track', $login, $planets);
				unset($p2p['bills'][$id]);
				$p2p['replay']['success'] = true;
				$p2p['replay']['total']++;
				if (!$p2p['score']) {
					p2p_buildReplay($aseco, 'success');
				}
				break;
			case 5:  // Refused
				$message = '{#server}> {#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}> {#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		} elseif ($state == 'skip') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				$time = time() + $p2p['skip']['delay'];
				$p2p['time']['skip'] = $time;
				$message = '$s$f90Player $z$s'.$nickname.'$z$s$f90  pays '.$planets.' planets. Map will be skipped shortly!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} planets to skip the current track', $login, $planets);
				unset($p2p['bills'][$id]);
				$p2p['skip']['success'] = true;
				p2p_buildSkip($aseco, 'success');
				break;
			case 5:  // Refused
				$message = '{#server}> {#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}> {#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		}		
	}
}

function p2p_time($aseco) { //Deal with time functions
	global $p2p;
	
	if (isset($p2p['time']['skip'])) {
		$time = time();
		
		if ($time >= $p2p['time']['skip']) {
			// load the next map
			// don't clear scores if in Cup mode
			if ($aseco->server->gameinfo->mode == 5)
				$aseco->client->query('NextMap', true);
			else
				$aseco->client->query('NextMap');
			unset($p2p['time']['skip']);
		}
	}
}

function p2p_apocalypse($aseco) { //Restore altered callvotes
	global $p2p;
	
	$aseco->client->query('SetCallVoteRatios', $p2p['oldvotes']);
}
		
?>
"Never surrender, sometimes retreat"

Image

Scottish Flat Trax servers

soluto
pedestrian
pedestrian
Posts: 7
Joined: 27 Nov 2013 11:31
Owned TM-games: TMU

Re: [Xaseco 1+2] Pay2Play plugin

Post by soluto » 29 Nov 2013 14:27

i fund the error -.-

its the other server-admin -.-

i dont know what he changed, but after i uploaded the plugin again and close his acc its work . thanks fpr the big help :)

PS: Another good idea for a Plugin i think is "pay2vote" ???
example:
player pay 200 to start a skip or replay vote. if the vote is succesful and the map will be skip or replay. the server keep the 200 planets. if the vote is not succesful the server give the player 3/4 back thats 150 and keep the other 50 planets in my example ;)

ok i think its hard to script but i thinks its possible :)

THATS NOT A REQUEST ONLY A IDEA

User avatar
Leigham
happy cruiser
happy cruiser
Posts: 139
Joined: 26 Mar 2011 01:04
Owned TM-games: TMUF, TMNF, TM²
Manialink(s): None

Re: [Xaseco 1+2] Pay2Play plugin

Post by Leigham » 29 Nov 2013 18:04

soluto wrote:i fund the error -.-

its the other server-admin -.-

i dont know what he changed, but after i uploaded the plugin again and close his acc its work . thanks fpr the big help :)
Glad it works :)
soluto wrote: PS: Another good idea for a Plugin i think is "pay2vote" ???
example:
player pay 200 to start a skip or replay vote. if the vote is succesful and the map will be skip or replay. the server keep the 200 planets. if the vote is not succesful the server give the player 3/4 back thats 150 and keep the other 50 planets in my example ;)
Sounds like a good idea, although since I barely have the time to fix my own plugins, I doubt I'll be launching any new ones for a while.
"Never surrender, sometimes retreat"

Image

Scottish Flat Trax servers

User avatar
L3cKy
happy cruiser
happy cruiser
Posts: 138
Joined: 05 Sep 2007 13:55
Owned TM-games: TMUF
Manialink(s): woa
Location: Sweden
Contact:

Re: [Xaseco 1+2] Pay2Play plugin

Post by L3cKy » 12 May 2017 00:25

For XASECO V1

Hej hej ... i added a little function to prevent players to skip a track after a player payed for it. (if a player pay's for a replay and the track gets replayed no one cant pay anymore for a skip while the track is replayed)

1. change the following code ->

Code: Select all

function p2p_connect($aseco) { //Deal with new player
	global $p2p;
	if (!$p2p['score']) {
		if ($p2p['replay']['active']) {
			if (!$p2p['replay']['success']){
				if (!$p2p['replay']['max']) {
					p2p_buildReplay($aseco);
				} else {
					p2p_buildReplay($aseco, 'max');
				}
			} else {
				p2p_buildReplay($aseco, 'success');
			}
		}
		if ($p2p['skip']['active']) {
			if (!$p2p['skip']['success']) {
				p2p_buildSkip($aseco);
			} else {
				p2p_buildSkip($aseco, 'success');
			}
		}
	}
}
into this code ->

Code: Select all

function p2p_connect($aseco) { //Deal with new player
	global $p2p;
	if (!$p2p['score']) {
		if ($p2p['replay']['active']) {
			if (!$p2p['replay']['success']){
				if (!$p2p['replay']['max']) {
					p2p_buildReplay($aseco);
				} else {
					p2p_buildReplay($aseco, 'max');
				}
			} else {
				p2p_buildReplay($aseco, 'success');
			}
		}
		if ($p2p['skip']['active']) {
    		if ($p2p['replay']['total'] >= 1) {
				p2p_buildSkip_replay($aseco, 'replay');
    		} elseif (!$p2p['skip']['success']) {
				p2p_buildSkip($aseco);
			} else {
				p2p_buildSkip($aseco, 'success');
			}
		}
	}
}
2. change the next following code ->

Code: Select all

function p2p_check($aseco) { //Check track and load widgets
	global $p2p;
	$p2p['score'] = false;
	if ($p2p['replay']['active']) {
		$aseco->client->query('GetCurrentChallengeInfo');
		$thistrack = $aseco->client->getResponse();
		if (isset($p2p['thistrack']['FileName']) && $p2p['thistrack']['FileName'] == $thistrack['FileName']) {

			if ($p2p['replay']['total'] >= $p2p['replay']['max_val'] && $p2p['replay']['max_val'] != 0) {
				$p2p['replay']['max'] = true;
				p2p_buildReplay($aseco, 'max');
			} else {
				p2p_buildReplay($aseco);
				$p2p['replay']['max'] = false;
			}
		} else {
			$p2p['replay']['total'] = 0;
			$p2p['replay']['max'] = false;
			p2p_buildReplay($aseco);
		}
		$p2p['thistrack'] = $thistrack;
	}
	if ($p2p['skip']['active']) {
		p2p_buildSkip($aseco);
	}
	$p2p['timelimit'] = time() + ($aseco->server->gameinfo->timelimit / 1000);
}
into this code ->

Code: Select all

function p2p_check($aseco) { //Check track and load widgets
	global $p2p;
	$p2p['score'] = false;
	if ($p2p['replay']['active']) {
		$aseco->client->query('GetCurrentChallengeInfo');
		$thistrack = $aseco->client->getResponse();
		if (isset($p2p['thistrack']['FileName']) && $p2p['thistrack']['FileName'] == $thistrack['FileName']) {
			if ($p2p['replay']['total'] >= $p2p['replay']['max_val'] && $p2p['replay']['max_val'] != 0) {
				$p2p['replay']['max'] = true;
				p2p_buildReplay($aseco, 'max');
			} else {
				p2p_buildReplay($aseco);
				$p2p['replay']['max'] = false;
			}
		} else {
			$p2p['replay']['total'] = 0;
			$p2p['replay']['max'] = false;
			p2p_buildReplay($aseco);
		}
		$p2p['thistrack'] = $thistrack;
	}
	if ($p2p['skip']['active']) {
    	if ($p2p['replay']['total'] >= 1) {
			p2p_buildSkip_replay($aseco, 'replay');
    	} else {
			p2p_buildSkip($aseco);
		}
	}
	$p2p['timelimit'] = time() + ($aseco->server->gameinfo->timelimit / 1000);
}
3. at least add after "function p2p_buildReplay($aseco, $state = false) {}" (not inside the function ... a new one ^^) follwoing code ->

Code: Select all

function p2p_buildSkip_replay($aseco, $state = false) { //Build skip widget
	global $p2p;

	if ($state == 'replay') {
	$a = array('style="TextTitle2Blink"', 0.5, 0.35, '$ccc', '$c90', 7);
		$xml = '<manialink id="'.$p2p['manialink'].'01">
 		  <frame posn="'.$p2p['skip']['position'].'">
				<quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem"/>
	      <label posn="2.25 -0.75 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'No"/>
				<label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'Skip"/>
				<label posn="2.25 -3.55 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'while"/>
 	 	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'Replay!"/>
 			</frame>
		</manialink>';
	$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
	}
}
Last edited by L3cKy on 20 May 2017 00:07, edited 2 times in total.

User avatar
Leigham
happy cruiser
happy cruiser
Posts: 139
Joined: 26 Mar 2011 01:04
Owned TM-games: TMUF, TMNF, TM²
Manialink(s): None

Re: [Xaseco 1+2] Pay2Play plugin

Post by Leigham » 12 May 2017 06:47

L3cKy wrote:Hej hej ... i added a little function to prevent players to skip a track after a player payed for it. (if a player pay's for a replay and the track gets replayed no one cant pay anymore for a skip while the track is replayed)
That's an excellent idea. Thanks!
"Never surrender, sometimes retreat"

Image

Scottish Flat Trax servers

User avatar
L3cKy
happy cruiser
happy cruiser
Posts: 138
Joined: 05 Sep 2007 13:55
Owned TM-games: TMUF
Manialink(s): woa
Location: Sweden
Contact:

Re: [Xaseco 1+2] Pay2Play plugin

Post by L3cKy » 12 May 2017 06:57

Another idea ive added is that the cost for a replay is raising with every replay ... in this case 3 times ...
But it is still beta ... need to include it also in the xml file ...

Code: Select all

function p2p_check($aseco) { //Check track and load widgets
	global $p2p;
	$p2p['score'] = false;
	if ($p2p['replay']['active']) {
		$aseco->client->query('GetCurrentChallengeInfo');
		$thistrack = $aseco->client->getResponse();
		if (isset($p2p['thistrack']['FileName']) && $p2p['thistrack']['FileName'] == $thistrack['FileName']) {
			if ($p2p['replay']['total'] >= $p2p['replay']['max_val'] && $p2p['replay']['max_val'] != 0) {
				$p2p['replay']['max'] = true;
				p2p_buildReplay($aseco, 'max');
			} else {
    			if ($p2p['replay']['total'] == 0) {
    				$p2p['replay']['cost'] =  75;
    			} elseif ($p2p['replay']['total'] == 1) {
    				$p2p['replay']['cost'] = 150;
    			} elseif ($p2p['replay']['total'] == 2) {
    				$p2p['replay']['cost'] = 300;
    			}
				p2p_buildReplay($aseco);
				$p2p['replay']['max'] = false;
			}
		} else {
			$p2p['replay']['total'] = 0;
			$p2p['replay']['max'] = false;
			p2p_buildReplay($aseco);
		}
		$p2p['thistrack'] = $thistrack;
	}
	if ($p2p['skip']['active']) {
    	if ($p2p['replay']['total'] == 1) {
			p2p_buildSkip_replay($aseco, 'replay');
    	} elseif ($p2p['replay']['total'] == 2) {
    		p2p_buildSkip_replay($aseco, 'replay');
		} else {
			p2p_buildSkip($aseco);
		}
	}
	$p2p['timelimit'] = time() + ($aseco->server->gameinfo->timelimit / 1000);
}

User avatar
L3cKy
happy cruiser
happy cruiser
Posts: 138
Joined: 05 Sep 2007 13:55
Owned TM-games: TMUF
Manialink(s): woa
Location: Sweden
Contact:

Re: [Xaseco 1+2] Pay2Play plugin

Post by L3cKy » 20 May 2017 00:16

And another Idea :)

Disabling the Replay Button if someone payed for a Skip.

Change following code ->

Code: Select all

function p2p_bill($aseco, $bill) {  //Deal with bill payments
	global $p2p, $jukebox, $atl_restart;
	$id = $bill[0];
	// check for known bill ID
	if (array_key_exists($id, $p2p['bills'])) {
		// get bill info
		$login = $p2p['bills'][$id][0];
		$nickname = $p2p['bills'][$id][1];
		$state = $p2p['bills'][$id][2];
		$coppers = $p2p[$state]['cost'];

		if ($state == 'replay') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				if (!$p2p['score']) {
					$uid = $aseco->server->challenge->uid;
					$jukebox = array_reverse($jukebox, true);
					$jukebox[$uid]['FileName'] = $aseco->server->challenge->filename;
					$jukebox[$uid]['Name'] = $aseco->server->challenge->name;
					$jukebox[$uid]['Env'] = $aseco->server->challenge->environment;
					$jukebox[$uid]['Login'] = $login;
					$jukebox[$uid]['Nick'] = $nickname;
					$jukebox[$uid]['source'] = 'Pay2Play';
					$jukebox[$uid]['tmx'] = false;
					$jukebox[$uid]['uid'] = $uid;
					$jukebox = array_reverse($jukebox, true);
					$aseco->releaseEvent('onJukeboxChanged', array('replay', $jukebox[$uid]));
				} else {
					if (isset($atl_restart)) $atl_restart = true;
					$aseco->client->query('ChallengeRestart');
				}
				$message = '$s$f90Player $z$s'.$nickname.'$z$s$f90  pays '.$coppers.' coppers and queues track for replay!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} coppers to replay the current track', $login, $coppers);
				unset($p2p['bills'][$id]);
				$p2p['replay']['success'] = true;
				$p2p['replay']['total']++;
				if (!$p2p['score']) {
					p2p_buildReplay($aseco, 'success');
				}
				break;
			case 5:  // Refused
				$message = '{#server}> {#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}> {#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		} elseif ($state == 'skip') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				$time = time() + $p2p['skip']['delay'];
				$p2p['time']['skip'] = $time;
				$message = '$s$f90Player $z$s'.$nickname.'$z$s$f90  pays '.$coppers.' coppers. Track will be skipped shortly!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} coppers to skip the current track', $login, $coppers);
				unset($p2p['bills'][$id]);
				$p2p['skip']['success'] = true;
				p2p_buildSkip($aseco, 'success');
				break;
			case 5:  // Refused
				$message = '{#server}> {#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}> {#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		}
	}
}
Into this code ->

Code: Select all

function p2p_bill($aseco, $bill) {  //Deal with bill payments
	global $p2p, $jukebox, $atl_restart;
	$id = $bill[0];
	// check for known bill ID
	if (array_key_exists($id, $p2p['bills'])) {
		// get bill info
		$login = $p2p['bills'][$id][0];
		$nickname = $p2p['bills'][$id][1];
		$state = $p2p['bills'][$id][2];
		$coppers = $p2p[$state]['cost'];

		if ($state == 'replay') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				if (!$p2p['score']) {
					$uid = $aseco->server->challenge->uid;
					$jukebox = array_reverse($jukebox, true);
					$jukebox[$uid]['FileName'] = $aseco->server->challenge->filename;
					$jukebox[$uid]['Name'] = $aseco->server->challenge->name;
					$jukebox[$uid]['Env'] = $aseco->server->challenge->environment;
					$jukebox[$uid]['Login'] = $login;
					$jukebox[$uid]['Nick'] = $nickname;
					$jukebox[$uid]['source'] = 'Pay2Play';
					$jukebox[$uid]['tmx'] = false;
					$jukebox[$uid]['uid'] = $uid;
					$jukebox = array_reverse($jukebox, true);
					$aseco->releaseEvent('onJukeboxChanged', array('replay', $jukebox[$uid]));
				} else {
					if (isset($atl_restart)) $atl_restart = true;
					$aseco->client->query('ChallengeRestart');
				}
				$message = '$z$s'.$nickname.'$z$s$f90  pays '.$coppers.' coppers and queues track for replay!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} coppers to replay the current track', $login, $coppers);
				unset($p2p['bills'][$id]);
				$p2p['replay']['success'] = true;
				$p2p['replay']['total']++;
				if (!$p2p['score']) {
					p2p_buildReplay($aseco, 'success');
				}
				break;
			case 5:  // Refused
				$message = '{#server}{#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}{#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		} elseif ($state == 'skip') {
				// check bill state
			switch($bill[1]) {
			case 4:  // Payed (Paid)
				$time = time() + $p2p['skip']['delay'];
				$p2p['time']['skip'] = $time;
				$message = '$z$s'.$nickname.'$z$s$f90  pays '.$coppers.' coppers. Track will be skipped shortly!';
				$aseco->client->query('ChatSendServerMessage', $message);
				$aseco->console('Player {1} paid {2} coppers to skip the current track', $login, $coppers);
				unset($p2p['bills'][$id]);
				$p2p['skip']['success'] = true;
				p2p_buildSkip($aseco, 'success');
				$xml = '<manialink id="'.$p2p['manialink'].'00"></manialink>';
				$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
				p2p_buildReplay_skip($aseco, 'skip');
				break;
			case 5:  // Refused
				$message = '{#server}{#error}Transaction refused!';
				$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				unset($p2p['bills'][$id]);
				break;
			case 6:  // Error
				$message = '{#server}{#error}Transaction failed: {#highlite}$i ' . $bill[2];
				if ($login != '')
					$aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
				else
					$aseco->client->query('ChatSendServerMessage', $aseco->formatColors($message));
				unset($p2p['bills'][$id]);
				break;
			default:  // CreatingTransaction/Issued/ValidatingPay(e)ment
				break;
			}
		}
	}
}
Add following code UNDER "function p2p_buildSkip(){}"

Code: Select all

function p2p_buildReplay_skip($aseco, $state = false) { //Build skip replay widget
	global $p2p;

	if ($state == 'skip') {

		if ($p2p['skip']['blink']) {
			$a = array('style="TextTitle2Blink"', 0.5, 0.35, '$ccc', '$c90', 7);
		} else {
			$a = array('', 0.9, 0.6, '', '', 5);
		}

	$a = array('style="TextTitle2Blink"', 0.5, 0.35, '$ccc', '$c90', 7);
		$xml = '<manialink id="'.$p2p['manialink'].'00">
 		  <frame posn="'.$p2p['replay']['position'].'">
				<quad posn="0 0 0" sizen="4.6 6.5" style="BgsPlayerCard" substyle="BgCardSystem"/>
	      <label posn="2.25 -0.75 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'NO"/>
				<label posn="2.25 -2.3 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'REPLAY"/>
				<label posn="2.25 -3.55 0.1" sizen="'.$a[5].' 2" halign="center" '.$a[0].' textsize="1" textcolor="FFFF" scale="'.$a[1].'" text="'.$a[3].'WHILE"/>
 	 	    <label posn="2.25 -5 0.1" sizen="8.4 2" halign="center" '.$a[0].' textsize="1" textcolor="FCOF" scale="'.$a[2].'" text="'.$a[4].'SKIP!"/>
 			</frame>
		</manialink>';
	$aseco->client->addCall('SendDisplayManialinkPage', array($xml, 0, false));
	}
}
Greetings

speedychris
wheelbarrow operator
wheelbarrow operator
Posts: 19
Joined: 12 Mar 2013 09:58
Owned TM-games: TMU, TM2

Re: [Xaseco 1+2] Pay2Play plugin

Post by speedychris » 09 Jun 2017 08:12

Unfortunately this very useful plugin does not work correct on uaseco (widget disappears after 2 rounds). Is there a fixed version possible?

User avatar
undef.de
Pit Crew
Pit Crew
Posts: 1309
Joined: 31 Aug 2009 18:38
Owned TM-games: TMF, TM2C/S/V, SM
Manialink(s): undef, tmkarma
Location: Germany
Contact:

Re: [Xaseco 1+2] Pay2Play plugin

Post by undef.de » 14 Jun 2017 22:01

speedychris wrote:
09 Jun 2017 08:12
Unfortunately this very useful plugin does not work correct on uaseco (widget disappears after 2 rounds). Is there a fixed version possible?
As this is only the port for XAseco(1,2), this question isn't right here. You better should ask this at https://forum.maniaplanet.com/viewforum.php?f=522 instead... leigham is there too: https://forum.maniaplanet.com/memberlis ... ile&u=3894
Developer of various plugins for XAseco/XAseco2 and MPAseco,
like Records-Eyepiece, TM-Karma, Alternate Scoretable...
Visit my Lab: www.undef.name

Get it now:
» TM2 Valley
» TM2 Canyon
» TM2 Stadium
» SM Storm

Post Reply