Milllk Posted September 20, 2015 Share Posted September 20, 2015 i wanna spawn a butterfly but it always fly away Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 oh i have solved..there's a butterfly_placer prefab can be used for this. Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 no,it's not this prefab,still butterfly,i use this c_give("butterfly",1) it worked i dont know if it gonna work when muiltyplayer. Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 is there any better solution?i guess c_give is only host can use . Link to comment Share on other sites More sharing options...
Toros Posted September 20, 2015 Share Posted September 20, 2015 Well, in game, capturing a butterfly with the bug net, planting it as a flower, gives unlimited butterflies that can be caught with a bug net.. Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 Well, in game, capturing a butterfly with the bug net, planting it as a flower, gives unlimited butterflies that can be caught with a bug net..i wanna create a trader actually , the player give it butterflywings,then it return a butterfly that can be placed,but it still not work right. Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 i wanna use the inventory:GiveItem("butterfly") but it gives me an error.how can i solve thislike this Link to comment Share on other sites More sharing options...
DrSmugleaf Posted September 20, 2015 Share Posted September 20, 2015 Look into components\trader.lua and prefabs\pigking.lua, also the Inventory:GiveItem function in inventory.lua which is used in the Trader:AcceptGift function of trader.lua, or paste your code here. Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 Look into components\trader.lua and prefabs\pigking.lua, also the Inventory:GiveItem function in inventory.lua which is used in the Trader:AcceptGift function of trader.lua, or paste your code here.local assets ={Asset("ANIM","anim/kazuhaamulet.zip"),Asset("ANIM","anim/torso_kazuhaamulet.zip"),Asset( "IMAGE", "images/inventoryimages/kazuhaamulet.tex" ),Asset( "ATLAS", "images/inventoryimages/kazuhaamulet.xml" ),}local prefabs = {"crystal_tiny", --2%"crystal_tiny_n", --2%"redgem", --5%"bluegem", --5%"goldnugget", --80%"nightmarefuel", --5%"butteryfly",}local function fn()local function onequip(inst,owner)owner.AnimState:OverrideSymbol("swap_body","torso_kazuhaamulet","blueamulet")--if isKazuha Remove debuffif ThePlayer.prefab == "kazuha" thenowner.components.combat.damagemultiplier = 1owner.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATEowner.components.sanity.dapperness = TUNING.DAPPERNESS_SMALLendif inst.components.fueled theninst.components.fueled:StartConsuming()endendlocal function onunequip(inst,owner)owner.AnimState:ClearOverrideSymbol("swap_body")--on unequip if is Kazuha Add debuffif ThePlayer.prefab == "kazuha" thenowner.components.combat.damagemultiplier = .45owner.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE * 1.25owner.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE * (- 1.25)endif inst.components.fueled theninst.components.fueled:StopConsuming()endendlocal function ontradeforgold(inst,item)local goldchance = .5for k = 1, item.components.tradable.goldvalue doif math.random() < goldchance thenlocal nug = SpawnPrefab("goldnugget")local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 1, 0)nug.Transform:SetPosition(pt:Get())local down = TheCamera:GetDownVec()local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREESlocal sp = math.random() * 4 + 2nug.Physics:SetVel(sp / 4 * math.cos(angle), math.random() * 2 + 8, sp / 4 * math.sin(angle))endendendlocal function ontradeforlargergoldval(inst,item)local nug = SpawnPrefab("crystal_tiny")local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 1, 0)nug.Transform:SetPosition(pt:Get())local down = TheCamera:GetDownVec()local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREESlocal sp = math.random() * 4 + 2nug.Physics:SetVel(sp / 4 * math.cos(angle), math.random() * 2 + 8, sp / 4 * math.sin(angle))endlocal function ontradeforbutterfly(inst,item)local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nilif owner thenowner.components.inventory:GiveItem("butteryfly")endendlocal function ShouldAcceptOrNot(inst, item, giver)local can_accept = item.components.tradable--edible and item.components.edible.foodtype == FOODTYPE.MEATreturn can_accept--return trueendlocal function OnGetItemFromPlayer(inst, giver, item)-- if item.components.edible ~= nil and item.components.edible.foodtype == FOODTYPE.MEAT then-- print("its ok")-- end--giver.components.inventory:GiveItem("butteryfly",2)if item.components.tradable.goldvalue > 0 and item.components.tradable.goldvalue <= 1 theninst:DoTaskInTime(20/30, ontradeforgold, item)elseif item.components.tradable.goldvalue > 1 theninst:DoTaskInTime(20/30, ontradeforlargergoldval, item)elseif item.prefab == "butterflywings" thengiver.components.inventory:ConsumeByName("butterflywings", 1)inst:DoTaskInTime(20/30, ontradeforbutterfly, item)endendlocal inst = CreateEntity()inst.entity:AddTransform()inst.entity:AddAnimState()inst.entity:AddNetwork()MakeInventoryPhysics(inst)inst.AnimState:SetBank("kazuhaamulet")inst.AnimState:SetBuild("kazuhaamulet")inst.AnimState:PlayAnimation("idle")inst:AddTag("kazuhaamulet")inst.foleysound = "dontstarve/movement/foley/jewlery"inst.entity:SetPristine()if not TheWorld.ismastersim thenreturn instendinst:AddComponent("inspectable")inst:AddComponent("equippable")inst.components.equippable.equipslot = EQUIPSLOTS.NECK or EQUIPSLOTS.BODYinst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALLinst.components.equippable:SetOnEquip(onequip)inst.components.equippable:SetOnUnequip(onunequip)inst:AddComponent("inventoryitem")inst.components.inventoryitem.atlasname = "images/inventoryimages/kazuhaamulet.xml"inst.components.inventoryitem.keepondeath = trueinst:AddComponent("fueled")inst.components.fueled.fueltype = FUELTYPE.NIGHTMAREinst.components.fueled:InitializeFuelLevel(TUNING.TOTAL_DAY_TIME*6)inst.components.fueled:SetDepletedFn(inst.Remove)inst.components.fueled.accepting = trueinst:AddComponent("trader")inst.components.trader.onaccept = OnGetItemFromPlayerinst.components.trader:SetAcceptTest(ShouldAcceptOrNot)MakeHauntableLaunch(inst)return instendreturn Prefab("common/inventory/kazuhaamulet", fn, assets, prefabs) Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 Look into components\trader.lua and prefabs\pigking.lua, also the Inventory:GiveItem function in inventory.lua which is used in the Trader:AcceptGift function of trader.lua, or paste your code here.it work for the items that can use Spawnprefab function ,but not work for the inventory items,i havent found any solution till then. Link to comment Share on other sites More sharing options...
DrSmugleaf Posted September 20, 2015 Share Posted September 20, 2015 I'm...what are you trying to do? An amulet? A trader? Both? And you don't need everything inside the fn() function, here you go: kazuhaamulet.lua Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 I'm...what are you trying to do? An amulet? A trader? Both? And you don't need everything inside the fn() function, here you go:yes..but how can i get the butterfly to the inventory Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 I'm...what are you trying to do? An amulet? A trader? Both? And you don't need everything inside the fn() function, here you go:i 've tried a lot of times ,always can't reference to the components Link to comment Share on other sites More sharing options...
DrSmugleaf Posted September 20, 2015 Share Posted September 20, 2015 inst.components.inventory:GiveItem(SpawnPrefab("butterfly")) Link to comment Share on other sites More sharing options...
Milllk Posted September 20, 2015 Author Share Posted September 20, 2015 inst.components.inventory:GiveItem(SpawnPrefab("butterfly"))wow,awesome!!!!!!!!!!! thank uuuuuuuuu Link to comment Share on other sites More sharing options...
Hyaciao Posted September 24, 2015 Share Posted September 24, 2015 (edited) Following up on this as I'm trying to do something similar. Is there a way I can use a variation of this format on the character itself?Basically I'm looking to do something like press "B" to spawn a berry in my character inventory. Using "player" or self in place of "inst" seems to yield a "nil" error. AddModRPCHandler(modname, "POCKETFOOD", function(player) if not player:HasTag("playerghost") and player.prefab == "fluff" then if not player.pocketfoodincooldown then player.components.talker:Say("Oh I found something.") player.components.health:DoDelta(-1) player.components.sanity:DoDelta(-5)-- inst.components.inventory:GiveItem(SpawnPrefab("smallmeat")) end player:DoTaskInTime(60, function() player.components.talker:Say("I'm all rest up") player.pocketfoodincooldown = false end) else player.components.talker:Say("I need some time.") end endend) Edited September 24, 2015 by Hyaciao Link to comment Share on other sites More sharing options...
Milllk Posted September 25, 2015 Author Share Posted September 25, 2015 (edited) Following up on this as I'm trying to do something similar. Is there a way I can use a variation of this format on the character itself?Basically I'm looking to do something like press "B" to spawn a berry in my character inventory. Using "player" or self in place of "inst" seems to yield a "nil" error. AddModRPCHandler(modname, "POCKETFOOD", function(player) if not player:HasTag("playerghost") and player.prefab == "fluff" then if not player.pocketfoodincooldown then player.components.talker:Say("Oh I found something.") player.components.health:DoDelta(-1) player.components.sanity:DoDelta(-5)-- inst.components.inventory:GiveItem(SpawnPrefab("smallmeat")) end player:DoTaskInTime(60, function() player.components.talker:Say("I'm all rest up") player.pocketfoodincooldown = false end) else player.components.talker:Say("I need some time.") end endend) check this maybe can help http://forums.kleientertainment.com/topic/52191-tournament-game-modes-and-mod-rpcs/ Edited September 25, 2015 by Milllk 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