Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualFunctions.ClientPrint not working inside EventBulletImpact, working for EventItemPickup example #677

Open
oscar-wos opened this issue Nov 16, 2024 · 3 comments
Labels
untriaged New issue has not been triaged

Comments

@oscar-wos
Copy link

oscar-wos commented Nov 16, 2024

RegisterEventHandler<EventBulletImpact>((@event, info) =>
{
    var player = @event.Userid;

    if (player == null || !player.IsValid)
        return HookResult.Continue;

    player.PrintToChat($"123"); // doesn't work
    player.PrintToCenterAlert("123"); // doesn't work
    player.PrintToCenter("123"); // doesn't work

    player.PrintToConsole("123"); // works
    player.PrintToCenterHtml("123"); // works
    player.PlayerPawn.Value!.Teleport(new Vector(@event.X, @event.Y, @event.Z), QAngle.Zero, Vector.Zero); // works
    Console.WriteLine($"{@event.X}, {@event.Y}, {@event.Z}"); // works
    return HookResult.Continue;
});

RegisterEventHandler<EventItemPickup>((@event, info) =>
{
    var player = @event.Userid;

    if (player == null || !player.IsValid)
        return HookResult.Continue;

    player.PrintToChat($"123"); // works
    player.PrintToCenterAlert("123"); // works
    player.PrintToCenter("123"); // works

    player.PrintToConsole("123"); // works
    player.PrintToCenterHtml("123"); // works
    //player.PlayerPawn.Value!.Teleport(new Vector(@event.X, @event.Y, @event.Z), QAngle.Zero, Vector.Zero); // works
    //Console.WriteLine($"{@event.X}, {@event.Y}, {@event.Z}"); // works
    return HookResult.Continue;
});

CounterStrikeSharp was created and is maintained by Michael "roflmuffin" Wilson.
Counter-Strike Sharp uses code borrowed from SourceMod, Source.Python, FiveM, Saul Rennison, source2gen and CS2Fixes.
See ACKNOWLEDGEMENTS.md for more information.
Current API Version: v287 (1.0.287+6cf124b)

Metamod:Source Version Information
Metamod:Source version 2.0.0-dev+1314

@github-actions github-actions bot added the untriaged New issue has not been triaged label Nov 16, 2024
@darkerz7
Copy link

use with
Server.NextFrame(() => { //print here });

@oscar-wos
Copy link
Author

use with Server.NextFrame(() => { //print here });

This just results in a seg fault

RegisterEventHandler<EventBulletImpact>((@event, info) =>
{
    var player = @event.Userid;

    if (player == null || !player.IsValid)
        return HookResult.Continue;

    Server.NextFrame(() =>
    {
        player.PrintToChat($"{@event.X}, {@event.Y}, {@event.Z}");
    });

    Console.WriteLine($"{@event.X}, {@event.Y}, {@event.Z}"); // works
    return HookResult.Continue;
});

{F14C2D50-B079-46A4-93E4-45F28C12E943}

https://pastebin.com/cV2ZwZM6

@darkerz7
Copy link

darkerz7 commented Nov 17, 2024

it is logical that in the next frame there is no event anymore copy the values ​​before this

float x = @event.X;
float y = @event.Y;
float z = @event.Z;
Server.NextFrame...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged New issue has not been triaged
Projects
None yet
Development

No branches or pull requests

2 participants