Jump to content

gsub player name


Recommended Posts

Hello guys, I have a problem, I'm trying to hide hex colors from a grid list and it didn't work

    for id,player in ipairs(getElementsByType("player")) do
      local row = guiGridListAddRow(gridlist)
	  setTimer ( guiGridListSetItemText , 100 , 1 , gridlist, row, column, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false ) 
    end

any help please?

Link to post

Hey,

You can use guiGridListAddRow to add a row and row data instead using the guiGridListSetItemText.

This should work:

for _, player in ipairs(getElementsByType("player")) do
	setTimer(guiGridListAddRow, 100, 1, playerList, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""))
end


BTW if there are many players it's not really good (in performance aspect) to create timers when adding them in the gridlist like this.

Edited by SpecT
Link to post

I still can click only to players with no hex, I think this is the problem

getPlayerFromName(guiGridListGetItemText(gridOpenSenior, guiGridListGetSelectedItem(gridOpenSenior), 1))

can gsub be added to this?

Link to post

I prefer this useful function for such stuff:

function getPlayerFromNamePart(name)
	if (name) then 
		for _, player in ipairs (getElementsByType("player")) do
			local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
			if name_:find(tostring(name):lower(), 1, true) then
				return player 
			end
		end
	end
end

Then it will be like this:

getPlayerFromNamePart(guiGridListGetItemText(gridOpenSenior, guiGridListGetSelectedItem(gridOpenSenior), 1))

PS: This function is used when you need to find a player by a part of his nick (i.e. in a command for something).

Edited by SpecT
  • Thanks 1
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...