DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
EnScript.c
Go to the documentation of this file.
1
10class Class
11{
23 proto native external bool IsInherited(typename type);
24
37 proto native owned external string ClassName();
38
39 string GetDebugName() { return ClassName(); }
40
52 proto native external typename Type();
53
64 proto external static typename StaticType();
65
73 static typename StaticGetType(typename t)
74 {
75 return t;
76 }
77
78 proto external string ToString();
79
94 proto static Class Cast(Class from);
95
110 proto static bool CastTo(out Class to, Class from);
111
113 private proto static bool SafeCastType(Class type, out Class to, Class from);
114};
115
118{
119};
120
123{
124};
125
127typedef int[] TypeID;
128
131{
132 private void ~ScriptModule();
133
139 proto volatile int Call(Class inst, string function, void parm);
140
146 proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm);
147 proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms);
148 proto native void Release();
149
160 static proto native ScriptModule LoadScript(ScriptModule parentModule, string scriptFile, bool listing);
161};
162
163//main script module (contains script.c and this file)
164//ScriptModule g_Script;
165
167{
168 private void EnScript() {}
169 private void ~EnScript() {}
170
188 static proto int GetClassVar(Class inst, string varname,int index, out void result);
189
211 static proto int SetClassVar(Class inst, string varname, int index, void input);
212
222 static proto int SetVar(out void var, string value);
223
230 static proto void Watch(void var, int flags);
231};
232
233
234
253proto void Sort(void param_array[], int num);
254proto void reversearray(void param_array);
255proto void copyarray(void destArray, void srcArray);
256
287proto int ParseStringEx(inout string input, string token);
288
307proto int ParseString(string input, out string tokens[]);
308
318proto native int KillThread(Class owner, string name);
319
323proto volatile void Idle();
324
336proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber);
337
339string String(string s)
340{
341 return s;
342}
343
345void PrintString(string s)
346{
347 Print(s);
348}
349
350class array<Class T>
351{
356 proto native int Count();
361 proto native void Clear();
365 proto void Set(int n, T value);
370 proto int Find(T value);
375 proto T Get(int n);
383 proto int Insert(T value);
394 proto int InsertAt(T value, int index);
425 void InsertAll(notnull array<T> from)
426 {
427 for ( int i = 0; i < from.Count(); i++ )
428 {
429 Insert( from.Get(i) );
430 }
431 }
438 proto native void Remove(int index);
445 proto native void RemoveOrdered(int index);
451 proto native void Resize(int newSize);
452
457 proto native void Reserve(int newSize);
458
463 proto native void Swap(notnull array<T> other);
464
468 proto native void Sort(bool reverse = false);
474 proto int Copy(notnull array<T> from);
475 proto int Init(T init[]);
476
477 void RemoveItem(T value)
478 {
479 int remove_index = Find(value);
480
481 if ( remove_index >= 0 )
482 {
483 RemoveOrdered(remove_index);
484 }
485 }
486
488 {
489 int remove_index = Find(value);
490
491 if ( remove_index >= 0 )
492 {
493 Remove(remove_index);
494 }
495 }
496
497 bool IsValidIndex( int index )
498 {
499 return ( index > -1 && index < Count() );
500 }
501
502 /*
503 T GetChecked( int index )
504 {
505 if( IsValidIndex( index ) )
506 return Get( index );
507 else
508 return null;
509 }
510 */
511
523 void Debug()
524 {
525 Print(string.Format("Array count: %1", Count()));
526 for (int i = 0; i < Count(); i++)
527 {
528 T item = Get(i);
529 Print(string.Format("[%1] => %2", i, item));
530 }
531 }
532
543 {
544 if ( Count() > 0 )
545 {
546 return Math.RandomInt(0, Count());
547 }
548
549 return -1;
550 }
551
562 {
563 return Get(GetRandomIndex());
564 }
565
566 void SwapItems(int item1_index, int item2_index)
567 {
568 T item1 = Get(item1_index);
569 Set(item1_index, Get(item2_index));
570 Set(item2_index, item1);
571 }
572
574 {
575 for (int i = 0; i < other.Count(); i++)
576 {
577 T item = other.Get(i);
578 Insert(item);
579 }
580 }
581
582 void Invert()
583 {
584 int left = 0;
585 int right = Count() - 1;
586 if (right > 0)
587 {
588 while (left < right)
589 {
590 T temp = Get(left);
591 Set(left++, Get(right));
592 Set(right--, temp);
593 }
594 }
595 }
596
610 int MoveIndex(int curr_index, int move_number)
611 {
612 int count = Count();
613 int new_index = curr_index;
614
615 if ( move_number > 0 )
616 {
617 new_index = curr_index + move_number;
618 }
619
620 if ( move_number < 0 )
621 {
622 new_index = curr_index - move_number;
623
624 if ( new_index < 0 )
625 {
626 if ( new_index <= -count )
627 {
628 new_index = (new_index % count);
629 }
630
631 new_index = new_index + count;
632 }
633 }
634
635 if ( new_index >= count )
636 {
637 new_index = (new_index % count);
638 }
639
640 // move_number is 0
641 return new_index;
642 }
643
645 {
646 for (int i = 0; i < Count(); i++)
647 {
648 SwapItems(i,GetRandomIndex());
649 }
650 }
651
665 {
666 if (Count() != pOtherArray.Count())
667 {
668 ErrorEx("arrays are not the same size");
669 return -1;
670 }
671
672 for (int i = 0; i < pOtherArray.Count(); ++i)
673 {
674 if (Get(i) != pOtherArray.Get(i))
675 {
676 return i;
677 }
678 }
679
680 return -1;
681 }
682};
683
684//force these to compile so we can link C++ methods to them
694
695class set<Class T>
696{
697 proto native int Count();
698 proto native void Clear();
703 proto int Find(T value);
704 proto T Get(int n);
712 proto int Insert(T value);
723 proto int InsertAt(T value, int index);
729 proto native void Remove(int index);
730 proto int Copy(set<T> from);
731 proto native void Swap(set<T> other);
732 proto int Init(T init[]);
733
734 void InsertSet(set<T> other)
735 {
736 int count = other.Count();
737 for (int i = 0; i < count; i++)
738 {
739 T item = other[i];
740 Insert(item);
741 }
742 }
743
744 void RemoveItem(T value)
745 {
746 int remove_index = Find(value);
747 if (remove_index >= 0)
748 {
749 Remove(remove_index);
750 }
751 }
752
753 void RemoveItems(set<T> other)
754 {
755 int count = other.Count();
756 for (int i = 0; i < count; i++)
757 {
758 T item = other[i];
759 RemoveItem(item);
760 }
761 }
762
763 void Debug()
764 {
765 Print(string.Format("Set count: %1", Count()));
766 for (int i = 0; i < Count(); i++)
767 {
768 T item = Get(i);
769 Print(string.Format("[%1] => %2", i, item));
770 }
771 }
772};
773
774//force these to compile so we can link C++ methods to them
775typedef set<string> TStringSet;
776typedef set<float> TFloatSet;
777typedef set<int> TIntSet;
778typedef set<Class> TClassSet;
779typedef set<Managed> TManagedSet;
780typedef set<ref Managed> TManagedRefSet;
781typedef set<typename> TTypenameSet;
782
783typedef int MapIterator;
800class map<Class TKey,Class TValue>
801{
806 proto native int Count();
807
811 proto native void Clear();
820 proto TValue Get(TKey key);
831 proto bool Find(TKey key, out TValue val);
841 proto TValue GetElement(int index);
851 proto TKey GetKey(int i);
856 proto void Set(TKey key, TValue value);
860 proto void Remove(TKey key);
867 proto void RemoveElement(int i);
871 proto bool Contains(TKey key);
880 proto bool Insert(TKey key, TValue value);
881 proto int Copy(map<TKey,TValue> from);
882
884 {
885 array<TKey> keys = new array<TKey>;
886 for (int i = 0; i < Count(); i++)
887 {
888 keys.Insert( GetKey( i ) );
889 }
890 return keys;
891 }
892
894 {
895 array<TValue> elements = new array<TValue>;
896 for (int i = 0; i < Count(); i++)
897 {
898 elements.Insert( GetElement( i ) );
899 }
900 return elements;
901 }
902
903 bool ReplaceKey(TKey old_key, TKey new_key)
904 {
905 if (Contains(old_key))
906 {
907 Set(new_key, Get(old_key));
908 Remove(old_key);
909 return true;
910 }
911 return false;
912 }
913
914 TKey GetKeyByValue(TValue value)
915 {
916 TKey ret;
917 for (int i = 0; i < Count(); i++)
918 {
919 if (GetElement(i) == value)
920 {
921 ret = GetKey(i);
922 break;
923 }
924 }
925
926 return ret;
927 }
928
929 bool GetKeyByValueChecked(TValue value, out TKey key)
930 {
931 for (int i = 0; i < Count(); i++)
932 {
933 if (GetElement(i) == value)
934 {
935 key = GetKey(i);
936 return true;
937 }
938 }
939 return false;
940 }
941
942 proto native MapIterator Begin();
943 proto native MapIterator End();
944 proto native MapIterator Next(MapIterator it);
947};
948
957
966
975
984
993
1002
void Remove(Object object)
DisplayElementBase GetElement(eDisplayElements element_id)
enum MagnumStableStateID init
array< ref PlayerStatBase > Get()
string name
Super root of all classes in Enforce script.
Definition EnScript.c:11
TODO doc.
Definition EnScript.c:118
Definition EnMath.c:7
TODO doc.
Definition EnScript.c:123
Module containing compiled scripts.
Definition EnScript.c:131
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
proto int ParseString(string input, out string tokens[])
Parses string into array of tokens returns number of tokens.
proto native void Reserve(int newSize)
map< Managed, int > TManagedIntMap
Definition EnScript.c:986
map< Managed, Class > TManagedClassMap
Definition EnScript.c:988
proto volatile int CallFunction(Class inst, string function, out void returnVal, void parm)
void SwapItems(int item1_index, int item2_index)
Definition EnScript.c:566
map< typename, float > TTypeNameFloatMap
Definition EnScript.c:976
static proto void Watch(void var, int flags)
Debug tool for watching certain variable. Invokes debugger whenever is variable used.
private void ~EnScript()
Definition EnScript.c:169
proto int ParseStringEx(inout string input, string token)
Parses one token from input string. Result is put into token string, and type of token is returned....
void InsertSet(set< T > other)
Definition EnScript.c:734
proto void Sort(void param_array[], int num)
Sorts static array of integers(ascendically) / floats(ascendically) / strings(alphabetically)
set< int > TIntSet
Definition EnScript.c:777
array< typename > TTypenameArray
Definition EnScript.c:693
TKey GetKeyByValue(TValue value)
Definition EnScript.c:914
proto void Remove(TKey key)
array< float > TFloatArray
Definition EnScript.c:686
proto void RemoveElement(int i)
set< Class > TClassSet
Definition EnScript.c:778
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto int Find(T value)
proto void Set(int n, T value)
map< Class, vector > TClassVectorMap
Definition EnScript.c:974
proto int Insert(T value)
proto int Copy(set< T > from)
void RemoveItemUnOrdered(T value)
Definition EnScript.c:487
map< Class, typename > TClassTypenameMap
Definition EnScript.c:973
proto native external bool IsInherited(typename type)
Returns true when instance is of the type, or inherited one.
map< ref Managed, Managed > TManagedRefManagedMap
Definition EnScript.c:998
array< string > TStringArray
Definition EnScript.c:685
static proto Class Cast(Class from)
Try to safely down-cast base class to child class.
proto native void RemoveOrdered(int index)
map< int, Class > TIntClassMap
Definition EnScript.c:952
map< Class, float > TClassFloatMap
Definition EnScript.c:967
map< string, vector > TStringVectorMap
Definition EnScript.c:965
proto native int KillThread(Class owner, string name)
Kills thread.
map< int, string > TIntStringMap
Definition EnScript.c:951
proto native void Swap(notnull array< T > other)
map< int, float > TIntFloatMap
Definition EnScript.c:949
proto native int Count()
proto owned string ThreadFunction(Class owner, string name, int backtrace, out int linenumber)
Debug function. Returns current function on stack of the thread.
bool IsValidIndex(int index)
Definition EnScript.c:497
proto int Copy(map< TKey, TValue > from)
proto native MapIterator Begin()
array< Managed > TManagedArray
Definition EnScript.c:690
map< ref Managed, vector > TManagedRefVectorMap
Definition EnScript.c:1001
proto native void Swap(set< T > other)
int MapIterator
Definition EnScript.c:783
int DifferentAtPosition(array< T > pOtherArray)
Returns an index where 2 arrays start to differ from each other.
Definition EnScript.c:664
proto static external StaticType()
Returns typename of object's reference.
map< ref Managed, float > TManagedRefFloatMap
Definition EnScript.c:994
void InsertArray(array< T > other)
Definition EnScript.c:573
array< vector > TVectorArray
Definition EnScript.c:692
array< ref Managed > TManagedRefArray
Definition EnScript.c:691
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:345
map< ref Managed, ref Managed > TManagedRefManagedRefMap
Definition EnScript.c:999
proto TKey GetIteratorKey(MapIterator it)
void RemoveItem(T value)
Definition EnScript.c:477
proto native MapIterator Next(MapIterator it)
proto int Copy(notnull array< T > from)
array< int > TIntArray
Definition EnScript.c:687
map< Class, Class > TClassClassMap
Definition EnScript.c:970
proto native void Sort(bool reverse=false)
proto native MapIterator End()
proto native void Release()
array< Class > TClassArray
Definition EnScript.c:689
map< Class, int > TClassIntMap
Definition EnScript.c:968
proto int InsertAt(T value, int index)
proto void copyarray(void destArray, void srcArray)
static proto int SetVar(out void var, string value)
Sets variable value by value in string.
set< float > TFloatSet
Definition EnScript.c:776
T GetRandomElement()
Returns a random element of array.
Definition EnScript.c:561
static StaticGetType(typename t)
Returns typename of class even without a variable or instance.
Definition EnScript.c:73
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition EnScript.c:339
map< ref Managed, typename > TManagedRefTypenameMap
Definition EnScript.c:1000
map< Managed, typename > TManagedTypenameMap
Definition EnScript.c:991
map< string, int > TStringIntMap
Definition EnScript.c:959
proto volatile void Idle()
set< ref Managed > TManagedRefSet
Definition EnScript.c:780
proto native void Clear()
proto TValue Get(TKey key)
string GetDebugName()
Definition EnScript.c:39
proto TValue GetElement(int index)
map< typename, vector > TTypeNameVectorMap
Definition EnScript.c:983
private static proto bool SafeCastType(Class type, out Class to, Class from)
This function is for internal script usage.
proto native void Resize(int newSize)
private void EnScript()
Definition EnScript.c:168
map< ref Managed, string > TManagedRefStringMap
Definition EnScript.c:996
map< int, typename > TIntTypenameMap
Definition EnScript.c:955
map< Class, ref Managed > TClassManagedRefMap
Definition EnScript.c:972
map< Managed, Managed > TManagedManagedMap
Definition EnScript.c:989
void RemoveItems(set< T > other)
Definition EnScript.c:753
proto void Set(TKey key, TValue value)
static proto int GetClassVar(Class inst, string varname, int index, out void result)
Dynamic read of variable value by its name.
map< typename, Managed > TTypeNameManagedMap
Definition EnScript.c:980
private void ~ScriptModule()
static proto native ScriptModule LoadScript(ScriptModule parentModule, string scriptFile, bool listing)
Do load script and create ScriptModule for it.
proto T Get(int n)
proto void reversearray(void param_array)
map< Managed, ref Managed > TManagedManagedRefMap
Definition EnScript.c:990
map< string, ref Managed > TStringManagedRefMap
Definition EnScript.c:963
map< typename, ref Managed > TTypeNameManagedRefMap
Definition EnScript.c:981
map< typename, int > TTypeNameIntMap
Definition EnScript.c:977
map< string, string > TStringStringMap
Definition EnScript.c:960
array< bool > TBoolArray
Definition EnScript.c:688
map< Class, string > TClassStringMap
Definition EnScript.c:969
map< int, int > TIntIntMap
Definition EnScript.c:950
bool ReplaceKey(TKey old_key, TKey new_key)
Definition EnScript.c:903
map< string, float > TStringFloatMap
Definition EnScript.c:958
map< ref Managed, int > TManagedRefIntMap
Definition EnScript.c:995
proto volatile int Call(Class inst, string function, void parm)
proto native void Remove(int index)
map< typename, Class > TTypeNameClassMap
Definition EnScript.c:979
int MoveIndex(int curr_index, int move_number)
Returns a index in array moved by specific number.
Definition EnScript.c:610
void InsertAll(notnull array< T > from)
Inserts all elements from array.
Definition EnScript.c:425
array< TValue > GetValueArray()
Definition EnScript.c:893
map< string, Class > TStringClassMap
Definition EnScript.c:961
int[] TypeID
script representation for C++ RTTI types
Definition EnScript.c:127
proto native owned external string ClassName()
Returns name of class-type.
set< typename > TTypenameSet
Definition EnScript.c:781
bool GetKeyByValueChecked(TValue value, out TKey key)
Definition EnScript.c:929
map< typename, string > TTypeNameStringMap
Definition EnScript.c:978
map< int, Managed > TIntManagedMap
Definition EnScript.c:953
proto external string ToString()
set< string > TStringSet
Definition EnScript.c:775
map< string, typename > TStringTypenameMap
Definition EnScript.c:964
static proto int SetClassVar(Class inst, string varname, int index, void input)
Dynamic write to variable by its name.
proto TValue GetIteratorElement(MapIterator it)
map< Managed, float > TManagedFloatMap
Definition EnScript.c:985
void Debug()
Print all elements in array.
Definition EnScript.c:523
proto int Init(T init[])
proto bool Insert(TKey key, TValue value)
int GetRandomIndex()
Returns a random index of array. If Count is 0, return index is -1 .
Definition EnScript.c:542
proto bool Find(TKey key, out TValue val)
proto native external Type()
Returns typename of object's class.
proto bool Contains(TKey key)
map< int, vector > TIntVectorMap
Definition EnScript.c:956
set< Managed > TManagedSet
Definition EnScript.c:779
map< int, ref Managed > TIntManagedRefMap
Definition EnScript.c:954
map< typename, typename > TTypeNameTypenameMap
Definition EnScript.c:982
map< ref Managed, Class > TManagedRefClassMap
Definition EnScript.c:997
map< Managed, string > TManagedStringMap
Definition EnScript.c:987
map< Managed, vector > TManagedVectorMap
Definition EnScript.c:992
void ShuffleArray()
Definition EnScript.c:644
proto volatile int CallFunctionParams(Class inst, string function, out void returnVal, Class parms)
map< string, Managed > TStringManagedMap
Definition EnScript.c:962
map< Class, Managed > TClassManagedMap
Definition EnScript.c:971
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].