Jump to content

Problem with GUI.


Bumbis

Recommended Posts

Hi everyone! I have stupid problem with GUI. It doesnt show nothing, just black screen when i connect. But it needs to be appeared. I have a mysql server and i connect it, its all ok with connection, but i think that the problem is in my client side script. Please look at my Server-side and Client-side scripts, i will appreciate that.

Server-side:

function connectMysql() 
    handler = mysql_connect("localhost", "root", "", "phptest") -- Establish the connection 
    if ( not handler ) then -- The connection failed 
      outputDebugString("Unable to connect to the MySQL server. Server is shutting down.") 
      stopAllResources() 
    else 
        outputDebugString("MYSQL loaded successfuly") 
    end 
end 
addEventHandler("onResourceStart",getRootElement(),connectMysql) 
  
function stopAllResources() 
    -- we store a table of resources 
    local allResources = getResources() 
    -- for each one of them, 
    for i, resource in ipairs(allResources) do 
        -- if it's running, and it is not the current resource 
        if ( getResourceState(resource) == "running" ) then 
            -- then stop it 
            stopResource(resource) 
        end 
    end 
end 
  
function joinHandler(player) 
    local x = 1959.55 
    local y = -1714.46 
    local z = 10 
    fadeCamera(source, true) 
    setCameraTarget(source,source) 
    outputChatBox("Hey,"..getPlayerName(source).."!", source) 
end 
  
function Showname(playerSource) 
    outputChatBox("Tavs vards ir - "..getPlayerName(playerSource)..".",playerSource) 
end 
addCommandHandler("name",Showname) 
  
  
function Showhelp(playerSource) 
    outputChatBox("#FAD904|-------| Kommandas |-------|",playerSource,0,0,0,true) 
    outputChatBox(" /help /name /veh",playerSource) 
    outputChatBox("#FAD904|---------------------------|",playerSource,0,0,0,true) 
end 
addCommandHandler("help",Showhelp) 
  
function vehicle(playerSource,commandName,vehid) 
    local x,y,z = getElementPosition(playerSource) 
    createVehicle(tonumber(vehid),x+1,y,z+0.2) 
end 
addCommandHandler("veh",vehicle) 
  
  
local chatRadius = 20  
function sendMessageToNearbyPlayers( message, messageType ) 
    if messageType == 0 then 
        local posX, posY, posZ = getElementPosition( source ) 
  
        local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) 
        destroyElement( chatSphere ) 
  
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            outputChatBox( getPlayerName(source).." saka#FFFFFF: "..message, nearbyPlayer,180,180,180,true ) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", getRootElement(), sendMessageToNearbyPlayers ) 
  
function blockChatMessage() 
    cancelEvent() 
end 
addEventHandler( "onPlayerChat", getRootElement(), blockChatMessage ) 
  
function Mecmd( message, messageType ) 
    if messageType == 0 then 
        local posX, posY, posZ = getElementPosition( source ) 
  
        local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) 
        destroyElement( chatSphere ) 
  
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            outputChatBox(getPlayerName(source).." saka#FFFFFF: "..message, nearbyPlayer,180,180,180,true ) 
        end 
    end 
end 
  
function checkPlayers() 
    if(handler) then 
        local q = mysql_query(handler,"SELECT * FROM mta_users WHERE Name='"..getPlayerName(source).."'") 
        if(mysql_num_rows(q) == 1) then 
            showCursor(source,true) 
            triggerClientEvent(getRootElement(),"CreateLoginWindow",getRootElement()) 
            triggerClientEvent(getRootElement(),"ShowLogin",getRootElement()) 
            mysql_free_result(q) 
        else if(mysql_num_rows(q)==0) then 
            showCursor(source,true) 
            triggerClientEvent(getRootElement(),"CreateRegisterWindow",getRootElement()) 
            mysql_free_result(q) 
            triggerClientEvent(getRootElement(),"ShowRegister",getRootElement()) 
        end 
    end 
end 
end 
addEventHandler("onPlayerJoin",getRootElement(),checkPlayers) 

