News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Adding Gravity Gun Capability to the Soul Cube

Started by VGames, June 13, 2015, 02:14:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

VGames

Ok I've given the Soul Cube a Gravity Gun ability while in the Zoomed in mode. Press fire to grab. Press alt fire to throw grabbed objects. It all works very well but I cant seem to keep the weapon from wanting to holster and switch back to the last weapon when grabbing stuff. Is there a way to keep the weapon from wanting to switch back to the previous weapon when you press the "fire" key? It'll stay in the zoomed mode and allow you to use the gravity feature as long as you don't zoom out but the instant you zoom out it switches back to the previous weapon.  The hud also displays the previous weapon and 1 round of ammo as soon as you press the fire key while zoomed in. Its like its just waiting for you to zoom out so it can switch back to the previous weapon. Here is my script file. Please help if you can. Also if you can figure out how to allow this gravity gun feature without any ammo having to be available that would be awesome.


/***********************************************************************

weapon_soulcube.script

***********************************************************************/

// blend times
#define SOULCUBE_IDLE_TO_LOWER 4
#define SOULCUBE_IDLE_TO_FIRE 4
#define SOULCUBE_RAISE_TO_IDLE 4
#define SOULCUBE_SPIN_TO_IDLE 0
#define SOULCUBE_IDLE_TO_SPIN 0

#define GG_RANGE 1150 //objects can be captured within this range
#define GG_HOVER 125 //captured objects hover in front of player at this distance
#define GG_AMMO_STRENGTH 10 //one ammo unit strength
#define GG_TARGET_SPEED 1100 //captured objects move to hover position with this speed
#define GG_LAUNCH_TIME 1 //caputred objects drop (after fire button is released) within this time, launch after
#define GG_LAUNCH_SPEED 24000 //captured objects launch away from player (after fire button is released) with this speed
#define GG_KICKBACK_SPEED 30 //player push back after captured object launch
#define GG_LAUNCH_AMMO 5 //ammo units used after captured object launch



object weapon_soulcube : weapon_base {

//entity beam1;
entity gg_owner;
//entity emit;
entity target;

float x;
float y;
float z;
float e;
float z_angle;
float xy_angle;
float target_health;
float justhurt;
float Parmangle;
float ammo_clip;

string target_class;
vector gg_angles;
vector gg_start;
vector gg_end;
vector gg_owner_size;
entity hand_emit;
entity weapon_ent;
entity owner;
float dragging;

vector target_pos;
vector move_dir;
vector push_dir;
float distance;
float frac;
float launch_time;
float current_time;
vector target_size;

float ftime;
float adjustorigin;



void init();
void UpdateShaderParms();

void Lower();
void Raise();
void Idle();
void Fire();
void Gravity();
void Grab();
void Dragging();
void Throw();
void Launch();
void ExitCinematic();

void FireSecondary();
};

void weapon_soulcube::init() {
cacheSoundShader( "player_drag" );
cacheSoundShader( "player_stopdrag" );
cacheSoundShader( "player_startdrag" );
cacheSoundShader( "player_drag_hum" );

weaponState( "Raise", 0 );
}

void weapon_soulcube::UpdateShaderParms() {
setShaderParm( SHADERPARM_MODE, totalAmmoCount() );
}

void weapon_soulcube::Raise() {
weaponRising();
playAnim( ANIMCHANNEL_ALL, "raise" );
while( !animDone( ANIMCHANNEL_ALL, SOULCUBE_RAISE_TO_IDLE ) ) {
UpdateShaderParms();
waitFrame();
}
weaponState( "Idle", SOULCUBE_RAISE_TO_IDLE );
}

void weapon_soulcube::Lower() {
weaponLowering();
playAnim( ANIMCHANNEL_ALL, "putaway" );
while( !animDone( ANIMCHANNEL_ALL, 0 ) ) {
UpdateShaderParms();
waitFrame();
}
weaponHolstered();
waitUntil( WEAPON_RAISEWEAPON );
weaponState( "Raise", 0 );
}

