Jump to content

IIYAMA

Moderators
  • Posts

    6,074
  • Joined

  • Last visited

  • Days Won

    211

Everything posted by IIYAMA

  1. A coroutine is a kind of thread type, which you can use to put a function to a temporary stop. The coroutine.create method requires a function and returns the coroutine. local co co = coroutine.create(function () end) The coroutine.yield method stops the thread, when it is called inside of the function. local co co = coroutine.create(function () coroutine.yield() end) To start a coroutine you can must call the method coroutine.resume, the first argument has to be the coroutine. local co co = coroutine.create(function () print("A") coroutine.yield() print("B") end) coroutine.resume(co) -- print A -- but does NOT print B To resume the coroutine after yield, just call coroutine.resume again. local co co = coroutine.create(function () coroutine.yield() print("B") end) coroutine.resume(co) -- start -- coroutine.yield() coroutine.resume(co) -- print B Add an async function of any kind (timer) and you are ready to go. local co co = coroutine.create(function () print("A") coroutine.yield() print("B") end) coroutine.resume(co) -- print A setTimer(function () coroutine.resume(co) -- print B end, 5000, 1)
  2. You could start with first making sure it works without database. Instead you save it inside of the memory. Unlike elementdata which is bound to an element, this will stay until the resource is stopped. local serialData = {} function setPlayerSerialData(player, value) serialData[getPlayerSerial(player)] = value return true end function getPlayerSerialData(player) return serialData[getPlayerSerial(player)] end -- SET setPlayerSerialData(player, perfectname) -- GET local perfectname = getPlayerSerialData(player) print(perfectname)
  3. Is everything clear or do you have any questions? @Dzsozi (h03)
  4. Use a database (and manager resource). There are some community resources out there that can help you with that. For example this one (which is not official released on the community resource since I am still building on it, but never the less feel free to use it. https://gitlab.com/IIYAMA12/asyncdatabase Read the readme Modify the config and set to SQLite Check the examples Others: https://community.multitheftauto.com/index.php?p=resources&s=details&id=17541 https://community.multitheftauto.com/index.php?p=resources&s=details&id=6313 Search query: https://community.multitheftauto.com/index.php?p=resources&s=list&name=data&descr=&category=
  5. There is a limit code can run for X amount of time each frame. If exceed this amount, the code will abort and you will receive this error. You can use a coroutine in order to temporary stop your code and resume in the next frame. local co co = coroutine.create(function () -- your code START ---------------------- -- inner loop START -- -- if getTickCount > ... then callNextFrame(function () coroutine.resume(co) end) coroutine.yield() -- -- inner loop END -- ---------------------- -- code END end) -- start coroutine.resume(co) Calling next frame: https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/blob/master/sync/sync_shared.lua#L421 (note there are some variables that are defined above the function)
  6. Thx @Shady1 P.s. I made some last tweaks for installation script. It seems it for some unknown reason didn't always create a meta.xml file for the API credentials.
  7. Serverinfo This resource is a small API for MTA server info, which you can modify / expand to your liking. It is many used to display information about the current state if the server. Like for example how many players are playing. Read the installation carefully, because you certainly do not want to put your admin login credentials online. ? Note: before you even download this resource, test if your web interface is even available. Start your server. Open a web browser and fill in your (local) IP and standard port. If it ask for a username and password, it looks like it is OK. If not, something doesn't seems to be correct. !Server hosts that are based on slots, might have disabled the exposure of the web interface. <ip>:<port> Endpoint: <ip>:<port>/<resourceName>/api/<endpointName>.json Local ip and standard port: http://127.0.0.1:22005 Analytics http://127.0.0.1:22005/serverinfo/api/analytics.json Team info http://127.0.0.1:22005/serverinfo/api/teamList.json Chat history http://127.0.0.1:22005/serverinfo/api/chat.json Generic info http://127.0.0.1:22005/serverinfo/api/info.json Player info http://127.0.0.1:22005/serverinfo/api/playerList.json Download: https://community.multitheftauto.com/?p=resources&s=details&id=18781
  8. Try this play ground of mine. Should be working, if not it might be a hardware or setting issue. do --[[ Capture content here ]] local renderTarget addEventHandler( "onClientResourceStart", resourceRoot, function() renderTarget = dxCreateRenderTarget( 500, 500, true ) end ) function captureContent( callBack ) if not renderTarget then return false end dxSetRenderTarget( renderTarget, true ) callBack() -- captureContent( >>> function() end <<< ) dxSetRenderTarget() return renderTarget end end do --[[ Cache renderTargets for static content ]] local cache = {} function cacheRenderTarget( key, renderTarget ) local pixels = dxGetTexturePixels( renderTarget ) if not pixels then return false end cache[key] = dxCreateTexture( pixels ) return true end function getTextureFromCache( key ) if cache[key] then iprint( 'from cache' ) end return cache[key] end end addEventHandler( "onClientRender", root, function() -- When updating content local dynamicTexture = captureContent( function() local size = getTickCount() % 501 dxDrawRectangle( 0, 0, size, size, tocolor( 0, 0, 100, 100 ) ) dxDrawText( "abcdefghi dynamic" .. getTickCount(), 10, 0, 500, 500, tocolor( 255, 255, 255 ), 1, "default", "left", "top", false, false, false, false, true ) dxDrawText( "abcdefghi dynamic" .. getTickCount(), 10, 20, 500, 500, tocolor( 255, 255, 255 ), 2, "default", "left", "top", false, false, false, false, true ) end ) if dynamicTexture then dxDrawImage( 0, 500, 500, 500, dynamicTexture ) end -- When just drawing static stuff local staticTexture = getTextureFromCache( 'static' ) if not staticTexture then staticTexture = captureContent( function() dxDrawRectangle( 0, 0, 500, 500, tocolor( 0, 0, 100, 100 ) ) dxDrawText( "abcdefghi static (not so sharp)", 10, 0, 500, 500, tocolor( 255, 255, 255 ), 1, "default", "left", "top", false, false, false, false, true ) dxDrawText( "abcdefghi static (not so sharp)", 10, 20, 500, 500, tocolor( 255, 255, 255 ), 2, "default", "left", "top", false, false, false, false, true ) end ) if staticTexture then cacheRenderTarget( 'static', staticTexture ) end end if staticTexture then dxDrawImage( 500, 500, 500, 500, staticTexture ) end end )
  9. Can you create a smaller version of your current resource, so that we can take a closer look at your problem? (small size is important because we can focus mainly on the problem) Just looking at your current code is a very inefficient method in finding a bug. Best to let the computer do the work for us.
  10. Keep in mind that the capture process starts at the left-top of the screen. posx = (sX/2)-(x1/2) dxText ( core, posx+2, posy-max*scrolling, rtW, rtH, tocolor ( 255, 255, 255, 255 ), z2*0.90,font,"left","top",true, true, false,false, true) It might not be captured. local rtW, rtH = dxGetMaterialSize(texture) You already know the size of the render target, no need to compute.
  11. string.sub(string.gsub("abcdefg69hijklmn7opqrs0tuvw71xyz72", "[^%d]", ""), 1, 4) -- 6970 With string.sub you can make a selection of characters. Arguments: The string Start index: 1 End index: 4 https://www.tutorialspoint.com/string-sub-function-in-lua
  12. You can for example replace all non numeric characters with empty strings. string.gsub("abcdefg69hijklmn7opqrs0tuvw71xyz72", "[^%d]", "") --[[ Returns 2 values: Result: 69707172 Items replaced (with empty string): 26 ]]
  13. A different technique: Guard Clauses You might want to read this, to get a better understanding of the technique. The result is more or less the same, except there are some differences with the returned values. In your function it doesn't matter, but there are functions where it does matter a lot.
  14. First of all, it important to understand there is serverside and there is clientside. Serverside is running on the server application, or just call it the server. This is where all players connect to in order to player the game together. MTA San Andreas 1.5\server\MTA Server.exe Here are server functions available. Clientside in running on each game application. It is literally the MTA game. MTA San Andreas 1.5\Multi Theft Auto.exe Keep in mind that there can multiple clientsides. For each connected player there is a clientside. The data between those clientsides is not shared. Here are client functions available. The reason why some function are not available on the other side is many because of security restrictions. You do not want to grant all players the rights to be able to ban each other, only the server should be able to ban a player. And some functions are just not so useful at the other side, like drawing an image just 1 frame on your screen. Imagine having server doing that every frame, your internet will just die.
  15. That looks fine. Next up, write the following in both situations to the serverlog. Collect them from the logs and place them here, so that we can compare the input from both situations. outputServerLog(inspect({freeID, login, vehID, positionVeh, vehcolor, cost, 1000, "TRANZIT", handlings, doors, panels, wheels, lights})) Code should be placed directly before the dbExec function call.
  16. local nameveh, cost = getVehicleDataFromTable( vehID ) Does this function accepts strings or numbers? Because addCommandHandler will provide the vehID as a string. local nameveh, cost = getVehicleDataFromTable( tonumber(vehID) ) if not nameveh then return end Please use the code tag for your code, or many forum users will not even attempt to look at your problem
  17. @Wozi I have moved your topic to tutorials, so that it is better preserved and easier to find. Good luck with your project!
  18. MTA useful functions do not exist unless they are added. See Code and expand the blue box 'Server- and/or clientside Script', there you can find the source code for that function. In that case I only recommend to post on your own language section. It saves some time for both of us. ?
  19. Checkout this useful function: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
  20. setPedStat ( thePlayer, 24, 1000 ) -- increase upper limit to max setElementHealth ( thePlayer, 200 ) -- fill to upper limit >> or spawn the player
  21. Sounds like a synchronous data query, which is writing/reading a lot of data all at once. The real reason 'why' is with the developer...
  22. IIYAMA

    mysql error

    Default value is used to fill in specific columns when you have no value provided for them. Normally the default value is null, when nothing is provided. Solutions: https://stackoverflow.com/questions/41077044/mysql-can-not-insert-because-no-default-value
  23. IIYAMA

    Pairs Loop

    First of all it is important to understand that tables(arrays) in Lua do not start at index 0, they start at index 1. The pairs function does not always loop in order. (unreliable for looping in order) The ipairs function does, but does not start at 0, it just skips it. So if you want a loop starting at 0, the basic for loop is the best option to be honest.
  24. https://wiki.multitheftauto.com/wiki/GetElementSpeed This useful function returns 1 speed value (based on x, y, z) What I explained is how the useful function works and how you can change it more or less from 3D(x,y,z) to 2D(x,y).
×
×
  • Create New...