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