Jump to content

Flashing marker [HELP]


Recommended Posts

Hello! I would like to solve this so that only one person with the same skin can see this marker, but it only flashes once when it is on the skin that it shouldn't be on.
 
 
 
function unit1()
  local playerskin = getElementModel(source)
  local x, y, z = getElementPosition(source)
    if (validSkin[playerskin]) then
       if not (status2) then
			status = false
			status3 =false
       
			statusB2 = createBlipAttachedTo(source, 0, 4, 0, 0, 255)
			statusMarker1 = createMarker(x, y, z, "checkpoint", 4, 255, 0, 0)
			destroyElement(statusMarker)
			destroyElement(statusB1)       
			attachElements(statusMarker1, source)
	     
			outputChatBox("#898c8f<<#2c469cNeXoN Roleplay#898c8f>> #0f5720Sikeressen megváltoztatad az egységed állapotát: #ffffff||Üldözés||", source, 255, 255, 255, true)


			status2 = true
	  
		else
		outputChatBox("#898c8f<<#2c469cNeXoN Roleplay#898c8f>> #0f5720Már ez az egységed állapota.", source, 255, 255, 255, true)
	  
	  
		end
	end
end
addEvent("Button2", true)
addEventHandler("Button2", root, unit1)
function checkSkin()
 local playerskin = getElementModel(source)
    if (validSkin[playerskin]) then
        setElementAlpha(statusMarker1, 255)

	else
	    setElementAlpha(statusMarker1, 0)
end
end
addEventHandler("onElementModelChange",root,checkSkin)

 

Link to comment

validSkin table is not defined, there are some variables that are not assigned globally and it will give you nil errors and checkSkin is not checking the specific player with the current akin it simply sets the alpha value for  ‘statusMarker1’  depending on the skin 

try changing the function to this and defining those variables 

local validSkin = {[1] = true, [2] = true} -- replace 1 and 2 with valid skin IDs
local status2 = false
local statusMarker1 = nil
local statusMarker = nil
local statusB1 = nil

function checkSkin(oldSkin, newSkin)
    local playerskin = newSkin
    if (validSkin[playerskin]) then
        if source == getAttachedTo(statusMarker1) then
            setElementAlpha(statusMarker1, 255)
        end
    else
        if source == getAttachedTo(statusMarker1) then
            setElementAlpha(statusMarker1, 0)
        end
    end
end
addEventHandler("onPlayerModelChange", root, checkSkin)

 

Link to comment
  • 2 months later...

To achieve the functionality you described, you can modify the code to include a check to ensure that only one person with the same skin can see the marker, and the marker only flashes once when it is on the wrong skin. We will create a system that ensures the marker is visible only to the correct player and flashes only once for the incorrect player.

First, let's create a table to keep track of players and their associated markers:
 

local skinMarkers = {}

Now, modify the unit1 function as follows:

function unit1()
  local playerskin = getElementModel(source)
  local x, y, z = getElementPosition(source)

  if (validSkin[playerskin]) then
    if not (status2) then
      status = false
      status3 = false

      -- Check if the player already has a marker
      if skinMarkers[source] then
        -- If the player already has a marker, destroy it
        destroyElement(skinMarkers[source].marker)
      end

      -- Create the blip and marker for the correct skin
      local statusB2 = createBlipAttachedTo(source, 0, 4, 0, 0, 255)
      local statusMarker1 = createMarker(x, y, z, "checkpoint", 4, 255, 0, 0)
      destroyElement(statusMarker)

      -- Store the marker and blip in the table for later use
      skinMarkers[source] = {
        marker = statusMarker1,
        blip = statusB2,
        skin = playerskin,
        flashing = false, -- Add a flashing flag
      }

      attachElements(statusMarker1, source)

      outputChatBox("#898c8f<<#2c469cNeXoN Roleplay#898c8f>> #0f5720Sikeressen megváltoztatad az egységed állapotát: #ffffff||Üldözés||", source, 255, 255, 255, true)

      status2 = true
    else
      outputChatBox("#898c8f<<#2c469cNeXoN Roleplay#898c8f>> #0f5720Már ez az egységed állapota.", source, 255, 255, 255, true)
    end
  end
end

Now, let's modify the checkSkin function to handle visibility and flashing:

function checkSkin()
  local playerskin = getElementModel(source)
  local markerData = skinMarkers[source]

  if (validSkin[playerskin]) then
    setElementAlpha(markerData.marker, 255)

    -- If the player has the wrong marker and it hasn't flashed yet, make it flash once
    if markerData.skin ~= playerskin and not markerData.flashing then
      markerData.flashing = true
      setTimer(function()
        setElementAlpha(markerData.marker, 0)
      end, 1000, 1) -- Flash for 1 second (adjust the duration as needed)
    end
  else
    setElementAlpha(markerData.marker, 0)
  end
end

addEventHandler("onElementModelChange", root, checkSkin)
This code should now provide the functionality you described. The marker will be visible only to the player with the correct skin, and it will flash once for the player with the incorrect skin. Additionally, the flashing will occur only once for the player with the wrong skin.
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...