代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二八八.刮刮乐(给路牌黄金买刮刮乐彩票中大奖)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/homesign.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function ShouldAcceptItem(inst, item)
7 if item.prefab == "goldnugget" then
8 return true
9 end
10 return false
11end
12local function OnGetItemFromPlayer(inst, giver, item)
13 if item.prefab == "goldnugget" then
14 local papyrus = SpawnPrefab("papyrus")
15 papyrus:AddComponent("lootdropper")
16 papyrus.components.inspectable.getstatus = function(papyrus)
17 if math.random()<.01 then
18 for k = 1, 50 do
19 papyrus.components.lootdropper:SpawnLootPrefab("goldnugget")
20 end
21 elseif math.random()<.05 then
22 for k = 1, 10 do
23 papyrus.components.lootdropper:SpawnLootPrefab("goldnugget")
24 end
25 elseif math.random()<.15 then
26 for k = 1, 2 do
27 papyrus.components.lootdropper:SpawnLootPrefab("goldnugget")
28 end
29 elseif math.random()<.3 then
30 papyrus.components.lootdropper:SpawnLootPrefab("goldnugget")
31 else
32 papyrus.components.lootdropper:SpawnLootPrefab("ash")
33 end
34 SpawnPrefab("collapse_small").Transform:SetPosition(papyrus.Transform:GetWorldPosition())
35 papyrus.components.stackable:Get():Remove()
36 end
37 giver.components.inventory:GiveItem(papyrus)
38 end
39end
40 inst:AddComponent("trader")
41 inst.components.trader.onaccept = OnGetItemFromPlayer
42 inst.components.trader:SetAcceptTest(ShouldAcceptItem)
43
44 即可给路牌黄金买刮刮乐彩票(拿黄金对路牌按鼠标左键),彩票(1张纸)直接装入主角物品栏,对物品栏中的纸按鼠标右键即可刮奖,一等奖50个黄金,二等奖10个黄金,三等奖2个黄金,四等奖1个黄金,末等奖只有一团灰。存档退出时,身上不要留彩票,因为再读档后会过期作废(不能再刮奖)