Sign in to follow this  
AkaiNight

inventory error (i don't know what is it)

Recommended Posts

AkaiNight    14
[00:02:48]: [string "scripts/components/inventory.lua"]:637: attempt to index local 'inst' (a nil value)
LUA ERROR stack traceback:
    scripts/components/inventory.lua:637 in (method) GiveItem (Lua) <636-769>
    scripts/prefabs/player_common.lua:1941 in (method) OnNewSpawn (Lua) <1937-1949>
    scripts/networking.lua:250 in () ? (Lua) <238-256>
    =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1>
    scripts/mainfunctions.lua:1289 in (local) cb (Lua) <1287-1290>
    scripts/frontend.lua:541 in (method) DoFadingUpdate (Lua) <505-545>
    scripts/frontend.lua:593 in (method) Update (Lua) <553-710>
    scripts/update.lua:92 in () ? (Lua) <33-129>

well here is crash log

and here is my swords code i believe it's causes error

local assets =
{

--sword +
  --  Asset("ANIM", "anim/fuingetsu.zip"),
  --  Asset("ANIM", "anim/swap_fuingetsu.zip"),
	
   -- Asset("ATLAS", "images/inventoryimages/fuingetsu.xml"),
  --  Asset("IMAGE", "images/inventoryimages/fuingetsu.tex"),
--------------------------------------------------------------------------

--hammer +
  --  Asset("ANIM", "anim/hakai.zip"),
  --  Asset("ANIM", "anim/swap_hakai.zip"),
	
    --Asset("ATLAS", "images/inventoryimages/hakai.xml"),
  --  Asset("IMAGE", "images/inventoryimages/hakai.tex"),
---------------------------------------------------------------------------	

--icicle +
  --  Asset("ANIM", "anim/kinshara.zip"),
  --  Asset("ANIM", "anim/swap_kinshara.zip"),

   -- Asset("ATLAS", "images/inventoryimages/kinshara.xml"),
  --  Asset("IMAGE", "images/inventoryimages/kinshara.tex"),
---------------------------------------------------------------------------

--pen
    --Asset("ANIM", "anim/tsuitou.zip"),
  --  Asset("ANIM", "anim/swap_tsuitou.zip"),
	
   -- Asset("ATLAS", "images/inventoryimages/tsuitou.xml"),
  --  Asset("IMAGE", "images/inventoryimages/tsuitou.tex"),
  --------------------------------------------------------------------------

--bow +
  --  Asset("ANIM", "anim/shinsou.zip"),
  --  Asset("ANIM", "anim/swap_shinsou.zip"),
	
--    Asset("ATLAS", "images/inventoryimages/shinsou.xml"),
  --  Asset("IMAGE", "images/inventoryimages/shinsou.tex"),
---------------------------------------------------------------------------	

--light staff
  --  Asset("ANIM", "anim/raika.zip"),
   -- Asset("ANIM", "anim/swap_raika.zip"),

  --  Asset("ATLAS", "images/inventoryimages/raika.xml"),
  --  Asset("IMAGE", "images/inventoryimages/raika.tex"),
---------------------------------------------------------------------------

--axe +
  --  Asset("ANIM", "anim/tobiume.zip"),
  --  Asset("ANIM", "anim/swap_tubiume.zip"),
	
  --  Asset("ATLAS", "images/inventoryimages/tobiume.xml"),
  --  Asset("IMAGE", "images/inventoryimages/tobiume.tex"),
--------------------------------------------------------------------------

--scythe +
  --  Asset("ANIM", "anim/shirayuki.zip"),
  --  Asset("ANIM", "anim/swap_shirayuki.zip"),
	
  --  Asset("ATLAS", "images/inventoryimages/shirayuki.xml"),
   -- Asset("IMAGE", "images/inventoryimages/shirayuki.tex"),
---------------------------------------------------------------------------	

--spear +
   -- Asset("ANIM", "anim/shiden.zip"),
  --  Asset("ANIM", "anim/swap_shiden.zip"),

  --  Asset("ATLAS", "images/inventoryimages/shiden.xml"),
   -- Asset("IMAGE", "images/inventoryimages/shiden.tex"),
---------------------------------------------------------------------------
}

local prefabs = { }

local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_kinshara", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
end
	
local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
end

local function onattack_kinshara(inst, attacker, target)
    player.components.talker:Say("Wingardium Levi... What do you expect 	me to do with that? Nya~")
end


local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst) 
	
    inst:AddComponent("talker")

    inst.AnimState:SetBank("kinshara")
    inst.AnimState:SetBuild("kinshara")
    inst.AnimState:PlayAnimation("idle")
	
    inst.components.weapon:SetOnAttack(onattack_kinshara)	

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "kinshara"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/kinshara.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true



