Hadif Posted September 16, 2015 Share Posted September 16, 2015 (edited) Hello, anyone knows how to replace vehicle model in race game-mode when the race map start? There's a event when the race game-mode map start called onMapStarting (source: https://wiki.multitheftauto.com/wiki/Resource:Race). So, how do I start? Edited September 20, 2015 by Guest Link to comment
JR10 Posted September 16, 2015 Share Posted September 16, 2015 addEvent('onMapStarting') addEventHandler('onMapStarting', root, function() for index, vehicle in pairs(getElementsByType('vehicle')) do setElementModel(vehicle, 411) end end) Link to comment
Hadif Posted September 16, 2015 Author Share Posted September 16, 2015 addEvent('onMapStarting') addEventHandler('onMapStarting', root, function() for index, vehicle in pairs(getElementsByType('vehicle')) do setElementModel(vehicle, 411) end end) What a genius! Thank you so much, ill try it asap. Link to comment
Hadif Posted September 19, 2015 Author Share Posted September 19, 2015 addEvent('onMapStarting') addEventHandler('onMapStarting', root, function() for index, vehicle in pairs(getElementsByType('vehicle')) do setElementModel(vehicle, 411) end end) Not working bro, I have made a new one but i got an error: addEventHandler("onResourceStart", getRootElement(), function() setPlayerVehicle(startedResource) end ) function setPlayerVehicle(startedResource) -- gamemodes="race" type="map" local gamemodes = getResourceInfo(startedResource, "gamemodes") local types = getResourceInfo(startedResource, "type") if (gamemodes == "race") and (types == "map") then for index, vehicle in pairs(getElementsByType("vehicle")) do setElementModel(vehicle, 409) end end end Link to comment
JR10 Posted September 19, 2015 Share Posted September 19, 2015 startedResource is not defined in the handler. You need to add it as a parameter. addEventHandler("onResourceStart", getRootElement(), function(startedResource) Link to comment
Hadif Posted September 20, 2015 Author Share Posted September 20, 2015 startedResource is not defined in the handler. You need to add it as a parameter. addEventHandler("onResourceStart", getRootElement(), function(startedResource) No error but not working , I think I have to research how's race gamemode works. Link to comment
Hadif Posted September 20, 2015 Author Share Posted September 20, 2015 I think this should work, but.. addEvent("onRaceStateChanging") addEventHandler("onRaceStateChanging", getRootElement(), function(newState, oldState) if (newState == "GridCountdown") then addEventHandler("onPlayerVehicleEnter", getRootElement(), setPlayerVehicle()) end end ) function setPlayerVehicle(player) local vehicle = getPedOccupiedVehicle(player) if getElementModel(vehicle) then setElementModel(vehicle, 400) -- Test outputChatBox("setPlayerVehicle") end end I get an error, 11: Bad Argument @ 'getPedOccupiedVehicle' [expected ped at argument 1, got nil] 12: Bad Argument @ 'getElementModel' [expected element at argument 1, got boolean] 5: Bad Argument @ 'addEventHandler' [expected function at argument 3, got none] Link to comment
HUNGRY:3 Posted September 20, 2015 Share Posted September 20, 2015 (edited) addEvent("onRaceStateChanging",true) addEventHandler("onRaceStateChanging", getRootElement(), function(newState, oldState) if (newState == "GridCountdown") then addEventHandler("onPlayerVehicleEnter", getRootElement(), setPlayerVehicle) -- don't add () end end ) function setPlayerVehicle(player) local vehicle = getPedOccupiedVehicle(player) if isPedInVehicle(player) then -- check if ped in vehicle if getElementModel(vehicle) then setElementModel(vehicle, 400) -- Test outputChatBox("setPlayerVehicle",player,255,0,0) end end end idk but should work Edited September 20, 2015 by Guest Link to comment
Hadif Posted September 20, 2015 Author Share Posted September 20, 2015 addEvent("onRaceStateChanging",true) addEventHandler("onRaceStateChanging", getRootElement(), function(newState, oldState) if (newState == "GridCountdown") then addEventHandler("onPlayerVehicleEnter", getRootElement(), setPlayerVehicle) -- don't add () end end ) function setPlayerVehicle(player) local vehicle = getPedOccupiedVehicle(player) if isPedInVehicle(player) then -- check if ped in vehicle if getElementModel(vehicle) then setElementModel(vehicle, 400) -- Test outputChatBox("setPlayerVehicle") end end end idk but should work Not working 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