Liberty Unleashed
Scripting => Script Help => Topic started by: Mido_Pop on November 07, 2013, 03:52:21 pm
-
What is The Error ?
Or How To Get The Highest Score ?
g_pPlayer <- FindLocalPlayer();
function onScriptLoad()
{
// Start
local Pos = VectorScreen( ScreenWidth - 148, ScreenHeight - 348 );
local Size = ScreenSize( 130, 208 );
local Text0Pos = VectorScreen( 5, 5 );
local TextSize = ScreenSize( 100, 10 );
Window <- GUIWindow( Pos, Size, "Kings Of The Server" );
Text0 <- GUILabel( Text0Pos, TextSize, "" );
Text0.FontName = "Verdana";
Text0.FontSize = 10;
Window.Colour = Colour(10, 10, 10);
Window.Alpha = 150;
Text0.TextColour = Colour( 255, 255, 255 );
AddGUILayer( Window );
Window.AddChild( Text0 );
// End
}
function onClientRender()
{
local players = GetPlayers();
if (players == 0){ return false; }
players += 10;
local pPlayer = null, id = 0;
while ( id < players )
{
pPlayer = FindPlayer( id );
if ( pPlayer)
{
if(pPlayer.Score >= 500)
{
Text0.Text = "*System* "+pPlayer.Name+" >> [ King ].";
}
}
id += 1;
}
}
-
First: There's no such thing as 0 players with an client script loaded.
Second: I wouldn't want to do something like that onClientRender. Why not update the GUIs when there's a score change? Like onKill?
Third: Add some debug messages. Print the amount of players, print if you get valid player pointers, print their scores. Etc. Etc.
-
Man I Want To Get The Highest player Score on The Server, I Don't Want The player Score.
You Can Give Me An Example ?
-
I gave you examples, you just have to add them yourself. They really are not hard to do..
Just add a Message() for each information you want to debug.
-
I dont have windows 7 at my PC anymore, so i cant check this code. You should try it:
g_pPlayer <- FindLocalPlayer();
print("Script test 1");
function onScriptLoad()
{
print("Script test 3");
// Start
local Pos = VectorScreen( ScreenWidth - 148, ScreenHeight - 348 );
local Size = ScreenSize( 130, 208 );
local Text0Pos = VectorScreen( 5, 5 );
local TextSize = ScreenSize( 100, 10 );
print("Script test 4");
Window <- GUIWindow( Pos, Size, "Kings Of The Server" );
Text0 <- GUILabel( Text0Pos, TextSize, "" );
Text0.FontName = "Verdana";
print("Script test 5");
Text0.FontSize = 10;
Window.Colour = Colour(10, 10, 10);
Window.Alpha = 150;
print("Script test 6");
Text0.TextColour = Colour( 255, 255, 255 );
AddGUILayer( Window );
Window.AddChild( Text0 );
// End
NewTimer("ScoreUpdater", 3000, 0);
print("Script test 7");
}
print("Script test 2");
function ScoreUpdater()
{
print("Score Updater launched");
local players = GetPlayers();
if (players == 0){ return false; }
players += 10;
local pPlayer = null, id = 0;
while ( id < players )
{
pPlayer = FindPlayer( id );
if ( pPlayer) {
if(pPlayer.Score >= 500){
Text0.Text = "*System* "+pPlayer.Name+" >> [ King ].";
Message("*System* "+pPlayer.Name+" >> [ King ].");
} }
id += 1;
}
print("Score Updater script has finished his job");
}
print("Script test 3");
1. Its good that you defined LocalPlayer in global variable g_pPlayer but since you never used g_pPlayer in your current script, it would be better to remove that variable until you need it again ( it's needed for RAM (Memory) optimization)
2. Maybe you noticed that i inserted in your code print("Script test 1"); ( and etc) its called "script debug system" and all serious Programmers/Scripters all over the world use this to find errors in their software.
Press a "~" (http://liberty-unleashed.co.uk/LUWiki/Client_Manual#Controls) key to open the console. Make sure you will get messages from Script test 1 to Script test 7. And then, each second you should recieve Score Updater launched vs Score Updater script has finished his job.
3. If you succeed with this code, remove debug messages and leave ScoreUpdater function to work with timer together, because as i remember some special code cant work with onClientRender, maybe it's your case.
-
Thanks For The Reply But I Can't Find The Error.
The Error In This Code
local players = GetPlayers();
if (players == 0){ return false; }
players += 10;
local pPlayer = null, id = 0;
while ( id < players )
{
pPlayer = FindPlayer( id );
if ( pPlayer) {
if(pPlayer.Score >= 500){
Text0.Text = "*System* "+pPlayer.Name+" >> [ King ].";
} }
id += 1;
}
-
If you want to find the problem you need to look a bit further then that piece of code...
-
ensure not work that way, do not put GetPlayers() because I see that I do not work :(
function onScriptLoad()
{
// Start
local Pos = VectorScreen( ScreenWidth - 148, ScreenHeight - 348 );
local Size = ScreenSize( 130, 208 );
local Text0Pos = VectorScreen( 5, 5 );
local TextSize = ScreenSize( 100, 10 );
Window <- GUIWindow( Pos, Size, "Kings Of The Server" );
Text0 <- GUILabel( Text0Pos, TextSize, "" );
Text0.FontName = "Verdana";
Text0.FontSize = 10;
Window.Colour = Colour(10, 10, 10);
Window.Alpha = 150;
Text0.TextColour = Colour( 255, 255, 255 );
AddGUILayer( Window );
Window.AddChild( Text0 );
// End
}
function onClientRender()
{
local x = 0;
local total = 30;
while ( x < total )
{
local plr = FindLocalPlayer( x );
if(plr)
{
if ( plr.Score >= 500 )
{
Text0.Text = "*System* " + plr.Name + " >> [ King ].";
}
}
x++;
}
}