Jump to content

Button error


Recommended Posts

Hi,

I'm making a login/register script and I added a dxDrawText to it, but when you login, I want the dxDrawText to disappear, is there any way to do that? I thought about settimer to the event handler, but if the player doesn't login until the timer's up, or logins too fast, then that would fail. Can you help me?

Client code:

function createGUI() 
  
showCursor(true) 
setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316) 
toggleAllControls(true, thePlayer, true, true) 
  
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Grid = {} 
  
rgbtn = guiCreateButton(386,360,99,20,"Inregistreaza-te",false) 
  
lgbtn = guiCreateButton(494,360,99,20,"Logheaza-te",false) 
  
un = guiCreateLabel(375,294,88,21,"Username: ",false) 
  
ps = guiCreateLabel(377,322,88,21,"Password: ",false) 
  
whatsnew = guiCreateLabel(374,405,202,19,"Ce e nou?",false) 
guiLabelSetHorizontalAlign(whatsnew,"center",false) 
  
thenewstuff = guiCreateLabel(384,434,191,18,"- Sistem de login/register terminat",false) 
  
uned = guiCreateEdit(443,294,103,20,"",false) 
  
psed = guiCreateEdit(443,321,103,20,"",false) 
  
upstuff = guiCreateGridList(0,0,1015,176,false) 
guiGridListSetSelectionMode(upstuff,2) 
  
guiSetAlpha(upstuff,0.34999999403954) 
  
downstuff = guiCreateGridList(0,592,1015,176,false) 
guiGridListSetSelectionMode(downstuff,2) 
  
guiSetAlpha(downstuff,0.5) 
  
end 
  
-- Direct X Drawing 
addEventHandler("onClientRender",root, 
    function() 
        text = dxDrawText("RDK Freeroam",277.0,162.0,411.0,219.0,tocolor(255,255,255,255),3.0,"diploma","left","top",false,false,false) 
    end 
) 
  
addEventHandler("onClientResourceStart", root, createGUI) 
addEventHandler("onClientGUIClick", lgbtn,  
  
function getEdits() 
  
    untxt = guiGetText(uned) 
    pstxt = guiGetText(psed) 
    triggerServerEvent("login", root, untxt, pstxt) 
     
end) 
  
addEventHandler("onClientGUIClick", rgbtn, triggerServerEvent("register", root, untxt, pstxt) 
  
function logged(thePlayer) 
  
    guiSetVisible(rgbtn, false) 
    guiSetVisible(lgbtn, false) 
    guiSetVisible(un, false) 
    guiSetVisible(ps, false) 
    guiSetVisible(uned, false) 
    guiSetVisible(psed, false) 
    guiSetVisible(upstuff, false) 
    guiSetVisible(downstuff, false) 
    guiSetVisible(whatsnew, false) 
    guiSetVisible(thenewstuff, false) 
    toggleAllControls(false, thePlayer, false, false) 
     
end 
  
addEvent("loggedin", true) 
addEventHandler("loggedin", root, logged) 

Server code:

function reg (thePlayer) 
  
    local regAlready = false 
    if untxt and pstxt ~= nil and regAlready == false then 
        addAccount(untxt, pstxt) 
        local regAlready = true 
        if untxt and pstxt == nil and regAlready == true then 
            return 
        end 
    end 
end 
  
function loginS (thePlayer) 
     
    acc = getAccount(untxt, pstxt) 
    if untxt and pstxt ~= false then 
        logIn(source, untxt, pstxt) 
    else 
        return 
    end 
    spawnPlayer (thePlayer, 0.0, 0.0, 5.0, 90.0, 0) 
    triggerClientEvent("loggedin", root) 
end 
  
addEvent("register", true) 
addEvent("login", true) 
addEventHandler("login", root, loginS) 
addEventHandler("register", root, reg) 

Edit: I also get an error, which makes the script not load: expected "(" near getEdits.

Edited by Guest
Link to comment
Oh yes sorry.
addEventHandler("onClientGUIClick", rgbtn, triggerServerEvent("register", root, untxt, pstxt)) 

You didn't closed this

I reviewed the script and edited it a bit. I got something like this:

Invalid argument 2 at event handler, line 48 and 58, got nil. But the button is defined in the GUI script and it is global. What's up with that?

Link to comment

untxt and pstxt values are not set.It takes value only when you click on other button.You never did guiGetText when it clicks on rgbtn button.

Do like this

  
function getRegEdits() 
    untxt = guiGetText(uned) 
    pstxt = guiGetText(psed) 
triggerServerEvent("register", root, untxt, pstxt) 
end 
addEventHandler("onClientGUIClick", rgbtn,getRegEdits) 

Link to comment
untxt and pstxt values are not set.It takes value only when you click on other button.You never did guiGetText when it clicks on rgbtn button.

Do like this

  
function getRegEdits() 
    untxt = guiGetText(uned) 
    pstxt = guiGetText(psed) 
triggerServerEvent("register", root, untxt, pstxt) 
end 
addEventHandler("onClientGUIClick", rgbtn,getRegEdits) 

That's what I had after editing my script a bit. It still gives me the same errors. :/

Link to comment
function createGUI()  
showCursor(true) 
setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316) 
toggleAllControls(true, thePlayer, true, true) 
  
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Grid = {} 
  
