custom plugin events and working sqlite explorer

Discuss the Dedicated Server Tools developed by Nadeo Live such as ManiaLive, Trust Circles, Dedicated Manager, Competition Manager and Lobbies

Moderator: NADEO

Post Reply
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

custom plugin events and working sqlite explorer

Post by reaby »

Custom plugin events ?
Well i managed to to this tonight after 3~4 hours of trial & error, as i'm totally noob with this new object orientated programming thingy. hopefully we get official support for plugin events for final version of manialive, as this can be ground breaking :)

for example i did a custom event for onCopperDonation...
you need to do new event class onCopperDonate.php

it has the class as following:

Code: Select all

namespace [define the namespace here for autoload]

class onCopperDonate extends \ManiaLive\Event\Event
{
	protected $login;
	protected $amount;
	
	function __construct($login, $amount)
	{
		$this->login = $login;
		$this->amount = $amount;
	}
	
	function fireDo($listener)
	{
		call_user_func_array(array($listener, 'onCopperDonate'), array($this->login, $this->amount));
	}
}

at CopperDonate.php you add this new class

Code: Select all

use ManiaLive\Event\Dispatcher;
use ManiaLivePlugins\MLEPP\DonateCoppers\Events\onCopperDonate;
and at the point, when you want the event to happen, command

Code: Select all

Dispatcher::dispatch(new onCopperDonate($login,$amount));
Then to the plugins where you want the event to happen...

Code: Select all

use ManiaLive\Event\Dispatcher;

function onInit() {
     if ($this->isPluginLoaded('MLEPP\DonateCoppers', 0.1)) {
	Dispatcher::register(\ManiaLivePlugins\MLEPP\DonateCoppers\Events\onCopperDonate::getClass(), $this);
      }	
}

function onCopperDonate($login, $amount) {
$this->sendChat("Hahaha, plugin interaction, and so $login gives $amount of coppers!");
}

Sqlite Browser for sqlite 2.1
The program version must be this 1.1, which is ancient, but it is freeware and works with manialive database.
http://mesh.dl.sourceforge.net/project/ ... .1-win.zip


now go, make new plugins,
-- Reaby
oliverde8
Posts: 1286
Joined: 16 Jun 2010, 07:33
Location: in a Blue Box

Re: custom plugin events and working sqlite explorer

Post by oliverde8 »

Very nice thanks, I won't need to search to se how it works :)
Image
Developper for The next generation, Clean and Powerfull controller eXpansion for your SM & TM server . Working on eXpansion² with full MP4 support and many other awesome features...
farfa
Nadeo
Nadeo
Posts: 585
Joined: 14 Jun 2010, 16:15
Location: In front of your hood with one lap late

Re: custom plugin events and working sqlite explorer

Post by farfa »

Congrats reaby it's almost this. you have understood how it works, but this is just a way to be more efficient ;)
Just something to optimize your code. With this Event, you have to create one class for each event you want to fire. It's just a bit painful (you'll see ;) ) What I recommend, is inspired of our usage of Event.
Create an Event class in your namespace with different constants, for example in \ManiaLive\ Data\Event we have:

Code: Select all

const ON_PLAYER_NEW_BEST_TIME = 1;
const ON_PLAYER_NEW_RANK = 2;
const ON_PLAYER_NEW_BEST_SCORE = 3;
Each constant is a particular event. To fire them, we use the following method

Code: Select all

function fireDo($listener)
{
	$method = null;
	
	switch($this->onWhat)
	{
		case self::ON_PLAYER_NEW_BEST_TIME: $method = 'onPlayerNewBestTime'; break;
		case self::ON_PLAYER_NEW_RANK: $method = 'onPlayerNewRank'; break;
		case self::ON_PLAYER_NEW_BEST_SCORE: $method = 'onPlayerNewBestScore'; break;
	}
	
	if ($method != null)
		call_user_func_array(array($listener, $method), $this->params);
}
For the full code, see https://code.google.com/p/manialive/sou ... /Event.php
Also known as: satanasdiabolo
Post Reply

Return to “Dedicated Server Tools”

Who is online

Users browsing this forum: No registered users and 1 guest