Jump to content

Recommended Posts

Hello, I've been trying to get a blunderbuss to take ammo like a slingshot. So far I've managed to get it to take slingshot ammo and fire it. But there are a few issues. Mainly with adding the small ui slot above the hand slot ui. I cannot get this to show up. I did however get it to take the ammo by changing "inst.components.container.canbeopened" to true but this crashes the game when you try to open the container.

[00:03:04]: [string "scripts/widgets/containerwidget.lua"]:30: attempt to index local 'widget' (a nil value)

Secondly it seems to use the default swinging animation and not the blunderbuss animations. I'm not sure what's causing that.

If anyone as any ideas on how to fix the issues, please let me know.
Thanks for your time!

The error is that the widget has not been loaded correctly by the game. The second problem has to do with the wilson stategraph's action handlers, where you would need to tell it to do a blunderbuss shoot animation when it enters an attack state. There exists a blunderbuss mod with container in the DST workshop and also another one in the DS workshop that adds a container. You can take a look at how they handled the blunderbuss.

Sorry for the late reply, but I cannot figure out how I would make the damage change with the ammo. 
I was thinking I could pull the damage value out of the slingshotammo.lua but I don't know how I'd do that.
Any ideas?

You can do something like this:

Spoiler

local function OnAmmoLoaded(inst,data)
	if data ~= nil and data.item ~= nil then
    	if data.item.components.weapon then
      		local damage = data.item.components.weapon.damage
      		--do whatever you want to do with the information of the damage of the ammo
      		--for example damagechange:
      		local old_damage = inst.components.weapon.damage
      		inst.components.weapon:SetDamage(old_damage + damage)
      	end
    end
end

local function OnAmmoLoaded(inst,data)
	if data ~= nil and data.prev_item ~= nil then
    	if data.prev_item.components.weapon then
      		local damage = data.prev_item.components.weapon.damage
      		--do whatever you want to do with the information of the damage of the ammo
      		--for example damagechange:
      		local old_damage = inst.components.weapon.damage
      		inst.components.weapon:SetDamage(old_damage - damage)
      	end
    end
end

--fn of blunderbluss
inst:ListenForEvent("itemlose", OnAmmoUnloaded)
inst:ListenForEvent("itemget", OnAmmoLoaded) 

 

 

  • Like 2

I've tried to implement the code you've suggested but I haven't had any luck with it.
It might be my fault, but it would help if I showed you what the code for the gun looks like.

I've attached the code to this post.

gun.lua

Thanks for all of the help so far!

If I don't know where the mod is going wrong, I just add a ton of print statements to see where it stops, this way you can see where the code breaks.

As for your case here, I think it has to do that you add an onattack fn, but your weapon uses a projectile. If you compare your code to the one of the slingshot, you will see that the code that you have in the onattack fn is called in the SetOnProjectileLaunched fn. As your weapon launches a projectile, the onattack fn is never called, instead it tries the SetOnProjectileLaunched, but as that one is empty, it just does nothing. I would try to use the slingshot prefab to get the projectile launching done with the SetOnProjectileLaunched fn.

You're welcome!

I'm having some trouble with the data parts. I think the data if parts aren't working as I cannot seem to print anywhere in the function. I'm not sure why it isn't working, it might be where I merged the code into my exsisting OnAmmoLoaded function, as I don't think you can have two OnAmmoLoaded functions at the same time.

It's not clear to me from which piece of code you're talking, but if you have 2 OnAmmoLoaded functions declared, the second one will overwrite the first one.

You could also try to start from scratch with slingshot.lua and add all the things you added one after the other so that you can see where problems happen.

Ok so I got the slinghshot.lua and added a few things. I managed to get it to function like the slingshot but have the visuals of the blunderbuss! It takes the ammo and sets the damage appropriately.

Now I'm going to see if I can get custom ammo working. Should just be able to make a copy of slingshotammo.lua and go from there.

Thanks for your help!

Edited by MrDoge124
  • 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...