Taso Posted March 18, 2014 Share Posted March 18, 2014 Hello all, I have a problem with userpanel on my server. When I buy the map it doesn't put in text. In the log I have this error : ERROR: [gamemodes]\[race]\userpanel\userpanel_server.lua:1536: Bad argument (Could not get Data) ERROR: [gamemodes]\[race]\userpanel\userpanel_server.lua:468: attempt to compare number with nil And when I go on top player i cant see the wins How fix that pls? Thanks, Link to comment
JR10 Posted March 18, 2014 Share Posted March 18, 2014 Post the code if you want anyone to help you. Link to comment
Taso Posted March 18, 2014 Author Share Posted March 18, 2014 userpanel_anim.lua --------------------------------- -- -- Userpanel created by Quitler#! -- --------------------------------- local font1 = dxCreateFont(":race/stf.ttf") sX,sY = guiGetScreenSize() local scale = (sX/1920)*(sY/1200) local animBar = false local bindBlock = true drawComponents = false window = {sX/2-300,sY/2-200} animate = { alpha = 1, barSize = {sX,sY/7}, pos = {0,sX}, title = {"STATS","ACHIEVEMENTS","MAP SHOP","TOP LIST","OPTIONS"}, fontScale = 4*scale, font = "default-bold", anim = false, tick = getTickCount() } local barFix = 0 for i=1,#animate.title do barFix = barFix+dxGetTextWidth(animate.title,animate.fontScale,animate.font) end local barFix = ((sX-barFix)/#animate.title) bar = { buttonSize = { dxGetTextWidth(animate.title[1],animate.fontScale,animate.font)+barFix, dxGetTextWidth(animate.title[2],animate.fontScale,animate.font)+barFix, dxGetTextWidth(animate.title[3],animate.fontScale,animate.font)+barFix, dxGetTextWidth(animate.title[4],animate.fontScale,animate.font)+barFix, dxGetTextWidth(animate.title[5],animate.fontScale,animate.font)+barFix, }, buttonSizeY = sY/13, buttonPos = { 0, dxGetTextWidth(animate.title[1],animate.fontScale,animate.font)+barFix, dxGetTextWidth(animate.title[1],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[2],animate.fontScale,animate.font)+(barFix*2), dxGetTextWidth(animate.title[1],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[2],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[3],animate.fontScale,animate.font)+(barFix*3), dxGetTextWidth(animate.title[1],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[2],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[3],animate.fontScale,animate.font)+dxGetTextWidth(animate.title[4],animate.fontScale,animate.font)+(barFix*4), }, buttonPosY = {animate.pos[2],animate.pos[2],animate.pos[2],animate.pos[2],animate.pos[2]}, lastButton = 0, currentAnimate = 0, hover = 0, currentWindow = 0, } function drawBottomBar() --dxDrawRectangle(animate.pos[1],animate.pos[2],animate.barSize[1],animate.barSize[2],tocolor(30,30,30,150*animate.alpha)) for i=1,#bar.buttonSize do dxDrawRectangle(bar.buttonPos,bar.buttonPosY,bar.buttonSize,animate.barSize[2],tocolor(20,20,20,100)) dxDrawLine(bar.buttonPos,bar.buttonPosY+2,bar.buttonPos+bar.buttonSize,bar.buttonPosY+2,tocolor(100,100,100,200),2) dxDrawLine(bar.buttonPos,bar.buttonPosY,bar.buttonPos,bar.buttonPosY+animate.barSize[2],tocolor(100,100,100,200),2) dxDrawLine(bar.buttonPos+bar.buttonSize-2,bar.buttonPosY,bar.buttonPos+bar.buttonSize-2,bar.buttonPosY+animate.barSize[2],tocolor(100,100,100,200),2) dxDrawText(animate.title,bar.buttonPos+1,bar.buttonPosY+1,bar.buttonPos+bar.buttonSize+1,bar.buttonPosY+bar.buttonSizeY+1,tocolor(0,0,0,255),animate.fontScale,animate.font,"center","center") dxDrawText(animate.title,bar.buttonPos,bar.buttonPosY,bar.buttonPos+bar.buttonSize,bar.buttonPosY+bar.buttonSizeY,tocolor(255, 128, 0,255),animate.fontScale,animate.font,"center","center") end end addEventHandler("onClientRender",getRootElement(),drawBottomBar) function animateBar() if not animBar then if not bindBlock then callServerFunction("unlockAch",getLocalPlayer(),14) showCursor(true) animBar = true animate.tick = getTickCount() addEventHandler("onClientRender",getRootElement(),animateToolbar) else outputChatBox("#ff8000* #ffffffYou need to be looged to open our userpanel!",255,255,255,true) end else animate.anim = false showCursor(false) bar.currentWindow = 0 animate.tick = getTickCount() addEventHandler("onClientRender",getRootElement(),removeAnimation) end end bindKey("U","down",animateBar) function checkHoverTab() if isCursorShowing() and animate.anim then local x,y = getCursorPosition() local x,y = x*sX,y*sY if x>=bar.buttonPos[1] and x<=bar.buttonPos[1]+bar.buttonSize[1] and y>=bar.buttonPosY[1] then animateButton(1) bar.hover = 1 elseif x>=bar.buttonPos[2] and x<=bar.buttonPos[2]+bar.buttonSize[2] and y>=bar.buttonPosY[2] then animateButton(2) bar.hover = 2 elseif x>=bar.buttonPos[3] and x<=bar.buttonPos[3]+bar.buttonSize[3] and y>=bar.buttonPosY[3] then animateButton(3) bar.hover = 3 elseif x>=bar.buttonPos[4] and x<=bar.buttonPos[4]+bar.buttonSize[4] and y>=bar.buttonPosY[4] then animateButton(4) bar.hover = 4 elseif x>=bar.buttonPos[5] and x<=bar.buttonPos[5]+bar.buttonSize[5] and y>=bar.buttonPosY[5] then animateButton(5) bar.hover = 5 else animateButton(0) bar.hover = 0 end end end addEventHandler("onClientRender",getRootElement(),checkHoverTab) function onPlayerButtonClick(button,state) if button == "left" and state == "down" and isCursorShowing() then if bar.hover ~= 0 then toggleWindow(bar.hover) end end end addEventHandler("onClientClick",getRootElement(),onPlayerButtonClick) animateWindow = {} function toggleWindow(id) if bar.currentWindow ~= id then bar.currentWindow = id animateWindow.tick = getTickCount() else bar.currentWindow = 0 end end function drawWindow() if bar.currentWindow ~= 0 then local tick = getTickCount() - animateWindow.tick local progress = tick/1000 if progress >= 1 then progress = 1 drawComponents = true else drawComponents = false end windowX,windowY = interpolateBetween(0,0,0,600,400,0,progress,"OutElastic") dxDrawText("", 0.5, sX - dxGetFontHeight(0.8, 'bankgothic'), false, font1, 0.6, 'left', tocolor (0, 51, 51, 255)) dxDrawRectangle((sX/2)-windowX/2,(sY/2)-windowY/2,windowX,windowY/14,tocolor(0,0,0,150)) dxDrawRectangle((sX/2)-windowX/2,(sY/2)-windowY/2,windowX,windowY,tocolor(0,0,0,200)) end end addEventHandler("onClientRender",getRootElement(),drawWindow) local currentTick = getTickCount() function animateButton(id) if bar.lastButton ~= id then bar.lastButton = id bar.currentAnimate = id currentTick = getTickCount() end if bar.currentAnimate then for i=1,5 do if bar.currentAnimate == i then local tick = getTickCount() local animProgress = tick - currentTick local progress = animProgress/500 bar.buttonPosY = interpolateBetween(bar.buttonPosY,0,0,sY-sY/8,0,0,progress,"Linear") else local tick = getTickCount() local animProgress = tick - currentTick local progress = animProgress/500 bar.buttonPosY = interpolateBetween(bar.buttonPosY,0,0,sY-sY/13,0,0,progress,"Linear") end end end end function allowBind(bOl) bindBlock = not bOl end function animateToolbar() local tick = getTickCount() - animate.tick local progress = tick/400 if progress >= 1 then progress = 1 removeEventHandler("onClientRender",getRootElement(),animateToolbar) animate.anim = true end animate.pos[2] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") bar.buttonPosY[1] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") bar.buttonPosY[2] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") bar.buttonPosY[3] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") bar.buttonPosY[4] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") bar.buttonPosY[5] = interpolateBetween(sY,0,0,sY-sY/13,0,0,progress,"Linear") end function removeAnimation() local tick = getTickCount() - animate.tick local progress = tick/500 if progress >= 1 then progress = 1 removeEventHandler("onClientRender",getRootElement(),removeAnimation) animBar = false end animate.pos[2] = interpolateBetween(sY-sY/13,0,0,sY,0,0,progress,"InBack") for i=1, 5 do bar.buttonPosY = animate.pos[2] end end fileDelete("userpanel_anim.lua") userpanel_client.lua --------------------------------- -- -- Userpanel created by Quitler#! -- --------------------------------- --0fc0fc --15,192,252 gui = { window = {}, stats = {}, shop = {}, options = {} } gui.window[1] = guiCreateWindow(0,0,600,400,"",false) gui.window[2] = guiCreateWindow(0,0,600,400,"",false) gui.window[3] = guiCreateWindow(0,0,600,400,"",false) gui.window[4] = guiCreateWindow(0,0,600,400,"",false) gui.window[5] = guiCreateWindow(0,0,600,400,"",false) for i=1,5 do guiSetPosition(gui.window,window[1],window[2],false) guiWindowSetMovable(gui.window,false) guiWindowSetSizable(gui.window,false) guiSetVisible(gui.window,false) guiSetAlpha(gui.window,0) end gui.stats[1] = guiCreateGridList(25,50,175,325,false,gui.window[1]) guiGridListAddColumn(gui.stats[1],"Player name",0.75) gui.shop[1] = guiCreateEdit(25,50,225,25,"",false,gui.window[3]) gui.shop[2] = guiCreateGridList(25,75,225,275,false,gui.window[3]) guiGridListAddColumn(gui.shop[2],"Map name",2) gui.shop[3] = guiCreateButton(25,350,225,25,"Buy as next map! $5000",false,gui.window[3]) gui.options[1] = guiCreateButton(450,100,100,25,"ENABLE",false,gui.window[5]) gui.options[2] = guiCreateButton(450,210,100,25,"ENABLE",false,gui.window[5]) gui.options[3] = guiCreateButton(450,320,100,25,"ENABLE",false,gui.window[5]) for i=1,#gui.stats do guiSetProperty(gui.stats,"InheritsAlpha","False") end for i=1,#gui.shop do guiSetProperty(gui.shop,"InheritsAlpha","False") end for i=1,#gui.options do guiSetProperty(gui.options,"InheritsAlpha","False") end statsLabel = {"Stats for player: ", "Cash: $", "Points: ", "Maps played: ", "Deaths: ", "Wons: ", "Wins ratio: ", "Achievements: ", "Highest streak: ", "Times joined: ", "Playing time: ", "Toptimes: ", "Hunters: ", "Total spins: "} stats = {getPlayerName(localPlayer),0,0,0,0,0,0,0,0,0,0} achievements = { "Are you new?", "Win master", "Die more", "Nolife", "Favorite server", "Expert", "Millionaire", "Sharing is caring", "First next", "Milestone", "Toptime expert", "Who can stop me?!", "Hunter magnet", "First time", "I like gambling", "Achievement master" } achievement_conditions = { "Login for the first time", -- 1 "Win on 100 maps", -- 2 "Die 1000 times", -- 3 "Play for 50 hours", -- 4 "Join the server 100 times", --5 "Reach 10,000 points", -- 6 "Have $1,000,000 on hand", -- 7 "Send over $1000 to a player", -- 8 "Buy a next map", -- 9 "Play a total of 2000 maps", -- 10 "Get 10 toptimes", -- 11 "Have a winning streak of 3 or more", -- 12 "Get 100 hunters", -- 13 "Open the userpanel", --14 "Spin 100 times", -- 15 "Unlock all achievements" -- 16 } achievement_states = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} achPos = 1 shopLabels = {"N/A","N/A","N/A","N/A","---","---","---","---","---","---"} toplist = { label = {"CASH","POINTS","TOPTIMES","HUNTERS","WINS","STREAK"}, labelWidth = 0, pos = {0,0,0,0,0,0,window[1]+575}, current = 1, hover = false, name = {"N/A","","","","","","","","","",""}, value = {"?","?","?","?","?","?","?","?","?","?","?"} } local label_Width = 0 for i=1,#toplist.label do label_Width = label_Width + dxGetTextWidth(toplist.label,1,"default-bold") end label_Width = label_Width/#toplist.label toplist.labelWidth = label_Width toplist.pos[1] = window[1]+25 for i=2,#toplist.label do toplist.pos = toplist.pos[i-1]+label_Width+dxGetTextWidth(toplist.label,1,"default-bold") end shaders = { title = {"Water shader","Car paint shader","Custom Infernus"}, details = {"This shader makes your water look better.","Shader makes your all cars in game more shiny.","This option change your old infernus skin to new fresh one!"} } function drawWindowComponents() if bar.currentWindow ~= 0 and isCursorShowing() and drawComponents then dxDrawText("",window[1],window[2],window[1]+200,window[2]+400/14,tocolor(255,255,255,255),0.8,"default-bold","center","center",false,false,false,true) if bar.currentWindow == 1 then guiSetVisible(gui.window[bar.currentWindow],true) dxDrawText("STATS",window[1],window[2],window[1]+600,window[2]+400/14,tocolor(255,128,0,255),1.5,"default-bold","center","center") dxDrawText(statsLabel[1]..stats[1],window[1]+200,window[2]+75,window[1]+600,window[2]+100,tocolor(255,255,255,255),2,"default-bold","center","center",false,false,false,true) for i=2,#stats do dxDrawText(statsLabel..stats,window[1]+250,window[2]+100+(25*(i-1)),window[1]+600,window[2]+100+(25*i),tocolor(255,255,255,255),1.2,"default-bold","left","center",false,false,false,true) end else guiSetVisible(gui.window[1],false) end if bar.currentWindow == 2 then dxDrawText("ACHIEVEMENTS",window[1],window[2],window[1]+600,window[2]+400/14,tocolor(255,128,0,255),1.5,"default-bold","center","center") local achC = 0 for i=1,#achievement_states do if achievement_states == 1 then achC = achC + 1 end end dxDrawText("Unlocked achievements: "..achC.."/"..#achievement_states,window[1],window[2]+50,window[1]+600,window[2]+75,tocolor(255,128,0,255),2,"default-bold","center","center") dxDrawRectangle(window[1]+25,window[2]+80,550,300,tocolor(20,20,20,150)) dxDrawRectangle(window[1]+25,window[2]+80,50,300,tocolor(255,128,0,255)) dxDrawText("* Use mouse scroll to scroll achievements",window[1],window[2]+380,window[1]+600,window[2]+400,tocolor(255,255,255,255),0.8,"default-bold","center") for i=1,6 do if i~=6 then dxDrawLine(window[1]+25,window[2]+80+(50*i),window[1]+575,window[2]+80+(50*i),tocolor(100,100,100,255)) end dxDrawText(i+(achPos-1)..".",window[1]+25,window[2]+80+(50*(i-1)),window[1]+75,window[2]+80+(50*i),tocolor(255,255,255,255),2,"default-bold","center","center") if achievement_states[i+(achPos-1)] == 0 then dxDrawText("LOCKED",window[1]+350,window[2]+80+(50*(i-1)),window[1]+550,window[2]+80+(50*i),tocolor(235,11,11,255),2,"default-bold","center","center") else dxDrawText("UNLOCKED",window[1]+350,window[2]+80+(50*(i-1)),window[1]+550,window[2]+80+(50*i),tocolor(11,235,11,255),2,"default-bold","center","center") end dxDrawText(achievements[i+achPos-1],window[1]+100,window[2]+80+(50*(i-1))+5,window[1]+200,window[2]+80+(50*i),tocolor(255,128,0,255),1,"default-bold","left","top") dxDrawText(achievement_conditions[i+achPos-1],window[1]+100,window[2]+80+(50*(i-1))+25,window[1]+200,window[2]+80+(50*i),tocolor(255,255,255,255),1,"default-bold","left","top") end end if bar.currentWindow == 3 then dxDrawText("MAP SHOP",window[1],window[2],window[1]+600,window[2]+400/14,tocolor(255,128,0,255),1.5,"default-bold","center","center") guiSetVisible(gui.window[bar.currentWindow],true) dxDrawText("MAP DEATILS",window[1]+250,window[2]+50,window[1]+600,window[2]+100,tocolor(255,255,255,255),2,"default-bold","center","center") dxDrawText("Map name: "..shopLabels[1],window[1]+275,window[2]+100,window[1]+600,window[2]+120,tocolor(255,255,255,255),1,"default-bold","left","center") dxDrawText("Author: "..shopLabels[2],window[1]+275,window[2]+120,window[1]+600,window[2]+140,tocolor(255,255,255,255),1,"default-bold","left","center") dxDrawText("Times Played: "..shopLabels[3],window[1]+275,window[2]+140,window[1]+600,window[2]+160,tocolor(255,255,255,255),1,"default-bold","left","center") dxDrawText("Last time played: "..shopLabels[4],window[1]+275,window[2]+160,window[1]+600,window[2]+180,tocolor(255,255,255,255),1,"default-bold","left","center") dxDrawText("TOPTIMES AT MAP",window[1]+250,window[2]+200,window[1]+600,window[2]+250,tocolor(255,255,255,255),2,"default-bold","center","center") dxDrawText("1. "..shopLabels[5],window[1]+275,window[2]+260,window[1]+600,window[2]+320,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) dxDrawText("2. "..shopLabels[6],window[1]+275,window[2]+280,window[1]+600,window[2]+340,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) dxDrawText("3. "..shopLabels[7],window[1]+275,window[2]+300,window[1]+600,window[2]+360,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) dxDrawText(shopLabels[8],window[1]+400,window[2]+260,window[1]+600,window[2]+320,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) dxDrawText(shopLabels[9],window[1]+400,window[2]+280,window[1]+600,window[2]+340,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) dxDrawText(shopLabels[10],window[1]+400,window[2]+300,window[1]+600,window[2]+360,tocolor(255,255,255,255),1,"default-bold","left","center",false,false,false,true) else guiSetVisible(gui.window[3],false) end if bar.currentWindow == 4 then local x,y = getCursorPosition() local x,y = x*sX,y*sY dxDrawText("TOP LIST",window[1],window[2],window[1]+600,window[2]+400/14,tocolor(255,128,0,255),1.5,"default-bold","center","center") dxDrawRectangle(window[1]+25,window[2]+50,550,330,tocolor(50,50,50,50)) for i=1,#toplist.name do dxDrawText(i..". "..toplist.name,window[1]+50,window[2]+50+(30*(i-1)),window[1]+50,window[2]+50+(30*i),tocolor(255,255,255,255),1.2,"default-bold","left","center",false,false,false,true) dxDrawText(toplist.value,window[1]+550,window[2]+50+(30*(i-1)),window[1]+550,window[2]+50+(30*i),tocolor(255,255,255,255),1.2,"default-bold","right","center",false,false,false,true) end for i=1,#toplist.label do if x>=toplist.pos[1] and x<=toplist.pos[6+1] and y>=window[2]+350 and y<=window[2]+380 then if x>=toplist.pos and x<=toplist.pos[i+1] and y>=window[2]+350 and y<=window[2]+380 then toplist.hover = i if toplist.current ~= i then dxDrawRectangle(toplist.pos,window[2]+350,toplist.pos[i+1]-toplist.pos,30,tocolor(255,128,0,255)) dxDrawText(toplist.label,toplist.pos,window[2]+350,toplist.pos[i+1],window[2]+380,tocolor(0,0,0,255),1,"default-bold","center","center") else dxDrawRectangle(toplist.pos,window[2]+350,toplist.pos[i+1]-toplist.pos,30,tocolor(255,128,0,255)) dxDrawText(toplist.label,toplist.pos,window[2]+350,toplist.pos[i+1],window[2]+380,tocolor(255,255,255,255),1,"default-bold","center","center") end else dxDrawRectangle(toplist.pos,window[2]+350,toplist.pos[i+1]-toplist.pos,30,tocolor(0,0,0,255)) dxDrawText(toplist.label,toplist.pos,window[2]+350,toplist.pos[i+1],window[2]+380,tocolor(255,255,255,255),1,"default-bold","center","center") end else toplist.hover = false if toplist.current ~= i then dxDrawRectangle(toplist.pos,window[2]+350,toplist.pos[i+1]-toplist.pos,30,tocolor(0,0,0,255)) dxDrawText(toplist.label,toplist.pos,window[2]+350,toplist.pos[i+1],window[2]+380,tocolor(255,255,255,255),1,"default-bold","center","center") else dxDrawRectangle(toplist.pos,window[2]+350,toplist.pos[i+1]-toplist.pos,30,tocolor(255,128,0,255)) dxDrawText(toplist.label,toplist.pos,window[2]+350,toplist.pos[i+1],window[2]+380,tocolor(0,0,0,255),1,"default-bold","center","center") end end end end if bar.currentWindow == 5 then guiSetVisible(gui.window[5],true) dxDrawText("OPTIONS",window[1],window[2],window[1]+600,window[2]+400/14,tocolor(255,128,0,255),1.5,"default-bold","center","center") for i=1,#shaders.title do dxDrawText(shaders.title,window[1]+25,window[2]+80+(100*(i-1)),window[1]+25,window[2],tocolor(255,128,0,255),2,"default-bold","left","top") dxDrawText(shaders.details,window[1]+25,window[2]+120+(100*(i-1)),window[1]+410,window[2],tocolor(255,255,255,255),1.5,"default-bold","left","top",false,true) end else guiSetVisible(gui.window[5],false) end else for i=1,5 do guiSetVisible(gui.window,false) end end end addEventHandler("onClientRender",getRootElement(),drawWindowComponents) function onPlayerButtonClick(button,state) if button == "left" and state == "down" and isCursorShowing() then if toplist.hover then toplist.current = toplist.hover getToplist(toplist.current) end end end addEventHandler("onClientClick",getRootElement(),onPlayerButtonClick) function scrollDown() if achPos <= #achievement_states-6 then achPos = achPos+1 end end bindKey("mouse_wheel_down","down",scrollDown) function scrollUP() if achPos > 1 then achPos = achPos-1 end end bindKey("mouse_wheel_up","down",scrollUP) -- Get all maps on server function getMaps() setTimer(callServerFunction,500,1,"getServerMaps",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getMaps) function loadMaps(gamemodeMapTable, gamemode, map) guiGridListClear(gui.shop[2]) if gamemodeMapTable then aGamemodeMapTable = gamemodeMapTable for id,gamemode in pairs (gamemodeMapTable) do if (gamemode.name == "Race") then for id,map in ipairs (gamemode.maps) do local row = guiGridListAddRow ( gui.shop[2] ) guiGridListSetItemText ( gui.shop[2], row, 1, map.name, false, false ) guiGridListSetItemData ( gui.shop[2], row, 1, map.resname) end end end end end function refreshConnectedPlayers(loggedPlayers) guiGridListClear(gui.stats[1]) if loggedPlayers then for i,player in ipairs(loggedPlayers) do local row = guiGridListAddRow (gui.stats[1]) guiGridListSetItemText(gui.stats[1],row,1,string.gsub(loggedPlayers,"#%x%x%x%x%x%x", ""),false,false) end end end function getPlayerServerStats() local row,column = guiGridListGetSelectedItem(gui.stats[1]) local playerName = guiGridListGetItemText(gui.stats[1],row,1) callServerFunction("getPlayerStats",getLocalPlayer(),findPlayerByName(playerName)) end addEventHandler ( "onClientGUIDoubleClick",gui.stats[1],getPlayerServerStats,false) function displayPersonalStats(thePlayer,playerStatsTable) stats[1] = getPlayerName(thePlayer) for i=2,#stats do stats = playerStatsTable[i-1] end end -- Map search function mapSearch() guiGridListClear(gui.shop[2]) local searchString = string.lower(guiGetText(gui.shop[1])) if ( searchString == "" ) then for id,gamemode in pairs (aGamemodeMapTable) do if (gamemode.name == "Race") then for id,map in ipairs (gamemode.maps) do local row = guiGridListAddRow ( gui.shop[2] ) guiGridListSetItemText ( gui.shop[2], row, 1, map.name, false, false ) guiGridListSetItemData ( gui.shop[2], row, 1, map.resname) end end end else local noMapsFound = true for id,gamemode in pairs (aGamemodeMapTable) do if (gamemode.name == "Race") then for id,map in ipairs (gamemode.maps) do if string.find(string.lower(map.name.." "..map.resname), searchString, 1, true) then local row = guiGridListAddRow ( gui.shop[2] ) guiGridListSetItemText ( gui.shop[2], row, 1, map.name, false, false ) guiGridListSetItemData ( gui.shop[2], row, 1, map.resname) noMapsFound = false end end end end if noMapsFound == true then local row = guiGridListAddRow(gui.shop[2]) guiGridListSetItemText (gui.shop[2], row, 1, "No maps matching your search query!", false, false) guiGridListSetItemColor (gui.shop[2], row, 1, 255,50,50) end end end addEventHandler ( "onClientGUIChanged", gui.shop[1], mapSearch, false ) function updateMapLabels() local row,column = guiGridListGetSelectedItem(gui.shop[2]) local mapName = guiGridListGetItemText(gui.shop[2],row,1) if mapName ~= "" then shopLabels[1] = mapName callServerFunction("sendMapInfoToPanel",getLocalPlayer(),mapName) else shopLabels[1] = "N/A" shopLabels[2] = "N/A" shopLabels[3] = "N/A" shopLabels[4] = "N/A" end end addEventHandler ( "onClientGUIClick", gui.shop[2], updateMapLabels, false ) function setMapInfoData(mapInfoData,toptimes) if mapInfoData then if mapInfoData.infoName ~= nil then if mapInfoData.author then shopLabels[2] = mapInfoData.author else shopLabels[2] = "N/A" end shopLabels[3] = mapInfoData.playedCount shopLabels[4] = mapInfoData.lastTimePlayed else shopLabels[2] = "N/A" shopLabels[3] = "N/A" shopLabels[4] = "N/A" end shopLabels[5] = "Empty" shopLabels[6] = "Empty" shopLabels[7] = "Empty" shopLabels[8] = "" shopLabels[9] = "" shopLabels[10] = "" if toptimes then for i,k in pairs (toptimes) do for index,data in pairs(k) do if i == 1 and index == 'playerName' then shopLabels[5] = data end if i == 1 and index == 'timeText' then shopLabels[8] = data end if i == 2 and index == 'playerName' then shopLabels[6] = data end if i == 2 and index == 'timeText' then shopLabels[9] = data end if i == 3 and index == 'playerName' then shopLabels[7] = data end if i == 3 and index == 'timeText' then shopLabels[10] = data end end end end end end function buyNextMap() local row,column = guiGridListGetSelectedItem(gui.shop[2]) local mapName = guiGridListGetItemText(gui.shop[2],row,1) callServerFunction("buyMap",getLocalPlayer(),mapName) end addEventHandler ( "onClientGUIClick", gui.shop[3], buyNextMap, false ) topServerValue = { "cash", "points", "totalToptimes", "totalHunters", "mapsWon", "highestWinstreak", } function getToplist(number) local datatype = nil datatype = topServerValue[number] if not datatype then return end callServerFunction("getTopList",getLocalPlayer(),false,datatype) end function updateTopList(ranking,TopType) if ranking then for i=1,10 do if ranking then if toplist.current == 1 then toplist.value = "$"..ranking.data toplist.name = ranking.name else toplist.value = ranking.data toplist.name = ranking.name end else toplist.name = "N/A" toplist.value = "???" end end end end function checkAchievements(ach) if ach then achievement_states = ach end end -- Fancy achievement FX local sx,sy = guiGetScreenSize() local gMe = getLocalPlayer() local achievement = {} addEventHandler("onClientResourceStart",resourceRoot,function() achievement.width = 400 achievement.queue = {} achievement.left = "left.png" achievement.left_image = "left_1.png" achievement.left_fade = 255 achievement.right = "right.png" achievement.background = "background.png" end) function showAchievement(locked,text,worth) achievementActive = 1 achievement.text = text achievement.worth = tostring(worth) achievement.background = "background.png" achievement.locked = locked achievement.active = true achievement.width = dxGetTextWidth((achievement.locked == true and "Achievement Locked" or "Achievement Unlocked"),2,"default-bold") achievement.fade = 0 achievement.step = 10 achievement.left_fade = 0 achievement.left_step = 10 if dxGetTextWidth(tostring(worth) .. "X - " .. achievement.text,2,"default-bold") > achievement.width then -- Check for width with the 'X' points, even though they're disabled (might add them later) if dxGetTextWidth(tostring(worth) .. "X - " .. achievement.text,2,"default-bold") <= 500 then achievement.width = dxGetTextWidth(tostring(worth) .. "X - " .. achievement.text,2,"default-bold") else achievement.width = 500 end end playSound("sounds/achievement.mp3",false) achievement.width = achievement.width + 10 addEventHandler("onClientRender",root,drawAchievement) achievement.swap = setTimer(function() achievement.left_step = achievement.left_step > 0 and -40 or 40 end,2000,0) achievement.timer = setTimer(function() achievement.step = -10 achievement.left_step = -10 achievement.left_fade = achievement.fade end,7000,1) end addEvent("showClientAchievement",true) addEventHandler("showClientAchievement",root,showAchievement) function drawAchievement() local alpha = fadeA(achievement.fade,achievement.step) if alpha == 0 and achievement.fade > alpha then removeAchievement() end achievement.fade = alpha if achievement.fade == 255 then dxDrawImage((sx/2)-(achievement.width/2)-63,sy-200,64,64,"img/"..achievement.left,0,0,0,tocolor(255,255,255,achievement.fade)) end dxDrawImage((sx/2)+(achievement.width/2)-1,sy-200,64,64,"img/"..achievement.right,0,0,0,tocolor(255,255,255,achievement.fade)) alpha = fadeA(achievement.left_fade,achievement.left_step) if alpha == 0 and achievement.left_fade > alpha then achievement.left_image = achievement.left_image == "left_1.png" and "left_2.png" or "left_1.png" achievement.left_step = 40 end achievement.left_fade = alpha dxDrawImage((sx/2)-(achievement.width/2)-63,sy-200,64,64,"img/"..achievement.left_image,0,0,0,tocolor(255,255,255,achievement.left_fade)) dxDrawImage((sx/2)-(achievement.width/2),sy-200,achievement.width,64,"img/"..achievement.background,0,0,0,tocolor(255,255,255,achievement.fade)) dxDrawText((achievement.locked == true and "Achievement Locked" or "Achievement Unlocked") .. "\n"--[[ .. achievement.worth .. "X - " -]].. achievement.text, (sx/2)-(achievement.width/2), sy-200, (sx/2)+(achievement.width/2), sy-136, tocolor(255,255,255,achievement.fade), 2, "default-bold", "center", "top", true, true) end function fadeA(value,step) if step > 0 then if value < 255 then value = value + step if value > 255 then value = 255 end end else if value > 0 then value = value + step if value <= 0 then value = 0 end end end return value end function removeAchievement() if achievement.swap and isTimer(achievement.swap) then killTimer(achievement.swap) end if achievement.timer and isTimer(achievement.timer) then killTimer(achievement.timer) end removeEventHandler("onClientRender",root,drawAchievement) achievement.active = false if achievement.queue then if achievement.queue[1] then showAchievement(achievement.queue[1][1],achievement.queue[1][2],achievement.queue[1][3]) table.remove(achievement.queue,1) end end achievementActive = 0 end local achievementTime -- Main function for unlocking achievements function unlockAchievement(achievementNumber) local achievementNumber = tonumber(achievementNumber) if achievementActive ~= 1 then local achievementName = achievements[achievementNumber] showAchievement(false,achievementName,1) callServerFunction("displayFancyUnlockText",getLocalPlayer(),achievements[achievementNumber]) outputDebugString("Unlocking achievement number: "..achievementNumber) callServerFunction("unlockAch",getLocalPlayer(),16) else achievementTimer(achievementNumber) end end function achievementTimer(achievementNumber) setTimer(unlockAchievement,2000,1,achievementNumber) end ---------------------- -- Find player by name ---------------------- function findPlayerByName (name) local player = getPlayerFromName(name) if player then return player end for i, player in ipairs(getElementsByType("player")) do if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then return player end end return false end -------------------------------- -- Custom hunter model & texture -------------------------------- function infernusModel(state) if state == true then infernusTexture = engineLoadTXD ( "model/infernus.txd" ) engineImportTXD ( infernusTexture, 411 ) infernusTexture = engineLoadDFF ( "model/infernus.dff", 411 ) engineReplaceModel ( infernusTexture, 411 ) else engineRestoreModel(411) end end function saveOption(item,value) local xmlFile = xmlLoadFile("settings.xml") if not xmlFile then xmlFile = xmlCreateFile("settings.xml","settings") xmlNodeSetAttribute(xmlFile,"car","false") xmlNodeSetAttribute(xmlFile,"water","true") xmlNodeSetAttribute(xmlFile,"infernus","false") xmlSaveFile(xmlFile) end xmlNodeSetAttribute(xmlFile,item,value) xmlSaveFile(xmlFile) xmlUnloadFile(xmlFile) end -- Loading options function loadOptions() local xmlFile = xmlLoadFile("settings.xml") if not xmlFile then xmlFile = xmlCreateFile("settings.xml.xml","settings") xmlNodeSetAttribute(xmlFile,"car","false") xmlNodeSetAttribute(xmlFile,"water","true") xmlNodeSetAttribute(xmlFile,"infernus","false") xmlSaveFile(xmlFile) end if xmlNodeGetAttribute(xmlFile,"car") == "true" then guiSetText(gui.options[2],"DISABLE") toggleCarpainShader(true) else guiSetText(gui.options[2],"ENABLE") toggleCarpainShader(false) end if xmlNodeGetAttribute(xmlFile,"water") == "true" then guiSetText(gui.options[1],"DISABLE") toggleWaterShaderByManager(true) else guiSetText(gui.options[1],"ENABLE") toggleWaterShaderByManager(false) end if xmlNodeGetAttribute(xmlFile,"infernus") == "true" then guiSetText(gui.options[3],"DISABLE") infernusModel(true) else guiSetText(gui.options[3],"ENABLE") infernusModel(false) end xmlUnloadFile(xmlFile) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loadOptions) function onOptionChanged(button,state) local buttonState = guiGetText(source) if source == gui.options[2] then if buttonState == "ENABLE" then guiSetText(gui.options[2],"DISABLE") toggleCarpainShader(true) saveOption("car","true") else guiSetText(gui.options[2],"ENABLE") toggleCarpainShader(false) saveOption("car","false") end elseif source == gui.options[1] then if buttonState == "ENABLE" then guiSetText(gui.options[1],"DISABLE") toggleWaterShaderByManager(true) saveOption("water","true") else guiSetText(gui.options[1],"ENABLE") toggleWaterShaderByManager(false) saveOption("water","false") end elseif source == gui.options[3] then if buttonState == "ENABLE" then guiSetText(gui.options[3],"DISABLE") infernusModel(true) saveOption("infernus","true") else guiSetText(gui.options[3],"ENABLE") infernusModel(false) saveOption("infernus","false") end end end addEventHandler ( "onClientGUIClick", gui.options[1], onOptionChanged, false ) addEventHandler ( "onClientGUIClick", gui.options[2], onOptionChanged, false ) addEventHandler ( "onClientGUIClick", gui.options[3], onOptionChanged, false ) function checkForOpenConsole(message,type) local isOpen = isConsoleActive() callServerFunction("checkReactionTest",getLocalPlayer(),message,type,isOpen) end function playingTimeTimer() addTime = setTimer(playingTimeTimerTrigger,60000,0) end function playingTimeTimerTrigger() callServerFunction("playingTimeAdd",getLocalPlayer()) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),playingTimeTimer) function playingTimeTimerStop() killTimer(addTime) end addEventHandler("onClientResourceStop",getResourceRootElement(getThisResource()),playingTimeTimerStop) ------------------------------------------ -- Calling function from the client's side ------------------------------------------ function callClientFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onServerCallsClientFunction", true) addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) ----------------------- -- Call server function ----------------------- function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end triggerServerEvent("onClientCallsServerFunction", resourceRoot , funcname, unpack(arg)) end fileDelete("userpanel_client.lua") userpanel_server.lua ------------------------------------------------------------------------------------------------------------- -- Original file by NeXTreme. Thanks for you'r awesome resource. -- -- -- -- This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.-- -- http://creativecommons.org/licenses/by-nc-nd/3.0/ -- -- -- -- Edited by Quitler#. All right reserved. Copyright 2013. -- ------------------------------------------------------------------------------------------------------------- -- String.random characters chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"} local dataTable = { "cash", "points", "firstTimeJoin", "totalTimesJoined", "unlockedAchievements", "mapsWon", "totalToptimes", "totalHunters", "mapsPlayed", "totalDeaths", "totalPlayingTimeMinutes", "totalPlayingTimeHours", "highestWinstreak", "totalSpins", "buyedMaps", "ach1", "ach2", "ach3", "ach4", "ach5", "ach6", "ach7", "ach8", "ach9", "ach10", "ach11", "ach12", "ach13", "ach14", "ach15", "ach16", } textDataTable = {"nick"} playerTableStats = {} ----------------------------------- --- Protect Userpanel ----------------------------------- function protectUserpanel() onResourceStart() end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),protectUserpanel) ----------- -- Settings ----------- mapCost = 5000 -- The price for setting maps. vehicleColor = 15000 headlightColor = 10000 moneyEarnPart = 30 -- The amount of money to calculate with to get the final money to give to the player. reactionMin = 900 -- Minimum money for the reaction test reactionMax = 2100 -- Maximum money for the reaction test reactionDuration = 20 -- Duration of the reaction test in seconds reactionMinRedo = 300 -- Minimum amount of time to pass before a new reaction test is started in seconds reactionMaxRedo = 400 -- Maximum amount of time to pass before a new reaction test is started in seconds reactionLength = 12 -- Number of characters to use in the reaction test function onResourceStart() mapIsAlreadySet = false reactionString = "" reactionMoney = 0 mapType = "" mapName = "" mapBlock = "" messegeSent = false messegeSentR = false setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1) outputDebugString("Resource is restarting, please stand by...") setTimer(outputDebugString,700,1,"Resource sucessfully started: FFP Userpanel by Xiti. ") end function clientMsgLoad() local toptimesMsg = get( "msgToptime" ) enableTopMsg = false if toptimesMsg then if(toptimesMsg == "true") then enableTopMsg = true else enableTopMsg = false end end end addEvent("onClientLoaded", true) addEventHandler( "onClientLoaded", getRootElement(), clientMsgLoad) -- Prices for each horn hornPrice={2000,4000,6000,8000,10000,15000,20000} -- Disable voting function disableVote() cancelEvent() end addCommandHandler("voteredo",disableVote) addCommandHandler("new",disableVote) ----------------------------------------------------------------------------------- -----------------------------------| USERPANEL |----------------------------------- ----------------------------------------------------------------------------------- ---------------------------- -- Refresh Players ---------------------------- function triggerRebuildPlayerGridlist(thePlayer) local loggedPlayers = {} for i,player in ipairs(getElementsByType("player")) do if not (isGuestAccount(getPlayerAccount(player))) then table.insert(loggedPlayers, tostring(getPlayerName(player))) end setTimer(callClientFunction,1000,1,getRootElement(),"refreshConnectedPlayers",loggedPlayers) end end addEventHandler("onPlayerChangeNick",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerLogin",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerJoin",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerLogout",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerQuit",getRootElement(),triggerRebuildPlayerGridlist) ---------------------------------- -- Tables System based on Accounts ---------------------------------- function createNewTables() local account = getPlayerAccount(source) if not (isGuestAccount(account)) then for i, data in ipairs(dataTable) do if not (getAccountData(account, data)) then setAccountData(account, data, "0") outputDebugString("Setting data: "..tostring(data).." for player: "..tostring(getPlayerName(source)).." to 0") end end end if not (isGuestAccount(account)) then for i, data in pairs(textDataTable) do if not (getAccountData(account, data)) then setAccountData(account, data, getPlayerName(source)) end end end end addEventHandler("onPlayerLogin", getRootElement(), createNewTables) addCommandHandler("resetStats", function (player, cmd, arg1) if (arg1) then local account = getPlayerAccount(player) if (isObjectInACLGroup("user." ..getAccountName(account), aclGetGroup("Admin"))) then local target = getPlayerWildcard(arg1) if (target) then local account = getPlayerAccount(target) if not (isGuestAccount(account)) then for i, data in ipairs(dataTable) do setAccountData(account, data, "0") outputDebugString("Setting data: "..tostring(data).." for player: "..tostring(getPlayerName(target)).." to 0") end end if not (isGuestAccount(account)) then for i, data in pairs(textDataTable) do end end end end end end) ------------------------------------------- -- Userpanel - handle requests from clients ------------------------------------------- function timesJoin() setElementData(source,"join","joined") scoreboardRefresh(source) end addEventHandler("onPlayerJoin",getRootElement(),timesJoin) -- Stats view function getPlayerStats(triggeringPlayer,thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then playerTableStats[1] = tonumber(getAccountData(account,"cash")) playerTableStats[2] = tonumber(getAccountData(account,"points")) playerTableStats[3] = tonumber(getAccountData(account,"mapsPlayed")) playerTableStats[4] = tonumber(getAccountData(account,"totalDeaths")) playerTableStats[5] = tonumber(getAccountData(account,"mapsWon")) playerTableStats[6] = 0 -- Win ratio if playerTableStats[3] == 0 and playerTableStats[5] == 0 then playerTableStats[6] = "0%" elseif playerTableStats[3] ~= 0 and playerTableStats[5] == 0 then playerTableStats[6] = "0%" elseif playerTableStats[3] ~= 0 and playerTableStats[5] ~= 0 then playerTableStats[6] = math.floor(math.round(((100/playerTableStats[3])*playerTableStats[5]),2)).."%" elseif playerTableStats[5] > playerTableStats[3] then playerTableStats[6] = "0%" end playerTableStats[7] = tonumber(getAccountData(account,"unlockedAchievements")).."/16" playerTableStats[8] = tonumber(getAccountData(account,"highestWinstreak")) playerTableStats[9] = tonumber(getAccountData(account,"totalTimesJoined")) playerTableStats[10] = "00:00" minutes = tonumber(getAccountData(account,"totalPlayingTimeMinutes")) hours = tonumber(getAccountData(account,"totalPlayingTimeHours")) if hours < 10 then hours = "0"..hours end if minutes < 10 then minutes = "0"..minutes end playerTableStats[10] = ""..hours..":"..minutes.."" -- Total Playing Time playerTableStats[11] = tonumber(getAccountData(account,"totalHunters")) playerTableStats[12] = tonumber(getAccountData(account,"totalToptimes")) playerTableStats[13] = tonumber(getAccountData(account,"totalSpins")) callClientFunction(triggeringPlayer,"displayPersonalStats",thePlayer,playerTableStats) end end -- Maps function getServerMaps (loadList) local tableOut if loadList then tableOut = {} -- local deletedMaps = {} local gamemodes = {} gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes") for id,gamemode in ipairs (gamemodes) do tableOut[id] = {} tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode) tableOut[id].resname = getResourceName(gamemode) tableOut[id].maps = {} local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode) for _,map in ipairs (maps) do table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) end table.sort(tableOut[id]["maps"], sortCompareFunction) end table.sort((tableOut), sortCompareFunction) table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}}) local countGmodes = #tableOut local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode") for id,map in ipairs (maps) do -- if fileOpen(":"..getResourceName(map).."/deleted") then -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) -- else table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) -- end end -- table.sort(deletedMaps, sortCompareFunction) table.sort(tableOut[countGmodes]["maps"], sortCompareFunction) -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}}) -- local countGmodes = countGmodes + 1 -- tableOut[countGmodes]["maps"] = deletedMaps end local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap") local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode") gamemode = gamemode and getResourceName(gamemode) or "N/A" map = map and getResourceName(map) or "N/A" callClientFunction(loadList,"loadMaps", tableOut, gamemode, map) end function sortCompareFunction(s1, s2) if type(s1) == "table" and type(s2) == "table" then s1, s2 = s1.name, s2.name end s1, s2 = s1:lower(), s2:lower() if s1 == s2 then return false end local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1)) if not byte1 then return true elseif not byte2 then return false elseif byte1 < byte2 then return true elseif byte1 == byte2 then return sortCompareFunction(s1:sub(2), s2:sub(2)) else return false end end function callGetMaps() for i,player in ipairs(getElementsByType("player")) do callClientFunction(player,"getMaps") end end addCommandHandler("rebuildMaps",callGetMaps) mapTimer = {} -- Buy a next map function buyMap(thePlayer,mapName,command) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then local playerCash = tonumber(getAccountData(account,"cash")) if mapIsAlreadySet == false then if not (mapName == "") then if playerCash >= mapCost then if command then mapName = getMapName(mapName) else mapName = tostring(mapName) end if not mapTimer[mapName] then executeCommandHandler("comprarmap", thePlayer, mapName) outputChatBox("#FFFFFFNextmap: "..getPlayerName(thePlayer).."#FFFFFF has bought a next map!",getRootElement(),255,255,255,true) outputChatBox("#FFFFFFNextmap: #ff8000"..tostring(mapName),getRootElement(),255,255,255,true) mapIsAlreadySet = true mapBlock = tostring(mapName) unlockAch(thePlayer,9) setAccountData(account,"cash",playerCash - mapCost) scoreboardRefresh(thePlayer) mapTimer[mapName] = true setTimer(resetMapTimer,900000,1,mapName) else outputChatBox("#ff8000* #FFFFFFYou can't set this map now, wait some time to set!",thePlayer,255,255,255,true) end else outputChatBox("#ff8000* #FFFFFFYou don't have enough money to set a map!",thePlayer,255,255,255,true) end else outputChatBox("#ff8000* #FFFFFFPlease select a map from the list first!",thePlayer,255,255,255,true) end else outputChatBox("#ff8000* #FFFFFFA map is already set at the moment! Please try again later.",thePlayer,255,255,255,true) end end end function resetMapSetStatus(g_MapInfo) if mapIsAlreadySet then if mapBlock == g_MapInfo.name then mapIsAlreadySet = false mapName = "" mapBlock = "" end end messegeSent = false messegeSentR = false earnFix = {} hunterFix = {} end addEvent("onMapStarting") addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus) hunterFix = {} function resetMapTimer(mapName) if mapTimer[mapName] then mapTimer[mapName] = nil outputChatBox( "#ff8000* #ff8000"..mapName.." #ffffffcan be bought again!", getRootElement(), 255,255,255,true) end end function buyMapCommand(player,command,mapString) local map, errormsg = findMap( mapString ) if not map then outputChatBox( "#ff8000* #ffffff"..errormsg, player, 255,255,255,true) return end buyMap(player,map,true) end addCommandHandler("bm",buyMapCommand) --- TEST function newReactionTest() reactionString = string.random(reactionLength) reactionMoney = math.random(reactionMin,reactionMax) outputChatBox("#ff8000[TEST] #FFFFFFSay #ff8000"..reactionString.."#FFFFFF to win #ff8000$"..reactionMoney.."#FFFFFF!",getRootElement(),255,255,255,true) addEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole) reactionTimer = setTimer( function() removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole) end,reactionDuration*1000,1) if isTimer(newReactionTimer) then killTimer(newReactionTimer) end newReactionTimer = setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1) end addCommandHandler("viptestr",newReactionTest) newReactionTimer = setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1) function checkForOpenConsole(message,type) callClientFunction(source,"checkForOpenConsole",message,type) end function checkReactionTest(thePlayer,message,type,isOpen) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if (isOpen == true) then outputChatBox("#ff8000[TEST] #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF attempted to cheat at the reaction test!",getRootElement(),255,255,255,true) outputChatBox("#ff8000[TEST] #FFFFFFMoney decreased by #ff8000$1,000#FFFFFF! Do not cheat!",getRootElement(),255,255,255,true) local playerCash = getAccountData(account,"cash") setAccountData(account,"cash",playerCash-1000) scoreboardRefresh(thePlayer) return end message = tostring(message) if message == "..." then return end if (message == reactionString) then local timeLeft,leftExec,totalExec = getTimerDetails(reactionTimer) killTimer(reactionTimer) removeEventHandler("onPlayerChat",getRootElement(),checkForOpenConsole) setTimer(outputChatBox,200,1,"#ff8000[TEST] #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas won the reaction test in #ff8000"..math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) .." #FFFFFFseconds and wins #ABCDEF$"..reactionMoney,getRootElement(),255,255,255,true) local playerCash = getAccountData(account,"cash") local totalReactionTests = tonumber(getAccountData(account,"totalReactionTests")) local bestReactionTime = tonumber(getAccountData(account,"bestReactionTime")) setAccountData(account,"cash",playerCash+reactionMoney) addStat(account,"totalReactionTests",1) if (math.round((reactionDuration*1000 - timeLeft)/1000)) < bestReactionTime or (bestReactionTime == 0) then addStat(account,"bestReactionTime",math.round((reactionDuration*1000 - timeLeft)/1000,2,floor)) end scoreboardRefresh(thePlayer) -- Check for achievement here if math.round((reactionDuration*1000 - timeLeft)/1000,2,floor) <= 5 then end reactionString = "" reactionMoney = 0 end end end function string.random(len) local str = "" for i=1,len do local getChar = math.random(1,35) if getChar <= 25 then local caps = math.random(1,2) if caps == 1 then str = str..string.upper(chars[getChar]) else str = str..string.lower(chars[getChar]) end else str = str..chars[getChar] end end return str end -- Playing time function playingTimeAdd(thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then local totalPlayingTimeMinutes = tonumber(getAccountData(account,"totalPlayingTimeMinutes")) local totalPlayingTimeHours = tonumber(getAccountData(account,"totalPlayingTimeHours")) if totalPlayingTimeMinutes == 59 then setAccountData(account,"totalPlayingTimeMinutes",0) addStat(account,"totalPlayingTimeHours",1) unlockAch(thePlayer,4) else addStat(account,"totalPlayingTimeMinutes",1) end end end -- Times joined the server function loginHandler() local account = getPlayerAccount(source) if not (isGuestAccount(account)) then local totalTimesJoined = tonumber(getAccountData(account,"totalTimesJoined")) local joined = getElementData(source,"join") local firstTime = tonumber(getAccountData(account,"firstTimeJoin")) callClientFunction(source,"allowBind",true) if firstTime == 0 then setAccountData(account,"nick",getPlayerName(source)) setAccountData(account,"firstTimeJoin",1) unlockAch(source,1) end if joined == "joined" then local nick = getAccountData(account,"nick") if nick == getPlayerName(source) then -- nothink else setAccountData(account,"nick",getPlayerName(source)) end addStat(account,"totalTimesJoined",1) destroyElement(source) unlockAch(source,5) outputChatBox("#ff8000* #FFFFFFWelcome to our DM server, "..getPlayerName(source).."#FFFFFF! Press '#ff8000U#ffffff' to open our userpanel.",source,255,255,255,true) end end end addEventHandler("onPlayerLogin",getRootElement(), loginHandler) function logoutHandler() callClientFunction(source,"allowBind",false) end addEventHandler("onPlayerLogout",getRootElement(),logoutHandler) function onPlayerChangeNick(oldNick,newNick) if getElementData ( source, "isNickMuted" ) then cancelEvent() outputChatBox ( "Please wait some time to change your nick again.", source, 255, 0, 0 ) return end if not (isGuestAccount(getPlayerAccount(source))) then setAccountData(getPlayerAccount(source),"nick",newNick) end end addEventHandler ( "onPlayerChangeNick", getRootElement(), onPlayerChangeNick ) -- Total maps played function totalMapsPlayedAdd() local account = getPlayerAccount(source) if not (isGuestAccount(account)) then local mapsPlayed = tonumber(getAccountData(account,"mapsPlayed")) addStat(account,"mapsPlayed",1) local mapsPlayed = getAccountData(account,"mapsPlayed") if mapsPlayed >= 2000 then unlockAch(source,10) end end end addEvent("onNotifyPlayerReady",true) addEventHandler("onNotifyPlayerReady",getRootElement(),totalMapsPlayedAdd) -- Unlocked Achievements function unlockedAchievementsAdd(thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then local unlockedAchievements = tonumber(getAccountData(account,"unlockedAchievements")) addStat(account,"unlockedAchievements", 1) end end --------------------------- -- Userpanel - Achievements --------------------------- function checkAchievements(thePlayer) local account = getPlayerAccount(thePlayer) ach = {} if not (isGuestAccount(account)) then for i=1,16 do ach = tonumber(getAccountData(account,"ach"..i)) end callClientFunction(thePlayer,"checkAchievements",ach) end end addEventHandler("onPlayerLogin", getRootElement(), function() local thePlayer = source checkAchievements(thePlayer) scoreboardRefresh(thePlayer) playingTimeAdd(thePlayer) end) function unlockAch(thePlayer,number) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if number == 1 then local firstTimeJoin = tonumber(getAccountData(account,"firstTimeJoin")) local ach1 = tonumber(getAccountData(account,"ach1")) if firstTimeJoin == 1 and ach1 == 0 then setAccountData(account,"ach1",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 2 then local mapsWin = tonumber(getAccountData(account,"mapsWon")) local ach2 = tonumber(getAccountData(account,"ach2")) if mapsWin >= 100 and ach2 == 0 then setAccountData(account,"ach2",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 3 then local dies = tonumber(getAccountData(account,"totalDeaths")) local ach3 = tonumber(getAccountData(account,"ach3")) if dies >= 100 and ach3 == 0 then setAccountData(account,"ach3",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 4 then local hours = tonumber(getAccountData(account,"totalPlayingTimeHours")) local ach4 = tonumber(getAccountData(account,"ach4")) if hours >= 50 and ach14 == 0 then setAccountData(account,"ach4",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 5 then local timesJoin = tonumber(getAccountData(account,"totalTimesJoined")) local ach5 = tonumber(getAccountData(account,"ach5")) if timesJoin >= 100 and ach5 == 0 then setAccountData(account,"ach5",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 6 then local points = tonumber(getAccountData(account,"points")) local ach6 = tonumber(getAccountData(account,"ach6")) if points >= 10000 and ach6 == 0 then setAccountData(account,"ach6",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 7 then local cash = tonumber(getAccountData(account,"cash")) local ach7 = tonumber(getAccountData(account,"ach7")) if cash >= 1000000 and ach7 == 0 then setAccountData(account,"ach7",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 8 then local ach8 = tonumber(getAccountData(account,"ach8")) if ach8 == 0 then setAccountData(account,"ach8",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 9 then local ach9 = tonumber(getAccountData(account,"ach9")) if ach9 == 0 then setAccountData(account,"ach9",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 10 then local maps = tonumber(getAccountData(account,"mapsPlayed")) local ach10 = tonumber(getAccountData(account,"ach10")) if maps >= 2000 and ach10 == 0 then setAccountData(account,"ach10",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 11 then local toptimes = tonumber(getAccountData(account,"totalToptimes")) local ach11 = tonumber(getAccountData(account,"ach11")) if toptimes >= 10 and ach11 == 0 then setAccountData(account,"ach11",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 12 then local winS = tonumber(getAccountData(account,"highestWinstreak")) local ach12 = tonumber(getAccountData(account,"ach12")) if winS >= 3 and ach12 == 0 then setAccountData(account,"ach12",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 13 then local hunters = tonumber(getAccountData(account,"totalHunters")) local ach13 = tonumber(getAccountData(account,"ach13")) if hunters >= 100 and ach13 == 0 then setAccountData(account,"ach13",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 14 then local ach14 = tonumber(getAccountData(account,"ach14")) if ach14 == 0 then setAccountData(account,"ach14",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 15 then local spins = tonumber(getAccountData(account,"totalSpins")) local ach15 = tonumber(getAccountData(account,"ach15")) if spins >= 100 and ach15 == 0 then setAccountData(account,"ach15",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end elseif number == 16 then local accCount = 0 for i=1,15 do local acc = tonumber(getAccountData(account,"ach"..i)) if acc == 1 then accCount = accCount + 1 end end local ach16 = tonumber(getAccountData(account,"ach40")) if accCount == 15 and ach16 == 0 then setAccountData(account,"ach16",1) callClientFunction(thePlayer,"unlockAchievement",number) checkAchievements(thePlayer) unlockedAchievementsAdd(thePlayer) end end end end function displayFancyUnlockText(thePlayer,achievementName) outputChatBox("#ff8000* #FFFFFF"..getPlayerName(thePlayer).."#FFFFFF has unlocked the achievement: #ff8000"..achievementName,getRootElement(),255,255,255,true) end ---------------------------------------- -- Toplist ---------------------------------------- local amountOfTopsToDisplay = 10 function getTopList( player, command, value ) if ( value == "cash" or value == "points" or "mapsPlayed" or "mapsWon" or "totalToptimes" or "totalHunters" or "totalDeaths" or "highestWinstreak" or "playingTime" or "unlockedAchievements" or "DMwins" or "DDwins" or "buyedMaps" ) then local tableOrder = {} if value ~= "playingTime" then for i, v in ipairs (getAccounts()) do table.insert (tableOrder, { name = getAccountData ( v, "nick" ) or getAccountName ( v ), data = getAccountData ( v, value ) or 0 } ) end elseif value == "playingTime" then for i, v in ipairs (getAccounts()) do local dataH = getAccountData ( v, "totalPlayingTimeHours" ) or 0 local dataM = getAccountData ( v, "totalPlayingTimeMinutes" ) or 0 local dataHms = dataH * 3600000 local dataMms = dataM * 60000 local time = dataHms+dataMms table.insert (tableOrder, { name = getAccountData ( v, "nick" ) or getAccountName ( v ), data = time } ) end end table.sort (tableOrder, function (a,b) return (tonumber(a.data) or 0) > (tonumber(b.data) or 0) end) callClientFunction(player,"updateTopList",tableOrder) else outputDebugString("ERROR! [getTopList] Bad value ("..value..")!",1,255,0,0) end end -------------------------------------------- -- Get alive and dead players by their STATE -------------------------------------------- function getAliveRacePlayers() local alivePlayers = 0 for index,player in ipairs(getElementsByType("player")) do if getElementData(player,"state") == "alive" then alivePlayers = alivePlayers + 1 end end return alivePlayers end function getDeadRacePlayers() local deadPlayers = 0 for index,player in ipairs(getElementsByType("player")) do if getElementData(player,"state") == "dead" then deadPlayers = deadPlayers + 1 end end return deadPlayers end -------------- -- Race winner -------------- LastWinners={} earnFix = {} function setWinnersStats(winner) local account = getPlayerAccount(winner) if not (isGuestAccount(account)) then if getPlayerCount() >= 3 then if not earnFix[winner] then earnFix[winner] = true local WinStreak = 0 local thePlayer = winner LastWinners[20] = LastWinners[19] LastWinners[19] = LastWinners[18] LastWinners[18] = LastWinners[17] LastWinners[17] = LastWinners[16] LastWinners[16] = LastWinners[15] LastWinners[15] = LastWinners[14] LastWinners[14] = LastWinners[13] LastWinners[13] = LastWinners[12] LastWinners[12] = LastWinners[11] LastWinners[11] = LastWinners[10] LastWinners[10] = LastWinners[9] LastWinners[9] = LastWinners[8] LastWinners[8] = LastWinners[7] LastWinners[7] = LastWinners[6] LastWinners[6] = LastWinners[5] LastWinners[5] = LastWinners[4] LastWinners[4] = LastWinners[3] LastWinners[3] = LastWinners[2] LastWinners[2] = LastWinners[1] LastWinners[1] = thePlayer if LastWinners[1] == thePlayer then WinStreak = 1 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer then WinStreak = 2 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer then WinStreak = 3 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer then WinStreak = 4 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer then WinStreak = 5 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer then WinStreak = 6 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer then WinStreak = 7 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer then WinStreak = 8 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer then WinStreak = 9 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer then WinStreak = 10 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer then WinStreak = 11 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer then WinStreak = 12 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer then WinStreak = 13 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer then WinStreak = 14 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer then WinStreak = 15 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer then WinStreak = 16 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer then WinStreak = 17 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer then WinStreak = 18 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer and LastWinners[19] == thePlayer then WinStreak = 19 if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer and LastWinners[19] == thePlayer and LastWinners[20] == thePlayer then WinStreak = 20 end end end end end end end end end end end end end end end end end end end end local pAlive = getAliveRacePlayers() local pDead = getDeadRacePlayers() local WinS = tonumber(getAccountData(account,"highestWinstreak")) if WinS < WinStreak then setAccountData(account,"highestWinstreak",WinStreak) end if WinStreak >= 2 then local WinStreakToExport = WinStreak call(getResourceFromName("race"), "setWinStreakOnMessege", WinStreakToExport) end if WinStreak >= 3 then unlockAch(winner,12) end local cashToWin = tonumber((moneyEarnPart*getPlayerCount())*WinStreak) local playerCash = getAccountData(account,"cash") if playerCash >= 1000000 then unlockAch(winner,7) end if not (cashToWin < 0) then setAccountData(account,"cash",playerCash+cashToWin) end local points = math.floor(((pAlive + pDead)*pDead)*WinStreak) if not (points < 0) then local playerPoints = tonumber(getAccountData(account,"points")) if playerPoints >= 10000 then unlockAch(winner,6) end setAccountData(account,"points",playerPoints+points) end addStat(account,"mapsWon",1) unlockAch(winner,2) outputChatBox ("#ff8000* #FFFFFF" .. getPlayerName(winner) .." #FFFFFFhas won! He/She gets $#ff8000" .. tostring(cashToWin) .." #ffffffand #ff8000"..points.."#ffffff points || x"..WinStreak.."#0fc0fc!",getRootElement(),255,255,255,true) scoreboardRefresh(winner) end else outputChatBox("#ff8000* #FFFFFFNot enough players to earn money - #ff80003 #FFFFFFrequired.",winner,255,255,255,true) end local thePlayer = winner scoreboardRefresh(thePlayer) end end addEvent("onPlayerDestructionDerbyWin",true) addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),setWinnersStats) ------------------- -- Other race ranks ------------------- function earnMoney() local thePlayer = source local position = (getAliveRacePlayers() + 1) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if getPlayerCount() >= 1 then if not earnFix[thePlayer] then if position ~= 1 then earnFix[thePlayer] = true local pAlive = getAliveRacePlayers() local pDead = getDeadRacePlayers() local finalCash = 250 if pAlive == 1 then pAlive = 2 end local finalCash = math.floor(((pDead+pAlive/position)*pDead)*5) -- Calculate the final money value. local points = math.floor(((pAlive + pDead)*pDead)/pAlive) local playerCash = getAccountData(account,"cash") local playerPoints = getAccountData(account,"points") setAccountData(account,"points",playerPoints+points) setAccountData(account,"cash",playerCash+finalCash) local playerCash = getAccountData(account,"cash") local playerPoints = getAccountData(account,"points") addStat(account,"totalDeaths",1) if playerPoints >= 10000 then unlockAch(thePlayer,6) end if playerCash >= 1000000 then unlockAch(thePlayer,7) end unlockAch(thePlayer,3) unlockAch(thePlayer,6) outputChatBox("#ff8000* #FFFFFFYou have recieved $#ff8000" .. finalCash .. " #ffffff and #ff8000"..points.."#ffffff points for#ff8000 "..position.." #ffffffplace!",thePlayer,255,255,255,true) end end else outputChatBox("#ff8000* #FFFFFFNot enough players to earn money - #ff80003 #FFFFFFrequired.",thePlayer,255,255,255,true) return end scoreboardRefresh(thePlayer) end end addEventHandler("onPlayerWasted",getRootElement(),earnMoney) ----------------- -- Hunter handler ----------------- function hunterBonus(thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if not hunterFix[thePlayer] then hunterFix[thePlayer] = true local cashToWin = 3000 local points = 100 outputChatBox("#ff8000* #FFFFFFYou recieved #ff8000"..cashToWin.." #FFFFFFand #ff8000"..points.." #FFFFFFpoints for getting hunter! ",thePlayer,255,255,255,true) local playerCash = getAccountData(account,"cash") local playerPoints = getAccountData(account,"points") setAccountData(account,"cash",playerCash+cashToWin) setAccountData(account,"points",playerPoints+points) scoreboardRefresh(thePlayer) addStat(account,"totalHunters",1) local playerCash = getAccountData(account,"cash") local playerPoints = getAccountData(account,"points") if playerPoints >= 10000 then unlockAch(thePlayer,6) end if playerCash >= 1000000 then unlockAch(thePlayer,7) end unlockAch(thePlayer,13) end end end function checkForHunter(number,sort,model) if sort == "vehiclechange" then if model == 425 then setTimer(hunterBonus,200,1,source) end end end addEvent('onPlayerPickUpRacePickup') addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkForHunter) function toptimeadd(player,newPos,newTime) local account = getPlayerAccount(player) if not (isGuestAccount(account)) then local cashToWin = math.floor(500/newPos) local points = math.floor(10/newPos) if newPos <= 10 then local playerCash = getAccountData(account,"cash") setAccountData(account,"cash",playerCash+cashToWin) addStat(account, "points",points) local thePlayer = player outputChatBox("#ff8000* #FFFFFFYou recieved $#ff8000"..cashToWin.."#ffffff and #ff8000"..points.."#ffffff points for set a toptime.",thePlayer,255,255,255,true) addStat(account,"totalToptimes",1) scoreboardRefresh(thePlayer) local playerCash = tonumber(getAccountData(account,"cash")) local playerPoints = tonumber(getAccountData(account,"points")) if playerPoints >= 10000 then unlockAch(thePlayer,6) end if playerCash >= 1000000 then unlockAch(thePlayer,7) end unlockAch(thePlayer,11) end end end addEvent("onPlayerToptimeImprovement",true) addEventHandler("onPlayerToptimeImprovement",getRootElement(),toptimeadd) -------------------- -- Spin command -------------------- spins = {} function spin(thePlayer,commandName,value) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if value then local value = tonumber(value) if (value >= 1) and (value<5001) then local playerCash = tonumber(getAccountData(account,"cash")) if playerCash > value then if spins[thePlayer] then outputChatBox("#ff8000* #ffffffYou have to wait 30 seconds.",thePlayer,255,255,255,true) else spins[thePlayer] = true setTimer(resetSpin,30000,1,thePlayer) local luck = math.random(1,2) addStat(account,"totalSpins",1) unlockAch(thePlayer,15) if luck == 1 then setAccountData(account,"cash",playerCash+value) outputChatBox("#ff8000* #ffffff"..getPlayerName(thePlayer).." #ffffffspin a coin and won $#ff8000"..value.."#ffffff!",getRootElement(),255,255,255,true) local playerCash = tonumber(getAccountData(account,"cash")) if playerCash >= 1000000 then unlockAch(thePlayer,7) end scoreboardRefresh(thePlayer) else setAccountData(account,"cash",playerCash-value) outputChatBox("#ff8000* #ffffff"..getPlayerName(thePlayer).." #ffffffspin a coin and lost $#ff0000"..value.."#ffffff!",getRootElement(),255,255,255,true) end end else outputChatBox("#ff8000* #ffffffYou dont have cash to spin a coin.",thePlayer,255,255,255,true) end else outputChatBox("#ff8000* #ffffffSet correct value. Maximal value of spin is $5000 and minimal 1$.",thePlayer,255,255,255,true) end else outputChatBox("#ff8000* #ffffffYou need to set value (For example /spin 1000).",thePlayer,255,255,255,true) end end end addCommandHandler("spin",spin) function resetSpin(thePlayer) spins[thePlayer] = nil end ------------- -- Give money ------------- function giveMoney(thePlayer,command,targetPlayer,amount) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then if not (targetPlayer == "") then if tonumber(amount) then local playerCash = tonumber(getAccountData(account,"cash")) if tonumber(amount) > 0 then if tonumber(amount) <= playerCash then if (findPlayerByName(targetPlayer)) then local target = findPlayerByName(targetPlayer) local targeta = getPlayerAccount(target) if target ~= thePlayer then local amount = math.ceil(amount) local playerCash = getAccountData(account,"cash") local targetCash = getAccountData(targeta,"cash") setAccountData(account,"cash",playerCash-tonumber(amount)) setAccountData(targeta,"cash",targetCash+tonumber(amount)) local playerCash = getAccountData(account,"cash") local targetCash = getAccountData(targeta,"cash") scoreboardRefresh(thePlayer) scoreboardRefresh(target) if amount >= 1000 then unlockAch(thePlayer, end if playerCash >= 1000000 then unlockAch(thePlayer,7) end if targetCash >= 1000000 then unlockAch(target,7) end outputChatBox("#ff8000* #FFFFFFYou have sent #ff8000$"..amount.."#FFFFFF to "..getPlayerName(target).."#FFFFFF!",thePlayer,255,255,255,true) outputChatBox("#ff8000* #FFFFFF"..getPlayerName(thePlayer).." #FFFFFFhas sent you #ff8000$"..amount.."#FFFFFF!",target,255,255,255,true) else outputChatBox("#ff8000* #FFFFFFERROR! You cannot send money to yourself!",thePlayer,255,255,255,true) return false end else outputChatBox("#ff8000* #FFFFFFERROR! The player you specified does not exist! (#FFFF00"..targetPlayer.."#FFFFFF)",thePlayer,255,255,255,true) return false end else outputChatBox("#ff8000* #FFFFFFERROR! You don't have enough money!",thePlayer,255,255,255,true) return false end else outputChatBox("#ff8000* #FFFFFFERROR! Invalid amount! [#ff8000"..amount.."#FFFFFF]",thePlayer,255,255,255,true) return false end else outputChatBox("#ff8000* #FFFFFFERROR! Please specify the amount to send!",thePlayer,255,255,255,true) return false end else outputChatBox("#ff8000* #FFFFFFERROR! Please select a player!",thePlayer,255,255,255,true) return false end end end addCommandHandler("give",giveMoney) ------------- -- PM system ------------- function privateMessage(player, command, toplayername, ...) local words = { ... } local message = table.concat(words," ") if toplayername then if (findPlayerByName (toplayername)) then toplayer = (findPlayerByName (toplayername)) if not (toplayer == player) then if message then outputChatBox("#ff8000[PM]#ff8000 Message to #FFFFFF" .. getPlayerName(toplayer) .. "#FFFFFF: " .. message, player, 255, 255, 255, true) outputChatBox("#ff8000[PM]#ff8000 Message from #FFFFFF" .. getPlayerName(player) .. "#FFFFFF: " .. message, toplayer, 255, 255, 255, true) else outputChatBox("#FFFF00[PM]#ff8000 Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) return false end else outputChatBox("#FFFF00[PM]#ff8000 You cannot PM yourself#FFFFFF!", player, 255, 255, 255, true) return false end else outputChatBox("#FFFF00[PM]#ff8000 Player not found! #FFFFFF("..toplayername..").", player, 255, 255, 255, true) return false end else outputChatBox("#FFFF00[PM]#ff8000 Invalid syntax! Usage:#FFFFFF /pm [partical player name] [message]", player, 255, 255, 255, true) return false end end addCommandHandler("pm", privateMessage) -------------------------------------- -- Find player by a part of their name -------------------------------------- function findPlayerByName (name) local player = getPlayerFromName(name) if player then return player end for i, player in ipairs(getElementsByType("player")) do if string.find(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", ""), name:lower(), 1, true) then return player end end return false end ---------------------- -- Automated Ghostmode ---------------------- addEventHandler("onMapStarting", getRootElement(), function(mapInfo, mapOptions, gameOptions) if (ismapDM(mapInfo.name) == 1) then outputChatBox("#ff8000P#FFFFFFlaying a #ff8000[DM]#FFFFFF map, #ff8000G#ffffffhostmode #ff8000ENABLED",getRootElement(),255,255,255,true) for theKey,thePlayer in ipairs(getElementsByType("player")) do setElementData( thePlayer, "overrideCollide.uniqueblah", 0, false ) end elseif (ismapDM(mapInfo.name) == 2) then outputChatBox("#ff8000P#FFFFFFlaying a #ff8000[DD]#FFFFFF map, #ff8000G#ffffffhostmode #ff8000DISABLED",getRootElement(),255,255,255,true) for theKey,thePlayer in ipairs(getElementsByType("player")) do setElementData(thePlayer, "overrideCollide.uniqueblah", nil, false ) end elseif (ismapDM(mapInfo.name) == 3) then outputChatBox("#ff8000P#FFFFFFlaying a #ff8000[FUN]#FFFFFF map, #ff8000G#ffffffhostmode #ff8000DISABLED",getRootElement(),255,255,255,true) for theKey,thePlayer in ipairs(getElementsByType("player")) do setElementData(thePlayer, "overrideCollide.uniqueblah", nil, false ) end mapType = "FUN" elseif (ismapDM(mapInfo.name)) == 4 then mapType = "?" end end) function ismapDM(isim) if string.find(isim, "[DM]", 1, true) then return 1 elseif string.find(isim, "[DD]", 1,true) then return 2 elseif string.find(isim, "[FUN]", 1,true) then return 3 else return 4 end end -- Get player's element data (testing) function getElementDataOnCommand(player,command,data) outputChatBox(tostring(getAccountData(getPlayerAccount(player),tostring(data)))) end addCommandHandler("get",getElementDataOnCommand) ----------------- -- Get dead count ----------------- function getDeadCount () deadAmount = 0 for i,v in ipairs (getDeadPlayers()) do deadAmount = deadAmount +1 end return deadAmount end ------------------ -- Get alive count ------------------ function getAliveCount () aliveAmount = 0 for i,v in ipairs (getAlivePlayers()) do aliveAmount = aliveAmount +1 end return aliveAmount end ------------------------------------------- -- Calling functions from the client's side ------------------------------------------- function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) ----------------------- -- Call client function ----------------------- function callClientFunction(client, funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) end ---------------------- -- Math.round function ---------------------- 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 ----------------------------------------------- SCOREBOARD ----------------------------------------------------- addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() exports.scoreboard:addScoreboardColumn("Rank",getRootElement(),6,30) exports.scoreboard:addScoreboardColumn("Money",getRootElement(),5) exports.scoreboard:addScoreboardColumn("Points",getRootElement(),5) exports.scoreboard:addScoreboardColumn("Hunters",getRootElement(),5) exports.scoreboard:removeScoreboardColumn("race rank") exports.scoreboard:removeScoreboardColumn("checkpoint") end) function scoreboardRefresh(thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then local playerCash = tonumber(getAccountData(account,"cash")) local playerPoints = tonumber(getAccountData(account,"points")) local playerHunt = tonumber(getAccountData(account,"totalHunters")) setElementData(thePlayer,"Money","$"..playerCash) setElementData(thePlayer,"Points",playerPoints) setElementData(thePlayer,"Hunters",playerHunt) else setElementData(thePlayer,"Money","Guest") setElementData(thePlayer,"Points","Guest") setElementData(thePlayer,"Rank","?") setElementData(thePlayer,"Hunters","?") end end function scoreboardRefreshTrigger() local thePlayer = source scoreboardRefresh(thePlayer) end addEventHandler("onPlayerLogout",getRootElement(),scoreboardRefreshTrigger) addEventHandler("onPlayerLogin",getRootElement(),scoreboardRefreshTrigger) addEventHandler("onPlayerWasted",getRootElement(),scoreboardRefreshTrigger) function scoreboardRefreshTriggerRank() getRankSB(source) end addEventHandler("onPlayerLogin",getRootElement(),scoreboardRefreshTriggerRank) function getAllRankSB() local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ) or getAccountName ( v ), data = getAccountData ( v, "points" ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) for i,player in pairs(getElementsByType("player")) do if not (isGuestAccount(getPlayerAccount(player))) then for i=1,#tableOrder do if tableOrder.name == getPlayerName(player) then setElementData(player,"Rank",i) end end end end outputDebugString("Updating rank for all player") end setTimer(function() getAllRankSB() end,300000,0) function getRankSB(player,command) local tableOrder = { } for i, v in ipairs ( getAccounts ( ) ) do table.insert ( tableOrder, { name = getAccountData ( v, "nick" ), data = getAccountData ( v, "points" ) } ) end table.sort ( tableOrder, function ( a, b ) return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) end ) for i=1,#tableOrder do if tableOrder.name == getPlayerName(player) then outputDebugString("Updating rank for: "..tostring(string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", ""))) setElementData(player,"Rank",i) break end end end -------------------------------------- -- Very importatnt account functions -------------------------------------- function addStat(account, data, val) if (tostring(data)) and (tonumber(val)) then local theData = getAccountData(account, data) if (theData) then setAccountData(account, data, tonumber(theData) + tonumber(val)) else outputDebugString("Bad argument (Could not get Data)", 1, 255, 0, 0) end else outputDebugString("Bad argument", 1, 255, 0, 0) end end local scriptcol = {{255,178,0,true},{255,0,0,true},{0,255,0,true}} addCommandHandler("setAccountData", function (player, command, target, data, value) local account = getPlayerAccount(player) if (isObjectInACLGroup("user." ..getAccountName(account), aclGetGroup("Admin"))) then if (target) and (data) and (value) then local targetPlayer = getPlayerWildcard(target) if (targetPlayer) then if not (isGuestAccount(getPlayerAccount(targetPlayer))) then for i, v in ipairs(dataTable) do if (v == data) then setAccountData(getPlayerAccount(targetPlayer), data, value) scoreboardRefresh(targetPlayer) outputChatBox("* Successfully set account data for : #FFFFFF"..getPlayerName(targetPlayer).." #ff8000[datatype: '"..tostring(data).."' , value: '"..tostring(value).."' ]",player,unpack(scriptcol[1])) outputChatBox("* #FFFFFF"..getPlayerName(player).."#ff8000 set new data for your account! [datatype: '"..tostring(data).."' , value: '"..tostring(value).."' ]",targetPlayer,unpack(scriptcol[3])) return end end else outputChatBox("* Error: Target not logged in!",player,unpack(scriptcol[2])) end else outputChatBox("* Error: Could not find player!",player,unpack(scriptcol[2])) end else outputChatBox("* Error: Syntax error: /setAccountData !",player,unpack(scriptcol[2])) end else outputChatBox("* Error: You can't use this function!",player,unpack(scriptcol[2])) end end) addCommandHandler("getAccountData", function (player, command, target, data) local account = getPlayerAccount(player) if (isObjectInACLGroup("user." ..getAccountName(account), aclGetGroup("Admin"))) then if (target) and (data) then local targetPlayer = getPlayerWildcard(target) if (targetPlayer) then if not (isGuestAccount(getPlayerAccount(targetPlayer))) then for i, v in ipairs(dataTable) do if (v == data) then local value = getAccountData(getPlayerAccount(targetPlayer), data) outputChatBox("* Account data for: #FFFFFF"..getPlayerName(targetPlayer).." #ff8000[datatype: '"..tostring(data).."' , value: '"..tostring(value).."' ]",player,unpack(scriptcol[3])) return end end else outputChatBox("* Error: Target not logged in!",player,unpack(scriptcol[2])) end else outputChatBox("* Error: Could not find player!",player,unpack(scriptcol[2])) end else outputChatBox("* Error: Syntax error: /getAccountData !",player,unpack(scriptcol[2])) end else outputChatBox("* Error: You can't use this function!",player,unpack(scriptcol[2])) end outputChatBox("* Error: Could not find the datatype!",player,unpack(scriptcol[2])) end) function getPlayerWildcard(namePart) namePart = string.lower(namePart) local bestaccuracy = 0 local foundPlayer, b, e for _,player in ipairs(getElementsByType("player")) do b,e = string.find(string.lower(string.gsub(getPlayerName(player):lower(),"#%x%x%x%x%x%x", "")), namePart) if b and e then if e-b > bestaccuracy then bestaccuracy = e-b foundPlayer = player end end end if (foundPlayer) then return foundPlayer else return false end end function findMap( query ) local maps = findMaps( query ) -- Make status string local status = "Found " .. #maps .. " match" .. ( #maps==1 and "" or "es" ) for i=1,math.min(5,#maps) do status = status .. ( i==1 and ": " or ", " ) .. "'" .. getMapName( maps ) .. "'" end if #maps > 5 then status = status .. " (" .. #maps - 5 .. " more)" end if #maps == 0 then return nil, status .. " for '" .. query .. "'" end if #maps == 1 then return maps[1], status end if #maps > 1 then return nil, status end end -- Find all maps which match the query string function findMaps( query ) local results = {} --escape all meta chars query = string.gsub(query, "([%*%+%?%.%(%)%[%]%{%}%\%/%|%^%$%-])","%%%1") -- Loop through and find matching maps for i,resource in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getResourceFromName( "race" ))) do local resName = getResourceName( resource ) local infoName = getMapName( resource ) -- Look for exact match first if query == resName or query == infoName then return {resource} end -- Find match for query within infoName if string.find( infoName:lower(), query:lower() ) then table.insert( results, resource ) end end return results end function getMapName( map ) return getResourceInfo( map, "name" ) or getResourceName( map ) or "unknown" end local g_MapInfoList function loadMapInfoAll(resName) local rows = executeSQLQuery( 'SELECT * FROM race_mapmanager_maps' ) g_MapInfoList = {} for i,row in ipairs(rows) do local map = getResourceFromName( row.resName ) if map then local mapInfo = getMapInfo( map ) mapInfo.infoName = row.infoName mapInfo.playedCount = row.playedCount mapInfo.lastTimePlayed = row.lastTimePlayedText end end end function getMapInfo( map ) if not g_MapInfoList then loadMapInfoAll() end if not g_MapInfoList[map] then g_MapInfoList[map] = {} end local mapInfo = g_MapInfoList[map] if mapInfo then return mapInfo end end function sendMapInfoToPanel(thePlayer,mapName) if mapName then mapInfo = getMapInfo(findMap(mapName)) author = load(findMap(mapName)) mapInfo.author = author.info['author'] toptimes = loadToptimes(mapName) if mapInfo then callClientFunction(thePlayer,"setMapInfoData",mapInfo,toptimes) end end end RaceMap = {} function load(res) --Check if there are any .'s by using the real element system first local resourceRoot = getResourceRootElement(res) --Spawnpoints are contained within the MTA map, therefore lets assume only MTA maps were used (removes general.ModifyOtherObjects dependency) local meta = xmlLoadFile(':' .. getResourceName(res) .. '/' .. 'meta.xml') if not meta then return false end local infoNode = xmlFindChild(meta, 'info', 0) local info = infoNode and xmlNodeGetAttributes ( infoNode ) or {} xmlUnloadFile(meta) local map = setmetatable({ info = info },RaceMap) return map end local columns = { 'playerName','timeText' } function loadToptimes(mapName) toptimes = {} local mode = 'Destruction Derby' local sqlResults = executeSQLQuery('SELECT * FROM '..makeDatabaseTableName(mode,mapName)) if not sqlResults then return false end toptimes = {} for r,sqlRow in ipairs(sqlResults) do local row = {} for c,column in ipairs(columns) do row[column] = sqlRow[column] end table.insert( toptimes, row ) end return toptimes end function makeDatabaseTableName( raceModeName, mapName ) return qsafestring('race maptimes ' .. raceModeName .. ' ' .. mapName) end function safestring( s ) -- escape ' return s:gsub( "(['])", "''" ) end function qsafestring( s ) -- ensure is wrapped in ' return "'" .. safestring(s) .. "'" end function qsafetablename( s ) return qsafestring(s) end Link to comment
JR10 Posted March 18, 2014 Share Posted March 18, 2014 Next time surround your code with [lua.] tags (without the period) and if it's that big use pastebin. Try this: userpanel_server.lua ------------------------------------------------------------------------------------------------------------- -- Original file by NeXTreme. Thanks for you'r awesome resource. -- -- -- -- This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.-- -- [url=http://creativecommons.org/licenses/by-nc-nd/3.0/ ]http://creativecommons.org/licenses/by-nc-nd/3.0/ [/url] -- -- -- -- Edited by Quitler#. All right reserved. Copyright 2013. -- ------------------------------------------------------------------------------------------------------------- -- String.random characters chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"} local dataTable = { "cash", "points", "firstTimeJoin", "totalTimesJoined", "unlockedAchievements", "mapsWon", "totalToptimes", "totalHunters", "mapsPlayed", "totalDeaths", "totalPlayingTimeMinutes", "totalPlayingTimeHours", "highestWinstreak", "totalSpins", "buyedMaps", "ach1", "ach2", "ach3", "ach4", "ach5", "ach6", "ach7", "ach8", "ach9", "ach10", "ach11", "ach12", "ach13", "ach14", "ach15", "ach16", } textDataTable = {"nick"} playerTableStats = {} ----------------------------------- --- Protect Userpanel ----------------------------------- function protectUserpanel() onResourceStart() end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),protectUserpanel) ----------- -- Settings ----------- mapCost = 5000 -- The price for setting maps. vehicleColor = 15000 headlightColor = 10000 moneyEarnPart = 30 -- The amount of money to calculate with to get the final money to give to the player. reactionMin = 900 -- Minimum money for the reaction test reactionMax = 2100 -- Maximum money for the reaction test reactionDuration = 20 -- Duration of the reaction test in seconds reactionMinRedo = 300 -- Minimum amount of time to pass before a new reaction test is started in seconds reactionMaxRedo = 400 -- Maximum amount of time to pass before a new reaction test is started in seconds reactionLength = 12 -- Number of characters to use in the reaction test function onResourceStart() mapIsAlreadySet = false reactionString = "" reactionMoney = 0 mapType = "" mapName = "" mapBlock = "" messegeSent = false messegeSentR = false setTimer(newReactionTest,math.random(reactionMinRedo*1000,reactionMaxRedo*1000),1) outputDebugString("Resource is restarting, please stand by...") setTimer(outputDebugString,700,1,"Resource sucessfully started: FFP Userpanel by Xiti. ") end function clientMsgLoad() local toptimesMsg = get( "msgToptime" ) enableTopMsg = false if toptimesMsg then if(toptimesMsg == "true") then enableTopMsg = true else enableTopMsg = false end end end addEvent("onClientLoaded", true) addEventHandler( "onClientLoaded", getRootElement(), clientMsgLoad) -- Prices for each horn hornPrice={2000,4000,6000,8000,10000,15000,20000} -- Disable voting function disableVote() cancelEvent() end addCommandHandler("voteredo",disableVote) addCommandHandler("new",disableVote) ----------------------------------------------------------------------------------- -----------------------------------| USERPANEL |----------------------------------- ----------------------------------------------------------------------------------- ---------------------------- -- Refresh Players ---------------------------- function triggerRebuildPlayerGridlist(thePlayer) local loggedPlayers = {} for i,player in ipairs(getElementsByType("player")) do if not (isGuestAccount(getPlayerAccount(player))) then table.insert(loggedPlayers, tostring(getPlayerName(player))) end setTimer(callClientFunction,1000,1,getRootElement(),"refreshConnectedPlayers",loggedPlayers) end end addEventHandler("onPlayerChangeNick",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerLogin",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerJoin",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerLogout",getRootElement(),triggerRebuildPlayerGridlist) addEventHandler("onPlayerQuit",getRootElement(),triggerRebuildPlayerGridlist) ---------------------------------- -- Tables System based on Accounts ---------------------------------- function createNewTables() local account = getPlayerAccount(source) if not (isGuestAccount(account)) then for i, data in ipairs(dataTable) do if not (getAccountData(account, data)) then setAccountData(account, data, "0") outputDebugString("Setting data: "..tostring(data).." for player: "..tostring(getPlayerName(source)).." to 0") end end end if not (isGuestAccount(account)) then for i, data in pairs(textDataTable) do if not (getAccountData(account, data)) then setAccountData(account, data, getPlayerName(source)) end end end end addEventHandler("onPlayerLogin", getRootElement(), createNewTables) addCommandHandler("resetStats", function (player, cmd, arg1) if (arg1) then local account = getPlayerAccount(player) if (isObjectInACLGroup("user." ..getAccountName(account), aclGetGroup("Admin"))) then local target = getPlayerWildcard(arg1) if (target) then local account = getPlayerAccount(target) if not (isGuestAccount(account)) then for i, data in ipairs(dataTable) do setAccountData(account, data, "0") outputDebugString("Setting data: "..tostring(data).." for player: "..tostring(getPlayerName(target)).." to 0") end end if not (isGuestAccount(account)) then for i, data in pairs(textDataTable) do end end end end end end) ------------------------------------------- -- Userpanel - handle requests from clients ------------------------------------------- function timesJoin() setElementData(source,"join","joined") scoreboardRefresh(source) end addEventHandler("onPlayerJoin",getRootElement(),timesJoin) -- Stats view function getPlayerStats(triggeringPlayer,thePlayer) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then playerTableStats[1] = tonumber(getAccountData(account,"cash")) playerTableStats[2] = tonumber(getAccountData(account,"points")) playerTableStats[3] = tonumber(getAccountData(account,"mapsPlayed")) playerTableStats[4] = tonumber(getAccountData(account,"totalDeaths")) playerTableStats[5] = tonumber(getAccountData(account,"mapsWon")) playerTableStats[6] = 0 -- Win ratio if playerTableStats[3] == 0 and playerTableStats[5] == 0 then playerTableStats[6] = "0%" elseif playerTableStats[3] ~= 0 and playerTableStats[5] == 0 then playerTableStats[6] = "0%" elseif playerTableStats[3] ~= 0 and playerTableStats[5] ~= 0 then playerTableStats[6] = math.floor(math.round(((100/playerTableStats[3])*playerTableStats[5]),2)).."%" elseif playerTableStats[5] > playerTableStats[3] then playerTableStats[6] = "0%" end playerTableStats[7] = tonumber(getAccountData(account,"unlockedAchievements")).."/16" playerTableStats[8] = tonumber(getAccountData(account,"highestWinstreak")) playerTableStats[9] = tonumber(getAccountData(account,"totalTimesJoined")) playerTableStats[10] = "00:00" minutes = tonumber(getAccountData(account,"totalPlayingTimeMinutes")) hours = tonumber(getAccountData(account,"totalPlayingTimeHours")) if hours < 10 then hours = "0"..hours end if minutes < 10 then minutes = "0"..minutes end playerTableStats[10] = ""..hours..":"..minutes.."" -- Total Playing Time playerTableStats[11] = tonumber(getAccountData(account,"totalHunters")) playerTableStats[12] = tonumber(getAccountData(account,"totalToptimes")) playerTableStats[13] = Link to comment
Taso Posted March 18, 2014 Author Share Posted March 18, 2014 Don't work for buy map & wins. Link to comment
JR10 Posted March 18, 2014 Share Posted March 18, 2014 I tried to fix the errors you've posted, is it fixed or not? Does it still output the same error? If it outputs other errors, post them. Link to comment
Taso Posted March 18, 2014 Author Share Posted March 18, 2014 ERROR: [gamemodes]\[race]\userpanel\userpanel_server.lua:1684: Database query failed: no such table: race_mapmanager_maps ERROR: [gamemodes]\[race]\userpanel\userpanel_server.lua:1686: bad argument #1 to 'ipairs' (table expected, got boolean) Link to comment
JR10 Posted March 18, 2014 Share Posted March 18, 2014 ERROR: [gamemodes]\[race]\userpanel\userpanel_server.lua:1684: Database query failed: no such table: race_mapmanager_maps The error is more than self-explanatory the table race_mapmanager_maps does not exist in the database. Looking at your code, you're using a part of the race resource, but missing some of the functions it uses. So your script is pretty messed up. I recommend you either copy it again or consult the one who wrote that code, if it's not you. Link to comment
Castillo Posted March 18, 2014 Share Posted March 18, 2014 Do you even have permission to use this script? 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