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

Secondary weapon firing on RMB - how?

Started by motorsep, May 11, 2015, 12:03:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

motorsep

Has anyone implemented such thing as firing secondary weapon with RMB ?

For example, keys 1 - 4 would select primary weapon, which needs to be fired with LMB (or whatever key it's bound to) and keys 5 - 0 would select secondary weapon, which will be fired with RMB (or whatever key it's bound to). Of course keys for weapon selection may vary.

How would you do that? Thanks.

BielBdeLuna

irc there was a mod with akimbo pistols. You need to either create  a model with two weapons, or code a second weapon appearing,  either way you need to implement a c++ variable for a "shoot2" flag that the script uses to start the process and the  animation.

motorsep

Right, but akimbo pistols mod use the same ammo. Technically it's the same weapon, just shoots from another bone when RMB is pressed.

I am after selecting pistol for LMB, and rocket launcher for RMB. Two entirely different weapons and ammo for each of the mouse buttons. Plus some weapons can be only on LMB, and some only on RMB.

BielBdeLuna

then you need to create this other weapon in C++ so the player holds two different weapons, and also because then you need to link the player input to two separated entities, that way you can change the weapons with any combination, I guess you have to copy all the weapon code in the player to a "weapon2" it doesn't seem too complicated, maybe the most complicated is to establish weapon2 in the same space as 1's so you mask it out correctly (the idea of v_weapons not appearing in third person and all that)

motorsep

#4
Care to give it a spin and test the waters? :)

Actually it's gotta be much more simple - secondary weapons will be standard Doom 3 weapons. Primary weapon will never have any raise/lower anims. And it will be strictly 3-rd person view. So technically it's just shooting a weapon with _impulse bound to LMB, and standard weapons are bound to RMB.

BielBdeLuna

#5
"will"? what?

so primary it's like a predator's shoulder mounted laser gun thing? and the v_weapon is the secondary?

then you might not need c++ at all although this all could be solved in c++ and free up script memory for more simpler scripts (less script loops, although c++ weapons animations (as all idtech4 animations) use script loops under the hoods, but I don't known if those are more optimized by the c++ compiler).
Anyway this all can be done via c++ or idtech4 script:

You can save a scriptobject reference of the over_the_shoulder_cannon_thingy entity and call it (in order to shoot it) via the player script

create a new reference for the new button in the defs (like the old script for iron-sights (only this time changing the actual button to the one you want to use))

then you attach this new entity (it can be a func_mover along with a ase model attached to it or whatever entity you want to use that is script controllable) with scripts to a bone from the player, any entity can call it's own scriptobject the degree of control of it's script over the entity itself depends on the entity, for a script object to be initiated you have to have a specific set of creator functions and destructor functions, those are named in the entity.cpp (and now I cannot remember their names)

you basically call from the player script the function that makes it shoot inside it's own entity scriptobject (somewhat how the player reloads the weapon, I think it's the "net reload" script function not the normal reloading)

and you make an idling state in the scriptobject of the cannon, and a shoot state, and you're set, you know the usual drill for weapon scripts.

in d3 I've only seen this in the specific case of the net_reload, a function in the scriptobject of the weapon that gets called from the player scriptobject

idtech4 scripts scriptsobejcts are not objects like the ones you can find in java or python, you have to create the entity first (script objects get associated only to existing entities and are called by the def) you can't initiate a scriptobject via code but you can create the entity via code and it will start it own script object, only once the entity exists there is a way to reference it's scriptobject  by referencing the entity itself, and so, work in tandem with it.

so bear in mind, scriptiobjects ACT LIKE objects but scriptobjects ARE NOT objects, idtech4 scripts is an object-less script language.

BloodRayne

#6
Quote from: BielBdeLuna on May 11, 2015, 05:54:58 PM
so bear in mind, scriptiobjects ACT LIKE objects but scriptobjects ARE NOT objects, idtech4 scripts is an object-less script language.

lolwut? :P

Of course there are objects. :)

