DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
IntroSceneCharacter.c
Go to the documentation of this file.
1class IntroSceneCharacter extends Managed
2{
3 protected int m_CharacterId;
4 protected string m_CharacterType;
9
10 protected ref TStringArray m_CharGenderList = new TStringArray;
11 protected ref TStringArray m_CharShirtList = new TStringArray; //legacy
12 protected ref TStringArray m_CharPantsList = new TStringArray; //legacy
13 protected ref TStringArray m_CharShoesList = new TStringArray; //legacy
14
16
18
20 {
22 }
23
25 {
27 }
28
30 {
31 return m_CharacterId == GameConstants.DEFAULT_CHARACTER_MENU_ID;
32 }
33
35 {
37 }
38 //==============================================
39 // SetcharacterID
40 //==============================================
41 void SetCharacterID(int char_id)
42 {
43 m_CharacterId = char_id;
44 }
45
46 //==============================================
47 // GetCharacterID
48 //==============================================
50 {
51 return m_CharacterId;
52 }
53
54 //==============================================
55 // GetCharacterObj
56 //==============================================
58 {
59 return m_CharacterObj;
60 }
61
62 //==============================================
63 // GetCharGenderList
64 //==============================================
66 {
67 return m_CharGenderList;
68 }
69
70 //==============================================
71 // GetCharGenderList
72 //==============================================
74 {
75 return m_Characters[gender];
76 }
77
78 //==============================================
79 // GetCharShirtsList
80 //==============================================
82 {
83 return m_CharShirtList;
84 }
85
86 //==============================================
87 // GetCharPantsList
88 //==============================================
90 {
91 return m_CharPantsList;
92 }
93
94 //==============================================
95 // GetCharShoesList
96 //==============================================
98 {
99 return m_CharShoesList;
100 }
101
102 //==============================================
103 // SetCharacterGender
104 //==============================================
106 {
107 m_CharGender = gender;
108 }
109
110 //==============================================
111 // IsCharacterFemale
112 //==============================================
114 {
115 return ( m_CharGender == ECharGender.Female );
116 }
117
118 //==============================================
119 // SetCharacterGender
120 //==============================================
122 {
123 return m_CharGender;
124 }
125
126 //==============================================
127 // GetPosition
128 //==============================================
130 {
131 return m_CharacterObj.GetPosition();
132 }
133
134 //==============================================
135 // GetNextCharacterID
136 //==============================================
138 {
139 int count = m_CharacterDta.GetCharactersCount();
140
141 if ( count == 0 )
142 {
143 return -1;
144 }
145
146 if ( m_CharacterId + 1 < count )
147 {
148 return m_CharacterId + 1;
149 }
150 else
151 {
152 return -1;
153 }
154 }
155
156 //==============================================
157 // GetPrevCharacterID
158 //==============================================
160 {
161 int count = m_CharacterDta.GetCharactersCount();
162
163 if ( count == 0 )
164 {
165 return -1;
166 }
167
168 if ( m_CharacterId > -1 )
169 {
170 return m_CharacterId - 1;
171 }
172
173 return count - 1;
174 }
175
176 //==============================================
177 // CreateNewCharacterRandom
178 //==============================================
180 {
181 // Select random gender
183
184 // Select random character skin (class name)
185 string char_name_random = m_Characters[GetCharacterGender()].GetRandomElement();
186
187 // Create new character
188 CreateNewCharacterByName( char_name_random );
189 }
190
191 //==============================================
192 // CreateNewCharacterById
193 //==============================================
194 void CreateNewCharacterById( int character_id )
195 {
196 if ( character_id == GameConstants.DEFAULT_CHARACTER_MENU_ID )
197 {
199 }
200 else
201 {
202 CharacterLoad( character_id, m_CharacterPos, m_CharacterRot );
203 }
204 }
205
206 //==============================================
207 // CreateNewCharacterByName
208 //==============================================
209 void CreateNewCharacterByName( string character_name, bool randomize_equip = true )
210 {
211 m_CharacterType = character_name;
213 if (randomize_equip)
215
217 }
218
220 {
222 //m_CharacterDta.RequestGetDefaultCharacterData();
224 if (m_CharacterType != "")
225 {
227 }
228
229 if(m_CharacterObj)
230 {
231 m_CharacterObj.PlaceOnSurface();
232 m_CharacterObj.SetPosition(m_CharacterPos);
233 m_CharacterObj.SetOrientation(m_CharacterRot);
234 }
235 else
236 {
237 string default_name = Widget.TranslateString( GameConstants.DEFAULT_CHARACTER_NAME );
239 //m_CharacterDta.SetCharacterName(GameConstants.DEFAULT_CHARACTER_MENU_ID, default_name);
241 }
242 }
243
244 void GetLastPlayedServer(int characterID, out string address, out string name, out int port)
245 {
246 m_CharacterDta.GetLastServerAddress(characterID,address);
247 port = m_CharacterDta.GetLastServerPort(characterID);
248 m_CharacterDta.GetLastServerName(characterID,name);
249 }
250 //==============================================
251 // CreateNewCharacter
252 //==============================================
254 {
255 // Unload old character (if exist)
257
258 // Create Character
259 m_CharacterObj = PlayerBase.Cast(g_Game.CreateObjectEx(m_CharacterType, m_CharacterPos, ECE_PLACE_ON_SURFACE));
260
261 if (m_CharacterObj)
262 {
263 m_CharacterObj.PlaceOnSurface();
264 m_CharacterObj.SetOrientation(m_CharacterRot);
266 }
267
268 //Create New Random Character
269 SetupPlayerName( true );
270 }
271
273 /*void EquipNewCharacter()
274 {
275 int slot_ID;
276 string attachment_type;
277 for (int i = 0; i < DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Count(); i++)
278 {
279 slot_ID = DefaultCharacterCreationMethods.GetAttachmentSlotsArray().Get(i);
280 if (DefaultCharacterCreationMethods.GetConfigArrayCountFromSlotID(slot_ID) > 0)
281 {
282 attachment_type = DefaultCharacterCreationMethods.GetConfigAttachmentTypes(slot_ID).GetRandomElement();
283 if (attachment_type != "")
284 SetAttachment(attachment_type,slot_ID);
285 }
286 }
287 }*/
288
289 //==============================================
290 // LoadCharacterData
291 //==============================================
292 void LoadCharacterData(vector char_pos, vector char_rot, bool default_char = false)
293 {
294 m_CharacterDta = g_Game.GetMenuData();
295 m_CharacterPos = char_pos;
296 m_CharacterRot = char_rot;
297
298 if (!default_char && m_CharacterDta.GetLastPlayedCharacter() > -1 )
299 {
300 m_CharacterId = m_CharacterDta.GetLastPlayedCharacter();
301 m_CharacterDta.GetCharacterName(m_CharacterId, g_Game.GetPlayerGameName());
302 }
303
304 // Load all avalible options for character creation; mostly legacy stuff
305 g_Game.ConfigGetTextArray("cfgCharacterCreation" + " gender", m_CharGenderList);
306 g_Game.ConfigGetTextArray("cfgCharacterCreation" + " top", m_CharShirtList);
307 g_Game.ConfigGetTextArray("cfgCharacterCreation" + " bottom", m_CharPantsList);
308 g_Game.ConfigGetTextArray("cfgCharacterCreation" + " shoe", m_CharShoesList);
309
310 // Init character table
311 m_Characters.Clear();
312 m_Characters.Insert( ECharGender.Male, new array<string> );
313 m_Characters.Insert( ECharGender.Female, new array<string> );
314
315 // Sort character by Gender
317 for (int i = 0; i < characters.Count(); i++)
318 {
319 string char_cfg_name = characters.Get(i);
320 if ( GetGame().IsKindOf(char_cfg_name, "SurvivorMale_Base") )
321 {
322 m_Characters[ECharGender.Male].Insert( char_cfg_name );
323 }
324 else
325 {
326 m_Characters[ECharGender.Female].Insert( char_cfg_name );
327 }
328 }
329
330 CreateNewCharacterById(m_CharacterId/*, m_CharacterPos, m_CharacterRot*/);
331
332 if (GetCharacterObj() )
333 {
334 if ( GetCharacterObj().IsMale() )
336 else
338 }
339 }
340
341 //-------------------------
342 // CharacterUnload
343 //-------------------------
344 protected void CharacterUnload()
345 {
346 if ( m_CharacterObj )
347 {
348 g_Game.ObjectDelete(m_CharacterObj);
349 m_CharacterObj = NULL;
350 }
351 }
352
353 //-------------------------
354 // CharacterLoad
355 //-------------------------
356 protected void CharacterLoad( int character_id, vector char_pos, vector char_rot )
357 {
358 if ( character_id == -1 )
359 {
360 Error("IntroSceneCharacter->CharacterLoad: character_id = "+ character_id +" Cant Load Character!!!");
361 return;
362 }
363
365
366 SetCharacterID( character_id );
367
368 m_CharacterObj = PlayerBase.Cast( m_CharacterDta.CreateCharacterPerson( character_id ) );
369
370 if ( m_CharacterObj )
371 {
372
373 m_CharacterObj.PlaceOnSurface();
374 m_CharacterObj.SetPosition(char_pos);
375 m_CharacterObj.SetOrientation(char_rot);
376 }
377 }
378
379 //-------------------------
380 // SetupPlayerName
381 //-------------------------
382 protected void SetupPlayerName( bool new_name )
383 {
385
386#ifdef PLATFORM_CONSOLE
387 BiosUserManager user_manager = GetGame().GetUserManager();
388 if( user_manager )
389 {
390 BiosUser user = user_manager.GetSelectedUser();
391 if( user )
392 {
393 name = user.GetName();
394 }
395 }
396#else
397 if ( !new_name )
398 {
399 m_CharacterDta.GetCharacterName(m_CharacterId, name);
400 }
401#endif
402
403 g_Game.SetPlayerGameName(name);
404 }
405
406 //==============================================
407 // SetAttachment
408 //==============================================
409 void SetAttachment(string type, int slot)
410 {
411 if ( !m_CharacterObj )
412 {
413 return;
414 }
415
416 g_Game.ObjectDelete(m_CharacterObj.GetInventory().FindAttachment(slot));
417
418 EntityAI entity = EntityAI.Cast( g_Game.CreateObjectEx(type, m_CharacterObj.GetPosition(), ECE_PLACE_ON_SURFACE) );
419
420 if (entity)
421 {
422 m_CharacterObj.LocalTakeEntityAsAttachmentEx(entity, slot);
423 }
424 }
425
426 string GetCharacterNameById(int char_id )
427 {
428 string character_name;
430 {
432 }
433 else
434 {
435 m_CharacterDta.GetCharacterName(char_id, character_name);
436 }
437 return character_name;
438 }
439
441 {
442 string character_name;
443 if (IsDefaultCharacter())
444 {
446 }
447 else
448 {
449 m_CharacterDta.GetCharacterName(m_CharacterId, character_name);
450 }
451 return character_name;
452 }
453
454 //==============================================
455 // SaveCharName
456 //==============================================
457 void SaveCharName( string name )
458 {
459 if (IsDefaultCharacter())
460 {
462 }
463 else
464 {
465 m_CharacterDta.SetCharacterName(m_CharacterId, name);
466 }
467 m_CharacterDta.SaveCharactersLocal();
468 }
469
470 //==============================================
471 // SaveDefaultCharacter
472 //==============================================
474 {
475 //if (m_CharacterObj)
476 {
477 m_CharacterDta.RequestSetDefaultCharacterData();
478 }
479 }
480}
const int ECE_PLACE_ON_SURFACE
DayZGame g_Game
Definition DayZGame.c:3654
ECharGender
Definition ECharGender.c:2
string name
proto native owned string GetName()
proto native BiosUser GetSelectedUser()
Returns the currently selected user.
MenuDefaultCharacterData GetMenuDefaultCharacterData(bool fill_data=true)
Definition Game.c:1392
proto native BiosUserManager GetUserManager()
override TStringArray ListAvailableCharacters()
Definition DayZGame.c:3252
TODO doc.
Definition EnScript.c:118
protected void CharacterUnload()
void CreateDefaultCharacter()
void SetAttachment(string type, int slot)
bool IsCharacterFemale()
int GetPrevCharacterID()
protected MenuData m_CharacterDta
bool IsDefaultCharacter()
protected ECharGender m_CharGender
TStringArray GetCharGenderList()
void CreateNewCharacter()
void SetToDefaultCharacter()
int GetNextCharacterID()
protected ref TStringArray m_CharGenderList
vector GetPosition()
protected ref TStringArray m_CharShirtList
TStringArray GetCharList(ECharGender gender)
void SaveCharName(string name)
protected ref TStringArray m_CharPantsList
void LoadCharacterData(vector char_pos, vector char_rot, bool default_char=false)
Generates random equip for the new IntroSceneCharacter, whatever is defined in 'cfgCharacterCreation'...
void CreateNewCharacterByName(string character_name, bool randomize_equip=true)
TStringArray GetCharShirtsList()
string GetCharacterName()
TStringArray GetCharPantsList()
protected void CharacterLoad(int character_id, vector char_pos, vector char_rot)
void SaveDefaultCharacter()
void SetCharacterID(int char_id)
TStringArray GetCharShoesList()
ECharGender GetCharacterGender()
protected vector m_CharacterPos
string GetCharacterNameById(int char_id)
void CreateNewCharacterRandom()
void GetLastPlayedServer(int characterID, out string address, out string name, out int port)
protected string m_CharacterType
void SetCharacterGender(ECharGender gender)
void ~IntroSceneCharacter()
protected void SetupPlayerName(bool new_name)
protected ref TStringArray m_CharShoesList
protected PlayerBase m_CharacterObj
protected vector m_CharacterRot
PlayerBase GetCharacterObj()
void CreateNewCharacterById(int character_id)
void IntroSceneCharacter()
protected int m_CharacterId
Definition EnMath.c:7
proto native int GetCharactersCount()
proto native int GetLastServerPort(int index)
proto native int GetLastPlayedCharacter()
proto native Man CreateCharacterPerson(int index)
Return Character person or null if character initialization failed (inventory load,...
proto void GetLastServerAddress(int index, out string address)
proto native void SetCharacterName(int index, string newName)
proto void GetLastServerName(int index, out string address)
proto void RequestSetDefaultCharacterData()
proto void GetCharacterName(int index, out string name)
proto native void SaveCharactersLocal()
Saves characters menu data to file.
void SetCharacterType(string character_type)
Definition gameplay.c:1059
void SetCharacterName(string name)
Definition gameplay.c:1049
void EquipDefaultCharacter(Man player)
Definition gameplay.c:989
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const string DEFAULT_CHARACTER_NAME
Definition constants.c:823
const int DEFAULT_CHARACTER_MENU_ID
Definition constants.c:825
array< string > TStringArray
Definition EnScript.c:685
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].