Author Topic: Detect when the client is pressing the jet key  (Read 1397 times)

I need it for this: http://forum.blockland.us/index.php?topic=225276.0

I need a piece of code that detects when the client presses the jet key. I would also appreciate if the code checked if there is a specified image mounted to $BackSlot before doing anything. Can this be done without schedules? Looking at the VCE script (there is a "jetting" variable replacer) it uses the following code but I don't understand it enough to customize it.
Code: [Select]
function Armor::onTrigger(%db,%player,%slot,%val)
{
switch(%slot)
{
...
case 4:
%player.vceJetting = %val;
}
return Parent::onTrigger(%db,%player,%slot,%val);
}
I only need this to attach the jet emitter to the jetpack image. The actual jetting is done with a custom playertype. Once I get this working I will be posting a new thread about that.

I need it for this: http://forum.blockland.us/index.php?topic=225276.0

I need a piece of code that detects when the client presses the jet key. I would also appreciate if the code checked if there is a specified image mounted to $BackSlot before doing anything. Can this be done without schedules? Looking at the VCE script (there is a "jetting" variable replacer) it uses the following code but I don't understand it enough to customize it.
Code: [Select]
function Armor::onTrigger(%db,%player,%slot,%val)
{
switch(%slot)
{
...
case 4:
%player.vceJetting = %val;
}
return Parent::onTrigger(%db,%player,%slot,%val);
}
Ok so if %slot is 4 than it's the jet key and if %val is true they pushed the jet key but if it's false then they released the jet key.

So if you want to do something over and over when the jet key is pushed and have it stop when it's released than you want to make a schedule that calls itself and than when they release the jet key you want to cancel the schedule.
« Last Edit: February 21, 2013, 11:55:40 AM by jes00 »

Okay... So like this?
Code: [Select]
function Armor::onTrigger(%this,%obj,%slot,%val)
{
Parent::onTrigger(%this,%obj,%slot,%val);
if(%slot == 4)
{
if(%val == 1)
{
%obj.mountImage(JetpackFire,1);
}
if(%val == 0)
{
%obj.unMountImage(%slot);
}
}
}

Put together from a snippet of code Port posted in Steam chat:
Code: [Select]
function yourPlayerTypeName::onTrigger( %this, %obj, %slot, %val )
{
parent::onTrigger( %this, %obj, %slot, %val );

if ( %slot == 2 )
{
%col.setImageAmmo( yourImageName.mountPoint, %val );
}
}
And the Stuntplane contrail script:
Code: [Select]
function contrailCheck(%obj)
{
if(!isObject(%obj))
return;
...
if(%obj.getMountedImage(3) $= 0)
{
%obj.mountImage(contrailImage1,2);
%obj.mountImage(contrailImage2,3);
}
...
schedule(2000,0,"contrailCheck",%obj);
}

How did I do? Does this function run every time a client presses the jet key using any playertype? How do I check if some image is mounted to $BackSlot?
« Last Edit: February 21, 2013, 01:26:33 PM by Demian »

If the pack is going to be a mounted image, then what you can do is make it like a weapon, which has an idle state, and another one that emits particles. Then mount it in a slot other than 0 so it won't actually take input from left clicking, and finally toggle it by using Player::setImageTrigger(%slot, %value). I might be wrong on this because weapon images move in mysterious ways, but that's how I'd approach it first.

I realize this doesn't really answer your question, so to cover a few things - first of all, try it and see before asking if it's right. Second, to check if an image is mounted a slot, I believe the command is getMountedImage(%slot). Problem is, the slot defined in the datablock only represents where it mounts on the player. Through the game's script, this should be linked up so that it also controls which image slot it's actually in (and possibly what trigger slot the image corresponds to, so you'd have a key to control what's on your feet, your back, your main hand, but this is just guesswork; all I know is Blockland has about thirty different meanings of %slot), but that is not the case. The item system always mounts images in slot 0 unless overridden with a different script. Use that script to mount your jetpack in another slot (0 and 1 are typically weapons and 3 is the player burn emitter, so 2 may work), then you can check it with getMountedImage.

Yeah that is a little beyond my skills. The stuntplane uses two images for the contrails. The image uses the default empty model and has a particle attached. Then it mounts those images to the slots in the vehicle. I guess you could achieve the same results with the state system but I feel like doing it with images is easier.