Jump to content

Country chat


Recommended Posts

No.

The default admin resource that comes with the default MTA server has an exported function getPlayerCountry.

the whole resource based on getPlayerIp() as i can see here

function getPlayerCountry ( player ) 
    return getIpCountry ( getPlayerIP ( player ) ) 
end 
  
function getIpCountry ( ip ) 
    local ip_group = tonumber ( gettok ( ip, 1, 46 ) ) 
    local ip_code = ( gettok ( ip, 1, 46 ) * 16777216 ) + ( gettok ( ip, 2, 46 ) * 65536 ) + ( gettok ( ip, 3, 46 ) * 256 ) + ( gettok ( ip, 4, 46 ) ) 
    if ( #aCountries == 0 ) then 
        loadIPGroups () 
    end 
    if ( not aCountries[ip_group] ) then 
        aCountries[ip_group] = {} 
    end 
    for id, group in ipairs ( aCountries[ip_group] ) do 
        if ( ( group.rstart <= ip_code ) and ( ip_code <= group.rend ) ) then 
            return group.rcountry 
        end 
    end 
    return false 
end 

Link to comment
for example i want make it if its from germany say the germany in chat so i need do is if
getPlayerCountry(player) == "germany"? 

local countryCode = getPlayerCountry(player)  
if countryCode then  
   if countryCode == "DE" then  
-- Your code 
  
   end  
end  

Link to comment

You can also do like that

countriesName = { 
    ["DE"] = "Geremany", 
    ["PL"] = "Poland", 
    ["RU"] = "Russia", 
    ... 
} 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        local countryShort = exports.admin:getPlayerCountry ( source ) 
        local countryName = countriesName [ countryShort ] and countriesName [ countryShort ] or "Unknown"; 
        if ( countryName ) then 
            outputChatBox ( "* " .. getPlayerName ( source ) .. " has joined the game from " .. countryName, root, 255, 255, 255, true ); 
        end 
    end 
); 

Link to comment

I've found PHP array which contain all countries name and I converted it to LUA

