Zahl Posted October 1, 2009 Share Posted October 1, 2009 Hi there, since I have lots of race tracks on my server that use plenty of explosive barrels, there are a lot of desyncs happening, where player A can still see a barrel while player B can't, and if player B hits the barrel on player A's client, he will still explode, which causes a lot of confusion or frustration. Maybe some of you are familiar with this occurrence. So while I don't really know how to make it work like in the old race client, where the player only exploded if he hit the barrel in his own client, my idea now was to make the barrels respawn periodically. It should at least be less confusing. More precisely that means: - For every barrel, create another barrel which will be located at z + 2000 - Every X seconds, call a function that iterates through all barrels and if z > 1900 move it to z - 2000, otherwise move it to z + 2000 (all modifications happen in race_client.lua) So this would make each pair of barrels switch places. Since the barrel is out of reach when it is at z + 2000, it will be streamed out and is not visible anymore, so when it is moved back down on the second call to the function, it is visible again. I tried modifying the code in initRace() to something like this: -- objects g_Objects = {} local pos, rot, cnt = 0 -- use the cnt var to get a unique index for all objects for i,object in ipairs(objects) do pos = object.position rot = object.rotation cnt = cnt + 1 g_Objects[cnt] = createObject(object.model, pos[1], pos[2], pos[3], rot[1], rot[2], rot[3]) if object.model == 1225 then -- if the object was a barrel, create another one at (x, y, z + 2000) cnt = cnt + 1 g_Objects[cnt] = createObject(object.model, pos[1], pos[2], pos[3] + 2000, rot[1], rot[2], rot[3]) end end But this already fails... 1225 would be the explosive barrel, but the second set of barrels won't be created. My switching function looks like this: -- Reset all explosives function resetExplosives() allObjects = getElementsByType ( "object" ) --outputConsole( 'objects: ' .. tostring(#allObjects)) for i,obj in ipairs(allObjects) do local model = getElementModel(obj) if model == 1225 then local x,y,z = getElementPosition(obj) if (z < 1900) then setElementPosition(obj, x, y, z + 2000) else setElementPosition(obj, x, y, z - 2000) end end end end Which works perfectly, the only problem being that since there is no second set of barrels, the barrels will just appear and disappear all the time. The function gets called by a timer created in the onClientResourceStart event: g_ExplosiveResetTimer = setTimer(resetExplosives, 2000, 0) I must admit that I'm still very unfamiliar with MTA scripting and some parts of the race resource are totally unclear to me Hopefully someone can understand what I am trying to do and provide a little help. Link to comment
subenji99 Posted October 1, 2009 Share Posted October 1, 2009 The barrel desync has already been fixed for MTA 1.0.1, and it's release is just around the corner (the Roadmap is sitting at 100% at the time of this post) so it's probably not worth attempting a scripting workaround at this time. Having said that, I did find your error. compare: g_Objects[cnt] = createObject(object.model, pos[1], pos[2], pos[3] + 2000, rot[1], rot[2], rot[3]) if (z < 1900) then I think you'll see it now. Your barrel is being created, but you're swapping position with one -2000 z, which doesn't exist. You created your duplicate at +2000 z. Link to comment
Dark Dragon Posted October 1, 2009 Share Posted October 1, 2009 it's been fixed for 1.0.1 but nice effort Link to comment
Zahl Posted October 1, 2009 Author Share Posted October 1, 2009 if (z < 1900) then was meant to move the barrels up that are currently on the ground, the else-part was meant to move the barrels down that are currently at z + 2000... But well, if 1.0.1 is about to be released I sure can wait a few more days :) Link to comment
subenji99 Posted October 1, 2009 Share Posted October 1, 2009 Good point, I was at error. I actually have no idea why it doesn't work But it doesn't really matter at this point. 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