Xfer1111

Country View Troll (Outdated)

Jul 8th, 2020 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. -- [[ Variable Declarations ]] --
  2.  
  3. --// Services
  4.  
  5. local WorkspaceService = game:GetService("Workspace")
  6. local PlayersService = game:GetService("Players")
  7. local RunService = game:GetService("RunService")
  8. local HttpService = game:GetService("HttpService")
  9.  
  10. --// Client
  11.  
  12. local Client = PlayersService.LocalPlayer
  13. local Camera = WorkspaceService.CurrentCamera
  14.  
  15. --// Collection
  16.  
  17. local Codes = {}
  18. local Listings = {}
  19.  
  20. -- [[ Function Declarations ]] --
  21.  
  22. local function CreateCountryListing(Player)
  23.    local CountryCode = get_hidden_prop(Player, "CountryRegionCodeReplicate")
  24.    local Country = Codes[CountryCode] or "Unknown Code: " .. CountryCode
  25.  
  26.    local Text = Drawing.new("Text")
  27.  
  28.    Text.Transparency = 1
  29.    Text.Text = Country
  30.    Text.Center = true
  31.    Text.Color = Color3.new(1, 1, 1)
  32.  
  33.    local Flag = Drawing.new("Image")
  34.  
  35.    Flag.Uri = "https://www.countryflags.io/" .. CountryCode .. "/shiny/64.png"
  36.    Flag.Transparency = 1
  37.  
  38.    Listings[Player] = {
  39.        Text = Text,
  40.        Flag = Flag
  41.    }
  42. end
  43.  
  44. local function UpdateListing(Listing, Player)
  45.    local Text = Listing.Text
  46.    local Flag = Listing.Flag
  47.  
  48.    local Character = Player.Character
  49.  
  50.    if (Character) then
  51.        local Head = Character:FindFirstChild("Head")
  52.  
  53.        if (Head) then
  54.            local CameraSize = Camera.ViewportSize
  55.  
  56.            local WorldPosition = Head.Position + Vector3.new(0, 3, 0)
  57.            local Position, Visible = Camera:WorldToViewportPoint(WorldPosition)
  58.            local Transparency = 1 - math.clamp(Position.Z / 25, 0, 1)
  59.  
  60.            Text.Visible = Visible
  61.            Text.Position = Vector2.new(Position.X, Position.Y)
  62.            Text.Size = CameraSize.X * 0.01
  63.            Text.Transparency = Transparency
  64.  
  65.            local TextBounds = Text.TextBounds
  66.  
  67.            Flag.Visible = Visible
  68.            Flag.ScaleFactor = .5
  69.            Flag.Position = Vector2.new(Position.X + TextBounds.X / 2 + 10, Position.Y - TextBounds.Y / 4)
  70.            Flag.Transparency = Transparency
  71.        end
  72.    else
  73.        Text.Visible = false
  74.        Flag.Visible = false
  75.    end
  76. end
  77.  
  78. -- [[ Init ]] --
  79.  
  80. do
  81.    --// Generate CountryCode to Country Pairing
  82.  
  83.    local Body = game:HttpGet("http://country.io/names.json")
  84.    local Info = HttpService:JSONDecode(Body)
  85.  
  86.    for Code, Country in pairs(Info) do
  87.        Codes[Code] = Country
  88.    end
  89. end
  90.  
  91. do
  92.    --// Create Country Listings
  93.  
  94.    local Players = PlayersService:GetPlayers()
  95.  
  96.    for _, Player in pairs(Players) do
  97.        --if (Player == Client) then continue end
  98.  
  99.        CreateCountryListing(Player)
  100.    end
  101.  
  102.    PlayersService.PlayerAdded:Connect(CreateCountryListing)
  103. end
  104.  
  105. do
  106.    --// Update Listings
  107.  
  108.    RunService.Heartbeat:Connect(function()
  109.        for Player, Listing in pairs(Listings) do
  110.            UpdateListing(Listing, Player)
  111.  
  112.            if (not Player) then
  113.                Listing.Text.Visible = false
  114.                Listing.Flag.Visible = false
  115.            end
  116.        end
  117.    end)
  118. end
Add Comment
Please, Sign In to add comment