wouter2004 11 Report post Posted November 14, 2021 (edited) EXPLAINATION: I was playing around with some lua scripts and functions and wanted to share this script with you. It is a slot machine NPC, which allows you to play a game for fairy coins and money. Everytime you play, there are three wheels with four rows that show randomized slots. If you get three of the same slots in one row, you win a prize. Prizes can be easily customized and also the costs to play this game. Enjoy! SCREENSHOT: THE FUNCTION: \resource\script\calculate\functions.lua slotmachine = {} slotmachine.wheel = {} slotmachine.wheel[1] = {} slotmachine.wheel[1][1] = '$$$' slotmachine.wheel[1][2] = '^-^' slotmachine.wheel[1][3] = 'LOL' slotmachine.wheel[1][4] = '*-*' slotmachine.wheel[1][5] = '*-*' slotmachine.wheel[1][6] = '^-^' slotmachine.wheel[1][7] = '777' slotmachine.wheel[1][8] = '777' slotmachine.wheel[2] = {} slotmachine.wheel[2][1] = '$$$' slotmachine.wheel[2][2] = '^-^' slotmachine.wheel[2][3] = 'LOL' slotmachine.wheel[2][4] = '*-*' slotmachine.wheel[2][5] = '*-*' slotmachine.wheel[2][6] = '^-^' slotmachine.wheel[2][7] = '777' slotmachine.wheel[2][8] = '777' slotmachine.wheel[3] = {} slotmachine.wheel[3][1] = '$$$' slotmachine.wheel[3][2] = '^-^' slotmachine.wheel[3][3] = 'LOL' slotmachine.wheel[3][4] = '*-*' slotmachine.wheel[3][5] = '*-*' slotmachine.wheel[3][6] = '^-^' slotmachine.wheel[3][7] = '777' slotmachine.wheel[3][8] = '777' slotmachine.wheel[4] = {} slotmachine.wheel[4][1] = '$$$' slotmachine.wheel[4][2] = '^-^' slotmachine.wheel[4][3] = 'LOL' slotmachine.wheel[4][4] = '*-*' slotmachine.wheel[4][5] = '*-*' slotmachine.wheel[4][6] = '^-^' slotmachine.wheel[4][7] = '777' slotmachine.wheel[4][8] = '777' function SlotMachine(role) local randomNumber1 = math.random(1, 8) --Returns a number between 1 and 10. local randomNumber2 = math.random(1, 8) --Also returns a number between 1 and 10. local randomNumber3 = math.random(1, 8) --Returns a number between 1 and 10. local randomNumber4 = math.random(1, 8) --Also returns a number between 1 and 10. local slot = {} local prize = 0 local bonus = 'no bonus' for x=1,4 do slot[x] = {} slot[x][1] = slotmachine.wheel[x][math.random(1, 8)] slot[x][2] = slotmachine.wheel[x][math.random(1, 8)] slot[x][3] = slotmachine.wheel[x][math.random(1, 8)] end for row=1,4 do if ( slot[row][1] == slot[row][2] and slot[row][2] == slot[row][3]) then -- ROW STREAK if(slot[row][1] =='$$$') then prize = prize + 1000000 end if(slot[row][1] =='^-^') then prize = prize + 500000 end if(slot[row][1] =='777') then prize = prize + 777777 end if(slot[row][1] =='LOL') then prize = prize + 200000 bonus = 'Heaven Berry' end if(slot[row][1] =='*-*') then prize = prize + 100000 end end end if(prize ~= 0) then AddMoney ( role , 0 , prize ) end if(bonus == 'Heaven Berry') then GiveItem( role , 0 , 3844 , 1 , 1 ) end HelpInfoX(role, 0, "** SLOTMACHINE **__".."row 1: ["..slot[1][1].."] - ".."["..slot[1][2].."] - ".."["..slot[1][3].."]_".."row 2: ["..slot[2][1].."] - ".."["..slot[2][2].."] - ".."["..slot[2][3].."]_".."row 3: ["..slot[3][1].."] - ".."["..slot[3][2].."] - ".."["..slot[3][3].."]_".."row 4: ["..slot[4][1].."] - ".."["..slot[4][2].."] - ".."["..slot[4][3].."]__".."PRIZE: "..tostring(prize).." gold, ".."BONUS: "..bonus) return LUA_TRUE end THE NPC: \resource\script\MisScript\NpcScript06.lua Jackpot = {} Jackpot.Coins = {} Jackpot.Coins.amount = 30 -- 3 stacks of fairy coins 297 Jackpot.Coins.item = 0855 -- 3 stacks of fairy coins Jackpot.Coins.money = 10000 -- Money needed for second class advancement. function JackpotNPC() InitTrigger() TriggerCondition(1, HasItem, Jackpot.Coins.item, Jackpot.Coins.amount) TriggerCondition( 1, HasMoney, Jackpot.Coins.money ) TriggerCondition( 1, HasLeaveBagGrid, 1 ) TriggerCondition( 1, KitbagLock, 0 ) TriggerAction( 1, TakeMoney, Jackpot.Coins.money ) TriggerAction( 1, TakeItem, Jackpot.Coins.item, Jackpot.Coins.amount ) TriggerAction( 1, SlotMachine ) TriggerFailure( 1, JumpPage, 2 ) Talk( 1, "Jackpot Machine: For "..Jackpot.Coins.money.." gold and "..Jackpot.Coins.amount.." of fairy coins, you can try your luck and win a prize." ) Text( 1, "Try your luck, play a round!", MultiTrigger, GetMultiTrigger(), 1) Text( 1, "Explain the game.", JumpPage, 3) Text( 1, "Prizes", JumpPage, 4) Talk( 3, "Everytime you play a round there are three_wheels with four rows._The wheels will spin and you will see_the result in the next window._If you have three of the same slots in one_row, you win a prize.") Text( 3, "Back", JumpPage, 1) Talk( 4, "PRIZES:_3 x $$$ = 1 milion gold_3 x ^-^ = 500000 gold_3 x 777 = 777777 gold_3 x LOL = 200000 + a heavens berry_3 x *-* = 100000 gold.") Text( 4, "Back", JumpPage, 1) Talk( 2, "Failed to play a round. Insufficient gold or fairy coins" ) end NEW NPC ACTION PROCEDURE: \resource\script\MisSdk\MissionSdk.lua elseif actions[i].func == SlotMachine then PRINT( "ActionProc: SlotMachine") local ret = SlotMachine( character ) if ret ~= LUA_TRUE then PRINT( "ActionProc:SlotMachine = false" ) return LUA_FALSE end Edited November 14, 2021 by wouter2004 2 Quote Share this post Link to post Share on other sites