void weapon_soulcube::Idle() {
float count;

weaponReady();

count = 8 + sys.random( 8 );
while( 1 ) {

count--;
if ( count <= 0 ) {
playAnim( ANIMCHANNEL_ALL, "spin" );
count = 8 + sys.random( 8 );
} else {
playAnim( ANIMCHANNEL_ALL, "idle" );
}
while( !animDone( ANIMCHANNEL_ALL, 0 ) ) {
UpdateShaderParms();
if ( WEAPON_LOWERWEAPON ) {
weaponState( "Lower", SOULCUBE_IDLE_TO_LOWER );
}
if ( WEAPON_ATTACK && !isLowered() && !BUTTON_ZOOM ) {
weaponState( "Fire", SOULCUBE_IDLE_TO_FIRE );
}
if ( BUTTON_ALTFIRE && !isLowered() && !BUTTON_ZOOM && ( ammoAvailable() > 0 ) ) {
weaponState( "FireSecondary", SOULCUBE_IDLE_TO_FIRE );
}
if ( BUTTON_ALTFIRE && !isLowered() && ( !ammoAvailable() ) ) {
weaponState( "Lower", SOULCUBE_IDLE_TO_LOWER );
}
if ( BUTTON_ZOOM && ( ammoAvailable() > 0 ) ) {
weaponState( "Gravity", SOULCUBE_IDLE_TO_SPIN );
}
if ( BUTTON_ZOOM && ( !ammoAvailable() ) ) {
weaponState( "Lower", SOULCUBE_IDLE_TO_LOWER );
}
waitFrame();
}
}
}

void weapon_soulcube::Fire() {
WEAPON_START_FIRING = true;
playAnim( ANIMCHANNEL_ALL, "fire" );

while( !animDone( ANIMCHANNEL_ALL, 0 ) ) {
UpdateShaderParms();
waitFrame();
}

WEAPON_START_FIRING = false;
weaponHolstered();
}

void weapon_soulcube::FireSecondary() {
WEAPON_START_FIRING = true;
playAnim( ANIMCHANNEL_ALL, "fire" );

launchProjectiles( 0, 0, 0, 1.0, 1.0 ); // don't launch any projectiles, we need this to fire off the soul's ammo
$player1.fireProjectile( "projectile_SKspawner", getJointPos(1), $player1.getViewAngles() );

WEAPON_START_FIRING = false;
weaponHolstered();
}

void weapon_soulcube::Gravity() {

float gg_trace;
string target_name;
dragging = 0;

weaponReady();
while ( !WEAPON_RELOAD && BUTTON_ZOOM ) {
if ( WEAPON_ATTACK ) {
//ammo_clip = ammoInClip();
gg_owner = getOwner();
gg_start = gg_owner.getWorldOrigin();
gg_owner_size = gg_owner.getSize();
gg_start_z = gg_start_z + (gg_owner_size_z - 6);
gg_angles = gg_owner.getViewAngles();
z_angle = gg_angles_x * -1;
xy_angle = gg_angles_y;
z = sys.sin(z_angle) * GG_RANGE;
e = sys.cos(z_angle) * GG_RANGE;
y = sys.sin(xy_angle) * e;
x = sys.cos(xy_angle) * e;
gg_end_x = x + gg_start_x;
gg_end_y = y + gg_start_y; //  //CONTENTS_PROJECTILE|
gg_end_z = z + gg_start_z;
gg_trace = sys.tracePoint(gg_start, gg_end, CONTENTS_CORPSE|MASK_MONSTERSOLID|CONTENTS_RENDERMODEL, gg_owner);
target = sys.getTraceEntity();
target_class = target.getKey("spawnclass");
//target_health = target.getHealth();
target_name = target.getName();
//sys.print( "Class: " + target_class + "\n" );

if (target_class == "idAFEntity_Generic" || target_class == "idAFEntity_WithAttachedHead" || target_class == "idAI" || target_class == "idPlayer" || target_class == "idExplodingBarrel" || target_class == "idMoveable" || target_class == "idMoveableItem") {
weaponState( "Grab", SOULCUBE_IDLE_TO_SPIN );
}
}
waitFrame();
}
weaponState( "Idle", SOULCUBE_SPIN_TO_IDLE );
}

