Page 1 of 1

callvote

Posted: 10 Oct 2012, 01:29
by MuNgLo
Hi. I got a couple of questions about callvote.

I want to use it for custom votes but I don't get how. What I need is to get some feedback to myplugin in some way. Is it even possible?

This is how it looks in DedicatedAPI/Connection

Code: Select all

/**
	 * Call a vote for a cmd. The command is a XML string corresponding to an XmlRpc request.
	 * You can additionally specifiy specific parameters for this vote: a ratio, a time out
	 * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
	 * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
	 * '1' means any player, '2' is for everybody, pure spectators included.
	 * @param Structures\Vote $vote
	 * @param double $ratio -1 means default, else ration should be between 0 and 1
	 * @param int $timeout time to vote in millisecondes, '0' means default
	 * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
	 * @param bool $multicall
	 * @throws InvalidArgumentException
	 */
	function callVote(Structures\Vote $vote, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
I'm guessing the " * @param Structures\Vote $vote" is the important bit. ;) But how do I use it?

The plugin I want to use it in is loaded as "BAZINGA/Changemap" and I would need to get some feedback to it from the vote as the effect of the vote can't be done in a single command or even a few.

Any help is appreciated.

Re: callvote

Posted: 10 Oct 2012, 09:49
by The_Big_Boo
Hi,

When using callVote, there are only 2 fields needed in the Vote structure:
  • cmdName: the method which will be called on the dedicated if the vote pass (eg. Kick, Ban, NextMap and so on for usual votes)
  • cmdParam: an array with the parameters for the method. If the methods doesn't need any parameter, you still need to pass an empty array.
Here is an example which does the same as the callVoteKick method:

Code: Select all

$vote = new \DedicatedApi\Structures\Vote();
$vote->cmdName = 'Kick';
$vote->cmdParam = array('a_login');
$connection->callVote($vote);
For feedback about the vote, there is the onVoteUpdated callback which informs you when a vote is created then the result of it: cancelled, failed or passed. If your plugin is listening to dedicated events, you just need to override it and do whatever you like with it.


You can also make totally custom votes using Echo. In this case, the first argument of Echo is the message that will be shown to players and the second one is a string which can help you to know what to do (it's easier to rely on a short string than on a whole question)
Here is an example:

Code: Select all

$vote = new \DedicatedApi\Structures\Vote();
$vote->cmdName = 'Echo';
$vote->cmdParam = array('Do you like cats', 'cat');
$connection->callVote($vote);
If the vote pass, you'll get the onEcho callback with 'cat' as first argument and 'Do you like cats' as second.

Re: callvote

Posted: 10 Oct 2012, 12:24
by MuNgLo
Thx for the info but I still can't seem to pull it off.
I tried both ways, a plain kickvote and a custom with the echo.

dumping the $vote in the console shows what looks like a proper Vote Object

$vote object when trying to get a kickvote to work

Code: Select all

DedicatedApi\Structures\Vote Object
(
    [status] =>
    [callerLogin] =>
    [cmdName] => Kick
    [cmdParam] => Array
        (
            [0] => munglo
        )

)
And still it gives me..

Code: Select all

Fatal error: Call to a member function callVote() on a non-object
You said that cmdName and cmdParam are enough so what am I doing wrong?

Re: callvote

Posted: 10 Oct 2012, 12:32
by The_Big_Boo
Your error means you're not calling callVote on an instance of \DedicatedApi\Connection. The $connection variable I used was just a placeholder.
If you're doing this in a plugin, you can use $this->connection though.

Re: callvote

Posted: 10 Oct 2012, 12:54
by MuNgLo
Well this code..

Code: Select all

$vote = new \DedicatedApi\Structures\Vote();
				$vote->cmdName = 'Kick';
				$vote->cmdParam = array('munglo');
				if(is_object($vote)) {Console::println( print_r($vote) );}
				$this->$connection->callVote($vote);
Still gives me "Fatal error: Cannot access empty property"

So I'm still missing something somewhere. :(

Re: callvote

Posted: 10 Oct 2012, 13:07
by The_Big_Boo
$this->$connection will obviously not work, you must not type $ in front of connection (unless you know what you're doing) but just $this->connection

Re: callvote

Posted: 10 Oct 2012, 13:16
by MuNgLo
LOOOOOL mah bad :P :roflol:

sry for being a blind moron :P

I really shoul've spotted that one

Re: callvote

Posted: 10 Oct 2012, 13:58
by MuNgLo
Ok got it all working now. Just gotta clean it up a bit.

Thx again Big Boo. You are a lifesaver.