View Full Version : Some TF2 Scripting Questions
Dr. McKay
12-31-2011, 16:39
Alright, there might be more than a few questions that I have to ask, so I'm just creating an umbrella thread. I'm creating a new TF2 gamemode entitled "Assassination Mode", inspired by Assassin's Creed's multiplayer, wherein each player is given a specific target on the other team to assassinate.
Here's my first few questions:
How can I go about triggering a round_win for either BLU or RED, or a stalemate?
Is there a way to set a round timelimit from SM?
Is there a way to disable all map objectives and remove them from the HUD? As if, for instance, someone wanted to play assassination mode on a CP map, can I disable the control points and remove them from the bottom of the screen? Perhaps by removing the control point's entity? I would also need to be able to override the map's default timelimit.
There will probably be more questions to come. This is all I can think of for now.
turtsmcgurts
12-31-2011, 20:29
• I don't know off the top of my head, nor do I have the time to look into it myself :(
• Something like ServerCommand("mp_timelimit %i", g_timelimit);
•I'm not positive you can remove the HUD element itself, but I am almost sure you can disable the objectives. Use the above method to change the time limit. Hopefully someone can help you more on this question.
Dr. McKay
12-31-2011, 20:35
• Something like ServerCommand("mp_timelimit %i", g_timelimit);
Thing is, that only changes the map's timelimit, not the round's timelimit. For instance, on control point maps where there's a 10 minute round timelimit. How would I change that?
turtsmcgurts
12-31-2011, 20:42
Thing is, that only changes the map's timelimit, not the round's timelimit. For instance, on control point maps where there's a 10 minute round timelimit. How would I change that?
I misread. The only alternative I see is doing it manually within the code, creating a timer, ect. You could use SetHudTextParams (http://docs.sourcemod.net/api/index.php?fastload=show&id=842&) to display the time left on each players HUD.
I misread yet again. The problem is the game would end too early... ignore the above. :d
How can I go about triggering a round_win for either BLU or RED, or a stalemate?
Hook the game_round_win (https://developer.valvesoftware.com/wiki/Game_round_win) entity, set the Team keyvalue(0 = Stalemate, 2 = Red, 3 = Blue), and fire the RoundWin input.
smlib (http://forums.alliedmods.net/showthread.php?t=148387) has a stock for this:
stock bool:Game_EndRound(team=0, bool:forceMapReset=false, bool:switchTeams=false)
Is there a way to set a round timelimit from SM?
Hook the team_round_timer (https://developer.valvesoftware.com/wiki/Team_round_timer) and fire the SetTime input.
Is there a way to disable all map objectives and remove them from the HUD? As if, for instance, someone wanted to play assassination mode on a CP map, can I disable the control points and remove them from the bottom of the screen? Perhaps by removing the control point's entity? I would also need to be able to override the map's default timelimit.
Not sure on this one, never attempted it, but according to the wiki, the
team_control_point (https://developer.valvesoftware.com/wiki/Team_control_point) entities are hidden from the hud with flag 1(Under the Flags section)
Dr. McKay
01-01-2012, 01:24
Thanks for those answers!
Here's another one:
Say I have a variable set up as such: new bool:variableName[MAXPLAYERS + 1] = false;
I'm setting it using variableName[client] = true;
How can I set all of the cells in the array to false in one go, without using a for loop to cycle through all of MAXPLAYERS?
Impact123
01-01-2012, 01:49
This makes no sense because false = std, but.
new bool:variableName[MAXPLAYERS+1] = {false, ...};Afterwards there is no way without a loop AFAIK.
I used this example with the profiler and came up with this
Example:
new bool:test[2048];
for(new i; i< 2048; i++)
{
test[i] = false;
}
Result:
Benchmark: 0.000028 seconds
With MAXPLAYERS+1 i came up with
Benchmark: 0.000001 seconds
So this should not be a problem.
Yours sincerely
Impact
Dr. McKay
01-01-2012, 02:12
Afterwards there is no way without a loop AFAIK.
Alright, I'm using a loop anyway. I just thought there might be a better way.
Also, how can I fill an array with unique random numbers? I'm currently doing this to generate 9 unique random numbers between 0 and 8:
new assignClasses[9] = -1;
new buffer;
for(new i = 0; i <= 8; i++) {
// Let's generate what the class assignment order will be
buffer = GetRandomInt(0, 8);
while(assignClasses[0] == buffer || assignClasses[1] == buffer || assignClasses[2] == buffer || assignClasses[3] == buffer || assignClasses[4] == buffer || assignClasses[5] == buffer || assignClasses[6] == buffer || assignClasses[7] == buffer || classes[8] == buffer) {
buffer = GetRandomInt(0, 8);
}
assignClasses[i] = buffer;
}
Impact123
01-01-2012, 02:45
This is an really bad example!, but maybe it'll help you.
new ToBeSaved[10];
new Buffer;
new tempstat;
for(new i; i < 10; i++)
{
Buffer = GetRandomInt(0, 10);
tempstat = true;
for(new j; j< 10; j++)
{
if(Buffer == ToBeSaved[j] && i >0)
{
i--;
tempstat = false;
break;
}
}
if(tempstat)
{
ToBeSaved[i] = Buffer;
}
}
Im sure there is some stock out there for this.
What are you doing this for?
new assignClasses[9] = -1;
Yours sincerely
Impact
Dr. McKay
01-01-2012, 03:55
What are you doing this for?
new assignClasses[9] = -1;
At the beginning of the script, I declared
new TFClassType:classes[9] = {TFClass_Scout, TFClass_Soldier, etc...}
The code that I posted should, in theory, assign a unique random value between 0-8 to each cell in assignClasses. Then, as I'm filling the teams, I just go in order of the cells in assignClasses, so the classes are selected randomly, but only one player per class per team.
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.