Jump to content

IIYAMA

Moderators
  • Posts

    6,069
  • Joined

  • Last visited

  • Days Won

    210

Posts posted by IIYAMA

  1. 41 minutes ago, Dzsozi (h03) said:

    By the way, can I get rid of CREATED_HIGHLIGHTS and make it part of Highlight table? Will it work with a Highlight = {created = {}} setup or something like this? Or should I just keep them seperate? Since I was thinking about making methods like Highlight.getAllByElementType and such so I can get every created highlight of vehicles for example.

    Yup, you can.

     

    3 hours ago, IIYAMA said:
    CREATED_HIGHLIGHTS = {}
    
    local Highlight = {}
    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)

     

     

    • Like 1
  2. 9 hours ago, Dzsozi (h03) said:

    I mean I don't understand how should I implement it in this case.

    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()

     

    Spoiler
    function isElement() return true end
    
    function iprint( ... ) return print( ... ) end

    Some polyfill's for quick testing here:
    https://www.lua.org/cgi-bin/demo

     

    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()

     

    • Thanks 1
  3. 10 hours ago, marcelluss said:

    I rechecked the correctness of the name 100 times when registering the file and the path to the folder, but not to which one.

    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.

  4. 16 hours ago, Dzsozi (h03) said:

    However, I can still call .new function in the testing section with

     

    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')

     

     

     

     

     

     

     

  5. 10 hours ago, Dzsozi (h03) said:

    UPDATE: I changed Class.lua type from 'shared' to 'server' to match testscript.lua type, made Class a local table again, and I got the error again, so I don't understand really why it should be a global variable.

    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())()
    

     

  6. 14 minutes ago, Huba221 said:

    <meta>
        <script src="c.lua type"="client" cache="false"/>
        <script src="s.lua"/>
        <file src="font.ttf"/>
    </meta>

     

    Some typo's.

    <meta>
        <script src="c.lua
    " type"="client" cache="false"/>
        <script src="s.lua"/>
        <file src="font.ttf"/>
    </meta>

    Green = added
    Red = removed

    <meta>
        <script src="c.lua" type="client" cache="false" />
        <script src="s.lua" />
        <file src="font.ttf" />
    </meta>

     

     

  7. 32 minutes ago, SinaAmp said:

    sorry i wasted your time @IIYAMAthank you for help

    No worries. BTW, you can only send the hunger value when you know which account this player has logged in to. There is a chance that the player hasn't logged in yet when the resource has been loaded.

    On closer inspection it might be better to try it on onPlayerLogin and using a login panel to delay the user-interaction.

    addEventHandler ("onPlayerLogin",root, afterlogin)
    

     

  8. 20 minutes ago, SinaAmp said:

    server triggered client side event but event is not added

     

    20 minutes ago, SinaAmp said:
    triggerClientEvent("onGetData", root,PHunger)

    You are sending a message to all clients/players directly when the server is executing the script. The clients/players haven't loaded their scripts yet, to receive the message.

  9. 28 minutes ago, SinaAmp said:

    when i use your library

    First of all, you do not need to use my library. Only if you are going to make use of callbacks.

     

    29 minutes ago, SinaAmp said:

    i dont know how to get my processed hunger and thirst from server side

    You do not get the hunger, you send it using triggerClientEvent.

     

     

    for _,row in ipairs(result) do

        Hunger = row["Hunger"]

        Thirst = row["Thirst"]

        break

    end

    local row = result[1]
    Hunger = row["Hunger"]
    Thirst = row["Thirst"]
    
          

     

    32 minutes ago, SinaAmp said:
    function checkHunger(player, PHunger)
    	if Hunger and Hunger >= 0 then
    		PHunger = Hunger - 1
    	end
    	if PHunger <= 20 then
    		outputChatBox("You need to feed as fast as possible.", 255, 0, 0)
    	end
    	if PHunger == 0 then	
    		if not isPedDead(Player) then
    			local hp = getElementHealth(Player)
    			setElementHealth(Player, hp - 30)
    		end
    	end
    end
    setTimer(checkHunger, 30000, 0)
    

    You should get here the current hunger values from the database.

    https://wiki.multitheftauto.com/wiki/DbPrepareString

    Finish the code yourself.

    local players = getElementsByType("player")
    
    local queryString = dbPrepareString( db, "SELECT Hunger,Thirst FROM stats WHERE Account IN ( "
    
    -- loop with player account names
    queryString = queryString .. dbPrepareString( db, "?, ",  AccName)
    -- loop end
    
    queryString = queryString .. " )"
      
     
    local handle = dbQuery( db, queryString )
      
    -- Receive data here and combine the correct database data with the player.

     

     

     

     

  10.  

    50 minutes ago, Cronoss said:

    I don't know really how to make it work

    Like the code below.

    I have put the bandwidth limit very low so that you can see the transfer status in action. Just make sure you are the only player in the server.

     

    local playerLatentHandles = {}
    
    
    local bandwidthLimit = 100 -- 104857600
    
    function hms(x,y,z)
    
    	triggerLatentClientEvent("mirarA", bandwidthLimit, false, client, x,y,z)
    	
    	-- Get the current handle
    	local handles = getLatentEventHandles(client)
    	local currentHandle = handles[#handles]
      
    	playerLatentHandles[client] = currentHandle
    
    end
    addEvent('mirarPS', true)
    addEventHandler('mirarPS', root, hmc)
    
    
    
    -- Testing:
    setTimer(function () 
    	local player = getRandomPlayer()
    	local currentHandle = playerLatentHandles[player]
    	if currentHandle then
    		local status = getLatentEventStatus( player,  currentHandle)
    		iprint(player, status)
    	end
    end, 500, 0)

     

    @Cronoss

    I did fixed a bug just a sec ago.

  11. 35 minutes ago, SinaAmp said:
    local Thirst = triggerServerEvent("onSendData", resourceRoot, Thirst) -- ***this***

    triggerServerEvent is unable to receive data.

     

    If you take a look at the syntax of that function, you will see that it only returns a boolean(true/false):

    676649160_Schermafbeelding2022-02-07om19_04_15.png.d0f41e82a6696070acef6b5216c742be.png

    https://wiki.multitheftauto.com/wiki/TriggerServerEvent

     

    You can make it possible using this library, but that wouldn't create a solid system. The server should be in charge of the hunger and Thirst values.

     

    What you want is the following:

    Server

    • A timer (or multiple timers)
    • This one gets the Hunger and Thirst
    • Updates the Hunger and Thirst (-1) according to your needs.
    • Sets the health or kills the player.
    • triggerClientEvent (or elementdata with https://wiki.multitheftauto.com/wiki/AddElementDataSubscriber + setElementData [syncMode is "subscribe"])

     

    Client

    • Just updates the UI to show the player his hunger and thirst values.

     

     

     

     

    • Like 1
  12. 53 minutes ago, Cronoss said:

    Do you mean using that in Client-side or something else?

    At the side the triggerClient/ServerEvent is locaties.

    53 minutes ago, Cronoss said:

    debug-script doesn't send me anything but I'm not sure if this works

    The debug console only shows you errors, warnings by default.

    If you want more information than that. You will have to add debug lines. (iprint) Those lines will show up as soon as the code execute them. If they are not shown up while they should, that means that there is a mistake before them. If you keep moving them forwards/backwards, you will eventually find the location of the problem. Between showing up and not showing up, is the problem.

    iprint("A")
    if false then --[[ <<<<
      B not is showing up?
      And A is? 
      Then here is the problem
     ]]
    
     iprint("B")
    end

     

    They are also handy to debug variables, which are often containing incorrect values when there is a bug.

  13. 9 hours ago, Cronoss said:

    , is it gonna be laggy for other players or something like that if I increase the bandwidth?

     

    Wiki:

    except the transmission rate of the data contained in the arguments can be limited and other network traffic is not blocked while the data is being transferred.

    It does 2 things:

    - It can be limited

    - It does not block while transferring.

     

    If you increase the bandwidth to max 100 MB: 100*1024*1024

    You basically undo the first thing. That is fine if you only send a little bit of data.

     

    What might lag for some players is the head movement. Which is caused by the non-block transfer thing.

    - If the player his download is not fast enough, there will be a delay. But there will be no/little lag created for other things, like remote-player movement. (Remote-players = other player elements than yourself in your game)

    - And if the player download is not fast enough and can't keep up. It will stack all those latent events in a queue, which only gets longer.

    If you are going to use this function, then I recommend to use getLatentEventStatus for each player to check if the player receives the data. If yes, then send the next update.

     

     

     

     

     

     

    • Thanks 1
  14. 2 hours ago, SinaAmp said:
    setTimer(checkThirst, 60000, 0)

    This update rate is fine, unless you have about/more than ~40 players in your server.

     

    Fix for that:

    Client (set Thirst with sync disabled)

    Thirst = Thirst - 1
    setElementData(localPlayer, "Thirst", Thirst, false)

    +

    https://wiki.multitheftauto.com/wiki/TriggerServerEvent

    (https://wiki.multitheftauto.com/wiki/TriggerLatentServerEvent)

    +
    Server (set Thirst with sync disabled)

    setElementData(client, "Thirst", Thirst, false)

     

     

     

    • Thanks 1
×
×
  • Create New...