Jump to content

IIYAMA

Moderators
  • Posts

    6,058
  • Joined

  • Last visited

  • Days Won

    208

Everything posted by IIYAMA

  1. You are not finished in the slightest + a lot of edge cases to look at. The most significant optimisation will be applied when working with subscriber mode. This will stop sending element data to other players and only the ones that need it. On vehicle enter: addElementDataSubscriber(veh, "Fuel", thePlayer ) On vehicle exit: removeElementDataSubscriber(veh, "Fuel", thePlayer ) https://wiki.multitheftauto.com/wiki/AddElementDataSubscriber setElementData( veh, "Fuel", fuelVeh, "subscribe" ) https://wiki.multitheftauto.com/wiki/SetElementData
  2. Clientside Doing a live check: if isPedInVehicle(localPlayer) then Serverside Add some more local's etc. local veh = getPedOccupiedVehicle(source) local stateG = getVehicleEngineState(veh) And make use of arguments for the vehMove() function. vehMove(veh, fuelVeh, x, y, z) -- in > arguments ------------- function vehMove(veh, fuelVeh, x, y, z) -- out > parameters That way you make sure that the data stays within the functions. Adding a fallback for new vehicles (until there is data available from a database): local fuelVeh = getElementData(veh, "Fuel") or 0 -- or set to max This doesn't looks like a logic line, there is no value change so there is no need to set it: 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)
  3. local duration = 10000 function cinematic1() smoothMoveCamera(2444.0747070312, -1656.7917480469, 28.93049621582, 2526.1335449219, -1710.7858886719, 10.195858001709, 2489.0947265625, -1636.412109375, 30.221374511719, 2499.2856445312, -1728.2391357422, -8.0401239395142, 10000) setTimer(cinematic2, duration , 1) end function cinematic2() smoothMoveCamera(1726.8065185547, -1484.8432617188, 143.54656982422, 1670.5084228516, -1413.7943115234, 185.7670135498, 1535.7916259766, -1267.5806884766, 272.14398193359, 1474.7834472656, -1199.0876464844, 311.97747802734, 10000) setTimer(cinematic3, duration , 1) end function cinematic3() smoothMoveCamera(1338.3666992188, -1257.4116210938, 95.983924865723, 1352.1002197266, -1257.2800292969, -3.0684490203857, 1340.6787109375, -1498.6977539062, 95.983924865723, 1354.4122314453, -1498.5661621094, -3.0684490203857, 10000) setTimer(cinematic1, duration , 1) end setPlayerHudComponentVisible("all", false) cinematic1() -- start Try this.
  4. Clientside is located on the player their pc. When the game is not running, you are able to modify your downloaded files. Files which are defined by the server meta.xml are protected and will be validated (+reset if incorrect). But files created by Lua scripts are not. As long as it is not setElementData, it is fine. Building the fuel system fuel-value-management clientside is OK, but not great.
  5. Saving the data on the client is possible (cookie). The downside is of course that the player could modify or delete it. XML file: https://wiki.multitheftauto.com/wiki/Client_Scripting_Functions#XML_functions Regular file: https://wiki.multitheftauto.com/wiki/Client_Scripting_Functions#File_functions + any format or the usage of JSON Note: If something is decreasing in a linear way, the server can nearly precise compute what the value will be in the future. It just needs to know: The start time. The start value. How much it decrease every <time interval> When the player quits: -- local startTime = getTickCount() -- 1. local startValue = 50 -- 2. local usageEachSecond = 1 -- 3. -- -- time passes here... -- on quit local timeNow = getTickCount() local timePassed = timeNow - startTime local used = (timePassed / 1000) * usageEachSecond local endValue = startValue - used if endValue < 0 then endValue = 0 end
  6. In most cases not. (with an important exception: on clientside setElementData used on an element which is created by serverside)
  7. Then do the selection 100% clientside, that way you eliminate the connection delay and also not wasting network for other players. In your code I do not see serverside btw.
  8. Here is a useful function to add a rate limit (to user input): https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
  9. The way the items are stacked depends on the inventory system. Basic formule: -- generate some fake data local item = {name = "apple", quantity = 36} -- do the stacking local stackSize = 10 local itemCount = item.quantity -- 36 local stacksRawCount = itemCount / stackSize local stacksMaxCount = math.ceil(stacksRawCount) -- 4 local stacksMinCount = math.floor(stacksRawCount) -- 3 local remainingItems = itemCount % stackSize -- 6
  10. It is unwanted network information. > > > setElementData. (getElementData doesn't use network) Every layer of information, means that you have less data to spare for future resources that also use the network. The servertimesync resource uses getTickCount(which Mkl explains) to synchronize time between the client and the server. Now all you have to do is send future time to the client, which will sets it's counter to the right time. Untested example, feel free to optimise it even more. Server -- set when a new round starts (NOT every second) local timeNow = exports.servertimesync:getServerTime() if timeNow then setElementData(resourceRoot,"lobbyEndTime", timeNow + 60000) end Client local timeNow = exports.servertimesync:getServerTime() if timeNow then local lobbyEndTime = getElementData(resourceRoot,"lobbyEndTime") if lobbyEndTime then local remainingTime = (lobbyEndTime - timeNow) / 1000 if remainingTime < 0 then remainingTime = 0 end dxDrawText("Time : " ..math.floor(remainingTime), 300, 300 ) end end
  11. When the player leaves. But the downside is of that is the chance of data loss. (when the server crashes) Yet, that part should be considered more as a feature than a must in my opinion. The most logic timing is when the player leaves. For some data it is not an option to make use of the onPlayerQuit event timing, for example the data that is only stored at the client their PC shouldn't/couldn't be send over to the server when a player quits.
  12. @Rendet_ I have moved your topic to here: https://forum.multitheftauto.com/forum/149-looking-for-staff/ Please read the rules and formatting of this section:
  13. Yes, everytime getElementsByType is called, a new table with the current players is created.
  14. The player-list is dynamic, it does not seems to be a worth option for your user-case. It is only an option when the list is static, so no new players. -- function ( playerSource, commandName ) local playerList = getElementsByType ("player") for index, player in pairs(playerList) do if player ~= playerSource then end end -- end
  15. Just compare each player with the player you do not want. Filtering is only beneficial when you keep that table for a longer period of time/repeat usage. -- loop start if player ~= otherPlayer then end -- loop end
  16. My library can do that, if you really want to be able to do it that way.
  17. Yup, you can. local Highlight local HighlightConstructor do local register = {} -- depending were you want it. Highlight = { register = register } HighlightConstructor = { register = register } end function Highlight:new( element, style, color, flashSpeed, intensityOrThickness ) local register = self.register if register[element] then return end local data = { element = element, style = style, color = color, flashSpeed = flashSpeed, intensityOrThickness = intensityOrThickness } register[element] = data -- ... -- newHightlight = Highlight:new() iprint(Highlight.register) iprint(newHightlight.register)
  18. You were almost there, you are doing great The trick here is to split of the constructor. So that your new table will only inherit methods from the constructor. local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor local CREATED_HIGHLIGHTS = {} local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor function HighlightConstructor:destroy() iprint( self, 'destroy' ) end --[[ function HighlightConstructor:test() iprint( self ) end ]] function Highlight:new( element, style, color, flashSpeed, intensityOrThickness ) if not isElement( element ) then return false end if CREATED_HIGHLIGHTS[element] then return false end local data = { element = element, style = style, color = color, flashSpeed = flashSpeed, intensityOrThickness = intensityOrThickness } return setmetatable( data, { __index = HighlightConstructor } ) end newHightlight = Highlight:new() newHightlight:destroy() Note keep in mind there is a difference in . and : calls, depending on the set-up. Just in case you didn't know, which you probably did know. test = {} test.a = function (self) -- first parameter iprint(self) end test.a() function test:b () iprint(self) -- already available. end test:b()
  19. See useful function: https://wiki.multitheftauto.com/wiki/GetPointFromDistanceRotation
  20. clientside or serverside? Where did you transfer the file to clientside btw? If you are going to share things, for clientside and serverside, then make sure that both directories got the file.
  21. Are you sure you do not have defined a function called 'getPlayerSerial' somewhere else in the code? (other file for example)
  22. Meta table = gets inherited local Highlight = {test1 = true} local newTable = setmetatable({test2 = true}, {__index = Highlight}) The normal table = is inheriting from meta table local Highlight = {test1 = true} local newTable = setmetatable({test2 = true}, {__index = Highlight}) print("newTable:", newTable.test1, newTable.test2 ) -- newTable: true true print("Highlight:", Highlight.test1, Highlight.test2 ) -- Highlight: true nil This means that the 'new' method should only be applied on newTable. local Highlight = {test1 = true} function newChild (self) print("self", self) return setmetatable({}, {__index = Highlight}) end local newTable = setmetatable({test2 = true, new = newChild}, {__index = Highlight}) print(newTable:new()) print(newTable:new().test1) -- true print(newTable:new():new()) -- attempt to call a nil value (method 'new')
  23. Do you remember that after loading a string, you have to call it again? It basically means that there is a function around it. And every time you call that function, you run the code inside it. -- https://www.lua.org/pil/8.html f = loadstring("i = i + 1") i = 0 f(); print(i) --> 1 f(); print(i) --> 2 See docs: https://www.lua.org/pil/8.html So this is how it more or less looks like when loaded: function () Class = {} Class.__index = Class setmetatable(Class, {__call = function( _,... ) return Class.new(...) end }) function Class.new() local self = setmetatable({}, Class) return self end end So what you want to do: [[ local Class = {} Class.__index = Class setmetatable(Class, {__call = function( _,... ) return Class.new(...) end }) function Class.new() local self = setmetatable({}, Class) return self end return Class]] local Class = loadstring(createClass())()
  24. You named your own function the same as the MTA function. function fadeCamera() fadeCamera(source, true, 0.5, 0, 0, 0) end
×
×
  • Create New...