Jump to content

Programming Assistance Required!


Recommended Posts

Hi there! I'm actively working on making a mod for my character, Pryce, in DST. He's already done in art and the basics of coding and I'm trying to apply my own knowledge to it to make a follower mechanic. This mechanic will be capable of taking normally hostile enemies (specifically Tallbirds and Hounds) and tame them to work on your side (he's a master strategist and pretty charismatic, so this makes sense). I've tried making it from scratch (that failed horribly) and using other mods as referral (I got places, but it never launched).


I will also be getting a custom item developed; basically it'd be a long, skinny, tri-edged black sword that glows. It'd have an ability to teleport the user in a distance shown on the screen, usable to break dens and nests (catcoons, slugs, etc.). 

If anyone can help, or point me to someone that can help, please let me know through a forum reply or contact in PM (from here we can talk there or by email :) ). 
 

Link to comment
Share on other sites

New issue at hand! I've pushed off the follower mechanic for a bit while I try and test out a dodge mechanic, and I've been stumbling over the implementation. I want it so that below "x" amount of health, it randomly generates a number and dodges if it's greater than "y". Here's the code I have going so far, and I've used print("test") to try and get it to work once I can launch it. Buuut I haven't been able to launch it. 

local function CombatPostInit(self)   
self._DoAttack = self.DoAttackfunction self:DoAttack(target_override, weapon, projectile)        
local targ = target_override or self.target    
if targ.prefab == "pryce" then
if self.inst.components.health > 20 and math.random > 50 then       
    print("test")-- inst.SoundEmitter:PlaySound("pryce/characters/pryce/dodge")
else        
    self:_DoAttack(target_override, weapon, projectile)    
end    
end
end
AddComponentPostInit("combat", CombatPostInit) 

Link to comment
Share on other sites

I'm assuming you want the dodge chance when your character is below 20 health, not when the attacker is below 20 health.

Put this in your character's master_postinit:

	inst._GetAttacked = inst.components.combat.GetAttacked
	inst.components.combat.GetAttacked = function(attacker, damage, weapon, stimuli)
		if inst.components.health.currenthealth < 20 and math.random() > .5 then -- Character got hit
			inst._GetAttacked(attacker, damage, weapon, stimuli) 
		else -- Character dodged
			inst.SoundEmitter:PlaySound("pryce/characters/pryce/dodge") 
		end
	end

That's a 50% chance to dodge when below 20 health.

Link to comment
Share on other sites

On 2/9/2016 at 8:16 PM, Squids said:

I'm assuming you want the dodge chance when your character is below 20 health, not when the attacker is below 20 health.

Put this in your character's master_postinit:


	inst._GetAttacked = inst.components.combat.GetAttacked
	inst.components.combat.GetAttacked = function(attacker, damage, weapon, stimuli)
		if inst.components.health.currenthealth < 20 and math.random() > .5 then -- Character got hit
			inst._GetAttacked(attacker, damage, weapon, stimuli) 
		else -- Character dodged
			inst.SoundEmitter:PlaySound("pryce/characters/pryce/dodge") 
		end
	end

That's a 50% chance to dodge when below 20 health.

Thank you! I did end up figuring out the attacker issue, and this did allow for the character to dodge. However, he only dodged. I did end up switching them around and it worked out! Though it was rough to see if it worked at first, I found out the RNG was just real for me. 

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