Jump to content

Recommended Posts

Hello,

 

I have recently figured out how to start out my character with a backpack and now I'd like to solve another problem that occurred while figuring this out.

 

Everything is working 100% fine but I wish my character also to start out with a spear but for some reason when I add the (Code below)

local start_inv = {	"spear"}
return MakePlayerCharacter("test", prefabs, assets, master_postinit, fn, start_inv)

It makes my character crash.

 

-------------------------------------------------------------------------------------------------------------------------------------

 

My original code to get him to spawn with a backpack equipped is this.

local fn = function(inst)	inst._OnNewSpawn = inst.OnNewSpawn	inst.OnNewSpawn = function()		local start_inv ={		"backpack",		}		for i, v in ipairs(start_inv) do            inst.components.inventory:GiveItem(SpawnPrefab(v))            inst.components.inventory:Equip(SpawnPrefab(v))        end			if inst._OnNewSpawn ~= nil then				inst:_OnNewSpawn()				inst._OnNewSpawn = nil        end    end
return MakePlayerCharacter("test", prefabs, assets, master_postinit, fn) 

I can't add a spear to this list otherwise he will start out with 2 spears. 1 Spear in this inventory and 1 spear equipped.

 

Could anyone shine some light on what I need to do or what I'm doing wrong?

 

Thanks for reading~

Edited by Chaoisia
return MakePlayerCha prefabs, assets, master_postinit, fn, start_inv)

u cut out a lot in the middle there, look into other character prefabs. aside from that, u have to add the spear to the prefablist(as also seen in other characterprefabs that have starting inventories). 

u cut out a lot in the middle there, look into other character prefabs. aside from that, u have to add the spear to the prefablist(as also seen in other characterprefabs that have starting inventories). 

 

Opps. Apparently I accidently deleted that half while editing the post without even noticing.

return MakePlayerCharacter("test", prefabs, assets, master_postinit, fn, start_inv)

Is what I originally meant.

 

--------------------------------

Update: (attached new .lua file in this post)

 

Ok, well maybe last time I had a typo in the code but I'm no longer crashing but nor am I starting out with a spear. I spawn inside the game with a backpack but no spear.

 

I'm clearly missing something and it's probably just something stupid.

test.lua

Edited by Chaoisia

@Chaoisia,

ok i gave up, here's a cleaned up version:

test.lua

also, u should rather add this stuff to your modmain:

STRINGS.CHARACTER_TITLES.test = "The Warrior"STRINGS.CHARACTER_NAMES.test = "Test"STRINGS.CHARACTER_DESCRIPTIONS.test = "*Starts with Spear! \n*Starts with a Backpack! \n*Hard Hitter!"STRINGS.CHARACTER_QUOTES.test = "\"To Battle!\""STRINGS.CHARACTERS.TEST = require "speech_test"
add them after the line

local STRINGS = GLOBAL.STRINGS
if your modmain doesn't have that line, add it too. Edited by Seiai

Using

local start_inv = {	"spear",	"backpack",}

A player will only start out with a spear and not a backpack. The reason is because a backpack can't go in an inventory slot. It can only be equipped and it can only be dropped.

 

That's why I had the fn in order for him to spawn with it and have it equipped because originally the start_inv has never worked for me in spawning backpacks. I'm looking for a way to use both the fn, and start_inv if possible. Or if I could just use the fn to spawn in the spear as well but I can't do that because it would spawn in with multiple spears.

Edited by Chaoisia

Ok, I've figured it out. It was just something simple and stupid. I completely removed the start_inv and just added the spear to the same code I was using to spawn in the backpack. I went back looked over my code again and deleted 1 simple line (lol) that allowed both the backpack and the spear to start off equipped on my character without doubling the amount of spears.

 

---Solved---

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