FOnline Development > General Discussion
"Ready Made" Solutions - Scripts, tricks, tips, and other useful info.
Berko:
For "OnHead" information you can do something like that :
this only add information on head and nothing more so it need modification to be used like awareness if you use it, etc
maybe it can be optimized (like change something only when needed)
comment is here to help with this example
The script file, i named it "gui_client_onhead.fos"
--- Code: ---#include "_defines.fos"
#include "_client_defines.fos"
#include "_colors.fos"
import int GUI_GetActiveMainScreen() from "client_gui";
#define GUI_ONHEAD_NB_MOD 4 //Number of mod that we can switch
#define GUI_ONHEAD_EMPTY 0 //Show nothing
#define GUI_ONHEAD_NAME 1 //Show the name
#define GUI_ONHEAD_DETAILS 2 //Show the name and HP
#define GUI_ONHEAD_DEBUG 3 //Show the name, id and pid
//global variable to store the current mod
uint GUI_OnHead_Mod;
//Initialize all that we need to initialize
void Init_GUI_OnHead()
{
GUI_OnHead_Mod = GUI_ONHEAD_EMPTY;
}
//Draw function where we change informations on head
void Draw_GUI_OnHead()
{
if( GUI_GetActiveMainScreen() != CLIENT_MAIN_SCREEN_GAME )
return;
CritterCl@ cr = GetChosen();
CritterCl@[] crs;
GetCritters( 0, FIND_ALL, crs );
switch(GUI_OnHead_Mod)
{
case GUI_ONHEAD_EMPTY:
for(uint i = 0, imax = crs.length(); i < imax; i ++)
{
crs[i].NameOnHead = "";
}
__ShowPlayerNames = false;
break;
case GUI_ONHEAD_NAME:
for(uint i = 0, imax = crs.length(); i < imax; i ++)
{
crs[i].NameOnHead = "";
}
__ShowPlayerNames = true;
break;
case GUI_ONHEAD_DETAILS:
{
int color_b = 0;
int color_g = 0;
int color_r = 0;
for(uint i = 0, imax = crs.length(); i < imax; i ++)
{
color_g = (255*crs[i].Param[ST_CURRENT_HP])/crs[i].Param[ST_MAX_LIFE];
if(color_g < 0)
color_g = 0;
color_r = 255 - color_g;
crs[i].NameOnHead = crs[i].Name + "\n|" + COLOR_RGB(color_r, color_g, color_b) + " " + crs[i].Param[ST_CURRENT_HP] + "/" + crs[i].Param[ST_MAX_LIFE];
}
__ShowPlayerNames = true;
break;
}
case GUI_ONHEAD_DEBUG:
for(uint i = 0, imax = crs.length(); i < imax; i ++)
{
crs[i].NameOnHead = crs[i].Name + "\n|" + COLOR_CONTOUR_YELLOW + " Id : " + crs[i].Id + "\nPid : " + crs[i].Pid;
}
__ShowPlayerNames = true;
break;
default :
GUI_OnHead_Mod = GUI_ONHEAD_EMPTY;
break;
}
}
//Called when we push F6
void Change_GUI_OnHead()
{
GUI_OnHead_Mod = (GUI_OnHead_Mod + 1) % GUI_ONHEAD_NB_MOD;
}
//Called when we push F7
void ShowNPC_GUI_OnHead()
{
__ShowNpcNames = !__ShowNpcNames;
}
--- End code ---
Add the module in script.cfg
In client_main.fos import functions
--- Code: ---import void Init_GUI_OnHead() from "client_gui_onhead";
import void Draw_GUI_OnHead() from "client_gui_onhead";
import void Change_GUI_OnHead() from "client_gui_onhead";
import void ShowNPC_GUI_OnHead() from "client_gui_onhead";
--- End code ---
and call these function where they need to be called
--- Code: ---...
bool start()
{
...
Init_GUI_OnHead();
...
}
...
void render_iface( uint layer )
{
...
if( layer == 3 )
{
...
Draw_GUI_OnHead();
...
}
...
}
...
bool key_down( uint8 key )
{
...
if(key == DIK_F6)
{
Change_GUI_OnHead();
return true;
}
if(key == DIK_F7)
{
ShowNPC_GUI_OnHead();
return true;
}
...
}
...
--- End code ---
When you push F6 it change the mode of informations on head. F7 only show or not the same informations for NPC. "Details" mode shows HP information only with gradient color from red to green. When it show additional information, the name keep the original color (color set in namecolorizing or NameColor).
Sorry for my English and I hope this example can be useful.
codave:
GUI Timeouts:
One of the many familiar features that the SDK is missing, and is great to have.
First, make a new script and name it "timeouts.fos", and paste in the following:
--- Code: ---//On-Screen Timeouts
//By: codave
#include "_macros.fos"
#include "_client_defines.fos"
#include "_colors.fos"
#include "_msgstr.fos"
#include "_defines.fos"
import int GUI_GetActiveMainScreen() from "client_gui";
import int GUI_GetActiveScreen() from "client_gui";
void InitTimeouts()
{
if( GUI_GetActiveMainScreen() != CLIENT_MAIN_SCREEN_GAME )
return;
CritterCl@ chosen = GetChosen();
if( not valid( chosen ) )
return;
int Y=30;
int X=10;
if( chosen.Timeout[ TO_SK_LOCKPICK ] > 0 )
{
DrawText("Lockpick: "+chosen.Timeout[ TO_SK_LOCKPICK ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_SK_FIRST_AID ] > 0 )
{
DrawText("First Aid: "+chosen.Timeout[ TO_SK_FIRST_AID ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_SK_DOCTOR ] > 0 )
{
DrawText("Doctor: "+chosen.Timeout[ TO_SK_DOCTOR ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_SK_REPAIR ] > 0 )
{
DrawText("Repair: "+chosen.Timeout[ TO_SK_REPAIR ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_BATTLE ] > 0 && chosen.Timeout[ TO_BATTLE ] < 10000 )
{
DrawText("Battle: "+chosen.Timeout[ TO_BATTLE ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_REPLICATION ] > 0 )
{
DrawText("Respawn Time: "+chosen.Timeout[ TO_REPLICATION ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
if( chosen.Timeout[ TO_SK_STEAL ] > 0 )
{
DrawText("Steal: "+chosen.Timeout[ TO_SK_STEAL ] / 10, X, Y-0, 500, 100, COLOR_GREEN, FONT_FALLOUT, FT_BORDERED );
Y=Y+15;
}
}
--- End code ---
Save it in the /server/scripts folder.
Next, open up client_main.fos, and add the script we just saved to the namespace at the top, like so:
--- Code: ---// Author: cvet, Atom
// Client main script
// Compile using fo_client.dll
#include "_client_defines.fos"
#include "_macros.fos"
#include "_msgstr.fos"
#include "sprite.fos"
#include "_colors.fos"
#include "_animation.fos"
#include "awareness.fos"
#include "timeouts.fos"
--- End code ---
Go down a bit further into the script, and find GUI_Init();, and add "InitTimeouts();, like this:
--- Code: ---GUI_Init();
InitNameColorizing();
InitIgnoreList();
// InitTestScreen();
InitRadioScreen();
InitChosenTabs();
InitAwarenessHead();
InitTimeouts();
#ifdef PLAYERS_3D
Init3DChaRegScreen();
#endif
--- End code ---
Scroll down further, and find "void render_iface", and add the same Init.
--- Code: ---if( layer == 3 )
{
InitTimeouts();
DrawChosenTabs();
GUI_Render();
}
--- End code ---
After everything is saved, fire the server up and test it. You can easily make color/x, y, and order adjustments on the fly by clicking "Reload Client Scripts" on the Server, and your changes will show up in game after a few seconds.
Enjoy...
Gob:
After using Berko's code I'm getting this:
--- Code: ---Script::BindImportedFunctions - Fail to bind imported functions, module<client_main>, error<-19>.
--- End code ---
I know it has something to do with the imports :/ but what?
SEGA_RUS:
--- Quote from: Gob on August 26, 2012, 05:57:31 pm ---
--- Code: ---Script::BindImportedFunctions - Fail to bind imported functions, module<client_main>, error<-19>.
--- End code ---
I know it has something to do with the imports :/ but what?
--- End quote ---
it means, that something does wrong when server trying to execute one of important function from awareness.fos or/and timeouts.fos before compiling
--- Code: ---#include "awareness.fos"
#include "timeouts.fos"
--- End code ---
check did u put this code in client_main
check did u added script name(s) to scripts.cfg
check did u copy all 2 files with right filenames ;D ;D
Moe Lester:
I followed above Codave's Awareness tutorial but something went wrong, it is how looks error during server start:
--- Code: ---[29:433] Script system initialization complete.
[29:539] Loading language packs...
[32:205] Loading language packs complete, loaded<2> packs.
[32:252] Reload client scripts...
[35:691] Script message: client_main : Error : Unexpected end of file : 14975, 1.
[35:769] Script message: client_main : Info : While parsing statement block : 12706, 1.
[35:857] Script::LoadScript - Unable to Build module<client_main>, result<-1>.
[35:910] FOServer::ReloadClientScripts - Unable to load client script<client_main>.
[38:278] Reload client scripts complete.
[38:417] AI manager initialization...
[38:510] Find bags...
[38:797] Loaded<156> bags.
[38:844] AI manager initialization complete.
--- End code ---
Some conclusions?
I had similiar problem with adding GUI Timeouts. Looks like Im making same fault in some step.
(Im using tla sdk not 2238)
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version