Jump to content

Hugos

Members
  • Posts

    172
  • Joined

  • Last visited

Posts posted by Hugos

  1. Hello to everyone. I want to make sure that the player 's name is displayed above his head, but I don 't know how to do it correctly. Found the function "dxDrawTextOnElement" - I can 't understand how to apply it correctly?

    P.S: Also I want to add a team with which players can choose whether they will see the names of other players or not. Is it possible to implement this?

  2. Just now, IIYAMA said:

    Triggers can't be deleted, only prevented by not trigger them.

    If it is not possible to delete, then such a question:
    I have "guiCreateStaticImage," and I use "onClientGUIClick" for the image.
    What function do I need to add them to avoid using a trigger?

  3. Just now, Overkillz said:

    Could you just tell me why not ?

    I have never used this, but you can try.

    
    triggerEvent("trig", resourceRoot)
    
    addEvent("trig", true)
    function trig()
     	...
    	removeEventHandler("trig", resourceRoot, trig)
    end
    addEventHandler("trig", resourceRoot, trig)
    

     

    Triggers are not deleted like this.

  4. Just now, Overkillz said:

    Just use a boolean to check if is running or not.

    
    triggerEvent("trig", resourceRoot)
    
    local isRunning = false
    addEvent("trig", true)
    function trig()
    	if not isRunning then
    		isRunning = true
    		...
    	end
    end
    addEventHandler("trig", resourceRoot, trig)
    

    Such an option is not suitable.

  5. Just now, Overkillz said:

    Could you be more specified ?

    If you want to remove an event to prevent his execution, just, don't execute it.

    Regards.

    I need to delete it after running)

  6. Would you please tell me how to remove the trigger?

    For example:

    triggerEvent("trig", resourceRoot)
    
    addEvent("trig", true)
    function trig()
     	...
    end
    addEventHandler("trig", resourceRoot, trig)

    ...how to remove it?

  7. 21 hours ago, IIYAMA said:

    The player list is dynamic. The location of the players in the table is changing when players are leaving.

     

    Player list (table)

    
    local players = getElementsByType("player")
    

     

    New players are added on the back of the table.

    
    players = {
     [1] = player1, [2] = player2, [3] = player3 
    }
    
    players[4] = player4
    
    
    players = {
     [1] = player1, [2] = player2, [3] = player3, [4] = player4
    }
    

     

     

    Leaving players are collapsing the list.

    
    players = {
     [1] = player1, [2] = player2, [3] = player3, [4] = player4
    }
    
    table.remove(players, 1) -- player1 is leaving
    
    
    players = {
     [1] = player2, [2] = player3, [3] = player4
    }
    

     


     

    If you want to generate IDs, you have to make sure they are always unique.

    
    do -- < Closed environment for the variable: id. Nothing can edit it, except for the newId function.
    	local id = 0
    	function newId()
    		id = id + 1
    		return id
    	end
    end
    
    local playerIDs = {}
    
    function getIDFromPlayer(player)
    	local id = playerIDs[player]
    	if not id then
    		id = newId()
    		playerIDs[player] = id
    	end
    	return id
    end
    

    Note, this table doesn't clean it self, yet.

     

    I didn 't get it a little bit. Then how should the function fully look?

  8. I have such a system for oral ID to the player:

    		function getIDFromPlayer(player)
    			if player then
    				local theid
    				players = getElementsByType("player")
    				for id,p in ipairs(players) do
    					if player == p then
    						theid = i
    				end
    			end
    			return theid
    		else return false end
    		end

    Please help. I need to make sure that every player is assigned an ID at spawn. But I now work a little off-line (when the player comes out with id 1, the player with id 2, assigned id 1, but I need this player to have id 2 left, and the one who comes in - established id 1-n  (is not busy) ).

  9. Tell me please if it is possible to make a function that opens an adress URL in your browser?
    P.S.: I mean open a browser not in the game (not createBrowser), but in a regular browser (out of the game).

  10. 2 minutes ago, IIYAMA said:

     

    Block the progress

    
    local timeNow = getTickCount()
    local iProgress = (timeNow - iStartTick)/1000
    if iProgress > 1 then
    	iProgress = 1
    end
    

     

    Stop the animation 3 seconds after the end time.

    
    if ((timeNow - iStartTick) / 1300) >= 1 then
    

     

    Do you want to write this code after 8 lines?

    • Like 1
  11. Hello to everyone. Please help.

    iStartTick = getTickCount()
    function StartAnimation()
    	local iProgress = (getTickCount()-iStartTick)/1000
    	local x1 = interpolateBetween(-(y/1.6), 0, 0, 0, 0, 0, iProgress, "OutBack") 
    	local x2 = interpolateBetween(-(y/70), 0, 0, y/1.6-y/70, 0, 0, iProgress, "OutBack") 
    	dxDrawRectangle(x1, y-y/7.5, y/1.6, y/15, tocolor(0, 0, 0), true)
    	dxDrawRectangle(x2, y-y/7.5, y/70, y/15, tocolor(255, 50, 65), true)
    	dxDrawText("ERROR!", x1, y-y/7.5, x1+y/1.6, y-y/7.5+y/15, tocolor(200, 200, 200), 1, Font, "center", "center", true, false, true)
    	if (iProgress >= 1) then
    		iStartTick = 0;
    		removeEventHandler("onClientRender", root, StartAnimation)
    	end
    end
    addEventHandler("onClientRender", root, StartAnimation)

    I have such animation (rectangle "leaves" on the left side and then goes missing), I need this rectangle not to chill, but to stay for 3 seconds and with the same animation "left" to the initial position (reverse animation). But I don 't know how to do it.

  12. 50 minutes ago, IIYAMA said:

     

    Add data to a database?

    
    INSERT INTO table_name (column1, column2 ) VALUES (?, ?)
    

     

    OR

     

    Get data from a database?

    
    SELECT * FROM table_name
    

     

    OR

     

    Import data to a database from another database.

     

    I get the player 's serial number at the moment, and if it 's not already recorded in the DB - I add.

    local username = getPlayerName(source)
    local serial = tostring(result_account.serial)
    local u_serial = getPlayerSerial(source)
    
    if (serial == u_serial) then --We check the serial number
    else
    	if (serial == "") then --number will stop. Assign a new
    		INSERT INTO accounts (,  ) VALUES (?, ?)
    	else
    	end
    end

    How it is correct to make it?

  13. I use the plugin "mta_mysql", and I write a similar function now (I want to know the player 's serial number and compare it to the one stored in the database)...

    You Can try it...

    local username = getPlayerName(source) --We learn the player's nickname
    local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=? LIMIT 1", username)
    --We find a player with such a nickname in the DB (I have fields with a name called "username")
    local result_account = dbPoll(qh_account, -1)[1]
    if result_account then
    	local serial = tostring(result_account.serial) --The serial number from a DB
    	local u_serial = getPlayerSerial(source) --Current Player Serial Number
    	if (serial == u_serial) then --compare
        	--if number does coincides.
    	else
    		 --if number does not coincides.
    	end

    P.S: Now I only have a question on how to record the player number if it does not match and is equal to 0. if you find a solution, please write.

  14. 4 hours ago, majqq said:

    I would like to try this way, but what do u mean by saying "a little buggy"?

    @IIYAMA

    I have question about dbPrepareString.

    
    serialsToUse = { "111", "222", "333" }
    
    local queryString = dbPrepareString( connection, "SELECT * FROM `player_info` WHERE true" )
    for _,serial in ipairs(serialsToUse) do
        queryString = queryString .. dbPrepareString( connection, " AND `serial`=?", serial )
    end
    local handle = dbQuery( connection, queryString )
    

    Not sure if i understand it correctly.

    
    "SELECT * FROM `player_info` WHERE true"
    

    Select everything from `player_info` table, where true? (what is true exactly for?)

    And later concatenate string with using serials (available in serialsToUse) as parameter.

    Do you need to get the player 's serial number from the DB?

  15. Just now, majqq said:

    Are you trying to edit script file or text file? This matters.

     text file.

    Quote
    • filePath: The filepath of the file in the following format: ":resourceName/path". 'resourceName' is the name of the resource the file is in, and 'path' is the path from the root directory of the resource to the file.
    For example, if there is a file named 'coolObjects.txt' in the resource 'objectSearch', it can be opened from another resource this way: fileOpen(":objectSearch/coolObjects.txt").
    If the file is in the current resource, only the file path is necessary, e.g. fileOpen("coolObjects.txt").

    I just don 't understand if this argument can be used in the new version?

  16. On 05/09/2019 at 00:53, majqq said:

    Wrong category.

    About function, here's my function which i've created for custom logs system. First version which could be improved and it should be improved (in my final ver, i've added buffer to reduce usage of file functions.)

    
    local function logEvent(file, text)
    	local file_exists = fileExists("logs/"..file)
    	local real_time = getRealTime()
    	local year = real_time.year + 1900
    	local month = real_time.month < 10 and "0"..real_time.month + 1 or real_time.month + 1
    	local month_day = real_time.monthday < 10 and "0"..real_time.monthday or real_time.monthday
    	local hour = real_time.hour < 10 and "0"..real_time.hour or real_time.hour
    	local minute = real_time.minute < 10 and "0"..real_time.minute or real_time.minute
    	local second = real_time.second < 10 and "0"..real_time.second or real_time.second
    	if file_exists then
    		local log_file = fileOpen("logs/"..file)
    		if log_file then
    			fileSetPos(log_file, fileGetSize(log_file))
    			fileWrite(log_file, "\r\n["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] "..text)
    			fileFlush(log_file)
    			fileClose(log_file)
    		else
    			outputDebugString("Couldn't open log file.", 0, 255, 127, 0)
    			return false
    		end
    	else
    		local new_log = fileCreate("logs/"..file)
    		if new_log then
    			outputDebugString(file.." log file created successfully.", 0, 255, 127, 0)
    			fileWrite(new_log, "["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] Log file created successfully.")
    			if text then
    				fileSetPos(new_log, fileGetSize(new_log))
    				fileWrite(new_log, "\r\n["..year.."-"..month.."-"..month_day.." "..hour..":"..minute..":"..second.."] "..text)
    			end
    			fileFlush(new_log)
    			fileClose(new_log)
    		else
    			outputDebugString("Couldn't create new log file.", 0, 255, 127, 0)
    			return false
    		end	
    	end
    end
    

    Usage:

    
    logEvent("path_to_file.txt", "Text you want to save")
    

     

    one problem...

    Quote

    Warning: As of 1.5.4 r10413, this function will fail when trying to access a script file of another resource, even with general.ModifyOtherObjects rights granted, which uses a mysql connection through dbConnect when database_credentials_protection is enabled in the server configuration. Additionally, meta.xml will be un-writable and will always open in read-only mode.

    https://wiki.multitheftauto.com/wiki/FileOpen

    I will need to edit a file that is in another resource. But how do I do this in version 1.5.4 r10413+?

  17. 2 hours ago, Erknneto said:
    
    function ... ()
    	local username = getPlayerName(source)
    	local qh_account = dbQuery(db, "SELECT * FROM accounts WHERE username=(?) LIMIT 1", username)
    	local result_account = dbPoll(qh_account,-1)[1]
    	if ( result_account ) then
    	local serial = tostring(result_account.serial)
    	local userSerial = getPlayerSerial(source)
    		if ( serial == userSerial ) then
    			outputChatBox("Yes.",source)
    			return
    		else
    			outputChatBox("No.",source)
    			return
    		end
    	end
    	return
    end
    

    The code you're using is kind different from the ones I use about databases, but this might work.
    You just needed to set the serial from the db as a string and check if it's the same as the one from the player.

    Thanks. Do not tell us how to save it to the database (how to add such a string)?

×
×
  • Create New...