魔兽Lua引擎的用法

2017-09-29 15:47 82 1 收藏

其实早在Lua脚本语言被大众所熟知以前,游戏业内人士就已经开始使用脚本来开发游戏了。我们熟悉的很多国内的网络游戏大都运用了脚本开发,比如网游的长青树“梦幻西游和《大话西游2就大量应用了脚本技术。特别是《大话西游2》,其实现基于Lua脚本游戏开发的时间要远早于《魔兽世界》。在脚本技术上,国内与国外其实是站在同一起跑线上的,并不存在什么差距,这也为国内游戏产业赶超国外游戏产业提供了强有力的技术保证。

【 tulaoshi.com - 游戏攻略 】




145904y5hrsy1nddstd1ni.jpg

 

你好,

我终于回到了新版的Warcraft Lua Engine。

那么,有什么变化

  • 以完整的新方式重新编写引擎,从而提高性能

  • 现在我们支持每一个jass本地人!没有你不能打电话的本地的。

  • 你可以在他们被调用之前钩住你想要的每一个jess native,一旦调用它们,就可以改变本机参数和返回值!

  • 添加了功能以获取其他加载的插件的句柄,以便您可以卸载它们,或者获取他们的名称和他们的作者姓名。

    (本文来源于图老师网站,更多请访问https://www.tulaoshi.com)
  • 增加了LuaSocket的支持。

  • 添加了一个插件编写器可以用来编译插件的工具(没有必要编译一个插件,但是我们给出这个工具,以防有人想在发布之前保护他们的代码。)

  • 以及我们将讨论的许多新功能


现在每个插件都应该有一个名为“初始化”的函数,这样游戏一打开就可以调用它。
“初始化”函数有1个参数,这是当前插件的句柄。
见下面的样本:
  1. function Initialize(plugin)

  2.     plugin:SetName("Test Plugin")

  3.     plugin:SetVersion("1.0")

  4.     plugin:SetAuthor("Shahriyar")

  5.     plugin:SetDescription("Lua Engine Test Plugin")

  6.     

  7.     plugin:RegisterGameEvent(EVENT.GAME_STARTED, "OnGameStarted")

  8. end

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)
正如你可以看到,我们可以做一些初始化函数中与给定的插件处理。
这里是插件类的全部功能列表:


  1. plugin:RegisterGameEvent(EVENT event, string funcName) -- Events are stated below

  2. plugin:RegisterNativeHook(string native, string funcName_pre, string funcname_post) -- The engine will call the pre function once before the native getting called so you can use or even edit the naive parameters and once after the native got called so you can use the return value and even change it to another value !

  3. plugin:RegisterChatEvent(string chat, string funcName) -- The function will get called when the local user send a chat message containing the string you stated (If the chat matches any event the game won't send the chat message to other clients)

  4. plugin:SetName(string name)

  5. plugin:SetVersion(string version)

  6. plugin:SetAuthor(string author)

  7. plugin:SetDescription(string description)

  8. plugin:GetName()

  9. plugin:GetVersion()

  10. plugin:GetAuthor()

  11. plugin:GetDescription()

  12. plugin:Unload()

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)
RegisterNativeHook example:

150817xghggpxuvgmvlgnr.png

 

  1. function MultiboardSetTitleText_Pre(multiboard, text)

  2.     local str = jParamStr2cStr(text)

  3.     str = "Lua Engine - " .. str

  4.     

  5.     return {multiboard, cStr2jParamStr(str)}

  6. end



  7. function Initialize(plugin)

  8.     plugin:SetName("Jass Hooking Test")

  9.     plugin:SetVersion("1.0")

  10.     plugin:SetAuthor("Shahriyar")

  11.     plugin:SetDescription("Lua Engine Sample Plugin")

  12.     

  13.     plugin:RegisterNativeHook("MultiboardSetTitleText", "MultiboardSetTitleText_Pre", "")

  14. end

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

如果你想改变任何参数,最后你应该返回一个表包含所有参数的正确顺序,如果你不想改变的参数只是返回零,最后。

事件:

  1. EVENT.ENTER_LOBBY

  2. EVENT.ENTER_LOADING

  3. EVENT.GAME_STARTED

  4. EVENT.GAME_PAUSED

  5. EVENT.GAME_RESUMED

  6. EVENT.GAME_FINISHED

  7. EVENT.GAME_TICK -- If you register this event the engine will call the function you given every 100 milliseconds.

  8. EVENT.PLUGIN_UNLOAD -- The engine will call this function as the last function before the plugin unloads

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)如果你想叫JASS本土你不再需要创建一个脚本类和初始化,而不是做为以下方式:


  1. Jass.GetLocalPlayer() -- Simple as that ;)

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

