Files
dsrc/sku.0/sys.server/compiled/game/script/structure/mini_vehicle_control.script
T
2013-09-10 23:17:15 -07:00

99 lines
2.5 KiB
Plaintext

// ALL MINI VEHICLE SCRIPTS
// structure/mini_vehicle_control.script
// creature/mini_vehicle.script
// terminal/mini_vehicle_terminal.script
include library.player_structure;
include library.utils;
//variable constants
const string VEHICLE_ID = "mini_vehicle.vehicle";
trigger OnAttach()
{
messageTo(self, "checkVehicleId", null, 3, false);
return SCRIPT_CONTINUE;
}
trigger OnReceivedItem(obj_id srcContainer, obj_id transferer, obj_id item)
{
if(isPlayer(item))
messageTo(self, "handlerMiniVehicleReceived", null, 6, false);
return SCRIPT_CONTINUE;
}
trigger OnLostItem(obj_id srcContainer, obj_id transferer, obj_id item)
{
if(isPlayer(item))
messageTo(self, "handlerMiniVehicleLost", null, 6, false);
return SCRIPT_CONTINUE;
}
//This is called on init to get the terminal user's OID
messageHandler checkVehicleId()
{
if(!isValidId(getObjIdObjVar(self, VEHICLE_ID)))
detachScript(self, "structure.mini_vehicle_control");
return SCRIPT_CONTINUE;
}
messageHandler handlerMiniVehicleReceived()
{
//remove the script if no vehicle exists
if(!isValidId(self) && !exists(self))
return SCRIPT_CONTINUE;
if(!hasObjVar(self, VEHICLE_ID))
{
detachScript(self, "structure.mini_vehicle_control");
}
obj_id vehicle = getObjIdObjVar(self, VEHICLE_ID);
if(!isValidId(vehicle) && !exists(vehicle))
return SCRIPT_CONTINUE;
//the vehicle is moving already or the owner is setting patrols
if(utils.hasScriptVar(vehicle, "vehicle.moving") || utils.hasScriptVar(vehicle, "vehicle.settingPatrol"))
{
return SCRIPT_CONTINUE;
}
obj_id[] players = player_structure.getPlayersInBuilding(self);
if(players == null || players.length == 0)
return SCRIPT_CONTINUE;
//players already here
if(players.length >= 1)
return SCRIPT_CONTINUE;
//Reactivate the sleeping vehicle
broadcastMessage("handleActivateVehicle", new dictionary());
return SCRIPT_CONTINUE;
}
messageHandler handlerMiniVehicleLost()
{
//remove the script if no vehicle exists
if(!isValidId(self) && !exists(self))
return SCRIPT_CONTINUE;
if(!hasObjVar(self, VEHICLE_ID))
detachScript(self, "structure.mini_vehicle_control");
obj_id vehicle = getObjIdObjVar(self, VEHICLE_ID);
if(!isValidId(vehicle) && !exists(vehicle))
return SCRIPT_CONTINUE;
if(utils.hasScriptVar(vehicle, "vehicle.settingPatrol"))
return SCRIPT_CONTINUE;
obj_id[] players = player_structure.getPlayersInBuilding(self);
if(players == null || players.length == 0)
{
broadcastMessage("handleDeactivateVehicle", new dictionary());
}
return SCRIPT_CONTINUE;
}