Client-side:

function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Lūdzu ielogojies", true) 
  
    -- define new X and Y positions for the first label 
    X = 0.0825 
    Y = 0.2 
    -- define new Width and Height values for the first label 
    Width = 0.25 
    Height = 0.25 
    -- create the first label, note the final argument passed is 'wdwLogin' meaning the window 
    -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window) 
    guiCreateLabel(X, Y, Width, Height, "Lietotājs", true, wdwLogin) 
    -- alter the Y value, so the second label is slightly below the first 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Parole", 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) 
    -- set the maximum character length for the username and password fields to 50 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
  
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.2 
    btnLogin = guiCreateButton(X, Y, Width, Height, "Ielogoties.", true, wdwLogin) 
  
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
end 
  
function createRegisterWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwReg = guiCreateWindow(X, Y, Width, Height, "Lūdzu reģistrējies", true) 
  
    -- define new X and Y positions for the first label 
    X = 0.0825 
    Y = 0.2 
    -- define new Width and Height values for the first label 
    Width = 0.25 
    Height = 0.25 
    -- create the first label, note the final argument passed is 'wdwLogin' meaning the window 
    -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window) 
    guiCreateLabel(X, Y, Width, Height, "Lietotājs", true, wdwReg) 
    -- alter the Y value, so the second label is slightly below the first 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Parole", true, wdwReg) 
  
  
    X = 0.415 
    Y = 0.2 
    Width = 0.5 
    Height = 0.15 
    regUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwReg) 
    Y = 0.5 
    regPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwReg) 
    -- set the maximum character length for the username and password fields to 50 
    guiEditSetMaxLength(regUser, 50) 
    guiEditSetMaxLength(regPass, 50) 
  
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.2 
    btnReg = guiCreateButton(X, Y, Width, Height, "Reģistrēties.", true, wdwReg) 
  
    -- make the window invisible 
    guiSetVisible(wdwReg, false) 
end 
  
addEvent("CreateLoginWindow",true) 
addEvent("CreateRegisterWindow",true) 
addEventHandler("CreateLoginWindow",getRootElement(),createLoginWindow) 
addEventHandler("CreateRegisterWindow",getRootElement(),createRegisterWindow) 
  
function showRegister() 
    guiSetVisible(wdwReg,true) 
end 
  
function showLogin() 
    guiSetVisible(wdwLogin,true) 
end 
  
addEvent("ShowRegister",true) 
addEvent("ShowLogin",true) 
addEventHandler("ShowRegister",getRootElement(),showRegister) 
addEventHandler("ShowLogin",getRootElement(),showLogin) 
  
addEventHandler("onClientRender",root, 
    function() 
        dxDrawLine(231.0,729.0,231.0,767.0,tocolor(255,255,255,255),1.0,false) 
        dxDrawLine(28.0,728.0,28.0,767.0,tocolor(255,255,255,255),1.0,false) 
        dxDrawLine(232.0,728.0,0.0,728.0,tocolor(255,255,255,255),1.0,false) 
        dxDrawText("Gonzas Roleplay",9.0,737.0,250.0,766.0,tocolor(150,100,100,200),1.0,"pricedown","center","top",true,false,false) 
    end 
) 

Edited by Guest
Link to comment

1. using so many events is a bit redundant (1 event to create and hide, next event to show?).

just create and hide windows on resource start, or use the same 1 event to create and show.

2. you're triggering client event for all players, not the one that needs it. use:

triggerClientEvent(source,"ShowLogin",getRootElement()) 

3. use "/debugscript 3" in game to see client-side script errors.

Link to comment

To do List:

-start your server

- type /register NAME PASSWORD eg: /register jack_miller lolapassword -- or register in console without the /

- shut down your server

- go in: MTA\server\mods\deathmatch

- open acl.xml

- find the admin category

- add under:

- (just the same just with your (registred) name)

- start your server

- /login NAME PASSWORD

- /debugscript 3

- be happy :D

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