if owner HasTag("swarduser") then --item turning to sword

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_fuingetsu", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
    inst.AnimState:SetBank("fuingetsu")
    inst.AnimState:SetBuild("fuingetsu")
    inst.AnimState:PlayAnimation("idle")
 
       inst.entity:SetPristine()
       inst:AddTag("sharp")
	inst:AddTag("fuingetsu")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")		

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(40)

    inst.components.weapon.attackrange = 1.1
    inst.components.weapon.hitrange = 1.1

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "fuingetsu"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/fuingetsu.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end

if owner HasTag("hammeruser") then --item turning to hammer

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_hakai", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
    inst.AnimState:SetBank("hakai")
    inst.AnimState:SetBuild("hakai")
    inst.AnimState:PlayAnimation("idle")
 
       inst.entity:SetPristine()
	inst:AddTag("hakai")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")		

    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.HAMMER, 1)

    inst.components.weapon.attackrange = 1.1
    inst.components.weapon.hitrange = 1.1

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "hakai"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/hakai.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end
	
if owner HasTag("bowuser") then --item turning to bow

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_shinsou", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
    local function onattack_shinsou(inst, attacker, target)

	if attacker and attacker.components.sanity then
	    attacker.components.sanity:DoDelta(-5)
		
	elseif attacker and attacker.components.sanity < 10 then
	    player.components.talker:Say("I... can't... aim... did i say it right? Nya~")
		
    end
end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
     inst.components.weapon:SetOnAttack(onattack_shinsou)
 
    inst.AnimState:SetBank("shinsou")
    inst.AnimState:SetBuild("shinsou")
    inst.AnimState:PlayAnimation("idle")
 
       inst.entity:SetPristine()
	inst:AddTag("shinsou")
	inst.AddTag("bow")
	inst:AddComponent("weapon")
	inst:AddComponent("talker")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")
	
    inst.components.weapon:SetDamage(15)
    inst.components.weapon:SetRange(8, 10)

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "shinsou"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/shinsou.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end

if owner HasTag("axeuser") then --item turning to axe

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_tobiume", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
    inst.AnimState:SetBank("tobiume")
    inst.AnimState:SetBuild("tobiume")
    inst.AnimState:PlayAnimation("idle")
 
       inst.entity:SetPristine()
	inst:AddTag("tobiume")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")		

    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.CHOP, 1)

    inst.components.weapon.attackrange = 1.1
    inst.components.weapon.hitrange = 1.1

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "tobiume"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/tobiume.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end

if owner HasTag("scytheuser") then --item turning to scythe

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_shirayuki", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
    inst.AnimState:SetBank("shirayuki")
    inst.AnimState:SetBuild("shirayuki")
    inst.AnimState:PlayAnimation("idle")
 
      inst.entity:SetPristine()
      inst:AddTag("sharp")
	inst:AddTag("shirayuki")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")		

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(20)
    inst.components.weapon.rosing = true

    inst.components.weapon.attackrange = 1.1
    inst.components.weapon.hitrange = 1.1

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "shirayuki"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/shirayuki.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end

if owner HasTag("spearuser") then --item turning to spear

	local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_shiden", "symbol0")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
	end
	
	local function OnUnequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
	end
	
	local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
 
    MakeInventoryPhysics(inst)   
 
    inst.AnimState:SetBank("shiden")
    inst.AnimState:SetBuild("shiden")
    inst.AnimState:PlayAnimation("idle")
 
       inst.entity:SetPristine()
	inst:AddTag("shiden")
 
    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inspectable")		

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(40)

    inst.components.weapon.attackrange = 1.1
    inst.components.weapon.hitrange = 1.1

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.keepondeath = true
    inst.components.inventoryitem.imagename = "shiden"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/shiden.xml"	
	
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.inventoryitem.keepondeath = true
	end
end

    return inst
end

return Prefab( "common/inventory/weapon", fn, assets) 

and here is my character's lua


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {
    "book_birds",
    "book_tentacles",
    "book_gardening",
    "book_sleep",
    "book_brimstone",
    "shadow_despawn",
    "statue_transition_2",
}

-- Custom starting items
local start_inv = {
	"kinshara",
}

