Snippet TD (or other maps) Leaver Snippet

Tyman2007

Ya Rly >.
Reaction score
74
Alright.. I haven't tested this because i didn't have time to put it into a map and test it, and it's pointless for me to post a screenie of a leaver snippet, but i have confidence it will absolutely positively 100% work.

I know i used a lot of BJs, but i don't know how to clear those BJs.. Also please tell me if i have anything pointless or if there's a way to make the code look and/or run much better please tell me.

Also if there's a bug, please don't just say "There's a bug, go fix it then i'll dl it", Be as specific as you can with it. Tell me the bug, the fix, and why it's a bug so i can learn more and create more efficiant vJass code. Also please only tell me about the bug for the vJass trigger, i already know GUI and use it only as a base.

Lastly, If there's any good intermediate vJass and Jass tutorials please give me a link. That would be much appreciated.

GUI/Jass/vJass: GUI or vJass
Leakless: Pretty much.

First off, the initialing trigger:

Code:
PL Init
    Events
        Map initialization
    Conditions
    Actions
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Trigger - Add to Player Leaves Jass <gen> the event (Player - (Picked player) leaves the game)

vJass version:

JASS:
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////                               Leaver snippet by Tyman2007                                      ////
////                                                                                                ////
////                                   How to install:                                              ////
////                         1. Copy the trigger PL Init to your map.                               ////
////                         2. Copy either Player Leaves Jass or Player Leaves GUI to your map     ////
////                                                                                                ////
////                                                                                                ////
////                                                                                                ////
////                                   Side Notes:                                                  ////
////                         -If your map doesn&#039;t use teams Don&#039;t use this.                         ////
////                         -If your map doesn&#039;t have multiple units per person Don&#039;t use this.    ////
////                         -If you don&#039;t have newgen or a vJass processor use the GUI version.    ////
////                         -If there&#039;s any bugs, Please notify Tyman2007 on Thehelper.net         ////
////                         -If you have any suggestions to improve the code notify Tyman2007      ////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////



scope PlayerLeaves initializer Init

globals

//Please don&#039;t mess with the variables a through i.
    private integer a
    private group b
    private integer c
    private integer d
    private integer e
    private force f
    private integer g
    private group h
    private player i

//Message that says that an anonymous player has left.
    private constant string msg1 = &quot;|c0000ccff[Game]|r|c00ff6600A|r|c00ff6300 |r|c00ff5f00p|r|c00ff5b00l|r|c00ff5700a|r|c00ff5400y|r|c00ff5000e|r|c00ff4c00r|r|c00ff4800 |r|c00ff4400h|r|c00ff4100a|r|c00ff3d00s|r|c00ff3900 |r|c00ff3500l|r|c00ff3200e|r|c00ff2e00f|r|c00ff2a00t|r|c00ff2600 |r|c00ff2200t|r|c00ff1f00h|r|c00ff1b00e|r|c00ff17&quot;
//Message that states the gold and towers have been equally distributed.
    private constant string msg2 = &quot;|c003366ff---Gold and Towers have been distributed equally to leaving players team-members---|r&quot;
//Message that says the gold you&#039;ve recieved.
    private constant string msg3 = &quot;|c00ffcc00G|r|c00ffd00bo|r|c00ffd315l|r|c00ffd71fd|r|c00ffda29 |r|c00ffdd33R|r|c00ffe13ee|r|c00ffe448c|r|c00ffe852i|r|c00ffeb5ce|r|c00ffee66v|r|c00fff271e|r|c00fff57bd|r|c00fff985:|r|c00fffc8f |r&quot;
endglobals

///////////////////////////////////////////////////////////////////////
//   If you edit below this line without knowing what you&#039;re doing   //
//              I make bad maps go away =)                           //
///////////////////////////////////////////////////////////////////////



private function GroupCond5 takes nothing returns boolean
    return ( IsPlayerAlly(GetFilterPlayer(), GetTriggerPlayer()) == true )
endfunction

private function GroupCond4 takes nothing returns boolean
    return ( GetPlayerController(GetFilterPlayer()) == MAP_CONTROL_USER )
endfunction

private function GroupCond3 takes nothing returns boolean
    return ( GetPlayerSlotState(GetFilterPlayer()) == PLAYER_SLOT_STATE_PLAYING )
endfunction

private function GroupCond2 takes nothing returns boolean
    return GroupCond4() and GroupCond3()
endfunction

private function GroupCond1 takes nothing returns boolean
    return GroupCond5() and GroupCond2()
endfunction

private function ForceActions takes nothing returns nothing
    call AdjustPlayerStateBJ( d, GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD )
    call DisplayTextToForce( GetForceOfPlayer(GetEnumPlayer()), ( msg3 + I2S(d) ) )
endfunction

private function GroupActions takes nothing returns nothing
    set i = ForcePickRandomPlayer(f)
    call SetUnitOwner( GetEnumUnit(), i, true )
    call ForceRemovePlayer( f, i )
    call GroupRemoveUnit( b, GetEnumUnit() )
    set i = null
endfunction