rgbtn = guiCreateButton(386,360,99,20,"Inregistreaza-te",false) 
  
lgbtn = guiCreateButton(494,360,99,20,"Logheaza-te",false) 
  
un = guiCreateLabel(375,294,88,21,"Username: ",false) 
  
ps = guiCreateLabel(377,322,88,21,"Password: ",false) 
  
whatsnew = guiCreateLabel(374,405,202,19,"Ce e nou?",false) 
guiLabelSetHorizontalAlign(whatsnew,"center",false) 
  
thenewstuff = guiCreateLabel(384,434,191,18,"- Sistem de login/register terminat",false) 
  
uned = guiCreateEdit(443,294,103,20,"",false) 
  
psed = guiCreateEdit(443,321,103,20,"",false) 
  
upstuff = guiCreateGridList(0,0,1015,176,false) 
guiGridListSetSelectionMode(upstuff,2) 
  
guiSetAlpha(upstuff,0.34999999403954) 
  
downstuff = guiCreateGridList(0,592,1015,176,false) 
guiGridListSetSelectionMode(downstuff,2) 
  
guiSetAlpha(downstuff,0.5) 
  
addEventHandler("onClientGUIClick", lgbtn, onLogin, false) 
addEventHandler("onClientGUIClick", rgbtn, onRegister, false) 
end 
  
-- Direct X Drawing 
addEventHandler("onClientRender",root, 
    function() 
        text = dxDrawText("RDK Freeroam",277.0,162.0,411.0,219.0,tocolor(255,255,255,255),3.0,"diploma","left","top",false,false,false) 
    end 
) 
  
addEventHandler("onClientResourceStart", resourceRoot, createGUI) 
  
function onLogin() 
    local untxt = guiGetText(uned) 
    local pstxt = guiGetText(psed) 
    triggerServerEvent("login", root, untxt, pstxt) 
end 
  
function onRegister() 
    local untxt = guiGetText(uned) 
    local pstxt = guiGetText(psed) 
    triggerServerEvent("register", root, untxt, pstxt) 
end 
  
function logged(thePlayer) 
    guiSetVisible(rgbtn, false) 
    guiSetVisible(lgbtn, false) 
    guiSetVisible(un, false) 
    guiSetVisible(ps, false) 
    guiSetVisible(uned, false) 
    guiSetVisible(psed, false) 
    guiSetVisible(upstuff, false) 
    guiSetVisible(downstuff, false) 
    guiSetVisible(whatsnew, false) 
    guiSetVisible(thenewstuff, false) 
    toggleAllControls(false, thePlayer, false, false) 
end 
addEvent("loggedin", true) 
addEventHandler("loggedin", root, logged) 

Link to comment

I'm dumb >.>.

Edit: Didn't work. I still got the same errors... It changed lines though, as Solidsnake's script had something edited.

WARNING: acc-sys\acc-sys-client.lua:52: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

WARNING: acc-sys\acc-sys-client.lua:59: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Link to comment
function createGUI() 
showCursor(true) 
setCameraMatrix(1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316) 
toggleAllControls(true, thePlayer, true, true) 
  
