Sign in to follow this  
Lergen

Gang color blips

Recommended Posts

Is this possible? What I'm trying to achieve is having player blips in freeroam be the color of whatever gang they're in, I would assume it would be since turfs are capable of using gang colors but I'm not sure if the same can be done for blips. I'm using Castillo's gang system. Any advice?

Share this post


Link to post
Posted (edited)

If you want have blips color and are with team you can do that 

createBlipAttachedTo
getElementsByType 
getPlayerTeam
getTeamColor or getPlayerNametagColor 

 

Edited by Dimos7

Share this post


Link to post

Thank you, although I'm trying to get it working with Castillo's gang system rather than teams. Turfsystem can utilize it for ColShapes so I would think it should be possible to set it for Blips and/or NametagColor as well, but I'm just too much of a novice to figure out how it works.

local playerGang = getElementData ( player, "gang" )
if ( playerGang ) then
local r, g, b = unpack ( getGangColor ( playerGang ) )
end
setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
g_PlayerData[player] = { vehicles = {}, settings={} }
g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b)
  
function getGangColor(gangName)
return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

Something I tried. This doesn't output any errors but it doesn't work either.

Share this post


Link to post
Posted (edited)
function getPlayerGang(thePlayer)
  local gangName = getElementData(thePlayer, gang“) 
  if gangName ~= nil then
  local r, g, b = unpack(getGangColor(gangName)) 
    setPlayerNametagColor(thePlayer, tonumber(r) , tonumber(g) , tonumber(b)) 
  createBlipAttachedTo(thePlayer, 0, 2, tonumber(r), tonumber(g), tonumber(b)) 
  end
end

function getGangColor(gangName) 
   return export["gang-system"]:getGangData(gangName, "color“) 
end 

 

Edited by Dimos7

Share this post


Link to post

Hey, thanks! I tried it out, but sadly it doesn't seem to work. I got these error messages:

')' expected near '∩'

Client (name) triggered serverside event onloadedAtClient but event is not added serverside

"Client (name) triggered event onServerCall, but event is not added serverside.

Where should I go from here?

Share this post


Link to post

Setting it as its own stand-alone script rather than trying to incorporate it into the Freeroam script, the only problem returned is the "Client (name) triggered event onServerCall, but event is not added serverside." one. I'm not sure what this means though.

Share this post


Link to post
Posted (edited)
function getPlayerGang(thePlayer)
  local gangName = getElementData(thePlayer, "gang") 
  if gangName ~= nil then
  local r, g, b = unpack(getGangColor(gangName)) 
    setPlayerNametagColor(thePlayer, tonumber(r) , tonumber(g) , tonumber(b)) 
  createBlipAttachedTo(thePlayer, 0, 2, tonumber(r), tonumber(g), tonumber(b)) 
  end
end

function getGangColor(gangName) 
   return export["gang-system"]:getGangData(gangName, "color“) 
end 

Mean you try to run a even on server that dosen't exist

Edited by Dimos7

Share this post


Link to post
Posted (edited)

Thanks, I messed around with it a bit and almost have it working! The nametags and blips show like they're supposed to, but only if I restart the freeroam gamemode each time a new person joins, otherwise they don't show at all. In other words, only on restarting freeroam whenever somebody joins can I get it to work. I'm not sure if it's related but I get this error in debug:

"server.lua 131:bad argument #1 to 'unpack' (table expected, got boolean)

Line 131 is line 6 here.

function joinHandler(player)
	if not player then
		player = source
	end
	local gangName = getElementData(player, "gang") 
    local r, g, b = unpack(getGangColor(gangName)) 
	setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
	g_PlayerData[player] = { vehicles = {}, settings={} }
	g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b))
	addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', player, 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

function getGangColor(gangName)
return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

I'm just using the default freeroam server script. Was there something I forgot to add?

 

Edited by Lergen

Share this post


Link to post
Posted (edited)
function joinHandler()
	local gangName = getElementData(source , "gang") 
  if gangName ~= nil then
    local r, g, b = getGangColor(gangName)
	setPlayerNametagColor(source , tonumber(r), tonumber(g), tonumber(b))
	g_PlayerData[source] = { vehicles = {}, settings={} }
	g_PlayerData[source].blip = createBlipAttachedTo(source , 0, 2, tonumber(r), tonumber(g), tonumber(b))
	addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', source , 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

function getGangColor(gangName)
return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

 

Edited by Dimos7

Share this post


Link to post
Posted (edited)

I appreciate your help. That code didn't output any errors, but it unfortunately didn't work.

 

This is what the default freeroam script looks like:

function joinHandler(player)
	if not player then
		player = source
	end
	local r, g, b = math.random(50, 255), math.random(50, 255), math.random(50, 255)
	setPlayerNametagColor(player, r, g, b)
	g_PlayerData[player] = { vehicles = {}, settings={} }
	g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, r, g, b)
	addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', player, 0, 255, 0)
		outputChatBox('Press F1 to show/hide controls', player, 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

And this is my modified version which should just be changing blip/nametag color:

function joinHandler(player)
	if not player then
		player = source
	end
	local gangName = getElementData(player, "gang") 
    local r, g, b = unpack(getGangColor(gangName)) 
	setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
	g_PlayerData[player] = { vehicles = {}, settings={} }
	g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b))
	addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', player, 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

This works like it should, but freeroam needs to be restarted for each new person that joins for the blip/nametag to show up. I'm just not sure what's breaking here.

Edited by Lergen

Share this post


Link to post
Posted (edited)
function joinHandler()
	local gangName = getElementData(source , "gang") 
  if gangName ~= nil then
    local r, g, b = getGangColor(gangName)
	setPlayerNametagColor(source , tonumber(r), tonumber(g), tonumber(b))
	g_PlayerData[source] = { vehicles = {}, settings={} }
	g_PlayerData[source].blip = createBlipAttachedTo(source , 0, 2, tonumber(r), tonumber(g), tonumber(b)) 
    addEventHandler
	("onFreeroamLocalSettingChange",source ,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', source , 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

function getGangColor(gangName)
return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

 

Edited by Dimos7

Share this post


Link to post

Thanks. I got "Bad argument at setPlayerNametagColor [Expected number at argument 2, got nil]

I'm at a loss. Could the problem be somewhere else in the freeroam script?

 

Share this post


Link to post
Posted (edited)

No i think is that not get the color of the gang 

function joinHandler()
	local gangName = getElementData(source , "gang") 
  if gangName ~= nil then
    local r, g, b = export["gang-system"] :getGangData(gangName, "color") 
	setPlayerNametagColor(source , tonumber(r), tonumber(g), tonumber(b))
	g_PlayerData[source] = { vehicles = {}, settings={} }
	g_PlayerData[source].blip = createBlipAttachedTo(source , 0, 2, tonumber(r), tonumber(g), tonumber(b)) 
    addEventHandler
	("onFreeroamLocalSettingChange",source ,onLocalSettingChange)
	if getOption('welcometextonstart') then
		outputChatBox('Welcome to Freeroam', source , 0, 255, 0)
	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

 

Edited by Dimos7

Share this post


Link to post
Posted (edited)

OK. Possibly(?) some progress.

local r,g,b = exports.gang_system:getGangData ( gangName, "color" )

Returns: "bad argument at 'setPlayerNametagColor' [expected number at argument 2, got nil]. using it this way, it can't get colors from the gang system.

 

I feel like reiterating that this

function joinHandler(player)
if not player then
player = source
end
local gangName = getElementData(player, "gang") 
local r, g, b = unpack(getGangColor(gangName)) 
setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
g_PlayerData[player] = { vehicles = {}, settings={} }
g_PlayerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b))
addEventHandler("onFreeroamLocalSettingChange",player,onLocalSettingChange)
    if getOption('welcometextonstart') then
    		outputChatBox('Welcome to Freeroam', player, 0, 255, 0)
    	end
end
addEventHandler('onPlayerJoin', root, joinHandler)

actually -works- it get the gang colors, and displays them like I want it to, the only thing is that freeroam needs to be restarted for it to work. It outputs only this one error when a player connects: "bad argument #1 to 'unpack' (table expected, got boolean). Could this be the problem?

Edited by Lergen

Share this post


Link to post

Still working on this, but no luck. What changes in a restart that would make it work when it wouldn't before? I'm starting to think it's the event 'onPlayerJoin' that may be messing it up somehow.

Share this post


Link to post
Posted (edited)
function startHandler()
    for _, player in pairs (getElementsByType("player")) do
	    local gangName = getElementData(player, "gang")
		local r, g, b = unpack(getGangColor(gangName))
		setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
		g_playerData[player] = {vehicles = {}, settings = {}}
		g_playerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b))
		addEventHandler("onFreeroamLocalSettingsChange", player, onLocalSettingsChange)
		    if getOption("welcometextonstart") then
			   ouputChatBox("Welcome to Freeroam", player, 0, 255, 0)
			end
	end
