Hi Guys, Nameless here again
This time I got a problem with guiSetText.
I am trying to create a userpanel with point, money, etc (with sqlite). All players who are online, will be set in a gridview. When a player opens the userpanel (F2) he will see his own stats. When the player clicks on another player in the gridview, the stats of the player he clicked on will show.
My problem now is: When PlayerA presses F2, and PlayerB has his userpanel open. PlayerB will get to see PlayerA his stats. Also when PlayerA clicks on another player in the gridview PlayerB will see the stats of the player PlayerA clicked on.
Here is my code:
Clientside:
local GUIWindow
local playerGridView
local playerColumn
--stat labels
local GUILabelMoney2
local GUILabelPoints2
local GUILabelMatches2
local GUILabelFirst2
local GUILabelSecond2
local GUILabelThird2
local GUILabelKills2
function createGUIWindow(test)
local width, height = guiGetScreenSize ()
local windowW,windowH = 700,350 --Main Window sizes
local windowX = (width/2) - (windowW/2) --Main Window horizontal position
local windowY = (height/2) - (windowH/2) --Main Window vertical position
--Window
GUIWindow = guiCreateWindow (windowX, windowY, windowW, windowH, "Player Information Screen", false)
--Tabpanel
local GUITabPanel = guiCreateTabPanel ( 0 ,0.1, windowW, windowH, true, GUIWindow )
local GUITabStatistics = guiCreateTab ( "Statistics", GUITabPanel )
--Labels
local GUILabelPlayerName = guiCreateLabel(0.02,0.06,0.94,0.2,"[PLAYER] his stats:",true,GUITabStatistics)
local GUILabelMoney = guiCreateLabel(0.02,0.11,0.94,0.2,"Money:",true,GUITabStatistics)
GUILabelMoney2 = guiCreateLabel(0.09,0.11,0.94,0.2,"",true,GUITabStatistics)
local GUILabelPoints = guiCreateLabel(0.02,0.16,0.94,0.2,"Points:",true,GUITabStatistics)
GUILabelPoints2 = guiCreateLabel(0.09,0.16,0.94,0.2,"",true,GUITabStatistics)
local GUILabelPlayTime = guiCreateLabel(0.35,0.11,0.94,0.2,"Playtime:",true,GUITabStatistics)
local GUILabelMatches = guiCreateLabel(0.02,0.30,0.94,0.2,"Mathes played:",true,GUITabStatistics)
GUILabelMatches2 = guiCreateLabel(0.15,0.30,0.94,0.2,"",true,GUITabStatistics)
local GUILabelFirst = guiCreateLabel(0.02,0.35,0.94,0.2,"1st Place:",true,GUITabStatistics)
GUILabelFirst2 = guiCreateLabel(0.11,0.35,0.94,0.2,"",true,GUITabStatistics)
local GUILabelSecond = guiCreateLabel(0.02,0.40,0.94,0.2,"2nd Place:",true,GUITabStatistics)
GUILabelSecond2 = guiCreateLabel(0.11,0.40,0.94,0.2,"",true,GUITabStatistics)
local GUILabelThird = guiCreateLabel(0.02,0.45,0.94,0.2,"3rd Place:",true,GUITabStatistics)
GUILabelThird2 = guiCreateLabel(0.11,0.45,0.94,0.2,"",true,GUITabStatistics)
local GUILabelKills = guiCreateLabel(0.02,0.50,0.94,0.2,"Kills:",true,GUITabStatistics)
GUILabelKills2 = guiCreateLabel(0.075,0.50,0.94,0.2,"",true,GUITabStatistics)
--Gridview
playerGridView = guiCreateGridList ( 0.60, 0.10, 0.35, 0.85, true, GUITabStatistics )
--Create a players column in the list
playerColumn = guiGridListAddColumn( playerGridView, "Player", 0.85 )
triggerEvent ( "refreshGridView", getRootElement() )
triggerServerEvent("getallstats", getRootElement())
--Set label colors:
guiLabelSetColor ( GUILabelPlayerName, 255, 0, 0 )
--Set all label fonts:
guiSetFont ( GUILabelPlayerName, "default-bold-small" )
guiSetFont ( GUILabelMoney, "default-bold-small" )
guiSetFont ( GUILabelPoints, "default-bold-small" )
guiSetFont ( GUILabelMatches, "default-bold-small" )
guiSetFont ( GUILabelFirst, "default-bold-small" )
guiSetFont ( GUILabelSecond, "default-bold-small" )
guiSetFont ( GUILabelThird, "default-bold-small" )
guiSetFont ( GUILabelPlayTime, "default-bold-small" )
guiSetFont ( GUILabelKills, "default-bold-small" )
addEventHandler ( "onClientGUIClick", playerGridView, updateStats, false )
guiSetVisible(GUIWindow, false)
end
addEventHandler("onClientResourceStart", getRootElement(),createGUIWindow)
------------------------------------------------------------------------------------------------------------
addEvent("refreshGridView", true)
function refreshPlayerGrid()
guiGridListClear ( playerGridView ) --clear gridview
if ( playerColumn ) then --If the column has been created, fill it with players
for id, player in ipairs(getElementsByType("player")) do
local row = guiGridListAddRow ( playerGridView )
guiGridListSetItemText ( playerGridView, row, playerColumn, getPlayerName ( player ), false, false )
end
end
end
addEventHandler("refreshGridView", getRootElement(), refreshPlayerGrid)
addEventHandler ( "onClientPlayerChangeNick", getRootElement(), refreshPlayerGrid)
------------------------------------------------------------------------------------------------------------
function showWindow(thePlayer) -- function for trigger
if (guiGetVisible(GUIWindow) == true) then -- if window opened then
guiSetVisible (GUIWindow,false ) -- close window
showCursor(false) --disable cursor
guiSetInputEnabled(false) --disable input focus
else
guiSetVisible (GUIWindow,true )-- enable --//--
showCursor(true) -- enable --//--
guiSetInputEnabled(true) --enable --//--
--trigger all stats event
triggerServerEvent("getallstats",getRootElement(),thePlayer)
end
end
addEvent( "showWdw", true )
addEventHandler( "showWdw", getRootElement(), showWindow )
------------------------------------------------------------------------------------------------------------
function showStats(money, points, matches, first, second, third, kills)
guiSetText ( GUILabelMoney2, money )
guiSetText ( GUILabelPoints2, points )
guiSetText ( GUILabelMatches2, matches )
guiSetText ( GUILabelFirst2, first )
guiSetText ( GUILabelSecond2, second )
guiSetText ( GUILabelThird2, third )
guiSetText ( GUILabelKills2, kills )
end
addEvent( "showStats", true )
addEventHandler( "showStats", getRootElement(), showStats )
------------------------------------------------------------------------------------------------------------
function updateStats()
local playerName = guiGridListGetItemText ( playerGridView, guiGridListGetSelectedItem ( playerGridView ), 1 )
if(playerName ~= false and playerName ~= nil and playerName ~= "") then
triggerServerEvent("getallstats",getRootElement(),getPlayerFromName(playerName))
end
end
------------------------------------------------------------------------------------------------------------
Serverside:
function refreshPlayerGrid()
triggerClientEvent("refreshGridView", getRootElement())
end
addEventHandler("onPlayerJoin", getRootElement(), refreshPlayerGrid)
addEventHandler ( "onPlayerQuit", getRootElement(), refreshPlayerGrid)
------------------------------------------------------------------------------------------------------------
function getAllStats(thePlayer)
local accountname = getAccountName (getPlayerAccount (thePlayer ))
local money
local points
local matches
local firstplace
local secondplace
local thirdplace
local kills
if( accountname ~= nil and accountname ~= false and accountname ~= "guest")then
local statsConnection = dbConnect( "sqlite", "statistics.db" )
if(statsConnection)then
local statsQuery = dbQuery ( statsConnection , "SELECT * FROM accountdata WHERE playername = ?" , accountname )
if(statsQuery)then
local statsResults = dbPoll ( statsQuery , -1 )
if(statsResults ~= false and statsResults ~= nil) then
for statsResults, row in pairs ( statsResults ) do
--get all results from given player (thePlayer)
money = ( row["money"])
points = ( row["points"])
matches = ( row["matches"])
firstplace = ( row["firstplace"])
secondplace = ( row["secondplace"])
thirdplace = ( row["thirdplace"])
kills = ( row["kills"])
end--end for loop
triggerEvent("returnallstats", getRootElement() , money, points, matches, firstplace, secondplace, thirdplace, kills )
end --end statsResults
end--end statsQuery
end--end statsconnection
end--end accountname
end--end getAllStatsFunction
addEvent("getallstats", true)
addEventHandler("getallstats", getRootElement(), getAllStats)
------------------------------------------------------------------------------------------------------------
function returnAllStats(money, points, matches, first, second, third, kills)
triggerClientEvent(source, "showStats", getRootElement(), money, points, matches, first, second, third, kills)
end
addEvent("returnallstats", true)
addEventHandler("returnallstats",getRootElement(), returnAllStats)
------------------------------------------------------------------------------------------------------------
--BINDKEYS
addEventHandler("onPlayerLogin", getRootElement(),
function()
bindKey(source, "F2", "down", function(player, key, state)
triggerClientEvent(player,"showWdw", getRootElement(), player)
end)
end
)
addEventHandler("onPlayerLogout", getRootElement(),
function()
unbindKey(source, "F2")
end
)
------------------------------------------------------------------------------------------------------------
I hope you guys can help me with this problem!
I am a beginning scripter, so if you have any other suggestions please feel free to post!
Cheers,
Nameless