dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 It don't work ! The train don't stop if I'm not in ! Link to comment
AGENT_STEELMEAT Posted June 11, 2011 Share Posted June 11, 2011 Did you edit the code I posted properly? Post your script again. Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 well, I've an error when i modify "getrootelement" function makeTrain(source) loco = createVehicle(537,1725.9,-1954,16) locool = createVehicle(538,1840,-1954,16) setTrainDerailable(loco, false) setTrainDerailable(locool, false) removeStreamable( loco ) removeStreamable( locool ) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) removeStreamable( pilot1 ) removeStreamable( pilot2 ) createBlipAttachedTo(loco, 42) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.203) outputChatBox("Train is here", source, 255, 255, 0) removeStreamable(markerGare2) setTimer(depart, 20000, 1) end addCommandHandler("traintest", makeTrain) local markerGare2 = createMarker(787, -1341.8, -1.8, "cylinder", 3, 255, 255, 255, 5) function markerHit(hitElement, matchingDimension) if matchingDimension and hitElement == loco then setTrainSpeed(hitElement, 0) outputChatBox("Your message here") setTimer(depart, 20000, 1) end setTimer(depart, 20000, 1) end addEventHandler( "onMarkerHit", markerGare2, stop ) function depart () setTrainSpeed(loco, 1) setTrainSpeed(locool, 1) end function removeStreamable( theElement ) triggerClientEvent( "removeStreamable", getRootElement(), theElement ) end Link to comment
SDK Posted June 11, 2011 Share Posted June 11, 2011 Well, your addEventHandler for onMarkerHit points to the wrong function, "stop" instead of "markerhit' Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 No change, it don't stop. Link to comment
Moderators Citizen Posted June 11, 2011 Moderators Share Posted June 11, 2011 Ok so I made few tests and I found the problem, the problem is that when we set the streamable of the trains to false, then ok there aren't streamed but their positions stay streamed. If I go to the 2nd station, I see the trains moving but not their positions. So their positions aren't updated but If I go to the position where they spawned, the position is "unstreamed" and the brake function works Maybe someone can add this bug in bugtracker ( idk how to use it ) If you want to make a test, then take this: Server: 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) -- removeStreamable( loco ) -- removeStreamable( locool ) 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) -- removeStreamable( pilot1 ) -- removeStreamable( pilot2 ) createBlipAttachedTo(loco, 42) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.203) outputChatBox("Train is here", source, 255, 255, 0) removeStreamable( loco ) setTimer(depart, 20000, 1) nextgare = 1 setTimer( check, 2000, 0 ) end addCommandHandler("traintest", makeTrain) -- local markerGare2 = createMarker(787, -1341.8, -1.8, "cylinder", 3, 255, 255, 255, 5) function stop (hitElement) -- outputChatBox("HIT") if not( getElementType( hitElement ) == "vehicle" ) then return end -- outputChatBox("c'est un véhicule") if not( getElementModel( hitElement ) == 537 ) then return end outputChatBox("Brake") setTrainSpeed(loco, 0) setTrainSpeed(locool, 0) -- if ( source ) then -- if ( source == markerGare2 )then -- outputChatBox("Le Train est dans Market Station.", getRootElement(), 255, 255, 0) -- end -- end setTimer(depart, 20000, 1) end -- addEventHandler( "onMarkerHit", getRootElement(), stop ) function depart () -- nextgare = nextgare+1 setTrainSpeed(loco, 1) setTrainSpeed(locool, 1) end function removeStreamable( theElement ) outputChatBox( "remove_s") triggerClientEvent( "removeStreamableLocos", getRootElement() ) end function check() local x, y, z = getElementPosition( getElementByID( "loco1" ) ) outputChatBox( x..", "..y..", "..z) if nextgare == 2 then if y >= -1341.8 then stop( loco ) nextgare = nextgare+1 end -- elseif nextgare == 3 then -- a decommenter pour continuer -- if >= then -- stop( loco ) -- end end end Client: addEvent("removeStreamableLocos", true ) function removeStreamableLocos( theElement ) setElementStreamable( getElementByID( "loco1" ), false ) setElementStreamable( getElementByID( "wagon1" ), false ) setElementStreamable( getElementByID( "pilot1" ), false ) setElementStreamable( getElementByID( "pilot2" ), false ) outputChatBox("destream") end addEventHandler("removeStreamableLocos", getRootElement(), removeStreamableLocos ) So go to the the station underground of LS then type /traintest ( the T on the map is the train ) wait 10 sec then the train will move. You will see that the position stay to 1725.9000244141, -1954, 16 and the train will not stop to the station. ok so now go to the spawn position and then the position will instantanly change to another position. Link to comment
dolmen62 Posted June 12, 2011 Author Share Posted June 12, 2011 I've test it, and it's really annoying ! We need a gost player ! But I don't know if it exist. Link to comment
Castillo Posted June 12, 2011 Share Posted June 12, 2011 A ghost player? maybe you could use a ped? Link to comment
dolmen62 Posted June 12, 2011 Author Share Posted June 12, 2011 No ! A real player who is all the time in the train. Link to comment
Castillo Posted June 12, 2011 Share Posted June 12, 2011 Well, you won't get a player who will be there full time, so why not a ped?? do you know what a PED is? Link to comment
dolmen62 Posted June 12, 2011 Author Share Posted June 12, 2011 Yes, I actually use it to control the train. Link to comment
dolmen62 Posted June 12, 2011 Author Share Posted June 12, 2011 I change my system, now I use Timer. My new problem is how to get in the train ! because it respawn when I want to get in ! Link to comment
dolmen62 Posted June 12, 2011 Author Share Posted June 12, 2011 Error found !!! Train's coordinates are used by the client, and not by the server ! Link to comment
Wojak Posted June 12, 2011 Share Posted June 12, 2011 Ok so I made few tests and I found the problem, the problem is that when we set the streamable of the trains to false, then ok there aren't streamed but their positions stay streamed. If I go to the 2nd station, I see the trains moving but not their positions. So their positions aren't updated but If I go to the position where they spawned, the position is "unstreamed" and the brake function works Maybe someone can add this bug in bugtracker ( idk how to use it ) its not a bug, its a MTA sync limit (100m for peds, 140 for vehicles) even if someone will "fix" this, you wont find a server that will handle it... Link to comment
DiSaMe Posted June 12, 2011 Share Posted June 12, 2011 I think this could be the solution: getElementPosition client-side --> triggerServerEvent with coordinates --> setElementPosition server-side. Link to comment
dolmen62 Posted June 13, 2011 Author Share Posted June 13, 2011 Yes I Will try it today. But, if no body is connected to the server, what happen ? Link to comment
DiSaMe Posted June 13, 2011 Share Posted June 13, 2011 If nobody is connected to the server, then server has no player to sync the train, so it won't move, but there will be no players to see that anyway. Link to comment
dolmen62 Posted June 13, 2011 Author Share Posted June 13, 2011 Thank you for your help. I Hope it work ! Link to comment
dolmen62 Posted June 14, 2011 Author Share Posted June 14, 2011 I don't know how to get client coordinates on the server. Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 Do you mean send data to the server? If so, then you can use triggerServerEvent function to send data. Link to comment
dolmen62 Posted June 14, 2011 Author Share Posted June 14, 2011 No, coordinates don't change in the server, that's why I Want to take coordinates from the client, to the server. But I try to use triggerClientEvent, but it don't work. I can't sens you code because I'm on my iPod. Link to comment
Castillo Posted June 14, 2011 Share Posted June 14, 2011 Well, I can't help you if don't post your code, also, you could also use setElementData and getElementData. Link to comment
dolmen62 Posted June 15, 2011 Author Share Posted June 15, 2011 View my code : 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" )) end addEventHandler("getTrain", getRootElement(), getTrain) Server side : function setTrain (theElement) 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 Link to comment
Castillo 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. 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