Jump to content

IIYAMA

Moderators
  • Posts

    6,093
  • Joined

  • Last visited

  • Days Won

    217

Posts posted by IIYAMA

  1. 53 minutes ago, ironimust said:

    but when I want to add a new information object, it gives an error while uploading x, y, z, measure, internal values to the server.

     

    58 minutes ago, ironimust said:

    Why is this code "tonumber" contains a line?

    The tonumber function is used to convert a string to a number. A string is basically text "abcdef12345!@$#%" and a number is 1234567890.

    local thisIsAString = "1234"
    
    print(type(thisIsAString)) -- string
    
    thisIsAString = tonumber(thisIsAString) -- convert a string to number
    
    print(type(thisIsAString)) -- number

     

    Why is it trying to convert a string to a number? Probably just to be sure, since the code will not work if strings are using for example for the position x, y, z

     

    7 hours ago, ironimust said:
    function makeInformationIcon(thePlayer, commandName, ...)

    This function is used to add information icons.

    Please specify errors are shown when using the following command:

    /addii

     

    And mark them in the function with a comment:

    local id = SmallestID() -- for example this line
    Spoiler
    function makeInformationIcon(thePlayer, commandName, ...)
        if exports.integration:isPlayerTrialAdmin(thePlayer) then
        if ... then
            local arg = {...}
            local information = table.concat( arg, " " )
            local x, y, z = getElementPosition(thePlayer)
            --z = z + 0.5 only use for i object
            local rx, ry, rz = getElementRotation(thePlayer)
            local interior = getElementInterior(thePlayer)
            local dimension = getElementDimension(thePlayer)
            local id = SmallestID()
            local createdby = getPlayerName(thePlayer):gsub("_", " ")
            local query = mysql:query_free("INSERT INTO informationicons SET id="..mysql:escape_string(id)..",createdby='"..mysql:escape_string(createdby).."',x='"..mysql:escape_string(x).."', y='"..mysql:escape_string(y).."', z='"..mysql:escape_string(z).."', rx='"..mysql:escape_string(rx).."', ry='"..mysql:escape_string(ry).."', rz='"..mysql:escape_string(rz).."', interior='"..mysql:escape_string(interior).."', dimension='"..mysql:escape_string(dimension).."', information='"..mysql:escape_string(information).."'")
            if query then
                informationicons[id] = createPickup(x, y, z, 3, 1239, 0)--createObject(1239, x, y, z, rx, ry, rz)
                setElementInterior(informationicons[id], interior)
                setElementDimension(informationicons[id], dimension)
                setElementData(informationicons[id], "informationicon:id", id)
                setElementData(informationicons[id], "informationicon:createdby", createdby)
                setElementData(informationicons[id], "informationicon:x", x)
                setElementData(informationicons[id], "informationicon:y", y)
                setElementData(informationicons[id], "informationicon:z", z)
                setElementData(informationicons[id], "informationicon:rx", rx)
                setElementData(informationicons[id], "informationicon:ry", ry)
                setElementData(informationicons[id], "informationicon:rz", rz)
                setElementData(informationicons[id], "informationicon:interior", interior)
                setElementData(informationicons[id], "informationicon:dimension", dimension)
                setElementData(informationicons[id], "informationicon:information", information)
                outputChatBox("Information icon created with ID: "..id, thePlayer, 0, 255, 0)
            else
                outputChatBox("Error creating information icon. Please report on the mantis.", thePlayer, 255, 0, 0)
            end
            else
                outputChatBox("SYNTAX: /addii [Information]", thePlayer, 255, 194, 14)
            end
        end
    end
    addCommandHandler("addii", makeInformationIcon, false, false)
    

     

     

  2. On 08/08/2023 at 18:27, Firespider said:

    Thanks, but I've already created the data, so the problem won't be there. At least I think so

    In that case it might be handy if we know at which line + file the error is occurring.

  3. 6 hours ago, ironimust said:

    info-system command lines;

     

    SELECT 
    	* 
    FROM 
    	`informationicons` AS infoIcons
    WHERE 
    	infoIcons.id IS NULL 
    	OR infoIcons.x IS NULL 
    	OR infoIcons.y IS NULL 
    	OR infoIcons.z IS NULL
    	OR infoIcons.interior IS NULL
    	OR infoIcons.dimension IS NULL

    Does this query gives you any results? (run in mysql interface)

    (note this query does only check for null values)

     

    If this query does not give you results.

    Add a log to the following function, in case of a missing x, y or z, it will log the ID of that database row (and abort the loading process).

    function loadAllInformationIcons()
        local ticks = getTickCount( )
        local counter = 0
        local result = mysql:query("SELECT * FROM `informationicons`")
        while true do
            local row = mysql:fetch_assoc(result)
            if not row then break end
            local id = tonumber(row["id"])
            local createdby = tostring(row["createdby"])
            local x = tonumber(row["x"])
            local y = tonumber(row["y"])   -- bunlar tuhaf
            local z = tonumber(row["z"])
            local rx = tonumber(row["rx"])
            local ry = tonumber(row["ry"])
            local rz = tonumber(row["rz"])
            local interior = tonumber(row["interior"])
            local dimension = tonumber(row["dimension"])
            local information = tostring(row["information"])
        	---------------------------------------------
        	if not x or not y or not z then
          		iprint("Data is corruption starts at ID", id)
          		break
          	end
        	---------------------------------------------
            informationicons[id] = createPickup(x, y, z, 3, 1239, 0)--createObject(1239, x, y, z, rx, ry, rz)
            setElementInterior(informationicons[id], interior)
            setElementDimension(informationicons[id], dimension)
            setElementData(informationicons[id], "informationicon:id", id)
            setElementData(informationicons[id], "informationicon:createdby", createdby)
            setElementData(informationicons[id], "informationicon:x", x)
            setElementData(informationicons[id], "informationicon:y", y)
            setElementData(informationicons[id], "informationicon:z", z)
            setElementData(informationicons[id], "informationicon:rx", rx)
            setElementData(informationicons[id], "informationicon:ry", ry)
            setElementData(informationicons[id], "informationicon:rz", rz)
            setElementData(informationicons[id], "informationicon:interior", interior)
            setElementData(informationicons[id], "informationicon:dimension", dimension)
            setElementData(informationicons[id], "informationicon:information", information)
            counter = counter + 1
        end

    After wards you can look the id up like this (replace ID 1 with the one in the debug logs)

    SELECT 
    	* 
    FROM 
    	`informationicons` AS infoIcons
    WHERE infoIcons.id = 1

     

     

  4. 1 hour ago, Firespider said:

    But for some reason this line of code is not good.

     

    You might want to check if there is actually is data and what the data structure is.

    iprint("Validating variable Data:", inspect(Data)) -- debug in /debugscript 3
    
    if not Data then return LogAlert("EmptyRectangle") end -- something is really wrong
    
    local loginCredentials = Data[1]
    if not loginCredentials then return LogAlert("EmptyRectangle") end -- no loginCredentials
    
    local username = loginCredentials[1] 
    local pass = loginCredentials[2] 
    if (username ~= "" or pass ~= "") then return LogAlert("EmptyRectangle") end -- no user name of password
    
    triggerServerEvent("attemptLogin", resourceRoot, username, hash("sha512", pass))

     

     

  5. On 02/08/2023 at 16:29, Burak5312 said:

    how can i convert pt unit to mta dx scale unit in photoshop?

    The units of png and jpg are always measured in pixels. In Photoshop you can edit your settings to pixels. (Edit > Preferences > Units & Rulers)


    Scaling of images can be optimised by enable mipmap. Mipmaps are smaller copies of the original, making rendering smaller variants faster. Mipmaps will be recreated every time you create a texture with dxCreateTexture (by default mipmaps are enabled, see argument mipmaps).

     

     

    • Thanks 1
  6. 1 hour ago, Sr.black said:

    I want to stop the process of riding any car, whether I am glued 

    You will have to cancel the following event when you are glued. You can for example check if the player is attached to anything and then cancel the event.

    https://wiki.multitheftauto.com/wiki/OnVehicleStartEnter

    addEventHandler ( "onVehicleStartEnter", root, 
    function (player) 
    	if getElementAttachedTo (player) then -- check here if you are glued or not.
    		cancelEvent()
    	end 
    end )

     

    • Thanks 1
  7. @scolen

    You can give this utility function a try (untested). It is important to know that you can only check this information serverside.

    --[[
        Check if the player is inside of an acl group with a specific name
        Argument 1: player element
        Argument 2: aclGroupName string
    ]]
    function isPlayerInAclGroupWithName (player, aclGroupName) 
        -- Check if the player argument is filled in correctly
        if not isElement(player) or getElementType(player) ~= "player" then
            error("Expected player element at argument 1, got " .. inspect(player), 2)
        end
    
        -- Check if the aclGroupName is filled in correctly
        if type(aclGroupName) ~= "string" then
            error("Expected string at argument 2, got " .. inspect(aclGroupName), 2)
        end
    
        -- Get the player account and check if the player is logged in
        local account = getPlayerAccount ( player )
        if isGuestAccount(account) then return false end
    
        -- Get the acl group
        local aclGroup = aclGetGroup ( aclGroupName ) 
        if not aclGroup then return false end
    
        -- Check if the account name of the user is inside of the acl group
        local accountName = getAccountName ( account )
        return isObjectInACLGroup ("user." .. accountName, aclGroup)
    end

    Usage:

    if isPlayerInAclGroupWithName(player, "police") then 
    	outputChatBox("I am the police", player)
    end

     

    • Thanks 1
  8. 2 hours ago, lgeri000 said:

    Probably i dont know something about mysql or JSON

    Please show the JSON, that is the easiest way of checking why the conversion is failing.

     

    Also don't use the following array formatting:

    {
    [1] = {},
    [2] = {}
    }

    Keep it clean, no gaps if possible, if you do have gaps add a false value or an empty table:

    {
    	{},
    	{}
    }

    The conversion between Lua and JSON is rather sensitive if you do not follow the JavaScript Object Notion rules.


    Another golden rule:
    Don't mix keys of different key types, it is either strings or integer each (sub)table. If one of them is a string, all of them become strings. There is no such thing as a table in JavaScript, there is only an default object(key strings) or an array(key integers).

     

    • Like 1
  9. 1 hour ago, Salchy said:

    but what does each of them mean?

    A matrix is a mixture of a position and orientation(rotation). With as main purpose able to calculating offset. For example you want to place a ramp in front of a vehicle, a matix helps you with that.

    But you do NOT need to know how a matrix works, don't waste your time XD.

     

    I prefer to use the Matrix class(without oop), instead of getElementMatrix:

    local x, y, z = getElementPosition(vehicle)
    local xr, yr, zr = getElementRotation(vehicle)
    
    local vehicleMatix = Matrix (Vector3(x, y, z), Vector3(xr, yr, zr)) -- build your matrix with position and rotation
    
    local offset = Vector3(0, 0, 0) -- fill in!
    
    local newPosition = matrix:transformPosition(offset)
    
    iprint(newPosition.x, newPosition.y, newPosition.z)

     

    See docs:

    https://wiki.multitheftauto.com/wiki/Matrix

     

    Utility function:

    function getMatrixFromElement (element)
    	return Matrix (Vector3(getElementPosition(element)), Vector3(getElementRotation(element)))
    end

     

     

     

     

     

     

     

  10.  

    21 hours ago, kukimuki said:

    nono, I just want to know that where I need to write this code? 

    Directly after getting the element data:

    On 12/07/2023 at 16:49, kukimuki said:
    local inv = getElementData(localPlayer, "char:items");
  11. 25 minutes ago, kukimuki said:

    can you explain me how is it works?

    How validation works?

    When data comes from an external source, in this case element-data, there is no way of knowing that it is valid. Therefore checking if the data is OK is essential.

    For example if the script tries to get the element-data under the key "char:items" before it has an value assigned to it, the script without data validation will most likely end up with an warning or error at a certain point.

     

    25 minutes ago, kukimuki said:

    and what you written me code is good for me?

    Are you suggesting that it is not good for you? Well this is more or less the format in which you receive help in this forum section🤷‍♂️ If I misunderstand you, please let me know.

  12. 2 hours ago, kukimuki said:

    I inserted the client file. 

     

    Always validate your element-data before you are going to do something with it:

    local inv = getElementData(localPlayer, "char:items");
    
    -----------------------------------------------
    
    assert(type(inv) == "table", "inv must be a table") -- hard error
    
    -- or
    
    if type(inv) != "table" then 
    	-- outputChatBox("OH NO, I need a table to put my head on...")
    	return
    end

     

    If element data is not set, the variable inv does not contain a table, but false instead.

     

     

  13. Another way would be manually modify the ACL:

    <right name="command.theCommand" access="false" />
    
    <right name="command.theCommand" access="true" />

    And set restricted to true (this is the syntax for addCommandHandler):

    bool addCommandHandler ( string commandName, function handlerFunction [, bool restricted = false, bool caseSensitive = true ] )

    This will restrict specific commands based on the ACL.

     

    The choice depends where you want the restriction/validation being placed. During executing the command or in the function of the script.

  14. 5 hours ago, scolen said:

    What is the reason for that ?

    You might consider using another filename. Also stopping the resource on onResourceStart is a good way for error handling, since this resource is not very useful without a databasse.

     

    addEventHandler ( "onResourceStart", resourceRoot, 
    function ()   
    	vehDB = dbConnect( 'sqlite', 'veiculosdatabase.db' )
    	if not vehDB then
    		return cancelEvent (true, "Unable to connect to database.")
    	end
    	dbExec( vehDB, ' CREATE TABLE IF NOT EXISTS `VehiclesSystem_Players` (pSerial, vehID, vehName, vehPrice, Subscription) ' )
    end, false)

     

     

  15. 2 hours ago, Burak5312 said:

    I'm undecided between these two but do you have a better idea?

     

    2 hours ago, Burak5312 said:
    local allpeds = {}
    local testped = createPed(0, 0,0,3)
    allpeds[testped] = true

    For easy and fast management.

     

    2 hours ago, Burak5312 said:
    local allpeds = {}
    local testped = createPed(0, 0,0,3)
    table.insert(allpeds, testped)

    For looping speed. (complexer management)

     

    Note: you can also go for both.

     


     

    Or you could go for this one:

    https://wiki.multitheftauto.com/wiki/CreateElement (as parent)

    https://wiki.multitheftauto.com/wiki/SetElementParent

     

    Benefits:

    • No need to clean up after a ped is deleted.
    • Able to get specific streamedin peds at clientside.
    • Attach eventHandlers to all your peds and only those.
    • (Whipe all peds with just one destroyElement call > propagation.)

     

    • Like 1
  16. 53 minutes ago, Burak5312 said:

    maybe I don't know my way of thinking is wrong but right now I can't see any way out

    AI thinking is not linear unfortunately. But some tasks are, and yet those probably can be interrupted in some way. Therefore it is important to run some of the checks every cycle.

     

    You could give something like this a try:

    local dataStorage_AI = {}
    
    -- Give the ped a brain if it hasn't one yet.
    function init_AI (ped)
    	if dataStorage_AI[ped] then return end
    	dataStorage_AI[ped] = {
    		controls = {}, -- pressed controls maybe? (since serverside is not aware)
    		element = ped
      	}
    end
    
    -- Run the main update cycle
    function update_AI(ped) 
      	if not dataStorage_AI[ped] then return end -- no storage, no brain...
    	if isPedDead(ped) then return end
    	if isElementInWater(ped) then 
    		return runPedInWaterInstructions (ped)
      	end
    end
    
    -- If the ped is in the water, do stuff here
    function runPedInWaterInstructions (ped)
    	local pedData =  dataStorage_AI[ped]
      	-- do something here
    end

     

     

    • Like 1
  17. 10 hours ago, Erfanice said:

    Is there a way to show where the problem is?

    You can inspect resource usage with the performancebrowser:

    http://SERVER_IP:HTTP_PORT/performancebrowser/
    (It will ask you to login with your ingame admin account)

     

    10 hours ago, Erfanice said:

    Is it because of spamming players?

    Might be, it also depends what is spammed. For example a command (attached to a synced database query) can be more impactful than just a chat message.

     

     

  18. On 15/04/2023 at 16:17, Kitsada said:

    I want to use datalist in html, I tried it and it doesn't work.

    I tested your code and it works fine.

    But keep in mind that in your current setup it is used as an auto complete feature. Typing `Jo` makes auto complete John available. Also when you press your arrow-down key, it should act more as the options tag as @FLUSHBICEPS referring to.

     

     

  19. 52 minutes ago, chris1384 said:

    How do you make a function loaded with loadstring() that also supports parameters?

     

    When loading code, you are putting a kind of chunk/function around it.

    So basically this:

    function(player) return getPlayerName(player) == 'owner' end

    Looks more or less like this:

     --  pcall(loadstringed) is calling this chunk/function:
    function ()
    	function(player) return getPlayerName(player) == 'owner' end
    end

     

    So in order to solve this:

    return function(player) return getPlayerName(player) == 'owner' end

     

    local success, theFunc = pcall(loadstringed)
    
    local success2, isOwner = pcall(theFunc, testPlayer)

     

    See also xpcall for better error handling:

    https://www.gammon.com.au/scripts/doc.php?lua=xpcall

    • Like 1
  20. 16 hours ago, Ahmedos said:

    I mean Multi Game Mode

    The generic answer is, you need to create a resource that serves as manager
    > and rewrite each gamemode, so that their usage can be scoped(data/elements/events) for specific players.

    Best is to get inspiration from an already existing Multi Game Mode resource. Since this is really a lot of work and complexity. Explaining the process from A to B would take too much of my time (sorry).

    • Thanks 1
  21. 2 hours ago, MTA.Castiel said:

    Our client event "runOurClientEvent" is currently being triggered for everyone in the team, including myself.

    Try this:

    triggerClientEvent ( 
        (function () 
            local players = getElementsByType("player")
            for i=1, #players do
                if players[i] == source then
                    table.remove(players, i)
                    break
                end
            end
            return players
        end)(), --  IIFE (Immediately Invoked Function Expression)
        "runOurClientEvent", root 
    )

     

    • Thanks 1
  22. 20 hours ago, itsHasaN said:

    then the handlers will stop working on other resources!

    When the resource starts a new resourceRoot element will be created. This element is destroyed when the resource stops.

    It is therefore not a good idea to attach eventHandlers to the resourceRoot's of other resources. (Unless you keep track of start/stop resources)

    Tre.png

     

    In your current example you mentioned the eventName onPlayerFirstSpawn.

    The player makes it's first spawn. From a semantic perspective, the player is therefore the one activating the event. And I expect it therefore to be used as the source of that event. The element above a player is the root element and should be used for the eventHandler of that event. The root element is not deleted when restarting resources.

    But never the less, here is how to solve the resource validation issue:

    addEventHandler("<eventName>", root, 
    function ()
        local resource = getResourceFromName( "<resourceName>" )
        if not resource then return end
        
        if source == getResourceRootElement(resource) then
    		-- The source is from the correct resource
        end
    end)

     

    Another way to keep the resource start up in order is to use the tag: <include resource="resourceName"/>

    https://wiki.multitheftauto.com/wiki/Resources

     

     

     

     

     

     

    • Thanks 1
  23. 46 minutes ago, Molvine said:

    I tried to do something similar.

    Looks nice! Just some side notes, feel free to ignore those.

     

    I recommend not do these kind of animations serverside. You are basically sending data to the client/player every 20 milliseconds, which might causing network trouble on a not local server. Just set the end-value serverside. And trigger an even clientside + do the animation there.

     

    Also the GTA default money animation can be displayed with setPlayerMoney (unless of course you want to use a custom transition): https://wiki.multitheftauto.com/wiki/SetPlayerMoney

    • Thanks 1
×
×
  • Create New...