-
Notifications
You must be signed in to change notification settings - Fork 18
improve C_Trigger usage example #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,31 +51,63 @@ Both of these functions return an instance of `C_Trigger` instance. You can of c | |
| // When the function is called, the instance hero will be placed in self (although it can be any other NPC if desired). | ||
| // The rest of the instances are left null (not used). | ||
|
|
||
| META | ||
| { | ||
| Engine = G1, G2A; | ||
| Parser = Game; | ||
| MergeMode = 1; | ||
| }; | ||
|
|
||
| class C_Trigger | ||
| { | ||
| var int Delay; // defines the frequency (in miliseconds) at which the function will be called. | ||
| var int Enabled; // determines if the trigger is active. If the value is equal to zero, the trigger is destroyed. | ||
| var int AIVariables[16]; // user data, which can be set independently when creating trigger (yes, you can write there absolutely everything you want). | ||
|
|
||
| // Hidden variable members | ||
| /* | ||
| - Func - The function that the trigger will call. | ||
| - Self - The NPC that will be placed in `self` when the function is called. | ||
| - Other - An NPC that will be placed in `other` when the function is called. | ||
| - Victim - The NPC that will be placed in `victim` when the function is called. | ||
| */ | ||
| }; | ||
|
|
||
| var C_Trigger trigger; | ||
| trigger = AI_StartTriggerScriptEx("c_loop", 1000, hero, null, null); | ||
| trigger.AIVariables[0] = 15; // how many times the function should be called | ||
| trigger.AIVariables[1] = 5; // how much damage to deal each iteration | ||
| ``` | ||
|
|
||
| The trigger function | ||
| func void poison_me() { | ||
| var C_Trigger trigger; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now this is in the function, local variable redefinition, same name as global. |
||
| trigger = AI_StartTriggerScriptEx("poison_me_loop", 1000, hero, null, null); | ||
| NadjaTrigger.Delay = 500; // repeat loop each call by 500ms | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NadjaTrigger? |
||
| trigger.AIVariables[0] = 15; // how many times the function should be called | ||
| trigger.AIVariables[1] = 5; // how much damage to deal each iteration | ||
|
Comment on lines
+82
to
+83
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that AIVariables can store anything, and there is no standard, I think this could be improved by removing the magic number indexing and add a global |
||
| }; | ||
|
|
||
| ```dae | ||
| func int c_loop() | ||
| func int poison_me_loop() | ||
| { | ||
| // Create a loop end check, if the number of | ||
| // available iterations has reached 0. If it did | ||
| // we stop the trigger by returning the LOOP_END value. | ||
| if (SelfTrigger.AIVariables[0] <= 0) | ||
| if (trigger.AIVariables[0] <= 0) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. part (2/2) |
||
| { | ||
| return Loop_end; | ||
| }; | ||
|
|
||
| SelfTrigger.Delay -= 20; // Accelerate loop each call by 20 ms | ||
| SelfTrigger.AIVariables[0] -= 1; // Reduce number of remaining repeats | ||
| self.Attribute[ATR_HITPOINTS] -= SelfTrigger.AIVariables[1]; // Take health from self | ||
|
|
||
| trigger.AIVariables[0] -= 1; // Reduce number of remaining repeats | ||
| self.Attribute[ATR_HITPOINTS] -= trigger.AIVariables[1]; // Take health from self | ||
| return LOOP_CONTINUE; | ||
| }; | ||
|
|
||
| func event GameLoop() | ||
| { | ||
| if (Hlp_KeyToggled(KEY_Z)) | ||
| { | ||
| poison_me(); | ||
| }; | ||
| }; | ||
| ``` | ||
| On `Z` key press it will poison the hero. | ||
|
|
||
| ## Trigger scope | ||
|
|
||
| Triggers can be divided into two types: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
miliseconds -> milliseconds