Jump to content

Scoreboard flags not showing


Ryan2233

Recommended Posts

I quickly roughed up a script that should theoretically show flags of the user in the scoreboard. But the flags and the flag column doesn't show. The flag script is separate from the main scoreboard.



countryNames = {
    ["IT"]="Italy",
    ["MX"]="Mexico",
    ["SA"]="SAUDI ARBIA",
    ["PK"]="Pakistan",
    ["AF"]="Afghanistan",
    ["DZ"]="Algeria",
    ["AS"]="American samoa",
    ["AU"]="Australlia",
    ["AO"]="Anqola",
    ["AI"]="Anquilla",
    ["AQ"]="Antarctica",
    ["AG"]="Antigua and Barbuda",
    ["AR"]="Argentina",
    ["AM"]="Armenia",
    ["AW"]="Aruba",
    ["AT"]="Austria",
    ["AZ"]="Azerbaijan",
    ["BS"]="Bahamas",
    ["BH"]="Bahrain",
    ["BD"]="Bangladesh",
    ["BB"]="Barbados",
    ["BY"]="Belarus",
    ["BE"]="Belgium",
    ["BZ"]="Belize",
    ["BJ"]="Benin",
    ["BM"]="Bermuda",
    ["BT"]="Bhutan",
    ["BO"]="Bolivia",
    ["BA"]="Bosnia",
    ["BH"]="Herzegovina",
    ["BW"]="Botswana",
    ["BR"]="Brazil",
    ["IO"]="British Indian Ocean Territory",
    ["VG"]="British Virgin Islands",
    ["BN"]="Brunei",
    ["BG"]="Bulgaria",
    ["BF"]="Burkina Faso",
    ["MM"]="Burma (Myanmar)",
    ["BI"]="Burundi",
    ["KH"]="Cambodia",
    ["CM"]="Cameroon",
    ["CA"]="Canada",
    ["CV"]="Cape Verde",
    ["KY"]="Cayman Islands",
    ["CF"]="Central African Republic",
    ["TD"]="Chad",
    ["CL"]="Chile",
    ["CN"]="China",
    ["CX"]="Christmas Island",
    ["CC"]="Cocos (Keeling) Islands",
    ["CO"]="Colombia",
    ["KM"]="Comoros",
    ["CK"]="Cook Islands",
    ["CR"]="Costa Rica",
    ["HR"]="Croatia",
    ["CU"]="Cuba",
    ["CY"]="Cyprus",
    ["CZ"]="Czech Republic",
    ["CD"]="Democratic Republic of the Congo",
    ["DK"]="Denmark",
    ["DJ"]="Djibouti",
    ["DM"]="Dominica",
    ["DO"]="Dominican Republic",
    ["EC"]="Ecuador",
    ["SV"]="El Salvador",
    ["GQ"]="Equatorial Guinea",
    ["ER"]="Eritrea",
    ["EE"]="Estonia",
    ["ET"]="Ethiopia",
    ["FK"]="Falkland Islands",
    ["FO"]="Faroe Islands",
    ["FJ"]="Fiji",
    ["FI"]="Finland",
    ["FR"]="France",
    ["PF"]="French Polynesia",
    ["GA"]="Gabon",
    ["GM"]="Gambia",
    ["GE"]="Georgia",
    ["DE"]="Germany",
    ["GH"]="Ghana",
    ["GI"]="Gibraltar",
    ["GR"]="Greece",
    ["GL"]="Greenland",
    ["GD"]="Grenada",
    ["GU"]="Guam",
    ["GT"]="Guatemala",
    ["GN"]="Guinea",
    ["GW"]="Guinea-Bissau",
    ["GY"]="Guyana",
    ["HT"]="Haiti",
    ["VA"]="Holy See (Vatican City)",
    ["HN"]="Honduras",
    ["HK"]="Hong Kong",
    ["HU"]="Hungary",
    ["IS"]="Iceland",
    ["IN"]="India",
    ["ID"]="Indonesia",
    ["IR"]="Iran",
    ["IQ"]="Iraq",
    ["IE"]="Ireland",
    ["IM"]="Isle of Man",
    ["IL"]="Israel",
    ["IT"]="Italy",
    ["CI"]="Ivory Coast",
    ["JM"]="Jamaica",
    ["JP"]="Japan",
    ["JE"]="Jersey",
    ["JO"]="Jordan",
    ["KZ"]="Kazakhstan",
    ["KE"]="Kenya",
    ["KI"]="Kiribati",
    ["KO"]="Kosovo",
    ["KW"]="Kuwait",
    ["KG"]="Kyrgyzstan",
    ["LA"]="Laos",
    ["LV"]="Latvia",
    ["LB"]="Lebanon",
    ["LS"]="Lesotho",
    ["LR"]="Liberia",
    ["LY"]="Libya",
    ["LI"]="Liechtenstein",
    ["LT"]="Lithuania",
    ["LU"]="Luxembourg",
    ["MO"]="Macau",
    ["MK"]="Macedonia",
    ["MG"]="Madagascar",
    ["MW"]="Malawi",
    ["MY"]="Malaysia",
    ["MV"]="Maldives",
    ["ML"]="Mali",
    ["MT"]="Malta",
    ["MH"]="Marshall Islands",
    ["MR"]="Mauritania",
    ["MU"]="Mauritius",
    ["YT"]="Mayotte",
    ["MX"]="Mexico",
    ["FM"]="Micronesia",
    ["MD"]="Moldova",
    ["MC"]="Monaco",
    ["MN"]="Mongolia",
    ["ME"]="Montenegro",    
    ["MS"]="Montserrat",
    ["MA"]="Morocco",
    ["MZ"]="Mozambique",
    ["NA"]="Namibia",
    ["NR"]="Nauru",
    ["NP"]="Nepal",
    ["NL"]="Netherlands",
    ["AN"]="Netherlands Antilles",
    ["NC"]="New Caledonia",
    ["NZ"]="New Zealand",
    ["NI"]="Nicaragua",
    ["NE"]="Niger",
    ["NG"]="Nigeria",
    ["NU"]="Niue",
    ["NI"]="Norfolk Island",
    ["KP"]="North Korea",
    ["MP"]="Northern Mariana Islands",
    ["NO"]="Norway",
    ["OM"]="Oman",
    ["PK"]="Pakistan",
    ["PW"]="Palau",
    ["PA"]="Panama",
    ["PG"]="Papua New Guinea",
    ["PY"]="Paraguay",
    ["PE"]="Peru",
    ["PH"]="Philippines",
    ["PN"]="Pitcairn Islands",
    ["PL"]="Poland",
    ["PT"]="Portugal",
    ["PR"]="Puerto Rico",
    ["QA"]="Qatar",
    ["CG"]="Republic of the Congo",
    ["RO"]="Romania",
    ["RU"]="Russia",
    ["RW"]="Rwanda",
    ["BL"]="Saint Barthelemy",
    ["SH"]="Saint Helena",
    ["KN"]="Saint Kitts and Nevis",
    ["LC"]="Saint Lucia",
    ["MF"]="Saint Martin",
    ["PM"]="Saint Pierre and Miquelon",
    ["VC"]="Saint Vincent and the Grenadines",
    ["WS"]="Samoa",
    ["SM"]="San Marino",
    ["ST"]="Sao Tome and Principe",
    ["SA"]="Saudi Arabia",
    ["SN"]="Senegal",
    ["RS"]="Serbia",
    ["SC"]="Seychelles",
    ["SL"]="Sierra Leone",
    ["SG"]="Singapore",
    ["SK"]="Slovakia",
    ["SI"]="Slovenia",
    ["SB"]="Solomon Islands",
    ["SO"]="Somalia",
    ["ZA"]="South Africa",
    ["KR"]="South Korea",
    ["ES"]="Spain",
    ["LK"]="Sri Lanka",
    ["SD"]="Sudan",
    ["SR"]="Suriname",
    ["SJ"]="Svalbard",
    ["SZ"]="Swaziland",
    ["SE"]="Sweden",
    ["CH"]="Switzerland",
    ["SY"]="Syria",
    ["TW"]="Taiwan",
    ["TJ"]="Tajikistan",
    ["TZ"]="Tanzania",
    ["TH"]="Thailand",
    ["TL"]="Timor-Leste",
    ["TG"]="Togo",
    ["TK"]="Tokelau",
    ["TO"]="Tonga",
    ["TT"]="Trinidad and Tobago",
    ["TN"]="Tunisia",
    ["TR"]="Turkey",
    ["TM"]="Turkmenistan",
    ["TC"]="Turks and Caicos Islands",
    ["TV"]="Tuvalu",
    ["UG"]="Uganda",
    ["UA"]="Ukraine",
    ["AE"]="United Arab Emirates",
    ["GB"]="United Kingdom",
    ["US"]="United States",
    ["UY"]="Uruguay",
    ["VI"]="US Virgin Islands",
    ["UZ"]="Uzbekistan",
    ["VU"]="Vanuatu",
    ["VE"]="Venezuela",
    ["VN"]="Vietnam",
    ["WF"]="Wallis and Futuna",
    ["WB"]="West Bank",
    ["EH"]="Western Sahara",
    ["YE"]="Yemen",
    ["ZM"]="Zambia",
    ["ZW"]="Zimbabwe",
    ["EG"]="Egypt"
}

