Anderson Mello Posted May 17, 2020 Posted May 17, 2020 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 addEvent("onSendMoney", true) addEventHandler("onSendMoney", getRootElement(), function(who, player) local money = getPlayerMoney(source) if player ~= nil then if tonumber(player) >= 200 then if tonumber(player) <= money then toWho = getPlayerFromPartialName(who) conta = getPlayerAccount (source) if isGuestAccount (conta) then outputChatBox("#FFFF00Você precisa estar logado.", source, 255, 255, 255, true) return end nick_do_jogador = getPlayerName ( toWho ) if toWho ~= false then givePlayerMoney(toWho, player) takePlayerMoney(source, player) name = getPlayerName(source) outputChatBox("#FFFF00Você transferiu #00ff00R$" .. player .. "#FFFF00 para #FFFF00" .. nick_do_jogador, source, 255, 255, 255, true) outputChatBox("".. name .. " #FFFF00lhe transferiu #FFFF00R$" .. player .. " #FFFF00!", toWho, 255, 255, 255, true) else outputChatBox("#FFFF00Você não selecionou um jogador da lista!", source, 255, 255, 255,true) end else outputChatBox("#FFFF00Você não tem dinheiro suficiente!", source, 255, 255, 255,true) end else outputChatBox("#FFFF00 O valor mínimo de transferências é R$ 200 !", source, 255, 255, 255,true) end end end )
KronoS Lettify Posted May 17, 2020 Posted May 17, 2020 Olá e bem-vindo ao fórum. Para manter o local organizado temos os respectivos sub-fóruns, por isso, sempre que criar um tópico por favor crie-o dentro do sub-fórum Portuguese / Português. Você pode encontrá-lo pela página inicial do fórum da forma mostrada abaixo: Isso evitará o trabalho que os moderadores têm diariamente de mover posts para os locais certos. Sempre que criar um novo tópico, certifique-se que esteja na devida categoria. No sub-fórum Português ficam todas postagens na linguagem portuguesa, enquanto que fora da categoria Other languages só é permitido posts em inglês, por isso, sempre que responder um tópico, preste atenção a isso. 1 1
Blaack Posted May 17, 2020 Posted May 17, 2020 7 hours ago, Anderson Mello said: 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 addEvent("onSendMoney", true) addEventHandler("onSendMoney", getRootElement(), function(who, player) local money = getPlayerMoney(source) if player ~= nil then if tonumber(player) >= 200 then if tonumber(player) <= money then toWho = getPlayerFromPartialName(who) conta = getPlayerAccount (source) if isGuestAccount (conta) then outputChatBox("#FFFF00Você precisa estar logado.", source, 255, 255, 255, true) return end nick_do_jogador = getPlayerName ( toWho ) if toWho ~= false then givePlayerMoney(toWho, player) takePlayerMoney(source, player) name = getPlayerName(source) outputChatBox("#FFFF00Você transferiu #00ff00R$" .. player .. "#FFFF00 para #FFFF00" .. nick_do_jogador, source, 255, 255, 255, true) outputChatBox("".. name .. " #FFFF00lhe transferiu #FFFF00R$" .. player .. " #FFFF00!", toWho, 255, 255, 255, true) else outputChatBox("#FFFF00Você não selecionou um jogador da lista!", source, 255, 255, 255,true) end else outputChatBox("#FFFF00Você não tem dinheiro suficiente!", source, 255, 255, 255,true) end else outputChatBox("#FFFF00 O valor mínimo de transferências é R$ 200 !", source, 255, 255, 255,true) end end end ) Amigo, qual erro está dando?
Anderson Mello Posted May 17, 2020 Author Posted May 17, 2020 2 hours ago, ~#BlackSCR said: Amigo, qual erro está dando? Ele está funcionando por Nome quero alterar para fazer transferência por ID
Blaack Posted May 19, 2020 Posted May 19, 2020 On 17/05/2020 at 10:18, Anderson Mello said: Ele está funcionando por Nome quero alterar para fazer transferência por ID Poderia mandar o codigo do lado do client ?
HiroShi Posted May 23, 2020 Posted May 23, 2020 (edited) Você terá que fazer uma função igual a function getPlayerFromPartialName(name) no caso você fará um loop que verifica todos os players e separa o que tem o id a qual foi chamado ex: function getPlayerFromId(id) for i,v in ipairs("players") do if getElementData(v, "ID") == tonumber(id) then -- nesse caso usei o elementData famoso do DNL que é do sistema de id dele que é "ID" return v -- esse "V" veio através do loop antes da if o "V" era todos os jogogadores, mais apartir da IF ele se transformou no destinário ! end end end espero ter ajudado edit: lembrando para você chamar ele dentro da function que for usar você usa getPlayerFromId(Id do jogador) Edited May 23, 2020 by HiroShi a questão de como chamar a function
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