Jump to content

[Coding Request] Vegetarian and Friendly to mobs


Nyogtha

Recommended Posts

I have for the most part produced a small set of character for my friends by cannibalizing code.

 

Unfortunately, no matter what code I try to pull these two particular traits from, they don't work.

 

I am trying to make a character that is a vegetarian (only able to eat "non meat" items) and is friendly to all mobs in the game.

 

Honestly though, I'd settle for any mobs in regards to that code. I copy pasted the code from Webber, Cthulhu, and a dozen others and everything still attacked the character, instead of being friendly.

 

I think I could get them all to just not attack by doing things with the targeting, but I would rather have them just be friendly.

 

Thank you so much for any help.

Thought this might be useful, the current code for the character:

 

I am using the esc template, haven't updated anything yet.

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),        Asset( "ANIM", "anim/esctemplate.zip" ),        Asset( "ANIM", "anim/ghost_esctemplate_build.zip" ),}local prefabs = {}local start_inv = {	"fireflies",	"fireflies",	"fireflies",	"fireflies",}-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- choose which sounds this character will play	inst.soundsname = "wendy"	-- Minimap icon	inst.MiniMapEntity:SetIcon( "esctemplate.tex" )end-- This initializes for the host onlylocal function master_postinit(inst)	--Friendly	-- Stats		inst.components.locomotor.walkspeed = (4)		inst.components.locomotor.runspeed = (6)	inst.components.health:SetMaxHealth(150)	inst.components.hunger:SetMax(50)	inst.components.sanity:SetMax(100)		local function updateHungerRate(inst, mult)       inst.components.hunger:SetRate(mult*TUNING.WILSON_HUNGER_RATE)end  inst:WatchWorldState( "startday", function() updateHungerRate(inst, -.5) end )inst:WatchWorldState( "startdusk", function() updateHungerRate(inst, 0) end )inst:WatchWorldState( "startnight", function() updateHungerRate(inst, 1.5) end )endreturn MakePlayerCharacter("esctemplate", prefabs, assets, common_postinit, master_postinit, start_inv)

>everything still attacked the character

you always will be attacked by "monsters", doesn't matter what you eat, unless you have same tag with them or change their code.

peaceful(like rabbits)/neutral(like pigs) creatures usually runaway or attack player with "monster" tag, so just don't use it.

about vegetarian - look how other vegetarian characters made, its just one option about food. I don't remember how its exactly called, i didn't touched DS source since august.

I have for the most part produced a small set of character for my friends by cannibalizing code.

 

Unfortunately, no matter what code I try to pull these two particular traits from, they don't work.

 

I am trying to make a character that is a vegetarian (only able to eat "non meat" items) and is friendly to all mobs in the game.

 

Honestly though, I'd settle for any mobs in regards to that code. I copy pasted the code from Webber, Cthulhu, and a dozen others and everything still attacked the character, instead of being friendly.

 

I think I could get them all to just not attack by doing things with the targeting, but I would rather have them just be friendly.

 

Thank you so much for any help.

 

Just copy the codes from "WINNIE" mod by Cyde042 . Winnie is a Vegetarian.

 

Meet the Vegetarian [WIP]

 

 

>everything still attacked the character

you always will be attacked by "monsters", doesn't matter what you eat, unless you have same tag with them or change their code.

 

I actually tried using tags. I tried several in fact, to see if I could get the character to count as everything:

local function common_postinit(inst)	inst:AddTag("merm")        inst:AddTag("spider")

But it didn't work.

 

I think tried just one tag:

local function common_postinit(inst)	inst:AddTag("spider")end--Current Code

but that didn't work either.

 

Are these supposed to exist under a specific section?

 

 

 

Just copy the codes from "WINNIE" mod by Cyde042 . Winnie is a Vegetarian.

 

 

I tried copy/pasting her code specifically for that reason, and in short order, I could never quiet get it to load.

 

I may try editing her character .lua for this. That may be the solution.

just call the eater component and SetVegetarian()

 

I'm not OP but how do you do that? I am working on a herbivorous character, only I started modding just a few days ago so I don't have much of a grasp on the component system.

Thanks for all the help so far.

 

I have given up on making the character friendly to all monsters, and have tried a few others things.

 

Unfortunately, some aren't working quite right.

 

I am trying to add a few additional foods to vegetarianism, like honey, but I cannot. I am not sure why they aren't working.

 

I am also trying to have the character level up from dragon pies. That is also not working at all.

 

Could someone provide advice as to the issue?

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),        Asset( "ANIM", "anim/spek.zip" ),        Asset( "ANIM", "anim/ghost_spek_build.zip" ),}local prefabs = {}local start_inv = {	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",}-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- choose which sounds this character will play	inst.soundsname = "wendy"	-- Minimap icon	inst.MiniMapEntity:SetIcon( "spek.tex" )end-- This initializes for the host onlylocal function master_postinit(inst)	--Friendly	inst:RemoveTag("scarytoprey")local foodset = {	tallbirdegg = true,	bird_egg = true,	goatmilk = true,	butter = true,	honey = true,}	-- Stats		inst.components.eater:SetVegetarian()local function applyupgrades(inst)	local max_upgrades = 10	local upgrades = math.min(inst.level, max_upgrades)	local hunger_percent = inst.components.hunger:GetPercent()	local health_percent = inst.components.health:GetPercent()	local sanity_percent = inst.components.sanity:GetPercent()	inst.components.hunger.max = math.ceil (10 + upgrades * 5)	inst.components.health.maxhealth = math.ceil (10 + upgrades * 4)	inst.components.sanity.max = math.ceil (10 + upgrades * 2)	inst.components.locomotor.walkspeed =  math.ceil (4 + upgrades / 6)		inst.components.locomotor.runspeed = math.ceil (6 + upgrades / 5)		inst.components.talker:Say("Level : ".. (inst.level))		if inst.level >9 then		inst.components.talker:Say("Level : Max!")	end	inst.components.hunger:SetPercent(hunger_percent)	inst.components.health:SetPercent(health_percent)	inst.components.sanity:SetPercent(sanity_percent)	endlocal function oneat(inst, food)		--if food and food.components.edible and food.components.edible.foodtype == "HELLO" then	if food and food.components.edible and food.prefab == "dragonpie"  then		--give an upgrade!		inst.level = inst.level + 1		applyupgrades(inst)			inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")		--inst.HUD.controls.status.heart:PulseGreen()		--inst.HUD.controls.status.stomach:PulseGreen()		--inst.HUD.controls.status.brain:PulseGreen()				--inst.HUD.controls.status.brain:ScaleTo(1.3,1,.7)		--inst.HUD.controls.status.heart:ScaleTo(1.3,1,.7)		--inst.HUD.controls.status.stomach:ScaleTo(1.3,1,.7)	endend	local function updateHungerRate(inst, mult)       inst.components.hunger:SetRate(mult*TUNING.WILSON_HUNGER_RATE)endinst:WatchWorldState( "startday", function() updateHungerRate(inst, -.5) end )inst:WatchWorldState( "startdusk", function() updateHungerRate(inst, 0) end )inst:WatchWorldState( "startnight", function() updateHungerRate(inst, 2) end )local mult = 0if TheWorld.state.isday then mult = -.5elseif TheWorld.state.isnight then mult = 2 endupdateHungerRate(inst, mult)endreturn MakePlayerCharacter("spek", prefabs, assets, common_postinit, master_postinit, start_inv)

Fair warning, stat numbers aren't balanced yet.

Got leveling working, just can't add the extra edibles. Any advice would be great!

