Snippet CWAL - Can't Wait Any Longer

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()-&gt;boolean{return true;}));
            TriggerRegisterPlayerUnitEvent(trig_Train<i>, Player(i), EVENT_PLAYER_UNIT_TRAIN_START, Filter(function()-&gt;boolean{return true;}));
            TriggerRegisterPlayerUnitEvent(trig_Upgrade<i>, Player(i), EVENT_PLAYER_UNIT_UPGRADE_START, Filter(function()-&gt;boolean{return true;}));
            TriggerRegisterPlayerUnitEvent(trig_Research<i>, Player(i), EVENT_PLAYER_UNIT_RESEARCH_START, Filter(function()-&gt;boolean{return true;}));
            TriggerRegisterPlayerUnitEvent(trig_RallyPoint, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, Filter(function()-&gt;boolean{return true;}));
            TriggerRegisterPlayerUnitEvent(trig_RallyUnit, Player(i), EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER, Filter(function()-&gt;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&#039;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) -&gt; 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) -&gt; 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) -&gt; 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) -&gt; 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!).
 

Attachments

  • CWAL v1.0.w3x
    128.5 KB · Views: 283

quraji

zap
Reaction score
144
TriggerSleepAction(0.) != instant.
Use a timer instead :D

Yeah I originally used a timer, but strangely TriggerSleepAction works better. When I used a timer, the unit for some reason would randomly keep showing the build animation (swinging a hammer or w/e) even if the build was complete. I didn't feel like testing it further to find out why :p

As for it not being instant, it's close enough not to notice, and it actually gives you time to see the building start constructing for a fraction of a second before it completes (it looks kinda better than just having it appear :p).
 

Executor

I see you
Reaction score
57
You could also increase the timer interval to 0.1 or sth. maybe this would change the effect and would be faster than sleep.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
You could make empiric tests with a period lower than 0.3 s (chat message and convert real to string powa)
 

quraji

zap
Reaction score
144
I suppose I could do that stuff, but like I said, too lazy to.

The sleep looks and works just fine :p

Unless someone tries it out and finds it just isn't instant enough for them :thup:
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> operation cwal" cheat (or the one from wc3 which I forget)

operation CWAL = Starcraft
warpten = WC3
 

SerraAvenger

Cuz I can
Reaction score
234
I think there is the possibility to compile ZINC it to vJASS. Don't know what the output looks like, though.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top