proracer Posted January 11, 2011 Share Posted January 11, 2011 (edited) Hello, I studied the "race_starter_pack" resource from Mar and it's really complicated (for me).I gave it a try to make own achievements by looking at his functions.But it doesn't work of course.Can you check what's wrong please? Achievements (serverside) function ResourceStart() executeSQLCreateTable("Achievments", "serial STRING,Ach1 INT") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ResourceStart) function ClientReady(g_player) local serial = getPlayerSerial(g_player) local playername = getPlayerName(g_player) CheckPlayer = executeSQLSelect ( "Achievements", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "Achievements", "'"..serial.."','0','0','0','0'" ) end end addEvent("onClientReady",true) addEventHandler("onClientReady",getRootElement(),ClientReady) -- Achievement #1 function Ach1(playeer) local playername = getPlayerName(playeer) local serial = getPlayerSerial(playeer) local Ach1 = executeSQLSelect ( "Achievments", "Ach1","serial = '" .. serial .. "'") Ach1 = tonumber(Ach1[1]["Ach1"]) + 1 if Ach1 == 1 then outputChatBox("**Achievments: "..playername.." unlocked the achievment 'Newb Racer' for winning 1 race! (5B)",getRootElement(),255,100,0) setElementData ( playeer ,"data.Ach1",Ach1,true) executeSQLUpdate ( "Achievments", "Ach1 = '"..Ach1.."'","serial = '" .. serial .. "'") end end function achUnlockedNumber(source) local serial = getPlayerSerial(source) local Ach1 = executeSQLSelect ( "Achievments", "Ach1","serial = '" .. serial .. "'") if tonumber(Ach1[1]["Ach1"]) >= 1 then U1 = 1 else U1 = 0 end function raceWin(rank) if rank ~= 1 then --Check if the player's rank is 1 return end local playername = getPlayerName(source) local serial = getPlayerSerial(source) triggerClientEvent (source,"onPlayerWin", getRootElement()) end setElementData(source,"data.playername",playername,true) if get("Achievments") == 'true' then Ach1(source) end end Achievements (clientside) function clientAchievements() local AchNum = getElementData(getLocalPlayer(),"data.Achnum") end addEvent("clientAchievements",true) addEventHandler("clientAchievements",getRootElement(), clientAchievements) Main Achievements (clientside, show picture with achievement you got) local rootElement = getRootElement() local screenWidth, screenHeight = guiGetScreenSize() GUIEditor_Grid = {} GUIEditor_Image = {} function AchText() dxDrawText( "Achievment Unlocked",528,613,311,23, tocolor ( 192,192,192,255 ), 1.15, "default-bold","left","top", false, false ,true ) end addEvent( "onAchUnlock", true ) function onAchUnlock() addEventHandler("onClientRender",rootElement, AchT) setTimer(function() removeEventHandler("onClientRender",rootElement, AchT) end, 5000,1) addEventHandler("onClientRender",rootElement, AchText) setTimer(function() removeEventHandler("onClientRender",rootElement, AchText) end, 5000,1) GUIEditor_Grid[1] = guiCreateGridList(432,607,424,64,false) GUIEditor_Image[1]= guiCreateStaticImage(1,0,88,64,"images/unlocked.png",false,GUIEditor_Grid[1]) setTimer(function() guiSetVisible(GUIEditor_Grid[1],false) guiSetVisible(GUIEditor_Image[1],false) end, 5000,1) playSound("sounds/achievement.mp3") end addEventHandler( "onAchUnlock", rootElement, onAchUnlock) function AchT() dxDrawText( "5 B - Newb Racer", 528,640,376,34, tocolor ( 192,192,192,255 ), 1.15, "default-bold","left","top", false, false ,true ) end Edited January 12, 2011 by Guest Link to comment
proracer Posted January 12, 2011 Author Share Posted January 12, 2011 I had 2 stupid errors (like forgot to end the function) and I modified it now. (First post) But still when I finish race it outputs no errors but it gives no achievement. Link to comment
proracer Posted January 12, 2011 Author Share Posted January 12, 2011 Please help anyone? (sry for double post) Link to comment
SDK Posted January 12, 2011 Share Posted January 12, 2011 You need to debug (and no, that's not opening /debugscript and looking for errors). https://wiki.multitheftauto.com/wiki/Deb ... s_executed add some custom debugmessages, like outputDebugString("player has finished map") so you can see where your code stops working Link to comment
proracer Posted January 12, 2011 Author Share Posted January 12, 2011 Hmm, I tried debugging "if's".But nothing... so I tried this code.Sorry if I'm mistaken. function raceWin(rank) if rank ~= 1 then --Check if the player's rank is 1 return end local playername = getPlayerName(source) local serial = getPlayerSerial(source) triggerClientEvent (source,"onPlayerWin", getRootElement()) end setElementData(source,"data.playername",playername,true) if get("Achievments") == 'true' then Ach1(source) outputDebugString("justtesting") end end Link to comment
SDK Posted January 13, 2011 Share Posted January 13, 2011 That code has a "end" on line 8 that shouldn't be there, didn't that show up when debugging? Link to comment
proracer Posted January 13, 2011 Author Share Posted January 13, 2011 This is the final code from Achievements (serverside) local rootElement= getRootElement() addEvent("onPlayerFinish") function ResourceStart() executeSQLCreateTable("Achievments", "serial STRING,Ach1 INT") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ResourceStart) function ClientReady(g_player) local serial = getPlayerSerial(g_player) local playername = getPlayerName(g_player) CheckPlayer = executeSQLSelect ( "Achievements", "serial", "serial = '" .. serial .. "'" ) if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then executeSQLInsert ( "Achievements", "'"..serial.."','0','0','0','0'" ) end end addEvent("onClientReady",true) addEventHandler("onClientReady",getRootElement(),ClientReady) -- Achievement #1 function Ach1(playeer) local playername = getPlayerName(playeer) local serial = getPlayerSerial(playeer) local Ach1 = executeSQLSelect ( "Achievments", "Ach1","serial = '" .. serial .. "'") Ach1 = tonumber(Ach1[1]["Ach1"]) + 1 if Ach1 == 1 then outputChatBox("**Achievments: "..playername.." unlocked the achievment 'Newb Racer' for winning 1 race! (5B)",getRootElement(),255,100,0) setElementData ( playeer ,"data.Ach1",Ach1,true) executeSQLUpdate ( "Achievments", "Ach1 = '"..Ach1.."'","serial = '" .. serial .. "'") end end function achUnlockedNumber(source) local serial = getPlayerSerial(source) local Ach1 = executeSQLSelect ( "Achievments", "Ach1","serial = '" .. serial .. "'") if tonumber(Ach1[1]["Ach1"]) >= 1 then U1 = 1 else U1 = 0 end end AchNumb = U1 setElementData(source,"data.Achnum",AchNumb,true) addEvent( "AchCount",true) addEventHandler( "AchCount", root,achUnlockedNumber ) function raceWin(rank) if rank ~= 1 then --Check if the player's rank is 1 return end local playername = getPlayerName(source) local serial = getPlayerSerial(source) triggerClientEvent (source,"onPlayerWin", getRootElement()) end setElementData(source,"data.playername",playername,true) if get("Achievments") == 'true' then Ach1(source) outputDebugString("justtesting") end addEventHandler("onPlayerFinish", rootElement, raceWin ) I was debugging it with ' /debugscript 3 ' and it said these 2 errors: Bad argument @ 'setElementData' (line 43) Bad argument @ 'setElementData' (line 52) Link to comment
proracer Posted January 15, 2011 Author Share Posted January 15, 2011 Sry for opening old thread back alive.Didn't wanted to create new one. So I wanted to ask how can I create achievement that gets example how many times player joined the server, how much time player is in server ... etc? Link to comment
LT Uranus Posted January 16, 2011 Share Posted January 16, 2011 little notice - such thing will make players to recconect often or to stay afk to complete these achievements ( ''cheaters'') exept u will make connect times limit and afk detector 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