[Support] On-Screen Player Health Information. GSC Code

Topic created · 7 Posts · 182 Views
  • I have been working on a HUD that shows the health of the player in Zombies Mode.
    The code I have so far shows me the health of spawning the player.

    init()
    {
    	level.clientid = 0;
    	level.perk_purchase_limit = 9;
    	level thread onplayerconnect();
    	}
    
    onplayerconnect()
    {
    	for ( ;; )
    	{
    		level waittill( "connecting", player );
    		player thread onplayerspawned();
    		player.clientid = level.clientid;
    		level.clientid++;
    		player thread healthPlayer(); // Here I call my HUD HEALTH function
    		
    	}
    }
    
    onplayerspawned()
    {
    	level endon( "game_ended" );
            self endon( "disconnect" );
    	for(;;)
    	{
    		self welcome();
    		self addScore();
    		
    	}
    }
    
    healthPlayer()
    {
    	self endon("disconnect");
    	self iPrintln("Entra a healthPlayer");
    	self iprintln( "HEALTH: "+ self.health);
    	self.healthText = createServerFontString("Objective" , 1.7);
            self.healthText setPoint("CENTER", "TOP", 300, "CENTER");
            while(true)
                  {
                   self.healthText setText( "^2HEALTH: ^7"+ self.health);
                   wait 0.5;
                  }
    }
    

    But I have a problem, when another player or more connects, it shows me my health on the screen it also shows the health of the other player or other players on my screen too. The same thing happens to the rest of the players, it shows them their health and the health of the other players is put on top of them.

    Any help on how to fix it, and to show each player the health that corresponds to them and not to show the health of all the players to each one?

  • @Kalitos said in On-Screen Player Health Information. !Help:

    healthPlayer()
    {
    self endon("disconnect");
    self iPrintln("Entra a healthPlayer");
    self iprintln( "HEALTH: "+ self.health);
    self.healthText = createServerFontString("Objective" , 1.7);
    self.healthText setPoint("CENTER", "TOP", 300, "CENTER");
    while(true)
    {
    self.healthText setText( "^2HEALTH: ^7"+ self.health);
    wait 0.5;
    }
    }

    healthPlayer()
    {
    	self endon("disconnect");
    	
    	if ( isDefined ( self.healthText ) )
    		return;
    	
    	self iPrintln("Entra a healthPlayer");
    	self iprintln( "HEALTH: "+ self.health);
    	
    	self.healthText = createServerFontString("Objective" , 1.7);
    	self.healthText setPoint("CENTER", "TOP", 300, "CENTER");
    	
    	while(true)
    	{
    		self.healthText setText( "^2HEALTH: ^7"+ self.health);
    		wait 0.5;
    	}
    }
    

    not tested but should work

  • I have fixed it.
    I have only had to change this function:

    createServerFontString("Objective" , 1.7);
    

    For this:

    createFontString("Objective" , 1.7);
    

    I think that the function, as its name says "It runs on the server for all players", instead the other function, "It runs on each of the clients.

    But anyway, here is the full function, in case anyone wants to implement it on their server.

    init()
    {
    	level.clientid = 0;
    	level.perk_purchase_limit = 9;
    	level thread onplayerconnect();
    }
    
    onplayerconnect()
    {
    	for ( ;; )
    	{
    		level waittill( "connecting", player );
    		player thread onplayerspawned();
    		player.clientid = level.clientid;
    		level.clientid++;
    		player thread healthPlayer(); // Here I call my HUD HEALTH function
    		
    	}
    }
    
    healthPlayer()
    {
    	self endon("disconnect");
    	//self iprintln( "HEALTH: "+ self.health);
    	self.healthText = createFontString("Objective" , 1.7); //Fixed
            self.healthText setPoint("CENTER", "TOP", 300, "CENTER");
            while(true)
                  {
                   self.healthText setText( "^2HEALTH: ^7"+ self.health);
                   wait 0.5;
                  }
    }
    

    I have tried it in zombies mode, I do not know if it also works in multiplayer mode.

  • oh yeah havent tought about that

  • Why this happens?

    **** 3 script error(s):
    **** Unresolved external : "onplayerspawned" with 0 parameters in "_clientids" at line 1 ****
    **** Unresolved external : "createfontstring" with 2 parameters in "_clientids" at line 1 ****
    **** Unresolved external : "setpoint" with 4 parameters in "_cl

  • @GangorraAidetica Did you add the include you need to execute the functions you use?

  • I threw in some hud imports and utils, but I believe it's supposed to be zombies specific utils, right?
    (I dont have em now because I was exploring scripts and already changed everything :P)

Log in to reply