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:
vJass version:
GUI Version:
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.
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't use teams Don't use this. ////
//// -If your map doesn't have multiple units per person Don't use this. ////
//// -If you don't have newgen or a vJass processor use the GUI version. ////
//// -If there'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'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 = "|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"
//Message that states the gold and towers have been equally distributed.
private constant string msg2 = "|c003366ff---Gold and Towers have been distributed equally to leaving players team-members---|r"
//Message that says the gold you've recieved.
private constant string msg3 = "|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"
endglobals
///////////////////////////////////////////////////////////////////////
// If you edit below this line without knowing what you'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 > 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.