NoSelfCaptures

Expand and mod your server.
Post Reply
User avatar
Zehra
Private First Class
Private First Class
Posts: 582
Joined: Sun Oct 18, 2015 3:36 pm
Location: Arctic

NoSelfCaptures

Post by Zehra » Sun Jul 01, 2018 11:42 am

Day 1 of the week of plug-ins:

Summary:
Players self-capping their own flags works alright on HTF maps, but however this does not work well on any other map.
So what this plug-in does is prevent players from capping their own flag.

License: LGPL 2.1

Link to plug-in: NoSelfCaptures

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
There's always something to remember and it's been a game I love. ~Zehra
The time spent is a time which can never be regained, so it's a time to enjoy. ~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.

User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5173
Joined: Fri Dec 13, 2002 4:11 am
Location: https://discord.gg/NN9uAvx
Contact:

Re: NoSelfCaptures

Post by JeffM » Sun Jul 01, 2018 4:02 pm

If (bz_getPlayerTeam(capData->playerCapping) == capData->teamCapped)
{
capData->allow = false;
}
else capData->allow = true;

You should be consistent in how you handle single line conditionals.

Also learn about assignment.

User avatar
blast
General
General
Posts: 4729
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: NoSelfCaptures

Post by blast » Sun Jul 01, 2018 4:21 pm

There is no need to get the capping player's team because it's already part of the event data, stored as teamCapping.

capData->allow = (capData->teamCapping != capData->teamCapped);

(That will set the 'allow' value to the boolean result of the inequality comparison of teamCapping and teamCapped)
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image

User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5173
Joined: Fri Dec 13, 2002 4:11 am
Location: https://discord.gg/NN9uAvx
Contact:

Re: NoSelfCaptures

Post by JeffM » Sun Jul 01, 2018 6:24 pm

A few more things;

Does this even run? You have your plugin members not marked as public, so they'll be private by default, you have an empty public section at the bottom.

You should put the license and copyright information in the file so it's clear what the license is. How do people who find the code on github know if they don't also somehow magically find this forum post. You also need to actually state the copyright holder's name.

Plugins like this should be exceptionaly short and simple.

Code: Select all

/* NoSelfCaptures
* This plug-in prevents self-captures in CTF maps.
* Copyright (c) 2018 ???????
*
* This package is free software;  you can redistribute it and/or
* modify it under the terms of the LGPL 2.1 license.
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "bzfsAPI.h"

class NoSelfCaptures : public bz_Plugin
{
public:
	virtual const char* Name()
	{
		return "NoSelfCaptures";
	}

	virtual void Init(const char* /*config*/)
	{
		Register(bz_eAllowCTFCaptureEvent);
	}

	virtual void Event(bz_EventData *eventData)
	{
		if (eventData->eventType == bz_eAllowCTFCaptureEvent)
		{
			bz_AllowCTFCaptureEventData_V1 *capData = (bz_AllowCTFCaptureEventData_V1*)eventData;
			capData->allow = capData->teamCapped != capData->teamCapping;
		}
	}

	virtual void Cleanup(void)
	{
		Flush();
	}
};

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


User avatar
Zehra
Private First Class
Private First Class
Posts: 582
Joined: Sun Oct 18, 2015 3:36 pm
Location: Arctic

Re: NoSelfCaptures

Post by Zehra » Sun Jul 01, 2018 7:36 pm

@JeffM
Thanks for the input, it looks like I didn't make it exactly right.
Seems like I remembered my badly written code, compare to standards. :doh:
(I'll take a few notes on conditionals and assignments.)

@blast
I tried to do something like this, but it didn't work as intended.(Or I might have messed up somewhere else.)

Code: Select all

      bz_AllowCTFCaptureEventData_V1 *capData = (bz_AllowCTFCaptureEventData_V1*)eventData;
      if (capData->teamCapping == capData->teamCapped)
      {
        capData->allow = false;
      }
else capData->allow = true;
blast wrote:
Sun Jul 01, 2018 4:21 pm
There is no need to get the capping player's team because it's already part of the event data, stored as teamCapping.

capData->allow = (capData->teamCapping != capData->teamCapped);

(That will set the 'allow' value to the boolean result of the inequality comparison of teamCapping and teamCapped)
I didn't know the solution could be so simple and elegant.

@JeffM
I made a localhost test after compiling the plug-in.
(It was possible to capture other teams flags, but not do self-caps.)
I didn't really think of adding the licenses in each plug-in, since I mostly intended them to be downloaded as a single release.
I had this for license information: Plug-in Licenses.
I'm not experienced with copyright matters, I thought simply adding a license was enough. (Sample is released into public domain.)
I'll see about making the plug-ins simple and short, as I haven't really seen examples of them.

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
There's always something to remember and it's been a game I love. ~Zehra
The time spent is a time which can never be regained, so it's a time to enjoy. ~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.

User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5173
Joined: Fri Dec 13, 2002 4:11 am
Location: https://discord.gg/NN9uAvx
Contact:

Re: NoSelfCaptures

Post by JeffM » Sun Jul 01, 2018 9:06 pm

Zehra wrote:
Sun Jul 01, 2018 7:36 pm
I didn't know the solution could be so simple and elegant.
Yeah you did, we went over this in irc. You keep saying you will learn the basics of c, but you never do.

As for copyright, you need to provide a copyright notice, usuallyt with your real name, and the license, with the work.
Last edited by JeffM on Sun Jul 01, 2018 10:09 pm, edited 1 time in total.

User avatar
Zehra
Private First Class
Private First Class
Posts: 582
Joined: Sun Oct 18, 2015 3:36 pm
Location: Arctic

Re: NoSelfCaptures

Post by Zehra » Sun Jul 01, 2018 9:11 pm

Okay, will look into this a bit more.
Edit: Plug-in now has license info in header.

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
There's always something to remember and it's been a game I love. ~Zehra
The time spent is a time which can never be regained, so it's a time to enjoy. ~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.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests