Wysłany: 2023-03-24, 02:42
_TigerKill_
Wiek: 23 Na forum: 1460 dni Posty: 5
Piwa : 6
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 i , player in ipairs ( getElementsByType ( "player" )) do
local account = getPlayerAccount ( player )
if account and not isGuestAccount ( account ) then
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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , accountName , playerName , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
end
end
end
updateCacheTable ()
end )
addEventHandler ( "onPlayerLogin" , root ,
function( _ , account )
local accountName = getAccountName ( account )
if not temporaryTable [ accountName ] then
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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , accountName , playerName , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
table . insert ( cacheTable , { accountName , playerName , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 })
end
end
end )
function calculateRank ( XP )
for i = 0 , 99999 do
CurrentXP = i *( i >= 1 and i 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 ( cacheTimer ) then
cacheTable = nil
cacheTable = {}
local result = dbPoll ( dbQuery ( db , "SELECT * FROM RankTable" ), - 1 )
if type ( result ) == "table" and #result ~= 0 then
for i , R 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( player , old , new)
if isElement ( player ) then
triggerClientEvent ( player , "onRankChange" , player , old , new)
end
end , 11000 , 1 , player , rankTable [ 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() end , 10000 , 1 )
end
end
addEvent ( "onClientRequestStats" , true )
addEventHandler ( "onClientRequestStats" , root ,
function()
local accountName = getAccountName ( getPlayerAccount ( source ))
triggerClientEvent ( source , "onServerSendStats" , source , cacheTable , accountName )
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 ( account ) then
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 [ accountName ] then
assistsTable [ accountName ] = assistsTable [ accountName ] + math . ceil ( loss )
else
assistsTable [ accountName ] = math . ceil ( loss )
end
setElementData ( source , "assists" , assistsTable , false )
if isTimer ( assistsTimer [ source ]) then
resetTimer ( assistsTimer [ source ])
else
assistsTimer [ source ] = setTimer (function( source )
assistsTimer [ source ] = nil
if isElement ( source ) then
setElementData ( source , "assists" , {}, false )
end
end , 10000 , 1 , source )
end
end
end
end
end )
addEventHandler ( "onPlayerWasted" , root ,
function( _ , killer , weapon , bodypart )
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 ( account ) then
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" , 255 , 255 , 255 )
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 ) + 1 , false )
if not isTimer ( multiKillTimer [ killer ]) then
multiKillTimer [ killer ] = setTimer (function( killer , accountName )
if isElement ( killer ) and getElementData ( killer , "multi_kill" ) then
triggerClientEvent ( killer , "outPutKillMsg" , killer , "#FFFFFFMulti Kill Bonus 20" , 255 , 255 , 255 )
temporaryTable [ accountName ][ "player_xp" ] = temporaryTable [ accountName ][ "player_xp" ] + 20
setElementData ( killer , "multi_kill" , false , false )
end
multiKillTimer [ killer ] = nil
end , 7000 , 1 , killer , accountName )
else
setElementData ( killer , "multi_kill" , true , false )
end
if isTimer ( multiKillTimer [ source ]) then
if getElementData ( killer , "Last_killer" ) ~= source then
triggerClientEvent ( killer , "outPutKillMsg" , killer , "#FFFFFFAvenger Bonus 25" , 255 , 255 , 255 )
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" , 255 , 255 , 255 )
temporaryTable [ accountName ][ "player_xp" ] = temporaryTable [ accountName ][ "player_xp" ] + 50
setElementData ( killer , "Last_killer" , false , false )
end
if bodypart == 9 then
temporaryTable [ accountName ][ "total_headshots" ] = temporaryTable [ accountName ][ "total_headshots" ] + 1
triggerClientEvent ( killer , "outPutKillMsg" , killer , "#FFFFFFHeadshot Bonus 50" , 255 , 255 , 255 )
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" , killer , false )
exports . tacticsMOD : setCameraSpectating ( source , source , "freecamera" )
setControlState ( source , "fire" , false )
toggleControl ( source , "fire" , false )
if killer and getElementType ( killer ) == "player" and killer ~= source then
local account = getPlayerAccount ( killer )
local kX , kY , kZ = getElementPosition ( killer )
if account and not isGuestAccount ( account ) then
local killerRank = rankTable [ getAccountName ( account )] or false
triggerClientEvent ( source , "onRankSystemWaste" , source , killer , math . ceil ( getElementHealth ( killer )), killerRank , getWeaponNameFromID ( weapon or 55 ), kX , kY , kZ )
else
triggerClientEvent ( source , "onRankSystemWaste" , source , killer , math . ceil ( getElementHealth ( killer )), false , getWeaponNameFromID ( weapon or 55 ), kX , kY , kZ )
end
else
triggerClientEvent ( source , "onRankSystemWaste" , source , false , false , false , getWeaponNameFromID ( weapon or 55 ))
end
if account and not isGuestAccount ( account ) then
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" , 0 , false )
end
local assistsTable = getElementData ( source , "assists" ) or {}
for accName , hp 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 " .. hp , 255 , 255 , 255 )
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( winner , reason , teamscores )
if teamscores and type ( teamscores ) == "table" then
for i , team in ipairs ( getElementsByType ( "team" )) do
if i ~= 1 then
if teamscores [ team ] and teamscores [ team ] > 0 then
for i , player in ipairs ( getPlayersInTeam ( team )) do
local account = getPlayerAccount ( player )
if account and not isGuestAccount ( account ) then
local accountName = getAccountName ( account )
temporaryTable [ accountName ][ "total_wins" ] = temporaryTable [ accountName ][ "total_wins" ] + 1
end
end
else
for i , player in ipairs ( getPlayersInTeam ( team )) do
local account = getPlayerAccount ( player )
if account and not isGuestAccount ( account ) then
local accountName = getAccountName ( account )
temporaryTable [ accountName ][ "total_loses" ] = temporaryTable [ accountName ][ "total_loses" ] + 1
end
end
end
end
end
end
for accountName , value 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 = ?" , PlayerName , XP , Kills , Deaths , Assists , Hits , DMG , Kill_Streak , HeadShots , Deagle , Sniper , Shotgun , Rifle , Grenade , Fist , Wins , Loses , Time_Played , accountName )
end
end
temporaryTable = nil
temporaryTable = {}
for i , player in ipairs ( getElementsByType ( "player" )) do
local account = getPlayerAccount ( player )
if account and not isGuestAccount ( account ) then
setElementData ( player , "multi_kill" , false , false )
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 ( account ) then
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 )
Ostatnio zmieniony przez TheSebaPL 2023-03-24, 06:11, w całości zmieniany 1 raz
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
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.
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
Dobra dzk jako? to ogarn?
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: