Fury Posted July 11, 2012 Posted July 11, 2012 server: ----------------------- -- Player Stats tabi -- ----------------------- function getPlayerStats(triggeringPlayer,thePlayer) local account = getPlayerAccount( thePlayer ) local points = tonumber(getAccountData( account,"points" )) local wins = tonumber(getAccountData( account,"wins" )) local second = tonumber(getAccountData( account,"second" )) local third = tonumber(getAccountData( account,"third" )) local rank = getElementData(source,"rank") callClientFunction1(triggeringPlayer,"displayPersonalStats",thePlayer,points,wins,second,third,rank) end -------------- function callServerFunction1(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("onClientCallsServerFunction1", true) addEventHandler("onClientCallsServerFunction1", resourceRoot , callServerFunction) function callClientFunction1(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, "onServerCallsClientFunction1", resourceRoot, funcname, unpack(arg or {})) end client: GUIEditor_Tab[6] = guiCreateTab("Player Stats",GUIEditor_TabPanel[1]) gridOnlinePlayers = guiCreateGridList(20,51,162,280,false,GUIEditor_Tab[6]) guiGridListSetSortingEnabled(gridOnlinePlayers, false) guiGridListAddColumn(gridOnlinePlayers,"Name",0.9) for _,player in ipairs(getElementsByType("player")) do local row = guiGridListAddRow (gridOnlinePlayers) guiGridListSetItemText(gridOnlinePlayers,row,1,string.gsub(getPlayerName(player),"#%x%x%x%x%x%x", ""),false,false) end lblConnectedPlayers = guiCreateLabel(20,26,162,19,"Connected players",false,GUIEditor_Tab[6]) guiLabelSetColor(lblConnectedPlayers,255,120,0) guiLabelSetVerticalAlign(lblConnectedPlayers,"center") guiLabelSetHorizontalAlign(lblConnectedPlayers,"center",false) guiSetFont(lblConnectedPlayers,"default-bold-small") btnViewStats = guiCreateButton(196,96,128,36,"View stats",false,GUIEditor_Tab[6]) playerStatsWindow = guiCreateWindow(screenWidth/2-SWindowWidth/2,screenHeight/2-SWindowHeight/2,SWindowWidth,SWindowHeight,"Loading, please wait...",false) guiWindowSetSizable(playerStatsWindow,false) guiSetVisible(playerStatsWindow,false) lblPStats = guiCreateLabel(17,22,107,49,"Stats",false,playerStatsWindow) guiLabelSetColor(lblPStats,255,120,0) guiSetFont(lblPStats,"sa-header") lblPwins = guiCreateLabel(17,97,129,16,"Wins: N/A",false,playerStatsWindow) guiSetFont(lblPwins,"default-bold-small") lblPpoints = guiCreateLabel(17,81,97,16,"Points: N/A",false,playerStatsWindow) guiSetFont(lblPpoints,"default-bold-small") lblPsecond = guiCreateLabel(17,123,204,18,"Second Places: N/A",false,playerStatsWindow) guiSetFont(lblPsecond,"default-bold-small") lblPthird = guiCreateLabel(17,165,204,18,"Third Places: N/A",false,playerStatsWindow) guiSetFont(lblPthird,"default-bold-small") lblPrank = guiCreateLabel(17,178,230,14,"Rank: N/A",false,playerStatsWindow) guiSetFont(lblPrank,"default-bold-small") btnClosePlayerStatsWindow = guiCreateButton(428,226,102,38,"Close",false,playerStatsWindow) function closeStatsWindow() guiSetVisible(playerStatsWindow,false) end function getPersonalStats() local row,column = guiGridListGetSelectedItem(gridOnlinePlayers) local playerName = guiGridListGetItemText(gridOnlinePlayers,row,1) if not (playerName == "") then callServerFunction1("getPlayerStats",getLocalPlayer(),findPlayerByName(playerName)) else outputChatBox("#c0c0c0* ERROR! Please select a player!",255,255,255,true) end end function displayPersonalStats(thePlayer,points,wins,second,third,rank) guiSetText (lblPpoints, "Points: "..points) guiSetText (lblPwins, "Wins: "..wins) guiSetText (lblPsecond, "Second Places: "..second) guiSetText (lblPthird, "Third Places: "..third) guiSetText (lblPMrank,"Rank: "..rank) guiSetText(playerStatsWindow,string.gsub(getPlayerName(thePlayer),"#%x%x%x%x%x%x", "").."'s stats") end addEventHandler ( "onClientGUIClick", btnViewStats, getPersonalStats, false ) addEventHandler ( "onClientGUIClick", btnClosePlayerStatsWindow, closeStatsWindow, false ) 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 function callClientFunction1(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("onServerCallsClientFunction1", true) addEventHandler("onServerCallsClientFunction1", resourceRoot, callClientFunction) function callServerFunction1(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("onClientCallsServerFunction1", resourceRoot , funcname, unpack(arg)) end error in line 47 client: guiSetText (lblPLevel, "Points: "..points)
Castillo Posted July 11, 2012 Posted July 11, 2012 callClientFunction1(client, funcname, ...) You are sending 'thePlayer' argument as well, but is not required.
Tete omar Posted July 11, 2012 Posted July 11, 2012 what's that addEventHandler ( "onClientGUIClick", btnViewStats, getPersonalStats ) where is this ? btnViewStats and close button randomly shown up not in GUI window or something try this serverside ----------------------- -- Player Stats tabi -- ----------------------- function getPlayerStats(triggeringPlayer,thePlayer) local account = getPlayerAccount( thePlayer ) local points = tonumber(getAccountData( account,"points" )) local wins = tonumber(getAccountData( account,"wins" )) local second = tonumber(getAccountData( account,"second" )) local third = tonumber(getAccountData( account,"third" )) local rank = getElementData(source,"rank") callClientFunction1(triggeringPlayer,"displayPersonalStats",thePlayer,points,wins,second,third,rank) end -------------- function callServerFunction1(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("onClientCallsServerFunction1", true) addEventHandler("onClientCallsServerFunction1", resourceRoot , callServerFunction1) function callClientFunction1(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, "onServerCallsClientFunction1", resourceRoot, funcname, unpack(arg or {})) end clientside guiSetFont(lblPthird,"default-bold-small") lblPrank = guiCreateLabel(17,178,230,14,"Rank: N/A",false,playerStatsWindow) guiSetFont(lblPrank,"default-bold-small") btnClosePlayerStatsWindow = guiCreateButton(428,226,102,38,"Close",false,playerStatsWindow) function closeStatsWindow() guiSetVisible(playerStatsWindow,false) end function getPersonalStats() local row,column = guiGridListGetSelectedItem(gridOnlinePlayers) local playerName = guiGridListGetItemText(gridOnlinePlayers,row,1) if not (playerName == "") then callServerFunction1("getPlayerStats",getLocalPlayer(),findPlayerByName(playerName)) else outputChatBox("#c0c0c0* ERROR! Please select a player!",255,255,255,true) end end function displayPersonalStats(thePlayer,points,wins,second,third,rank) guiSetText (lblPpoints, "Points: "..points) guiSetText (lblPwins, "Wins: "..wins) guiSetText (lblPsecond, "Second Places: "..second) guiSetText (lblPthird, "Third Places: "..third) guiSetText (lblPMrank,"Rank: "..rank) guiSetText(playerStatsWindow,string.gsub(getPlayerName(thePlayer),"#%x%x%x%x%x%x", "").."'s stats") end addEventHandler ( "onClientGUIClick", getRootElement(), getPersonalStats, false ) addEventHandler ( "onClientGUIClick", btnClosePlayerStatsWindow, closeStatsWindow, false ) 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 function callClientFunction1(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("onServerCallsClientFunction1", true) addEventHandler("onServerCallsClientFunction1", resourceRoot, callClientFunction1) function callServerFunction1(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("onClientCallsServerFunction1", resourceRoot , funcname, unpack(arg)) end i tested it but it looks like not fit to me good luck
Castillo Posted July 11, 2012 Posted July 11, 2012 callClientFunction1(triggeringPlayer,"displayPersonalStats",thePlayer,points,wins,second,third,rank)
Fury Posted July 11, 2012 Author Posted July 11, 2012 lol. i fixed the problem. i have made a very bad mistake. thanks for help anyways
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