Jump to content

code not work


Dimos7

Recommended Posts

function rainbowColor(thePlayer) 
   local money = getPlayerMoney(thePlayer) 
   local theVehicle= getPedOccupiedVehicle(thePlayer) 
   local r, g, b = math.random(0, 255) , math.random(0, 255), math.random(0, 255) 
   if isPedInVehicle(thePlayer) then 
      if money >= 10000 then 
         takePlayerMoney(thePlayer, 10000) 
         theTimer = setTimer(setVehicleColor, 1000, 0, theVehicle, r, g, b) 
      else 
         outputChatBox("You not have enough money for this", thePlayer, 255, 0, 0) 
         return false 
       end 
    end 
    if isTimer(theTimer) then 
       killTimer(theTimer) 
    end 
end 
addCommandHandler("rainbow", rainbowColor) 

time pass but color not change

Edited by Guest
Link to comment
  • Moderators

The problem with your code is that your timer is calling only one function which is setVehicleColor every 1 second with the given arguments instead of:

1 - regenerating the r, g, b values

AND THEN

2 - call the setVehicleColor with the new values.

So your rainbow timer needs to do 2 things instead of one. As the setTimer can only call one function, you have to wrap the 2 things inside a new function that will do both (l.14-17):

function rainbowColor(thePlayer) 
    if isPedInVehicle(thePlayer) then 
        local theVehicle = getPedOccupiedVehicle(thePlayer) 
         
        local rainbowTimer = getElementData(theVehicle, "rainbowTimer") -- getting the rainbowTimer from the vehicle (false if none has been saved yet) 
        if isTimer(rainbowTimer) then -- if the timer already exists for that vehicle then 
            killTimer(rainbowTimer) -- just stop it (no need to take money to stop it) 
            return -- we are done, stop the function 
        end 
         
        -- If we get there, it means that the vehicle doesn't have rainbow timer activated so let's create it 
        local money = getPlayerMoney(thePlayer) 
        if money >= 10000 then 
            takePlayerMoney(thePlayer, 10000) 
            local rainbowTimer = setTimer(function (veh) 
                local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255) 
                setVehicleColor(veh, r, g, b) 
            end, 1000, 0, theVehicle) 
            setElementData(theVehicle, "rainbowTimer", rainbowTimer, false) -- saving the rainbowTimer in the vehicle element 
        else 
            outputChatBox("You do not have enough money for this ! ($10000 required)", thePlayer, 255, 0, 0) 
        end 
    else 
        outputChatBox("You have to be in a vehicle to do that !", thePlayer, 255, 0, 0) 
    end 
end 
addCommandHandler("rainbow", rainbowColor) 

One potential problem with this is that anyone inside the vehicle can turn the rainbow thing on and off.

I mean for example, you (Dimos7) are the owner of the vehicle, you do /rainbow to start it, then I (Citizen) can turn it off by doing /rainbow too but on a passenger seat.

A solution would be to replace this:

if isPedInVehicle(thePlayer) then 

by this:

if getPedOccupiedVehicleSeat( thePlayer ) == 0 then 

Which will only allow the driver to use the command for the vehicle.

Best regards,

Citizen

Link to comment
local GUIEditor = { 
      window, 
      label, 
      button, 
      edit 
} 
  
function createPasswordWindow() 
   GUIEditor.window[1]= guiCreateWindow(714, 272, 502, 344, "Password change:", false) 
   GUIEditor.label[1]= guiCreateLabel(10, 38, 75, 15, "Password:", false, GUIEditor.window[1]) 
   GUIEditor.edit[1]= guiCreateEdit(85, 34, 359, 37, "", false, GUIEditor.window[1]) 
   guiWindowSetMovable(GUIEditor.window[1], false) 
   guiWindowSetSizable(GUIEditor.window[1], false) 
   guiEditSetMasked(GUIEditor.edit[1], true) 
   GUIEditor.label[2]= guiCreateLabel(10, 115, 75, 15, "Repeat:", false, GUIEditor.window[1]) 
   GUIEditor.edit[2]= guiCreateEdit(85, 101, 359, 37, "", false, GUIEditor.window[1]) 
   guiEditSetMasked(GUIEditor.edit[2], true) 
   GUIEditor.button[1]= guiCreateButton(92, 241, 126, 84, "Change", false, GUIEditor.window[1]) 
   GUIEditor.button[2]= guiCreateButton(235, 241 ,126, 84, "Cancel", false, GUIEditor.window[1]) 
   guiSetVisible(GUIEditor.window[1], false) 
   addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw) 
   addEventHandler("onClientGUIClick", GUIEditor.button[2], clientCancelChangepw) 