-- When the character is revived from human, well works 
local function onbecamehuman(inst)
	-- Set speed when reviving from ghost (optional)
	inst.components.locomotor.walkspeed = 4.6
	inst.components.locomotor.runspeed = 7
	inst.components.combat:SetAttackPeriod (0.6)
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor.walkspeed = 8.0
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
	inst.components.locomotor.walkspeed = 4.6
	inst.components.locomotor.runspeed = 7
	inst.components.combat:SetAttackPeriod (0.6	)
	
    if not inst:HasTag("playerghost") then
        onbecameghost(inst)
    end
end

--Critters sanity aura
local function critter_SanityAura(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local delta = 0
	local ents = TheSim:FindEntities(x, y, z, 20, {"critter_puppy", "player" , "critter_kitten"})
	local bonus_sanity = nil
	local distsq = nil
    	local totalDelta = nil
	
	for k, v in pairs(ents) do
		if v ~= inst then
			if v.prefab == "critter_puppy" then
				bonus_sanity = -TUNING.SANITYAURA_MEDIUM
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
				
			elseif v.prefab == "critter_kitten" then
				bonus_sanity = TUNING.SANITYAURA_SMALL
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
				
			elseif v:HasTag ("player") then
				bonus_sanity = -TUNING.SANITYAURA_SMALL
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
			
			else
			end
		end
        totalDelta = totalDelta + delta
	end
    
    if #ents > 0 then
    	totalDelta = totalDelta / #ents
    else
    	totalDelta = 0
    end
    
	return totalDelta
end

--For can not wear anything
--local function OnEquip(inst)
	--Get the equipped item
--	local hat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
--	local body = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
--	local hand = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND)
	
	--If it doesn't have your unique tag drop it

--if not hat:HasTag("youruniquetagname") then
--		inst.components.inventory:DropItem(hat)
--	end

--	if not body:HasTag("youruniquetagname") then
--		inst.components.inventory:DropItem(body)
	--end

--	if not hand:HasTag("fuingetsu") then
--		inst.components.inventory:DropItem(hand)
--	end

--end

--Can't pick up chester
local function OnPickup(inst)
	if data.prefab == "chester_eyebone" then
		local eyebone = data.prefab
		inst.components.sanity:DoDelta(-30)
		inst.components.inventory:DropItem(eyebone)
	end
end

--Counter freeze attack
local function OnBeingAttacked(inst, data)
	local damage = data and data.damage
	if damage then
		local last_time_first_hit = inst.last_time_first_hit
		local current_time = GetTime()
		-- If the hit is the first, or more than 60 seconds passed, reset the damage received and the last hit time
		-- Else, add it up
		if (last_time_first_hit == nil) or (current_time - last_time_first_hit > 59.5) then
			inst.total_damage_received = damage
			inst.last_time_first_hit = current_time
		else
			inst.total_damage_received = inst.total_damage_received + damage
		end
		-- We pass 50 damage, freeze everything, then reset damage and timer
		if inst.total_damage_received > 49.5 then
		
		if inst.level < 40 then
			inst.components.talker:Say("My skills are sealed for now. Nya~")
		end
			local x, y, z = inst.Transform:GetWorldPosition()
			-- First table, table with "must have" tags, entities with freezable component have freezable tag
			-- Second table, table with "cant have" tags, player has player tag
			inst.components.talker:Say("It hurts! Nya~")
			local ents = TheSim:FindEntities(x, y, z, 20, {"freezable"}, {"player"})
			for i, v in ipairs(ents) do
				v.components.freezable:AddColdness(10)
				v.components.freezable:SpawnShatterFX()
			end
			inst.total_damage_received = 0
			inst.last_time_hit = nil
		end
	end
end

--Stat chance on moons
local function PowerUpAtNewMoon(inst)
    if TheWorld.state.isnight then

        if TheWorld.state.moonphase == "new" then
            inst.components.combat:SetAttackPeriod (0.4)
            inst.components.locomotor.walkspeed = 6
            inst.components.locomotor.runspeed = 10
            inst.Light:Enable(true)
            inst.Light:SetRadius(18)
            inst.Light:SetFalloff(0.75)
            inst.Light:SetIntensity(.7)
            inst.Light:SetColour(70/255,230/255,12/170)
            inst.components.talker:Say("The curse has gone We are finally free! Nya~")
			
        elseif TheWorld.state.moonphase == "full" then
            inst.components.combat:SetAttackPeriod (0.8)
            inst.components.locomotor.walkspeed = 3.2
            inst.components.locomotor.runspeed = 4
            inst.components.talker:Say("I can feel the curse of moon. The moon binds us! Nya~")
        end

    elseif TheWorld.state.isdusk then

        if TheWorld.state.moonphase == "new" then
            inst.components.combat:SetAttackPeriod (0.4)
            inst.components.locomotor.walkspeed = 6
            inst.components.locomotor.runspeed = 10
            inst.components.talker:Say("I can't feel the moon. Finally i can be free. Nya~")
			
        elseif TheWorld.state.moonphase == "full" then

            inst.components.combat:SetAttackPeriod (0.8)
            inst.components.locomotor.walkspeed = 3.2
            inst.components.locomotor.runspeed = 4
            inst.components.talker:Say("Oh! I can feel the moon. This night will be cursed. Nya~")
        end
        
    elseif TheWorld.state.isday then
	
		inst.components.locomotor.walkspeed = 4.6
		inst.components.locomotor.runspeed = 7
		inst.components.combat:SetAttackPeriod (0.6)
    end
