Jump to content

Recommended Posts

@Aphid98 Err. You can't just pass the component into AddKeyDownHandler.. you need a key and a function. Also, the AddComponent function doesn't return anything, so "breath" is nil.

 

Try something like this.

local function breathe_fire()    -- Call a function within your component here (you need to create it first)    -- inst.components.firebreath:BreatheFire()end-- Binds the key with the function aboveTheInput:AddKeyDownHandler(key, breathe_fire)

-

 

Your firebreath component right now seems like it would fit well on an item, but not a character. You have a function to collect equipped actions, which makes no sense on characters.

I suggest changing it up so it has a function which can be called from the key binding.

function firebreath:BreatheFire()    -- Here, you can shoot a fireball at the direction the character is facing    -- Or find the entity below the cursor, and shoot at it    -- Or whatever you want the "fire breath" to doend
@Aphid98 You can get the entity under the mouse using:
local target = TheInput:GetWorldEntityUnderMouse()
And pass that variable to the projectile component's Throw function:
-- Where "self.inst" refers to the player instance.-- Syntax is Projectile:Throw(owner, target, attacker)proj.components.projectile:Throw(self.inst, target, self.inst)

 

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

Edited by Blueberrys

 

@Aphid98 You can get the entity under the mouse using:
local target = TheInput:GetWorldEntityUnderMouse()
And pass that variable to the projectile component's Throw function:
-- Where "self.inst" refers to the player instance.-- Syntax is Projectile:Throw(owner, target, attacker)proj.components.projectile:Throw(self.inst, target, self.inst)

 

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

 

like this?firebreath.lua

@Aphid98 Sure, I guess that might work. But you might wanna clean up that code a little. There's a lot of unnecessary and confusing bits in there.
 
Specifically:

  • What does the BreatheFire function do?
  • Why is LaunchProjectile taking in 2 parameters and completely replacing one of them? ("target")
  • CollectEquippedActions is not needed, you can't equip your own firebreath.
  • What is OnAttack doing? When will it be called?
Edited by Blueberrys
@Blueberrys

I have removed CollectEquippedActions,

taken out "target" from the function call,

and removed the OnAttack function.

The idea behind BreatheFire is that it will light things on fire, but i guess that i dont need it because the projectile launch already does that? 

 

@Blueberrys

I wrote:

 

local prefabs = {}

 
local fn = function(inst)
 
-- choose which sounds this character will play
inst.soundsname = "maxwell"
 
-- a minimap icon must be specified
inst.MiniMapEntity:SetIcon( "wolfgang.png" )
 
-- todo: Add an example special power here.
local function breath_fire()
    inst.components.firebreath:LaunchProjectile()
end
local key = GLOBAL.KEY_G -- See constants.lua for all keys/codes
 
TheInput:AddKeyDownHandler(key, breath_fire)
end

@Aphid98 If this isn't in modmain, remove "GLOBAL". You only need to use the GLOBAL table when accessing global variables from modmain, other scripts already have access to them.

i can actually load the world now! But, there is a new error. here is the log and the code:

local fn = function(inst)
 
-- choose which sounds this character will play
inst.soundsname = "maxwell"
 
-- a minimap icon must be specified
inst.MiniMapEntity:SetIcon( "wolfgang.png" )
 
-- todo: Add an example special power here.
local function breath_fire()
    inst.components.firebreath:LaunchProjectile()
end
local key = KEY_G -- See constants.lua for all keys/codes
 
TheInput:AddKeyDownHandler(key, breath_fire)
end

log.txt

 

@Aphid98

Your log:

...nt_starve/data/../mods/Cole/scripts/prefabs/cole.lua:49: attempt to index field 'firebreath' (a nil value)

I think you forgot to add the firebreath component to your character.

inst:AddComponent("firebreath")

I've added it and i got a new error:

here is the log :) 

log.txt

Blueberrys

I'm not sure whats wrong... here is the code:

function firebreath:LaunchProjectile(attacker)

local target = TheInput:GetWorldEntityUnderMouse()
    if self.onprojectilelaunch then
        self.onprojectilelaunch(self.inst, attacker, target)
    end
 
local proj = SpawnPrefab(self.projectile)
if proj and proj.components.projectile then
   proj.Transform:SetPosition(attacker.Transform:GetWorldPosition() )     <---------- bad part
   proj.components.projectile:Throw(self.inst, target, attacker)
end
end
 
Edited by Aphid98

@Aphid98 Those are both incorrect.

 

"attacker" is a parameter for the LaunchProjectile function. You must pass in a value for the parameter, or it will be blank. Check if you're passing in anything when you are calling the function.

 

Info on variables.

Edited by Blueberrys
no, because there isn't a component named "attacker"...
That's correct. The reason that it worked for the previous one is because you are trying to access the component "firebreath". Not all variables work that way, only components. ( "inst.components.some_component" )

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
×
  • Create New...