FiGo Posted April 13, 2021 Posted April 13, 2021 (edited) function setVelocity(player, command) local veh = getPedOccuipedVehicle(player) if (not veh or veh == nil or getPedOccuipedVehicleSeat(player) ~= 0 ) then return end if (command=="1") then setVehicleHandling(veh, "maxVelocity", 320) outputChatBox("Sport Mod Enabled", veh, 255, 255, 0, true) elseif (command=="2") then setVehicleHandling(veh, "maxVelocity", 180) outputChatBox("Business Mod Enabled", veh, 255, 255, 0, true) end end addCommandHandler("1", setVelocity) addCommandHandler("2", setVelocity) why it doesn't work Edited April 13, 2021 by FiGo
Erlkonig Posted April 13, 2021 Posted April 13, 2021 There no "getPedOccuipedVehicle", it should be "getPedOccupiedVehicle". Use /debugscript.
FiGo Posted April 13, 2021 Author Posted April 13, 2021 when i press 1 it should make the speed of the car to 320 and when i press 2 it should make the speed 180 but nothing work
Erlkonig Posted April 13, 2021 Posted April 13, 2021 1 minute ago, FiGo said: when i press 1 it should make the speed of the car to 320 and when i press 2 it should make the speed 180 but nothing work It works like you write it. Max Velocity it's maximum of velocity, not acceleration. For check your vehicle handling you can use something like this: addCommandHandler("gethandling", function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) local handling = getVehicleHandling(veh) outputChatBox("maxVelocity is "..handling.maxVelocity, thePlayer, 255, 255, 255, true) end) I guess you need "engineAcceleration". Just I never used that stuff.
FiGo Posted April 13, 2021 Author Posted April 13, 2021 okay i checked the max velocity and its 230 and what is next
Erlkonig Posted April 13, 2021 Posted April 13, 2021 2 minutes ago, FiGo said: okay i checked the max velocity and its 230 and what is next Can you please copy-paste the code here?
FiGo Posted April 13, 2021 Author Posted April 13, 2021 addCommandHandler("gethandling", function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) local handling = getVehicleHandling(veh) outputChatBox("maxVelocity is "..handling.maxVelocity, thePlayer, 255, 255, 255, true) end) -- Bullet -- (250km/h) function setVelocity(player, command) local veh = getPedOccuipedVehicle(player) if (not veh or veh == nil or getPedOccuipedVehicleSeat(player) ~= 0 ) then return end if (command=="1") then setVehicleHandling(veh, "maxVelocity", 230) outputChatBox("Sport Mod Enabled", veh, 255, 255, 0, true) elseif (command=="2") then setVehicleHandling(veh, "maxVelocity", 180) outputChatBox("Business Mod Enabled", veh, 255, 255, 0, true) end end addCommandHandler("1", setVelocity) addCommandHandler("2", setVelocity)
Erlkonig Posted April 13, 2021 Posted April 13, 2021 It will not work as I said earlier. Edit getPedOccuipedVehicle(player) to getPedOccupiedVehicle(player).
Erlkonig Posted April 13, 2021 Posted April 13, 2021 (edited) function setVehicleVelocity(player, command) local veh = getPedOccupiedVehicle(player) if (not veh or veh == nil or getPedOccupiedVehicleSeat(player) ~= 0 ) then return end if (command == "sportmod") then setVehicleHandling(veh, "maxVelocity", 320) outputChatBox("Sport Mod Enabled", player, 255, 255, 0, true) elseif (command == "business") then setVehicleHandling(veh, "maxVelocity", 180) outputChatBox("Business Mod Enabled", player, 255, 255, 0, true) end end addCommandHandler("sportmod", setVehicleVelocity) addCommandHandler("business", setVehicleVelocity) addCommandHandler("gethandling", function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) local handling = getVehicleHandling(veh) outputChatBox("maxVelocity is "..handling.maxVelocity, thePlayer, 255, 255, 255, true) end) Edited April 13, 2021 by Erlkonig
FiGo Posted April 13, 2021 Author Posted April 13, 2021 okay last thing can't i make the addCommandHandler with numbers
Erlkonig Posted April 13, 2021 Posted April 13, 2021 Just now, FiGo said: okay last thing can't i make the addCommandHandler with numbers What exactly do you want to do?
FiGo Posted April 13, 2021 Author Posted April 13, 2021 (edited) when i press 1 it auto changed to sport mod when i press 2 it changes to business Edited April 13, 2021 by FiGo
Erlkonig Posted April 13, 2021 Posted April 13, 2021 Just now, FiGo said: when i press 1 it auto changed to sport mod when i press 2 it changes to business https://wiki.multitheftauto.com/wiki/OnClientKey https://wiki.multitheftauto.com/wiki/TriggerServerEvent
Erlkonig Posted April 13, 2021 Posted April 13, 2021 (edited) 6 minutes ago, FiGo said: can't use please make it and thanks Try to do it yourself. If something will wrong, you can ask here about your issue. Edited April 13, 2021 by Erlkonig
FiGo Posted April 13, 2021 Author Posted April 13, 2021 (edited) function playerPressedKey(button, press) if (press) then -- Only output when they press it down --outputChatBox("You pressed the "..button.." key!") end end addEventHandler("onClientKey", root, playerPressedKey) addEventHandler( "onClientKey", root, function(button,press) if button == "1" then triggerServerEvent("sportmod", localPlayer) elseif button == "2" then triggerServerEvent("business", localPlayer) return true end return false end ) it says [2021-04-13 14:31:03] ERROR: Client (FiGo) triggered serverside event sportmod, but event is not added serverside anyone please Edited April 13, 2021 by FiGo
Erlkonig Posted April 13, 2021 Posted April 13, 2021 AddEvent on the serverside-script. addEvent("sportmod", true) addEvent("business", true) addEventHandel("sportmod", root, setVehicleVelocity(sportmod)) addEventHandel("business", root, setVehicleVelocity(business)) Of course you should to edit setVehicleVelocity function.
Erlkonig Posted April 13, 2021 Posted April 13, 2021 2 minutes ago, FiGo said: but when i press 1 and 2 it doesn't work Send here client & server side code. Please use "Insert Code Snippet". It's near the smile.
FiGo Posted April 13, 2021 Author Posted April 13, 2021 function playerPressedKey(button, press) if (press) then -- Only output when they press it down --outputChatBox("You pressed the "..button.." key!") end end addEventHandler("onClientKey", root, playerPressedKey) addEventHandler( "onClientKey", root, function(button,press) if button == "1" then triggerServerEvent("sportmod", localPlayer) elseif button == "2" then triggerServerEvent("business", localPlayer) return true end return false end ) function setVehicleVelocity(player, command) local veh = getPedOccupiedVehicle(player) if (not veh or veh == nil or getPedOccupiedVehicleSeat(player) ~= 0 ) then return end if (command == "sportmod") then setVehicleHandling(veh, "maxVelocity", 320) setVehicleHandling(veh, "engineAcceleration", 20) setVehicleHandling(veh, "driveType", "awd") setVehicleHandling(veh, "handlingFlags", 0x1008000) outputChatBox("Sport Mod Enabled", player, 255, 255, 0, true) elseif (command == "business") then setVehicleHandling(veh, "maxVelocity", 180) setVehicleHandling(veh, "engineAcceleration", 20) setVehicleHandling(veh, "driveType", "awd") setVehicleHandling(veh, "handlingFlags", 0x1008000) outputChatBox("Business Mod Enabled", player, 255, 255, 0, true) end end addCommandHandler("sportmod", setVehicleVelocity) addCommandHandler("business", setVehicleVelocity) addEvent("sportmod", true) addEvent("business", true) addEventHandel("sportmod", root, setVehicleVelocity(sportmod)) addEventHandel("business", root, setVehicleVelocity(business)) server side
Erlkonig Posted April 13, 2021 Posted April 13, 2021 -- YOUR CLIENT: addEventHandler( "onClientKey", root, function(button,press) if button == "1" then triggerServerEvent("sportmod", localPlayer) elseif button == "2" then triggerServerEvent("business", localPlayer) end end ) -- SERVER: function setVehicleVelocity(player, mode) local veh = getPedOccupiedVehicle(player) if (not veh) or getPedOccupiedVehicleSeat(player) ~= 0 ) then return end if (mode == "sportmod") then setVehicleHandling(veh, "maxVelocity", 320) setVehicleHandling(veh, "engineAcceleration", 20) setVehicleHandling(veh, "driveType", "awd") setVehicleHandling(veh, "handlingFlags", 0x1008000) outputChatBox("Sport Mod Enabled", player, 255, 255, 0, true) elseif (mode == "business") then setVehicleHandling(veh, "maxVelocity", 180) setVehicleHandling(veh, "engineAcceleration", 20) setVehicleHandling(veh, "driveType", "awd") setVehicleHandling(veh, "handlingFlags", 0x1008000) outputChatBox("Business Mod Enabled", player, 255, 255, 0, true) end end addCommandHandler("sportmod", setVehicleVelocity) addCommandHandler("business", setVehicleVelocity) addEvent("sportmod", true) addEvent("business", true) addEventHandel("sportmod", root, setVehicleVelocity("sportmod")) addEventHandel("business", root, setVehicleVelocity("business")) I am note sure but try this.
FiGo Posted April 13, 2021 Author Posted April 13, 2021 [2021-04-13 15:42:41] ERROR: Loading script failed: CITvehicles\server.lua:26: 'then' expected near ')'
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