Jump to content

Basic Gamemode script - Issues


Misha

Recommended Posts

Basically, i tried to make my own gamemode, a base for future testing. I made it based on the tutorials and modded the things i felt comfortable to mod. I got it written and got my first notes of wisdom, but when i started teh script and logged on, i was only met by a black screen.

THe script includes 2 files atm - script.lua and gui.lua(under /client). Meta is correct.

script.lua

function joinHandler()
local x = 1959.55
local y = -1714.46
local z = 15
outputChatBox("Welcome to My Server", source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)
 
 
function loginHandler(username,password)
if username == "Misha" and password == "noob" then
 
if (client) then
spawnPlayer(client, 1959.55, -1714.46, 10)
fadeCamera(client, true)
outputChatBox("Welcome", client)
end
 
 
elseif username == "Faberge" and password == "Faberge" then
 
if(client) then
		spawnplayer(client,1959.55, -1710.46, 10)
		fadecamera(client, true)
outputChatBox("Welcome.", client)
end
else
outputChatBox("Failed. Relog.",client)
end
end
addEvent("submitLogin",true)
addEventHandler("submitLogin",root,loginHandler)
 
 
function createVehicleForPlayer(thePlayer, command, vehiclemodel, vehiclecolor)
local x,y,z = getElementPosition(thePlayer)
	x= x + 2
local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
if (createdVehicle ==false) then
outputChatBox("You Fail, try again.",thePlayer)
end
end
addCommandHandler("makeveh", createVehicleForPlayer)
 
 
function playerDied(totalAmmo, killer, killerWeapon, bodypart)
outputChatBox(getPlayerName(source) .. " Fail!")
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)
 
function moveThePlayer(x,y,z,rotation)
 
if x and y and z and rotation then
 
local skin = getElementModel(client)
 
	spawnplayer(client,x,y,z,rotation,skin)
 
setCameraTarget(client,client)
 
end
end
addEvent("movePlayerToPosition",true)
addEventHandler("movePlayerToPosition",root,moveThePlayer)

Gui.lua

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function createLoginWindow()
local X = 0.375
local Y = 0.375
local Width = 0.25
local Height = 0.25
wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
 
X = 0.0825
Y = 0.2
Width = 0.25
height = 0.25
 
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
 
Y = 0.5
guiCreateLabel(X, Y, Width, height, "Password", true, wdwLogin)
 
X = 0.415
Y = 0.2
Width = 0.5
Height = 0.15
edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
Y = 0.5
edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
guiEditSetMaxLength(edtuser, 50)
guieditSetMaxLength(edtPass, 50)
 
X = 0.415
Y = 0.7
X = 0.415
Y = 0.7
Width = 0.25
Height = 0.2
btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
 
addEventHandler("onClientGUIClick", btnlogin, clientSubmitLogin, false)
 
guiSetVisible(wdwLogin, false)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
 
function ()
outputChatBox("Welcome, i'm a noob.")
 
if(wdwLogin ~= nil) then
guiSetVisible(wdwLogin, true)
else
outputChatBox("I failed, yet again.")
end
 
showCursor(true)
guiSetInputEnabled(true)
end
 
)
addEventHandler("onClientGUIClick", btnlogin, clientSubmitLogin, false)
 
function clientSubmitLogin(button,state)
if button == "left" and state == "up" then
local username = guiGetText(edtUser)
local password = guiGetText(edtPass)
 
if username and password then
triggerServerEvent("submitLogin", getRootElement(), username, password)
guiSetInputEnabled(false)
guiSetVisible(wdwLogin, false)
showCursor(false)
else
 
outputChatBox("You need a fucking username and password! LOL!")
end
end
end
 
function createRulesWindow()
local sWidth, sHeight = 445,445
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
rulesWindow = guiCreateWindow(X,Y,Width,Height,"Test",false)
 
guiWindowSetMovable(rulesWindow,true)
 
guiWindowSetSizable(rulesWindow,false)
 
rulesButton = guiCreateButton(137,394,156,37,"Sure",false,rulesWindow)
 
rulesLabel = guiCreateLabel(10,25,425,359,[[
Hello!
 
This is my first server ever, that i've tried to make. In fact, this is the first real script i've ever made, even though with the help of the 	tutorial.
My goal is to create a script that could become useful in vG MTA-RP. What script it is, i am not sure. I hope to create a mileage meter.
This is me talking to myself.]], false,rulesWindow)
 
