Jump to content

Home

Lua Scripting For The Client Side


ensiform

Recommended Posts

Python would be a lot more work. Though, for true, full, and very robust GM support it can also be a pain, especially those with low experience and no C++ knowledge.

 

To even initialize the GM stuff I call this entire block:

 

	void CG_InitGM(void) {
	CG_Printf("------- Initializing Game Monkey Script Engine -------\n");
	// Set machine callbacks
	m_scriptEngine = new gmMachine;
	m_scriptEngine->SetDebugMode(true);
	gmMachine::s_printCallback = gmPrintf;
	gmMachine::s_machineCallback = ScriptMachineCallback;

	gmGCRootManager::Init();

	m_scriptEngine->EnableGC(false);

	const int MEM_USAGE_MB = 2 * 1048576;
	const int MEM_USAGE_KB = 0 * 1024;
	const int HARD_MEM_USAGE = MEM_USAGE_MB + MEM_USAGE_KB;
	const int SOFT_MEM_USAGE = HARD_MEM_USAGE * 9 / 10;
	m_scriptEngine->SetDesiredByteMemoryUsageHard(HARD_MEM_USAGE);
	m_scriptEngine->SetDesiredByteMemoryUsageSoft(SOFT_MEM_USAGE);

	//////////////////////////////////////////////////////////////////////////
	CG_Printf("Hard Memory Limit: %s\n", Utils::FormatByteString(HARD_MEM_USAGE).c_str());
	CG_Printf("Soft Memory Limit: %s\n", Utils::FormatByteString(SOFT_MEM_USAGE).c_str());

	lastUpdateTime = cg.time;

	// Allocate some permanent strings for properties that will be used alot.
	g_CommandTableString = m_scriptEngine->AllocPermanantStringObject("Commands");
	g_ICCTableString = m_scriptEngine->AllocPermanantStringObject("ICC");
	g_ColorTableString = m_scriptEngine->AllocPermanantStringObject("COLOR");
	g_EventsTableString = m_scriptEngine->AllocPermanantStringObject("Events");

	// Bind libraries.
	gmBindMathLibrary(m_scriptEngine);
	gmBindVectorLib(m_scriptEngine);
	gmBindStringLib(m_scriptEngine);

	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, gmVariable(g_CommandTableString), gmVariable(m_scriptEngine->AllocTableObject()));
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, gmVariable(g_ICCTableString), gmVariable(m_scriptEngine->AllocTableObject()));
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, gmVariable(g_ColorTableString), gmVariable(m_scriptEngine->AllocTableObject()));
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, gmVariable(g_EventsTableString), gmVariable(m_scriptEngine->AllocTableObject()));

	// Add the color constants to the global table.
	gmTableObject *colorTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, gmVariable(g_ColorTableString), gmVariable(colorTable));
	colorTable->Set(m_scriptEngine, "NONE", gmVariable(CT_NONE));
	colorTable->Set(m_scriptEngine, "BLACK", gmVariable(CT_BLACK));
	colorTable->Set(m_scriptEngine, "RED", gmVariable(CT_RED));
	colorTable->Set(m_scriptEngine, "GREEN", gmVariable(CT_GREEN));
	colorTable->Set(m_scriptEngine, "BLUE", gmVariable(CT_BLUE));
	colorTable->Set(m_scriptEngine, "YELLOW", gmVariable(CT_YELLOW));
	colorTable->Set(m_scriptEngine, "MAGENTA", gmVariable(CT_MAGENTA));
	colorTable->Set(m_scriptEngine, "CYAN", gmVariable(CT_CYAN));
	colorTable->Set(m_scriptEngine, "WHITE", gmVariable(CT_WHITE));
	colorTable->Set(m_scriptEngine, "LTGREY", gmVariable(CT_LTGREY));
	colorTable->Set(m_scriptEngine, "MDGREY", gmVariable(CT_MDGREY));
	colorTable->Set(m_scriptEngine, "DKGREY", gmVariable(CT_DKGREY));
	colorTable->Set(m_scriptEngine, "DKGREY2", gmVariable(CT_DKGREY2));
	colorTable->Set(m_scriptEngine, "VLTORANGE", gmVariable(CT_VLTORANGE));
	colorTable->Set(m_scriptEngine, "LTORANGE", gmVariable(CT_LTORANGE));
	colorTable->Set(m_scriptEngine, "DKORANGE", gmVariable(CT_DKORANGE));
	colorTable->Set(m_scriptEngine, "VDKORANGE", gmVariable(CT_VDKORANGE));
	colorTable->Set(m_scriptEngine, "VLTBLUE1", gmVariable(CT_VLTBLUE1));
	colorTable->Set(m_scriptEngine, "LTBLUE1", gmVariable(18));
	colorTable->Set(m_scriptEngine, "DKBLUE1", gmVariable(19));
	colorTable->Set(m_scriptEngine, "VDKBLUE1", gmVariable(CT_VDKBLUE1));
	colorTable->Set(m_scriptEngine, "VLTBLUE2", gmVariable(CT_VLTBLUE2));
	colorTable->Set(m_scriptEngine, "LTBLUE2", gmVariable(CT_LTBLUE2));
	colorTable->Set(m_scriptEngine, "DKBLUE2", gmVariable(CT_DKBLUE2));
	colorTable->Set(m_scriptEngine, "VDKBLUE2", gmVariable(CT_VDKBLUE2));
	colorTable->Set(m_scriptEngine, "VLTBROWN", gmVariable(CT_VLTBROWN1));
	colorTable->Set(m_scriptEngine, "LTBROWN", gmVariable(CT_LTBROWN1));
	colorTable->Set(m_scriptEngine, "DKBROWN", gmVariable(CT_DKBROWN1));
	colorTable->Set(m_scriptEngine, "VDKBROWN", gmVariable(CT_VDKBROWN1));
	colorTable->Set(m_scriptEngine, "VLTGOLD", gmVariable(CT_VLTGOLD1));
	colorTable->Set(m_scriptEngine, "LTGOLD", gmVariable(CT_LTGOLD1));
	colorTable->Set(m_scriptEngine, "DKGOLD", gmVariable(CT_DKGOLD1));
	colorTable->Set(m_scriptEngine, "VDKGOLD", gmVariable(CT_VDKGOLD1));
	colorTable->Set(m_scriptEngine, "VLTPURPLE1", gmVariable(CT_VLTPURPLE1));
	colorTable->Set(m_scriptEngine, "LTPURPLE1", gmVariable(CT_LTPURPLE1));
	colorTable->Set(m_scriptEngine, "DKPURPLE1", gmVariable(CT_DKPURPLE1));
	colorTable->Set(m_scriptEngine, "VDKPURPLE1", gmVariable(CT_VDKPURPLE1));
	colorTable->Set(m_scriptEngine, "VLTPURPLE2", gmVariable(CT_VLTPURPLE2));
	colorTable->Set(m_scriptEngine, "LTPURPLE2", gmVariable(CT_LTPURPLE2));
	colorTable->Set(m_scriptEngine, "DKPURPLE2", gmVariable(CT_DKPURPLE2));
	colorTable->Set(m_scriptEngine, "VDKPURPLE2", gmVariable(CT_VDKPURPLE2));
	colorTable->Set(m_scriptEngine, "VLTPURPLE3", gmVariable(CT_VLTPURPLE3));
	colorTable->Set(m_scriptEngine, "LTPURPLE3", gmVariable(CT_LTPURPLE3));
	colorTable->Set(m_scriptEngine, "DKPURPLE3", gmVariable(CT_DKPURPLE3));
	colorTable->Set(m_scriptEngine, "VDKPURPLE3", gmVariable(CT_VDKPURPLE3));
	colorTable->Set(m_scriptEngine, "VLTRED1", gmVariable(CT_VLTRED1));
	colorTable->Set(m_scriptEngine, "LTRED1", gmVariable(CT_LTRED1));
	colorTable->Set(m_scriptEngine, "DKRED1", gmVariable(CT_DKRED1));
	colorTable->Set(m_scriptEngine, "VDKRED1", gmVariable(CT_VDKRED1));
	colorTable->Set(m_scriptEngine, "VDKRED", gmVariable(CT_VDKRED));
	colorTable->Set(m_scriptEngine, "DKRED", gmVariable(CT_DKRED));
	colorTable->Set(m_scriptEngine, "VLTAQUA", gmVariable(CT_VLTAQUA));
	colorTable->Set(m_scriptEngine, "LTAQUA", gmVariable(CT_LTAQUA));
	colorTable->Set(m_scriptEngine, "DKAQUA", gmVariable(CT_DKAQUA));
	colorTable->Set(m_scriptEngine, "VDKAQUA", gmVariable(CT_VDKAQUA));
	colorTable->Set(m_scriptEngine, "LTPINK", gmVariable(CT_LTPINK));
	colorTable->Set(m_scriptEngine, "DKPINK", gmVariable(CT_DKPINK));
	colorTable->Set(m_scriptEngine, "LTCYAN", gmVariable(57));
	colorTable->Set(m_scriptEngine, "DKCYAN", gmVariable(58));
	colorTable->Set(m_scriptEngine, "LTBLUE3", gmVariable(CT_LTBLUE3));
	colorTable->Set(m_scriptEngine, "BLUE3", gmVariable(CT_BLUE3));
	colorTable->Set(m_scriptEngine, "DKBLUE3", gmVariable(CT_DKBLUE3));
	colorTable->Set(m_scriptEngine, "HUD_GREEN", gmVariable(CT_HUD_GREEN));
	colorTable->Set(m_scriptEngine, "HUD_RED", gmVariable(CT_HUD_RED));
	colorTable->Set(m_scriptEngine, "ICON_BLUE", gmVariable(CT_ICON_BLUE));
	colorTable->Set(m_scriptEngine, "NO_AMMO_RED", gmVariable(CT_NO_AMMO_RED));
	colorTable->Set(m_scriptEngine, "HUD_ORANGE", gmVariable(CT_HUD_ORANGE));

	gmTableObject *pMaxTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "MAX", gmVariable(pMaxTable));
	pMaxTable->Set(m_scriptEngine, "CLIENTS", gmVariable(MAX_CLIENTS));
	pMaxTable->Set(m_scriptEngine, "TERRAINS", gmVariable(MAX_TERRAINS));
	pMaxTable->Set(m_scriptEngine, "LOCATIONS", gmVariable(MAX_LOCATIONS));
	pMaxTable->Set(m_scriptEngine, "MODELS", gmVariable(MAX_MODELS));
	pMaxTable->Set(m_scriptEngine, "SOUNDS", gmVariable(MAX_SOUNDS));
	pMaxTable->Set(m_scriptEngine, "ICONS", gmVariable(MAX_ICONS));
	pMaxTable->Set(m_scriptEngine, "FX", gmVariable(MAX_FX));
	pMaxTable->Set(m_scriptEngine, "G2BONES", gmVariable(MAX_G2BONES));
	pMaxTable->Set(m_scriptEngine, "SUB_BSP", gmVariable(MAX_SUB_BSP));
	pMaxTable->Set(m_scriptEngine, "AMBIENT_SETS", gmVariable(MAX_AMBIENT_SETS));
	pMaxTable->Set(m_scriptEngine, "LIGHT_STYLES", gmVariable(MAX_LIGHT_STYLES));
	pMaxTable->Set(m_scriptEngine, "CONFIGSTRINGS", gmVariable(MAX_CONFIGSTRINGS));

	gmTableObject *pKeyTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "KEYCATCH", gmVariable(pKeyTable));
	pKeyTable->Set(m_scriptEngine, "CONSOLE", gmVariable(KEYCATCH_CONSOLE));
	pKeyTable->Set(m_scriptEngine, "UI", gmVariable(KEYCATCH_UI));
	pKeyTable->Set(m_scriptEngine, "MESSAGE", gmVariable(KEYCATCH_MESSAGE));
	pKeyTable->Set(m_scriptEngine, "CGAME", gmVariable(KEYCATCH_CGAME));

	gmTableObject *pScreenTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "SCREEN", gmVariable(pScreenTable));
	pScreenTable->Set(m_scriptEngine, "WIDTH", gmVariable(SCREEN_WIDTH));
	pScreenTable->Set(m_scriptEngine, "HEIGHT", gmVariable(SCREEN_HEIGHT));

	gmTableObject *pDataTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "PD", gmVariable(pDataTable));
	pDataTable->Set(m_scriptEngine, "HEALTH", gmVariable(PD_HEALTH));
	pDataTable->Set(m_scriptEngine, "MAX_HEALTH", gmVariable(PD_MAX_HEALTH));
	pDataTable->Set(m_scriptEngine, "ARMOR", gmVariable(PD_ARMOR));
	pDataTable->Set(m_scriptEngine, "FORCE", gmVariable(PD_FORCE));
	pDataTable->Set(m_scriptEngine, "WEAPON", gmVariable(PD_WEAPON));
	pDataTable->Set(m_scriptEngine, "AMMO", gmVariable(PD_AMMO));
	pDataTable->Set(m_scriptEngine, "SABERTEXT", gmVariable(PD_SABERTEXT));
	pDataTable->Set(m_scriptEngine, "NAME", gmVariable(PD_NAME));
	pDataTable->Set(m_scriptEngine, "LOCATIONTEXT", gmVariable(PD_LOCATIONTEXT));
	pDataTable->Set(m_scriptEngine, "SIEGECLASSTEXT", gmVariable(PD_SIEGECLASSTEXT));
	pDataTable->Set(m_scriptEngine, "TEAM", gmVariable(PD_TEAM));
	pDataTable->Set(m_scriptEngine, "SPECSTATE", gmVariable(PD_SPECSTATE));
	pDataTable->Set(m_scriptEngine, "SIEGECLASS", gmVariable(PD_SIEGECLASS));
	pDataTable->Set(m_scriptEngine, "ORIGIN", gmVariable(PD_ORIGIN));
	pDataTable->Set(m_scriptEngine, "ANGLES", gmVariable(PD_ANGLES));
	pDataTable->Set(m_scriptEngine, "SNAPNUMBER", gmVariable(PD_SNAPNUMBER));
	pDataTable->Set(m_scriptEngine, "LOCALNUMBER", gmVariable(PD_LOCALNUMBER));

	gmTableObject *pTextTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "TEXT", gmVariable(pTextTable));
	pTextTable->Set(m_scriptEngine, "NORMAL", gmVariable(ITEM_TEXTSTYLE_NORMAL));
	pTextTable->Set(m_scriptEngine, "BLINK", gmVariable(ITEM_TEXTSTYLE_BLINK));
	pTextTable->Set(m_scriptEngine, "PULSE", gmVariable(ITEM_TEXTSTYLE_PULSE));
	pTextTable->Set(m_scriptEngine, "SHADOWED", gmVariable(ITEM_TEXTSTYLE_SHADOWED));
	pTextTable->Set(m_scriptEngine, "OUTLINED", gmVariable(ITEM_TEXTSTYLE_OUTLINED));
	pTextTable->Set(m_scriptEngine, "OUTLINESHADOWED", gmVariable(ITEM_TEXTSTYLE_OUTLINESHADOWED));
	pTextTable->Set(m_scriptEngine, "SHADOWEDMORE", gmVariable(ITEM_TEXTSTYLE_SHADOWEDMORE));

	gmTableObject *pFontTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "FONT", gmVariable(pFontTable));
	pFontTable->Set(m_scriptEngine, "SMALL", gmVariable(FONT_SMALL));
	pFontTable->Set(m_scriptEngine, "MEDIUM", gmVariable(FONT_MEDIUM));
	pFontTable->Set(m_scriptEngine, "LARGE", gmVariable(FONT_LARGE));
	pFontTable->Set(m_scriptEngine, "SMALL2", gmVariable(FONT_SMALL2));

	gmTableObject *pCSTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "CS", gmVariable(pCSTable));
	pCSTable->Set(m_scriptEngine, "SERVERINFO", gmVariable(CS_SERVERINFO));
	pCSTable->Set(m_scriptEngine, "SYSTEMINFO", gmVariable(CS_SYSTEMINFO));
	pCSTable->Set(m_scriptEngine, "MUSIC", gmVariable(CS_MUSIC));
	pCSTable->Set(m_scriptEngine, "MESSAGE", gmVariable(CS_MESSAGE));
	pCSTable->Set(m_scriptEngine, "MOTD", gmVariable(CS_MOTD));
	pCSTable->Set(m_scriptEngine, "WARMUP", gmVariable(CS_WARMUP));
	pCSTable->Set(m_scriptEngine, "SCORES1", gmVariable(CS_SCORES1));
	pCSTable->Set(m_scriptEngine, "SCORES2", gmVariable(CS_SCORES2));
	pCSTable->Set(m_scriptEngine, "VOTE_TIME", gmVariable(CS_VOTE_TIME));
	pCSTable->Set(m_scriptEngine, "VOTE_STRING", gmVariable(CS_VOTE_STRING));
	pCSTable->Set(m_scriptEngine, "VOTE_YES", gmVariable(CS_VOTE_YES));
	pCSTable->Set(m_scriptEngine, "VOTE_NO", gmVariable(CS_VOTE_NO));
	pCSTable->Set(m_scriptEngine, "TEAMVOTE_TIME", gmVariable(CS_TEAMVOTE_TIME));
	pCSTable->Set(m_scriptEngine, "TEAMVOTE_STRING", gmVariable(CS_TEAMVOTE_STRING));
	pCSTable->Set(m_scriptEngine, "TEAMVOTE_YES", gmVariable(CS_TEAMVOTE_YES));
	pCSTable->Set(m_scriptEngine, "TEAMVOTE_NO", gmVariable(CS_TEAMVOTE_NO));
	pCSTable->Set(m_scriptEngine, "GAME_VERSION", gmVariable(CS_GAME_VERSION));
	pCSTable->Set(m_scriptEngine, "LEVEL_START_TIME", gmVariable(CS_LEVEL_START_TIME));
	pCSTable->Set(m_scriptEngine, "INTERMISSION", gmVariable(CS_INTERMISSION));
	pCSTable->Set(m_scriptEngine, "FLAGSTATUS", gmVariable(CS_FLAGSTATUS));
	pCSTable->Set(m_scriptEngine, "SHADERSTATE", gmVariable(CS_SHADERSTATE));
	pCSTable->Set(m_scriptEngine, "BOTINFO", gmVariable(CS_BOTINFO));
	pCSTable->Set(m_scriptEngine, "CLIENT_JEDIMASTER", gmVariable(CS_CLIENT_JEDIMASTER));
	pCSTable->Set(m_scriptEngine, "CLIENT_DUELWINNER", gmVariable(CS_CLIENT_DUELWINNER));
	pCSTable->Set(m_scriptEngine, "CLIENT_DUELISTS", gmVariable(CS_CLIENT_DUELISTS));
	pCSTable->Set(m_scriptEngine, "CLIENT_DUELHEALTHS", gmVariable(CS_CLIENT_DUELHEALTHS));
	pCSTable->Set(m_scriptEngine, "GLOBAL_AMBIENT_SET", gmVariable(CS_GLOBAL_AMBIENT_SET));
	pCSTable->Set(m_scriptEngine, "ENSIMODINFO", gmVariable(CS_ENSIMODINFO));
	pCSTable->Set(m_scriptEngine, "MUTANT", gmVariable(CS_MUTANT));
	pCSTable->Set(m_scriptEngine, "SVCV", gmVariable(CS_SVCV));
	pCSTable->Set(m_scriptEngine, "AMBIENT_SET", gmVariable(CS_AMBIENT_SET));
	pCSTable->Set(m_scriptEngine, "SIEGE_STATE", gmVariable(CS_SIEGE_STATE));
	pCSTable->Set(m_scriptEngine, "SIEGE_OBJECTIVES", gmVariable(CS_SIEGE_OBJECTIVES));
	pCSTable->Set(m_scriptEngine, "SIEGE_TIMEOVERRIDE", gmVariable(CS_SIEGE_TIMEOVERRIDE));
	pCSTable->Set(m_scriptEngine, "SIEGE_WINTEAM", gmVariable(CS_SIEGE_WINTEAM));
	pCSTable->Set(m_scriptEngine, "SIEGE_ICONS", gmVariable(CS_SIEGE_ICONS));
	pCSTable->Set(m_scriptEngine, "MODELS", gmVariable(CS_MODELS));
	pCSTable->Set(m_scriptEngine, "SKYBOXORG", gmVariable(CS_SKYBOXORG));
	pCSTable->Set(m_scriptEngine, "ICONS", gmVariable(CS_ICONS));
	pCSTable->Set(m_scriptEngine, "PLAYERS", gmVariable(CS_PLAYERS));
	pCSTable->Set(m_scriptEngine, "G2BONES", gmVariable(CS_G2BONES));
	pCSTable->Set(m_scriptEngine, "LOCATIONS", gmVariable(CS_LOCATIONS));
	pCSTable->Set(m_scriptEngine, "PARTICLES", gmVariable(CS_PARTICLES));
	pCSTable->Set(m_scriptEngine, "EFFECTS", gmVariable(CS_EFFECTS));
	pCSTable->Set(m_scriptEngine, "LIGHT_STYLES", gmVariable(CS_LIGHT_STYLES));
	pCSTable->Set(m_scriptEngine, "TERRAINS", gmVariable(CS_TERRAINS));
	pCSTable->Set(m_scriptEngine, "BSP_MODELS", gmVariable(CS_BSP_MODELS));
	pCSTable->Set(m_scriptEngine, "MAX", gmVariable(CS_MAX));

	gmTableObject *pTeamTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "TEAM", gmVariable(pTeamTable));
	pTeamTable->Set(m_scriptEngine, "FREE", gmVariable(TEAM_FREE));
	pTeamTable->Set(m_scriptEngine, "RED", gmVariable(TEAM_RED));
	pTeamTable->Set(m_scriptEngine, "BLUE", gmVariable(TEAM_BLUE));
	pTeamTable->Set(m_scriptEngine, "SPECTATOR", gmVariable(TEAM_SPECTATOR));

	gmTableObject *pGameTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "GAME", gmVariable(pGameTable));
	pGameTable->Set(m_scriptEngine, "FFA", gmVariable(GT_FFA));
	pGameTable->Set(m_scriptEngine, "HOLOCRON", gmVariable(GT_HOLOCRON));
	pGameTable->Set(m_scriptEngine, "JEDIMASTER", gmVariable(GT_JEDIMASTER));
	pGameTable->Set(m_scriptEngine, "DUEL", gmVariable(GT_DUEL));
	pGameTable->Set(m_scriptEngine, "POWERDUEL", gmVariable(GT_POWERDUEL));
	pGameTable->Set(m_scriptEngine, "SINGLE_PLAYER", gmVariable(GT_SINGLE_PLAYER));
	pGameTable->Set(m_scriptEngine, "TEAM", gmVariable(GT_TEAM));
	pGameTable->Set(m_scriptEngine, "SIEGE", gmVariable(GT_SIEGE));
	pGameTable->Set(m_scriptEngine, "CTF", gmVariable(GT_CTF));
	pGameTable->Set(m_scriptEngine, "CTY", gmVariable(GT_CTY));

	gmTableObject *pChatTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "CHAT", gmVariable(pChatTable));
	pChatTable->Set(m_scriptEngine, "DEFAULT", gmVariable(SAY_ALL));
	pChatTable->Set(m_scriptEngine, "TEAM", gmVariable(SAY_TEAM));

	gmTableObject *pWeaponTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "WEAPON", gmVariable(pWeaponTable));
	pWeaponTable->Set(m_scriptEngine, "NONE", gmVariable(WP_NONE));
	pWeaponTable->Set(m_scriptEngine, "STUN", gmVariable(WP_STUN_BATON));
	pWeaponTable->Set(m_scriptEngine, "MELEE", gmVariable(WP_MELEE));
	pWeaponTable->Set(m_scriptEngine, "SABER", gmVariable(WP_SABER));
	pWeaponTable->Set(m_scriptEngine, "PISTOL", gmVariable(WP_BRYAR_PISTOL));
	pWeaponTable->Set(m_scriptEngine, "BLASTER", gmVariable(WP_BLASTER));
	pWeaponTable->Set(m_scriptEngine, "DISRUPTOR", gmVariable(WP_DISRUPTOR));
	pWeaponTable->Set(m_scriptEngine, "BOWCASTER", gmVariable(WP_BOWCASTER));
	pWeaponTable->Set(m_scriptEngine, "REPEATER", gmVariable(WP_REPEATER));
	pWeaponTable->Set(m_scriptEngine, "DEMP2", gmVariable(WP_DEMP2));
	pWeaponTable->Set(m_scriptEngine, "FLECHETTE", gmVariable(WP_FLECHETTE));
	pWeaponTable->Set(m_scriptEngine, "ROCKET_LAUNCHER", gmVariable(WP_ROCKET_LAUNCHER));
	pWeaponTable->Set(m_scriptEngine, "THERMAL", gmVariable(WP_THERMAL));
	pWeaponTable->Set(m_scriptEngine, "TRIP_MINE", gmVariable(WP_TRIP_MINE));
	pWeaponTable->Set(m_scriptEngine, "DET_PACK", gmVariable(WP_DET_PACK));
	pWeaponTable->Set(m_scriptEngine, "CONCUSSION", gmVariable(WP_CONCUSSION));
	pWeaponTable->Set(m_scriptEngine, "OLDPISTOL", gmVariable(WP_BRYAR_OLD));
	pWeaponTable->Set(m_scriptEngine, "EMPLACED", gmVariable(WP_EMPLACED_GUN));
	pWeaponTable->Set(m_scriptEngine, "TURRET", gmVariable(WP_TURRET));

	gmTableObject *pAmmoTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "AMMO", gmVariable(pAmmoTable));
	pAmmoTable->Set(m_scriptEngine, "NONE", gmVariable(AMMO_NONE));
	pAmmoTable->Set(m_scriptEngine, "BLASTER", gmVariable(AMMO_BLASTER));
	pAmmoTable->Set(m_scriptEngine, "POWERCELL", gmVariable(AMMO_POWERCELL));
	pAmmoTable->Set(m_scriptEngine, "METALBOLTS", gmVariable(AMMO_METAL_BOLTS));
	pAmmoTable->Set(m_scriptEngine, "ROCKETS", gmVariable(AMMO_ROCKETS));
	pAmmoTable->Set(m_scriptEngine, "THERMAL", gmVariable(AMMO_THERMAL));
	pAmmoTable->Set(m_scriptEngine, "TRIPMINE", gmVariable(AMMO_TRIPMINE));
	pAmmoTable->Set(m_scriptEngine, "DETPACK", gmVariable(AMMO_DETPACK));

	gmTableObject *pForceTable = m_scriptEngine->AllocTableObject();
	m_scriptEngine->GetGlobals()->Set(m_scriptEngine, "FORCE", gmVariable(pForceTable));
	pForceTable->Set(m_scriptEngine, "HEAL", gmVariable(FP_HEAL));
	pForceTable->Set(m_scriptEngine, "JUMP", gmVariable(FP_LEVITATION));
	pForceTable->Set(m_scriptEngine, "SPEED", gmVariable(FP_SPEED));
	pForceTable->Set(m_scriptEngine, "PUSH", gmVariable(FP_PUSH));
	pForceTable->Set(m_scriptEngine, "PULL", gmVariable(FP_PULL));
	pForceTable->Set(m_scriptEngine, "MINDTRICK", gmVariable(FP_TELEPATHY));
	pForceTable->Set(m_scriptEngine, "GRIP", gmVariable(FP_GRIP));
	pForceTable->Set(m_scriptEngine, "LIGHTNING", gmVariable(FP_LIGHTNING));
	pForceTable->Set(m_scriptEngine, "RAGE", gmVariable(FP_RAGE));
	pForceTable->Set(m_scriptEngine, "PROTECT", gmVariable(FP_PROTECT));
	pForceTable->Set(m_scriptEngine, "ABSORB", gmVariable(FP_ABSORB));
	pForceTable->Set(m_scriptEngine, "TEAM_HEAL", gmVariable(FP_TEAM_HEAL));
	pForceTable->Set(m_scriptEngine, "TEAM_ENERGIZE", gmVariable(FP_TEAM_FORCE));
	pForceTable->Set(m_scriptEngine, "DRAIN", gmVariable(FP_DRAIN));
	pForceTable->Set(m_scriptEngine, "SEE", gmVariable(FP_SEE));
	pForceTable->Set(m_scriptEngine, "SABER_OFFENSE", gmVariable(FP_SABER_OFFENSE));
	pForceTable->Set(m_scriptEngine, "SABER_DEFENSE", gmVariable(FP_SABER_DEFENSE));
	pForceTable->Set(m_scriptEngine, "SABER_THROW", gmVariable(FP_SABERTHROW));

	gmBindCGameLib(m_scriptEngine);
	m_scriptEngine->EnableGC(true);
	CG_Printf("------------------------------------------------------\n");
}

 