function OnResourceStart()
	call(getResourceFromName("SAGSscoreboard"),"addScoreboardColumn","Country", getRootElement(), 10, 150)

	

    local tPlayers = getElementsByType('player')
    for _,uPlayer in ipairs(tPlayers) do
		local countryCode = exports["admin"]:getPlayerCountry(uPlayer)
		local name = "Unknown"
			
		if countryCode and countryNames[countryCode] then
			name = countryNames[countryCode]
			
			local sFlagImagePath = ':'..getResourceName( getThisResource() )..'/flags/'..string.lower(countryCode)..'.png'
			if fileExists(sFlagImagePath) then
				setElementData(uPlayer, "countryFlagImage", sFlagImagePath )
			else
				setElementData(uPlayer, "countryFlagImage", "??" )
			end
		end
		setElementData(uPlayer, "Country", name )
	end
end
     


addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), OnResourceStart)
 
function OnPlayerJoin ()
    local countryCode = exports["admin"]:getPlayerCountry(source)
	local name = "Unknown"
	if countryCode and countryNames[countryCode] then
		name = countryNames[countryCode]
		local sFlagImagePath = ':'..getResourceName( getThisResource() )..'/flags/'..string.lower(countryCode)..'.png'
		if fileExists(sFlagImagePath) then
			setElementData( source, "countryFlagImage", sFlagImagePath )
		else
			setElementData( source, "countryFlagImage", "??" )
		end
	end
 setElementData(source, "Country", name) 
  
