iiv03 Posted December 25, 2019 Share Posted December 25, 2019 (edited) is there a way to get players name like this? name players example : bot , robot, unknown /give bot robot unknown 9999 i mean comes the name of players at according to the mentioning of the names, meaning like if you mentioned 5 names or 2 names depending on the name you want https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName Edited December 25, 2019 by xFabel Link to comment
Moderators Patrick Posted December 25, 2019 Moderators Share Posted December 25, 2019 -- SERVER addCommandHandler("give", function(player, cmd, ...) local args = {...} -- example: bot robot unknown 9999 -- we know: the last arg is the amount, a number --> and every arg behind the amount are names local args_count = #args if args_count < 2 then return outputChatBox("USE: /"..cmd.." name[name ... name] amount", player) end -- minimum need 2 argument local amount = tonumber(args[args_count]) if not amount or amount < 1 then return outputChatBox("Invalid amount.", player) end -- loop players (amount (last argument in table) excluded) for i = 1, args_count-1 do local name = args[i] local target_player = getPlayerFromPartialName(name) if isElement(target_player) then outputChatBox("Something gived to " .. getPlayerName(target_player), player) else outputChatBox("Player " .. name .. " not found.", player) end end end) -- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName 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 You mean something like this? 1 Link to comment
iiv03 Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) 36 minutes ago, stPatrick said: -- SERVER addCommandHandler("give", function(player, cmd, ...) local args = {...} -- example: bot robot unknown 9999 -- we know: the last arg is the amount, a number --> and every arg behind the amount are names local args_count = #args if args_count < 2 then return outputChatBox("USE: /"..cmd.." name[name ... name] amount", player) end -- minimum need 2 argument local amount = tonumber(args[args_count]) if not amount or amount < 1 then return outputChatBox("Invalid amount.", player) end -- loop players (amount (last argument in table) excluded) for i = 1, args_count-1 do local name = args[i] local target_player = getPlayerFromPartialName(name) if isElement(target_player) then outputChatBox("Something gived to " .. getPlayerName(target_player), player) else outputChatBox("Player " .. name .. " not found.", player) end end end) -- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName 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 You mean something like this? ofc but this work in two players if i change value argus_count to 1 will cause a problems ? bcs i'm alone in my local Edited December 25, 2019 by xFabel Link to comment
Moderators Patrick Posted December 25, 2019 Moderators Share Posted December 25, 2019 (edited) 7 minutes ago, xFabel said: ofc but this work in two players if i change value argus_count to 1 will cause a problems ? bcs i'm alone in my local It works with unlimited player. Edited December 25, 2019 by stPatrick 1 Link to comment
Moderators Patrick Posted December 25, 2019 Moderators Share Posted December 25, 2019 1 minute ago, xFabel said: thx bro Welcome Link to comment
iiv03 Posted December 25, 2019 Author Share Posted December 25, 2019 (edited) hey i'm forget to telling you so if i set command like this /give bot 5 unknown 3 robot 4 player amount, player amount, player amount smth like this how? Edited December 25, 2019 by xFabel Link to comment
Moderators Patrick Posted December 25, 2019 Moderators Share Posted December 25, 2019 (edited) 46 minutes ago, xFabel said: hey i'm forget to telling you so if i set command like this /give bot 5 unknown 3 robot 4 player amount, player amount, player amount smth like this how? addCommandHandler("give", function(player, cmd, ...) local args = {...} -- example: bot 7777 robot 8888 unknown 9999 -- we know: every 2th arg is the amount local args_count = #args if args_count < 2 or args_count % 2 ~= 0 then return outputChatBox("USE: /"..cmd.." [name amount ... name amount]", player) end -- minimum need 2 argument -- loop datas for i = 0, args_count/2-1 do local name = args[i*2+1] local amount = tonumber(args[i*2+2]) if amount and amount > 0 then local target_player = getPlayerFromPartialName(name) if isElement(target_player) then outputChatBox(amount .. " gived to " .. getPlayerName(target_player), player) else outputChatBox("Player " .. name .. " not found.", player) end else outputChatBox("Invalid amount '"..(args[i*2+2]).."' for "..name, player) end end end) -- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName 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 Edited December 25, 2019 by stPatrick 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