Skip to content

Instantly share code, notes, and snippets.

Created July 17, 2016 23:03
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/f9cf38cdc5baf5d144daaea3c52c839c to your computer and use it in GitHub Desktop.
Save anonymous/f9cf38cdc5baf5d144daaea3c52c839c 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"
import int GUI_GetActiveScreen() from "client_gui";
string@ MouseOverText;
bool __ShowHealthInfo = true;
bool ShowNpcName = false;
uint FullSecond = 0;
void InitCritterInfo() // import
{
CritterInfoOverMouse MouseMove;
GUI_AddScreenElement( CLIENT_MAIN_SCREEN_GAME )
.CallbackMouseMove( MouseMove );
CritterInfoOnHead Draw;
GUI_AddScreenElement( CLIENT_MAIN_SCREEN_GAME )
.CallbackDraw( Draw );
}
bool ShowHealthInfo() // import
{
return __ShowHealthInfo = !__ShowHealthInfo;
}
bool ShowPlayerNames() // import
{
return __ShowPlayerNames;
}
bool ShowNpcNames() // import
{
return ShowNpcName = !ShowNpcName;
}
bool CompareCritters(CritterCl@[]@ old, CritterCl@[]@ new) // unused
{
if(old.length() == 0)
return false;
if (old.length() == new.length())
return false;
for (uint i = 0; i < old.length(); i++)
{
if(old[i].Id == new[i].Id && old[i].Stat[ST_CURRENT_HP] == new[i].Stat[ST_CURRENT_HP])
continue;
else
return false;
}
return true;
}
string@ GetMouseOverText() // import
{
return MouseOverText;
}
class CritterInfoOverMouse : IGUIElementCallbackMouseMove {
void OnMouseMove(int x, int y)
{
if( GUI_GetActiveScreen() != CLIENT_MAIN_SCREEN_GAME )
return;
CritterCl@ chosen = GetChosen();
CritterCl@ critter = GetMonitorCritter(x, y);
if(!valid(chosen) || !valid(critter)) {
@MouseOverText = null;
return;
}
string str;
// works only if nothing is shown onhead
if(critter.IsNpc() && !ShowNpcName || critter.IsPlayer() && !__ShowPlayerNames)
{
uint color = critter.IsChosen() ? COLOR_WHITE : COLOR_LGRAY;
if(critter.IsNpc())
color = COLOR_YELLOW;
// 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;
// }
str += "|"+color + " " + critter.Name;
}
// works all the time
// health
bool awareness = chosen.Perk[PE_AWARENESS] != 0;
if( !__ShowHealthInfo || critter.IsDead() ) {
str += GetHealthStr(critter, awareness);
}
// gear
if( awareness ) {
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;
}
}
CritterCl@[] oldcritters;
class CritterInfoOnHead : IGUIElementCallbackDraw {
void OnDraw(int id) {
// __FullSecond increases naturally
if( !(__FullSecond > FullSecond) )
return;
CritterCl@ chosen = GetChosen();
if(!valid(chosen))
return;
bool awareness = chosen.Perk[PE_AWARENESS] != 0;
CritterCl@[] critters;
GetCritters(0, FIND_ALL, critters);
if( CompareCritters( oldcritters, critters ) )
return;
for (uint i = 0; i < critters.length(); i++)
{
CritterCl@ critter = critters[i];
if(!valid(critter))
continue;
if ( critter.IsPlayer() ) {
if(critter.Name == ADMIN_NAME ) {
critter.NameOnHead = "|" + COLOR_RED + " " + "[GM]\n";
critter.NameOnHead += __ShowPlayerNames ? "|" + COLOR_CRITTER_NAME + " " + critter.Name : "";
}
else
critter.NameOnHead = __ShowPlayerNames ? "|" + COLOR_CRITTER_NAME + " " + critter.Name : "";
if( critter.Param[INCOGNITO] != 0 ) //name is visible only if critter is not in incognito mode
critter.NameOnHead = "";
}
// need retreive the name from GAME TEXT...
if ( critter.IsNpc() ) {
critter.NameOnHead = ShowNpcName ? "|" + COLOR_CRITTER_NAME + " " + GetMsgStr( TEXTMSG_DLG, STR_NPC_PROTO_NAME(critter.Pid) ) : "";
}
if(__ShowHealthInfo) {
if( !critter.IsDead() )
critter.NameOnHead += GetHealthStr(critter, awareness);
else
critter.Name = "";
}
}
oldcritters = critters;
FullSecond = __FullSecond;
}
}
string@ GetHealthStr(CritterCl@ critter, bool awareness)
{
string str;
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 ) );
}
return @str;
}
#endif
import void InitCritterInfo() from "client_critter_info";
bool start()
{
InitCritterInfo();
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 );
@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);
}
}
else if( layer == 100 && __GmapActive ) {}
}
import bool ShowHealthInfo() from "client_critter_info";
import bool ShowPlayerNames() from "client_critter_info";
import bool ShowNpcNames() from "client_critter_info";
bool key_down(uint8 key, string& keyText)
{
if(key == DIK_F6) {
Message("ShowPlayerNames: " + (ShowPlayerNames() ? "on" : "off"));
}
if(key == DIK_F7) {
Message("ShowNpcNames: " + (ShowNpcNames() ? "on" : "off"));
}
if(key == DIK_F9) {
Message("ShowHealthInfo: " + (ShowHealthInfo() ? "on" : "off"));
}
}
#ifdef __CLIENT
__ShowPlayerNames = true;
__ShowNpcNames = true;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment