Hse Posted November 4, 2017 Share Posted November 4, 2017 (edited) hello-o, i'm new here and english is not my main language so sorry if my sentences suxx a bit D: sooo i don't know how to code and i'm trying to make a wood character mod and i want him to "spawn" wood logs when he takes damages from ennemies. and also, sometimes just spawn randomly wood logs when he walks/runs is this possible? thank you for your help and time Edited November 15, 2017 by Hse Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/ Share on other sites More sharing options...
Hse Posted November 9, 2017 Author Share Posted November 9, 2017 bumpi ;w; Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972271 Share on other sites More sharing options...
Lumina Posted November 9, 2017 Share Posted November 9, 2017 Try looking at event. Something like this inst:ListenForEvent("attacked", OnAttacked) Then set an "OnAttacked" function that will drop an item, maybe something random so it doesn't happen at every hit. Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972297 Share on other sites More sharing options...
Cunning fox Posted November 9, 2017 Share Posted November 9, 2017 This will spawn log with 50% chance when your char got hitted inst:ListenForEvent("attacked", function(inst) inst:DoRaskInTime(0, function(inst) if math.random <= .5 then local wood = SpawnPrefab("log") wood.Transform:SetPostiton(inst.Transform:GetWorldPosition()) if wood.Physics ~= nil then local x, y, z = wood.Transform:GetWorldPosition() wood.Physics:Teleport(x, .3, z) local angle = (math.random() * 20 - 10) * DEGREES angle = angle + math.random() * 2 * PI local speed = projectile and 2 + math.random() or 3 + math.random() * 2 wood.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed) end end end) end) 1 Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972369 Share on other sites More sharing options...
Hse Posted November 9, 2017 Author Share Posted November 9, 2017 (edited) oooo ty for your answer ! do i have the put Lumina's code first ? there is an error message when i start a new game with the character Edited November 9, 2017 by Hse wrong image xD Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972406 Share on other sites More sharing options...
. . . Posted November 9, 2017 Share Posted November 9, 2017 change DoRaskInTime to DoTaskInTime Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972598 Share on other sites More sharing options...
Hse Posted November 9, 2017 Author Share Posted November 9, 2017 Oh yeah, true haha ! now i can enter in game, but when an ennemi hit my character : line 72 is: if math.random <= .5 then Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972602 Share on other sites More sharing options...
Lumina Posted November 10, 2017 Share Posted November 10, 2017 Maybe it should be if math.random() < .5 then Not hundred percent sure, but i found a lot of similar function in game code. Worth a try. Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-972798 Share on other sites More sharing options...
Hse Posted November 12, 2017 Author Share Posted November 12, 2017 not working ;w; but just to be sure, where i have to put those lines of code? in scripts > prefabs correct ? Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-973535 Share on other sites More sharing options...
Lumina Posted November 12, 2017 Share Posted November 12, 2017 In your character.lua file. can you copy your code ? Where did you put it ? Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-973537 Share on other sites More sharing options...
Hse Posted November 12, 2017 Author Share Posted November 12, 2017 oh so yeah, i'm at the good place, in the character.lua. well the code is at the end of the file local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } 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, "magicaca_speed_mod", 1) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "magicaca_speed_mod") end -- When loading or spawning the character local function onload(inst) 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( "magicaca.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 = "wilson" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(150) inst.components.hunger:SetMax(300) inst.components.sanity:SetMax(200) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst.OnLoad = onload inst.OnNewSpawn = onload -- Movement speed (optional) inst.components.locomotor.walkspeed = 8 inst.components.locomotor.runspeed = 11 inst:ListenForEvent("attacked", function(inst) inst:DoTaskInTime(0, function(inst) if math.random() < .4 then local wood = SpawnPrefab("log") wood.Transform:SetPostiton(inst.Transform:GetWorldPosition()) if wood.Physics ~= nil then local x, y, z = wood.Transform:GetWorldPosition() wood.Physics:Teleport(x, .3, z) local angle = (math.random() * 20 - 10) * DEGREES angle = angle + math.random() * 2 * PI local speed = projectile and 2 + math.random() or 3 + math.random() * 2 wood.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed) end end end) end) end return MakePlayerCharacter("magicaca", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-973703 Share on other sites More sharing options...
Lumina Posted November 12, 2017 Share Posted November 12, 2017 Is the error still the same ? (I just noticed the name of your mod, lol) Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-973711 Share on other sites More sharing options...
Hse Posted November 13, 2017 Author Share Posted November 13, 2017 hahahaha ^^ nope, another message when an ennemy hit my character Ty for your help btw ! Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-974050 Share on other sites More sharing options...
Lumina Posted November 13, 2017 Share Posted November 13, 2017 Try change Postiton by Position. Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-974053 Share on other sites More sharing options...
Hse Posted November 14, 2017 Author Share Posted November 14, 2017 (edited) Wiiiiiiiiiii it's working now waaah wouuuuh ! Ty guys ! Edited November 14, 2017 by Hse Link to comment https://forums.kleientertainment.com/forums/topic/83766-solved-can-custom-character-spawn-objects/#findComment-974160 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