end 
  
function createLoginWindow() 
    GUIEditor.window[2]= guiCreateWindow(714, 272, 502, 344, "Infernus panel", false) 
    GUIEditor.label[3]= guiCreateLabel(10, 38, 75, 15, "Username:", false, GUIEditor.window[2]) 
    GUIEditor.edit[3]= guiCreateEdit(85, 34, 359, 37, "", false, GUIEditor.window[2]) 
    GUIEditor.label[4]= guiCreateLabel(10, 115, 75, 15, "Password:", false, GUIEditor.window[2]) 
    GUIEditor.edit[4]= guiCreateEdit(85, 101, 359, 37, "", false, GUIEditor.window[2]) 
    guiEditSetMasked(GUIEditor.edit[4], true) 
    guiWindowSetMovable(GUIEditor.window[2], false) 
    guiWindowSetSizable(GUIEditor.window[2], false) 
    GUIEditor.button[3]= guiCreateButton(92, 241, 126, 84, "Login", false, GUIEditor.window[2]) 
    GUIEditor.button[4]= guiCreateButton(235, 241, 126, 84, "Register", false, GUIEditor.window[2]) 
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin) 
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister) 
end 
  
function resourceStart () 
   createLoginWindow() 
   if (GUIEditor.window[2] ~= nil) then 
       guiSetVisible(GUIEditor.window[2], true) 
   else 
      outputChatBox("An error has occurred!") 
   end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEventHandler("onClientResourceStart", resourceRoot, resourceStart) 
  
function changePw() 
   createPasswordWindow() 
   guiSetVisible(GUIEditor.window[1], true) 
   showCursor(true) 
   guiSetInputEnabled(true) 
 end 
  
 function clientCancelChangepw(button, state) 
    if button == "left" and state ==" down" then 
       if source == GUIEditor.button[2] then 
          guiSetVisible(GUIEditor.window[1], false) 
          showCursor(false) 
          guiSetInputEnabled(false) 
       end 
    end 
end 
  
function clientSubmitChangepw(button, state) 
    if button == "left" and state == "down" then 
       if source == GUIEditor.button[1] then 
          password = guiGetText(GUIEditor.edit[1]) 
          cpassword = guiGetText(GUIEditor.edit[2]) 
          if password ~= "" and cpassword ~="" then 
             triggerServerEvent("submitChangepw", root, localPlayer, password, cpassword) 
          else 
             outputChatBox("You need put password and confirmpassword!") 
          end 
      end 
    end 
end 
  
function clientSubmitLogin(button, state) 
   if button == "left" and state == "down" then 
      if source == GUIEditor.button[3] then 
         username = guiGetText(GUIEditor.edit[3]) 
         password = guiGetText(GUIEditor.edit[4]) 
         if username ~= "" and password ~= "" then 
            triggerServerEvent("submitLogin", root, localPlayer, username, password) 
        else 
           outputChatBox("You need put username and password!") 
        end 
     end 
    end 
end 
  
function clientSubmitRegister(button, state) 
    if button == "left" and state == "down" then 
       if source == GUIEditor.button[4] then 
          username = guiGetText(GUIEditor.edit[3]) 
          password = guiGetText(GUIEditor.edit[4]) 
          if username ~= "" and password ~= "" then 
             triggerServerEvent("submitRegister", root, localPlayer, username, password) 
          else 
             outputChatBox("You need put username and password!") 
          end 
       end 
    end 
end 
  
