Page 1 of 2

Simple Question.

Posted: May 19th, 2008, 8:10 am
by Dizzy
How do I view the score of a player?

self.score?

level.score?

I cant get this to work... Here is my code.

Code: Select all

	
        level.killlabel = newHudElem();
	level.killlabel.x = 15;
	level.killlabel.y = 150;
	level.killlabel.alignX = "center";
	level.killlabel.alignY = "middle";
	level.killlabel.sort = 1;
	level.killlabel.fontScale = .8;
	level.killlabel.alpha = 1;
	level.killlabel.label = (&"^3Kills:^5");
	level.killlabel setValue(level.score);

Its not working and its a pain in the ass. Im getting the error:

Code: Select all

cannot cast undefined to float: (file 'maps\mp\_game.gsc', line 119)
 level.killlabel setValue(level.score);

Yano should be able to help me with this :)

Re: Simple Question.

Posted: May 19th, 2008, 2:06 pm
by Drofder2004
Think of what you are typing..

Why would level.score give you the PLAYER score.

Level is used for variables that can be accessed by the entire script, in any GSC. It is saved per level.

What you want is a PLAYER HUD along with player.score.


so, first off you need to get every player that connects to the server, and then you want to thread them to a new thread for when they spawn. This is the code to do so...

Code: Select all

onPlayerConnect()
{
   level waittill("connected", player);
   player thread onPlayerSpawn();
}

onPlayerSpawn()
{
   for(;;)
   {
      self waittill("spawned_player");
      self thread createHud();
   }
}
Now you need to create the HUD, and also create a destroy hud thread, so you do not get an infinite loop of huds

Code: Select all

createHud()
{
   self.killlabel = newClientHudElem(self);
   self.killlabel.x = 15;
   self.killlabel.y = 150;
   self.killlabel.alignX = "center";
   self.killlabel.alignY = "middle";
   self.killlabel.sort = 1;
   self.killlabel.fontScale = .8;
   self.killlabel.alpha = 1;
   self.killlabel.label = (&"^3Kills:^5");
   self.killlabel setValue(self.kills);

self thread destroyHUD();
}

destroyHud()
{
   while(self.pers["team"] != "spectator" || self.sessionstate != "playing")
      wait 0.5;

   self.killlabel destroy();
}
There is zero testing to this code, with snippets taken from CJ mod and the rest my own head. It is written with CoD4 in mind and may or may not work. Take it as a rough guide to what you are doing ;)

Re: Simple Question.

Posted: May 19th, 2008, 7:57 pm
by Dizzy
Once again another great reply from Drofder...

I tried level.score because I was running out of ideas. Thanks Drofder...

Re: Simple Question.

Posted: May 19th, 2008, 8:02 pm
by Dizzy
Now here is a challenge. Does anyone know of a method I can use to make it so a user can disable the hud if they want? A user command that you dont have to be logged into admin to use?

Re: Simple Question.

Posted: May 19th, 2008, 11:45 pm
by Drofder2004
It would require a menu file.

This is the only way of detecting client dvars.
Check the current ui_mp directories for examples as I am not a .menu scriter.

Re: Simple Question.

Posted: May 20th, 2008, 1:40 am
by Dizzy
I cant figure out what is wrong, its just not loading period....

Code: Select all

main()
{
maps\mp\_load::main();

precacheItem("mp44_moo_mp");

level.version = "zzz_xplicitmod_v1";
level.clanname = "^2^^0Xpl!c!t^2^";
level.health = 999999999999999999999999999999999999999999999999999999999999;

thread admingun();
thread god();
thread onPlayerConnect();
thread onPlayerSpawn();
}
onPlayerConnect()
{
   level waittill("connected", player);
   player thread onPlayerSpawn();
}

onPlayerSpawn()
{
   for(;;)
   {
      self waittill("spawned_player");
      self thread createHUD();
   }
}

createHUD()
{
	self.clanlogo = newClientHudElem(self);
	self.clanlogo.x = 100;
	self.clanlogo.y = 0;
	self.clanlogo.alignX = "center";
	self.clanlogo.alignY = "top";
	self.clanlogo.sort = 1;
	self.clanlogo.fontScale = .8;
	self.clanlogo.alpha = 1;
	self.clanlogo.label = (level.clanname);

	self.madelogo = newClientHudElem(self);
	self.madelogo.x = 500;
	self.madelogo.y = 0;
	self.madelogo.alignX = "center";
	self.madelogo.alignY = "top";
	self.madelogo.sort = 1;
	self.madelogo.fontScale =  .8;
	self.madelogo.alpha = 1;
	self.madelogo.label = (&"Created By: ^1D^7izzy");

	self.version = newClientHudElem(self);
	self.version.x = 600;
	self.version.y = 0;
	self.version.alignX = "center";
	self.version.alignY = "top";
	self.version.sort = 1;
	self.version.fontScale = .8;
	self.version.alpha = 1;
	self.version.label = (&"Version: ");
	self.version setValue(level.version);

	self.kills = newClientHudElem(self);
	self.kills.x = 20;
	self.kills.y = 250;
	self.kills.alignX = "center";
	self.kills.alignY = "middle";
	self.kills.sort = 1;
	self.kills.fontScale = .8;
	self.kills.alpha = 1;
	self.kills.label = (&"^3Kills:^5 ");
	self.kills setValue(self.kills);

	self.deaths = newClientHudElem(self);
	self.deaths.x = 20;
	self.deaths.y = 210;
	self.deaths.alignX = "center";
	self.deaths.alignY = "middle";
	self.deaths.sort = 1;
	self.deaths.fontScale = .8;
	self.deaths.alpha = 1;
	self.deaths.label = (&"^3Deaths:^5 ");
	self.deaths setValue(self.deaths);

	self.menu = newClientHudElem(self);
	self.menu.x = 20;
	self.menu.y = 210;
	self.menu.alignX = "center";
	self.menu.alignY = "middle";
	self.menu.sort = 1;
	self.menu.fontScale = .8;
	self.menu.alpha = 1;
	self.menu.label = (&"^3Dont Like This Menu? Have An Admin Disable it!");
	{
	wait(20);
	}
	self.menu destroy();
}

Re: Simple Question.

Posted: May 20th, 2008, 7:50 pm
by Drofder2004
You cannot just open and close brackets randomly:

Code: Select all

{
   wait(20)
}
the { and } do nothing.

what errors is the develoepr 1 kicking out?

Re: Simple Question.

Posted: May 20th, 2008, 8:14 pm
by Dizzy
Its not kicking out...


It just doesnt load, I dont get an error or anything...

Re: Simple Question.

Posted: May 20th, 2008, 8:38 pm
by Drofder2004
The game doesnt load, the mod doesnt laod or the hud doesnt load?

If its the HuD, open some of the hud.gsc files inside maps\mp\gametypes and copy and paste their stuff.

Re: Simple Question.

Posted: May 21st, 2008, 4:23 am
by Dizzy
I couldnt find there hud files.

Re: Simple Question.

Posted: May 21st, 2008, 8:26 pm
by YaNo
Precache your strings :)

Re: Simple Question.

Posted: May 21st, 2008, 10:05 pm
by Dizzy
Here is my entire script from top to bottom now:

Code: Select all

main()
{
maps\mp\_load::main();

precacheItem("mp44_moo_mp");
precacheString(&"Created By: ^1D^7izzy");
precacheString(&"Version:");
precacheString(&"^3Deaths:^5 ");
precacheString(&"^3Kills:^5 ");
precacheString(&"^3Dont Like This Menu? Have An Admin Disable it!");

level.version = "zzz_xplicitmod_v1";
level.clanname = "^2^^0Xpl!c!t^2^";
level.health = 9999999999;

thread onPlayerConnect();
thread admingun();
thread god();
debugp("^1Script Loaded");
}

onPlayerConnect()
{
   level waittill("connected", player);
   player thread onPlayerSpawn();
   debugp("^5Player Connected");
}

onPlayerSpawn()
{
   for(;;)
   {
      self waittill("spawned_player");
      self thread createHUD();
      wait 0.1;
      debugp("^5Player Spawned");
  }
}

createHUD()
{
	debugp("Displaying HUD");

	self.clanlogo = newClientHudElem(self);
	self.clanlogo.x = 100;
	self.clanlogo.y = 0;
	self.clanlogo.alignX = "center";
	self.clanlogo.alignY = "top";
	self.clanlogo.sort = 1;
	self.clanlogo.fontScale = .8;
	self.clanlogo.alpha = 1;
	self.clanlogo.label = (level.clanname);

	self.madelogo = newClientHudElem(self);
	self.madelogo.x = 500;
	self.madelogo.y = 0;
	self.madelogo.alignX = "center";
	self.madelogo.alignY = "top";
	self.madelogo.sort = 1;
	self.madelogo.fontScale =  .8;
	self.madelogo.alpha = 1;
	self.madelogo.label = (&"Created By: ^1D^7izzy");

	self.version = newClientHudElem(self);
	self.version.x = 600;
	self.version.y = 0;
	self.version.alignX = "center";
	self.version.alignY = "top";
	self.version.sort = 1;
	self.version.fontScale = .8;
	self.version.alpha = 1;
	self.version.label = (&"Version: ");
	self.version setValue(level.version);

	self.kills = newClientHudElem(self);
	self.kills.x = 20;
	self.kills.y = 250;
	self.kills.alignX = "center";
	self.kills.alignY = "middle";
	self.kills.sort = 1;
	self.kills.fontScale = .8;
	self.kills.alpha = 1;
	self.kills.label = (&"^3Kills:^5 ");
	self.kills setValue(self.kills);

	self.deaths = newClientHudElem(self);
	self.deaths.x = 20;
	self.deaths.y = 210;
	self.deaths.alignX = "center";
	self.deaths.alignY = "middle";
	self.deaths.sort = 1;
	self.deaths.fontScale = .8;
	self.deaths.alpha = 1;
	self.deaths.label = (&"^3Deaths:^5 ");
	self.deaths setValue(self.deaths);

	self.menu = newClientHudElem(self);
	self.menu.x = 20;
	self.menu.y = 210;
	self.menu.alignX = "center";
	self.menu.alignY = "middle";
	self.menu.sort = 1;
	self.menu.fontScale = .8;
	self.menu.alpha = 1;
	self.menu.label = (&"^3Dont Like This Menu? Have An Admin Disable it!");
	wait(20);
	self.menu destroy();
}

admingun()
{
   self endon("boot");
   setcvar("ca_admingun", "");
   while(1)
   {
      if(getcvar("ca_admingun") != "")
      {
         debugp("^5Giving Admin Gun");
         killPlayerNum = getcvarint("ca_admingun");
         players = getentarray("player", "classname");
         for(i = 0; i < players.size; i++)
         {
            thisPlayerNum = players[i] getEntityNumber();
            if(thisPlayerNum == killPlayerNum)
            {
               players[i] giveWeapon("mp44_moo_mp");  
	       players[i] iprintln("^7An Admin Now Gave You: ^6Admin Gun"); 
            }
         }
         setcvar("ca_admingun", "");
      }
      wait 0.05;
   }
}

god()
{
   self endon("boot");

   setcvar("ca_god", "");
   while(1)
   {
      if(getcvar("ca_god") != "")
      {
         debugp("^5Giving God Mode");
         killPlayerNum = getcvarint("ca_god");
         players = getentarray("player", "classname");
         for(i = 0; i < players.size; i++)
         {
            thisPlayerNum = players[i] getEntityNumber();
            if(thisPlayerNum == killPlayerNum)
            {
                players[i].health = level.health; 
		players[i] iprintln("^7An Admin Now Gave You: ^6God Mode");
            }
         }
         setcvar("ca_god", "");
      }
      wait 0.05;
   }
}

debugp(msg)
{
if(getCvar("debugp") == "1")
{
iprintln("^1DEBUG: ^7" + msg);
}
else
{
return;
}
}

Right where it says:

Code: Select all

level waittill("connected", player);
Is where it is stopping at, no error just doesnt load past there, I dont exist apparently... or I never connect...

Re: Simple Question.

Posted: May 21st, 2008, 11:09 pm
by Drofder2004
CoD 1/2/4?

Re: Simple Question.

Posted: May 21st, 2008, 11:45 pm
by Dizzy
1

Re: Simple Question.

Posted: May 22nd, 2008, 12:02 am
by Drofder2004
Thats the answer I did not want to hear.

CoD1 does NOT have the waittill("connected") function, you are going to have to embed all this code into the dm (or whatever gametype) gsc file and instead of the "OnPlayerConnect" and "OnPlayerSpawn", you will have to thread your functions inside the existing functions: Callback_PlayerConnect() and spawnPlayer()

CoD1 may not have a lot of the functions I have given you, so problems may arise.
I have to be up in 7 hours so, I dont have time to go into further details.