BlueTheFurry Posted February 16, 2015 Share Posted February 16, 2015 Hello community, i am here with another problem, when a player joins who does not have his stats saved yet, he just gets a random Player's drift states, Debugscript says nothing, debugDB just has the standart stuff: [Query:INSERT INTO drifttab (spielername) VALUES ('RLS9001')] [Query:UPDATE drifttab SET Best=3,Last=3,Total=3 WHERE spielername ='RLS9001' ] etc server: local root = getRootElement() local thisResourceRoot = getResourceRootElement(getThisResource()) local drift_mejor = 0 local drift_nombre = "N/A" local connect=dbConnect("sqlite", "Drift.db" ) addEventHandler ( "onResourceStart", thisResourceRoot, function() dbExec(connect,"CREATE TABLE IF NOT EXISTS drifttab ( spielername TEXT, Best INTEGER DEFAULT 0, Last INTEGER DEFAULT 0, Total INTEGER DEFAULT 0)") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Drift Rank") local xmlFile = xmlLoadFile("recordDrift.xml") local xmlPuntaje = xmlFindChild(xmlFile, "score", 0) local xmlNombre = xmlFindChild(xmlFile, "name", 0) if xmlPuntaje and xmlNombre then drift_mejor = tonumber(xmlNodeGetValue(xmlPuntaje)) drift_nombre = xmlNodeGetValue(xmlNombre) outputDebugString(string.format("Drift: Record restored. (%d points) (%s)",drift_mejor,drift_nombre)) setTimer(triggerClientEvent, 3000, 1, root, "driftActualizarRecord", root, drift_mejor, drift_nombre) xmlUnloadFile(xmlFile) else outputDebugString("Drift: Server failed loading record data.") end end ) addEventHandler ( "onResourceStop", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Total Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Drift Rank") end ) addEventHandler("onVehicleDamage", root, function() thePlayer = getVehicleOccupant(source, 0) if thePlayer then triggerClientEvent(thePlayer, "driftCarCrashed", root, source) end end) function playerLoggedIn() local derAccount = getPlayerAccount(source) local pname = getPlayerName(source) if (derAccount) then local query = dbQuery( connect, "SELECT * FROM drifttab WHERE spielername = '"..pname.."';" ) local result, spaltenanzahl, errms = dbPoll(query,0) if spaltenanzahl > 0 then for result,row in pairs(result) do driftbest = row["Best"] driftlast = row["Last"] drifttotal = row["Total"] end else savepanelspalte=dbExec(connect, "INSERT INTO drifttab (spielername) VALUES (?)",pname) setElementData(getPlayerFromName(pname), "Last Drift", 3) setElementData(getPlayerFromName(pname), "Total Drift", 3) setElementData(getPlayerFromName(pname), "Best Drift", 3) local dq = dbQuery( connect, "UPDATE drifttab SET Best=?,Last=?,Total=? WHERE spielername =? ",getElementData(getPlayerFromName(pname), "Best Drift"),getElementData(getPlayerFromName(pname), "Last Drift"),getElementData(getPlayerFromName(pname), "Total Drift"),pname) dbFree(dq) end end if driftbest then setElementData(source, "Last Drift", driftlast) setElementData(source, "Total Drift", drifttotal) setElementData(source, "Best Drift", driftbest) outputChatBox("Drift Data Loaded.", source) elseif driftbest == "0" or driftbest == 0 then setElementData(source, "Last Drift", 3) setElementData(source, "Total Drift", 3) setElementData(source, "Best Drift", 3) elseif driftbest == nil then setElementData(source, "Last Drift", 3) setElementData(source, "Total Drift", 3) setElementData(source, "Best Drift", 3) end end addEventHandler("onPlayerLogin", getRootElement(), playerLoggedIn) function playerQuitSave() local Account = getPlayerAccount(source) local pname = getPlayerName(source) if (Account) then if not isGuestAccount(Account) then local query = dbQuery( connect, "UPDATE drifttab SET Best=?,Last=?,Total=? WHERE spielername =? ",getElementData(source, "Best Drift"),getElementData(source, "Last Drift"),getElementData(source, "Total Drift"),pname) dbFree(query) end end end addEventHandler("onPlayerQuit", getRootElement(), playerQuitSave) addEvent("driftNuevoRecord", true) addEventHandler("driftNuevoRecord", root, function(score, name) if score > drift_mejor then -- outputChatBox(string.format("New drift record! (%d points) (%s)",score,name)) drift_mejor = score drift_nombre = name triggerClientEvent(root, "driftActualizarRecord", root, drift_mejor, drift_nombre) end end) addEvent("driftClienteListo", true) addEventHandler("driftClienteListo", root, function(player) triggerClientEvent(player, "driftActualizarRecord", root, drift_mejor, drift_nombre) --outputChatBox(string.format("The actual record is %d points (%s)", drift_mejor, drift_nombre), player) end) --- FIN function updatelvl() local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do totaldrift = tonumber(getElementData(thePlayer, "Total Drift" )) or 0 if totaldrift < 99000 then setElementData(thePlayer, "Drift Rank", "Newbie" ) elseif totaldrift > 100000 and totaldrift < 500000 then setElementData(thePlayer, "Drift Rank", "Trained" ) elseif totaldrift > 500000 and totaldrift < 1000000 then setElementData(thePlayer, "Drift Rank", "Drifter" ) elseif totaldrift > 1000000 and totaldrift < 5000000 then setElementData(thePlayer, "Drift Rank", "Adv. Drifter" ) elseif totaldrift > 5000000 and totaldrift < 25000000 then setElementData(thePlayer, "Drift Rank", "Best Drifter" ) elseif totaldrift > 25000000 and totaldrift < 50000000 then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif totaldrift > 50000000 and totaldrift < 100000000 then setElementData(thePlayer, "Drift Rank", "Drift Expert" ) elseif totaldrift > 100000000 and totaldrift < 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Master" ) elseif totaldrift > 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Elite" ) end end end setTimer( updatelvl, 30000, 0 ) --addEvent("updatelvl", true ) --addEventHandler("updatelvl", getRootElement(), updatelvl ) client: --these are the banned vehicle ids where you cannot get drift points. local BannedIDs = { 432, 532 } local rootElem = getRootElement() local thisRoot = getResourceRootElement(getThisResource()) local player = getLocalPlayer() local vehicle local isValid = false local size = 1.2 local modo = 0.01 local score = 0 local screenScore = 0 local tick local idleTime local multTime local driftTime local Yellow = tocolor(255,255,0) local Red = tocolor(234,0,3) local TempCol = Yellow local mult = 1 local tablamult = {350,1400,4200,11200} local anterior = 0 local mejor = 0 local total = 0 local global_mejor = 0 local global_nombre = "N/A" local screenWidth, screenHeight = guiGetScreenSize() local x1,y1,x2,y2 = screenWidth*0.2,screenHeight*0,screenWidth*0.8,screenHeight*0.8 addEventHandler("onClientResourceStart", thisRoot, function() addEventHandler("onClientRender", rootElem, showText) triggerServerEvent("driftClienteListo", rootElem, player) end ) addEventHandler("onClientResourceStop", thisRoot, function() removeEventHandler("onClientRender", rootElem, showText) end ) function isValidVehicle(source) local temp = source or getPedOccupiedVehicle(player) if temp and getVehicleType(temp) ~= "Automobile" then return false end if getVehicleOccupant(temp,0) ~= player then return false end local vehID = getElementModel(temp) for k,v in ipairs(BannedIDs) do if vehID == v then return false end end return true end function showText() --dxDrawText(string.format("Best Drift: %s - %d",global_nombre,global_mejor),44,screenHeight-43,screenWidth,screenHeight,Yellow,1,"pricedown") local tempVehicle = getPedOccupiedVehicle(player) if not tempVehicle then isValid = false vehicle = nil return elseif not isValid then isValid = vehicle ~= tempVehicle and isValidVehicle(tempVehicle) vehicle = tempVehicle return elseif vehicle ~= tempVehicle then isValid = isValidVehicle(tempVehicle) vehicle = tempVehicle return end if size > 1.3 then modo = -0.01 elseif size < 1.2 then modo = 0.01 end size = size + modo tick = getTickCount() local angulo,velocidad = angle() total=getElementData(player, "Total Drift") mejor=getElementData(player, "Best Drift") local tempBool = tick - (idleTime or 0) < 750 if not tempBool and score ~= 0 then anterior = score setElementData(player, "Last Drift", anterior) total = total+anterior setElementData(player, "Total Drift", total) if score > mejor then mejor = score setElementData(player, "Best Drift", mejor) if score > global_mejor then triggerServerEvent("driftNuevoRecord", rootElem, score, getPlayerName(player)) end end triggerEvent("onVehicleDriftEnd", rootElem, tick-driftTime-750) score = 0 end if angulo ~= 0 then if tempBool then score = score + math.floor(angulo*velocidad)*mult else score = math.floor(angulo*velocidad)*mult triggerEvent("onVehicleDriftStart", rootElem) driftTime = tick end if TempCol == Red then TempCol = Yellow end screenScore = score idleTime = tick end local temp2 = string.format("Factor: X%d\n%s",mult,mult~=5 and string.format("Gain X%d with %d",mult+1,tablamult[mult]) or "MAX") dxDrawText(temp2, 20,200,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) if velocidad <= 0.3 and mult ~= 1 then dxDrawText("\n\nToo Slow!", 20,200,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) end if tick - (idleTime or 0) < 3000 then local temp = "DRIFT" if score >= 100000 then temp = "DRIFT\n\nDrift King!" elseif score >= 50000 then temp = "DRIFT\n\nInsane Drift!" elseif score >= 20000 then temp = "DRIFT\n\nOutrageous!" elseif score >= 15000 then temp = "DRIFT\n\nColossal!" elseif score >= 7000 then temp = "DRIFT\n\nSuberb!" elseif score >= 3000 then temp = "DRIFT\n\nGreat Drift!" elseif score >= 1000 then temp = "DRIFT\n\nGood Drift!" end dxDrawText(temp, x1,y1 + 6,x2,y2 + 0.2, TempCol, 2.2, "sans","center","top", false,true,false) dxDrawText(string.format("\n%d",screenScore), x1,y1+4,x2,y2, TempCol, size, "pricedown","center","top", false,true,false) end end function angle() local vx,vy,vz = getElementVelocity(vehicle) local modV = math.sqrt(vx*vx + vy*vy) if not isVehicleOnGround(vehicle) then return 0,modV end local rx,ry,rz = getElementRotation(vehicle) local sn,cs = -math.sin(math.rad(rz)), math.cos(math.rad(rz)) local deltaT = tick - (multTime or 0) if mult~= 1 and modV <= 0.3 and deltaT > 750 then mult = mult-1 multTime = tick elseif deltaT > 1500 then local temp = 1 if score >= 11200 then temp = 5 elseif score >= 4200 then temp = 4 elseif score >= 1400 then temp = 3 elseif score >= 350 then temp = 2 end if temp>mult then mult = temp multTime = tick end end if modV <= 0.2 then return 0,modV end --speed over 40 km/h local cosX = (sn*vx + cs*vy)/modV if cosX > 0.966 or cosX < 0 then return 0,modV end --angle between 15 and 90 degrees return math.deg(math.acos(cosX))*0.5, modV end addEvent("driftCarCrashed", true) addEventHandler("driftCarCrashed", rootElem, function() if score ~= 0 then idleTime = nil score = 0 mult = 1 TempCol = Red triggerEvent("onVehicleDriftEnd", rootElem, 0) end end ) addEvent("driftActualizarRecord", true) addEventHandler("driftActualizarRecord", rootElem, function(score, name) global_mejor = score global_nombre = name end ) addCommandHandler("resetdrift", function() anterior,mejor,total = 0,0,0 setElementData(player, "Last Drift", anterior) setElementData(player, "Total Drift", total) setElementData(player, "Best Drift", mejor) end ) this script isnt made by me, i just modified it, Link to comment
.:HyPeX:. Posted February 16, 2015 Share Posted February 16, 2015 You're using the player name as DB variable, wich is really crazy actually (Anyone before with the same name could've done the drifts). Use the serial and check again. Link to comment
BlueTheFurry Posted February 16, 2015 Author Share Posted February 16, 2015 You're using the player name as DB variable, wich is really crazy actually (Anyone before with the same name could've done the drifts). Use the serial and check again. Thanks, i now set it so it saves the Serials and set the Database up correctly, i'll report back when i get to test it! Link to comment
BlueTheFurry Posted February 19, 2015 Author Share Posted February 19, 2015 Nope its still the same, the player logged in without stats gets a random players stats ;_; Link to comment
.:HyPeX:. Posted February 19, 2015 Share Posted February 19, 2015 What would you define by random player stats? You're btw not using any value obtained from SQL onto the player, or at least not correctly: if driftbest then setElementData(source, "Last Drift", driftlast) setElementData(source, "Total Drift", drifttotal) setElementData(source, "Best Drift", driftbest) outputChatBox("Drift Data Loaded.", source) elseif driftbest == "0" or driftbest == 0 then setElementData(source, "Last Drift", 3) setElementData(source, "Total Drift", 3) setElementData(source, "Best Drift", 3) elseif driftbest == nil then setElementData(source, "Last Drift", 3) setElementData(source, "Total Drift", 3) setElementData(source, "Best Drift", 3) end This doesnt make much sence, since it will be either the first one (it exists) or the last one (It doesnt. Aka. nil) So if it doesnt exists, then it will be "3". This would be your "random player"? Link to comment
BlueTheFurry Posted February 19, 2015 Author Share Posted February 19, 2015 I dont get what you mean, "3" is the Element Data aka Drift Score on the scoreboard, "source" is the logged in player Link to comment
.:HyPeX:. Posted February 19, 2015 Share Posted February 19, 2015 I dont get what you mean, "3" is the Element Data aka Drift Score on the scoreboard, "source" is the logged in player "3" is being the DATA itself there. Not the key. if the random player data you get is 3 then there's your problem. Link to comment
AMARANT Posted February 19, 2015 Share Posted February 19, 2015 Btw, I wouldn't recommend you to use dbQuery in UPDATE statements. Use dbExec instead. Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 Btw, I wouldn't recommend you to use dbQuery in UPDATE statements. Use dbExec instead. Thanks, I'll try that asap @Hypex The Element Data is correct, setElementData(element, key, value) and 3 is just the Drift score of souce Link to comment
.:HyPeX:. Posted February 20, 2015 Share Posted February 20, 2015 Btw, I wouldn't recommend you to use dbQuery in UPDATE statements. Use dbExec instead. Thanks, I'll try that asap @Hypex The Element Data is correct, setElementData(element, key, value) and 3 is just the Drift score of souce Could you post the code after you changed the variable to serial? i cant find anything else wrong with the code Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 k server: function getPlayerFromSerial ( serial ) assert ( type ( serial ) == "string" and #serial == 32, "getPlayerFromSerial - invalid serial" ) for index, player in ipairs ( getElementsByType ( "player" ) ) do if ( getPlayerSerial ( player ) == serial ) then return player end end return false end local root = getRootElement() local thisResourceRoot = getResourceRootElement(getThisResource()) local drift_mejor = 0 local drift_nombre = "N/A" local connect=dbConnect("sqlite", "Drift.db" ) addEventHandler ( "onResourceStart", thisResourceRoot, function() dbExec(connect,"CREATE TABLE IF NOT EXISTS drifttab ( spielername TEXT, Best INTEGER DEFAULT 0, Last INTEGER DEFAULT 0, Total INTEGER DEFAULT 0)") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Drift Rank") local xmlFile = xmlLoadFile("recordDrift.xml") local xmlPuntaje = xmlFindChild(xmlFile, "score", 0) local xmlNombre = xmlFindChild(xmlFile, "name", 0) if xmlPuntaje and xmlNombre then drift_mejor = tonumber(xmlNodeGetValue(xmlPuntaje)) drift_nombre = xmlNodeGetValue(xmlNombre) outputDebugString(string.format("Drift: Record restored. (%d points) (%s)",drift_mejor,drift_nombre)) setTimer(triggerClientEvent, 3000, 1, root, "driftActualizarRecord", root, drift_mejor, drift_nombre) xmlUnloadFile(xmlFile) else outputDebugString("Drift: Server failed loading record data.") end end ) addEventHandler ( "onResourceStop", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Total Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Drift Rank") end ) addEventHandler("onVehicleDamage", root, function() thePlayer = getVehicleOccupant(source, 0) if thePlayer then triggerClientEvent(thePlayer, "driftCarCrashed", root, source) end end) function playerLoggedIn() local derAccount = getPlayerAccount(source) local pname = getPlayerName(source) local pserial = getPlayerSerial(source) if (derAccount) then local query = dbQuery( connect, "SELECT * FROM drifttab WHERE spielername = '"..pserial.."';" ) local result, spaltenanzahl, errms = dbPoll(query,-1) if spaltenanzahl > 0 then for result,row in pairs(result) do driftbest = row["Best"] driftlast = row["Last"] drifttotal = row["Total"] end dbFree(query) else savepanelspalte=dbExec(connect, "INSERT INTO drifttab (spielername) VALUES (?)",pserial) setElementData(getPlayerFromSerial(pserial), "Last Drift", 3) setElementData(getPlayerFromSerial(pserial), "Total Drift", 3) setElementData(getPlayerFromSerial(pserial), "Best Drift", 3) local dq = dbExec( connect, "UPDATE drifttab SET Best=?,Last=?,Total=? WHERE spielername =? ",getElementData(getPlayerFromSerial(pserial), "Best Drift"),getElementData(getPlayerFromSerial(pserial), "Last Drift"),getElementData(getPlayerFromSerial(pserial), "Total Drift"),pserial) dbFree(dq) end end if driftbest then setElementData(getPlayerFromSerial(pserial), "Last Drift", driftlast) setElementData(getPlayerFromSerial(pserial), "Total Drift", drifttotal) setElementData(getPlayerFromSerial(pserial), "Best Drift", driftbest) outputChatBox("Drift Data Loaded.", source) elseif driftbest == "0" or driftbest == 0 then setElementData(getPlayerFromSerial(pserial), "Last Drift", 3) setElementData(getPlayerFromSerial(pserial), "Total Drift", 3) setElementData(getPlayerFromSerial(pserial), "Best Drift", 3) elseif driftbest == nil then setElementData(getPlayerFromSerial(pserial), "Last Drift", 3) setElementData(getPlayerFromSerial(pserial), "Total Drift", 3) setElementData(getPlayerFromSerial(pserial), "Best Drift", 3) end end addEventHandler("onPlayerLogin", getRootElement(), playerLoggedIn) function playerQuitSave() local Account = getPlayerAccount(source) local pname = getPlayerName(source) local pserial = getPlayerSerial(source) if (Account) then if not isGuestAccount(Account) then local query = dbQuery( connect, "UPDATE drifttab SET Best=?,Last=?,Total=? WHERE spielername =? ",getElementData(source, "Best Drift"),getElementData(source, "Last Drift"),getElementData(source, "Total Drift"),pserial) dbFree(query) end end end addEventHandler("onPlayerQuit", getRootElement(), playerQuitSave) addEvent("driftNuevoRecord", true) addEventHandler("driftNuevoRecord", root, function(score, name) if score > drift_mejor then -- outputChatBox(string.format("New drift record! (%d points) (%s)",score,name)) drift_mejor = score drift_nombre = name triggerClientEvent(root, "driftActualizarRecord", root, drift_mejor, drift_nombre) end end) addEvent("driftClienteListo", true) addEventHandler("driftClienteListo", root, function(player) triggerClientEvent(player, "driftActualizarRecord", root, drift_mejor, drift_nombre) --outputChatBox(string.format("The actual record is %d points (%s)", drift_mejor, drift_nombre), player) end) --- FIN function updatelvl() local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do totaldrift = tonumber(getElementData(thePlayer, "Total Drift" )) or 0 if totaldrift < 99000 then setElementData(thePlayer, "Drift Rank", "Newbie" ) elseif totaldrift > 100000 and totaldrift < 500000 then setElementData(thePlayer, "Drift Rank", "Trained" ) elseif totaldrift > 500000 and totaldrift < 1000000 then setElementData(thePlayer, "Drift Rank", "Drifter" ) elseif totaldrift > 1000000 and totaldrift < 5000000 then setElementData(thePlayer, "Drift Rank", "Adv. Drifter" ) elseif totaldrift > 5000000 and totaldrift < 25000000 then setElementData(thePlayer, "Drift Rank", "Best Drifter" ) elseif totaldrift > 25000000 and totaldrift < 50000000 then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif totaldrift > 50000000 and totaldrift < 100000000 then setElementData(thePlayer, "Drift Rank", "Drift Expert" ) elseif totaldrift > 100000000 and totaldrift < 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Master" ) elseif totaldrift > 250000000 and totaldrift < 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Legend" ) elseif totaldrift > 500000000 then setElementData(thePlayer, "Drift Rank", "Drift Elite" ) end end end setTimer( updatelvl, 30000, 0 ) --addEvent("updatelvl", true ) --addEventHandler("updatelvl", getRootElement(), updatelvl ) c --these are the banned vehicle ids where you cannot get drift points. local BannedIDs = { 432, 532 } local rootElem = getRootElement() local thisRoot = getResourceRootElement(getThisResource()) local player = getLocalPlayer() local vehicle local isValid = false local size = 1.2 local modo = 0.01 local score = 0 local screenScore = 0 local tick local idleTime local multTime local driftTime local Yellow = tocolor(255,255,0) local Red = tocolor(234,0,3) local TempCol = Yellow local mult = 1 local tablamult = {350,1400,4200,11200} local anterior = 0 local mejor = 0 local total = 0 local global_mejor = 0 local global_nombre = "N/A" local screenWidth, screenHeight = guiGetScreenSize() local x1,y1,x2,y2 = screenWidth*0.2,screenHeight*0,screenWidth*0.8,screenHeight*0.8 addEventHandler("onClientResourceStart", thisRoot, function() addEventHandler("onClientRender", rootElem, showText) triggerServerEvent("driftClienteListo", rootElem, player) end ) addEventHandler("onClientResourceStop", thisRoot, function() removeEventHandler("onClientRender", rootElem, showText) end ) function isValidVehicle(source) local temp = source or getPedOccupiedVehicle(player) if temp and getVehicleType(temp) ~= "Automobile" then return false end if getVehicleOccupant(temp,0) ~= player then return false end local vehID = getElementModel(temp) for k,v in ipairs(BannedIDs) do if vehID == v then return false end end return true end function showText() --dxDrawText(string.format("Best Drift: %s - %d",global_nombre,global_mejor),44,screenHeight-43,screenWidth,screenHeight,Yellow,1,"pricedown") local tempVehicle = getPedOccupiedVehicle(player) if not tempVehicle then isValid = false vehicle = nil return elseif not isValid then isValid = vehicle ~= tempVehicle and isValidVehicle(tempVehicle) vehicle = tempVehicle return elseif vehicle ~= tempVehicle then isValid = isValidVehicle(tempVehicle) vehicle = tempVehicle return end if size > 1.3 then modo = -0.01 elseif size < 1.2 then modo = 0.01 end size = size + modo tick = getTickCount() local angulo,velocidad = angle() total=getElementData(player, "Total Drift") mejor=getElementData(player, "Best Drift") local tempBool = tick - (idleTime or 0) < 750 if not tempBool and score ~= 0 then anterior = score setElementData(player, "Last Drift", anterior) total = total+anterior setElementData(player, "Total Drift", total) if score > mejor then mejor = score setElementData(player, "Best Drift", mejor) if score > global_mejor then triggerServerEvent("driftNuevoRecord", rootElem, score, getPlayerName(player)) end end triggerEvent("onVehicleDriftEnd", rootElem, tick-driftTime-750) score = 0 end if angulo ~= 0 then if tempBool then score = score + math.floor(angulo*velocidad)*mult else score = math.floor(angulo*velocidad)*mult triggerEvent("onVehicleDriftStart", rootElem) driftTime = tick end if TempCol == Red then TempCol = Yellow end screenScore = score idleTime = tick end local temp2 = string.format("Factor: X%d\n%s",mult,mult~=5 and string.format("Gain X%d with %d",mult+1,tablamult[mult]) or "MAX") dxDrawText(temp2, 20,200,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) if velocidad <= 0.3 and mult ~= 1 then dxDrawText("\n\nToo Slow!", 20,200,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) end if tick - (idleTime or 0) < 3000 then local temp = "DRIFT" if score >= 100000 then temp = "DRIFT\n\nDrift King!" elseif score >= 50000 then temp = "DRIFT\n\nInsane Drift!" elseif score >= 20000 then temp = "DRIFT\n\nOutrageous!" elseif score >= 15000 then temp = "DRIFT\n\nColossal!" elseif score >= 7000 then temp = "DRIFT\n\nSuberb!" elseif score >= 3000 then temp = "DRIFT\n\nGreat Drift!" elseif score >= 1000 then temp = "DRIFT\n\nGood Drift!" end dxDrawText(temp, x1,y1 + 6,x2,y2 + 0.2, TempCol, 2.2, "sans","center","top", false,true,false) dxDrawText(string.format("\n%d",screenScore), x1,y1+4,x2,y2, TempCol, size, "pricedown","center","top", false,true,false) end end function angle() local vx,vy,vz = getElementVelocity(vehicle) local modV = math.sqrt(vx*vx + vy*vy) if not isVehicleOnGround(vehicle) then return 0,modV end local rx,ry,rz = getElementRotation(vehicle) local sn,cs = -math.sin(math.rad(rz)), math.cos(math.rad(rz)) local deltaT = tick - (multTime or 0) if mult~= 1 and modV <= 0.3 and deltaT > 750 then mult = mult-1 multTime = tick elseif deltaT > 1500 then local temp = 1 if score >= 11200 then temp = 5 elseif score >= 4200 then temp = 4 elseif score >= 1400 then temp = 3 elseif score >= 350 then temp = 2 end if temp>mult then mult = temp multTime = tick end end if modV <= 0.2 then return 0,modV end --speed over 40 km/h local cosX = (sn*vx + cs*vy)/modV if cosX > 0.966 or cosX < 0 then return 0,modV end --angle between 15 and 90 degrees return math.deg(math.acos(cosX))*0.5, modV end addEvent("driftCarCrashed", true) addEventHandler("driftCarCrashed", rootElem, function() if score ~= 0 then idleTime = nil score = 0 mult = 1 TempCol = Red triggerEvent("onVehicleDriftEnd", rootElem, 0) end end ) addEvent("driftActualizarRecord", true) addEventHandler("driftActualizarRecord", rootElem, function(score, name) global_mejor = score global_nombre = name end ) addCommandHandler("resetdrift", function() anterior,mejor,total = 0,0,0 setElementData(player, "Last Drift", anterior) setElementData(player, "Total Drift", total) setElementData(player, "Best Drift", mejor) end ) Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 No ideas? Link to comment
.:HyPeX:. Posted February 20, 2015 Share Posted February 20, 2015 i was sleeping... Try this function for the login. Also, you might want to flush the table from all the "name" older usless entries. function playerLoggedIn() local derAccount = getPlayerAccount(source) local pname = getPlayerName(source) local pserial = getPlayerSerial(source) if (derAccount) then local query = dbQuery( connect, "SELECT * FROM drifttab WHERE spielername = '"..pserial.."';" ) local result, spaltenanzahl, errms = dbPoll(query,-1) if spaltenanzahl > 0 then for result,row in pairs(result) do driftbest = row["Best"] driftlast = row["Last"] drifttotal = row["Total"] end setElementData(getPlayerFromSerial(pserial), "Last Drift", driftlast) setElementData(getPlayerFromSerial(pserial), "Total Drift", drifttotal) setElementData(getPlayerFromSerial(pserial), "Best Drift", driftbest) outputChatBox("Drift Data Loaded.", source) else savepanelspalte=dbExec(connect, "INSERT INTO drifttab (spielername) VALUES (?)",pserial) setElementData(getPlayerFromSerial(pserial), "Last Drift", 3) setElementData(getPlayerFromSerial(pserial), "Total Drift", 3) setElementData(getPlayerFromSerial(pserial), "Best Drift", 3) local dq = dbExec( connect, "UPDATE drifttab SET Best=?,Last=?,Total=? WHERE spielername =? ",getElementData(getPlayerFromSerial(pserial), "Best Drift"),getElementData(getPlayerFromSerial(pserial), "Last Drift"),getElementData(getPlayerFromSerial(pserial), "Total Drift"),pserial) end end end addEventHandler("onPlayerLogin", getRootElement(), playerLoggedIn) Remove both dbFree, they're not needed (Neither with dbExec nor after dbPoll was called) Also, you use the function getPlayerFromSerial (Becouse you assume the source is not available there) But then you use the variable serial, wich is exactly the same as source there (It is even defined local) Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 i was sleeping... Try this function for the login. Also, you might want to flush the table from all the "name" older usless entries. i already changed the "name" entries to the serials anyways, thanks, i'll try that, i'll report back asap Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 Nope, still got my other players stats, i am going crazy here ;_; Link to comment
.:HyPeX:. Posted February 20, 2015 Share Posted February 20, 2015 Nope, still got my other players stats, i am going crazy here ;_; Do this: -Backup the database - Flush it - Test again if you get random player stats. Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 Thanks, i'll try it Link to comment
BlueTheFurry Posted February 20, 2015 Author Share Posted February 20, 2015 I dont know anymore 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