end
addEventHandler("onPlayerJoin", getRootElement(), OnPlayerJoin)

 

Link to comment

I'm from phone so can't give any code but i did notice one thing. You can't set the flag just by setting element data as you can other things. To put flags in the scoreboard you have to use dxDrawImage. I'll give you my scoreboard's flags lines tomorrow so you see how it's made. I can give you my modified scoreboard actually. It puts flags and full country names in column called "Country". Reply here if you want it. (It didn't work by using a 3rd party resource for me neither when i tried to use one from community.)

Link to comment
9 minutes ago, koragg said:

I'm from phone so can't give any code but i did notice one thing. You can't set the flag just by setting element data as you can other things. To put flags in the scoreboard you have to use dxDrawImage. I'll give you my scoreboard's flags lines tomorrow so you see how it's made. I can give you my modified scoreboard actually. It puts flags and full country names in column called "Country". Reply here if you want it. (It didn't work by using a 3rd party resource for me neither when i tried to use one from community.)

That would be great! Thank you. 

Link to comment

Actually, you don't need a modified scoreboard resource to display images. You need to, however, properly set up the element data.

local data = {
  type = "image",
  src = ":(name of resource with the images)/(path to image).png",
  color = tocolor(255,255,255,255),
  width = 20,
  height = 20
}
setElementData(element, elementdataKey, data)

This is adapted from the "voice" resource https://github.com/multitheftauto/mtasa-resources/blob/master/[gameplay]/voice/cPlayerMuting.lua#L4-L26

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