ScriptFuns.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:129k
源码类别:

模拟服务器

开发平台:

C/C++

  1. if (nPlayerIndex > 0)
  2. {
  3. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_Level);
  4. else
  5. Lua_PushNil(L);
  6. return 1;
  7. }
  8. int LuaGetPlayerLife(Lua_State * L)
  9. {
  10. int nPlayerIndex = GetPlayerIndex(L);
  11. if (nPlayerIndex > 0)
  12. {
  13. {
  14. int nType = (int)Lua_ValueToNumber(L,1);
  15. switch((int)Lua_ValueToNumber(L,1))
  16. {
  17. case 0:
  18. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentLife);break;
  19. case 1:
  20. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LifeMax); break;
  21. case 2:
  22. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_LifeMax);break;
  23. default:
  24. Lua_PushNil(L);
  25. }
  26. }
  27. else
  28. Lua_PushNil(L);
  29. return 1;
  30. }
  31. int LuaRestorePlayerLife(Lua_State * L)
  32. {
  33. int nPlayerIndex = GetPlayerIndex(L);
  34. if (nPlayerIndex > 0)
  35. {
  36. Npc[Player[nPlayerIndex].m_nIndex].RestoreLife();
  37. }
  38. return 0;
  39. }
  40. int LuaRestorePlayerMana(Lua_State * L)
  41. {
  42. int nPlayerIndex = GetPlayerIndex(L);
  43. if (nPlayerIndex > 0)
  44. {
  45. Npc[Player[nPlayerIndex].m_nIndex].RestoreMana();
  46. }
  47. return 0;
  48. }
  49. int LuaRestorePlayerStamina(Lua_State * L)
  50. {
  51. int nPlayerIndex = GetPlayerIndex(L);
  52. if (nPlayerIndex > 0)
  53. {
  54. Npc[Player[nPlayerIndex].m_nIndex].RestoreStamina();
  55. }
  56. return 0;
  57. }
  58. int LuaGetPlayerLifeReplenish(Lua_State * L)
  59. {
  60. MacroFun_GetPlayerInfoInt( L, m_LifeReplenish);
  61. }
  62. int LuaGetPlayerMana(Lua_State * L)
  63. {
  64. int nPlayerIndex = GetPlayerIndex(L);
  65. if (nPlayerIndex > 0)
  66. {
  67. {
  68. int nType = (int)Lua_ValueToNumber(L,1);
  69. switch((int)Lua_ValueToNumber(L,1))
  70. {
  71. case 0:
  72. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentMana);break;
  73. case 1:
  74. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ManaMax); break;
  75. case 2:
  76. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_ManaMax);break;
  77. default:
  78. Lua_PushNil(L);
  79. }
  80. }
  81. else
  82. Lua_PushNil(L);
  83. return 1;
  84. }
  85. int LuaGetPlayerStamina(Lua_State * L)
  86. {
  87. int nPlayerIndex = GetPlayerIndex(L);
  88. if (nPlayerIndex > 0)
  89. {
  90. {
  91. int nType = (int)Lua_ValueToNumber(L,1);
  92. switch((int)Lua_ValueToNumber(L,1))
  93. {
  94. case 0:
  95. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_CurrentStamina);break;
  96. case 1:
  97. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_StaminaMax); break;
  98. case 2:
  99. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_StaminaMax);break;
  100. default:
  101. Lua_PushNil(L);
  102. }
  103. }
  104. else
  105. Lua_PushNil(L);
  106. return 1;
  107. }
  108. int LuaGetPlayerManaReplenish(Lua_State * L)
  109. {
  110. MacroFun_GetPlayerInfoInt(L , m_ManaReplenish);
  111. }
  112. int LuaGetPlayerDefend(Lua_State * L)
  113. {
  114.     MacroFun_GetPlayerInfoInt(L , m_Defend);
  115. }
  116. int LuaGetPlayerSex(Lua_State * L)
  117. {
  118. MacroFun_GetPlayerInfoInt(L , m_nSex);
  119. }
  120. int LuaGetPlayerIndex(Lua_State * L)
  121. {
  122. MacroFun_GetPlayerInfoInt(L , GetPlayerIdx());
  123. return 0;
  124. }
  125. int LuaGetPlayerSeries(Lua_State * L)
  126. {
  127. MacroFun_GetPlayerInfoInt(L , m_Series);
  128. }
  129. int LuaSetPlayerSeries(Lua_State * L)
  130. {
  131. int nPlayerIndex = GetPlayerIndex(L);
  132. if (nPlayerIndex > 0)
  133. {
  134. int nValue = (int)Lua_ValueToNumber(L,1);
  135. Npc[Player[nPlayerIndex].m_nIndex].SetSeries(nValue);
  136. return 0;
  137.     
  138. }
  139. int LuaGetPlayerCount(Lua_State * L)
  140. {
  141. Lua_PushNumber(L, PlayerSet.GetPlayerNumber());
  142. return 1;
  143. }
  144. int LuaGetPlayerName(Lua_State * L)
  145. {
  146.     int nPlayerIndex = GetPlayerIndex(L);
  147. if (nPlayerIndex > 0)
  148. {
  149.         Lua_PushString(L, Player[nPlayerIndex].m_PlayerName);
  150. }
  151. else
  152. Lua_PushNil(L);
  153. return 1;
  154. }
  155. int LuaGetPlayerID(Lua_State * L)
  156. {
  157. int nPlayerIndex = GetPlayerIndex(L);
  158. if (nPlayerIndex > 0)
  159. {
  160.         Lua_PushNumber(L, Player[nPlayerIndex].m_dwID);
  161. }
  162. else
  163. Lua_PushNil(L);
  164. return 1;
  165. }
  166. int LuaGetPlayerLeadExp(Lua_State * L)
  167. {
  168. int nPlayerIndex = GetPlayerIndex(L);
  169. if (nPlayerIndex > 0)
  170. {
  171.         Lua_PushNumber(L, Player[nPlayerIndex].m_dwLeadExp);
  172. }
  173. else
  174. Lua_PushNil(L);
  175. return 1;
  176. }
  177. int LuaGetPlayerLeadLevel(Lua_State * L)
  178. {
  179. int nPlayerIndex = GetPlayerIndex(L);
  180. if (nPlayerIndex > 0)
  181. {
  182.         Lua_PushNumber(L, Player[nPlayerIndex].m_dwLeadLevel);
  183. }
  184. else
  185. Lua_PushNil(L);
  186. return 1;
  187. }
  188. int LuaGetPlayerRestAttributePoint(Lua_State * L)
  189. {
  190. int nPlayerIndex = GetPlayerIndex(L);
  191. if (nPlayerIndex > 0)
  192. {
  193.         Lua_PushNumber(L, Player[nPlayerIndex].m_nAttributePoint);
  194. }
  195. else
  196. Lua_PushNil(L);
  197. return 1;
  198. }
  199. int LuaGetPlayerRestSkillPoint(Lua_State * L)
  200. {
  201.     int nPlayerIndex = GetPlayerIndex(L);
  202. if (nPlayerIndex > 0)
  203. {
  204.         Lua_PushNumber(L, Player[nPlayerIndex].m_nSkillPoint);
  205. }
  206. else
  207. Lua_PushNil(L);
  208. return 1;
  209. }
  210. /*
  211. int LuaModifyPlayerRestSkillPoint(Lua_State *L)
  212. {
  213. //Question
  214. int nPlayerIndex = GetPlayerIndex(L);
  215. if (nPlayerIndex > 0)
  216. {
  217. int nDValue = (int)Lua_ValueToNumber(L, 1);
  218.   int nNewSkillPoint = Player[nPlayerIndex].m_nSkillPoint + nDValue;
  219.   if (nNewSkillPoint < 0 ) return 0;
  220.   
  221. Player[nPlayerIndex].m_nSkillPoint = nNewSkillPoint;
  222. }
  223.   return 0;
  224.   }
  225. */
  226. //基本属性
  227. int LuaGetPlayerLucky(Lua_State * L)
  228. {
  229.     int nPlayerIndex = GetPlayerIndex(L);
  230. if (nPlayerIndex > 0)
  231. {
  232. int nType = (int)Lua_ValueToNumber(L,1);
  233. switch((int)Lua_ValueToNumber(L,1))
  234. {
  235. case 0:
  236. Lua_PushNumber(L, Player[nPlayerIndex].m_nCurLucky);break;
  237. case 1:
  238. Lua_PushNumber(L, Player[nPlayerIndex].m_nLucky);break;
  239. case 2:
  240. Lua_PushNumber(L, Player[nPlayerIndex].m_nLucky);break;
  241. default:
  242. Lua_PushNil(L);
  243. }
  244. return 1;
  245. }
  246. int LuaGetPlayerEngergy(Lua_State * L)
  247. {
  248.     int nPlayerIndex = GetPlayerIndex(L);
  249. if (nPlayerIndex > 0)
  250. {
  251. int nType = (int)Lua_ValueToNumber(L,1);
  252. switch((int)Lua_ValueToNumber(L,1))
  253. {
  254. case 0:
  255. Lua_PushNumber(L, Player[nPlayerIndex].m_nCurEngergy);break;
  256. case 1:
  257. Lua_PushNumber(L, Player[nPlayerIndex].m_nEngergy);break;
  258. case 2:
  259. Lua_PushNumber(L, Player[nPlayerIndex].m_nEngergy);break;
  260. default:
  261. Lua_PushNil(L);
  262. }
  263. }
  264. return 1;
  265. }
  266. int LuaGetPlayerDexterity(Lua_State * L)
  267. {
  268.     int nPlayerIndex = GetPlayerIndex(L);
  269. if (nPlayerIndex > 0)
  270. {
  271. int nType = (int)Lua_ValueToNumber(L,1);
  272. switch((int)Lua_ValueToNumber(L,1))
  273. {
  274. case 0:
  275. Lua_PushNumber(L, Player[nPlayerIndex].m_nCurDexterity);break;
  276. case 1:
  277. Lua_PushNumber(L, Player[nPlayerIndex].m_nDexterity);break;
  278. case 2:
  279. Lua_PushNumber(L, Player[nPlayerIndex].m_nDexterity);break;
  280. default:
  281. Lua_PushNil(L);
  282. }
  283. return 1;
  284. }
  285. int LuaGetPlayerStrength(Lua_State * L)
  286. {
  287. int nPlayerIndex = GetPlayerIndex(L);
  288. if (nPlayerIndex > 0)
  289. {
  290. int nType = (int)Lua_ValueToNumber(L,1);
  291. switch((int)Lua_ValueToNumber(L,1))
  292. {
  293. case 0:
  294. Lua_PushNumber(L, Player[nPlayerIndex].m_nCurStrength);break;
  295. case 1:
  296. Lua_PushNumber(L, Player[nPlayerIndex].m_nStrength);break;
  297. case 2:
  298. Lua_PushNumber(L, Player[nPlayerIndex].m_nStrength);break;
  299. default:
  300. Lua_PushNil(L);
  301. }
  302. return 1;
  303. }
  304. int LuaGetPlayerVitality(Lua_State * L)
  305. {
  306. int nPlayerIndex = GetPlayerIndex(L);
  307. if (nPlayerIndex > 0)
  308. {
  309. int nType = (int)Lua_ValueToNumber(L,1);
  310. switch((int)Lua_ValueToNumber(L,1))
  311. {
  312. case 0:
  313. Lua_PushNumber(L, Player[nPlayerIndex].m_nCurVitality);break;
  314. case 1:
  315. Lua_PushNumber(L, Player[nPlayerIndex].m_nVitality);break;
  316. case 2:
  317. Lua_PushNumber(L, Player[nPlayerIndex].m_nVitality);break;
  318. default:
  319. Lua_PushNil(L);
  320. }
  321. return 1;
  322. }
  323. int LuaGetPlayerCashMoney(Lua_State * L)
  324. {
  325.     int nPlayerIndex = GetPlayerIndex(L);
  326.     if (nPlayerIndex > 0)
  327. {
  328. Lua_PushNumber(L, Player[nPlayerIndex].m_ItemList.GetMoney(room_equipment));
  329. }
  330. else Lua_PushNumber(L,0);
  331. return 1;
  332. }
  333. int LuaPlayerPayMoney(Lua_State * L)
  334. {
  335.     
  336.     int nPlayerIndex = GetPlayerIndex(L);
  337.     if (nPlayerIndex > 0)
  338. {
  339.         int nMoney = (int)Lua_ValueToNumber(L, 1);
  340.         if (nMoney <= 0) return 0;
  341.         if (Player[nPlayerIndex].Pay(nMoney))
  342. Lua_PushNumber(L, 1);
  343. else
  344. Lua_PushNumber(L, 0);
  345. }
  346. else
  347. Lua_PushNumber(L, 0);
  348. return 1;
  349. }
  350. int LuaPlayerEarnMoney (Lua_State  *L)
  351. {
  352.     int nPlayerIndex = GetPlayerIndex(L);
  353.     if (nPlayerIndex > 0)
  354. {
  355.         int nMoney = (int)Lua_ValueToNumber(L, 1);
  356.         if (nMoney <= 0) return 0;
  357.         Player[nPlayerIndex].Earn(nMoney);
  358. }
  359. return 0;
  360. }
  361. int LuaPlayerPrePayMoney(Lua_State *L)
  362. {   
  363.     int nPlayerIndex = GetPlayerIndex(L);
  364.     if (nPlayerIndex > 0)
  365. {
  366.         int nMoney = (int)Lua_ValueToNumber(L, 1);
  367.         if (nMoney <= 0) return 0;
  368.         if (Player[nPlayerIndex].PrePay(nMoney))
  369. Lua_PushNumber(L, 1);
  370. else
  371. Lua_PushNumber(L, 0);
  372. }
  373. else
  374. Lua_PushNumber(L, 0);
  375. return 1;
  376. }
  377. int LuaPlayerExecuteScript(Lua_State * L)
  378. {
  379. return 1;
  380. }
  381. //Attack dwID, Damage
  382. int LuaAttackNpc(Lua_State * L)
  383. {
  384. int nParamCount = 0;
  385. if ( (nParamCount = Lua_GetTopIndex(L)) < 2) return 0;
  386. int nPlayerIndex = GetPlayerIndex(L);
  387. if (nPlayerIndex <= 0) return 0;
  388. DWORD nNpcID = (DWORD)Lua_ValueToNumber(L,1);
  389. int nNpcIndex = Player[nPlayerIndex].FindAroundNpc(nNpcID);//NpcSet.SearchID(nNpcID);
  390. if (nNpcIndex <= 0) return 0;
  391. KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
  392. memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
  393. DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
  394. DamageMagicAttribs[0].nValue[0] = 65534;
  395. DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
  396. DamageMagicAttribs[1].nValue[0] = 1;
  397. for (int i = 0; i < nParamCount - 1; i++)
  398. {
  399. int nVlau = (int)Lua_ValueToNumber(L, 2 + i);
  400. DamageMagicAttribs[i + 2].nValue[0] = (int)Lua_ValueToNumber(L, 2 + i);
  401. DamageMagicAttribs[i + 2].nValue[2] = (int)Lua_ValueToNumber(L, 2 + i);
  402. }
  403. Npc[nNpcIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
  404. return 0;
  405. }
  406. int LuaSetPlayerChatForbiddenFlag(Lua_State * L)
  407. {
  408. if (Lua_GetTopIndex(L) < 1) 
  409. return 0;
  410. int nPlayerIndex = GetPlayerIndex(L);
  411. if (nPlayerIndex < 0)
  412. return 0;
  413. int nFlag = Lua_ValueToNumber(L, 1);
  414. Player[nPlayerIndex].SetChatForbiddenFlag(nFlag);
  415. return 0;
  416. }
  417. int LuaKickOutPlayer(Lua_State *L)
  418. {
  419. if (Lua_GetTopIndex(L) < 1)
  420. return 0;
  421. const char* pszName = (const char*)Lua_ValueToString(L, 1);
  422. int nIndex = PlayerSet.GetFirstPlayer();
  423. while(nIndex > 0)
  424. {
  425. if (strcmp(Player[nIndex].m_PlayerName, pszName) == 0)
  426. break;
  427. nIndex = PlayerSet.GetNextPlayer();
  428. }
  429. if (nIndex && Player[nIndex].m_nNetConnectIdx >= 0)
  430. {
  431. printf("GM Kick out specific player.n");
  432. g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
  433. }
  434. return 0;
  435. }
  436. int LuaKickOutAccount(Lua_State *L)
  437. {
  438. if (Lua_GetTopIndex(L) < 1)
  439. return 0;
  440. const char* pszName = (const char*)Lua_ValueToString(L, 1);
  441. int nIndex = PlayerSet.GetFirstPlayer();
  442. while(nIndex > 0)
  443. {
  444. if (strcmpi(Player[nIndex].m_AccoutName, pszName) == 0)
  445. break;
  446. nIndex = PlayerSet.GetNextPlayer();
  447. }
  448. if (nIndex && Player[nIndex].m_nNetConnectIdx >= 0)
  449. {
  450. printf("GM Kick out specific player.n");
  451. g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
  452. }
  453. return 0;
  454. }
  455. int LuaKickOutSelf(Lua_State *L)
  456. {
  457. int nIndex = GetPlayerIndex(L);
  458. if (nIndex <= 0)
  459. return 0;
  460. if (Player[nIndex].m_nNetConnectIdx >= 0)
  461. {
  462. printf("GM Kick out player one.n");
  463. g_pServer->ShutdownClient(Player[nIndex].m_nNetConnectIdx);
  464. }
  465. return 0;
  466. }
  467. int LuaKillNpc(Lua_State * L)
  468. {
  469. int nParamCount = 0;
  470. if ( (nParamCount = Lua_GetTopIndex(L)) < 1) return 0;
  471. int nPlayerIndex = GetPlayerIndex(L);
  472. if (nPlayerIndex <= 0) return 0;
  473. DWORD nNpcID = (DWORD)Lua_ValueToNumber(L,1);
  474. int nNpcIndex = Player[nPlayerIndex].FindAroundNpc(nNpcID);
  475. if (nNpcIndex <= 0) return 0;
  476. KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
  477. memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
  478. DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
  479. DamageMagicAttribs[0].nValue[0] = 50000;
  480. DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
  481. DamageMagicAttribs[1].nValue[0] = 1;
  482. DamageMagicAttribs[2].nValue[0] = 50000;
  483. DamageMagicAttribs[2].nValue[2] = 50000;
  484. Npc[nNpcIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
  485. return 0;
  486. }
  487. int LuaKillPlayer(Lua_State * L)
  488. {
  489. int nPlayerIndex = GetPlayerIndex(L);
  490. if (nPlayerIndex <= 0) 
  491. return 0;
  492. KMagicAttrib DamageMagicAttribs[MAX_MISSLE_DAMAGEATTRIB];
  493. memset(DamageMagicAttribs, 0, sizeof(DamageMagicAttribs));
  494. DamageMagicAttribs[0].nAttribType = magic_attackrating_v;
  495. DamageMagicAttribs[0].nValue[0] = 50000;
  496. DamageMagicAttribs[1].nAttribType = magic_ignoredefense_p;
  497. DamageMagicAttribs[1].nValue[0] = 1;
  498. DamageMagicAttribs[2].nValue[0] = 50000;
  499. DamageMagicAttribs[2].nValue[2] = 50000;
  500. Npc[Player[nPlayerIndex].m_nIndex].ReceiveDamage(Player[nPlayerIndex].m_nIndex, 0, DamageMagicAttribs, 0, TRUE);
  501. return 0;
  502. }
  503. int LuaSetFightState(Lua_State * L)
  504. {
  505. int nPlayerIndex = GetPlayerIndex(L);
  506. if (nPlayerIndex <= 0) return 0;
  507. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  508. Npc[Player[nPlayerIndex].m_nIndex].SetFightMode(Lua_ValueToNumber(L,1) != 0);
  509. return 0;
  510. }
  511. int LuaGetFightState(Lua_State * L)
  512. {
  513. int nPlayerIndex = GetPlayerIndex(L);
  514. if (nPlayerIndex <= 0) return 0;
  515. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  516. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_FightMode);
  517. return 1;
  518. }
  519. int LuaGetLevel(Lua_State * L)
  520. {
  521. int nPlayerIndex = GetPlayerIndex(L);
  522. if (nPlayerIndex <= 0) Lua_PushNumber(L,0);
  523. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  524. Lua_PushNumber(L, Npc[Player[nPlayerIndex].m_nIndex].m_Level);
  525. return 1;
  526. }
  527. //
  528. int LuaUseTownPortal(Lua_State * L)
  529. {
  530. int nPlayerIndex = GetPlayerIndex(L);
  531. if (nPlayerIndex <= 0) return 0;
  532. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  533. Player[nPlayerIndex].UseTownPortal();
  534. return 0;
  535. }
  536. int LuaReturnFromTownPortal(Lua_State * L)
  537. {
  538. int nPlayerIndex = GetPlayerIndex(L);
  539. if (nPlayerIndex <= 0) return 0;
  540. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  541. Player[nPlayerIndex].BackToTownPortal();
  542. return 0;
  543. }
  544. #endif
  545. int GetPlayerIndex(Lua_State * L)
  546. {
  547. Lua_GetGlobal(L, SCRIPT_PLAYERINDEX);
  548.     if (lua_isnil(L,Lua_GetTopIndex(L)))
  549.         return -1;
  550. int nIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
  551.     if (nIndex >= MAX_PLAYER || nIndex <= 0) 
  552. {
  553. _ASSERT(0);
  554. return -1;
  555. } if (Player[nIndex].m_nIndex >= MAX_NPC || Player[nIndex].m_nIndex < 0)
  556. {
  557. _ASSERT(0);
  558. return -1;
  559. }
  560.     return nIndex;
  561. }
  562. int GetObjIndex(Lua_State * L)
  563. {
  564. Lua_GetGlobal(L, SCRIPT_OBJINDEX);
  565.     if (lua_isnil(L,Lua_GetTopIndex(L)))
  566.         return -1;
  567. int nIndex = (int)Lua_ValueToNumber(L, Lua_GetTopIndex(L));
  568.     if (nIndex >= MAX_OBJECT || nIndex <= 0) 
  569. {
  570. _ASSERT(0);
  571. return -1;
  572. }
  573. if (Object[nIndex].m_nIndex != nIndex)
  574. {
  575. _ASSERT(0);
  576. return -1;
  577. }
  578.     return nIndex;
  579. }
  580. int  LuaMessage(Lua_State * L)
  581. {
  582. const char * szString;
  583. szString  = lua_tostring (L,1);
  584. g_DebugLog((char *)szString);
  585. return 0;
  586. }
  587. #ifdef _SERVER
  588. //AddStation(N)
  589. int LuaAddPlayerWayPoint(Lua_State * L)
  590. {
  591. int nPlayerIndex = GetPlayerIndex(L);
  592. if (nPlayerIndex <= 0) return 0;
  593. int nWayPoint = (int)Lua_ValueToNumber(L,1);
  594. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  595. {
  596. KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerWayPointList.GetHead();
  597. while(pNode)
  598. {
  599. if (pNode->m_nIndex == nWayPoint) return 0;
  600. pNode = (KIndexNode*)pNode->GetNext();
  601. }
  602. KIndexNode * pNewNode = new KIndexNode;
  603. pNewNode->m_nIndex = nWayPoint;
  604. int nCount = Player[nPlayerIndex].m_PlayerWayPointList.GetNodeCount();
  605. for (int i = 0; i < nCount - 2; i ++ )
  606. {
  607. KIndexNode *  pDelNode = (KIndexNode*)Player[nPlayerIndex].m_PlayerWayPointList.RemoveHead();
  608. delete pDelNode;
  609. }
  610. Player[nPlayerIndex].m_PlayerWayPointList.AddTail(pNewNode);
  611. }
  612. return 0;
  613. }
  614. int LuaAddPlayerStation(Lua_State * L)
  615. {
  616. int nPlayerIndex = GetPlayerIndex(L);
  617. if (nPlayerIndex <= 0) return 0;
  618. int nStation = (int )Lua_ValueToNumber(L,1);
  619. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  620. {
  621. KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerStationList.GetHead();
  622. while(pNode)
  623. {
  624. if (pNode->m_nIndex == nStation) return 0;
  625. pNode = (KIndexNode*)pNode->GetNext();
  626. }
  627. KIndexNode * pNewNode = new KIndexNode;
  628. pNewNode->m_nIndex = nStation;
  629. Player[nPlayerIndex].m_PlayerStationList.AddTail(pNewNode);
  630. }
  631. return 0;
  632. }
  633. int LuaGetPlayerStationCount(Lua_State *L)
  634. {
  635. int nPlayerIndex = GetPlayerIndex(L);
  636. if (nPlayerIndex <= 0) return 0;
  637. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  638. Lua_PushNumber(L, Player[nPlayerIndex].m_PlayerStationList.GetNodeCount());
  639. return 1;
  640. }
  641. //获得当前玩家有效城市列表中的第n个(除去当前所在城市)
  642. int LuaGetPlayerStation(Lua_State * L)
  643. {
  644. int nPlayerIndex = GetPlayerIndex(L);
  645. if (nPlayerIndex <= 0) return 0;
  646. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  647. if (Lua_GetTopIndex(L) < 2)
  648. {
  649. Lua_PushNumber(L, 0);
  650. return 1;
  651. }
  652. int nStationId = 0;
  653. KIndexNode * pNode =  (KIndexNode*)Player[nPlayerIndex].m_PlayerStationList.GetHead();
  654. if (pNode)
  655. {
  656. int nNo = (int )Lua_ValueToNumber(L, 1);
  657. int nCurStation = (int) Lua_ValueToNumber(L,2);
  658. int nVisitNo = 0;
  659. while(pNode)
  660. {
  661. if (pNode->m_nIndex != nCurStation && g_GetPriceToStation( nCurStation , pNode->m_nIndex) > 0) 
  662. {
  663. nVisitNo ++;
  664. if (nVisitNo == nNo)
  665. {
  666. nStationId = pNode->m_nIndex;
  667. break;
  668. }
  669. }
  670. pNode = (KIndexNode*)pNode->GetNext();
  671. }
  672. }
  673. Lua_PushNumber(L, nStationId);
  674. return 1;
  675. }
  676. int LuaGetPlayerWayPoint(Lua_State * L)
  677. {
  678. int nPlayerIndex = GetPlayerIndex(L);
  679. if (nPlayerIndex <= 0) return 0;
  680. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  681. KIndexNode * pNode = (KIndexNode*) Player[nPlayerIndex].m_PlayerWayPointList.GetHead();
  682. if (pNode)
  683. {
  684. int nNo = (int)Lua_ValueToNumber(L, 1);
  685. if (nNo > TASKVALUE_MAXWAYPOINT_COUNT) 
  686. Lua_PushNumber(L, 0);
  687. else
  688. {
  689. for (int i = 0; i < nNo - 1; i ++)
  690. {
  691. if (pNode == NULL ) break;
  692. pNode = (KIndexNode *)pNode->GetNext();
  693. }
  694. if (pNode)
  695. Lua_PushNumber(L, pNode->m_nIndex);
  696. else
  697. Lua_PushNumber(L, 0);
  698. }
  699. }
  700. else
  701. Lua_PushNumber(L, 0);
  702. return 1;
  703. }
  704. //根据传入的城市唯一id获得其名称
  705. int LuaGetStationName(Lua_State * L)
  706. {
  707. int nPlayerIndex = GetPlayerIndex(L);
  708. if (nPlayerIndex <= 0) return 0;
  709. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  710. if (Lua_GetTopIndex(L) <= 0 ) 
  711. {
  712. Lua_PushString(L, "");
  713. return 1;
  714. }
  715. int nStationId = (int)Lua_ValueToNumber(L,1);
  716. char szName[50];
  717. g_StationTabFile.GetString(nStationId + 1, "DESC", "无名城",  szName, 50 );
  718. Lua_PushString(L, szName);
  719. return 1;
  720. }
  721. int LuaGetWayPointName(Lua_State * L)
  722. {
  723. int nPlayerIndex = GetPlayerIndex(L);
  724. if (nPlayerIndex <= 0) return 0;
  725. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  726. if (Lua_GetTopIndex(L) <= 0 ) 
  727. {
  728. Lua_PushString(L, "");
  729. return 1;
  730. }
  731. int nWayPointId = (int)Lua_ValueToNumber(L,1);
  732. char szName[50];
  733. g_WayPointTabFile.GetString(nWayPointId + 1, "DESC", "未记录",  szName, 50 );
  734. Lua_PushString(L, szName);
  735. return 1;
  736. }
  737. //GetCityCount 
  738. int LuaGetAllStationCount(Lua_State * L)
  739. {
  740. int nCityCount = g_StationTabFile.GetHeight() - 1;
  741. if (nCityCount < 0) nCityCount = 0;
  742. Lua_PushNumber(L,nCityCount);
  743. return 1;
  744. }
  745. //cityid, price = GetCity(citynum, curcity)
  746. int LuaGetCity(Lua_State * L)
  747. {
  748. return 0;
  749. }
  750. int LuaGetPriceToWayPoint(Lua_State *L)
  751. {
  752. int nCurStation = (int)Lua_ValueToNumber(L,1);
  753. int nDesWayPoint = (int)Lua_ValueToNumber(L,2);
  754. Lua_PushNumber(L, g_GetPriceToWayPoint(nCurStation, nDesWayPoint));
  755. return 1;
  756. }
  757. int LuaGetPriceToStation(Lua_State *L)
  758. {
  759. int nCurStation  = (int)Lua_ValueToNumber(L,1);
  760. int nNextStation = (int)Lua_ValueToNumber(L,2);
  761. Lua_PushNumber(L, g_GetPriceToStation(nCurStation, nNextStation));
  762. return 1;
  763. }
  764. int LuaGetStationPos(Lua_State * L)
  765. {
  766. int nStationId = (int)Lua_ValueToNumber(L,1);
  767. char szPos[100] ;
  768. int nCount = 0;
  769. int nRow = g_StationTabFile.FindColumn("COUNT");
  770. g_StationTabFile.GetInteger(nStationId + 1, nRow,  0, &nCount);
  771. if (nCount <= 0) return 0;
  772. int nRandSect = g_Random(100) % nCount + 1;
  773. char szSectName[32];
  774. sprintf(szSectName, "SECT%d", nRandSect);
  775. char szValue[100];
  776. nRow = g_StationTabFile.FindColumn(szSectName);
  777. g_StationTabFile.GetString(nStationId + 1, nRow, "0,0,0", szValue, 100);
  778.     int nX, nY, nWorld;
  779.     const char *pcszTemp = szValue;
  780.     
  781.     nWorld = KSG_StringGetInt(&pcszTemp, 0);
  782.     KSG_StringSkipSymbol(&pcszTemp, ',');
  783.     nX = KSG_StringGetInt(&pcszTemp, 0);
  784.     KSG_StringSkipSymbol(&pcszTemp, ',');
  785.     nY = KSG_StringGetInt(&pcszTemp, 0);
  786. //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
  787.     Lua_PushNumber(L,nWorld);
  788. Lua_PushNumber(L,nX);
  789. Lua_PushNumber(L,nY);
  790. return 3;
  791. }
  792. int LuaGetWayPointPos(Lua_State * L)
  793. {
  794. int nWayPointId = (int)Lua_ValueToNumber(L,1);
  795. char szPos[100] ;
  796. int nCount = 0;
  797. char szValue[30];
  798. int nRow;
  799. nRow = g_WayPointTabFile.FindColumn("SECT");
  800. g_WayPointTabFile.GetString(nWayPointId + 1, nRow, "0,0,0", szValue, 30);
  801. int nX, nY, nWorld;
  802.     const char *pcszTemp = szValue;
  803.     
  804.     nWorld = KSG_StringGetInt(&pcszTemp, 0);
  805.     KSG_StringSkipSymbol(&pcszTemp, ',');
  806.     nX = KSG_StringGetInt(&pcszTemp, 0);
  807.     KSG_StringSkipSymbol(&pcszTemp, ',');
  808.     nY = KSG_StringGetInt(&pcszTemp, 0);
  809. //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
  810. Lua_PushNumber(L,nWorld);
  811. Lua_PushNumber(L,nX);
  812. Lua_PushNumber(L,nY);
  813. return 3;
  814. }
  815. int LuaGetRank(Lua_State * L)
  816. {
  817. int nPlayerIndex = GetPlayerIndex(L);
  818. if (nPlayerIndex <= 0) return 0;
  819. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  820. Lua_PushNumber(L,Npc[Player[nPlayerIndex].m_nIndex].m_btRankId);
  821. return 1;
  822. }
  823. int LuaSetRank(Lua_State * L)
  824. {
  825. BYTE btRank = (BYTE)Lua_ValueToNumber(L,1);
  826. int nPlayerIndex = GetPlayerIndex(L);
  827. if (nPlayerIndex <= 0) return 0;
  828. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  829. Npc[Player[nPlayerIndex].m_nIndex].m_btRankId = btRank;
  830. return 0;
  831. }
  832. int LuaSetObjPropState(Lua_State *L)
  833. {
  834. int  nParamNum = ( int ) Lua_GetTopIndex(L);
  835. int nState  = 1;
  836. if (nParamNum >= 1)
  837. {
  838. nState = (int)Lua_ValueToNumber(L,1);
  839. nState = (nState == 0)?0 : 1;
  840. }
  841. int nIndex = 0;
  842. if ((nIndex = GetObjIndex(L)) < 0) 
  843. return 0;
  844. Object[nIndex].SetState(nState);
  845. return 0;
  846. }
  847. int LuaGetServerName(Lua_State * L)
  848. {
  849. char szServerName[100]  ;
  850. unsigned long   stServerNameLen = 100;
  851. #ifndef __linux
  852. if (GetComputerName(szServerName, &stServerNameLen))
  853. {
  854. Lua_PushString(L, szServerName);
  855. }
  856. else
  857. #else
  858. if (SOCKET_ERROR != gethostname(szServerName, sizeof(szServerName)))
  859. {
  860. Lua_PushString(L, szServerName);
  861. }
  862. else
  863. #endif
  864. Lua_PushString(L, "");
  865. return 1;
  866. }
  867. //GetWharfCount(nDock)
  868. int LuaGetDockCount(Lua_State * L)
  869. {
  870. int nCount = 0;
  871. int nCurStation = 0;
  872. int nTotalCount = 0;
  873. int i  = 0;
  874. if (Lua_GetTopIndex(L) < 1 )  
  875. {
  876. goto DockCount;
  877. }
  878. nCurStation = (int)Lua_ValueToNumber(L,1);
  879. nTotalCount = g_DockPriceTabFile.GetHeight() - 1;
  880. for (i = 0; i < nTotalCount; i ++)
  881. {
  882. int nPrice = g_GetPriceToDock(nCurStation, i + 1);
  883. if (nPrice > 0) nCount ++;
  884. }
  885. DockCount:
  886. Lua_PushNumber(L, nCount);
  887. return 1;
  888. }
  889. int LuaGetDockPrice(Lua_State * L)
  890. {
  891. int nCurDock = (int)Lua_ValueToNumber(L,1);
  892. int nDesDock = (int)Lua_ValueToNumber(L,2);
  893. Lua_PushNumber(L, g_GetPriceToDock(nCurDock, nDesDock));
  894. return 1;
  895. }
  896. int LuaGetDock(Lua_State * L)
  897. {
  898. int nCurDock = (int)Lua_ValueToNumber(L, 1);
  899. int nDock = (int)Lua_ValueToNumber(L, 2);
  900. int nCount = 0;
  901. int nTotalCount = g_DockPriceTabFile.GetHeight() - 1;
  902. int nGetDock = 0;
  903. for (int i = 0; i < nTotalCount; i ++)
  904. {
  905. int nPrice = g_GetPriceToDock(nCurDock, i + 1);
  906. if (nPrice > 0) 
  907. {
  908. nCount ++ ;
  909. if (nCount == nDock)
  910. {
  911. nGetDock = i + 1;
  912. break;
  913. }
  914. }
  915. }
  916. Lua_PushNumber(L, nGetDock);
  917. return 1;
  918. }
  919. int LuaGetDockName(Lua_State * L)
  920. {
  921. int nDock  = (int)Lua_ValueToNumber(L, 1);
  922. char szName[100] ;
  923. if (nDock > g_DockPriceTabFile.GetHeight() - 1)
  924. {
  925. strcpy(szName, "未知码头");
  926. goto DockName;
  927. }
  928. g_DockTabFile.GetString(nDock + 1, "DESC", "未知码头", szName, 100);
  929. DockName:
  930. Lua_PushString (L, szName);
  931. return 1;
  932. }
  933. int LuaGetDockPos(Lua_State * L)
  934. {
  935. int nDock  = (int)Lua_ValueToNumber(L, 1);
  936. if (nDock > g_DockTabFile.GetHeight() - 1) 
  937. {
  938. printf("GetWharfPos Script Is Error!");
  939. return 0;
  940. }
  941. char szPos[100] ;
  942. int nCount = 0;
  943. int nRow = g_DockTabFile.FindColumn("COUNT");
  944. g_DockTabFile.GetInteger(nDock + 1, nRow,  0, &nCount);
  945. if (nCount <= 0) return 0;
  946. int nRandSect = g_Random(100) % nCount + 1;
  947. char szSectName[32];
  948. sprintf(szSectName, "SECT%d", nRandSect);
  949. char szValue[100];
  950. nRow = g_DockTabFile.FindColumn(szSectName);
  951. g_DockTabFile.GetString(nDock + 1, nRow, "0,0,0", szValue, 100);
  952. int nX, nY, nWorld;
  953.     const char *pcszTemp = szValue;
  954.     
  955.     nWorld = KSG_StringGetInt(&pcszTemp, 0);
  956.     KSG_StringSkipSymbol(&pcszTemp, ',');
  957.     nX = KSG_StringGetInt(&pcszTemp, 0);
  958.     KSG_StringSkipSymbol(&pcszTemp, ',');
  959.     nY = KSG_StringGetInt(&pcszTemp, 0);
  960. //sscanf(szValue, "%d,%d,%d", &nWorld, &nX, &nY);
  961. Lua_PushNumber(L,nWorld);
  962. Lua_PushNumber(L,nX);
  963. Lua_PushNumber(L,nY);
  964. return 3;
  965. }
  966. int LuaGetWayPointFightState(Lua_State * L)
  967. {
  968. int nPlayerIndex = GetPlayerIndex(L);
  969. if (nPlayerIndex <= 0) return 0;
  970. if (Player[nPlayerIndex].m_nIndex <= 0) return 0;
  971. int nFightState = 0;
  972. if (Lua_GetTopIndex(L) > 0 ) 
  973. {
  974. int nWayPointId = (int)Lua_ValueToNumber(L,1);
  975. g_WayPointTabFile.GetInteger(nWayPointId + 1, "FightState", 0,  &nFightState);
  976. }
  977. Lua_PushNumber(L, nFightState);
  978. return 1;
  979. }
  980. // SetMissionValue(valueid, value)
  981. int LuaSetMissionValue(Lua_State * L)
  982. {
  983. int nSubWorldIndex = GetSubWorldIndex(L);
  984. if (nSubWorldIndex < 0) 
  985. return 0;
  986. int nParamCount = Lua_GetTopIndex(L);
  987. if (nParamCount < 2) 
  988. return 0;
  989. int nValueId = (int)Lua_ValueToNumber(L, 1);
  990. int nValue = (int)Lua_ValueToNumber(L, 2);
  991. if (nValueId  < 0)
  992. return 0;
  993. SubWorld[nSubWorldIndex].m_MissionArray.SetMissionValue(nValueId, nValue);
  994. return 0;
  995. }
  996. int LuaGetMissionValue(Lua_State * L)
  997. {
  998. int nResultValue = 0;
  999. int nSubWorldIndex = -1;
  1000. int nParamCount = Lua_GetTopIndex(L);
  1001. if (nParamCount < 1) 
  1002. goto lab_getmissionvalue;
  1003. nSubWorldIndex = GetSubWorldIndex(L);
  1004. if (nSubWorldIndex >= 0) 
  1005. {
  1006. int  nValueId = (int)Lua_ValueToNumber(L, 1);
  1007. if (nValueId > 0)
  1008. nResultValue = SubWorld[nSubWorldIndex].m_MissionArray.GetMissionValue(nValueId);
  1009. }
  1010. lab_getmissionvalue:
  1011. Lua_PushNumber(L, nResultValue);
  1012. return 1;
  1013. }
  1014. // SetMissionValue(mapid/mapname, valueid, value)
  1015. int LuaSetGlobalMissionValue(Lua_State * L)
  1016. {
  1017. int nParamCount = Lua_GetTopIndex(L);
  1018. if (nParamCount < 2) 
  1019. return 0;
  1020. int nValueId = (int)Lua_ValueToNumber(L, 1);
  1021. int nValue = (int)Lua_ValueToNumber(L, 2);
  1022. if (nValueId  < 0)
  1023. return 0;
  1024. g_GlobalMissionArray.SetMissionValue(nValueId, nValue);
  1025. return 0;
  1026. }
  1027. int LuaGetGlobalMissionValue(Lua_State * L)
  1028. {
  1029. int nResultValue = 0;
  1030. int nValueId = 0;
  1031. int nParamCount = Lua_GetTopIndex(L);
  1032. if (nParamCount < 1) 
  1033. goto lab_getglobalmissionvalue;
  1034. nValueId = (int)Lua_ValueToNumber(L, 1);
  1035. if (nValueId < 0)
  1036. goto lab_getglobalmissionvalue;
  1037. nResultValue = g_GlobalMissionArray.GetMissionValue(nValueId);
  1038. lab_getglobalmissionvalue:
  1039. Lua_PushNumber(L, nResultValue);
  1040. return 1;
  1041. }
  1042. //StartMission(missionid)
  1043. int LuaInitMission(Lua_State * L)
  1044. {
  1045. if (Lua_GetTopIndex(L) < 1) 
  1046. return 0;
  1047. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1048. if (nMissionId < 0 )
  1049. return 0;
  1050. int nSubWorldIndex = GetSubWorldIndex(L);
  1051. if (nSubWorldIndex < 0) 
  1052. return 0;
  1053. int nPlayerIndex = GetPlayerIndex(L);
  1054. if (nPlayerIndex <= 0) 
  1055. return 0;
  1056. KMission Mission;
  1057. Mission.SetMissionId(nMissionId);
  1058. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1059. if (pMission)
  1060. {
  1061. _ASSERT(0);
  1062. return 0;
  1063. }
  1064. pMission = SubWorld[nSubWorldIndex].m_MissionArray.Add();
  1065. if (pMission)
  1066. {
  1067. pMission->m_MissionPlayer.Clear();
  1068. pMission->SetMissionId(nMissionId);
  1069. char szScript[MAX_PATH];
  1070. g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
  1071. if (szScript[0])
  1072. Player[nPlayerIndex].ExecuteScript(szScript, "InitMission", "");
  1073. }
  1074. return 0;
  1075. }
  1076. int LuaRunMission(Lua_State * L)
  1077. {
  1078. if (Lua_GetTopIndex(L) < 1) 
  1079. return 0;
  1080. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1081. if (nMissionId < 0 )
  1082. return 0;
  1083. int nSubWorldIndex = GetSubWorldIndex(L);
  1084. if (nSubWorldIndex < 0) 
  1085. return 0;
  1086. int nPlayerIndex = GetPlayerIndex(L);
  1087. if (nPlayerIndex <= 0) 
  1088. return 0;
  1089. KMission Mission;
  1090. Mission.SetMissionId(nMissionId);
  1091. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1092. if (pMission)
  1093. {
  1094. char szScript[MAX_PATH];
  1095. g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
  1096. if (szScript[0])
  1097. Player[nPlayerIndex].ExecuteScript(szScript, "RunMission", "");
  1098. }
  1099. return 0;
  1100. }
  1101. //CloseMission(missionId)
  1102. int LuaCloseMission(Lua_State * L)
  1103. {
  1104. if (Lua_GetTopIndex(L) < 1) 
  1105. return 0;
  1106. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1107. if (nMissionId < 0 )
  1108. return 0;
  1109. int nSubWorldIndex = GetSubWorldIndex(L);
  1110. if (nSubWorldIndex < 0) 
  1111. return 0;
  1112. KMission StopMission;
  1113. StopMission.SetMissionId(nMissionId);
  1114. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&StopMission);
  1115. if (pMission)
  1116. {
  1117. char szScript[MAX_PATH];
  1118. g_MissionTabFile.GetString(nMissionId + 1, 2, "", szScript, MAX_PATH);
  1119. if (szScript[0])
  1120. pMission->ExecuteScript(szScript, "EndMission",0);
  1121. pMission->StopMission();
  1122. SubWorld[nSubWorldIndex].m_MissionArray.Remove(pMission);
  1123. }
  1124. return 0;
  1125. }
  1126. //StopMissionTimer(missionid, timerid)
  1127. int LuaStopMissionTimer(Lua_State * L)
  1128. {
  1129. if (Lua_GetTopIndex(L) < 2) 
  1130. return 0;
  1131. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1132. int nTimerId = (int)Lua_ValueToNumber(L, 2);
  1133. int nSubWorldIndex = GetSubWorldIndex(L);
  1134. if (nMissionId < 0 || nTimerId < 0 ) 
  1135. return 0;
  1136. if (nSubWorldIndex >= 0) 
  1137. {
  1138. KMission Mission;
  1139. Mission.SetMissionId(nMissionId);
  1140. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1141. if (pMission)
  1142. {
  1143. KTimerTaskFun StopTimer;
  1144. StopTimer.SetTimer(1, nTimerId);
  1145. KTimerTaskFun * pTimer = pMission->m_cTimerTaskSet.GetData(&StopTimer);
  1146. if (pTimer)
  1147. {
  1148. pTimer->CloseTimer();
  1149. pMission->m_cTimerTaskSet.Remove(pTimer);
  1150. }
  1151. }
  1152. }
  1153. return 0;
  1154. }
  1155. //StartMissionTimer(missionid, timerid, time)
  1156. int LuaStartMissionTimer(Lua_State * L)
  1157. {
  1158. if (Lua_GetTopIndex(L) < 3) 
  1159. return 0;
  1160. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1161. int nTimerId = (int)Lua_ValueToNumber(L, 2);
  1162. int nTimeInterval = (int)Lua_ValueToNumber(L, 3);
  1163. int nSubWorldIndex = GetSubWorldIndex(L);
  1164. if (nMissionId < 0 || nTimerId < 0 || nTimeInterval < 0) 
  1165. return 0;
  1166. if (nSubWorldIndex >= 0) 
  1167. {
  1168. KMission Mission;
  1169. Mission.SetMissionId(nMissionId);
  1170. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1171. if (pMission)
  1172. {
  1173. KTimerTaskFun * pTimer = pMission->m_cTimerTaskSet.Add();
  1174. if (pTimer)
  1175. {
  1176. pTimer->SetTimer(nTimeInterval, nTimerId);
  1177. }
  1178. }
  1179. }
  1180. return 0;
  1181. }
  1182. //SetTempRev(worldid, x, y)
  1183. int LuaSetDeathRevivalPos(Lua_State * L)
  1184. {
  1185. int nPlayerIndex = GetPlayerIndex(L);
  1186. if (nPlayerIndex <= 0) 
  1187. return 0;
  1188. int nParamCount = Lua_GetTopIndex(L);
  1189. PLAYER_REVIVAL_POS * pTempRev = Player[nPlayerIndex].GetDeathRevivalPos();
  1190. if (nParamCount > 2)
  1191. {
  1192. pTempRev->m_nSubWorldID  = (int) Lua_ValueToNumber(L, 1);
  1193. pTempRev->m_nMpsX = (int) Lua_ValueToNumber(L, 2);
  1194. pTempRev->m_nMpsY = (int) Lua_ValueToNumber(L, 3); 
  1195. }
  1196. else if (nParamCount == 1)
  1197. {
  1198. pTempRev->m_nSubWorldID = SubWorld[Npc[Player[nPlayerIndex].m_nIndex].m_SubWorldIndex].m_SubWorldID;
  1199. POINT Pos;
  1200. int nRevId = (int) Lua_ValueToNumber(L, 1);
  1201. g_SubWorldSet.GetRevivalPosFromId(pTempRev->m_nSubWorldID, nRevId, &Pos);
  1202. pTempRev->m_ReviveID = nRevId;
  1203. pTempRev->m_nMpsX = Pos.x;
  1204. pTempRev->m_nMpsY = Pos.y;
  1205. }
  1206. else 
  1207. {
  1208. return 0;
  1209. }
  1210. return 0;
  1211. }
  1212. //AddMSPlayer(MissionId, PlayerIndex, groupid); / AddMSPlayer(MissionId, groupid)
  1213. int LuaAddMissionPlayer(Lua_State * L)
  1214. {
  1215. int nParamCount = Lua_GetTopIndex(L);
  1216. if (nParamCount < 2) 
  1217. return 0;
  1218. int nMissionId = 0;
  1219. int nPlayerIndex = 0;
  1220. int nGroupId = 0;
  1221. if (nParamCount >=3)
  1222. {
  1223. nMissionId = (int)Lua_ValueToNumber(L,1);
  1224. nPlayerIndex = (int )Lua_ValueToNumber(L,2);
  1225. nGroupId = (int) Lua_ValueToNumber(L,3);
  1226. }
  1227. else
  1228. {
  1229. nMissionId = (int)Lua_ValueToNumber(L,1);
  1230. nGroupId = (int) Lua_ValueToNumber(L,2);
  1231. nPlayerIndex = GetPlayerIndex(L);
  1232. }
  1233. if (nMissionId < 0 || nPlayerIndex <= 0 || nGroupId <0)
  1234. return 0;
  1235. int nSubWorldIndex = GetSubWorldIndex(L);
  1236. if (nSubWorldIndex >= 0) 
  1237. {
  1238. KMission Mission;
  1239. Mission.SetMissionId(nMissionId);
  1240. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1241. if (pMission)
  1242. {
  1243. pMission->AddPlayer(nPlayerIndex, Player[nPlayerIndex].m_dwID, nGroupId);
  1244. }
  1245. }
  1246. return 0;
  1247. }
  1248. int LuaRevivalAllNpc(Lua_State * L)
  1249. {
  1250. int nSubWorldIndex = GetSubWorldIndex(L);
  1251. if (nSubWorldIndex >= 0) 
  1252. {
  1253. SubWorld[nSubWorldIndex].RevivalAllNpc();
  1254. }
  1255. return 0;
  1256. }
  1257. //RemoveMSPlayer(MissionId, PlayerIndex, groupid)
  1258. int LuaRemoveMissionPlayer(Lua_State * L)
  1259. {
  1260. int nParamCount = Lua_GetTopIndex(L);
  1261. if (nParamCount < 2) 
  1262. return 0;
  1263. int nMissionId = 0;
  1264. int nPlayerIndex = 0;
  1265. int nGroupId = 0;
  1266. if (nParamCount >=3)
  1267. {
  1268. nMissionId = (int)Lua_ValueToNumber(L,1);
  1269. nPlayerIndex = (int )Lua_ValueToNumber(L,2);
  1270. nGroupId = (int) Lua_ValueToNumber(L,3);
  1271. }
  1272. else
  1273. {
  1274. nMissionId = (int)Lua_ValueToNumber(L,1);
  1275. nGroupId = (int) Lua_ValueToNumber(L,2);
  1276. nPlayerIndex = GetPlayerIndex(L);
  1277. }
  1278. if (nMissionId < 0 || nPlayerIndex <= 0 || nGroupId <0)
  1279. return 0;
  1280. int nSubWorldIndex = GetSubWorldIndex(L);
  1281. if (nSubWorldIndex >= 0) 
  1282. {
  1283. KMission Mission;
  1284. Mission.SetMissionId(nMissionId);
  1285. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1286. if (pMission)
  1287. {
  1288. pMission->RemovePlayer(nPlayerIndex);
  1289. //pMission->AddPlayer(nPlayerIndex, Player[nPlayerIndex].m_dwID, nGroupId);
  1290. }
  1291. }
  1292. return 0;
  1293. }
  1294. //GetNextPlayer(mission, idx,group)
  1295. int LuaGetNextPlayer(Lua_State * L)
  1296. {
  1297. unsigned long nPlayerIndex = 0;
  1298. if (Lua_GetTopIndex(L) < 2)
  1299. {
  1300. Lua_PushNumber(L ,0);
  1301. Lua_PushNumber(L, 0);
  1302. return 2;
  1303. }
  1304. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1305. int nIdx = (int)Lua_ValueToNumber(L, 2);
  1306. int nGroup = (int)Lua_ValueToNumber(L, 3);
  1307. int nSubWorldIndex = GetSubWorldIndex(L);
  1308. int nResultIdx = 0;
  1309. if (nMissionId < 0 || nIdx < 0 || nGroup < 0) 
  1310. goto lab_getnextplayer;
  1311. if (nSubWorldIndex >= 0) 
  1312. {
  1313. KMission Mission;
  1314. Mission.SetMissionId(nMissionId);
  1315. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1316. if (pMission)
  1317. {
  1318. nResultIdx = pMission->GetNextPlayer(nIdx, nGroup, nPlayerIndex);
  1319. }
  1320. }
  1321. lab_getnextplayer:
  1322. Lua_PushNumber(L, nResultIdx);
  1323. Lua_PushNumber(L, nPlayerIndex);
  1324. return 2;
  1325. }
  1326. //MSMsg2Group(missionid, string , group)
  1327. int LuaMissionMsg2Group(Lua_State * L)
  1328. {
  1329. int nMissionId = (int)Lua_ValueToNumber(L,1);
  1330. char * strMsg = (char *)Lua_ValueToString(L, 2);
  1331. int nGroupId = (int) Lua_ValueToNumber(L, 3);
  1332. if (nMissionId < 0 || !strMsg || nGroupId <0)
  1333. return 0;
  1334. int nSubWorldIndex = GetSubWorldIndex(L);
  1335. if (nSubWorldIndex >= 0) 
  1336. {
  1337. KMission Mission;
  1338. Mission.SetMissionId(nMissionId);
  1339. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1340. if (pMission)
  1341. {
  1342. pMission->Msg2Group(strMsg, nGroupId);
  1343. }
  1344. }
  1345. return 0;
  1346. }
  1347. //MSMsg2Group(missionid, string)
  1348. int LuaMissionMsg2All(Lua_State * L)
  1349. {
  1350. int nMissionId = (int)Lua_ValueToNumber(L,1);
  1351. char * strMsg = (char *)Lua_ValueToString(L, 2);
  1352. if (nMissionId < 0 || !strMsg)
  1353. return 0;
  1354. int nSubWorldIndex = GetSubWorldIndex(L);
  1355. if (nSubWorldIndex >= 0) 
  1356. {
  1357. KMission Mission;
  1358. Mission.SetMissionId(nMissionId);
  1359. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1360. if (pMission)
  1361. {
  1362. pMission->Msg2All(strMsg);
  1363. }
  1364. }
  1365. return 0;
  1366. }
  1367. //MSMsg2Group(missionid, string , group)
  1368. int LuaMissionMsg2Player(Lua_State * L)
  1369. {
  1370. int nMissionId = (int)Lua_ValueToNumber(L,1);
  1371. char * strMsg = (char *)Lua_ValueToString(L, 2);
  1372. int nPlayerIndex = (int) Lua_ValueToNumber(L, 3);
  1373. if (nMissionId < 0 || !strMsg || nPlayerIndex <0)
  1374. return 0;
  1375. int nSubWorldIndex = GetSubWorldIndex(L);
  1376. if (nSubWorldIndex >= 0) 
  1377. {
  1378. KMission Mission;
  1379. Mission.SetMissionId(nMissionId);
  1380. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1381. if (pMission)
  1382. {
  1383. pMission->Msg2Group(strMsg, nPlayerIndex);
  1384. }
  1385. }
  1386. return 0;
  1387. }
  1388. int LuaMissionPlayerCount(Lua_State * L)
  1389. {
  1390. int nParamCount = Lua_GetTopIndex(L);
  1391. unsigned long ulCount = 0;
  1392. int nMissionId = 0;
  1393. int nGroupId = 0;
  1394. int nSubWorldIndex = 0;
  1395. if (nParamCount < 1) 
  1396. goto lab_getmissionplayercount;
  1397. if (nParamCount >= 2)
  1398. {
  1399. nMissionId = (int)Lua_ValueToNumber(L,1);
  1400. nGroupId = (int) Lua_ValueToNumber(L,2);
  1401. }
  1402. else
  1403. {
  1404. nMissionId = (int)Lua_ValueToNumber(L,1);
  1405. }
  1406. if (nMissionId < 0 || nGroupId <0)
  1407. goto lab_getmissionplayercount;
  1408. nSubWorldIndex = GetSubWorldIndex(L);
  1409. if (nSubWorldIndex >= 0) 
  1410. {
  1411. KMission Mission;
  1412. Mission.SetMissionId(nMissionId);
  1413. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1414. if (pMission)
  1415. {
  1416. ulCount = pMission->GetGroupPlayerCount(nGroupId);
  1417. }
  1418. }
  1419. lab_getmissionplayercount:
  1420. Lua_PushNumber(L, ulCount);
  1421. return 1;
  1422. }
  1423. int LuaSetPlayerDeathScript(Lua_State * L)
  1424. {
  1425. int nPlayerIndex = GetPlayerIndex(L);
  1426. if (nPlayerIndex <= 0) return 0;
  1427. if (Player[nPlayerIndex].m_nIndex <= 0) 
  1428. return 0;
  1429. char * szScript = (char *)Lua_ValueToString(L, 1);
  1430. Player[nPlayerIndex].m_dwDeathScriptId = g_FileName2Id(szScript);
  1431. return 0;
  1432. }
  1433. int LuaNpcIndexToPlayerIndex(Lua_State * L)
  1434. {
  1435. int nResult = 0;
  1436. int nNpcIndex = (int)Lua_ValueToNumber(L, 1);
  1437. if (nNpcIndex <=  0 || nNpcIndex >= MAX_NPC)
  1438. goto lab_npcindextoplayerindex;
  1439. if (Npc[nNpcIndex].m_Index > 0 && Npc[nNpcIndex].IsPlayer())
  1440. {
  1441. if (Npc[nNpcIndex].GetPlayerIdx() > 0)
  1442. nResult = Npc[nNpcIndex].GetPlayerIdx();
  1443. }
  1444. lab_npcindextoplayerindex:
  1445. Lua_PushNumber(L, nResult);
  1446. return 1;
  1447. }
  1448. //  
  1449. int LuaGetMissionPlayer_PlayerIndex(Lua_State * L)
  1450. {
  1451. unsigned long nResult = 0;
  1452. int nSubWorldIndex = 0;
  1453. if (Lua_GetTopIndex(L) < 2) 
  1454. goto lab_getmissionplayer_npcindex;
  1455. nSubWorldIndex = GetSubWorldIndex(L);
  1456. if (nSubWorldIndex >= 0) 
  1457. {
  1458. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1459. int nDataIndex = (int)Lua_ValueToNumber(L, 2);
  1460. if (nMissionId < 0 || nDataIndex < 0)
  1461. goto lab_getmissionplayer_npcindex;
  1462. KMission Mission;
  1463. Mission.SetMissionId(nMissionId);
  1464. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1465. if (pMission)
  1466. {
  1467. nResult = pMission->GetMissionPlayer_PlayerIndex(nDataIndex);
  1468. }
  1469. }
  1470. lab_getmissionplayer_npcindex:
  1471. Lua_PushNumber(L,nResult);
  1472. return 1;
  1473. }
  1474. int LuaGetMissionPlayer_DataIndex(Lua_State * L)
  1475. {
  1476. unsigned long nResult = 0;
  1477. int nSubWorldIndex = 0;
  1478. if (Lua_GetTopIndex(L) < 2) 
  1479. goto lab_getmissionplayer_dataindex;
  1480. nSubWorldIndex = GetSubWorldIndex(L);
  1481. if (nSubWorldIndex >= 0) 
  1482. {
  1483. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1484. int nPlayerIndex = (int)Lua_ValueToNumber(L, 2);
  1485. if (nMissionId < 0 || nPlayerIndex < 0)
  1486. goto lab_getmissionplayer_dataindex;
  1487. KMission Mission;
  1488. Mission.SetMissionId(nMissionId);
  1489. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1490. if (pMission)
  1491. {
  1492. nResult = pMission->GetMissionPlayer_DataIndex(nPlayerIndex);
  1493. }
  1494. }
  1495. lab_getmissionplayer_dataindex:
  1496. Lua_PushNumber(L,nResult);
  1497. return 1;
  1498. }
  1499. //SetMPParam(missionid, nDidx, vid, v)
  1500. int LuaSetMissionPlayerParam(Lua_State * L)
  1501. {
  1502. int nSubWorldIndex = 0;
  1503. if (Lua_GetTopIndex(L) < 4) 
  1504. return 0;
  1505. nSubWorldIndex = GetSubWorldIndex(L);
  1506. if (nSubWorldIndex >= 0) 
  1507. {
  1508. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1509. int nDataIndex = (int)Lua_ValueToNumber(L, 2);
  1510. int nParamId =  (int)Lua_ValueToNumber(L ,3);
  1511. int nValue =  (int )Lua_ValueToNumber(L, 4);
  1512. if (nMissionId < 0 || nDataIndex < 0 || nParamId > 2)
  1513. return 0;
  1514. KMission Mission;
  1515. Mission.SetMissionId(nMissionId);
  1516. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1517. if (pMission)
  1518. {
  1519. if (nParamId == 1)
  1520. pMission->m_MissionPlayer.SetParam1(nDataIndex, nValue);
  1521. else
  1522. pMission->m_MissionPlayer.SetParam2(nDataIndex, nValue);
  1523. }
  1524. }
  1525. return 0;
  1526. }
  1527. int LuaGetMissionPlayerParam(Lua_State * L)
  1528. {
  1529. int nResult = 0;
  1530. int nSubWorldIndex = 0;
  1531. if (Lua_GetTopIndex(L) < 3) 
  1532. goto lab_getmissionplayerparam;
  1533. nSubWorldIndex = GetSubWorldIndex(L);
  1534. if (nSubWorldIndex >= 0) 
  1535. {
  1536. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1537. int nDataIndex = (int)Lua_ValueToNumber(L, 2);
  1538. int nParamId =  (int)Lua_ValueToNumber(L ,3);
  1539. if (nMissionId < 0 || nDataIndex < 0 || nParamId > 2)
  1540. goto lab_getmissionplayerparam;
  1541. KMission Mission;
  1542. Mission.SetMissionId(nMissionId);
  1543. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1544. if (pMission)
  1545. {
  1546. if (nParamId == 1)
  1547. nResult = pMission->m_MissionPlayer.GetParam1(nDataIndex);
  1548. else
  1549. nResult = pMission->m_MissionPlayer.GetParam2(nDataIndex);
  1550. }
  1551. }
  1552. lab_getmissionplayerparam:
  1553. Lua_PushNumber(L, nResult);
  1554. return 1;
  1555. }
  1556. int LuaGetPlayerMissionGroup(Lua_State * L)
  1557. {
  1558. int nResult = 0;
  1559. int nSubWorldIndex = 0;
  1560. if (Lua_GetTopIndex(L) < 2) 
  1561. goto lab_getmissionplayergroup;
  1562. nSubWorldIndex = GetSubWorldIndex(L);
  1563. if (nSubWorldIndex >= 0) 
  1564. {
  1565. int nMissionId = (int)Lua_ValueToNumber(L, 1);
  1566. int nNpcIndex = (int)Lua_ValueToNumber(L, 2);
  1567. if (nMissionId < 0 || nNpcIndex < 0)
  1568. goto lab_getmissionplayergroup;
  1569. KMission Mission;
  1570. Mission.SetMissionId(nMissionId);
  1571. KMission * pMission = SubWorld[nSubWorldIndex].m_MissionArray.GetData(&Mission);
  1572. if (pMission)
  1573. {
  1574. nResult = pMission->GetMissionPlayer_GroupId(nNpcIndex);
  1575. }
  1576. }
  1577. lab_getmissionplayergroup:
  1578. Lua_PushNumber(L ,nResult);
  1579. return 1;
  1580. }
  1581. int LuaSetPlayerRevivalOptionWhenLogout(Lua_State * L)
  1582. {
  1583. int nPlayerIndex = GetPlayerIndex(L);
  1584. if (nPlayerIndex <= 0) return 0;
  1585. if (Player[nPlayerIndex].m_nIndex <= 0) 
  1586. return 0;
  1587. int nType = (int)Lua_ValueToNumber(L, 1);
  1588. if (nType)
  1589. Player[nPlayerIndex].SetLoginType(1);
  1590. else
  1591. Player[nPlayerIndex].SetLoginType(0);
  1592. return 0;
  1593. }
  1594. int LuaSetPlayerPKValue(Lua_State * L)
  1595. {
  1596. if (Lua_GetTopIndex(L) < 1) 
  1597. return 0;
  1598. int nPKValue = (int)Lua_ValueToNumber(L,1);
  1599. int nPlayerIndex = GetPlayerIndex(L);
  1600. if (nPlayerIndex <= 0)
  1601. return 0;
  1602. if (Player[nPlayerIndex].m_nIndex <= 0) 
  1603. return 0;
  1604. Player[nPlayerIndex].m_cPK.SetPKValue(nPKValue);
  1605. return 0;
  1606. }
  1607. int LuaGetPlayerPKValue(Lua_State * L)
  1608. {
  1609. int nPKValue = 0;
  1610. int nPlayerIndex = GetPlayerIndex(L);
  1611. if (nPlayerIndex <= 0)
  1612. goto lab_getplayerpkvalue;
  1613. if (Player[nPlayerIndex].m_nIndex <= 0) 
  1614. goto lab_getplayerpkvalue;
  1615. nPKValue = Player[nPlayerIndex].m_cPK.GetPKValue();
  1616. lab_getplayerpkvalue:
  1617. Lua_PushNumber(L, nPKValue);
  1618. return 1;
  1619. }
  1620. int LuaGetCurNpcIndex(Lua_State * L)
  1621. {
  1622. int nNpcIndex = 0;
  1623. int nPlayerIndex = GetPlayerIndex(L);
  1624. if (nPlayerIndex <= 0)
  1625. goto lab_getcurnpcindex;
  1626. lab_getcurnpcindex:
  1627. Lua_PushNumber(L, Player[nPlayerIndex].m_nIndex);
  1628. return 1;
  1629. }
  1630. //showladder(count, ladderid1, ladderid2.....)
  1631. int LuaShowLadder(Lua_State * L)
  1632. {
  1633. int nParamCount = Lua_GetTopIndex(L);
  1634. if (nParamCount < 2) 
  1635. return 0;
  1636. int nLadderCount = (DWORD) Lua_ValueToNumber(L, 1);
  1637. if (nLadderCount <= 0)
  1638. return 0;
  1639. int nPlayerIndex = GetPlayerIndex(L);
  1640. if (nPlayerIndex <= 0)
  1641. return 0;
  1642. if (nLadderCount > nParamCount - 1 )
  1643. nLadderCount = nParamCount - 1;
  1644. BYTE Buffer[sizeof(LADDER_LIST) + 50 * sizeof(DWORD)];
  1645. LADDER_LIST * pLadderList = (LADDER_LIST*)&Buffer;
  1646. pLadderList->ProtocolType = s2c_ladderlist;
  1647. pLadderList->nCount = nLadderCount;
  1648. pLadderList->wSize = sizeof(LADDER_LIST) + nLadderCount * sizeof(DWORD) - 1;
  1649. for (int i = 0; i < nLadderCount; i ++)
  1650. {
  1651. pLadderList->dwLadderID[i] = (DWORD)Lua_ValueToNumber(L, i + 2);
  1652. }
  1653. g_pServer->PackDataToClient(Player[nPlayerIndex].m_nNetConnectIdx, &Buffer, pLadderList->wSize + 1);
  1654. return 0;
  1655. }
  1656. int LuaSwearBrother(Lua_State * L)
  1657. {
  1658. if (Lua_GetTopIndex(L) < 1) 
  1659. return 0;
  1660. int nTeamId = Lua_ValueToNumber(L, 1);
  1661. if (nTeamId >= MAX_TEAM || nTeamId < 0)
  1662. return 0;
  1663. KPlayerChat::STRINGLIST BrotherList;
  1664. _ASSERT(g_Team[nTeamId].m_nCaptain > 0);
  1665. std::string strCapName;
  1666. strCapName = Npc[Player[g_Team[nTeamId].m_nCaptain].m_nIndex].Name;
  1667. BrotherList.push_back(strCapName);
  1668. for (int i  = 0; i < g_Team[nTeamId].m_nMemNum; i++)
  1669. {
  1670. int nPlayerIndex = g_Team[nTeamId].m_nMember[i];
  1671. if ( nPlayerIndex > 0 && nPlayerIndex < MAX_PLAYER)
  1672. {
  1673. std::string strName;
  1674. strName =  Npc[Player[nPlayerIndex].m_nIndex].Name;
  1675. BrotherList.push_back(strName);
  1676. }
  1677. }
  1678. KPlayerChat::MakeBrother(BrotherList);
  1679. return 0;
  1680. }
  1681. int LuaMakeEnemy(Lua_State * L)
  1682. {
  1683. return 0;
  1684. }
  1685. int LuaAddLeadExp(Lua_State * L)
  1686. {
  1687. if (Lua_GetTopIndex(L) < 1)
  1688. return 0;
  1689. int nPlayerIndex = GetPlayerIndex(L);
  1690. if (nPlayerIndex <= 0)
  1691. return 0;
  1692. int nLeadExp = (int)Lua_ValueToNumber(L, 1);
  1693. Player[nPlayerIndex].AddLeadExp(nLeadExp);
  1694. return 0;
  1695. }
  1696. int LuaGetLeadLevel(Lua_State * L)
  1697. {
  1698. int nPlayerIndex = GetPlayerIndex(L);
  1699. int nLeadLevel = 0;
  1700. if (nPlayerIndex <= 0)
  1701. goto lab_getleadlevel;
  1702. nLeadLevel = (int)Player[nPlayerIndex].m_dwLeadLevel;
  1703. lab_getleadlevel:
  1704. Lua_PushNumber(L, nLeadLevel);
  1705. return 1;
  1706. }
  1707. int LuaAddMagicPoint(Lua_State * L)
  1708. {
  1709. if (Lua_GetTopIndex(L) < 1)
  1710. return 0;
  1711. int nPlayerIndex = GetPlayerIndex(L);
  1712. if (nPlayerIndex <= 0)
  1713. return 0;
  1714. int nSkillPoint = (int)Lua_ValueToNumber(L, 1);
  1715. Player[nPlayerIndex].m_nSkillPoint += nSkillPoint;
  1716. if (Player[nPlayerIndex].m_nSkillPoint < 0)
  1717. Player[nPlayerIndex].m_nSkillPoint = 0;
  1718. return 0;
  1719. }
  1720. int LuaGetMagicPoint(Lua_State * L)
  1721. {
  1722. int nPlayerIndex = GetPlayerIndex(L);
  1723. int nSkillPoint = 0;
  1724. if (nPlayerIndex <= 0)
  1725. goto lab_getmagicpoint;
  1726. lab_getmagicpoint:
  1727. Lua_PushNumber(L, Player[nPlayerIndex].m_nSkillPoint);
  1728. return 1;
  1729. }
  1730. int LuaAddPropPoint(Lua_State * L)
  1731. {
  1732. int nPlayerIndex = GetPlayerIndex(L);
  1733. int nPropPoint = 0;
  1734. if (nPlayerIndex <= 0)
  1735. return 0;
  1736. nPropPoint = (int)Lua_ValueToNumber(L, 1);
  1737. Player[nPlayerIndex].m_nAttributePoint += nPropPoint;
  1738. return 0;
  1739. }
  1740. //PayExtPoint
  1741. int LuaPayExtPoint(Lua_State * L)
  1742. {
  1743. int nResult = 0;
  1744. int nPay = 0;
  1745. int nPlayerIndex = 0;
  1746. if (Lua_GetTopIndex(L) < 1)
  1747. goto lab_payextpoint;
  1748. nPlayerIndex = GetPlayerIndex(L);
  1749. if (nPlayerIndex <= 0)
  1750. goto lab_payextpoint;
  1751. nPay = Lua_ValueToNumber(L, 1);
  1752. if (nPay < 0)
  1753. goto lab_payextpoint;
  1754. nResult = Player[nPlayerIndex].PayExtPoint(nPay);
  1755. lab_payextpoint:
  1756. Lua_PushNumber(L, nResult);
  1757. return 1;
  1758. }
  1759. //PayExtPoint
  1760. int LuaGetExtPoint(Lua_State * L)
  1761. {
  1762. int nResult = 0;
  1763. int nPlayerIndex = 0;
  1764. if (Lua_GetTopIndex(L) < 1)
  1765. goto lab_getextpoint;
  1766. nPlayerIndex = GetPlayerIndex(L);
  1767. if (nPlayerIndex <= 0)
  1768. goto lab_getextpoint;
  1769. nResult = Player[nPlayerIndex].GetExtPoint();
  1770. lab_getextpoint:
  1771. Lua_PushNumber(L, nResult);
  1772. return 1;
  1773. }
  1774. int LuaGetRestPropPoint(Lua_State * L)
  1775. {
  1776. int nPlayerIndex = GetPlayerIndex(L);
  1777. int nPropPoint = 0;
  1778. if (nPlayerIndex <= 0)
  1779. goto lab_getrestproppoint;
  1780. nPropPoint = Player[nPlayerIndex].m_nAttributePoint;
  1781. lab_getrestproppoint:
  1782. Lua_PushNumber(L, nPropPoint);
  1783. return 1;
  1784. }
  1785. //Msg2GM(str, id)
  1786. int LuaMsgToGameMaster(Lua_State * L)
  1787. {
  1788. int nParamCount = Lua_GetTopIndex(L);
  1789. if ( nParamCount < 1 ) 
  1790. return 0;
  1791. int nParamID = 0;
  1792. const char * szMsg = Lua_ValueToString(L, 1) ;
  1793. if (!szMsg) 
  1794. return 0;
  1795. if (nParamCount < 2)
  1796. {
  1797. nParamID = 0;
  1798. }
  1799. else
  1800. {
  1801. nParamID = (int) Lua_ValueToNumber(L, 2);
  1802. }
  1803. int nPlayerIndex = GetPlayerIndex(L);
  1804. if (nPlayerIndex > 0) 
  1805. {
  1806. char szID[32];
  1807. sprintf(szID, "%d", nParamID);
  1808. //KPlayerChat::SendInfoToGM(Player[nPlayerIndex].m_AccoutName, Npc[Player[nPlayerIndex].m_nIndex].Name, (char *) szMsg, strlen(szMsg) );
  1809. KPlayerChat::SendInfoToGM("GM", szID, (char *) szMsg, strlen(szMsg) );
  1810. }
  1811. return 0;
  1812. }
  1813. //Msg2IP(IP, ID, str)
  1814. int LuaMsgToIP(Lua_State * L)
  1815. {
  1816. int nParamCount = Lua_GetTopIndex(L);
  1817. if ( nParamCount < 3 ) 
  1818. return 0;
  1819. int nIP = 0;
  1820. const char * szIP = Lua_ValueToString(L, 1) ;
  1821. nIP = _a2ip(szIP);
  1822. if (nIP == 0)
  1823. return 0;
  1824. int nID = (int) Lua_ValueToNumber(L, 2);
  1825. const char * szMsg = Lua_ValueToString(L, 3) ;
  1826. if (!szMsg) 
  1827. return 0;
  1828. int nParamID = 0;
  1829. if (nParamCount < 4)
  1830. {
  1831. nParamID = 0;
  1832. }
  1833. else
  1834. {
  1835. nParamID = (int) Lua_ValueToNumber(L, 4);
  1836. }
  1837. char szID[32];
  1838. sprintf(szID, "%d", nParamID);
  1839. KPlayerChat::SendInfoToIP(nIP, nID, "GM", szID, (char *) szMsg, strlen(szMsg) );
  1840. return 0;
  1841. }
  1842. int LuaGetPlayerInfo(Lua_State * L)
  1843. {
  1844. int nPlayerIndex = GetPlayerIndex(L);
  1845. char szDesMsg[250];
  1846. char szMsg[800];
  1847. int nNpcIdx = 0;
  1848. KNpc * pNpc = NULL;
  1849. KPlayer* pPlayer = NULL;
  1850. szDesMsg[0] = 0;
  1851. if (nPlayerIndex <= 0)
  1852. goto lab_getplayerinfo;
  1853. pPlayer = &Player[nPlayerIndex];
  1854. nNpcIdx = pPlayer->m_nIndex;
  1855. pNpc = &Npc[nNpcIdx];
  1856. 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 );
  1857. g_StrCpyLen(szDesMsg, szMsg, 250);
  1858. lab_getplayerinfo:
  1859. Lua_PushString(L, szDesMsg);
  1860. return 1;
  1861. }
  1862. int LuaGetIP(Lua_State * L)
  1863. {
  1864. int nPlayerIndex = GetPlayerIndex(L);
  1865. char szDesMsg[200];
  1866. szDesMsg[0] = 0;
  1867. KPlayer * pPlayer = NULL;
  1868. if (nPlayerIndex <= 0)
  1869. goto lab_getplayerip;
  1870. pPlayer = &Player[nPlayerIndex];
  1871. strcpy(szDesMsg, g_pServer->GetClientInfo(pPlayer->m_nNetConnectIdx));
  1872. lab_getplayerip:
  1873. Lua_PushString(L, szDesMsg);
  1874. return 1;
  1875. }
  1876. int LuaSetDeathPunish(Lua_State * L)
  1877. {
  1878. if (Lua_GetTopIndex(L) < 1) 
  1879. return 0;
  1880. int nPlayerIndex = GetPlayerIndex(L);
  1881. if (nPlayerIndex <= 0)
  1882. {
  1883. int nState = Lua_ValueToNumber(L, 1);
  1884. if (nState == 0)
  1885. Npc[Player[nPlayerIndex].m_nIndex].m_nCurPKPunishState = 0;
  1886. else
  1887. Npc[Player[nPlayerIndex].m_nIndex].m_nCurPKPunishState = enumDEATH_MODE_PKBATTLE_PUNISH;
  1888. }
  1889. return 0;
  1890. }
  1891. int LuaHideNpc(Lua_State * L)
  1892. {
  1893. if (Lua_GetTopIndex(L) < 2)
  1894. return 0;
  1895. int nNpcIndex  = 0;
  1896. if (Lua_IsNumber(L,1))
  1897. {
  1898. nNpcIndex = (int)Lua_ValueToNumber(L, 1);
  1899. }
  1900. else 
  1901. {
  1902. const char * szName = Lua_ValueToString(L, 1);
  1903. int nSubWorldIndex = GetSubWorldIndex(L);
  1904. if (nSubWorldIndex < 0)
  1905. return 0;
  1906. nNpcIndex = SubWorld[nSubWorldIndex].FindNpcFromName(szName);
  1907. }
  1908. if (nNpcIndex > 0 || nNpcIndex < MAX_NPC)
  1909. {
  1910. int nFrame = Lua_ValueToNumber(L, 2);
  1911. if (nFrame <= 0)
  1912. nFrame = 1;
  1913. Npc[nNpcIndex].ExecuteRevive();
  1914. Npc[nNpcIndex].m_Frames.nTotalFrame = nFrame;
  1915. Npc[nNpcIndex].m_Frames.nCurrentFrame = 0;
  1916. }
  1917. return 0;
  1918. }
  1919. #endif
  1920. int LuaPlayMusic(Lua_State * L)//PlayMusic(musicname,loop=1, vol );
  1921. {
  1922. if (Lua_GetTopIndex(L) < 1) 
  1923. return 0;
  1924. int nPlayerIndex = GetPlayerIndex(L);
  1925. if (nPlayerIndex < 0) return 0;
  1926. PLAYER_SCRIPTACTION_SYNC UiInfo;
  1927. UiInfo.m_bUIId = UI_PLAYMUSIC;
  1928. UiInfo.m_bOptionNum = 1;
  1929. UiInfo.m_nOperateType = SCRIPTACTION_UISHOW;
  1930. int nMsgId = 0;
  1931. g_StrCpyLen(UiInfo.m_pContent, Lua_ValueToString(L,1), sizeof(UiInfo.m_pContent));
  1932. UiInfo.m_nBufferLen = strlen(((char *)UiInfo.m_pContent));
  1933. UiInfo.m_bParam1 = 0;
  1934. #ifndef _SERVER
  1935. UiInfo.m_bParam2 = 0;
  1936. #else
  1937. UiInfo.m_bParam2 = 1;
  1938. #endif
  1939. Player[nPlayerIndex].DoScriptAction(&UiInfo);
  1940. return 0;
  1941. }
  1942. int LuaFadeInMusic(Lua_State * L)
  1943. {
  1944. return 0;
  1945. }
  1946. int LuaFadeOutMusic(Lua_State * L)
  1947. {
  1948. return 0;
  1949. }
  1950. #ifndef _SERVER
  1951. int LuaPlaySound(Lua_State * L)
  1952. {
  1953. return 0;
  1954. }
  1955. int LuaPlaySprMovie(Lua_State * L)
  1956. {
  1957. return 0;
  1958. }
  1959. #endif
  1960. TLua_Funcs GameScriptFuns[] = 
  1961. {
  1962. //通用指令
  1963. {"Say", LuaSelectUI},
  1964. {"Talk", LuaTalkUI},
  1965. {"GetTaskTemp", LuaGetTempTaskValue},
  1966. {"SetTaskTemp", LuaSetTempTaskValue},
  1967. {"Message", LuaMessage},
  1968. {"GetBit", LuaGetBit},
  1969. {"GetByte", LuaGetByte},
  1970. {"SetBit", LuaSetBit},
  1971. {"SetByte", LuaSetByte},
  1972. {"Include",LuaIncludeFile},
  1973. {"PutMessage", LuaSendMessageInfo},
  1974. {"AddGlobalNews",LuaAddGlobalNews},
  1975. {"AddGlobalTimeNews",LuaAddGlobalTimeNews},
  1976. {"AddGlobalCountNews",LuaAddGlobalCountNews },
  1977. {"AddLocalNews",LuaAddLocalNews},
  1978. {"AddLocalTimeNews",LuaAddLocalTimeNews},
  1979. {"AddLocalCountNews",LuaAddLocalCountNews },
  1980. //服务器端脚本指令
  1981. #ifdef _SERVER
  1982. //-----------------基本功能
  1983. {"AddRepute", LuaModifyRepute}, //修改声望值
  1984. {"GetRepute",LuaGetRepute},
  1985. {"GetNpcIdx", LuaGetCurNpcIndex},
  1986. {"SetTimer", LuaSetTimer}, //SetTimer(时间量, 时间TaskId):给玩家打开计时器,时间到时将自动调用OnTimer函数
  1987. {"StopTimer", LuaStopTimer}, //StopTimer():关闭当前玩家的计时器
  1988. {"GetRestTime", LuaGetRestTime}, //GetRestTime:获得计时器将触发的剩于时间
  1989. {"GetTimerId", LuaGetCurTimerId}, //CurTimerId = GetTimerId():获得当前执行的计时器的id,如果没有则返回0
  1990. {"GetTask", LuaGetTaskValue}, //GetTask(任务号):获得当前玩家该任务号的值
  1991. {"SetTask", LuaSetTaskValue}, //SetTask(任务号,值):设置任务值
  1992. {"IsCaptain", LuaIsLeader}, //IsCaptain()是否为队长
  1993. {"GetTeam", LuaGetTeamId}, //GetTeam()返回玩家队伍ID
  1994. {"GetTeamSize", LuaGetTeamSize}, //GetTeamSize()
  1995. {"LeaveTeam", LuaLeaveTeam}, //LeaveTeam()让玩家离开自身队伍
  1996. {"Msg2Player", LuaMsgToPlayer }, //Msg2Player(消息)
  1997. {"Msg2Team", LuaMsgToTeam}, //Msg2Team(消息)通知玩家的组
  1998. {"Msg2SubWorld", LuaMsgToSubWorld}, //Msg2SubWorld(消息)通知世界
  1999. {"Msg2Region", LuaMsgToAroundRegion},//Msg2Region(消息)通知周围Region
  2000. {"Msg2GM", LuaMsgToGameMaster}, //Msg2GM(StrInfo)
  2001. {"Msg2IP", LuaMsgToIP}, //Msg2IP(IP, ID, StrInfo)
  2002. {"GetInfo", LuaGetPlayerInfo}, //str = GetInfo()
  2003. {"GetIP", LuaGetIP},
  2004. {"SetPos", LuaSetPos}, //SetPos(x,y)进入某点
  2005. {"GetPos", LuaGetPos}, //GetPos() return x,y,subworldindex
  2006. {"GetWorldPos", LuaGetNewWorldPos}, //W,X,Y = GetWorldPos()返回于NewWorld配陪的坐标
  2007. {"NewWorld", LuaEnterNewWorld},
  2008. {"DropItem", LuaDropItem}, //DropItem(NpcId, 物品id或物品名)
  2009. {"AddItem", LuaAddItem}, //AddItem(nItemClass, nDetailType, nParticualrType, nLevel, nSeries, nLuck, nItemLevel..6)
  2010. {"AddEventItem", LuaAddEventItem }, //AddEventItem(事件物品ID)
  2011. {"DelItem", LuaDelItem}, //
  2012. {"HaveItem", LuaHaveItem},
  2013. {"GetItemCount", LuaGetTaskItemCount}, //GetItemCount(TaskItemName Or TaskItemId)
  2014. {"AddMagic", LuaAddMagic}, //AddMagic(魔法id或魔法名)给玩家加某个魔法
  2015. {"DelMagic", LuaDelMagic}, //DelMagic(魔法id或魔法名)
  2016. {"HaveMagic", LuaHaveMagic}, //HaveMagic(魔法id或魔法名)返回0或1
  2017. {"GetMagicLevel", LuaGetMagicLevel}, //GetMagicLevel(魔法id或魔法名)返回等级
  2018. {"AddMagicPoint", LuaAddMagicPoint},
  2019. {"GetMagicPoint", LuaGetMagicPoint},
  2020. {"SubWorldID2Idx", LuaSubWorldIDToIndex}, //SubWorldID2Idx
  2021. {"AddLeadExp", LuaAddLeadExp},
  2022. {"GetLeadLevel", LuaGetLeadLevel},
  2023. {"SetFightState", LuaSetFightState}, 
  2024. {"GetFightState", LuaGetFightState},
  2025. {"AddNpc", LuaAddNpc}, //AddNpc(人物模板id或人物模板名,所处世界id,点坐标x,点坐标y),返回npcid值
  2026. {"DelNpc", LuaDelNpc}, //DelNpc(Npcid)
  2027. {"SetNpcScript", LuaSetNpcActionScript}, //SetNpcScript(npcid, 脚本文件名)设置npc当前的脚本
  2028. {"SetRevPos", LuaSetPlayerRevivalPos},//SetRevPos(点位置X,点位置Y)设置玩家的当前世界的等入点位置
  2029. {"SetTempRevPos", LuaSetDeathRevivalPos}, //SetTempRevPos(subworldid, x, y ) or SetTempRevPos(id);
  2030. {"GetCurCamp", LuaGetPlayerCurrentCamp},//GetCurCamp()获得玩家的当前阵营
  2031. {"GetCamp", LuaGetPlayerCamp },//GetCamp()获得玩家阵营
  2032. {"SetCurCamp", LuaSetPlayerCurrentCamp},//SetCurCamp(阵营号):设置玩家当前阵营
  2033. {"SetCamp", LuaSetPlayerCamp},   //SetCamp(阵营号):设置阵营
  2034. {"RestoreCamp", LuaRestorePlayerCamp },//RestoreCamp()恢复阵营
  2035. {"GetFaction", LuaGetPlayerFaction, },//GetFaction()获得玩家的门派名 
  2036. {"SetFaction", LuaChangePlayerFaction},  //SetFaction(门派名):设置玩家门派名
  2037. {"GetColdR", LuaGetPlayerColdResist},
  2038. {"SetColdR", LuaGetPlayerColdResist},
  2039. {"GetFireR", LuaGetPlayerFireResist },
  2040. {"SetFireR", LuaSetPlayerFireResist },
  2041. {"GetLightR", LuaGetPlayerLightResist },
  2042. {"SetLightR", LuaSetPlayerLightResist},
  2043. {"GetPoisonR", LuaGetPlayerPoisonResist},
  2044. {"SetPoisonR", LuaSetPlayerPoisonResist},
  2045. {"GetPhyR", LuaGetPlayerPhysicsResist },
  2046. {"SetPhyR", LuaSetPlayerPhysicsResist },
  2047. {"GetExp", LuaGetPlayerExp }, //GetExp():获得玩家的当前经验值
  2048. {"AddExp", LuaModifyPlayerExp}, //AddExp(经验值,对方等级,是否组队共享经验值)
  2049. {"AddOwnExp", LuaAddOwnExp }, //AddOwnExp(Exp),给玩家直接加经验
  2050. {"GetLife", LuaGetPlayerLife}, //GetLife()获得玩家的生命值
  2051. {"RestoreLife", LuaRestorePlayerLife}, //RestoreLife()恢复玩家的生命
  2052. {"GetMana", LuaGetPlayerMana}, //GetMana()获得玩家的Mana
  2053. {"RestoreMana", LuaRestorePlayerMana}, //RestoreMana()恢复玩家的Mana
  2054. {"GetStamina", LuaGetPlayerStamina}, //GetStamina()获得玩家Stamina
  2055. {"RestoreStamina", LuaRestorePlayerStamina}, //RestoreMana()恢复玩家的Stamina
  2056. {"GetDefend", LuaGetPlayerDefend}, //GetDefend()获得玩家的防御力
  2057. {"GetSex", LuaGetPlayerSex}, //GetSex()获得玩家的性别
  2058. {"GetSeries", LuaGetPlayerSeries}, //GetSeries()获得玩家的系0man/1woman
  2059. {"SetSeries", LuaSetPlayerSeries}, //SetSeries(性别号)
  2060. {"GetName", LuaGetPlayerName}, //GetName()获得玩家的姓名
  2061. {"GetUUID", LuaGetPlayerID}, //GetUUID()获得玩家的唯一ID
  2062. {"GetLeadExp", LuaGetPlayerLeadExp}, //GetLeadExp()获得玩家的统率经验值
  2063. {"GetLeadLevel", LuaGetPlayerLeadLevel}, //GetLeadLevel()获得玩家的统率等级
  2064. {"GetLevel", LuaGetLevel}, //GetLevel()GetPlayers Level
  2065. {"GetRestAP", LuaGetPlayerRestAttributePoint},//GetRestAP()获得玩家的剩于属性点数
  2066. {"GetRestSP", LuaGetPlayerRestSkillPoint}, //GetRestSP()获得玩家的剩于技能点数
  2067. {"GetLucky", LuaGetPlayerLucky}, //GetLucky()获得玩家的幸运值
  2068. {"GetEng", LuaGetPlayerEngergy}, //GetEng()获得玩家的力量值Eng
  2069. {"GetDex", LuaGetPlayerDexterity}, //GetDex()获得玩家的Dex
  2070. {"GetStrg", LuaGetPlayerStrength}, //GetStrg()
  2071. {"GetVit", LuaGetPlayerVitality}, //GetVit()
  2072. {"GetCash", LuaGetPlayerCashMoney}, //GetCash()获得玩家的现金
  2073. {"Pay", LuaPlayerPayMoney}, //Pay(金额数)扣除玩家金钱成功返回1,失败返回0
  2074. {"Earn", LuaPlayerEarnMoney}, //Earn(金额数)增加玩家金钱
  2075. {"PrePay", LuaPlayerPrePayMoney}, //付定金,成功返回1,失败返回0
  2076. {"ExeScript", LuaPlayerExecuteScript}, //ExeScript(脚本文件名,参数),执行时会调用main函数
  2077. {"AttackNpc", LuaAttackNpc}, //AttackNpc(NpcDwid,物理伤害值,冰,火,电,毒)
  2078. {"KillNpc", LuaKillNpc}, //KillNpc(NpcDWID)
  2079. {"KillPlayer", LuaKillPlayer}, //KillPlayer();
  2080. {"Sale", LuaSale}, //Sale(SaleId)买卖,SaleId为便卖的物品信息列表id
  2081. {"UseTownPortal", LuaUseTownPortal },
  2082. {"ReturnFromPortal",LuaReturnFromTownPortal },
  2083. {"SetNpcCurCamp", LuaSetNpcCurCamp},
  2084. {"OpenBox", LuaOpenBox},
  2085. {"AddStation", LuaAddPlayerStation},
  2086. {"AddTermini", LuaAddPlayerWayPoint},
  2087. {"GetStation", LuaGetPlayerStation },
  2088. {"GetStationCount", LuaGetPlayerStationCount},
  2089. {"GetCityCount", LuaGetAllStationCount},
  2090. {"GetCity", LuaGetCity},
  2091. {"GetWayPoint", LuaGetPlayerWayPoint},
  2092. {"GetStationName", LuaGetStationName},
  2093. {"GetWayPointName", LuaGetWayPointName},
  2094. {"GetPrice2Station", LuaGetPriceToStation},
  2095. {"GetPrice2WayPoint", LuaGetPriceToWayPoint },
  2096. {"GetStationPos", LuaGetStationPos},
  2097. {"GetWayPointPos", LuaGetWayPointPos},
  2098. {"GetPlayerCount", LuaGetPlayerCount},
  2099. {"GetRank", LuaGetRank},//GetRank()
  2100. {"SetRank", LuaSetRank},//SetRank(id)
  2101. {"SetPropState", LuaSetObjPropState},//SetPropState( hide = 1) hide obj
  2102. {"GetServerName", LuaGetServerName},
  2103. //------------------Station Script ---------------
  2104. {"GetWharfName", LuaGetDockName},
  2105. {"GetWharfCount", LuaGetDockCount},
  2106. {"GetWharfPrice", LuaGetDockPrice},
  2107. {"GetWharf", LuaGetDock},
  2108. {"GetWharfPos", LuaGetDockPos},
  2109. {"GetTerminiFState", LuaGetWayPointFightState},
  2110. //------------------------------------------------
  2111. {"KickOutPlayer", LuaKickOutPlayer},
  2112. {"KickOutSelf", LuaKickOutSelf},
  2113. {"GetSkillId", LuaGetSkillIdInSkillList},
  2114. {"SetSkillLevel", LuaSetSkillLevel},
  2115. {"SetChatFlag", LuaSetPlayerChatForbiddenFlag},
  2116. //------------------------------------------------
  2117. {"AddNote", LuaAddNote},
  2118. //-----------------Mission Script-----------------
  2119. {"GetMissionV", LuaGetMissionValue},//GetMissionV(Vid)
  2120. {"SetMissionV", LuaSetMissionValue},//SetMissionV(Vid, Value)
  2121. {"GetGlbMissionV", LuaGetGlobalMissionValue },
  2122. {"SetGlbMissionV", LuaSetGlobalMissionValue },
  2123. {"OpenMission", LuaInitMission},//OpenMission(missionid)
  2124. {"RunMission", LuaRunMission},
  2125. {"CloseMission", LuaCloseMission},//CloseMission(missionid)
  2126. {"StartMissionTimer", LuaStartMissionTimer},////StartMissionTimer(missionid, timerid, time)
  2127. {"StopMissionTimer", LuaStopMissionTimer},
  2128. {"GetMSRestTime", LuaGetMissionRestTime}, //GetMSRestTime(missionid, timerid)
  2129. {"GetMSIdxGroup",LuaGetPlayerMissionGroup},//GetPlayerGroup(missionid, playerid);
  2130. {"AddMSPlayer", LuaAddMissionPlayer},
  2131. {"DelMSPlayer", LuaRemoveMissionPlayer},
  2132. {"GetNextPlayer", LuaGetNextPlayer},
  2133. {"PIdx2MSDIdx", LuaGetMissionPlayer_DataIndex},//(missionid, pidx)
  2134. {"MSDIdx2PIdx", LuaGetMissionPlayer_PlayerIndex},//(missionid, dataidx)
  2135. {"NpcIdx2PIdx", LuaNpcIndexToPlayerIndex},
  2136. {"GetMSPlayerCount", LuaMissionPlayerCount},//GetMSPlayerCount(missionid, group = 0)
  2137. {"RevivalAllNpc", LuaRevivalAllNpc},
  2138. {"SetPMParam", LuaSetMissionPlayerParam },
  2139. {"GetPMParam", LuaGetMissionPlayerParam},
  2140. {"Msg2MSGroup", LuaMissionMsg2Group},
  2141. {"Msg2MSAll", LuaMissionMsg2All},
  2142. {"Msg2MSPlayer", LuaMissionMsg2Player},
  2143. {"SetDeathScript", LuaSetPlayerDeathScript},
  2144. {"Death", LuaKillNpc},
  2145. {"HideNpc", LuaHideNpc} ,//HideNpc(npcindex/npcname, hidetime)
  2146. {"SetLogoutRV", LuaSetPlayerRevivalOptionWhenLogout},
  2147. {"SetCreateTeam",LuaSetCreateTeamOption},
  2148. {"GetPK", LuaGetPlayerPKValue},  //pkValue = GetPK() 
  2149. {"SetPK", LuaSetPlayerPKValue}, //SetPK(pkValue)
  2150. //------------------------------------------------
  2151. //排名相关函数
  2152. {"ShowLadder", LuaShowLadder}, //ShowLadder(LadderCount, LadderId1,LadderId2,...);
  2153. //------------------------------------------------
  2154. {"OpenTong", LuaOpenTong}, //OpenTong()通知玩家打开帮会界面
  2155. {"SetPunish", LuaSetDeathPunish},// SetPunish(0/1) 0表示不受任何惩罚
  2156. //-------------------------------------------------
  2157. //结拜
  2158. { "SwearBrother", LuaSwearBrother}, // ret = SwearBrother(TeamId);
  2159. {"MakeEnemy", LuaMakeEnemy}, //结仇 MakeEnemy(enemyname)
  2160. {"RollbackSkill", LuaRollBackSkills},
  2161. {"UpdateSkill", LuaUpdateSkillList},
  2162. //-------------------------------------------------
  2163. {"AddProp", LuaAddPropPoint},//加玩家属性点
  2164. {"GetProp", LuaGetRestPropPoint },
  2165. {"GetExtPoint", LuaGetExtPoint},
  2166. {"PayExtPoint", LuaPayExtPoint},
  2167. //{"Trade", LuaTrade }, //Trade("maininfo", "IniFileName.ini的路径名")
  2168. //Trade("MainInfo", n, "item1|price1|function1", "item2|price2|function2", ......, "itemn|pricen|functionn")
  2169. //客户端脚本指令
  2170. #else 
  2171. {"PlaySound", LuaPlaySound}, //PlaySound(Sound);
  2172. {"PlaySprMovie",LuaPlaySprMovie},//PlaySprMovie(npcindex, Movie, times)
  2173. #endif
  2174. {"PlayMusic", LuaPlayMusic}, //PlayMusic(Music,Loop)
  2175. {"FadeInMusic",LuaFadeInMusic},
  2176. {"FadeOutMusic",LuaFadeOutMusic},
  2177. };
  2178. TLua_Funcs WorldScriptFuns[] =// 非指对玩家的脚本指令集
  2179. {
  2180. //通用指令
  2181. {"AddLocalNews",LuaAddLocalNews},
  2182. {"AddLoaclTimeNews",LuaAddLocalTimeNews},
  2183. {"AddLocalCountNews",LuaAddLocalCountNews },
  2184. //服务器端脚本指令
  2185. #ifdef _SERVER
  2186. {"Msg2SubWorld", LuaMsgToSubWorld}, //Msg2SubWorld(消息)通知世界
  2187. {"Msg2IP", LuaMsgToIP}, //Msg2IP(IP, ID, StrInfo)
  2188. {"SubWorldID2Idx", LuaSubWorldIDToIndex}, //SubWorldID2Idx
  2189. {"GetServerName", LuaGetServerName},
  2190. {"KickOutPlayer", LuaKickOutPlayer},
  2191. {"KickOutAccount", LuaKickOutAccount},
  2192. #endif
  2193. // {"GetMissionV", LuaGetMissionValue},//GetMissionV(Vid)
  2194. // {"SetMissionV", LuaSetMissionValue},//SetMissionV(Vid, Value)
  2195. // {"GetGlbMissionV", LuaGetGlobalMissionValue },
  2196. // {"SetGlbMissionV", LuaSetGlobalMissionValue },
  2197. // {"OpenMission", LuaInitMission},//OpenMission(missionid)
  2198. // {"RunMission", LuaRunMission},
  2199. // {"CloseMission", LuaCloseMission},//CloseMission(missionid)
  2200. // {"StartMissionTimer", LuaStartMissionTimer},////StartMissionTimer(missionid, timerid, time)
  2201. // {"StopMissionTimer", LuaStopMissionTimer},
  2202. // {"GetMSRestTime", LuaGetMissionRestTime}, //GetMSRestTime(missionid, timerid)
  2203. // {"GetMSIdxGroup",LuaGetPlayerMissionGroup},//GetPlayerGroup(missionid, playerid);
  2204. //
  2205. // {"AddMSPlayer", LuaAddMissionPlayer},
  2206. // {"DelMSPlayer", LuaRemoveMissionPlayer},
  2207. // {"GetNextPlayer", LuaGetNextPlayer},
  2208. // {"PIdx2MSDIdx", LuaGetMissionPlayer_DataIndex},//(missionid, pidx)
  2209. // {"MSDIdx2PIdx", LuaGetMissionPlayer_PlayerIndex},//(missionid, dataidx)
  2210. // {"NpcIdx2PIdx", LuaNpcIndexToPlayerIndex},
  2211. //{"GetMSPlayerCount", LuaMissionPlayerCount},//GetMSPlayerCount(missionid, group = 0)
  2212. // {"RevivalAllNpc", LuaRevivalAllNpc},
  2213. //{"SetPMParam", LuaSetMissionPlayerParam },
  2214. //{"GetPMParam", LuaGetMissionPlayerParam},
  2215. //{"Msg2MSGroup", LuaMissionMsg2Group},
  2216. //{"Msg2MSAll", LuaMissionMsg2All},
  2217. //{"Msg2MSPlayer", LuaMissionMsg2Player},
  2218. }; 
  2219. int g_GetGameScriptFunNum()
  2220. {
  2221. return sizeof(GameScriptFuns)  / sizeof(GameScriptFuns[0]);
  2222. }
  2223. int g_GetWorldScriptFunNum()
  2224. {
  2225. return sizeof(WorldScriptFuns)  / sizeof(WorldScriptFuns[0]);
  2226. }