end
addEventHandler("onResourceStart", resourceRoot, startHandler)

function joinHandler()
    local gangName = getElementData(source, "gang")
	local r, g, b = unpack(getGangColor(gangName))
	setPlayerNametagColor(source, tonumber(r), tonumber(g), tonumber(b))
	g_playerData[source] = {vehicles = {}, settings = {}}
	g_playerData[source].blip = createBlipAttachedTo(source, 0, 2, tonumber(r), tonumber(g), tonumber(b))
	addEventHandler("onFreeroamLocalSettingsChange", source, onLocalSettingsChange)
	    if getOption("welcometextonstart") then
		   outputChatBox("Welcome to Freeroam", source, 0, 255, 0)
		end
end
addEventHandler("onPlayerJoin", root, joinHandler)

function getGangColor(gangName)
   return exports["gang-system"]:getGangData(gangName, "color")
end

 

Edited by Dimos7

Share this post


Link to post

I'm almost positive I've figured out why it's not calling the colors. It's the SQL - I didn't add it to my script. This is what the  entire Turf script looks like that I've been using for reference:

addEventHandler("onResourceStart", resourceRoot,
function()
	executeSQLQuery("CREATE TABLE IF NOT EXISTS Turf_System ( Turfs TEXT, GangOwner TEXT, r INT, g INT, b INT)")
	--
	local check = executeSQLQuery("SELECT * FROM Turf_System" )
	if #check == 0 then
		for i=1,#turfPos do
			executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0)
		end
	elseif #check > 1 then
		for i = #check, #turfPos do
			executeSQLQuery("INSERT INTO Turf_System(Turfs,GangOwner,r,g,b) VALUES(?,?,?,?,?)", "Turf["..tostring(i).."]", "Nadie", 0, 255, 0)
		end
	end
	
	for i,v in ipairs(turfPos) do
		local sqlData = executeSQLQuery("SELECT * FROM Turf_System WHERE Turfs=?", "Turf["..tostring(i).."]")
		local turfCol = createColCuboid(unpack(v))
		setElementData(turfCol, "getTurfGang", sqlData[1].GangOwner)
		local turfArea = createRadarArea(v[1], v[2], v[4], v[5], sqlData[1].r, sqlData[1].g, sqlData[1].b, 175)
		turfElement[turfCol] = {turfCol, turfArea, i}
		turfTimer[turfCol] = {}
	end
	
	outputDebugString( messages[1] )
end )

addEventHandler ('onPlayerLogin', root,
function ( player )
    local playerGang = getElementData ( player, "gang" )
		if ( playerGang ) then
			local r, g, b = unpack ( getGangColor ( playerGang ) )
			setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
			end
end
)

addEventHandler ( "onColShapeHit", root,
	function ( player )
		if turfElement[source] and source == turfElement[source][1] then
			local turf,area,id = unpack( turfElement[source] )
			local playerGang = getElementData ( player, "gang" )
			local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(id).."]" )
			if ( turfGang[1].GangOwner == playerGang ) then
				outputChatBox( messages[2]:format( turfGang[1].GangOwner or "None" ), player, 0, 255, 0, false )
			else
				local playerGang = getElementData ( player, "gang" )
				setElementData( source, "warTurf", playerGang )
				if ( isTimer ( turfTimer[source][1] ) ) then
					if isTimer( turfTimer[source][2] ) then killTimer( turfTimer[source][2] ) end 
					return 
				end
				if ( playerGang ) then
					local r, g, b = unpack ( getGangColor ( playerGang ) )
					-- local r, g, b = 255, 255, 255
					setRadarAreaFlashing ( area, true )
					if turfGang[1].GangOwner ~= "Nadie" then
						outputChatBox( messages[3]:format( turfGang[1].GangOwner ), player, 0, 255, 0, false )
					else
						outputChatBox( messages[4], player, 0, 255, 0, false )
					end
					
					turfTimer[source][1] = setTimer (
						function ( )
							local players = getGangPlayersInTurf ( turf, playerGang )
							setRadarAreaColor ( area, tonumber(r), tonumber(g), tonumber(b), 175 )
							for _, player in ipairs ( players ) do
								outputChatBox( messages[5], player, 0, 255, 0, false )
								triggerClientEvent(player, "onTakeTurf", player)
								givePlayerMoney ( player, 4000 )
								executeSQLQuery("UPDATE Turf_System SET GangOwner=?,r=?,g=?,b=? WHERE Turfs=?", playerGang, tonumber(r), tonumber(g), tonumber(b), "Turf["..tostring(id).."]" )
								-- setElementData ( turf, "getTurfGang", playerGang )
							end
							setRadarAreaFlashing ( area, false )
						end
					,120000, 1)
				end
			end
		end
	end
)

