Author Topic: Item hit event  (Read 1892 times)

How would I make an event that activates when the brick is hit by an item?

Can I ask something? What Programming Language you used to script here in BlockLand? (Yeah, I'm an out sider.)

Can I ask something? What Programming Language you used to script here in BlockLand? (Yeah, I'm an out sider.)
Irrelevant and crossposting.
I'll answer this in your own topic.

Most of the add-ons that have an onhit event are made with this:
Code: [Select]
registerInputEvent(fxDTSBrick,onToolHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");
function ToolProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onToolHit,%obj.client);
}
}
As far as i know, it works fine.
You can replace onToolHit with anything (that makes sense), like onAxeHit.
Also replace ToolProjectile with the name of the item's projectile.
Like AxeProjectile.

Most of the add-ons that have an onhit event are made with this:
Code: [Select]
registerInputEvent(fxDTSBrick,onToolHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");
function ToolProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onToolHit,%obj.client);
}
}
As far as i know, it works fine.
You can replace onToolHit with anything (that makes sense), like onAxeHit.
Also replace ToolProjectile with the name of the item's projectile.
Like AxeProjectile.
I see. So I do need a projectile. I'll have to look into that then.

I see. So I do need a projectile. I'll have to look into that then.
How else did you want to hit the brick?
Raycasts?

How else did you want to hit the brick?
Raycasts?
That might be better. Can you limit the range of raycasts? I'm making a keycard and it would be pretty confusing if you could hit bricks very far away with such an item.

That might be better. Can you limit the range of raycasts? I'm making a keycard and it would be pretty confusing if you could hit bricks very far away with such an item.
Of course you can.
Will you work with Spaceguy's raycast script then it should be obvious how.

I copypasted the Support_RaycastingWeapons.cs from Space Guy's Buster Gun and added it to the server.cs executions along with the Event_onKeycardhit.cs which contains the code you provided and the cards of course.

It's not working. The event does appear on the list, but it's not working.

Currently my keycard projectile looks like this. Yes I changed the projectile name in the event script.
Code: [Select]
datablock ProjectileData(keyCardProjectile)
{
   directDamage = 0;

   muzzleVelocity = 200;
   velInheritFactor = 1;

   armingDelay = 0;
   lifetime = 1000;
   fadeDelay = 100;
   bounceElasticity = 0;
   bounceFriction = 0;
   isBallistic = false;
   gravityMod = 0;

   hasLight = false;
   lightRadius = 1.0;
   lightColor = "0 0 0";

   uiName = "";
};
The large values are just for testing.

Help?

Now you work with raycasts, you have to adept the function for the event.
Like this,
Code: [Select]
registerInputEvent(fxDTSBrick,onToolHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");
function ToolProjectile::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onToolHit,%obj.client);
}
}
That should do the trick.

Now you work with raycasts, you have to adept the function for the event.
-snip-
That should do the trick.
Doesn't work. Am I doing it right?

Code: [Select]
registerInputEvent(fxDTSBrick,onKeycardHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");

function keyCardProjectile::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onKeycardHit,%obj.client);
}
}

Doesn't work. Am I doing it right?

Code: [Select]
registerInputEvent(fxDTSBrick,onKeycardHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");

function keyCardProjectile::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onKeycardHit,%obj.client);
}
}
Oh sorry, i forgot to mention something else you have to change. :S
Instead of using the function on the projectile, you should now use the function on the itemImage.
Like this,
Code: [Select]
registerInputEvent(fxDTSBrick,onKeycardHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");

function keyCardImage::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onKeycardHit,%obj.client);
}
}

Oh sorry, i forgot to mention something else you have to change. :S
Instead of using the function on the projectile, you should now use the function on the itemImage.
Like this,
Code: [Select]
registerInputEvent(fxDTSBrick,onKeycardHit,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "Minigame Minigame");

function keyCardImage::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit)
{
parent::onHitObject(%this,%obj,%slot,%col,%pos,%normal,%shotVec,%crit);
if(%col.getClassName() $= "fxDTSBrick")
{
$InputTarget_["Self"] = %col;
$InputTarget_["Player"] = %obj.client.player;
$InputTarget_["Client"] = %obj.client;
if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj.client);
}
else
{
if(getMiniGameFromObject(%col) == getMiniGameFromObject(%obj.client))
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%col);
}
else
{
$InputTarget_["MiniGame"] = 0;
}
}
%col.processInputEvent(onKeycardHit,%obj.client);
}
}
Perfect. Works like a charm... with the default card. How do I make it work with multiple images? Since all the colored cards have their own image. (greenCard, blueCard etc.)

Of course you could make it work for multiple by naming it so, HOWEVER i guess you want a simpeler script for multiple stuff...
Well, i think i have an idea, but that takes an other way. (Packages, Parenting and of course checking if the item is the one we are searching for.

I cannot write it all down now, i will try to answer this later.

It's so cold in here all alone.

It's so cold in here all alone.
Sorry.
Will respond soon.
Wonder why noone else cares to respond. :C