Jump to content

Need help making special powers


Recommended Posts

@Aphid98 The new error is irrelevant, you can't put "cole" (with quotes) as the parameter, it doesn't make sense. Take a step back, change it to "attacker" (without quotes) and find out why the parameter attacker is nil. Check out the links I've provided, you don't need to read all of them, just skim through them at least and read the parts about parameters.

Link to comment
Share on other sites

@Blueberrys

ummm... When i said i changed it to "cole", i meant when i called it i said

local function breath_fire()
inst:AddComponent("firebreath")
    inst.components.firebreath:LaunchProjectile("cole")
end
local key = KEY_G -- See constants.lua for all keys/codes
 
not when i defined the function...
Link to comment
Share on other sites

@Aphid98 Ah, okay. I assumed you changed it in the definition because you wrote "function firebreath:LaunchProjectile".

 

You have the right idea, but "cole" is not what you want to pass in. The attacker parameter needs to be an instance of the attacker, not the name. Since you already have the player instance in a variable ("inst"), you can just pass that in.

inst.components.firebreath:LaunchProjectile(inst)

-

 

Edit: Alternately, since your component is attached to the player, you can use this in the firebreath:LaunchProjectile function:

local attacker = self.inst

Because in your firebreath.lua script, you have:

local firebreath = Class(function(self, inst)    self.inst = inst    -- ...

Where inst is the player instance.

Link to comment
Share on other sites

@Blueberrys

Yeah sorry i messed that up, but i works now (sort of) it launches a fireball at the target but there are two problems. The first one is that the fireball doesnt light anything on fire, the second is that when i launch one without pointing at something it crashes with this error:

......n/dont_starve/data/scripts/components/projectile.lua:71: attempt to index local 'target' (a nil value)

Link to comment
Share on other sites

The first one is that the fireball doesn't light anything on fire

The firestaff does that in its onattack function, you will need to do it yourself since you're not using the staff.

I suggest using the projectile component's onhit function.

-- Where proj is the projectiles instance-- Hint: After "if proj and proj.components.projectile then"local old_onhit = proj.components.projectile.onhitlocal function NewOnHit(inst, attacker, target)	if target.components.burnable and not target.components.burnable:IsBurning() then		if target.components.freezable and target.components.freezable:IsFrozen() then			target.components.freezable:Unfreeze()		else			target.components.burnable:Ignite(true)		end	end	return old_onhit(inst, attacker, target)endproj.components.projectile:SetOnHitFn(NewOnHit) 

-

 

the second is that when i launch one without pointing at something it crashes with this error:

 

Edit: Make sure target isn't nil before you pass it. You might also want to make sure it's an enemy, so you don't go around accidentally shooting rocks and trees (unless you want that, which could make it interesting).
if target then    -- ...end
Link to comment
Share on other sites

@Aphid98 Hmm. That's happening because the combat component requires some sort of "weapon" to be used. Your character isn't considered a weapon, so it doesn't know what to make of it.

You can add the weapon component to your character, but I'm not sure how well that would work. I think a better approach would be to overwrite your character's combat:DoAttack function.

-- (mostly) Copied from original DoAttacklocal function new_DoAttack(self, target_override, weapon, projectile)	local targ = target_override or self.target	local weapon = weapon or self:GetWeapon()	if self:CanHitTarget(targ, weapon) then		local damage = self:CalcDamage(targ, weapon)		targ.components.combat:GetAttacked(self.inst, damage, weapon)		if METRICS_ENABLED and self.inst:HasTag( "player" ) then			ProfileStatsAdd("hitson_"..targ.prefab,math.floor(damage))			FightStat_Attack(targ,weapon,projectile,damage)		end	else		self.inst:PushEvent("onmissother", {target = targ, weapon = weapon})		if self.areahitrange then			local epicentre = projectile or self.inst			self:DoAreaAttack(epicentre, self.areahitrange, weapon)		end	endendlocal old_DoAttack = inst.components.combat.DoAttackfunction inst.components.combat:DoAttack(target_override, weapon, projectile)	if weapon.prefab == "fire_projectile" then		return new_DoAttack(self, target_override, weapon, projectile)	else		return old_DoAttack(self, target_override, weapon, projectile)	endend
Link to comment
Share on other sites

@Aphid98 I don't have the time to work on this right now, sorry. Wait and see if anyone else can assist you. It would be helpful to post the current state of your code and the error(s) it produces.

 

Also, use [ member='member_name' ] (without spaces) to give the person a notification. Or select a part of their post and click "mention".

Link to comment
Share on other sites

I haven't worked on this much recently because I don't know what to do mainly. But, I still would love help figuring out how to fix it.

I will attach my error log to this post so that anyone can look at it, if you find out what the problem is PLEASE notify me asap. Tell me if you need my code as I would be happy to provide it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...