function PlayerNameToPlayer takes string name returns player
set name = StringCase(name,false)
if name == "red" then
return Player(0)
elseif name == "blue" then
return Player(1)
elseif name == "teal" then
return Player(2)
elseif name == "purple" then
return Player(3)
elseif name == "yellow" then
return Player(4)
elseif name == "orange" then
return Player(5)
elseif name == "green" then
return Player(6)
elseif name == "pink" then
return Player(7)
elseif name == "grey" or name == "gray" then
return Player(8)
elseif name == "light blue" or name == "lightblue" then
return Player(9)
elseif name == "dark green" or name == "darkgreen" then
return Player(10)
elseif name == "brown" then
return Player(11)
endif
return null
endfunction
function SplitString takes string to, string sp returns nothing
local integer i = 0
local integer l = StringLength(sp)
local integer e = StringLength(to)
local integer a = 0
set udg_MessagePartsLength = -1
loop
exitwhen i+l>e
if SubString(to,i,i+l) == sp then
set udg_MessagePartsLength = udg_MessagePartsLength + 1
set udg_MessageParts[udg_MessagePartsLength] = SubString(to,a,i)
set a = i+l
endif
set i = i + 1
endloop
if i<=e then
set udg_MessagePartsLength = udg_MessagePartsLength + 1
set udg_MessageParts[udg_MessagePartsLength] = SubString(to,a,i+1)
endif
endfunction
function GiveDigest takes player t, string in returns integer
local integer g
local player p
call SplitString(in," ")
if udg_MessagePartsLength < 3 or udg_MessagePartsLength > 4 or udg_MessageParts[1] != "gold" or udg_MessageParts[2] != "to" then
return 0
elseif udg_MessagePartsLength == 4 then
set udg_MessageParts[3] = udg_MessageParts[3] + udg_MessageParts[4]
endif
set g = S2I(udg_MessageParts[0])
if g < 0 then
set g = -g
endif
set p = PlayerNameToPlayer(udg_MessageParts[3])
if g > 0 and g <= GetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD) and p != null then
call SetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD)-g)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+g)
return g
endif
return 0
endfunction