Here is my first piece of code for Cafu. I am a big fan of opening as much up as possible in lua, so to give someone an option to create a custom GUI for a particular weapon for example, I decided to expose the current active weapon slot to lua.
I haven't been able to test it yet, as I can't figure out any code to indicate if it is working or not in lua, any feedback on whether it looks correct or not would be great
HumanPlayer.hpp:95 - I added the line
Code: Select all
static int GetActiveWeaponSlot(lua_State* LuaState);
Then it was onto create the exposure code.
HumanPlayer.cpp
Code: Select all
//Line 94 Added:
{ "GetActiveWeaponSlot", EntHumanPlayerT::GetActiveWeaponSlot },
//At the end of the file, Line 1375 I added:
int EntHumanPlayerT::GetActiveWeaponSlot(lua_State* LuaState)
{
cf::ScriptBinderT Binder(LuaState);
IntrusivePtrT<EntHumanPlayerT> Ent = Binder.GetCheckedObjectParam< IntrusivePtrT<EntHumanPlayerT> >(1);
const EntityStateT& State = Ent->State;
if (State.ActiveWeaponSlot)
{
lua_pushstring(LuaState, State.ActiveWeaponSlot)
}
else
{
// Let the HUD know that we have no weapon.
lua_pushstring(LuaState, "");
}
return 1;
}