-Blaze- Posted July 3, 2015 Share Posted July 3, 2015 Hello , I am working on a mounted machine gun script , that places big guns on cars and a player is able to go on top and use it. I am using createObject for making a base_minigun and then using createWeapon to make a custom weapon and attaching them both with attachElements However these are all made clientside (since createWeapon is a clientside function) and are not visible and synced with all the players. when a player uses the mounted gun , he is able to rotate it and direct the line of fire, but the rotation of the weapon cannot be seen by all the players. Is there a way i can sync the client side created object and custom weapon so it is visible to all the players? My code so far : Server : addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() truck1 = createVehicle ( 470, 201.33500671387, 1908.2733154297, 17.640625 ,0,0,0, "Hex" ) setElementData( truck1, "mgtruck1", true) createBlipAttachedTo ( truck1, 0, 1) setTimer(triggerClientEvent, 500, 1, getRootElement(), "one", resourceRoot) end) i created the vehicle serverside because clientside vehicles aren't enterable. Client: function attachmgtotruckone() alltruck1 = getElementsByType ( "vehicle" ) for key, thetruck1 in ipairs ( alltruck1 ) do if getElementModel( thetruck1 ) == 470 then if getElementData(thetruck1, "mgtruck1" ) then local x, y, z = getElementPosition( thetruck1 ) local rx, ry, rz = getElementRotation( thetruck1 ) stand1 = createObject( 2985, x+2, y, z-1 ,rx,ry,rz+90) mountgun1 = createWeapon ( "minigun", 0, 0, 0 ) setElementAlpha( mountgun1, 50) attachElements( mountgun1, stand1, -0.2, 0 , 0.-- s8) --> attachElements( stand1, thetruck1, 0, 0, 0.6, 0, 0, 90) setElementCollisionsEnabled ( mountgun1, false ) setElementCollisionsEnabled ( stand1, false ) end end end end addEvent("one", true) addEventHandler("one", root, attachmgtotruckone) function moveup1() if isElement( stand1) then local thetruck1 = getElementAttachedTo ( stand1 ) if getElementData( localPlayer, "mg1controller") then if roty1 == 30 then return end attachElements( stand1, thetruck1, 0, 0, 0.6, 0, roty1+5, rotz1) roty1 = roty1+ 5 end end end function movedown1() if isElement( stand1) then local thetruck1 = getElementAttachedTo ( stand1 ) if getElementData( localPlayer, "mg1controller") then if roty1 == -30 then return end attachElements( stand1, thetruck1, 0, 0, 0.6, 0, roty1-5, rotz1) roty1 = roty1 - 5 end end end function moveleft1() if isElement( stand1) then local thetruck1 = getElementAttachedTo ( stand1 ) if getElementData( localPlayer, "mg1controller") then attachElements( stand1, thetruck1, 0, 0, 0.6, 0, roty1, rotz1+5) rotz1 = rotz1 + 5 end end end function moveright1() if isElement( stand1) then local thetruck1 = getElementAttachedTo ( stand1 ) if getElementData( localPlayer, "mg1controller") then attachElements( stand1, thetruck1, 0, 0, 0.6, 0, roty1, rotz1-5) rotz1 = rotz1 - 5 end end end bindKey("a", "down", moveleft1) bindKey("d", "down", moveright1) bindKey("s", "down", moveup1) bindKey("w", "down", movedown1) Link to comment
MTA Team botder Posted July 3, 2015 MTA Team Share Posted July 3, 2015 You need to send the rotation from your client to server and from your server to other clients. Link to comment
-Blaze- Posted July 4, 2015 Author Share Posted July 4, 2015 Can you give an example? 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