Newbie Spellweaver
- Joined
- Sep 1, 2024
- Messages
- 26
- Reaction score
- 17
Not sure if this works or not or if anyone's tried. I just noticed it while cleaning up, and thought It'd be something interesting to point out.
ItemScript.lua is a script that was made to give certain bonuses to items, either as an event, or as a test to move items towards lua. You can essentially run a server bonus on selected items, or mimic functionality via script.
To renable
and fix this to newer lua
luaL_openlibs loads standard lua libraries in the lua vm. You can load individual libraries apparently to avoid the extra overhead.
When the server starts, the following is ran:
Which then, it'll bind the static functions in the same file as the 'CompileItemScript' function and then it compiles the lua script.
Currently, the system was never completed or used, but the only two implementations they've had was set and reset destparam. It'd look for the function and if found, it'll call the function:
itemscript.lua
As you can see, the "Use" function is not implemented. Also, one of the downfalls is the requirements of calling equip and unequip, otherwise, you're creating stat stacking methods. You could redesign this to be a table or an array of data instead of the functions and have a lua function to call a search on it, or load the data in to C++ memory instead, which is probably why this system didn't go anywhere.
But, depending on the nature of what you want, remember there's scriptable and reloadable toolsets available which is the main reason im pointing this out. IE: you could adopt this in to Event.lua and make certain items have event bonuses.
Most of CFlyFF is Lua.
ItemScript.lua is a script that was made to give certain bonuses to items, either as an event, or as a test to move items towards lua. You can essentially run a server bonus on selected items, or mimic functionality via script.
To renable
C++:
#define __LUASCRIPT060908
and fix this to newer lua
C++:
BOOL InitializeScriptLib()
{
#if !defined(__LUASCRIPT060908)
return TRUE;
#else
g_VM = luaL_newstate(); // creates a new lua engine state
luaL_openlibs(g_VM);
return TRUE;
#endif
}
luaL_openlibs loads standard lua libraries in the lua vm. You can load individual libraries apparently to avoid the extra overhead.
When the server starts, the following is ran:
C++:
if (CompileItemScript("ItemScript.lua") == FALSE)
return FALSE;
Which then, it'll bind the static functions in the same file as the 'CompileItemScript' function and then it compiles the lua script.
C++:
lua_register( pVM, "Trace", Trace );
lua_register( pVM, "SetDestParam", _SetDestParam );
lua_register( pVM, "ResetDestParam", _ResetDestParam );
if( luaL_dofile( pVM, szFile ) !=0 )
Currently, the system was never completed or used, but the only two implementations they've had was set and reset destparam. It'd look for the function and if found, it'll call the function:
C++:
BOOL RunItemScript( CMover* pMover, DWORD dwItemID, ITEM_OP operation, int* pResult )
{
#if !defined(__LUASCRIPT060908)
return TRUE;
#endif
char szFunction[64];
// uses the ItemId to look for specific functions
if( operation == ITEM_OP_USE )
sprintf( szFunction, "F%d_use", dwItemID );
else if( operation == ITEM_OP_EQUIP )
sprintf( szFunction, "F%d_equip", dwItemID );
else if( operation == ITEM_OP_UNEQUIP )
sprintf( szFunction, "F%d_unequip", dwItemID );
lua_State* pVM = GetVM();
lua_pushstring( pVM, szFunction );
lua_gettable( pVM, -2 );
if ( lua_isfunction( pVM, -1 ) )
{
lua_pushlightuserdata( pVM, pMover ); // 1st arg
lua_call( pVM, 1, 1 );
if( pResult )
*pResult = (int)lua_tonumber( pVM, -1 ); // return value
lua_pop( pVM, 1);
return TRUE;
}
lua_pop( pVM, 1);
return FALSE;
}
itemscript.lua
Code:
-- Predefine some variables
DST_STR = 1
DST_DEX = 2
DST_INT = 3
DST_STA = 4
-- Long sword contains the ID of 23.
function F23_equip( pMover )
Trace( "Longsword equiped" ) -- calls the Trace debugging function in c++
SetDestParam( pMover, DST_STR, 3 ); -- this will call the _SetDestParam C++ function
return 1
end
function F23_unequip( pMover )
Trace( "LongSword unequiped" )
ResetDestParam( pMover, DST_STR, 3 );
return 1
end
As you can see, the "Use" function is not implemented. Also, one of the downfalls is the requirements of calling equip and unequip, otherwise, you're creating stat stacking methods. You could redesign this to be a table or an array of data instead of the functions and have a lua function to call a search on it, or load the data in to C++ memory instead, which is probably why this system didn't go anywhere.
But, depending on the nature of what you want, remember there's scriptable and reloadable toolsets available which is the main reason im pointing this out. IE: you could adopt this in to Event.lua and make certain items have event bonuses.
Most of CFlyFF is Lua.
Last edited: