Jump to content

Creating server side vehicle and changing it's gravity


Recommended Posts

I have a script which is supposed to create a plane and set it's Z vector gravity high so it can't take off. Now here's the problem, in order to set the vehicles gravity I need to use setVehicleGravity function which is client sided only. Therefore I have to create a client-sided vehicle.. And that's where the problem arrives: The client sided vehicles are unenterable and undestructive... As an alternative I tried using warpPlayerIntoVehicle function but it is server-side function only. And now I am stuck, I don't know what to do, but the best solution would be to somehow create the vehicle server sided because I would like others to see it and somehow change the other part. Basically my question is: How do I make server-sided vehicle and change

it's gravity?

If it helps anyhow, this is the client sided code I wrote in order to create vehicle and change the gravity:

function createPlane() 
    local guy = getLocalPlayer() 
    plane = createVehicle (577, -1635.5999755859, -142.30000305176, 14.800000190735, 0, 0, 316 ) 
    setVehicleGravity(plane, 0.008, 0.008, -10) 
end 
addCommandHandler ("go", createPlane) 

Thanks in advance,

Koyax

Link to comment
  • Moderators

Why don't you go reading what triggerServerEvent is?

and maybe also take a close look at the wiki sample.

To send information back.

triggerClientEvent

Edited by Guest
Link to comment

If server and client scripts were completely separate, the latter ones would be nearly useless. But since client-side scripts can use all elements the client sees and server-side elements are visible for client, you can use functions on server-side elements in client-side scripts. The general ways to transfer the data between server and client are custom events and element data:

addEvent 
addEventHandler 
triggerServerEvent 
triggerClientEvent 
  
setElementData 
getElementData 

When you cross-trigger the event on one side, the handler functions for that event on the other side will be called. You can pass the data as additional arguments and it will be transfered to another side.

Element data is a simpler way to synchronize data: whatever you set on server/client becomes automatically synced for server and all clients unless you set the synchronize argument to false.

Also, you can set the synced identifier and use it to get the element on the client:

setElementID 
getElementByID 

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