Dimos7 Posted March 10, 2017 Share Posted March 10, 2017 (edited) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end end end function privateMessage(thePlayer, _, sendToName, ...) local message = table.concat({...}, " ") if sendToName then if getPlayerFromPartialName(sendToName) then toPlayer = getPlayerFromPartialName(sendToName) if toPlayer ~= thePlayer then if not message == "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputChatBox("Use /re [message] to answer.", thePlayer, 236, 205, 45) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("Syntax:/pm [part of name] [message]", thePlayer, 255, 0, 0) return false end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else outputChatBox("Syntax: /pm [part of name] [message]", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) function privateMessageReply(thePlayer, commandName, _, ...) local message = table.concat({...}, " ") local pmblocked = getElementData(thePlayer, "pmblocked") local toPlayer = getElementData(thePlayer, "pmPartner") if toPlayer then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84, true) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45, true) outputChatBox("Use /re [message] to answer.", toPlayer, 236, 205, 45, true) else outputChatBox("SYNTAX: /"..commandName.." [message]", thePlayer, 255, 0, 0, true) end if pmblocked == 1 then outputChatBox("This person has disable his pm try later.", thePlayer, 255, 0, 0, true) end else outputChatBox("None is pming you!", thePlayer, 255, 0, 0, true) end end addCommandHandler("re", privateMessageReply) when try contact someone online with sort of his name not working apear /pm part of name and message also i want make it work with id too Edited March 10, 2017 by Dimos7 Link to comment
Dimos7 Posted March 10, 2017 Author Share Posted March 10, 2017 anyone? when try for my self or play not be in server work when try speak to someone is on server for example lets say the play called bombMaxs and do /pm bo test apear the message SYNTAX: /pm [part of name] [message] why? Link to comment
Ayush Rathore Posted March 11, 2017 Share Posted March 11, 2017 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end else return false end end function privateMessage(thePlayer,cmd,sendToName,...) local message = table.concat({...}, " ") local name = getPlayerFromPartialName(sendToName) if name then toPlayer = name if toPlayer ~= thePlayer then if message == "" then outputChatBox("No Message given", thePlayer, 255, 0, 0) return false else outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputChatBox("Use /re [message] to answer.", thePlayer, 236, 205, 45) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end end addCommandHandler("pm", privateMessage) function privateMessageReply(thePlayer, commandName, _, ...) local message = table.concat({...}, " ") local pmblocked = getElementData(thePlayer, "pmblocked") local toPlayer = getElementData(thePlayer, "pmPartner") if toPlayer then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84, true) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45, true) outputChatBox("Use /re [message] to answer.", toPlayer, 236, 205, 45, true) else outputChatBox("SYNTAX: /"..commandName.." [message]", thePlayer, 255, 0, 0, true) end if pmblocked == 1 then outputChatBox("This person has disable his pm try later.", thePlayer, 255, 0, 0, true) end else outputChatBox("None is pming you!", thePlayer, 255, 0, 0, true) end end addCommandHandler("re", privateMessageReply) Try This Link to comment
Dimos7 Posted March 11, 2017 Author Share Posted March 11, 2017 si have a id system make by my and want work with id too gerPlayerFromID and take it and pm that person how to do it that wihtout to export my function from id-system? Link to comment
Ayush Rathore Posted March 11, 2017 Share Posted March 11, 2017 give that id script that i can tell ? Link to comment
Dimos7 Posted March 11, 2017 Author Share Posted March 11, 2017 ID = { } exports["scoreboard"]:scoreboardAddColumn("ID", root, 20, "ID", 1) -------------------------- [ 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) -------------------------- [ Functions ] ----------------------- function getPlayerID(thePlayer) if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" and getElementData(thePlayer, "ID") then return getElementData(thePlayer, "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 Link to comment
Ayush Rathore Posted March 11, 2017 Share Posted March 11, 2017 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end else return false end end function privateMessage(thePlayer,cmd,sendToName,...) local message = table.concat({...}, " ") if type(sendToName) == 'number' then player = exports.id_reso:getPlayerFromID(sendToName) if player then toPlayer = player if toPlayer ~= thePlayer then if message == "" then outputChatBox("No Message given", thePlayer, 255, 0, 0) return false else outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputChatBox("Use /re [message] to answer.", thePlayer, 236, 205, 45) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end else local name = getPlayerFromPartialName(sendToName) if name then toPlayer = name if toPlayer ~= thePlayer then if message == "" then outputChatBox("No Message given", thePlayer, 255, 0, 0) return false else outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputChatBox("Use /re [message] to answer.", thePlayer, 236, 205, 45) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) end else outputChatBox("You can't speak to your self.", thePlayer, 255, 0, 0) return false end else outputChatBox("Player not found.", thePlayer, 255, 0, 0) return false end end end addCommandHandler("pm", privateMessage) function privateMessageReply(thePlayer, commandName, _, ...) local message = table.concat({...}, " ") local pmblocked = getElementData(thePlayer, "pmblocked") local toPlayer = getElementData(thePlayer, "pmPartner") if toPlayer then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84, true) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45, true) outputChatBox("Use /re [message] to answer.", toPlayer, 236, 205, 45, true) else outputChatBox("SYNTAX: /"..commandName.." [message]", thePlayer, 255, 0, 0, true) end if pmblocked == 1 then outputChatBox("This person has disable his pm try later.", thePlayer, 255, 0, 0, true) end else outputChatBox("None is pming you!", thePlayer, 255, 0, 0, true) end end addCommandHandler("re", privateMessageReply) after copying it change the export function resource to your id resource in the above player = exports.id_reso:getPlayerFromID(sendToName) and and in meta.xml of id resource add <export function="getPlayerFromID" type="server" /> Link to comment
Dimos7 Posted March 11, 2017 Author Share Posted March 11, 2017 that have export without export it not possible? Link to comment
Dimos7 Posted March 11, 2017 Author Share Posted March 11, 2017 also apear play not found Link to comment
Ayush Rathore Posted March 12, 2017 Share Posted March 12, 2017 pm script function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end else return false end end function sendMess(from,to,message) if from ~= to then if message == "" then outputChatBox("No Message given", thePlayer, 255, 0, 0) return false else outputChatBox("PM to "..getPlayerName(to).." : "..message, from, 238, 232, 84) outputChatBox("PM from "..getPlayerName(from).." : "..message, to, 236, 205, 45) outputChatBox("Use /re [message] to answer.", to, 236, 205, 45) setElementData(from, "pmPartner", to) setElementData(to, "pmPartner", from) end else outputChatBox("You can't speak to your self.", from, 255, 0, 0) return false end end function privateMessage(thePlayer,cmd,sendToName,...) local message = table.concat({...}, " ") local name = getPlayerFromPartialName(sendToName) local player = exports.idres:getPlayerFromID(tonumber(sendToName)) local b = 0 if player then b = 1 sendMess(thePlayer,player,message) return true end if name then b = 1 sendMess(thePlayer,name,message) return true end if b == 0 then outputChatBox("No Player Found", thePlayer, 255, 0, 0) end end addCommandHandler("pm", privateMessage) function privateMessageReply(thePlayer, commandName, _, ...) local message = table.concat({...}, " ") local pmblocked = getElementData(thePlayer, "pmblocked") local toPlayer = getElementData(thePlayer, "pmPartner") if toPlayer then if tonumber(pmblocked) == 1 then outputChatBox("This person has disable his pm try later.", thePlayer, 255, 0, 0, true) else sendMess(thePlayer,toPlayer,message) end else outputChatBox("None is pming you!", thePlayer, 255, 0, 0, true) end end addCommandHandler("re", privateMessageReply) id resource's x.lua ID = { } exports["scoreboard"]:scoreboardAddColumn("ID", root, 20, "ID", 1) -------------------------- [ 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) -------------------------- [ Functions ] ----------------------- function getPlayerID(thePlayer) if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" and getElementData(thePlayer, "ID") then return getElementData(thePlayer, "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 now id resource's meta.xml <meta> <script src="x.lua" type="server" /> <export function="getPlayerFromID" type="server" /> </meta> Hope that will fulfill your needs 1 Link to comment
Dimos7 Posted March 12, 2017 Author Share Posted March 12, 2017 my resouce called id-system and apear error <meta> <script src="ids.lua" type="server"/> <export function="getPlayerFromID" type="server"/> </meta> ID = { } exports["scoreboard"]:scoreboardAddColumn("ID", root, 20, "ID", 1) -------------------------- [ 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) -------------------------- [ Functions ] ----------------------- function getPlayerID(thePlayer) if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" and getElementData(thePlayer, "ID") then return getElementData(thePlayer, "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 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end end end function privateMessage(thePlayer, commandName, sendToName, ...) local message = table.concat({...}, " ") local toPlayer = getPlayerFromPartialName(sendToName) or exports.id-system:getPlayerFromID(tonumber(sendToName)) if toPlayer then local pmblocked = getElementData(toPlayer, "pmblocked") if toPlayer ~= thePlayer then if pmblocked ~= 1 then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputServerLog("PM to "..getPlayerName(toPlayer).." : "..message) outputServerLog("PM from "..getPlayerName(thePlayer)..": "..message) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("SYNTAX: /"..commandName.." [part of name] [message]", thePlayer, 255, 0, 0) end else outputChatBox("This person has diasble his pm try later!", thePlayer, 255, 0, 0) end else outputChatBox("You can't speak to yourself!", thePlayer, 255, 0, 0) end else outputChatBox("Player not found!", thePlayer, 255, 0, 0) end end addCommandHandler("pm", privateMessage) call non running server resource(id) [string "?"] attempt to index global 'system( a nil value) Link to comment
Ayush Rathore Posted March 12, 2017 Share Posted March 12, 2017 (edited) well you should change the name of your id 4 minutes ago, Dimos7 said: my resouce called id-system and apear error <meta> <script src="ids.lua" type="server"/> <export function="getPlayerFromID" type="server"/> </meta> ID = { } exports["scoreboard"]:scoreboardAddColumn("ID", root, 20, "ID", 1) -------------------------- [ 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) -------------------------- [ Functions ] ----------------------- function getPlayerID(thePlayer) if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" and getElementData(thePlayer, "ID") then return getElementData(thePlayer, "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 function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 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(name, 1, true) then return player end end endendfunction privateMessage(thePlayer, commandName, sendToName, ...) local message = table.concat({...}, " ") local toPlayer = getPlayerFromPartialName(sendToName) or exports.id-system:getPlayerFromID(tonumber(sendToName)) if toPlayer then local pmblocked = getElementData(toPlayer, "pmblocked") if toPlayer ~= thePlayer then if pmblocked ~= 1 then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).." : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).." : "..message, toPlayer, 236, 205, 45) outputServerLog("PM to "..getPlayerName(toPlayer).." : "..message) outputServerLog("PM from "..getPlayerName(thePlayer)..": "..message) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) else outputChatBox("SYNTAX: /"..commandName.." [part of name] [message]", thePlayer, 255, 0, 0) end else outputChatBox("This person has diasble his pm try later!", thePlayer, 255, 0, 0) end else outputChatBox("You can't speak to yourself!", thePlayer, 255, 0, 0) end else outputChatBox("Player not found!", thePlayer, 255, 0, 0) endend addCommandHandler("pm", privateMessage) call non running server resource(id) [string "?"] attempt to index global 'system( a nil value) resource '-' in your resource name is causing trouble or change this line to exports.id-system:getPlayerFromID(tonumber(sendToName)) to exports["id-system"]:getPlayerFromID(tonumber(sendToName)) Well when i tested on my server it worked fine Edited March 12, 2017 by Ayush Rathore no its more correct Link to comment
Dimos7 Posted March 20, 2017 Author Share Posted March 20, 2017 function getPlayerID(player) if player then local theid players = getElementsByType("player") for id,p in ipairs(players) do if player == p then theid = i end end return theid else return false end end function getPlayerFromID(theID) if theID then theID = tonumber(theID) local theplayer players = getElementsByType("player") for id,p in ipairs(players) do if theID == id then theplayer = p end end return theplayer else return false end end function privateMessage(thePlayer, commandName, sendToName, ...) local message = table.concat({...}, " ") local toPlayer = getPlayerFromPartialName(sendToName) or getPlayerFromID(sendToName) if toPlayer then local pmblocked = getElementData(toPlayer, "pmblocked") if toPlayer ~= thePlayer then if pmblocked ~= 1 then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).."("..getPlayerID(toPlayer)..") : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).."("..getPlayerID(thePlayer)..") : "..message, toPlayer, 236, 205, 45) outputServerLog("PM to "..getPlayerName(toPlayer).."("..getPlayerID(toPlayer)..") : "..message) outputServerLog("PM from "..getPlayerName(thePlayer).."("..getPlayerID(thePlayer)..") : "..message) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) end else outputChatBox("This person has diasble his pm try later!", thePlayer, 255, 0, 0) end else outputChatBox("You can't speak to yourself!", thePlayer, 255, 0, 0) end else outputChatBox("Player not found!", thePlayer, 255, 0, 0) end end addCommandHandler("pm", privateMessage) error attempt concatenate a nil value first output chatbox Link to comment
Ayush Rathore Posted March 21, 2017 Share Posted March 21, 2017 function getPlayerID(player) if player then local theid players = getElementsByType("player") for id,p in ipairs(players) do if player == p then theid = id end end return theid else return false end end function getPlayerFromID(theID) if theID then theID = tonumber(theID) local theplayer players = getElementsByType("player") for id,p in ipairs(players) do if theID == id then theplayer = p end end return theplayer else return false end end function privateMessage(thePlayer, commandName, sendToName, ...) local message = table.concat({...}, " ") local toPlayer = getPlayerFromPartialName(sendToName) or getPlayerFromID(sendToName) if toPlayer then local pmblocked = getElementData(toPlayer, "pmblocked") if toPlayer ~= thePlayer then if pmblocked ~= 1 then if message ~= "" then outputChatBox("PM to "..getPlayerName(toPlayer).."("..getPlayerID(toPlayer)..") : "..message, thePlayer, 238, 232, 84) outputChatBox("PM from "..getPlayerName(thePlayer).."("..getPlayerID(thePlayer)..") : "..message, toPlayer, 236, 205, 45) outputServerLog("PM to "..getPlayerName(toPlayer).."("..getPlayerID(toPlayer)..") : "..message) outputServerLog("PM from "..getPlayerName(thePlayer).."("..getPlayerID(thePlayer)..") : "..message) setElementData(thePlayer, "pmPartner", toPlayer) setElementData(toPlayer, "pmPartner", thePlayer) end else outputChatBox("This person has diasble his pm try later!", thePlayer, 255, 0, 0) end else outputChatBox("You can't speak to yourself!", thePlayer, 255, 0, 0) end else outputChatBox("Player not found!", thePlayer, 255, 0, 0) end end addCommandHandler("pm", privateMessage) now try Link to comment
Gordon_G Posted March 21, 2017 Share Posted March 21, 2017 In order to reduce the lag, you should replace the ipairs to pairs. 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