1

Topic: [HELP] Removing entity problem...

Heyhey!

My idea was to create a command which loads the weapons or removes them in a running round! (de/activating weapons).
Well, it probably works fine, that meens inserting works great (as often as I want... cause I store the positions) but removing is a problem... it's not that easy as I thought or am I to stupid to see the error..xD

In hooks.cpp I've got below my command this two lines for removing the shoutgun from the map..

            ENTITY *ent = game.world.find_first(8);
            game.world.remove_entity(ent);

What happens? The player respawns... and weapons of the player do not work anymore (shooting not possible), but they are still on the map... but the main problem: Why the hell does the player respawn...

Index 8 = ENTITY_WEAPON_SHOTGUN

Would be great if someone can help, cause than this little command would be finished...

Avatar by Crises
Tee-Project - Website coming soon... [http://project.tee-city.net]

2 (edited by buffer[] 2010-01-08 21:21:16)

Re: [HELP] Removing entity problem...

Are you serious ?
Do you even know a line of TeeWorlds code ?

A weapon isn't an entity...

    ENTITY *find_first(int type);

Where types are NETOBJTYPE_***

What you're talking about might be make pickup inactive.
Just look into game/server/entities/pickup.(hpp/cpp)

Just make a variable, and if this variable is set, make a return into the tick function, and in the snap one.
But take care of freezing respawn_tick or pickups will respawn when you reactivate it without any respawn time.

And for multiple weapons disabling, make like
-2 default, nothing happens,
-1, no pickups
0, 1, ..., special weapon disabling


This is getting worse and worse.

|ZPote| buffer[]'s posterous

3 (edited by Whitefire 2010-01-09 00:16:34)

Re: [HELP] Removing entity problem...

Nono... I thought on using the pickup system, but there is one problem with how my command will work:

if I write sv_weapons 1 all weapons are available on the map suddenly (that works fine)
if I write sv_weapons 0 all weapons will be away (not shown, not "getable", they have to be deleted - the weapons)

I thought on entity cause I use the "on_entity" to insert them into the map... The admin can decide in his config if the weapons are loaded at start or not... and he can de/activate them every time in the current running round.

bool GAMECONTROLLER::on_entity(int index, vec2 pos)
{
    int type = -1;
    int subtype = 0;

    ...
    else if(index == ENTITY_WEAPON_SHOTGUN)
    {
        type = POWERUP_WEAPON;
        subtype = WEAPON_SHOTGUN;
        if(round_start)
        {
            weapon_points[0][num_weapon_points[0]++] = pos;
        }
    }
    else if(index == ENTITY_WEAPON_GRENADE)
    {
        type = POWERUP_WEAPON;
        subtype = WEAPON_GRENADE;
        if(round_start)
        {
            weapon_points[1][num_weapon_points[1]++] = pos;
        }
    }
    else if(index == ENTITY_WEAPON_RIFLE)
    {
        type = POWERUP_WEAPON;
        subtype = WEAPON_RIFLE;
        if(round_start)
        {
            weapon_points[2][num_weapon_points[2]++] = pos;
        }
    }
   ....

    if(type != -1)
    {
        if(weapon_off && subtype != 0)
        {
            return false;
        }
        PICKUP *pickup = new PICKUP(type, subtype);
        pickup->pos = pos;
        return true;
    }

    return false;
}

Cause I ask there for "ENTITY_WEAPON_SHOTGUN" etc. I thougth I have to remove them as entitys and there was "first_entity"... shame on me^^
But if I understand right it is that way meant?:
on the entity "ENTITY_WEAPON_SHOTGUN" (from the map itself, the tile in the editor is the "ENTITY") I say create a pickup which creates me this NETOBJTYPE? So the existing weapon in the game is a NETOBJTYPE and that what I set in the editor is the ENTITY on the map right?

Question: Is the pickup snap loaded every time? So if I write there a return false if a variable becomes true / false all weapons of that type could be "away"? If yes that would be great and a good solution. Anyway I try it this night and will tell you about what came out. I took a clearer look now and as I see it seems like the checks are running always.^^

Ps: Problem is not coding itself, I have to "come into" Teeworlds stuff... didn't coded a lot yet in Teeworlds, the entity / netobject stuff is one of the captures I still have to find out how they are correctly working smile


EDIT: Big shame on me... your solution is much much shorter and works perfect... thanks!

Avatar by Crises
Tee-Project - Website coming soon... [http://project.tee-city.net]

4

Re: [HELP] Removing entity problem...

No problem.

About the snap thing :
In TeeWorlds (in the game, not the engine), many classes inerits two functions, which are called every tick :
tick() and snap().
tick() make every things that need to be done like movement, cheking stuff, etc.
snap() just add a new snap_item to the current snap in order to send information to the client relative to the object itself, like position for projectile, tees, or skin, name, etc.

|ZPote| buffer[]'s posterous

5

Re: [HELP] Removing entity problem...

Thanks, also for the info smile

Avatar by Crises
Tee-Project - Website coming soon... [http://project.tee-city.net]