Author Topic: Make something happen when vehicle enters zone, without editing Event_Zones  (Read 791 times)

Part of a gamemode I'm making requires changing clients' variables when they drive vehicles into zones, so I accomplished this by editing a function in the Event_Zones add-on. But I need a way to do this without having to edit Event_Zones, because that makes it difficult to release the gamemode.

So what would be the best way to make this happen without editing Event_Zones?
Is it feasible to just copy-paste the editted function in Event_Zones into the server.cs of my gamemode?

Below is the function I've edited in Event_Zones. The portion of the code I added is surrounded by /////////////////.
Code: [Select]
function fxDTSBrick::onVehicleEnterZone(%obj,%vehicle)
{
//obj is the brick!
if(isObject(%obj.trigger) && %obj.trigger.istriggerBricktrigger == 1)
{
%DriverClient = "";
%DriverPlayer = "";
%VehicleOwnerClient = "";
%VehicleOwnerPlayer = "";
%BrickOwnerClient = %obj.getGroup().client;
%BrickOwnerPlayer = %obj.getGroup().client.player;

//Figure Out Driver---------------------------------
if(isObject(%vehicle.getControllingClient()))
{
%DriverClient = %vehicle.getControllingClient();
}
else//the vehicle may be skiis or there is no driver..
{
if(isObject(%vehicle.client))
{
%DriverClient = %vehicle.client;
}
//otherwise leave the DriverClient empty...
}
%DriverPlayer = %DriverClient.player;

//Figure Out Owner-----------------------------------
if(IsObject(%vehicle.brickGroup))
{
%OwnerClient = %vehicle.brickGroup.client;
}
else//if skiis, Owner is driver..
{
if(IsObject(%vehicle.client))
{
%OwnerClient = %vehicle.client;
}
}
%OwnerPlayer = %OwnerClient.player;

///////////////////////////////////////////////////////////////////////      Faraday's Pizza Delivery crap BELOW      //////////////////////////////////////////////////////////////////////////////////////////

if(%DriverClient.deliverTo == %obj && %DriverClient.pizzaCount >= 1)
{
%DriverClient.score += mceil(0.1*(vectorDist(%DriverClient.deliverFromPos,%DriverClient.deliverTo.getposition())));
%DriverClient.pizzaCount -= 1;
if($DelivMode == 1)
{
%DriverClient.deliverTo = $PizzaDeliveryGamemodeLocations[getRandom(1,$PizzaDeliveryGamemodeNumLocations)];
}
if($DelivMode == 2)
{
$Mode2Deliv = $PizzaDeliveryGamemodeLocations[getRandom(1,$PizzaDeliveryGamemodeNumLocations)];
}
echo("Someone delivered a pizza");
talk("Someone delivered a pizza");
}


if(%obj.getname() $= "_pizza")
{
%DriverClient.pizzaCount = 3;
echo("Someone got more pizza");
talk("Someone got more pizza");
}

//////////////////////////////////////////////////////////////////////      Faraday's Pizza Delivery crap ABOVE      /////////////////////////////////////////////////////////////////////////////////////////

$InputTarget_["Self"] = %obj;
$InputTarget_["Vehicle"] = %vehicle;



$InputTarget_["Driver(Client)"] = %DriverClient;
$InputTarget_["Driver(Player)"] = %DriverPlayer;

$InputTarget_["MiniGame"] = %OwnerClient.minigame;

$InputTarget_["Vehicle_Owner(Player)"] = %OwnerPlayer;
$InputTarget_["Vehicle_Owner(Client)"] = %OwnerClient;

$InputTarget_["Brick_Owner(Client)"] = %BrickOwnerClient;
$InputTarget_["Brick_Owner(player)"] = %BrickOwnerPlayer;

if(isObject(%DriverClient))//driver client.
{
%obj.processInputEvent("onVehicleEnterZone",%DriverClient);
}
else//try the .client field used with skiis - if not settle for brick group owner.
{
%obj.processInputEvent("onVehicleEnterZone",%OwnerClient);
}
}

}
« Last Edit: June 16, 2016, 05:44:33 AM by Farad »

Why not just use a package.

forceRequiredAddOn zones
Package
onVehicleEnterZone
parent
do edited functionality

optionally you could just embed this custom version into the gamemode itself and have it execute the event in the server.cs file in the gamemode

Why not just use a package.

forceRequiredAddOn zones
Package
onVehicleEnterZone
parent
do edited functionality

Alright, I tried that but nothing happens when I enter the zones. I probably did the solution wrong - do you see what's wrong below?
Jut to clarify - the below code is written in the server.cs of my gamemode.
Code: [Select]
// We need the Event_Zones add-on for this, so force it to load.
%error = ForceRequiredAddOn("Event_Zones");

// If the add-on was not found, show error
if(%error == $Error::AddOn_NotFound)
{
error("ERROR: Event_Zones - required add-on Event_Zones not found.");
}


package VehicleEnterZonePackage
{
function fxDTSBrick::onVehicleEnterZone(%obj,%vehicle)
{
                if(isObject(%obj.trigger) && %obj.trigger.istriggerBricktrigger == 1)
{
//if the client reaches their delivery location and has pizza...
if(%DriverClient.deliverTo == %obj && %DriverClient.pizzaCount >= 1)
{
%DriverClient.score += mceil(0.1*(vectorDist(%DriverClient.deliverFromPos,%DriverClient.deliverTo.getposition())));
%DriverClient.pizzaCount -= 1;

if($DelivMode == 1)
{
%DriverClient.deliverTo = $PizzaDeliveryGamemodeLocations[getRandom(1,$PizzaDeliveryGamemodeNumLocations)];
}
if($DelivMode == 2)
{
$Mode2Deliv = $PizzaDeliveryGamemodeLocations[getRandom(1,$PizzaDeliveryGamemodeNumLocations)];
}
echo("Someone delivered a pizza");
talk("Someone delivered a pizza");
}

//if the client drives through a pizza box pick-up zone...
if(%obj.getname() $= "_pizza")
{
%DriverClient.pizzaCount = 3;
echo("Someone got more pizza");
talk("Someone got more pizza");
}
}
Parent::onVehicleEnterZone(%obj,%vehicle);
}
};
activatePackage(VehicleEnterZonePackage);

optionally you could just embed this custom version into the gamemode itself and have it execute the event in the server.cs file in the gamemode
Oh, I see. Wouldn't the real Event_Zones server.cs overwrite my custom one if it is executed after my gamemode though?

update: I got this to work, thanks.
« Last Edit: June 16, 2016, 03:13:58 PM by Farad »

Crispy made an addon that combines both Events and Bricks together, and has events "OnVehicleEnterBrick" "OnVehicleLeaveBreak" and "OnVehicleInBrick". It should be on Blockland Glass.