end

--Restat for foods
local function oneat(inst, food)	

	if food and food.components.edible and food.prefab == "fishsticks" then
	       inst.components.health:DoDelta(50)
		inst.components.sanity:DoDelta(50)
		inst.components.hunger:DoDelta(50)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fishtacos" then
	       inst.components.health:DoDelta(50)
		inst.components.sanity:DoDelta(50)
		inst.components.hunger:DoDelta(50)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fish" then
		inst.components.health:DoDelta(20)
		inst.components.sanity:DoDelta(30)
		inst.components.hunger:DoDelta(20)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
	
	elseif food and food.components.edible and food.prefab == "fish_cooked" then
		inst.components.sanity:DoDelta(-15)
		inst.components.talker:Say("Don't you know the fire is not good for me! Do not try to eat that me again!!!. Nya~", 1.2, true)
	
       elseif food and food.components.edible and food.prefab == "ice" then
	       inst.components.health:DoDelta(5)
		inst.components.sanity:DoDelta(10)
		inst.components.talker:Say("Itadakimasu. Nya~", 1.2, true)
		
	elseif food and food.components.edible and food.prefab  == not "ice" or "fish_cooked" or "fish" or "fishtacos" or "fishsticks" then
    local hungerboost = 5
    local sanityboost = -5
    
    local foodcheck = food.prefab == "spoiled_food" and 0 or hungerboost

    inst.components.health:DoDelta(0) 
    inst.components.sanity:DoDelta(-5) 
    inst.components.hunger:DoDelta(5)
    inst.components.talker:Say("I shouldn't eat that. Nya~")
	
	end
end

--Level system
local function levelexp(inst, data)

	local max_exp = 999999999994650
	local min_exp = -99999999999999
	local level = math.min(inst.level, max_exp)
	
	local health_percent = inst.components.health:GetPercent()
	local sanity_percent = inst.components.sanity:GetPercent()
	local hunger_percent = inst.components.hunger:GetPercent()
	
	if inst.level <=999999999994650 then
	inst.components.talker:Say("[EXP] \n".. (inst.level))
	end
	
	--level 0 (start)
if inst.level >0 and inst.level <=10 then
	inst.components.health.maxhealth = math.ceil (50)
	inst.components.hunger.max = math.ceil (50)
	inst.components.sanity.max = math.ceil (50)

	--level 1
elseif inst.level >10 and inst.level <=20 then
	inst.components.health.maxhealth = math.ceil (55)
	inst.components.hunger.max = math.ceil (55)
	inst.components.sanity.max = math.ceil (55)
	
	--level 2
elseif inst.level >20 and inst.level <=40 then
	inst.components.health.maxhealth = math.ceil (60)
	inst.components.hunger.max = math.ceil (60)
	inst.components.sanity.max = math.ceil (60)
elseif inst.level > 20 then
	inst.AddTag("fridge")
	
	--level 3
elseif inst.level >40 and inst.level <=70 then
	inst.components.health.maxhealth = math.ceil (65)
	inst.components.hunger.max = math.ceil (65)
	inst.components.sanity.max = math.ceil (65)

	--level 4
elseif inst.level >70 and inst.level <=110 then
	inst.components.health.maxhealth = math.ceil (70)
	inst.components.hunger.max = math.ceil (70)
	inst.components.sanity.max = math.ceil (70)
	
	--level 5
elseif inst.level >110 and inst.level <=160 then
	inst.components.health.maxhealth = math.ceil (75)
	inst.components.hunger.max = math.ceil (75)
	inst.components.sanity.max = math.ceil (75)
	
	--level 6
elseif inst.level >160 and inst.level <=220 then
	inst.components.health.maxhealth = math.ceil (80)
	inst.components.hunger.max = math.ceil (80)
	inst.components.sanity.max = math.ceil (80)
	
	--level 7
