Jump to content

Custom Character Perks regardiing ranged weapons


Recommended Posts

So uhh, I made this thing based on Wanda's perk, Is this good before I test this out?

local function CustomCombatDamage(inst, target, weapon, multiplier)
	if weapon ~= nil and weapon:HasTag("rangedweapon" or "thrown" or "projectile") then
	inst.components.combat.damagemultiplier = 1.5
	
end
Link to comment
Share on other sites

4 hours ago, LeTrying said:

So uhh, I made this thing based on Wanda's perk, Is this good before I test this out?


local function CustomCombatDamage(inst, target, weapon, multiplier)
	if weapon ~= nil and weapon:HasTag("rangedweapon" or "thrown" or "projectile") then
	inst.components.combat.damagemultiplier = 1.5
	
end

Unfortunately it won't check those tags like you're wanting it to, LUA will detect the 'or' statements and return back the first string only before HasTag is called.

weapon:HasTag("rangedweapon") or weapon:HasTag("thrown") or weapon:HasTag("projectile")

And it looks like you've left off an 'end' there to close your if-then statement.

  • Like 1
Link to comment
Share on other sites

No Good.
Always ends with the game closing. I wish there was like a log once the game closes telling you what happened
Here's what i have
 

local function CustomCombatDamage(inst, target, weapon, multiplier)
	if weapon ~= nil and weapon:HasTag("rangedweapon") or weapon:HasTag("thrown") or weapon:HasTag("projectile") then
		return 1.5
	else
		return 1
	end
end

I feel like its missing something for it to work, but i have no idea what it is

Link to comment
Share on other sites

@LeTrying

Good news!  There is a log file to look over, you can find it by following the helper guides at:

https://support.klei.com/hc/en-us/articles/360029881191-Logs-and-Useful-Information-for-Bug-Reports-for-Don-t-Starve-Together

If you're trying to host the game without caverns on, then the client_log.txt will contain the stack trace.  Otherwise it will be in one of the server_log.txt files located in the subdirectory: ~/klei/DoNotStarveTogether/###/Cluster_#/Master/server_log.txt

If this stack trace doesn't lead you to anywhere, then please don't hesitate to reply back with more of the code in the file being ran.  Sometimes the error can be a syntax related thing above it, or some weird handling of a function below.

  • Like 1
Link to comment
Share on other sites

I feel embaressed, the error isn't from the code (maybe not yet) but its from the speech file.

Whoops.

Gonna check to see if things change once that is fixed

Also,
 

local function CustomCombatDamage(weapon, multiplier)
	if weapon ~= nil and weapon:HasTag("rangedweapon") or weapon:HasTag("thrown") or weapon:HasTag("projectile") then
		return TUNING.SKULLCAT_DAMAGE_RANGED
	else
		return TUNING.SKULLCAT_DAMAGE_NORMAL
	end
	
	return 1
end

Here's the code now

Link to comment
Share on other sites

@CarlZalph
So uh, i finally fixed issues that caused the crashes, but now the important one.
So once I shot down a target with an item that has one of the tags (a normal blowdart) the game crashed.
 

Quote

[00:05:20]: [string "scripts/components/combat.lua"]:740: attempt to perform arithmetic on a function value
LUA ERROR stack traceback:
    scripts/components/combat.lua:740 in (method) CalcDamage (Lua) <699-747>
    scripts/components/combat.lua:917 in (method) DoAttack (Lua) <859-946>
    scripts/components/projectile.lua:217 in (method) Hit (Lua) <197-224>
    scripts/components/projectile.lua:291 in (upvalue) DoUpdate (Lua) <263-330>
    scripts/components/projectile.lua:358 in (method) OnUpdate (Lua) <332-359>
    scripts/update.lua:256 in () ? (Lua) <218-292>
   

Here is the error message

Link to comment
Share on other sites

@LeTrying

Are you setting the damage modifier like:

<Player entity>.components.combat.damagemultiplier = CustomCombatDamage

If you are, then this isn't going to do it unfortunately, the damagemultiplier variable is expected to be a number.  You'd have to invoke the function call:

<Player entity>.components.combat.damagemultiplier = CustomCombatDamage(<weapon entity>)

From where you update this will also be important, though I think the easier route for your character to do more damage for ranged items is to modify the ranged item's damage when it's equipped by your character prefab, then decrease it back when it's no longer on.  You'd be able to do this by dynamically hooking the weapon entity's weapon component's GetDamage return value to be multiplied by your character's constant if it's ranged whenever it is equipped.  Then unhook the GetDamage function when it's unequipped.

  • Like 1
