Left 4 Sharkb8 Posted December 17, 2021 Share Posted December 17, 2021 So I'd like to make it so that a specific character of mine has a chance of getting a random item instead of what they intended to craft whenever they make an item. Unfortunately, I have absolutely no idea where to start for this particular process. Link to comment https://forums.kleientertainment.com/forums/topic/136266-making-it-so-that-when-my-character-crafts-something-they-get-a-random-item-instead-of-what-they-made/ Share on other sites More sharing options...
_Yue_Yue_ Posted January 4, 2022 Share Posted January 4, 2022 (edited) local loots = {...} AddPrefabPostInit("xxxxx",function(inst) if not TheWorld.ismastersim then return inst end inst:DoTaskInTime(0,function(inst) local owner = inst.components.inventoryitem.owner if owner ~= nil then inst.components.inventoryitem:RemoveFromOwner(true) local container = owner.components.inventory or owner.components.container or nil if container ~= nil then local item = loots[math.random(#loots)].item local loot = SpawnPrefab(item) if loot == nil then return end container:GiveItem(loot) end else local item = loots[math.random(#loots)].item local loot = SpawnPrefab(item) if loot == nil then return end loot.Transform:SetPosition(inst.Transform:GetWorldPosition()) if loot.Physics ~= nil then local angle = math.random() * 2 * PI loot.Physics:SetVel(2 * math.cos(angle), 10, 2 * math.sin(angle)) end end inst:Remove() end) end) 小心嵌套 Edited January 4, 2022 by _Yue_Yue_ Link to comment https://forums.kleientertainment.com/forums/topic/136266-making-it-so-that-when-my-character-crafts-something-they-get-a-random-item-instead-of-what-they-made/#findComment-1530513 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