Romek
Super Moderator
- Reaction score
- 963
No Leavers
By Romek
By Romek
Introduction
I'm sure nearly everyone here has been in a game which has been completely ruined by some idiot leaving for no reason, and 9 players following him...
This was actually inspired by people leaving!
Well, now there's a solution. "No Leavers" stops players leaving by nearly any means possible, reducing the chances of people not being able to play your map because of leavers.
Pros:
- Stops players leaving in nearly every possible way.
- If the player does leave, they'll most likely have to close wc3.
Cons:
- Disables the Quest and Log menus.
- A Player can still leave if they have a way of pressing keys quickly (Such as a Gamers Keyboard with Macro Buttons) or by using CTRL + ALT + DEL.
The Code:
JASS:
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-= No Leavers Function by Romek V1.5 =-=-=-
// +-----------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-----------------------------+
// | >> REQUIRES A vJASS PREPROCESSER << |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= How to Use: =-=- |
// | - Create a new trigger or copy the Snippet into the map header |
// | - Change the Global REFRESH_TIME to whatever you want. 0.025 recommended =] |
// | - Change the function "Exceptions" to whatever you need (If GetFilterPlayer() == true, then |
// | that player won't get effected) |
// | - The system can be Turned on/off by Enabling and Disabling the trigger "NoLeavers_T" |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= How to Edit the Exceptions Function: =-=- |
// | - Remove "False" |
// | - Add a player related condition such as: "GetPlayerName(GetFilterPlayer()) == Romek" |
// | - GetFilterPlayer() is the Player the condition applies to. Don't change it. |
// | - In this case, It won't effect a player named "Romek" |
// | - To add multiple conditions, add "or" between the conditions. |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= PROS: =-=- |
// | - Stops any player leaving using nearly any method |
// | - Even if they do leave, They'll have to close Wc3 |
// | |
// | -=-= CONS: =-=- |
// | - Disables the Quests and Log menus |
// | - Players can leave using CTRL + ALT + DELETE or if they have a method of pressing keys |
// | extremely quickly (Such as a Gamers Keyboard with Macro Keys) |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= Changelog: =-=- |
// | - As this didn't work on the > majority < of games, it can now be used as a 'punishment' by |
// | setting the "PUNISH" variable to true. The ADMIN_PLAYER will then be able to use NL_PREFIX |
// | on/off to own a player =] |
// +-----------------------------------------------------------------------------------------------------+
// | Credit isn't needed if used. |
// +-----------------------------------------------------------------------------------------------------+
scope NoLeave initializer Init
globals
private constant real REFRESH_TIME = 0.025 // Edit here to set the Refresh time. Higher = MoreLag + Less Chances of Leaving
private constant boolean PUNISH = true // Set to true to make this a punishment.
private constant player ADMIN_PLAYER = Player(0) // This is the player which can use the "-noleave" commands
private constant string NL_PREFIX_ON = "punish" // This is the command ADMIN_PLAYER uses to stop a player leaving
private constant string NL_PREFIX_OFF = "unpunish" // This is the command ADMIN_PLAYER uses to let a player leave again
// Use NL_PREFIX_## 1 to Punish player 1 (red)
endglobals
private function Exceptions takes nothing returns boolean // The Exceptions
return false
endfunction
// +-----------------------------------------------------------------------------------------------------+ \\
// | >>> DO NOT EDIT BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING! <<< | \\ |
// +-----------------------------------------------------------------------------------------------------+ \\
globals
private boolexpr BOOL
private force NoLeavers = CreateForce()
public trigger T = CreateTrigger()
endglobals
private function Refresh takes nothing returns nothing
if IsPlayerInForce(GetLocalPlayer(), NoLeavers) then
call ForceUICancel()
endif
endfunction
private function CheckString takes string s returns boolean
if S2I(s)/S2I(s) != 1 then
return false
endif
return true
endfunction
private function PunishedOn takes nothing returns nothing
local integer l = StringLength(GetEventPlayerChatString())
local integer le = StringLength(NL_PREFIX_ON) + 1
local integer i
if CheckString(SubString(GetEventPlayerChatString(), le , l)) == true then
set i = S2I(SubString(GetEventPlayerChatString(), le , l)) - 1
else
return
endif
debug call BJDebugMsg("Punish")
debug call BJDebugMsg(I2S(i))
if IsPlayerInForce(Player(i), NoLeavers) == false and Player(i) != ADMIN_PLAYER then
call ForceAddPlayer(NoLeavers, Player(i))
endif
endfunction
private function PunishedOff takes nothing returns nothing
local integer l = StringLength(GetEventPlayerChatString())
local integer le = StringLength(NL_PREFIX_OFF) + 1
local integer i
if CheckString(SubString(GetEventPlayerChatString(), le , l)) == true then
set i = S2I(SubString(GetEventPlayerChatString(), le , l)) - 1
else
return
endif
if IsPlayerInForce(Player(i), NoLeavers) and Player(i) != ADMIN_PLAYER then
call ForceRemovePlayer(NoLeavers, Player(i))
endif
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t2 = CreateTrigger()
set BOOL = Filter(function Exceptions)
set BOOL = Not(BOOL)
call TriggerRegisterTimerEvent(T, REFRESH_TIME, true)
call TriggerAddAction(T, function Refresh)
if PUNISH == false then
call ForceEnumPlayers(NoLeavers, BOOL)
call DestroyBoolExpr(BOOL)
call DestroyTrigger(t)
set t = null
call DestroyTrigger(t2)
set t2 = null
else
call TriggerRegisterPlayerChatEvent(t, ADMIN_PLAYER, NL_PREFIX_ON, false)
call TriggerAddAction(t, function PunishedOn)
call TriggerRegisterPlayerChatEvent(t2, ADMIN_PLAYER, NL_PREFIX_OFF, false)
call TriggerAddAction(t2, function PunishedOff)
endif
endfunction
endscope
The Old Code:
JASS:
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-= No Leavers Function by Romek V1.0 =-=-=-
// +-----------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-----------------------------+
// | >> REQUIRES A vJASS PREPROCESSER << |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= How to Use: =-=- |
// | - Create a new trigger or copy the Snippet into the map header |
// | - Change the Global REFRESH_TIME to whatever you want. 0.025 recommended =] |
// | - Change the function "Exceptions" to whatever you need (If GetFilterPlayer() == true, then |
// | that player won't get effected) |
// | - The system can be Turned on/off by Enabling and Disabling the trigger "NoLeavers_T" |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= How to Edit the Exceptions Function: =-=- |
// | - Remove "False" |
// | - Add a player related condition such as: "GetPlayerName(GetFilterPlayer()) == Romek" |
// | - GetFilterPlayer() is the Player the condition applies to. Don't change it. |
// | - In this case, It won't effect a player named "Romek" |
// | - To add multiple conditions, add "or" between the conditions. |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= PROS: =-=- |
// | - Stops any player leaving using nearly any method |
// | - Even if they do leave, They'll have to close Wc3 |
// | |
// | -=-= CONS: =-=- |
// | - Disables the Quests and Log menus |
// | - Players can leave using CTRL + ALT + DELETE or if they have a method of pressing keys |
// | extremely quickly (Such as a Gamers Keyboard with Macro Keys) |
// +-----------------------------------------------------------------------------------------------------+
// | Credit isn't needed if used. |
// +-----------------------------------------------------------------------------------------------------+
scope NoLeave initializer Init
globals
private constant real REFRESH_TIME = 0.025 // Edit here to set the Refresh time. Higher = MoreLag + Less Chances of Leaving
endglobals
private function Exceptions takes nothing returns boolean // The Exceptions
return false
endfunction
// +-----------------------------------------------------------------------------------------------------+ \\
// | >>> DO NOT EDIT BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING! <<< | \\ |
// +-----------------------------------------------------------------------------------------------------+ \\
globals
private boolexpr BOOL
private force NoLeavers = CreateForce()
public trigger T = CreateTrigger()
endglobals
private function Refresh takes nothing returns nothing
if IsPlayerInForce(GetLocalPlayer(), NoLeavers) then
call ForceUICancel()
endif
endfunction
private function Init takes nothing returns nothing
local boolexpr B
set BOOL = Filter(function Exceptions)
set B = Not(BOOL)
call ForceEnumPlayers(NoLeavers, B)
call TriggerRegisterTimerEvent(T, REFRESH_TIME, true)
call TriggerAddAction(T, function Refresh)
call DestroyBoolExpr(BOOL)
call DestroyBoolExpr(B)
set B = null
endfunction
endscope
The Map:
Do you really need a map? It's so small and easy to import!