xXGhostXx Posted October 18, 2018 Posted October 18, 2018 (edited) 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 October 18, 2018 by xXGhostXx
Dimos7 Posted October 18, 2018 Posted October 18, 2018 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
xXGhostXx Posted October 18, 2018 Author Posted October 18, 2018 (edited) 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 October 18, 2018 by xXGhostXx
Dimos7 Posted October 18, 2018 Posted October 18, 2018 (edited) 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 October 18, 2018 by Dimos7
xXGhostXx Posted October 18, 2018 Author Posted October 18, 2018 2 minutes ago, Dimos7 said: Yes lisen there you have findPlayer put or getPlayerFromID and that it I want used Part of Name or ID !
Dimos7 Posted October 18, 2018 Posted October 18, 2018 (edited) 21 minutes ago, xXGhostXx said: I want used Part of Name or ID ! Show me your code Edited October 18, 2018 by Dimos7
xXGhostXx Posted October 18, 2018 Author Posted October 18, 2018 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 )
Dimos7 Posted October 18, 2018 Posted October 18, 2018 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
xXGhostXx Posted October 18, 2018 Author Posted October 18, 2018 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
Dimos7 Posted October 18, 2018 Posted October 18, 2018 (edited) 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 October 18, 2018 by Dimos7
xXGhostXx Posted October 18, 2018 Author Posted October 18, 2018 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 !
Dimos7 Posted October 19, 2018 Posted October 19, 2018 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
xXGhostXx Posted October 19, 2018 Author Posted October 19, 2018 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
Dimos7 Posted October 19, 2018 Posted October 19, 2018 2 hours ago, xXGhostXx said: It didn't work Any errors or warnings in /debugscipt 3 Also id system runing?
xXGhostXx Posted October 19, 2018 Author Posted October 19, 2018 2 hours ago, Dimos7 said: Any errors or warnings in /debugscipt 3 Also id system runing? Not error, Test it yourself.
Dimos7 Posted October 19, 2018 Posted October 19, 2018 24 minutes ago, xXGhostXx said: Not error, Test it yourself. You mess the code that why at my work fine
xXGhostXx Posted October 19, 2018 Author Posted October 19, 2018 2 minutes ago, Dimos7 said: You mess the code that why at my work fine Please check :
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