Jump to content

Problems


Jaysds1

Recommended Posts

  • Replies 365
  • Created
  • Last Reply

Top Posters In This Topic

Hi everyone again,

I'm having a trouble with this Local chat script,

When the person/player presses u, it's suppose to show "Local" instead of "Say" and have the type in, but the keys aren't bind and it doesn't work at all

  
addEventHandler("onPlayerJoin", getRootElement(), 
function(player) 
bindKey(player,"u","down",locl) 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function(player) 
    for index, player in pairs(getElementsByType("player")) do 
    unbindKey ( player, "u", "down",locl ) 
    end 
end) 
  
function locl(button,state,_,...) 
    if (button == "left") and (state == "down") then 
        local px,py,pz = getElementPosition(source) 
        local msg = table.concat({...}, " ") 
        local nick = getPlayerName(source) 
        local r,g,b = getTeamColor(getPlayerTeam(source)) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox("(Local) "..nick..": "..msg,v,r,g,b,true) 
            end 
        end 
    end 
end 
  
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 

Link to comment

The code you copied from another topic was wrong, you forgot functions and changed things wrongly.

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
    bindKey(source,"U","down","chatbox","Local") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player,"U","down","chatbox","Local") 
    end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,i,...) 
  local px,py,pz=getElementPosition(player) 
  local nick=getPlayerName(player) 
  local msg = table.concat({...}, " ") 
  local r,g,b = getTeamColor(getPlayerTeam(player))   
  for i,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("(Local) ".. nick ..": "..msg,v,r,g,b,true) 
    end 
  end 
end 
addCommandHandler("Local",onChat) 

Link to comment

Hi everyone,

I have a problem with this Save script, it's suppose to save the players username but first it checks to see if there is anything in the value, but it doesn't check and doesn't save the username,

Client-side ONLY:

  
        if (guiCheckBoxGetSelected(user_safe) == true) then 
                safe = xmlLoadFile("safe.xml") 
                child = xmlFindChild(safe,"Username") 
                if (xmlNodeGetValue(child) ~= nil) then 
                    xmlNodeSetValue(child,username) 
                    if (xmlNodeGetValue(child1) ~= "") then 
                        child2 = xmlFindChild(safe,"Username2") 
                        if (xmlNodeGetValue(child2) ~= "") then 
                            outputChatBox("*INFO*: THERE IS NO MORE SPACE IN YOUR SAFE DIRECTORY TO SAVE YOUR USERNAME!",getLocalPlayer(),255,0,0) 
                        else 
                            xmlNodeSetValue(child2,username) 
                        end 
                    else 
                        xmlNodeSetValue(child1,username) 
                    end 
                else 
                    child1 = xmlFindChild(safe,"Username1") 
                end 
        end 

Link to comment

Try:

        if (guiCheckBoxGetSelected(user_safe) == true) then 
                safe = xmlLoadFile("safe.xml") 
                child = xmlFindChild(safe,"Username",0) 
                if (xmlNodeGetValue(child) ~= nil) then 
                    xmlNodeSetValue(child,username) 
                    if (xmlNodeGetValue(child1) ~= "") then 
                        child2 = xmlFindChild(safe,"Username2",0) 
                        if (xmlNodeGetValue(child2) ~= "") then 
                            outputChatBox("*INFO*: THERE IS NO MORE SPACE IN YOUR SAFE DIRECTORY TO SAVE YOUR USERNAME!",getLocalPlayer(),255,0,0) 
                        else 
                            xmlNodeSetValue(child2,username) 
                        end 
                    else 
                        xmlNodeSetValue(child1,username) 
                    end 
                else 
                    child1 = xmlFindChild(safe,"Username1",0) 
                end 
        end 

Link to comment

Hi all,

Today I'm editing my Login GUI and when the player presses enter the Login GUI is suppose to close, but when I press enter it doesn't close,

Here's my script:

  
function finishNow() 
if (guiGetVisible(logGui) == true) then 
        local username = guiGetText(user_edit) 
        local password = guiGetText(pass_edit) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("log",getRootElement(),username,password,gui) 
        else 
            outputChatBox("*INFO*: Please enter your username and password",getLocalPlayer(),255,0,0) 
        end 
elseif (guiGetVisible(regGui) == true) then 
            local username = guiGetText(user_edit1) 
            local password = guiGetText(pass_edit1) 
            if (username ~= "") and (password ~= "") then 
                triggerServerEvent("reg",getRootElement(),username,password) 
            else 
                outputChatBox("*INFO*: Please enter a username and password",getLocalPlayer(),255,0,0) 
            end 
end 
end 
addEvent("c1",true) 
  