And to load a script:

 

	void CG_LoadGMScript(const char *fileName) {
	GM_ASSERT(m_scriptEngine);
	if(!m_scriptEngine)
		return;
	PHYSFS_File *file;

	CG_Printf("...loading '%s'\n", fileName);

	file = PFS_openRead(MODPATH_FS_GAME, fileName);
	if(!file) {
		CG_Printf(S_COLOR_RED "file not found: %s\n", fileName);
		return;
	}

	int len = PFS_fileLength(file);
	boost::shared_array<char> pScript(new char[len+1]);
	PFS_read(file, pScript.get(), len);
	pScript[len] = 0;
	PFS_close(file);

	int errors = m_scriptEngine->ExecuteString(pScript.get(), GM_INVALID_THREAD, false, fileName);
	if(errors) {
		gmLogAnyErrorMsgs(m_scriptEngine);
	}
}

Link to comment
Share on other sites

  • 3 weeks later...

I've actually been pondering just recently a better way to implement an alternate scripting for server-side all together (LUA, GM, Squirrel, or w/e you want).

 

But you'd want to consider the following:

 

Replace ICARUS ****.

Allow for server manipulation type stuff (that can be see in like ETPro, and other various games/mods)

As you can see, ICARUS is using a separate file for each script which is kind of messy and you would want to limit map scripts to just 1 script and do everything in that file.

 

