glowdemon1 Posted September 1, 2013 Posted September 1, 2013 Hi, I haven't noticed a command that allows you to pause your script for a second, I'm basicly creating a vehicle, but then I NEED to implement something that it waits 1 second after that, after that one second it does setElementFrozen. function bikeShop() lowriderBike = createVehicle(509, 698.6, -521.20, 16,0,0,90) os.sleep(1) -- ??? setElementFrozen(lowriderBike, true) end
glowdemon1 Posted September 1, 2013 Author Posted September 1, 2013 setTimer Yeah, I was thinking of something easier, more compact that only requires one line, like wait() or sleep(). Well anyhow I dedicated a new function to this timer and it works now,but I was hoping there would be a more compact thing.
50p Posted September 1, 2013 Posted September 1, 2013 There are coroutines but they are more complex than timers.
glowdemon1 Posted September 1, 2013 Author Posted September 1, 2013 Mh, well I've struck on yet another problem, whenever I try to lock certain vehicles upon spawning, it just doesn't lock them, here's teh code : function freezeElements() setElementFrozen(lowriderBike,true) setElementFrozen(bmxBike, true) setElementFrozen(mountainbikeBike,true) end function bikeShop() lowriderBike = createVehicle(509, 698.6, -521.20, 16,0,0,225) setVehicleLocked(lowriderBike, true) bmxBike = createVehicle(481, 695.6, -521.20, 16,0,0,225) setVehicleLocked(bmxBike,true) mountainbikeBike = createVehicle(510, 692.6, -521.20, 16,0,0,225) setVehicleLocked(mountainbikeBike,true) end setTimer(freezeElements,90,1) addEventHandler("onResourceStart", getRootElement(), bikeShop) Its kind of messy indeed, but I'm not the best coder, heh.
glowdemon1 Posted September 1, 2013 Author Posted September 1, 2013 Alright so, aparently : notLockableVehicles = {594, 606, 607, 611, 584, 608, 435, 450, 591, 539, 441, 464, 501, 465, 564, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 581, 509, 481, 462, 521, 463, 510, 522, 461, 448, 468, 586, 425, 520} I guess I'll have to make it so that the script restarts each couple of minutes, would while true do setTimer(bikeShop,900000,1)-- executes bikeShop once each fifteen minutes end work ?
BieHDC Posted September 1, 2013 Posted September 1, 2013 Try this: edit: is this serverside? if its serverside you can prevent entering the vehicle with OnVehicleStartEnter and CancelEvent "https://wiki.multitheftauto.com/wiki/OnVehicleStartEnter" function bikeShop() lowriderBike = createVehicle(509, 698.6, -521.20, 16,0,0,225) setElementFrozen(lowriderBike,true) bmxBike = createVehicle(481, 695.6, -521.20, 16,0,0,225) setElementFrozen(bmxBike, true) mountainbikeBike = createVehicle(510, 692.6, -521.20, 16,0,0,225) setElementFrozen(mountainbikeBike,true) end addEventHandler("onResourceStart", getRootElement(), bikeShop)
glowdemon1 Posted September 1, 2013 Author Posted September 1, 2013 Alright, I'll try that. But would the scrip I said work ? I need reload the bikeshop every 15 minutes
BieHDC Posted September 1, 2013 Posted September 1, 2013 why the bikeshop schould reload every 15 min?
glowdemon1 Posted September 1, 2013 Author Posted September 1, 2013 Incase anything gets bugged, rather take some precauting stuff.
csiguusz Posted September 1, 2013 Posted September 1, 2013 while true do setTimer(bikeShop,900000,1)-- executes bikeShop once each fifteen minutes end work ? No, it won't work, it doesn't mean what you tought it means. For infinite repetitions use 0 as the last argument.
Moderators IIYAMA Posted September 1, 2013 Moderators Posted September 1, 2013 I guess I'll have to make it so that the script restarts each couple of minutes, would while true do setTimer(bikeShop,900000,1)-- executes bikeShop once each fifteen minutes end work ? Lol lol lol, how many timers are you willing to make? local vehicleShopTable = {} local shopResetTimer -- functions -- local shopResetFunction --------------- addEventHandler("onResourceStart",resourceRoot, function () vehicleShopTable[#vehicleShopTable+1] = createVehicle(509, 698.6, -521.20, 16,0,0,225) vehicleShopTable[#vehicleShopTable+1] = createVehicle(481, 695.6, -521.20, 16,0,0,225) vehicleShopTable[#vehicleShopTable+1] = createVehicle(510, 692.6, -521.20, 16,0,0,225) shopResetTimer = setTimer (shopResetFunction ,900000,0) end) shopResetFunction = function () for i=1, #vehicleShopTable do respawnVehicle ( vehicleShopTable[i] ) end end
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