Commit 95844961 authored by Mikleo's avatar Mikleo
Browse files

Folder structure changed. (prefabs/modelshortcuts)

preset renamed to prefab.
Commander The Flag template on highpass.
parent 3bed1ca7
Pipeline #12072 passed with stages
in 15 seconds
......@@ -10,7 +10,7 @@
#include <SteamWorks>
#define PluginVersion "1.28"
#define PluginVersion "1.29"
float pVersion;
// note linearmap field is unstable
......@@ -55,7 +55,7 @@ char lastCommand[64];
bool usedFlagIndex[32] = {false,...};
ConVar ef_editlock,ef_baseswap,ef_scenario_vote_delay,ef_scenario_vote_duration,ef_scenario_vote_runoff_duration,ef_scenario_vote_min_timeleft,ef_scenario_vote_display_description,ef_scenario_vote_display_name,ef_scenario_vote_display_tags,ef_scenario_reload_map_config,ef_votelist_base,ef_alledit,ef_downloadeditorcfg,ef_disablevehicletakedamage,ef_useblockmodels;
ConVar ef_editlock,ef_baseswap,ef_scenario_vote_delay,ef_scenario_vote_duration,ef_scenario_vote_runoff_duration,ef_scenario_vote_min_timeleft,ef_scenario_vote_display_description,ef_scenario_vote_display_name,ef_scenario_vote_display_tags,ef_scenario_reload_map_config,ef_votelist_base,ef_alledit,ef_downloadeditorcfg,ef_useblockmodels;
ConVar emp_sv_commander_freeze_time, emp_sv_player_refinery_multiplier, emp_sv_refinery_multiplier;
......@@ -67,10 +67,12 @@ char nextMapScenario[64];
int idxArmor;
char customPresetFilePath[] = "scenarios/custom_presets.txt";
char standardPresetFilePath[] = "scenarios/standard_presets.txt";
char customVehiclePresetFilePath[] = "scenarios/custom_vehiclepresets.txt";
char standardVehiclePresetFilePath[] = "scenarios/standard_vehiclepresets.txt";
char PrefabFolderPath[] = "scenarios/_prefabs";
char VehicleFolderPath[] = "scenarios/_prefabs/vehicles";
char lastLevelOverride[64];
int lastLevelOverrideTime;
......@@ -183,7 +185,7 @@ public void OnPluginStart()
RegConsoleCmd("sm_scenariolist", Command_Scenario_List);
// save a preset here
RegAdminCmd("sm_savepreset", Command_Save_Preset, ADMFLAG_SLAY);
RegAdminCmd("sm_saveprefab", Command_Save_Prefab, ADMFLAG_SLAY);
RegAdminCmd("sm_scenariovar", Command_Scenario_Var, ADMFLAG_SLAY);
RegAdminCmd("sm_scenariovote", Command_Scenario_Vote, ADMFLAG_SLAY);
RegAdminCmd("sm_scenariovotelist", Command_Scenario_Votelist, ADMFLAG_SLAY);
......@@ -205,7 +207,6 @@ public void OnPluginStart()
RegAdminCmd("sm_commandlog", Command_Command_Log, ADMFLAG_SLAY);
ef_disablevehicletakedamage = CreateConVar("ef_disablevehicletakedamage", "1", "disable using SDKHooks_TakeDamage on vehicles");
ef_editlock = CreateConVar("ef_editlock", "1", "prevent admins from edit map entities/resources/tickets after game has begun.");
ef_baseswap = CreateConVar("ef_baseswap", "0", "Enable Base Swapping");
// set to 0 in case cvar already existed.
......@@ -1046,11 +1047,11 @@ public Action Command_Action(int client,int args)
}
else if (StrEqual(arg,"vehicle",false))
{
createdEntity = Load_Preset(client,arg,true,position);
createdEntity = Load_Prefab(client,arg,true,position);
}
else if (StrEqual(arg,"preset",false))
else if (StrEqual(arg,"prefab",false))
{
createdEntity = Load_Preset(client,arg,false,position);
createdEntity = Load_Prefab(client,arg,false,position);
}
else if(StrEqual(arg,"buildable",false))
{
......@@ -1509,7 +1510,7 @@ int Create_Building( int client, char[] nfclassname,char[] beclassname,float pos
return entindex;
}
public int Load_Preset(int client,char[] presetName,bool isVehicle,float position[3])
public int Load_Prefab(int client,char[] presetName,bool isVehicle,float position[3])
{
......@@ -1520,9 +1521,9 @@ public int Load_Preset(int client,char[] presetName,bool isVehicle,float positio
if(isVehicle)
PrintToChat(client,"/create vehicle [presetname] \n look at console for a list of presets");
else
PrintToChat(client,"/create preset [presetname] [optional:teamOverride] [optional:pointNumberOverride] \n look at console for a list of presets");
PrintToChat(client,"/create prefab [presetname] [optional:teamOverride] [optional:pointNumberOverride] \n look at console for a list of presets");
PrintAllPresetsToConsole(client,isVehicle);
PrintAllPrefabsToConsole(client,isVehicle);
return -2;
}
......@@ -1549,10 +1550,10 @@ public int Load_Preset(int client,char[] presetName,bool isVehicle,float positio
float angles[3] = {0.0,0.0,0.0};
if(!BaseSpawnPreset(client,arg,isVehicle,position,angles,overrideTeam,overridePointNumber))
if(!BaseSpawnPrefab(client,arg,isVehicle,position,angles,overrideTeam,overridePointNumber))
{
PrintToChat(client,"preset %s not found, look at console for a list of valid presets",arg);
PrintAllPresetsToConsole(client,isVehicle);
PrintAllPrefabsToConsole(client,isVehicle);
return -1;
}
......@@ -1567,13 +1568,13 @@ public int Load_Preset(int client,char[] presetName,bool isVehicle,float positio
return -2;
}
bool BaseSpawnPreset(int client,char[] presetName,bool isVehicle,float position[3],float angles[3],int overrideTeam = -1,int overridePointNumber = -1)
bool BaseSpawnPrefab(int client,char[] presetName,bool isVehicle,float position[3],float angles[3],int overrideTeam = -1,int overridePointNumber = -1)
{
// do it once so don't get out of sync
int timeID = GetTime()%9000000;
KeyValues kv = GetPreset(presetName,isVehicle);
KeyValues kv = GetPrefab(presetName,isVehicle);
bool success = true;
char nameBuffer[128];
......@@ -1628,7 +1629,7 @@ bool BaseSpawnPreset(int client,char[] presetName,bool isVehicle,float position[
kv.SetNum("pointNumber",0);
}
int newEntity = LoadPreset(kv);
int newEntity = LoadPrefab(kv);
if(client > 0 && IsValidEntity(newEntity))
{
AddToSelection(client,newEntity);
......@@ -1656,7 +1657,7 @@ void KVAddIDStamp(KeyValues kv,char[] key,int IDStamp)
}
}
// save all the selected entities.
public Action Command_Save_Preset(int client, int args)
public Action Command_Save_Prefab(int client, int args)
{
if(selectedEntities[client] == null || selectedEntities[client].Length == 0)
{
......@@ -1673,9 +1674,8 @@ public Action Command_Save_Preset(int client, int args)
return Plugin_Handled;
}
KeyValues kv = new KeyValues("Presets");
KeyValues kv = new KeyValues("Prefabs");
......@@ -1686,13 +1686,26 @@ public Action Command_Save_Preset(int client, int args)
char className[64];
GetEntityClassname(originEntity, className, sizeof(className));
char folderpath[64];
if(selectedEntities[client].Length == 1 && StrEqual(className,"emp_vehicle",false))
kv.ImportFromFile(customVehiclePresetFilePath);
strcopy(folderpath,sizeof(folderpath),VehicleFolderPath);
else
kv.ImportFromFile(customPresetFilePath);
strcopy(folderpath,sizeof(folderpath),PrefabFolderPath);
char filepath[64];
if (GetCmdArg(2, filepath, sizeof(filepath)))
{
Format(filepath,sizeof(filepath),"%s/%s.txt",folderpath,filepath);
kv.ImportFromFile(filepath);
}
else
{
Format(filepath,sizeof(filepath),"%s/%s.txt",folderpath,name);
}
// remove the current contents of the key.
kv.DeleteKey(name);
kv.JumpToKey(name,true);
......@@ -1731,12 +1744,15 @@ public Action Command_Save_Preset(int client, int args)
kv.Rewind();
kv.ExportToFile(customPresetFilePath);
kv.ExportToFile(filepath);
delete kv;
PrintToChatAll("Saved the preset as %s",name);
PrintToChatAll("Saved the prefab as %s",name);
return Plugin_Handled;
......@@ -2262,16 +2278,8 @@ ExecuteRemoveEntity(int entity)
if(StrEqual(className,"emp_vehicle",true))
{
if(ef_disablevehicletakedamage.IntValue == 0)
SDKHooks_TakeDamage(entity, 0, 0, 100000.0, 0, 0);
else
{
// try this instead.
SetVariantInt(0);
AcceptEntityInput(entity,"SetHealth");
}
SDKHooks_TakeDamage(entity, 0, 0, 100000.0, 0, 0);
int presetEnt = -1;
int spawnerEnt = GetVehicleSpawnerEnts(entity,presetEnt);
......@@ -3016,7 +3024,7 @@ int CloneEntity(int entity,char [] className, float[3] position, int timeID = -1
return newEntity;
}
int LoadPreset(KeyValues kv)
int LoadPrefab(KeyValues kv)
{
char className[32];
kv.GetString("className",className,sizeof(className));
......@@ -3028,7 +3036,7 @@ int LoadPreset(KeyValues kv)
}
else
{
PrintToServer("Failed to create preset entity %s",className);
PrintToServer("Failed to create prefab entity %s",className);
}
return entity;
......@@ -3678,7 +3686,6 @@ public Action Command_Scenario_Info(int client, int args)
ShowScenarioInfo(client,12,true);
return Plugin_Handled;
}
......@@ -6138,7 +6145,7 @@ bool GetModelName(char[] shortcut,char[] output,int outputSize,float[3] offset,
{
if(!GetModelNameFromShortcut(shortcut,"scenarios/custom_modelshortcuts.txt",output,outputSize,offset,offsetAngles,disableShadows))
{
return GetModelNameFromShortcut(shortcut,"scenarios/standard_modelshortcuts.txt",output,outputSize,offset,offsetAngles,disableShadows);
return GetModelNameFromShortcut(shortcut,"scenarios/core_modelshortcuts.txt",output,outputSize,offset,offsetAngles,disableShadows);
}
return true;
}
......@@ -6154,74 +6161,130 @@ bool GetModelNameFromShortcut(char[] shortcut,char[] file,char[] output,int outp
delete kv;
return strlen(output) > 0;
}
KeyValues GetPreset(char[] preset, bool isVehicle)
KeyValues GetPrefab(char[] prefabName, bool isVehicle)
{
KeyValues kv;
if(isVehicle)
{
kv = GetPresetFromFile(preset,customVehiclePresetFilePath);
if(kv == null)
kv = GetPresetFromFile(preset,standardVehiclePresetFilePath);
kv = GetPrefabFromFolder(prefabName,VehicleFolderPath);
}
else
{
kv = GetPresetFromFile(preset,customPresetFilePath);
if(kv == null)
kv = GetPresetFromFile(preset,standardPresetFilePath);
kv = GetPrefabFromFolder(prefabName,PrefabFolderPath);
}
return kv;
}
KeyValues GetPresetFromFile(char[] preset,char[] file)
// change to get prefab from folder.
KeyValues GetPrefabFromFolder(char[] prefabName,char[] folder)
{
KeyValues kv = new KeyValues("Shortcuts");
kv.ImportFromFile(file);
if(KVHasKey(kv,preset))
KeyValues kv = new KeyValues("Prefabs");
char filePath[64];
char fileBuffer[64];
bool foundItem = false;
for(int i= 0;i<2 && !foundItem;i++)
{
kv.JumpToKey(preset,true);
DirectoryListing dL = OpenDirectory(folder);
if(dL != null)
{
while (dL.GetNext(fileBuffer, sizeof(fileBuffer)))
{
bool isStandard = StrContains(fileBuffer,"core_",true) >= 0;
if((i == 0 && !isStandard) || (i == 1 && isStandard))
{
Format(filePath,sizeof(filePath),"%s/%s",folder,fileBuffer);
if(kv.ImportFromFile(filePath) && KVHasKey(kv,prefabName))
{
kv.JumpToKey(prefabName);
foundItem = true;
break;
}
else
kv.DeleteThis();
}
}
}
delete dL;
}
if(foundItem)
return kv;
else
{
delete kv;
kv = null;
return null;
}
return kv;
}
void PrintAllPresetsToConsole(int client, bool isVehicle)
void PrintAllPrefabsToConsole(int client, bool isVehicle)
{
if(isVehicle)
{
PrintPresetsToConsole(client,customVehiclePresetFilePath);
PrintPresetsToConsole(client,standardVehiclePresetFilePath);
PrintPrefabsFromFolderToConsole(client,VehicleFolderPath);
}
else
{
PrintPresetsToConsole(client,customPresetFilePath);
PrintPresetsToConsole(client,standardPresetFilePath);
PrintPrefabsFromFolderToConsole(client,PrefabFolderPath);
}
}
void PrintPresetsToConsole(int client,char[] filepath)
void PrintPrefabsFromFolderToConsole(int client,char[] folder)
{
KeyValues kv = new KeyValues("Preset");
kv.ImportFromFile(filepath);
char buffer[128];
kv.GotoFirstSubKey(false);
do
char filePath[64];
char fileBuffer[64];
for(int i= 0;i<2;i++)
{
kv.GetSectionName(buffer, sizeof(buffer));
// special character for internal presets
if(buffer[0] != '$')
DirectoryListing dL = OpenDirectory(folder);
if(dL != null)
{
PrintToConsole(client,buffer);
while (dL.GetNext(fileBuffer, sizeof(fileBuffer)))
{
bool isStandard = StrContains(fileBuffer,"core_",true) >= 0;
if((i == 0 && !isStandard) || (i == 1 && isStandard))
{
Format(filePath,sizeof(filePath),"%s/%s",folder,fileBuffer);
PrintPrefabsToConsole(client,filePath);
}
}
}
} while (kv.GotoNextKey(false));
kv.Rewind();
delete dL;
}
}
void PrintPrefabsToConsole(int client,char[] filepath)
{
KeyValues kv = new KeyValues("Prefabs");
if(kv.ImportFromFile(filepath))
{
char buffer[128];
kv.GotoFirstSubKey(false);
do
{
kv.GetSectionName(buffer, sizeof(buffer));
// special character for internal presets
if(buffer[0] != '$')
{
PrintToConsole(client,buffer);
}
} while (kv.GotoNextKey(false));
}
delete kv;
}
......@@ -6229,8 +6292,8 @@ void PrintPresetsToConsole(int client,char[] filepath)
void PrintModelShortcutsToConsole(int client)
{
PrintModelShortcutFileToConsole(client,"scenarios/custom_modelshortcuts.txt");
PrintModelShortcutFileToConsole(client,"scenarios/standard_modelshortcuts.txt");
PrintModelShortcutFileToConsole(client,"scenarios/_modelshortcuts/custom_modelshortcuts.txt");
PrintModelShortcutFileToConsole(client,"scenarios/_modelshortcuts/core_modelshortcuts.txt");
}
void PrintModelShortcutFileToConsole(int client,char[] file)
{
......
......@@ -7,6 +7,8 @@
typedef OnCloseCommand = function void (int commandID);
// return entity to target or -1
typedef OnCommandFunction= function int (int entity,char[] args,char[] remainder);
......@@ -36,7 +38,7 @@ enum struct ScriptEnum {
char context[32];
}
OnCommandFunction commandFunctions[40];
OnCommandFunction commandFunctions[64];
// max args is handy for error checking. Especially for missing quotes.
int maxCommandArgs[40];
bool autoReplaceVariables[40];
......@@ -79,6 +81,7 @@ void Funcs_OnPluginStart()
AddCommand("TargetClassnameAll",TargetClassnameAllCommand,6);
AddCommand("TargetParams",TargetParamsCommand,0);
AddCommand("FilterTeam",FilterTeamCommand,1);
AddCommand("FilterClassname",FilterClassnameCommand,1);
AddCommand("SetHealth",SetHealthCommand,1);
AddCommand("TakeDamage",TakeDamageCommand,1);
AddCommand("Cancel",CancelCommand,100);
......@@ -89,6 +92,8 @@ void Funcs_OnPluginStart()
AddCommand("Set",SetVariable,10,false);
AddCommand("Inc",IncVariable,1,false);
AddCommand("Dec",DecVariable,1,false);
AddCommand("OnStartTouch",OnStartTouchHookCommand,2,false);
AddCommand("OnEndTouch",OnEndTouchHookCommand,2,false);
......@@ -188,7 +193,6 @@ void Funcs_OnMapStart()
void Funcs_OnGameStart()
{
LoadScript("OnGameStart",EU_ParamEntity());
LoadScriptBeginning("s_",EU_ParamEntity());
......@@ -197,7 +201,6 @@ void Funcs_OnGameEnd()
{
// clear all game scripts here. its just easier to handle
ClearCommands();
LoadScript("OnGameEnd",EU_ParamEntity());
LoadScriptBeginning("e_",EU_ParamEntity());
}
void Funcs_OnMapEnd()
......@@ -213,7 +216,6 @@ void Funcs_AfterLoadScenario()
{
ProcessScripts();
LoadScriptBeginning("i_",EU_ParamEntity());
LoadScript("OnScenarioLoaded",EU_ParamEntity());
}
void ClearCommands()
{
......@@ -289,13 +291,17 @@ void OnCloseDefault(int commandID)
}
int CreateCommand(int entity,Handle timer,OnCloseCommand closeCommand,char[] remainder,char[] userIdentifier,char[] stringSlot1,int intSlot1 = -1)
int CreateCommand(int entRef,Handle timer,OnCloseCommand closeCommand,char[] remainder,char[] userIdentifier,char[] stringSlot1,int intSlot1 = -1)
{
CommandTrack commandTrack;
// make sure to save as a reference.
if(entRef >= 0 )
entRef = EntIndexToEntRef(entRef);
CommandTrack commandTrack;
commandTrack.index = -1;
commandTrack.entRef = entity;
commandTrack.entRef = entRef;
commandTrack.timerHandle = timer;
commandTrack.closeCommand = closeCommand;
commandTrack.intSlot1 = intSlot1;
......@@ -516,6 +522,7 @@ bool LoadScript(char[] scriptname,int entRef)
}
else
{
PrintToServer("Couldent find script %s \n %s",scriptname,scriptContext);
found = false;
}
}
......@@ -726,7 +733,16 @@ public bool EvaluateCondition(int entity,char[] condition)
char conditionType[32];
BreakArg(condition,conditionType,sizeof(conditionType),argIndex);
if(!BreakArg(condition,conditionType,sizeof(conditionType),argIndex))
{
// evaluate single boolean condition
float value1Float = StringToFloat(value1);
if(value1Float > 0.0)
return true;
else
return false;
}
char value2[32];
BreakArg(condition,value2,sizeof(value2),argIndex);
......@@ -940,6 +956,8 @@ public int InputCommand(int entity,char[] args,char[] remainder)
}
public int HookOutputCommand(int entity,char[] args,char[] remainder)
{
int argIndex;
......@@ -951,16 +969,10 @@ public int HookOutputCommand(int entity,char[] args,char[] remainder)
HookSingleEntityOutput(entity,arg1,OnOutput_Hook);
// do a userIdentifier as well.
char callIdentifier[64];
BreakArg(args,callIdentifier,sizeof(callIdentifier),argIndex);
// do a userIdentifier as well.
char userIdentifier[64];
BreakArg(args,userIdentifier,sizeof(userIdentifier),argIndex);
int targetActivator = 0;
char targetActivatorString[64];
if(BreakArg(args,targetActivatorString,sizeof(targetActivatorString),argIndex) && StrEqual(targetActivatorString,"TargetActivator",false))
......@@ -968,6 +980,14 @@ public int HookOutputCommand(int entity,char[] args,char[] remainder)
targetActivator = 1;
}
// do a userIdentifier as well.
char userIdentifier[64];
BreakArg(args,userIdentifier,sizeof(userIdentifier),argIndex);
CreateCommand(entity,INVALID_HANDLE,OnOutput_Close,callIdentifier,userIdentifier,arg1,targetActivator);
}
return entity;
......@@ -975,15 +995,23 @@ public int HookOutputCommand(int entity,char[] args,char[] remainder)
}
public void OnOutput_Hook(const char[] output, int caller, int activator, float delay)
public void OnOutput_Hook(char[] output, int caller, int activator, float delay)
{
int entRef = EntIndexToEntRef(caller);
LoadCommandScriptByQuery(caller,activator,OnOutput_Close,output);
// find the commands associated with this caller and output
}
bool LoadCommandScriptByQuery(int entRef,int activator,OnCloseCommand closeCommand,char [] stringSlot1)
{
if(entRef >= 0)
entRef = EntIndexToEntRef(entRef);
CommandTrack commandTrack;
for(int i= 0;i<commands.Length;i++)
{
LoadCommandTrack(i,commandTrack);
if(commandTrack.index != -1 && commandTrack.entRef == entRef && commandTrack.closeCommand == OnOutput_Close && StrEqual(commandTrack.stringSlot1,output,false))
if(CommandTrackMatchQuery(commandTrack,entRef,closeCommand,stringSlot1))
{
int ent = commandTrack.entRef;
if(commandTrack.intSlot1 == 1)
......@@ -993,8 +1021,11 @@ public void OnOutput_Hook(const char[] output, int caller, int activator, float
LoadScript(commandTrack.remainder,ent);
}
}
// find the commands associated with this caller and output
}
void OnOutput_Close(int commandID)
{
CommandTrack commandTrack;
......@@ -1540,7 +1571,7 @@ public int SpawnPresetCommand(int entity,char[] args,char[] remainder)
float angles[3];
GetEntPropVector(entity, Prop_Data, "m_angAbsRotation", angles);
BaseSpawnPreset(0,presetName,isVehicle,position,angles);
BaseSpawnPrefab(0,presetName,isVehicle,position,angles);
return entity;
......@@ -1708,6 +1739,22 @@ public int FilterTeamCommand(int entity,char[] args,char[] remainder)
return -1;
}
public int FilterClassnameCommand(int entity,char[] args,char[] remainder)
{
int argIndex;
char classnameFilter[64];
BreakArg(args,classnameFilter,sizeof(classnameFilter),argIndex);
char className[64];
GetEntityClassname(entity,className,sizeof(className));
if(StrEqual(className,classnameFilter,false))
return entity;
return -1;
}
public int SetHealthCommand(int entity,char[] args,char[] remainder)
{
......@@ -1781,6 +1828,89 @@ public int CancelCommand(int entity,char[] args,char[] remainder)
}
public int OnStartTouchHookCommand(int entity,char[] args,char[] remainder)
{
return SimpleEntityHookCommand(entity,args,remainder,SDKHook_StartTouch,OnStartTouchHook,OnStartTouchHook_Close);
}
public Action:OnStartTouchHook(int entity, int other)
{
LoadCommandScriptByQuery(entity,other,OnStartTouchHook_Close,"");
return Plugin_Continue;
}
public void OnStartTouchHook_Close(int commandID)
{
SimpleEntityHookCommand_Close(commandID,SDKHook_StartTouch,OnStartTouchHook);
}