#Paper Posted March 24, 2011 Share Posted March 24, 2011 The table.string in bad argument function getPlayer(thePlayer) local players = {} for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) local playerName = playerName:gsub("#%x%x%x%x%x%x", "") table.insert(players, playerName) end if string.find(players, thePlayer) then return playerName else return false end end Link to comment
Castillo Posted March 24, 2011 Share Posted March 24, 2011 function getPlayer(thePlayer) local players = {} for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) local playerName = playerName:gsub("#%x%x%x%x%x%x", "") table.insert(players, playerName) end if string.find(players, thePlayer) then return playerName else return false end end Why do you need a table for this? also, why do you need to make a new function if there is getPlayerFromName already...? function getPlayer(thePlayer) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") if string.find(tostring(playerName2), tostring(thePlayer)) then return playerName else return false end end Try it (not tested) Link to comment
Moderators Citizen Posted March 25, 2011 Moderators Share Posted March 25, 2011 @SolidSnake: I think that he want to return the playerName whithout the hexa color so it's: return playerName2 But I'm sure that you just forgot it ^^ @AcitanoX: You can't make that: local playerName = something local playerName = somethingElse But you can like this: local playerName = something playerName = somethingElse ( I delete the second "local" => but the variable stay to a local variable ) Link to comment
#Paper Posted March 25, 2011 Author Share Posted March 25, 2011 @SolidSnake: I think that he want to return the playerName whithout the hexa color so it's: return playerName2 Yes, i want it Link to comment
Castillo Posted March 26, 2011 Share Posted March 26, 2011 You are right Citizen, i forgot about that Link to comment
#Paper Posted March 28, 2011 Author Share Posted March 28, 2011 @SolidSnake: I think that he want to return the playerName whithout the hexa color so it's: return playerName2 But I'm sure that you just forgot it ^^ @AcitanoX: You can't make that: local playerName = something local playerName = somethingElse But you can like this: local playerName = something playerName = somethingElse ( I delete the second "local" => but the variable stay to a local variable ) the same thing, doesn't work... Link to comment
Moderators Citizen Posted March 28, 2011 Moderators Share Posted March 28, 2011 Ok I understood your function and I modify it like if I have to make this function myself ( almost the same ): Your function fixed: function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) --local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") -- not needed if ( string.find( tostring( thePlayerName ), tostring( playerName ) ) then return playerName else return false end end end My function ( optimized ): function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do if ( string.find( tostring( thePlayerName ), tostring( getPlayerName(player) ) ) then return getPlayerName(player) else return false end end end Link to comment
#Paper Posted March 28, 2011 Author Share Posted March 28, 2011 Ok I understood your function and I modify it like if I have to make this function myself ( almost the same ):Your function fixed: function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) --local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") -- not needed if ( string.find( tostring( thePlayerName ), tostring( playerName ) ) then return playerName else return false end end end Why don't needed? I i type "AcitanoX" and my nick is "#ff00ffAcit#00ff00anoX" the server can't get AcitanoX player, because the nick is separed by the codes... Link to comment
Moderators Citizen Posted March 28, 2011 Moderators Share Posted March 28, 2011 yeah sorry, I just see that in my mind: "#ff00ffAcitanoX" so it can find Acitanox whithout the gsub ^^ The new code: function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") if ( string.find( tostring( thePlayerName ), tostring( playerName2 ) ) then return playerName else return false end end end It's almost the same as the SolidSnake code, I just added a missed end Link to comment
#Paper Posted March 29, 2011 Author Share Posted March 29, 2011 yeah sorry, I just see that in my mind:"#ff00ffAcitanoX" so it can find Acitanox whithout the gsub ^^ The new code: function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player) local playerName2 = playerName:gsub("#%x%x%x%x%x%x", "") if ( string.find( tostring( thePlayerName ), tostring( playerName2 ) ) then return playerName else return false end end end It's almost the same as the SolidSnake code, I just added a missed end it's "#ff00ffAcit#00ff00anoX" and if i type "AcitanoX" i must retrieve "#ff00ffAcit#00ff00anoX" player... Link to comment
x86 Posted March 29, 2011 Share Posted March 29, 2011 function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") if ( string.find ( tostring( thePlayerName ), tostring( playerName ) ) then return playerName end end return false end Link to comment
#Paper Posted March 29, 2011 Author Share Posted March 29, 2011 function getPlayer(thePlayerName) for id, player in ipairs(getElementsByType("player")) do local playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") if ( string.find ( tostring( thePlayerName ), tostring( playerName ) ) then return playerName end end return false end LoL, it works, ty Link to comment
Moderators Citizen Posted March 29, 2011 Moderators Share Posted March 29, 2011 Hahahaha, I forgot again this: return playerName2 instead of return playerName Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now