Post tutorial RSS Adding Client-Side Console Commands to Shogo

This tutorial will explain how to add client-side console command variables to Shogo

Posted by on - Advanced Client Side Coding

Originally posted here: Planetshogo.com

Created by: Jeff Ploetner aka Bunghole.

Mirrored here for archival purposes

Adding Client-Side Console Commands to Shogo

Version 1.0
March 28th, 1999

by Jeff Ploetner aka Bunghole.
bung@planetshogo.com

This tutorial will explain how to add client-side console command variables to Shogo. I will give you 3 of mine I've added to Tow Arena so you get the idea.
Here is what it will look like when I'm done:

console

RiotClientShell.cpp, Line ~850-~900
DDWORD CRiotClientShell::OnEngineInitialized(struct RMode_t *pMode, DGUID *pAppGuid)
{
// ...

m_MoveMgr->Init(pClientDE);

pClientDE->RegisterConsoleProgram("LeakFile", LeakFileFn);
pClientDE->RegisterConsoleProgram("Connect", ConnectFn);
pClientDE->RegisterConsoleProgram("FragSelf", FragSelfFn);
pClientDE->RegisterConsoleProgram("Record", RecordFn);
pClientDE->RegisterConsoleProgram("PlayDemo", PlayDemoFn);
pClientDE->RegisterConsoleProgram("InitSound", InitSoundFn);
//JSP add console variables...
pClientDE->RegisterConsoleProgram("Help", HelpFn);
pClientDE->RegisterConsoleProgram("FlashyColors", FlashyColorsFn);
pClientDE->RegisterConsoleProgram("MegaGibs", MegaGibsFn);
///

//...
}

Here you are registering new console variables. The text in the quotation marks is the text that, if typed in to the console, will execute the second paremeter, which is a function (notice that there are no parenthesis). Ex. If I type "help" in the console, it will execute the HelpFn(). The text is not case sensitive. Let's go look at the HelpFn()

I added these after the other function handlers...
RiotClientShell.cpp, Line ~200

void HelpFn(int argc, char **argv)
{
g_pRiotClientShell->GetClientDE()->CPrint("/--------------------------\\");
g_pRiotClientShell->GetClientDE()->CPrint("|Tow Arena Console Commands|");
g_pRiotClientShell->GetClientDE()->CPrint("\\--------------------------/");
g_pRiotClientShell->GetClientDE()->CPrint("FlashyColors (1/0) - Enables/Disables the flashy colors.");
g_pRiotClientShell->GetClientDE()->CPrint("MegaGibs (1/0) - Enables/Disables the megagibs.");
}

Here I just made it print out text for my other console commands. This is a good thing to do, and I think all mods should have a standard "help" function to do this. Let's look at FlashyColors and MegaGibs.

void FlashyColorsFn(int argc, char **argv)
{
if (argc < 1)
{
g_pRiotClientShell->GetClientDE()->CPrint("FlashyColors = %d",g_pRiotClientShell->FlashyColors);
}

if (argc == 1)
{
if(!strcmp(argv[0],"0"))
{
g_pRiotClientShell->FlashyColors=DFALSE;
g_pRiotClientShell->GetClientDE()->CPrint("FlashyColors disabled...=%d",g_pRiotClientShell->FlashyColors);
}

if(!strcmp(argv[0],"1"))
{
g_pRiotClientShell->FlashyColors=DTRUE;
g_pRiotClientShell->GetClientDE()->CPrint("FlashyColors enabled...=%d",g_pRiotClientShell->FlashyColors);
}
}
}

Here I'm just setting some variables to true or false...

Notice the (int argc, char **argv) ? In case you've never used these before (I hadn't), it works like this:
It's like a 'main' routine. 'argc' contains an integer with the number of parameters, while argv is an array of char pointers.
For example, if you typed this in the console:
MegaGibs 1 hello 54
You would get:
argc = 3
argv[0] = "1"
argv[1] = "hello"
argv[2] = "54"

void MegaGibsFn(int argc, char **argv)
{
if (argc < 1)
{
g_pRiotClientShell->GetClientDE()->CPrint("MegaGibs = %d",g_pRiotClientShell->MegaGibs);
}

if (argc == 1)
{
if(!strcmp(argv[0],"0"))
{
g_pRiotClientShell->MegaGibs=DFALSE;
g_pRiotClientShell->GetClientDE()->CPrint("MegaGibs disabled...=%d",g_pRiotClientShell->MegaGibs);
}

if(!strcmp(argv[0],"1"))
{
g_pRiotClientShell->MegaGibs=DTRUE;
g_pRiotClientShell->GetClientDE()->CPrint("MegaGibs enabled...=%d",g_pRiotClientShell->MegaGibs);
}
}
}

Same thing here...

So, there you have it...Just look over what I did up there with the FlashyColorsFn() and the MegaGibsFn(), and you can modify it to fit your mod. :) (as long as I didn't screw up that is...if I did, please correct me, :)

BTW, Geist just informed me of something that I did not know (but you probably did):

Suppose you have strcmp(s1,s2)
if s1<s2, it returns -1
if s1=s2, it returns 0
if s1>s2, it returns 1

That's why I had to do the ! in: if(!strcmp(argv[0],"0"))
I thought that if the strings were the same, it would return a true, but now I know. :)
Thanks Geist!

That's all folks.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Tutorial
Tags
level, shogo
Browse
Tutorials
Share
Related Games
Shogo: Mobile Armor Division
Shogo: Mobile Armor Division First Person Shooter
Related Engines
LithTech
LithTech Commercial
Related Groups
Interplay Entertainment
Interplay Entertainment Developer & Publisher
Monolith Productions
Monolith Productions Developer & Publisher