function hidePasswordWindow() 
    guiSetVisible(GUIEditor.window[1], false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
end 
  
function hideLoginWindow() 
   guiSetVisible(GUIEditor.window[2], false) 
   showCursor(false) 
   guiSetInputEnabled(false) 
end 
  
addEvent("hidePasswordWindow", true) 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", root, hideLoginWindow) 
addEventHandler("hidePasswordWindow", root, hidePasswordWindow) 
addCommandHandler("changepass", changePw) 

line 26 attempt to index field window a nill value

Link to comment

Client

local GUIEditor = { 
      window = {}, 
      label = {}, 
      button = {}, 
      edit = {} 
} 
  
function createPasswordWindow() 
   GUIEditor.window[1]= guiCreateWindow(714, 272, 502, 344, "Password change:", false) 
   GUIEditor.label[1]= guiCreateLabel(10, 38, 75, 15, "Password:", false, GUIEditor.window[1]) 
   GUIEditor.edit[1]= guiCreateEdit(85, 34, 359, 37, "", false, GUIEditor.window[1]) 
   guiWindowSetMovable(GUIEditor.window[1], false) 
   guiWindowSetSizable(GUIEditor.window[1], false) 
   guiEditSetMasked(GUIEditor.edit[1], true) 
   GUIEditor.label[2]= guiCreateLabel(10, 115, 75, 15, "Repeat:", false, GUIEditor.window[1]) 
   GUIEditor.edit[2]= guiCreateEdit(85, 101, 359, 37, "", false, GUIEditor.window[1]) 
   guiEditSetMasked(GUIEditor.edit[2], true) 
   GUIEditor.button[1]= guiCreateButton(92, 241, 126, 84, "Change", false, GUIEditor.window[1]) 
   GUIEditor.button[2]= guiCreateButton(235, 241 ,126, 84, "Cancel", false, GUIEditor.window[1]) 
   guiSetVisible(GUIEditor.window[1], false) 
   addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw) 
   addEventHandler("onClientGUIClick", GUIEditor.button[2], clientCancelChangepw) 
end 
  
function createLoginWindow() 
    GUIEditor.window[2]= guiCreateWindow(714, 272, 502, 344, "Infernus panel", false) 
    GUIEditor.label[3]= guiCreateLabel(10, 38, 75, 15, "Username:", false, GUIEditor.window[2]) 
    GUIEditor.edit[3]= guiCreateEdit(85, 34, 359, 37, "", false, GUIEditor.window[2]) 
    GUIEditor.label[4]= guiCreateLabel(10, 115, 75, 15, "Password:", false, GUIEditor.window[2]) 
    GUIEditor.edit[4]= guiCreateEdit(85, 101, 359, 37, "", false, GUIEditor.window[2]) 
    guiEditSetMasked(GUIEditor.edit[4], true) 
    guiWindowSetMovable(GUIEditor.window[2], false) 
    guiWindowSetSizable(GUIEditor.window[2], false) 
    GUIEditor.button[3]= guiCreateButton(92, 241, 126, 84, "Login", false, GUIEditor.window[2]) 
    GUIEditor.button[4]= guiCreateButton(235, 241, 126, 84, "Register", false, GUIEditor.window[2]) 
    addEventHandler("onClientGUIClick", GUIEditor.button[3], clientSubmitLogin) 
    addEventHandler("onClientGUIClick", GUIEditor.button[4], clientSubmitRegister) 
end 
  
function resourceStart () 
   createLoginWindow() 
   if (GUIEditor.window[2] ~= nil) then 
       guiSetVisible(GUIEditor.window[2], true) 
   else 
      outputChatBox("An error has occurred!") 
   end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEventHandler("onClientResourceStart", resourceRoot, resourceStart) 
  
function changePw() 
   createPasswordWindow() 
   guiSetVisible(GUIEditor.window[1], true) 
   showCursor(true) 
   guiSetInputEnabled(true) 
 end 
  
 function clientCancelChangepw(button, state) 
    if button == "left" and state ==" down" then 
       if source == GUIEditor.button[2] then 
          guiSetVisible(GUIEditor.window[1], false) 
          showCursor(false) 
          guiSetInputEnabled(false) 
       end 
    end 
end 
  
function clientSubmitChangepw(button, state) 
    if button == "left" and state == "down" then 
       if source == GUIEditor.button[1] then 
          password = guiGetText(GUIEditor.edit[1]) 
          cpassword = guiGetText(GUIEditor.edit[2]) 
          if password ~= "" and cpassword ~="" then 
             triggerServerEvent("submitChangepw", root, localPlayer, password, cpassword) 
          else 
             outputChatBox("You need put password and confirmpassword!") 
          end 
      end 
    end 
end 
  
function clientSubmitLogin(button, state) 
   if button == "left" and state == "down" then 
      if source == GUIEditor.button[3] then 
         username = guiGetText(GUIEditor.edit[3]) 
         password = guiGetText(GUIEditor.edit[4]) 
         if username ~= "" and password ~= "" then 
            triggerServerEvent("submitLogin", root, localPlayer, username, password) 
        else 
           outputChatBox("You need put username and password!") 
        end 
     end 
    end 
end 
  
