Jump to content

Need help making special powers


Recommended Posts

@Aphid98 Binding the key is probably the easiest part. See if you can make the component first.

Ideally, you would also have a modified or custom stategraph that can play a firebreathing animation when the fireball is launched, or it would just come out of nowhere.

 

To bind a key, use one of the AddKey_Handler's in TheInput. (See input.lua)

Example:

TheInput = GLOBAL.TheInputlocal key = GLOBAL.KEY_G -- See constants.lua for all keys/codeslocal function PrintHi()    print("hi")endTheInput:AddKeyDownHandler(key, PrintHi)

This prints "hi" to the console when you press "g".

So i have added the code I think i need, but now whenever i open the character in a world the game crashes... Here is the log:log.txt

i opened it and i had no idea where to look for the messed up code... Any ideas?

Link to comment
Share on other sites

wait... How do you mean component?

because, i put all of the fire breathing code in the special powers place  :wilson_smile:

edit: Not all of it, just the attack/add fire projectile and sound 

 p.s: I'm really sorry, I am a bad programmer.

Link to comment
Share on other sites

@Aphid98

 

In your log:

cole.lua:123: attempt to index global 'TheInput' (a nil value)
In prefabs/scripts, you don't need TheInput = GLOBAL.TheInput because global variables are already available. You only need it in modmain.

 

See this guide for more information on reading log files.

 

Information on components:

Link to comment
Share on other sites

@Aphid98 Have you read about components from either of the links? If so, please have a look at any component's code (in "..\scripts\components", then compare the general structure with your code (just the first and last ~20 lines). Your code is attempting to make a prefab, not a component. If you don't want to write the code from scratch, I suggest finding a component that is very similar to what you need and modifying that.

Link to comment
Share on other sites

@Blueberrys I need help with a special power (2 to be exact)

 

1 of them is a perk that innocents (rabbits, bird etc.) won't run away when the palyer gets close to it

2nd one will be a perk (more like a downside) is that the character will take 100 damage when eating berries, roasted ones and also fist      full of jam (only)

 

If you can give me a head start or at least a direction to start with will be most helpful. Thanks. :wickerbottomthanks:

Link to comment
Share on other sites

@Blueberrys I need help with a special power (2 to be exact)

 

1 of them is a perk that innocents (rabbits, bird etc.) won't run away when the palyer gets close to it

2nd one will be a perk (more like a downside) is that the character will take 100 damage when eating berries, roasted ones and also fist      full of jam (only)

 

If you can give me a head start or at least a direction to start with will be most helpful. Thanks.

 

both go to the part in your characters file that has the other player abilities

 

1)

inst:RemoveTag("scarytoprey")

 

2)

local function BerryDeath(inst, data)

  if data.food then

    if data.food.prefab == "berries" or data.food.prefab == "WHATEVER" then --you can continue on the "or ... = ..."

      inst.components.health:DoDelta(-100)

    end

  end

end

 

inst:ListenForEvent("oneat",BerryDeath)

Link to comment
Share on other sites

both go to the part in your characters file that has the other player abilities

 

1)

inst:RemoveTag("scarytoprey")

 

2)

local function BerryDeath(inst, data)

  if data.food then

    if data.food.prefab == "berries" or data.food.prefab == "WHATEVER" then --you can continue on the "or ... = ..."

      inst.components.health:DoDelta(-100)

    end

  end

end

 

inst:ListenForEvent("oneat",BerryDeath)

Thanks a lot! 

But I don't get the file you are talking about...

Or do I need to create another prefab or something?

Link to comment
Share on other sites

Thanks a lot! 

But I don't get the file you are talking about...

Or do I need to create another prefab or something?

 

Have you used a template? It should have a bit saying "add powers here" or alike. That's where you put the code.

 

Also, keep in mind that WHATEVER isn't an actual prefab, but a placeholder. I got bored :p

Link to comment
Share on other sites

@Aphid98 Have you read about components from either of the links? If so, please have a look at any component's code (in "..\scripts\components", then compare the general structure with your code (just the first and last ~20 lines). Your code is attempting to make a prefab, not a component. If you don't want to write the code from scratch, I suggest finding a component that is very similar to what you need and modifying that

Ok, I am having a lot of trouble making the component file.  I still crashes every time i run it, (probably because of the bad component file)

I have attached the file here: firebreath.lua

i think it has problems with it not specifying that it is a special power? Idk...

Link to comment
Share on other sites

I don't get the file you are talking about...

Your character's prefab file "..\your_mod\scripts\your_character_prefab.lua".

You need to put those inside the create function (named "fn" usually) because "inst" refers to the player.

 

@Aphid98 That one looks a lot better, well done. If you post your log, we can point out what's causing the problem.

Link to comment
Share on other sites

Have you used a template? It should have a bit saying "add powers here" or alike. That's where you put the code.

 

Also, keep in mind that WHATEVER isn't an actual prefab, but a placeholder. I got bored :razz:

 

 

Your character's prefab file "..\your_mod\scripts\your_character_prefab.lua".

You need to put those inside the create function (named "fn" usually) because "inst" refers to the player.

 

@Aphid98 That one looks a lot better, well done. If you post your log, we can point out what's causing the problem.

So do I put it in : local common_postinit = function(inst)   (or in the)   local master_postinit = function(inst)

 

thanks again guys...Probably gonna credit you guys if the mod gets onto the workshop! :kiwi:

 

shaman.lua

Link to comment
Share on other sites

Your character's prefab file "..\your_mod\scripts\your_character_prefab.lua".

You need to put those inside the create function (named "fn" usually) because "inst" refers to the player.

 

@Aphid98 That one looks a lot better, well done. If you post your log, we can point out what's causing the problem.

Awesome! Here is the log:log.txt

Link to comment
Share on other sites

@Aphid98

Your log says:

...nt_starve/data/../mods/Cole/scripts/prefabs/cole.lua:52: variable 'firebreath' is not declared

The problem is in cole.lua. Check around line 52, see if you can figure it out. Provide the file's content if you get stuck.

I don't actually know how to reference my component correctly, How should i tell it to look for the file?

Link to comment
Share on other sites

 

@Aphid98 See how the other prefabs do it.

For example, "houndstooth.lua":

inst:AddComponent("stackable")inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

It seems that the problem is my firebreath variable is not declared, this is the code:

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.
inst:AddComponent("firebreath")
local key = GLOBAL.KEY_LCTRL -- See constants.lua for all keys/codes
 
TheInput:AddKeyDownHandler(key, firebreath)
end
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...