Author Topic: Getting %client in an output event  (Read 1078 times)

Hey all the title explains most of it but heres some more.
I have
Code: [Select]
function fxDTSBrick::checkVip(%client)
{
echo("Event Called");

if(findclientbyname(%client).isVip)
{
echo("Is a VIP");
fxDTSBrick::onVipTrue();
}

}

When I manually type in
Code: [Select]
fxDTSBrick::checkVip(); in the console I see both "Event Called" and "Is a VIP".
However when I click on a brick that has "OnActivate => Self => CheckVIP" I only see "Event Called".
Anyone know what the problem is?

The first argument in an object method is always the object that has the method called on it.

i.e.
%this.butt(); where %this is a ScriptObject object of the lowercaseh class is equivalent to lowercaseh::butt(%this);

Your %client object is actually the fxDTSBrick object that has had the checkVip method called on it. Additionally, to have the activating client passed to a non-GameConnection output event, you must set the switch to append the client in the event registration.

registerOutputEvent(%class, %name, %parameterList, %appendClient)

You're also unnecessarily calling findClientByName when you already are expecting %client to be a GameConnection object. findClientByName is a function used to resolve a player name to a client object currently in the server. It's not necessary to use it in any case except this one.

edit:
the way you're calling the function will also not work in the context of an event
if you called your current function as fxDTSBrick::checkVip("rarw"); it would work fine, but an event wouldn't work in this way.
« Last Edit: March 19, 2014, 06:39:49 PM by otto-san »

The first argument in an object method is always the object that has the method called on it.

i.e.
%this.butt(); where %this is a ScriptObject object of the lowercaseh class is equivalent to lowercaseh::butt(%this);

Your %client object is actually the fxDTSBrick object that has had the checkVip method called on it. Additionally, to have the activating client passed to a non-GameConnection output event,
you must set the switch to append the client in the event registration.

registerOutputEvent(%class, %name, %parameterList, %appendClient)

You're also unnecessarily calling findClientByName when you already are expecting %client to be a GameConnection object. findClientByName is a function used to resolve a player name to a client object currently in the server. It's not necessary to use it in any case except this one.

edit:
the way you're calling the function will also not work in the context of an event
if you called your current function as fxDTSBrick::checkVip("rarw"); it would work fine, but an event wouldn't work in this way.


Thanks Otto

The first parameter on a class object is always refering to the object.

It should be fxDTSBrick::checkVip(%this,%client)

Make sure you see otto's registerOutputEvent function so you can see these on the events.

So basically you would have the code rewritten:


function fxDTSBrick::checkVip(%this,%client)
{
   echo("Brick ==> checkVip > Event Called");
   if(%client.isVip)
   {
      echo(%client.getPlayerName() @ " is VIP!");
      %this.processInputEvent(onVipTrue,%client); //Call the event
   }
}


For an input event, it would be a little different.

It would be


registerInputEvent(fxDTSBrick, onVipTrue, "Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "MiniGame MiniGame");

function fxDTSBrick::onVipTrue(%this,%obj)
{
   echo("Brick ==> onVipTrue > Event Called");
   $InputTarget_["Self"] = %this; //Call the brick
   $InputTarget_["Player"] = %obj; //Call the object that is activating it
   $InputTarget_["Client"] = %obj.client; //Call the object's client
   $InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client); //Call the object's minigame
   %this.processInputEvent("onVipTrue", %obj.client); //Process it
}
« Last Edit: March 19, 2014, 06:52:09 PM by Advanced Bot »

Fixed it after what otto told me and looking at VCE's "Mod Varible".
Code: [Select]
function GameConnection::checkVip(%client)
{
echo("Event Called");

%target = %client;
if(%target.isVip)
{
echo("Is a VIP");
fxDTSBrick::onVipTrue();
}

}


function fxDTSBrick::onVipTrue(%this,%obj)
{
   echo("Brick ==> onVipTrue > Event Called");
   $InputTarget_["Self"] = %this; //Call the brick
   $InputTarget_["Player"] = %obj; //Call the object that is activating it
   $InputTarget_["Client"] = %obj.client; //Call the object's client
   $InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client); //Call the object's minigame
   %this.processInputEvent("onVipTrue", %obj.client); //Process it
}

This isnt working. In the console I get "Brick ==> onVipTrue > Event Called" but the output even I set on the same brick "Self ==> playSound" isnt working


Code: [Select]
fxDTSBrick::onVipTrue();

You cant do this here. You need to get the brick object, which you don't have and cant get properly (even VCE's method is unreliable). The best way to get the brick is to use the Self target for the event, so function fxDTSBrick::checkVip(%brick, %client) and use the %appendClient bool when registering the event.

You cant do this here. You need to get the brick object, which you don't have and cant get properly (even VCE's method is unreliable). The best way to get the brick is to use the Self target for the event, so function fxDTSBrick::checkVip(%brick, %client) and use the %appendClient bool when registering the event.

He's already using the Self target though..

Closing. Got 1 on 1 help from viso. Thanks anyways!