TeamDeathZones

Expand and mod your server.
Post Reply
User avatar
Zehra
Private First Class
Private First Class
Posts: 915
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

TeamDeathZones

Post by Zehra »

Day 4 of the week of plug-ins:

Summary:
Death objects are limited, they are not specific and kill all teams.
World weapons can be used, but require the no team kill setting to work and would be limited to 2 teams and it prevents rogues from going through the zones.
So now with this plug-in, you can allow or disallow teams, depending on the settings you choose.

License: LGPL 2.1

Link to plug-in: TeamDeathZones

Notes: Plug-in does not contain messages on death. (Maybe it will be revised to include them later, if I can find a fix, I will add them in.)
Plug-in inspired by these two forum threads: Death Objects And Hiding Objects and Stay Out Areas for a certain team

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Re: TeamDeathZones

Post by JeffM »

The code does no error checking, and is very inefficient and not very maintainable/consistent.
Again, you need to learn about basic assignments and stop using long lists of complex if statements, when a simple assignment or equality test will do.

Code: Select all

// TeamDeathZone.cpp 
/*
Copyright (c) 2018 Jeffery Myers
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

*/

#include "bzfsAPI.h"
#include "plugin_utils.h"
#include <vector>

class ZoneDef :public bz_CustomZoneObject
{
public:
    int TeamIndex = -1;
};

class TeamDeathZone : public bz_Plugin, bz_CustomMapObjectHandler
{
protected:
    std::vector<ZoneDef> ZoneList;

public:
    virtual const char* Name() { return "Team Death Zones"; }
    virtual void Init(const char* config)
    {
        Register(bz_ePlayerUpdateEvent);
        bz_registerCustomMapObject("TeamDeathZone", this);
    }

    virtual void Cleanup(void)
    {
        bz_removeCustomMapObject("TeamDeathZone");
        Flush();
    }

    virtual void Event(bz_EventData *eventData)
    {
        if (eventData->eventType == bz_ePlayerUpdateEvent)
        {
            bz_PlayerUpdateEventData_V1* pUpdate = (bz_PlayerUpdateEventData_V1*)eventData;

            for (unsigned int i = 0; i < ZoneList.size(); i++)
            {
                if (!ZoneList[i].pointInZone(pUpdate->state.pos))
                    continue;

                if (bz_getPlayerTeam(pUpdate->playerID) == ZoneList[i].TeamIndex)
                    bz_killPlayer(pUpdate->playerID, false, BZ_SERVER);
            }
        }
    }

    virtual bool MapObject(bz_ApiString objectName, bz_CustomMapObjectInfo *objectData)
    {
        objectName.toupper();
        if (objectData == nullptr || objectName != "TEAMDEATHZONE")
            return false;

        ZoneDef zone;
        zone.handleDefaultOptions(objectData);

        for (size_t i = 0; i < objectData->data.size(); i++)
        {
            bz_ApiString line = objectData->data.get(i);

            bz_APIStringList *words = bz_newStringList();
            words->tokenize(line.c_str(), " ");

            if (words->size() > 0)
            {
                bz_ApiString key = words->get(0);
                key.toupper();

                if (key == "TEAM")
                {
                   
                    try
                    {
                        if (words->size() > 1)
                            zone.TeamIndex = atoi(words->get(1).c_str());
                    }
                    catch (...)
                    {
                        zone.TeamIndex = -1;
                    }
                }
            }
            bz_deleteStringList(words);
        }

        if (zone.TeamIndex >= 0)
            ZoneList.push_back(zone);

        return true;
    }
};

BZ_PLUGIN(TeamDeathZone)

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4


Also, your zone test is very primitive, it requires the client to send an update while the center of the tank is inside the zone. Really you'd at least want to check the path from the last update to this update to see if that ray intersects the zone. Optimally you'd do a moving box test against the zone to check if edges clipped in.
ImageJeffM
User avatar
Zehra
Private First Class
Private First Class
Posts: 915
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

Re: TeamDeathZones

Post by Zehra »

I guess I could have simplified the lists of if statements, but I knew they would work, so I used them.
Seems like my solutions work, but aren't the best ones.(And seem to have lots of bugs in them.)
(I'll take the time to research C in depth when I'm finished with the week of plug-ins and will probably revise many of them :book: .)

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Post Reply