I'm trying to use the Rules script from MTA wiki, but it shows the error:
Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil] at Line 49
function createRulesWindow()
-- get the screen width and height
local sWidth, sHeight = guiGetScreenSize()
-- create the window, using some maths to find the centre of the screen
local Width,Height = 445,445
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
-- create the window and save the window gui element in a variable called 'rulesWindow'
rulesWindow = guiCreateWindow(X,Y,Width,Height,"Rules",false)
-- stop players from being able to simply move the window out of the way
-- note that we use our 'rulesWindow' variable to make changes to the window
guiWindowSetMovable(rulesWindow,false)
-- stop players from being able to resize the window
guiWindowSetSizable(rulesWindow,false)
-- create the button and save the button gui element in a variable called 'rulesButton'
rulesButton = guiCreateButton(137,394,158,37,"Accept",false,rulesWindow)
-- create the label and save the label gui element in a variable called 'rulesLabel'
-- we set the text of the label to our rules
rulesLabel = guiCreateLabel(10,25,425,359,[[
Welcome to my MTA Server!
Please carefully read the rules before accepting.
By accepting the rules, you are agreeing to play by them.
Anyone caught breaking these rules will be kicked and/or banned from this server.
If you do not accept the rules within 90 seconds, you will be kicked.
1: No cheating.
2: No bug abuse.
3: No mods to your game.
4: No flaming.
5: Respect other players.
6: Be nice!]],false,rulesWindow)
guiLabelSetHorizontalAlign(rulesLabel,"center",true)
end
addEventHandler("onClientGUIClick", rulesButton, acceptRules, false)
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function ()
-- call the createRulesWindow function to create our gui
createRulesWindow()
-- show the cursor to the player
showCursor(true,true)
end
)
function inactivePlayer(status)
-- if status is 1 (this means it is the first warning)
if status == 1 then
-- output a warning
outputChatBox("Please accept our rules or be kicked.")
-- set another timer to call inactivePlayer in another 30 seconds, with "2" as an argument
rulesWarningTimer = setTimer(inactivePlayer,30000,1,2)
-- if status is 2 (the second warning)
elseif status == 2 then
-- output a final warning
outputChatBox("FINAL WARNING: Please accept our rules or be kicked.")
-- set a final timer to call inactivePlayer in another 30 seconds, with "3" as an argument
rulesWarningTimer = setTimer(inactivePlayer,30000,1,3)
elseif status == 3 then
-- trigger the server so we can kick the player
triggerServerEvent("clientKickInactivePlayer",getLocalPlayer())
end
end
function acceptRules(button,state)
-- if our accept button was clicked with the left mouse button, and the state of the mouse button is up
if button == "left" and state == "up" then
-- hide the window and all the components
guiSetVisible(rulesWindow, false)
-- hide the mouse cursor
showCursor(false,false)
-- output a message to the player
outputChatBox("Thank you for accepting our rules. Have fun!")
-- if the warning timer exists
if rulesWarningTimer then
-- stop the timer and set the variable to nil
-- this is the timer used to kick players who do not accept the rules. We will cover this in more detail in the next section.
killTimer(rulesWarningTimer)
rulesWarningTimer = nil
end
end
end