Created
December 30, 2016 19:26
-
-
Save CaptainPRICE/b99d338625d4a1c14e880b0e53d700a6 to your computer and use it in GitHub Desktop.
Holograms Are Fun v1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### <copyright>Copyright (c) 2016 https://github.com/CaptainPRICE. All rights reserved.</copyright> | |
| ### <license>MIT license (see "LICENSE.md" file).</license> | |
| ### <dependency>holo</dependency> | |
| ### <contributors>github.com/CaptainPRICE (https://steamcommunity.com/profiles/76561198092225548/)</contributors> | |
| @name Hologram Are Fun v1 | |
| #ifdef holoCreate(number) | |
| @persist Holograms:array IsDone LastHoloID MaxAmount StartedTime SpawnedCount NAME:string | |
| @trigger none | |
| @model models/led.mdl | |
| if (first()) | |
| { | |
| NAME = "Hologram Are Fun v1" | |
| #region Event Callbacks | |
| ### <summary>Callback function, it is run once a hologram is spawned.</summary> | |
| ### <param name="Holo">Entity of the spawned hologram.</param> | |
| ### <param name="Index">ID/index of the spawned hologram.</param> | |
| function event_OnHoloSpawned(Holo:entity, Index) | |
| { | |
| # Do something with a spawned hologram. | |
| Holograms[Index, entity] = Holo # Insert it into an array of Holograms. | |
| SpawnedCount = Holograms:count() | |
| "self_UpdateStatusName"() | |
| } # End of function void=event_OnHoloSpawned(en) | |
| ### <summary>Callback function, it is run only once all (maximum amount) of holograms has been spawned.</summary> | |
| function event_OnHoloSpawnFinished() | |
| { | |
| # Do something when all of the holograms has finished spawning. | |
| # Calculate the time (in seconds) for how long it took to spawn the maximum amount of holograms. | |
| local TimeSpent = systime() - StartedTime | |
| print(_HUD_PRINTCENTER, "Holograms-Are-Fun: Done, reached the maximum holo entity count.") | |
| hint(format("It took %.2f seconds to complete.", TimeSpent), 4.0) | |
| "self_UpdateStatusName"() | |
| } # End of function void=event_OnHoloSpawnFinished() | |
| #endregion Event Callbacks | |
| ### <summary>Call this function to update the status (name of Expression 2 gate).</summary> | |
| function self_UpdateStatusName() | |
| { | |
| # Set/Update name of the Expression 2 gate, and display the status/progress (and percentage). | |
| local CompletedPercentage = (SpawnedCount / MaxAmount) * 100 | |
| local TimeSpent = systime() - StartedTime | |
| setName(format("%s\n\nStatus: Spawned %d out of %d holograms (%.2f%%, %.2fs).", NAME, SpawnedCount, MaxAmount, CompletedPercentage, TimeSpent)) | |
| } # End of function void=self_UpdateStatusName() | |
| MaxAmount = holoMaxAmount() | |
| StartedTime = systime() | |
| runOnTick(1) | |
| } # End of first() | |
| if (IsDone) | |
| { | |
| # Max amount of props has been spawned. Now do something with them. | |
| # NOTE: This block of code is run repeatedly after the maximum amount of holograms have been spawned in. | |
| # TODO: Insert your code here (i.e. update hologram angles/position in here, etc). | |
| } | |
| else | |
| { | |
| # Spawn the maximum amount of holograms allowed. | |
| while (perf(99)) | |
| { | |
| if (LastHoloID < MaxAmount) | |
| { | |
| if (holoCanCreate()) | |
| { | |
| LastHoloID++ | |
| local Holo = holoCreate(LastHoloID) # TODO: Maybe use another holoCreate overload here, if you wish. | |
| if (Holo) | |
| { | |
| event_OnHoloSpawned(Holo, LastHoloID) | |
| } | |
| else | |
| { | |
| LastHoloID-- | |
| } | |
| } | |
| } | |
| elseif (!IsDone) | |
| { | |
| IsDone = 1 | |
| event_OnHoloSpawnFinished() | |
| } | |
| } | |
| } | |
| interval(1) | |
| #else | |
| error("holo extension is not enabled on the server!") | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment