Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » C++ Help request
C++ Help request [message #420409] Sat, 20 February 2010 10:21 Go to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Can anybody help me with creating this function. I failed and wasted much hours on this Huh

What the function needs to do:

Showing health number for 5 seconds and after that showing shield number for 5 seconds. The function needs to repeat itself over and over again.

healthinfo.h

/*	HealthInfoItemClass
	Copyright 2009 Mark Sararu

	This code file is made by: Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
	the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#ifndef SHADERS_HEALTHINFO_H_
#define SHADERS_HEALTHINFO_H_

class HealthInfoItemClass
{
protected:
	bool Enabled;
	bool Enabled2;

	Render2DClass*		Render2D;
	Render2DTextClass*	Render2DText;

	int					NextPrint;

	Vector2				TextPosition;
	char *				TextFontFile;

	unsigned int		StopTime;

public:
	HealthInfoItemClass();
	~HealthInfoItemClass();
	void Load(INIClass* ini);
	void Render();
};

extern HealthInfoItemClass HealthInfo;

#endif



healthinfo.cpp

/*	HealthInfoItemClass
	Copyright 2009 Mark Sararu

	This code file is made by: Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
	the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#include "scripts.h"
#include "shadereng.h"
#include "healthinfo.h"

SimpleDynVecClass<unsigned int> *Colors9;
unsigned long HealthInfoColor = 0;

HealthInfoItemClass::HealthInfoItemClass():
	Enabled(false),
	Enabled2(false),
	Render2D(NULL), 
	Render2DText(NULL),
	NextPrint(1),
	StopTime(0),
	TextPosition(0, 0),
	TextFontFile(NULL)
{
};

HealthInfoItemClass::~HealthInfoItemClass()
{
	SAFE_DELETE(Render2D);
	SAFE_DELETE(Render2DText);
	SAFE_DELETE(TextFontFile);
};

void HealthInfoItemClass::Load(INIClass *ini)
{
	if (!ini) return; // if you don't have an ini, something is horribly wrong!

	const char* section_name = "HealthInfo";

	Enabled = ini->Get_Bool(section_name, "HealthInfoEnabled", false);
	Enabled2 = ini->Get_Bool("General", "HealthInfoEnabled", false);
	if ((!Enabled) && (!Enabled2)) return;



	// Gathers the colors from hud.ini
	Colors9 = new SimpleDynVecClass<unsigned int>;

	unsigned int color = RGB(255,255,255)+0xFF000000;
	Colors9->Add(color);
	unsigned int colors9 = ini->Get_Int("General","ColorCount",0);
	for (unsigned int i = 0;i < colors9;i++)
	{
		char section[10];
		sprintf(section,"Color%d",i+1);
		unsigned int Red = ini->Get_Int(section,"Red",255);
		unsigned int Green = ini->Get_Int(section,"Green",255);
		unsigned int Blue = ini->Get_Int(section,"Blue",255);
		unsigned int Alpha = (ini->Get_Int(section,"Alpha",255) << 24);
		color = RGB(Blue,Green,Red)+Alpha;
		Colors9->Add(color);
	}
	unsigned int HealthInfoCol = ini->Get_Int(section_name,"HealthInfoColor",0);
	HealthInfoColor = (*Colors9)[HealthInfoCol];

	Render2D = CreateRender2DClass();

	Vector2 screen_center;
	screen_center.X = (ScreenResolution->Right - ScreenResolution->Left) / 2.0f;
	screen_center.Y = (ScreenResolution->Bottom - ScreenResolution->Top) / 2.0f;

	char temp[512];
	ini->Get_String(section_name, "Text.Font.File", "DEFAULT_FONT", temp, 512);
	Render2DText = CreateRender2DTextClass(temp);
	TextFontFile = newstr(temp);

	float average_height = ini->Get_Float(section_name, "Text.Font.AverageCharacterHeight", 16);

	bool text_centered = ini->Get_Bool(section_name, "Text.Position.Centered", true);
	TextPosition.X = ini->Get_Float(section_name, "Text.Position.X", 0.0f);
	TextPosition.Y = ini->Get_Float(section_name, "Text.Position.Y", 0.0f);
	if (TextPosition.X < 0)
	{
		TextPosition.X += ScreenResolution->Right;
	}
	if (TextPosition.Y < 0)
	{
		TextPosition.Y += ScreenResolution->Bottom;
	}

	if (text_centered)
	{
		TextPosition = TextPosition + screen_center;
		TextPosition.Y -= average_height / 2.0f;
	}
};



void HealthInfoItemClass::Render()
{
	if ((!Enabled) && (!Enabled2)) return;

	GameObject *obj = Get_Vehicle_Return((GameObject *)(*TheStar)->obj);
	float health = Commands->Get_Health(obj);
	float shield = Commands->Get_Shield_Strength(obj);
	unsigned int current_time = *SyncTime;
	StopTime = current_time + 10000;

	unsigned int color = 0;
	color = HealthInfoColor;

	// needs to render the health number for 5 sec while not showing shield number.
	if // something
	{
		Render2DText->Reset();
		RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
		r->Top = TextPosition.Y;
		r->Left = TextPosition.X;
		r->Bottom = TextPosition.Y;
		r->Right = TextPosition.X;
		char temp[64];
		unsigned int h = (unsigned int)(health + 0.5f);
		char icon_health[8] = "+_";
		sprintf(temp,"%s%03d" ,icon_health,h);
		Render2DText->Draw_Text(temp, color);
		Render2DText->Render();
	}
	// needs to render the Shield number for 5 sec while not showing health number.
	else if // something
	{
		Render2DText->Reset();
		RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
		r->Top = TextPosition.Y; 
		r->Left = TextPosition.X; 
		r->Bottom = TextPosition.Y; 
		r->Right = TextPosition.X;
		char temp[64];
		unsigned int s = (unsigned int)(shield + 0.5f);
		char icon_shield[8] = "*_";
		sprintf(temp,"%s%03d" ,icon_shield,s);
		Render2DText->Draw_Text(temp, color);
		Render2DText->Render();
	}
};

//--------------------------------------------------------------------------------
// globals
//--------------------------------------------------------------------------------
HealthInfoItemClass HealthInfo;



shaderhud.cpp

#include "healthinfo.h" // HealthInfo

HealthInfo.Load(hudini); // HealthInfo

HealthInfo.Render(); // HealthInfo



HUD.ini

[HealthInfo]
HealthInfoEnabled=true
Text.Font.File=font12x16.tga
Text.Font.AverageCharacterHeight=0
Text.Position.Centered=false
Text.Position.X=185.0
Text.Position.Y=-130.0
HealthInfoColor=1



Anybody please help Dont Get It


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: C++ Help request [message #420411 is a reply to message #420409] Sat, 20 February 2010 10:30 Go to previous messageGo to next message
Sladewill is currently offline  Sladewill
Messages: 291
Registered: January 2009
Location: United Kingdom
Karma: 0
Recruit

i think that would be classed as one of those things that servers will not allow, so probably no one will help you

FT-Owners - Sladewill,Snazy2007,Willdy
http://FT-Gaming.com for more info...
Re: C++ Help request [message #420418 is a reply to message #420411] Sat, 20 February 2010 10:40 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Sladewill wrote on Sat, 20 February 2010 11:30

i think that would be classed as one of those things that servers will not allow, so probably no one will help you


Its an innocent piece of code. It would be really stupid to not allow this Dont Get It


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: C++ Help request [message #420778 is a reply to message #420409] Wed, 24 February 2010 08:27 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
I also constructed a new piece of code, while I was trying to make it work. Maybe this is getting more in the direction, but I failed another time to make it work. Huh

Something like this:

	if (RunIt == true)
	{
		StopTime_1 = current_time + 5000;
		RunIt = false;
	}

	if (current_time == StopTime_1)
	{
		HealthVisible = true;
		StopTime_2 = current_time + 5000;
		Commands->Create_2D_WAV_Sound("stpccw1.wav"); /* test, and it seems that the sound is never played ingame */
	}

	if (current_time == StopTime_2)
	{
		HealthVisible = false;
		RunIt = true;
	}



Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: C++ Help request [message #420780 is a reply to message #420409] Wed, 24 February 2010 08:43 Go to previous messageGo to next message
Sladewill is currently offline  Sladewill
Messages: 291
Registered: January 2009
Location: United Kingdom
Karma: 0
Recruit

can u use scripts in the shadders?

FT-Owners - Sladewill,Snazy2007,Willdy
http://FT-Gaming.com for more info...
Re: C++ Help request [message #420787 is a reply to message #420780] Wed, 24 February 2010 10:16 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Well, only as a last resort. Because then I need to release a scripts.dll also.

Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: C++ Help request [message #420789 is a reply to message #420409] Wed, 24 February 2010 10:48 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
time_t reftime = 0;
bool ShowHealth = 1;


void TimerThink()
{
   if(reftime - time(0) > 5)
   {
      ShowHealth = ShowHealth ? 0 : 1;
      reftime = time(0);
   }
}

//draw code:

TimerThink(); //not a good place for this tbh, but whatever

if(ShowHealth)
{
    //draw health
}


Be sure to:

#include "time.h"
Re: C++ Help request [message #420796 is a reply to message #420789] Wed, 24 February 2010 12:28 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
No Message Body

Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png

[Updated on: Fri, 26 February 2010 10:12]

Report message to a moderator

Re: C++ Help request [message #420941 is a reply to message #420409] Fri, 26 February 2010 09:49 Go to previous messageGo to next message
Tunaman
Messages: 1190
Registered: January 2005
Karma: 2
General (1 Star)
hehe, he gave you the code that will make it work as well. ^^

http://img694.imageshack.us/img694/9055/tunamanlmao.png
Re: C++ Help request [message #420945 is a reply to message #420409] Fri, 26 February 2010 10:13 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Thank you JNZ !! : Big Ups Satisfied

I will have a look at it.


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Re: C++ Help request [message #420969 is a reply to message #420409] Fri, 26 February 2010 13:02 Go to previous messageGo to next message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Why is it not working Huh ?

Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png

[Updated on: Fri, 26 February 2010 17:27]

Report message to a moderator

Re: C++ Help request [message #421003 is a reply to message #420409] Fri, 26 February 2010 17:32 Go to previous messageGo to next message
Tunaman
Messages: 1190
Registered: January 2005
Karma: 2
General (1 Star)
void HealthInfoItemClass::Render()
{
	if ((!Enabled) && (!Enabled2)) return;

	GameObject *obj = Get_Vehicle_Return((GameObject *)(*TheStar)->obj);
	float health = Commands->Get_Health(obj);
	float shield = Commands->Get_Shield_Strength(obj);
	unsigned int current_time = *SyncTime;

	unsigned int color = HealthInfoColor;
	Render2DText->Reset();
	RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
	r->Top = TextPosition.Y;
	r->Left = TextPosition.X;
	r->Bottom = TextPosition.Y;
	r->Right = TextPosition.X;
	char temp[64];
        if(current_time > StopTime)
	{
		HealthVisible = !HealthVisible;
		StopTime = current_time + 5000;
	}
        if(HealthVisible)
        {
		sprintf(temp,"+%03d",(unsigned int)(health + 0.5f));
	}
	else
	{
		sprintf(temp, "*_%03d", (unsigned int)(shield + 0.5f));
	}
	Render2DText->Draw_Text(temp, color);
	Render2DText->Render();
};


You should try replacing your render code with that one. I just changed it in notepad, so hopefully it works. Make sure the variables HealthVisible(bool) and StopTime(unsigned int) are declared at the top. ^^


http://img694.imageshack.us/img694/9055/tunamanlmao.png
Re: C++ Help request [message #421004 is a reply to message #420409] Fri, 26 February 2010 17:48 Go to previous message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma: 0
Recruit
Thank you Tunaman and JNZ! Big Ups

Tunaman's code did what I wanted to create. The final code will soon be available when I release the complete HUD.


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
Previous Topic: Help installing LUA 5?
Next Topic: C&C Volcano
Goto Forum:
  


Current Time: Sun Dec 22 07:11:51 MST 2024

Total time taken to generate the page: 0.00821 seconds