GUIEditor_Button = {} 
GUIEditor_Label = {} 
GUIEditor_Grid = {} 
  
rgbtn = guiCreateButton(386,360,99,20,"Inregistreaza-te",false) 
  
lgbtn = guiCreateButton(494,360,99,20,"Logheaza-te",false) 
  
un = guiCreateLabel(375,294,88,21,"Username: ",false) 
  
ps = guiCreateLabel(377,322,88,21,"Password: ",false) 
  
whatsnew = guiCreateLabel(374,405,202,19,"Ce e nou?",false) 
guiLabelSetHorizontalAlign(whatsnew,"center",false) 
  
thenewstuff = guiCreateLabel(384,434,191,18,"- Sistem de login/register terminat",false) 
  
uned = guiCreateEdit(443,294,103,20,"",false) 
  
psed = guiCreateEdit(443,321,103,20,"",false) 
  
upstuff = guiCreateGridList(0,0,1015,176,false) 
guiGridListSetSelectionMode(upstuff,2) 
  
guiSetAlpha(upstuff,0.34999999403954) 
  
downstuff = guiCreateGridList(0,592,1015,176,false) 
guiGridListSetSelectionMode(downstuff,2) 
  
guiSetAlpha(downstuff,0.5) 
addEventHandler("onClientGUIClick", rgbtn, onRegister, false) 
addEventHandler("onClientGUIClick", lgbtn, onLogin, false) 
end 
  
-- Direct X Drawing 
addEventHandler("onClientRender",root, 
    function() 
        text = dxDrawText("RDK Freeroam",277.0,162.0,411.0,219.0,tocolor(255,255,255,255),3.0,"diploma","left","top",false,false,false) 
    end 
) 
  
addEventHandler("onClientResourceStart", resourceRoot, createGUI) 
  
function onLogin() 
    local untxt = guiGetText(uned) 
    local pstxt = guiGetText(psed) 
    triggerServerEvent("login", root, untxt, pstxt) 
end 
  
function onRegister() 
    local untxt = guiGetText(uned) 
    local pstxt = guiGetText(psed) 
    triggerServerEvent("register", root, untxt, pstxt) 
end 
  
function logged(thePlayer) 
    guiSetVisible(rgbtn, false) 
    guiSetVisible(lgbtn, false) 
    guiSetVisible(un, false) 
    guiSetVisible(ps, false) 
    guiSetVisible(uned, false) 
    guiSetVisible(psed, false) 
    guiSetVisible(upstuff, false) 
    guiSetVisible(downstuff, false) 
    guiSetVisible(whatsnew, false) 
    guiSetVisible(thenewstuff, false) 
    toggleAllControls(false, thePlayer, false, false) 
end 
addEvent("loggedin", true) 
addEventHandler("loggedin", root, logged) 

Try this

Link to comment

Thanks for pointing that out. I know how to do this, if it happens again ;P.

Edit: I got 2 more errors and a fail in the script. Sorry for bothering you, but I need more help.

The errors are these two:

[2012-01-12 13:13:13] WARNING: acc-sys\acc-sys-server.lua:17: Bad argument @ 'logIn' [Expected player at argument 1, got root]

[2012-01-12 13:13:13] WARNING: acc-sys\acc-sys-server.lua:21: Bad 'player' pointer @ 'spawnPlayer'(1)

And whenever I type a random username+password and click login without registering, it works. I tried fixing it by doing this

acc = getAccount(untxt, pstxt)

if untxt and pstxt ~= false and acc == true then

but the login button doesn't work at all now.

Link to comment

Try

Client

function createGUI( ) 
  
showCursor( true ) 
setCameraMatrix( 1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316 ) 
toggleAllControls( true ) 
  
GUIEditor_Button = { } 
GUIEditor_Label = { } 
GUIEditor_Grid = { } 
  
rgbtn = guiCreateButton( 386,360,99,20,"Inregistreaza-te",false ) 
  
lgbtn = guiCreateButton( 494,360,99,20,"Logheaza-te",false ) 
  
un = guiCreateLabel( 375,294,88,21,"Username: ",false ) 
  
ps = guiCreateLabel( 377,322,88,21,"Password: ",false ) 
  
