Page 1 of 1

NoSelfCaptures

Posted: Sun Jul 01, 2018 11:42 am
by Zehra
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

Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 4:02 pm
by JeffM
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.

Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 4:21 pm
by blast
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)

Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 6:24 pm
by JeffM
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


Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 7:36 pm
by Zehra
@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

Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 9:06 pm
by JeffM
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.

Re: NoSelfCaptures

Posted: Sun Jul 01, 2018 9:11 pm
by Zehra
Okay, will look into this a bit more.
Edit: Plug-in now has license info in header.

-Zehra