Jump to content
The Dark Mod Forums

Making weapons appear as inventory items


MirceaKitsune

Recommended Posts

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?

Link to comment
Share on other sites

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.

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Check the script ref on wiki for weapons stuff.

Include keybind for weapon pickup as ready:

http://wiki.thedarkmod.com/index.php?title=DEF_Files

"frob action script"

http://wiki.thedarkmod.com/index.php?title=TDM_Script_Reference#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
Link to comment
Share on other sites

Check the script ref on wiki for weapons stuff.

Include keybind for weapon pickup as ready:

http://wiki.thedarkmod.com/index.php?title=DEF_Files

 

"frob action script"

 

http://wiki.thedarkmod.com/index.php?title=TDM_Script_Reference#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.

Link to comment
Share on other sites

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...


I only know that the .def frob_script call is there from looking - it's not something I've used nor ever seen anyone else use with regards to a weapon...

 

/* don't forget that any script disabling weapons will need to enableWeapon(); to get it working again, but... it's from the definition script call, so, every time it's picked up it'd have to check it it's disabled... idk that one.

It would be cool to be able to break open locks with a combat knife instead of using picks, but idk how you'd tie that in.

GetDoor, GetLock(); Open(); (idk, it'd have to target the door and lock or something... idk how lockpicks work, but it'd be a case of figuring that out - probably somewhere in the SDK - and changing it so the knife is a weapon as well as a lockpick)

*/

Considering how the other guys have explained how weapons work in TDM, how to drop them, spawn a dupe and all that, I can't think of a reason why calling a script would intefere with the item pickup - unless the script purposefully does so.

Examples of using the .def frob_script for TDM that I might think of:
Some ultimate loot and the .def says to call a script to start a mover to wake and release a bunch of guards and set an alarm state.
Tampering with some wiring for a camera, because a button wasn't pushed to "close" the camera view (eg, closing a small hole in rotating room with guard set peeking through the hole who's gonna trigger an alarm).
Entering or exiting some realm / drugged up state / dream by teleporting the player around the map with some cool effects.
Setting off a timed explosion to destroy some stuff, closing off a tunnel, replacing the skybox and revealing a bunch of debris objects, particles, sounds, etc... and starting or ending a chain of events.

There are easier solutions to all of these, without messing with the .def stuff - I'd reckon that everything would have to be scripted, and it'd probably end up being fairly complicated considering the dependencies and calls required.

There's:

 

scriptEvent entity getGrabbed(); (to target entity currently in grabber) scriptEvent float isDroppable(); (player - is item droppable?) or scriptEvent void setDroppable(float droppable); (when item picked up - can be dropped?) scriptEvent float holdEntity(entity entity); (force player to "grab", dropping current item - wonder what would happen if the equipped item wasn't droppable and this was used..?)

Might help with figuring some way to deselect a held item or force it to be dropped or "deselected" by being replaced with $null_entity, by using holdEntity. Would have to figure a way of tying that into the "hotkey" press (it would be really nice to be able to simply press the same button to put away the weapon in TDM, but there's the "clear weapon/inventory" buttons instead (I use ` and ¦ or backspace for those, or tap "1" and scrollwheel down to holster - can be annoying if "1" is the sword cos it increases visability for a moment).

 

 

Wrt to weapons:

scriptEvent void selectWeapon(string weapon); (player, selects weapon to be held - this entry is duplicated in script reference, use the 2nd entry)
(
$player1.selectWeapon(s);

where 's' is one of these strings:

"unarmed" "blackjack" "shortsword" "broadhead" "waterarrow" "firearrow" "ropearrow" "gasarrow" "noisemaker" "mossarrow" "vinearrow")

 

Guess that something like this might be a "use" script..?

scriptEvent void activate(entity activator); (activates as trigger, like the brush - idk if there can be another use) scriptEvent void activateTargets(entity activator); (same as before but for multiples)

 

For "select", idk...

scriptEvent entity setCurInvItem(string itemName); (don't understand this one, but states it does something with inventory pointing)

Maybe it'd be easier to steal the definitions of the closest matching weapon in TDM, cos the scripts target those things already... and... thing is - it's gonna run this script every time the weapon is picked up. So there's probably a lot to take into account that someone who is involved with that knows about.

Idk if you can make a .def call more than one script, but there's no reason why a single script can't catch everything.

It's just gonna be a pain in the arse to figure out and be mammoth scripting - the script reference page is not pretty to look at and doesn't explain much, so it's a case of trying stuff out until it kind of does what you want, or you figure out another way of doing it, I guess. But it's your best bet, I reckon...
That's why I prefer to work with "mechanical" solutions using the most basic scripts that I can figure.

I'm only a lowly artist who gets roped into making puzzles and comes up with ideas, narrative and design that occasionally work, plus BVT/QA if there's nothing else.
It helps sometimes to speculate why something fails or works in a report.

Until it's built, idk jack til someone who knows jack figures it out and the new test lets me know what the difference was that means it works now.



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

 



Edited by teh_saccade
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • Ansome

      Finally got my PC back from the shop after my SSD got corrupted a week ago and damaged my motherboard. Scary stuff, but thank goodness it happened right after two months of FM development instead of wiping all my work before I could release it. New SSD, repaired Motherboard and BIOS, and we're ready to start working on my second FM with some added version control in the cloud just to be safe!
      · 0 replies
    • Petike the Taffer  »  DeTeEff

      I've updated the articles for your FMs and your author category at the wiki. Your newer nickname (DeTeEff) now comes first, and the one in parentheses is your older nickname (Fieldmedic). Just to avoid confusing people who played your FMs years ago and remember your older nickname. I've added a wiki article for your latest FM, Who Watches the Watcher?, as part of my current updating efforts. Unless I overlooked something, you have five different FMs so far.
      · 0 replies
    • Petike the Taffer

      I've finally managed to log in to The Dark Mod Wiki. I'm back in the saddle and before the holidays start in full, I'll be adding a few new FM articles and doing other updates. Written in Stone is already done.
      · 4 replies
    • nbohr1more

      TDM 15th Anniversary Contest is now active! Please declare your participation: https://forums.thedarkmod.com/index.php?/topic/22413-the-dark-mod-15th-anniversary-contest-entry-thread/
       
      · 0 replies
    • JackFarmer

      @TheUnbeholden
      You cannot receive PMs. Could you please be so kind and check your mailbox if it is full (or maybe you switched off the function)?
      · 1 reply
×
×
  • Create New...