They have functions, and methods and properties and values and events... There are objects like player and weapon and any sort of entity is an object. Some of those have script states and others do not, it depends on what underlying objects they inherit from, as programmed in the SDK/gamecode.

motorsep

I am thinking it's gotta be easier than explanation sounds :)

I was thinking just have an _impluseX calling a function that shoots (or rather uses a weapon script I guess). I suppose the issue is how to make weapons shoot from different bones, and not from "barrel" bone only.

Example would be a hovertank in Steel Storm - miniguns have their own bone, rockets - another, homing missiles - yet another, etc. While in Doom 3 all weapons have the same shooting bone.

The Happy Friar

All weapons do have their own bone but it can be changed for each weapon.  I'd figure there's no reason to not just have 3rd person weapons that have a simple invisible model & just have the bones be in the places you want to fire from.

I thought there was a tutorial in D3W that told how to make a projectile spawn & fly like a weapon fired it.  Maybe it was even Bloodrayne who wrote it, I don't remember. 

BielBdeLuna

Quote from: BloodRayne on May 13, 2015, 01:33:27 PM

lolwut? :P

Of course there are objects. :)

They have functions, and methods and properties and values and events... There are objects like player and weapon and any sort of entity is an object. Some of those have script states and others do not, it depends on what underlying objects they inherit from, as programmed in the SDK/gamecode.

you can't initiate an object from a class that doesn't depend on an entity, you can create a class you can create an object of the type class you created, but once you try to call it's functions it won't respond

in fact there isn't a single object in d3 script that is initiated in script code all objectscripts are initiated in c++ code or def files

BloodRayne

Quote from: BielBdeLuna on May 14, 2015, 12:06:04 AM
Quote from: BloodRayne on May 13, 2015, 01:33:27 PM

lolwut? :P

Of course there are objects. :)

They have functions, and methods and properties and values and events... There are objects like player and weapon and any sort of entity is an object. Some of those have script states and others do not, it depends on what underlying objects they inherit from, as programmed in the SDK/gamecode.

you can't initiate an object from a class that doesn't depend on an entity, you can create a class you can create an object of the type class you created, but once you try to call it's functions it won't respond

in fact there isn't a single object in d3 script that is initiated in script code all objectscripts are initiated in c++ code or def files

I don't want to attack you, but what you are saying is nonsense.

You said 'there are no objects in idtech4 script, idtech4 script is object-less'.

That is simply not true, whether objects are instantiated in C++ or not is irrelevant. Everything is instantiated in C++, idtecht4 script isn't a base programming language, so yeah.. everything 'happens' in C++.

But you still have all those objects available in your scripts, so to call idtech4 script object-less is nonsense.

BloodRayne

#11
Quote from: motorsep on May 13, 2015, 02:47:42 PM
I am thinking it's gotta be easier than explanation sounds :)

I was thinking just have an _impluseX calling a function that shoots (or rather uses a weapon script I guess). I suppose the issue is how to make weapons shoot from different bones, and not from "barrel" bone only.

Example would be a hovertank in Steel Storm - miniguns have their own bone, rockets - another, homing missiles - yet another, etc. While in Doom 3 all weapons have the same shooting bone.

You seem to have some challenges here. :)

The most clean and beautiful option is to instantiate another Weapon Object for your player in the gamecode, but that is very invasive, it'll take you a couple of hours of coding to make sure all the nitty gritty like savegames and loading works. Then you have to animate weapons to be on the other hand etc..

You can instantiate a project entity (object , wink wink Biel) and then move it to any bone, prior to launching it. I do the same in Grimm Quest for the Gatherer's key where I've added alt-fire. It also allows for different kind of projectiles and trajectories so Grimm's alt-firing mechanism is very robust and extremely simple (just a couple of code changes in the SDK).

Really, go and check out Grimm's codebase. So much of your requests that I see popping by have been solved in that code that it's a waste not to look at it. ;)

motorsep

Quote from: BloodRayne on May 14, 2015, 04:10:03 AM
The most clean and beautiful option is to instantiate another Weapon Object for your player in the gamecode, but that is very invasive, it'll take you a couple of hours of coding to make sure all the nitty gritty like savegames and loading works. Then you have to animate weapons to be on the other hand etc..

