Thread Rating:
  • 9 Vote(s) - 4.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release MW3 Server Addon Extensions
#1
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:
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.
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
Reply

#2
Very good!
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
Great job
[Image: MaEIQ.png]
Reply

#4
Master131, ur an hero Smile Thank you so much, you made my daySmile Big Grin
[Image: b_560_95_1.png]
[Image: hax0r3ez.gif]
Reply

#5
ok i give where have i gone wrong?


Error 1 Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll? C:\Users\test\documents\visual studio 2010\Projects\addon\addon\Class1.cs 136 57 addon
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#6
(12-10-2012, 16:10)hillbilly Wrote: ok i give where have i gone wrong?


Error 1 Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll? C:\Users\test\documents\visual studio 2010\Projects\addon\addon\Class1.cs 136 57 addon

You can not read this?
Just include System.Core.dll ( References > Add > .NET > find ?)
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#7
(12-10-2012, 16:16)SailorMoon Wrote:
(12-10-2012, 16:10)hillbilly Wrote: ok i give where have i gone wrong?


Error 1 Cannot define a new extension method because the compiler required type 'System.Runtime.CompilerServices.ExtensionAttribute' cannot be found. Are you missing a reference to System.Core.dll? C:\Users\test\documents\visual studio 2010\Projects\addon\addon\Class1.cs 136 57 addon

You can not read this?
Just include System.Core.dll ( References > Add > .NET > find ?)

i can read it, i just can't find it.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#8
I got the same error and system.core is added.

also it's underlining this:

public static void CloneBrushModelToScriptModel(this Entity scriptModel, int brushModelEntityId)
Reply

#9
(12-10-2012, 16:37)8q4s8 Wrote: I got the same error and system.core is added.

also it's underlining this:

public static void CloneBrushModelToScriptModel(this Entity scriptModel, int brushModelEntityId)

yeah, system.core is added and as you say i also still get the error.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

Reply

#10
By me it works fine, I also gave my project files, and still not working.
If u need someinformation : I have Microsoft visual C# 2010 express, and I compiled with 3.0
My references are :
- Addon
- Microsoft.CSharp
- System
- System.core
- System.data
- System.data.datasetextensions
- System.Xml
- System.Xml.Linq

2 classes :
Extensions.cs (with the code from master131)
Class1.cs (My own code for carepackages )
Code class1.cs
Code:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Addon;



namespace Boxes
{
    public class Class1 : CPlugin
    {
        public override void OnMapChange()
        {
            string map = GetDvar("mapname");
            if (map == "mp_carbon")
            {
                Entity ent = SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(-926f, -4535f, 4576f));
                ent.CloneBrushModelToScriptModel(Extensions.FindAirdropCrateCollisionId());
                
            }

        }

        public override void OnFastRestart()
        {
            string map = GetDvar("mapname");
            if (map == "mp_carbon")
            {
                Entity ent = SpawnModel("script_model", "com_plasticcase_trap_friendly", new Vector(-926f, -4535f, 4576f));
                ent.CloneBrushModelToScriptModel(Extensions.FindAirdropCrateCollisionId());
            }


        }


    }

}

I hope u can use this info for something

EDIT : I have also 2 warnings
Code:
Warning    2    The referenced component 'Microsoft.CSharp' could not be found.
Code:
Warning    1    Could not resolve this reference. Could not locate the assembly "Microsoft.CSharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.    Boxes
[Image: b_560_95_1.png]
[Image: hax0r3ez.gif]
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Help, server Admin largosik 0 2,287 02-02-2019, 18:09
Last Post: largosik
  Add a point shop to my server h1dexyz 1 3,144 03-04-2018, 22:36
Last Post: h1dexyz
Lightbulb Preview Weapon Classe For Infected Clasic Server groochu1982 0 2,441 02-19-2017, 08:35
Last Post: groochu1982
Exclamation Help HOW CAN I TURN OFF THE "CROSSHAIR" IN MY SERVER? Eliichong0 0 2,804 06-16-2016, 16:01
Last Post: Eliichong0
Bug Upload files to FTP server S3VDIT0 4 4,573 01-28-2016, 17:17
Last Post: S3VDIT0

Forum Jump:


Users browsing this thread:
4 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.