Jump to content

setVehicleColor not working


aintaro

Recommended Posts

Hello guys,

my vehicle color won't change to the color I want it to be, here is my simple command to spawn a vehicle with a certain color :

function colorVehicle() 
    local x,y,z = getElementPosition(getLocalPlayer()) -- get the position of the player 
                x = x + 5 
    local vehicleShowz = createVehicle ( 491, x, y, z) 
    setVehicleColor(vehicleShowz, 255, 0, 0) 
end 
  
addCommandHandler("spawnVehicle", colorVehicle) 

Anybody help?

Thanks in addvance,

Aintaro

Link to comment

A client vehicle will only exist in the client who created it somehow, it's pretty much like creating a vehicle in GTA SA single player. A server sided vehicle on the other hand will exist in the server and stay synced between all players in the server. Basically, any element that you want to have synced between all players should be created server side, which is pretty much all elements. I can't find any possible situation where you need to create elements on the client.

Link to comment
Creating vehicles client side will make the vehicle unusable.

MTA security measures i guess?

This has nothing to do with mta security measures, creating a vehicle client-side will only create it for a specific client (player), nobody will be able to see it except for this client, that's why you can't enter a vehicle that was created on client-side.

Link to comment
Also, always color vehicles server-sided - coloring it clientside will only show the color to you.

However, sometimes coloring clientside is a good thing - like preview of modshop vehicle colors for example.

Thats exactly why I want to create a Vehicle client sided, I want the user to preview the car before he actually spawns it

Link to comment

Then it's called a "dummiecar", create it with a local pointer client side, change the color on the client then when the configuration is done and the user press ok or spawn you save the configuration in local variables but removes the actual car. After that you should trigger a server event, pass the configuration parameters and then spawn a car server side that looks exactly like the client sided car you just removed.

Link to comment
Then it's called a "dummiecar", create it with a local pointer client side, change the color on the client then when the configuration is done and the user press ok or spawn you save the configuration in local variables but removes the actual car. After that you should trigger a server event, pass the configuration parameters and then spawn a car server side that looks exactly like the client sided car you just removed.

Every player has he's own vehicle, so before spawning the vehicle i want the player to see a dummy version of the vehicle client dided before we spawn it server sided

Link to comment
create the vehicle to another dimension and set player's camera to it then, if he cancels the spawning or spawns the vehicle, destroy the preview one, set players camera back to the player and spawn the vehicle.

Yeah thats a way of doing it, I just though cliënt sided would be so much more efficiënt

Link to comment
Creating vehicles client side will make the vehicle unusable.

MTA security measures i guess?

This has nothing to do with mta security measures, creating a vehicle client-side will only create it for a specific client (player), nobody will be able to see it except for this client, that's why you can't enter a vehicle that was created on client-side.

Thought of some anti-cheat for local side. Anyways, you can create it, warp a ped inside, and make it accelerate with toggleControl, its kind of usable :mrgreen:

EDIT:

@Post starter:

Client:

  
function createVehicle(cmd,id) 
if veh then 
destroyElement(veh) 
end 
local x,y,z = getElementPosition(getLocalPlayer()) 
veh = createVehicle(id,x+5,y,z) 
end 
addCommandHandler("createVehicle", createVehicle) 
  
function setColor(cmd, r,g,b,a) 
setVehicleColor(veh, r,g,b,a) 
end 
addCommandHandler("setColor", setColor) 
  
function SpawnVehicle() 
local r,g,b,a = getVehicleColor(veh) -- Should be global variable 
local x,y,z = getElementPosition(veh) 
local rx,ry,rz = getElementRotation(veh) 
local id = getElementModel(veh) 
triggerServerEvent("SpawnVehicle", getLocalPlayer(), id,x,y,z,rx,ry,rz,r,g,b,a) 
destroyElement(veh) 
end 
addCommandHandler("spawnVehicle", SpawnVehicle) 
  

Server:

  
veh = {} 
function SpawnVehicle(id,x,y,z,rx,ry,rz,r,g,b,a) 
veh[source] = createVehicle(id,x,y,z) 
setElementRotation(veh[source],rx,ry,rz) 
setVehicleColor(veh[source], r,g,b,a) 
end 
addEvent("SpawnVehicle") 
addEventHandler("SpawnVehicle", getRootElement(), SpawnVehicle) 
  

PD: Didnt tested it.

EDIT2:

About another dimension:

client:

(Add this to the prev)

  
function SpecVehicle() 
if veh then 
setElementDimension(veh, 30) 
local x,y,z = getElementPosition(veh) 
local dimension = getElementDimension(veh) 
setElementDimension(getLocalPlayer(), dimension) 
setCameraMatrix(x-5,y,z+5, unpack(getElementPosition(veh))) 
else 
setElementDimension(getLocalPlayer(), 0) 
setCameraTarget(getLocalPlayer()) 
end 
end 
addEventHandler("onClientRender", getRootElement(), SpecVehicle) 
  

Link to comment
Thought of some anti-cheat for local side. Anyways, you can create it, warp a ped inside, and make it accelerate with toggleControl, its kind of usable :mrgreen:

I didn't say you can't move a client-sided vehicle, you can but only with peds, or by using setElementVelocity. Also i think it IS possible to control a client-sided vehicle, since you can warp the ped into it and control it by using setPedControlState ;).

Link to comment
Why does the client sided setvehicle color exist when it has no use?

Becouse you can create some animations and effects with the vehicles, a podium is a clear example of this. (I'd make winner vehicle golde, second one silver, and third one bronze colour)

Anyways, check my previous post and tell me if it works okay.

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