Jump to content

Ihnify

Members
  • Posts

    22
  • Joined

  • Last visited

Posts posted by Ihnify

  1. 1 hour ago, IIYAMA said:

    Exactly, that is why I gave you an example of how to do that, don't waste it.

    Since you still do not understand it, this is my last attempt to show you how you can delete clientside elements by also using a serverside element. If you still don't understand it, then that unfortunately.

     

    Serverside

    
    
    
    local playerBlipElementContainerElement = createElement("playerBlipElementContainer", "playerBlipElementContainer:24436dg45632Ddfg") 
    
    addEventHandler("onPlayerJoin", root, 
    function () 
    	local serverSideElement = createElement("playerBlipElement_serverSide") 
    	setElementData(serverSideElement, "owner", source)
    	setElementParent(serverSideElement, playerBlipElementContainerElement)
    end)
    
    --[[ 
    -- Players already ingame
    addEventHandler("onClientResourceStart"... getElementsByType("player") ...
    
    ]]

     

    Clientside

    
    
    
    local playerBlipElementContainerElement = getElementByID("playerBlipElementContainer:24436dg45632Ddfg")
    
    
    -------------------
    -- MODIFY THIS, for players already ingame (add a little delay) and for new players (onClientPlayerJoin + add a little delay)
    
    local serverSideElements = getElementChildren(playerBlipElementContainerElement)
    for i=1, #serverSideElements do
    	local serverSideElement = serverSideElements[i]
    	local owner = getElementData(serverSideElement, "owner")
    	local blip = createBlipAttachedTo(owner, 0, 1, 150, 150, 150, 255, 1)
      
    	setElementParent(blip, serverSideElement)
    end

     

     

     

    Sorry, but I didn't understand :D I'm really stupid, you can use an example with creating a blip for an vehicle, and deleting it on the server, please, if it's not difficult

  2. this client side 

    local vehicleBlipRoot = createElement("vehicleBlipRoot", "vehicleBlipRoot")
    
    local function streamIn()
    	if getElementType(source) ~= "vehicle" then
    		return
    	end
    	
    	for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
    		if getElementAttachedTo(blip) == source then
    			return
    		end
    	end
    
    	if source == getPedOccupiedVehicle(localPlayer) then
    		return
    	end
    
    	local blip = createBlipAttachedTo(source, 0, 1, 150, 150, 150, 255, 1)
    	setElementParent(blip, vehicleBlipRoot)
    end
    addEventHandler("onClientElementStreamIn", root, streamIn)
    
    local function streamOut()
    	if getElementType(source) ~= "vehicle" then
    		return
        end
    	
        for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
    		if getElementAttachedTo(blip) == source then
    			destroyElement(blip)
    			break
    		end
    	end
    end
    addEventHandler("onClientElementStreamOut", root, streamOut)

    I need to delete blip on the server

    14 minutes ago, IIYAMA said:
    • Server created elements are available clientside.
    • Client created elements are NOT available on serverside.

     

    But there is 1 trick you can use to delete clientside elements by serverside.

    Start the following example when you are not downloading other resources, clientside must have been started before 10 seconds.

     

    Server

    
    
    local serverSideElement = createElement("exampleElement", "id:3563454hasduy3685dsfs") 
    
    
    setTimer(function () -- destroy the element over 10 seconds
    	destroyElement(serverSideElement)
    end, 10000, 1)

     

    Client

    
    
    local clientSideElement = createElement("exampleExample")
    
    
    -- get the serverside element
    local serverSideElement = getElementByID("id:3563454hasduy3685dsfs")
    if isElement(serverSideElement) then
    	setElementParent(clientSideElement, serverSideElement) -- set the clientside element as child of the serverside element
    end
    
    
    addEventHandler("onClientElementDestroy", clientSideElement, 
    function () 
      iprint("onClientElementDestroy")
    end, false)

     

    ***

    Fixed the wrong ID value.

     

     

    but I need to delete the blip created on the client

  3. 1 minute ago, Rakashy said:

    use destroyElement


    type
     

    
    destroyElement (element)

    example:
    let's assume that the created blip is called BlipCarro, then insert the function to execute when the player enters the car
     

    
     destroyElement (BlipCarro)

     

    but blip is created only when a player gets into the transport stream zone, then blip is created, and I want to make sure that blip is not created if the player is in the car, and if the transport is already in the player's stream zone and another player got into the car, blip was deleted

  4. Hi

    how to send information about the created element to the server from the client

    example :

    vehicleBlip = createElement('vehicleBlip', 'vehicleBlip')

    I need to send vehicleBlip to the server

    I want the blip to be deleted when the player gets in the car

    how?)

  5. what is the difference

    example #1

    Fuel = {
        id = { }; --
        
         object = {
            {611.23419189453, 1694.9637451172, 6.5105047225952},
            {607.91522216797, 1699.8511962891, 6.5105137825012},
            {2210.05859375, 2474.6975097656, 10.33863067627},
            {2200.486328125, 2476.20703125, 10.338635444641},
            {2114.7475585938, 928.62805175781, 10.338633537292},
            {2114.5134277344, 911.67749023438, 10.33864402771},
            {1382.2032470703, 461.80364990234, 19.623880386353},
            {-98.42310333252, -1166.6186523438, 2.0666558742523},
            {-85.406776428223, -1171.2337646484, 1.7744096517563},
            {1005.0834350586, -933.74597167969, 41.69800567627},
            {1004.5383300781, -940.85437011719, 41.665897369385},
            {1938.9345703125, -1772.6749267578, 12.904432296753},
            {1945.3464355469, -1772.1834716797, 12.906016349792},
        };
      
        init = function ( )
            addEventHandler("onPlayerVehicleEnter", root, Fuel.playerVehicleEnterFuel)
            addEventHandler("onPlayerVehicleExit", root, Fuel.playerVehicleExitFuel)
            addEventHandler("setVehicleFuel", root, Fuel.setVehicleFuel)
        
            for index in pairs(Fuel.object) do
                Fuel.id[index] = createMarker( )
            end
        end;
         
        getID = function ( theVehicle )
            -- code
        end;
        setVehicleFuel = function ( theVehicle, fuel )
            -- code
        end;
      
        playerVehicleExitFuel = function ( theVehicle, seat ) 
            -- code
        end;
      
        playerVehicleExitFuel = function ( theVehicle, seat ) 
            -- code
        end
    }
    addEventHandler('onResourceStart', resourceRoot, Fuel.init)
    and use example
    Fuel.getID(theVehicle) in another server file
    for example, as I understand it, the global variable fuel is created, is it good or bad? If used like this often
     
    or example #2
    and here a local variable is created
    getID(theVehicle) in another server file
     
    local fuel = {
        id = { },
        
        object = {
          {611.23419189453, 1694.9637451172, 6.5105047225952},
          {607.91522216797, 1699.8511962891, 6.5105137825012},
          {2210.05859375, 2474.6975097656, 10.33863067627},
          {2200.486328125, 2476.20703125, 10.338635444641},
          {2114.7475585938, 928.62805175781, 10.338633537292},
          {2114.5134277344, 911.67749023438, 10.33864402771},
          {1382.2032470703, 461.80364990234, 19.623880386353},
          {-98.42310333252, -1166.6186523438, 2.0666558742523},
          {-85.406776428223, -1171.2337646484, 1.7744096517563},
          {1005.0834350586, -933.74597167969, 41.69800567627},
          {1004.5383300781, -940.85437011719, 41.665897369385},
          {1938.9345703125, -1772.6749267578, 12.904432296753},
          {1945.3464355469, -1772.1834716797, 12.906016349792},
        }
    }
    
    function initFuel ( )
        for index in pairs(fuel.object) do
            fuel.id[index] = createMarker()
        end
    end
    addEventHandler( "onResourceStart", resourceRoot, initFuel)
    
    function getID ( theVehicle )
        return fuel.id[number] -- example
    end
    
    function setVehicleFuel ( theVehicle, fuel )
        -- code
    end
    addEventHandler("setVehicleFuel", root, setVehicleFuel)
    
    function playerVehicleEnterFuel ( theVehicle, seat )
        -- code
    end
    addEventHandler("onPlayerVehicleEnter", root, playerVehicleEnterFuel)
    
    function playerVehicleExitFuel ( theVehicle, seat ) 
       -- code
    end
    addEventHandler("onPlayerVehicleExit", root, playerVehicleExitFuel)

     

  6. 16 minutes ago, majqq said:

    One resource:

    No need for use exports (which are slow) or triggers.

    Direct access to functions.

    If you want to introduce/change something - you need to restart whole mod.

    Several resources:

    In order to have all functionality exports are needed or triggers.

    Using functions through exports/triggers (if function is in other resource).

    If you want to introduce/change something - you just restart desired resource.


    In other words, one resource for best performance, or several resources for elasticity.

    LUAC compiles (and obfuscates code if selected), compiling script converts it directly to Lua bytecode, therefore client/server doesn't need to do that.

    how can I protect my scripts, if possible in more detail

  7. for example, if I do this

    tiggerClientEvent ( source, "fuel", source, Vehicle.fuel [ vehicle ] )

     

    client

    local vehicleFuel
    addEvent ( "fuel", true )
    addEventHandler ( "fuel", root, function ( fuel ) 
    
    vehicleFuel = fuel
    
    end )

     

     

    and use vehicleFuel on speedometer, or element data

     

    this is normal?

  8.     init = function()
            for index in pairs ( Vehicle.vehicles ) do
                Vehicle.vehicleObject [ index ] = createVehicle( Vehicle.vehicles[index][1], Vector3( Vehicle.vehicles[index][2], Vehicle.vehicles[index][3] , Vehicle.vehicles [ index ] [ 4 ] ), 0, 0, Vehicle.vehicles [ index ] [ 5 ] )
    
                Vehicle.fuel [ index ] = 1.5
            end
        end;
    addEventHandler ( "onResourceStart", resourceRoot, Vehicle.init )

     

    Did I make a good script "fuel system"? 

    I load the cars and set them a certain amount of fuel.

    Then I take the fuel data, and use it on the client, in the speedometer.

    Are there standards for writing systems, or give an example of how to use it correctly in the future. I appreciate that.

    Learn language lua +- month

  9. How well did the script "fuel system" that is is, download auto download auto install Qty benzyl

    Then I take this gasoline and show on the client, if there are tips on how to do better, or as an example of how to further make such scripts - write, I will be glad

    Study lua +- month

    server

    1. local timer = {}
      addEventHandler("onPlayerVehicleEnter", root, function ( theVehicle, seat ) 
          if seat == 0 then 
              for i = 1, #Vehicle.vehicles do
                  if theVehicle == Vehicle.vehicleObject [ i ] then
      
                      if(Vehicle.fuel [ i ] <= 0.1) then 
                          return outputChatBox ( "В авто закончился бензин", source )    
                      end
      
                      outputChatBox ( "enter ok", source )
      
                      local thePlayer = source
                      timer [ source ] = setTimer ( function () 
                          if ( Vehicle.fuel [ i ] <= 0.1 ) then
                              outputChatBox ( "В авто закончился бензин", thePlayer )
                              setVehicleEngineState ( theVehicle, false )
                      
                              if isTimer ( sourceTimer ) then  killTimer ( sourceTimer ) end
                          end
                      
                          speedVehicle = getElementSpeed ( theVehicle )
                      
                          kmhFloor = math.floor ( speedVehicle )
      
                          Vehicle.fuel [ i ] = Vehicle.fuel[ i ] - ( speedVehicle + 1 ) / 15000;
      
                          setElementData ( theVehicle, "Fuel",  Vehicle.fuel [ i ] )
                      end, 300, 0 )
                  end
              end
          end
      end)
  10. Насколько хорошо сделал скрипт "система бензина", то есть есть загрузка авто, в загрузке авто устанавливаем кол-во бенза

    Потом я беру данный бензина и показываю на клиенте, если есть советы как сделать лучше, или как пример как в дальнейшем делать подобные скрипты - пишите, буду рад

    Изучаю ЯП +- месяц

    ServerSide :

    local timer = {}
    addEventHandler("onPlayerVehicleEnter", root, function ( theVehicle, seat ) 
        if seat == 0 then 
            for i = 1, #Vehicle.vehicles do
                if theVehicle == Vehicle.vehicleObject [ i ] then
    
                    if(Vehicle.fuel [ i ] <= 0.1) then 
                        return outputChatBox ( "В авто закончился бензин", source )    
                    end
    
                    outputChatBox ( "enter ok", source )
    
                    local thePlayer = source
                    timer [ source ] = setTimer ( function () 
                        if ( Vehicle.fuel [ i ] <= 0.1 ) then
                            outputChatBox ( "В авто закончился бензин", thePlayer )
                            setVehicleEngineState ( theVehicle, false )
                    
                            if isTimer ( sourceTimer ) then  killTimer ( sourceTimer ) end
                        end
                    
                        speedVehicle = getElementSpeed ( theVehicle )
                    
                        kmhFloor = math.floor ( speedVehicle )
    
                        Vehicle.fuel [ i ] = Vehicle.fuel[ i ] - ( speedVehicle + 1 ) / 15000;
    
                        setElementData ( theVehicle, "Fuel",  Vehicle.fuel [ i ] )
                    end, 300, 0 )
                end
            end
        end
    end)

     

     

     


×
×
  • Create New...