I think it would have to be the case for 1st person view dual wielding weapons. I am not sure about couple of hours of work - there is only one game that does it - Borderlands 2. So I am sure it's not as trivial to implement as it might appear at first :)

For third person view where character is tank, we can get away with player model having all weapons mounted on it already.

Quote from: BloodRayne on May 14, 2015, 04:10:03 AM
You can instantiate a project entity (object , wink wink Biel) and then move it to any bone, prior to launching it. I do the same in Grimm Quest for the Gatherer's key where I've added alt-fire. It also allows for different kind of projectiles and trajectories so Grimm's alt-firing mechanism is very robust and extremely simple (just a couple of code changes in the SDK).
Really, go and check out Grimm's codebase. So much of your requests that I see popping by have been solved in that code that it's a waste not to look at it. ;)

Well, if you could post short how-to here, it would be awesome ;)  (or at least where in the code you have alt-firing functionality and how it's hooked up in the scripts)

Thanks!

BielBdeLuna

BloodRayne I don't know why would you want to "attack" me because you disagree with me.

what you are suggesting is to spawn a weapon entity and save it in a variable, and so you reference that variable in order to use it, you can attach the weapon entity to any bone and you can control it via scripts, isn't it?

is there a way to initiate and use an object within scripting without using any entity? that would be very useful for AI!

BloodRayne

Quote from: motorsep on May 14, 2015, 10:10:39 AM
Quote from: BloodRayne on May 14, 2015, 04:10:03 AM
The most clean and beautiful option is to instantiate another Weapon Object for your player in the gamecode, but that is very invasive, it'll take you a couple of hours of coding to make sure all the nitty gritty like savegames and loading works. Then you have to animate weapons to be on the other hand etc..

I think it would have to be the case for 1st person view dual wielding weapons. I am not sure about couple of hours of work - there is only one game that does it - Borderlands 2. So I am sure it's not as trivial to implement as it might appear at first :)

For third person view where character is tank, we can get away with player model having all weapons mounted on it already.

Quote from: BloodRayne on May 14, 2015, 04:10:03 AM
You can instantiate a project entity (object , wink wink Biel) and then move it to any bone, prior to launching it. I do the same in Grimm Quest for the Gatherer's key where I've added alt-fire. It also allows for different kind of projectiles and trajectories so Grimm's alt-firing mechanism is very robust and extremely simple (just a couple of code changes in the SDK).
Really, go and check out Grimm's codebase. So much of your requests that I see popping by have been solved in that code that it's a waste not to look at it. ;)

Well, if you could post short how-to here, it would be awesome ;)  (or at least where in the code you have alt-firing functionality and how it's hooked up in the scripts)

Thanks!

Quote from: BielBdeLuna on May 14, 2015, 08:36:49 PM
BloodRayne I don't know why would you want to "attack" me because you disagree with me.

what you are suggesting is to spawn a weapon entity and save it in a variable, and so you reference that variable in order to use it, you can attach the weapon entity to any bone and you can control it via scripts, isn't it?

is there a way to initiate and use an object within scripting without using any entity? that would be very useful for AI!

Not the weapon but the projectile. :)
Basically you add an impulse in the SDK, then when that impulse is called, and create an event on the weapon object called alt_fire. Then in the weapon script, catch that event.

note: You can also do this without the impulse and SDK code, but it's dirtier, by either replacing your weapon_reload code to use it as alt_fire, or watch for a button press in script via a loop in the weapon code, by accessing player1's buttons or a console variable (bind a key to toggle a consolevar, then check the variable in a loop).

Add a simple extra projectile definition in your weapon def, e.g.:

   "def_projectile"         "projectile_cannonBall"
   "def_altprojectile"         "projectile_cannonBall_small"

In the alt_fire event, set it's worldorigin to the bone you want to launch from: projectile.setWorldOrigin(), entity_weapon.getJointPos(string weapon joint want to get the position of)
The projectile will then travel from the point you moved it to.