guiLabelsetHorizontalAlign(ruleslabel,"center",true)
addEventHandler("onClientGUIClick", rulesButton, acceptRules, false)
rulesWarningTimer = setTimer(inactivePlayer,120000,1,1)
 
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
 
function ()
 
	createRulesWindow()
 
showCursor(true,true)
end
)	
 
function acceptRules(button,state)
if button == "left" and state == "up" then
guiSetVisible(rulesWindow, false)
 
showCursor(false,false)	
 
	outputChatbox("You passed me.")
 
 
if rulesWarningTimer then
killTimer(rulesWarningTimer)
		rulesWarningTimer = nil
end
end
end	
 
function inactivePlayer(status)
if status == 1 then
	outputChatbox("Please, cope with this timer i made")
	rulesWarningTimer = setTimer (inactivePlayer,10000,1,2)
 
elseif status == 2 then
outputChatBox("You have 5 seconds, lol")
	rulesWarningTimer = setTimer(inactivePlayer,5000,1,3)
elseif status == 3 then
outputChatBox("I was about to kick myself. Not going to happen today, mate.")
end
end
 
function createTelePortWindow()
local sWidth, sHeight = guiGetScreenSize()
 
local Width,Height = 231,188
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
teleportWindow = guiCreateWindow(X,Y,Width,Height,"Magic",false)
 
guiWindowSetSizable(teleportWindow,true)
guiWindowSetMovable(teleportWindow,true)
showCursor(true,true)
 
teleportLabel = guiCreateLabel(18,23,191,33,"Serious magic, bro",false,teleportWindow)
 
guiLabelSetHorizontalAlign(teleportLabel,"center",true)	
 
teleportButtonLS = guiCreateButton(18,63,195,35,"Los Santos",false,teleportWindow)
 
teleportButtonSF = guiCreateButton(18,103,195,35,"San Fierro",false,teleportWindow)
 
teleportButtonLV = guiCreateButton(18,143,195,35,"Las Venturas",false,teleportWindow)
 
guiSetVisible(teleportWindow,false)
 
addEventHandler("onClientGUIClivk", teleportButtonLS, teleportPlayer, false)
 
addEventHandler("onClientGUIClick", teleportButtonSF, teleportPlayer, false)
 
addEventHandler("onClientGUIClick", teleportButtonLV, teleportPlayer, false)
end
addEventHandler("onClientResourceStart", getResourceRootElement(getHisResource()),
function ()
	createTeleportWindow
end
)
function open TeleportWindow
guiSetVisible(teleportWindow,true)
 
showCursor(true,true)
end
addCommandHandler("teleportme",openTeleportWindow)
 
function teleportPlayer(button,state)
if button == "left" and state == "up" then
if source ==teleportButtonLS then
triggerServerEvent ("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0)
 
outputChatBox ("You managed to not fail!")
 
elseif source == teleportButtonSF then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),-2265.5,534.0,35.0,270)
 
outputChatBox("Coool")
 
elseif source == teleportButtonLV then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),2036.9,1545.2,10.8,270)
 
outputChatBox("Coolest")
end
 
guiSetVisible(teleportWindow,false)
 
showCursor(false)
end
end

If you are bored enough to help me, i will be glad. I like to try things. I would not post this if i wouldn't have been frustrated with it for a week, which is probably dumb.

Thank you for reading this to the end, if you did.

Link to comment
At this moment, when i started the gamemode in server, i had no errors. Though when i go in-game, iam confronted with a black screen with the only message being "Welcome to My Server."

Did you check for errors using /debugscript 3 or just in the server console? since not everything gets reported to the console.

Link to comment

I am sorry for being late.

Debug (SS)

http://img291.imageshack.us/img291/1272/debug.png (2 monitors, second shows the gui script itself.

(script currently)

addEventHandler("onClientResourceStart", getResourceRootElement,
function ()
local X = 0.375
local Y = 0.375
local Width = 0.25
local Height = 0.25
	wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
	X = 0.0825
	Y = 0.2
	Width = 0.25
	height = 0.25
 
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
 
	Y = 0.5
guiCreateLabel(X, Y, Width, height, "Password", true, wdwLogin)
 
	X = 0.415
	Y = 0.2
	Width = 0.5
	Height = 0.15
	edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
	Y = 0.5
	edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
guiEditSetMaxLength(edtuser, 50)
	guieditSetMaxLength(edtPass, 50)
 
	X = 0.415
	Y = 0.7
	X = 0.415
	Y = 0.7
	Width = 0.25
	Height = 0.2
	btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
 
addEventHandler("onClientGUIClick", btnlogin, clientSubmitLogin, false)
 
guiSetVisible(wdwLogin, false)
end
)
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
 
