Jump to content

Cronoss

Members
  • Posts

    173
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Cronoss

  1. I modified the code a little bit and this how it looks now; function showSpeedoMeterFunction(player) if player == localPlayer then return end vehicle = getPedOccupiedVehicle(player) if getPedOccupiedVehicleSeat(player) == 0 or getPedOccupiedVehicleSeat(player) == 1 then showSpeedometer() ------add the render isSpeedoVisible=true if getPedOccupiedVehicleSeat(player) == 0 then timer = setTimer(function() ------this part it's because the fuel-system for the vehicle if getVehicleEngineState(vehicle)==true then -----if the engine it's on triggerServerEvent("chekG", localPlayer, localPlayer, vehicle) end end, 20000, 0) ---------the timer update the fuel every 20 seconds end end end addEventHandler("onClientVehicleEnter", root, showSpeedoMeterFunction) function hideSpeedoMeterFunction(player) if player == localPlayer then return end hideSpeedometer() ---- removes the render isSpeedoVisible=false if getPedOccupiedVehicleSeat(player)==0 then -----check if the player who left the vehicle was the driver killTimer(timer) --------kills the fuel-check timer end end addEventHandler("onClientVehicleStartExit", root, hideSpeedoMeterFunction) I want to know if this may be a problem. I'm using "onElementDataChange" for the fuel system detection in the drawImage; function checkDataFuel(Fuel, oldValue, newValue) if vehicle then if Fuel=="Fuel" then if tonumber(newValue) ~= tonumber(oldValue) then percentG = tonumber(newValue) ------- I convert the new value from "Fuel" data to a number iprint("changed to: "..percentG) end end end end addEventHandler("onClientElementDataChange", root, checkDataFuel) function getCarStateColor() --------this function it's called in the ("onclientrender") function local fuelVeh = percentG or 100 -------I use the "percentG" value in number to change the image on client render local engineON = getVehicleEngineState(vehicle) if (engineON==true) then local g = (255/100) * fuelVeh local r = 255 - g local b = 0 return r, g, b elseif not (fuelVeh) and (engineON==false) then return 0, 255, 0 else return 106, 106, 106 end end Why I'm using it like this way? I want to change the color of the image with the fuel data number, when the fuel start to decrease, the image starts to turn in red It is a good way to make what I want or I should change this? I didn't used getElementData because Burak told me it would be a bad idea, and I know it is. That's why I changed to "onElementDataChange", but I don't know if this is right
  2. I don't know what's wrong with this, I'm trying to cancel an animation with a timer: (server-side) function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) ------- this part works setTimer( function () setPedAnimation(player) ---------got nil / doesn't exist end, 1000, 1) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon) And the console keeps sending me the message "expected element, got nil", I tried this way: function changeWeapon(player) setPedAnimation(player, "colt45", "colt45_reload", 0, false, false, true, true) ------- this part works setTimer( function (player) -------* setPedAnimation(player) ----------still don't work end, 1000, 1) end addEvent("animCw", true) addEventHandler("animCw", root, changeWeapon)
  3. How do I change the local isSpeedoMeterVisible status? ?
  4. What it is exactly what you mean? are you using mysql? you should show us the code you need help for so people in the community can help you
  5. I made these functions because I want to avoid low fps and lag in my server, in my mind this was a great idea because "if I delete the handler from a "onClientRender" function I'm deleting unnecesary stuff" but I was thinking about it recently... and I have the question, is this system efficient or not? function hideSpeedometer() removeEventHandler("onClientRender", root, speedoMeterGUI) ----------------removes the eventhandler end function showSpeedometer() if not isEventHandlerAdded("onClientRender", root, speedoMeterGUI) then ----------if event handler it is not added then the function adds it addEventHandler("onClientRender", root, speedoMeterGUI) end end ---------------------------------------------- function A1(player) vehicle = getPedOccupiedVehicle(player) if getPedOccupiedVehicleSeat(player)==0 or getPedOccupiedVehicleSeat(player)==1 then showSpeedometer() -------call to create the handler end end addEventHandler("onClientVehicleEnter", root, A1) function A2() hideSpeedometer() -----call to remove the handler end addEventHandler("onClientVehicleStartExit", root, A2) I don't know if it is a good idea or I'm messing up the server with this, I need answers because I'm bad at optimizing
  6. I see that you want to randomize the money, I made this little example with "addCommandHandler", I tested it (I know this is not the way you want the script works but this is how I tested and It isn't showing any syntax error or something like that): -----------EXAMPLE 1-------------- (TABLE) moneyTable = {41244, 421, 1, 9876} ----A table in case you want specific "numbers" function moneyRandomizer(thePlayer, command) local money = (moneyTable[math.random(#moneyTable)]) -------- This is how I randomize the number inside the table givePlayerMoney(thePlayer, money) iprint("money: "..money) end addCommandHandler("plata", moneyRandomizer) ------------EXAMPLE 2------------ (WITHOUT TABLE) function moneyRandomizer(thePlayer, command) local money = math.random(190, 240) ----------------------This randomize between two values givePlayerMoney(thePlayer, money) iprint("money: "..money) end addCommandHandler("plata", moneyRandomizer) So in your table you should replace local money = math.random(money1, money2) ----- your code ----Replace it with: yourTable = {240, 260} local money = (yourTable[math.random(#yourTable)]) ------EXAMPLE 1 ----Or: local money = math.random(190, 240)--------EXAMPLE 2 Also, you made the local function money twice, maybe you should remove it
  7. Well, I'm trying to make two different GUI panels, one of them opens when the player is in "Jefferson" and types the command "buy", and the other one opens when the player is in "Rodeo". Inside this panels there is a gridlist that is using two different tables: vehCS = { {"Manana", 10000, 410}, } vehGT = { {"ZR-350",230000, 477}, } local distancePickup = 3 function detectPanel() local x,y,z = getElementPosition(localPlayer) local px1, py1, pz1 = 2131.8557128906,-1150.8621826172,24.111211776733 local px2, py2, pz2 = 562.91925048828,-1293.4617919922,17.248237609863 local gps = getZoneName(x,y,z) if (gps=="Jefferson") then if getDistanceBetweenPoints3D ( px1, py1, pz1, x,y,z) <= distancePickup then CScns() end else if getDistanceBetweenPoints3D ( px2, py2, pz2, x,y,z) <= distancePickup then GTcns() end end end addCommandHandler("buy", detectPanel) addCommandHandler("BUY", detectPanel) function CScns() screenW, screenH = guiGetScreenSize() showCursor(true) setElementFrozen(localPlayer, true) windowCS = guiCreateWindow(10, (screenH - 527) / 2, 330, 527,"Test1", false) guiWindowSetSizable(windowCS, false) list = guiCreateGridList(12, 28, 304, 437, false, windowCS) guiGridListAddColumn(list, "vehicle", 0.5) guiGridListAddColumn(list, "price", 0.5) for i=1,#vehCS do guiGridListAddRow(list, vehCS[i][1], vehCS[i][2]) end buybtn = guiCreateButton(30, 474, 120, 39, "buy", false, windowCS) guiSetProperty(buybtn, "NormalTextColour", "FF0AF415") closebtn = guiCreateButton(174, 474, 120, 39, "close", false, windowCS) guiSetProperty(closebtn, "NormalTextColour", "FFFE0000") addEventHandler("onClientGUIClick", list, verVehiculo, false) addEventHandler("onClientGUIDoubleClick", list, buyVehCS, false) addEventHandler("onClientGUIClick", buybtn, buyVehCS, false) addEventHandler("onClientGUIClick", closebtn, closeGUIcs, false) end function GTcns() screenW, screenH = guiGetScreenSize() showCursor(true) setElementFrozen(localPlayer, true) windowGT = guiCreateWindow(10, (screenH - 527) / 2, 330, 527,"Test2", false) guiWindowSetSizable(windowGT, false) listGT = guiCreateGridList(12, 28, 304, 437, false, windowGT) guiGridListAddColumn(listGT, "vehicle", 0.5) guiGridListAddColumn(listGT, "price", 0.5) for i=1,#vehGT do guiGridListAddRow(listGT, vehGT[i][1], vehGT[i][2]) end buybtn = guiCreateButton(30, 474, 120, 39, "Buy", false, windowGT) guiSetProperty(buybtn, "NormalTextColour", "FF0AF415") closebtn = guiCreateButton(174, 474, 120, 39, "Close", false, windowGT) guiSetProperty(closebtn, "NormalTextColour", "FFFE0000") addEventHandler("onClientGUIClick", listGT, watchVehicleGT, false) addEventHandler("onClientGUIDoubleClick", listaGT, buyVehicleGT, false) addEventHandler("onClientGUIClick", buybtn, buyVehicleGT, false) addEventHandler("onClientGUIClick", closebtn, closeGUIGT, false) end This is not efficient, isn't there a better way to make something like this? I don't want to clone every function that the GUI calls with a certain button or action
  8. Hey, I just have one more question because the wiki doesn't spicifies this or I didn't get the meaning of some words translated. If I set the data first in server-side from another resource I should use just "setElementData"? or also use "addElementDataSubscriber"? (Thanks for your patiente btw) function addFuelToPlayer(thePlayer) addElementDataSubscriber(source, "Fuel", thePlayer) iprint("addfuel") end addEventHandler("onVehicleEnter", getRootElement(), addFuelToPlayer) function removeFuelToPlayer(thePlayer) removeElementDataSubscriber(source, "Fuel", thePlayer) iprint("removefuel") end addEventHandler("onVehicleExit", getRootElement(), removeFuelToPlayer) --------------------------SERVER SIDE FROM ANOTHER FUNCTION------------------------------- vehicle = (createVehicle, 410, bla, bla, bla) vehicleGas = setElementData(vehicle, "Fuel", 100, "subscriber")--or setElementData(vehicle, "Fuel", 100), or addElementDataSubscriber
  9. And I'm guessing this is the most optimized way to make a system like this? I'm very worried about it and thank you so much for helping me
  10. I don't want to be annoying with this topic but I really want to learn and make my script the best as I can I want to make it in the right way I've been trying with this in server-side: function setG() veh = getPedOccupiedVehicle(source) stateG = getVehicleEngineState(veh) if (veh) then if (stateG==true) then plate = getVehiclePlateText(veh) x,y,z = getElementPosition(veh) fuelVeh = getElementData(veh, "Fuel") ---------setElementData is in another resource when the player buys the car (server-side) if (fuelVeh <= 0) then -----if the fuel it's 0 or less then the car engine turns off setVehicleEngineState(veh, false) setElementData(veh, "Fuel", 0) ----this fix some problems like "-0.023" numbers else setElementData(veh, "Fuel", fuelVeh) ------if the fuel it's above 0 then the fuel recieved it's saved (this is because of the next function) vehMove() -------This function it's called end end end end addEvent("chekG", true) addEventHandler("chekG", root, setG) ------------------------------------------------------------------------------------- function vehMove() ---vehicle movement local dx,dy,dz = x+0.05, y+0.05,z+0.05 local fuelConsumption = 0.900 if (fuelVeh) >= 1 then distance = getDistanceBetweenPoints3D(x,y,z,dx,dy,dz) newFuel = tonumber((fuelVeh - (fuelConsumption*distance))) iprint("Gas: "..newFuel) setElementData(veh, "Fuel", newFuel) else iprint("No fuel") end end And the client who calls the first function in server-side: setTimer(function() if (vehicle) then triggerServerEvent("chekG", localPlayer) end end, 10000, 0) ------------10 seconds before it repeats
  11. Update, I moved the "getElementData" thing into client-side, I just noticed that I should've just tell what I was trying to make instead of giving examples. I wanted to make a Fuel-System for vehicles, I moved all the getElementData and setElementData into client-side, and it works pretty good but I want to ask... using getElementData for a "on client render" function could cause problems? The function "onclientrender" changes the color of the fuel-icon so if the player starts to get less than 50% the icon starts to turning red, that's why I need to get the "fuel value"
  12. Sorry, I didn't respond; I understand the solution you made, and I appreciate it but in this case "the player's thing" it's a number that is constantly changing (decreasing) so if I want to save that I should use setElementData I guess, because if the player quits and join again the script should show the last "thing count", isn't there a way to display this info without involving server-side ?
  13. Thank you so much, I though that Client-side also could affect the other's player in some way, appreciate your time
  14. Answering this, the system I'm showing this time it's not for the vehicle "definitive" creation, it's just my method to show the player what vehicle it's selecting, confirm the creation doesn't work for me, because I need to show the player the vehicle at the moment he selects the row in the "carshop" panel In my opinion, limiting the player's time to select the next vehicle wouldn't look too good. I guess there is no way to optimize a system like this because i've been searching for something similar and nothing. I think that I need a new method to show the player the vehicle he is selecting but I can't figure out how to make it better
  15. My script requires to ask the data from the user; it's constantly changing. I'm guessing this might cause problems if a player starts to spam the command, that's not the problem, I know how to disable the command for a couple of seconds but my question is, how should I ask this info if I don't want to get low fps for the players? I know it doesn't make sence that I ask this kind of stuff because I said "I know how to disable the command for a couple of seconds" but I meant that I know how to make my system work (a system that I don't really like), but I maybe there is a way to make it work ten times better, that's why I'm posting this, I need to know how to make this without asking the element data every time... function example(thePlayer, cmd) local thingCheck = tonumber(getElementData(thePlayer, "thing")) --------get total "things" in player's data local thingCount = tostring(thingCheck) ---convert to string if (thingCheck>=1) then outputChatBox("You have "..thingCount.. " thing(s).", thePlayer, 255,255,255) -----display the info that the player want to know else outputChatBox("You don't have anything.", thePlayer, 255, 255, 255) end end addCommandHandler("mythings", example)
  16. I made a function for my "carshop system", basically the function spawns the car that the player select and then, if the player select another car from the list, the script delete the car and starts again. But I know that creating and deleting this element in client-side everytime the player clicks on a row from the gridlist would be bad for my server, so I want to know how could I optimize this as much as it's possible Client-Side function vehicleVisible() local row = guiGridListGetSelectedItem(list) ---------get the row from the gui gridlist iprint("1") if row~=-1 then -----------if row is not -1 destroyVehicleVisible() ----another function that destroys the element "vehicleVisibleForPlayer" local id = guiGridListGetItemText(list, row, 1) iprint("2") if id then iddef = getVehicleModelFromName(id) ----------get the vehicle id from the name iprint("ID: "..iddef) vehicleVisibleForPlayer = createVehicle(iddef, 2123.560546875,-1129.4521484375,25.453437805176) ----spawns the car iprint("Llego hasta acá") local rot = setElementRotation(vehicleVisibleForPlayer, -0, 0, 331.40734863281) end end end
  17. Sorry for coming back... I have a new question. Is it more efficient save the data with a "timer function" or save the data when the player leaves?
  18. Well, I'm trying to optimize my server as much as I can, so I wonder if this -> destroyElement() would help. In this case, I'm deleting the player's car every time he quit the game, but I don't know if this is a good method or maybe this would cause problems in the future, I just need to know if this system it's fine for the purpose I want or it's wrong, I would appreciate an answer The code (server-side): function hideVehicle() local owner = getPlayerName(source) local askVeh = exports.mysql:_Query("SELECT plate FROM vehicles WHERE owner=? LIMIT 3", owner) if (#askVeh>0) then for _,row in ipairs(askVeh) do for k,v in pairs(row) do plateAsked = tostring(v) break end for k,v in ipairs(getElementsByType("Vehicle")) do if (getVehiclePlateText(v)==plateAsked) then setTimer( function () destroyElement(v) end, 5000, 1) end end end end end addEventHandler("onPlayerQuit", getRootElement(), hideVehicle)
  19. If someone could help me, this is the code where i need to "display" multiple results: function saveInf() for i,vehicle in pairs(getElementsByType("vehicle")) do local x,y,z = getElementPosition(vehicle) local rx,ry,rz = getElementRotation(vehicle) local health = getElementHealth(vehicle) local engineState = getVehicleEngineState(vehicle) if (engineState==true) then engineSend = 1 else engineSend = 0 end local lock = isVehicleLocked(vehicle) if (lock==true) then lockSend = 1 else lockSend = 0 end local plate = getVehiclePlateText(vehicle) local model = getElementModel(vehicle) local owner = getPlayerName(source) local sendToSQL = exports.mysql:_Query("UPDATE vehicles SET x=?, y=?, z=?, rx=?, ry=?, rz=?, health=?, engine=?, locked=?, plate=?, model=? WHERE owner=?", x,y,z,rx,ry,rz,health,engineSend,lockSend,plate,model,owner) if (sendToSQL) then iprint("1") end end end addEventHandler("onPlayerQuit", getRootElement(), saveInf) I want to save the vehicles of the player but the problem is... if the player have more than one car, the system saves all the info from the last vehicle in all the rows, so when he log-in, two cars with the same info spawns in the location where the last car was used (2 cars if the player only spawned 2, if the spawned 3, 3 vehicles with the same info spawns)
  20. I figured out, no need for more answers, thank you
  21. I understand this part, but I also need the sql consult to verify if the player it's the owner of the vehicle, that's why I call it almost every 5 seconds in the script but I don't know how to verify the player only once
  22. But how could I display more rows then? I'm talking about something like this: for _,column in ipairs(tableCheck) do awesomethingRow1 = --------------------row 1, awesomething's first result awesomethingRow2 = --------------------row 2, awesomething's next result
×
×
  • Create New...