countriesName = { 
    ["AF"] = "Afghanistan", 
    ["AX"] = "Aland Islands", 
    ["AL"] = "Albania", 
    ["DZ"] = "Algeria", 
    ["AS"] = "American Samoa", 
    ["AD"] = "Andorra", 
    ["AO"] = "Angola", 
    ["AI"] = "Anguilla", 
    ["AQ"] = "Antarctica", 
    ["AG"] = "Antigua And Barbuda", 
    ["AR"] = "Argentina", 
    ["AM"] = "Armenia", 
    ["AW"] = "Aruba", 
    ["AU"] = "Australia", 
    ["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 And Herzegovina", 
    ["BW"] = "Botswana", 
    ["BV"] = "Bouvet Island", 
    ["BR"] = "Brazil", 
    ["IO"] = "British Indian Ocean Territory", 
    ["BN"] = "Brunei Darussalam", 
    ["BG"] = "Bulgaria", 
    ["BF"] = "Burkina Faso", 
    ["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", 
    ["CG"] = "Congo", 
    ["CD"] = "Congo, Democratic Republic", 
    ["CK"] = "Cook Islands", 
    ["CR"] = "Costa Rica", 
    ["CI"] = "Cote D'Ivoire", 
    ["HR"] = "Croatia", 
    ["CU"] = "Cuba", 
    ["CY"] = "Cyprus", 
    ["CZ"] = "Czech Republic", 
    ["DK"] = "Denmark", 
    ["DJ"] = "Djibouti", 
    ["DM"] = "Dominica", 
    ["DO"] = "Dominican Republic", 
    ["EC"] = "Ecuador", 
    ["EG"] = "Egypt", 
    ["SV"] = "El Salvador", 
    ["GQ"] = "Equatorial Guinea", 
    ["ER"] = "Eritrea", 
    ["EE"] = "Estonia", 
    ["ET"] = "Ethiopia", 
    ["FK"] = "Falkland Islands (Malvinas)", 
    ["FO"] = "Faroe Islands", 
    ["FJ"] = "Fiji", 
    ["FI"] = "Finland", 
    ["FR"] = "France", 
    ["GF"] = "French Guiana", 
    ["PF"] = "French Polynesia", 
    ["TF"] = "French Southern Territories", 
    ["GA"] = "Gabon", 
    ["GM"] = "Gambia", 
    ["GE"] = "Georgia", 
    ["DE"] = "Germany", 
    ["GH"] = "Ghana", 
    ["GI"] = "Gibraltar", 
    ["GR"] = "Greece", 
    ["GL"] = "Greenland", 
    ["GD"] = "Grenada", 
    ["GP"] = "Guadeloupe", 
    ["GU"] = "Guam", 
    ["GT"] = "Guatemala", 
    ["GG"] = "Guernsey", 
    ["GN"] = "Guinea", 
    ["GW"] = "Guinea-Bissau", 
    ["GY"] = "Guyana", 
    ["HT"] = "Haiti", 
    ["HM"] = "Heard Island & Mcdonald Islands", 
    ["VA"] = "Holy See (Vatican City State)", 
    ["HN"] = "Honduras", 
    ["HK"] = "Hong Kong", 
    ["HU"] = "Hungary", 
    ["IS"] = "Iceland", 
    ["IN"] = "India", 
    ["ID"] = "Indonesia", 
    ["IR"] = "Iran, Islamic Republic Of", 
    ["IQ"] = "Iraq", 
    ["IE"] = "Ireland", 
    ["IM"] = "Isle Of Man", 
    ["IL"] = "Israel", 
    ["IT"] = "Italy", 
    ["JM"] = "Jamaica", 
    ["JP"] = "Japan", 
    ["JE"] = "Jersey", 
    ["JO"] = "Jordan", 
    ["KZ"] = "Kazakhstan", 
    ["KE"] = "Kenya", 
    ["KI"] = "Kiribati", 
    ["KR"] = "Korea", 
    ["KW"] = "Kuwait", 
    ["KG"] = "Kyrgyzstan", 
    ["LA"] = "Lao People's Democratic Republic", 
    ["LV"] = "Latvia", 
    ["LB"] = "Lebanon", 
    ["LS"] = "Lesotho", 
    ["LR"] = "Liberia", 
    ["LY"] = "Libyan Arab Jamahiriya", 
    ["LI"] = "Liechtenstein", 
    ["LT"] = "Lithuania", 
    ["LU"] = "Luxembourg", 
    ["MO"] = "Macao", 
    ["MK"] = "Macedonia", 
    ["MG"] = "Madagascar", 
    ["MW"] = "Malawi", 
    ["MY"] = "Malaysia", 
    ["MV"] = "Maldives", 
    ["ML"] = "Mali", 
    ["MT"] = "Malta", 
    ["MH"] = "Marshall Islands", 
    ["MQ"] = "Martinique", 
    ["MR"] = "Mauritania", 
    ["MU"] = "Mauritius", 
    ["YT"] = "Mayotte", 
    ["MX"] = "Mexico", 
    ["FM"] = "Micronesia, Federated States Of", 
    ["MD"] = "Moldova", 
    ["MC"] = "Monaco", 
    ["MN"] = "Mongolia", 
    ["ME"] = "Montenegro", 
    ["MS"] = "Montserrat", 
    ["MA"] = "Morocco", 
    ["MZ"] = "Mozambique", 
    ["MM"] = "Myanmar", 
    ["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", 
    ["NF"] = "Norfolk Island", 
    ["MP"] = "Northern Mariana Islands", 
    ["NO"] = "Norway", 
    ["OM"] = "Oman", 
    ["PK"] = "Pakistan", 
    ["PW"] = "Palau", 
    ["PS"] = "Palestinian Territory, Occupied", 
    ["PA"] = "Panama", 
    ["PG"] = "Papua New Guinea", 
    ["PY"] = "Paraguay", 
    ["PE"] = "Peru", 
    ["PH"] = "Philippines", 
    ["PN"] = "Pitcairn", 
    ["PL"] = "Poland", 
    ["PT"] = "Portugal", 
    ["PR"] = "Puerto Rico", 
    ["QA"] = "Qatar", 
    ["RE"] = "Reunion", 
    ["RO"] = "Romania", 
    ["RU"] = "Russian Federation", 
    ["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 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", 
    ["GS"] = "South Georgia And Sandwich Isl.", 
    ["ES"] = "Spain", 
    ["LK"] = "Sri Lanka", 
    ["SD"] = "Sudan", 
    ["SR"] = "Suriname", 
    ["SJ"] = "Svalbard And Jan Mayen", 
    ["SZ"] = "Swaziland", 
    ["SE"] = "Sweden", 
    ["CH"] = "Switzerland", 
    ["SY"] = "Syrian Arab Republic", 
    ["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", 
    ["UM"] = "United States Outlying Islands", 
    ["UY"] = "Uruguay", 
    ["UZ"] = "Uzbekistan", 
    ["VU"] = "Vanuatu", 
    ["VE"] = "Venezuela", 
    ["VN"] = "Viet Nam", 
    ["VG"] = "Virgin Islands, British", 
    ["VI"] = "Virgin Islands, U.S.", 
    ["WF"] = "Wallis And Futuna", 
    ["EH"] = "Western Sahara", 
    ["YE"] = "Yemen", 
    ["ZM"] = "Zambia", 
    ["ZW"] = "Zimbabwe", 
} 

Link to comment

might this help you ;)

countryNames = { 
    ['AD'] = 'Andorra', 
    ['AE'] = 'United Arab Emirates', 
    ['AF'] = 'Afghanistan', 
    ['AG'] = 'Antigua and Barbuda', 
    ['AI'] = 'Anguilla', 
    ['AL'] = 'Albania', 
    ['AM'] = 'Armenia', 
    ['AO'] = 'Angola', 
    ['AP'] = 'ARIPO', 
    ['AR'] = 'Argentina', 
    ['AT'] = 'Austria', 
    ['AU'] = 'Australia', 
    ['AW'] = 'Aruba', 
    ['AZ'] = 'Azerbaijan', 
    ['BA'] = 'Bosnia and Herzegovina', 
    ['BB'] = 'Barbados', 
    ['BD'] = 'Bangladesh', 
    ['BE'] = 'Belgium', 
    ['BF'] = 'Burkina Faso', 
    ['BG'] = 'Bulgaria', 
    ['BH'] = 'Bahrain', 
    ['BI'] = 'Burundi', 
    ['BJ'] = 'Benin', 
    ['BM'] = 'Bermuda', 
    ['BN'] = 'Brunei Darussalam', 
    ['BO'] = 'Bolivia', 
    ['BQ'] = 'Bonaire', 
    ['BR'] = 'Brazil', 
    ['BS'] = 'Bahamas', 
    ['BT'] = 'Bhutan', 
    ['BV'] = 'Bouvet Island', 
    ['BW'] = 'Botswana', 
    ['BY'] = 'Belarus', 
    ['BZ'] = 'Belize', 
    ['CA'] = 'Canada', 
    ['CD'] = 'Congo', 
    ['CF'] = 'Central African Republic', 
    ['CG'] = 'Congo', 
    ['CH'] = 'Switzerland', 
    ['CI'] = 'Cote d?Ivoire', 
    ['CK'] = 'Cook Islands', 
    ['CL'] = 'Chile', 
    ['CM'] = 'Cameroon', 
    ['CN'] = 'China', 
    ['CO'] = 'Colombia', 
    ['CR'] = 'Costa Rica', 
    ['CU'] = 'Cuba', 
    ['CV'] = 'Cape Verde', 
    ['CW'] = 'Curacao', 
    ['CY'] = 'Cyprus', 
    ['CZ'] = 'Czech Republic', 
    ['DE'] = 'Germany', 
    ['DJ'] = 'Djibouti', 
    ['DK'] = 'Denmark', 
    ['DM'] = 'Dominica', 
    ['DO'] = 'Dominican Republic', 
    ['DZ'] = 'Algeria', 
    ['EC'] = 'Ecuador', 
    ['EE'] = 'Estonia', 
    ['EG'] = 'Egypt', 
    ['EH'] = 'Western Sahara', 
    ['ER'] = 'Eritrea', 
    ['ES'] = 'Spain', 
    ['ET'] = 'Ethiopia', 
    ['FI'] = 'Finland', 
    ['FJ'] = 'Fiji', 
    ['FK'] = 'Malvinas', 
    ['FO'] = 'Faroe Islands', 
    ['FR'] = 'France', 
    ['GA'] = 'Gabon', 
    ['GB'] = 'United Kingdom', 
    ['GD'] = 'Grenada', 
    ['GE'] = 'Georgia', 
    ['GG'] = 'Guernsey', 
    ['GH'] = 'Ghana', 
    ['GI'] = 'Gibraltar', 
    ['GL'] = 'Greenland', 
    ['GM'] = 'Gambia', 
    ['GN'] = 'Guinea', 
    ['GQ'] = 'Equatorial Guinea', 
    ['GR'] = 'Greece', 
    ['GT'] = 'Guatemala', 
    ['GW'] = 'Guinea-Bissau', 
    ['GY'] = 'Guyana', 
    ['HN'] = 'Honduras', 
    ['HR'] = 'Croatia', 
    ['HT'] = 'Haiti', 
    ['HU'] = 'Hungary', 
    ['ID'] = 'Indonesia', 
    ['IE'] = 'Ireland', 
    ['IL'] = 'Palestine', 
    ['IM'] = 'Isle of Man', 
    ['IN'] = 'India', 
    ['IQ'] = 'Iraq', 
    ['IR'] = 'Iran', 
    ['IS'] = 'Iceland', 
    ['IT'] = 'Italy', 
    ['JE'] = 'Jersey', 
    ['JM'] = 'Jamaica', 
    ['JO'] = 'Jordan', 
    ['JP'] = 'Japan', 
    ['KE'] = 'Kenya', 
    ['KG'] = 'Kyrgyzstan', 
    ['KH'] = 'Cambodia', 
    ['KI'] = 'Kiribati', 
    ['KM'] = 'Comoros', 
    ['KN'] = 'Saint Kitts and Nevis', 
    ['KP'] = 'Korea', 
    ['KR'] = 'Korea', 
    ['KW'] = 'Kuwait', 
    ['KY'] = 'Cayman Islands', 
    ['KZ'] = 'Kazakhstan', 
    ['LA'] = 'Lao People?s Republic', 
    ['LB'] = 'Lebanon', 
    ['LC'] = 'Saint Lucia', 
    ['LI'] = 'Liechtenstein', 
    ['LK'] = 'Sri Lanka', 
    ['LR'] = 'Liberia', 
    ['LS'] = 'Lesotho', 
    ['LT'] = 'Lithuania', 
    ['LU'] = 'Luxembourg', 
    ['LV'] = 'Latvia', 
    ['LY'] = 'Libyan Arab Jamahiriya', 
    ['MA'] = 'Morocco', 
    ['MC'] = 'Monaco', 
    ['MD'] = 'Moldova', 
    ['ME'] = 'Montenegro', 
    ['MG'] = 'Madagascar', 
    ['MK'] = 'Macedonia', 
    ['ML'] = 'Mali', 
    ['MM'] = 'Myanmar', 
    ['MN'] = 'Mongolia', 
    ['MO'] = 'Macao', 
    ['MP'] = 'Northern Mariana Islands', 
    ['MR'] = 'Mauritania', 
    ['MS'] = 'Montserrat', 
    ['MT'] = 'Malta', 
    ['MU'] = 'Mauritius', 
    ['MV'] = 'Maldives', 
    ['MW'] = 'Malawi', 
    ['MX'] = 'Mexico', 
    ['MY'] = 'Malaysia', 
    ['MZ'] = 'Mozambique', 
    ['NA'] = 'Namibia', 
    ['NE'] = 'Niger', 
    ['NG'] = 'Nigeria', 
    ['NI'] = 'Nicaragua', 
    ['NL'] = 'Netherlands', 
    ['NO'] = 'Norway', 
    ['NP'] = 'Nepal', 
    ['NR'] = 'Nauru', 
    ['NZ'] = 'New Zealand', 
    ['OM'] = 'Oman', 
    ['PA'] = 'Panama', 
    ['PE'] = 'Peru', 
    ['PG'] = 'Papua New Guinea', 
    ['PH'] = 'Philippines', 
    ['PK'] = 'Pakistan', 
    ['PL'] = 'Poland', 
    ['PT'] = 'Portugal', 
    ['PW'] = 'Palau', 
    ['PY'] = 'Paraguay', 
    ['QA'] = 'Qatar', 
    ['RO'] = 'Romania', 
    ['RS'] = 'Serbia', 
    ['RU'] = 'Russian Federation', 
    ['RW'] = 'Rwanda', 
    ['SA'] = 'Saudi Arabia', 
    ['SB'] = 'Solomon Islands', 
    ['SC'] = 'Seychelles', 
    ['SD'] = 'Sudan', 
    ['SE'] = 'Sweden', 
    ['SG'] = 'Singapore', 
    ['SH'] = 'Saint Helena', 
    ['SI'] = 'Slovenia', 
    ['SK'] = 'Slovakia', 
    ['SL'] = 'Sierra Leone', 
    ['SM'] = 'San Marino', 
    ['SN'] = 'Senegal', 
    ['SO'] = 'Somalia', 
    ['SR'] = 'Suriname', 
    ['ST'] = 'Sao Tome and Principe', 
    ['SV'] = 'Salvador', 
    ['SX'] = 'Sint Maarten (Dutch part)', 
    ['SY'] = 'Syrian Arab Republic', 
    ['SZ'] = 'Swaziland', 
    ['TC'] = 'Turks and Caicos Islands', 
    ['TD'] = 'Chad', 
    ['TG'] = 'Togo', 
    ['TH'] = 'Thailand', 
    ['TJ'] = 'Tajikistan', 
    ['TL'] = 'Timor?Leste', 
    ['TM'] = 'Turkmenistan', 
    ['TN'] = 'Tunisia', 
    ['TO'] = 'Tonga', 
    ['TR'] = 'Turkey', 
    ['TT'] = 'Trinidad and Tobago', 
    ['TV'] = 'Tuvalu', 
    ['TW'] = 'Taiwan', 
    ['TZ'] = 'Tanzania', 
    ['UA'] = 'Ukraine', 
    ['UG'] = 'Uganda', 
    ['US'] = 'United States of America', 
    ['UY'] = 'Uruguay', 
    ['UZ'] = 'Uzbekistan', 
    ['VA'] = 'Holy See', 
    ['VC'] = 'Saint Vincent', 
    ['VE'] = 'Venezuela', 
    ['VG'] = 'Virgin Islands', 
    ['VN'] = 'Viet Nam', 
    ['VU'] = 'Vanuatu', 
    ['WS'] = 'Samoa', 
    ['YE'] = 'Yemen', 
    ['ZA'] = 'South Africa', 
    ['ZZ'] = 'N/A', 
    ['ZM'] = 'Zambia', 
    ['ZW'] = 'Zimbabwe', 
}; 
  
function countryChat( thePlayer, cmd, ... ) 
    local msg = table.concat( { ... }, ' ' ); 
    for _, players in ipairs( getElementsByType( 'player' ) ) do 
     
        local myCountry = exports['admin']:getPlayerCountry( thePlayer ); 
        local playersInMyCountry = exports['admin']:getPlayerCountry( players ); 
         
        if ( playersInMyCountry == myCountry and msg and msg ~= '' ) then 
            outputChatBox( countryNames[ myCountry ].. ' : '..getPlayerName( thePlayer )..': #FFFFFF'..msg..'', players, 255, 255, 255, true ); 
        end 
    end 
end 
addCommandHandler( 'country', countryChat ); 
  
addEventHandler( 'onPlayerJoin',root, 
    function( ) 
        bindKey( source, 'l', 'down', 'chatbox', 'country' ); 
    end 
); 
  
addEventHandler( 'onResourceStart', resourceRoot, 
    function ( ) 
        for _, player in ipairs( getElementsByType( 'player' ) ) do 
            bindKey( player, 'l', 'down', 'chatbox', 'country' ); 
        end 
    end 
); 

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