Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help example timing.cs[fx] [C#]
#1
hey guys could you give me a timing/cs code Example? I would like to learn, interesting things somebody can give me an example about 3-5?
Reply

#2
Learn to read, idiots.

There's code from @AddonExtensions

Example
Code:
public override void OnServerFrame()
{
    // This is required for timers to work.
    Timing.ProcessFrame(GetClients());
}

private int _stealthBombFx;

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 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, 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);
    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, () =>
    {
        iPrintLnBold("Testing!", client);

        // Let the timer know to keep going. Return false to remove/stop the timer.
        return true;
    });

    // Override class selection.
    Timing.OnNotify("menuresponse", client, menu =>
    {
        // Check that the menu name is "team_marinesopfor" (this is the value of game["menu_team"])
        if(menu.As<string>() == "team_marinesopfor")
        {
            // Tell the code in _menu.gsc that we want to change to class0.
            // Note how I put the delay, if that's not there, it screws up the menu.
            Timing.AfterDelay(100, () => Timing.Notify(client, "menuresponse", "changeclass", "class0"));
        }
    });
}

public override void OnPlayerSpawned(ServerClient client)
{
    // Spawn a care package with a collision, making 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);
    TellClient(client.ClientNum, string.Format("The care package's angles are: ({0}, {1}, {2})", angles.X, angles.Y, angles.Z), true);

    // 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);
    });
}
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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