Jump to content

Some Questions


Diesulke

Recommended Posts

Posted (edited)

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
Posted

The 1st one doesn't work because you're looping through all vehicles in the server and setting their color. The second one doesn't work because there is no "player" parameter in the event. It's just a matter of using the brain, reading the code and thinking.

Posted

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.

Guest Guest4401
Posted
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 

Posted

Other players won't see the color, because you setting it client side, you need to set it server side to make other players see the color too.

Posted (edited)

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
Posted

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

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