addEventHandler("c1",getRootElement(),function()    if (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(logGui) showCursor(false) guiSetInputEnabled(false)  end end) 
  
addEvent("c2",true) 
  
addEventHandler("c2",getRootElement(),function()    if (guiGetVisible(regGui) == true) and (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(regGui) destroyElement(logGui)   showCursor(false) guiSetInputEnabled(false) end end) 

It basically gets the text in the username and password box and triggers an event, then another event triggers back to the script and unbind the key.

Link to comment

I think you are never binding the keys at all.

function finishNow() 
if (guiGetVisible(logGui) == true) then 
        local username = guiGetText(user_edit) 
        local password = guiGetText(pass_edit) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("log",getRootElement(),username,password,gui) 
        else 
            outputChatBox("*INFO*: Please enter your username and password",getLocalPlayer(),255,0,0) 
        end 
elseif (guiGetVisible(regGui) == true) then 
            local username = guiGetText(user_edit1) 
            local password = guiGetText(pass_edit1) 
            if (username ~= "") and (password ~= "") then 
                triggerServerEvent("reg",getRootElement(),username,password) 
            else 
                outputChatBox("*INFO*: Please enter a username and password",getLocalPlayer(),255,0,0) 
        end 
    end 
end 
bindKey("enter","down",finishNow) 
  
addEvent("c1",true) 
addEventHandler("c1",getRootElement(),function()    if (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(logGui) showCursor(false) guiSetInputEnabled(false)  end end) 
  
addEvent("c2",true)  
addEventHandler("c2",getRootElement(),function()    if (guiGetVisible(regGui) == true) and (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(regGui) destroyElement(logGui)   showCursor(false) guiSetInputEnabled(false) end end) 

Link to comment

sorry, this is how it looks:

  
addEventHandler("onClientPlayerJoin",getRootElement(),function() bindKey("enter","down",finishNow) end) 
function finishNow() 
if (guiGetVisible(logGui) == true) then 
        local username = guiGetText(user_edit) 
        local password = guiGetText(pass_edit) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("log",getRootElement(),username,password,gui) 
        else 
            outputChatBox("*INFO*: Please enter your username and password",getLocalPlayer(),255,0,0) 
        end 
elseif (guiGetVisible(regGui) == true) then 
            local username = guiGetText(user_edit1) 
            local password = guiGetText(pass_edit1) 
            if (username ~= "") and (password ~= "") then 
                triggerServerEvent("reg",getRootElement(),username,password) 
            else 
                outputChatBox("*INFO*: Please enter a username and password",getLocalPlayer(),255,0,0) 
            end 
end 
end 
  
addEvent("c1",true) 
  
addEventHandler("c1",getRootElement(),function()    if (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(logGui) showCursor(false) guiSetInputEnabled(false)  end end) 
  
addEvent("c2",true) 
  
addEventHandler("c2",getRootElement(),function()    if (guiGetVisible(regGui) == true) and (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then    unbindKey("enter","down",finishNow) destroyElement(img) destroyElement(regGui) destroyElement(logGui)   showCursor(false) guiSetInputEnabled(false) end end) 

Link to comment

Like I told you before, the key is not being binded, because onClientPlayerJoin is only triggered by other players, not the CLIENT, use onClientResourceStart instead.

function finishNow() 
if (guiGetVisible(logGui) == true) then 
        local username = guiGetText(user_edit) 
        local password = guiGetText(pass_edit) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("log",getRootElement(),username,password,gui) 
        else 
            outputChatBox("*INFO*: Please enter your username and password",getLocalPlayer(),255,0,0) 
        end 
elseif (guiGetVisible(regGui) == true) then 
        local username = guiGetText(user_edit1) 
        local password = guiGetText(pass_edit1) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("reg",getRootElement(),username,password) 
        else 
            outputChatBox("*INFO*: Please enter a username and password",getLocalPlayer(),255,0,0) 
        end 
    end 
end 
addEventHandler("onClientResourceStart",resourceRoot,function() bindKey("enter","down",finishNow) end) 
  
addEvent("c1",true) 
addEventHandler("c1",getRootElement(),function()  
if (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then 
    unbindKey("enter","down",finishNow)  
    destroyElement(img)  
    destroyElement(logGui)  
    showCursor(false)  
    guiSetInputEnabled(false)   
end end) 
  
addEvent("c2",true) 
addEventHandler("c2",getRootElement(),function() 
if (guiGetVisible(regGui) == true) and (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then 
    unbindKey("enter","down",finishNow)  
    destroyElement(img)  
    destroyElement(regGui)  
    destroyElement(logGui) 
    showCursor(false)  
    guiSetInputEnabled(false)  
end end) 

Link to comment

Use onClientKey instead of bindKey, this way it works with the input too.

function finishNow() 
if (guiGetVisible(logGui) == true) then 
        local username = guiGetText(user_edit) 
        local password = guiGetText(pass_edit) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("log",getRootElement(),username,password,gui) 
        else 
            outputChatBox("*INFO*: Please enter your username and password",getLocalPlayer(),255,0,0) 
        end 
elseif (guiGetVisible(regGui) == true) then 
        local username = guiGetText(user_edit1) 
        local password = guiGetText(pass_edit1) 
        if (username ~= "") and (password ~= "") then 
            triggerServerEvent("reg",getRootElement(),username,password) 
        else 
            outputChatBox("*INFO*: Please enter a username and password",getLocalPlayer(),255,0,0) 
        end 
    end 
end 
addEventHandler("onClientResourceStart",resourceRoot,function() addEventHandler("onClientKey", root, onEnterKeyPressed) end) 
  
addEvent("c1",true) 
addEventHandler("c1",getRootElement(),function() 
if (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then 
    removeEventHandler("onClientKey", root, onEnterKeyPressed) 
    destroyElement(img) 
    destroyElement(logGui) 
    showCursor(false) 
    guiSetInputEnabled(false)   
end end) 
  
addEvent("c2",true) 
addEventHandler("c2",getRootElement(),function() 
if (guiGetVisible(regGui) == true) and (guiGetVisible(logGui) == true) and (guiGetVisible(img) == true) then 
    removeEventHandler("onClientKey", root, onEnterKeyPressed) 
    destroyElement(img) 
    destroyElement(regGui) 
    destroyElement(logGui) 
    showCursor(false) 
    guiSetInputEnabled(false) 
end end) 
  
function onEnterKeyPressed(button, press) 
    if (press and button=="enter") then 
        finishNow() 
    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...