function clientSubmitRegister(button, state) 
    if button == "left" and state == "down" then 
       if source == GUIEditor.button[4] then 
          username = guiGetText(GUIEditor.edit[3]) 
          password = guiGetText(GUIEditor.edit[4]) 
          if username ~= "" and password ~= "" then 
             triggerServerEvent("submitRegister", root, localPlayer, username, password) 
          else 
             outputChatBox("You need put username and password!") 
          end 
       end 
    end 
end 
  
function hidePasswordWindow() 
    guiSetVisible(GUIEditor.window[1], false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
end 
  
function hideLoginWindow() 
   guiSetVisible(GUIEditor.window[2], false) 
   showCursor(false) 
   guiSetInputEnabled(false) 
end 
  
addEvent("hidePasswordWindow", true) 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", root, hideLoginWindow) 
addEventHandler("hidePasswordWindow", root, hidePasswordWindow) 
addCommandHandler("changepass", changePw) 

Server

local connection = exports.SQL:getSQLConnection() 
  
function passwordHandler(thePlayer, password, cpassword) 
    local account = getPlayerAccount(thePlayer) 
    if (account) then 
        if (isGuestAccount(account)) then 
           outputChatBox("You must be logged in to change your password!", thePlayer, 255, 0, 0) 
           return 
        end 
        if password == cpassword then 
           if (string.len(password)>= 5) then 
              setAccountPassword(account, password) 
              triggerClientEvent(thePlayer, "hidePaswwordWindow", root) 
              dbExec(connection, "UPATE accounts SET password=?", tostring(password)) 
           
           else 
              outputChatBox("Your new password must be at least 5 characters long!", thePlayer, 255, 0, 0) 
           end 
        else 
          outputChatBox("Password aren't the same!", thePlayer, 255, 0, 0) 
        end 
    end 
end 
  
function loginHandler(thePlayer, username, password) 
    local account = getAccount(username, password) 
    local query = dbQuery(connection, "SELECT * FROM accounts WHERE username=? and password=?", username, password) 
    local result, num_affected_row = dbPoll(query, -1) 
    if (account ~= false) and num_affected_row == 1 then 
        if (logIn(thePlayer, account, password) == true) then 
           outputChatBox("Welcome back to Infernus RPG!", thePlayer, 0, 255, 150) 
           triggerClientEvent(thePlayer, "hideLoginWindow", root) 
        else 
           outputChatBox("Account not found!", thePlayer, 255, 0, 0) 
        end 
    else 
       outputChatBox("Username or password are invaild!", thePlayer, 255, 0, 0) 
    end 
end 
  
function registerHandler(thePlayer, username, password) 
    local account = getAccount(username, password) 
    local query = dbQuery(connection, "SELECT * FROM accounts WHERE username=? and password=?", username, password) 
    local result, num_affected_row = dbPoll(query, -1) 
    if (account ~= false) and num_affected_row == 1 then 
        outputChatBox("This username alread exist!", thePlayer, 255, 0, 0) 
    else 
       account = addAccount(username, password) 
       outputChatBox("You succefully register!", thePlayer, 0, 255, 0) 
       dbExec(connection, "INSERT INTO accounts(username, password, name, serial) VALUES ('"..tostring(username)..'","'..tostring(password).."','"..tostring(getPlayerName(thePlayer))..'","'..tostring(getPlayerSerial(thePlayer)).."')") 
       if (logIn(thePlayer, account, password) == true ) then 
          outputChatBox("Welcome to Infernus RPG", thePlayer, 0, 255, 150) 
          triggerClientEvent(thePlayer, "hideLoginWindow", root) 
      else 
         outputChatBox("Account not found!", thePlayer, 255, 0, 0) 
      end 
   end 
end 
addEvent("submitChangepw", true) 
addEvent("submitLogin", true) 
addEvent("submitRegister", true) 
addEventHandler("submitChangepw", root, passwordHandler) 
addEventHandler("submitLogin", root, loginHandler) 
addEventHandler("submitRegister", root, registerHandler) 

Not error or warning when click login orRegister nothing happend

and yes its on admin group

Link to comment
  • Moderators

Try to add ",false" without the quotes to all your onClientGUIClick:

addEventHandler("onClientGUIClick", GUIEditor.button[1], clientSubmitChangepw, false) 

Also, when something doesn't work without any error or warning, then you can use outputChatBoxs to know where the code execution is going and where it stops.

This is part of your job which is "debugging" your code.

Note: I didn't say it was the error neither the only one. But try that first and use outputChatBox everywhere you can.

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