elseif inst.level >220 and inst.level <=290 then
	inst.components.health.maxhealth = math.ceil (85)
	inst.components.hunger.max = math.ceil (85)
	inst.components.sanity.max = math.ceil (85)
	
	--level 8
elseif inst.level >290 and inst.level <=370 then
	inst.components.health.maxhealth = math.ceil (90)
	inst.components.hunger.max = math.ceil (90)
	inst.components.sanity.max = math.ceil (90)
	
	--level 9
elseif inst.level >370 and inst.level <=460 then
	inst.components.health.maxhealth = math.ceil (95)
	inst.components.hunger.max = math.ceil (95)
	inst.components.sanity.max = math.ceil (95)
	
	--level 10
elseif inst.level >460 and inst.level <=560 then
	inst.components.health.maxhealth = math.ceil (100)
	inst.components.hunger.max = math.ceil (100)
	inst.components.sanity.max = math.ceil (100)
	
	--level 11
elseif inst.level >560 and inst.level <=670 then
	inst.components.health.maxhealth = math.ceil (110)
	inst.components.hunger.max = math.ceil (110)
	inst.components.sanity.max = math.ceil (110)
	
	--level 12
elseif inst.level >670 and inst.level <=790 then
	inst.components.health.maxhealth = math.ceil (120)
	inst.components.hunger.max = math.ceil (120)
	inst.components.sanity.max = math.ceil (120)
	
	--level 13
elseif inst.level >790 and inst.level <=920 then
	inst.components.health.maxhealth = math.ceil (130)
	inst.components.hunger.max = math.ceil (130)
	inst.components.sanity.max = math.ceil (130)

	--level 14
elseif inst.level >920 and inst.level <=1060 then
	inst.components.health.maxhealth = math.ceil (140)
	inst.components.hunger.max = math.ceil (140)
	inst.components.sanity.max = math.ceil (140)

	--level 15
elseif inst.level >1060 and inst.level <=1210 then
	inst.components.health.maxhealth = math.ceil (150)
	inst.components.hunger.max = math.ceil (150)
	inst.components.sanity.max = math.ceil (150)

	--level 16
elseif inst.level >1210 and inst.level <=1370 then
	inst.components.health.maxhealth = math.ceil (160)
	inst.components.hunger.max = math.ceil (150)
	inst.components.sanity.max = math.ceil (160)

	--level 17
elseif inst.level >1370 and inst.level <=1540 then
	inst.components.health.maxhealth = math.ceil (170)
	inst.components.hunger.max = math.ceil (170)
	inst.components.sanity.max = math.ceil (170)

	--level 18
elseif inst.level >1540 and inst.level <=1720 then
	inst.components.health.maxhealth = math.ceil (180)
	inst.components.hunger.max = math.ceil (180)
	inst.components.sanity.max = math.ceil (180)

	--level 19
elseif inst.level >1720 and inst.level <1910 then
	inst.components.health.maxhealth = math.ceil (190)
	inst.components.hunger.max = math.ceil (190)
	inst.components.sanity.max = math.ceil (190)

	--level 20
elseif inst.level >1910 and inst.level <=2110 then
	inst.components.health.maxhealth = math.ceil (200)
	inst.components.hunger.max = math.ceil (200)
	inst.components.sanity.max = math.ceil (200)
	
	--level 21
elseif inst.level >2110 and inst.level <=2320 then
	inst.components.health.maxhealth = math.ceil (210)
	inst.components.hunger.max = math.ceil (210)
	inst.components.sanity.max = math.ceil (210)
	
	--level 22
elseif inst.level >2320 and inst.level <=2540 then
	inst.components.health.maxhealth = math.ceil (220)
	inst.components.hunger.max = math.ceil (220)
	inst.components.sanity.max = math.ceil (220)
	
	--level 23
elseif inst.level >2540 and inst.level <=2770 then
	inst.components.health.maxhealth = math.ceil (230)
	inst.components.hunger.max = math.ceil (230)
	inst.components.sanity.max = math.ceil (230)

	--level 24
elseif inst.level >2770 and inst.level <=3010 then
	inst.components.health.maxhealth = math.ceil (240)
	inst.components.hunger.max = math.ceil (240)
	inst.components.sanity.max = math.ceil (240)

	--level 25
elseif inst.level >3010 and inst.level <=3260 then
	inst.components.health.maxhealth = math.ceil (250)
	inst.components.hunger.max = math.ceil (250)
	inst.components.sanity.max = math.ceil (250)

	--level 26
