Jump to content

[HELP] Player ID & Part of Name


xXGhostXx

Recommended Posts

Hello.

How to sync my two codes, (e.g. My ID SYSTEM and Part of Name).

I like to use both of them: (ID System and Part of Name) in one command (e.g. /Respawn <Part of Name / ID>)

Part of name codes

function findPlayer( partofname )
  local player = getPlayerFromName ( tostring(partofname) )
  if player then
    return player
  end

  for _, player in pairs( getElementsByType 'player' ) do
    if string.find ( string.gsub ( getPlayerName ( player ):lower( ), "#%x%x%x%x%x%x", "" ), partofname:lower( ), 1, true ) then
      return player
    end
  end
end

ID System codes

function getPlayerID(player)
  if player and isElement(player) and getElementType(player) == "player" and getElementData(player, "id") then
    return getElementData(player, "id")
  end
  return false
end

--

function getPlayerFromID(id)
    if id and tonumber(id) and ID[tonumber(id)] then
       return ID[tonumber(id)]
    end
  return false
end

@iMr.WiFi..!

Edited by xXGhostXx
Link to comment

Simple do that

function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end 

 

Link to comment
43 minutes ago, Dimos7 said:

Simple do that


function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end 

 

It didn't work !

When I used command, that only works with "Part of Name" just like my default command.
But I want <PartofName/ID> BOTH!

Edited by xXGhostXx
Link to comment

 

31 minutes ago, xXGhostXx said:

It didn't work !

When I used command, that only works with "Part of Name" just like my default command.
But I want <PartofName/ID> BOTH!

Yes lisen there you have findPlayer put or getPlayerFromID and that it

Edited by Dimos7
Link to comment
1 minute ago, Dimos7 said:

Show me the code 

Show me your code 

Full ID system code :

ID = {}

------------------------  [ Events ] --------------------------

addEventHandler("onPlayerJoin", root, function()
       for i = 1 , getMaxPlayers() do
          if not ID[i] then
             ID[i] = source
             setElementData(source, "id", i)
             break
          end
      end
end)

--

addEventHandler("onPlayerQuit", root, function()
      ID[getPlayerID(source)] = nil
end)

--

addEventHandler("onResourceStart", resourceRoot, function()
       for _, v in ipairs(getElementsByType("player")) do
            for i = 1, getMaxPlayers() do
                if not ID[i]  then
                   ID[i] = v
                   setElementData(v, "id", i)
                   break
                end
            end
       end
end)

function getPlayerID(player)
  if player and isElement(player) and getElementType(player) == "player" and getElementData(player, "id") then
    return getElementData(player, "id")
  end
  return false
end

--

function getPlayerFromID(id)
    if id and tonumber(id) and ID[tonumber(id)] then
       return ID[tonumber(id)]
    end
  return false
end

Part of Name Code :

function findPlayer( partofname )
  local player = getPlayerFromName ( tostring(partofname) )
  if player then
    return player
  end

  for _, player in pairs( getElementsByType 'player' ) do
    if string.find ( string.gsub ( getPlayerName ( player ):lower( ), "#%x%x%x%x%x%x", "" ), partofname:lower( ), 1, true ) then
      return player
    end
  end
end

Test code for use Part of Name Or ID

addCommandHandler("fix",
function(thePlayer, cmd, player)
  if not ( isPlayerOnGroup ( thePlayer ) ) then
    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)
    return false
  end
if player ~= nil then
local yaru = findPlayer ( player ) --find player
if yaru then
if isPedInVehicle ( yaru ) then
local mashineyaru = getPedOccupiedVehicle(yaru)
local esmesh = getPlayerName(yaru)
fixVehicle(mashineyaru)
    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)
    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)
else
    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)
end
end
)

 

Link to comment
function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end
addCommandHandler("fix",
function(thePlayer, cmd, target)
  if not ( isPlayerOnGroup ( thePlayer ) ) then
    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)
    return false
  end
if targ3t ~= nil then
local yaru = findPlayer (target) or getPlayerFromID(target) --find player
if yaru then
if isPedInVehicle ( yaru ) then
local mashineyaru = getPedOccupiedVehicle(yaru)
local esmesh = getPlayerName(yaru)
fixVehicle(mashineyaru)
    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)
    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)
else
    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)
end
end
)

Put that together and try

Link to comment
34 minutes ago, Dimos7 said:

function findPlayer(name)   local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil  if name then    for _, player in pairs(getElementsByType("player")) do      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()       if name_:find(name, 1, true) then        return player      end    end  endendfunction getPlayerID(player)   if player then    local theID    for id, p in pairs(getElementsByType("player")) do      if p == player then        theID = id      end      return theID      end  else return endendfunction getPlayerFromID(theID)   if theID then     tonumber(theID)     local thePlayer     for id, p in pairs(getElementsByType("player")) do          if theID == id then            thePlayer = p        end        return thePlayer       end  else return endend

addCommandHandler("fix",function(thePlayer, cmd, target)  if not ( isPlayerOnGroup ( thePlayer ) ) then    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)    return false  endif targ3t ~= nil thenlocal yaru = findPlayer (target) or getPlayerFromID(target) --find playerif yaru thenif isPedInVehicle ( yaru ) thenlocal mashineyaru = getPedOccupiedVehicle(yaru)local esmesh = getPlayerName(yaru)fixVehicle(mashineyaru)    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)else    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)endelse    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)endelse    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)endend)

Put that together and try

It didn't work :(

Link to comment
addCommandHandler("fix" , function(thePlayer, cmd, target)
  if not ( isPlayerOnGroup ( thePlayer ) ) then
    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)
    return false
  end
if target ~= nil then
local yaru = findPlayer (target) or getPlayerFromID(target) --find player
if yaru then
if isPedInVehicle ( yaru ) then
local mashineyaru = getPedOccupiedVehicle(yaru)
local esmesh = getPlayerName(yaru)
fixVehicle(mashineyaru)
    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)
    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)
else
    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)
end
end) 

function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end

 

Edited by Dimos7
Link to comment
5 minutes ago, Dimos7 said:

addCommandHandler("fix" , function(thePlayer, cmd, target)
  if not ( isPlayerOnGroup ( thePlayer ) ) then
    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)
    return false
  end
if target ~= nil then
local yaru = findPlayer (target) or getPlayerFromID(target) --find player
if yaru then
if isPedInVehicle ( yaru ) then
local mashineyaru = getPedOccupiedVehicle(yaru)
local esmesh = getPlayerName(yaru)
fixVehicle(mashineyaru)
    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)
    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)
else
    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)
end
end) 

function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end

 

It didn't work :(

Part of Name just work !

Link to comment
addCommandHandler("fix" , function(thePlayer, cmd, target)
  if not ( isPlayerOnGroup ( thePlayer ) ) then
    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)
    return false
  end
if target ~= nil then
local yaru = findPlayer (target) or getPlayerFromID(target) --find player
if yaru then
if isPedInVehicle ( yaru ) then
local mashineyaru = getPedOccupiedVehicle(yaru)
local esmesh = getPlayerName(yaru)
fixVehicle(mashineyaru)
    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)
    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)
else
    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)
end
else
    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)
end
end) 

function findPlayer(name) 
  local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil
  if name then
    for _, player in pairs(getElementsByType("player")) do
      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
      if name_:find(name, 1, true) then
        return player
      end
    end
  end
end

function getPlayerID(player) 
  if player then
    local theID
    for id, p in pairs(getElementsByType("player")) do
      if p == player then
        theID = id
      end
      return theID
      end
  else return end
end

function getPlayerFromID(theID) 
  if theID then
     theID = tonumber(theID) 
    local thePlayer 
    for id, p in pairs(getElementsByType("player")) do 
         if theID == id then 
           thePlayer = p
        end
        return thePlayer 
      end
  else return end
end

 

 

50 minutes ago, xXGhostXx said:

It didn't work :(

Part of Name just work !

A small miskate my bad

Link to comment
9 hours ago, Dimos7 said:

addCommandHandler("fix" , function(thePlayer, cmd, target)  if not ( isPlayerOnGroup ( thePlayer ) ) then    outputChatBox("#ff0000[Error]: #ffffffShoma Dastresi Be In Dastoor Nadarid!", thePlayer, 255, 255, 255, true)    return false  endif target ~= nil thenlocal yaru = findPlayer (target) or getPlayerFromID(target) --find playerif yaru thenif isPedInVehicle ( yaru ) thenlocal mashineyaru = getPedOccupiedVehicle(yaru)local esmesh = getPlayerName(yaru)fixVehicle(mashineyaru)    outputChatBox("#00ff00[Done]: #ffffffShoma Mashine #00ff00"..esmesh.." #ffffffRa Fix Kardid!", thePlayer, 255, 255, 255, true)    outputChatBox("#FFFF00[Info]: #ffffffAdmin #FFFF00".. getPlayerName ( thePlayer ) .." #ffffffMashin Shoma Ra Fix Kard!", yaru, 255, 255, 255, true)else    outputChatBox("#ff0000[Error]: #ffffffIn Player Ke Savare Mashin Nist!", thePlayer, 255, 255, 255, true)endelse    outputChatBox("#ff0000[Error]: #ffffffPlayer Peyda Nashod!", thePlayer, 255, 255, 255, true)endelse    outputChatBox("#00FF00Bezan : /fix <PartOfName/ID>", thePlayer, 255, 255, 255, true)endend) function findPlayer(name)   local name = name and name:gsub("#%x%x%x%x%x%x", "" ):lower() or nil  if name then    for _, player in pairs(getElementsByType("player")) do      local name_=getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()       if name_:find(name, 1, true) then        return player      end    end  endendfunction getPlayerID(player)   if player then    local theID    for id, p in pairs(getElementsByType("player")) do      if p == player then        theID = id      end      return theID      end  else return endendfunction getPlayerFromID(theID)   if theID then     theID = tonumber(theID)     local thePlayer     for id, p in pairs(getElementsByType("player")) do          if theID == id then            thePlayer = p        end        return thePlayer       end  else return endend

 

 

A small miskate my bad

It didn't work :(

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