iron015 Posted June 12, 2014 Share Posted June 12, 2014 Добрый вечер. Скачал дрифт счетчик, но не сохраняются рекорды. В чем проблема? local xmlFile = xmlLoadFile("recordDrift.xml") if xmlFile then local temp = xmlFindChild(xmlFile, "score", 0) if not temp then temp = xmlCreateChild(xmlFile, "score") end xmlNodeSetValue(temp, tostring(drift_mejor)) temp = xmlFindChild(xmlFile, "name", 0) if not temp then temp = xmlCreateChild(xmlFile, "name") end xmlNodeSetValue(temp, drift_nombre) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) end Link to comment
Memory Posted June 12, 2014 Share Posted June 12, 2014 Посмотри debug. И по данному кусочку мы ничем не поможем тебе. Link to comment
iron015 Posted June 12, 2014 Author Share Posted June 12, 2014 в чате написал /debugscript 3, чисто, ошибок нет. local root = getRootElement() local thisResourceRoot = getResourceRootElement(getThisResource()) local drift_mejor = 0 local drift_nombre = "N/A" addEventHandler ( "onResourceStart", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Drift") 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("Дрифт: Рекорд восстановлен. (%d points) (%s)",drift_mejor,drift_nombre)) setTimer(triggerClientEvent, 3000, 1, root, "driftActualizarRecord", root, drift_mejor, drift_nombre) xmlUnloadFile(xmlFile) else outputDebugString("Drift: Не удалось загрузить рекорды.") end end ) addEventHandler ( "onResourceStop", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Total Drift") local xmlFile = xmlLoadFile("recordDrift.xml") if xmlFile then local temp = xmlFindChild(xmlFile, "score", 0) if not temp then temp = xmlCreateChild(xmlFile, "score") end xmlNodeSetValue(temp, tostring(drift_mejor)) local temp2 = xmlFindChild(xmlFile, "name", 0) if not temp2 then temp2 = xmlCreateChild(xmlFile, "name") end xmlNodeSetValue(temp2, drift_nombre) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) outputChatBox ( "Saved and unloaded the XML." ) end 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_mejor then outputChatBox(string.format("Новый рекорд дрифта! (%d очков) (%s)",score,name)) drift_mejor = score drift_nombre = name local xmlFile = xmlLoadFile("recordDrift.xml") if xmlFile then local temp = xmlFindChild(xmlFile, "score", 0) if not temp then temp = xmlCreateChild(xmlFile, "score") end xmlNodeSetValue(temp, tostring(drift_mejor)) local temp2 = xmlFindChild(xmlFile, "name", 0) if not temp2 then temp2 = xmlCreateChild(xmlFile, "name") end xmlNodeSetValue(temp2, drift_nombre) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) outputChatBox ( "Saved and unloaded the XML." ) end triggerClientEvent(root, "driftActualizarRecord", root, drift_mejor, drift_nombre) end end) addEventHandler("onElementDataChange",getRootElement(), function ( ElementData ) if ( ElementData == "Last Drift" ) then givePlayerMoney(source,getElementData(source,ElementData)) end end ) addEvent("driftClienteListo", true) addEventHandler("driftClienteListo", root, function(player) triggerClientEvent(player, "driftActualizarRecord", root, drift_mejor, drift_nombre) outputChatBox(string.format("Текущий рекорд %d очков (%s)", drift_mejor, drift_nombre), player) end) --- FIN Link to comment
Memory Posted June 12, 2014 Share Posted June 12, 2014 Кинь ещё клиентскую часть. На каком месте не срабатывает? Просто тут везде outputChatBox и outputDebugString, так что проследить нетрудно. А вобще, по мне, скрипт кривовато написан. Link to comment
iron015 Posted June 12, 2014 Author Share Posted June 12, 2014 вот ссылка на весь скрипт http://rghost.ru/56343989 --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,232,25) 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.1,screenWidth*0.8,screenHeight*0.8 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(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("Лучший дрифт: %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() 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("Множитель: X%d\n%s",mult,mult~=5 and string.format("Повышение до X%d при %d",mult+1,tablamult[mult]) or "MAX") dxDrawText(temp2, 20,210,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) if velocidad <= 0.3 and mult ~= 1 then dxDrawText("\n\nСлишком медленно!", 20,155,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\nКОРОЛЬ дрифта!" elseif score >= 50000 then temp = "DRIFT\n\nБезумный дрифт!" elseif score >= 20000 then temp = "DRIFT\n\nВозмутительный дрифт!" elseif score >= 15000 then temp = "DRIFT\n\nКолоссальный дрифт!" elseif score >= 7000 then temp = "DRIFT\n\nСупер!" elseif score >= 3000 then temp = "DRIFT\n\nВеликолепный дрифт" elseif score >= 1000 then temp = "DRIFT\n\nХороший дрифт" elseif score < 1000 then temp = "DRIFT\n\nСлабовато" 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, "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
Memory Posted June 13, 2014 Share Posted June 13, 2014 Даже не знаю. У меня всё работает. Вы ничего не изменяли в скрипте? Link to comment
iron015 Posted June 13, 2014 Author Share Posted June 13, 2014 Да, я туда с другого скрипта вставил, чтоб за дрифт деньги давались. Но даже в нетронутом виде не сохранялось. Link to comment
Memory Posted June 13, 2014 Share Posted June 13, 2014 Блин, даже не знаю, чем помочь: ошибок у тебя дебаг никаких не выдаёт, да и у меня работает скрипт, сохраняет нормально. Link to comment
August_Alonso Posted June 27, 2014 Share Posted June 27, 2014 Переходите на MySQL, проще и удобнее. 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