Sorata_Kanda

Members
  • Content Count

    76
  • Joined

  • Last visited

Community Reputation

6 Neutral

About Sorata_Kanda

  • Rank
    Transformer

Recent Profile Visitors

225 profile views
  1. Sorata_Kanda

    [HELP] How to sync the sound for all players?

    You could create a server event that includes a loop where it triggers a client event playing the sound file for each player.
  2. Sorata_Kanda

    Best practice to synchronize server/client caches

    I'm not sure if it's really worth the resources to block events from being called multiple times simultaneously as I don't think that there's a high chance 25 people are locking/unlocking the same house at the same time. I thought about having the serversided cache updated mainly, e. g. someone unlocks house -> set "locked" to false in house object in server table and in a certain interval, the changed table is pushed to MySQL database.
  3. Sorata_Kanda

    module question

    @JeViCo Take this wiki page as a reference. You can just include/loadup it into your server and just use the functions like any other function in mta. E.g. if you defined foo_bar() in your module, then you can simply use foo_bar(). However, do remember that .dll can be only used by Windows binaries. For Linux, you have to use .so files
  4. Sorata_Kanda

    Best practice to synchronize server/client caches

    Let's imagine this: I go into a pickup and want to have a GUI to appear. Following implementation: -- Is it good to pass in the element in order to keep the reference to the house object? local pickup = --Pickup element local owner = -- Owner string local rent = -- random int addEventHandler('onPickupHit', resourceRoot, function() triggerClientEvent(source, 'showGUI', pickup, owner, rent) -- Notice that pickup is used as source element end) My problem is that somehow I need to keep the reference as I want to e.g. enter the house or lock it. That means I need to trigger a server event, passing that element again. I'm not sure if this is reliable or not. Possible implementation --- Client - Used in GUI triggerServerEvent('enterHouse', localPlayer, source) -- source equals pickup that was set as source element in the implementation above --- Server -- A table where each house object that was instantiated is being kept track with pickup elements as a reference houses = { pickup1 = House(...), pickup2 = House(...) } -- Table keeping track of booleans for each event in order to realize "synchronized" state (like Java) blocked_exec = { "lockHouse" = false } addEventHandler('lockHouse', resourceRoot, function(pickupElement) while (blocked_exec["lockHouse"]) do end -- In case this event is currently handled by someone else, keep in loop until finished blocked_exec["lockHouse"] = true -- Block execution until finished (possible concurrency problem/race condition?) local houseObject = houses[pickupElement] houseObject:setLocked(not houseObject:isLocked()) blocked_exec["lockHouse"] = false end) Got any feedback on this concept?
  5. Sorata_Kanda

    Best practice to synchronize server/client caches

    So it should be better to just use one server-sided cache and i. e. if I unlock a door of a house through GUI, I'm better off using TriggerServerEvent? As I use OOP for creating house objects, I'm worried about how to display house details properly in a GUI if the house object isn't exisiting on the client-side and element data is async. Is there something like a keyword (synchronized in Java) in Lua? Or do I have use a boolean to set the event execution to be blocked until the previous execution is finished?
  6. Hello everyone, as you probably know, some people suggest that it makes sense to use element data without having them synchronized. With that being said, I try to script a resource which uses OOP and in order to e. g. make changes through GUI, I need to push objects through events to client, then modify specific attributes that have been changed through GUI, and afterwards send that object back to the server and save it in a table. I'm wondering if you should have both server and client caches or just have a server-sided cache and push the affected objects through events. What is an efficient way to handle caches? Thanks in advance!
  7. Sorata_Kanda

    module question

    I'm quite not sure, but shouldn't you be able to just use your methods? Also, I think you can add 'require' permissions to your resource via ACL.
  8. Sorata_Kanda

    How to check if argument is empty?

    if argument then end represents if argument ~= nil then end If you'd like to check if it's nil: if not argument then -- Do something end -- or if argument == nil then -- Do something end EDIT: It doesn't matter which of the two methods you choose. As far as I know, the common code style uses if not element then -- Do something end -- etc.
  9. Sorata_Kanda

    Creating global/native functions

    But how were all the functions ported to all LuaVMs? They must have been defined in the source code. So I suspect that you could manage to provide your own functions natively by creating modules.
  10. Sorata_Kanda

    Advertisments PROBLEM !

    Because this looks like the query you sent to your MySQL database doesn't return your values. Did you look up in the debug log files of /debugdb? Send some lines where it occurs.
  11. Sorata_Kanda

    Advertisments PROBLEM !

    Did you make sure the MySQL connection exists?
  12. Sorata_Kanda

    Creating global/native functions

    Hey everyone, I've been wondering if there's a way to create functions that are natively available without using functions exports. I did a little research and found modules which might be suiting in this case. However, I downloaded the SDK and opened it in Visual Studio, and it sort of looks like outdated? So does there a method of creating native functions in Lua exist? If so, how do you do it? Thanks in advance!
  13. Sorata_Kanda

    Advertisments PROBLEM !

    Either way you don't have a connection to your MySQL database or the table/entry does not exist. Use /debugdb and check the MySQL logs for detailed error messages.
  14. Sorata_Kanda

    Override existing functions

    Hey everyone, I'm wondering if you're able to override existing functions. I can image that doing on OOP side, but I don't know if it's possible to do so on a normal function. For example: function _setElementData( player, key, value ) -- Wrapper return setElementData( player, key, value, false ) end Element.setData = _setElementData -- OOP -- But why to do it on setElementData? Just simply setElementData = _setElementData? Thanks in advance!
  15. Sorata_Kanda

    OOP vs element data

    So I sort of managed it like this -- Server races = {} addEventHandler('onResourceStart', resourceRoot, function() -- Query all races from DB for _, race in ipairs(queryResult) do local raceObject = Race.new(race) races[raceObject:getElement()] = raceObject end addEventHandler('onPlayerJoin', resourceRoot, function() triggerClientEvent(source, 'raceUpdateClientTable', this, races) end) end) -- Client races = {} addEvent('raceUpdateClientTable', true) addEventHandler('raceUpdateClientTable', resourceRoot, function(raceTbl) for _, race in pairs(raceTbl) do attachRaceClasses(race) -- See @IIYAMA's example end races = raceTbl end) Any suggestions for improvements?