proracer Posted January 21, 2011 Share Posted January 21, 2011 Hello guys it's me again.I have been making some progress with simple stats system (yes it's very hard for me because I'm just learning LUA for 3 weeks). So my problem is script is adding new tables every map and it won't give points and add how much dm you won (race dm). Only part that is working is that it counts how much DM's you played. addEvent("onMapStarting") function createSQLTables() executeSQLCreateTable ("PointsSystem", "accountname TEXT, earnedpoints INT") executeSQLCreateTable ("PointsSystem2", "accountname TEXT, DMWins INT") executeSQLCreateTable ("PointsSystem3", "accountname TEXT, DMAttempted INT") outputChatBox("Points System by Pr0RaC3R, v0.1 started!") end addEventHandler ("onResourceStart", getRootElement(), createSQLTables) function login1(prev, account, autologin) local re = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(account).."'") local re2 = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(account).."'") local re3 = executeSQLSelect("PointsSystem", "DMAttempted", "accountname = '"..getAccountName(account).."'") if re and #re > 0 then setElementData(source, "earnedpoints2", tonumber(re[1]["earnedpoints"]) or 0) setElementData(source, "DMWins2", tonumber(re2[1]["DMWins"]) or 0) setElementData(source, "DMAttempted2", tonumber(re3[1]["DMAttempted"]) or 0) else executeSQLInsert("PointsSystem", "'0', '"..getAccountName(account).."'", "earnedpoints, accountname") executeSQLInsert("PointsSystem2", "'0', '"..getAccountName(account).."'", "DMWins, accountname") executeSQLInsert("PointsSystem3", "'0', '"..getAccountName(account).."'", "DMAttempted, accountname") end end addEventHandler("onPlayerLogin", getRootElement(), login1) function onPlayerQuit() local acc = getPlayerAccount(source) if not isGuestAccount(acc) then executeSQLUpdate("PointsSystem", "earnedpoints = '"..getElementData(source,"earnedpoints2").."'", "accountname = '"..getAccountName(acc).."'") executeSQLUpdate("PointsSystem2", "DMWins = '"..getElementData(source,"DMWins2").."'", "accountname = '"..getAccountName(acc).."'") executeSQLUpdate("PointsSystem3", "DMAttempted = '"..getElementData(source,"DMAttempted2").."'", "accountname = '"..getAccountName(acc).."'") end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) addEventHandler("onPlayerLogout", getRootElement(), onPlayerQuit) -- public stats command function publicstatsinfo( stats ) local askdname = getPlayerName ( source ) local DMWins = getElementData(source,"DMWins2") local DMAttempted = getElementData(source,"DMAttempted2") local points = getElementData(source,"earnedpoints2") local stats_int = tonumber( stats ) outputChatBox( "* ".. askdname .." Stats are:", 255, 12, 15 ) outputChatBox( "* Total Points gained: ".. points .."", 255, 12, 15 ) outputChatBox( "* Total Matches won: ".. DMWins .."", 255, 12, 15 ) outputChatBox( "* Total Matches played: ".. DMAttempted .."", 255, 12, 15 ) end addEvent("stats", true) addEventHandler( "stats",getRootElement(),publicstatsinfo ) function checkCommand ( message, messageType ) if ( messageType == 0 ) then if ( message == "!stats" ) then setTimer( triggerEvent, 100, 1, "stats", source ) end end end addEventHandler ( "onPlayerChat", getRootElement(), checkCommand ) --- function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then local players = getElementsByType("player") for k,v in ipairs(players) do setElementData(v,"DMAttempted2",tonumber(getElementData(v,"DMAttempted2"))+1) end end end function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local Points = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(account).."'") local DeathMatchesWon = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(account).."'") outputChatBox("*Wins: "..playername.." took 10 points for surviving!",getRootElement(),255,255,0) setElementData(thePlayer ,"data.playername",playername,true) setElementData(thePlayer ,"earnedpoints2",tonumber(getElementData(thePlayer,"earnedpoints2"))+10) setElementData(thePlayer ,"DMWins2",tonumber(getElementData(thePlayer,"DMWins2"))+1) end addEventHandler("onMapStarting", getRootElement() , DestructionMoney) NO ERRORS.But the problem is what I defined... it just won't give points and add how dm's you won.So probably there is some error between lines 75-84. Here I will copy a code from counting alive players.It's made by MAR (resource name - race_starter_pack) so thanks to him alot! AlivePlayers = {} function addStartingPlayers(newState,oldState) if newState == "GridCountdown" then if info == "Destruction derby" then cacheStartingPlayers() end end end addEventHandler("onRaceStateChanging",getRootElement(),addStartingPlayers) function cacheStartingPlayers() for k,thePlayer in ipairs(getElementsByType("player")) do if not isPlayerDead(thePlayer) and getPedOccupiedVehicle(thePlayer) then AlivePlayers[k] = thePlayer end end end function onPlayerQuit() if info == "Destruction derby" then for k,thePlayer in ipairs(getElementsByType("player")) do if thePlayer == source then table.remove(AlivePlayers,k) end end end end addEventHandler("onPlayerQuit",getRootElement(),onPlayerQuit) function removeAlivePlayers() if info == "Destruction derby" then for k,thePlayer in ipairs(getElementsByType("player")) do if thePlayer == source then table.remove(AlivePlayers,k) end end if #AlivePlayers == 1 then DestructionMoney2(AlivePlayers[1]) end end end addEventHandler("onPlayerWasted",getRootElement(),removeAlivePlayers) -- Nothing changed in his script. Link to comment
Aibo Posted January 21, 2011 Share Posted January 21, 2011 local Points = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(account).."'") local DeathMatchesWon = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(account).."'") so where's the account? Link to comment
proracer Posted January 21, 2011 Author Share Posted January 21, 2011 I have changed the arg to "thePlayer" but still nothing. Link to comment
Aibo Posted January 21, 2011 Share Posted January 21, 2011 thePlayer is not an account, getAccountName requires an account, not player element. Link to comment
proracer Posted January 22, 2011 Author Share Posted January 22, 2011 Ok I have changed it but still nothing. local Points = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(getPlayerAccount(thePlayer)).."'") local DeathMatchesWon = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(getPlayerAccount(thePlayer)).."'") EDIT: New script: addEvent("onMapStarting") function createSQLTables() executeSQLCreateTable ("PointsSystem", "accountname TEXT, earnedpoints INT") executeSQLCreateTable ("PointsSystem2", "accountname TEXT, DMWins INT") executeSQLCreateTable ("PointsSystem3", "accountname TEXT, DMAttempted INT") outputChatBox("Points System by Pr0RaC3R, Pre-alpha v0.1 started!") outputChatBox("Points System is still in testing stage.Report any bugs on our site.") end addEventHandler ("onResourceStart", getRootElement(), createSQLTables) function login1(prev, account, autologin) local re = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(account).."'") local re2 = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(account).."'") local re3 = executeSQLSelect("PointsSystem", "DMAttempted", "accountname = '"..getAccountName(account).."'") if re and #re > 0 then setElementData(source, "earnedpoints2", tonumber(re[1]["earnedpoints"]) or 0) setElementData(source, "DMWins2", tonumber(re2[1]["DMWins"]) or 0) setElementData(source, "DMAttempted2", tonumber(re3[1]["DMAttempted"]) or 0) else executeSQLInsert("PointsSystem", "'0', '"..getAccountName(account).."'", "earnedpoints, accountname") executeSQLInsert("PointsSystem2", "'0', '"..getAccountName(account).."'", "DMWins, accountname") executeSQLInsert("PointsSystem3", "'0', '"..getAccountName(account).."'", "DMAttempted, accountname") end end addEventHandler("onPlayerLogin", getRootElement(), login1) function onPlayerQuit() local acc = getPlayerAccount(source) if not isGuestAccount(acc) then executeSQLUpdate("PointsSystem", "earnedpoints = '"..getElementData(source,"earnedpoints2").."'", "accountname = '"..getAccountName(acc).."'") executeSQLUpdate("PointsSystem2", "DMWins = '"..getElementData(source,"DMWins2").."'", "accountname = '"..getAccountName(acc).."'") executeSQLUpdate("PointsSystem3", "DMAttempted = '"..getElementData(source,"DMAttempted2").."'", "accountname = '"..getAccountName(acc).."'") end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) addEventHandler("onPlayerLogout", getRootElement(), onPlayerQuit) -- public stats command function publicstatsinfo( stats ) local askdname = getPlayerName ( source ) local DMWins = getElementData(source,"DMWins2") local DMAttempted = getElementData(source,"DMAttempted2") local points = getElementData(source,"earnedpoints2") local stats_int = tonumber( stats ) outputChatBox( "* ".. askdname .." Stats are:", 255, 12, 15 ) outputChatBox( "* Total Points gained: ".. points .."", 255, 12, 15 ) outputChatBox( "* Total Matches won: ".. DMWins .."", 255, 12, 15 ) outputChatBox( "* Total Matches played: ".. DMAttempted .."", 255, 12, 15 ) end addEvent("stats", true) addEventHandler( "stats",getRootElement(),publicstatsinfo ) function checkCommand ( message, messageType ) if ( messageType == 0 ) then if ( message == "!stats" ) then setTimer( triggerEvent, 100, 1, "stats", source ) end end end addEventHandler ( "onPlayerChat", getRootElement(), checkCommand ) --- function DestructionMoney(mapInfo,mapOptions,gameOptions) info = mapInfo.modename if mapInfo.modename == "Destruction derby" then local players = getElementsByType("player") for k,v in ipairs(players) do setElementData(v,"DMAttempted2",tonumber(getElementData(v,"DMAttempted2"))+1) executeSQLUpdate("PointsSystem3", "DMAttempted = '"..getElementData(v,"DMAttempted2").."'","accountname = '" .. getAccountName(getPlayerAccount(v)) .. "'") end end end function DestructionMoney2(thePlayer) local playername = getPlayerName(thePlayer) local Points = executeSQLSelect("PointsSystem", "earnedpoints", "accountname = '"..getAccountName(getPlayerAccount(thePlayer)).."'") local DeathMatchesWon = executeSQLSelect("PointsSystem", "DMWins", "accountname = '"..getAccountName(getPlayerAccount(thePlayer)).."'") outputChatBox("*Wins: "..playername.." took 10 points for surviving!",getRootElement(),255,255,0) setElementData(thePlayer ,"data.playername",playername,true) setElementData(thePlayer ,"earnedpoints2",tonumber(getElementData(thePlayer,"earnedpoints2"))+10) setElementData(thePlayer ,"DMWins2",tonumber(getElementData(thePlayer,"DMWins2"))+1) executeSQLUpdate("PointsSystem", "earnedpoints = '"..getElementData(thePlayer,"earnedpoints2").."'","accountname = '" .. getAccountName(getPlayerAccount(thePlayer)) .. "'") executeSQLUpdate("PointsSystem2", "DMWins = '"..getElementData(thePlayer,"DMWins2").."'","accountname = '" .. getAccountName(getPlayerAccount(thePlayer)) .. "'") end addEventHandler("onMapStarting", getRootElement() , DestructionMoney) Still doesn't add points and when I leave server it says: 'Database query failed: no such column name (accountname,DMWins and DMAttempted) - line 13,14,15,21 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