Page 1 of 3

Re: hi perr

Posted: Tue Jun 02, 2015 6:14 am
by perrinoia
You do not have to rewrite the base GroupTrigger events.

Code: Select all

	instant Trigger "GroupTrigger" {
		dataBlock = "GroupTrigger";
		name = "CaptureTrigger";	// "function <name>::onEnter(%this, %object)", "function <name>::onTrigger(%this, %object)", "function <name>::onLeave(%this, %object)"
		position = "0 0 20";
		rotation = "0 0 0";
		boundingBox = "-1 -1 -1 1 1 1";
		isSphere = "False";
	};
};
//--- export object end ---//
$teamScoreLimit = 12;
exec(objectives);
$Game::missionType = "CTF";
$cdTrack = 2;
$cdPlayMode = 1;

function CaptureTrigger::onEnter(%this, %object)
{
	messageAll(0, "CaptureTrigger works!");
}
What is the purpose of this trigger, by the way?

It almost looks like you are trying to code Battlefield 2 style base capturing. Am I right?

If this is the case... You should use onTrigger, instead of onEnter.

onEnter is called once, when you enter the box.
onTrigger is called approximately 3 times per second, while you are in the box.
onLeave is never called, and I've tried several things to remedy this, such as incrementing a variable in onTrigger, and then evaluating the onLeave event if decrementing the same variable half a second later makes it equal to zero. It works, but can be thwarted by lag.

If you are attempting to implement BF2 style base capturing, I recommend using a variable that contains the trigger's object id and the player's team...

For instance:

Code: Select all

function CaptureTrigger::onTrigger(%this, %object)
{
	%max = getNumTeams();
	%team = GameBase::getTeam(%object);
	schedule(sprintf("if($pwns[%1, %3]-- < "@ $pwns[%this, %team]++ @") CaptureTrigger::onLeave(%1, %2);", %this, %object, %team), 0.5);	// ++ now, -- later. Interval must be greater than 1/3 seconds.
	for(%i = 0; %i < %max; %i++)
		%pwnt += ($pwns[%this, %i] < $pwns[%this, %team]);	// count the teams that have less pwnage.
	if(%pwnt == %max - 1)	// if all others are pwnt, declare a winner!
	{
		echo($Server::teamName[%team] @" pwns "@ %this @".");
	}
}

Re: hi perr

Posted: Tue Jun 02, 2015 1:36 pm
by perrinoia
OK, both the function I previously wrote and the one you previously wrote are crap...

Let's start over.

I put this code in my mission file:

Code: Select all

function CaptureTrigger::onEnter(%this, %object)
{
	messageAll(0, "CaptureTrigger::onEnter("@ %this @", "@ %object @");");
}

function CaptureTrigger::onTrigger(%this, %object)
{
	messageAll(0, "CaptureTrigger::onTrigger("@ %this @", "@ %object @");");
}

function CaptureTrigger::onLeave(%this, %object)
{
	messageAll(0, "CaptureTrigger::onLeave("@ %this @", "@ %object @");");
}
I named a trigger "CaptureTrigger" and then walked through it and this is what I see.
CaptureTrigger.png
CaptureTrigger.png (9.17 KiB) Viewed 4105 times
Does that make sense?

8408 = Trigger
8415 = Player

Re: hi perr

Posted: Tue Jun 02, 2015 9:00 pm
by perrinoia

Code: Select all

function capture::post(%this, %player)

schedule("Capturing::Post("@ %this @", "@ %player @");", 0.01);
Don't forget to spell your function and command the same way, though... One says capture, the other says capturing.

Re: hi perr

Posted: Wed Jun 03, 2015 9:56 am
by perrinoia
Ps: why is it scheduled?

Why not just write capture::post(%this, %player);

Re: hi perr

Posted: Wed Jun 03, 2015 12:05 pm
by perrinoia
Wait, is this team based, or free for all?

Re: hi perr

Posted: Thu Jun 04, 2015 6:02 am
by perrinoia

