Jump to content

IIYAMA

Moderators
  • Posts

    6,093
  • Joined

  • Last visited

  • Days Won

    217

Posts posted by IIYAMA

  1. 6 hours ago, pixel77 said:

    The old triggerServerEvent validating still working or not?

    It does.

    The new method is a utility function, which does everything for you. But also for some parts it forces you to be more strict. For example the: protectedKeys table part.

     

     

    6 hours ago, pixel77 said:
                -- The source for this event is always 'resourceRoot'
                if source ~= resourceRoot then
                    reportNaughtyness( eventName, client, "source" )
                    return
                end

    For resourceRoot you can also block this, instead of reporting. Saves you some lines of code.

    addEvent("onRaiseTheRoof", true)
    addEventHandler("onRaiseTheRoof", resourceRoot,
    function(arg1, arg2)
    
    end, false) -- propagate disable, making sure only resourceRoot can be passed as the source

     

    • Thanks 1
  2. On 13/12/2023 at 17:50, FlorinSzasz said:

    and add a 3d line to it to see where they aim.

    Bullets do not start from the weapon Muzzle position.

    The start position is:
    https://wiki.multitheftauto.com/wiki/GetPedTargetStart

    And the end position:
    https://wiki.multitheftauto.com/wiki/GetPedTargetEnd

    Both can be used to create a vector for the line you are referring to.

     

    This is related to the reason why people can shoot around corners without showing more than their elbows. Since the bullets start more to the right of the weapon.

    • Thanks 1
  3. 5 hours ago, kajahun said:

    I have an achievement list store in the scripts.  How can I store the completed achievements for the users in the SQL?

    As roaddog mentioned, toJSON is the easiest way to dynamic store data. But keep an eye on the limitations of JSON. Only store JavaScript structured default {} objects or [] arrays, nothing in between! (else it will be converted to the default {} object variant)

     

    5 hours ago, kajahun said:

    Maybe a third connection table? Because it is a many-to-many connection

    This would be the most space saving solution. Depending on the amount of players you receive every day, it might be a better solution when there are a lot. Just keep in mind that it will be more work.

     

     

    • Like 1
  4. 20 minutes ago, FlorinSzasz said:

    I want to see your money every 20 - 30 seconds and from 1000$ you go to 999999999$ something is wrong.

    If you are worrying about performance, in that case you might consider using MySQL triggers. Those are as close as it gets to your db, making sure you do not cause overhead and align the value-checks with the update moments.

    https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

    1. Create a value-check table / rollback table:
      1. Stores the value that it is being incremented (within 30 seconds)
      2. Stores the future time, when elapse the incrementing value can be ignored and resets to 0
    2. Create a trigger which triggers on update
      1. Do behaviour of value-check table.
      2. If the value jumps too much UP:
        1. Report to a separate table
        2. Freeze account
        3. Rollback manually / automatic (not recommended)

     

     

     

     

    • Thanks 1
  5. 2 hours ago, FlorinSzasz said:

    I wonder what method should i use ?

    Preventing is better than checking for unusual values. Especially when you can't don't keep track of how they have been changed. This could have been done by an exploit instead of real cheats. I personally consider exploiting almost cheating, since the developers should be responsible to deliver decent code.

     

    Back to the subject:

    Value changes in databases are often done by user input. This should be your primary objective.

    For example if you have a marker that opens a GUI to transfer money:

    addEvent("onPlayerTransferMoney", true)
    addEventHandler("onPlayerTransferMoney", resourceRoot,
    function (marker, transferAccountId)
    	-- Possible cheating? = hard returns
    	if not isElement(marker) then return end
    	
    	local playerX, playerY, playerZ = getElementPosition(client)
    	local markerX, markerY, markerZ = getElementPosition(marker)
    	if getDistanceBetweenPoints3D ( playerX, playerY, playerZ, markerX, markerY, markerZ ) > 10 then return end
        
    	-- More user friendly returns
    	if not checkPassiveTimer("event:onPlayerTransferMoney", client, 1000) then return outputChatBox(client, "You can only transfer money every 1 sec.") end -- Source code: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer
    	if not transferAccountId then return end
        
    	-- resume operations
        
    	--
    end)
    • Check if marker exist
    • Check if player is close enough to the marker
    • Limit execution speed (else users can create database lag by spamming the UI button)

    Building an anti cheat system to check for anomalies in your database should be a secondary objective.

    In this case you could start with defining limits. For example a money limit. A soft limit to detect possible cheating and a hard limit to define the impossible.

    For a soft limit you only report to yourself, as it might be very active player.

    And for a hard limit, you could for example freeze the money. In this case you could inform the user that you are investigating the issue. > As you might not know if the user itself is responsible for the anomaly or if another user is responsible. That user could also be helpful in finding/knowing the exploit that is responsible for the anomaly.

    • Like 1
  6. 51 minutes ago, hendawh said:

    From what you wrote I understand that I should create and export the dbResponse() function in each resource that performs a database query at some point?

    Yes, in every resource that is receiving data from the database manager, you should add an export function with the name dbResponse.
    (it is important that the name 'dbResponse' is used consistent)
     

  7. 19 hours ago, hendawh said:

    You mentioned that I should prepare two functions (including one in a separate resource) and I don't understand what you meant.

    A - Resource requesting data

    B - Database manager

     

    A > B

    The first export function is db_query, located in resource B, which you have already created.

    -- Resource A makes this call to resource B
    exports.database_connection:db_query(id, "SELECT * FROM `players`")
    <!-- Resource B -->
    <export function="db_query" type="server" />
    Spoiler
    -- Resource B
    function db_query(id, ...)
    	-- The source resource that made this call (important to rename the pre-defined variable, else it will be lost)
    	local theSourceResource = sourceResource
      
    	if (db_settings.db_connection) then
    		dbQuery(function(query_handle)
    			local result, num_affected_rows, last_insert_id = dbPoll(query_handle, 0)
    
    
    			call( theSourceResource, "dbResponse", id,  result, num_affected_rows, last_insert_id )
    
    		end, db_settings.db_connection, ...)
    	end
    end

     


     

    B > A

    The second one is dbResponse, located in resource A, which is where the response is returned to, with:

    -- Resource B makes this call to resource A
    call( theSourceResource, "dbResponse", id,  result, num_affected_rows, last_insert_id )
    <!-- Resource A -->
    <export function="dbResponse" type="server" />
    -- Resource A
    function dbResponse (id, ...)
    	if not callbacks[id] then return end
    	callbacks[id](...)
    end

    Not sure if you want to keep your function naming style, else it will be db_response ofcourse.

     

     

  8. 49 minutes ago, hendawh said:

    Any help?

     

    The following examples are part of a project I have build before.

    You will have to set-up:

    • 2 export function (one each resource)
      • For sending (as you have now)
      • And for receiving
    • You will have to generate an unique identifier for each query, so that each request can be wired back to where you want the data.
      -- Resource A
      Identifier = {}
      function Identifier:newGenerator() return setmetatable( { index = 0 }, { __index = Identifier } ) end
      function Identifier:generate()
        local index = self.index + 1
        self.index = index
        return "id:" .. getTickCount() .. "|" .. index
      end
      -- For new ID's
      local identifierGenerator = Identifier:newGenerator()
      
      -- function ()
      
      	local id = identifierGenerator:generate()
      
      -- end
    • Before you send a request you make sure that there is a destination:
      • -- Resource A
        callbacks = {}
        -- function ()
        	local id = identifierGenerator:generate()
        	
        	-- Set-up the callback destination, anonymous func if you want to keep going where you left of.
        	callbacks[id] = function (...)
          		iprint(...)
        	end
        	exports.database_connection:db_query(id, "SELECT * FROM `players`")
        	
        
        -- end

         

      • Add wiring for receiving and calling back your callback function:

        -- Resource A
        
        function dbResponse (id, ...)
        	if not callbacks[id] then return end
        	callbacks[id](...)
        end

         

    • Keep the wiring going in the db resource, so that the ID goes ping pong:
    -- Resource B
    function db_query(id, ...)
    	-- The source resource that made this call (important to rename the pre-defined variable, else it will be lost)
    	local theSourceResource = sourceResource
      
    	if (db_settings.db_connection) then
    		dbQuery(function(query_handle)
    			local result, num_affected_rows, last_insert_id = dbPoll(query_handle, 0)
    
    
    			call( theSourceResource, "dbResponse", id,  result, num_affected_rows, last_insert_id )
    
    		end, db_settings.db_connection, ...)
    	end
    end

     

     

     

     

     

    • Thanks 1
  9. 9 hours ago, Ryuto said:

    I also wanted to ask if it is possible to change the default fire color, without affecting the original fire.

    Not sure about replacing it without affecting the original fire.

    But if you look closely at the fire animations, you can see that it exist out of 2x > 2D animations. Each of them starts at one of the feet.

    Which you could draw with: dxDrawMaterialLine3D (that is if you have the frames or a shader)

    Note: Too much of those calls can be demanding, make sure to optimise the textures.

     

    Please consider replying on your other topic.

  10. 5 hours ago, MGO said:

    if anyone knows any solution plz help.

    Just move the text by 1 pixel:

    local borderSize = 1
    dxDrawText(v.text, sx - (0.5 * width) - borderSize, yPos, sx - (0.5 * width) - borderSize, yPos - (i * fontHeight), tocolor(0,0,0), 1, font, "left", "top", false, false, false)
    dxDrawText(v.text, sx - (0.5 * width) + borderSize, yPos, sx - (0.5 * width) + borderSize, yPos - (i * fontHeight), tocolor(0,0,0), 1, font, "left", "top", false, false, false)
    dxDrawText(v.text, sx - (0.5 * width) - borderSize, yPos, sx - (0.5 * width) + borderSize, yPos - (i * fontHeight), tocolor(0,0,0), 1, font, "left", "top", false, false, false)
    dxDrawText(v.text, sx - (0.5 * width) + borderSize, yPos, sx - (0.5 * width) - borderSize, yPos - (i * fontHeight), tocolor(0,0,0), 1, font, "left", "top", false, false, false)
    
    dxDrawText(v.text, sx - (0.5 * width), yPos, sx - (0.5 * width), yPos - (i * fontHeight), tocolor(unpack(v.color)), 1, font, "left", "top", false, false, false)

     

  11. 17 hours ago, Ryuto said:

    I'm sorry to reopen this post again but I have a question.

    Is there a way to detect if the player is being selected from another external script so I can execute a function?

    Yes, you use the event system for that.

    --[[
    	Ⓒ FLUSHBICEPS
    ]]
    
    addEventHandler("onClientKey", root,
    	function(button, press)
    		if not press then return end
    		if button == "mouse_wheel_up" then
    			selectedIndex = selectedIndex - 1
    			if selectedIndex < 1 then
    				selectedIndex = #nearbyPlayers
    			end
    		elseif button == "mouse_wheel_down" then
    			selectedIndex = selectedIndex + 1
    			if selectedIndex > #nearbyPlayers then
    				selectedIndex = 1
    			end
    		else return end
    
    		local selectedPlayer = nearbyPlayers[selectedIndex]
    		if not isElement(selectedPlayer) then return end
    		triggerEvent("onClientSelectPlayer", selectedPlayer, selectedIndex)
        end
    )

     

    addEvent('onClientSelectPlayer', false)
    addEventHandler('onClientSelectPlayer', root, 
    function (selectedIndex)
    	iprint('Player-element:', source, ', index:', selectedIndex)
    end)

     

  12. 32 minutes ago, Ryuto said:

    What functions could I use?

    It is not possible at the moment with the help of gravity functions, because there is only a gravity function for vertical for non vehicle elements.

    That being said, you might be able to fake it. With some inspiration from the superman resource. But it will not be easy.

     

     

  13. -- Run this one time
    local fuelImage = dxCreateTexture ("fuel.png", "argb", true, "clamp")

     

    And:

    dxDrawImageSection(screenX - ScaleY(289), screenY - ScaleY(19), ScaleY(47), ScaleY(-(123*(fuel/100))), 0, 0, ScaleY(47), ScaleY(-(123*(fuel/100))), fuelImage , 0, 0, 0, tocolor(2,153,0,255), false)

     

  14. 18 hours ago, erisP said:

    I m trying to sort it Will I have any problems if I use it this way? or how can I do it better?

    This is fine.

     

    You could transform it in 1 query. But that basically means that you will have to split them up later with Lua.

    SELECT 
    	name, 
    	'time' AS type, 
    	time, 
    	NULL AS kills 
    FROM general ORDER BY time DESC LIMIT 20
    
    UNION ALL
    
    SELECT 
    	name, 
    	'kills' AS type, 
    	NULL AS time, 
    	kills 
    FROM general ORDER BY kills DESC LIMIT 20

     

     

     

    • Thanks 1
  15. To solve this problem, you have to use debug lines(iprint) to get to the problem.

     

    I fixed here a logic issue, where the player is not removed from the database when he is not ingame.

    function unmutePlayer(serial, punisherName, ruleNumber, ruleDescription)
        local player = getPlayerFromSerial(serial)
        iprint(
            "<unmutePlayer> mutedPlayers[serial]:",
            mutedPlayers[serial],
            ", player:",
            player
        )
        if mutedPlayers[serial] then
            if mutedPlayers[serial].unmuteTimer then
                killTimer(mutedPlayers[serial].unmuteTimer)
            end
    
            mutedPlayers[serial] = nil
            iprint("<unmutePlayer> remove from database")
            executeSQLQuery("DELETE FROM punishments WHERE serial = ?", serial)
    
            if player then
                local playerName = getPlayerName(player)
                setPlayerMuted(player, false)
                outputChatBox("#00FF00" .. playerName .. " has been unmuted by #FFFFFF" .. punisherName .. " #006600[#FFFFFFReason: Manual unmute#006600]", getRootElement(), 255, 255, 255, true)
            end
        elseif player then
            local playerName = getPlayerName(player)
            outputChatBox(playerName .. " is not currently muted.", getRootElement(), 255, 255, 255, true)
        end
    end

     

    And here I added some debug lines, tweaked the select query and removed the loop.

    
    addEventHandler("onPlayerJoin", root, function()
        local player = source
        local playerName = getPlayerName(player)
        local playerSerial = getPlayerSerial(player)
        local query = executeSQLQuery("SELECT * FROM punishments WHERE serial = ? LIMIT 1", playerSerial)
        iprint('<onPlayerJoin> query:', query)
        if query and #query > 0 then
            
    
            local row = query[1]
            local totalDuration = tonumber(row.duration)
            local ruleNumber = row.reason
            local ruleDescription = rulesTable[ruleNumber]
            
            iprint('<onPlayerJoin>', 
                "totalDuration:", totalDuration, 
                ", difference:", (getRealTime().timestamp - row.timestamp), 
                ", remaining:", totalDuration - (getRealTime().timestamp - row.timestamp))
    
            local remainingDuration = totalDuration - (getRealTime().timestamp - row.timestamp)
            if remainingDuration <= 0 then
                executeSQLQuery("DELETE FROM punishments WHERE serial = ?", playerSerial)
            else
                setPlayerMuted(player, true)
                
                mutedPlayers[playerSerial] = { duration = remainingDuration, startTime = row.timestamp }
    
                mutedPlayers[playerSerial].unmuteTimer = setTimer(unmutePlayer, remainingDuration * 1000, 1, playerSerial, "Console", ruleNumber, ruleDescription)
    
                outputChatBox("#FFFFFF".. playerName .. " has been muted by #FFFFFFConsole. Reason: RULE #" .. ruleNumber .. ": " .. ruleDescription .. ". Duration: " .. formatTime(remainingDuration), getRootElement(), 255, 255, 255, true)
            end
        end
    end)

     

  16. 2 hours ago, Snakegold said:

    THIS MESSAGE IS NOT APPEARING IN THE CHATBOX AFTER THE PLAYER RECONNECTS

    Don't use playername, use serial.

     

    And don't pass the player to this function:

    function unmutePlayer(player, punisherName, ruleNumber, ruleDescription)

    Pass over it's serial

    function unmutePlayer(serial, punisherName, ruleNumber, ruleDescription)
    	local player = getPlayerFromSerial ( serial ) -- utility function copy from: https://wiki.multitheftauto.com/wiki/GetPlayerFromSerial
    	if player then -- is the player in the server?
    		-- inform the player that he has been unmuted
    	end

     

     

     

    • Like 1
  17. 21 hours ago, Xwaw said:

    It's the same with the rest, the middle line, when it notices something

     

    Keep it simple:

    local hit = processLineOfSight(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, true, false, false)
    
    local colorSet = hit and 1 or 2
    
    dxDrawLine3D(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, tocolor(color[colorSet][1], color[colorSet][2], color[colorSet][3]), 2)

     

  18. 3 hours ago, Father0625 said:
    triggerClientEvent("raceCevent", thePlayer) 

     

    3 hours ago, Father0625 said:
    addEventHandler("raceCevent", localPlayer, function()

    Normally this combination should be working.

     

    But there is one thing that is incorrect, and that is where the event is triggered.

    Currently it should trigger for all players, but multiplied by the amount of players. Since there is no player target set to where the event is sending to.

    triggerClientEvent("raceCevent", thePlayer) 

     

    My recommendations:

    Serverside

    triggerClientEvent(
      thePlayer, -- send to this player
      "raceCevent", 
      resourceRoot -- source is resourceRoot
    ) 

     

    Clientside

    addEvent("raceCevent", true)
    addEventHandler("raceCevent", 
    resourceRoot, -- activate the event based on the source resourceRoot
    function ()
        
    end, false) -- disable propagate for security reasons

     

    • Thanks 2
  19. 3 hours ago, ewxlyz said:

    can you help me fix this SQ


    It is intended behaviour, your query is doing something that is not allowed:

    Quote

     

    The correct way to solve this (making sure it will always work) is to insert those default values when you insert a new row inside of the database.

    INSERT INTO 
    	accounts (
    		name,
    		email,
    		... etc,
    		usedEmails /* the column */
    	)
    	VALUES (
    		?,
    		?,
    		... etc,
    		'[ [ ] ]' /* the intial value */
    	)

     

    Note: I do not expect that you will be able to fix this in one go. Make sure to make a backup!

  20. 24 minutes ago, Father0625 said:
    outputChatBox ( user" "..pass.." "..mail, player, 255, 0, 0,)

    Not sure if it is related, but there are missing some .. after the variable user:

    outputChatBox ( user .. " " .. pass .. " " .. mail, player, 255, 0, 0,)

     

    24 minutes ago, Father0625 said:

    Server side (the event):

    This code is located in Checkplayer.lua or Connect.lua?

  21. 5 hours ago, Egor_Varaksa said:

    ^[A-Za-z_0-9]+$

    And what if you do:

    ^[A-Za-z_0-9]+$|^$

     

    | = OR

    ^ = START

    $ = END

    ^$ = allows empty string since there is nothing between the START and the END.

  22. 42 minutes ago, Firespider said:

    but the system indicates that the password is not correct and I enter it correctly

    In that case you might want to view those in the debug console and check how they differ.

    iprint(result[1]["password"], pass)

     

  23. 9 hours ago, Firespider said:
    if result[2]["password"] == pass then

    if result[2]["password"] == pass then

    And if you do:

    if result[1]["password"] == pass then

    Since normally you want to get the username and password from the same row.

     

×
×
  • Create New...