void weapon_soulcube::Grab() {

float th;
justhurt = 0;
adjustorigin = 0;

weapon_ent = gg_owner.getWeaponEntity();

playAnim( ANIMCHANNEL_ALL, "idle" );

sys.setSpawnArg( "model", "hand_glow_drag.prt" );
sys.setSpawnArg( "origin", target.getOrigin() );
hand_emit = sys.spawn( "func_emitter" );

//startSoundShader( "player_startdrag", SND_CHANNEL_ANY );
startSoundShader( "player_drag", SND_CHANNEL_ANY );


launch_time = (sys.getTime() + GG_LAUNCH_TIME);

if ( target_class == "idAI" || target_class == "idPlayer" ) { //just hurt monsters if their not dead yet
if ( target.getHealth() > 0 ) {
justhurt = 1;
//emit.setOrigin( '0 0 32' );
//startSoundShader( "player_startdrag", SND_CHANNEL_ANY );
playAnim( ANIMCHANNEL_ALL, "idle" );

target.allowMovement( false );
// useAmmo( 5 );
while ( WEAPON_ATTACK ) {
// sys.radiusDamage( target.getOrigin(), self, gg_owner, gg_owner, "damage_oneshot", 1.0 );
th = target.getHealth();

//SHOW THE MONSTERS HEALTH IN THE METERS
// setShaderParm( 2, (th / 750 ));

ftime = sys.getTime() + 0.1; //pain every 0.3 seconds
while ( ftime > current_time ) {
current_time = sys.getTime();
hand_emit.setWorldOrigin(weapon_ent.getJointPos(weapon_ent.getJointHandle( "Barrel" )));
waitFrame();
}
if ( target.getHealth() < 1 ) {
justhurt = 0;
weaponState( "Dragging", 1 );
}
waitFrame();
}
stopSound( SND_CHANNEL_ANY, false );
target.allowMovement( true );
}
}

if ( justhurt != 1 ) {
weaponState( "Dragging", 0 );
}

hand_emit.remove();
weaponState( "Gravity", 4 );
}

void weapon_soulcube::Dragging() {
// ammo_clip = ammoInClip();
// if ( ammo_clip < 1 ) {
// hand_emit.remove();
// weaponState( "Reload", 2 );
// }

dragging = 1;
// weapon_ent.setSkin( "skins/gg_active" );
// useAmmo( 1 );
while ( WEAPON_ATTACK ) { //following math continously calcs hover & captured object positions
gg_start = gg_owner.getWorldOrigin();
gg_owner_size = gg_owner.getSize();
gg_start_z = gg_start_z + (gg_owner_size_z - 6);
gg_angles = gg_owner.getViewAngles();
z_angle = gg_angles_x * -1;
xy_angle = gg_angles_y;
z = sys.sin(z_angle) * GG_HOVER;
e = sys.cos(z_angle) * GG_HOVER;
y = sys.sin(xy_angle) * e;
x = sys.cos(xy_angle) * e;
gg_end_x = x + gg_start_x;
gg_end_y = y + gg_start_y;
if (  target_class == "idAFEntity_WithAttachedHead" || target_class == "idAI" || target_class == "idPlayer" ) {
gg_end_z = z + gg_start_z + 16;
} else {
gg_end_z = z + gg_start_z;
}

target_pos = target.getWorldOrigin();

move_dir = gg_end - target_pos; //direction from captured object towards hover postion
distance = sys.vecLength(move_dir);

setShaderParm( 2, 0.02 + (distance / 60) + sys.random(0.05) );

move_dir = sys.vecNormalize(move_dir);
frac = (distance / GG_HOVER);
target.setLinearVelocity(move_dir * frac * GG_TARGET_SPEED); //move captured object towards hover position

hand_emit.setWorldOrigin(weapon_ent.getJointPos(weapon_ent.getJointHandle( "barrel" )));

if ( BUTTON_ALTFIRE && !isLowered() ) {
stopSound( SND_CHANNEL_ANY, false );
weaponState( "Throw", 0 );
}
waitFrame();
}

current_time = sys.getTime();
setShaderParm( 2, 0.01 );

stopSound( SND_CHANNEL_ANY, false );

waitFrame();
dragging = 0;
hand_emit.remove();
// weapon_ent.setSkin( "" );

weaponState( "Gravity", 4 );
}

