View previous topic :: View next topic |
Author |
Message |
pardik
Joined: 13 Feb 2010 Posts: 6 Location: Modena - Italy
|
Posted: Wed Dec 08, 2010 2:12 Post subject: nwnx_lua |
|
|
Starting from the great nwnx_ruby by elven, I have written a plugin to embed the lua language into nwn.
If someone wants to try out, debug or contribute you are welcome.
I'am only an hobbist in programming so please be kind with me.
here is the link
http://dl.dropbox.com/u/1285601/nwnx_lua.7z
Please look at the examples provided and in the source, sorry but there are no docs for now, only a readme. |
|
Back to top |
|
|
pardik
Joined: 13 Feb 2010 Posts: 6 Location: Modena - Italy
|
Posted: Sun Dec 26, 2010 14:46 Post subject: |
|
|
here is a new version of nwnx_lua, please redownload it from the same link above. I have polished and rewritten the code: now ALL functions from nwscript are set.
I am curious if someone as tried it already, in case let me know please.
nwnx_lua provides a Lua Eval function and an Event function to nwscript, see examples in the scripts dir.
ALL function of the base nwscript are set and defined inside LUA, including function for talent, event and itemproperty functions.
Nwscript functions that return TRUE or FALSE return a boolean value (true, false) inside Lua, in the same manner all function that accept TRUE or FALSE in nwscript inside Lua accept booleans.
- Eval lua code inside nwscript you can write code like this:
LuaEvalVoid("ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectBlindness(), GetFirstPC(), 0.0)");
or:
LuaEvalVoid("local oPC=GetFirstPC; if GetIsPC(oPC) then SendMessageToPC(oPC, 'Welcome '..GetName(oPC)) end");
- Event function
ini option: eventListener = "Lua function"
The event listener accepts two arguments; event (string) and object (number)
example:
run_event(event, obj)
event is a string (ex. 'mod_load'), obj is a number (integer) representing the object calling the event itself.
Calling event inside NWScript, example:
void LuaRunEvent(string sEvent, object oSelf=OBJECT_SELF)
{
SetLocalString(GetModule(), "NWNX!LUA!EVENT", sEvent+":0x"+ObjectToString(oSelf));
}
LuaRunEvent("mod_load", GetModule());
In the preload script provided there is an example of run_event function.
- SCORCO listener
ini option: sco and rco
The SCORCO listeners are an rco(key, player) function and an sco(key, player, data) function
examples in the scripts provided,inside Lua they are called like in these examples:
--
Scorco.scorco_proc = function(data)
data = mysql.escape_string(data)
DB:query(string.format("REPLACE INTO variables SET value='%s', tag='%s', type='object', name='%s'", data, GetTag(obj), name))
end
StoreCampaignObject("LUA", "-", value, obj)
--
DB:query(string.format("SELECT value FROM variables WHERE tag='%s' AND type='%s' AND name='%s'", GetTag(obj), otype, name))
local var = res:fetch_assoc()
Scorco.scorco_res = var['value']
RetrieveCampaignObject("LUA", "-", loc, owner, obj)
The following functions: DelayCommand, AssignCommand and ActionDoCommand, are implemented via relay scripts.
They are defined in the example script supplied (in the ./scripts directory)
The three functions above are called via the TOKEN library and the tokenListener function.
Here is an example of a DelayCommand Implementation:
DelayCommand(6.0, oPC, ClearAllActions, {true})- arguments are: 1- time to delay, 2 object, 3 function to be called, 4 arguments of the function as a table
the same for AssignCommand and ActionDoCommand |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Thu Jun 02, 2011 18:14 Post subject: |
|
|
Would you agree to me merging this into branches/core-2.8/plugins? |
|
Back to top |
|
|
pardik
Joined: 13 Feb 2010 Posts: 6 Location: Modena - Italy
|
Posted: Tue Jun 07, 2011 20:45 Post subject: |
|
|
elven wrote: | Would you agree to me merging this into branches/core-2.8/plugins? |
I agree, I released nwnx_lua for the nwnx community, so you can do what you think is better. |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Tue Jun 07, 2011 20:46 Post subject: |
|
|
Alright, thank you.
I will probably do that after core-2.8 is merged into trunk, for simplicity reasons. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|