Jump to content

Search the Community

Showing results for tags 'saving'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Multi Theft Auto: San Andreas 1.x
    • Support for MTA:SA 1.x
    • User Guides
    • Open Source Contributors
    • Suggestions
    • Ban appeals
  • General MTA
    • News
    • Media
    • Site/Forum/Discord/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • MTA Community
    • Scripting
    • Maps
    • Resources
    • Other Creations & GTA modding
    • Competitive gameplay
    • Servers
  • Other
    • General
    • Multi Theft Auto 0.5r2
    • Third party GTA mods
  • Archive
    • Archived Items
    • Trash

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Gang


Location


Occupation


Interests

Found 3 results

  1. سلام میخواستم بدونم چطور باید دیتا های پلیر مثل فکشنش اسکینش میزان پولش و غیره رو وقتی از سرور میره ذخیره کنم و وقتی دوباره بر میگرده همون اطلاعاتو بهش بدم؟
  2. Hi guys. Hm, After wandering for a while I found right here on the community the saving drift points script I asked about before. I don't know much about programming, but I've been studying it and apparently there's something wrong with the code... It only works when I start the resource, If I drift for a second time it just doesn't work, nothing happens, and the points I get when I drift for the first time after starting the resource doesn't appear on the scoreboard, even though the columns are there! I don't want to bother anyone, but could someone help me out with it? I've been looking for it for weeks now! This is the file drft.lua --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 size = 1.4 local modo = 0.01 local score = 0 local screenScore = 0 local tick local idleTime local multTime local driftTime local Yellow = tocolor(0,255,0) local Red = tocolor(234,0,3) local TempCol = Yellow local White = tocolor(255,255,255) 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.1,screenWidth*0.8,screenHeight*0.8 textcols = { {0,255,0, 255}, { 255,232,25, 255 }, { 0, 150, 255, 255 }, {0,255,0, 255}, { 255,232,25, 255 }, { 0, 150, 255, 255 }, {0,255,0, 255}, { 255,232,25, 255 }, { 0, 150, 255, 255 }, {0,255,0, 255}, { 255,232,25, 255 }, { 0, 150, 255, 255 } } function randomtxtcol( ) _tempcols = math.random(#textcols) tempr, tempg, tempb = textcols[_tempcols][1], textcols[_tempcols][2], textcols[_tempcols][3] Yellow = tocolor(tempr, tempg, tempb) TempCol = Yellow end setTimer( randomtxtcol, 600000, 0 ) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), randomtxtcol ) addEventHandler("onClientResourceStart", thisRoot, function() addEventHandler("onClientRender", rootElem, showText) --outputChatBox("Waiting for server drift data...") triggerServerEvent("driftClienteListo", rootElem, player) end ) addEventHandler("onClientResourceStop", thisRoot, function() removeEventHandler("onClientRender", rootElem, showText) end ) function isValidVehicle() local temp = getPedOccupiedVehicle(player) if not temp or getVehicleOccupant(temp,0) ~= player or getVehicleType(temp) ~= "Automobile" then return false end local vehID = getElementModel(temp) for k,v in ipairs(BannedIDs) do if vehID == v then return false end end return temp end function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end function showText() dxDrawText(string.format("Best Drift: %s - %d",global_nombre,global_mejor),24,screenHeight-280,screenWidth,screenHeight,White,0.85,"pricedown") vehicle = isValidVehicle() if not vehicle then 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, "Drift Score" ) 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 cash = anterior/100 triggerServerEvent("updatecash", player, player, cash ) checkPuntaje(anterior) setElementData(player, "Drift Score", total) if score > mejor then mejor = score setElementData(player, "Best Drift", mejor) end triggerEvent("onVehicleDriftEnd", rootElem, tick-driftTime-750) score = 0 end if angulo ~= 0 then if score == 0 then triggerEvent("onVehicleDriftStart", rootElem) driftTime = tick end if tempBool then score = score + math.floor(angulo*velocidad)*mult else score = math.floor(angulo*velocidad)*mult 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,195,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) if velocidad <= 0.3 and mult ~= 1 then dxDrawText("\n\nToo Slow!", 20,195,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,x2,y2, TempCol, 2.2, "sans","center","top", false,true,false) dxDrawText(string.format("\n%d",screenScore), x1,y1-10,x2,y2, TempCol, size+0.15, "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 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 ) function resetScore() anterior,mejor,total = 0,0,0 setElementData(player, "Last Drift", anterior) setElementData(player, "Drift Score", total) setElementData(player, "Best Drift", mejor) end addCommandHandler("resetdrift", resetScore) function checkPuntaje(sendscore) if sendscore > global_mejor then triggerServerEvent("driftNuevoRecord", rootElem, sendscore, getPlayerName(player)) end end addEventHandler("onClientPlayerFinish", rootElem, checkPuntaje) addEventHandler("onClientPlayerOutOfTime", rootElem, checkPuntaje) drft_server.lua local root = getRootElement() local thisResourceRoot = getResourceRootElement(getThisResource()) local drift_records = {} --local drift_record_number = 0 --local drift_record_player = "N/A" -- Record Saving function XMLInit() xmlRecordsFile = xmlLoadFile("recordDrift.xml") scorenode = xmlFindChild( xmlRecordsFile, "score", 0 ) xmlRecordScore = xmlNodeGetValue( scorenode ) playernode = xmlFindChild ( xmlRecordsFile, "name", 0 ) xmlRecordPlayer = xmlNodeGetValue( playernode ) drift_record_number = tonumber(xmlRecordScore) drift_record_player = xmlRecordPlayer --outputChatBox("The Current Drift Record holder is: "..xmlRecordPlayer.." with "..xmlRecordScore.." Points!", root, 255, 255, 255 ) xmlUnloadFile( xmlRecordsFile ) end function XMLSetRecord(record,user) xmlRecordsFile = xmlLoadFile("recordDrift.xml") scorexml = xmlFindChild( xmlRecordsFile, "score", 0 ) xmlNodeSetValue( scorexml, record ) playerxml = xmlFindChild( xmlRecordsFile, "name", 0 ) xmlNodeSetValue( playerxml, user ) xmlSaveFile( xmlRecordsFile ) xmlUnloadFile( xmlRecordsFile ) end addEventHandler("onResourceStart", thisResourceRoot, XMLInit ) -- Drift Ranks call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Drift Rank") function updatelvl() local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do totaldrift = tonumber(getElementData(thePlayer, "Drift Score" )) 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 Expert" ) elseif totaldrift > 50000000 and totaldrift < 100000000 then setElementData(thePlayer, "Drift Rank", "Drift King" ) elseif totaldrift > 100000000 and totaldrift < 250000000 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 ) addEventHandler ( "onResourceStart", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Drift Score") XMLInit() addEvent("driftClienteListo", true) addEventHandler("driftClienteListo", root, function(player) triggerClientEvent(player, "driftActualizarRecord", root, drift_record_number, drift_record_player) if drift_record_number == 0 then outputChatBox("There's no drift record set!", player) else outputChatBox(string.format("The current drift record is %d points (%s)", drift_record_number, drift_record_player), player) end end) end ) addEventHandler ( "onResourceStop", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Drift Score") end ) addEventHandler ( "onGamemodeMapStop", root, function(mapResource) end) addEventHandler("onVehicleDamage", root, function() thePlayer = getVehicleOccupant(source, 0) if thePlayer then triggerClientEvent(thePlayer, "driftCarCrashed", root, source) end end) addEvent("driftNuevoRecord", true) addEventHandler("driftNuevoRecord", root, function(score, name) if score > drift_record_number then outputChatBox(string.format("New drift record! (%d points) (%s)",score,name)) drift_record_number = score drift_record_player = name XMLSetRecord( score, name ) triggerClientEvent(root, "driftActualizarRecord", root, drift_record_number, drift_record_player) end end) function gcash(player,money) givePlayerMoney( player, tonumber(money) ) end addEvent("updatecash", true ) addEventHandler("updatecash", root, gcash ) -- saving / Load function loadDrift (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount (source))) then if getAccountData(theCurrentAccount, "Drift Score") == false or getAccountData(theCurrentAccount, "Drift Score") == nil then setAccountData(theCurrentAccount, "Drift Score", 0 ) setElementData(source, "Drift Score", 0 ) end setElementData( source, "Drift Score", getAccountData(theCurrentAccount, "Drift Score" ) ) if getAccountData(theCurrentAccount, "Best Drift") == false or getAccountData(theCurrentAccount, "Best Drift") == nil then setAccountData(theCurrentAccount, "Best Drift", 0 ) setElementData(source, "Best Drift", 0 ) end setElementData( source, "Best Drift", getAccountData(theCurrentAccount, "Best Drift" ) ) end end addEventHandler ("onPlayerLogin", getRootElement(), loadDrift) function saveDrift (quitType, reason, responsibleElement) if not (isGuestAccount (getPlayerAccount (source))) then account = getPlayerAccount (source) if (account) then if getElementData(source, "Drift Score") == false or getElementData(source, "Drift Score") == nil then setAccountData(account, "Drift Score", 0 ) setElementData(source, "Drift Score", 0 ) end setAccountData(account, "Drift Score", getElementData(source, "Drift Score" ) ) if getElementData(source, "Best Drift") == false or getElementData(source, "Best Drift") == nil then setAccountData(account, "Best Drift", 0 ) setElementData(source, "Best Drift", 0 ) end setAccountData(account, "Best Drift", getElementData(source, "Best Drift" ) ) end end end addEventHandler ("onPlayerQuit", getRootElement(), saveDrift) recordDrift.xml <meta> <score>1</score> <name>None</name> </meta>
  3. so i tried to make saving system that saves kills and deaths but it doesn't save full script local root = getRootElement() local scoresRoot = getResourceRootElement(getThisResource()) local scoreColumns = {"Kills", "Deaths", "ratio", "status"} local isColumnActive = {} local KDR_DECIMAL_PLACES = 2 --http://lua-users.org/wiki/SimpleRound local function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end local function setScoreData (element, column, data) if isColumnActive[column] then setElementData(element, column, data) end end local dbConnection = dbConnect("sqlite", "backupexprank.db") local qh = dbQuery( dbConnection,"CREATE TABLE IF NOT EXISTS scores (name text,Kills text,Deaths text)") dbFree( qh ) function saveScore(sourcePlayer) local account = getPlayerAccount(sourcePlayer) local name = getAccountName(account) local Kills = getAccountData(account, "Kills") local Deaths = getAccountData(account, "Deaths") local qh = dbQuery( dbConnection, "SELECT * FROM scores where name=?",name) local res = dbPoll(qh,-1) dbFree( qh ) if #res > 0 then dbExec( dbConnection, "UPDATE scores SET Deaths=? where name=? ", Deaths,name ) dbExec( dbConnection, "UPDATE scores SET Kills=? where name=? ", Kills,name ) outputChatBox ( "Saved account " .. name .. " with the Kills " .. Kills .. " with the Deaths" .. Deaths .. " to our database") else dbExec(dbConnection, "INSERT INTO scores VALUES(?, ?, ?)", name, Kills, Deaths) outputChatBox ( "Saved account " .. name .. " with the Kills " .. Kills .. " with the Deaths" .. Deaths .. " to our database") end end addCommandHandler("savestats", saveScore) local function resetScores (element) setScoreData(element, "Kills", 0) setScoreData(element, "Deaths", 0) local status = "" if isPedDead(element) then status = "Dead" end setScoreData(element, "status", status) end local function updateRatio (element) local Deaths = getElementData(element, "Deaths") if Deaths == 0 then setScoreData(element, "ratio", "-") else local kdr = round(getElementData(element, "Kills") / Deaths, KDR_DECIMAL_PLACES) setScoreData(element, "ratio", tostring(kdr)) end end function updateActiveColumns () for i, column in ipairs(scoreColumns) do if get(column) then isColumnActive[column] = true exports.scoreboard:addScoreboardColumn(column) elseif isColumnActive[column] then isColumnActive[column] = false exports.scoreboard:removeScoreboardColumn(column) end end end addEventHandler("onResourceStart", scoresRoot, function () updateActiveColumns() for i, player in ipairs(getElementsByType("player")) do resetScores(player) end end ) addEventHandler("onResourceStop", scoresRoot, function () for i, column in ipairs(scoreColumns) do if isColumnActive[column] then exports.scoreboard:removeScoreboardColumn(column) end end end ) addEventHandler("onPlayerJoin", root, function () resetScores(source) end ) addEventHandler("onPlayerWasted", root, function (ammo, killer, weapon) if killer then if killer ~= source then -- killer killed victim setScoreData(killer, "Kills", getElementData(killer, "Kills") + 1) setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["ratio"] then updateRatio(killer) updateRatio(source) end else -- victim killed himself setScoreData(source, "self", getElementData(source, "self") + 1) end else -- victim died setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["ratio"] then updateRatio(source) end end setScoreData(source, "status", "Dead") end ) addEventHandler("onPlayerSpawn", root, function () setScoreData(source, "status", "") end ) i need that it would save always without typing command like player died save to db
×
×
  • Create New...