quraji
zap
- Reaction score
- 144
CWAL - Can't Wait Any Longer
Requires:
-NewGen with recent JassHelper (that supports vJass/Zinc)
This system just allows you to enable instant build, train, upgrade, and research modes for a player. With all four enabled you get a similar effect to the "operation cwal" cheat (or the one from wc3 which I forget).
I'm not really sure what the policy on Zinc submissions is, but I'll assume it's allowed since it compiles with the same tool as vJass.
JASS:
//! zinc
library CWAL requires CWALGetUnitCosts
{
// CWAL: Can't Wait Any Longer v1.0 by quraji
//
// This library emulates the CWAL cheat that allows you to instantly
// build and train units; upgrade buildings, and research technology.
//
// PROS: -Allows control over the 4 CWAL modes (build, train, upgrade and research) for each player
// -Can attempt to subtract the costs of units (as enabling instant train will make them free)
// -Tracks when a building sets a rally point, and makes units rally to it as normal
//
// CONS: -Can not get the costs of heroes
//
// USAGE:
//
// Using the system is pretty easy. First, if you DON'T want unit costs to be subtracted, then set the below line to
// false instead of true.
constant boolean SUBTRACT_UNIT_COSTS = true;
//
// After that you just need to use the provided functions when you like:
//
// CWAL_InstantBuildIsEnabled (player p) -> boolean
// This will return true if InstantBuild is enabled for the player, false if not
// CWAL_EnableInstantBuild (player p, boolean flag)
// Pass a player and true to enable InstantBuild for that player, or false to disable.
//
// CWAL_InstantTrainIsEnabled (player p) -> boolean
// This will return true if InstantTrain is enabled for the player, false if not
// CWAL_EnableInstantTrain (player p, boolean flag)
// Pass a player and true to enable InstantTrain for that player, or false to disable.
//
// CWAL_InstantUpgradeIsEnabled (player p) -> boolean
// This will return true if InstantUpgrade is enabled for the player, false if not
// CWAL_EnableInstantUpgrade (player p, boolean flag)
// Pass a player and true to enable InstantUpgrade for that player, or false to disable.
//
// CWAL_InstantResearchIsEnabled (player p) -> boolean
// This will return true if InstantResearch is enabled for the player, false if not
// CWAL_EnableInstantResearch (player p, boolean flag)
// Pass a player and true to enable InstantResearch for that player, or false to disable.
//
// That's it, have fun.
//
constant integer ORDER_CANCEL = 851976, ORDER_RALLY = 851980, ORDER_RIGHTCLICK = 851971;
constant key KEY_RALLY_X, KEY_RALLY_Y, KEY_RALLY_UNIT;
hashtable HT = InitHashtable();
trigger trig_Build[12],
trig_Train[12],
trig_Upgrade[12],
trig_Research[12],
trig_RallyPoint=CreateTrigger(),
trig_RallyUnit=CreateTrigger();
function onBuild ()
{
unit u = GetConstructingStructure();
TriggerSleepAction(0.);
UnitSetConstructionProgress(u, 100);
u = null;
}
function onTrain ()
// cancels the train order and creates a unit of that type.
// note that canceling the train order refunds the cost of the unit
// if the building training the unit has a rally point saved, the unit will walk there
{
unit trainer = GetTriggerUnit(), u;
player p = GetOwningPlayer(trainer);
integer tid = GetHandleId(trainer), utype = GetTrainedUnitType();
IssueImmediateOrderById(trainer, ORDER_CANCEL);
u = CreateUnit(p, utype, GetUnitX(trainer), GetUnitY(trainer), 270.);
if (HaveSavedHandle(HT, tid, KEY_RALLY_UNIT))
{
IssueTargetOrderById(u, ORDER_RIGHTCLICK, LoadWidgetHandle(HT, tid, KEY_RALLY_UNIT));
}
if (HaveSavedReal(HT, tid, KEY_RALLY_X))
{
IssuePointOrderById(u, ORDER_RIGHTCLICK, LoadReal(HT, tid, KEY_RALLY_X), LoadReal(HT, tid, KEY_RALLY_Y));
}
static if (SUBTRACT_UNIT_COSTS)
{
if (!IsUnitType(u, UNIT_TYPE_HERO))
{
SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)-GetUnitGoldCost(utype));
SetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER)-GetUnitWoodCost(utype));
}
}
p = null; trainer = null; u = null;
}
function onUpgrade ()
{
unit u = GetTriggerUnit();
TriggerSleepAction(0.);
UnitSetUpgradeProgress(u, 100);
u = null;
}
function onResearch ()
{
player p = GetTriggerPlayer();
integer tech = GetResearched();
SetPlayerTechResearched(p, tech, GetPlayerTechCount(p, tech, true)+1);
p = null;
}
function onRallyCheck () -> boolean
// checks to see if the point order was issued by a building, and that it is a rally order or right-click order.
// might be redundant - I forget if there are buildings that can cast an spells..
{
integer id=GetIssuedOrderId();
return (IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) && (id==ORDER_RALLY || id==ORDER_RIGHTCLICK));
}
function onRallyPoint ()
// store the rally point in the hashtable
{
integer id=GetHandleId(GetTriggerUnit());
SaveReal(HT, id, KEY_RALLY_X, GetOrderPointX());
SaveReal(HT, id, KEY_RALLY_Y, GetOrderPointY());
RemoveSavedHandle(HT, id, KEY_RALLY_UNIT);
}
function onRallyUnit ()
// store the rally unit in the hashtable
{
integer id=GetHandleId(GetTriggerUnit());
SaveWidgetHandle(HT, id, KEY_RALLY_UNIT, GetOrderTarget());
RemoveSavedReal(HT, id, KEY_RALLY_X);
RemoveSavedReal(HT, id, KEY_RALLY_Y);
}
function onInit ()
{
integer i=0;
for (0<=i<12)
{
// create the triggers
trig_Build<i>=CreateTrigger();trig_Train<i>=CreateTrigger();trig_Upgrade<i>=CreateTrigger();trig_Research<i>=CreateTrigger();
// register the events
TriggerRegisterPlayerUnitEvent(trig_Build<i>, Player(i), EVENT_PLAYER_UNIT_CONSTRUCT_START, Filter(function()->boolean{return true;}));
TriggerRegisterPlayerUnitEvent(trig_Train<i>, Player(i), EVENT_PLAYER_UNIT_TRAIN_START, Filter(function()->boolean{return true;}));
TriggerRegisterPlayerUnitEvent(trig_Upgrade<i>, Player(i), EVENT_PLAYER_UNIT_UPGRADE_START, Filter(function()->boolean{return true;}));
TriggerRegisterPlayerUnitEvent(trig_Research<i>, Player(i), EVENT_PLAYER_UNIT_RESEARCH_START, Filter(function()->boolean{return true;}));
TriggerRegisterPlayerUnitEvent(trig_RallyPoint, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, Filter(function()->boolean{return true;}));
TriggerRegisterPlayerUnitEvent(trig_RallyUnit, Player(i), EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER, Filter(function()->boolean{return true;}));
// add the appropriate actions and disable the triggers until CWAL is enabled
TriggerAddAction(trig_Build<i>, function onBuild);
TriggerAddAction(trig_Train<i>, function onTrain);
TriggerAddAction(trig_Upgrade<i>, function onUpgrade);
TriggerAddAction(trig_Research<i>, function onResearch);
DisableTrigger(trig_Build<i>); DisableTrigger(trig_Train<i>); DisableTrigger(trig_Upgrade<i>); DisableTrigger(trig_Research<i>);
}
// don't disable rally trigger, as you want rally points to be tracked regardless if CWAL is enabled
TriggerAddCondition(trig_RallyPoint, Filter(function onRallyCheck));
TriggerAddCondition(trig_RallyUnit, Filter(function onRallyCheck));
TriggerAddAction(trig_RallyPoint, function onRallyPoint);
TriggerAddAction(trig_RallyUnit, function onRallyUnit);
}
public function CWAL_InstantBuildIsEnabled (player p) -> boolean { return IsTriggerEnabled(trig_Build[GetPlayerId(p)]); }
public function CWAL_EnableInstantBuild (player p, boolean flag)
{
if (flag) EnableTrigger(trig_Build[GetPlayerId(p)]);
else DisableTrigger(trig_Build[GetPlayerId(p)]);
}
public function CWAL_InstantTrainIsEnabled (player p) -> boolean { return IsTriggerEnabled(trig_Train[GetPlayerId(p)]); }
public function CWAL_EnableInstantTrain (player p, boolean flag)
{
if (flag) EnableTrigger(trig_Train[GetPlayerId(p)]);
else DisableTrigger(trig_Train[GetPlayerId(p)]);
}
public function CWAL_InstantUpgradeIsEnabled (player p) -> boolean { return IsTriggerEnabled(trig_Upgrade[GetPlayerId(p)]); }
public function CWAL_EnableInstantUpgrade (player p, boolean flag)
{
if (flag) EnableTrigger(trig_Upgrade[GetPlayerId(p)]);
else DisableTrigger(trig_Upgrade[GetPlayerId(p)]);
}
public function CWAL_InstantResearchIsEnabled (player p) -> boolean { return IsTriggerEnabled(trig_Research[GetPlayerId(p)]); }
public function CWAL_EnableInstantResearch (player p, boolean flag)
{
if (flag) EnableTrigger(trig_Research[GetPlayerId(p)]);
else DisableTrigger(trig_Research[GetPlayerId(p)]);
}
}
//! endzinc
library CWALGetUnitCosts
// this had to be done in vJass
native GetUnitGoldCost takes integer unitid returns integer
native GetUnitWoodCost takes integer unitid returns integer
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
Attached is a demo map (kick the computer's butt!).