id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Scripting => Topic started by: bitterman on February 12, 2017, 12:06:11 PM

Title: Inventory
Post by: bitterman on February 12, 2017, 12:06:11 PM
Is there a manual about how to work with inventory?

Some info placed here but seems like it's for TDM only and based on addition C++ code.

http://wiki.thedarkmod.com/index.php?title=Inventory (http://wiki.thedarkmod.com/index.php?title=Inventory)

In D3 I can place some model on the map, set key "inv_name" and triggered some action with it.

But how organized info about items in inventory and how to works with it via scripts (for vanilla D3)?

Thanks.
Title: Re: Inventory
Post by: argoon on February 12, 2017, 02:21:56 PM
Edit:  Realized just now that you made the Debug HUD thread so you already know most of this stuff!  *facepalm  Oh well it doesn't hurt to have this here for others.

Yes in here (https://modwiki.xnet.fi/GUI_scripting) and here (https://www.iddevnet.com/quake4/GUIEditor), the quake 4 one has some commands that don't work on idtech 4 based on Doom 3, is really a trial and error but i can say that "stoptransitions " only work on Quake 4.

btw I'm more or less stuck on that as well, it seams Doom 3 inventory is hardcoded, for example i tried to use the battery definition that comes with doom 3, to have a functional battery in game but it seams id never made the c++ code necessary to support batteries, by the def existence, they tested that, perhaps for the flashlight but then removed the code and went with a weapon based flashlight, using that def i only get a error on the console.

After have said that i think it IS possible to do a script based inventory, this is what i think one should do:

Make gui for the inventory, make a ingame model to attach that gui to (with a model def or on the editor), using the key/val par:

key - gui
val - guis/gui_name.gui


To change values on the gui, using a script or a trigger, you need to go trough the model where that gui is defined:

the cmd for that is:

1- in the GUI inside a WindowDef you first need to make a special key/val  for example:


windowDef TextItemName
{
rect 10,5,50,10
visible 1
text "gui::foo" // gui::valueName, valuename can be anything is just a pointer/placeholder for the value - afaik valueName must be unique between parm's but i could be wrong
textalign 0       // or texalign "gui::valueName"
textscale 0.15
font "fonts/micro"
}


update 1 - gui::valueName can be used in logic operations, for example:

if ("gui::player_armor"  <= 0) {
set "Lines1::visible" "0" ;
set "Lines1_1::visible" "1" ;
}


2 - Then use in a script -> $gameObject.setGuiParm("foo","bar"); // foo initial parm value -> bar new parm value


To change values on the GUI directly you use:


// onEvent runs every frame, carefull
onEvent
{
set "TextItemName::text" "foo" ;
}



OnNamedEvent  // this seams to be called from the c++ code, didn't found a way, for now, to use this from script or even run this directly from the GUI cmd's like onAction.


Use the normal GUI cmd's for example.


windowDef inventory_slot
{
rect 0,0,77,66
visible 1
background "guis/assets/pda/inventory/inventory_slot"
matcolor 1,1,1,1
float "numbON" 1
//notime 1

onMouseEnter
{
                                               // highlights the button
                                               transition "numb::matcolor" "1 1 1 1" "0.6 0.7 0.7 1" "1000";
}

onMouseExit
{
                                               // un-highlights the button
transition "numb::matcolor" "0.6 0.7 0.7 1" "1 1 1 1" "1000";
}

onAction
{
//set "cmd" "play guisounds_menuclickup" ; // this is not working but seams to be supported by the Doom 3 GUI system!

localSound guisounds_menuclickup; // this works

if ( "inventory_slot::numbON" == 1 )
{
set "numb::visible" "0";
set "inventory_slot::numbON" "0";
set "TextItemName::text" "foo"
}
if ( "inventory_slot::numbON" == 0 )
{
set "numb::visible" "1";
set "inventory_slot::numbON" "1";
set "TextItemName::text" "bar"
}
}

Title: Re: Inventory
Post by: argoon on February 12, 2017, 06:06:53 PM
I also realized that you are not talking of the GUI per se but how to handle player inventory items?

If so, personally i don't know much about it, i do know that you can use editor special entity def's, like target_give, func_itemremove, i now that you can also define new items, on the items.def, but afaik they need to be based around existent ones, because also afaik item properties are hardcoded on the c++ code, that is why the Battery item that i talked above, even tho defined in the items.def file, doesn't work.

btw aren't items also Entities, so anything that applies to entities should also apply to items?
Title: Re: Inventory
Post by: The Happy Friar on February 13, 2017, 08:38:21 AM
The only experience with inventory items in stock D3 I've had is they're used like a key: the player needs item X to access thing Y, a script checks to see if player has X.  If he does, Y is accessed, if not, the player is told you need X.
I'm not familiar with TDM's inventory system but I know stock D3 doesn't have a system like Quake 2 or 3, where you can pick things up & later use them.
Well, it kind of does: the weapon system is like that, so if you added more weapons via script/C you could select & use them, or you could replace current weapons with something not for offensive purposes (like something to drop a mine, activate a shield, give health, etc).
Title: Re: Inventory
Post by: motorsep on February 13, 2017, 10:52:35 AM
In RoE you can store power cell and use it later.
Title: Re: Inventory
Post by: argoon on February 13, 2017, 05:43:29 PM
Quote from: The Happy Friar on February 13, 2017, 08:38:21 AM
... stock D3 doesn't have a system like Quake 2 or 3, where you can pick things up & later use them...

Isn't the parm "inv_carry" in items for that?

This is what it says: if set to 1, is carried as opposed to instant use


Title: Re: Inventory
Post by: The Happy Friar on February 13, 2017, 10:28:12 PM
I believe that's how the power cell motorsep is referring to works in ROE.  I still think the power cell is used via scripts though, I haven't played ROE in a while.
Instant use would be health, a key would be carried.
Title: Re: Inventory
Post by: bitterman on February 15, 2017, 10:42:09 AM
Thanks for info.

The base concept (as I think now):

P.S. Also I see other interesting things (e.g. inv_text, inv_id) but looks like this is unrealized features.
Title: Re: Inventory
Post by: The Happy Friar on February 15, 2017, 12:54:35 PM
good chance it's used in RoE, Q4 or Prey.  stock D3 seemed to have stuff for all three scattered about but never used/finished in the original game dll.
Title: Re: Inventory
Post by: bitterman on February 21, 2017, 11:09:49 AM
So we have array of items. Each of item is accessible from gui script via "gui::inv_name_n" (from "inv_name_0" to "inv_name_19", but not tested yet).

Current number of items is placed in "inv_count" (and can be read via "gui::inv_count").
Title: Re: Inventory
Post by: bitterman on February 25, 2017, 08:55:58 AM
Now I try to work with items from map and scripts.

First pretender is func_itemremove. I just placed this func on the map and set key "remove". But seems like it doesn't works. I can put item in inv_name_0 then touch func but there is no reaction. I still see item in PDA. What's wrong?

Perhaps I must refresh windowDef witch contain inv_name_0 in PDA, but how?

In Code I see:
#ifdef _D3XP
EVENT GiveInventoryItem/RemoveInventoryItem


How to know is current exe was compiled with this key?

*************** upd

Ok I set trigger and targeteg it with func_itemremove. Trigger is working but item is still shown in PDA.
Title: Re: Inventory
Post by: bitterman on February 28, 2017, 10:18:19 AM
func_itemremove works with 'inv_name' key, not 'name'.
Title: Re: Inventory
Post by: argoon on March 26, 2017, 09:27:44 AM
Bitterman thank you for your experiments and posting detail images of your findings they will certainly help.

Today working on a complex "swingdoor" i reached a spot where i need to work with inventory items, for keys and required inventory items, from my limited studies, to be able to detect those item's from the player character you need to assign some reference to them on the player def file, and use $player1.getKey(keyname), the problem is how do you assign a item to the player at run time using this method?
Perhaps setKey will do? It doesn't change the behavior of the entity at run time because spawn arguments only run at spawn time, but at lest you can change the value and use that change with getkey again, in this way you spawn with no key for a door "key = null" at run time change the value using setkey to "key = inv_name",  retrieve that new value with getkey and use that to open or close the door. 
This ability afaik is already built on the func_door entity from Doom 3 but i don't know if it works automatically i have yet to test this on it.

So this is what i gathered till now i'm still to find or think of a way to detect them directly from the player inventory from script, something like the c++ function FindInventoryItem you showed above, saying this i realized many functions we need exist but aren't exposed to the script, fortunately many can be replicated on the script side.

I know is possible to expose them to script relatively easy but that requires you to compile the source code, and at lest for me my tries coding on the c++ side ended in disaster till now, is much more complex, i hit barriers and frustration much faster and crash the engine very easily, just by changing or adding some small stuff, i don't blame the (fhdoom) engine of course but my lack of knowledge on c++ coding, my lack of knowledge how the code is structured and how the engine parts are really interconnected, compared to that scripting is so much easier at lest to a person like me with limited coding experience.
Title: Re: Inventory
Post by: bitterman on March 26, 2017, 10:57:16 AM
Try to use trigger with key/val 'requires' 'key_name' and 'remove' '1' (or something like).
It works only if required item present in inventory and then remove it from inventory.
Title: Re: Inventory
Post by: argoon on March 26, 2017, 12:54:22 PM
Thanks i will try that but my swingDoor is not based on the normal func_door but on a func_mover (with some complex scripting in the mix) because only those have the rotation functions ability built in, don't know if it has the required c++ code for that to work, from my source code readings i do know that both func_door and func_mover inherent from mover_binary but func_door has plenty more code on it.
Title: Re: Inventory
Post by: The Happy Friar on March 27, 2017, 11:59:25 AM
Swinging doors are awesome!  :)  I did one here a while ago:
http://www.sterlingshield.net/home/steve/doom3/july05.html

Here's an idea that might work very well for you & your door:
still use a func_door but have it very fast & transparent (make sure it's still solid).  Have it locked with the key.  Keep it blocking your swing door so you can't access the swing door w/o opening the func_door. 
Now, do your key/lock with the func_door (which supports keys) & when you have the key have it open really really fast, then you can access the swing door.  :)

It's easier then doing scripting to check manually.
Title: Re: Inventory
Post by: argoon on March 27, 2017, 03:15:05 PM
Quote from: The Happy Friar on March 27, 2017, 11:59:25 AM
Swinging doors are awesome!  :)  I did one here a while ago:
http://www.sterlingshield.net/home/steve/doom3/july05.html

Here's an idea that might work very well for you & your door:
still use a func_door but have it very fast & transparent (make sure it's still solid).  Have it locked with the key.  Keep it blocking your swing door so you can't access the swing door w/o opening the func_door. 
Now, do your key/lock with the func_door (which supports keys) & when you have the key have it open really really fast, then you can access the swing door.  :)

It's easier then doing scripting to check manually.

That is a nice work around indeed! Nice thinking outside the box. :)   

My swingDoors are working for the most part, i can open and close them and they play sounds just like the func_door ones, only the key, and required item in player inventory functionality is missing but i'm working on it, btw is missing key functionality at lest to open closed doors at run time, because i coded the ability for my doors to be closed at spawn time, i will try both of your suggestions and see how they work with my interaction system, i don't use trigger boxes or GUI surfaces to open doors like Doom 3 did, i do it like TDM does by "frobbing" or mouse hovering the door, need to see if the invisible func_door will not mess with the mouse trace, at lest for now i need it to detect the correct door for the texture highlight to work.