Dodgerer Posted October 22, 2017 Share Posted October 22, 2017 So i recently made a mod that adds a crockpot recipe, now when i tested it, it worked, and I could make the crockpot recipe, so i added it to my server and there, when attempting to make a different crockpot recipe it crashed(attempt to compare nil value) basically the only recipe i can make is the recipe i added and all other recipes crash the game, it had no adverse effects post removal of mod but I would like to find out what part of the code I have wrong, as I have copied it from the apiexamples modmain.lua Spoiler modmain.lua Spoiler PrefabFiles = { "speargun", "speargun_projectile", "inv_rocks", "flint", "cutstone", "spear", } GLOBAL.STRINGS.NAMES.SPEARGUN= "Speargun" STRINGS = GLOBAL.STRINGS RECIPETABS = GLOBAL.RECIPETABS Recipe = GLOBAL.Recipe Ingredient = GLOBAL.Ingredient TECH = GLOBAL.TECH STRINGS.RECIPE_DESC.SPEARGUN = "For when you want to get that spear into a far away enemy" -- Declare new fueltype for Speargun: GLOBAL.FUELTYPE["SPEARGUN"] = "SPEARGUN" --addingredient spear AddIngredientValues({"spear"}, {inedible=2}) -- Add a new recipe which requires spears as an ingredient. -- NOTE!!! No prefabs for this recipe exist, so you won't actually be able to -- cook it. This is just a code sample. local speargun = { name = "speargun", test = function(cookpot, names, tags) return tags.inedible >= 7 end, priority = 0.1, weight = 1, -- foodtype="VEGGIE", -- health = TUNING.HEALING_TINY, -- hunger = TUNING.CALORIES_LARGE, -- sanity = TUNING.SANITY_TINY, -- perishtime = TUNING.PERISH_MED, cooktime = 0.05, } AddCookerRecipe("cookpot", speargun) notably, when testing the item itself(it's a weapon) it works as planned and can be crafted as planned. also note, there's a large number of spaces that didn't paste from the modmain.lua, and I know I didn't define the foodtype etc as it is not a food. the weapon itself is not the same as from SW but uses the assets, and a fuel system and is created with half the fuel intact. speargun.lua Spoiler local assets= { Asset("ANIM", "anim/speargun.zip"), Asset("ANIM", "anim/swap_speargun.zip"), Asset("ATLAS", "images/inventoryimages/speargun.xml"), Asset("IMAGE", "images/inventoryimages/speargun.tex"), } local prefabs = { "impact", "speargun_projectile", } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_speargun", "swap_speargun") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function onunequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_object") owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local function onhit(inst, attacker, target) local impactfx = SpawnPrefab("impact") if impactfx ~= nil then local follower = impactfx.entity:AddFollower() follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0) if attacker ~= nil then impactfx:FacePoint(attacker.Transform:GetWorldPosition()) end end inst:Remove() end local function onprojectilelaunch(inst, target) inst.components.fueled:DoDelta(-1) end local function SpearGunCanAcceptFuelItem(self, item) if item ~= nil and item.components.fuel ~= nil and (item.components.fuel.fueltype == FUELTYPE.SPEARGUN or item.prefab == "rocks" or item.prefab == "flint" or item.prefab == "spear" or item.prefab == "cutstone") then return true else return false end end local function SpearGunTakeFuel(self, item) if self:CanAcceptFuelItem(item) then if item.prefab == "flint" then inst.components.fueled:DoDelta(1) end item:Remove() return true end if self:CanAcceptFuelItem(item) then if item.prefab =="rocks" then inst.components.fueled:DoDelta(1) end item:Remove() return true end if self:CanAcceptFuelItem(item) then if item.prefab =="spear" then inst.components.fueled:DoDelta(4) end item:Remove() return true end if self:CanAcceptFuelItem(item) then if item.prefab =="cutrocks" then inst.components.fueled:DoDelta(5) end item:Remove() return true end end local function init(anim, tags, removephysicscolliders) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("speargun") inst.AnimState:SetBuild("speargun") inst.AnimState:PlayAnimation("speargun") --- inst:AddTag("speargun") inst:AddTag("swap") inst:AddTag("projectile") --- if tags ~= nil then -- for i, v in ipairs(tags) do -- inst:AddTag(v) -- end -- end if removephysicscolliders then RemovePhysicsColliders(inst) end if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("fueled") inst.components.fueled.accepting = true inst.components.fueled.fueltype = FUELTYPE.SPEARGUN inst.components.fueled.maxfuel = 100 inst.components.fueled:StopConsuming() inst.components.fueled.currentfuel = 50 inst.components.fueled.CanAcceptFuelItem = SpearGunCanAcceptFuelItem inst.components.fueled.accepting = true inst:AddComponent("weapon") inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE) inst.components.weapon:SetRange(9, 11) inst.components.weapon:SetProjectile("speargun_projectile") inst.components.weapon:SetOnProjectileLaunch(onprojectilelaunch) -- inst:AddComponent("projectile") -- inst.components.projectile:SetSpeed(60) -- inst.components.projectile:SetOnHitFn(onhit) -- inst:ListenForEvent("onthrown", onthrown) ------- inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/speargun.xml" inst.components.inventoryitem.imagename = "speargun" inst:AddComponent("equippable") inst.components.equippable:SetOnEquip(onequip) inst.components.equippable:SetOnUnequip(onunequip) inst.noammo = 1 inst:DoPeriodicTask(1/10, function() -- Don't take fuel if magazine is full! if inst.components.fueled.maxfuel == inst.components.fueled.currentfuel and inst.components.fueled.accepting == true then inst.components.fueled.accepting = false end -- If gun magazine was emptied and refueled, restore its abilities! if not inst:HasTag("emptygun") and inst.components.fueled:IsEmpty() then inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE) inst.components.weapon:SetRange(9, 11) inst.components.weapon:SetProjectile("speargun_projectile") inst.components.weapon:SetOnProjectileLaunch(onprojectilelaunch) end -- empty gun loses range and attack if inst.components.fueled:IsEmpty() then if not inst:HasTag("emptygun") then inst:AddTag("emptygun") end inst.components.weapon:SetRange(5, 7) inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*0.5) end if not inst.components.fueled:IsEmpty() and inst:HasTag("emptygun") then inst:RemoveTag("emptygun") end end) MakeHauntableLaunch(inst) return inst end return Prefab( "common/inventory/speargun", init, assets, prefabs) speargun_projectile.lua Spoiler local assets = { Asset("ANIM", "anim/spear.zip"), } local prefabs = { "impact", } local function onhit(inst, attacker, target) local impactfx = SpawnPrefab("impact") if impactfx ~= nil then local follower = impactfx.entity:AddFollower() follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0) if attacker ~= nil then impactfx:FacePoint(attacker.Transform:GetWorldPosition()) end end local activeitem = attacker.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) local dmgmult = attacker.components.combat.damagemultiplier -- We've dealt damage... but what about target aggro? Let's fix this: if target and target.components.combat then target.components.combat:SuggestTarget(attacker) end inst:Remove() end local function common(anim, bloom) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) RemovePhysicsColliders(inst) inst.AnimState:SetBank("speargun") inst.AnimState:SetBuild("speargun") inst.AnimState:PlayAnimation("speargun") --- inst.AnimState:PlayAnimation("animsparrow_projectile", true) if bloom ~= nil then inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh") end inst:AddTag("projectile") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("projectile") inst.components.projectile:SetSpeed(38) inst.components.projectile:SetOnHitFn(onhit) inst.components.projectile:SetOnMissFn(inst.Remove) return inst end return Prefab("common/inventory/speargun_projectile", common, assets) spear, flint,inv_rocks, cutstone, all got this line[just under inst:AddComponent("inventoryitem")]: Spoiler inst:AddComponent("fuel") inst.components.fuel.fueltype = FUELTYPE.SPEARGUN Link to comment Share on other sites More sharing options...
Lumina Posted October 22, 2017 Share Posted October 22, 2017 Is there a reason why you make your weapon in the crockpot ? Why not using classic recipe ? Link to comment Share on other sites More sharing options...
Dodgerer Posted October 22, 2017 Author Share Posted October 22, 2017 using 4 spears for instance doesn't allow for the recdipe to show for me in the fight tab. Link to comment Share on other sites More sharing options...
w00tyd00d Posted October 22, 2017 Share Posted October 22, 2017 (edited) 2 hours ago, Dodgerer said: using 4 spears for instance doesn't allow for the recdipe to show for me in the fight tab. Spoiler Like this? You might've gotten a part of your AddRecipe() syntax wrong but it is entirely possible to make a recipe with 4 spears the code I used: AddRecipe("<your item here>", {Ingredient("spear", 4)}, RECIPETABS.WAR, TECH.SCIENCE_TWO) GLOBAL.STRINGS.RECIPE_DESC.<YOUR ITEM HERE> = "The power of 4 spears combined!" -- Then if you wanted to make it appear at the top of the crafting grid, you can insert this line too GLOBAL.AllRecipes["tentaclespike"].sortkey = -1 Hope this helped! Edited October 22, 2017 by w00tyd00d Link to comment Share on other sites More sharing options...
Dodgerer Posted October 22, 2017 Author Share Posted October 22, 2017 (edited) Wooty, thank you I just realized, I was using RECIPETABS.FIGHT instead of WAR before. Note, I would still like to know why this problem happened for future modding problems. Edited October 22, 2017 by Dodgerer Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now