Skip to content

Commit

Permalink
game: make Lua ent create no longer set a static classname (see script
Browse files Browse the repository at this point in the history
create), fix possible crash
  • Loading branch information
IR4T4 committed Jan 8, 2019
1 parent 8041122 commit ab12171
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/game/g_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ gentity_t *G_Lua_CreateEntity(char *params)
if (level.numSpawnVars == MAX_SPAWN_VARS)
{
// see above note
G_Printf("%s API: can't spawn and entity - MAX_SPAWN_VARS reached.\n", LUA_VERSION);
G_Printf("%s API: can't spawn an entity - MAX_SPAWN_VARS reached.\n", LUA_VERSION);
return NULL;
}

Expand All @@ -1324,7 +1324,12 @@ gentity_t *G_Lua_CreateEntity(char *params)
}
create = G_SpawnGEntityFromSpawnVars();

create->classname = "lua_spawn"; // make additional param?
//create->classname = "lua_spawn"; // make additional param?

if (!create) // don't link NULL ents
{
return NULL;
}

trap_LinkEntity(create);
return create;
Expand Down
2 changes: 2 additions & 0 deletions src/game/g_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ void G_Script_ScriptParse(gentity_t *ent)
{
if (wantScript)
{
// note: There are maps available which don't start anymore
// Fix the mapscripts!
G_Error("G_Script_ScriptParse(), Error (line %d): '{' expected, but found '%s'.\n", COM_GetCurrentParseLine(), token);
}

Expand Down
5 changes: 5 additions & 0 deletions src/game/g_script_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -5137,6 +5137,11 @@ qboolean G_ScriptAction_Create(gentity_t *ent, char *params)
}
create = G_SpawnGEntityFromSpawnVars();

if (!create)
{
return qfalse; // don't link NULL ents
}

trap_LinkEntity(create);
return qtrue;
}
2 changes: 2 additions & 0 deletions src/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ gentity_t *G_SpawnGEntityFromSpawnVars(void)
G_SpawnInt("notteam", "0", &i);
if (i)
{
G_Printf("G_SpawnGEntityFromSpawnVars Warning: Can't spawn entity in team games - returning NULL\n");

G_FreeEntity(ent);
return NULL;
}
Expand Down

0 comments on commit ab12171

Please sign in to comment.