Puma Posted September 21, 2010 Share Posted September 21, 2010 Ohai, I'm doing a script in which I attach an object to a vehicle, created using createVehicle on position x, y, z. When I let the vehicle 'drive' to a new position using "setElementVelocity", the position (x, y, z) stays the same. Pretty weird, seen that the position of the vehicle itself DID change (I output the position right after it checks it, which happens to stay the same while the vehicle is driving away from me). Why am I doing this? I want to change position of a colshape that belongs to the vehicle. Since it isn't possible to attach colshapes to elements, I request the position and rotation of the vehicle every 50 ms. Problem is that the position of the colshape stays the same: where it was created. My script: -- SERVERSIDE -- -- SERVERSIDE -- -- SERVERSIDE -- function bindGreen ( p, green ) bindKey ( p, "lctrl", "down", shootGreen, green ) end function shootGreen ( p, a, b, green ) unbindKey ( p, "lctrl", "down", shootGreen ) local v = getPedOccupiedVehicle ( p ) local x, y, z = getElementPosition ( v ) local rx, ry, rz = getVehicleRotation ( v ) local greenV = createVehicle ( 441, x, y, z, rx, ry, rz ) local col = createColSphere ( x, y, z, 5 ) setElementData ( col, "green", green ) setElementData ( col, "greenV", greenV ) setElementData ( greenV, "col", col ) setElementData ( greenV, "green", green ) setElementData ( greenV, "gdist", 0 ) setElementData ( greenV, "gpos", {x, y, z} ) setElementData ( greenV, "rot", { rx, ry, rz } ) setElementData ( col, "source", v ) checkGreen ( p, col, green, greenV ) end function checkGreen ( p, col, green, greenV ) if isElement ( col ) and isElement ( green ) and isElement ( greenV ) then local x, y, z = getElementPosition ( greenV ) local rx, ry, rz = getVehicleRotation ( greenV ) setElementPosition ( col, x, y, z ) setElementRotation ( col, rx, ry, rz ) setElementData ( greenV, "greenHit", 0 ) driveGreen ( p, col, green, greenV ) end end function killShell ( col, greenV, green ) destroyElement ( green ) destroyElement ( greenV ) destroyElement ( col ) end function driveGreen ( p, col, green, greenV ) triggerClientEvent ( p, "onDriveGreen", greenV, p, col, green ) end function boostGreen ( p, col, green ) local v = source local rot = getElementData ( source, "rot" ) local rx = rot[1] local ry = rot[2] local rz = rot[3] setVehicleRotation ( source, rx, ry, rz ) local vx, vy, vz = getElementVelocity ( v ) setElementVelocity ( v, 0.5*math.sin(math.rad(360-rz)), 0.5*math.cos(math.rad(360-rz)), vz ) setTimer ( checkGreen, 50, 1, p, col, green, source ) end addEvent ( "onBoostGreen", true ) addEventHandler ( "onBoostGreen", getRootElement(), boostGreen ) -- CLIENTSIDE -- -- CLIENTSIDE -- -- CLIENTSIDE -- function driveGreen ( p, col, green ) triggerServerEvent ( "onBoostGreen", source, p, col, green ) end addEvent ( "onDriveGreen", true ) addEventHandler ( "onDriveGreen", getRootElement(), driveGreen ) There's a lot more in the functions, these are just the relevant parts. I bind a key, when it is pressed I create a vehicle and do some shit with it. The colshape changes position to the position of the created vehicle, a clientside event is triggered and then a serverside event is triggered, in which the created vehicle get's a boost. 50 ms later the whole process, from changing the position of the colshape, repeats untill a part of the script breaks it (I left that part out, because it isn't relevant). In short: local x, y, z = getElementPosition ( greenV ) setElementPosition ( col, x, y, z ) .. in "checkGreen" doesn't change the col's position. And yes, the elements that are checked do exist. So... whut should I do? Link to comment
MTA Team Blokker_1999 Posted September 21, 2010 MTA Team Share Posted September 21, 2010 i know waiting can be frustrating but give it some time, not everyone is checking thses forums all the time. Link to comment
Puma Posted September 21, 2010 Author Share Posted September 21, 2010 Okay this is weird: 00 0 0 0 0 0 0 0 0 0 21.911735534668 That's what is being output when I use this: function driveGreen ( p, col, green, greenV ) local x, y, z = getElementPosition ( greenV ) local oldPos = getElementData ( greenV, "gpos" ) local oldDist = getElementData ( greenV, "gdist" ) local newDist = getDistanceBetweenPoints3D ( x, y, z, oldPos[1], oldPos[2], oldPos[3] ) + oldDist outputChatBox ( newDist ) setElementData ( greenV, "gdist", newDist ) setElementData ( greenV, "gpos", {x, y, z} ) if newDist > 50 then killShell ( col, greenV, green ) else triggerClientEvent ( p, "onDriveGreen", greenV, p, col, green ) end end driveGreen is executed every 50 ms, and because the colshape doesn't change position I suddenly am 'in the colshape' and it kills me (other part of the script). Link to comment
Puma Posted September 21, 2010 Author Share Posted September 21, 2010 Ah, I know the problem: A vehicle that's created using createVehicle can't change position serverside without setElementPosition, since the server doesn't render the game and the game's physics: the moves of the vehicle are rendered clientside . Link to comment
dzek (varez) Posted September 21, 2010 Share Posted September 21, 2010 i don't get the idea of syncers, but i thought one of players should be syncer of the vehicle, so server should get its position.. but im not sure how it really works. in no players are around - you cant get its position for sure Link to comment
[M2S]moe Posted September 23, 2010 Share Posted September 23, 2010 Why dont you script around it? create a transparent marker attached to the vehicle, get its position, move colshape to it. Link to comment
Dark Dragon Posted September 23, 2010 Share Posted September 23, 2010 getting the position of vehicles which are not in syncer range of anyone shouldn't be a problem. Link to comment
dzek (varez) Posted September 23, 2010 Share Posted September 23, 2010 getting the position of vehicles which are not in syncer range of anyone shouldn't be a problem. yes, but setting the velocity on server when noone is around? server dont have psychics Link to comment
Puma Posted September 23, 2010 Author Share Posted September 23, 2010 When you create a vehicle and move it to x,y,z without a player sitting in it (so using setElementVelocity), the position of that vehicle does not change serverside, since the server doesn't render the game and its physics. Link to comment
dzek (varez) Posted September 23, 2010 Share Posted September 23, 2010 maybe try this: https://wiki.multitheftauto.com/wiki/Set ... Streamable set to false Link to comment
Puma Posted September 23, 2010 Author Share Posted September 23, 2010 I got it fixed a day ago already . Link to comment
Puma Posted September 23, 2010 Author Share Posted September 23, 2010 Well I use the player that shoots it as calculator: I trigger a clientside event, get the position and rotation and send that info back serverside by triggering a serverevent. 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