void weapon_soulcube::Throw() {

// ammo_clip = ammoInClip();
// if ( ammo_clip < 3 ) {
// stopSound( SND_CHANNEL_ANY, false );
// hand_emit.remove();
// weaponState( "Idle", 2 );
// }
// useAmmo( 3 );

// weapon_ent.setSkin( "" );
hand_emit.remove();
startSoundShader( "player_stopdrag", SND_CHANNEL_ANY );

push_dir = gg_start - target_pos;
push_dir = sys.vecNormalize(push_dir);
playAnim( ANIMCHANNEL_ALL, "Idle" );
if ( target_class == "idExplodingBarrel" || target_class == "idMoveable" || target_class == "idMoveableItem") {
target.setLinearVelocity(push_dir * (GG_LAUNCH_SPEED/20) * -1);
} else {
target.setLinearVelocity(push_dir * (GG_LAUNCH_SPEED/1.5) * -1); //objects such as monsters get a higher speed due to higher mass
}
gg_owner.setLinearVelocity(push_dir * GG_KICKBACK_SPEED);

ftime = sys.getTime() + 1; //hold pain for 1.5 seconds
while ( ftime > current_time ) {
current_time = sys.getTime();
sys.radiusDamage( target.getOrigin(), self, gg_owner, target, "damage_gravitygun", 2.0 );
setShaderParm( 2, 0.01 + sys.random(0.02) );
waitFrame();
}
weaponState( "Gravity", 3 );
}



void weapon_soulcube::Launch() {
launchProjectiles( 1, 0, 0, 1.0, 1.0 );
}

void weapon_soulcube::ExitCinematic() {
weaponState( "Idle", 0 );
}


Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

BielBdeLuna

available without ammo it's done in the player definition file, it should be like weapon_fists


VGames

Well I want the soulcube to use ammo when it's does anything else but the gravity gun stuff.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

BielBdeLuna

so when there is no ammo you still want to be able to use it as gravity gun isn't it? if so you will net to be able to select it and use it, hence the player def file change.

VGames

Anybody got any ideas on how to stop the soulcube from switching to the previous weapon once the fire key is used?
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

VGames

All this awesome E3 Doom stuff has taken over this forum. I need help!!!!!
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

The Happy Friar

The soulcube uses baddie souls as it's ammo and uses them all up when it's fired.  I'd say you need to find out if it is using all those souls for your gravity gun modification &, if it is, tell it to either not use souls for the gravity part or always change the current # of soul ammo to whatever it was before you zoomed in.

The easiest way would be to try using the soulcube after you fire the gravity gun.  If you can't fire then it's using the souls.

There might be an option in the settings to not switch weapons when you run out of ammo.

VGames

No it's not using ammo at all. That's the thing. I have it set up to where it just does the gravity stuff without ammo use. But it does need to have ammo in order to use the gravity feature. I think that's where changes need to be made in the def file like it was suggested. But when I press fire and get out of zoom mode the weapon switches back to the last weapon. And if I switch back to the soulcube it still has ammo. Crazy.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

The Happy Friar

Could you post a zip of all your def/script changes to get the new weapon mode to work?  Maybe someone else could try it and see something you're not.

VGames

The only thing that changed in the def was I added 2 damage definitions. And set them to 0 damage. I don't think that's gonna make a big difference. And then there's some sounds and particle effects for the gravity gun. Making a zip for just the soulcube would be tasking because it would include stuff for the soul knight, pet mod coding in the monster base, and much more. If somebody could just take the stuff from this script that has to do with the gravity feature and add it to the soulcube minus the soul knight stuff that would be much easier. Comment out the damage def calls too. I think it may be an sdk thing but I'm not sure.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

VGames

Could somebody please check this out for me? All you have to is comment out the soul knight stuff and damage def commands.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

VGames

Still no takers? I may have to drop this idea. So sad since there's only one little flaw holding it back.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

VGames

Forgot to mention that I did fix this issue within the SDK. Gravity gun feature is awesome.
Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500