Wojak Posted June 15, 2011 Share Posted June 15, 2011 Client side : addEvent("getTrain", true ) function getTrain () local x, y, z = getElementPosition(getElementByID( "loco1" )) local a, b, c = getElementPosition(getElementByID( "wagon1" )) local g, h, i = getElementPosition(getElementByID( "pilot2" )) local d, e, f = getElementPosition(getElementByID( "pilot1" )) triggerServerEvent("setTrainPosition",getRootElement(),x,y,z,a,b,c,g,h,i,d,e,f) end addEventHandler("getTrain", getRootElement(), getTrain) Server side : addEvent("setTrainPosition",true) function setTrain (x,y,z,a,b,c,g,h,i,d,e,f) triggerClientEvent( "getTrain", getRootElement()) setElementPosition(loco, x, y, z, false) setElementPosition(locool, a, b, c, false) setElementPosition(pilot1, d, e, f, false) setElementPosition(pilot2, g, h, i, false) end addEventHandler("setTrainPosition",getRootElement(),setTrain) I don't know if that's what you wanted. This may work with one player on the server, but most likely result with high ping or timeout. if there will be more than one client on the server, events will multiply and crach the server, not to mention the data conflict, if somehow the coordinates on each client will be diferent Link to comment
dolmen62 Posted June 15, 2011 Author Share Posted June 15, 2011 Yes, I have to use the ping of the player. If the ping is > 150 ten ... Link to comment
karlis Posted June 15, 2011 Share Posted June 15, 2011 you should reduce the sending to ~100 ms, and add a velocity var, so sync can still be proper Link to comment
AGENT_STEELMEAT Posted June 15, 2011 Share Posted June 15, 2011 What are you guys doing? Just make a train serverside, make it move, on use setElementStreamable to ensure all clients have it loaded all the time. It isn't hard... Link to comment
karlis Posted June 15, 2011 Share Posted June 15, 2011 What are you guys doing? Just make a train serverside, make it move, on use setElementStreamable to ensure all clients have it loaded all the time. It isn't hard... bother reading some pages before?streaming is bugged Link to comment
AGENT_STEELMEAT Posted June 15, 2011 Share Posted June 15, 2011 I doubt that, I've done similar stuff before on 1.0.5 with no issues. Link to comment
Wojak Posted June 15, 2011 Share Posted June 15, 2011 I doubt that, I've done similar stuff before on 1.0.5 with no issues. It has nothing to do with streaming, vehicles that are located more than 140 m from any player are not synced, even if it is still moving, the movment is lical, and the position for the server is not updated, when the vehicle get close enough to a player again, it vill jump to last synced position. Link to comment
dolmen62 Posted June 15, 2011 Author Share Posted June 15, 2011 I just have an idea. If I warp the man into the train, with a marker, It can work ! Link to comment
dolmen62 Posted June 15, 2011 Author Share Posted June 15, 2011 Client side : addEvent("getTrain", true ) function getTrain () local x, y, z = getElementPosition(getElementByID( "loco1" )) local a, b, c = getElementPosition(getElementByID( "wagon1" )) local g, h, i = getElementPosition(getElementByID( "pilot2" )) local d, e, f = getElementPosition(getElementByID( "pilot1" )) triggerServerEvent("setTrainPosition",getRootElement(),x,y,z,a,b,c,g,h,i,d,e,f) end addEventHandler("getTrain", getRootElement(), getTrain) Server side : addEvent("setTrainPosition",true) function setTrain (x,y,z,a,b,c,g,h,i,d,e,f) triggerClientEvent( "getTrain", getRootElement()) setElementPosition(loco, x, y, z, false) setElementPosition(locool, a, b, c, false) setElementPosition(pilot1, d, e, f, false) setElementPosition(pilot2, g, h, i, false) end addEventHandler("setTrainPosition",getRootElement(),setTrain) I don't know if that's what you wanted. It don't work, the train can't move, and it's very laggy. Link to comment
Castillo Posted June 15, 2011 Share Posted June 15, 2011 Yes, I suposed it was going to lag a lot. Link to comment
DiSaMe Posted June 16, 2011 Share Posted June 16, 2011 There's no need to sync the train so often. Just create a timer which executes the function like every 5 or 10 seconds, checks if the train has the syncer, and if it doesn't, find the nearest player, use triggerClientEvent to ask for train position, on the client side, get the position, use triggerServerEvent to send the position to the server and again, on the server side, use those coordinates in setElementPosition. Link to comment
dolmen62 Posted June 16, 2011 Author Share Posted June 16, 2011 I don't think I will use that, because, it's to laggy. I'm working on a system of marker, to put the player into the train. But only when it is here "if nextgare == number of the station " Link to comment
DiSaMe Posted June 16, 2011 Share Posted June 16, 2011 Laggy? 1 update in 5 seconds, what's so laggy? Have you already tried that? Link to comment
dolmen62 Posted June 16, 2011 Author Share Posted June 16, 2011 No... Ok I will try ! But how to execute the function, only for the nearest player ? Link to comment
DiSaMe Posted June 16, 2011 Share Posted June 16, 2011 There's an optional argument for triggerClientEvent. And to find the nearest player, you need to loop through all of them and calculate the distances. Link to comment
dolmen62 Posted June 17, 2011 Author Share Posted June 17, 2011 It don't work, I have error, when i want to setElement Position ! Link to comment
dolmen62 Posted June 26, 2011 Author Share Posted June 26, 2011 I have an Idea : refresh coordinates only when the train is in the station. Link to comment
dolmen62 Posted July 4, 2011 Author Share Posted July 4, 2011 Well, I've a new idea. view my code : It don't work. Client Side : addEvent("removeStreamableLocos", true ) function removeStreamableLocos( theElement ) setElementStreamable( getElementByID( "loco1" ), false ) setElementStreamable( getElementByID( "wagon1" ), false ) setElementStreamable( getElementByID( "pilot1" ), false ) setElementStreamable( getElementByID( "pilot2" ), false ) end addEventHandler("removeStreamableLocos", getRootElement(), removeStreamableLocos ) addEvent("getTrain", true ) function getTrain () local x, y, z = getElementPosition(getElementByID( "loco1" )) local a, b, c = getElementPosition(getElementByID( "wagon1" )) local g, h, i = getElementPosition(getElementByID( "pilot2" )) local d, e, f = getElementPosition(getElementByID( "pilot1" )) triggerServerEvent("setTrainPosition",getRootElement(),x,y,z,a,b,c,g,h,i,d,e,f) end addEventHandler("getTrain", getRootElement(), getTrain) and Server Side : function makeTrain(source) loco = createVehicle(537,1725.9,-1954,16) locool = createVehicle(538,1840,-1954,16) setElementID( loco, "loco1" ) setElementID( locool, "wagon1" ) setTrainDerailable(loco, false) setTrainDerailable(locool, false) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) setElementID( pilot1, "pilot1" ) setElementID( pilot2, "pilot2" ) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) setTimer(setTrain, 5000, 0) createBlipAttachedTo(loco, 42) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.203) setTimer(assemblage, 10000, 1) outputChatBox("Train is here", source, 255, 255, 0) removeStreamable( loco ) setTimer(depart, 20000, 1) nextgare = 0 end addCommandHandler("traintest", makeTrain) function assemblage () nextgare = nextgare+1 setTrainSpeed(loco, 0) setTrainSpeed(locool, 0) setTimer(depart, 20000,1) end function depart () nextgare = nextgare+1 setTrainSpeed(loco, 1) setTrainSpeed(locool, 1) if nextgare == 0 then setTimer(assemblage, 88000, 1) else if nextgare == 2 then setTimer(assemblage, 23000, 1) else if nextgare == 4 then setTimer(assemblage, 93000, 1) else if nextgare == 6 then setTimer(assemblage,102000, 1) else if nextgare == 8 then setTimer(assemblage, 50000, 1) else if nextgare == 10 then nextgare = 0 end end end end end end end function speed () setTrainSpeed(loco, 1) setTrainSpeed(locool, 1) end function removeStreamable( theElement ) triggerClientEvent( "removeStreamableLocos", getRootElement() ) end addEvent("setTrainPosition",true) function setTrain (x,y,z,a,b,c,g,h,i,d,e,f) triggerClientEvent( "getTrain", getRootElement()) setElementPosition(loco, x, y, z, false) setElementPosition(locool, a, b, c, false) setElementPosition(pilot1, d, e, f, false) setElementPosition(pilot2, g, h, i, false) end addEventHandler("setTrainPosition",getRootElement(),setTrain) Link to comment
JR10 Posted July 4, 2011 Share Posted July 4, 2011 YOU TRIPLE POSTED. Dont double post use the edit button. Link to comment
DiSaMe Posted July 4, 2011 Share Posted July 4, 2011 Is it "double posting" to post a message a few days later from the last message? And now, the script problems: server-side function setTrain and client-side function getTrain trigger events, calling each other. That means the train position will be refreshed very fast, as the server asks for the new position right after it gets the previous. And the number of such cycles is increased every 5 seconds. That will make the game unplayable very soon. I will try to explain better what you need to do: 1. Make the server-side timer do NOTHING more than just triggering the client-side event (asking for position). 2. When server gets the position, the function called by setTrainPosition event should do NOTHING more than setting element positions. No event triggering. Link to comment
dolmen62 Posted July 5, 2011 Author Share Posted July 5, 2011 Thank you !!! It work great now !!! Now I have to program station ^^ Link to comment
Dev Posted July 6, 2011 Share Posted July 6, 2011 I nedd help ! The train don't stop on the marker, when no body is near it. That is one bug you cannot fix, in MTA the train will only work with 'setTrainSpeed' if there is any player in syncing range near the train. I made a train resource myself and it was working fabulous until I noticed that as soon as I go far away from it, the train stops moving. Link to comment
ecoxp Posted July 6, 2011 Share Posted July 6, 2011 Thank you !!! It work great now !!!Now I have to program station ^^ Give us the script, please Link to comment
qaisjp Posted July 6, 2011 Share Posted July 6, 2011 YOU TRIPLE POSTED.Dont double post use the edit button. Please refrain from backseat moderating "OOPS, I just moderated xD" Link to comment
dolmen62 Posted July 6, 2011 Author Share Posted July 6, 2011 I need to program station now. But timer are not presise it change in function of the processor charge. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now