Citryon25 Posted February 7, 2017 Share Posted February 7, 2017 Pessoal, to criando um sistema de cash(outra moeda no jogo, sendo moeda normal e cash) e para ver se o comando de dar cash está funcionando eu criei uma função para ver o cash na conta, porém estou com um problema infernal. Quando eu digito o comando aparece : ' getPlayerAccount' [expected element at argument 1, got string 'meucash] Já usei source, playerSource, localPlayer e thePlayer onde está player, porém a função não identifica o elemento. Código: function checkMyCash (_, player, account) local account = getPlayerAccount( player ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "cash") if (playercash) then outputChatBox("Você tem ".. playercash .." cash restante(s) em sua conta.", player, 100, 255, 100) end end end addCommandHandler( "meucash", checkMyCash ) Link to comment
[M]ister Posted February 8, 2017 Share Posted February 8, 2017 Quando um comando é utilizado, é repassado para função de manipulação, diversos parâmetros e o primeiro deles é o player que acionou o comando... Tente: function checkMyCash (player) local account = getPlayerAccount( player ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "cash") if (playercash) then outputChatBox("Você tem ".. playercash .." cash restante(s) em sua conta.", player, 100, 255, 100) end end end addCommandHandler( "meucash", checkMyCash ) 1 Link to comment
Citryon25 Posted February 9, 2017 Author Share Posted February 9, 2017 Mui 20 hours ago, MaligNos said: Quando um comando é utilizado, é repassado para função de manipulação, diversos parâmetros e o primeiro deles é o player que acionou o comando... Tente: function checkMyCash (player) local account = getPlayerAccount( player ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "cash") if (playercash) then outputChatBox("Você tem ".. playercash .." cash restante(s) em sua conta.", player, 100, 255, 100) end end end addCommandHandler( "meucash", checkMyCash ) Obrigado, deu certo, porém, estou com alguns outros problemas no código. A função que eu criei para dar cash não está funcionando, no debug aparece: "attempt to index local 'name'(a userdata value). (linha 14 [função getPlayerByPartialName]). Notei também que de nenhuma forma a informação é atribuída na função setAccountData Abaixo o código completo: function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or false 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 giveCash(targetPlayer, player, account) --local accName = getAccountName ( getPlayerAccount ( source ) ) -- if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then ARRUMAR DEPOIS<< if targetPlayer then if (getPlayerFromPartialName( targetPlayer )) then local targetPlayer = (getPlayerFromPartialName( targetPlayer )) local account = getPlayerAccount( targetPlayer ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "system.cash") if (playercash) then setAccountData(account, "system.cash", playercash + tonumber(value)) end end end end end --end addCommandHandler("cash", giveCash) function checkMyCash (player) local account = getPlayerAccount( player ) if ( account ) and not isGuestAccount ( account ) then playercash = getAccountData(account, "system.cash") if not(playercash) then outputChatBox("Você não possui cash em sua conta.", player, 100, 255, 100) outputChatBox("Você tem ".. playercash .." cash restante(s) em sua conta.", player, 100, 255, 100) end end end addCommandHandler( "meucash", checkMyCash ) Link to comment
[M]ister Posted February 9, 2017 Share Posted February 9, 2017 Tente: function giveCash(player,comando,targetPlayer,value) --local accName = getAccountName ( getPlayerAccount ( source ) ) -- if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then ARRUMAR DEPOIS<< if targetPlayer then if (getPlayerFromPartialName( targetPlayer )) then local targetPlayer = (getPlayerFromPartialName( targetPlayer )) local account = getPlayerAccount( targetPlayer ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "system.cash") if (playercash) then setAccountData(account, "system.cash", playercash + tonumber(value)) end end end end end --end addCommandHandler("cash", giveCash) Exemplo de uso: /cash MaligNos 100 giveCash(player,comando,targetPlayer,value) player = Player que executou o comando comando = "cash" targetPlayer = "MaligNos" value = "100" Link to comment
Citryon25 Posted February 9, 2017 Author Share Posted February 9, 2017 20 hours ago, MaligNos said: Tente: function giveCash(player,comando,targetPlayer,value) --local accName = getAccountName ( getPlayerAccount ( source ) ) -- if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Console" ) ) then ARRUMAR DEPOIS<< if targetPlayer then if (getPlayerFromPartialName( targetPlayer )) then local targetPlayer = (getPlayerFromPartialName( targetPlayer )) local account = getPlayerAccount( targetPlayer ) if ( account ) and not isGuestAccount ( account ) then local playercash = getAccountData(account, "system.cash") if (playercash) then setAccountData(account, "system.cash", playercash + tonumber(value)) end end end end end --end addCommandHandler("cash", giveCash) Exemplo de uso: /cash MaligNos 100 giveCash(player,comando,targetPlayer,value) player = Player que executou o comando comando = "cash" targetPlayer = "MaligNos" value = "100" Agora deu erro ao digitar o comando /meucash: Attempt to concatenate global 'playercash' (a boolean value) function checkMyCash (player) local account = getPlayerAccount( player ) if ( account ) and not isGuestAccount ( account ) then -- Global playercash: playercash = getAccountData(account, "system.cash") if not(playercash) then outputChatBox("Você não possui cash em sua conta.", player, 100, 255, 100) -- LINHA DO ERRO: outputChatBox("Você tem ".. playercash .." cash restante(s) em sua conta.", player, 100, 255, 100) end end end addCommandHandler( "meucash", checkMyCash ) Link to comment
Citryon25 Posted February 12, 2017 Author Share Posted February 12, 2017 Valeu ai, consegui arrumar o script 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