Author Topic: Set Events on a brick.  (Read 974 times)

I would like to know how one would go about automatically setting events on a brick via script.  Like the JVS content starts with the events automatically.

Try looking at the JVS content scripts.

Try looking at the JVS content scripts.
Already did.  Couldn't find anything.  I'm the sorta guy who tries to do everything on his own.  So, generally I don't post unless I couldn't find it.

Code: [Select]
%oldWrenchBrick = %brick.client.wrenchBrick;
%brick.client.wrenchBrick = %brick;
//%enabled: boolean whether the new line of events is enabled
//%input: index of the input event (inputEvent_GetInputEventIdx("onActivate"))
//%delay: delay in milliseconds
//%target: index of the target on the input event (inputEvent_GetTargetIndex("fxDTSBrick",%input,"Player"))
//%namedTarget: named brick you want to target. I have no idea how to get the index position of a brick from a client. (-1 for no named brick)
//%output: index of the output event (outputEvent_GetOutputEventIdx("fxDtsBrick","setColor"))
//%param1-4: Obvious
serverCmdAddEvent(%brick.client,%enabled,%input,%delay,%target,%namedTarget,%output,%param1,%param2,%param3,%param4);
%brick.client.wrenchBrick = %oldWrenchBrick;

Code: [Select]
%oldWrenchBrick = %brick.client.wrenchBrick;
%brick.client.wrenchBrick = %brick;
//%enabled: boolean whether the new line of events is enabled
//%input: index of the input event (inputEvent_GetInputEventIdx("onActivate"))
//%delay: delay in milliseconds
//%target: index of the target on the input event (inputEvent_GetTargetIndex("fxDTSBrick",%input,"Player"))
//%namedTarget: named brick you want to target. I have no idea how to get the index position of a brick from a client. (-1 for no named brick)
//%output: index of the output event (outputEvent_GetOutputEventIdx("fxDtsBrick","setColor"))
//%param1-4: Obvious
serverCmdAddEvent(%brick.client,%enabled,%input,%delay,%target,%namedTarget,%output,%param1,%param2,%param3,%param4);
%brick.client.wrenchBrick = %oldWrenchBrick;
How would I put that into a script?

Rather, how would I use this function to make a brick specifically cause a player to lose health when touched?
« Last Edit: March 24, 2010, 09:32:32 PM by Gadgethm »

Code: [Select]
package ?
{
function fxDtsBrick::onPlant(%brick)
{
Parent::onPlant(%brick);
if(%brick.getDatablock() != NAMEOFDATABLOCK)
return;
%oldWrenchBrick = %brick.client.wrenchBrick;
%brick.client.wrenchBrick = %brick;

%onPlayerTouchIndex = inputEvent_GetInputEventIdx("onPlayerTouch");
%addHealthIndex = outputEvent_GetOutputEventIdx("Player","addHealth");
%playerIndex = inputEvent_GetTargetIndex("fxDTSBrick",%onPlayerTouchIndex,"Player");

%damageAmount = 10; //causes 10 damage
serverCmdAddEvent(%brick.client,1,%onPlayerTouchIndex,0,%playerIndex,-1,%addHealthIndex,-%damageAmount);

%brick.client.wrenchBrick = %oldWrenchBrick;
}
};
activatePackage(?);
Next time try it yourself please, not everyone is as lenient as me when it comes to spoon-feeding code.

-codesnip-
Next time try it yourself please, not everyone is as lenient as me when it comes to spoon-feeding code.
Ok, thanks.  I didn't know that you had to assign each part of the event to a variable.  I guess I know now...

Thanks again. :/