ScriptFuns.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:129k
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_Level);
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaGetPlayerLife(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentLife);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LifeMax); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LifeMax);break;
- default:
- Lua_PushNil(L);
- }
- }
-
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaRestorePlayerLife(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].RestoreLife();
- }
- return 0;
- }
- int LuaRestorePlayerMana(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].RestoreMana();
- }
- return 0;
- }
- int LuaRestorePlayerStamina(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Npc[Player[nPlayerIndex].m_nIndex].RestoreStamina();
- }
- return 0;
- }
- int LuaGetPlayerLifeReplenish(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt( L, m_LifeReplenish);
- }
- int LuaGetPlayerMana(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentMana);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ManaMax); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ManaMax);break;
- default:
- Lua_PushNil(L);
- }
- }
-
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaGetPlayerStamina(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentStamina);break;
- case 1:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_StaminaMax); break;
- case 2:
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_StaminaMax);break;
- default:
- Lua_PushNil(L);
- }
- }
-
- }
- else
- Lua_PushNil(L);
- return 1;
- }
- int LuaGetPlayerManaReplenish(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L , m_ManaReplenish);
- }
- int LuaGetPlayerDefend(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L , m_Defend);
- }
- int LuaGetPlayerSex(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L , m_nSex);
- }
- int LuaGetPlayerIndex(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L , GetPlayerIdx());
- return 0;
- }
- int LuaGetPlayerSeries(Lua_State * L)
- {
- MacroFun_GetPlayerInfoInt(L , m_Series);
- }
- int LuaSetPlayerSeries(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nValue = (int)Lua_ValueToNumber(L,1);
- Npc[Player[nPlayerIndex].m_nIndex].SetSeries(nValue);
- }
- return 0;
-
- }
- int LuaGetPlayerCount(Lua_State * L)
- {
- Lua_PushNumber(L, PlayerSet.GetPlayerNumber());
- return 1;
- }
- int LuaGetPlayerName(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushString(L, Player[nPlayerIndex].m_PlayerName);
- }
- else
- Lua_PushNil(L);
-
- return 1;
-
- }
- int LuaGetPlayerID(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_dwID);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- int LuaGetPlayerLeadExp(Lua_State * L)
- {
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_dwLeadExp);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- int LuaGetPlayerLeadLevel(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_dwLeadLevel);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- int LuaGetPlayerRestAttributePoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_nAttributePoint);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- int LuaGetPlayerRestSkillPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_nSkillPoint);
- }
- else
- Lua_PushNil(L);
-
- return 1;
- }
- /*
- int LuaModifyPlayerRestSkillPoint(Lua_State *L)
- {
- //Question
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nDValue = (int)Lua_ValueToNumber(L, 1);
- int nNewSkillPoint = Player[nPlayerIndex].m_nSkillPoint + nDValue;
- if (nNewSkillPoint < 0 ) return 0;
-
- Player[nPlayerIndex].m_nSkillPoint = nNewSkillPoint;
- }
-
- return 0;
- }
- */
- //基本属性
- int LuaGetPlayerLucky(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nCurLucky);break;
- case 1:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nLucky);break;
- case 2:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nLucky);break;
- default:
- Lua_PushNil(L);
- }
-
- }
- return 1;
- }
- int LuaGetPlayerEngergy(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nCurEngergy);break;
- case 1:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nEngergy);break;
- case 2:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nEngergy);break;
- default:
- Lua_PushNil(L);
- }
- }
-
- return 1;
- }
- int LuaGetPlayerDexterity(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nCurDexterity);break;
- case 1:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nDexterity);break;
- case 2:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nDexterity);break;
- default:
- Lua_PushNil(L);
- }
-
- }
- return 1;
- }
- int LuaGetPlayerStrength(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nCurStrength);break;
- case 1:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nStrength);break;
- case 2:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nStrength);break;
- default:
- Lua_PushNil(L);
- }
-
- }
- return 1;
-
- }
- int LuaGetPlayerVitality(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
-
- int nType = (int)Lua_ValueToNumber(L,1);
- switch((int)Lua_ValueToNumber(L,1))
- {
- case 0:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nCurVitality);break;
- case 1:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nVitality);break;
- case 2:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nVitality);break;
- default:
- Lua_PushNil(L);
- }
-
- }
- return 1;
-
- }
- int LuaGetPlayerCashMoney(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex > 0)
- {
- Lua_PushNumber(L, Player[nPlayerIndex].m_ItemList.GetMoney(room_equipment));
- }
- else Lua_PushNumber(L,0);
-
- return 1;
- }
- int LuaPlayerPayMoney(Lua_State * L)
- {
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nMoney = (int)Lua_ValueToNumber(L, 1);
- if (nMoney <= 0) return 0;
- if (Player[nPlayerIndex].Pay(nMoney))
- Lua_PushNumber(L, 1);
- else
- Lua_PushNumber(L, 0);
- }
- else
- Lua_PushNumber(L, 0);
-
- return 1;
- }
- int LuaPlayerEarnMoney (Lua_State *L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nMoney = (int)Lua_ValueToNumber(L, 1);
- if (nMoney <= 0) return 0;
- Player[nPlayerIndex].Earn(nMoney);
- }
- return 0;
- }
- int LuaPlayerPrePayMoney(Lua_State *L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- int nMoney = (int)Lua_ValueToNumber(L, 1);
- if (nMoney <= 0) return 0;
- if (Player[nPlayerIndex].PrePay(nMoney))
- Lua_PushNumber(L, 1);
- else
- Lua_PushNumber(L, 0);
- }
- else
- Lua_PushNumber(L, 0);
-
- return 1;
- }
- int LuaPlayerExecuteScript(Lua_State * L)
- {
-
- return 1;
- }
- //Attack dwID, Damage
- int LuaAttackNpc(Lua_State * L)
- {
- int nParamCount = 0;
- if ( (nParamCount = Lua_GetTopIndex(L)) < 2) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- DWORD nNpcID = (DWORD)Lua_ValueToNumber(L,1);
- int nNpcIndex = Player[nPlayerIndex].FindAroundNpc(nNpcID);//NpcSet.SearchID(nNpcID);
- if (nNpcIndex <= 0) return 0;
-
- KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
- memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
-
- DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
- DamageMagicAttribs[0].nValue[0] = 65534;
-
- DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
- DamageMagicAttribs[1].nValue[0] = 1;
-
- for (int i = 0; i < nParamCount - 1; i++)
- {
- int nVlau = (int)Lua_ValueToNumber(L, 2 + i);
- DamageMagicAttribs[i + 2].nValue[0] = (int)Lua_ValueToNumber(L, 2 + i);
- DamageMagicAttribs[i + 2].nValue[2] = (int)Lua_ValueToNumber(L, 2 + i);
- }
-
- Npc[nNpcIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
- return 0;
- }
- int LuaSetPlayerChatForbiddenFlag(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0)
- return 0;
- int nFlag = Lua_ValueToNumber(L, 1);
- Player[nPlayerIndex].SetChatForbiddenFlag(nFlag);
- return 0;
- }
- int LuaKickOutPlayer(Lua_State *L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- const char* pszName = (const char*)Lua_ValueToString(L, 1);
-
- int nIndex = PlayerSet.GetFirstPlayer();
- while(nIndex > 0)
- {
- if (strcmp(Player[nIndex].m_PlayerName, pszName) == 0)
- break;
-
- nIndex = PlayerSet.GetNextPlayer();
- }
- if (nIndex && Player[nIndex].m_nNetConnectIdx >= 0)
- {
- printf("GM Kick out specific player.n");
- g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
- }
- return 0;
- }
- int LuaKickOutAccount(Lua_State *L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- const char* pszName = (const char*)Lua_ValueToString(L, 1);
-
- int nIndex = PlayerSet.GetFirstPlayer();
- while(nIndex > 0)
- {
- if (strcmpi(Player[nIndex].m_AccoutName, pszName) == 0)
- break;
-
- nIndex = PlayerSet.GetNextPlayer();
- }
- if (nIndex && Player[nIndex].m_nNetConnectIdx >= 0)
- {
- printf("GM Kick out specific player.n");
- g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
- }
- return 0;
- }
- int LuaKickOutSelf(Lua_State *L)
- {
- int nIndex = GetPlayerIndex(L);
-
- if (nIndex <= 0)
- return 0;
-
- if (Player[nIndex].m_nNetConnectIdx >= 0)
- {
- printf("GM Kick out player one.n");
- g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
- }
- return 0;
- }
- int LuaKillNpc(Lua_State * L)
- {
- int nParamCount = 0;
- if ( (nParamCount = Lua_GetTopIndex(L)) < 1) return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- DWORD nNpcID = (DWORD)Lua_ValueToNumber(L,1);
- int nNpcIndex = Player[nPlayerIndex].FindAroundNpc(nNpcID);
- if (nNpcIndex <= 0) return 0;
-
- KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
- memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
-
- DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
- DamageMagicAttribs[0].nValue[0] = 50000;
-
-
-
- DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
- DamageMagicAttribs[1].nValue[0] = 1;
-
-
- DamageMagicAttribs[2].nValue[0] = 50000;
- DamageMagicAttribs[2].nValue[2] = 50000;
-
- Npc[nNpcIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
- return 0;
- }
- int LuaKillPlayer(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
- memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
-
- DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
- DamageMagicAttribs[0].nValue[0] = 50000;
-
- DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
- DamageMagicAttribs[1].nValue[0] = 1;
-
-
- DamageMagicAttribs[2].nValue[0] = 50000;
- DamageMagicAttribs[2].nValue[2] = 50000;
-
- Npc[Player[nPlayerIndex].m_nIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
- return 0;
- }
- int LuaSetFightState(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Npc[Player[nPlayerIndex].m_nIndex].SetFightMode(Lua_ValueToNumber(L,1) != 0);
- return 0;
- }
- int LuaGetFightState(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_FightMode);
- return 1;
- }
- int LuaGetLevel(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) Lua_PushNumber(L,0);
-
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_Level);
- return 1;
- }
- //
- int LuaUseTownPortal(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
-
- Player[nPlayerIndex].UseTownPortal();
- return 0;
- }
- int LuaReturnFromTownPortal(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
-
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
-
- Player[nPlayerIndex].BackToTownPortal();
- return 0;
- }
- #endif
- int GetPlayerIndex(Lua_State * L)
- {
- Lua_GetGlobal(L, SCRIPT_PLAYERINDEX);
- if (lua_isnil(L,Lua_GetTopIndex(L)))
- return -1;
- int nIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
- if (nIndex >= MAX_PLAYER || nIndex <= 0)
- {
- _ASSERT(0);
- return -1;
- } if (Player[nIndex].m_nIndex >= MAX_NPC || Player[nIndex].m_nIndex < 0)
- {
- _ASSERT(0);
- return -1;
- }
- return nIndex;
- }
- int GetObjIndex(Lua_State * L)
- {
- Lua_GetGlobal(L, SCRIPT_OBJINDEX);
- if (lua_isnil(L,Lua_GetTopIndex(L)))
- return -1;
- int nIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
- if (nIndex >= MAX_OBJECT || nIndex <= 0)
- {
- _ASSERT(0);
- return -1;
- }
- if (Object[nIndex].m_nIndex != nIndex)
- {
- _ASSERT(0);
- return -1;
- }
- return nIndex;
- }
- int LuaMessage(Lua_State * L)
- {
- const char * szString;
- szString = lua_tostring (L,1);
- g_DebugLog((char *)szString);
- return 0;
- }
- #ifdef _SERVER
- //AddStation(N)
- int LuaAddPlayerWayPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- int nWayPoint = (int)Lua_ValueToNumber(L,1);
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- {
- KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerWayPointList.GetHead();
- while(pNode)
- {
- if (pNode->m_nIndex == nWayPoint) return 0;
- pNode = (KIndexNode*)pNode->GetNext();
- }
-
- KIndexNode * pNewNode = new KIndexNode;
- pNewNode->m_nIndex = nWayPoint;
- int nCount = Player[nPlayerIndex].m_PlayerWayPointList.GetNodeCount();
- for (int i = 0; i < nCount - 2; i ++ )
- {
- KIndexNode * pDelNode = (KIndexNode*)Player[nPlayerIndex].m_PlayerWayPointList.RemoveHead();
- delete pDelNode;
- }
- Player[nPlayerIndex].m_PlayerWayPointList.AddTail(pNewNode);
- }
- return 0;
- }
- int LuaAddPlayerStation(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- int nStation = (int )Lua_ValueToNumber(L,1);
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- {
- KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerStationList.GetHead();
- while(pNode)
- {
- if (pNode->m_nIndex == nStation) return 0;
- pNode = (KIndexNode*)pNode->GetNext();
- }
-
- KIndexNode * pNewNode = new KIndexNode;
- pNewNode->m_nIndex = nStation;
- Player[nPlayerIndex].m_PlayerStationList.AddTail(pNewNode);
- }
- return 0;
- }
- int LuaGetPlayerStationCount(Lua_State *L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Lua_PushNumber(L, Player[nPlayerIndex].m_PlayerStationList.GetNodeCount());
- return 1;
- }
- //获得当前玩家有效城市列表中的第n个(除去当前所在城市)
- int LuaGetPlayerStation(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
-
- if (Lua_GetTopIndex(L) < 2)
- {
- Lua_PushNumber(L, 0);
- return 1;
- }
-
- int nStationId = 0;
- KIndexNode * pNode = (KIndexNode*)Player[nPlayerIndex].m_PlayerStationList.GetHead();
- if (pNode)
- {
- int nNo = (int )Lua_ValueToNumber(L, 1);
- int nCurStation = (int) Lua_ValueToNumber(L,2);
- int nVisitNo = 0;
- while(pNode)
- {
- if (pNode->m_nIndex != nCurStation && g_GetPriceToStation( nCurStation , pNode->m_nIndex) > 0)
- {
- nVisitNo ++;
- if (nVisitNo == nNo)
- {
- nStationId = pNode->m_nIndex;
- break;
- }
- }
- pNode = (KIndexNode*)pNode->GetNext();
- }
- }
-
- Lua_PushNumber(L, nStationId);
-
- return 1;
- }
- int LuaGetPlayerWayPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
-
- KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerWayPointList.GetHead();
- if (pNode)
- {
- int nNo = (int)Lua_ValueToNumber(L, 1);
- if (nNo > TASKVALUE_MAXWAYPOINT_COUNT)
- Lua_PushNumber(L, 0);
- else
- {
- for (int i = 0; i < nNo - 1; i ++)
- {
- if (pNode == NULL ) break;
- pNode = (KIndexNode *)pNode->GetNext();
- }
-
- if (pNode)
- Lua_PushNumber(L, pNode->m_nIndex);
- else
- Lua_PushNumber(L, 0);
-
- }
- }
- else
- Lua_PushNumber(L, 0);
-
- return 1;
- }
- //根据传入的城市唯一id获得其名称
- int LuaGetStationName(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- if (Lua_GetTopIndex(L) <= 0 )
- {
- Lua_PushString(L, "");
- return 1;
- }
- int nStationId = (int)Lua_ValueToNumber(L,1);
- char szName[50];
- g_StationTabFile.GetString(nStationId + 1, "DESC", "无名城", szName, 50 );
- Lua_PushString(L, szName);
- return 1;
- }
- int LuaGetWayPointName(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- if (Lua_GetTopIndex(L) <= 0 )
- {
- Lua_PushString(L, "");
- return 1;
- }
- int nWayPointId = (int)Lua_ValueToNumber(L,1);
- char szName[50];
- g_WayPointTabFile.GetString(nWayPointId + 1, "DESC", "未记录", szName, 50 );
- Lua_PushString(L, szName);
- return 1;
- }
- //GetCityCount
- int LuaGetAllStationCount(Lua_State * L)
- {
- int nCityCount = g_StationTabFile.GetHeight() - 1;
- if (nCityCount < 0) nCityCount = 0;
- Lua_PushNumber(L,nCityCount);
- return 1;
- }
- //cityid, price = GetCity(citynum, curcity)
- int LuaGetCity(Lua_State * L)
- {
- return 0;
- }
- int LuaGetPriceToWayPoint(Lua_State *L)
- {
-
- int nCurStation = (int)Lua_ValueToNumber(L,1);
- int nDesWayPoint = (int)Lua_ValueToNumber(L,2);
- Lua_PushNumber(L, g_GetPriceToWayPoint(nCurStation, nDesWayPoint));
- return 1;
- }
- int LuaGetPriceToStation(Lua_State *L)
- {
- int nCurStation = (int)Lua_ValueToNumber(L,1);
- int nNextStation = (int)Lua_ValueToNumber(L,2);
- Lua_PushNumber(L, g_GetPriceToStation(nCurStation, nNextStation));
- return 1;
- }
- int LuaGetStationPos(Lua_State * L)
- {
- int nStationId = (int)Lua_ValueToNumber(L,1);
- char szPos[100] ;
- int nCount = 0;
- int nRow = g_StationTabFile.FindColumn("COUNT");
- g_StationTabFile.GetInteger(nStationId + 1, nRow, 0, &nCount);
- if (nCount <= 0) return 0;
- int nRandSect = g_Random(100) % nCount + 1;
- char szSectName[32];
- sprintf(szSectName, "SECT%d", nRandSect);
- char szValue[100];
- nRow = g_StationTabFile.FindColumn(szSectName);
- g_StationTabFile.GetString(nStationId + 1, nRow, "0,0,0", szValue, 100);
-
- int nX, nY, nWorld;
- const char *pcszTemp = szValue;
-
- nWorld = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nX = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nY = KSG_StringGetInt(&pcszTemp, 0);
- //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
-
- Lua_PushNumber(L,nWorld);
- Lua_PushNumber(L,nX);
- Lua_PushNumber(L,nY);
- return 3;
- }
- int LuaGetWayPointPos(Lua_State * L)
- {
- int nWayPointId = (int)Lua_ValueToNumber(L,1);
- char szPos[100] ;
- int nCount = 0;
- char szValue[30];
- int nRow;
- nRow = g_WayPointTabFile.FindColumn("SECT");
- g_WayPointTabFile.GetString(nWayPointId + 1, nRow, "0,0,0", szValue, 30);
- int nX, nY, nWorld;
- const char *pcszTemp = szValue;
-
- nWorld = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nX = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nY = KSG_StringGetInt(&pcszTemp, 0);
- //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
-
- Lua_PushNumber(L,nWorld);
- Lua_PushNumber(L,nX);
- Lua_PushNumber(L,nY);
- return 3;
- }
- int LuaGetRank(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Lua_PushNumber(L,Npc[Player[nPlayerIndex].m_nIndex].m_btRankId);
- return 1;
- }
- int LuaSetRank(Lua_State * L)
- {
- BYTE btRank = (BYTE)Lua_ValueToNumber(L,1);
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- Npc[Player[nPlayerIndex].m_nIndex].m_btRankId = btRank;
- return 0;
- }
- int LuaSetObjPropState(Lua_State *L)
- {
- int nParamNum = ( int ) Lua_GetTopIndex(L);
- int nState = 1;
-
- if (nParamNum >= 1)
- {
- nState = (int)Lua_ValueToNumber(L,1);
- nState = (nState == 0)?0 : 1;
- }
-
- int nIndex = 0;
- if ((nIndex = GetObjIndex(L)) < 0)
- return 0;
-
- Object[nIndex].SetState(nState);
- return 0;
- }
- int LuaGetServerName(Lua_State * L)
- {
- char szServerName[100] ;
- unsigned long stServerNameLen = 100;
- #ifndef __linux
- if (GetComputerName(szServerName, &stServerNameLen))
- {
- Lua_PushString(L, szServerName);
- }
- else
- #else
- if (SOCKET_ERROR != gethostname(szServerName, sizeof(szServerName)))
- {
- Lua_PushString(L, szServerName);
- }
- else
- #endif
- Lua_PushString(L, "");
- return 1;
- }
- //GetWharfCount(nDock)
- int LuaGetDockCount(Lua_State * L)
- {
- int nCount = 0;
- int nCurStation = 0;
- int nTotalCount = 0;
- int i = 0;
- if (Lua_GetTopIndex(L) < 1 )
- {
- goto DockCount;
- }
-
- nCurStation = (int)Lua_ValueToNumber(L,1);
- nTotalCount = g_DockPriceTabFile.GetHeight() - 1;
-
- for (i = 0; i < nTotalCount; i ++)
- {
- int nPrice = g_GetPriceToDock(nCurStation, i + 1);
- if (nPrice > 0) nCount ++;
- }
-
- DockCount:
- Lua_PushNumber(L, nCount);
- return 1;
- }
- int LuaGetDockPrice(Lua_State * L)
- {
- int nCurDock = (int)Lua_ValueToNumber(L,1);
- int nDesDock = (int)Lua_ValueToNumber(L,2);
- Lua_PushNumber(L, g_GetPriceToDock(nCurDock, nDesDock));
- return 1;
- }
- int LuaGetDock(Lua_State * L)
- {
- int nCurDock = (int)Lua_ValueToNumber(L, 1);
- int nDock = (int)Lua_ValueToNumber(L, 2);
- int nCount = 0;
- int nTotalCount = g_DockPriceTabFile.GetHeight() - 1;
- int nGetDock = 0;
-
- for (int i = 0; i < nTotalCount; i ++)
- {
- int nPrice = g_GetPriceToDock(nCurDock, i + 1);
- if (nPrice > 0)
- {
- nCount ++ ;
- if (nCount == nDock)
- {
- nGetDock = i + 1;
- break;
- }
- }
- }
- Lua_PushNumber(L, nGetDock);
- return 1;
- }
- int LuaGetDockName(Lua_State * L)
- {
- int nDock = (int)Lua_ValueToNumber(L, 1);
- char szName[100] ;
-
- if (nDock > g_DockPriceTabFile.GetHeight() - 1)
- {
- strcpy(szName, "未知码头");
- goto DockName;
- }
-
- g_DockTabFile.GetString(nDock + 1, "DESC", "未知码头", szName, 100);
-
- DockName:
- Lua_PushString (L, szName);
- return 1;
- }
- int LuaGetDockPos(Lua_State * L)
- {
- int nDock = (int)Lua_ValueToNumber(L, 1);
- if (nDock > g_DockTabFile.GetHeight() - 1)
- {
- printf("GetWharfPos Script Is Error!");
- return 0;
- }
-
- char szPos[100] ;
- int nCount = 0;
- int nRow = g_DockTabFile.FindColumn("COUNT");
- g_DockTabFile.GetInteger(nDock + 1, nRow, 0, &nCount);
- if (nCount <= 0) return 0;
- int nRandSect = g_Random(100) % nCount + 1;
- char szSectName[32];
- sprintf(szSectName, "SECT%d", nRandSect);
- char szValue[100];
- nRow = g_DockTabFile.FindColumn(szSectName);
- g_DockTabFile.GetString(nDock + 1, nRow, "0,0,0", szValue, 100);
- int nX, nY, nWorld;
- const char *pcszTemp = szValue;
-
- nWorld = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nX = KSG_StringGetInt(&pcszTemp, 0);
- KSG_StringSkipSymbol(&pcszTemp, ',');
- nY = KSG_StringGetInt(&pcszTemp, 0);
- //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
-
- Lua_PushNumber(L,nWorld);
- Lua_PushNumber(L,nX);
- Lua_PushNumber(L,nY);
- return 3;
- }
- int LuaGetWayPointFightState(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
- int nFightState = 0;
- if (Lua_GetTopIndex(L) > 0 )
- {
- int nWayPointId = (int)Lua_ValueToNumber(L,1);
- g_WayPointTabFile.GetInteger(nWayPointId + 1, "FightState", 0, &nFightState);
- }
- Lua_PushNumber(L, nFightState);
- return 1;
- }
- // SetMissionValue(valueid, value)
- int LuaSetMissionValue(Lua_State * L)
- {
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex < 0)
- return 0;
-
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2)
- return 0;
-
- int nValueId = (int)Lua_ValueToNumber(L, 1);
- int nValue = (int)Lua_ValueToNumber(L, 2);
-
- if (nValueId < 0)
- return 0;
- SubWorld[nSubWorldIndex].m_MissionArray.SetMissionValue(nValueId, nValue);
- return 0;
- }
- int LuaGetMissionValue(Lua_State * L)
- {
- int nResultValue = 0;
- int nSubWorldIndex = -1;
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 1)
- goto lab_getmissionvalue;
-
- nSubWorldIndex = GetSubWorldIndex(L);
-
- if (nSubWorldIndex >= 0)
- {
- int nValueId = (int)Lua_ValueToNumber(L, 1);
- if (nValueId > 0)
- nResultValue = SubWorld[nSubWorldIndex].m_MissionArray.GetMissionValue(nValueId);
- }
-
- lab_getmissionvalue:
- Lua_PushNumber(L, nResultValue);
- return 1;
- }
- // SetMissionValue(mapid/mapname, valueid, value)
- int LuaSetGlobalMissionValue(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2)
- return 0;
-
- int nValueId = (int)Lua_ValueToNumber(L, 1);
- int nValue = (int)Lua_ValueToNumber(L, 2);
-
- if (nValueId < 0)
- return 0;
- g_GlobalMissionArray.SetMissionValue(nValueId, nValue);
- return 0;
- }
- int LuaGetGlobalMissionValue(Lua_State * L)
- {
- int nResultValue = 0;
- int nValueId = 0;
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 1)
- goto lab_getglobalmissionvalue;
- nValueId = (int)Lua_ValueToNumber(L, 1);
- if (nValueId < 0)
- goto lab_getglobalmissionvalue;
-
- nResultValue = g_GlobalMissionArray.GetMissionValue(nValueId);
-
- lab_getglobalmissionvalue:
- Lua_PushNumber(L, nResultValue);
- return 1;
- }
- //StartMission(missionid)
- int LuaInitMission(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- if (nMissionId < 0 )
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex < 0)
- return 0;
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- return 0;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- _ASSERT(0);
- return 0;
- }
-
- pMission = SubWorld[nSubWorldIndex].m_MissionArray.Add();
- if (pMission)
- {
- pMission->m_MissionPlayer.Clear();
- pMission->SetMissionId(nMissionId);
- char szScript[MAX_PATH];
- g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
- if (szScript[0])
- Player[nPlayerIndex].ExecuteScript(szScript, "InitMission", "");
- }
-
- return 0;
- }
- int LuaRunMission(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- if (nMissionId < 0 )
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex < 0)
- return 0;
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- return 0;
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- char szScript[MAX_PATH];
- g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
- if (szScript[0])
- Player[nPlayerIndex].ExecuteScript(szScript, "RunMission", "");
- }
-
- return 0;
- }
- //CloseMission(missionId)
- int LuaCloseMission(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- if (nMissionId < 0 )
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex < 0)
- return 0;
- KMission StopMission;
- StopMission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&StopMission);
- if (pMission)
- {
- char szScript[MAX_PATH];
- g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
- if (szScript[0])
- pMission->ExecuteScript(szScript, "EndMission",0);
- pMission->StopMission();
- SubWorld[nSubWorldIndex].m_MissionArray.Remove(pMission);
-
- }
- return 0;
- }
- //StopMissionTimer(missionid, timerid)
- int LuaStopMissionTimer(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2)
- return 0;
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nTimerId = (int)Lua_ValueToNumber(L, 2);
- int nSubWorldIndex = GetSubWorldIndex(L);
-
- if (nMissionId < 0 || nTimerId < 0 )
- return 0;
-
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- KTimerTaskFun StopTimer;
- StopTimer.SetTimer(1, nTimerId);
- KTimerTaskFun * pTimer = pMission->m_cTimerTaskSet.GetData(&StopTimer);
- if (pTimer)
- {
- pTimer->CloseTimer();
- pMission->m_cTimerTaskSet.Remove(pTimer);
- }
- }
-
- }
-
- return 0;
- }
- //StartMissionTimer(missionid, timerid, time)
- int LuaStartMissionTimer(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 3)
- return 0;
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nTimerId = (int)Lua_ValueToNumber(L, 2);
- int nTimeInterval = (int)Lua_ValueToNumber(L, 3);
- int nSubWorldIndex = GetSubWorldIndex(L);
-
- if (nMissionId < 0 || nTimerId < 0 || nTimeInterval < 0)
- return 0;
-
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- KTimerTaskFun * pTimer = pMission->m_cTimerTaskSet.Add();
- if (pTimer)
- {
- pTimer->SetTimer(nTimeInterval, nTimerId);
- }
- }
-
- }
- return 0;
- }
- //SetTempRev(worldid, x, y)
- int LuaSetDeathRevivalPos(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
-
- if (nPlayerIndex <= 0)
- return 0;
- int nParamCount = Lua_GetTopIndex(L);
-
- PLAYER_REVIVAL_POS * pTempRev = Player[nPlayerIndex].GetDeathRevivalPos();
-
- if (nParamCount > 2)
- {
- pTempRev->m_nSubWorldID = (int) Lua_ValueToNumber(L, 1);
- pTempRev->m_nMpsX = (int) Lua_ValueToNumber(L, 2);
- pTempRev->m_nMpsY = (int) Lua_ValueToNumber(L, 3);
- }
- else if (nParamCount == 1)
- {
- pTempRev->m_nSubWorldID = SubWorld[Npc[Player[nPlayerIndex].m_nIndex].m_SubWorldIndex].m_SubWorldID;
- POINT Pos;
- int nRevId = (int) Lua_ValueToNumber(L, 1);
- g_SubWorldSet.GetRevivalPosFromId(pTempRev->m_nSubWorldID, nRevId, &Pos);
- pTempRev->m_ReviveID = nRevId;
- pTempRev->m_nMpsX = Pos.x;
- pTempRev->m_nMpsY = Pos.y;
- }
- else
- {
- return 0;
- }
-
- return 0;
- }
- //AddMSPlayer(MissionId, PlayerIndex, groupid); / AddMSPlayer(MissionId, groupid)
- int LuaAddMissionPlayer(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2)
- return 0;
- int nMissionId = 0;
- int nPlayerIndex = 0;
- int nGroupId = 0;
- if (nParamCount >=3)
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- nPlayerIndex = (int )Lua_ValueToNumber(L,2);
- nGroupId = (int) Lua_ValueToNumber(L,3);
- }
- else
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- nGroupId = (int) Lua_ValueToNumber(L,2);
- nPlayerIndex = GetPlayerIndex(L);
- }
-
- if (nMissionId < 0 || nPlayerIndex <= 0 || nGroupId <0)
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- pMission->AddPlayer(nPlayerIndex, Player[nPlayerIndex].m_dwID, nGroupId);
- }
- }
- return 0;
- }
- int LuaRevivalAllNpc(Lua_State * L)
- {
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- SubWorld[nSubWorldIndex].RevivalAllNpc();
- }
- return 0;
- }
- //RemoveMSPlayer(MissionId, PlayerIndex, groupid)
- int LuaRemoveMissionPlayer(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2)
- return 0;
- int nMissionId = 0;
- int nPlayerIndex = 0;
- int nGroupId = 0;
- if (nParamCount >=3)
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- nPlayerIndex = (int )Lua_ValueToNumber(L,2);
- nGroupId = (int) Lua_ValueToNumber(L,3);
- }
- else
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- nGroupId = (int) Lua_ValueToNumber(L,2);
- nPlayerIndex = GetPlayerIndex(L);
- }
-
- if (nMissionId < 0 || nPlayerIndex <= 0 || nGroupId <0)
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- pMission->RemovePlayer(nPlayerIndex);
- //pMission->AddPlayer(nPlayerIndex, Player[nPlayerIndex].m_dwID, nGroupId);
- }
- }
- return 0;
- }
- //GetNextPlayer(mission, idx,group)
- int LuaGetNextPlayer(Lua_State * L)
- {
- unsigned long nPlayerIndex = 0;
-
- if (Lua_GetTopIndex(L) < 2)
- {
- Lua_PushNumber(L ,0);
- Lua_PushNumber(L, 0);
- return 2;
- }
-
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nIdx = (int)Lua_ValueToNumber(L, 2);
- int nGroup = (int)Lua_ValueToNumber(L, 3);
- int nSubWorldIndex = GetSubWorldIndex(L);
- int nResultIdx = 0;
-
- if (nMissionId < 0 || nIdx < 0 || nGroup < 0)
- goto lab_getnextplayer;
-
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- nResultIdx = pMission->GetNextPlayer(nIdx, nGroup, nPlayerIndex);
- }
- }
-
- lab_getnextplayer:
- Lua_PushNumber(L, nResultIdx);
- Lua_PushNumber(L, nPlayerIndex);
- return 2;
- }
- //MSMsg2Group(missionid, string , group)
- int LuaMissionMsg2Group(Lua_State * L)
- {
- int nMissionId = (int)Lua_ValueToNumber(L,1);
- char * strMsg = (char *)Lua_ValueToString(L, 2);
- int nGroupId = (int) Lua_ValueToNumber(L, 3);
-
- if (nMissionId < 0 || !strMsg || nGroupId <0)
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- pMission->Msg2Group(strMsg, nGroupId);
- }
- }
-
- return 0;
- }
- //MSMsg2Group(missionid, string)
- int LuaMissionMsg2All(Lua_State * L)
- {
- int nMissionId = (int)Lua_ValueToNumber(L,1);
- char * strMsg = (char *)Lua_ValueToString(L, 2);
-
- if (nMissionId < 0 || !strMsg)
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- pMission->Msg2All(strMsg);
- }
- }
-
- return 0;
- }
- //MSMsg2Group(missionid, string , group)
- int LuaMissionMsg2Player(Lua_State * L)
- {
- int nMissionId = (int)Lua_ValueToNumber(L,1);
- char * strMsg = (char *)Lua_ValueToString(L, 2);
- int nPlayerIndex = (int) Lua_ValueToNumber(L, 3);
-
- if (nMissionId < 0 || !strMsg || nPlayerIndex <0)
- return 0;
-
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- pMission->Msg2Group(strMsg, nPlayerIndex);
- }
- }
-
- return 0;
- }
- int LuaMissionPlayerCount(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- unsigned long ulCount = 0;
- int nMissionId = 0;
- int nGroupId = 0;
- int nSubWorldIndex = 0;
- if (nParamCount < 1)
- goto lab_getmissionplayercount;
-
- if (nParamCount >= 2)
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- nGroupId = (int) Lua_ValueToNumber(L,2);
- }
- else
- {
- nMissionId = (int)Lua_ValueToNumber(L,1);
- }
-
- if (nMissionId < 0 || nGroupId <0)
- goto lab_getmissionplayercount;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- ulCount = pMission->GetGroupPlayerCount(nGroupId);
- }
- }
-
- lab_getmissionplayercount:
- Lua_PushNumber(L, ulCount);
- return 1;
- }
- int LuaSetPlayerDeathScript(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0)
- return 0;
- char * szScript = (char *)Lua_ValueToString(L, 1);
- Player[nPlayerIndex].m_dwDeathScriptId = g_FileName2Id(szScript);
- return 0;
- }
- int LuaNpcIndexToPlayerIndex(Lua_State * L)
- {
- int nResult = 0;
- int nNpcIndex = (int)Lua_ValueToNumber(L, 1);
- if (nNpcIndex <= 0 || nNpcIndex >= MAX_NPC)
- goto lab_npcindextoplayerindex;
-
- if (Npc[nNpcIndex].m_Index > 0 && Npc[nNpcIndex].IsPlayer())
- {
- if (Npc[nNpcIndex].GetPlayerIdx() > 0)
- nResult = Npc[nNpcIndex].GetPlayerIdx();
- }
-
- lab_npcindextoplayerindex:
- Lua_PushNumber(L, nResult);
- return 1;
-
- }
- //
- int LuaGetMissionPlayer_PlayerIndex(Lua_State * L)
- {
- unsigned long nResult = 0;
- int nSubWorldIndex = 0;
- if (Lua_GetTopIndex(L) < 2)
- goto lab_getmissionplayer_npcindex;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nDataIndex = (int)Lua_ValueToNumber(L, 2);
- if (nMissionId < 0 || nDataIndex < 0)
- goto lab_getmissionplayer_npcindex;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- nResult = pMission->GetMissionPlayer_PlayerIndex(nDataIndex);
- }
- }
-
- lab_getmissionplayer_npcindex:
- Lua_PushNumber(L,nResult);
- return 1;
- }
- int LuaGetMissionPlayer_DataIndex(Lua_State * L)
- {
- unsigned long nResult = 0;
- int nSubWorldIndex = 0;
- if (Lua_GetTopIndex(L) < 2)
- goto lab_getmissionplayer_dataindex;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nPlayerIndex = (int)Lua_ValueToNumber(L, 2);
- if (nMissionId < 0 || nPlayerIndex < 0)
- goto lab_getmissionplayer_dataindex;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- nResult = pMission->GetMissionPlayer_DataIndex(nPlayerIndex);
- }
- }
-
- lab_getmissionplayer_dataindex:
- Lua_PushNumber(L,nResult);
- return 1;
- }
- //SetMPParam(missionid, nDidx, vid, v)
- int LuaSetMissionPlayerParam(Lua_State * L)
- {
- int nSubWorldIndex = 0;
- if (Lua_GetTopIndex(L) < 4)
- return 0;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nDataIndex = (int)Lua_ValueToNumber(L, 2);
- int nParamId = (int)Lua_ValueToNumber(L ,3);
- int nValue = (int )Lua_ValueToNumber(L, 4);
-
- if (nMissionId < 0 || nDataIndex < 0 || nParamId > 2)
- return 0;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- if (nParamId == 1)
- pMission->m_MissionPlayer.SetParam1(nDataIndex, nValue);
- else
- pMission->m_MissionPlayer.SetParam2(nDataIndex, nValue);
- }
- }
- return 0;
- }
- int LuaGetMissionPlayerParam(Lua_State * L)
- {
- int nResult = 0;
- int nSubWorldIndex = 0;
- if (Lua_GetTopIndex(L) < 3)
- goto lab_getmissionplayerparam;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nDataIndex = (int)Lua_ValueToNumber(L, 2);
- int nParamId = (int)Lua_ValueToNumber(L ,3);
-
- if (nMissionId < 0 || nDataIndex < 0 || nParamId > 2)
- goto lab_getmissionplayerparam;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- if (nParamId == 1)
- nResult = pMission->m_MissionPlayer.GetParam1(nDataIndex);
- else
- nResult = pMission->m_MissionPlayer.GetParam2(nDataIndex);
- }
- }
- lab_getmissionplayerparam:
- Lua_PushNumber(L, nResult);
- return 1;
- }
- int LuaGetPlayerMissionGroup(Lua_State * L)
- {
- int nResult = 0;
- int nSubWorldIndex = 0;
- if (Lua_GetTopIndex(L) < 2)
- goto lab_getmissionplayergroup;
-
- nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex >= 0)
- {
- int nMissionId = (int)Lua_ValueToNumber(L, 1);
- int nNpcIndex = (int)Lua_ValueToNumber(L, 2);
-
- if (nMissionId < 0 || nNpcIndex < 0)
- goto lab_getmissionplayergroup;
-
- KMission Mission;
- Mission.SetMissionId(nMissionId);
- KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
- if (pMission)
- {
- nResult = pMission->GetMissionPlayer_GroupId(nNpcIndex);
- }
- }
- lab_getmissionplayergroup:
- Lua_PushNumber(L ,nResult);
- return 1;
-
- }
- int LuaSetPlayerRevivalOptionWhenLogout(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0) return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0)
- return 0;
- int nType = (int)Lua_ValueToNumber(L, 1);
-
- if (nType)
- Player[nPlayerIndex].SetLoginType(1);
- else
- Player[nPlayerIndex].SetLoginType(0);
-
- return 0;
- }
- int LuaSetPlayerPKValue(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- int nPKValue = (int)Lua_ValueToNumber(L,1);
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- if (Player[nPlayerIndex].m_nIndex <= 0)
- return 0;
- Player[nPlayerIndex].m_cPK.SetPKValue(nPKValue);
- return 0;
- }
- int LuaGetPlayerPKValue(Lua_State * L)
- {
- int nPKValue = 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- goto lab_getplayerpkvalue;
-
- if (Player[nPlayerIndex].m_nIndex <= 0)
- goto lab_getplayerpkvalue;
- nPKValue = Player[nPlayerIndex].m_cPK.GetPKValue();
-
- lab_getplayerpkvalue:
- Lua_PushNumber(L, nPKValue);
- return 1;
- }
- int LuaGetCurNpcIndex(Lua_State * L)
- {
- int nNpcIndex = 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- goto lab_getcurnpcindex;
-
- lab_getcurnpcindex:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nIndex);
- return 1;
- }
- //showladder(count, ladderid1, ladderid2.....)
- int LuaShowLadder(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if (nParamCount < 2)
- return 0;
- int nLadderCount = (DWORD) Lua_ValueToNumber(L, 1);
- if (nLadderCount <= 0)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
-
- if (nLadderCount > nParamCount - 1 )
- nLadderCount = nParamCount - 1;
- BYTE Buffer[sizeof(LADDER_LIST) + 50 * sizeof(DWORD)];
- LADDER_LIST * pLadderList = (LADDER_LIST*)&Buffer;
- pLadderList->ProtocolType = s2c_ladderlist;
- pLadderList->nCount = nLadderCount;
- pLadderList->wSize = sizeof(LADDER_LIST) + nLadderCount * sizeof(DWORD) - 1;
- for (int i = 0; i < nLadderCount; i ++)
- {
- pLadderList->dwLadderID[i] = (DWORD)Lua_ValueToNumber(L, i + 2);
- }
- g_pServer->PackDataToClient(Player[nPlayerIndex].m_nNetConnectIdx, &Buffer, pLadderList->wSize + 1);
- return 0;
-
- }
- int LuaSwearBrother(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- int nTeamId = Lua_ValueToNumber(L, 1);
-
- if (nTeamId >= MAX_TEAM || nTeamId < 0)
- return 0;
-
- KPlayerChat::STRINGLIST BrotherList;
- _ASSERT(g_Team[nTeamId].m_nCaptain > 0);
- std::string strCapName;
- strCapName = Npc[Player[g_Team[nTeamId].m_nCaptain].m_nIndex].Name;
- BrotherList.push_back(strCapName);
- for (int i = 0; i < g_Team[nTeamId].m_nMemNum; i++)
- {
- int nPlayerIndex = g_Team[nTeamId].m_nMember[i];
- if ( nPlayerIndex > 0 && nPlayerIndex < MAX_PLAYER)
- {
- std::string strName;
- strName = Npc[Player[nPlayerIndex].m_nIndex].Name;
- BrotherList.push_back(strName);
- }
- }
-
- KPlayerChat::MakeBrother(BrotherList);
- return 0;
- }
- int LuaMakeEnemy(Lua_State * L)
- {
-
- return 0;
- }
- int LuaAddLeadExp(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
-
- int nLeadExp = (int)Lua_ValueToNumber(L, 1);
- Player[nPlayerIndex].AddLeadExp(nLeadExp);
- return 0;
- }
- int LuaGetLeadLevel(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nLeadLevel = 0;
- if (nPlayerIndex <= 0)
- goto lab_getleadlevel;
- nLeadLevel = (int)Player[nPlayerIndex].m_dwLeadLevel;
-
- lab_getleadlevel:
- Lua_PushNumber(L, nLeadLevel);
- return 1;
- }
- int LuaAddMagicPoint(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- return 0;
- int nSkillPoint = (int)Lua_ValueToNumber(L, 1);
-
- Player[nPlayerIndex].m_nSkillPoint += nSkillPoint;
- if (Player[nPlayerIndex].m_nSkillPoint < 0)
- Player[nPlayerIndex].m_nSkillPoint = 0;
-
- return 0;
- }
- int LuaGetMagicPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nSkillPoint = 0;
- if (nPlayerIndex <= 0)
- goto lab_getmagicpoint;
-
- lab_getmagicpoint:
- Lua_PushNumber(L, Player[nPlayerIndex].m_nSkillPoint);
- return 1;
- }
- int LuaAddPropPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nPropPoint = 0;
- if (nPlayerIndex <= 0)
- return 0;
- nPropPoint = (int)Lua_ValueToNumber(L, 1);
- Player[nPlayerIndex].m_nAttributePoint += nPropPoint;
- return 0;
- }
- //PayExtPoint
- int LuaPayExtPoint(Lua_State * L)
- {
- int nResult = 0;
- int nPay = 0;
- int nPlayerIndex = 0;
- if (Lua_GetTopIndex(L) < 1)
- goto lab_payextpoint;
-
- nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- goto lab_payextpoint;
- nPay = Lua_ValueToNumber(L, 1);
- if (nPay < 0)
- goto lab_payextpoint;
- nResult = Player[nPlayerIndex].PayExtPoint(nPay);
- lab_payextpoint:
- Lua_PushNumber(L, nResult);
- return 1;
- }
- //PayExtPoint
- int LuaGetExtPoint(Lua_State * L)
- {
- int nResult = 0;
- int nPlayerIndex = 0;
- if (Lua_GetTopIndex(L) < 1)
- goto lab_getextpoint;
-
- nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- goto lab_getextpoint;
-
- nResult = Player[nPlayerIndex].GetExtPoint();
-
- lab_getextpoint:
- Lua_PushNumber(L, nResult);
- return 1;
- }
- int LuaGetRestPropPoint(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- int nPropPoint = 0;
- if (nPlayerIndex <= 0)
- goto lab_getrestproppoint;
- nPropPoint = Player[nPlayerIndex].m_nAttributePoint;
-
- lab_getrestproppoint:
- Lua_PushNumber(L, nPropPoint);
- return 1;
- }
- //Msg2GM(str, id)
- int LuaMsgToGameMaster(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if ( nParamCount < 1 )
- return 0;
- int nParamID = 0;
- const char * szMsg = Lua_ValueToString(L, 1) ;
- if (!szMsg)
- return 0;
- if (nParamCount < 2)
- {
- nParamID = 0;
- }
- else
- {
- nParamID = (int) Lua_ValueToNumber(L, 2);
- }
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex > 0)
- {
- char szID[32];
- sprintf(szID, "%d", nParamID);
- //KPlayerChat::SendInfoToGM(Player[nPlayerIndex].m_AccoutName, Npc[Player[nPlayerIndex].m_nIndex].Name, (char *) szMsg, strlen(szMsg) );
- KPlayerChat::SendInfoToGM("GM", szID, (char *) szMsg, strlen(szMsg) );
- }
- return 0;
- }
- //Msg2IP(IP, ID, str)
- int LuaMsgToIP(Lua_State * L)
- {
- int nParamCount = Lua_GetTopIndex(L);
- if ( nParamCount < 3 )
- return 0;
- int nIP = 0;
- const char * szIP = Lua_ValueToString(L, 1) ;
- nIP = _a2ip(szIP);
- if (nIP == 0)
- return 0;
- int nID = (int) Lua_ValueToNumber(L, 2);
- const char * szMsg = Lua_ValueToString(L, 3) ;
- if (!szMsg)
- return 0;
- int nParamID = 0;
- if (nParamCount < 4)
- {
- nParamID = 0;
- }
- else
- {
- nParamID = (int) Lua_ValueToNumber(L, 4);
- }
- char szID[32];
- sprintf(szID, "%d", nParamID);
- KPlayerChat::SendInfoToIP(nIP, nID, "GM", szID, (char *) szMsg, strlen(szMsg) );
- return 0;
- }
- int LuaGetPlayerInfo(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- char szDesMsg[250];
- char szMsg[800];
- int nNpcIdx = 0;
- KNpc * pNpc = NULL;
- KPlayer* pPlayer = NULL;
- szDesMsg[0] = 0;
- if (nPlayerIndex <= 0)
- goto lab_getplayerinfo;
-
- pPlayer = &Player[nPlayerIndex];
- nNpcIdx = pPlayer->m_nIndex;
- pNpc = &Npc[nNpcIdx];
- sprintf(szMsg, "Name:%s,Lvl:%d,IP:%s,Lf:%d|%d,Mn:%d|%d,Mny:%d,sp:%d,ap:%d", pNpc->Name, pNpc->m_Level, g_pServer->GetClientInfo(pPlayer->m_nNetConnectIdx), pNpc->m_CurrentLife, pNpc->m_CurrentLifeMax, pNpc->m_CurrentMana, pNpc->m_CurrentManaMax, pPlayer->m_ItemList.GetMoney(room_equipment), pPlayer->m_nSkillPoint, pPlayer->m_nAttributePoint );
- g_StrCpyLen(szDesMsg, szMsg, 250);
-
- lab_getplayerinfo:
- Lua_PushString(L, szDesMsg);
- return 1;
- }
- int LuaGetIP(Lua_State * L)
- {
- int nPlayerIndex = GetPlayerIndex(L);
- char szDesMsg[200];
- szDesMsg[0] = 0;
- KPlayer * pPlayer = NULL;
- if (nPlayerIndex <= 0)
- goto lab_getplayerip;
- pPlayer = &Player[nPlayerIndex];
- strcpy(szDesMsg, g_pServer->GetClientInfo(pPlayer->m_nNetConnectIdx));
-
- lab_getplayerip:
- Lua_PushString(L, szDesMsg);
- return 1;
- }
- int LuaSetDeathPunish(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex <= 0)
- {
- int nState = Lua_ValueToNumber(L, 1);
- if (nState == 0)
- Npc[Player[nPlayerIndex].m_nIndex].m_nCurPKPunishState = 0;
- else
- Npc[Player[nPlayerIndex].m_nIndex].m_nCurPKPunishState = enumDEATH_MODE_PKBATTLE_PUNISH;
- }
- return 0;
- }
- int LuaHideNpc(Lua_State * L)
- {
- if (Lua_GetTopIndex(L) < 2)
- return 0;
-
- int nNpcIndex = 0;
-
- if (Lua_IsNumber(L,1))
- {
- nNpcIndex = (int)Lua_ValueToNumber(L, 1);
- }
- else
- {
- const char * szName = Lua_ValueToString(L, 1);
- int nSubWorldIndex = GetSubWorldIndex(L);
- if (nSubWorldIndex < 0)
- return 0;
-
- nNpcIndex = SubWorld[nSubWorldIndex].FindNpcFromName(szName);
- }
-
- if (nNpcIndex > 0 || nNpcIndex < MAX_NPC)
- {
- int nFrame = Lua_ValueToNumber(L, 2);
- if (nFrame <= 0)
- nFrame = 1;
-
- Npc[nNpcIndex].ExecuteRevive();
- Npc[nNpcIndex].m_Frames.nTotalFrame = nFrame;
- Npc[nNpcIndex].m_Frames.nCurrentFrame = 0;
- }
-
- return 0;
- }
- #endif
- int LuaPlayMusic(Lua_State * L)//PlayMusic(musicname,loop=1, vol );
- {
- if (Lua_GetTopIndex(L) < 1)
- return 0;
-
- int nPlayerIndex = GetPlayerIndex(L);
- if (nPlayerIndex < 0) return 0;
-
- PLAYER_SCRIPTACTION_SYNC UiInfo;
- UiInfo.m_bUIId = UI_PLAYMUSIC;
- UiInfo.m_bOptionNum = 1;
- UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
-
- int nMsgId = 0;
-
- g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), sizeof(UiInfo.m_pContent));
- UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
- UiInfo.m_bParam1 = 0;
-
- #ifndef _SERVER
- UiInfo.m_bParam2 = 0;
- #else
- UiInfo.m_bParam2 = 1;
- #endif
-
- Player[nPlayerIndex].DoScriptAction(&UiInfo);
- return 0;
- }
- int LuaFadeInMusic(Lua_State * L)
- {
- return 0;
- }
- int LuaFadeOutMusic(Lua_State * L)
- {
- return 0;
- }
- #ifndef _SERVER
- int LuaPlaySound(Lua_State * L)
- {
-
- return 0;
- }
- int LuaPlaySprMovie(Lua_State * L)
- {
- return 0;
- }
- #endif
- TLua_Funcs GameScriptFuns[] =
- {
- //通用指令
-
- {"Say", LuaSelectUI},
- {"Talk", LuaTalkUI},
- {"GetTaskTemp", LuaGetTempTaskValue},
- {"SetTaskTemp", LuaSetTempTaskValue},
- {"Message", LuaMessage},
-
- {"GetBit", LuaGetBit},
- {"GetByte", LuaGetByte},
- {"SetBit", LuaSetBit},
- {"SetByte", LuaSetByte},
- {"Include",LuaIncludeFile},
- {"PutMessage", LuaSendMessageInfo},
- {"AddGlobalNews",LuaAddGlobalNews},
- {"AddGlobalTimeNews",LuaAddGlobalTimeNews},
- {"AddGlobalCountNews",LuaAddGlobalCountNews },
- {"AddLocalNews",LuaAddLocalNews},
- {"AddLocalTimeNews",LuaAddLocalTimeNews},
- {"AddLocalCountNews",LuaAddLocalCountNews },
-
- //服务器端脚本指令
- #ifdef _SERVER
- //-----------------基本功能
- {"AddRepute", LuaModifyRepute}, //修改声望值
- {"GetRepute",LuaGetRepute},
- {"GetNpcIdx", LuaGetCurNpcIndex},
-
- {"SetTimer", LuaSetTimer}, //SetTimer(时间量, 时间TaskId):给玩家打开计时器,时间到时将自动调用OnTimer函数
- {"StopTimer", LuaStopTimer}, //StopTimer():关闭当前玩家的计时器
- {"GetRestTime", LuaGetRestTime}, //GetRestTime:获得计时器将触发的剩于时间
- {"GetTimerId", LuaGetCurTimerId}, //CurTimerId = GetTimerId():获得当前执行的计时器的id,如果没有则返回0
- {"GetTask", LuaGetTaskValue}, //GetTask(任务号):获得当前玩家该任务号的值
- {"SetTask", LuaSetTaskValue}, //SetTask(任务号,值):设置任务值
- {"IsCaptain", LuaIsLeader}, //IsCaptain()是否为队长
- {"GetTeam", LuaGetTeamId}, //GetTeam()返回玩家队伍ID
- {"GetTeamSize", LuaGetTeamSize}, //GetTeamSize()
- {"LeaveTeam", LuaLeaveTeam}, //LeaveTeam()让玩家离开自身队伍
- {"Msg2Player", LuaMsgToPlayer }, //Msg2Player(消息)
- {"Msg2Team", LuaMsgToTeam}, //Msg2Team(消息)通知玩家的组
- {"Msg2SubWorld", LuaMsgToSubWorld}, //Msg2SubWorld(消息)通知世界
- {"Msg2Region", LuaMsgToAroundRegion},//Msg2Region(消息)通知周围Region
- {"Msg2GM", LuaMsgToGameMaster}, //Msg2GM(StrInfo)
- {"Msg2IP", LuaMsgToIP}, //Msg2IP(IP, ID, StrInfo)
- {"GetInfo", LuaGetPlayerInfo}, //str = GetInfo()
- {"GetIP", LuaGetIP},
- {"SetPos", LuaSetPos}, //SetPos(x,y)进入某点
- {"GetPos", LuaGetPos}, //GetPos() return x,y,subworldindex
- {"GetWorldPos", LuaGetNewWorldPos}, //W,X,Y = GetWorldPos()返回于NewWorld配陪的坐标
- {"NewWorld", LuaEnterNewWorld},
- {"DropItem", LuaDropItem}, //DropItem(NpcId, 物品id或物品名)
- {"AddItem", LuaAddItem}, //AddItem(nItemClass, nDetailType, nParticualrType, nLevel, nSeries, nLuck, nItemLevel..6)
- {"AddEventItem", LuaAddEventItem }, //AddEventItem(事件物品ID)
- {"DelItem", LuaDelItem}, //
- {"HaveItem", LuaHaveItem},
- {"GetItemCount", LuaGetTaskItemCount}, //GetItemCount(TaskItemName Or TaskItemId)
- {"AddMagic", LuaAddMagic}, //AddMagic(魔法id或魔法名)给玩家加某个魔法
- {"DelMagic", LuaDelMagic}, //DelMagic(魔法id或魔法名)
- {"HaveMagic", LuaHaveMagic}, //HaveMagic(魔法id或魔法名)返回0或1
- {"GetMagicLevel", LuaGetMagicLevel}, //GetMagicLevel(魔法id或魔法名)返回等级
- {"AddMagicPoint", LuaAddMagicPoint},
- {"GetMagicPoint", LuaGetMagicPoint},
-
- {"SubWorldID2Idx", LuaSubWorldIDToIndex}, //SubWorldID2Idx
-
-
- {"AddLeadExp", LuaAddLeadExp},
- {"GetLeadLevel", LuaGetLeadLevel},
-
- {"SetFightState", LuaSetFightState},
- {"GetFightState", LuaGetFightState},
-
- {"AddNpc", LuaAddNpc}, //AddNpc(人物模板id或人物模板名,所处世界id,点坐标x,点坐标y),返回npcid值
- {"DelNpc", LuaDelNpc}, //DelNpc(Npcid)
- {"SetNpcScript", LuaSetNpcActionScript}, //SetNpcScript(npcid, 脚本文件名)设置npc当前的脚本
- {"SetRevPos", LuaSetPlayerRevivalPos},//SetRevPos(点位置X,点位置Y)设置玩家的当前世界的等入点位置
- {"SetTempRevPos", LuaSetDeathRevivalPos}, //SetTempRevPos(subworldid, x, y ) or SetTempRevPos(id);
- {"GetCurCamp", LuaGetPlayerCurrentCamp},//GetCurCamp()获得玩家的当前阵营
- {"GetCamp", LuaGetPlayerCamp },//GetCamp()获得玩家阵营
- {"SetCurCamp", LuaSetPlayerCurrentCamp},//SetCurCamp(阵营号):设置玩家当前阵营
- {"SetCamp", LuaSetPlayerCamp}, //SetCamp(阵营号):设置阵营
- {"RestoreCamp", LuaRestorePlayerCamp },//RestoreCamp()恢复阵营
- {"GetFaction", LuaGetPlayerFaction, },//GetFaction()获得玩家的门派名
- {"SetFaction", LuaChangePlayerFaction}, //SetFaction(门派名):设置玩家门派名
- {"GetColdR", LuaGetPlayerColdResist},
- {"SetColdR", LuaGetPlayerColdResist},
- {"GetFireR", LuaGetPlayerFireResist },
- {"SetFireR", LuaSetPlayerFireResist },
- {"GetLightR", LuaGetPlayerLightResist },
- {"SetLightR", LuaSetPlayerLightResist},
- {"GetPoisonR", LuaGetPlayerPoisonResist},
- {"SetPoisonR", LuaSetPlayerPoisonResist},
- {"GetPhyR", LuaGetPlayerPhysicsResist },
- {"SetPhyR", LuaSetPlayerPhysicsResist },
- {"GetExp", LuaGetPlayerExp }, //GetExp():获得玩家的当前经验值
- {"AddExp", LuaModifyPlayerExp}, //AddExp(经验值,对方等级,是否组队共享经验值)
- {"AddOwnExp", LuaAddOwnExp }, //AddOwnExp(Exp),给玩家直接加经验
- {"GetLife", LuaGetPlayerLife}, //GetLife()获得玩家的生命值
- {"RestoreLife", LuaRestorePlayerLife}, //RestoreLife()恢复玩家的生命
- {"GetMana", LuaGetPlayerMana}, //GetMana()获得玩家的Mana
- {"RestoreMana", LuaRestorePlayerMana}, //RestoreMana()恢复玩家的Mana
- {"GetStamina", LuaGetPlayerStamina}, //GetStamina()获得玩家Stamina
- {"RestoreStamina", LuaRestorePlayerStamina}, //RestoreMana()恢复玩家的Stamina
- {"GetDefend", LuaGetPlayerDefend}, //GetDefend()获得玩家的防御力
- {"GetSex", LuaGetPlayerSex}, //GetSex()获得玩家的性别
- {"GetSeries", LuaGetPlayerSeries}, //GetSeries()获得玩家的系0man/1woman
- {"SetSeries", LuaSetPlayerSeries}, //SetSeries(性别号)
- {"GetName", LuaGetPlayerName}, //GetName()获得玩家的姓名
- {"GetUUID", LuaGetPlayerID}, //GetUUID()获得玩家的唯一ID
- {"GetLeadExp", LuaGetPlayerLeadExp}, //GetLeadExp()获得玩家的统率经验值
- {"GetLeadLevel", LuaGetPlayerLeadLevel}, //GetLeadLevel()获得玩家的统率等级
- {"GetLevel", LuaGetLevel}, //GetLevel()GetPlayers Level
- {"GetRestAP", LuaGetPlayerRestAttributePoint},//GetRestAP()获得玩家的剩于属性点数
- {"GetRestSP", LuaGetPlayerRestSkillPoint}, //GetRestSP()获得玩家的剩于技能点数
- {"GetLucky", LuaGetPlayerLucky}, //GetLucky()获得玩家的幸运值
- {"GetEng", LuaGetPlayerEngergy}, //GetEng()获得玩家的力量值Eng
- {"GetDex", LuaGetPlayerDexterity}, //GetDex()获得玩家的Dex
- {"GetStrg", LuaGetPlayerStrength}, //GetStrg()
- {"GetVit", LuaGetPlayerVitality}, //GetVit()
- {"GetCash", LuaGetPlayerCashMoney}, //GetCash()获得玩家的现金
- {"Pay", LuaPlayerPayMoney}, //Pay(金额数)扣除玩家金钱成功返回1,失败返回0
- {"Earn", LuaPlayerEarnMoney}, //Earn(金额数)增加玩家金钱
- {"PrePay", LuaPlayerPrePayMoney}, //付定金,成功返回1,失败返回0
- {"ExeScript", LuaPlayerExecuteScript}, //ExeScript(脚本文件名,参数),执行时会调用main函数
- {"AttackNpc", LuaAttackNpc}, //AttackNpc(NpcDwid,物理伤害值,冰,火,电,毒)
- {"KillNpc", LuaKillNpc}, //KillNpc(NpcDWID)
- {"KillPlayer", LuaKillPlayer}, //KillPlayer();
- {"Sale", LuaSale}, //Sale(SaleId)买卖,SaleId为便卖的物品信息列表id
- {"UseTownPortal", LuaUseTownPortal },
- {"ReturnFromPortal",LuaReturnFromTownPortal },
- {"SetNpcCurCamp", LuaSetNpcCurCamp},
- {"OpenBox", LuaOpenBox},
- {"AddStation", LuaAddPlayerStation},
- {"AddTermini", LuaAddPlayerWayPoint},
- {"GetStation", LuaGetPlayerStation },
- {"GetStationCount", LuaGetPlayerStationCount},
-
- {"GetCityCount", LuaGetAllStationCount},
- {"GetCity", LuaGetCity},
-
- {"GetWayPoint", LuaGetPlayerWayPoint},
- {"GetStationName", LuaGetStationName},
- {"GetWayPointName", LuaGetWayPointName},
- {"GetPrice2Station", LuaGetPriceToStation},
- {"GetPrice2WayPoint", LuaGetPriceToWayPoint },
- {"GetStationPos", LuaGetStationPos},
- {"GetWayPointPos", LuaGetWayPointPos},
- {"GetPlayerCount", LuaGetPlayerCount},
- {"GetRank", LuaGetRank},//GetRank()
- {"SetRank", LuaSetRank},//SetRank(id)
- {"SetPropState", LuaSetObjPropState},//SetPropState( hide = 1) hide obj
- {"GetServerName", LuaGetServerName},
-
-
- //------------------Station Script ---------------
- {"GetWharfName", LuaGetDockName},
- {"GetWharfCount", LuaGetDockCount},
- {"GetWharfPrice", LuaGetDockPrice},
- {"GetWharf", LuaGetDock},
- {"GetWharfPos", LuaGetDockPos},
- {"GetTerminiFState", LuaGetWayPointFightState},
- //------------------------------------------------
- {"KickOutPlayer", LuaKickOutPlayer},
- {"KickOutSelf", LuaKickOutSelf},
- {"GetSkillId", LuaGetSkillIdInSkillList},
- {"SetSkillLevel", LuaSetSkillLevel},
- {"SetChatFlag", LuaSetPlayerChatForbiddenFlag},
- //------------------------------------------------
-
- {"AddNote", LuaAddNote},
- //-----------------Mission Script-----------------
- {"GetMissionV", LuaGetMissionValue},//GetMissionV(Vid)
- {"SetMissionV", LuaSetMissionValue},//SetMissionV(Vid, Value)
- {"GetGlbMissionV", LuaGetGlobalMissionValue },
- {"SetGlbMissionV", LuaSetGlobalMissionValue },
- {"OpenMission", LuaInitMission},//OpenMission(missionid)
- {"RunMission", LuaRunMission},
- {"CloseMission", LuaCloseMission},//CloseMission(missionid)
- {"StartMissionTimer", LuaStartMissionTimer},////StartMissionTimer(missionid, timerid, time)
- {"StopMissionTimer", LuaStopMissionTimer},
- {"GetMSRestTime", LuaGetMissionRestTime}, //GetMSRestTime(missionid, timerid)
- {"GetMSIdxGroup",LuaGetPlayerMissionGroup},//GetPlayerGroup(missionid, playerid);
-
- {"AddMSPlayer", LuaAddMissionPlayer},
- {"DelMSPlayer", LuaRemoveMissionPlayer},
- {"GetNextPlayer", LuaGetNextPlayer},
- {"PIdx2MSDIdx", LuaGetMissionPlayer_DataIndex},//(missionid, pidx)
- {"MSDIdx2PIdx", LuaGetMissionPlayer_PlayerIndex},//(missionid, dataidx)
- {"NpcIdx2PIdx", LuaNpcIndexToPlayerIndex},
- {"GetMSPlayerCount", LuaMissionPlayerCount},//GetMSPlayerCount(missionid, group = 0)
- {"RevivalAllNpc", LuaRevivalAllNpc},
-
- {"SetPMParam", LuaSetMissionPlayerParam },
- {"GetPMParam", LuaGetMissionPlayerParam},
- {"Msg2MSGroup", LuaMissionMsg2Group},
- {"Msg2MSAll", LuaMissionMsg2All},
- {"Msg2MSPlayer", LuaMissionMsg2Player},
- {"SetDeathScript", LuaSetPlayerDeathScript},
- {"Death", LuaKillNpc},
- {"HideNpc", LuaHideNpc} ,//HideNpc(npcindex/npcname, hidetime)
- {"SetLogoutRV", LuaSetPlayerRevivalOptionWhenLogout},
- {"SetCreateTeam",LuaSetCreateTeamOption},
- {"GetPK", LuaGetPlayerPKValue}, //pkValue = GetPK()
- {"SetPK", LuaSetPlayerPKValue}, //SetPK(pkValue)
- //------------------------------------------------
- //排名相关函数
- {"ShowLadder", LuaShowLadder}, //ShowLadder(LadderCount, LadderId1,LadderId2,...);
- //------------------------------------------------
- {"OpenTong", LuaOpenTong}, //OpenTong()通知玩家打开帮会界面
- {"SetPunish", LuaSetDeathPunish},// SetPunish(0/1) 0表示不受任何惩罚
- //-------------------------------------------------
- //结拜
- { "SwearBrother", LuaSwearBrother}, // ret = SwearBrother(TeamId);
- {"MakeEnemy", LuaMakeEnemy}, //结仇 MakeEnemy(enemyname)
- {"RollbackSkill", LuaRollBackSkills},
- {"UpdateSkill", LuaUpdateSkillList},
- //-------------------------------------------------
- {"AddProp", LuaAddPropPoint},//加玩家属性点
- {"GetProp", LuaGetRestPropPoint },
-
- {"GetExtPoint", LuaGetExtPoint},
- {"PayExtPoint", LuaPayExtPoint},
-
- //{"Trade", LuaTrade }, //Trade("maininfo", "IniFileName.ini的路径名")
- //Trade("MainInfo", n, "item1|price1|function1", "item2|price2|function2", ......, "itemn|pricen|functionn")
-
- //客户端脚本指令
- #else
- {"PlaySound", LuaPlaySound}, //PlaySound(Sound);
- {"PlaySprMovie",LuaPlaySprMovie},//PlaySprMovie(npcindex, Movie, times)
- #endif
- {"PlayMusic", LuaPlayMusic}, //PlayMusic(Music,Loop)
- {"FadeInMusic",LuaFadeInMusic},
- {"FadeOutMusic",LuaFadeOutMusic},
- };
- TLua_Funcs WorldScriptFuns[] =// 非指对玩家的脚本指令集
- {
- //通用指令
- {"AddLocalNews",LuaAddLocalNews},
- {"AddLoaclTimeNews",LuaAddLocalTimeNews},
- {"AddLocalCountNews",LuaAddLocalCountNews },
- //服务器端脚本指令
- #ifdef _SERVER
- {"Msg2SubWorld", LuaMsgToSubWorld}, //Msg2SubWorld(消息)通知世界
- {"Msg2IP", LuaMsgToIP}, //Msg2IP(IP, ID, StrInfo)
- {"SubWorldID2Idx", LuaSubWorldIDToIndex}, //SubWorldID2Idx
- {"GetServerName", LuaGetServerName},
- {"KickOutPlayer", LuaKickOutPlayer},
- {"KickOutAccount", LuaKickOutAccount},
- #endif
- // {"GetMissionV", LuaGetMissionValue},//GetMissionV(Vid)
- // {"SetMissionV", LuaSetMissionValue},//SetMissionV(Vid, Value)
- // {"GetGlbMissionV", LuaGetGlobalMissionValue },
- // {"SetGlbMissionV", LuaSetGlobalMissionValue },
- // {"OpenMission", LuaInitMission},//OpenMission(missionid)
- // {"RunMission", LuaRunMission},
- // {"CloseMission", LuaCloseMission},//CloseMission(missionid)
- // {"StartMissionTimer", LuaStartMissionTimer},////StartMissionTimer(missionid, timerid, time)
- // {"StopMissionTimer", LuaStopMissionTimer},
- // {"GetMSRestTime", LuaGetMissionRestTime}, //GetMSRestTime(missionid, timerid)
- // {"GetMSIdxGroup",LuaGetPlayerMissionGroup},//GetPlayerGroup(missionid, playerid);
- //
- // {"AddMSPlayer", LuaAddMissionPlayer},
- // {"DelMSPlayer", LuaRemoveMissionPlayer},
- // {"GetNextPlayer", LuaGetNextPlayer},
- // {"PIdx2MSDIdx", LuaGetMissionPlayer_DataIndex},//(missionid, pidx)
- // {"MSDIdx2PIdx", LuaGetMissionPlayer_PlayerIndex},//(missionid, dataidx)
- // {"NpcIdx2PIdx", LuaNpcIndexToPlayerIndex},
- //{"GetMSPlayerCount", LuaMissionPlayerCount},//GetMSPlayerCount(missionid, group = 0)
- // {"RevivalAllNpc", LuaRevivalAllNpc},
-
- //{"SetPMParam", LuaSetMissionPlayerParam },
- //{"GetPMParam", LuaGetMissionPlayerParam},
- //{"Msg2MSGroup", LuaMissionMsg2Group},
- //{"Msg2MSAll", LuaMissionMsg2All},
- //{"Msg2MSPlayer", LuaMissionMsg2Player},
- };
- int g_GetGameScriptFunNum()
- {
- return sizeof(GameScriptFuns) / sizeof(GameScriptFuns[0]);
- }
- int g_GetWorldScriptFunNum()
- {
- return sizeof(WorldScriptFuns) / sizeof(WorldScriptFuns[0]);
- }