TextPrompt Entity
by -=( Slyprid )=-
Slipbinary
TextPrompt Entity - With this entity you are able to add small
text bits to your game when a player steps within certain areas of your world.
Useful for bringing up storyline or player conditions to add to the setting of
the room. If you have any questions feel free to
email me at slyprid@msn.com
Ok, lets begin our work on our TextPrompt Entity
First off load up your Genvs.h header. In here we will be adding the definition for our entity. Don't forget to make sure this file is also saved to your header directory for GEdit or other Genesis 3D level editors, or it won't appear in your entity list.
Around line 174 or so, you will see
| // Door #pragma GE_Type("Model.ico") typedef struct Door { #pragma GE_Published geWorld_Model *Model; geVec3d Origin; #pragma GE_Origin(Origin) } Door; |
This is the Door entity, we are going to add our code directly after this code bit.
| // TextPrompt #pragma GE_Type("Model.ico") typedef struct TextPrompt { #pragma GE_Published geWorld_Model *Model; char *TextInput; char *TextInput1; char *TextInput2; geVec3d Origin; #pragma GE_Origin(Origin) } TextPrompt; |
TextPrompt is the name of the Entity. Make sure this matches up with rest of code. |
Now what this does for us, is adds a entity to the Genesis project. This entity is named TextPrompt and has 5 properties, Model, TextInput, TextInput1, TextInput2, Origin. Ok, the stuff that is highlighted red can be changed to what ever you want, just remember that it must be consistent throughout your project.
Now we have the Entity definition in our header files for use. Now lets begin adding the code to GMain.c.
We will begin by adding a single line after the #include 's at the start of the file.
This should be similar to what you see (won't see HUD.h if this is from a fresh GTest project with no additions)
| #include
"GMain.h" #include "Quatern.h" #include "HUD.h" |
Now we add...
| extern TextPrompt *TP; |
This allows us to call the entity from anywhere in this file. You will need to change TextPrompt to match what ever you named your entity up at the top. TP is our pointer to the TextPrompt Entity.
Now around Line 48 or so, you will see
| geBoolean Client_Control(GenVSI *VSI, void *PlayerData, float Time); |
After this we will add...
| static
geBoolean TextPrompt_Trigger(GenVSI
*VSI, void *PlayerData,
void *TargetData,
void *Context,
TextPrompt *TP); static geBoolean TextPrompt_Spawn(GenVSI *VSI, void *PlayerData, void *ClassData, char *EntityName); |
These are used to declare our Trigger and Spawn for our entity.
Now our next part of code will fall under...
| geBoolean Server_Main(GenVSI *VSI, const char *LevelName) |
This is the server main sub-routine.
Now if we scroll down a couple of lines, we will see the code...
| GenVSI_SetClassSpawn(VSI, "Door", Door_Spawn, NULL); |
After this line, we are going to add our line of code
| GenVSI_SetClassSpawn(VSI, "TextPrompt", TextPrompt_Spawn, NULL); |
Once again, TextPrompt refers back to the name we gave the entity in Genvs.h
Now for the big portion of the code...
Go to the end of the file and add these lines.
| //===================================================================================== // TextPrompt_Trigger //===================================================================================== static geBoolean TextPrompt_Trigger(GenVSI *VSI, void *PlayerData, void *TargetData, void *Context, TextPrompt *TP) { GPlayer *Player, *Target, *Owner; char TInput[256]; Player = (GPlayer*)PlayerData; Target = (GPlayer*)TargetData; if (Player->State == PSTATE_Opened) return GE_TRUE; Player->State = PSTATE_Opened; Player->FrameTime = 0.0f; assert(Player->Model); Player->ViewFlags |= VIEW_TYPE_MODEL_OPEN; TP = (TextPrompt*)Player->ClassData; sprintf(TInput, "%s", TP->TextInput); GenVSI_ConsoleHeaderPrintf(VSI, Owner->ClientHandle, GE_TRUE, "%s", TInput); sprintf(TInput, "%s", TP->TextInput1); GenVSI_ConsoleHeaderPrintf(VSI, Owner->ClientHandle, GE_TRUE, "%s", TInput); sprintf(TInput, "%s", TP->TextInput2); GenVSI_ConsoleHeaderPrintf(VSI, Owner->ClientHandle, GE_TRUE, "%s", TInput); //GenVSI_PlaySound(VSI, 2, &Player->XForm.Translation); return GE_TRUE; } //===================================================================================== // TextPropmpt_Spawn //===================================================================================== static geBoolean TextPrompt_Spawn(GenVSI *VSI, void *PlayerData, void *ClassData, char *EntityName) { geWorld_Model *Model; geMotion *Motion; gePath *Path; GPlayer *Player; TextPrompt *FuncTP; geWorld *World; Player = (GPlayer*)PlayerData; Player->Control = NULL; Player->Trigger = TextPrompt_Trigger; Player->Blocked = NULL; Player->ControlIndex = 1; //Player->TriggerIndex = 2; Player->Time = 0.0f; // Grab the model FuncTP = (TextPrompt*)ClassData; Player->VPos = FuncTP->Origin; Model = FuncTP->Model; if (!Model) { GenVS_Error( "TextPrompt_Spawn: No model for entity:%s.\n",EntityName); return GE_FALSE; } World = GenVSI_GetWorld(VSI); //geWorld_GetModelRotationalCenter(World, Model, &Player->VPos); // Set the default xform to time 0 of the animation Motion = geWorld_ModelGetMotion(Model); if (!Motion) { GenVS_Error( "TextPrompt_Spawn: No motion for model ('%s').\n",EntityName); return GE_FALSE; } Path = geMotion_GetPath(Motion, 0); if (!Path) { GenVS_Error( "TextPrompt_Spawn: No path for model motion ('%s').\n",EntityName); return GE_FALSE; } // Put model at default position gePath_Sample(Path, 0.0f, &Player->XForm); Player->ViewFlags = VIEW_TYPE_MODEL | VIEW_TYPE_TOUCH; Player->ViewIndex = GenVSI_ModelToViewIndex(VSI, Model); // Special index // Register the model with the player if all is ok // NOTE - If somthing went bad, then this should not be called!!! GenVSI_RegisterPlayerModel(VSI, Player, Model); return GE_TRUE; } |
Once again, remember to keep all the red correlating to what you have above in the rest of the code.
Well that's it for the code part, now just create a map, add your entity, remember to add a model to it, and then go to your Entity properties list and add the text you want to the 3 lines you can display. Also remember that each line can only contain a maximum of 256 characters.
Well have fun, and if you have any comments or questions, send me a post on the Genesis3D forum, or contact me at slyprid@msn.com
Thanks
-=( Slyprid )=-