Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @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 More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @Blueberrysummm... When i said i changed it to "cole", i meant when i called it i saidlocal function breath_fire()inst:AddComponent("firebreath") inst.components.firebreath:LaunchProjectile("cole")endlocal key = KEY_G -- See constants.lua for all keys/codes not when i defined the function... Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @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.instBecause 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 More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @BlueberrysYeah 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 More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 The first one is that the fireball doesn't light anything on fireThe 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 More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @BlueberrysI can't get it to work... It lights things on fire now (btw: Thanks so much for the help ) But i cant figure out how to make it not try to do anything when i'm not pointing at something... Link to comment Share on other sites More sharing options...
Blueberrys Posted April 10, 2015 Share Posted April 10, 2015 @Aphid98local target = TheInput:GetWorldEntityUnderMouse()if not target then returnend Link to comment Share on other sites More sharing options...
Aphid98 Posted April 10, 2015 Author Share Posted April 10, 2015 @Aphid98local target = TheInput:GetWorldEntityUnderMouse()if not target then returnendwhenever i try to attack a creature it crashes... Here is the log:log.txt Link to comment Share on other sites More sharing options...
Blueberrys Posted April 11, 2015 Share Posted April 11, 2015 @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 More sharing options...
Aphid98 Posted April 11, 2015 Author Share Posted April 11, 2015 @Blueberryswhere should i put this code? Link to comment Share on other sites More sharing options...
Blueberrys Posted April 11, 2015 Share Posted April 11, 2015 @Aphid98 Somewhere that has the inst variable referring to the player. Link to comment Share on other sites More sharing options...
Aphid98 Posted April 12, 2015 Author Share Posted April 12, 2015 @Aphid98 Somewhere that has the inst variable referring to the player.This code gave me the same error:cole.luawhats wrong with that one? Link to comment Share on other sites More sharing options...
Corrosive Posted April 13, 2015 Share Posted April 13, 2015 @Aphid98, Post your error log? Link to comment Share on other sites More sharing options...
Aphid98 Posted April 13, 2015 Author Share Posted April 13, 2015 @Aphid98, Post your error log?Ok, here it is:log.txt Link to comment Share on other sites More sharing options...
Aphid98 Posted April 17, 2015 Author Share Posted April 17, 2015 @Blueberrys @CorrosiveAny ideas? Link to comment Share on other sites More sharing options...
Aphid98 Posted April 30, 2015 Author Share Posted April 30, 2015 BlueberrysAre you there? Link to comment Share on other sites More sharing options...
Blueberrys Posted April 30, 2015 Share Posted April 30, 2015 @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 More sharing options...
Aphid98 Posted May 11, 2015 Author Share Posted May 11, 2015 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 More sharing options...
Recommended Posts
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.