Skip to content

Commit

Permalink
Add basic support for spawning entities through Lua
Browse files Browse the repository at this point in the history
 - Not very well tested, but is able to spawn info_ff_scripts like flags and have them work like normal
 - Added baseentity:SetName(string name)
 - Added global function SpawnEntity(string entity_class_name, string entity_name) that returns the entity spawned or nil if unsuccessful (example: `local entity = SpawnEntity("info_ff_script", "red_flag")`)
 - Added global function SpawnEntity(string entity_class_name) that returns the entity spawned or nil if unsuccessful (example: `local entity = SpawnEntity("info_ff_script")`)
 - Closes #63
  • Loading branch information
squeek502 committed Jun 18, 2016
1 parent 4748651 commit b6ddcab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions dlls/ff/ff_lualib_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void CFFLuaLib::InitBase(lua_State* L)
.def("StopSound", (void(CBaseEntity::*)(const char*))&CBaseEntity::StopSound)
.def("GetClassName", &CBaseEntity::GetClassname)
.def("GetName", &CBaseEntity::GetName)
.def("SetName", &CBaseEntity::SetName)
.def("GetTeam", &CBaseEntity::GetTeam)
.def("GetTeamId", &CBaseEntity::GetTeamNumber)
.def("GetId", &CBaseEntity::entindex)
Expand Down
20 changes: 19 additions & 1 deletion dlls/ff/ff_lualib_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,22 @@ namespace FFLib
_menuman.RemoveLuaMenuOption( szMenuName, iSlot );
}

CBaseEntity* SpawnEntity(const char *szEntityClassName, const char *szEntityName)
{
CBaseEntity *pEntity = CreateEntityByName(szEntityClassName);
if (szEntityName && pEntity)
{
pEntity->SetName( MAKE_STRING(szEntityName) );
}
int status = DispatchSpawn(pEntity);
return status == 0 ? pEntity : NULL;
}

CBaseEntity* SpawnEntity(const char *szEntityClassName)
{
return SpawnEntity(szEntityClassName, NULL);
}

} // namespace FFLib

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3238,6 +3254,8 @@ void CFFLuaLib::InitGlobals(lua_State* L)
def("DestroyMenu", &FFLib::DestroyMenu),
def("SetMenuTitle", &FFLib::SetMenuTitle),
def("AddMenuOption", &FFLib::AddMenuOption),
def("RemoveMenuOption", &FFLib::RemoveMenuOption)
def("RemoveMenuOption", &FFLib::RemoveMenuOption),
def("SpawnEntity", (CBaseEntity*(*)(const char *))&FFLib::SpawnEntity),
def("SpawnEntity", (CBaseEntity*(*)(const char *, const char *))&FFLib::SpawnEntity)
];
}

0 comments on commit b6ddcab

Please sign in to comment.