Author Topic: How to make Target events?  (Read 839 times)

How do you make/register a target event? Can someone give me a example?

OnActivate-namedbrick-setmovingtarget-guy
Just an example, but it is at the bottem of the output events.

Not the target events by spaceguy. Like scripting a target event. Such as:
Self
Vehicle
Bot
Named brick
Client
Etc.

What exactly do you mean?

Not the target events by spaceguy.

Off topic, but Space Guy based his off the pure-script version from the tutorial.

Warning - while you were typing a new reply has been posted. You may wish to review your post.

He means the list of targets. How to set up who an event targets.

i thought ephi made the target events, maybe not...

also, why would you need another category? it looks like pretty much everything is covered, unless you want global/server

Yes, I've been wanting to make a server target too.

i thought ephi made the target events, maybe not...

also, why would you need another category? it looks like pretty much everything is covered, unless you want global/server
Ephialtes made the models and the original script for the Tutorial. I used that to make an event-usable form, but the 'moving' ones were quite inefficient and laggy. Overall this version is better, using JVS Content to run it and let it be customisable instead of one arbitrary "up" "down" mode.


For the actual topic, it may be helpful to create a new type of ScriptObject and add functions to that/add events for that, or add them to existing object types if you can. I made some "Event Items" test a while back which among other things used a special "Weapon" target for some output events like "Weapon->spawnProjectile" to shoot from a specially made tool instead of the player's head.

Here's what I did for my one:
Code: [Select]
registerInputEvent(fxDTSBrick, "onItemUse",           "Self fxDTSBrick\tPlayer Player\tWeapon WeaponImage\tClient GameConnection\tMiniGame MiniGame",1);

function fxDTSBrick::onItemUse(%this, %weapon, %client)
{
//setup targets
$InputTarget_["Self"]   = %this;
$InputTarget_["Weapon"] = %weapon; //This is received from whatever calls onItemUse
$InputTarget_["Player"] = %client.player;
$InputTarget_["Client"] = %client;

...

//process the event
%this.processInputEvent("onItemUse", %client);
}

...

//EventGunImage has the "ClassName" parameter set to "WeaponImage", you can only do this for shape images though
function EventGunImage::onMount(%this,%obj,%mount)
{
Parent::onMount(%this,%obj,%mount);

...
        
%brick.onItemUse(%this,%obj.client); //Passes "%this" as the target a "WeaponImage" datablock
}

The outputs are exactly like any other event, but you use your new type instead:
Code: [Select]
registerOutputEvent(WeaponImage,playSound,"datablock Sound",1);

function WeaponImage::playSound(%this,%sound,%client)
{
...
}

You will need to create an object of that type first if it's not an existing thing (Player, Vehicle, WeaponImage, ...) so for your server type you'd make some kind of global variable like:
Code: [Select]
$ServerEvents::Object = new ScriptObject(ServerEventSO);

registerOutputEvent(ServerEventSO,incCount,"int -100 100 1",1);
function ServerEventSO::incCount(%this,%num,%client)
{
   %this.counter += %num;
   messageAll('',%client.getPlayerName() SPC "set the counter to" SPC %this.counter);
}
... and then in each input event with a "Server" target use $InputTarget_["Server"] = $ServerEvents::Object;

In trying to use this, though, there's a problem as you'd have to redefine every single existing input event in case you want "onActivate -> Server -> ..." "onContentStart -> Server -> ..." and for something like "onServer..." events you'd have to be able to know which bricks it should trigger on instead of everything on the server.

Output targets are defined by class name, not the name in the events menu like "Bot" and "OwnerClient" (JVS Content). You can have both "Player" and "Bot" in one event, it just sets different objects for each.
Code: [Select]
registerInputEvent(fxDTSBrick, "onBotChaseTarget",  "Self fxDTSBrick"
                                                      TAB "Bot Player"
                                                      TAB "Player Player"
                                                      TAB "MiniGame MiniGame");
//Both "Bot" and "Player" are going to be "Player" objects so they'll both get the same list of outputs ("burn" "kill" "addHealth" ...)

function fxDTSBrick::onBotChaseTarget(%obj,%player)
{
   //setup targets
   $InputTarget_["Self"]   = %obj;
   $InputTarget_["Bot"]   = %obj.vehicle; //The event is put on whichever brick spawned the bot
   $InputTarget_["Client"]   = %player.client;
   $InputTarget_["Player"]   = %player; //The player it's decided to chase it set separately

   ...
  
   //process the event
   %obj.processInputEvent("onBotChaseTarget", %obj.connection.owner);
}
« Last Edit: November 02, 2010, 04:26:07 PM by Space Guy »