library CharacterSys initializer Init requires SimError
globals
//Constants
private constant integer NEXT_CHOICE = 'A00B'
private constant integer PRE_CHOICE = 'A00C'
private constant integer NEXT_ATT = 'A009'
private constant integer PRE_ATT = 'A008'
private constant integer SKIN_CHANGE = 'A001'
private constant string INT_COLOR = "|cffd8da81"
private constant string END = "|r"
private constant real MAX = 125.0
private constant real MIN = 70.0
private constant integer STRING_MAX = 16
private constant integer STRING_MIN = 3
private string array NOTALLOWED[50]
private constant integer NA = 38
private constant integer MAXATT = 6
private constant string ARROW = "=>"
private constant real formula = 187.5/126
private boolean array Done[10]
private dialog array Creation[10]
private button array New[10]
private button array Load[10]
private rect array Stage[10]
private camerasetup array Camera[10]
private unit array Display[10]
private hashtable Options = InitHashtable()
private hashtable OStrings = InitHashtable()
private integer array MaxChoice[5]
private trigger d = CreateTrigger()
private dialog array CDialog[10]
private button array CNew[10]
private button array CLoad[10]
private string array Alert[10]
endglobals
private function InitVars takes nothing returns nothing
//Symbols
set NOTALLOWED[1] = "1"
set NOTALLOWED[2] = "2"
set NOTALLOWED[3] = "3"
set NOTALLOWED[4] = "4"
set NOTALLOWED[5] = "5"
set NOTALLOWED[6] = "6"
set NOTALLOWED[7] = "7"
set NOTALLOWED[8] = "8"
set NOTALLOWED[9] = "9"
set NOTALLOWED[10] = "0"
set NOTALLOWED[11] = "!"
set NOTALLOWED[12] = "@"
set NOTALLOWED[13] = "#"
set NOTALLOWED[14] = "$"
set NOTALLOWED[15] = "%"
set NOTALLOWED[16] = "^"
set NOTALLOWED[17] = "&"
set NOTALLOWED[18] = "*"
set NOTALLOWED[19] = "("
set NOTALLOWED[20] = ")"
set NOTALLOWED[21] = "-"
set NOTALLOWED[22] = "_"
set NOTALLOWED[23] = "+"
set NOTALLOWED[24] = "="
set NOTALLOWED[25] = "~"
set NOTALLOWED[26] = "`"
set NOTALLOWED[27] = "["
set NOTALLOWED[28] = "]"
set NOTALLOWED[29] = "{"
set NOTALLOWED[30] = "}"
set NOTALLOWED[31] = ">"
set NOTALLOWED[32] = "<"
set NOTALLOWED[33] = ","
set NOTALLOWED[34] = ":"
set NOTALLOWED[35] = ";"
set NOTALLOWED[36] = "?"
set NOTALLOWED[37] = "."
set NOTALLOWED[38] = "'"
set Alert[1] = "Symbols and Numbers are not allowed! Name Denied."
set Alert[2] = "Name can not exceed " + I2S(STRING_MAX) + " characters! Name Denied."
set Alert[3] = "Name can not be less than " + I2S(STRING_MIN) + " characters! Name Denied."
set Alert[4] = "Name Accepted!"
set Stage[0] = gg_rct_Player_1
set Camera[0] = gg_cam_Player_1
set Stage[1] = gg_rct_Player_1
set Camera[1] = gg_cam_Player_1
//Hair Color
call SaveInteger(Options, 1, 1, 'B002') //Black
call SaveStringBJ("Black", 1, 1, OStrings)
call SaveInteger(Options, 1, 2, 'B00D') //Blonde
call SaveStringBJ("Blonde", 1, 2, OStrings)
call SaveInteger(Options, 1, 3, 'B00B') //Blue
call SaveStringBJ("Blue", 1, 3, OStrings)
call SaveInteger(Options, 1, 4, 'B000') //Brown
call SaveStringBJ("Brown", 1, 4, OStrings)
call SaveInteger(Options, 1, 5, 'B004') //Gray
call SaveStringBJ("Gray", 1, 5, OStrings)
call SaveInteger(Options, 1, 6, 'B009') //Green
call SaveStringBJ("Green", 1, 6, OStrings)
call SaveInteger(Options, 1, 7, 'B006') //Red
call SaveStringBJ("Red", 1, 7, OStrings)
set MaxChoice[1] = 7
//Skin Color
call SaveInteger(Options, 2, 1, 'B001') //Black
call SaveInteger(Options, 2, 2, 'B00C') //Blonde
call SaveInteger(Options, 2, 3, 'B00A') //Blue
call SaveInteger(Options, 2, 4, 'B007') //Brown
call SaveInteger(Options, 2, 5, 'B003') //Gray
call SaveInteger(Options, 2, 6, 'B008') //Green
call SaveInteger(Options, 2, 7, 'B005') //Red
//Beards
//5 is missing because that is the "no beard"
call SaveInteger(Options, 3, 1, 'A005') //Walrus
call SaveStringBJ("Walrus", 3, 1, OStrings)
call SaveInteger(Options, 3, 2, 'A000') //Full
call SaveStringBJ("Full", 3, 2, OStrings)
call SaveInteger(Options, 3, 3, 'A003') //Half
call SaveStringBJ("Half", 3, 3, OStrings)
call SaveInteger(Options, 3, 4, 'A004') //Hipster
call SaveStringBJ("Hipster", 3, 4, OStrings)
call SaveStringBJ("None", 3, 5, OStrings)
set MaxChoice[3] = 5
endfunction
private function NewDialog takes nothing returns nothing
local integer a = 0
loop
exitwhen a > 9
set CDialog[a] = DialogCreate()
call DialogSetMessage(CDialog[a], "Welcome, To Argos!")
call TriggerRegisterDialogEventBJ(d, CDialog[a])
set CNew[a] = DialogAddButton(CDialog[a], "New Character", 0)
set CLoad[a] = DialogAddButton(CDialog[a], "Load Character", 0)
call DialogDisplayBJ(true, CDialog[a], Player(a))
set a = a+1
endloop
endfunction
function FuncInit takes nothing returns nothing
local destructable skin
local integer m = 1
local integer PID = GetPlayerId(GetTriggerPlayer())
local CharDat dat
local integer a = 0
call RegisterVars(PID)
set dat = LoadInteger(CD, PID, 1)
set dat.Instructions = CreateMultiboard()
call MultiboardSetItemsStyle(dat.Instructions, true, false)
call MultiboardSetColumnCount(dat.Instructions, 3)
call MultiboardSetRowCount(dat.Instructions, 10)
call MultiboardSetItemWidthBJ(dat.Instructions, 1, 0, 1.0)
call MultiboardSetItemWidthBJ(dat.Instructions, 2, 0, 12.5)
call MultiboardSetItemWidthBJ(dat.Instructions, 3, 0, 7)
call MultiboardSetItemWidthBJ(dat.Instructions, 2, 1, 24)
call MultiboardSetItemWidthBJ(dat.Instructions, 2, 2, 24)
call MultiboardSetItemWidthBJ(dat.Instructions, 2, 3, 24)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 1, INT_COLOR+"Use the Up and Down Arrow Keys to navigate attributes."+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 2, INT_COLOR+"Use the Left and Right Arrow Keys to navigate choices."+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 3, INT_COLOR+"Press Right at CONFIRM to finalize your character."+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 4, INT_COLOR+"Hair Color:"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 5, INT_COLOR+"Skin Color:"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 6, INT_COLOR+"Facial Hair:"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 7, INT_COLOR+"Size:"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 8, INT_COLOR+"Name:"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 2, 9, INT_COLOR+"CONFIRM"+END)
call MultiboardSetItemValueBJ(dat.Instructions, 3, 4, LoadStringBJ(1, 1, OStrings))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 5, "White")
call MultiboardSetItemValueBJ(dat.Instructions, 3, 6, LoadStringBJ(3, 5, OStrings))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 7, R2S((dat.size/formula)/12)+" ft.")
call MultiboardSetItemValueBJ(dat.Instructions,1,4, ARROW)
call MultiboardSetTitleText(dat.Instructions, "Instructions")
call MultiboardDisplay(dat.Instructions, false)
if ( GetLocalPlayer() == GetTriggerPlayer()) then
call MultiboardDisplay(dat.Instructions, true)
endif
set a = 0
call CameraSetupApplyForPlayer( true, Camera[PID], Player(PID), 0 )
call TriggerSleepAction( 0.01 )
call RotateCameraAroundLocBJ(0.01, GetCameraTargetPositionLoc(), GetTriggerPlayer(), 99999.0)
set Display[PID] = CreateUnit(Player(PID), 'h003', GetRectCenterX(Stage[PID]), GetRectCenterY(Stage[PID]), 270.0)
set dat.Character = Display[PID]
call UnitAddAbility(Display[PID], SKIN_CHANGE)
set skin = CreateDestructable(LoadInteger(Options, 1, 1), GetRectCenterX(Stage[PID]), GetRectCenterY(Stage[PID]), 0.0, 0.0, 0)
call IssueTargetOrder( Display[PID], "grabtree", skin)
set dat.Attribute = 1
set dat.Choices[1] = 1
call SetUnitScalePercent(Display[PID], 100.0, 100.0, 100.0)
set skin = null
endfunction
private function NextAtt takes nothing returns nothing
local integer ary = GetPlayerId(GetTriggerPlayer())
local CharDat dat = LoadInteger(CD, ary, 1)
if (dat.Attribute < MAXATT) then
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, " ")
set dat.Attribute = dat.Attribute+1
else
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, " ")
set dat.Attribute = 1
set dat.name = false
endif
if (dat.Attribute==5) then
if (dat.name == false) then
set dat.name = true
endif
endif
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, ARROW)
endfunction
private function PreAtt takes nothing returns nothing
local integer ary = GetPlayerId(GetTriggerPlayer())
local CharDat dat = LoadInteger(CD, ary, 1)
if (dat.Attribute == 1) then
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, " ")
set dat.Attribute = MAXATT
else
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, " ")
set dat.Attribute = dat.Attribute-1
endif
call MultiboardSetItemValueBJ(dat.Instructions,1,dat.Attribute+3, ARROW)
endfunction
private function NextChoice takes nothing returns nothing
local integer ary = GetPlayerId(GetTriggerPlayer())
local CharDat dat = LoadInteger(CD, ary, 1)
if (dat.Attribute == 1) then
if (dat.Choices[1] < MaxChoice[1]) then
set dat.Choices[1] = dat.Choices[1] + 1
if (dat.Skin == false) then
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
else
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
endif
else
set dat.Choices[1] = 1
if (dat.Skin == false) then
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
else
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
endif
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 4, LoadStringBJ(1, dat.Choices[1], OStrings))
endif
if (dat.Attribute == 2) then
if (dat.Skin == false) then
set dat.Skin = true
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 5, "Black")
else
set dat.Skin = false
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 5, "White")
endif
endif
if (dat.Attribute == 3) then
if (dat.Choices[3] < MaxChoice[3]) then
call UnitRemoveAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
set dat.Choices[3] = dat.Choices[3]+1
call UnitAddAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
else
call UnitRemoveAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
set dat.Choices[3] = 1
call UnitAddAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 6, LoadStringBJ(3, dat.Choices[3], OStrings))
endif
if (dat.Attribute==4) then
if (dat.size < MAX) then
set dat.size = dat.size+5.0
call SetUnitScalePercent(Display[ary], dat.size, dat.size, dat.size)
else
set dat.size = MIN
call SetUnitScalePercent(Display[ary], dat.size, dat.size, dat.size)
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 7, R2S((dat.size/formula)/12)+" ft.")
endif
endfunction
private function PreChoice takes nothing returns nothing
local integer ary = GetPlayerId(GetTriggerPlayer())
local CharDat dat = LoadInteger(CD, ary, 1)
if (dat.Attribute == 1) then
if (dat.Choices[1] == 1) then
set dat.Choices[1] = MaxChoice[1]
if (dat.Skin == false) then
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
else
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
endif
else
set dat.Choices[1] = dat.Choices[1]-1
if (dat.Skin == false) then
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
else
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
endif
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 4, LoadStringBJ(1, dat.Choices[1], OStrings))
endif
if (dat.Attribute == 2) then
if (dat.Skin == false) then
set dat.Skin = true
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 2, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 5, "Black")
else
set dat.Skin = false
call IssueTargetOrder( Display[ary], "grabtree", CreateDestructable(LoadInteger(Options, 1, dat.Choices[1]), GetRectCenterX(Stage[ary]), GetRectCenterY(Stage[ary]), 0.0, 0.0, 0))
call MultiboardSetItemValueBJ(dat.Instructions, 3, 5, "White")
endif
endif
if (dat.Attribute == 3) then
if (dat.Choices[3] == 1) then
call UnitRemoveAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
set dat.Choices[3] = MaxChoice[3]
call UnitAddAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
else
call UnitRemoveAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
set dat.Choices[3] = dat.Choices[3]-1
call UnitAddAbility(Display[ary], LoadInteger(Options, 3, dat.Choices[3]))
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 6, LoadStringBJ(3, dat.Choices[3], OStrings))
endif
if (dat.Attribute==4) then
if (dat.size == MIN) then
set dat.size = MAX
call SetUnitScalePercent(Display[ary], dat.size, dat.size, dat.size)
else
set dat.size = dat.size-5.0
call SetUnitScalePercent(Display[ary], dat.size, dat.size, dat.size)
endif
call MultiboardSetItemValueBJ(dat.Instructions, 3, 7, R2S((dat.size/formula)/12)+" ft.")
endif
endfunction
private function FuncInitCond takes nothing returns boolean
local integer a = 0
loop
exitwhen a > 9
if (( GetClickedButton() == CNew[a] ) ) then
return true
endif
set a = a+1
endloop
return false
endfunction
private function ProcessName takes nothing returns nothing
local integer ary = GetPlayerId(GetTriggerPlayer())
local CharDat dat = LoadInteger(CD, ary, 1)
local integer slength = StringLength(GetEventPlayerChatString())
local integer a = 0
local integer b = 0
local boolean accepted = true
local boolean length = true
local boolean minlength = true
if (dat.name == true) then
loop
exitwhen a > slength
loop
exitwhen b > NA
if (SubStringBJ(GetEventPlayerChatString(), a, a) == NOTALLOWED[b]) then
set accepted = false
endif
set b = b+1
endloop
set b = 0
set a = a+1
endloop
set a = 0
if (slength > STRING_MAX) then
set length = false
endif
if (slength < STRING_MIN) then
set minlength = false
endif
if (accepted == false) then
//call BJDebugMsg("Symbols are not allowed!")
call SimError(Player(ary), Alert[1])
endif
if (length == false) then
call SimError(Player(ary), Alert[2])
endif
if (minlength == false) then
call SimError(Player(ary), Alert[3])
endif
if (accepted == true) and (length == true) and (minlength == true) then
call SimError(Player(ary), Alert[4])
set dat.Name = GetEventPlayerChatString()
call DestroyTextTag(dat.tname)
set dat.tname = CreateTextTagLocBJ( "["+dat.Name+"]", OffsetLocation(GetUnitLoc(Display[ary]), -40+I2R(StringLength(dat.Name)), 0), dat.size, 10, 35, 100, 35, 0 )
call MultiboardSetItemValueBJ(dat.Instructions, 3, 8, dat.Name)
endif
endif
endfunction
private function KeyCond takes nothing returns boolean
local integer a = 0
loop
exitwhen a > 9
if (( Done[a] == false ) ) then
return true
endif
set a = a+1
endloop
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer a = 0
call InitVars()
loop
exitwhen a > 9
call TriggerRegisterPlayerKeyEventBJ( t, Player(a), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
set a = a+1
endloop
call TriggerAddAction(t, function PreAtt)
call TriggerAddCondition(t, Condition(function KeyCond))
set a = 0
set t = CreateTrigger()
loop
exitwhen a > 9
call TriggerRegisterPlayerKeyEventBJ( t, Player(a), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
set a = a+1
endloop
call TriggerAddAction(t, function NextAtt)
call TriggerAddCondition(t, Condition(function KeyCond))
set a = 0
set t = CreateTrigger()
loop
exitwhen a > 9
call TriggerRegisterPlayerKeyEventBJ( t, Player(a), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT )
set a = a+1
endloop
call TriggerAddAction(t, function NextChoice)
call TriggerAddCondition(t, Condition(function KeyCond))
set a = 0
set t = CreateTrigger()
loop
exitwhen a > 9
call TriggerRegisterPlayerKeyEventBJ( t, Player(a), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
set a = a+1
endloop
call TriggerAddAction(t, function PreChoice)
call TriggerAddCondition(t, Condition(function KeyCond))
set a = 0
set t = CreateTrigger()
call TriggerRegisterTimerEventSingle(t, 0.01)
call TriggerAddAction(t, function NewDialog)
call TriggerAddCondition(d, Condition(function FuncInitCond))
call TriggerAddAction(d, function FuncInit)
set t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "", false)
call TriggerAddAction(t, function ProcessName)
set a = 0
endfunction
endlibrary