function ()
outputChatBox("Welcome, i'm a noob.")
 
if(wdwLogin ~= nil) then
guiSetVisible(wdwLogin, true)
else
outputChatBox("I failed, yet again.")
end
 
showCursor(true)
guiSetInputEnabled(true)
end
 
)
addEventHandler("onClientGUIClick", btnlogin, clientSubmitLogin, false)
 
function clientSubmitLogin(button,state)
if button == "left" and state == "up" then
local username = guiGetText(edtUser)
local password = guiGetText(edtPass)
 
if username and password then
triggerServerEvent("submitLogin", getRootElement(), username, password)
guiSetInputEnabled(false)
guiSetVisible(wdwLogin, false)
showCursor(false)
else
 
outputChatBox("You need a fucking username and password! LOL!")
end
end
end
 
function createRulesWindow()
local sWidth, sHeight = 445,445
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
rulesWindow = guiCreateWindow(X,Y,Width,Height,"Test",false)
 
guiWindowSetMovable(rulesWindow,true)
 
guiWindowSetSizable(rulesWindow,false)
 
rulesButton = guiCreateButton(137,394,156,37,"Sure",false,rulesWindow)
 
rulesLabel = guiCreateLabel(10,25,425,359,[[
Hello!
 
This is my first server ever, that i've tried to make. In fact, this is the first real script i've ever made, even though with the help of the 	tutorial.
My goal is to create a script that could become useful in vG MTA-RP. What script it is, i am not sure. I hope to create a mileage meter.
This is me talking to myself.]], false,rulesWindow)
 
guiLabelsetHorizontalAlign(ruleslabel,"center",true)
addEventHandler("onClientGUIClick", rulesButton, acceptRules, false)
rulesWarningTimer = setTimer(inactivePlayer,120000,1,1)
 
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
 
function ()
 
	createRulesWindow()
 
showCursor(true,true)
end
)	
 
function acceptRules(button,state)
if button == "left" and state == "up" then
guiSetVisible(rulesWindow, false)
 
showCursor(false,false)	
 
	outputChatbox("You passed me.")
 
 
if rulesWarningTimer then
killTimer(rulesWarningTimer)
		rulesWarningTimer = nil
end
end
end	
 
function inactivePlayer(status)
if status == 1 then
	outputChatbox("Please, cope with this timer i made")
	rulesWarningTimer = setTimer (inactivePlayer,10000,1,2)
 
elseif status == 2 then
outputChatBox("You have 5 seconds, lol")
	rulesWarningTimer = setTimer(inactivePlayer,5000,1,3)
elseif status == 3 then
outputChatBox("I was about to kick myself. Not going to happen today, mate.")
end
end
 
function createTelePortWindow()
local sWidth, sHeight = guiGetScreenSize()
 
local Width,Height = 231,188
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
teleportWindow = guiCreateWindow(X,Y,Width,Height,"Magic",false)
 
guiWindowSetSizable(teleportWindow,true)
guiWindowSetMovable(teleportWindow,true)
showCursor(true,true)
 
teleportLabel = guiCreateLabel(18,23,191,33,"Serious magic, bro",false,teleportWindow)
 
guiLabelSetHorizontalAlign(teleportLabel,"center",true)	
 
teleportButtonLS = guiCreateButton(18,63,195,35,"Los Santos",false,teleportWindow)
 
teleportButtonSF = guiCreateButton(18,103,195,35,"San Fierro",false,teleportWindow)
 
teleportButtonLV = guiCreateButton(18,143,195,35,"Las Venturas",false,teleportWindow)
 
guiSetVisible(teleportWindow,false)
 
addEventHandler("onClientGUIClivk", teleportButtonLS, teleportPlayer, false)
 
addEventHandler("onClientGUIClick", teleportButtonSF, teleportPlayer, false)
 
