Jump to content

combat damage


Recommended Posts

i'm trying to make a char mod that you can pick some of your attributes at the beginning It looks like it works for the hunger health and sanity but not combat damage.... This is part of the code i'm trying to use.

in modinfo.lua there's

configuration_options =
{
	{
		name = "health",
		label = "Max Health",
		options =	{
						{description = "100", data = 1},
						{description = "150", data = 2},
						{description = "175", data = 3},
						{description = "200", data = 4},

					},
		default = true,
	},
	{
		name = "hunger",
		label = "Max Hunger",
		options =	{
						{description = "100", data = 1},
						{description = "150", data = 2},
						{description = "175", data = 3},
						{description = "200", data = 4},
					},
		default = true,
	},
	{
		name = "sanity",
		label = "Max Sanity",
		options =	{
						{description = "100", data = 1},
						{description = "150", data = 2},
						{description = "175", data = 3},
						{description = "200", data = 4},
					},
		default = true,
	},
	{
		name = "attack",
		label = "Damage multiplier",
		options =	{
						{description = "100%", data = 1},
						{description = "150%", data = 2},
						{description = "175%", data = 3},
						{description = "200%", data = 4},
					},
		default = true,
	}
}

 in modmain.lua there's

if attack == 1 then --Tiny
    AddPlayerPostInit(function(player)
        inst.components.combat.damagemultiplier = 1

	end)
	
	elseif attack ==2 then --Poor
    AddPlayerPostInit(function(player)
        inst.components.combat.damagemultiplier = 1.5
	
	end)
	
	elseif attack == 3 then --Large
    AddPlayerPostInit(function(player)
        inst.components.combat.damagemultiplier = 1.75
	
	end)
	
	elseif attack == 4 then --Lots
    AddPlayerPostInit(function(player)
        inst.components.combat.damagemultiplier = 2

	end)
		
end

 

Link to comment
Share on other sites

So I forgot to add 

 

local attack = GetModConfigData("attack")

 

but it crashes with that

[string "../mods/workshop-b/modmain.lua"]:110: attempt to index global 'inst' (a nil value)

LUA ERROR stack trceback:

../mods/workshop-b/main.lua(110,1) in function 'fn'

scripts/modutil.lua(426,1)

=(tail xall) ?

=[C] in function 'xpcall'

scripts/mods.lua(158,1) in funtcion 'prefabpostinitany'

scripts/mainfunctions.lua(280,1)

=[C] in funtion 'SendResumeRequestToServer'

script/prefabs/world_network.lua(30,1) in function 'fn 

Link to comment
Share on other sites

That's an easy one: you named your parameter "player" instead of "inst" ;)

You should really combine the things into one big AddPlayerPostInit, instead of creating a bunch of them. Just move all the if-statements into one big AddPlayerPostInit. Then it won't have to add 4 per player.

Link to comment
Share on other sites

54 minutes ago, Ultroman said:

That's an easy one: you named your parameter "player" instead of "inst" ;)

You should really combine the things into one big AddPlayerPostInit, instead of creating a bunch of them. Just move all the if-statements into one big AddPlayerPostInit. Then it won't have to add 4 per player.

Thanks looks like that's working. 

The codes probably a big mess I really don't know what i'm doing i'm just messing around and pulling parts from other mods and trying to learn. 

"Just move all the if-statements into one big AddPlayerPostInit."  Not sure exactly what that means 

AddPlayerPostInit(function(inst)
	if damagemultiplier == 1 then --Tiny
			inst.components.combat.damagemultiplier =  1
		
		elseif damagemultiplier == 2 then --Poor
			inst.components.combat.damagemultiplier = 1.5
	
		elseif damagemultiplier == 3 then --Large
			inst.components.combat.damagemultiplier = 1.75

	
		elseif damagemultiplier == 4 then --Lots
			inst.components.combat.damagemultiplier = 2
		
	end
end)

Like this?

Link to comment
Share on other sites

Yep

You could also merge all the health, sanity and hunger stuff into the same AddPlayerPostInit.

This mod, though...it kind of has to be a server mod, which means the settings will be applied to every single player, no matter which character they've picked. Most character mods have balanced their character's stats to fit their special abilities, so you might end up really messing up the balance of these characters. For playing singleplayer, it's a nice mod, though, since you'll know which character you're going to pick, and can choose settings accordingly.

Edited by Ultroman
Link to comment
Share on other sites

What exactly are you trying to do? Do you want the ability to change the stats for the Maxwell character only, by setting the stats in the settings for your mod?

I don't think you can make a mod, where clients can set their own stats before joining. I'm not sure it's impossible either, though.

Edited by Ultroman
Link to comment
Share on other sites

Then you can just do

AddPlayerPostInit(function(inst)
	if inst.prefab == "waxwell" then
		return
	end
	-- do all your stat changes
end)

 

Or even better

AddPrefabPostInit("waxwell", function(inst)
	-- do all your stat changes
end)

Not sure if AddPrefabPostInit also works for player characters, but it's worth a try.

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
 Share

×
  • Create New...