1 (edited by Mika56 2009-07-14 23:58:30)

Topic: [HELP] How to create a "create_damageind dest" value?

Hi,
I try to send damage indicator to only the team of damaged-player.
I've done this :

for(int i = 0; i < MAX_CLIENTS; i++)
{
    if(game.players[i] && game.players[i]->team == character->player->team)
    {
        game.create_damageind(character->player->view_pos, aff*1.5f, aff, i);
    }
}

The problem is that it doesn't work, damage indicator are send to somebody, who are or not to the team (and some users who are in the team don't see).

So, my question is "who" is "int dest" in the create_damageind function ?

Mika.

2 (edited by lxde 2009-07-15 12:37:29)

Re: [HELP] How to create a "create_damageind dest" value?

I wonder because create_damageind has normally only 4 parameters...
But I'll try to explain how to send an event only to one team.
In the function "void GAMECONTEXT::create_damageind(vec2 p, float angle, int amount)", file "src/game/server/gamecontext.cpp", line 38, the Damage indicator is really created in line 47:

[...]
NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)events....create(NETEVENTTYPE_DAMAGEIND,
sizeof(NETEVENT_DAMAGEIND));
[...]

events.create has an additional parameter named "mask". It specifies to which players the event should be send.

Here's the modified function "void GAMECONTEXT::create_damageind(vec2 p, float angle, int amount, int team:

void GAMECONTEXT::create_damageind_team(vec2 p, float angle, int amount, int team)
{
    float a = 3 * 3.14159f / 2 + angle;
    //float a = get_angle(dir);
    float s = a-pi/3;
    float e = a+pi/3;

    int mask = 0;
    for(int i = 0; i < MAX_CLIENTS; i++)
    {
        if(players[i] && players[i].team == team)
        {
            mask = mask | cmask_one(players[i].client_id);
        }
    }

    for(int i = 0; i < amount; i++)
    {
        float f = mix(s, e, float(i+1)/float(amount+2));
        NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)events.create(NETEVENTTYPE_DAMAGEIND, sizeof(NETEVENT_DAMAGEIND), mask);
        if(ev)
        {
            ev->x = (int)p.x;
            ev->y = (int)p.y;
            ev->angle = (int)(f*256.0f);
        }
    }
}

Insert this code in "src/game/server/gamecontext.cpp",
and insert this code in declaration of the class "GAMECONTEXT" in "src/game/server/gamecontext.hpp":

void GAMECONTEXT::create_damageind_team(vec2 p, float angle, int amount, int team)

By the way, the function to get a mask for the events.create(..) function from a client id is "cmask_one(int cid)", which is a member function of the GAMECONTEXT class.
It takes a client id as input, and outputs the fitting mask.
If you still have got unanswered questions, just ask. smile

3

Re: [HELP] How to create a "create_damageind dest" value?

Thank you a lot, my problem was with the "mask" tongue

Mika.

Ps : The "int dest", it's me who was added it, but dest is send as mask to creave_damageind