Jump to content

triggerClientEvent problem


bandi94

Recommended Posts

i am :shock: whit this script

server side

  
function  spawn() 
local repulo1 = createVehicle(519,1949.039,-2494.000,14.539,0,0,90) 
local pilota1 = createPed(61,0,0,0) 
warpPedIntoVehicle(pilota1,repulo1) 
  
  triggerClientEvent ( "fly",  getRootElement(),pilota1) 
end 
addEventHandler("onResourceStart",root,spawn) 
  

client side

function go(pilota1) 
setPedControlState(pilota1,"accelerate",true) 
setTimer(setPedControlState,4000,1,pilota1,"steer_back",true) 
setTimer(setPedControlState,10000,1,pilota1,"steer_back",false) 
end 
addEvent( "fly", true ) 
addEventHandler("fly",root,go) 

meta

<meta> 
                      <script src="server.lua" type="server" /> 
                      <script src="client.lua" type="client" /> 
</meta> 

and i get " Server triggered clientside event fly, but event is not added clientside" hmm where I wrong

Link to comment

the problem is that onResourceStart is fired before the client finishes up downloading.

the clientside code will only exist after the download has completed. So when you run your script, the client doesn't know about the client data yet :)

Change the event/handler to something you'll know the client had downloaded when you run it.

Link to comment

Try:

server side:

function  spawn() 
local repulo1 = createVehicle(519,1949.039,-2494.000,14.539,0,0,90) 
local pilota1 = createPed(61,0,0,0) 
warpPedIntoVehicle(pilota1,repulo1) 
  
  triggerClientEvent ( "fly",  getRootElement(),pilota1) 
end 
addEvent("onResourceDownloaded",true) 
addEventHandler("onResourceDownloaded",root,spawn) 

client side:

addEventHandler("onClientResourceStart",resourceRoot, 
function() 
triggerServerEvent("onResourceDownloaded",getLocalPlayer()) 
end) 
  
function go(pilota1) 
setPedControlState(pilota1,"accelerate",true) 
setTimer(setPedControlState,4000,1,pilota1,"steer_back",true) 
setTimer(setPedControlState,10000,1,pilota1,"steer_back",false) 
end 
addEvent( "fly", true ) 
addEventHandler("fly",root,go) 

Not tested, but should work.

Link to comment

There's no need to trigger events at all. It's much easier to do with setElementID and getElementByID. For example change triggerClientEvent line into something like:

setElementID(pilota1,"pilot") 

Then in go function:

local pilota1 = getElementByID("pilot") 

And attach go function to onClientResourceStart.

Link to comment

ohhh thx for all and now I realized that i make a s**t bk the server side make's a plane whit a pilot and the client side script moves the planeand its visible to everyone but if i have 2 players each client side script it will control it in difrent sync and it will make a big s**t however i wana make 1 NPC plane but whit SetControlState i can't make it bk its only for player not work for created ped somebody some ideas how can i make it ( 1 plane controled by script visible to everyone in same time (sync for all player) takeoff fly land and back .....)

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