Jump to content

Sorata_Kanda

Members
  • Posts

    76
  • Joined

  • Last visited

Everything posted by Sorata_Kanda

  1. You could create a server event that includes a loop where it triggers a client event playing the sound file for each player.
  2. 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. @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. 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. 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. 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. 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. 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. 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. 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!
  12. 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.
  13. 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!
  14. 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?
  15. So as I thought, I won't be coming around with storing those objects in a table. I probably have to fill those reference tables at resource start + with event or something. (Aside: Imagine having those objects "stored" in MySQL. I sort of try to avoid double queries for those Race elements as I think it's not necessary)
  16. The rendering happens only when you're near the Race elements. So that shouldn't be a problem? But I still need to have a reference to the object when looping through Race elements. And as far as I found out, they don't update either.
  17. @IIYAMA But in order to work with onClientRenders so I can display info with 3D Text labels, I need to store each information in elementData, right?
  18. Wow, I wish I'd come up with such a simple solution easily. Thank you very much
  19. Because you mentioned using elementdata non-synced: Would it still make sense to create an element called 'Race'? I did that because I'd like to get later on all races by: for i, race in ipairs(getElementsByType('race')) do -- do stuff here end Or is there another elegent solution?
  20. Ah, okay. Thank you. Asking for a small piece of advice: Would you stick with oop in this case or rather use setelementdata to store title and stuff?
  21. So basically I have to create a new instance each time I send them over to the other side?
  22. Well, as long as I don't need it in any other resouces, no. Also: local raceObj = Race.new(...) -- sending object (table) through triggerClientEvent and triggerServerEvent raceObj:setTitle(string) -- Won't work Race.setTitle(raceObj, string) -- This works. Because Race:setTitle(string) equals Race.setTitle(self, string) As I mentioned before, I think that sending OOP objects through events sort of messes up the table, setting functions defined in raceObj to nil.
  23. @IIYAMA Coming back to the problem I've stated above. So basically, everytime I grab my Race object through getElementData(...) in my Race element and change the title, I need to update the object stored in my Race element again in order to complete the changes, right?
×
×
  • Create New...