whatsnew = guiCreateLabel( 374,405,202,19,"Ce e nou?",false ) 
guiLabelSetHorizontalAlign( whatsnew,"center",false ) 
  
thenewstuff = guiCreateLabel( 384,434,191,18,"- Sistem de login/register terminat",false ) 
  
uned = guiCreateEdit( 443,294,103,20,"",false ) 
  
psed = guiCreateEdit( 443,321,103,20,"",false ) 
  
upstuff = guiCreateGridList( 0,0,1015,176,false ) 
guiGridListSetSelectionMode( upstuff,2 ) 
  
guiSetAlpha( upstuff,0.34999999403954 ) 
  
downstuff = guiCreateGridList( 0,592,1015,176,false ) 
guiGridListSetSelectionMode( downstuff,2 ) 
  
guiSetAlpha( downstuff,0.5 ) 
  
end 
  
-- Direct X Drawing 
addEventHandler( "onClientRender",root, 
    function( ) 
        dxDrawText( "RDK Freeroam",277.0,162.0,411.0,219.0,tocolor( 255,255,255,255 ),3.0,"diploma","left","top",false,false,false ) 
    end 
) 
  
addEventHandler( "onClientResourceStart", resourceRoot, createGUI ) 
  
addEventHandler( "onClientGUIClick", lgbtn,  
    function( ) 
        local chec1 = guiGetText( uned ) 
        local check2 = guiGetText( psed ) 
        if chec1 and check2 then  
            triggerServerEvent( "login", localPlayer, check1, check2 ) 
        end  
    end 
,false ) 
  
addEventHandler( "onClientGUIClick", rgbtn, 
    function( ) 
        local chec1 = guiGetText( uned ) 
        local check2 = guiGetText( psed ) 
        if chec1 and check2 then  
            triggerServerEvent( "register", localPlayer, check1, check2 ) 
        end  
    end 
,false )     
  
function logged( ) 
    guiSetVisible( rgbtn, false ) 
    guiSetVisible( lgbtn, false ) 
    guiSetVisible( un, false ) 
    guiSetVisible( ps, false ) 
    guiSetVisible( uned, false ) 
    guiSetVisible( psed, false ) 
    guiSetVisible( upstuff, false ) 
    guiSetVisible( downstuff, false ) 
    guiSetVisible( whatsnew, false ) 
    guiSetVisible( thenewstuff, false ) 
    toggleAllControls( false, false, false ) 
end 
addEvent( "loggedin", true ) 
addEventHandler( "loggedin", root, logged ) 
  

Server

function reg ( name,pass ) 
    local regAlready = false 
    if not regAlready then 
        addAccount( name, pass ) 
        local regAlready = true 
        outputChatBox( "Register succes!" ) 
    end 
end 
  
function loginS ( name,pass ) 
    local acc = getAccount( name,pass ) 
    if acc then 
        logIn( source, acc, pass ) 
        spawnPlayer ( source, 0.0, 0.0, 5.0, 90.0, 0 ) 
        triggerClientEvent( source,"loggedin", source ) 
        outputChatBox( "Login succes!" ) 
    else 
        outputChatBox( "Error login!" )     
    end  
end 
  
addEvent( "register", true ) 
addEvent( "login", true ) 
addEventHandler( "login", root, loginS ) 
addEventHandler( "register", root, reg ) 

Link to comment

Search MTA_FOLDER\server\mods\deathmatch\acl.xml and find

add this line

  
<object name="resource.your_resource_name" /> 
  

example

  
... 
<group name="Admin"> 
        <acl name="Moderator" /> 
        <acl name="SuperModerator" /> 
        <acl name="Admin" /> 
        <object name="resource.admin" /> 
        <object name="resource.your_resource_name" /> 
        ... 
</group> 
... 
  

Edited by Guest
Link to comment

Lols.. I made a noob mistake. I forgot to edit the resource name in the acl group >.>. It will probably work now. Let me check.

It works, but the camera matrix doesn't change and it remains on the vinewood sign. I fixed it.

Edit2: When I type keys that are binded to MTA's chat system, they work, even if I toggled the controls. Do I have to unbind them and bind them after?

Edit3: Fixed :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...