Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 17/08/20 in Posts

  1. Olá talvez aqui voce entenda como brinca um pouco com ele e largar as db do proprio mta Bom primeiro vamos entender o SQL vamos usar aqui SQLITE e uma versao lite do SQL onde e possivel guarda as info em arquivo .db voce pode usar oque vou ensinar aqui em SQL tb primeiro vamos fazer a connecta ao banco db = dbConnect( "sqlite", "db/banco.db" ) não precisa ter o arquivo o, proprio mta cria ele para voce ? Agora vamos criar as TABELAS e suas COLUNAS dbExec(db, "CREATE TABLE IF NOT EXISTS SERVIDOR (CONTAPLAYER TEXT,SERIAL_PLAYER TXT,SENHA_PLAYER TEXT,DINHEIRO_PLAYER INT)") O codigo acima vai criar uma tabela chamda " SERVIDOR " com 4 colunas vamos entender os tipos de coluna que usei TEXT > E uma coluna do tipo TEXTO INT > E uma coluna do tipo NUMERO INTEIROS ex ( 1 | 33333 | 77777) como eu sei que o dinheiro do player e um numero inteiro botei INT voce não vai precisa coloca isso caso não queira. e melhor para o futuro e tals vou mostra aqui para voce algums argumento de consulta,alteração,e deletar dbQuery(db, "SELECT * FROM SERVIDOR") SELECT > SELECIONA * > TUDO FROM > DE SERVIDOR > NOME DA TABELA nessa ai vimos que eu mandei um comando falando para selecionar tudo da tabela SERVIDOR function SQLiteCall_SERVER () local SV = dbQuery(db, "SELECT * FROM SERVER") if SV then return SV end end aqui um ex de função que vai retorna a tabela selecionada Porem tem que ler ela de uma forma que voce pode ver os dados colocados nela function QualMeuDinheiro(source) local Serial = getPlayerSerial( source ) -- PEGANDO O SERIAL DO PLAYER QUE CHAMO A FUNÇÃO local banco = SQLiteCall_Fazendas() -- CHAMANDO A FUNÇÃO QUE SELECIONA O BANCO DE DADOS if banco then -- VERIFICA SE A TABELA QUE ELE PEGO EXISTE local p = dbPoll(banco,-1) -- BASICAMENTE ELA SERVER PARA RECEBER O RESULTADO DA TABELA for index , dados in ipairs(p) do -- AQUI ABRE A TABELA E TORNA O DADOS POSSIVEL DE LER if Serial == dados["SERIAL_PLAYER"] then -- AQUI TO COMPARANDO O SERIAL COM O DADO LA NO BANCO DE DADOS outputChatBox( "SEU DINHERO E :"..dados["DINHEIRO_PLAYER"],source,255,255,255,true) -- E AQUI FOI SELECIONADO O DINHEIRO DO PLAYER DA VERIFICAÇÃO ACIMA end end end end addCommandHandler( "meudinheiro",QualMeuDinheiro ) a função acima informa o dinheiro do player baseado oque tem no banco de dados essa parte dados["DINHEIRO_PLAYER"] "DINHEIRO_PLAYER" ea nome da coluna la na tabela Ok aqui voce aprendeu a ler os dados e exibir. Agora voce me pergunta e fazer update? dbExec(db, "UPDATE SERVIDOR SET DINHEIRO_PLAYER=? WHERE SERIAL_PLAYER=?",dinheiro,serial) UPDATE > FAZER ALTERAÇÃO SET > QUAL COLUNA DINHEIRO_PLAYER > O NOME DA COLUNA WHERE > E QUAL PARTE | isso que dizer que ele vai pesguisa no banco SERIAL_PLAYER > o nome da tabela que ele vai procura function MoneyMoney(source) local DINHEIRO_NOVO = 10000 local serial = getPlayerSerial( source ) dbExec(db, "UPDATE SERVIDOR SET DINHEIRO_PLAYER=? WHERE SERIAL_PLAYER=?",DINHEIRO_NOVO,serial) -- AQUI FOI FEITO ALTERAÇAO end addCommandHandler( "querodinheiro",MoneyMoney ) essa função faiz o update no banco de dados mais lembre-se se o player tem 50000 la no banco de dados e voce fizer update para 10000 o valor vai ser 10000 então para almenta ou diminuir faça a consulta no banco de dados dps some com o valor novo e assim faiz o update dbExec(db, "INSERT INTO SERVIDOR (CONTAPLAYER,SERIAL_PLAYER,SENHA_PLAYER,DINHEIRO_PLAYER) VALUES(?,?,?,?)",Conta,Serial,Senha,Dinheiro) INSERT > Inserir Into > Em Servidor > Nome da tabela function Megrava () local Conta = "OlaLogin" local Serial = "65D56AS45D5A45D56A4DADAD5A4D" local Senha = "1234b" local Dinheiro = 50000 dbExec(db, "INSERT INTO SERVIDOR (CONTAPLAYER,SERIAL_PLAYER,SENHA_PLAYER,DINHEIRO_PLAYER) VALUES(?,?,?,?)",Conta,Serial,Senha,Dinheiro) --/\ ? são o tanto de argumento que vai por -- end addCommandHandler( "gravar",Megrava ) Nessa parte eu to gravando os dados do player no banco de dados dbExec(db, "DELETE FROM SERVIDOR WHERE SERIAL_PLAYER=?", Serial) -- MESMA IDEIA DO UPDATE MAIS AQUI VOCE DELETA OS DADOS DE UM SERIAL X dbExec(db, "DELETE FROM SERVIDOR") -- AQUI VOCE DELETA TUDO QUE TEM NA TABELA SERVIDOR esse ai e para DELETAR elemento na tabela do banco de dados Eu acho que isso eu basico e todo que voce precisa saber sobre MYSQL qualquer outra duvida pode pergunta @DNL291 DNL se tiver erros de portugues que eu sei que tem kkkk pode corrigir e se tiver confuso pode da uma melhorada se possivel? acho que esse e um tutorial importante ^^
    1 point
  2. السلام عليكم انا بحب ممارسة الميمز او اسمها الاخر الكوميكس فاحبيت اقدم ليكم صور ساخرة عن مجتمع mta and lua لغة مش عارف هتعبجكم ولا لاء اول صورة انا نفسى مش مبرمج لكن اما بعدل شى طويل ممكن بسبب العلامة دى متخليش الاسكريبت يشتغل تانى صورة لما تبرمج شى من غير مزاج الشاشة هتنفجر من الايروور الصورة رقم 3 الناس الى بتنسى بسرعة من قلة الممارسة فى ناس كدة حتى لو فى لغات برمجية اخرى محبتشى ازود فى الصورة يارب تعجبكم
    1 point
  3. When you cancel the event, the tires can't be flatten. So you probably will have to do that manually. https://wiki.multitheftauto.com/wiki/OnClientVehicleDamage element theAttacker, int theWeapon, float loss, float damagePosX, float damagePosY, float damagePosZ, int tireID >>> Set clientside (for people with high ping AND can also be used to prevent an overflow of data between client and server, since you do not have to communicate with the server when the tire is already flatten): https://wiki.multitheftauto.com/wiki/SetVehicleWheelStates > triggerServerEvent Set serverside: (Now other players should be able to see it, I am not sure if this is required because I do not know if this tire state is streamed when the setVehicleWheelStates function is called on clientside.) https://wiki.multitheftauto.com/wiki/SetVehicleWheelStates Or do not cancel the event when a tire is hit.
    1 point
  4. local weapon_table = { -- model, id [30] = { [422]=10, --Bobcat [596]=9, --PoliceLS }, } function getElementSpeed(theElement, unit) -- Check arguments for errors assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") local elementType = getElementType(theElement) assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")") assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") -- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) -- Setup our multiplier to convert the velocity to the specified unit local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) -- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit return (Vector3(getElementVelocity(theElement)) * mult).length end addEventHandler("onClientVehicleDamage", root, function(attacker,weapon,loss,dmgx,dmgy,dmgz,tireid) if tireid then return end if getElementData(source,'god-mode') then return end if isVehicleDamageProof(source) then return end if attacker and getElementType(attacker)=='player' then if dmg_table[getElementModel(source)] then cancelEvent() setElementHealth(source,getElementHealth(source)-(dmg_table[getElementModel(source)]+weapon_table[weapon][getElementModel(source)])) print(getElementHealth(source)) end --elseif attacker~=('vehicle' or 'ped') then --setElementHealth(source,getElementHealth(source)-(getElementSpeed(source,1)/30*10)) end end) Try this. I added line 25. I haven't tested it, but I assume tireid is nil if no tire was hit.
    1 point
  5. This: results[1].password returns nil? First take a look in what is inside (this in most of the cases gives you the solution right away): inspect("Input password:", password, "\n Database results:", results) https://wiki.multitheftauto.com/wiki/DbExec dbExec doesn't support callback functions. It returns true when the connection is successful. This does not give you any information if the value is correctly set. dbExec(function() --triggerClientEvent(player, "loginSuccess", token) end, See here how to do that correctly (for insert): https://wiki.multitheftauto.com/wiki/DbPoll
    1 point
×
×
  • Create New...