http.Fetch on Murder gamemode?

I want to use “[URL=]http://namey.muffinlabs.com/name.json” in the murder bystander name list, yet i’m not sure how to do it.

I’m not sure how Murder sets its names, but you can do something like this:


for k,v in pairs(player.GetAll()) do
   http.Fetch("http://namey.muffinlabs.com/name.json", function( name )
	v:MurderSetNameFunctionHere( name:sub( 3, #name - 2 ) )
   end)
end

Those are the default names on Murder


GM.BystanderNameParts = {"Alfa",
"Bravo",
"Charlie",
"Delta",
"Echo",
"Foxtrot",
"Golf",
"Hotel",
"India",
"Juliett",
"Kilo",
"Lima",
"Miko",
"November",
"Oscar",
"Papa",
"Quebec",
"Romeo",
"Sierra",
"Tango",
"Uniform",
"Victor",
"Whiskey",
"X-ray",
"Yankee",
"Zulu"
}

And this is the rest of the code (not relevant)


local PlayerMeta = FindMetaTable("Player")
local EntityMeta = FindMetaTable("Entity")

GM.BystanderWords = CreateClientConVar( "mu_bystandername_words", 1, FCVAR_ARCHIVE, "Number of words to generate for bystander name" )

// adds a name to the bystander parts generation table
function GM:AddBystanderNamePart(name)
	table.insert(self.BystanderNameParts, name)
end

// removes a name to the bystander parts generation table
function GM:RemoveBystanderNamePart(name)
	table.RemoveByValue(self.BystanderNameParts, name)
end

// returns the bystander parts generation table
function GM:GetBystanderNameParts()
	return self.BystanderNameParts
end

function GM:GenerateName(words)
	if #self.BystanderNameParts <= 0 then
		return "error"
	end
	local name
	for i = 1, words do
		local word = self.BystanderNameParts[math.random(#self.BystanderNameParts)]
		if !name then
			name = word
		else
			name = name .. " " .. word
		end
	end
	return name
end

function GM:LoadBystanderNames()
	local jason = file.ReadDataAndContent("murder/bystander_name_parts.txt")
	if jason then
		local tbl = {}
		local i = 1
		for name in jason:gmatch("[^
]+") do
			table.insert(tbl, name)
		end
		self.BystanderNameParts = tbl
	end
end

function EntityMeta:GenerateBystanderName()
	local words = math.max(1, GAMEMODE.BystanderWords:GetInt())
	local name = GAMEMODE:GenerateName(words)
	self:SetNWString("bystanderName", name)
	self.BystanderName = name
end

function EntityMeta:SetBystanderName(name)
	self:SetNWString("bystanderName", name)
	self.BystanderName = name
end

function EntityMeta:GetBystanderName()
	local name = self:GetNWString("bystanderName")
	if !name || name == "" then
		return "Bystander" 
	end
	return name
end

concommand.Add("mu_print_players", function (admin, com, args)
	if !admin:IsAdmin() then return end

	for k, ply in pairs(player.GetAll()) do
		local c = ChatText()
		c:Add(ply:Nick())
		local col = ply:GetPlayerColor()
		c:Add(" " .. ply:GetBystanderName(), Color(col.x * 255, col.y * 255, col.z * 255))
		c:Add(" " .. ply:SteamID())
		c:Add(" " .. team.GetName(ply:Team()), team.GetColor(ply:Team()))
		c:Send(admin)
	end
end)

To fix code_gs code, it should be



for k,v in pairs(player.GetAll()) do
   http.Fetch("http://namey.muffinlabs.com/name.json", function( json )
	GAMEMODE:AddBystanderNamePart( util.JSONToTable(json)[1] )
   end)
end


Either one will work in this case, but if for some reason it returns multiple names code_gs code will stop working.