Link to comment
Share on other sites

@CarlZalph
So uh, i changed the component to
 

inst.components.combat.customdamagemultfn = CustomCombatDamage

It works now, not crashing the game when dealing damage, but it doesn't increase damage (most likely need to redo the conditions again)
This is also the component that Wanda uses to increase her Shadow Weapons Damage

 

Also, whats a good target to test the damage on, without attacking you back?

 

Link to comment
Share on other sites

okay, so attacking without the weapon crashes the game, actually, i should check if beefalo attackwould crash it as well

For the no weapon Attack
 

Quote

[00:24:45]: [workshop-2189004162 (Insight)]:    A crash has occured.    
[00:24:45]: [workshop-2189004162 (Insight)]:    Title:    WARNING!    
[00:24:45]: [workshop-2189004162 (Insight)]:    Text:    [string "../mods/Skullcat/scripts/prefabs/skullcat.l..."]:54: attempt to index local 'weapon' (a nil value)
LUA ERROR stack traceback:
    ../mods/Skullcat/scripts/prefabs/skullcat.lua:54 in (field) customdamagemultfn (Lua) <53-61>
    scripts/components/combat.lua:745 in (method) CalcDamage (Lua) <699-747>
    scripts/components/combat.lua:917 in (method) DoAttack (Lua) <859-946>
    scripts/actions.lua:1225 in (field) fn (Lua) <1208-1227>
    scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
    scripts/entityscript.lua:1415 in (method) PerformBufferedAction (Lua) <1402-1425>
    scripts/stategraphs/SGwilson.lua:7164 in (field) fn (Lua) <7157-7167>
    scripts/stategraph.lua:576 in (method) UpdateState (Lua) <544-588>
    scripts/stategraph.lua:615 in (method) Update (Lua) <607-635>
    scripts/stategraph.lua:128 in (method) Update (Lua) <109-146>
    scripts/update.lua:282 in () ? (Lua) <218-292>

For the Beefalo Attack
 

Quote

[00:13:03]: [string "../mods/Skullcat/scripts/prefabs/skullcat.l..."]:54: attempt to index local 'weapon' (a nil value)
LUA ERROR stack traceback:
    ../mods/Skullcat/scripts/prefabs/skullcat.lua:54 in (field) customdamagemultfn (Lua) <53-61>
    scripts/components/combat.lua:745 in (method) CalcDamage (Lua) <699-747>
    scripts/components/combat.lua:917 in (method) DoAttack (Lua) <859-946>
    scripts/actions.lua:1225 in (field) fn (Lua) <1208-1227>
    scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
    scripts/entityscript.lua:1415 in (method) PerformBufferedAction (Lua) <1402-1425>
    scripts/stategraphs/SGwilson.lua:7164 in (field) fn (Lua) <7157-7167>
    scripts/stategraph.lua:576 in (method) UpdateState (Lua) <544-588>
    scripts/stategraph.lua:615 in (method) Update (Lua) <607-635>
    scripts/stategraph.lua:128 in (method) Update (Lua) <109-146>
    scripts/update.lua:282 in () ? (Lua) <218-292>

Same, but still so long as im not using a weapon it gets a crash

Link to comment
Share on other sites

@LeTrying

In the combat component's customdamagemultfn, the 'weapon' argument can be nil.

So in the callback function check to see if weapon isn't nil first before using it.  If it's nil, then it's definitely not ranged.

Also be sure your order of operations are as you expect them to be in your oneliner.  Use parenthesis liberally to force logic how you want it to be.

if weapon ~= nil and (weapon:HasTag("rangedweapon") or weapon:HasTag("thrown") or weapon:HasTag("projectile")) then

Without the parenthesis the compiler will invoke it like you meant it as:

if (weapon ~= nil and weapon:HasTag("rangedweapon")) or (weapon:HasTag("thrown")) or (weapon:HasTag("projectile")) then

So since the first part is false when you have no weapon equipped, it tries to evaluate the second part which won't be runtime good since weapon is nil and it's trying to use it like an object table.

  • Like 1
Link to comment
Share on other sites

The Parenthesis don't work, so I decided to shorten it to only read projectiles,
 

local function CustomCombatDamage(inst, target, weapon, multiplier)
		if weapon ~= nil and weapon:HasTag("projectile") then
			return 1.5
		else
			return 1
		end
		return 1
end

I decided to only read projectiles, and its enough to make it work while not causing a crash.

I probably should have did it like this instead.

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