Author Topic: [Coding] Sword lunge and clashing  (Read 1192 times)

I'm trying to re-create the energy sword from Halo 3, and i want it to lunge it toward the player's target, before firing the projectile, if possible, and also be able to clash if both players are using the weapon at the same time, thus doing no damage and spawning a no-damage explosion

Both of the scripts are currently in the sword's 'projectile::onCollision' function

Sword clashing:
The following script is basically how i figure something like this could work out
Code: [Select]
if(%col.getClassName() $="Player" || %col.getClassName() $= "AIPlayer")
{
if(%col.getClassName() $= "AIPlayer")
{
if(%col.getMountedImage(0) $=  plasmaBladeImage.getId() && %col.isImageFiring() $= "0")
{
%this = %obj.plasmaBladeProjectile;
%this.directDamage = 0;
%this.explosion = "";
serverPlay3D(plasmaBladeClashSound, %obj.getTransform());
%proj = new Projectile()
{
  scale = %obj.getScale();
  dataBlock = esClashExplosionProjectile;
  initialVelocity = %obj.getVelocity();
  initialPosition = %obj.getPosition();
  sourceObject = %obj;
  sourceSlot = 0;
  client = %obj.client;
};
MissionCleanup.add(%proj);
}else{
serverPlay3D(plasmaBladeHitFleshSound, %obj.getTransform());
}
}
}
else
{
serverPlay3D(plasmaBladeHitSound, %obj.getTransform());
}
parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);

Basically, using the projectile, or fire some kind of raycast before actually firing, that checks if the state of the target's weapon is currently in a state where 'stateFire' is set to true, then if so, no damage is done and it spawns an explosion, either by spawning a projectile first (like what gory death does), or by just spawning an explosion with a schedule or something

Sword lunge:
Currently, i'm using a modified version of the script from Kaje's hookshot, but it doesn't always work (which also happens with the hookshot at close ranges), and the lunge flings to, and over, your target, so i'd like to know if there's a better way to do this, or if there's some way to fix this script
Code: [Select]
function plasmaBladeProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
-SNIPPED SWORD CLASH STUFF-

%player = %obj.client.player;
%pmount = %player.getObjectMount();

if(isObject(%pmount))
{
if(%pmount.getClassName() $= "WheeledVehicle" || %pmount.getClassName() $= "AIplayer")
{
if(%col.getClassName() $= "Player" || %col.getClassName() $= "WheeledVehicle" || %col.getClassName() $= "FlyingVehicle" ||  

%col.getClassName() $= "AIplayer")
{
pushPlayerToObj2(%pmount, %col);
}else{
pushPlayerToObj(%ppmount, %pos);
}
return;
}
}

if(%col.getClassName() $= "Player" || %col.getClassName() $= "AIplayer")
{
pushPlayerToObj(%player, %pos);
}
}


function pushPlayerToObj(%player, %cpos)
{
if (!isObject(%player)) return; //make sure these are still objects, get rid of checking if the collision is an object
%ppos = getWords(%player.getTransform(), 0, 2);
%vec = VectorSub(%cpos, %ppos); //This automatically subtracts the positions
%len = VectorLen(%vec); //find the distance between the two coordinates
if (%len < 5)
{
return;
} //we don't check the same position because they won't be the same, just close to each other
%vec = VectorNormalize(%vec); //makes it small
if (%len < 15)
{
%vec = VectorScale(%vec, 30);
}
}


function pushPlayerToObj2(%player, %cpos)
{
if (!isObject(%player)) return; //make sure these are still objects, get rid of checking if the collision is an object
%ppos = getWords(%player.getTransform(), 0, 2);
%cpos2 = getWords(%cpos.getTransform(), 0, 2);
if(%cpos.getClassName() $= "FlyingVehicle"){
%cpos2 = VectorAdd(%cpos2, "0 0 1");
}
if(%cpos.getclassname() $= "WheeledVehicle")
{
%cpos2 = VectorAdd(%cpos2, "0 0 2");
}
%vec = VectorSub(%cpos2, %ppos); //This automatically subtracts the positions
%len = VectorLen(%vec); //find the distance between the two coordinates
if (%len < 5){

return;
}
%vec = VectorNormalize(%vec); //makes it smallif (%len < 15)
if (%len < 15)
{
%vec = VectorScale(%vec, 30);
}

(Optional) Dynamic custom crosshair:
I already have the player's crosshair change and all, but i would like to know if it's possible to change the crosshair's texture whenever the player looks at, and is close enough, to another player

This is the script, for reference
Code: [Select]
if(isObject(%obj.client))
{
crossHair.setBitmap("Add-Ons/weapon_plamablade/esret_notarget");
}
« Last Edit: December 06, 2015, 08:42:54 AM by Masterlegodude »

for the crosshair, shouldn't you package onunmount to reset the crosshair back to the one in ci/base/whatever? on death could be done by packaging the death function.

this is purely conceptual, as i don't know any of the details i need to make this work. but given from what i know this sounds like the way to handle this.

for the crosshair, shouldn't you package onunmount to reset the crosshair back to the one in ci/base/whatever?
For onUnMount, it works without packaging, i might have worded things wrong, but the crosshair does go back to normal when you un-equip the item or switch to something else, the only problem is that if a player dies, they can't un-equip what they don't have

But i'll give packaging an on death function a go

Well, that worked, don't know why i didn't think of that beforehand :I
« Last Edit: December 06, 2015, 08:45:14 AM by Masterlegodude »

The crosshair will only change in non-dedicated hosting.