For instance:

 

If you have some entity that has many scripts attached to it, instead of each file per "behavior set" you'd just have events set up as such:

 

GM could be like so:

 

some code above...

//note [color=blue]this.[/color] inside these functions would be accessing myEnt (I think) Might be events but not positive.

myEnt = FunctionToRetrieveEntity(params?);
myEnt.Events[EVENT.SPAWN] = function(SpawnTime) {
//do some actions upon myEnt spawning
};

myEnt.Events[EVENT.USE] = function(UseEnt) {
//do some actions when myEnt has been used
};

myEnt.Events[EVENT.AWAKE] = function(params?) {
//do some actions when myEnt has awoken or been startled
};

myEnt.Events[EVENT.ANGER] = function(Enemy) {
//do some actions when myEnt has found an enemy
};

myEnt.Events[EVENT.VICTORY] = function(Victim, MeansOfDeath) {
//do some actions when myEnt has killed someone or something
};

myEnt.Events[EVENT.LOSTENEMY] = function(LastEnemy) {
//do some actions when myEnt has lost its enemy
};

myEnt.Events[EVENT.PAIN] = function(Inflictor) {
//do some actions when myEnt takes damage
};

myEnt.Events[EVENT.FLEE] = function(Health) {
//do some actions when myEnt's health is below 50%
};