local MakePlayerCharacter = require "prefabs/player_common"local assets = {        Asset( "ANIM", "anim/player_basic.zip" ),        Asset( "ANIM", "anim/player_idles_shiver.zip" ),        Asset( "ANIM", "anim/player_actions.zip" ),        Asset( "ANIM", "anim/player_actions_axe.zip" ),        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),        Asset( "ANIM", "anim/player_actions_shovel.zip" ),        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),        Asset( "ANIM", "anim/player_actions_eat.zip" ),        Asset( "ANIM", "anim/player_actions_item.zip" ),        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),        Asset( "ANIM", "anim/player_actions_fishing.zip" ),        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),        Asset( "ANIM", "anim/player_bush_hat.zip" ),        Asset( "ANIM", "anim/player_attacks.zip" ),        Asset( "ANIM", "anim/player_idles.zip" ),        Asset( "ANIM", "anim/player_rebirth.zip" ),        Asset( "ANIM", "anim/player_jump.zip" ),        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),        Asset( "ANIM", "anim/player_teleport.zip" ),        Asset( "ANIM", "anim/wilson_fx.zip" ),        Asset( "ANIM", "anim/player_one_man_band.zip" ),        Asset( "ANIM", "anim/shadow_hands.zip" ),        Asset( "SOUND", "sound/sfx.fsb" ),        Asset( "SOUND", "sound/wilson.fsb" ),        Asset( "ANIM", "anim/beard.zip" ),        Asset( "ANIM", "anim/spek.zip" ),        Asset( "ANIM", "anim/ghost_spek_build.zip" ),}local prefabs = {}local start_inv = {	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",	"fireflies",}--Level Uplocal function applyupgrades(inst)	local max_upgrades = 30	local upgrades = math.min(inst.level, max_upgrades)	local hunger_percent = inst.components.hunger:GetPercent()	local health_percent = inst.components.health:GetPercent()	local sanity_percent = inst.components.sanity:GetPercent()	inst.components.hunger.max = math.ceil (50 + upgrades * 2) --300	inst.components.health.maxhealth = math.ceil (100 + upgrades * 2) --220	inst.components.sanity.max = math.ceil (150 + upgrades * 2) --150		inst.components.locomotor.walkspeed =  math.ceil (6 + upgrades / 6) --9	inst.components.locomotor.runspeed = math.ceil (8 + upgrades / 5) --12		inst.components.talker:Say("Level : ".. (inst.level))		if inst.level >29 then		inst.components.talker:Say("Level : Max!")	end	inst.components.hunger:SetPercent(hunger_percent)	inst.components.health:SetPercent(health_percent)	inst.components.sanity:SetPercent(sanity_percent)	endlocal function oneat(inst, food)		--if food and food.components.edible and food.components.edible.foodtype == "HELLO" then	if food and food.components.edible and food.prefab == "dragonpie"  then		--give an upgrade!		inst.level = inst.level + 1		applyupgrades(inst)			inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")		--inst.HUD.controls.status.heart:PulseGreen()		--inst.HUD.controls.status.stomach:PulseGreen()		--inst.HUD.controls.status.brain:PulseGreen()				--inst.HUD.controls.status.brain:ScaleTo(1.3,1,.7)		--inst.HUD.controls.status.heart:ScaleTo(1.3,1,.7)		--inst.HUD.controls.status.stomach:ScaleTo(1.3,1,.7)	endendlocal function onpreload(inst, data)	if data then		if data.level then			inst.level = data.level			applyupgrades(inst)			--re-set these from the save data, because of load-order clipping issues			if data.health and data.health.health then inst.components.health.currenthealth = data.health.health end			if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end			if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end			inst.components.health:DoDelta(0)			inst.components.hunger:DoDelta(0)			inst.components.sanity:DoDelta(0)		end	endendlocal function onsave(inst, data)	data.level = inst.level	data.charge_time = inst.charge_timeend-- This initializes for both clients and the hostlocal common_postinit = function(inst) 	-- choose which sounds this character will play	inst.soundsname = "wendy"	-- Minimap icon	inst.MiniMapEntity:SetIcon( "spek.tex" )end-- This initializes for the host onlylocal function master_postinit(inst)	--Friendly	inst:RemoveTag("scarytoprey")	inst.level = 0	inst.components.eater:SetOnEatFn(oneat)	inst.OnSave = onsave	inst.OnPreLoad = onpreloadlocal foodset = {	tallbirdegg = true,	bird_egg = true,	goatmilk = true,	butter = true,	honey = true,}--Stats		inst.components.eater:SetVegetarian()	local function updateHungerRate(inst, mult)       inst.components.hunger:SetRate(mult*TUNING.WILSON_HUNGER_RATE)endinst:WatchWorldState( "startday", function() updateHungerRate(inst, -.5) end )inst:WatchWorldState( "startdusk", function() updateHungerRate(inst, 0) end )inst:WatchWorldState( "startnight", function() updateHungerRate(inst, 2) end )local mult = 0if TheWorld.state.isday then mult = -.5elseif TheWorld.state.isnight then mult = 2 endupdateHungerRate(inst, mult)endreturn MakePlayerCharacter("spek", prefabs, assets, common_postinit, master_postinit, start_inv)

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