plugins/testsuite/gamerules-props.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3333 e247490894a1
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 #include <sourcemod>
     2 #include <sdktools>
     3 
     4 enum Game { Game_TF, Game_SWARM }
     5 new Game:g_Game;
     6 
     7 public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
     8 {
     9 	decl String:gamedir[64];
    10 	GetGameFolderName(gamedir, sizeof(gamedir));
    11 	if (!strcmp(gamedir, "tf"))
    12 	{
    13 		g_Game = Game_TF;
    14 		return APLRes_Success;
    15 	}
    16 	
    17 	if (!strcmp(gamedir, "swarm"))
    18 	{
    19 		g_Game = Game_SWARM;
    20 		return APLRes_Success;
    21 	}
    22 	
    23 	strcopy(error, err_max, "These tests are only supported on TF2 and Alien Swarm");
    24 	return APLRes_Failure;
    25 }
    26 
    27 public OnPluginStart()
    28 {	
    29 	if (g_Game == Game_TF)
    30 	{
    31 		RegConsoleCmd("gr_getstate", gr_getstate);
    32 		RegConsoleCmd("gr_ttr", gr_ttr);
    33 		RegConsoleCmd("gr_tbs", gr_tbs);
    34 		RegConsoleCmd("gr_nextspawn", gr_nextspawn);
    35 		RegConsoleCmd("gr_settime", gr_settime);
    36 		RegConsoleCmd("gr_getgoal", gr_getgoal);
    37 		RegConsoleCmd("gr_setgoal", gr_setgoal);
    38 	}
    39 	else if (g_Game == Game_SWARM)
    40 	{
    41 		HookEvent("entity_killed", entity_killed);
    42 		RegConsoleCmd("gr_getstimmer", gr_getstimmer);
    43 	}
    44 }
    45 
    46 public Action:gr_getstate(client, argc)
    47 {
    48 	ReplyToCommand(client, "Round state is %d", GameRules_GetRoundState());
    49 	return Plugin_Handled;
    50 }
    51 
    52 stock Float:GameRules_GetTimeUntilRndReset()
    53 {
    54 	new Float:flRestartTime = GameRules_GetPropFloat("m_flRestartRoundTime");
    55 	if (flRestartTime == -1.0)
    56 		return flRestartTime;
    57 	
    58 	return flRestartTime - GetGameTime();
    59 }
    60 
    61 public Action:gr_ttr(client, argc)
    62 {
    63 	ReplyToCommand(client, "Time til restart is %.2f", GameRules_GetTimeUntilRndReset());
    64 	return Plugin_Handled;
    65 }
    66 
    67 public Action:gr_tbs(client, argc)
    68 {
    69 	ReplyToCommand(client, "Time between spawns for team2 is %.2f", GameRules_GetPropFloat("m_TeamRespawnWaveTimes", 2));
    70 	return Plugin_Handled;
    71 }
    72 
    73 public Action:gr_nextspawn(client, argc)
    74 {
    75 	ReplyToCommand(client, "Next spawn for team2 is %.2f", GameRules_GetPropFloat("m_flNextRespawnWave", 2));
    76 	return Plugin_Handled;
    77 }
    78 
    79 public Action:gr_settime(client, argc)
    80 {
    81 	GameRules_SetPropFloat("m_TeamRespawnWaveTimes", 2.0, 2, true);
    82 	return Plugin_Handled;
    83 }
    84 
    85 public Action:gr_getgoal(client, argc)
    86 {
    87 	decl String:goal[64];
    88 	GameRules_GetPropString("m_pszTeamGoalStringRed", goal, sizeof(goal));
    89 	ReplyToCommand(client, "Red goal string is \"%s\"", goal);
    90 	return Plugin_Handled;
    91 }
    92 
    93 public Action:gr_setgoal(client, argc)
    94 {
    95 	GameRules_SetPropString("m_pszTeamGoalStringRed", "urururur", true);
    96 	
    97 	decl String:goal[64];
    98 	GameRules_GetPropString("m_pszTeamGoalStringRed", goal, sizeof(goal));
    99 	ReplyToCommand(client, "Red goal string is \"%s\"", goal);
   100 	return Plugin_Handled;
   101 }
   102 
   103 //.. DIE
   104 public entity_killed(Handle:event, const String:name[], bool:dontBroadcast)
   105 {
   106 	new ent = GetEventInt(event, "entindex_killed");
   107 	if (!IsValidEdict(ent))
   108 		return;
   109 	
   110 	decl String:classname[64];
   111 	GetEdictClassname(ent, classname, sizeof(classname));
   112 	
   113 	if (!!strcmp(classname, "asw_marine"))
   114 		return;
   115 	
   116 	decl Float:deathvec[3];
   117 	GameRules_GetPropVector("m_vMarineDeathPos", deathvec);
   118 	PrintToChatAll("Death vec is %.3f %.3f %.3f", deathvec[0], deathvec[1], deathvec[2]);
   119 }
   120 
   121 // you can manually induce this with asw_PermaStim (needs sv_cheats)
   122 public Action:gr_getstimmer(client, argc)
   123 {
   124 	ReplyToCommand(client, "%N (%.2f/%.2f)",
   125 		GameRules_GetPropEnt("m_hStartStimPlayer"),
   126 		GameRules_GetPropFloat("m_flStimStartTime"),
   127 		GameRules_GetPropFloat("m_flStimEndTime"));
   128 	return Plugin_Handled;
   129 }