Jump to content

spoty

Members
  • Posts

    334
  • Joined

  • Last visited

Everything posted by spoty

  1. hi i wanted to edit this line from my script so it shows a image inplace of text but i dont know how to edit this because this shows a dxDrawText from x1 to x5 but i wanne replace it with images that shows x1 to x5 can someone help me? or explain me how to do it 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)
  2. verry confusing right now i hear from alot of ppl use dbExec and from other dbQuery
  3. The variable check is a boolean value. Using the operator '#' on it is illegal. That operator tries to get the length of strings and tables. #check This won't work - the error tells you that. if ( #check > 0 ) then In conclusion this will not work at all with 'check' as a boolean value. how to make a other working check then? i using it to check if there is a table if not then it creates one and to check if its a valid account
  4. okay i did it right now but its still recounting the points when i rejoin
  5. already readed over 20 times but i still cant get it fixed and i know Returns Returns true unless the connection is incorrect, in which case it returns false. but its all about this line if ( #check > 0 ) then that is giving a boolean value
  6. can you mayby show me how to use it then i am realy confused right now
  7. hey i am verry noobish at SQLite database scripting can someone help me? if i use this code local check = dbExec ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ; -- checking if exist row if ( #check > 0 ) then dbExec ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbExec ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); i get this error ERROR 2: attempt to get lenght of local 'check' (a boolean value) i dont know what i am doing wrong over here... i used this before local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); that was working fine but it dind what it should need to do so i asked help and someone told me to use dbExec --- inplace off dbQuery
  8. spoty

    [TUT] SQLite

    okay thnx for telling me was asking for couple days now i gonna try it out and see if it will work better
  9. i wanne keep the old saved points from when you quit and when you join again it needs to update the old save data with the new one like it updates the points evry time like normal but then also when you start drifting after join the server script dataName = { ["anterior"] = "Last Drift", ["total"] = "Total Drift", ["mejor"] = "Best Drift" } addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite" , "Driftpoint.db" ) if ( connection ) then dbQuery ( connection , "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); this are the score when i quit this are the loaded scores when i join the game and login this are the score when i join and did 1 drift
  10. spoty

    [TUT] SQLite

    hey i have a question can you see whats wrong with this i get this warning and it dont update the points into table after reconnect script dataName = { ["anterior"] = "Last Drift", ["total"] = "Total Drift", ["mejor"] = "Best Drift" } addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite" , "Driftpoint.db" ) if ( connection ) then dbQuery ( connection , "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); this are the score when i quit this are the loaded scores when i join the game and login this are the score when i join and did 1 drift
  11. hey i have a question can you see whats wrong with this i get this warning and it dont update the points into table after reconnect script dataName = { ["anterior"] = "Last Drift", ["total"] = "Total Drift", ["mejor"] = "Best Drift" } addEventHandler ( "onResourceStart", root, function ( ) -- creating connection and if true creates column if not exist connection = dbConnect ( "sqlite" , "Driftpoint.db" ) if ( connection ) then dbQuery ( connection , "CREATE TABLE IF NOT EXISTS `drift` ( `data` TEXT, `account` TEXT )" ); outputDebugString ( "connected" ); else outputDebugString ( "not connected" ); end -- creating connection and if true creates column if not exist end ); function saveDriftPoints ( ) local account = getPlayerAccount ( source ); -- getting account if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local t = { } -- creating table for drift's data for k, v in pairs ( dataName ) do local data = getElementData ( source, v ); if ( data ) then t[v] = data; -- inserting values to table from ElementData end end local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if exist row if ( #check > 0 ) then dbQuery ( connection, "UPDATE `drift` SET `data`=? WHERE `account`=?", toJSON ( t ), accName ); -- if yes updating elseif ( #check == 0 ) then dbQuery ( connection, "INSERT INTO `drift` ( `data`, `account` ) VALUES ( ?, ? )", toJSON ( t ), accName ); -- if not creating end end addEventHandler ( "onPlayerQuit", root, saveDriftPoints ); function loadDriftPoints ( _, account ) if ( isGuestAccount ( account ) ) then -- checking if it is valid account return; end local accName = getAccountName ( account ); -- getting name local check = dbPoll ( dbQuery ( connection, "SELECT `data` FROM `drift` WHERE `account`=?", accName ), -1 ); -- checking if row exist if ( #check > 0 ) then -- if yes local d = check[1]; local t = fromJSON ( d["data"] ); if ( type ( t ) == "table" ) then for k, v in pairs ( t ) do setElementData ( source, k, v ); -- setting ElementData from saved drift's table in table end end end end addEventHandler ( "onPlayerLogin", root, loadDriftPoints ); this are the score when i quit this are the loaded scores when i join the game and login this are the score when i join and did 1 drift
  12. its saving and loading the points but when you quit and later join back you see your last saved points but when you start at 1st drift it recounts all points from last total and best drift scores
  13. now i get a error when i have edited my resource
  14. hey i need some help i have a resource [ drift score resource from 50p ] and i have a database for it to save the total last and best drift scores but it keeps reseting the points when you make the 1st drift after rejoin the database is good but the drift resource make it recount after reconnect or rejoin can someone help me? i already tryed to fix the problem on couply ways here is the drift scripts drft.lua - client local BannedIDs = { 432, 532 } local rootElem = getRootElement() local thisRoot = getResourceRootElement(getThisResource()) local player = getLocalPlayer() local vehicle 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() 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 showText() dxDrawText(string.format("Best Drift: %s - %d",global_nombre,global_mejor),44,screenHeight-43,screenWidth,screenHeight,Yellow,1,"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() 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) 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,155,screenWidth,screenHeight, Yellow, 1.2, "sans","left","top", false,true,false) if velocidad <= 0.3 and mult ~= 1 then dxDrawText("\n\nToo Slow!", 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\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, "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 checkPuntaje() if total > global_mejor then triggerServerEvent("driftNuevoRecord", rootElem, total, getPlayerName(player)) end end addEventHandler("onClientPlayerFinish", rootElem, checkPuntaje) addEventHandler("onClientPlayerOutOfTime", rootElem, checkPuntaje) drft_server.lua - server local root = getRootElement() local thisResourceRoot = getResourceRootElement(getThisResource()) local drift_records = {} 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") executeSQLCreateTable("recordsDrift","pista TEXT, nombre TEXT, score INTEGER") addEvent("driftClienteListo", true) addEventHandler("driftClienteListo", root, function(player) triggerClientEvent(player, "driftActualizarRecord", root, drift_mejor, drift_nombre) if drift_mejor == 0 then outputChatBox("There's no record set on this map", player) else outputChatBox(string.format("The current record is %d points (%s)", drift_mejor, drift_nombre), player) end end) end ) addEventHandler ( "onResourceStop", thisResourceRoot, function() call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Best Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Last Drift") call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "Total Drift") end ) addEventHandler ( "onGamemodeMapStart", root, function(mapResource) local mapname = getResourceInfo(mapResource, "name") or getResourceName(mapResource) local command = string.format("pista='%s'",mapname) local record = executeSQLSelect("recordsDrift","nombre, score",command) if #record == 0 then executeSQLInsert("recordsDrift",string.format("'%s', 'twista', 0",mapname)) drift_mejor = 0 drift_nombre = "N/A" else drift_mejor = record[1]["score"] drift_nombre = record[1]["nombre"] end triggerClientEvent(root, "driftActualizarRecord", root, drift_mejor, drift_nombre) triggerClientEvent(root, "driftResetAllScores", root) if drift_mejor == 0 then outputChatBox("There's no record set on this map") else outputChatBox(string.format("The current record is %d points (%s)", drift_mejor, drift_nombre)) end end) addEventHandler ( "onGamemodeMapStop", root, function(mapResource) local mapname = getResourceInfo(mapResource, "name") or getResourceName(mapResource) if not mapname then return end local command = string.format("pista='%s'",mapname) executeSQLUpdate("recordsDrift",string.format("nombre = '%s', score = %d", drift_nombre, drift_mejor), command) 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("New drift record! (%d points) (%s)",score,name)) drift_mejor = score drift_nombre = name 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 )
  15. hmm ok can you mayby fix it later or explain me how to do
  16. ye i have restarted i have added the resource to admin acl and i dont see any error idk whats wrong
  17. no its still the same this are the score when i quit this are the score when i join and did 1 drift
  18. its working but it still not working fully its saving and loading but when there coming new points its recounting example i quit the game when i have 2564 best drift, 231 last drift, 5684322 total drift and when i join the game and make 1 drift from 6 points then it shows on scoreboard 6 best drift, 6 last drift, 6 total drift
  19. and i have downloaded the script from vps and it also dind putted anything into Drift_DB.db
  20. i ave cleared up the Drift_DB.db and i have changed the drft_db.lua to your code i tryed to let it work in meta as server side but dind work 0 error's and also same for client side and id dind save / load
  21. current it have addEventHandler ("onPlayerLogin",root, function (thePreviousAccount, theCurrentAccount, autoLogin) local anterior = getAccountData (theCurrentAccount,"Last_Drift") local total = getAccountData (theCurrentAccount,"Total_Drift") local mejor = getAccountData (theCurrentAccount,"Best_Drift") setElementData(source, "Last Drift", anterior) setElementData(source, "Total Drift", total) setElementData(source, "Best Drift", mejor) end) addEventHandler ("onPlayerLogout", root, function() if not kickPlayer (source, nil, "Logging out is disallowed.") then -- if the player doesn't get kicked(no admin rights) setElementData(source, "Last Drift", false) setElementData(source, "Total Drift", false) setElementData(source, "Best Drift", false) end end) addEventHandler ("onPlayerQuit", root, function (quitType, reason, responsibleElement) local account = getPlayerAccount (source) if not isGuestAccount (account) then local anterior = getElementData(source, "Last Drift") local total = getElementData(source, "Total Drift") local mejor = getElementData(source, "Best Drift") setAccountData (account,"Last_Drift",anterior) setAccountData (account,"Total_Drift",total) setAccountData (account,"Best_Drift",mejor) end end) but it wont calculate old point to the new points its just recount after rejoin
  22. do i need to ? it have exact same code as .db
×
×
  • Create New...