addEventHandler ( "onColShapeLeave", root, 
	function( player )
		if turfElement[source] and source == turfElement[source][1] then
			if isTimer( turfTimer[source][1] ) then
				local aGang = getElementData( source, "warTurf" )
				local ps = getGangPlayersInTurf( source, aGang )
				if #ps == 0 then
					outputChatBox( messages[6], player, 255, 0, 0 )
					turfTimer[source][2] = setTimer(
						function(source, aGang)
							if isTimer(turfTimer[source][1]) then killTimer(turfTimer[source][1]) end
							setRadarAreaFlashing(turfElement[source][2], false)
							for _, v in ipairs( getElementsByType("player") ) do
								if getElementData(v, "gang") == aGang then
									outputChatBox(messages[7], v, 255, 0, 0)
								end
							end
						end
					, 20000, 1, source, aGang)
				end
			end
		end
	end
)

function getGangPlayersInTurf( turf, gang ) -- element, string
	if turf and gang then
		local players = getElementsWithinColShape ( turf, "player" )
		local gPla = {}
		for _, v in ipairs(	players ) do		
			if getElementData(v, "gang") == gang then
				table.insert(gPla, v)
			end
		end
		return gPla
	end
end

function getGangColor(gangName)
	return exports[ "gang_system" ]:getGangData ( gangName, "color" )
end

 

I'm still learning, but I think what's happening is that it's getting the gang colors and turning them into the table that's needed for the unpack (hence the "bad argument #1 to 'unpack' (table expected, got boolean)) error in my own script. But I don't know where to go from here. Do I modify the SQL so that it just gets colors with none of the turf stuff or is there a simpler way of doing this?

Share this post


Link to post

The turf system has nothing to do with this just make sure that in gang system the getGangData is a table and not a boolen

Share this post


Link to post

That's the problem, it isn't a table and I can't modify it because the code is compiled. https://community.mtasa.com/index.php?p=resources&s=details&id=1514

The reason I'm looking at turf system is because it's somehow still managing to call the colors despite that (when a player takes over a turf, it changes to their gang's color). That's why I'm starting to think the SQL is what's allowing that script to call the colors and why mine isn't working. I don't know what else the problem could be, but I don't know. I could be way off here.

Share this post


Link to post
function startHandler()
    for _, player in pairs (getElementsByType("player")) do
	    local playerGang = getElementData(player, "gang")
    if playerGang then
		local r, g, b = unpack(getGangColor(playerGang))
		setPlayerNametagColor(player, tonumber(r), tonumber(g), tonumber(b))
		g_playerData[player] = {vehicles = {}, settings = {}}
		g_playerData[player].blip = createBlipAttachedTo(player, 0, 2, tonumber(r), tonumber(g), tonumber(b))
		addEventHandler("onFreeroamLocalSettingsChange", player, onLocalSettingsChange)
		    if getOption("welcometextonstart") then
			   ouputChatBox("Welcome to Freeroam", player, 0, 255, 0)
			end
      end
	end
end
addEventHandler("onResourceStart", resourceRoot, startHandler)

function joinHandler()
    local playerGang = getElementData(source, "gang")
  if playerGang then
	local r, g, b = unpack(getGangColor(playerGang))
	setPlayerNametagColor(source, tonumber(r), tonumber(g), tonumber(b))
	g_playerData[source] = {vehicles = {}, settings = {}}
	g_playerData[source].blip = createBlipAttachedTo(source, 0, 2, tonumber(r), tonumber(g), tonumber(b))
	addEventHandler("onFreeroamLocalSettingsChange", source, onLocalSettingsChange)
	    if getOption("welcometextonstart") then
		   outputChatBox("Welcome to Freeroam", source, 0, 255, 0)
		end
    end 
end
addEventHandler("onPlayerJoin", root, joinHandler)

function getGangColor(gangName)
   return exports["gang-system"]:getGangData(gangName, "color")
end

Try this

Share this post


Link to post

A little over a month of trying different things but I've still had no luck on this. Everything I've tried just results in the same dead-end: It won't work unless I restart the resource when a new player joins. I have no idea what's going wrong in the script.

Share this post


Link to post

Try make it in resource restart when a player join and will be shovle your problem

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.