Evil-Cod3r Posted March 3, 2012 Share Posted March 3, 2012 Hi all how to Make script that give money if player write in the chat the correct word ? like [Random] the faster one type "mta" get Money if some type it (getPlayerName(source) .. is the faster typer and got ... i want some one make halft of it so i can learn how to Make it by my self thx all Link to comment
bandi94 Posted March 3, 2012 Share Posted March 3, 2012 local money=100 first=false function money(player) if first then givePlayerMoney(player,money) first=false outputChatBox(getPlayerName(player).."was the first and got 100 $") else outputChatBox("You are not the first") end end addCommandHandler(freemoney,money)-- if the player write /freemoney and he is the firs after loading the money then he will get 100 $ function reloadmoney() first=true outputChatBox("Write '/freemoney' and you can won 100$ if you type it fast") end addCommandHandler(startmoney,money) -- if you type startmoney the you will start a new chance to type you can make it whit a timer ex. in every 5 min to load money or how you want Link to comment
drk Posted March 3, 2012 Share Posted March 3, 2012 local money=100 first=false function money(player) if first then givePlayerMoney(player,money) first=false outputChatBox(getPlayerName(player).."was the first and got 100 $") else outputChatBox("You are not the first") end end addCommandHandler(freemoney,money)-- if the player write /freemoney and he is the firs after loading the money then he will get 100 $ function reloadmoney() first=true outputChatBox("Write '/freemoney' and you can won 100$ if you type it fast") end addCommandHandler(startmoney,money) -- if you type startmoney the you will start a new chance to type Your code is wrong. local first = false addEventHandler('onPlayerChat',root, function(message,messageType) if messageType == "0" and message == "money" then if first then givePlayerMoney(source,100) outputChatBox(getPlayerName(source).." was the first and got 100$!",root,255,255,255,false) else outputChatBox("Next time try to be more faster!",source,255,255,255,false) end end end ) Only a example. Link to comment
myonlake Posted March 3, 2012 Share Posted March 3, 2012 Won't work. It will always reset it and all will be winners. Make a function to start the competition and then the first one saying the word wins. When you type /startspeedtest it will wait for a minute and those who joined will be added in the game, more than one player. And if you wrote faster than a second, you will fail because of bind/F8. Or depends how long word. Link to comment
Evil-Cod3r Posted March 3, 2012 Author Share Posted March 3, 2012 i want as Draken write not a command a a word type in chat then win like this ?? local Name = getPlayerName(source) local g_Root = getRootElement() local win = math.random (1,100) local first = false addEventHandler('onPlayerChat',root, function(message, messageType) if messageType == "0" and message == "money" then if (first) then givePlayerMoney(source,win) outputChatBox(Name .." was The First Player and got".. win.. "$ !",g_Root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) Link to comment
Castillo Posted March 3, 2012 Share Posted March 3, 2012 local alreadyWon = false local msg = "money" addEventHandler('onPlayerChat',root, function(message, messageType) if (messageType == 0 and message == msg) then if ( not alreadyWon ) then local win = math.random (1, 100) alreadyWon = true givePlayerMoney(source, win) outputChatBox(getPlayerName(source) .." was The First Player and got $".. win.. "!",root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) Link to comment
Evil-Cod3r Posted March 3, 2012 Author Share Posted March 3, 2012 Castillo i have 2 questions 1- Can i make a table for The Words ? 2- is it will give all players Money or just the one who type it ? Link to comment
Castillo Posted March 3, 2012 Share Posted March 3, 2012 You can make a table with letters and numbers and then randomize it with math.random, there's another way if I'm right, but this should be easier for you. And no, it'll only give to the player who won. Link to comment
Evil-Cod3r Posted March 3, 2012 Author Share Posted March 3, 2012 i have made this as a start for learn lua and how to make simple roll local alreadyWon = false local word = { 'SoldSnake14' 'Evil-Cod3r' } addEventHandler('onPlayerChat',root, function(message, messageType) if (messageType == 0 and message == word) then if ( not alreadyWon ) then local win = math.random (1, 100) local Random = word[ math.random( word ) ] alreadyWon = true givePlayerMoney(source, win) outputChatBox(getPlayerName(source) .." was The First Player and got $".. win.. "!",root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) Link to comment
drk Posted March 3, 2012 Share Posted March 3, 2012 i have made this as a start for learn lua and how to make simple roll local alreadyWon = false local word = { 'SoldSnake14' 'Evil-Cod3r' } addEventHandler('onPlayerChat',root, function(message, messageType) if (messageType == 0 and message == word) then if ( not alreadyWon ) then local win = math.random (1, 100) local Random = word[ math.random( word ) ] alreadyWon = true givePlayerMoney(source, win) outputChatBox(getPlayerName(source) .." was The First Player and got $".. win.. "!",root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) I think it will work... local alreadyWon = false local words = { '39s939k239' 'ds9sd8409' } setTimer( function() word = words[math.random(#words)] money = math.random(50,500) outputChatBox("Say "..word.." to win $"..money.."!",root,255,255,false) end, 100000,0) addEventHandler('onPlayerChat',root, function(message, messageType) if (messageType == 0 and message == word) then if ( not alreadyWon ) then alreadyWon = true givePlayerMoney(source, money) outputChatBox(getPlayerName(source) .." was The First Player and got $"..money.. "!",root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) Link to comment
Castillo Posted March 3, 2012 Share Posted March 3, 2012 local alreadyWon = false local wordsTable = { 'SoldSnake14' 'Evil-Cod3r' } local word = "" function setRandomWord() word = wordsTable[math.random(#wordsTable)] outputChatBox("Write: ".. word .." to get some money!",root,255,255,0) alreadyWon = false setTimer(setRandomWord,60000,1) end setTimer(setRandomWord,60000,1) addEventHandler('onPlayerChat',root, function(message, messageType) if (messageType == 0 and message == word) then if ( not alreadyWon ) then local win = math.random (1, 100) alreadyWon = true word = "" givePlayerMoney(source, win) outputChatBox(getPlayerName(source) .." was The First Player and got $".. win.. "!",root,255,255,0,false) else outputChatBox("Next Time Try To Be More Faster !",source,255,0,255,false) end end end ) Every 60 seconds a random word will be set. Link to comment
Evil-Cod3r Posted March 3, 2012 Author Share Posted March 3, 2012 Thanx Castillo for this now i well study it to be good scripter just like you thanx Darken for help to Link to comment
drk Posted March 3, 2012 Share Posted March 3, 2012 Thanx Castillo for this now i well study it to be good scripter just like you thanx Darken for help to No problem. Link to comment
myonlake Posted March 3, 2012 Share Posted March 3, 2012 (edited) lock = false join = false players = 0 addCommandHandler("startgame", function(player, cmd) if lock then outputChatBox("Fastest typer game started - join with /joingame.", root, 255, 255, 0, false) setTimer(closeJoining, 60000, 1) lock = true else outputChatBox("Game is already running!", player, 255, 0, 0, false) end end ) addCommandHandler("joingame", function(player, cmd) if join then if not getElementData(player, "moneygame") then players = tonumber(players) + 1 setElementData(player, "moneygame", 1) outputChatBox(getPlayerName(player) .. " has joined the money game!", root, 0, 255, 0, false) else outputChatBox("You're already participating the game!", player, 255, 0, 0, false) end else outputChatBox("Game is not started or is running already!", player, 255, 0, 0, false) end end ) function closeJoining() if players > 1 then join = false outputChatBox("Money game is now locked - game starts in 20 seconds!", root, 255, 0, 0, false) setTimer(outputChatBox, 20000, 1, "Money game started! Say 'money' first to win!", root, 255, 255, 255, false) else players = 0 outputChatBox("Money game was not started due not enough players.", root, 255, 0, 0, false) end end addEventHandler("onPlayerChat", root, function(message, messageType) if messageType == "0" and string.find(message, "money") then if getElementData(source, "moneygame") then cancelEvent() outputChatBox(getPlayerName(source) .. " was first and won $100!", root, 255, 255, 0, false) givePlayerMoney(source, 100) for i,v in ipairs(getElementsByType("player")) do if getElementData(v, "moneygame") then outputChatBox("Sorry you lost the game!", v, 255, 0, 0, false) removeElementData(v, "moneygame") end end players = 0 end end end ) EDIT: Looks like you did it already.. well here's mine. Edited March 4, 2012 by Guest Link to comment
Cadu12 Posted March 4, 2012 Share Posted March 4, 2012 http://lua-users.org/wiki/RandomStrings Link to comment
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