Examples - nosoop/SM-LevelKeyValues GitHub Wiki
Here are some examples of what Level KeyValues is capable of:
// global forward that gets called after a block of key/value pairs comprising an entity is parsed
// any return value other than Plugin_Stop will add the block to the level entity list to be serialized later
public Action LevelEntity_OnEntityKeysParsed(LevelEntityKeyValues entity) {
char classname[64];
entity.GetString("classname", classname, sizeof(classname));
// remove any spawn areas that don't have team numbers
// TF2 navigation meshes treat areas as the wrong team when they are present
if (StrEqual(classname, "info_player_teamspawn") && !entity.GetNum("TeamNum")) {
return Plugin_Stop;
}
// swap intel teams and capture zones around
// make sure you're on CTF first though
if (StrEqual(classname, "item_teamflag") || StrEqual(classname, "func_capturezone")) {
switch (entity.GetNum("TeamNum")) {
case TFTeam_Red: {
entity.Remove("TeamNum");
entity.AddNum("TeamNum", TFTeam_Blue);
}
case TFTeam_Blue: {
entity.Remove("TeamNum");
entity.AddNum("TeamNum", TFTeam_Red);
}
}
}
return Plugin_Continue;
}
// global forward that gets called once all entity blocks are parsed, you may do things with the entire list
public void LevelEntity_OnAllEntitiesParsed() {
LevelEntityKeyValues hostage = new LevelEntityKeyValues();
float origin[] = { 1376.0, 3168.0, -112.0 }, angles[] = { 0.0, 111.0, 0.0 };
hostage.AddVector("origin", origin);
hostage.AddNum("HostageType", 0);
hostage.AddVector("angles", angles);
hostage.AddString("classname", "hostage_entity");
LevelEntityList.Push(hostage);
delete hostage;
}