Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2023-03-24, 02:42


_TigerKill_







Wiek: 23
Na forum: 1460 dni
Posty: 5

Piwa: 6

Respekt: 50

Witam mam problem bo nie wiem jak stworzy? baze danych pod ten skrypt a jestem pocz?tkowy w lua i nie za bardzo kumam potrzebuj? pomocy za pomoc oferuj? piwko

cacheTable = {}
temporaryTable = {}
assistsTimer = {}
multiKillTimer = {}
rankTable = {}

addEventHandler("onResourceStart"resourceRoot,
function()
    db dbConnect("sqlite""database.db")
    dbExec(db"DELETE FROM RankTable WHERE player_xp <= 0")
    dbExec(db"CREATE TABLE IF NOT EXISTS RankTable (account_name STRING NOT NULL PRIMARY KEY, player_name, player_xp int, total_kills int, total_deaths int, total_assists int, total_fires int, total_hits int, total_dmg int, kill_streak int, total_headshots int, total_deagle int, total_sniper int, total_shotgun int, total_rifle int, total_grenade int, total_fist int, total_playtime int, total_wins int, total_loses int)")
    for iplayer in ipairs(getElementsByType("player")) do
        local account getPlayerAccount(player)
        if account and not isGuestAccount(accountthen
            local accountName getAccountName(account)
            temporaryTable[accountName] = {
                ["player_xp"] = 0,
                ["total_kills"] = 0,
                ["total_deaths"] = 0,
                ["total_assists"] = 0,
                ["total_hits"] = 0,
                ["total_dmg"] = 0,
                ["kill_streak"] = 0,
                ["total_headshots"] = 0,
                ["total_deagle"] = 0,
                ["total_sniper"] = 0,
                ["total_shotgun"] = 0,
                ["total_rifle"] = 0,
                ["total_grenade"] = 0,
                ["total_fist"] = 0,
                ["total_wins"] = 0,
                ["total_loses"] = 0,
                ["total_playtime"] = getTickCount()
            }
            local result dbPoll(dbQuery(db"SELECT account_name FROM RankTable WHERE account_name = ?"accountName), -1)
            if type(result) == "table" and #result <= 0 then
                local playerName string.gsub(getPlayerName(player), "#%x%x%x%x%x%x""")
                dbExec(db"INSERT INTO RankTable VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"accountNameplayerName000000000000000000)
            end
        end
    end
    updateCacheTable()
end)

addEventHandler("onPlayerLogin"root,
function(_account)
    local accountName getAccountName(account)
    if not temporaryTable[accountNamethen
        temporaryTable[accountName] = {
            ["player_xp"] = 0,
            ["total_kills"] = 0,
            ["total_deaths"] = 0,
            ["total_assists"] = 0,
            ["total_hits"] = 0,
            ["total_dmg"] = 0,
            ["kill_streak"] = 0,
            ["total_headshots"] = 0,
            ["total_deagle"] = 0,
            ["total_sniper"] = 0,
            ["total_shotgun"] = 0,
            ["total_rifle"] = 0,
            ["total_grenade"] = 0,
            ["total_fist"] = 0,
            ["total_wins"] = 0,
            ["total_loses"] = 0,
            ["total_playtime"] = getTickCount()
        }
        local result dbPoll(dbQuery(db"SELECT account_name FROM RankTable WHERE account_name = ?"accountName), -1)
        if type(result) == "table" and #result <= 0 then
            local playerName string.gsub(getPlayerName(source), "#%x%x%x%x%x%x""")
            dbExec(db"INSERT INTO RankTable VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"accountNameplayerName000000000000000000)
            table.insert(cacheTable, {accountNameplayerName000000000000000000})
        end
    end
end)

function calculateRank(XP)
    for i=099999 do
        CurrentXP i*(>= and or 1-1)*400
        if CurrentXP XP then
            return (i-1)
        end
    end
end

function table.size(tab)
    local length 0
    for _ in pairs(tab) do length length 1 end
    return length
end

function updateCacheTable()
    if not isTimer(cacheTimerthen
        cacheTable nil
        cacheTable = {}
        local result dbPoll(dbQuery(db"SELECT * FROM RankTable"), -1)
        if type(result) == "table" and #result ~= 0 then
            for iR in pairs(result) do
                local currentRank calculateRank(R["player_xp"])
                if rankTable[R["account_name"]] and rankTable[R["account_name"]] < currentRank then
                    local player getAccountPlayer(getAccount(R["account_name"]))
                    if player then
                        setTimer(function(playerold, new)
                            if isElement(playerthen
                                triggerClientEvent(player"onRankChange"playerold, new)
                            end
                        end110001playerrankTable[R["account_name"]], currentRank)
                    end
                end
                table.insert(cacheTable, {R["account_name"], R["player_name"], R["player_xp"], R["total_kills"], R["total_deaths"], R["total_assists"], R["total_fires"], R["total_hits"], R["total_dmg"], R["kill_streak"], R["total_headshots"], R["total_deagle"], R["total_sniper"], R["total_shotgun"], R["total_rifle"], R["total_grenade"], R["total_fist"], R["total_playtime"], R["total_wins"], R["total_loses"]})
                rankTable[R["account_name"]] = currentRank
            end
        end
        cacheTimer setTimer(function() end100001)
    end
end

addEvent("onClientRequestStats"true)
addEventHandler("onClientRequestStats"root,
function()
    local accountName getAccountName(getPlayerAccount(source))
    triggerClientEvent(source"onServerSendStats"sourcecacheTableaccountName)
end)

addEventHandler("onPlayerDamage"root,
function(attacker__loss)
    if exports.tacticsMOD:getRoundMapInfo()["modename"] ~= "lobby" then
        if attacker and getElementType(attacker) == "player" and attacker ~= source then
            local account getPlayerAccount(attacker)
            if account and not isGuestAccount(accountthen
                local accountName getAccountName(account)
                temporaryTable[accountName]["total_hits"] = temporaryTable[accountName]["total_hits"] + 1
                temporaryTable[accountName]["total_dmg"] = temporaryTable[accountName]["total_dmg"] + math.ceil(loss)
                local assistsTable getElementData(source"assists") or {}
                if assistsTable[accountNamethen
                    assistsTable[accountName] = assistsTable[accountName] + math.ceil(loss)
                else
                    assistsTable[accountName] = math.ceil(loss)
                end
                setElementData(source"assists"assistsTablefalse)
                if isTimer(assistsTimer[source]) then 
                    resetTimer(assistsTimer[source])
                else
                    assistsTimer[source] = setTimer(function(source)
                        assistsTimer[source] = nil
                        if isElement(sourcethen
                            setElementData(source"assists", {}, false)
                        end
                    end100001source)
                end
            end
        end
    end
end)

addEventHandler("onPlayerWasted"root,
function(_killerweaponbodypart)
    if exports.tacticsMOD:getRoundMapInfo()["modename"] ~= "lobby" then
        if killer and getElementType(killer) == "player" and killer ~= source then
            local account getPlayerAccount(killer)
            if account and not isGuestAccount(accountthen
                local accountName getAccountName(account)
                temporaryTable[accountName]["player_xp"] = temporaryTable[accountName]["player_xp"] + 100
                triggerClientEvent(killer"outPutKillMsg"killer"#FFFFFF["..getWeaponNameFromID(weapon or 55).."]  #FF7D00"..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x""").."  #FFFFFF100"255255255)
                temporaryTable[accountName]["total_kills"] = temporaryTable[accountName]["total_kills"] + 1
                temporaryTable[accountName]["total_hits"] = temporaryTable[accountName]["total_hits"] + 1
                temporaryTable[accountName]["total_dmg"] = temporaryTable[accountName]["total_dmg"] + math.ceil(getElementHealth(source))
                setElementData(killer"kill_streak", (getElementData(killer"kill_streak") or 0) + 1false)
                if not isTimer(multiKillTimer[killer]) then
                    multiKillTimer[killer] = setTimer(function(killeraccountName)
                        if isElement(killer) and getElementData(killer"multi_kill"then
                            triggerClientEvent(killer"outPutKillMsg"killer"#FFFFFFMulti Kill Bonus 20"255255255)
                            temporaryTable[accountName]["player_xp"] = temporaryTable[accountName]["player_xp"] + 20
                            setElementData(killer"multi_kill"falsefalse)
                        end
                        multiKillTimer[killer] = nil
                    end70001killeraccountName)
                else
                    setElementData(killer"multi_kill"truefalse)
                end
                if isTimer(multiKillTimer[source]) then
                    if getElementData(killer"Last_killer") ~= source then
                        triggerClientEvent(killer"outPutKillMsg"killer"#FFFFFFAvenger Bonus 25"255255255)
                        temporaryTable[accountName]["player_xp"] = temporaryTable[accountName]["player_xp"] + 25
                    end
                end
                if getElementData(killer"Last_killer") == source then
                    triggerClientEvent(killer"outPutKillMsg"killer"#FFFFFFPayback Bonus 50"255255255)
                    temporaryTable[accountName]["player_xp"] = temporaryTable[accountName]["player_xp"] + 50
                    setElementData(killer"Last_killer"falsefalse)
                end
                if bodypart == 9 then
                    temporaryTable[accountName]["total_headshots"] = temporaryTable[accountName]["total_headshots"] + 1
                    triggerClientEvent(killer"outPutKillMsg"killer"#FFFFFFHeadshot Bonus 50"255255255)
                    temporaryTable[accountName]["player_xp"] = temporaryTable[accountName]["player_xp"] + 50
                end
                if weapon == 0 then
                    temporaryTable[accountName]["total_fist"] = temporaryTable[accountName]["total_fist"] + 1
                elseif weapon == 24 then
                    temporaryTable[accountName]["total_deagle"] = temporaryTable[accountName]["total_deagle"] + 1
                elseif weapon == 25 then
                    temporaryTable[accountName]["total_shotgun"] = temporaryTable[accountName]["total_shotgun"] + 1
                elseif weapon == 34 then
                    temporaryTable[accountName]["total_sniper"] = temporaryTable[accountName]["total_sniper"] + 1
                elseif weapon == 33 then
                    temporaryTable[accountName]["total_rifle"] = temporaryTable[accountName]["total_rifle"] + 1
                elseif weapon == 16 then
                    temporaryTable[accountName]["total_grenade"] = temporaryTable[accountName]["total_grenade"] + 1
                end
            end
        end
        local account getPlayerAccount(source)
        setElementData(source"Last_killer"killerfalse)
        exports.tacticsMOD:setCameraSpectating(sourcesource"freecamera")
        setControlState(source"fire"false)
        toggleControl(source"fire"false)
        if killer and getElementType(killer) == "player" and killer ~= source then
            local account getPlayerAccount(killer)
            local kXkYkZ getElementPosition(killer)
            if account and not isGuestAccount(accountthen
                local killerRank rankTable[getAccountName(account)] or false
                triggerClientEvent(source"onRankSystemWaste"sourcekillermath.ceil(getElementHealth(killer)), killerRankgetWeaponNameFromID(weapon or 55), kXkYkZ)
            else
                triggerClientEvent(source"onRankSystemWaste"sourcekillermath.ceil(getElementHealth(killer)), falsegetWeaponNameFromID(weapon or 55), kXkYkZ)
            end
        else
            triggerClientEvent(source"onRankSystemWaste"sourcefalsefalsefalsegetWeaponNameFromID(weapon or 55))
        end
        
        if account and not isGuestAccount(accountthen
            local accountName getAccountName(account)
            temporaryTable[accountName]["total_deaths"] = temporaryTable[accountName]["total_deaths"] + 1
            temporaryTable[accountName]["kill_streak"] = math.max((getElementData(source"kill_streak") or 0), (temporaryTable[accountName]["kill_streak"] or 0))
            setElementData(source"kill_streak"0false)
        end
        local assistsTable getElementData(source"assists") or {}
        for accNamehp in pairs(assistsTable) do
            local player getAccountPlayer(getAccount(accName))
            if player and player ~= killer then
                temporaryTable[accName]["total_assists"] = temporaryTable[accName]["total_assists"] + 1
                temporaryTable[accName]["player_xp"] = temporaryTable[accName]["player_xp"] + hp
                triggerClientEvent(player"outPutKillMsg"player"#FFFFFFKill Assist "..hp255255255)
            end
        end
        setElementData(source"assists", {}, false)
        if isTimer(assistsTimer[source]) then 
            killTimer(assistsTimer[source])
            assistsTimer[source] = nil
        end
    end
end)

addEvent("onRoundFinish"true)
addEventHandler("onRoundFinish"root,
function(winnerreasonteamscores)
    if teamscores and type(teamscores) == "table" then
        for iteam in ipairs(getElementsByType("team")) do
            if ~= 1 then
                if teamscores[team] and teamscores[team] > 0 then
                    for iplayer in ipairs(getPlayersInTeam(team)) do
                        local account getPlayerAccount(player)
                        if account and not isGuestAccount(accountthen
                            local accountName getAccountName(account)
                            temporaryTable[accountName]["total_wins"] = temporaryTable[accountName]["total_wins"] + 1
                        end
                    end
                else
                    for iplayer in ipairs(getPlayersInTeam(team)) do
                        local account getPlayerAccount(player)
                        if account and not isGuestAccount(accountthen
                            local accountName getAccountName(account)
                            temporaryTable[accountName]["total_loses"] = temporaryTable[accountName]["total_loses"] + 1
                        end
                    end
                end
            end
        end
    end
    for accountNamevalue in pairs(temporaryTable) do
        local result dbPoll(dbQuery(db"SELECT * FROM RankTable WHERE account_name = ?"accountName), -1)
        if type(result) == "table" and #result ~= 0 then
            local mPlayer getAccountPlayer(getAccount(accountName))
            local PlayerName
            if mPlayer then
                PlayerName getPlayerName(mPlayer)
            else
                PlayerName result[1]["player_name"]
            end
            local XP value["player_xp"] + result[1]["player_xp"]
            local Kills value["total_kills"] + result[1]["total_kills"]
            local Deaths value["total_deaths"] + result[1]["total_deaths"]
            local Assists value["total_assists"] + result[1]["total_assists"]
            local Hits value["total_hits"] + result[1]["total_hits"]
            local DMG value["total_dmg"] + result[1]["total_dmg"]
            local HeadShots value["total_headshots"] + result[1]["total_headshots"]
            local Deagle value["total_deagle"] + result[1]["total_deagle"]
            local Sniper value["total_sniper"] + result[1]["total_sniper"]
            local Shotgun value["total_shotgun"] + result[1]["total_shotgun"]
            local Rifle value["total_rifle"] + result[1]["total_rifle"]
            local Grenade value["total_grenade"] + result[1]["total_grenade"]
            local Fist value["total_fist"] + result[1]["total_fist"]
            local Wins value["total_wins"] + result[1]["total_wins"]
            local Loses value["total_loses"] + result[1]["total_loses"]
            local Kill_Streak math.max((temporaryTable[accountName]["kill_streak"] or 0), result[1]["kill_streak"])
            local Time_Played = ((getTickCount() - value["total_playtime"])/1000) + result[1]["total_playtime"]
            dbExec(db"UPDATE RankTable SET player_name = ?, player_xp = ?, total_kills = ?, total_deaths = ?, total_assists = ?, total_hits = ?, total_dmg = ?, kill_streak = ?, total_headshots = ?, total_deagle = ?, total_sniper = ?, total_shotgun = ?, total_rifle = ?, total_grenade = ?, total_fist = ?, total_wins = ?, total_loses = ?, total_playtime = ? WHERE account_name = ?"PlayerNameXPKillsDeathsAssistsHitsDMGKill_StreakHeadShotsDeagleSniperShotgunRifleGrenadeFistWinsLosesTime_PlayedaccountName)
        end
    end
    temporaryTable nil
    temporaryTable = {}
    for iplayer in ipairs(getElementsByType("player")) do
        local account getPlayerAccount(player)
        if account and not isGuestAccount(accountthen
            setElementData(player"multi_kill"falsefalse)
            local accountName getAccountName(account)
            temporaryTable[accountName] = {
                ["player_xp"] = 0,
                ["total_kills"] = 0,
                ["total_deaths"] = 0,
                ["total_assists"] = 0,
                ["total_hits"] = 0,
                ["total_dmg"] = 0,
                ["kill_streak"] = 0,
                ["total_headshots"] = 0,
                ["total_deagle"] = 0,
                ["total_sniper"] = 0,
                ["total_shotgun"] = 0,
                ["total_rifle"] = 0,
                ["total_grenade"] = 0,
                ["total_fist"] = 0,
                ["total_wins"] = 0,
                ["total_loses"] = 0,
                ["total_playtime"] = getTickCount()
            }
        end
    end
end)

addEvent("onSendAmmoFired"true)
addEventHandler("onSendAmmoFired"root,
function(ammoFired)
    if ammoFired and ammoFired 0 then
        local account getPlayerAccount(source)
        if account and not isGuestAccount(accountthen
            local accountName getAccountName(account)
            local result dbPoll(dbQuery(db"SELECT total_fires FROM RankTable WHERE account_name = ?"accountName), -1)
            if type(result) == "table" and #result ~= 0 then
                dbExec(db"UPDATE RankTable SET total_fires = ? WHERE account_name = ?"ammoFired+result[1]["total_fires"], accountName)
            end
        end
    end
    updateCacheTable()
end)


Komentarz TheSebaPL dodany 2023-03-24, 06:11Dodałem tagi
Ostatnio zmieniony przez TheSebaPL 2023-03-24, 06:11, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2023-03-24, 10:45


Norbert1234

Nie umiem w LUA






Wiek: 22
Na forum: 3987 dni
Posty: 319
Nick w MP: Gusterowskyy

Piwa: 242

Respekt: 60

Kolego, powiem Ci tak. Nikt ci tu gotowca nie da, poczytaj o tym na czym polega jak si? tworzy, nie jest A? TAK skomplikowane dla mta wystarczy dla najprostszego dzia?ania sama podstawa. Podejrzewam, ze paczka by?a stawiana na czym? o ile si? nie myle sprawd? na czym
i scgiagnij baze.

Jak robicie pseudole to prosz? nie zmieniajcie grafiki nawet bez skalowania w?asnego, w???cie cos w ten kod. Scena mta i tak jest w pseudolach tak zostanie. Ale prosz? jak nie umiecie doda? tabelek w db, nie bie?cie sie za to, chyba, ze w celu nauki, popieram dobra metoda, wk?ad w?asny trzeba w?o?y?, gtao nie zrobi serwera za ciebie nawet jak masz gotowa paczke.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2023-03-24, 11:17


_TigerKill_







Wiek: 23
Na forum: 1460 dni
Posty: 5

Piwa: 6

Respekt: 50

Dobra dzk jako? to ogarn?

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Tagi: baza :: danych :: pod :: tactica
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku