function Trig_Simple_Load_Conditions takes nothing returns boolean
return StringLength(GetEventPlayerChatString()) > 6
endfunction
function Trig_Simple_Load_Actions takes nothing returns nothing
local player p = GetTriggerPlayer()
local string CODE = SubString(GetEventPlayerChatString(), 6, 0)
local string CODEID = SubString(CODE, 0, 1)
local integer CODELEN = StringLength(CODE)
local integer MAX = StringLength(CodeType(CODEID))
local string C_CODE
local integer CLASS
local integer H_LEN
local integer CODELEN1
local string H
local integer DATA_AMOUNT_IN_H = 7 //H = holder number (ex: 12112010), where every digit show how long the following 8 stat:LEVEL, EXP, STR, AGI, INT, GOLD, LUMBER
local integer ERROR = 0
local integer i
local integer array CLASSTYPE
local integer MAXCLASS = 16
local real X
local real Y
local unit u
local integer LEVEL
local integer EXP
local integer STR
local integer AGI
local integer INT
local integer GOLD
local integer LUMBER
local integer H_LEVEL
local integer H_EXP
local integer H_STR
local integer H_AGI
local integer H_INT
local integer H_GOLD
local integer H_LUMBER
local string C_H
if MAX > 10 then
if CODELEN < 6 then
set ERROR = 1
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Warning:|r invalid loading code." )
else
set C_CODE = SubString(CODE, 2, 0)
set CLASS = StoI (SubString(CODE, 1, 2), CODEID)
set H_LEN = StoI (SubString(CODE, 2, 3), CODEID)
set CODELEN1 = StoI(SubString(CODE, CODELEN - 2, 0), CODEID)
if CODELEN != CODELEN1 or CLASS < 0 or CLASS > MAXCLASS then
set ERROR = 2
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Warning:|r invalid loading code." )
else
set C_H = SubString(CODE, 3, 3+H_LEN)
set H = I2S(StoI(C_H, CODEID))
if StringLength(H) < DATA_AMOUNT_IN_H then
set ERROR = 1
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Warning:|r invalid loading code.")
else
set H_LEVEL = S2I(SubString(H, 0, 1))
set H_EXP = S2I(SubString(H, 1, 2))
set H_STR = S2I(SubString(H, 2, 3))
set H_AGI = S2I(SubString(H, 3, 4))
set H_INT = S2I(SubString(H, 4, 5))
set H_GOLD = S2I(SubString(H, 5, 6))
set H_LUMBER = S2I(SubString(H, 6, 7))
set EXP = 0 //0 values needed for avoid null variable bugs
set STR = 0 //0 values needed for avoid null variable bugs
set AGI = 0 //0 values needed for avoid null variable bugs
set INT = 0 //0 values needed for avoid null variable bugs
set GOLD = 0
set LUMBER = 0
if H_LEVEL < 1 or H_STR < 1 or H_AGI < 1 or H_INT < 1 then
set ERROR = 1
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Warning:|r invalid loading code.")
else
set i = H_LEN + 3
set LEVEL = StoI(SubString(CODE, i, i + H_LEVEL), CODEID)
set i = i + H_LEVEL
if H_EXP > 0 then
set EXP = StoI(SubString(CODE, i, i + H_EXP), CODEID)
set i = i + H_EXP
endif
if H_STR > 0 then
set STR = StoI(SubString(CODE, i, i + H_STR), CODEID)
set i = i + H_STR
endif
if H_AGI > 0 then
set AGI = StoI(SubString(CODE, i, i + H_AGI), CODEID)
set i = i + H_AGI
endif
if H_INT > 0 then
set INT = StoI(SubString(CODE, i, i + H_INT), CODEID)
set i = i + H_INT
endif
if H_GOLD > 0 then
set GOLD = StoI(SubString(CODE, i, i + H_GOLD), CODEID)
set i = i + H_GOLD
endif
if H_LUMBER > 0 then
set LUMBER = StoI(SubString(CODE, i, i + H_LUMBER), CODEID)
set i = i + H_LUMBER
endif
// call DisplayTextToPlayer ( p, 0, 0,"LeveL"+I2S(LEVEL)+"exp"+I2S(EXP)+"str"+I2S(STR)+"agi"+I2S(AGI)+"int"+I2S(INT)+"gold"+I2S(GOLD)+"Lumber"+I2S(LUMBER))
//declare the heroes rawcode to the CLASSTYPE
set CLASSTYPE[1] = 'Hpal' //human paladin
set CLASSTYPE[2] = 'Hamg' //human archmage
set CLASSTYPE[3] = 'Hmkg' //human mountain king
set CLASSTYPE[4] = 'Hblm' //human blood mage
set CLASSTYPE[5] = 'Obla' //orc blademaster
set CLASSTYPE[6] = 'Ofar' //orc far seer
set CLASSTYPE[7] = 'Otch' //orc tauron chieftain
set CLASSTYPE[8] = 'Oshd' //orc shadow hunter
set CLASSTYPE[9] = 'Udea' //undead death kinght
set CLASSTYPE[10] = 'Ulch' //undead lich king
set CLASSTYPE[11] = 'Udre' //undead dread knight
set CLASSTYPE[12] = 'Ucrl' //undead crypt lord
set CLASSTYPE[13] = 'Ekee' //nightelf keeper of grove
set CLASSTYPE[14] = 'Emoo' //nightelf moon priestess
set CLASSTYPE[15] = 'Edem' //nightelf demon hunter
set CLASSTYPE[16] = 'Ewar' //nightelf warden
set X = GetCameraEyePositionX()
set Y = GetCameraEyePositionY()
set u = CreateUnit( p, CLASSTYPE[CLASS], X, Y, 0)
call SetHeroLevel(u, LEVEL, false)
call SetHeroXP (u, EXP, false)
call SetHeroStr (u, STR, true)
call SetHeroAgi (u, AGI, true)
call SetHeroInt (u, INT, true)
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GOLD)
call SetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER, LUMBER)
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Load:|r "+GetUnitName(u)+" loaded." )
if GetLocalPlayer() == p then
call ClearSelection()
call SelectUnit(u, true)
call PanCameraTo(X, Y)
endif
set u = null
endif
endif
endif
endif
else
call DisplayTextToPlayer ( p, 0, 0, "|cffffff00Warning:|r invalid loading code." )
endif
set p = null
endfunction
//===========================================================================
function InitTrig_Simple_Load takes nothing returns nothing
set gg_trg_Simple_Load = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_Simple_Load, Player(0), "-Load", false )
call TriggerAddCondition( gg_trg_Simple_Load, Condition( function Trig_Simple_Load_Conditions ) )
call TriggerAddAction( gg_trg_Simple_Load, function Trig_Simple_Load_Actions )
endfunction