library CSV2 initializer Init
/* Very effective and customizable system. It efficiently uses minimal string creations, other than those
repeated I.E. Colors, real names along with substrings to check for commands.
Map Config Needed: Make sure to set Advanced > Game Interface > first five fields (Chat fields) to exactly 240
spaces. Also you will need JNPG to compile this script.
Credits (Scripter) to:
khamarr3524: 95% of the work done, with critiquing from others listed below. 5% to Sean, R.I.P.
Credits (From thehiveworkshop.com) to:
TheMaker: For assisting me in portions of the script along with helping me understand initializers.
Troll - Brain: For assisting me in portions of the script and debugging along with initializers.
Magtheridon96: For supportive feedback and assisting me in portions of the script along with understaind initializers.
Dr Super Good: For helping me understand substring clauses and assisting me in portions of the script.
PurgeandFire111: For helping me understand substring clauses.
Credits (From friends) to:
Stygian_Shadow: For testing the script.
RoxasHikari: For testing the script.
Suppressed: For testing the script.
Kavudragon: For testing the script.
Aradicator: For testing the script.
Fluffysaur: For testing the script.
Sean: Helping with the script layout, dedication to him, may he rest in peace.
*/
globals
private string array cCol
private string array colName
string array custName
private integer array pCol
private real messTime
force playForce = CreateForce()
private boolean allies = false
private boolean all = false
private boolean priv = false
private boolean sCol = false
private boolean cName = false
public boolean privOn
public boolean allOn
public boolean allyOn
public boolean colOn
constant integer colorCount = 18
public boolean nameOn
constant string errorOn = "|c00ff3300You cannot use this function.|r"
private integer whoPrivate
private player sendPlayer = null
private string message = ""
endglobals
scope Start
function DoMapSetup 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
//Set this to a real integer for time to display messages. Negative values cause crashes.
set messTime = 10.
//Here you can specify what you want to be enabled. Setting True means it will be active. False will be inactive.
//By creating a trigger series or library, (probably will be made by me and posted), you can let the play in
//"host slot select these options on start of map ;). Otherwise you can just use set <variable> = true/false
set privOn = true
set allOn = true
set allyOn = true
set colOn = true
set nameOn = true
//-----------------------------------------------------------------
set cCol[0] = "|c00ff0000"
set cCol[1] = "|c000000ff"
set cCol[2] = "|c0000ffff"
set cCol[3] = "|c00660099"
set cCol[4] = "|c00ffff00"
set cCol[5] = "|c00ff9900"
set cCol[6] = "|c0033ff00"
set cCol[7] = "|c00ff00ff"
set cCol[8] = "|c00999999"
set cCol[9] = "|c009999ff"
set cCol[10] = "|c00006600"
set cCol[11] = "|c00330000"
set cCol[12] = "|c00000000"
set cCol[13] = "|c00990000"
set cCol[14] = "|c00999900"
set cCol[15] = "|cffffffff"
set cCol[16] = "|c00999999"
set cCol[17] = "|c0033ff00"
set cCol[18] = "|c00ff33ff"
//------------------------------------------------
//Add any colors here that you want. Remember if you add colors to change colorCount in the globals and add the
//wc3 color code to correspond to the index and name here in the cCols.
set colName[0] = "Red"
set colName[1] = "Blue"
set colName[2] = "Teal"
set colName[3] = "Purple"
set colName[4] = "Yellow"
set colName[5] = "Orange"
set colName[6] = "Lgreen"
set colName[7] = "Pink"
set colName[8] = "Gray"
set colName[9] = "Lblue"
set colName[10] = "Green"
set colName[11] = "Brown"
set colName[12] = "Black"
set colName[13] = "Maroon"
set colName[14] = "Gold"
set colName[15] = "White"
set colName[16] = "Silver"
set colName[17] = "Lime"
set colName[18] = "Fuchsia"
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
if allOn then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, messTime, (cCol[pNum] + "(All): " + custName[pNum] + ":|r " + cCol[pCol[pNum]] + message + "|r" ) )
set message = null
set sendPlayer = null
set p = null
set recP = null
return
endif
call DisplayTimedTextToPlayer(p, 0, 0, 10, errorOn)
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 )
if privOn then
if custName[whoPrivate] == null then
call DisplayTimedTextToPlayer(p, 0, 0, messTime, "That player isn't in the game.")
set message = null
set sendPlayer = null
set p = null
set recP = null
return
endif
call DisplayTimedTextToPlayer( recP, 0, 0, messTime, ( cCol[pNum] + "(Private): " + custName[pNum] + ":|r " + cCol[pCol[pNum]] + message + "|r") )
call DisplayTimedTextToPlayer(p, 0, 0, messTime, ( cCol[GetPlayerId(recP)] + "(Private): " + custName[GetPlayerId(recP)] + ":|r " + cCol[pCol[pNum]] + message + "|r" ) )
set message = null
set sendPlayer = null
set p = null
set recP = null
return
endif
call DisplayTimedTextToPlayer(p, 0, 0, messTime, errorOn)
set message = null
set sendPlayer = null
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
if allyOn then
loop
set recP = Player( i )
if IsPlayerInForce( recP, playForce ) and IsPlayerAlly( recP, p ) then
call DisplayTimedTextToPlayer( recP, 0, 0, messTime, ( cCol[pNum] + "(Allies): " + custName[pNum] + ":|r " + cCol[pCol[pNum]] + message + "|r" ) )
endif
set i = i + 1
exitwhen i > 11
endloop
set message = null
set sendPlayer = null
set p = null
set recP = null
return
endif
call DisplayTimedTextToPlayer(p, 0, 0, messTime, errorOn)
set message = null
set sendPlayer = null
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 nameOn then
if message == "" or message == " " or StringLength(message) > 15 then
call DisplayTimedTextToPlayer(p, 0, 0, messTime, "You must enter a valid name.")
set p = null
set message = null
set sendPlayer = null
return
endif
set custName[pNum] = message
call DisplayTimedTextToPlayer(p, 0, 0, messTime, "|c00ff3300Your name is now: " + custName[pNum] + "|r")
set message = null
set sendPlayer = null
set p = null
return
endif
call DisplayTimedTextToPlayer(p, 0, 0, messTime, errorOn)
set message = null
set sendPlayer = null
set p = null
endmethod
private static method color takes nothing returns nothing
local player p = sendPlayer
local integer pNum = GetPlayerId(p)
local integer i = 0
if colOn then
loop
if StringCase(message, false) == StringCase(colName[i], false) then
set pCol[pNum] = i
call DisplayTimedTextToPlayer(p, 0, 0, messTime, "|c00ff3300Your color is now:|r " + colName[i])
return
endif
set i = i + 1
exitwhen i > colorCount
endloop
call DisplayTimedTextToPlayer(p, 0, 0, messTime, "|c00ff3300Please type an available color.|r")
return
endif
call DisplayTimedTextToPlayer(p, 0, 0, messTime, errorOn)
set p = null
set message = null
set sendPlayer = null
endmethod
static method sendMessage takes nothing returns nothing
if allies then
call thistype.textAllies( )
set allies = false
elseif all then
call thistype.textAll( )
set all = false
elseif priv then
call thistype.textPrivate( )
set priv = false
elseif cName then
call thistype.name()
set cName = false
elseif sCol then
call thistype.color()
set sCol = false
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 priv = true
set whoPrivate = (S2I( SubString( origString, 4, 6 ) ) - 1 )
if whoPrivate < 0 or whoPrivate > 11 then
call DisplayTimedTextToPlayer( sendPlayer, 0, 0, messTime, "You must enter a digit 1-12.")
set priv = false
set origString = null
set codeString = null
return
endif
set message = SubString( origString, 6, end )
call Text.sendMessage( )
set origString = null
set codeString = null
return
endif
set isAlly = isAlly + 1
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( )
set origString = null
set codeString = null
return
else
set isAlly = isAlly + 1
endif
set codeString = SubString(origString, 0, 7)
if codeString == "-color " then
set sCol = true
set message = SubString(origString, 7, end)
call Text.sendMessage()
set origString = null
set codeString = null
return
elseif codeString == "-cname " then
set cName = true
set message = SubString(origString, 7, 18)
call Text.sendMessage()
set origString = null
set codeString = null
return
elseif 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 pCol[i] = 15 //if you want this to be changed to their color. Swap it with the next line.
//set pCol[i] = [i]
endif
set i = i + 1
exitwhen i > 11
endloop
call TriggerAddAction( t, function ConvertText )
set t = null
set p = null
endfunction
endlibrary
scope PlayerLeaves initializer init
private function Leaver takes nothing returns nothing
local player p = GetTriggerPlayer()
call ForceRemovePlayer(playForce, p)
set custName[GetPlayerId(p)] = null
call SetPlayerName(p, "Left the Game!")
set p = null
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_LEAVE)
set i = i + 1
exitwhen i > 11
endloop
call TriggerAddAction(t, function Leaver)
set t = null
endfunction
endscope