myEnt.Events[EVENT.DEATH] = function(Inflictor, MeansOfDeath) {
//do some actions when myEnt has died
};

myEnt.Events[EVENT.DELAYED] = function(TimedDelay) {
//do some actions when myEnt delayScriptTime has been reached (this could be done away with IMO and replaced with script delays...)
};

myEnt.Events[EVENT.BLOCKED] = function(BlockEnt) {
//do some actions when myEnt is blocked by a friendly NPC or player
};

myEnt.Events[EVENT.BUMPED] = function(Bumpee, Radius) {
//do some actions when myEnt is bumped by a friendly NPC or player
};

myEnt.Events[EVENT.STUCK] = function(BlockEnt) {
//do some actions when myEnt is blocked by a wall
};

myEnt.Events[EVENT.FFIRE] = function(Victim, MethodOfDamage) {
//do some actions when myEnt shoots at its teammates
};

myEnt.Events[EVENT.FFDEATH] = function(Victim, MeansOfDeath) {
//do some actions when myEnt kills a teammate
};

myEnt.Events[EVENT.MINDTRICK] = function(Inflictor) {
//do some actions when myEnt has been mind tricked by someone
};

some code below...

Link to comment
Share on other sites

  • 1 month later...
I've actually been pondering just recently a better way to implement an alternate scripting for server-side all together (LUA, GM, Squirrel, or w/e you want).

 

