How to make a ManiaLive Plugin ?

Post here every finished plugin

Moderator: NADEO

Post Reply
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

How to make a ManiaLive Plugin ?

Post by Boss-Bravo »

Hi !

ManiaLive is installed on my pc recently, and i want some plugins special, but i have a problem, i don't know how can i make plugin, i read this document : http://code.google.com/p/manialive/wiki/DeveloperDoc And i understand the most important of this.
Is there another more complete documentation on how to create plugins ? because i want in my first plugin to create 2 Admins command, I developed a plugin, but he doesn't work. It's difficult to create plugin only to look others plugins :D

I Need Help please, a documentation, or for resolve errors of that plugin.
I want to create 2 admins command, for mute and unmute all players except admins (for F1 races on TrackMania United)
I make that :

Code: Select all

<?php
 
namespace ManiaLivePlugins\BBP\MuteGP;

use ManiaLive\DedicatedApi\Connection;
use ManiaLive\Features\ChatCommand\Command;
use ManiaLive\Utilities\Console;
use ManiaLive\Data\Storage;
use ManiaLive\Config\Loader;


class MuteGP extends \ManiaLive\PluginHandler\Plugin {
	private $desc = "Usage: /mutall";
	private $help = "The mutall plugin mute/unmute all players except admins.

\$wUsage\$z:
\$o/mutall
\$o/unmutall";

	function onInit() {
		$this->setVersion(294);
        $this->setPublicMethod('getVersion');
        $this->setPublicMethod('addAdminCommand');
	}
	
	
	function onLoad() {
		Console::println('['.date('H:i:s').'] [BBP] Plugin: MuteGP r'.$this->getVersion().' by Bo$$ Bravo.');
		
		$this->addAdminCommand(array($this,'mutall'),array('mutall'),true,false,false);
		$this->addAdminCommand(array($this,'unmutall'),array('unmutall'),true,false,false);
	}
	

	function mutall($fromLogin, $param1, $param2 = NULL, $param3 = NULL) {        
		foreach ($this->storage->players as $player) {
		$admin = Storage::GetInstance()->getPlayerObject($fromLogin);
		$this->connection->ignore($player);
		}
		$this->sendChat('$o$0aeAdmin $fff'.$admin->nickName.'$z$o$0ae Ignores All players except Admins');
	}
	
	function unmutall($fromLogin, $param1, $param2 = NULL, $param3 = NULL) {
		$admin = Storage::GetInstance()->getPlayerObject($fromLogin);
        foreach ($this->storage->players as $player) {
        $this->connection->unIgnore($player);
		}
        $this->sendChat('$o$0aeAdmin $fff'.$admin->nickName.'$z$o$0ae unIgnores All players');
	}
}
?>

And in config.ini :

Code: Select all

plugins.load[] = 'BBP\MuteGP'

The error is on that line :

Code: Select all

$this->setPublicMethod('addAdminCommand');
And says :
The method "addAdminCommand" does not exist and therefor can not be exposed !
Thanks to help me. I'm a good developer but, i don't understand that :roflol:
I never made a plugin on XAseco, ManiaLive or whatever, but I need more plugins for tm² server with ManiaLive, so I'd like you to help me !

Regards.

Bo$$ Bravo
The_Big_Boo
Posts: 1026
Joined: 15 Jun 2010, 15:46

Re: How to make a ManiaLive Plugin ?

Post by The_Big_Boo »

The method "addAdminCommand" does not exist and therefor can not be exposed !
Actually the error message is pretty clear. in your "onInit" method you're calling "setPublicMethod('addAdminCommand')" but this method does not exist in your plugin.
Moreover, setPublicMethod is here to expose your plugin's methods to other plugins. I don't think it's what you really want to do. So you should remove this line and use $this->registerChatCommand() to add your two chat commands.
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: How to make a ManiaLive Plugin ?

Post by Boss-Bravo »

The_Big_Boo wrote:
The method "addAdminCommand" does not exist and therefor can not be exposed !
Actually the error message is pretty clear. in your "onInit" method you're calling "setPublicMethod('addAdminCommand')" but this method does not exist in your plugin.
Moreover, setPublicMethod is here to expose your plugin's methods to other plugins. I don't think it's what you really want to do. So you should remove this line and use $this->registerChatCommand() to add your two chat commands.
Ok, thanks, but for a admin command, it's not the same ? :)
The_Big_Boo
Posts: 1026
Joined: 15 Jun 2010, 15:46

Re: How to make a ManiaLive Plugin ?

Post by The_Big_Boo »

It's the same method. Its signature is:

Code: Select all

/**
	 * Registers a chatcommand at the Interpreter.
	 * @param string $command_name
	 * @param integer $parameter_count
	 * @param string $callback_method
	 * @param bool $add_login
	 * @param array[string] $authorizedLogin
	 * @return \ManiaLive\Features\ChatCommand\Command
	 */
	final function registerChatCommand($command_name, $callback_method,
		$parameter_count = 0, $add_login = false, $authorizedLogin = array())
So you can specify who is able to use it. For admins only (declared in config.ini), you can set the last parameter to \ManiaLive\Features\Admin\AdminGroup::get().
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: How to make a ManiaLive Plugin ?

Post by Boss-Bravo »

Ok, thank you, I test it tonight :thumbsup:
TheM
Posts: 1379
Joined: 15 Jun 2010, 14:30
Location: Uden, Noord-Brabant, Netherlands
Contact:

Re: How to make a ManiaLive Plugin ?

Post by TheM »

Actually, what you did... is copied a part of the Admin plugin (MLEPP) into your plugin.
addAdminCommand is a function used by MLEPP to register a Admin command.
You can do that too, just do like the following:

Code: Select all

$this->callPublicMethod('MLEPP\AdminPanel', 'addAdminCommand', array($this,'test'),array("get","plugin","test"), true, false, false);
This will add the command "/admin get plugin test" and send that to the function named "test" in your plugin ;)
Also see: http://code.google.com/p/mlepp/wiki/adminPanelHowTo
Global moderator | Dutch moderator | Laddermoderator | ManiaWiki moderator
Server Manager/webmaster of Smurfen.net, join us on Canyon, Valley and Royal!
ESL (Game) Staff Head for TrackMania (Stadium, Canyon and Valley).
Post Reply

Return to “ManiaLive Plugins”

Who is online

Users browsing this forum: No registered users and 2 guests