Jump to content

Cronoss

Members
  • Posts

    173
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Cronoss

  1. I want to display more than one result (from mysql database) in a function because in my system the player can have more than one object saved, I need to display all the rows added. Example: (Data base view) row #1 = [id | car | color 3] row#2 = [id | car | color6] How it would look into .lua file local thingRequest = exports.mysql:_Query("SELECT awesomething FROM thingsTable WHERE owner=?", owner) if (#thingRequest>0) then local awesomethingText1 = --awesomething[1] (row #1) local awesomethingText2 = --awesomething[2] (row #2) if (awesomethingText1=="") then return else awesomeEvent() end if (awesomethingText2=="") then return else awesomeEvent() end
  2. I'm very worried about the optimization in my server and I was wondering how to test it. Also maybe some advices about stuff like this -> If in my script there is a value that gets the "ped ocuppied vehicle" but then I get the ped occupied vehicle again in another function, that would cause problems? How could I solve it if I want to be sure about the information of the player? First function: function toggleEngine(playerSource, cmd) local vehicle = getPedOccupiedVehicle(playerSource) if (vehicle) then Second function: function toggleLights(playerSource, cmd) local vehicle = getPedOccupiedVehicle(thePlayer) if (vehicle) then Also, calling the database in different functions would cause bad optimization / lag ? Example: function toggleLock(playerSource, cmd) ---------Toggle lock function local owner = tostring(getPlayerName(playerSource)) local vehicle = getNearestVehicle( playerSource, 5 ) or getPedOccupiedVehicle(playerSource) if (vehicle) then local nameplate = getVehiclePlateText( vehicle ) local ownerReq = exports.mysql:_Query("SELECT * FROM vehicles WHERE plate=?", nameplate) ------"First" time using the database to compare the plate if (ownerReq) then ----------Toggle engine function----------- local nameplate = getVehiclePlateText( vehicle ) local ownerReq = exports.mysql:_Query("SELECT * FROM vehicles WHERE plate=?", nameplate) --second time using the database in ANOTHER FUNCTION if (ownerReq) then if(#ownerReq > 0) then
  3. I understand the solution, but how I could make the "fuel" start to "decrease" if that event it's not added? edit: I mean the fuel-system, it starts to decrease when the player starts moving with the vehicle or/and the engine it's on
  4. How could i pass that parameter, triggering the server event in this? function refreshVehicle(fuelVeh) vehicle = getPedOccupiedVehicle(player) -----------trigger blabla end addEventHandler("onClientRender", root, refreshVehicle)
  5. Full client-side [1]: local smoothedRPMRotation = 0 local vehicleNos = nil local vehicleRPM = 0 -- 'main stats' function refreshVehicle() vehicle = getPedOccupiedVehicle(player) end addEventHandler("onClientRender", root, refreshVehicle) -- 'vehicle speed' function getVehicleSpeed() if (vehicle) then local vx, vy, vz = getElementVelocity(vehicle) if (vx) and (vy)and (vz) then return math.sqrt(vx^2 + vy^2 + vz^2) * 180 -- km/h else return 0 end else return 0 end end function getVehicleSpeedString() local speedString = math.floor(getVehicleSpeed() + 0.5) return string.format("%03d", speedString) end -- 'vehicle gear' function getVehicleGear() if (vehicle) then local vehicleGear = getVehicleCurrentGear(vehicle) return tonumber(vehicleGear) else return 0 end end function getFormattedVehicleGear() local gear = getVehicleGear() local rearString = "R" if (gear > 0) then return gear else return rearString end end -- 'vehicle rpm' function getVehicleRPM() if (vehicle) then if (isVehicleOnGround(vehicle)) then isVehicleInStunt = "false" if (getVehicleEngineState(vehicle) == true) then if(getVehicleGear() > 0) then vehicleRPM = math.floor(((getVehicleSpeed()/getVehicleGear())*180) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end else vehicleRPM = math.floor(((getVehicleSpeed()/1)*180) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end end else vehicleRPM = 0 end else isVehicleInStunt = "true" if (getVehicleEngineState(vehicle) == true) then vehicleRPM = vehicleRPM - 150 if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9800) then vehicleRPM = 9800 end else vehicleRPM = 0 end end return tonumber(vehicleRPM) else return 0 end end function getRPMRoation() if (getVehicleRPM()) and (getVehicleRPM() >= 0) then local rpmRotation = math.floor(((270/9800)* getVehicleRPM()) + 0.5) if (smoothedRPMRotation < rpmRotation) then smoothedRPMRotation = smoothedRPMRotation + 2 end if (smoothedRPMRotation > rpmRotation) then smoothedRPMRotation = smoothedRPMRotation - 2 end return tonumber(smoothedRPMRotation) else return 0 end end function getFormattedRpmRotation() local rpm = getRPMRoation() local rpm1 = rpm local rpm2 = rpm local rpm3 = rpm local rpm4 = rpm if (rpm1 >= 90) then rpm1 = 90 elseif (rpm1 < 0) then rpm1 = 0 end if (rpm2 >= 180) then rpm2 = 180 elseif (rpm2 < 0) then rpm2 = 0 end if (rpm3 >= 219) then rpm3 = 219 elseif (rpm3 < 0) then rpm3 = 0 end if (rpm4 >= 360) then rpm4 = 360 elseif (rpm4 < 0) then rpm4 = 0 end return rpm1, rpm2, rpm3, rpm4 end function getCarStateColor(fuelVeh) triggerServerEvent("verGasolina", localPlayer) if (fuelVeh) then local g = (255/100.0000) * fuelVeh local r = 255 - g local b = 0 return r, g, b else return 0, 255, 0 end end function getNitroStateColor() local nitro = getVehicleUpgradeOnSlot(vehicle, 8) if (nitro > 0) then return 0, 255, 0 else return 75, 75, 75 end end Full client-side [2] (HUD): local screenWidth, screenHeight = guiGetScreenSize() -- 'Textures' local speedometerBG = "textures/speedometerBG.png" local speedometerBG2 = "textures/speedometerBG2.png" local speedometerNeedleWhite = "textures/speedometerNeedleWhite.png" local speedometerNeedleRed = "textures/speedometerNeedleRed.png" local speedometerOverlay = "textures/speedometerOverlay.png" local speedometerGlass = "textures/speedometerGlass.png" local carState = "textures/carState.png" local nitroState ="textures/nitroState.png" -- 'fonts' fontPrototype10 = dxCreateFont("fonts/Prototype.ttf", 10) fontPrototype40 = dxCreateFont("fonts/Prototype.ttf", 40) fontLCD22 = dxCreateFont("fonts/lcd.ttf", 22) function speedoMeterGUI() if (vehicle) then local rpm1, rpm2, rpm3, rpm4 = getFormattedRpmRotation() -- 'Speedometer' dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerBG) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerNeedleRed, rpm4) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerNeedleWhite, rpm3) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerNeedleWhite, rpm2) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerNeedleWhite, rpm1) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerBG2) dxDrawText(getFormattedVehicleGear(), screenWidth - 160, screenHeight - 170, screenWidth - 160, screenHeight - 170, tocolor(255, 255, 255, 255), 1, fontPrototype40, "left", "top", false, false, false) dxDrawText("OOO", screenWidth - 160, screenHeight - 115, screenWidth - 160, screenHeight - 115, tocolor(25, 25, 25, 255), 1, fontLCD22, "left", "top", false, false, false) dxDrawText("***", screenWidth - 160, screenHeight - 115, screenWidth - 160, screenHeight - 115, tocolor(25, 25, 25, 255), 1, fontLCD22, "left", "top", false, false, false) dxDrawText(getVehicleSpeedString(), screenWidth - 160, screenHeight - 115, screenWidth - 160, screenHeight - 115, tocolor(255, 255, 255, 255), 1, fontLCD22, "left", "top", false, false, false) dxDrawText("km/h", screenWidth - 110, screenHeight - 95, screenWidth - 110, screenHeight - 95, tocolor(255, 255, 255, 255), 1, fontPrototype10, "left", "top", false, false, false) local nsr, nsg, nsb = getNitroStateColor() dxDrawImage(screenWidth - 108, screenHeight - 155, 24, 24, nitroState, 0, 0, 0, tocolor(nsr, nsg, nsb, 255), true) local csr, csg, csb = getCarStateColor() dxDrawImage(screenWidth - 108, screenHeight - 125, 24, 24, carState, 0, 0, 0, tocolor(csr, csg, csb , 255), true) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerOverlay) dxDrawImage(roundValue(screenWidth - 270), roundValue(screenHeight - 270), 200, 200, speedometerGlass) end end addEventHandler("onClientRender", root, speedoMeterGUI) Function (in server-side): function checkGas() veh = getPedOccupiedVehicle(source) x,y,z = getElementPosition(veh) if (veh) then local plate = getVehiclePlateText(veh) local consulta = exports.mysql:_Query("SELECT * FROM vehicles WHERE plate=?", plate) if (consulta) then if (#consulta>0) then for _,column in ipairs(consulta) do ownerGet = tostring(column["owner"]) keyOW = tostring(column["keyOW"]) break end end end local check = exports.mysql:_Query("SELECT * FROM vehicles WHERE owner=? AND keyOW=?", ownerGet,keyOW) if (check) then if(#check > 0) then for _,column in ipairs(check) do fuelVeh = (column["fuelofcar"]) ---------The "fuelveh" gets the table value representing the fuel of the vehicle motor = tonumber(column["motor"]) break end end end if (fuelVeh <= 0) then --------works, if fuelVeh 0 or less, then the vehicle turn off setVehicleEngineState(veh, false) mot = 0 ------new value to update local sendF = exports.mysql:_Query("UPDATE vehicles SET motor=? WHERE owner=? AND keyOW=?",mot,ownerGet,keyOW) end vehMove() --------function end end addEvent("verGasolina", true) addEventHandler("verGasolina", root, checkGas, fuelVeh) function vehMove() local fx,fy,fz = x+0.5, y+0.5,z+0.5 local fuelConsumption = 0.005 if (veh) then if (fuelVeh) then distance = getDistanceBetweenPoints3D(x,y,z,fx,fy,fz) enginePlus = 0 if getVehicleEngineState(veh) then enginePlus = 0.08 end local newFuel = (fuelVeh - (fuelConsumption*(distance+enginePlus))) local sendFuel = exports.mysql:_Query("UPDATE vehicles SET gasolina=? WHERE owner=? AND keyOW=?",newFuel,ownerGet,keyOW) else if (fuelVeh) then ---I think I messed up here fuelNew = (fuelVeh) else fuelVeh = 100 end end end end Edit = I added the hud part
  6. It worked And, sorry if this is too much, but I want to ask, what's the problem here? function getCarStateColor(fuelVeh) triggerServerEvent("verGasolina", localPlayer) if (fuelVeh) then local g = (255/1000) * fuelVeh local r = 255 - g local b = 0 return r, g, b else return 0, 255, 0 end end I want to change the color of a icon with the fuelVeh value... I mean, if the fuel it's to low then the icon will turn "red", but it doesn't work properly. (The fuel system works, it turn off the veh if the fuel it's 0 all it's fine, that's why I think the problem it's in the function and not into the fuel-check system)
  7. It says "Expected ped at argument 1, got root"
  8. The end of the "fuelcheck" in server side: addEvent("verGasolina", true) addEventHandler("verGasolina", root, checkGas, fuelVeh) The call in client-side: function getCarStateColor(fuelVeh) triggerServerEvent("verGasolina", root) if (fuelVeh) then local g = (255/1000) * health local r = 255 - g local b = 0 return r, g, b else return 0, 255, 0 end end
  9. Exactly the console says "line 2, line 3", basically that part function checkGas() veh = getPedOccupiedVehicle(player) --------nil value, expected element x,y,z = getElementPosition(veh) -----------error, because "veh" now it's a boolean after that part, it is just sql requests and validation of "fuel": function checkGas() veh = getPedOccupiedVehicle(player) x,y,z = getElementPosition(veh) if (veh) then local plate = getVehiclePlateText(veh) local consulta = exports.mysql:_Query("SELECT * FROM vehicles WHERE plate=?", plate) if (consulta) then if (#consulta>0) then for _,column in ipairs(consulta) do ownerGet = tostring(column["owner"]) keyOW = tostring(column["keyOW"]) break end end end local flcheck = exports.mysql:_Query("SELECT * FROM vehicles WHERE owner=? AND keyOW=?", ownerGet,keyOW) if (flcheck) then if(#flcheck > 0) then for _,column in ipairs(flcheck) do fuelVeh = tonumber(column["fuelCar"]) engineVeh = tonumber(column["engineCar"]) break end end end
  10. I'm trying to connect a "fuel-check" system to a speedometer resource. I know I'm doing something wrong but I can't understand how to get the "vehicle" without using "getPedOccupiedVehicle"... <- I noticed that this is already called in client-side (this is not my resource) I don't know if that's the problem but well, here is the code: First "getPedOccupiedVehicle" (client-side): function refreshVehicle() vehicle = getPedOccupiedVehicle(player) end addEventHandler("onClientRender", root, refreshVehicle) "getOccupiedVehicle" in server-side Event(check fuel system) function checkGas() veh = getPedOccupiedVehicle(player) x,y,z = getElementPosition(veh) if (veh) then Client-side triggering the checkGas function: function getCarStateColor() triggerServerEvent("verGasolina", root) if (fuelVeh) then local g = (255/1000) * health local r = 255 - g local b = 0 return r, g, b else return 0, 255, 0 end end
  11. I'm trying to make a gearbox system; I was testing "setElementSpeed",I used all the parameters needed, but still don't work for some reason, the console and debugscript2 don't send me any error, I put a "iprint" and it prints in the console, so the function "velocittt" runs... here it's the full code: function getElementSpeed(theElement, unit) assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") local elementType = getElementType(theElement) assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")") assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) return (Vector3(getElementVelocity(theElement)) * mult).length end function setElementSpeed(element, unit, speed) local unit = unit or 0 local speed = tonumber(speed) or 0 local acSpeed = getElementSpeed(element, unit) if acSpeed and acSpeed~=0 then local diff = speed/acSpeed if diff ~= diff then return false end local x, y, z = getElementVelocity(element) return setElementVelocity(element, x*diff, y*diff, z*diff) end return false end function velocittt(thePlayer, cmd) local veh = getPedOccupiedVehicle(thePlayer) local speed1set = setElementSpeed(veh, "km/h", 10) ------Doesn't work end addCommandHandler("vel", velocittt)
  12. Still sounding for everybody, just if this helps to resolve my problem, this is what it looks like the first part of the code: function lockcar(thePlayer, cmd) local owner = tostring(getPlayerName(thePlayer)) local vehicle = getNearestVehicle( thePlayer, 5 ) or getPedOccupiedVehicle(thePlayer) if (vehicle) then ----------------bla
  13. i tried with that, and the other players can't hear the sound, i want them to hear, but in a specific range
  14. I don't get what's wrong with this, I want to attach the playsound3d to the "source player" who executed the command, I don't want to attach the sound to EVERYBODY. But for some reason it keeps giving me an annoying bug; when the player execute the command, the sound plays, but the "localPlayer" in client-side take everybody as the "source player" and every player hears the sound in max volume, I don't want this, I want to make the sound have range of audition Event trigger in server side: triggerClientEvent(root, "playBLQ", thePlayer) Function in client-side: function snbl() local x, y, z = getElementPosition(localPlayer) -------The problem it's here, I tried using a outputchatbox with "localPlayer" and the text shows for everybody local bloqueo = playSound3D("blq.mp3", x, y, z, false) setSoundMaxDistance(bloqueo, 20) end addEvent("playBLQ", true) addEventHandler("playBLQ", root, snbl)
  15. Hello again, I'm having a problem to understand how the tables work... I want to get ALL players inside a vehicle and get their health but I don't know how to make the table select every player and get their different healths This is function vhDam(loss) local playersLossHP = getVehicleOccupants(source) local setLossToPlayers = getElementHealth(#playersLossHP) --------- how could I get every player's health? ---------------blablabla end addEventHandler("onVehicleDamage", root, vhDam)
  16. Just tested it with another person and it works, thank you so much! But then, this table solution it's dynamic? I'm not too good for some english concepts, I just want to know if this add "new players" in the list, because I don't think that this command should keep static information... I'm sorry if you already explained it, I don't get some words
  17. That loop should be before or after "for i,v in ipairs (playersAround) do"? Because I'm trying everything I can think and still can see the message I want to keep the table for a long period of time, because it will be a frequently command used in the server, so yes, this kind of solution would help. local jugadores = getElementsByType ("player") if (player~=thePlayer) then ----also tried with "(jugadores ~=thePlayer, source, sourcePlayer...)
  18. I tried to translate the code to english and I missed that part, the table "jugadores" (now called playersAround) contains all the players, and yes, I know the "table.remove" need two parameters, but I don't know how to make the table ignores the source player (player who started the function) (fixed) local playersAround = getElementsByType ("player") local x, y, z = getElementPosition (thePlayer)) for i,v in ipairs (playersAround) do table.remove(playersAround, ?) -----don't know what to add here, I tried with "source, sourcePlayer, thePlayer, player" but it don't work as i want local x2, y2, z2 = getElementPosition (v) if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanceofmsj then if getElementDimension (thePlayer) == getElementDimension (v) then outputChatBox ("testeo", v, 21, 208, 24) end end I tried with table.remove(playersAround, ........ source,sourceplayer,theplayer,player,i), nothing seems to work... well, it works but it removes the other players and not the source player, so I get the "inverse" result that I want
  19. I want to show a specific message to players near to the "source player", but when I get "elements by type ("player"), it takes all the players, including the one it's executing the command, but i don't want to show the message like that, just for the players around... I've been trying to remove the sourceplayer from the table but nothing seems to work ----- local playersAround = getElementsByType ("player") local x, y, z = getElementPosition (thePlayer)) for i,v in ipairs (jugadores) do table.remove(jugadores, ?) -----don't know what to add here, I tried with "source, sourcePlayer, thePlayer, player" but it don't work as i want local x2, y2, z2 = getElementPosition (v) if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanceofmsj then if getElementDimension (thePlayer) == getElementDimension (v) then outputChatBox ("testeo", v, 21, 208, 24) end end
  20. It worked, thank you again Burak!
  21. Well, I'm trying to make something like this; if the owner locked his vehicle, then he CAN'T get out of the car. The problem with this is that when I use "cancelEvent()" for it, the script also stops the event for "car jack", so if another player tries to steal a locked car with the owner inside, the server doesn't show the "try to enter in a vehicle" animation and the car-lock system stops working correctly Code in server side: function blockExit() local playerInside = getVehicleOccupant(source) -------I added this recently, because I want to figure out how to make only the player inside get the "cancel event" and not the player outside the vehicle if(isVehicleLocked(source)) then -----if veh locked cancelEvent() ----cancels the event but it also cancels the carjack animation and gets me an annoying bug end end addEventHandler("onVehicleStartExit", getRootElement(), blockExit)
  22. I saw some servers that allow the player to make animations while the player walks, moves, or run, that's why I'm wondering, it is another way to make animations? something like "custom" animations? ?
×
×
  • Create New...