library CSV2 initializer Init
/* Very effective and customizable system. It efficiently uses minimal string creations, other than those
repeated I.E. Colors and real names.
*/
globals
string array color
string array colNum
string array custName
integer array pColor
force playForce = CreateForce()
boolean allies = false
boolean all = false
boolean private = false
boolean sColor = false
boolean cName = false
integer whoPrivate
player sendPlayer = null
string message = ""
endglobals
scope Start
function DoMapSetup takes nothing returns nothing
local integer i = 0
set color[0] = "|c00ff0000"
set color[1] = "|c000000ff"
set color[2] = "|c0000ffff"
set color[3] = "|c00660099"
set color[4] = "|c00ffff00"
set color[5] = "|c00ff6600"
set color[6] = "|c00ff00ff"
set color[8] = "|c0000ff00"
set color[9] = "|c00666666"
set color[10] = "|c009999ff"
set color[11] = "|c00336600"
set color[12] = "|c00000000"
set color[13] = "|c00990000"
set color[14] = "|c00999900"
set color[15] = "|cffffffff"
//------------------------------------------------
set colNum[0] = "Red"
set colNum[1] = "Blue"
set colNum[2] = "Teal"
set colNum[3] = "Purple"
set colNum[4] = "Yellow"
set colNum[5] = "Orange"
set colNum[6] = "Pink"
set colNum[7] = "Lgreen"
set colNum[8] = "Gray"
set colNum[9] = "Lblue"
set colNum[10] = "Green"
set colNum[11] = "Brown"
set colNum[12] = "Black"
set colNum[13] = "Maroon"
set colNum[14] = "Gold"
set colNum[15] = "White"
endfunction
struct Text extends array
private static method textAll takes nothing returns nothing
local player p = sendPlayer
local integer pNum = GetPlayerId( p )
local integer i = 0
local player recP
loop
set recP = Player( i )
if IsPlayerInForce( recP, playForce ) == true then
call DisplayTimedTextToPlayer(recP, 0, 0, 8.5, (color[pNum] + "(All): " + custName[pNum] + ":|r " + color[pColor[pNum]] + message + "|r" ) )
endif
set i = i + 1
exitwhen i > 11
endloop
set p = null
set recP = null
endmethod
private static method textPrivate takes nothing returns nothing
local player p = sendPlayer
local integer pNum = GetPlayerId( p )
local player recP = Player( whoPrivate )
call DisplayTimedTextToPlayer( recP, 0, 0, 8.5, ( color[pNum] + "(Private): " + custName[pNum] + ":|r " + color[pColor[pNum]] + message + "|r" ) )
call DisplayTimedTextToPlayer(p, 0, 0, 8.5, ( color[GetPlayerId(recP)] + "(Private): |r" + color[pNum] + custName[pNum] + ":|r " + message + "|r" ) )
set p = null
set recP = null
endmethod
private static method textAllies takes nothing returns nothing
local player p = sendPlayer
local integer pNum = GetPlayerId( p )
local integer i = 0
local player recP
loop
set recP = Player( i )
if IsPlayerInForce( recP, playForce ) == true and IsPlayerAlly( recP, p ) == true then
//call DisplayTimedTextToPlayer( recP, 0, 0, 8.5, ( color[pNum] + "(Allies): " + GetPlayerName( recP ) + ":|r " + color[pColor[pNum]] + message + "|r" ) )
endif
set i = i + 1
exitwhen i > 11
endloop
set p = null
set recP = null
endmethod
private static method name takes nothing returns nothing
local player p = sendPlayer
local integer pNum = GetPlayerId(p)
if message == "" or message == " " then
call DisplayTimedTextToPlayer(p, 0, 0, 8.5, "You must enter a valid name.")
set p = null
return
endif
set custName[pNum] = message
set p = null
endmethod
private static method color takes nothing returns nothing
endmethod
static method sendMessage takes nothing returns nothing
if allies == true then
call thistype.textAllies( )
set allies = false
return
endif
if all == true then
call thistype.textAll( )
set all = false
return
endif
if private == true then
call thistype.textPrivate( )
set private = false
return
endif
if cName == true then
call thistype.name()
set cName = false
return
endif
if sColor == true then
call thistype.color()
set sColor = false
return
endif
endmethod
endstruct
endscope
private function ConvertText takes nothing returns nothing
local string origString = GetEventPlayerChatString( )
local string codeString = SubString( origString, 0, 4 )
local integer end = StringLength( origString )
local integer isAlly = 0
set sendPlayer = GetTriggerPlayer( )
if codeString == "-pm " then
set private = true
set whoPrivate = (S2I( SubString( origString, 4, 6 ) ) -1 )
if whoPrivate !=0 and whoPrivate != 1 and whoPrivate != 2 and whoPrivate != 3 and whoPrivate != 4 and whoPrivate != 5 and whoPrivate != 6 and whoPrivate != 7 and whoPrivate != 8 and whoPrivate != 9 and whoPrivate != 10 and whoPrivate != 11 then
call DisplayTimedTextToPlayer( sendPlayer, 0,0,8.5, "You must enter a digit 1-12.")
set private = false
return
endif
set message = SubString( origString, 6, end )
call Text.sendMessage( )
return
else
set isAlly = isAlly + 1
endif
if codeString == "-all" then
set all = true
set message = SubString ( origString, 4, end )
if SubString(message, 0,1) == " " then
set message = SubString(message, 1, StringLength(message))
endif
call Text.sendMessage( )
return
else
set isAlly = isAlly + 1
endif
set codeString = SubString(origString, 0, 6)
if codeString == "-color " then
set sColor = true
set message = SubString(origString, 6, 12)
call Text.sendMessage()
return
endif
if codeString == "-cname " then
set cName = true
set message = SubString(origString, 6, 18)
call Text.sendMessage()
return
endif
if isAlly == 2 then
set allies = true
endif
set message = SubString( origString, 0, end )
call Text.sendMessage( )
set origString = null
set codeString = null
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
local integer i = 0
local player p
call DoMapSetup()
loop
if GetPlayerSlotState( Player( i ) ) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController( Player( i ) ) == MAP_CONTROL_USER then
call TriggerRegisterPlayerChatEvent( t, Player(i), "", false)
set pColor[i] = 15
endif
set i = i + 1
exitwhen i > 11
endloop
call TriggerAddAction( t, function ConvertText )
set t = null
endfunction
endlibrary
scope FormForce initializer init
private function FormForce takes nothing returns nothing
local integer i = 0
local player p
loop
set p = Player(i)
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
call ForceAddPlayer(playForce, p)
set custName[i] = GetPlayerName(p)
endif
set i = i + 1
exitwhen i > 11
endloop
set p = null
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, .5, false)
call TriggerAddAction(t, function FormForce)
set t = null
endfunction
endscope