But you'd want to consider the following:

 

Replace ICARUS ****.

Allow for server manipulation type stuff (that can be see in like ETPro, and other various games/mods)

As you can see, ICARUS is using a separate file for each script which is kind of messy and you would want to limit map scripts to just 1 script and do everything in that file.

 

For instance:

 

If you have some entity that has many scripts attached to it, instead of each file per "behavior set" you'd just have events set up as such:

 

GM could be like so:

 

some code above...

//note [color=blue]this.[/color] inside these functions would be accessing myEnt (I think) Might be events but not positive.

myEnt = FunctionToRetrieveEntity(params?);
myEnt.Events[EVENT.SPAWN] = function(SpawnTime) {
//do some actions upon myEnt spawning
};

myEnt.Events[EVENT.USE] = function(UseEnt) {
//do some actions when myEnt has been used
};

myEnt.Events[EVENT.AWAKE] = function(params?) {
//do some actions when myEnt has awoken or been startled
};

myEnt.Events[EVENT.ANGER] = function(Enemy) {
//do some actions when myEnt has found an enemy
};

myEnt.Events[EVENT.VICTORY] = function(Victim, MeansOfDeath) {
//do some actions when myEnt has killed someone or something
};

myEnt.Events[EVENT.LOSTENEMY] = function(LastEnemy) {
//do some actions when myEnt has lost its enemy
};

