[SOLVED] kill count

Hello everyone,
sorry if my English is bad.

I have a zombie script like this:

Citizen.CreateThread(function()
          while true do
            Citizen.Wait(1)
            for i, entity in pairs(entitys) do
                playerX, playerY, playerZ = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
                pedX, pedY, pedZ = table.unpack(GetEntityCoords(entity, true))
                if DoesEntityExist(entity) == false then
                    table.remove(entitys, i)
                end
                if IsPedDeadOrDying(entity, 1) == 1 then
                    if GetPedSourceOfDeath(entity) == PlayerPedId() then
                        dead = dead + 1
                        Citizen.Wait(1000)
                        RandomLoot()
                        ClearPedSecondaryTask(GetPlayerPed(-1))
                        local model = GetEntityModel(entity)
                        SetEntityAsNoLongerNeeded(entity)
                        SetModelAsNoLongerNeeded(model)
                        table.remove(entitys, i)
                        exports.esx_xp:ESXP_Add(10)
                    end
                    Citizen.Wait(1000)
                    DeleteEntity(entity)
                end
            end
        end
    end)

I want to add when zombie dead add count zombie dead to the database.
how do I make it on the client and server side?
I really appreciate your help

Firstly, never put clean code in post, use Blockquote to do it. Secondly you can use this MySQL Library which include methods to INSERT, UPDATE or GET values from Database. To know basics you can watch this or this.

In my opinion your server.lua will look like this:

RegisterNetEvent('zombie:count')
AddEventHandler('zombie:cout', function()
  MySQL.Async.execute('UPDATE YOUR_TABLE_NAME SET killedZombie = killedZombie + 1 WHERE steamhex = @steamhex',
  { ['@steamhex'] = PlayerIdentifier('steam', GetPlayerServerId(GetPlayerPed(-1))) },
  function(affectedRows)
    print(affectedRows)
  end
)
1 Like

Sorry for clean code,
I’ve edited it, and thank you very much for your help