Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2016 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fe2dbba76fc0e35f3ad63370a22c9c8b to your computer and use it in GitHub Desktop.
Save anonymous/fe2dbba76fc0e35f3ad63370a22c9c8b to your computer and use it in GitHub Desktop.
#ifdef __CLIENT
#include "_client_defines.fos"
#include "client_gui_h.fos"
#include "_macros.fos"
#include "_msgstr.fos"
#define ADMIN_NAME "anton"
#define _IsAdmin # (name) ( name == ADMIN_NAME )
import int GUI_GetActiveScreen() from "client_gui";
string@ MouseOverText;
bool ShowHealthInfo = true;
bool ShowNpcNames = false;
void InitCritterInfo() // import
{
CritterInfoOverMouse MouseMove;
GUI_AddScreenElement( CLIENT_MAIN_SCREEN_GAME )
.CallbackMouseMove( MouseMove );
}
bool ToggleHealthInfo() // import
{
return ShowHealthInfo = !ShowHealthInfo;
}
bool ToggleNpcNames() // import
{
return ShowNpcNames = !ShowNpcNames;
}
bool IsChosenAware()
{
CritterCl@ chosen = GetChosen();
if( !valid(chosen) )
return false;
return chosen.Perk[PE_AWARENESS] != 0;
}
void UpdateInfoOnHeads()
{ // import
CritterCl@[] critters;
GetCritters(0, FIND_ALL, critters);
if( !valid(critters) )
return;
if( !(critters.length() > 0) )
return;
for ( uint i = 0; i < critters.length(); i++ )
{
CritterCl@ critter = critters[i];
if( !valid(critter) )
return;
GetOnHeadStr( critter, IsChosenAware() );
}
}
void UpdateInfoOnHead( CritterCl@ critter )
{ // import
GetOnHeadStr( critter, IsChosenAware() );
}
void CritterHealthActivity( CritterCl& critter, uint, int )
{ // called by Parameters behaviour change
UpdateInfoOnHead( critter );
}
void GetOnHeadStr(CritterCl@ critter, bool awareness)
{
if ( critter.IsPlayer() ) {
if( _IsAdmin( critter.Name ) ) {
critter.NameOnHead = "|" + COLOR_RED + " [GM]\n" + "|" + COLOR_CRITTER_NAME + " " + critter.Name;
}
else
critter.NameOnHead = "|" + COLOR_CRITTER_NAME + " " + critter.Name;
//if( critter.Param[INCOGNITO] != 0 ) //name is visible only if critter is not in incognito mode
// critter.NameOnHead = "";
}
if ( critter.IsNpc() ) {
critter.NameOnHead = ShowNpcNames ? "|" + COLOR_YELLOW + " " + GetMsgStr( TEXTMSG_DLG, STR_NPC_PROTO_NAME(critter.Pid) ) : "";
}
if( ShowHealthInfo ) {
if( critter.IsDead() ) {
return;
}
critter.NameOnHead += "\n";
uint color;
string hpText;
int hpPercentage = critter.Stat[ST_CURRENT_HP] * 100 / critter.Stat[ST_MAX_LIFE];
if( hpPercentage < 34 ) {
color = COLOR_RED;
hpText = "\u25a0\u25a1\u25a1\u25a1";
}
else if( hpPercentage < 67 ) {
color = COLOR_ORANGE;
hpText = "\u25a0\u25a0\u25a1\u25a1";
}
else if( hpPercentage < 100 ) {
color = COLOR_DGREEN;
hpText = "\u25a0\u25a0\u25a0\u25a1";
}
else {
color = COLOR_GREEN;
hpText = "\u25a0\u25a0\u25a0\u25a0";
}
critter.NameOnHead += "|" + color + " " + hpText;
}
return;
}
////////////////////////////////////////////////////////////////////////////////
// MOUSE
string@ GetMouseOverText() // import
{
return MouseOverText;
}
class CritterInfoOverMouse : IGUIElementCallbackMouseMove
{
void OnMouseMove(int x, int y)
{
if( GUI_GetActiveScreen() != CLIENT_MAIN_SCREEN_GAME )
return;
CritterCl@ critter = GetMonitorCritter(x, y);
if(!valid(critter)) {
@MouseOverText = null;
return;
}
string str;
// works only if nothing is shown onhead
if( critter.IsNpc() && !ShowNpcNames || critter.IsPlayer() && !__ShowPlayerNames ) {
uint color = 0;
if( critter.IsNpc() ) {
color = COLOR_YELLOW;
str += "|"+color + " " + GetMsgStr( TEXTMSG_DLG, STR_NPC_PROTO_NAME(critter.Pid) );
}
else {
uint color = critter.IsChosen() ? COLOR_WHITE : COLOR_LGRAY;
str += "|"+color + " " + critter.Name;
}
// if(!critter.IsChosen() && critter.Param[PVP_TEAM] != 0)
// {
// if(valid(chosen) && chosen.Param[PVP_TEAM] != 0)
// color = chosen.Param[PVP_TEAM] == critter.Param[PVP_TEAM] ? COLOR_GREEN : COLOR_RED;
// }
}
// works all the time
// health
if( !ShowHealthInfo || critter.IsDead() ) {
str += "\n";
int hp_proc = critter.Stat[ ST_CURRENT_HP ] * 100 / critter.Stat[ ST_MAX_LIFE ];
if( critter.IsDead() )
str += "|" + COLOR_GRAY + " " + GetMsgStr( TEXTMSG_GAME, STR_CRIT_LOOK_STATE( 0 ) );
else if( hp_proc < 34 )
str += "|" + COLOR_RED + " " + GetMsgStr( TEXTMSG_GAME, STR_CRIT_LOOK_STATE( 1 ) );
else if( hp_proc < 67 )
str += "|" + COLOR_ORANGE + " " + GetMsgStr( TEXTMSG_GAME, STR_CRIT_LOOK_STATE( 2 ) );
else if( hp_proc < 100 )
str += "|" + COLOR_DGREEN + " " + GetMsgStr( TEXTMSG_GAME, STR_CRIT_LOOK_STATE( 3 ) );
else {
// if awareness... here
str += "|" + COLOR_GREEN + " " + GetMsgStr( TEXTMSG_GAME, STR_CRIT_LOOK_STATE( 4 ) );
}
}
// gear
if( IsChosenAware() ) {
ItemCl@ armor = critter.GetItem(0, SLOT_ARMOR);
if(valid(armor))
if(armor.Lexems != "")
str += "\n|" + COLOR_GRAY + " " + FormatTags(GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(armor)), armor.Lexems);
else
str += "\n|" + COLOR_GRAY + " " + GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(armor));
ItemCl@ item = critter.GetItem(0, SLOT_HAND1);
if(valid(item))
if(item.Lexems != "")
str += "\n|" + COLOR_WHITE + " " + FormatTags(GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(item)), item.Lexems);
else
str += "\n|" + COLOR_WHITE + " " + GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(item));
}
@MouseOverText = str;
}
}
#endif
import void InitCritterInfo() from "client_critter_info";
bool start()
{
// Add this at end.
InitCritterInfo();
// test
SetParameterChangeBehaviour( ST_CURRENT_HP, "client_critter_info@CritterHealthActivity" );
SetParameterChangeBehaviour( ST_MAX_LIFE, "client_critter_info@CritterHealthActivity" );
return true;
}
import string @GetMouseOverText() from "client_critter_info";
string@ MouseOverText;
void render_iface( uint layer )
{
if( layer == 2 )
{
GUI_Render( true );
}
else if( layer == 3 )
{
DrawChosenTabs();
GUI_Render( false );
// Add this ...
@MouseOverText = @GetMouseOverText();
if(valid(MouseOverText) && GUI_GetActiveScreen() == CLIENT_MAIN_SCREEN_GAME )
{
string@[] lines = split(MouseOverText, "\n");
DrawText(MouseOverText, __MouseX + 10, __MouseY - 10 * lines.length(), 200, lines.length() * 10, COLOR_WHITE, FONT_FALLOUT, FT_BORDERED);
}
}
}
import bool ToggleHealthInfo() from "client_critter_info";
import bool ToggleNpcNames() from "client_critter_info";
import void UpdateInfoOnHeads() from "client_critter_info";
bool key_down( uint8 key, string& keyText )
{
// add this to control on head informations
// if(key == DIK_F6) {
// Message("ShowPlayerNames: " + (TogglePlayerNames() ? "on" : "off"));
// CrittersUpdate();
// }
if(key == DIK_F7) {
Message("ShowNpcNames: " + (ToggleNpcNames() ? "on" : "off"));
UpdateInfoOnHeads();
}
if(key == DIK_F9) {
Message("ShowHealthInfo: " + (ToggleHealthInfo() ? "on" : "off"));
UpdateInfoOnHeads();
}
}
import void UpdateInfoOnHead( CritterCl@ critter ) from "client_critter_info";
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Called on something critter in/out game.
void critter_in( CritterCl& cr )
{
// at beginning of the function!
// we don't use __ShowNpcNames
// erase the name so it's not shown when critters dies.
if (cr.IsNpc())
if ( cr.Name.length() > 0 )
cr.Name = "";
UpdateInfoOnHead(cr);
}
void InitializeGame() // Export
{
#ifdef __CLIENT
__ShowPlayerNames = true;
__ShowNpcNames = true;
#endif
}
@ client module client_critter_info
Copy link

ghost commented May 18, 2022

Ooof, 6 years ago... I'm getting old :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment