Jump to content

Add a function to a tool/weapon


joordann

Recommended Posts

Hi,

 

So i was playing with my burglar yesterday and i came across a barricaded door, i wanted to enter that said door but i didnt have a hammer, only a CROWBAR, which i could use it to take the planks of something irl but i could'nt for some reason in the game.

 

And then i had an idea: Let make a mod!

 

I was looking trough out the files trying to find the expecific file or line to make a .lua script and add the function to the crowbar in game, but i could'nt.

 

So i was wondering if someone out there can tell me how the hell can i do that?

 

A simple as add a function to something is making my head hurt, im not too familiar with lua or java, but i have SOME xp in programming.

 

So please, help me.

 

I just need to add the ability to unbarricade stuff with a crowbar and nothing more :(

 

Thanks and sorry if my english is a bit broken, its not my first language!

 

(allready read some tutorials i found but i coud'nt find the how to add function to itens like this)

(also, thanks again :) )

 

Link to comment
Share on other sites

Here you go...

 

If you're holding a Hammer or Crowbar it will use what is in your hand.

If you are holding nothing, it will look for Crowbar first... then Hammer.

 

 

Workshop id=2010986515
Mod id=Crowbar2UnBarricade

 

 

preview.png

Edited by Arsenal26
Link to comment
Share on other sites

3 hours ago, joordann said:

Thanks a lot Arsenal! I was trying to do that mod for some time!

i guess ill let this typo of thing for professionals :D

 

LOL... i'm such a noob at modding its embarrassing... :unsure:

 

Anyways, I made the mod last night after reading your post and uploaded to see if it worked... but the title of your thread was "how to do that" so here's what I figured out during that 20 minutes of poking around... (took longer to find that picture of the guy prying a plank)

 

First of all, we are not adding a FUNCTION to a TOOL... because the function already existed which is unbarricade... We merely added a TOOL to the FUNCTION.

 

In the timed action ISUnbarricadeAction, the isValid function kicks you out if you don't have a Hammer or Stone Hammer... so I just added the Crowbar there...

 

In the ISWorldContextMenu.lua  it only shows the option to Unbarricade if "hasHammer" is true... So since we did not want to be able to use the Crowbar to Barricade (install planks) and only Unbarricade (remove planks), I added a new check in in the ISWorldObjectContextMenu function for "hasCrowbar" so as not to affect everything else that checked for "hasHammer". I don't think we wanted to be able to hammer nails with a Crowbar right ?

 

Next we find each instance where Unbarricade is made visible in the context menu, and add the check for "hasCrowbar"....

in this case, (3) instances existed :

  - if not IgnoreObject

  - if window ~= nil

  - if door ~= nil

 

And finally, the function ISWorldObjectContextMenu.onUnbarricade has all the logic to determine what ends up in your PrimaryHandItem... I added a check to not automatically equip a hammer every time if you are holding a Crowbar, and visa versa... Previously, it just always equipped either of the (2) possible hammers.

 

So that's how we added a TOOL to this FUNCTION...

 

Admittedly, I did it the Caveman way by replacing the whole vanilla file instead of making the changes in a more elegant way.... But I think we can agree that this should just be in the base game.... So I didn't waste too much more brain juice on it other than to see if it worked...

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...