Author Topic: Help  (Read 2037 times)

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Help
« on: November 07, 2013, 03:52:21 pm »
What is The Error ?
Or How To Get The Highest Score ?
Code: [Select]
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;
}
}
« Last Edit: November 07, 2013, 03:54:53 pm by Mido_Pop »



Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Help
« Reply #1 on: November 07, 2013, 04:49:31 pm »
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.

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Re: Help
« Reply #2 on: November 08, 2013, 08:49:14 am »
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 ?



Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Help
« Reply #3 on: November 08, 2013, 12:52:59 pm »
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.

Nihau

  • Newbie
  • *
  • Posts: 49
  • Karma: +27/-18
    • View Profile
Re: Help
« Reply #4 on: November 08, 2013, 03:16:39 pm »
I dont have windows 7 at my PC anymore, so i cant check this code. You should try it:

Code: [Select]
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 "~" 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.

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Re: Help
« Reply #5 on: November 12, 2013, 04:41:09 pm »
Thanks For The Reply But I Can't Find The Error.
The Error In This Code
Code: [Select]
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;
}



Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Help
« Reply #6 on: November 12, 2013, 05:51:00 pm »
If you want to find the problem you need to look a bit further then that piece of code...

Kevin

  • Newbie
  • *
  • Posts: 32
  • Karma: +9/-35
    • View Profile
    • www.edgarcain.zz.mu
Re: Help
« Reply #7 on: November 14, 2013, 08:29:01 pm »
ensure not work that way, do not put GetPlayers() because I see that I do not work  :(
Code: [Select]
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++;
}
}
Kevin  ;)

 

© Liberty Unleashed Team.