Jump to content

IIYAMA

Moderators
  • Posts

    6,089
  • Joined

  • Last visited

  • Days Won

    216

Everything posted by IIYAMA

  1. This code is executed every frame. I can see that you add some validation checks. But check the execution rate of the following code, if it is too high it will be a much bigger than not playing sounds: As for the not playing sound, you forgot to index the table: themes[math.random(#themes )]
  2. You can also use this useful function: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer Which does more or less the same as AfuSensi his example, after adding the source code.
  3. That question can only be answered if you know why the FPS is dropping. And there are multiple reasons for. A common reason: Execution time exceeds the frame time 1000 / 60 max fps = 16,66666666666667 = frame time local timeNow = getTickCount() for i=1, 10000 do end outputChatBox(getTickCount() - timeNow) -- execution time So even if your computer can run the game at 60 fps, if the execution time takes longer than the frame time the next frame has to wait longer and so your pc will render less frames each second. And how to optimise that? Well, making sure that this does not happen with the total execution time of all render events, as (not so) simple as that. By setting priority for 2 addEventHandlers that are attached to render events, 1 super high priority and 1 super low priority, you probably will be able to calculate the total execution time for that event. addEventHandler( "onClientRender", root, ..., false, "high+1000" ) addEventHandler( "onClientRender", root, ..., false, "low-1000" )
  4. You will also need to separate clientside from serverside. Red coloured functions are clientside. Orange coloured functions are serverside and blue can be used for both.
  5. Export functions must be a global, so that whole concept will probably not work. Here was a similar quest asked, with 2 possible solutions when you want to re-use the same function name.
  6. If that resource name is not allowed, then what is the resource name now?
  7. These brackets are used for hidden folders: [hidden folder] The resource name is the folder that contains DIRECTLY the meta.xml.
  8. @Argom These are more or less the basic components for a not moving image, which can be enhanced with a moving image later on. (order matters): https://wiki.multitheftauto.com/wiki/DxCreateTexture function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end <function start> https://wiki.multitheftauto.com/wiki/GetLocalPlayer https://wiki.multitheftauto.com/wiki/GetPedOccupiedVehicle https://wiki.multitheftauto.com/wiki/GetElementMatrix x1, y1, z1 = getPositionFromElementOffset(vehicle, 0, 0, 0) x2, y2, z2 = getPositionFromElementOffset(vehicle, 3, 0, 0) https://wiki.multitheftauto.com/wiki/DxDrawMaterialLine3D <function end> https://wiki.multitheftauto.com/wiki/OnClientPreRender
  9. If you want to create environments, OOP would be another way and maybe also use a meta table to inherit properties But I can understand that it might be a little bit complex, especially when you are doing it like this: showContentConstructor = { new = function (self) local newShowContent = {} setmetatable(newShowContent, self.metaTable) return newShowContent end, prototype = { -- initial properties text = "<please set text>", sayHI = function (self) return outputChatBox(self.text) end } } -- Set the meta table as lookup table when the information is not found in the instance table showContentConstructor.metaTable = {__index = showContentConstructor.prototype} -- create new instances showContent1 = showContentConstructor:new() showContent2 = showContentConstructor:new() showContent1:sayHI() showContent1.text = "test1" showContent1:sayHI() showContent2:sayHI() showContent2.text = "test2" showContent2:sayHI() Unfortunately there are no options without tables afaik, so you really need to be able to understand the basics of tables, if you want to build this. So I recommend doing it the way as in my previous reply, which should be easy to do.
  10. A function name is just a variable. When creating a function with the same name, you will overwrite that variable/function. You can solve your problem with a table. Main file: showContent = {} setTimer(function () -- add a little delay so that the function can be added before calling it. showContent[1]() showContent[2]() showContent[3]() end, 100, 1) For each other file: local fileID = --[[...]] showContent[fileID] = function () sayHI() end
  11. You can't give a player to another player. givePlayerMoney ( killer, source ) Some extra validation might be required, not only a player can kill another player. if ( killer ) and ( killer ~= source ) and getElementType(killer) == "player" and money > 0 then givePlayerMoney ( killer, money ) end
  12. If that is the case, then your code didn't wait for the 2 events per model (txd + dff). That is the moment you can apply the model, not a millisecond before that.
  13. Here: addEventHandler("onClientResourceStart", resourceRoot, function ( ) setTimer ( function ( ) refreshList ( ) local file = xmlLoadFile ( '@saving.xml', 'data' ) if file then for i, v in ipairs ( xmlNodeGetChildren( file ) ) do local name = tostring( xmlNodeGetAttribute( v, 'name' ) ) local enabled = toboolean( xmlNodeGetAttribute( v, 'enabled' ) ) if ( getModData(name) and tostring( enabled ):lower ( ) ~= "false" ) then --[[ here ]] end end end end, 500, 1 ) end ) (download + register the name) local immediatelyLoading = {} -- -- onClientResourceStart -- local _, _, dff, txd = getModData(name) dff = 'modlar/' .. dff txd = 'modlar/' .. txd -- set up status local loadingStatus = { value = 2, name = name, dff = dff, txd = txd } -- set up reference to status immediatelyLoading[dff] = loadingStatus immediatelyLoading[txd] = loadingStatus -- -- onClientFileDownloadComplete -- local loadingStatus = immediatelyLoading[file] local value = loadingStatus.value value = value - 1 loadingStatus.value = value if value == 0 then immediatelyLoading[loadingStatus.dff] = nil -- clear immediatelyLoading[loadingStatus.txd] = nil -- clear local name = immediatelyLoading.name -- load model end And also here: function onDownloadFinish (file, success) if ( source == resourceRoot ) then if ( success ) then refreshList() new("Your mod has been successfully downloaded ("..tostring(file)..")", 0, 255, 0) end end end addEventHandler ( "onClientFileDownloadComplete", getRootElement(), onDownloadFinish ) Using registration to load the mod immediately when both files are downloaded.
  14. Because the files haven't been validated. Use the downloadFile function again to validate if the correct files are placed on the client his pc. Note: If the correct file is found, no re-download will be starting. After the event onClientDownloadComplete, for dff and txd you can start the replacement process.
  15. dbQuery is used for retrieving information from the database. Even if you are only inserting data, there is still information returned about the success/failure state. dbPoll is used to collect that information (from the queryHandle). Since you didn't use that function on the queryHandle = the variable you named `zapisz` , there was no attempt to collect that information, so it was still waiting to be collected and therefore it gave you that warning. If you do not think you need that information, you can better use dbExec. That is just a one-way trip.
  16. Should be fine. As long as you do not over do it. Note: The position X and Y can also be used for the weather.
  17. There is also a useful function you can use. https://wiki.multitheftauto.com/wiki/CheckPassiveTimer Which represents DNL291's second way, but with it's own ecosystem.
  18. A combination. - hit events is for starting the timer. - The timer is used to check if everybody is inside of the colshape meets all the criteria. Like if everybody is still alive or inside of a vehicle. For a basic script, bandwidth is only used when a player hits or leaves a colshape. You do not have control over that, since it is always working even if you do not add eventHandlers. But keep in mind that if you use that timer to synchronize the same information over and over, sure that can be bad.
  19. Is freeroam start able? Since the stage resource wants these resources to be working before you can start it: freeroam realdriveby emerlights You can also delete this include xml tag from stage: <include resource="freeroam" /> Which allows you to start it, but first make sure freeroam can start since that is better idea.
  20. Cool When creating your vehicles you can link the ID to the vehicle in a few ways. Either by table: No synchronization server/client Across resources if you use exports. More maintenance (if a vehicle gets deleted) local linkVehiclesToDataBase = { element_to_ID = {}, ID_to_element = {} } function setVehicleByDataBaseID (ID, vehicle) linkVehiclesToDataBase.ID_to_element[ID] = vehicle return true end function getVehicleByDataBaseID (ID) return linkVehiclesToDataBase.ID_to_element[ID] end function setDataBaseIDByVehicle (vehicle, ID) linkVehiclesToDataBase.element_to_ID[vehicle] = ID return true end function getDataBaseIDByVehicle (vehicle) return linkVehiclesToDataBase.element_to_ID[vehicle] end --------- local ID = --... local vehicle = createVehicle(--[[...]]) setDataBaseIDByVehicle (vehicle, ID) -- enables: getDataBaseIDByVehicle (vehicle) setVehicleByDataBaseID (ID, vehicle) -- enables: getVehicleByDataBaseID (ID) Or by ID: setElementID ( vehicle, "vehicle-database-ID:" .. ID) https://wiki.multitheftauto.com/wiki/SetElementID Less maintenance Synchronization server/client Across resources Problem that can occur: Double ID's created by other resources or ID overwrite by other resources. + https://wiki.multitheftauto.com/wiki/GetElementID https://wiki.multitheftauto.com/wiki/GetElementByID
  21. You can loop through all vehicles and check if their plate is the same as the item in the database. But it is easier and more efficient to set an identifier when you create the vehicle. What is used as your database primary key per vehicle?
  22. I am not sure why you want to pass the plate into that function. But the function requires a player, not a plate. Basically this would give you the closest vehicle from the player that executed the event: local vehicle = getNearestVehicle( client ) But if you also want to pass the plate as well, sure that is also possible. Adding a second argument: local vehicle = getNearestVehicle( client, vehicleplate ) And adding second parameter: function getNearestVehicle( player, vehicleplate ) Note: If you do this, you will have to do something within this function with the plate, else it has no functionality.
  23. Did you actually select something from the list? (and is it still selected when you clicked the button?)
  24. So yes. Since you clicked on the button, which makes the button the source and not the gridlist. So that condition will never be true. Just change it to: if gridlist then -- or: if isElement(gridlist) then -- < if you do not trust anything Now you check if the gridlist is actually created. How does it feel to debug like this? Line for line until you know where and what the problem is.
×
×
  • Create New...