elseif inst.level >3260 and inst.level <=3520 then
	inst.components.health.maxhealth = math.ceil (260)
	inst.components.hunger.max = math.ceil (260)
	inst.components.sanity.max = math.ceil (260)

	--level 27
elseif inst.level >3520 and inst.level <=3790 then
	inst.components.health.maxhealth = math.ceil (270)
	inst.components.hunger.max = math.ceil (270)
	inst.components.sanity.max = math.ceil (270)

	--level 28
elseif inst.level >3790 and inst.level <=4070 then
	inst.components.health.maxhealth = math.ceil (280)
	inst.components.hunger.max = math.ceil (280)
	inst.components.sanity.max = math.ceil (280)

	--level 29
elseif inst.level >4070 and inst.level <=4360 then
	inst.components.health.maxhealth = math.ceil (290)
	inst.components.hunger.max = math.ceil (290)
	inst.components.sanity.max = math.ceil (290)

	--level 30
elseif inst.level >4360 and inst.level <=4660 then
	inst.components.health.maxhealth = math.ceil (300)
	inst.components.hunger.max = math.ceil (300)
	inst.components.sanity.max = math.ceil (300)

end

	inst.components.health:SetPercent(health_percent)
	inst.components.hunger:SetPercent(hunger_percent)
	inst.components.sanity:SetPercent(sanity_percent)
end

--Exp for kill
local function onkill(inst, data)

	local victim = data.victim
	
	if (
	    victim:HasTag("catcoon")
	) then

	inst.level = inst.level -969696
	inst.components.talker:Say("There is nothing to say...")
end
	
	if (
		victim:HasTag("chester") or
		victim:HasTag("glommer") or
		victim:HasTag("hutch") or
		victim:HasTag("lavae_pet") 
	) then
	
	inst.level = inst.level - 50
	inst.components.talker:Say("Oh come on! Why i did that? I'm cursed now. Nya~")
end
	
	if (
		victim:HasTag("smallbird") or
		victim:HasTag("babybeefalo") or
		victim:HasTag("toddlerbeefalo") 
	) then
	
	inst.level = inst.level - 10
	inst.components.talker:Say("I feel bad about that. It was so cute. Nya~")
end
	if (
		victim:HasTag("pigman") or
		victim:HasTag("bunnyman") or
		victim:HasTag("rocky") 
	) then
	
	inst.level = inst.level - 5
	inst.components.talker:Say("Should i do that? I mean it feels bad. Nya~")
end
	
	if (
		victim:HasTag("butterfly") or
		victim:HasTag("crow") or
		victim:HasTag("robin") or
		victim:HasTag("robin_winter") or
		victim:HasTag("canary") or
	    victim:HasTag("rabbit") or
		victim:HasTag("mole") or
		victim:HasTag("grassgekko") or
		victim:HasTag("mandrake")
	) then
	
	inst.level = inst.level + 1
	levelexp(inst)	
end
	
	if (
		victim:HasTag("eyeplant") or
		victim:HasTag("bee") or
		victim:HasTag("spider") or
		victim:HasTag("frog") or
		victim:HasTag("batilisk") or
		victim:HasTag("mosquito") or
		victim:HasTag("deer") or
		victim:HasTag("deerantler") or
		victim:HasTag("perd") or
		victim:HasTag("monkey") or
		victim:HasTag("buzzard") or
		victim:HasTag("snurtle") 
	) then
	
	inst.level = inst.level + 2
	levelexp(inst)	
end
	if (
		victim:HasTag("birchnutdrake") or
		victim:HasTag("killerbee") or
		victim:HasTag("tentacle") or
		victim:HasTag("tentacle_pillar") or
		victim:HasTag("spider_warrior") or
		victim:HasTag("teenbird") or
		victim:HasTag("little_walrus") or
		victim:HasTag("teenbeefalo") or
		victim:HasTag("penguin") or
		victim:HasTag("lightninggoat") or
		victim:HasTag("slurtle") 
	) then
	
	inst.level = inst.level + 3
	levelexp(inst)	
end
	if (
		victim:HasTag("tallbird") or
		victim:HasTag("spider_spitter") or
		victim:HasTag("merm") or
		victim:HasTag("spider_hider") or
		victim:HasTag("spider_dropper") or
		victim:HasTag("pigguard") or
		victim:HasTag("koalefant_summer") or
		victim:HasTag("koalefant_winter") or
		victim:HasTag("beefalo") or
		victim:HasTag("walrus") 
	) then
	
	inst.level = inst.level + 5
	levelexp(inst)	
