icantevenname Posted April 10, 2017 Share Posted April 10, 2017 The mod I'm working on at the moment is the Sunflower from Plants Vs. Zombies. More specifically her Garden Warfare appearance. I feel like keeping her medic capabilities, and I want to do that by having her drop healing suns every now and then. I'm sure I can figure out making the suns, but I have no idea how to have her drop suns regularly. Any pointers please? Link to comment Share on other sites More sharing options...
IronHunter Posted April 10, 2017 Share Posted April 10, 2017 You'll probably want to look into making a DoPeriodicTask(time, function) that is called at the interval you want it to drop suns. The function you are calling will drop the suns. If you need more in depth assistance just ask. Link to comment Share on other sites More sharing options...
icantevenname Posted April 11, 2017 Author Share Posted April 11, 2017 3 hours ago, IronHunter said: You'll probably want to look into making a DoPeriodicTask(time, function) that is called at the interval you want it to drop suns. The function you are calling will drop the suns. If you need more in depth assistance just ask. This goes under that master_postinit thing, right? By time, is it an already set increment, or do I have to set a specific increment as well as a number? Like seconds, minutes, in-game days? And for function, do I put in drop_sun, or spawn_sun, or something like that? Link to comment Share on other sites More sharing options...
IronHunter Posted April 11, 2017 Share Posted April 11, 2017 (edited) Assuming you are using the sample_character template: You can do something like this: Spoiler local function spawnitem(quantity, prefab, location) local quantity = 1 if quantity > 0 then for i = 1, quantity do local item = SpawnPrefab(prefab) if item ~= nil then local x, y, z = location.Transform:GetWorldPosition() if item.Physics ~= nil then local speed = 2 + math.random() local angle = math.random() * 2 * PI item.Transform:SetPosition(x, y + 1, z) item.Physics:SetVel(speed * math.cos(angle), speed * 3, speed * math.sin(angle)) else item.Transform:SetPosition(x, y, z) end if item.components.propagator ~= nil then item.components.propagator:Delay(5) end end end end end local function onbecamehuman(inst) inst.sunTask = inst:DoPeriodicTask(5, spawnitem(1, "sundrop", inst)) end local function onbecameghost(inst) if inst.sunTask ~= nil then inst.sunTask:Cancel() inst.sunTask = nil end end local function onload(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end Ok to explain: inst:DoPeriodicTask(time in seconds, function that is called when that amount of time passes) The spawnitem thing is something I use for a bunch of stuff in my mod as a catch all useful thing. I can explain in more detail, but hopefully you should be able to decipher the rest. Edited April 11, 2017 by IronHunter This is to help get you in the right direction, hopefully you can modify it from there to your needs. Link to comment Share on other sites More sharing options...
icantevenname Posted April 11, 2017 Author Share Posted April 11, 2017 I'm confused, I put in the code, just changing "sundrop" to "meat" (I wanna see if the code works before I make the suns.) I waited around for at least an in-game day and nothing happened. I died and revived and dropped meat. I died multiple times and each time I revived, I dropped meat. Link to comment Share on other sites More sharing options...
IronHunter Posted April 11, 2017 Share Posted April 11, 2017 Please post your characters code so that I can see how you are integrating the code with the character template. Link to comment Share on other sites More sharing options...
icantevenname Posted April 12, 2017 Author Share Posted April 12, 2017 local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), Asset( "ANIM", "anim/sunny.zip" ), Asset( "ANIM", "anim/ghost_sunny_build.zip" ), } local prefabs = {} -- Custom starting items local start_inv = { } -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "sunny_speed_mod", 1) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "sunny_speed_mod") end local function spawnitem(quantity, prefab, location) local quantity = 1 if quantity > 0 then for i = 1, quantity do local item = SpawnPrefab(prefab) if item ~= nil then local x, y, z = location.Transform:GetWorldPosition() if item.Physics ~= nil then local speed = 2 + math.random() local angle = math.random() * 2 * PI item.Transform:SetPosition(x, y + 1, z) item.Physics:SetVel(speed * math.cos(angle), speed * 3, speed * math.sin(angle)) else item.Transform:SetPosition(x, y, z) end if item.components.propagator ~= nil then item.components.propagator:Delay(5) end end end end end local function onbecamehuman(inst) inst.sunTask = inst:DoPeriodicTask(5, spawnitem(1, "meat", inst)) end local function onbecameghost(inst) if inst.sunTask ~= nil then inst.sunTask:Cancel() inst.sunTask = nil end end local function onload(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "sunny.tex" ) 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 = "sunny" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(250) inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.GOODIES }) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = .75 * TUNING.WILSON_HUNGER_RATE local easing = require("easing") inst.components.sanity.custom_rate_fn = function(inst) local wet_dapperness = 0 for _,v in pairs(inst.components.inventory.equipslots) do if v.components.equippable ~= nil then if v.components.equippable.inst:GetIsWet() then wet_dapperness = wet_dapperness + TUNING.WET_ITEM_DAPPERNESS end end end wet_dapperness = wet_dapperness * inst.components.sanity.dapperness_mult local wet_dapper_delta = wet_dapperness * TUNING.SANITY_DAPPERNESS local moisture_delta = easing.inSine(inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, inst.components.moisture:GetMaxMoisture()) return -5.0*(moisture_delta+wet_dapper_delta) end inst.components.locomotor.walkspeed = 7 inst.components.locomotor.runspeed = 8 inst.OnLoad = onload inst.OnNewSpawn = onload end return MakePlayerCharacter("sunny", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
IronHunter Posted April 12, 2017 Share Posted April 12, 2017 Sorry for the delayed reply, been busy with school. Spoiler local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), Asset( "ANIM", "anim/sunny.zip" ), Asset( "ANIM", "anim/ghost_sunny_build.zip" ), } local prefabs = {} -- Custom starting items local start_inv = { } local function spawnitem(quantity, prefab, location) local quantity = 1 if quantity > 0 then for i = 1, quantity do local item = SpawnPrefab(prefab) if item ~= nil then local x, y, z = location.Transform:GetWorldPosition() if item.Physics ~= nil then local speed = 2 + math.random() local angle = math.random() * 2 * PI item.Transform:SetPosition(x, y + 1, z) item.Physics:SetVel(speed * math.cos(angle), speed * 3, speed * math.sin(angle)) else item.Transform:SetPosition(x, y, z) end if item.components.propagator ~= nil then item.components.propagator:Delay(5) end end end end end -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "sunny_speed_mod", 1) inst.sunTask = inst:DoPeriodicTask(5, function () spawnitem(1, "meat", inst) end) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "sunny_speed_mod") if inst.sunTask ~= nil then inst.sunTask:Cancel() inst.sunTask = nil end end local function onload(inst, data) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "sunny.tex" ) 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 = "sunny" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(200) inst.components.sanity:SetMax(250) inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.GOODIES }) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = .75 * TUNING.WILSON_HUNGER_RATE local easing = require("easing") inst.components.sanity.custom_rate_fn = function(inst) local wet_dapperness = 0 for _,v in pairs(inst.components.inventory.equipslots) do if v.components.equippable ~= nil then if v.components.equippable.inst:GetIsWet() then wet_dapperness = wet_dapperness + TUNING.WET_ITEM_DAPPERNESS end end end wet_dapperness = wet_dapperness * inst.components.sanity.dapperness_mult local wet_dapper_delta = wet_dapperness * TUNING.SANITY_DAPPERNESS local moisture_delta = easing.inSine(inst.components.moisture:GetMoisture(), 0, TUNING.MOISTURE_SANITY_PENALTY_MAX, inst.components.moisture:GetMaxMoisture()) return -5.0*(moisture_delta+wet_dapper_delta) end inst.components.locomotor.walkspeed = 7 inst.components.locomotor.runspeed = 8 inst.OnLoad = onload inst.OnNewSpawn = onload end return MakePlayerCharacter("sunny", prefabs, assets, common_postinit, master_postinit, start_inv) Merged your become human and become ghost functions and also fixed the DoPeriodicTask it requires a function to call the spawn the function. Works fine for me Cheers Link to comment Share on other sites More sharing options...
icantevenname Posted April 13, 2017 Author Share Posted April 13, 2017 Thanks alot! Now to make the suns. I bet I'll be fine doing that. Thanks again! 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