Jump to content

Recommended Posts

I'm quite new to modding (and to forums) so I'm not quite certain where to begin. For now I'm just editing someone else's mod for personal use only.

What I've learned so far is that when you create a weapon (or tool) you also are able to set it's range.
What I'd like to know is if you can change this variable for a single character.

For a quick example: Say I want my character's reach to be 90% of default. I want this to affect collecting materials like grass all the way to chopping a tree or hitting a spider (with or without a weapon).

I also need this to be compatible with other mods like the growing sword mod which has a default reach of 1.05 and a boost of about 1.365.

If you're dealing with existing mod files, you can make one check during the creation function of the tool in question that asks, is the inst (or however you reference the current character in your context) the character that I want? If so, do some function that puts in a different number for the range. The issue with this however will be that the change will be applied to the tool itself and not limited to the current user. For that, you might have to do a check just before the tool's action occurs and temporarily change the range then set it back when the action is done.

I took a very quick look at some tools in the game and didn't see a range defined, so you might have to alter some component, but if this is not a problem in the mod you're dealing with, then hopefully this works.

I know this all probably sounds very generic, but I don't know how much programming you already know...

I slightly understand where you're going with that, unfortunately the first option means that I would have to edit every tool in the game including the spear, axe, and pick-axe (cause I'm not just dealing with mod files). So finding a way to do this in the character creation files is important to me.

BTW: The command for setting the weapons range in the weapon creation is "inst.components.weapon:SetRange(X)"

As far as learning do to this with the action, I'm still digging through files but I don't think that'll work as I don't see a built in command for that.

I'll be taking a break from digging and rely on this forum for a bit cause I'm starting to burn myself out reading only code and not making progress (least I feel like I'm learning).

Well if changing a range is all you want to do, maybe you could try making a list of prefabs that you want to change and run the AddPrefabPostInit(prefab, myFunction) in a for loop for each tool in that list...

Would you mind going into a bit more detail as to how I would/should format this. (I'm slightly worried that if I change the prefab like this it might effect the other characters as well. I realize that the fix is to have the function reference the player/character I just don't know how to do that yet)

I'll try to do more research on Friday for some more general modding to get some more experience with lua. (and probably practice with that as well. It would be helpful if there was a script resource for this game so you could look up the more obscure available code all in one place..Like a local IDE or something idk...)

Well, after thinking about ranges, I'm not sure all tools have a range type of functionality... Like an axe for example, you can only use it when you're next to an object in the world itself. I'm not really sure how to change that type of range since it's seems like most all of the code runs with some fundamental assumptions, but if this is completely irrelevant then just let me know. If you found anything interesting let me know

I am hoping to utilize this for tools as well, I've taken a bit of a break so I'm not certain if I'll be getting back in the code just yet, but what my thoughts are right now are if I can figure out what those fundamental assumptions are I might be able to either create a new function that gives tools and such range, or if the assumptions already act on range using that. I'm still hoping to find something on this but I'm starting to become discouraged due to the fact that a) not finding much atm and b) working on this (with the exception of this forum) alone.

I wonder if there's a base function in the character that predetermines it's base range.
... well here's hoping something pops up soon. I'll look into it more soon.

Well, It is possible to make, for example, an axe have more attack range but making it have more chopping range is a bit more complicated. In order to change an action range for an axe you would probably have to edit the "tool" component which could be difficult.

But changing the attack range is way easier. A quick code for such effect:

AddPlayerPostInit(function(inst) -- Adding a AddPlayerPostInit is in my opinion is the easiest way
	local function ChangeRange(inst) -- A function that changes items range
		if inst.prefab ~= "wilson" then -- Checking if the user is a certain character, you can use your character prefab here, any character that isn't Wilson, in this case, won't have their weapons range changed
			if inst.components.inventory ~= nil then
				local hands = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) -- Local "hands" used to store information about the item
				
				if hands ~= nil and hands.components ~= nil and hands.components.weapon ~= nil then
					if hands:HasTag("rangedweapon") or hands:HasTag("blowdart") or hands:HasTag("thrown") or hands.prefab == "sleepbomb" then -- Eliminating some weapons that shouldn't have their range changed
						return
					else
						hands.components.weapon:SetRange() -- Setting the range to default because this is not Wilson
					end
				elseif hands ~= nil and hands.components ~= nil then
					hands:AddComponent("weapon") -- Adding "weapon" component, just in case
					hands.components.weapon:SetRange() -- Setting the range to default because this is not Wilson
				end
			end
		else -- if this IS Wilson
			if inst.components.inventory ~= nil then
				local hands = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) -- Local "hands" used to store information about the item
				
				if hands ~= nil and hands.components ~= nil and hands.components.weapon ~= nil then
					if hands:HasTag("rangedweapon") or hands:HasTag("blowdart") or hands:HasTag("thrown") or hands.prefab == "sleepbomb" then -- Eliminating some weapons
						return
					else
						hands.components.weapon:SetRange(2, 3) -- Changing the range (Use range, Hitting range)
					end
				elseif hands ~= nil and hands.components ~= nil then
					hands:AddComponent("weapon") -- Adding "weapon" component, just in case
					hands.components.weapon:SetRange(2, 3) -- Changing the range (Use range, Hitting range)
				end
			end
		end
	end
	
	inst:ListenForEvent("equip", ChangeRange) -- Listening for an "equip" event and setting the ChangeRange function
end)

If you need any more explanation tell me.

Edited by IThatGuyI
  • Like 1

This actually helps a lot. I'm just curious if you could set it to a player instance instead of just checking if a certain player is used?
I'll certainly try to work with this and see if I can find the function for tools as well.

Another reason I might want to use a player over a AddPlayerPostInit() is to leave the possibility to update this value mid game.

Also, only one question. Why not have the code simply end as soon as a different character is used?
ie:

if inst.prefab ~= "wilson" then
	end
else 
        ...

or even

if inst.prefab == "wilson" then
	...
else 
	end

Just seems like this would be an easy way to simplify that code.

I tried doing AddPrefabPostInit("wilson") but for some reason it didn't work and I don't know why.

Also if the right character picks up an item (in this case Wilson) this item has its range overwritten. Because of that any other character that picks up that item after Wilson, will have the same additional range as him. That's why you have to make any other character change the items range to default.

  • Like 1

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