예제 #1
0
BOOL	KMission::ExecuteScript(DWORD dwScriptId,  char * szFunName, int nParam)
{
	try
	{
		KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId);
		if (pScript)
		{
			KSubWorld * pSubWorld = (KSubWorld*)GetOwner();
			
			if (pSubWorld)
			{
				Lua_PushNumber(pScript->m_LuaState, pSubWorld->m_nIndex);
				pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX);
			}
			
			int nTopIndex = 0;
			
			pScript->SafeCallBegin(&nTopIndex);
			pScript->CallFunction(szFunName,0, "d", nParam);
			pScript->SafeCallEnd(nTopIndex);
		}
		return TRUE;
	}
	catch(...)
	{
		printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
		g_DebugLog("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
		return FALSE;
	}
	return TRUE;
}
예제 #2
0
int CoreServerShell::OnLunch(LPVOID pServer)
{
	g_SetServer(pServer);

//	g_SetFilePath("\\script");
	KLuaScript * pStartScript =(KLuaScript*) g_GetScript("\\script\\ServerScript.lua");
	int i = 0;
	
	if (!pStartScript)
		g_DebugLog("Load ServerScript failed!");
	else
	{	
		pStartScript->CallFunction("StartGame",0,"");
	}

	PlayerSet.ReloadWelcomeMsg();

	return true;
}
예제 #3
0
//-------------------------------------------------------------------------
//	功能:	运行物件脚本
//-------------------------------------------------------------------------
void	KObj::ExecScript(int nPlayerIdx)
{
	if (!m_dwScriptID)
		return;
	if (nPlayerIdx < 0)
		return;
	DWORD dwScriptId = m_dwScriptID;//g_FileName2Id(m_szScriptName);
	KLuaScript * pScript = (KLuaScript*)g_GetScript(dwScriptId);
	try
	{
		if (pScript)
		{
			if (Player[nPlayerIdx].m_nIndex < 0) return ;
			Npc[Player[nPlayerIdx].m_nIndex].m_ActionScriptID = dwScriptId;
			Lua_PushNumber(pScript->m_LuaState, Player[nPlayerIdx].GetPlayerIndex());
			pScript->SetGlobalName(SCRIPT_PLAYERINDEX);
			
			Lua_PushNumber(pScript->m_LuaState, Player[nPlayerIdx].GetPlayerID());
			pScript->SetGlobalName(SCRIPT_PLAYERID);
			
			Lua_PushNumber(pScript->m_LuaState, m_nIndex);
			pScript->SetGlobalName(SCRIPT_OBJINDEX);
			
			int nTopIndex = 0;
			pScript->SafeCallBegin(&nTopIndex);
			
			BOOL bResult = FALSE;
			bResult = pScript->CallFunction("main", 0, "");
			pScript->SafeCallEnd(nTopIndex);
			
		}
	}
	catch(...)
	{
		printf("Exception Have Chought When Execute Obj Script[%d]!!!!!", dwScriptId);
	}
	return;
}