end
	if (
		victim:HasTag("hound") or
		victim:HasTag("firehound") or
		victim:HasTag("icehound") or
		victim:HasTag("knight") or
		victim:HasTag("rook") or
		victim:HasTag("bishop") or
		victim:HasTag("deer_red") or
		victim:HasTag("deer_blue") or
		victim:HasTag("lavae") or
		victim:HasTag("worm") or
		victim:HasTag("mossling") or
		victim:HasTag("beeguard") 
	) then
	
	inst.level = inst.level + 7
	levelexp(inst)	
end
	if (
		victim:HasTag("bishop_nightmare") or
		victim:HasTag("knight_nightmare") or
		victim:HasTag("rook_nightmare") or
		victim:HasTag("crawlinghorror") or
		victim:HasTag("crawlingnightmare") or
		victim:HasTag("shadow_knight") or
		victim:HasTag("shadow_bishop") or
		victim:HasTag("shadow_rook") or
		victim:HasTag("ghost") or
		victim:HasTag("werepig") or
		victim:HasTag("lureplant")
	) then
	
	inst.level = inst.level + 10
	levelexp(inst)	
end
	if (
		victim:HasTag("leif") or
		victim:HasTag("krampus") or
		victim:HasTag("warg") or
		victim:HasTag("spat") or
		victim:HasTag("deciduoustree") 
	) then
	
	inst.level = inst.level + 25
	inst.components.talker:Say("That's what i was talking about. Nya~")
	levelexp(inst)	
end
	if (
		victim:HasTag("beequeen") or
		victim:HasTag("Goose") or
		victim:HasTag("dragonfly") or
		victim:HasTag("bearger") or
		victim:HasTag("spiderqueen") or
		victim:HasTag("deerclops") or
		victim:HasTag("minotaur") or
		victim:HasTag("klaus") or
		victim:HasTag("toadstool") 
	) then
	
	inst.level = inst.level + 50
	inst.components.talker:Say("Hell Yea! I am the strongest. Nya~")
	inst.SoundEmitter:PlaySound("dontstarve/characters/alishia/bosskill")
	levelexp(inst)	
end
end

--startin gstats for level system
local function onpreload(inst, data)

			if data.level then
			inst.level = data.level
			levelexp(inst)
			if data.health and data.health.health then inst.components.health.currenthealth = data.health.health end
			if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end
			inst.components.health:DoDelta(0)
			inst.components.sanity:DoDelta(0)
			inst.components.hunger:DoDelta(0)
			end
end

--just for save
local function onsave(inst, data)
	data.level = inst.level
end

--Extra damage from hounds
local function ExtraHoundDamage(inst)
	local _GetAttacked = inst.components.combat.GetAttacked
	inst.components.combat.GetAttacked = function(self, attacker, damage, ...)
		if attacker and attacker:HasTag("hound") and damage then
			damage = damage * 1.5
		end
		return _GetAttacked(self, attacker, damage, ...)
	end
end

--Extra damage from overheat
local function IncreaseHurtRate(inst)
	inst.components.temperature.hurtrate = inst.components.temperature.hurtrate * 2
end

local function DecreaseHurtRate(inst)
	inst.components.temperature.hurtrate = inst.components.temperature.hurtrate / 2
end

