FOnline Development > General Discussion
"Ready Made" Solutions - Scripts, tricks, tips, and other useful info.
codave:
As suggested, this topic is for "Ready Made" works that people wish to share with the community, or other tips, tricks, and hints.
Also, check out these:
http://forum.newfmc.pl/index.php?board=11.0
http://fonline.ru/forum/forumdisplay.php?s=79df0d600c79ad37bf89288db19870f9&f=5
(English speakers, get a Translator extension for your browser.)
Awareness:
HP/HP, Injured (With HP colorizing based on % of max HP)
Hand Slot Item/Unarmed
Armor/No Armor
Pretty close to 2238 Awareness, since I like the way it was implemented. Some of the colors and percentages for HP may be off, but you can change them to suit your wants or needs.
First make a new script in the Server/Scripts folder, and name it "Awareness.fos". Open it up, and paste in the following, and save it:
--- Code: ---//Awareness On Mouse-Over
//Author: codave
#include "_macros.fos"
#include "_client_defines.fos"
#include "_colors.fos"
#include "_msgstr.fos"
void InitAwarenessHead() // Export
{
CritterCl@ cr = GetMonitorCritter(__MouseX, __MouseY);
if( !valid(cr) )
return;
ItemCl@ item = cr.GetItem( 0, SLOT_HAND1 );
ItemCl@ itemArmor = cr.GetItem( 0, SLOT_ARMOR );
int hp_amo = cr.Stat[ ST_CURRENT_HP ];
if(valid(cr) )
{
int Y=__MouseY;
int hp_proc = cr.Stat[ ST_CURRENT_HP ] * 100 / cr.Stat[ ST_MAX_LIFE ];
if(_CritIsInjured(cr))
{
if (hp_proc < 1)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE]+", Injured", __MouseX, Y-60, 500, 100, COLOR_LGRAY, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc < 25)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE]+", Injured", __MouseX, Y-60, 500, 100, COLOR_RED, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc < 50)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE]+", Injured", __MouseX, Y-60, 500, 100, COLOR_DRED, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc <= 75)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE]+", Injured", __MouseX, Y-60, 500, 100, COLOR_DGREEN, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc <= 100)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE]+", Injured", __MouseX, Y-60, 500, 100, 0x0, FONT_FALLOUT, FT_BORDERED);
Y=Y+13;
}
else
{
if (hp_proc < 1)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE], __MouseX, Y-60, 500, 100, COLOR_LGRAY, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc < 25)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE], __MouseX, Y-60, 500, 100, COLOR_RED, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc < 50)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE], __MouseX, Y-60, 500, 100, COLOR_DRED, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc <= 75)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE], __MouseX, Y-60, 500, 100, COLOR_DGREEN, FONT_FALLOUT, FT_BORDERED);
else if (hp_proc <= 100)
DrawText (cr.Stat[ST_CURRENT_HP]+"/"+cr.Stat[ST_MAX_LIFE], __MouseX, Y-60, 500, 100, 0x0, FONT_FALLOUT, FT_BORDERED);
Y=Y+13;
}
if(valid(itemArmor))
{
DrawText (""+GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(itemArmor)), __MouseX, Y-60, 500, 100, 0x0, FONT_FALLOUT, FT_BORDERED);
Y=Y+13;
}
else
{
DrawText ("No Armor", __MouseX, Y-60, 500, 100, COLOR_LGRAY, FONT_FALLOUT, FT_BORDERED);
Y=Y+13;
}
if(valid(item))
{
DrawText (""+GetMsgStr(TEXTMSG_ITEM, STR_ITEM_INFO(item)), __MouseX, Y-60, 500, 100, 0x0, FONT_FALLOUT, FT_BORDERED);
}
else
{
DrawText ("Unarmed", __MouseX, Y-60, 500, 100, COLOR_LGRAY, FONT_FALLOUT, FT_BORDERED);
}
}
}
--- End code ---
Next, find "client_main.fos". We need to include the Awareness script we just created. In the headspace, enter "#include "awareness.fos", so it looks like this:
--- Code: ---#include "_client_defines.fos"
#include "_macros.fos"
#include "_msgstr.fos"
#include "sprite.fos"
#include "_colors.fos"
#include "_animation.fos"
#include "awareness.fos"
--- End code ---
Scroll down a bit further and find "GUI_Init();", and enter in "InitAwarenessHead();" so it looks like this:
--- Code: ---GUI_Init();
InitNameColorizing();
InitIgnoreList();
// InitTestScreen();
InitRadioScreen();
InitChosenTabs();
InitAwarenessHead();
#ifdef PLAYERS_3D
Init3DChaRegScreen();
#endif
--- End code ---
Scroll down a little further and find "Void render_iface( unit layer)". Paste in the following, so it looks like this:
--- Code: ---void render_iface( uint layer )
{
if(layer == 1 )
{
CritterCl@ chosen = GetChosen();
if(valid(chosen) && chosen.Perk[PE_AWARENESS] != 0)
{
InitAwarenessHead();
}
}
if( layer == 3 )
{
DrawChosenTabs();
GUI_Render();
}
--- End code ---
The color codes can be found in _colors.fos, if you want to change them.
A big thanks to lothar70 and Wipe for some help with this.
Ganado:
Thank you for this. :)
Grey:
Really nice :) Thank you
Wipe:
My first guess was that using 4x DrawText() in a row instead of one (cos "\n" [new line] actually works in there) may cause slowdowns - DrawText() isn't "cheap" function, as we all know. But after closer look:
--- Quote from: codave on June 22, 2012, 01:41:54 am ---
--- Code: ---CritterCl@ cr = GetMonitorCritter(__MouseX, __MouseY);
ItemCl@ item = cr.GetItem( 0, SLOT_HAND1 );
ItemCl@ itemArmor = cr.GetItem( 0, SLOT_ARMOR );
int hp_amo = cr.Stat[ ST_CURRENT_HP ];
--- End code ---
--- End quote ---
I really advice to put something like this after 1st line
--- Code: ---if( !valid(cr) ) return;
--- End code ---
Without it, client tries to get cr Items at the current mouse xy - problem is that cr can be null, and yet you are trying to get info from it - without checking if you actually have a Critter pointer. If you don't, 2nd+ lines creates an error, which client tries to log into file (and as you fiddle with scripts, i guess that you have logging to FOnline.log enabled) on every frame render~ That's no good, everything what's called inside render_iface() function should be guarded with sanity checks, like any other (reserved) functions which are called by client frequently.
--- I hope you get what i mean, i suck in explaining things...
codave:
I understand completely. Thank you, that cleared the problem right up. It's now smooth as hell.
;D
I need to get better at this scripting thing.
Navigation
[0] Message Index
[#] Next page
Go to full version