Code: Select all

Group::iterateRecursive(getGroup(%this), Gamebase::setTeam, Gamebase::getTeam(%object));
This will set the team of everything in the trigger's group and sub-groups to match the team of the object that triggered the trigger.

Changing the color of the laser is more difficult. You'll need a different color laser for each team. You'll need to delete the old laser and spawn a new one, each time.

Re: hi perr

Posted: Thu Jun 04, 2015 6:25 pm
by perrinoia
Wut?

You don't need to replace the switch. It's emblems reflect the team it belongs to.
You do needed to replace the laser, but it sounds like you've got that covered.

As for the description variable, no... I don't think so...

But you can use Object::getName(%this) to get the object name (not to be confused with the name of the object, lol), which you could call "Zone A", if you wish.

Code: Select all

 instant trigger "Zone A" {
    name = "CapturePost";
    Etc...
}
Or you could get the group's name:

Code: Select all

 instant SIMgroup "Zone A" {
    Instant trigger "anything" {
        Name = "CapturePost";
        Etc...
    }
}

Re: hi perr

Posted: Thu Jun 04, 2015 11:16 pm
by perrinoia
Well, first of all, you should use onInit instead of onAdd, unless your switch is not part of the mission.

In that function, you should create a generic laser, and store it's object ID in a global variable (use $ instead of %, or store it as a property of the switch, example %this.laserID = projectile::spawnprojectile, blah blah blah).

Then, in your capture post function, you should delete the old laser and spawn a new one.

Re: hi perr

Posted: Tue Jun 09, 2015 7:44 pm
by perrinoia
Need to work on spawning lasers, triggers, or players?

Re: hi perr

Posted: Thu Jun 11, 2015 8:23 am
by perrinoia
The last function was copy and pasted from Annihilation mod. I commented out two lines and added two more to that function.
The first 4 functions, however, are completely rewritten for your purposes.

Code: Select all

// Adds this to set if no obstructions are nearby.
function DropPointMarker::pickRandomSpawn(%this, %set)
{
	%tmp = newObject("Obstructions", SimSet);
	if(!containerBoxFillSet(%tmp, $SimPlayerObjectType | $MineObjectType | $StaticObjectType, GameBase::getPosition(%this), 2, 2, 2, 0))
		addToSet(%set, %this);
	deleteObject(%tmp);
}

// If the tower switch is on the right team, runs DropPointMarker::pickRandomSpawn for each DropPointMarker in the TowerSwitch's group.
function TowerSwitch::getSpawns(%this, %team, %set)
{
	if(GameBase::getTeam(%this) == %team)
		Group::iterateRecursive(getGroup(%this), GameBase::virtual, "pickRandomSpawn", %set);
}

// Runs TowerSwitch::getSpawns for every TowerSwitch in the mission.
function Game::pickRandomSpawn(%team)
{
	%tmp = newObject("Random", SimSet);
	Group::iterateRecursive(MissionGroup, GameBase::virtual, "getSpawns", %team, %tmp);
	return Group::getObject(%tmp, floor(getRandom() * Group::objectCount(%tmp)));
	deleteObject(%tmp);
}

// Modified to prevent picking a random spawn when there are no start spawns.
function Game::pickTeamSpawn(%team, %respawn)
{
	return getWord(Game::pickStartSpawn(%team) @" "@ Game::pickRandomSpawn(%team), %respawn);
}

// Modified to prevent spawning when no valid spawn points are found.
function Game::playerSpawn(%clientId, %respawn)
{
	if(!$ghosting)
		return false;
	
	Client::clearItemShopping(%clientId);
	%spawnMarker = Game::pickPlayerSpawn(%clientId, %respawn);
	
	%clientId.guiLock = "";
	%clientId.dead = "";
	if(%spawnMarker == -1)
	{
// 		%spawnPos = "0 0 300";
// 		%spawnRot = "0 0 0";
		BottomPrint(%clientId, "<jc>No available spawn points.\nTry again later.", 2);
		return;
	}
	else
	{
		%spawnPos = GameBase::getPosition(%spawnMarker);
		// make sure the player doesnt end up with goofy rotation and screw up deploying items.. -plasmatic
		%spawnRot = "0 0 "@ getword(GameBase::getRotation(%spawnMarker),2);
	}
	//plasmatic 3.0
	if($build)
	{
		$DefaultArmor[Male] = armormBuilder;
		$DefaultArmor[Female] = armorfBuilder;	
	}
	else
	{
		$DefaultArmor[Male] = armormWarrior;
		$DefaultArmor[Female] = armorfWarrior;			
	}
	%armor = $DefaultArmor[Client::getGender(%clientId)];
	
	%pl = spawnPlayer(%armor, %spawnPos, %spawnRot);
	echo("SPAWN: "@ Client::getName(%clientID)@ " cl:" @ %clientId @ " pl:" @ %pl @ " marker:" @ %spawnMarker @ " armor:" @ %armor @" rot: "@gamebase::getrotation(%pl));
	%pl.cloakable = true;	//for base cloaker -plasmatic
	
	%clientId.observerMode = "";
	%pl.teled = "";	// for teleporter 2.2 model -plasmatic
	%clientId.ConnectBeam = "";	//for zappy invs -plasmatic
	%clientId.InvTargetable = "";	//zap!
	%ClientId.InvConnect = "";	//Zap!
	
	if(%pl != -1)
	{
		//Client::clearItemShopping(%clientId);
		GameBase::setTeam(%pl, Client::getTeam(%clientId));
		Client::setOwnedObject(%clientId, %pl);
		Game::playerSpawned(%pl, %clientId, %armor, %respawn);
		%pl.cloakable = true;
		$jailed[%pl] = "";
		$released[%pl] = "";
		if($matchStarted)
		{
			Client::setControlObject(%clientId, %pl);
			%clientId.droid=false;
		}
		else
		{
			%clientId.observerMode = "pregame";
			Client::setControlObject(%clientId, Client::getObserverCamera(%clientId));
			Observer::setOrbitObject(%clientId, %pl, 3, 3, 3);
		}
		//==================  respawn Invulnerable -plasmatic
		$respawnInvulnerableTime = 10;
		if(%respawn)	
		{
			$respawnInvulnerableTime = 5;
			if($siegeFlag)	Siege::waypointClient(%clientId);
		}
		%damage = %armor.maxDamage - 0.001;
		GameBase::setEnergy(%pl, %armor.maxEnergy);	///2);
		GameBase::setAutoRepairRate(%pl, %damage / $respawnInvulnerableTime);
		%pl.invulnerable = true;
		%pl.cloakable = true;	//fer base cloaker -plasmatic
		$jailed[%pl] = "";	//just to be certain for jail..
		$released[%pl] = "";
		
		incInvulnerable(%pl, 0);
		%weapon = Player::getMountedItem(%pl,$WeaponSlot);
		if(%weapon != -1) 
		{
			%pl.lastWeapon = %weapon;
			Player::unMountItem(%pl,$WeaponSlot);
		}
		if(!%respawn)
		{
			// initial drop
			if($siegeFlag)
			{
				schedule("Client::sendMessage("@%clientId@", 0, \"Welcome to Siege! Capture or hold the switch to complete the mission.\");",5);
				schedule("Siege::InitialwaypointClient("@%clientId@");",5);
			}
// 			if(%clientId.SpecialMessage == true)
// 				CustomMessage(%clientId);
// 			ModSettingsInfo(%clientId, true);
			//echo("join team "@Client::getTeam(%clientId)@" old team = "@%clientId.lastteam);
			if(%clientId.LastTeam != -1 && %clientId.LastTeam != Client::getTeam(%clientId))
			{
				if($annihilation::DisableTurretsOnTeamChange)
				Turret::DisableClients(%clientId);	
			}
			
			%clientId.LastTeam = Client::getTeam(%clientId);
		}  
		
	}
	return true;
}