Event Request (Source)

Event Request (Source)

Postby Conor » 21 Jan 2013, 15:49

Hello.

This isn't a command request but I was unsure where to post my query, this seems most appropriate. I would have directly asked you Dzienny, but I posted it so that it can help everyone if possible.

First off, I'm not sure if there is an event like this which already exists. But I'm in need of an event which is called once a players rotation changes (and) position if needed. The old method in Player.cs was 'void HandleInput(object m)', so this is what I'm targeting.

I am wanting to make a command which needs access to the constant changes in a players position, but I am unsure how to do this efficiently, an event which I could use inside the custom command to access this information would be great.

Thanks.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Event Request (Source)

Postby dzienny » 22 Jan 2013, 01:41

I don't think that you need an event for this. The simplest way I can think of implementing position check is to create a timer that checks the position and rotation variables every 100ms or so. Player's position is saved to (Player).pos[] and .rot[] where pos[0] is x, pos[1] is y, pos[2] is z and rot[0] and rot[1] contain rotation data. As far as I remember Player's position is updated every 40ms.

Example of how to use the Timer class:
Code: Select all
System.Timers.Timer positionCheck = new System.Timers.Timer(100);

void InitPositionCheck();
{
    positionCheck.Elapsed += TimerCallback;
    positionCheck.Start();
}

private void TimerCallback(object sender, ElapsedEventArgs e)
{
    Player.players.ForEach(p =>
    {
        if (PosToBlockPos(p.pos[0]) == 10 && PosToBlockPos(p.pos[1]) == 32 && PosToBlockPos(p.pos[2]) == 5)
        {
            Command.all.Find("kill").Use(null, p.name + " got sliced by a laser.");
        }
    });
}

static int PosToBlockPos(int position)
{
    return position / 32;
}
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Event Request (Source)

Postby Conor » 22 Jan 2013, 17:52

Oh I see.

"Command.all.Find("kill").Use(null, p.name + " got sliced by a laser.");" xD

Thanks for the help Dzienny ! :)
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 3 guests

cron