Jump to content

Please help me with this script pretty please


Dentos

Recommended Posts

So I got this small script that allows you to see only the people in your gang(blips) in the map it works fine but theres a little problem with it when I login as a player with no gang it works fine at first but after you walk for while you start seeing people that dont have gang in map ... so I want make it so if you dont have gang you can never see anyone in the map

heres the script

playerBlibs = {} 
amouunt = 0 
function updateGPS() 
amouunt = 0 
local gangname = getElementData(getLocalPlayer(),"gang") 
 for i, blip in ipairs(playerBlibs) do 
  destroyElement(blip) 
 end 
if not getElementData(getLocalPlayer(),"gang") then return end  
playerBlibs = {}  
 for i, player in ipairs(getElementsByType("player")) do 
  if gangname == getElementData(player,"gang") then 
   amouunt = amouunt+1 
   playerBlibs[amouunt] = createBlipAttachedTo(player,0,2,22,255,22) 
   setBlipVisibleDistance(playerBlibs[amouunt],1000) 
  end 
 end 
end 
setTimer(updateGPS,1000,0) 

Link to comment
  
playerBlibs = {} 
amouunt = 0 
  
function deleteBlips() 
    for i, v in ipairs(getElementsByType("blip")) do 
        if getBlipIcon(v) == 0 then 
            destroyElement(v) 
        end 
    end 
end 
  
function updateGPS() 
amouunt = 0 
local gangname = getElementData(getLocalPlayer(),"gang") 
 for i, blip in ipairs(playerBlibs) do 
  destroyElement(blip) 
 end 
if not getElementData(getLocalPlayer(),"gang") then return deleteBlips() end 
playerBlibs = {} 
 for i, player in ipairs(getElementsByType("player")) do 
  if gangname == getElementData(player,"gang") then 
   amouunt = amouunt+1 
   playerBlibs[amouunt] = createBlipAttachedTo(player,0,2,22,255,22) 
   setBlipVisibleDistance(playerBlibs[amouunt],1000) 
  end 
 end 
end 
setTimer(updateGPS,1000,0) 
  

Link to comment

Still the same i think my server counts player who dont have gang as a gang since when you dont have gang you can only see player that dont have gang and not player that do :/

btw im using castillos gang system idk if that helps at all

maybe something like this

  
if gangname == ("") then  destroyElement(blip) 
  

tired it didnt work :/

Link to comment

You're using a timer which is pretty usless since it can cause some laggs because of 3 loops every min. I'll fix you're full code but if you're happy with laggs then I've no problem. This code seems fine. If you're still having problem with it then just send me the part where you're setting element data "gang".

Link to comment

IIYAMA I tried this but nothing

playerBlibs = {} 
amouunt = 0 
function updateGPS() 
amouunt = 0 
local gangname = getElementData(getLocalPlayer(),"gang") 
 for i, blip in ipairs(playerBlibs) do 
  destroyElement(blip) 
 end 
if not getElementData(getLocalPlayer(),"gang") then return end 
playerBlibs = {} 
 for i, player in ipairs(getElementsByType("player")) do 
  if gangname == getElementData(player,"gang") then 
   amouunt = amouunt+1 
   playerBlibs[amouunt] = createBlipAttachedTo(player,0,2,22,255,22) 
   setBlipVisibleDistance(playerBlibs[amouunt],1000) 
if not gangname then  --ADDED THIS BUT STILL NOTHING 
  destroyElement(blip) 
  end 
 end 
end 
end 
setTimer(updateGPS,1000,0) 

Saml1er my script works fine but for some reason its making player who dont have gang see eachother in map its a Dayz server so i dont want for you able to so people in map unless there people from your gang

Link to comment
  • Moderators

you aren't debugging your code, if you did you want see that the variable blip is nil.

You also would see that the: if not gangname then : part never get executed unless the localPlayer has no element data as well.

Link to comment
  
  
playerBlibs = {} 
amouunt = 0 
  
function deleteBlips() 
    for i, v in ipairs(getElementsByType("blip")) do 
        if v then 
            destroyElement(v) 
        end 
    end 
end 
  
function updateGPS() 
amouunt = 0 
local gangname = getElementData(getLocalPlayer(),"gang") 
 for i, blip in ipairs(playerBlibs) do 
  destroyElement(blip) 
 end 
if not getElementData(getLocalPlayer(),"gang") then return deleteBlips() end 
playerBlibs = {} 
 for i, player in ipairs(getElementsByType("player")) do 
  if gangname == getElementData(player,"gang") then 
   amouunt = amouunt+1 
   playerBlibs[amouunt] = createBlipAttachedTo(player,0,2,22,255,22) 
   setBlipVisibleDistance(playerBlibs[amouunt],1000) 
  end 
 end 
end 
setTimer(updateGPS,1000,0) 
  

Link to comment
  • Moderators

clientside

local playerBlibs = {} 
  
-- events -- 
"onClientPlayerSpawn" --> attach blip 
"onClientPlayerWasted" --> remove blip 
"onClientElementDataChange" --> attach blip/remove blip 
"onClientResourceStart" --> (use resourceRoot instead of root) loop through players:  attach blips  

serverside

-- events --  
"onResourceStart" --> (use resourceRoot instead of root) loop through players: set the elementdata to false for all players. So onClientElementDataChange event will work in the beginning. 

Link to comment

still nothing Anubhav i can still see ppl that dont have gang when i dont have gang its funny cuz I cant see ppl dont have gang when im in a gang it works and i can only see gang member and when im not in gang it dosent work its like it ipairs ppl dont have a gang as it was gang

Link to comment

IYAMA I tired script like that but dosent even work

local pBlips = { } 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        for index, player in ipairs(getElementsByType("player")) do 
            addTeamBlip(player) 
        end 
    end 
) 
  
function addTeamBlip(player) 
    if ( pBlips[player] ) then return false end -- Adding a prevention of duplicate blips 
    local pAccount = getPlayerAccount(player) 
    local theGang = ( isGuestAccount(pAccount) and false ) or exports["gang_system"]:getAccountGang(pAccount) 
    if ( theGang ) then 
        local r, g, b = getPlayerNametagColor( player ) 
        local theBlip = createBlipAttachedTo( player, 0, 2, r, g, b ) 
        -- Change visibility to only the team members 
        setElementVisibleTo( theBlip, root, false ) 
        for index, value in ipairs ( exports["gang_system"]:getGangMembers(theGang) ) do 
            setElementVisibleTo( theBlip, value, true ) 
        end 
        pBlips[player] = theBlip 
    end 
end 
  
function destroyBlip(element) 
    local theElement = source or element 
    if ( theElement ) then 
        destroyElement(pBlips[theElement]) 
        pBlips[theElement] = nil -- Just in-case... 
    end 
end 
  
-- Events 
addEventHandler ( "onPlayerSpawn", root, addTeamBlip ) -- onPlayerSpawn will now add a teamBlip 
addEventHandler ( "onPlayerQuit", root, destroyBlip ) 
addEventHandler ( "onPlayerWasted", root, destroyBlip ) 

Link to comment
  • Moderators

I never mentioned the serverside functions:

"onPlayerSpawn"

"onPlayerQuit"

"onPlayerWasted"

You are going to create the blips clientside.

and I forgot the event:

"onClientPlayerQuit" --> remove blip 

and save the blips like this:

playerBlibs[player]= blip 

get the blips like this:

local blip = playerBlibs[player] 

clear the data from the table like this:

playerBlibs[player] = nil 

Link to comment
  • Moderators

Does that mean you don't have to try it? I don't think so. As long as you try things there are alway People to correct you and at the end you have your script and learnt from it.

If there are things you don't understand, I expect you to ask them and not that you say that you can't do it because that is wasting my time.

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