private function Actions takes nothing returns nothing
    local integer loopy = 1
    call DisplayTextToForce(GetPlayersAll(), msg1)
    call DisplayTextToForce(GetPlayersAll(), msg2)
    set a = GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
    set b = GetUnitsOfPlayerAll(GetTriggerPlayer())
    set f = GetPlayersMatching(Condition(function GroupCond1))
    set c = CountPlayersInForceBJ(f)
    set d = ( a / c )
    set g = CountUnitsInGroup(b)
    set e = ( g / c )
    call SetPlayerState( GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, 0 )
    call ForForce( f, function ForceActions )
    loop
        exitwhen loopy &gt; c
        set h = GetRandomSubGroup(e, b)
        call ForGroup( h, function GroupActions )
        call DestroyGroup(h)
        set loopy = loopy + 1
    endloop
    call DestroyGroup(b)
    call DestroyForce(f)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerEvent( trig, Player(i), EVENT_PLAYER_LEAVE )
        set i = i + 1
    endloop
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


GUI Version:

Code:
Player Leaves GUI
    Events
    Conditions
    Actions
        Game - Display to (All players) the text: |c0000ccff[Game]|r|...
        Game - Display to (All players) the text: |c003366ff---Gold a...
        Set a = ((Triggering player) Current gold)
        Set b = (Units owned by (Triggering player))
        Set f = (All players matching ((((Matching player) is an ally of (Triggering player)) Equal to (==) True) and ((((Matching player) controller) Equal to (==) User) and (((Matching player) slot status) Equal to (==) Is playing))))
        Set c = (Number of players in f)
        Set d = (a / c)
        Set g = (Number of units in b)
        Set e = (g / c)
        Player - Set (Triggering player) Current gold to 0
        Player Group - Pick every player in f and do (Actions)
            Loop - Actions
                Player - Add d to (Picked player) Current gold
                Game - Display to (Player group((Picked player))) the text: (|c00ffcc00G|r|c00ffd00bo|r|c00ffd315l|r|c00ffd71fd|r|c00ffda29 |r|c00ffdd33R|r|c00ffe13ee|r|c00ffe448c|r|c00ffe852i|r|c00ffeb5ce|r|c00ffee66v|r|c00fff271e|r|c00fff57bd|r|c00fff985:|r|c00fffc8f |r + (String(d)))
         Do Multiple ActionsFor each (Integer A) from 1 to c, do (Actions)
            Loop - Actions
                Set h = (Random e units from b)
                Unit Group - Pick every unit in h and do (Actions)
                    Loop - Actions
                        Set i = (Random player from f)
                        Unit - Change ownership of (Picked unit) to i and Change color
                        Player Group - Remove i from f
                        Unit Group - Remove (Picked unit) from b
                        Custom script:   set udg_i = null
                Custom script:   call DestroyGroup(udg_h)
        Custom script:   call DestroyGroup(udg_b)
        Custom script:   call DestroyForce(udg_f)

Alright, now questions, comments, concernes, complaints, constructive criticism.

EDIT: Forgot... To use the GUI version, make the global triggers

integer - a
unit group - b
integer - c
integer - d
integer - e
player group - f
integer - g
unit group - h
player - i

UPDATE: Updated code.
UPDATE2: Fixed a bug.
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Change return GetBooleanAnd(lol1, lol2) to return lol1 and lol2 (If you want them to be true.)

This will make it more efficient.


Change "TRIGSTR_002" to the value it should contain since if you create a new map it won't contain that value.



Usa a local iterator instead of "bj_forLoopAIndex".



Try to simplify your loop so it doesn't dynamicly creates groups and destroys.
 

Flare

Stops copies me!
Reaction score
662
Your globals really could use renaming - they are fairly misguiding (generally, i would refer to an integer of some sort, not a player :p)

Code:
Trigger - Add to Player Leaves Jass <gen> the event (Player - (Picked player) leaves the game)
Can you explain where this Player Leaves Jass trigger is? It's certainly not in the JASS script

What exactly are msg1 and msg3 supposed to read (too many colour codes making them completely unreadable)
 

Tyman2007

Ya Rly >.
Reaction score
74
Eh... Player Leaves Jass is the name of the trigger.

msg1 = [Game]A player has left the game.
msg3 = Gold Recieved:

I haven't tested this... but umm.. if i need to add the events in the JASS trigger into the trigger itself and not using another trigger to do so then can you post the event thing for it?
 

Flare

Stops copies me!
Reaction score
662
Eh... Player Leaves Jass is the name of the trigger.
If you're talking about the JASS script, then no - the 'trigger' at the left side creates a variable entitled gg_trg_Insert_Name_Here, and you're not using that trigger (you're using a local trigger instead), so you can't add any events to gg_trg_Insert_Name_Here because (1) that trigger (the variable type trigger) hasn't been created and (2) it's not being used

can you post the event thing for it?
I don't know the player events :( Would be something along the lines of
JASS:
//In your init function
local integer i = 0
loop
exitwhen i == bj_PLAYER_MAX_SLOTS
  call TriggerRegisterPlayerEvent (trig, event, filterFunc)
//Check TESH for the exact event registration function/playerevent used
  set i = i + 1
endloop
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top