Jump to content

[HELP] What fails in this script?


LGato

Recommended Posts

I want know what fail in my script because i'm new in LUA Scripting and if a "professional" resolve my problem maybe i can learn of that 

In this script i want make math problems and if the players resolve this gain $2k

setTimer(function()
x1 = math.random(500)
x2 = math.random(600)
outputChatBox("#1860F1[Math]#ffffff " .. x1 .. " + " .. x2 .. " = ", root, 255, 255, 255, true)
end, 30000, 0)
 
function mathSystem(text, source)
outputChatBox(text, source, 255, 255, 255, true)
if text == x1 + x2 then
givePlayerMoney(source, 2000)
end
end
addEventHandler("onPlayerChat", root, mathSystem)
Link to comment
  • LGato changed the title to [HELP] What fails in this script?
  1. setTimer(function()
  2. x1 = math.random(1,1000)
  3. x2 = math.random(1,1000)
  4. outputChatBox("#1860F1[Math]#ffffff " .. x1 .. " + " .. x2 .. " = ", root, 255, 255, 255, true)
  5. end, 30000, 0)
  6. function mathSystem(text, source)
  7. outputChatBox(text, source, 255, 255, 255, true)
  8. if text == x1 + x2 then
  9. givePlayerMoney(source, 2000)
  10. end
  11. end
  12. addEventHandler("onPlayerChat", root, mathSystem)
    Quote

    That's the error math.random need to be for example (1,500) from 1 to 500

 

Link to comment

try this 

local result = nil 

setTimer(function()
local x1,x2 = math.random(1,1000) , math.random(1,1000)
result = x1 + x2
outputChatBox("#1860F1[Math]#ffffff " .. x1 .. " + " .. x2 .. " = ", root, 255, 255, 255, true)
end, 30000, 0)

addEventHandler ( "onPlayerChat" , root , function ( message , typ ) 
if ( typ == 0 and result ~= nil and message == tostring ( result ) ) then 
givePlayerMoney ( source , 2000 ) 
result = nil 
end
end ) 

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...