此外游戏类,在引擎的第一个版本改变了JASS类一样。
例子:

  1. Game.GetMapName()

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)


在游戏命名空间中的函数是一些自定义的函数,我们发现需要添加和这里是列表:

  1. bool Game.IsInGame(bool bPaused) -- If you pass false to this functions the function will return false if you are in game but the game is paused if you pass true the function will return true if you are in game (doesn't matter if the game is paused or not)

  2. void Game.WriteText(string text, FRAME frame, float duration) -- Frames are stated below

  3. void Game.ExecuteCmd(unit Unit, COMMAND cmd, float x, float y, unit target) -- Commands are stated below

  4. string Game.GetMapName()

  5. AbilityState Game.GetAbilityState(unit Unit, integer abilityID) -- Ability states are stated below

  6. bool Game.SendChat(string message, bool bSendToAll, bool bForceMaximizeGame)

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)
框架:

  1. FRAME.MESSAGEFRAME.UNITFRAME.CHATFRANE.TOP

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)
命令:

  1. CMD.MOVECMD.ATTACKCMD.HOLDCMD.STOP您还可以将自定义代码作为整数传递(您可以通过提取地图并从war3map.j读取来获取法术的代码文件)

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)能力状态:

  1. ABILITY_STATE.READYABILITY_STATE.COOLDOWNABILITY_STATE.INVALID

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)还可以使用一些通用功能:

  1. Sleep(integer milliseconds) -- Same as WinAPI Sleep functionGetPlugins() -- Return a table containing handle of all loaded pluginsGetVersion() -- Return the version of the lua engine you're currently using as stringjParamStr2cStr(jParmStr) -- Get a readble string from the jass string handle in native parameters (only usable in hooked native functions)jHandleStr2cStr(jHandleStr) -- Get a readble string from the jass string handle in native return values (only usable in hooked native functions)cStr2jParamStr(cStr) -- Convert an string to jass param string handle (only usable in hooked native functions)GetFloat(jFloat) -- Convert jass floating points handles to readble floating point (only usable in hooked native functions)MakeFloat(float) -- Convert floating point to jass floating point handle  (only usable in hooked native functions)

复制代码

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com)

来源:https://www.tulaoshi.com/n/20170929/2673113.html

延伸阅读
《热血魔兽》新手体验心得 热血魔兽今天也终于内测了,那么游戏中刚刚入门大家都应该注意些什么呢?下面小编为大家带来热血魔兽新手体验心得分享,一起看看吧。 1.初入游戏 刚进入游戏,最纠结的莫过于选什么职业,我的建议是选牛头和月女,因为不管是花钱还是不花钱,这游戏你只要想...
标签: 网络游戏
魔兽世界--魔兽世界版《最炫民族风》   《魔兽世界》(World of Warcraft、简称WoW或魔兽)是著名的游戏公司暴雪娱乐(Blizzard Entertainment)所制作的一款大型多人在线角色扮演游戏(MMORPG),于2004年年中在北美公开测试。《魔兽世界》在中国大陆的前代理商为第九城市,2005年3月21日下午开始限量测试,2005年4月23日关闭限量测试...
《小小魔兽》拉格纳罗斯通关心得 下面分享一下《小小魔兽》地下城拉格纳罗斯的通关心得,主要是简单的就介绍一下打法和难点,希望对大家有所帮助。 推荐战力4W3至少(2.3之后版本) 推荐阵容 :3输出,1肉盾,1主奶,1辅助 1:磨血到90,躲,继续杀 2:磨血到70,躲,继续杀 ...
《火炬之光》成为魔兽世界资料片大灾变玩法 【劲爆】简单操作——火炬之光成为 WOW资料片 【大灾变】 ,领先全球!!(玩法) 不好意思,做了回标题党~~~~ 嘿嘿 说下 玩法 首先您需要 修改器! 建立一个人物 把你的人物修改到 85级 技能点84点 属性...
《全民魔兽》什么英雄值得培养?潜力英雄分析 全民魔兽什么英雄值得培养: 在小编看来但凡卡牌养成手游必要面对英雄培养问题,这也是卡牌养成手游的乐趣之一,培养不同的英雄发展方向也不一样,所以在小编认为归纳总结出有发展潜力的英雄是非常有必要的。这不仅仅是为了让老玩家们更好...

经验教程

830

收藏

99
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部