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

"Use" feature

Started by Cyber8, June 12, 2017, 08:02:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Cyber8

Hello everyone, as we know, Doom 3 uses fancy GUIs to make player interact with environment. It doesn't feature the [Press "key" to use].
I want to make that feature, however I don't fully know the structure of Doom 3 files. I don't know where to start, where that feature should be added.
The player must simply approach, point at the brush, press the "key" and the brush will do it's func. For now setting the "key" would be under "bind" command.
I just want to ask, where do I add the custom trigger option?

argoon

There's only Three ways you can accomplish this that i found out:

1 - Script it from scratch using the tracing of rays ability from the scripting system, works like a charm and that was what i did.

2 - Use invisible world GUI's over the objects, that is the easiest and fastest way but looks strange, was something some did before tho.

3 - Edit the source code of the game and engine it self, look into the player.cpp file to see how they did the mouse over functionality for when the player interacts with characters in the game, search for "talk cursor" the "impulse" and "buttons", are also very important is the way doom calls keyboard and mouse key presses, impulses are single fire, buttons fire for how long you keep the key pressed. 

Cyber8

Seems like making a script is a reasonable way, I've seen the GUI technique, but having fire button to interact is way out of place.
So If I make use.script and include it in doom_main.script, I should be able to interact with brushes with basic func's. (correct me if I miss something)
Do you mind If I could take a look on your script?

argoon

Quote from: Cyber8 on June 14, 2017, 10:43:59 AM
Seems like making a script is a reasonable way, I've seen the GUI technique, but having fire button to interact is way out of place.
So If I make use.script and include it in doom_main.script, I should be able to interact with brushes with basic func's. (correct me if I miss something)
Do you mind If I could take a look on your script?

Unfortunately you don't have much choice about what keys you use for things you script, because only buttons (so no impulses) are available for scripting and even on those only a small subset works, idtech 4 is not like UE4 or Unity3D where you can do everything only using scripting, on this engine some things do require messing with the source code.

About my script i will post it below, more or less complete, some code is custom functions made by me or #defines written at the top of the script, for example giveButtons(useBtn, "btn0"),  isA(x) or isAClass(x), are not idtech 4 existent script functions, they are custom made by me, if you know how to code and you have some basic knowledge of id script commands is not hard to come with your own.

Btw you can see the humble beginnings of this code on this thread, is not the exact code but show how it all started.




#define USE_BTN giveButtons(useBtn, "btn0")


/*
====================
player::detectFrobableEnt
====================
*/
void player::detectFrobableEnt() {
    entity frobEntity;

// Get player Location - do not use "self" because it will get the thirdperson player model location instead
vector plWorldLoc = $player1.getWorldOrigin();

vector viewOffset = $player1.getSize();

viewOffset_x = 0;
viewOffset_y = 0;
viewOffset_z -= 6;


vector startPLVec = plWorldLoc + viewOffset;
vector plFowardVec = sys.angToForward( $player1.getViewAngles() );
vector endPLVec = $player1.getWorldOrigin() + viewOffset + ( plFowardVec * 80.0f);


//sys.debugArrow('1 0 0', startPLVec, endPLVec, 4, 0.05); // (color, start vec, end vec, , visibility time)
sys.trace( startPLVec, endPLVec, '0 0 0','0 0 0', MASK_ALL , $player1 );
frobEntity = sys.getTraceEntity();
isFrobable = frobEntity.getIntKey("frob");
    if ( !isFrobable || frobEntity == $null_entity )
{
               FROBBING = false;
}
    if ( isFrobable && frobEntity != $null_entity )
{
                frobable_entity = frobEntity;
FrobEntName = frobable_entity.getName();
                FROBBING = true;
}
if ( FROBBING )
{
frobable_entity.callFunction( "frobOn" );

// This is to prevent the frobing action to run more than once
// at btn press
if(!USE_BTN)
{
btnState = STATE_BUTTON_UP;
}

playerCMD();

}
if ( !FROBBING )
{
frobable_entity.callFunction("frobOff");
}
}

/*
==================
player::frobUpdate
==================
*/
void player::frobUpdate() {

while( LoopON ) {

detectFrobableEnt();

sys.waitFrame();
}
}



void player::frob_init(){
sys.waitFrame(); // wait for init() routines to finish

    thread frobUpdate();
}


void player::playerCMD()
{

if(playercmdON)
{
useBtn = $player1.getButtons();

if( isA(frobable_entity) == "func_swing_door" || isA(frobable_entity) == "func_door"  )
{  // NOTE: - || (or) && (and) only work with boolean expressions like: this == this or !this
if( USE_BTN && btnState == STATE_BUTTON_UP )
{
btnState = STATE_BUTTON_DOWN;

frobable_entity.callFunction("signalOn");
}
}
if (isAClass(frobable_entity) == "idItem" || isAClass(frobable_entity) == "idMoveableItem")
{
if ( USE_BTN && btnState == STATE_BUTTON_UP && btnState != STATE_BUTTON_DOWN )
{
btnState = STATE_BUTTON_DOWN;
frobable_entity.callFunction( "putNameInSlot" );
//sys.println("i picked up the key!!!!!");
}
}

}
}

The Happy Friar

Since switches/buttons are triggers, and you CAN run a script from a bound key, shouldn't making all your switches/buttons respond only to non-player/monster entities & making it so you have a trigger box bound to the front of the player that is unhidden/hidden via script via bound key press work?  Would require nothing fancy, just the design of the level.  A trigger could even be bound to the player via the map editor.  I did similar in my old mod with the grenade that would give the player health when blown up in your hand.

It wouldn't work with existing GUI setup, but no other presented way would either, right?

Quote from: argoon on June 15, 2017, 04:08:19 PM
Unfortunately you don't have much choice about what keys you use for things you script, because only buttons (so no impulses) are available for scripting and even on those only a small subset works, idtech 4 is not like UE4 or Unity3D where you can do everything only using scripting, on this engine some things do require messing with the source code.

To be fair D3 tech is from 2004 and no other AAA engine at the time let you modify as much as D3 tech did w/o moding code.