DzMG-LV Posted March 14, 2016 Share Posted March 14, 2016 So i use carwash script, but when i drive to wash it, it doesn't clean the car. Anyone can help? I've got this error Bad argument @ 'getPlayerOccupiedVehicle' [Expected ped at argument 1, got vehicle] Client: local myShader = dxCreateShader("texture.fx") addEventHandler("onClientElementDataChange", root, function (dataName) if (getElementType(source) == "vehicle") and (dataName == "Cleaned") then engineApplyShaderToWorldTexture(myShader, "vehiclegrunge256", source) engineApplyShaderToWorldTexture(myShader, "?emap*", source) end end) addEventHandler("onClientElementDataChange", root, function (dataName) for _, vehicle in ipairs(getElementsByType("vehicle")) do if (getElementData(vehicle, "Cleaned") then engineApplyShaderToWorldTexture(myShader, "vehiclegrunge256", vehicle) engineApplyShaderToWorldTexture(myShader, "?emap*", vehicle) end end end) Server: local x,y,z = 1911.2, -1776, 12 local Marker = createMarker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function (hitPlayer, matchingDimension) local theVehicle = getPlayerOccupiedVehicle(hitPlayer) if (theVehicle) then setElementData(source, "Cleaned", true) fadeCamera(source, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, source, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", source, 0, 255, 255) end end) addEventHandler("onMarkerLeave", Marker, function () moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Link to comment
Captain Cody Posted March 14, 2016 Share Posted March 14, 2016 OnMarkerHit is finding the vehicle that hit it not the player, Try this addEventHandler("onMarkerHit", Marker, function (hitPlayer, matchingDimension) if getElementType(hitPlayer) == "player" and matchingDimension then local theVehicle = getPlayerOccupiedVehicle(hitPlayer) if (theVehicle) then setElementData(theVehicle, "Cleaned", true) fadeCamera(hitPlayer, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, hitPlayer, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Welcome to the car wash.", hitPlayer, 0, 255, 255) end end) Or you can use this addEventHandler("onMarkerHit", Marker, function (hitElement, matchingDimension) if getElementType(hitElement) == "vehicle" and matchingDimension then local driver = getVehicleOccupant ( hitElement) if (driver) then setElementData(hitElement, "Cleaned", true) fadeCamera(driver , false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, driver , true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Welcome to the car wash.", driver , 0, 255, 255) end end) Link to comment
DzMG-LV Posted March 14, 2016 Author Share Posted March 14, 2016 Now it's show text and fade camera, but the car still is not clean after cleaning. Link to comment
Dimos7 Posted March 14, 2016 Share Posted March 14, 2016 local x, y, z = 1911.2, -1776, 12 local Marker = createMaker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function(hitPlayer, matchingDimension) if isElement(hitPlayer) and getElementType(hitPlayer) == "player" then local theVehicle = getPedOccupiedVehicle(hitPlayer) if (theVehicle) then setElementData(source, "Cleaned", true) fadeCamera(source, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, source, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", source, 0, 255, 255) end end end) addEventHandler("onMarkerLeave", Marker, function () moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Link to comment
DzMG-LV Posted March 14, 2016 Author Share Posted March 14, 2016 local x, y, z = 1911.2, -1776, 12 local Marker = createMaker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function(hitPlayer, matchingDimension) if isElement(hitPlayer) and getElementType(hitPlayer) == "player" then local theVehicle = getPedOccupiedVehicle(hitPlayer) if (theVehicle) then setElementData(source, "Cleaned", true) fadeCamera(source, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, source, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", source, 0, 255, 255) end end end) addEventHandler("onMarkerLeave", Marker, function () moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Doesn't work, now marker doesnt appear Link to comment
Dimos7 Posted March 14, 2016 Share Posted March 14, 2016 local x, y, z = 1911.2, -1776, 12 local Marker = createMaker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function(hitElement, matchingDimension) if isElement(hitElement) and getElementType(hitElement) == "player" then local theVehicle = getPedOccupiedVehicle(hitElement) if (theVehicle) then setElementData(hitElement, "Cleaned", true) fadeCamera(hitElement, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, hitElement, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", hitElement, 0, 255, 255) end end end) addEventHandler("onMarkerLeave", Marker, function () moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Link to comment
Tox Posted March 14, 2016 Share Posted March 14, 2016 you have to set setElementData function's last argument to true to sync with client setElementData (vehicle, "Cleaned", true, true) though i support using triggerClientEvent, i guess you can solve your problem with that Link to comment
Moderators Citizen Posted March 14, 2016 Moderators Share Posted March 14, 2016 You were actually cleaning the player instead of the vehicle, becarefull with what stores your variables: client: local myShader = dxCreateShader("texture.fx") addEventHandler("onClientElementDataChange", root, function (dataName) if getElementType(source) == "vehicle" and dataName == "Cleaned" then local newValue = getElementData(source, dataName) -- DEBUG output below, to be removed when done with tests: outputChatBox("[DEBUG]'Cleaned' element data changed: "..tostring(newValue)) -- Check here if newValue is true to remove the shader and false to apply it ? engineApplyShaderToWorldTexture(myShader, "vehiclegrunge256", source) engineApplyShaderToWorldTexture(myShader, "?emap*", source) end end) server: local x,y,z = 1911.2, -1776, 12 local Marker = createMarker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function (hitPlayer) if getElementType(hitPlayer) ~= "player" or getPedOccupiedSeat(hitPlayer) ~= 0 then return end local theVehicle = getPedOccupiedVehicle(hitPlayer) if theVehicle then setElementData(theVehicle, "Cleaned", true) fadeCamera(hitPlayer, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, hitPlayer, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", hitPlayer, 0, 255, 255) end end) addEventHandler("onMarkerLeave", Marker, function (hitplayer) if getElementType(hitPlayer) ~= "player" or getPedOccupiedSeat(hitPlayer) ~= 0 then return end moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Just for your information, when driving a vehicle into a marker, onMarkerHit will be called 2 (or more times): 1 for the vehicle itself, and at the very same time, 1 per passenger (driver included). If a vehicle with 4 players inside (1 driver and 3 passengers) your function for onMarkerHit will be called 5 times (1 time for the vehicle, another time for the driver, and again for each passenger). That's why I'm also cancelling the function if the hitPlayer is not the driver (a passenger or someone on foot). @Dimos7: Thank you for trying to help but for me you don't have the skill yet to be able to answer with a good solution on this forum. You are introducing bugs, breaking things that were already working (like breaking the marker creation ... Seriously how did you remove the 'r' in 'creationMaker', it's 'creationMarker'. @Tox: If you have read the wiki, you would have seen that by default the synchronize argument is already true, so it wasn't the problem and is useless to specify true again. Best regards, Citizen Link to comment
DzMG-LV Posted March 14, 2016 Author Share Posted March 14, 2016 You were actually cleaning the player instead of the vehicle, becarefull with what stores your variables:client: local myShader = dxCreateShader("texture.fx") addEventHandler("onClientElementDataChange", root, function (dataName) if getElementType(source) == "vehicle" and dataName == "Cleaned" then local newValue = getElementData(source, dataName) -- DEBUG output below, to be removed when done with tests: outputChatBox("[DEBUG]'Cleaned' element data changed: "..tostring(newValue)) -- Check here if newValue is true to remove the shader and false to apply it ? engineApplyShaderToWorldTexture(myShader, "vehiclegrunge256", source) engineApplyShaderToWorldTexture(myShader, "?emap*", source) end end) server: local x,y,z = 1911.2, -1776, 12 local Marker = createMarker(x, y, z, "cylinder", 5, 255, 0, 0, 150) local gate = createObject(968, 1915.5, -1771.80, 13, 0, -90) local gate1 = createObject(968, 1915.5, -1780.85, 16, 0, -90) addEventHandler("onMarkerHit", Marker, function (hitPlayer) if getElementType(hitPlayer) ~= "player" or getPedOccupiedSeat(hitPlayer) ~= 0 then return end local theVehicle = getPedOccupiedVehicle(hitPlayer) if theVehicle then setElementData(theVehicle, "Cleaned", true) fadeCamera(hitPlayer, false, 2.5, 0, 0, 0) setTimer(fadeCamera, 2500, 1, hitPlayer, true, 2.5) moveObject(gate, 9000, 1915.5, -1771.80, 16) moveObject(gate1, 2000, 1915.5, -1780.85, 13) outputChatBox("Your Welcome in car wash", hitPlayer, 0, 255, 255) end end) addEventHandler("onMarkerLeave", Marker, function (hitplayer) if getElementType(hitPlayer) ~= "player" or getPedOccupiedSeat(hitPlayer) ~= 0 then return end moveObject(gate, 2000, 1915.5, -1771.80, 13) moveObject(gate1, 9000, 1915.5, -1780.85, 16) end) Just for your information, when driving a vehicle into a marker, onMarkerHit will be called 2 (or more times): 1 for the vehicle itself, and at the very same time, 1 per passenger (driver included). If a vehicle with 4 players inside (1 driver and 3 passengers) your function for onMarkerHit will be called 5 times (1 time for the vehicle, another time for the driver, and again for each passenger). That's why I'm also cancelling the function if the hitPlayer is not the driver (a passenger or someone on foot). @Dimos7: Thank you for trying to help but for me you don't have the skill yet to be able to answer with a good solution on this forum. You are introducing bugs, breaking things that were already working (like breaking the marker creation ... Seriously how did you remove the 'r' in 'creationMaker', it's 'creationMarker'. @Tox: If you have read the wiki, you would have seen that by default the synchronize argument is already true, so it wasn't the problem and is useless to specify true again. Best regards, Citizen Thanks a lot 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