myEnt.Events[EVENT.PAIN] = function(Inflictor) {
//do some actions when myEnt takes damage
};

myEnt.Events[EVENT.FLEE] = function(Health) {
//do some actions when myEnt's health is below 50%
};

myEnt.Events[EVENT.DEATH] = function(Inflictor, MeansOfDeath) {
//do some actions when myEnt has died
};

myEnt.Events[EVENT.DELAYED] = function(TimedDelay) {
//do some actions when myEnt delayScriptTime has been reached (this could be done away with IMO and replaced with script delays...)
};

myEnt.Events[EVENT.BLOCKED] = function(BlockEnt) {
//do some actions when myEnt is blocked by a friendly NPC or player
};

myEnt.Events[EVENT.BUMPED] = function(Bumpee, Radius) {
//do some actions when myEnt is bumped by a friendly NPC or player
};

myEnt.Events[EVENT.STUCK] = function(BlockEnt) {
//do some actions when myEnt is blocked by a wall
};

myEnt.Events[EVENT.FFIRE] = function(Victim, MethodOfDamage) {
//do some actions when myEnt shoots at its teammates
};

myEnt.Events[EVENT.FFDEATH] = function(Victim, MeansOfDeath) {
//do some actions when myEnt kills a teammate
};

myEnt.Events[EVENT.MINDTRICK] = function(Inflictor) {
//do some actions when myEnt has been mind tricked by someone
};

some code below...

We have implented serverside lua now and a release is available already at http://www.jkalua.net/ Please check it out and tell me what you think about it :p

Link to comment
Share on other sites

it tells you an error if you havent defined the hooks in your scripts. But this error is just handled and the game will shutdown without crashing.

 

We haven't got the icarus replacement yet because animations and stuff isnt in there yet. We will put that in the next release probably. As for now we need to get people who would like to use it.

Link to comment
Share on other sites

it tells you an error if you havent defined the hooks in your scripts. But this error is just handled and the game will shutdown without crashing.

 

I think the best thing would be to just not call it at all if it doesn't exist and assume that its not there. If it is and not correct maybe, but I wouldn't shutdown.

 

This is what I do with GameMonkey:

 

(It's cgame but still my example for doing hooks/callbacks (the command/icc one is a little more complex tho)

 

http://pastebin.com/m2e77372b

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...