Jump to content

setElementVisibleTo need help and got questions :)


Dazee

Recommended Posts

So I want the blip to be visible only to the player who created it I am not sure what to do here is my script below!

function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function markPlayer(thePlayer,commandname,player2) 
playername = getPlayerFromPartialName(player2) 
playername2 = getPlayerName(playername) 
playeraccount2 = getPlayerAccount(playername) 
allplayers = getElementsByType("player") 
if getAccountData(playeraccount2, "settings.marking") == false then 
  
if getElementData(playername, "tempdata.marked") == true then 
cancelEvent() 
outputChatBox("That player is already marked use /unmark to remove the mark!",thePlayer, 255,0,0) 
else 
outputChatBox("" ..playername2..  " has been marked!",thePlayer,0,255,0) 
blip1 = createBlipAttachedTo(playername,58) 
setElementVisibleTo(blip1, allplayers, false) 
setElementVisibleTo(blip1, thePlayer, true) 
end 
setElementData(playername, "tempdata.marked",true) 
end 
  
else 
  
outputChatBox("" ..playername2.. " has disabled marking!",thePlayer, 255,0,0) 
 end 
  
end 
function checkMark(thePlayer,commandname,player3) 
playername = getPlayerFromPartialName(player3) 
if getElementData(playername, "tempdata.marked") == true then 
outputChatBox("The mark was removed from "..playername2.. "",thePlayer,255,0,0) 
destroyElement(blip1) 
setElementData(playername,"tempdata.marked", false) 
  end 
end 
function disableMarking(thePlayer,commandname,atr3) 
playeraccount = getPlayerAccount(thePlayer) 
  
if atr3 == "marking" then 
  
if getAccountData(playeraccount, "settings.marking") == true then 
outputChatBox("You have enabled marking!",thePlayer, 0,255,0) 
setAccountData(playeraccount, "settings.marking", false) 
elseif getAccountData(playeraccount, "settings.marking") == false then 
outputChatBox("You have disabled marking!",thePlayer, 255,0,0) 
setAccountData(playeraccount, "settings.marking", true) 
 end 
 else 
 outputChatBox("That setting does not exist!",thePlayer,255,0,0) 
end 
end 
addCommandHandler("mark",markPlayer) 
addCommandHandler("unmark",checkMark) 
addCommandHandler("settings",disableMarking) 

Link to comment

Finished my script was no need to use client side it didn't want to work for some reason createBlipAttachedTo not sure why maybe MTA is bugged or something but suceeded to make it only visible to the player that actually marked someone and also made a lot of improvements on my script and soon adding an SMS feature :D, setElementVisibleTo FTW

function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function markPlayer(thePlayer,commandname,player2) 
playername = getPlayerFromPartialName(player2) 
if player2 == nil or not playername then 
outputChatBox("You have to insert a valid player name to mark them, or a part of their name!",thePlayer,255,0,0) 
cancelEvent() 
else 
playername = getPlayerFromPartialName(player2) 
playername2 = getPlayerName(playername) 
playeraccount2 = getPlayerAccount(playername) 
  
if getAccountData(playeraccount2, "settings.marking") == false then 
  
if getElementData(playername, "tempdata.marked") == true then 
cancelEvent() 
outputChatBox("" ..playername2.. " is already marked use /unmark  to remove the mark!",thePlayer, 255,0,0) 
else 
outputChatBox("" ..playername2..  " has been marked!",thePlayer,0,255,0) 
blip1 = createBlipAttachedTo(playername,58) 
setElementVisibleTo(blip1, root, false) 
setElementVisibleTo(blip1, thePlayer, true) 
setElementData(playername, "tempdata.marked",true) 
  
end 
else 
outputChatBox("" ..playername2.. " has disabled marking!",thePlayer, 255,0,0) 
end 
end 
end 
function checkMark(thePlayer,commandname,player3) 
playername = getPlayerFromPartialName(player3) 
playername4 = getPlayerName(playername) 
if player3 == nil or not playername then 
outputChatBox("You have to insert a player's name to unmark them, or a part of their name!",thePlayer,255,0,0) 
cancelEvent() 
else 
if getElementData(playername, "tempdata.marked") == true then 
outputChatBox("The mark was removed from "..playername2.. "",thePlayer,255,0,0) 
destroyElement(blip1) 
setElementData(playername,"tempdata.marked", false) 
elseif getElementData(playername, "tempdata.marked") == false then 
outputChatBox("" ..playername4.. " is not marked!",thePlayer,255,0,0) 
cancelEvent() 
  end 
end 
end 
function disableMarking(thePlayer,commandname,atr3) 
playeraccount = getPlayerAccount(thePlayer) 
  
if atr3 == nil or not attribute  then 
outputChatBox("You have to insert a setting to see the list of settings do /settings list",thePlayer,0,255,0) 
cancelEvent() 
  
elseif atr3 == "marking" then 
  