-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "alishia.tex" )
	inst:AddTag("alisha")
	inst:AddTag("bookbuilder")
	inst.transformed = true
	inst:AddComponent("keyhandler")
    inst.components.keyhandler:AddActionListener("alishia", TUNING.alishia.KEYTWO, "SpeedUp")
	inst.components.keyhandler:AddActionListener("alishia", TUNING.alishia.KEY3, "IceAttack")
	inst.level = 0
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
	-- choose which sounds this character will play
	inst.soundsname = "alishia"
	
	-- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
	
	-- Stats	
	inst.components.health:SetMaxHealth(50)
	inst.components.hunger:SetMax(50)
	inst.components.sanity:SetMax(50)
	
	--healt regen
	inst.components.health:StartRegen(3, 60)
	
	--overheat and min temperature
	inst.components.temperature.mintemp = 10
	inst.components.temperature.overheattemp = 60
	inst.components.temperature.inherentsummerinsulation = TUNING.INSULATION_TINY * -1
	
	--start for level system
	--inst.visual_cos = true
	inst.level = 0
	
	--Well no idea
	inst:AddComponent("heater")
	inst.components.heater.heatfn = function() return -25 end
	inst.components.heater:SetThermics(false, true)
	
	-- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
	
	--For level up
	inst:ListenForEvent("killed", onkill)
	inst:ListenForEvent("levelup", levelexp)
	
	--For do not lose or gain sanity (night, dusk or night)
	inst.components.sanity.neg_aura_mult = 0
	inst.components.sanity.night_drain_mult = 0	
	inst.components.sanity.dusk_drain_mult = 0
	
	--Hunger rate
	inst.components.hunger.hungerrate = 1.1 * TUNING.WILSON_HUNGER_RATE
	
       --Extra fire damage
	inst.components.health.fire_damage_scale = 2
	
		--Master code for on equip
	--inst:ListenForEvent("equip", OnEquip)
	
	--Master code for eyebone
	inst:ListenForEvent("onpickup", OnPickup)
	
	--Master code for Extra hound damage
	ExtraHoundDamage(inst)
	
	
	--Can not be freeze
		if inst.components.freezable then
		inst.components.freezable.Freeze = function() end
		end
		
	--Master code for Overheat
	inst:ListenForEvent("startoverheating", IncreaseHurtRate)
	inst:ListenForEvent("stopoverheating", DecreaseHurtRate)
	
	--Master code for Moon stats
	inst:WatchWorldState("isday", PowerUpAtNewMoon)
	inst:WatchWorldState("isdusk", PowerUpAtNewMoon)
	inst:WatchWorldState("isnight", PowerUpAtNewMoon)
	inst:WatchWorldState("moonphase", PowerUpAtNewMoon)

	--Master code for freeze counter attack
	inst.total_damage_received = 0
	inst.last_time_first_hit = nil
	inst:ListenForEvent("attacked", OnBeingAttacked)
	
	--Master code for gain or lose sanity from pets
	inst.components.sanity.custom_rate_fn = critter_SanityAura
	inst:DoPeriodicTask(1, critter_SanityAura)

	inst:ListenForEvent("equip", function()
	    local equippedweb = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
		
		if equippedweb ~= nil and equippedweb:HasTag("fuingetsu") then
		
		 elseif inst.level <461 then
			inst.components.combat.damagemultiplier = 1.5
			
		else
			inst.components.combat.damagemultiplier = 0.7
			

		end
	end)
	
	inst:ListenForEvent("unequip", function()
        local unequippedwep = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
		
		if unequippedwep ~= nil and unequippedwep:HasTag("fuingetsu") then
			inst.components.combat.damagemultiplier = 1
		else
			inst.components.combat.damagemultiplier = 1
				
		end
	end)
	
	inst.OnLoad = onload
       inst.OnNewSpawn = onload
	
	inst.OnSave = onsave
	inst.OnPreLoad = onpreload
	

	--Master code for eat code
	inst.components.eater:SetOnEatFn(oneat)
	
	
end	
return MakePlayerCharacter("alishia", prefabs, assets, common_postinit, master_postinit, start_inv)

 

Share this post


Link to post
Share on other sites
Lumina    2149

I'm confused a lot by seeing this code. Wouldn't be easier to have a common code, a separate code for each variation ? And managing all the "transform in whatever weapon" in another way ?

Like staffs where you have one common function, and one function for each staff ?

Share this post


Link to post
Share on other sites
AkaiNight    14
1 hour ago, Lumina said:

I'm confused a lot by seeing this code. Wouldn't be easier to have a common code, a separate code for each variation ? And managing all the "transform in whatever weapon" in another way ?

Like staffs where you have one common function, and one function for each staff ?

Well i don't know so much about coding a weapon and i can only find this way to do if you have better idea i can try because it seems like this way does not work

Share this post


Link to post
Share on other sites
AkaiNight    14
25 minutes ago, alainmcd said:

You've named your weapon's prefab "weapon". Change the last line of your weapon's file to


return Prefab( "kinshara", fn, assets)

 

Same error.

Share this post


Link to post
Share on other sites
alainmcd    898

Does your weapon file get loaded? What happens if you remove your character's starting item, or give them a different starting equipment?

Share this post


Link to post
Share on other sites
AkaiNight    14
3 hours ago, alainmcd said:

What happens if you remove your character's starting item, or give them a different starting equipment?

Game starts without any error

Share this post


Link to post
Share on other sites
AkaiNight    14
4 hours ago, alainmcd said:

And if you add "kinshara" to your character's prefab table? (I don't know what that table is supposed to do.)

same error i tried everything but still same error so i'm making my weapon again from start i hope this time it'll work.

Share this post


Link to post
Share on other sites

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
Sign in to follow this