Jump to content

Recommended Posts

Hello, I'm trying to create a mod that will craft two stones, I managed to add the recipe in the recipe tab, and created the prefabs for them however when i click on the recipe to create those items I get an error without adding the AddPhysics() line I got an unknown error after adding it i got the error "attempt to call method 'AddPhysics' (a nil value)" below is the code of my prefab

local assets ={	Asset("IMAGE", "images/inventoryimages/angelstone.tex"),	Asset("ATLAS", "images/inventoryimages/angelstone.xml"),	Asset("IMAGE", "images/inventoryimages/devilstone.tex"),	Asset("ATLAS", "images/inventoryimages/devilstone.xml"),}local function use_stone(inst)	print "started using"	if inst:HasTag("angelstone") then		print "used angelstone"	elseif inst:HasTag("devilstone") then		print "used devilstone"	else		print "WTF?"	endendlocal function commonfn()	local inst = CreateEntity()    inst.entity:AddTransform()	inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()	inst:AddPhysics()	MakeInventoryPhysics(inst)		inst:AddComponent("inventoryitem")	--inst.AddComponent("useableitem")	--inst.components.useableitem:SetOnUseFn(use_stone)    --inst:AddComponent("inspectable")    	--inst.entity:AddTransform()	--inst.entity:AddAnimState()    return instendlocal function angelstone()	local inst = commonfn()	inst:AddTag("angelstone")	inst.components.inventoryitem.atlasname = "images/inventoryimages/angelstone.xml"endlocal function devilstone()	local inst = commonfn()	inst:AddTag("devilstone")	inst.components.inventoryitem.atlasname = "images/inventoryimages/devilstone.xml"endreturn Prefab( "common/inventory/angelstone", angelstone, assets),       Prefab( "common/inventory/devilstone", devilstone, assets) 
what am I doing wrong?

My guess is he did, by replacing inst:AddPhysics() with inst.entity:AddPhysics().

I'll have to take note of that for future use.I hate to branch off from the topic, but I had a question for you [MENTION=44092]simplex[/MENTION]
Could you tell me how I can have this actually occur during the game? If I remove the item check, it all works as it should. I think that the reason it isn't working is because I'm checking to see if "candle" is equipped, and that check doesn't run constantly?Or am I checking for the equipped item incorrectly?
function go_away(inst)	inst:DoTaskInTime(0, function()		local MainCharacter = GetPlayer()	local has_candle = MainCharacter.components.inventory:IsItemEquipped("candle")		if has_candle then		print "Run away, little monster!"		no_harm = 100		inst.components.combat:BlankOutAttacks(no_harm)	end			end)endfunction scared_away(inst)	inst:AddTag("scared")	inst:AddComponent("playerprox")	inst.components.playerprox:SetDist(6,10)	inst.components.playerprox:SetOnPlayerNear(go_away)end--List of enemies that can be kept away.AddPrefabPostInit('spider', scared_away)

I'll have to take note of that for future use.I hate to branch off from the topic, but I had a question for you [MENTION=44092]simplex[/MENTION]

Could you tell me how I can have this actually occur during the game? If I remove the item check, it all works as it should. I think that the reason it isn't working is because I'm checking to see if "candle" is equipped, and that check doesn't run constantly?Or am I checking for the equipped item incorrectly?
function go_away(inst)	inst:DoTaskInTime(0, function()		local MainCharacter = GetPlayer()	local has_candle = MainCharacter.components.inventory:IsItemEquipped("candle")		if has_candle then		print "Run away, little monster!"		no_harm = 100		inst.components.combat:BlankOutAttacks(no_harm)	end			end)endfunction scared_away(inst)	inst:AddTag("scared")	inst:AddComponent("playerprox")	inst.components.playerprox:SetDist(6,10)	inst.components.playerprox:SetOnPlayerNear(go_away)end--List of enemies that can be kept away.AddPrefabPostInit('spider', scared_away)
Just by looking at the code, I'd say it's doing what it was written to do: prevent enemies from attacking you. You'd still have to write some sort of code to apply movement in the opposite direction of the player, since currently there is none. But, as general notes, you should really set no_harm to something much lower (such as 2, just don't set it below 0.333), and preferably declare it local. And you don't really have to put it inside a DoTaskInTime call, just do it directly. go_away gets called every 0.333 seconds whenever the player is close enough.

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