addEventHandler("onClientGUIClick", teleportButtonLV, teleportPlayer, false)
end
addEventHandler("onClientResourceStart", getResourceRoot, createTeleportWindow)
function ()
	createTeleportWindow
end
)
function open TeleportWindow()
guiSetVisible(teleportWindow,true)
 
showCursor(true,true)
end
addCommandHandler("teleportme",openTeleportWindow)
 
function teleportPlayer(button,state)
if button == "left" and state == "up" then
if source ==teleportButtonLS then
triggerServerEvent ("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0)
 
outputChatBox ("You managed to not fail!")
 
elseif source == teleportButtonSF then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),-2265.5,534.0,35.0,270)
 
outputChatBox("Coool")
 
elseif source == teleportButtonLV then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),2036.9,1545.2,10.8,270)
 
outputChatBox("Coolest")
end
 
guiSetVisible(teleportWindow,false)
 
showCursor(false)
end
end

Updated, got rid of the line 2 error, stuck on line 174 now.

script.lua is unchanged.

EDIT: GUI is fixed, teh script finally starts. Now there are issues in script.lua. Player model doesn't appear. After ogging in you're basically looking into the sky.

Link to comment

After some help:

local users =
{
Misha = "noob",
Faberge = "Faberge"
}
 
local function isValidAccount( username, password )
return username and password and users[ username ] == password
end
 
function loginHandler( username, password )
if client == source then
if isValidAccount( username, password ) then
spawnPlayer( source, 1479.6,-1612.8,16.56 )
fadeCamera( source, true )
outputChatBox( "Welcome", source )
else
outputChatBox( "Failed. Relog.", source )
end
end
end
addEvent("submitLogin",true)
addEventHandler("submitLogin",root,loginHandler)
 
function createVehicleForPlayer(thePlayer, command, vehiclemodel, vehiclecolor)
local x,y,z = getElementPosition(thePlayer)
	x= x + 2
local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
if (createdVehicle ==false) then
outputChatBox("You Fail, try again.",thePlayer)
end
end
addCommandHandler("makeveh", createVehicleForPlayer)
 
 
function playerDied(totalAmmo, killer, killerWeapon, bodypart)
outputChatBox(getPlayerName(source) .. " Fail!")
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)
 
function moveThePlayer(x,y,z,rotation)
 
if x and y and z and rotation then
 
local skin = getElementModel(client)
 
	spawnplayer(client,x,y,z,rotation,skin)
 
setCameraTarget(client,client)
 
end
end
addEvent("movePlayerToPosition",true)
addEventHandler("movePlayerToPosition",root,moveThePlayer)

That was script.lua

addEventHandler("onClientResourceStart", getResourceRootElement(),
function ()
local X = 0.375
local Y = 0.375
local Width = 0.25
local Height = 0.25
	wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
	X = 0.0825
	Y = 0.2
	Width = 0.25
	height = 0.25
 
guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
 
	Y = 0.5
guiCreateLabel(X, Y, Width, height, "Password", true, wdwLogin)
 
	X = 0.415
	Y = 0.2
	Width = 0.5
	Height = 0.15
	edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
	Y = 0.5
	edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
guiEditSetMaxLength(edtuser, 50)
guiEditSetMaxLength(edtPass, 50)
 
	X = 0.415
	Y = 0.7
	X = 0.415
	Y = 0.7
	Width = 0.25
	Height = 0.2
	btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)
guiSetVisible(wdwLogin, false)
end
)
addEventHandler("onClientResourceStart", getResourceRootElement(),
function ()
outputChatBox("Welcome, i'm a noob.")
if(wdwLogin ~= nil) then
guiSetVisible(wdwLogin, true)
else
outputChatBox("I failed, yet again.")
end
showCursor(true)
guiSetInputEnabled(true)
end
)
 
function clientSubmitLogin(button,state)
if button == "left" and state == "up" then
local username = guiGetText(edtUser)
local password = guiGetText(edtPass)
 
if username and password then
triggerServerEvent("submitLogin", getLocalPlayer(), username, password)
guiSetInputEnabled(false)
guiSetVisible(wdwLogin, false)
showCursor(false)
else
 
outputChatBox("You need a fucking username and password! LOL!")
end
end
end
 
function createRulesWindow()
local sWidth, sHeight = guiGetScreenSize()
local Width, Height = 445,445
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
rulesWindow = guiCreateWindow(X,Y,Width,Height,"Test",false)
 
