Jump to content


Photo

Making weapons appear as inventory items

code definitions weapons items tools

6 replies to this topic

#1 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 701 posts

Posted 16 February 2018 - 03:55 PM

This question addresses a feature I plan for my cyberpunk extension The Dark Module. It will eventually have an unified inventory, on which every item will be part of the same tool belt.

 

I would like to know how I can combine weapons with item definitions, making them appear and be possible to select from the item browser. Basically I want to make the Blackjack / Sword / Arrows appear in the same inventory list as the Lamp / Compass / Lockpicks / Readables / etc: Just as you select the Lamp item and hit the "use" key to toggle the light, you could select the Sword item and hit the "use" key to select or holster the sword weapon. Obviously you can still activate weapons using their keybinds... although my mod will replace those with a customizable hotbar, which is what this feature is as a starting step for.

 

Technical note 1: I'm aware that weapons are defined differently from player tools, using builtin idTech 4 entries of the form "def_weapon1 atdm:weapon_blackjack". This would obviously not change! What I believe I'm looking for is an additional definition per weapon, which separately creates an item entry for that weapon as well: When you pick up a weapon on the map, the player gets both the normal weapon entry as well as an inventory entry... this entry separately creates an item for that weapon in the player tools list, which activates its weapon when used.

 

Technical note 2: Item dropping would have to be accounted for. If you select a Lockpick for instance, there is a key to hold the item in front of you then drop it to the ground. When doing this with a weapon, dropping the item should of course also unregister the weapon entry and make it unavailable. Obviously the weapon may not be selected while carrying its inventory entry as an item.

 

What is the simplest and cleanest way to achieve this? Can I make the weapon definition register an item directly, or does that have to be a separate entity? If it's the later, how do I make it so that the weapon entity you receive from the map offers both the weapon definition and inventory item to the player simultaneously?



#2 demagogue

demagogue

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 5356 posts

Posted 17 February 2018 - 08:13 PM

There are script functions for arming a weapon, and you can call a script in the .def of inventory items that runs when it's spawned or persistently with the item; you can also call a script when you frob it. So I'd just make a dummy object for the inventory that when you inventory-frob calls that script and the script arms the weapon.

 

Another set of script functions are for inventory management. So you could have maybe a persistent .def script (unless you can figure out how to call a script when you drop an inventory item, which would be preferable) that checks the dummy-weapon-items in your inventory, and when the relevant item isn't in your inventory then it drops the actual weapon. Adding a weapon when you pick up a dummy object is easier since you can call a script by frobbing-to-pick-up, which I believe is how arrows already work anyway.


Posted Image

#3 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 701 posts

Posted 17 February 2018 - 09:15 PM

I believe the cleanest way would be to make the dummy inventory item control the weapon, and have this item be picked up from the map instead of the weapon entity. This inventory item would itself only need 3 calls / features as far as I can tell:

  • When you pick it up, it gives the player the weapon in cause.
  • When you drop it, it removes the weapon from the player.
  • When you use it, it selects the weapon as if you pressed its keybind.

But I don't know how to add this functionality from the item's def. If it's simple, could anyone explain the lines I'd need in order to achieve this?



#4 teh_saccade

teh_saccade

    Advanced Member

  • Member
  • PipPipPip
  • 630 posts

Posted 18 February 2018 - 03:07 AM

Check the script ref on wiki for weapons stuff.

Include keybind for weapon pickup as ready:

http://wiki.thedarkm...title=DEF_Files

"frob action script"

http://wiki.thedarkm...erence#idWeapon

"weaponstate"

/* also "an" is only used before a word that has a hard/glottal U sound. Such as "an umbrella / "an umbered coloured gemstone". If it's a "you" U sound - a is how it goes. "A use key" "Pete's a useless tosser". Not "Pete's AN useless tosser" */

 

As for the inventory stuff, idk about that.
Used the inventory screen once - didn't like it - never used it again.


Edited by teh_saccade, 18 February 2018 - 03:11 AM.


#5 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1476 posts

Posted 18 February 2018 - 05:36 AM

Removing weapons was discussed in this thread. Apparently, you cannot really drop weapons. The only option you seem to have is to disable a specific weapon as soon as the dummy item is dropped and reactivate it, when you pick it up again.



#6 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 701 posts

Posted 18 February 2018 - 09:20 AM

Check the script ref on wiki for weapons stuff.

Include keybind for weapon pickup as ready:

http://wiki.thedarkm...title=DEF_Files

"frob action script"

http://wiki.thedarkm...erence#idWeapon

"weaponstate"

/* also "an" is only used before a word that has a hard/glottal U sound. Such as "an umbrella / "an umbered coloured gemstone". If it's a "you" U sound - a is how it goes. "A use key" "Pete's a useless tosser". Not "Pete's AN useless tosser" */

 

As for the inventory stuff, idk about that.
Used the inventory screen once - didn't like it - never used it again.

 

Thank you very much for the info! So I will use frob_action_script to set the given weapon slot as active, which I assume doesn't interfere with the item being picked up in the process. What I would also need in that case is a drop_script / select_script / deselect_script / use_script for the item... are there any def hooks for calling script functions on this as well please?

 

And don't worry about that: My mod will ultimately have a customizable hotbar, different from the vanilla inventory screen (think Minecraft of DeusEx inventories). I might need to ask other questions when I get there, for now though this is the first step to unifying weapons with other items.

 

Removing weapons was discussed in this thread. Apparently, you cannot really drop weapons. The only option you seem to have is to disable a specific weapon as soon as the dummy item is dropped and reactivate it, when you pick it up again.

 

That's fine: With this model weapon entities are treated as virtual registers, being set and unset only by the dummy item. In fact I'd prefer making it impossible to place the weapon def directly on the map for my original weapons, to avoid any potential mismatches and inconsistencies. This might however require some extra tweaking.



#7 teh_saccade

teh_saccade

    Advanced Member

  • Member
  • PipPipPip
  • 630 posts

Posted 19 February 2018 - 12:41 AM

Not knowing what I'm talking about, I've really no idea how to set about accomplishing what you are trying to achieve. Might be more confusing than anything...

Spoiler


Maybe someone who knows what they're talking about can help more..?

 

 


 
 


Edited by teh_saccade, 19 February 2018 - 12:54 AM.




Reply to this topic



  



Also tagged with one or more of these keywords: code, definitions, weapons, items, tools

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users