I know alot of people have been have been waiting for a public (working) release for CloneBrushmodelToScriptmodel and other functions, so I went ahead and made my own implementation of it (in C# anyway). This code uses alot of C# hackery (yes, I even created a function hook in Timing.cs) and I tried to avoid using the unsafe keyword just for the sake of it. This will only work for the latest version of MW3 Server which is 1.9.461.
Each of the following files are independent, meaning they don't rely on each other. You are free to use which ever one(s) you want.
Extensions.cs:
http://pastebin.com/zT9h5Bvz
Timing.cs:
http://pastebin.com/0FeybQJx
TestClients.cs:
http://pastebin.com/aDvB5vab
Functions:
Extensions.CloneBrushModelToScriptModel
Extensions.Show
Extensions.Hide
Extensions.SetAngles
Extensions.GetAngles
Extensions.LoadFX
Extensions.PlayFX
Extensions.SetContents
Timing.OnInterval
Timing.AfterDelay
Timing.ProcessFrame
Timing.OnNotify
Timing.Notify
TestClients.AddTestClient
TestClients.ConnectBot
TestClients.IsBot
Useful TestClient DVARs: (set them in the console or whatever)
testClients_doAttack
testClients_doCrouch
testClients_doMove
testClients_doReload
testClients_watchKillcam
Example:
You will notice that you won't be able to move when you spawn which means it works.
Known bugs:
- Standing on a hidden care package with collision will cause the player's camera to shake.
Credits:
@zxz0O0 Implementing CloneBrushmodelToScriptmodel the function into the "private" version of the addon.
Everyone who has helped to make MW3 Server Addon exist and stay up to date.
@estebespt - Posting a version of the addon with "solid" support, despite it being for an older version of MW3 Server.
@NTAuthority - For making InfinityScript somewhat open-source and allowing me to find CloneBrushmodelToScriptmodel before even looking at the addon posted by @estebespt. I was going for a "full on" GSC approach for the past 2 days but decided to use the "hackery" (jumping mid function) as seen in the assembly stub in the code I've posted above. Also credits to him for the AddTestClients code and inspiration for the Timing functions.
@SailorMoon - Testing angle craps cause I was lazy to.
@Nukem - Overall great help.
Each of the following files are independent, meaning they don't rely on each other. You are free to use which ever one(s) you want.
Extensions.cs:
http://pastebin.com/zT9h5Bvz
Timing.cs:
http://pastebin.com/0FeybQJx
TestClients.cs:
http://pastebin.com/aDvB5vab
Functions:
Extensions.CloneBrushModelToScriptModel
Extensions.Show
Extensions.Hide
Extensions.SetAngles
Extensions.GetAngles
Extensions.LoadFX
Extensions.PlayFX
Extensions.SetContents
Timing.OnInterval
Timing.AfterDelay
Timing.ProcessFrame
Timing.OnNotify
Timing.Notify
TestClients.AddTestClient
TestClients.ConnectBot
TestClients.IsBot
Useful TestClient DVARs: (set them in the console or whatever)
testClients_doAttack
testClients_doCrouch
testClients_doMove
testClients_doReload
testClients_watchKillcam
Example:
Code:
public override void OnServerFrame()
{
// This is required for timers to work.
Timing.ProcessFrame(GetClients());
}
private int _stealthBombFx;
private bool _spawnedBots;
public override void OnPrecache()
{
// Load the stealth_bomb_mp FX, it is important to preload ALL fx in the OnPrecache override.
_stealthBombFx = Extensions.LoadFX("explosions/stealth_bomb_mp");
}
public override void OnMapChange()
{
// Reconnect and spawn the bots, otherwise they get stuck on map load.
foreach (var client in GetClients())
if (TestClients.IsBot(client))
TestClients.ConnectBot(client);
}
public override void OnPlayerConnect(ServerClient client)
{
// Display a message in the console when someone is hurt and how much health they lost.
// Note how .As<T> was used. Supported types are: int, float, bool, string, Vector, Entity, ServerClient
// The 'client' is also optional, but it allows you to filter the message for that player/entity only.
// In GSC, this is the equivalent of:
// self waittill("damage", amount, attacker);
Timing.OnNotify("damage", client, (amount, attacker) =>
{
ServerPrint(client.Name + " was damaged and lost " + amount.As<int>() + " HP.");
if (attacker.IsPlayer)
ServerPrint(client.Name + "'s attacker was: " + attacker.As<ServerClient>().Name);
});
// Display a message to the client every 5 seconds.
// Note how ServerClient can be passed as a second argument (optional), but this allows
// the timer to remove/stop the timer automatically in-case the client disconnects.
Timing.OnInterval(5000, client, () =>
{
iPrintLn("Welcome to the server!", client);
// Let the timer know to keep going. Return false to remove/stop the timer.
return true;
});
// Auto select team and class for bots.
if (TestClients.IsBot(client))
{
Timing.AfterDelay(200, () =>
{
// Auto-assign the team.
Timing.Notify(client, "menuresponse", "team_marinesopfor", "autoassign");
// After a small delay, set the class.
Timing.AfterDelay(500, () => Timing.Notify(client, "menuresponse", "changeclass", "class0"));
});
}
// Spawn bots if we haven't already (we'll spawn 5 of them)
if (!_spawnedBots)
{
// Set this to true now so the bots don't run this code.
_spawnedBots = true;
for (int i = 0; i < 5; i++)
TestClients.AddTestClient();
}
}
public override void OnPlayerSpawned(ServerClient client)
{
// Spawn a care package with a collision and make it solid.
var origin = new Vector(client.OriginX, client.OriginY, client.OriginZ);
Entity ent = SpawnModel("script_model", "com_plasticcase_green_big_us_dirt", origin);
Extensions.CloneBrushModelToScriptModel(ent, Extensions.FindAirdropCrateCollisionId());
// Display the care package's angles, should display (0, 0, 0)
// You can remove this code, it's only to demonstrate what Extensions.GetAngles can do.
Vector angles = Extensions.GetAngles(ent);
iPrintLn(string.Format("The care package's angles are: ({0}, {1}, {2})", angles.X, angles.Y, angles.Z), client);
// Rotate the care package 90 degrees.
Extensions.SetAngles(ent, new Vector(0, 90, 0));
// After 2 seconds, play an explosion FX on top of the care package.
Timing.AfterDelay(2000, () =>
{
origin.Z += 30;
Extensions.PlayFX(_stealthBombFx, origin);
});
}
You will notice that you won't be able to move when you spawn which means it works.
Known bugs:
- Standing on a hidden care package with collision will cause the player's camera to shake.
Credits:
@zxz0O0 Implementing CloneBrushmodelToScriptmodel the function into the "private" version of the addon.
Everyone who has helped to make MW3 Server Addon exist and stay up to date.
@estebespt - Posting a version of the addon with "solid" support, despite it being for an older version of MW3 Server.
@NTAuthority - For making InfinityScript somewhat open-source and allowing me to find CloneBrushmodelToScriptmodel before even looking at the addon posted by @estebespt. I was going for a "full on" GSC approach for the past 2 days but decided to use the "hackery" (jumping mid function) as seen in the assembly stub in the code I've posted above. Also credits to him for the AddTestClients code and inspiration for the Timing functions.
@SailorMoon - Testing angle craps cause I was lazy to.
@Nukem - Overall great help.
A casual conversation between barata and I about Nukem.