if getAccountData(playeraccount, "settings.marking") == true then 
outputChatBox("You have enabled marking!",thePlayer, 0,255,0) 
setAccountData(playeraccount, "settings.marking", false) 
elseif getAccountData(playeraccount, "settings.marking") == false then 
outputChatBox("You have disabled marking!",thePlayer, 255,0,0) 
setAccountData(playeraccount, "settings.marking", true) 
 end 
 elseif atr3 == "sms" then 
if getAccountData(playeraccount, "settings.sms") == true then 
 outputChatBox("Your SMS is enabled now, others may SMS you!",thePlayer,0,255,0) 
 setAccountData(playeraccount, "settings.sms",false) 
 elseif getAccountData(playeraccount, "settings.sms") == false then 
 outputChatBox("You have disabled your SMS, no one can SMS you now!",thePlayer,255,0,0) 
 setAccountData(playeraccount, "settings.sms", true) 
  end 
 end 
end 
addCommandHandler("mark",markPlayer) 
addCommandHandler("unmark",checkMark) 
addCommandHandler("settings",disableMarking) 

Link to comment
You do know that if you create a blip, then anybody can destroy it when they unmark someone? aswell as that your "tempdata.marked" data is global, means it's being set to the player you mark directly, the data is being shared by everyone.

Thanks for noticing that will fix it when i get time then post here :)

EDIT:I fixed it decided to use account data :D

function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function markPlayer(thePlayer,commandname,player2) 
playername = getPlayerFromPartialName(player2) 
if player2 == nil or not playername then 
outputChatBox("You have to insert a valid player name to mark them, or a part of their name!",thePlayer,255,0,0) 
cancelEvent() 
else 
playername = getPlayerFromPartialName(player2) 
playername2 = getPlayerName(playername) 
playeraccount2 = getPlayerAccount(thePlayer) 
  
if getAccountData(playeraccount2, "settings.marking") == false then 
  
if getAccountData(playeraccount2, "marked.latest.temp") == playername2 then 
cancelEvent() 
outputChatBox("" ..playername2.. " is already marked use /unmark  to remove the mark!",thePlayer, 255,0,0) 
else 
outputChatBox("" ..playername2..  " has been marked!",thePlayer,0,255,0) 
blip1 = createBlipAttachedTo(playername,58) 
setElementVisibleTo(blip1, root, false) 
setElementVisibleTo(blip1, thePlayer, true) 
--setElementData(thePlayer, "tempdata.marked1",true) 
setAccountData(playeraccount2, "marked.latest.temp", playername2 ) 
  
end 
else 
outputChatBox("" ..playername2.. " has disabled marking!",thePlayer, 255,0,0) 
end 
end 
end 
function checkMark(thePlayer,commandname,player3) 
playername = getPlayerFromPartialName(player3) 
playername4 = getPlayerName(playername) 
playeraccount3 = getPlayerAccount(thePlayer) 
if player3 == nil or not playername then 
outputChatBox("You have to insert a player's name to unmark them, or a part of their name!",thePlayer,255,0,0) 
cancelEvent() 
else 
if getAccountData(playeraccount3, "marked.latest.temp") == playername2 then 
outputChatBox("The mark was removed from "..playername2.. "",thePlayer,255,0,0) 
destroyElement(blip1) 
setAccountData(playeraccount3,"marked.latest.temp",false) 
elseif getAccountData(playeraccount3, "marked.latest.temp") == false then 
outputChatBox("" ..playername4.. " is not marked!",thePlayer,255,0,0) 
cancelEvent() 
  end 
end 
end 
function disableMarking(thePlayer,commandname,atr3) 
playeraccount = getPlayerAccount(thePlayer) 
  
if atr3 == nil or not "marking" then 
outputChatBox("You have to insert a setting to see the list of settings do /settings list",thePlayer,0,255,0) 
cancelEvent() 
  
elseif atr3 == "marking" then 
  
if getAccountData(playeraccount, "settings.marking") == true then 
outputChatBox("You have enabled marking!",thePlayer, 0,255,0) 
setAccountData(playeraccount, "settings.marking", false) 
elseif getAccountData(playeraccount, "settings.marking") == false then 
outputChatBox("You have disabled marking!",thePlayer, 255,0,0) 
setAccountData(playeraccount, "settings.marking", true) 
 end 
 elseif atr3 == "sms" then 
if getAccountData(playeraccount, "settings.sms") == true then 
 outputChatBox("Your SMS is enabled now, others may SMS you!",thePlayer,0,255,0) 
 setAccountData(playeraccount, "settings.sms",false) 
 elseif getAccountData(playeraccount, "settings.sms") == false then 
 outputChatBox("You have disabled your SMS, no one can SMS you now!",thePlayer,255,0,0) 
 setAccountData(playeraccount, "settings.sms", true) 
  end 
 end 
end 
addCommandHandler("mark",markPlayer) 
addCommandHandler("unmark",checkMark) 
addCommandHandler("settings",disableMarking) 

Altho i forgot to fix the sms attribute part just lazy bout it bcuz im not using the attribute for anything yet

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...