Jump to content

Some Questions


Diesulke

Recommended Posts

Hello,

My script is not working how it should work.

My carcolor should change when I press the button, but when i press the button the car of all players is changing to the same color.

function changeColor ( ButtonC ) 
        if ButtonC == "left" then 
for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
local number4 = guiGetText(TextC) 
 local success = setVehicleColor(car, tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) 
  if not success then 
  outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) 
  end 
end 
end 
end 

I also tried this, but then i'll get an error: Bad argument @ 'isPedInVehicle'.

function changeColor ( ButtonC ) 
        if ButtonC == "left" then 
local number4 = guiGetText(TextC) 
if isPedInVehicle( player ) then 
 local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) 
  if not success then 
  outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) 
  end 
end 
end 
end 

Any ideas?

Edited by Guest
Link to comment

Even when I add the parameter like this:

    function changeColor ( player, ButtonC ) 
            if ButtonC == "left" then 
    local number4 = guiGetText(TextC) 
    if isPedInVehicle( player ) then 
     local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) 
      if not success then 
      outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) 
      end 
    end 
    end 
    end 

it doesn't work.

Link to comment
Guest Guest4401
function changeColor ( ButtonC ) 
    if ButtonC == "left" then 
        local car = getPedOccupiedVehicle(localPlayer) 
        if car then 
            local number4 = guiGetText(TextC) 
            local success = setVehicleColor(car, tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) 
            if not success then 
                outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) 
            end 
        end 
    end 
end 

Link to comment

Thanks, made it work.

Server:

addEvent("onColorChangeRequest",true) 
function changeColor(num) 
  local car = getPedOccupiedVehicle(source) 
  if not car then 
    outputChatBox("You are not in a car!",source,255,255,255,true) 
    return false 
  end 
  setVehicleColor(car,num,num,num,num) 
end 
addEventHandler("onColorChangeRequest",getRootElement(),changeColor) 

Client:

function changeColor ( ButtonC ) 
  if ButtonC == "left" then 
    local number4 = guiGetText(TextC) 
    number4 = tonumber(number4) 
    if not number4 then 
      outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) 
      return false 
    end 
    triggerServerEvent("onColorChangeRequest",getLocalPlayer(),number4) 
  end 
end 

Edited by Guest
Link to comment

Next Time Use Lua/Lua Tag Same This :

function changeColor ( ButtonC ) 
  if ButtonC == "left" then 
    local number4 = guiGetText(TextC) 
    number4 = tonumber(number4) 
    if not number4 then 
      outputChatBox( "Invalid input, use numbers only!", 255, 255, 255) 
      return false 
    end 
    triggerServerEvent("onColorChangeRequest",getLocalPlayer(),number4) 
  end 
end 
Link to comment
Even when I add the parameter like this:

    function changeColor ( player, ButtonC ) 
            if ButtonC == "left" then 
    local number4 = guiGetText(TextC) 
    if isPedInVehicle( player ) then 
     local success = setVehicleColor(getPedOccupiedVehicle ( player ), tonumber(number4), tonumber(number4), tonumber(number4), tonumber(number4)) 
      if not success then 
      outputChatBox( "Invalid input, use numbers only!", 255, 255, 255, source ) 
      end 
    end 
    end 
    end 

it doesn't work.

It doesn't work because you're adding parameters that doesn't exist.

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