Komaqtion
You can change this now in User CP.
- Reaction score
- 469
Hi!
I was just wondering a couple of things about swap systems...
First, is there any out there ? :S
Second, I've already made one here actually, but it's a bit messy atm and I'm not sure if I've got everything it should have :S
Could you take a look ?
So, this will basicall list all heroes and the owning players by typing:
"-swap"
And when you then want to swap, you'll type:
"-swap X" (X - Is the number of the player you want to swap with (GUI range, from 1 - 12))
And then you have to wait for him to accept by typing "-swap yourplayernumber"...
Anything I've missed here ? :S
Third, Will this be useful ? :S
(I'd think so, as I made this by *request from this thread:
http://www.thehelper.net/forums/showthread.php?t=140752)
* By "request", I mean that I saw that he needed it, so I tried to make it XD
Fourth, Have I done it "The right way" ? XD
I mean, I haven't done this from a very wierd approach or concept, right ? :S
Here's a Demo Map, and the system is under the category "Own Systems" and is called "Swap" (Oddly enough )
I was just wondering a couple of things about swap systems...
First, is there any out there ? :S
Second, I've already made one here actually, but it's a bit messy atm and I'm not sure if I've got everything it should have :S
Could you take a look ?
JASS:
library SwapHero initializer Init requires PlayerColors, TimerUtils
globals
private constant boolean TIME_LIMIT_ENABLED = true
private constant real TIME_LIMIT = 30.0
private constant boolean ONE_SWAP_ONLY = true
private constant boolean CHANGE_POS = true
private force f = CreateForce()
private group g = CreateGroup()
private boolean array swapped
endglobals
private struct Heroes
player target
player self
unit own
timer t
private static method TimeStop takes nothing returns nothing
local thistype this = GetTimerData( GetExpiredTimer() )
call DisplayTextToPlayer( this.self, 0.0, 0.0, "You039;ve not recieved any answer from the swapping request, and it has therefore been removed !" )
if swapped[GetPlayerId( this.self )] == true then
call this.destroy()
else
set this.target = null
set this.self = null
set this.own = null
endif
endmethod
static method create takes player target, player self, real time returns thistype
local thistype this = thistype.allocate()
local unit u
set this.target = target
set this.self = self
call GroupEnumUnitsOfPlayer( g, self, null )
loop
set u = FirstOfGroup( g )
exitwhen u == null or IsUnitType( u, UNIT_TYPE_HERO ) == true
endloop
set this.own = u
if TIME_LIMIT_ENABLED then
set this.t = NewTimer()
call SetTimerData( this.t, this )
call TimerStart( this.t, TIME_LIMIT, false, function thistype.TimeStop )
endif
return this
endmethod
private method onDestroy takes nothing returns nothing
set swapped[GetPlayerId( this.self )] = true
endmethod
endstruct
globals
private player triggerer
private Heroes array Data
endglobals
private function EnumHeroes takes nothing returns boolean
local unit u = GetEnumUnit()
local player p = GetOwningPlayer( u )
if IsUnitType( u, UNIT_TYPE_HERO ) == true and p != triggerer then
call DisplayTextToPlayer( triggerer, 0.0, 0.0, PlayerColoredString( GetPlayerId( p ), GetUnitName( u ) ) + " : " + PlayerColoredString( GetPlayerId( p ), GetPlayerName( p ) ) )
endif
return false
endfunction
private function HeroDisplay takes nothing returns nothing
local player p = GetEnumPlayer()
call GroupEnumUnitsOfPlayer( g, p, null )
call ForGroup( g, function EnumHeroes )
endfunction
private function SwapList takes nothing returns boolean
set triggerer = GetTriggerPlayer()
call ForceEnumPlayers( f, null )
call ForForce( f, function HeroDisplay )
return false
endfunction
private function SwapHero takes nothing returns boolean
local string s = GetEventPlayerChatString()
local string s2 = SubString( s, 6, 8 )
local integer i = S2I( s2 ) - 1
local integer i2 = 0
local integer i3 = 1
local player targ = Player( i )
local player self = GetTriggerPlayer()
local integer tid = GetPlayerId( targ )
local integer sid = GetPlayerId( self )
local real x
local real y
local real x2
local real y2
local unit temp
if SubString( s, 8, 9 ) == " " or SubString( s, 8, 9 ) == "" then
set s2 = SubString( s, 6, 7 )
set i = S2I( s2 ) - 1
endif
if self != targ and self != null and targ != null then
if Heroes ( Data[sid] ).target != Heroes ( Data[tid] ).self and Heroes ( Data[sid] ).self != Heroes ( Data[tid] ).target and ( swapped[sid]!= true or swapped[tid]!= true ) then
call DisplayTextToPlayer( self, 0.0, 0.0, "You039;ve asked " + PlayerColoredString( tid, GetPlayerName( targ ) ) + " to swap heroes with you..." + "\n" + "Now you039;ll have to wait for him to accept !" )
call DisplayTextToPlayer( targ, 0.0, 0.0, PlayerColoredString( sid, GetPlayerName( self ) ) + " wants to swap heroes with you." + "\n" + "Do you accept ?")
elseif Heroes ( Data[sid] ).target == Heroes ( Data[tid] ).self and Heroes ( Data[sid] ).self == Heroes ( Data[tid] ).target then
call DisplayTextToPlayer( self, 0.0, 0.0, "You039;ve accepted " + PlayerColoredString( tid, GetPlayerName( targ ) ) + "039;s request to swap heroes with you !" + "\n" + "You039;ll now recieve the new hero !" )
call DisplayTextToPlayer( targ, 0.0, 0.0, PlayerColoredString( sid, GetPlayerName( self ) ) + " has accepted your offer to swap heroes..." + "\n" + "You039;ll now recieve the new hero !")
elseif swapped[sid] == true then
call DisplayTextToPlayer( self, 0.0, 0.0, "You039;ve already swapped a hero before, and cannot do so twice !" )
elseif swapped[tid] == true then
call DisplayTextToPlayer( targ, 0.0, 0.0, "The player you wish to swap heroes with has already swapped before, and cannot do so twice ! Please choose another player to swap with..." )
endif
if swapped[sid] != true then
if TIME_LIMIT_ENABLED then
if Data[sid] == 0 then
set Data[sid] = Heroes.create( targ, self, TIME_LIMIT )
else
set Heroes ( Data[sid] ).target = targ
set Heroes ( Data[sid] ).self = self
endif
else
if Data[sid] == 0 then
set Data[sid] = Heroes.create( targ, self, 0.0 )
else
set Heroes ( Data[sid] ).target = targ
set Heroes ( Data[sid] ).self = self
endif
endif
endif
endif
loop
if Heroes( Data[i2] ).self == targ and Heroes( Data[sid] ).target == targ and Heroes ( Data[i2] ).target == self and Heroes( Data[sid] ).self == self then
loop
set x = GetUnitX( Heroes( Data[i2] ).own )
set y = GetUnitY( Heroes( Data[i2] ).own )
call UnitDropItemPoint( Heroes( Data[i2] ).own, UnitItemInSlot( Heroes( Data[i2] ).own, i3 ), x, y )
set x = GetUnitX( Heroes( Data[sid] ).own )
set y = GetUnitY( Heroes( Data[sid] ).own )
call UnitDropItemPoint( Heroes( Data[sid] ).own, UnitItemInSlot( Heroes( Data[sid] ).own, i3 ), x, y )
set i3 = i3 + 1
exitwhen i3 > 6
endloop
if CHANGE_POS == true then
set x = GetUnitX( Heroes( Data[i2] ).own )
set y = GetUnitY( Heroes( Data[i2] ).own )
set x2 = GetUnitX( Heroes( Data[sid] ).own )
set y2 = GetUnitY( Heroes( Data[sid] ).own )
call SetUnitX( Heroes( Data[sid] ).own, x )
call SetUnitY( Heroes( Data[sid] ).own, y )
call SetUnitX( Heroes( Data[i2] ).own, x2 )
call SetUnitY( Heroes( Data[i2] ).own, y2 )
endif
call SetUnitOwner( Heroes( Data[i2].own ), self, true )
call SetUnitOwner( Heroes( Data[sid].own ),targ, true )
set temp = Heroes( Data[sid] ).own
set Heroes ( Data[sid] ).target = null
set Heroes ( Data[sid] ).self = null
set Heroes ( Data[sid] ).own = Heroes ( Data[i2] ).own
set Heroes ( Data[i2] ).target = null
set Heroes ( Data[i2] ).self = null
set Heroes ( Data[i2] ).own = temp
set temp = null
if ONE_SWAP_ONLY == true then
call Heroes( Data[sid] ).destroy()
call Heroes( Data[i2] ).destroy()
endif
endif
set i2 = i2 + 1
exitwhen i2 > 11
endloop
return false
endfunction
static if DEBUG_MODE then
function sets takes nothing returns nothing
set Data[1] = Heroes.create( Player( 0 ), Player( 1 ), 0.0 )
endfunction
endif
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerChatEvent( t, Player( i ), "-swap", true )
set i = i + 1
exitwhen i > 11
endloop
call TriggerAddCondition( t, Condition( function SwapList ) )
set t = CreateTrigger()
set i = 0
loop
call TriggerRegisterPlayerChatEvent( t, Player( i ), "-swap ", false )
set i = i + 1
exitwhen i > 11
endloop
call TriggerAddCondition( t, Condition( function SwapHero ) )
static if DEBUG_MODE then
set t = CreateTrigger()
call TriggerRegisterTimerEvent( t, 0.01, false )
call TriggerAddAction( t, function sets )
endif
endfunction
endlibrary
So, this will basicall list all heroes and the owning players by typing:
"-swap"
And when you then want to swap, you'll type:
"-swap X" (X - Is the number of the player you want to swap with (GUI range, from 1 - 12))
And then you have to wait for him to accept by typing "-swap yourplayernumber"...
Anything I've missed here ? :S
Third, Will this be useful ? :S
(I'd think so, as I made this by *request from this thread:
http://www.thehelper.net/forums/showthread.php?t=140752)
* By "request", I mean that I saw that he needed it, so I tried to make it XD
Fourth, Have I done it "The right way" ? XD
I mean, I haven't done this from a very wierd approach or concept, right ? :S
Here's a Demo Map, and the system is under the category "Own Systems" and is called "Swap" (Oddly enough )