Jump to content

IIYAMA

Moderators
  • Posts

    6,093
  • Joined

  • Last visited

  • Days Won

    217

Posts posted by IIYAMA

  1. 2 hours ago, #nofear said:

    Please evaluate the original version of the Server.lua section of the Login Panel.

     

    Here is a fix for a vulnerability for cheaters to abuse (else cheaters can create accounts for other players):

    addEvent("onAccountManage", true)
    addEventHandler("onAccountManage", root, function(typ, username, password, save_log)
    	if source ~= client then return end -- Fix vulnerability

     

    The addAccount function returns the new created account, but can fail. Not the end of the world.

    addAccount(username, password)

     

    Are there any errors in this code?

    I can't find the variable declaration of idTablo, is this one located in another file?

     

     

  2. 5 minutes ago, szampan said:

    The event could be faked by the client, but im just using a variable rn instead

    Yea true, but everything can be faked, even files.

    But that does not mean that you can't personalize data based on user specifications mixed with salt/private key.

     

    6 minutes ago, szampan said:

    can close

    actually in my scenario i would always know if the client faked it but either way i have found a new solution

    I will lock/close your topic, good luck with your new solution!

    • Like 1
  3. On 04/07/2024 at 17:44, #nofear said:

    However, I'm unable to resolve the error in this login panel.

    There are a lot of things wrong with this code. I also noticed that the code contains both tabs and spaces, which mean two different users have been messing with this code (80% sure). And on top of that 50% of the code is broken... 🤦‍♂️

    I have fixed the spaces/tabs for you, and showed you where mistakes are located. But the rest is up to you, especially since I have not clue how this is suppose to be working.

     

    function getIDFromPlayer(id)
    	if id then
    		local theid                 -- Issue: not defined
    		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
    		for id, p in pairs(idTablo) do
    			if id == p then         -- Issue: Comparing integer with an element
    				theid = i           -- Issue: `i` not defined
    				-- Issue: loop should have been broken with `break`
    			end
    		end
    		return theid
    	else
    		return false
    	end
    end
    
    function getPlayerFromID(id)
    	if id then
    		id = tonumber(id)             -- Issue: tonumber should be before the `if id then`
    		local theplayer               -- Issue: Value is nil
    		idTablo = getElementsByType("id") -- Issue: Returns a table of elements, the order can vary and the index does not necessary means it's the correct it.
    		for id, p in pairs(idTablo) do
    			if theID == id then       -- Issue: theID is not defined, comparing nil with integer
    				theplayer = p
    				-- Issue: loop should have been broken with `break`
    			end
    		end
    		return theplayer
    	else
    		return false
    	end
    end
    
    addEventHandler("onPlayerLogin", root, function(_, hesap)
    	setElementData(source, "loggedin", true)
    	setElementData(source, "TuningMenuTrue", false)
    	local hesapID = getAccountID(hesap)
    	if idTablo[hesapID] then  -- Issue: idTablo might not be defined
    		ozelID = idTablo[hesapID]
    		setElementID(source, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
    	else
    		setElementID(source, hesapID)
    	end
    	local oyuncu = (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", ""))
    	local id = getElementID(source) or "-1"
    	-- Variable `oyuncu` and `id` not being used
    end)
    
    addEventHandler("onResourceStart", resourceRoot, function()
    	-- Issue: `id` is not defined
    	if id then
    		id = tonumber(id) -- Issue: tonumber should be before the `if id then`
    		local theplayer -- Issue: Value is nil
    		idTablo = getElementsByType("id")
    		for id, p in ipairs(getElementsByType("player")) do
    			-- Issue: neither variable `id` nor `p` are being used
    			-- Issue: player is not defined. (shouldn't have been variable `p`?)
    			setElementData(player, "loggedin", not isGuestAccount(getPlayerAccount(player)))
    			setElementData(player, "TuningMenuTrue", isGuestAccount(getPlayerAccount(player)))
    			if getPlayerAccount(player) then
    				local hesapID = getAccountID(getPlayerAccount(player))
    				if idTablo[hesapID] then
    					ozelID = idTablo[hesapID] -- Issue: Should be a local, ozelID is an element, not an id
    					setElementID(player, ozelID) -- ozelID if from getElementsByType is an element, not an integer/string
    				end
    			end
    		end
    	end
    end)

     

  4. 12 hours ago, tzn said:

    Hello, why is the message sent by the player not canceled?

    Most likely because of another resource.

     

    Use the AddDebugHook function on outputChatBox, to figure out which one. (this function shows you where a MTA function is called or event is triggered)

  5. 6 hours ago, #nofear said:

     The player dies but does not appear to have left the area.

    If these are the only lines of code that trigger 'destroyTimers'/'destroyTrepassor', then I don't think you have to check element data on clientside.

     

    But if they are not, you could use triggerClientEvent arguments instead. But keep in mind that the clientside handler functions also has to do other things, else it doesn't make sense to have the condition isInResArea in the first place.

     

    Server

    triggerClientEvent ( 
    	pla, -- receiver (player)
    	"destroyTrepassor", 
    	g_root, -- source
    	true -- < isInResArea 
    )

     

    Clientside

    addEvent ( "destroyTrepassor", true )
    addEventHandler ( "destroyTrepassor", g_loc_root,
    	function (isInResArea)
    		-- ...
    		if isInResArea == true then
          
    		-- ...

     

  6. On 26/05/2024 at 15:47, DanHR said:

    fileClose(localFile)

    Just some context why your code is not working as intended.

    You are currently closing the file after running the first command. Do this on onClientResourceStop + resourceRoot.

     

    Quote
    fileWrite(localFile, tostring(i)..", "..tostring(voiceType)..", "..tostring(voiceName)..";")
    • Don't forget to add newlines with \n.
    • After every command run fileFlush, so that the file writes are actually written to the file.
    • Like 1
  7. 18 minutes ago, 31cmTrueDamage said:

    Thank you, sorry to bother, but what recommendations do you have to work better in multiplayer,

    For multiplayer you have to store data for each player. And one of the ways to do that is using tables.

     

    Here some basic functions you could use.

    • Init the storage first: initPlayerData (onPlayerJoin)
    • And after that you can set and get data from the table, for each player: getPlayerData, setPlayerData
    • When a player disconnects: deletePlayerData (onPlayerQuit)

     

    ---@type {[userdata]: {[string]: unknown}|nil}
    local playerDataCollection = {}
    
    ---@param player userdata
    ---@param key string
    ---@return unknown|nil
    function getPlayerData(player, key)
        local playerData = playerDataCollection[player]
        if not playerData then return end
        return playerData[key]
    end
    
    ---@param player userdata
    ---@param key string
    ---@param value any
    function setPlayerData(player, key, value)
        local playerData = playerDataCollection[player]
        if not playerData then return end
        playerData[key] = value
    end
    
    --- Create a storage table for data of a specific player
    ---@param player userdata
    function initPlayerData(player)
        if playerDataCollection[player] then return end
        playerDataCollection[player] = {}
    end
    
    --- Remove all player data and remove it's storage table
    ---@param player userdata
    function deletePlayerData(player)
        if not playerDataCollection[player] then return end
        playerDataCollection[player] = nil
    end

     

     

     

     

  8. 17 hours ago, 31cmTrueDamage said:

    so i guess i am not getting the player position correctly maybe? not sure.

    Your initial code looked fine except for a duplicated message when you are in the marker:

    Stage time:
    Stage finished! Time:

     

    Here you have an alternative version + debug lines so that you can validate what is wrong.

    View in debug console: /debugscript 3

     

    Also keep in mind that this code will not work very good in multiplayer, as startTime, startMarker and finishMarker are shared between all players.

     

    You can ignore the ---@ annotations, those are helping me to automatic validate your code. (and perhaps help you to improve readability)

     

    ----------
    
    -- Add to top of script (local's making sure other scripts can't modify these values by accident)
    
    ---@type integer
    local startTime = 0
    
    ---@type userdata|nil
    local startMarker
    
    ---@type userdata|nil
    local finishMarker
    
    ---------
    
    -- ... --
    
    ---------
    
    ---@param player userdata
    function checkStageProgress(player)
        iprint("Validate player", player, isElement(player) and getElementType(player))
        if not isElement(startMarker) or not isElement(finishMarker) then
            iprint("Not startMarker:", isElement(startMarker) and "It exist" or "does not exist", "or not finishMarker:", isElement(finishMarker) and "It exist" or "does not exist")
            return
        end
        
        if not raceInProgress then
            iprint("Race is not in progress")
            local startX, startY, startZ = getElementPosition(startMarker)
            local playerX, playerY, playerZ = getElementPosition(player)
            local distanceToStart = getDistanceBetweenPoints2D(startX, startY, playerX, playerY)
    
            if distanceToStart <= 3 then
                raceInProgress = true
                startTime = getTickCount() -- Start counting time
                outputChatBox("Stage started!", player)
            end
            return
        end
    
        -------------------------
        -- Race is in progress --
    
        local elapsedTime = math.floor((getTickCount() - startTime) / 1000) 
        if isElementWithinMarker(player, finishMarker) then
            outputChatBox("Stage finished! Time: " .. elapsedTime .. " seconds.", player)
            raceInProgress = false
            return
        end
        -----------------------------
        -- Player is not in marker --
    
        outputChatBox("Stage time: " .. elapsedTime .. " seconds.", player)
    end

     

     

  9. On 11/03/2024 at 01:14, Snakegold said:

    ERROR: Client "playername" triggered serverside event onPlayerDamage, but event is not marked as remotely triggerable

    • Double check if the serverside file is running and init as serverside.
    • Do not enable remote for native events. This is a security risk.
    • Use the predefined client variable for remote triggers, else cheaters can kill a whole server instantly.

     

    iprint(triggerClientEvent and "serverside" or "clientside") -- inspect if the file is running serverside
    
    addEvent("onPlayerDamage", false) -- disable remote
    
    function handlePlayerDamage(attacker, weapon, bodypart, loss)
        if client ~= source then return end
        local victim = client
        triggerEvent("onPlayerDamage", victim, attacker, weapon, bodypart, loss) -- emulate the (client) cancelled onPlayerDamage event
        if getElementHealth(victim) > 0 then
            setElementHealth(victim, getElementHealth(victim) - loss)
            
            if getElementHealth(victim) <= 0 then
                setElementData(victim, "isDead", true)
                killPed(victim)
            end  
        end
    end
    addEvent("onCustomPlayerDamage", true)
    addEventHandler("onCustomPlayerDamage", root, handlePlayerDamage)
    
    function isPlayerDead(player)
        return getElementData(player, "isDead") or false
    end

     

    function onClientPlayerDamage(attacker, weapon, bodypart, loss)
        if attacker and getElementType(attacker) == "player" then
            triggerServerEvent("onCustomPlayerDamage", localPlayer, attacker, weapon, bodypart, loss)
            cancelEvent()
        end
    end
    addEventHandler("onClientPlayerDamage", root, onClientPlayerDamage)

     

  10. 7 hours ago, Snakegold said:

    I want to ensure that only one player dies in such situations.

    Technically it is possible, but it will only work as intended when the latency is very low (< 60 ping) and stable internet (no packet loss).

    How it technically works is that the server is used as mediator for all the damage. When a player it's health is 0, all future damage done by this player is ignored.

    But keep in mind that this will look very weird when the latency is too high. (unplayable)

     

    Some basics:

    Clientside

    onClientPlayerDamage

    cancelEvent

    triggerServerEvent

     

    Serverside

    addEvent

    addEventHandler

    getElementHealth

    setElementHealth

    killPed
     

     

     

  11. 2 hours ago, Ryan167 said:

    how could I make the marker only trigger on dimension 11?

    If the parameter matchingDimension contains the value true, the marker is hit in the same dimension.

    2 hours ago, Ryan167 said:

    What I'm trying to do is have a marker in dimension 11 and when the player joins the marker the player can't use a jetpack (it works but it stays working even outside the marker) and the weapons disabled, which works fine.

    Instead of setting a timer. Which currently is being created infinity > crashing the server at a given point.

    Do the following:

    When giving a jetpack, check if the player is inside of the marker. Based on that, give the Jetpack yes / no.

    -- Making the marker find able inside of another resource
    local antiJetpack = createElement ( "antiJetpackType", "antiJetpackID" )
    
    local marker = createMarker ( 0, 0, 0, "cylinder", 1.5, 255, 255, 0, 170 )
    
    setElementParent(marker, antiJetpack)

    (Other resource)

    local parent = getElementByID ("antiJetpackID")
    if not parent then return end  
    
    local marker = getElementChildren ( parent )[1]
    
    local status =  isElementWithinMarker ( thePlayer, marker )

    https://wiki.multitheftauto.com/wiki/IsElementWithinMarker

     

     

  12. 23 hours ago, RandomRambo said:

    and one more thing...where I can download mta 1.6n?Cus it says I need it to join the server on mta-1.6.0-unstable-7976-net41DA build on which it works...

    Can't you just copy your Program Files (x86)\MTA San Andreas 1.6\server to the server? (maybe I am missing something, but a windows server should be able to start up windows stuff)

  13. 3 hours ago, pixel77 said:

    data[1] and data[2] are numbers. 

    For example: inUseData[12][5] = true

    The client is clicking on a dxDraw button, that is rendered on the 3D World. 

    Then the code looks fine. Unless the numbers are a mixture of numbers and strings. 123 vs "123"

     

    16 hours ago, pixel77 said:

    So they can run the "--some more code here to do things" in the same time, and I don't want to allow this.

    In theory it shouldn't be possible because this function is ran single threaded. There will always be one that is first. The whole function chain-call should have been ended before a new call can be made.

    The following should be finished before the root function can be called again.

    16 hours ago, pixel77 said:
    --some more code here to do things

     

     

    • Thanks 1
×
×
  • Create New...