Jump to content

sacr1ficez

Retired Staff
  • Posts

    636
  • Joined

  • Days Won

    8

Posts posted by sacr1ficez

  1. 17 hours ago, redditing said:

    I would like to know how I could get ElementData from server to client and vice versa

     

    
    -- server side
    marker = createMarker(0, 0, 1.5, "cylinder", 2, 255, 0, 0)
    
    setElementData(marker, "Item", 5)
    
    addEvent("GetItem", true)
    
    addEventHandler("GetItem", root, function()
      	ClientMarker = marker
        
        ItemOfClientMarker = getElementData(marker, "Item")
      end)
    
    addEventHandler("onMarkerHit", marker, function(hp)
        triggerClientEvent("Element", resourceRoot)
        
      	setElementData(hp, "ItemTwo", ElementVariable+getElementData(marker, "Item"))
      end)
    
    -- client side
    function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,...)
    	local x, y, z = getElementPosition(TheElement)
    	local x2, y2, z2 = getCameraMatrix()
    	local distance = distance or 20
    	local height = height or 1
    
    	if (isLineOfSightClear(x, y, z+2, x2, y2, z2, ...)) then
    		local sx, sy = getScreenFromWorldPosition(x, y, z+height)
    		if(sx) and (sy) then
    			local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
    			if(distanceBetweenPoints < distance) then
    				dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center")
    			end
    		end
    	end
    end
    
    setElementData(getLocalPlayer(), "ItemTwo", 0)
    
    addEvent("Element", true)
    
    addEventHandler("Element", root, function()
      	ElementVariable = getElementData(getLocalPlayer() , "ItemTwo")
      end)
    
    addEventHandler("onClientRender", root, function()
        triggerServerEvent("GetItem", root)
        
    	dxDrawTextOnElement(ClientMarker, tostring(ItemOfClientMarker), 2, 50, 255, 255, 0, 3, "arial")
      end)
    

    Does it have a chance to work? because that's something I imagine...

    You should fix it, before your server will die out of endless triggering.

    addEventHandler("onClientRender", root, function()
    triggerServerEvent("GetItem", root)--give an order to make this event "getItem" run in server per frame
    end)

    Trigger client/server even should be well maintained. Right now, you call this function every frame, what if more players will join?

  2. 20 minutes ago, VenomNX said:

    Local player is actually the client!

    So server side script hasn't local player because the script is server side :)

    you should use this in client side

    
    triggerServerEvent("EventName",localPlayer) -- localPlayer = source of the event in server side
    

    and you can receive your event from server side like this :

    
    addEvent("EventName",true)
    addEventHandler("EventName",root,
      function()
        local localPlayer = source; -- source is that player you put in the triggerServerEvent
        -- now you have the localPlayer in the server
      end
    )
    

    also, there are another methods you can use, but this is a simple example.

     

    Note :

    When you need to use the localPlayer in server side, you will be automatically must be using the triggerServerEvent function.

    So in the logic you have to trigger an event

     

    When you want to use localPlayer?

    Using source variable isn't safe.

    function EventName()
    	if client then
    		outputChatBox("Hi player!", client)
    	end
    end
    addEvent("EventName", true)
    addEventHandler("EventName", root, EventName)
    Quote
    • All parameters including 'source' can be faked and should not be trusted.
    • Global variable 'client' can be trusted.

    https://wiki.multitheftauto.com/wiki/Script_security

    • Like 1
    • Thanks 1
  3. 3 hours ago, LOOah said:

    Hello i want to do script that when player aim, you will see player nick and distance between you and player that you aiming at ( sorry for english ) i did something like this

    
    if playerTarget then
      local x,y,z = getElementPosition(playerTarget)
      local x,y,distance = getScreenFromWorldPosition (x,y,z+0.5)
      distance = 30
      if getElementData(playerTarget,"bandit") then
        text = string.gsub(getPlayerName(playerTarget), '#%x%x%x%x%x%x', '' ) else
        text = string.gsub(getPlayerName(playerTarget), '#%x%x%x%x%x%x', '' ) end
      local w = dxGetTextWidth(text,distance*0.033,"default-bold") 
      if w and x and y and text and distance then
        dxDrawText ( text.."("..(getDistanceBetweenPoints3D( x,y,z, getElementPosition ( localPlayer )))..")",x-(w/5),y,x-(w/5),y,tocolor(100, 255, 100, 200),distance*0.033,"bankgothic") end end end);
    

    that line is the showing name and distance

    
    dxDrawText text.."("..(getDistanceBetweenPoints3D( x,y,z, getElementPosition ( localPlayer )))..")",x-(w/5),y,x-(w/5),y,tocolor(100, 255, 100, 200),distance*0.033,"bankgothic")
    

    but i dont know why i have so damn large output

    spacer.png

    Perhaps it's your issue:

    distance*0.033

    It's a text scale.

  4. 1 minute ago, enzoDs said:
    
    tabla = {}
    function iniciar ()
    for _, object in ipairs(aclGroupListObjects(aclGetGroup( "RSPD" )) or {}) do
    	nombre = object:gsub("user.","")
        table.insert( tabla, nombre..", "..getJugadorPermiso(getAccount(nombre))..", "..getJugadorPuesto(getAccount(nombre))..", "..getJugadorSueldo(getAccount(nombre)))
    end
    return tabla
    end
    

    I need clear the table to so that every time the function is executed, no added elements are added

     

    (google translate english xd)

    Just do:

    tabla = {}

    Before loop.

    • Thanks 1
  5. 13 minutes ago, Volltron said:

    Im struggling with how to use the values without declaring them local outside the function
     

    function createTreasure()
        local treasureRadar = createRadarArea( treasurePositions[randomRadar][1- 25, treasurePositions[randomRadar][2- 2550502552210100)
     
        local treasureArea = createColRectangle( treasurePositions[randomRadar][1- 25, treasurePositions[randomRadar][2- 255050)
     
        local treasureObject = createObject(2060, treasurePositions[randomRadar].tabel[randomTreasure][1], treasurePositions[randomRadar].tabel[randomTreasure][2], treasurePositions[randomRadar].tabel[randomTreasure][3- 1)
        
        local treasureCol = createColSphere(treasurePositions[randomRadar].tabel[randomTreasure][1], treasurePositions[randomRadar].tabel[randomTreasure][2], treasurePositions[randomRadar].tabel[randomTreasure][3- 11.5)
        attachElements(treasureCol, treasureObject)
        if (treasureObject) then
            setObjectScale (treasureObject, 2)
        end
    end
    addEventHandler("onResourceStart"getRootElement(), createTreasure)
     
    addEventHandler("onColShapeHit", treasureArea, function(thePlayer)
        if (getElementType(thePlayer) == "player"then
            setRadarAreaFlashing( treasureRadar, true )
        end 
    end )
     
    addEventHandler("onColShapeLeave", treasureArea, function(thePlayer)
        if (getElementType(thePlayer) == "player"then
            setRadarAreaFlashing( treasureRadar, false )
        end 
    end )
     
    addEventHandler("onColShapeHit", treasureCol, function(thePlayer)
        local detect = isElementWithinColShape (thePlayer, treasureCol)
        if detect then
            outputChatBox("Write /dig to dig", thePlayer, 255,255,255 )
        end 
    end )
     
    function playerDigTreasure(thePlayercommand)
        local detect = isElementWithinColShape (thePlayer, treasureCol)
        if detect then
            setPedAnimation(thePlayer, "BOMBER""BOM_Plant"-1falsefalsenilfalse);
            setTimerfunction()
                givePlayerMoney( thePlayer, 100000)
                destroyElement(treasureObject)
                destroyElement(treasureCol)
                destroyElement(treasureArea)
                destroyElement(treasureRadar)
                outputChatBox("Next treasure spawning in 5 seconds"getRootElement(), 255,255,255 )
                setTimer(createTreasure, 50001)
            end20001)
        end 
    end
    addCommandHandler("dig", playerDigTreasure)

    You should use locals whenever you can.

    local col1 = createColSphere(...)
    local col2 = createColSphere(...)
    local col3 = createColSphere(...)
    
    do
    	col1 = "still local, but it's a string now"
    	col2 = "still local, but it's a string now"
    	col3 = "still local, but it's a string now"
    end

    Tip:

    Attaching resource start event to root will cause that function will be triggered when ANY resource starts, use resourceRoot instead.

    addEventHandler("onResourceStart", getRootElement(), createTreasure)

     

    • Thanks 1
  6. 2 hours ago, Soull_Sec said:

     

    I started learning .moon recently, would it be like that?

     

    addEventHandler("onClientPlayerJoin", resourceRoot,
        function()

            animTable.ifp["block"] = "ped"
            animTable.ifp["ifp"] = engineLoadIFP("ped.ifp", animTable.ifp["block"])

            for _, v in ipairs(animTable.anims) do
                engineReplaceAnimation(localPlayer, "ped", v, animTable.ifp["block"], v)
            end

        end
    )
     

     

    Yes, but load IFP just once. This should work correct if player latejoined, now just do the same, with all players when you loaded IFP (so if you started or restarted resource it will affect all players)

  7. 25 minutes ago, Soull_Sec said:

    I put custom animations on my server, but only I can see them in

    my character, the character of the others continues with the original

    animations of GTA, what can this be and how to solve it? HELP ?

    "This function only affects a specific player or ped, the internal animation is not replaced for everyone, for instance, different players and peds are able to have completely different crouching, walking, and fighting etc., animations running simultaneously at the same time. Also, it's not synchronized, you'll need to execute this function on every client in Lua to synchronize it.", after loading IFP loop all players, and replace animation for them, aswell you will need onClientPlayerJoin to replace animation for him (if he joined late).

  8. 9 minutes ago, IIYAMA said:

    Also without mods? There are some mods that do have some collision issues.

    I don't think it's a mods issue, i remember that i had similiar case on tactics gamemode. Tested it without replaced models and seems like it's the same.

     

  9. 13 minutes ago, IIYAMA said:

    You mean that there is no damage given?

    Either there is no damage, body part is invalid (unknown) or hit counts but damage doesn't.

    Test code:

    local vHits = 0
    local tMuzzle = {}
    local vParts = {
    	[3] = "Torso",
    	[4] = "Ass",
    	[5] = "Left arm",
    	[6] = "Right arm",
    	[7] = "Left leg",
    	[8] = "Right leg",
    	[9] = "Head",
    }
    
    function onClientPlayerWeaponFire(pWeapon, pAmmo, pAmmoInClip, pHitX, pHitY, pHitZ, pHitElement, pStartX, pStartY, pStartZ)
    	if not pHitElement then 
    		return 
    	end
    	
    	local vStartX, vStartY, vStartZ = getPedWeaponMuzzlePosition(source)
    	local vCol = {processLineOfSight(pStartX, pStartY, pStartZ, pHitX, pHitY, pHitZ, true, true, true, true, false, true, true, false, nil, false, false)}
    	local vHitPart = vParts[vCol[11]] or "UNKNOWN"
    	tMuzzle = {pStartX, pStartY, pStartZ, pHitX, pHitY, pHitZ}
    
    	vHits = vHits + 1
    	outputChatBox("[HIT #"..vHits.."]: X, Y, Z: "..pHitX..", "..pHitY..", "..pHitZ.." | Hit element: "..tostring(pHitElement).." | Hit bodypart: "..vHitPart)
    end
    addEventHandler("onClientPlayerWeaponFire", root, onClientPlayerWeaponFire)
    
    --
    
    function onClientPlayerDamage()
    	outputChatBox("Damage confirmed at hit: "..vHits)
    end
    addEventHandler("onClientPlayerDamage", root, onClientPlayerDamage)
    
    --
    
    function onClientRender()
    	if #tMuzzle == 6 then
    		dxDrawLine3D(tMuzzle[1], tMuzzle[2], tMuzzle[3], tMuzzle[4], tMuzzle[5], tMuzzle[6], tocolor(200, 0, 0, 255), 3)
    	end
    end
    addEventHandler("onClientRender", root, onClientRender)

    lGmo7Ev.png

    On screen below, there was no collision check. But hits #6, #7 confirmed that element got hit, but no damage was given. (don't mind bodypart, there was no collision check on it)

    BdbV6Yh.png

  10. On 31/03/2019 at 13:59, IIYAMA said:

    Might be possible, as long as it is detected by MTA.

    Not all animations are for some unknown reason detected.

    Just test it!

    Hi. I've just found out that it's a task.

    unknown.png

    Is there any way to disable it?

    It cause some hits to not confirm.

  11. 2 hours ago, Serius said:

    Hi everyone,

    I do scripts, but the script I make eats too many processors. Can you explain how to write an optimized script?

    ı'm using 'onClientRender'.

    Have a nice day 

     

     

    Show your code and i might help you with optimisation. (if possible)

  12. 7 hours ago, Geo said:

    I decided the best course of action would be saving all this character data locally instead of MySQL, here's where my problem comes in.

    What if user will delete cache? Or will manipulate it on other way?

    Do not be afraid to use SQLite/MySQL. If you have lot of data, you can store it in one column as a JSON string aswell.

    • Thanks 1
  13. 1 minute ago, Tekken said:

    But why shared will not work?

    Tables aren't synced by default. If you create tables via shared script, they do not have same data (unless you will sync it). Take a look at this topic, might be helpful.

     

    • Like 1
  14. 12 minutes ago, Tekken said:

    So I'm interested into replacing element data functions to more efficient store data into tables but with this comes a problem, syncing the data between client and server so I taught of creating a shared Lua file and building the system there so in this way the functions will work both client/server.

    But will this work?

    Or should I use a make around with the event system?

    Shared won't work.

    Example:

    -- Client
    
    local clientTable = {}
    
    --
    
    function onClientDataSync(serverData)
    	clientTable = serverData
    end
    addEvent("onClientDataSync", true)
    addEventHandler("onClientDataSync", resourceRoot, onClientDataSync)
    
    --
    
    function onClientReceiveVehicleData(...)
    	local receivedData = {...}
    	local vehicleUserdata = receivedData[1]
    	local vehicleData = receivedData[2]
    
    	clientTable[vehicleUserdata] = vehicleData
    
    	outputConsole(inspect(clientTable))
    end
    addEvent("onClientReceiveVehicleData", true)
    addEventHandler("onClientReceiveVehicleData", resourceRoot, onClientReceiveVehicleData)
    -- Server
    
    local serverTable = {}
    local newVehicle = createVehicle(411, 0, 0, 3)
    
    --
    
    serverTable[newVehicle] = "Some data you want to pass"

    About sync:

    --[[Sync for everyone]]
    
    triggerClientEvent(root, "onClientReceiveVehicleData", resourceRoot, newVehicle, serverTable[newVehicle])
    
    --[[When player latejoined - pass data f.e when he logins]]
    
    triggerClientEvent(source, "onClientDataSync", resourceRoot, serverTable)

     

    • Thanks 1
  15. 28 minutes ago, NoviceWithManyProblems said:

    why this creates me two separate gridlist instead of introducing them to one?

    You don't check if this gridlist exists.

    About this part of code, you are destroying your server network.

    for k,v in ipairs(getElementsByType("ped") do
        if getElementData(v, "created") then
          pedsToTrigger = {}
          table.insert(pedsToTrigger, v)
          triggerClientEvent(thePlayer, "someEvent", resourceRoot, pedsToTrigger)
        end
    end

    Trigger will be called 1 * count of peds, it's very bad. Because it could be done with just trigger.

    -- Client
    
    local pedsGridlist = false
    
    --
    
    function customEvent(serverTable)
    	if not pedsGridlist then
    		pedsGridlist = guiCreateGridList(200, 100, 50, 50, false)
    	end
    
    	-- Finish your code
    end
    addEvent("customEvent", true)
    addEventHandler("customEvent", resourceRoot, customEvent)
    local peds = {
    	{11, 0, 0, 3, "NPC 1"},
    	{11, 0, 0, 4, "NPC 2"},
    }
    
    --
    
    function createPeds()
    	local ped = false
    	local pedData = false
    	local dataToSend = {}
    
    	for i = 1, #peds do
    		pedData = peds[i]
    
    		ped = createPed(pedData[1], pedData[2], pedData[3], pedData[4])
    		dataToSend[#dataToSend + 1] = {ped, pedData[5]}
    	end
    
    	setTimer(function()
    		triggerClientEvent(root, "customEvent", resourceRoot, dataToSend)
    	end, 1000, 1)
    end
    addEventHandler("onResourceStart", resourceRoot, createPeds)

     

    • Thanks 1
  16. 1 hour ago, xendomrayden said:

    Why do you want money for a script that was written in a few seconds?
    For those who need a global chat:

    
    GLOBAL = {};
    
    addCommandHandler("Global",function(player,cmd,...)
    	local msg = table.concat({...}," ");
    	if(#msg >= 1)then
    		outputChatBox("[GLOBAL] "..getPlayerName(player)..": "..msg,root,255,255,255);
    	end
    end)
    
    function GLOBAL.setBindKey(player)
    	bindKey(player,"g","down","chatbox","Global");
    end
    addEventHandler("onPlayerJoin",root,function() GLOBAL.setBindKey(source) end)
    for _,v in pairs(getElementsByType("player"))do GLOBAL.setBindKey(v) end
    

    You're welcome ¯\_( ͡° ͜ʖ ͡°)_/¯

     

    7 hours ago, Messi..! said:

    between ur servers

     

    • Haha 1
  17. 1 hour ago, NoviceWithManyProblems said:

    spacer.png

    You didn't passed table.

    I prefer adding elements manually.

    local someTable = {}
    local somePed = createPed(11, 0, 0, 3)
    
    -- 1st way, ped will be accessible via number, mostly you will need to loop whole table if there's more elements
    
    someTable[#someTable + 1] = somePed
    print(tostring(someTable[1])) -- output: ped userdata
    
    -- 2nd way, ped will be accessible via reference
    
    someTable[somePed] = somePed
    print(tostring(someTable[somePed])) -- output: ped userdata

     

    • Like 1
    • Thanks 1
  18. 3 hours ago, Swagy said:

    So basically, all I want to do is to Apply a vehicle mod to a certain vehicle.

    For example I use:

    local vehicle  = createVehicel(id, x,y,z)

    and then I want that vehicle mod to be replaced, but not all the vehicles with same Vehicle ID would be modded.

    I don't want to use shaders, because I'm willing to change the DFF file so.

    I don't really know how to express it xD but I hope you got what I meant

    Use vehicle variants maybe?

    https://wiki.multitheftauto.com/wiki/Vehicle_variants

  19. 47 minutes ago, Tekken said:

    So in my server I have a lots of peds but when I try to drive them over they do nothing but blocking the car.

    How can I do that they tumbles down?

    Other solution, you might try to use animation when they got hit by car. (onClientPedDamage)

×
×
  • Create New...