guiWindowSetMovable(rulesWindow,true)
 
guiWindowSetSizable(rulesWindow,false)
 
rulesButton = guiCreateButton(137,394,156,37,"Sure",false,rulesWindow)
 
rulesLabel = guiCreateLabel(10,25,425,359,[[
Hello!
 
This is my first server ever, that i've tried to make.
	 In fact, this is the first real script i've ever made,
 even though with the help of the 	tutorial.
  	 My goal is to create a script that could become useful in vG MTA-RP.
 What script it is, i am not sure. I hope to create a mileage meter.
 This is me talking to myself.]], false,rulesWindow)
 
guiLabelSetHorizontalAlign(ruleslabel,"center",true)
addEventHandler("onClientGUIClick", rulesButton, acceptRules, false)
rulesWarningTimer = setTimer(inactivePlayer,120000,1,1)
 
end
 
function acceptRules(button,state)
if button == "left" and state == "up" then
guiSetVisible(rulesWindow, false)
 
showCursor(false,false)	
 
outputChatBox("You passed me.")
 
 
if rulesWarningTimer then
killTimer(rulesWarningTimer)
		rulesWarningTimer = nil
end
end
end	
 
function inactivePlayer(status)
if status == 1 then
outputChatBox("Please, cope with this timer i made")
	rulesWarningTimer = setTimer (inactivePlayer,10000,1,2)
 
elseif status == 2 then
outputChatBox("You have 5 seconds, lol")
	rulesWarningTimer = setTimer(inactivePlayer,5000,1,3)
elseif status == 3 then
outputChatBox("I was about to kick myself. Not going to happen today, mate.")
end
end
 
function createTeleportWindow ()
local sWidth, sHeight = guiGetScreenSize()
 
local Width,Height = 231,188
local X = (sWidth/2) - (Width/2)
local Y = (sHeight/2) - (Height/2)
 
teleportWindow = guiCreateWindow(X,Y,Width,Height,"Magic",false)
 
guiWindowSetSizable(teleportWindow,true)
guiWindowSetMovable(teleportWindow,true)
showCursor(true,true)
 
teleportLabel = guiCreateLabel(18,23,191,33,"Serious magic, bro",false,teleportWindow)
 
guiLabelSetHorizontalAlign(teleportLabel,"center",true)	
 
teleportButtonLS = guiCreateButton(18,63,195,35,"Los Santos",false,teleportWindow)
 
teleportButtonSF = guiCreateButton(18,103,195,35,"San Fierro",false,teleportWindow)
 
teleportButtonLV = guiCreateButton(18,143,195,35,"Las Venturas",false,teleportWindow)
 
guiSetVisible(teleportWindow,false)
 
addEventHandler("onClientGUIClick", teleportButtonLS, teleportPlayer, false)
addEventHandler("onClientGUIClick", teleportButtonSF, teleportPlayer, false)
addEventHandler("onClientGUIClick", teleportButtonLV, teleportPlayer, false)
end
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function ()
	createRulesWindow()
	createTeleportWindow()
showCursor(true,true)
end
)	
 
 
function openTeleportWindow()
guiSetVisible(teleportWindow,true)
 
showCursor(true,true)
end
addCommandHandler("teleportme",openTeleportWindow)
 
function teleportPlayer(button,state)
if button == "left" and state == "up" then
if source ==teleportButtonLS then
triggerServerEvent ("movePlayerToPosition",getLocalPlayer(),1479.6,-1612.8,14.0,0)
 
outputChatBox ("You managed to not fail!")
 
elseif source == teleportButtonSF then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),-2265.5,534.0,35.0,270)
 
outputChatBox("Coool")
 
elseif source == teleportButtonLV then
 
triggerServerEvent("movePlayerToPosition",getLocalPlayer(),2036.9,1545.2,10.8,270)
 
outputChatBox("Coolest")
end
 
guiSetVisible(teleportWindow,false)
 
showCursor(false)
end
end

gui.lua

gui.lua seems to be fine at the moment, but i have an issue - The player is not spawning.

Link to comment

So what message do you get? Do you see "Welcome", or "Failed. Relog." Or don't you get either?

If you don't get any, try changing "root" in line 23 to "getRootElement()", as "root" doesn't appear to be defined.

(also, I think you forgot setCameraTarget in function loginHandler)

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...