├── .gitignore ├── README.md ├── client ├── .gitignore ├── build │ ├── entitysync │ │ ├── endpoints │ │ │ ├── markers │ │ │ │ ├── index.js │ │ │ │ └── marker.js │ │ │ ├── objects │ │ │ │ ├── async-models.js │ │ │ │ ├── index.js │ │ │ │ └── object.js │ │ │ ├── textlabels │ │ │ │ ├── index.js │ │ │ │ ├── labels.rml │ │ │ │ └── textlabel.js │ │ │ └── world-objects │ │ │ │ ├── index.js │ │ │ │ └── worldObject.js │ │ ├── enums │ │ │ └── endpoints.js │ │ ├── factory.js │ │ ├── index.js │ │ └── interfaces.js │ ├── fonts │ │ └── Inter-Bold.ttf │ ├── index.js │ ├── resource.cfg │ └── utils.js ├── package-lock.json ├── package.json ├── src │ ├── entitysync │ │ ├── endpoints │ │ │ ├── markers │ │ │ │ ├── index.ts │ │ │ │ └── marker.ts │ │ │ ├── objects │ │ │ │ ├── async-models.ts │ │ │ │ ├── index.ts │ │ │ │ └── object.ts │ │ │ ├── textlabels │ │ │ │ ├── index.ts │ │ │ │ ├── labels.rml │ │ │ │ └── textlabel.ts │ │ │ └── world-objects │ │ │ │ ├── index.ts │ │ │ │ └── worldObject.ts │ │ ├── enums │ │ │ └── endpoints.ts │ │ ├── factory.ts │ │ ├── index.ts │ │ └── interfaces.ts │ ├── fonts │ │ └── Inter-Bold.ttf │ ├── index.ts │ ├── resource.cfg │ └── utils.ts └── tsconfig.json └── server ├── AltV.CoffeeGen.EntityStreamersOS.csproj ├── DynamicObject.cs ├── IDynamicObject.cs ├── Init.cs ├── MarkerStreamer.cs ├── ObjectStreamer.cs ├── TextLabelStreamer.cs └── WorldObject.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALT:V MP Server-side Entity Streamers 2 | A server-side C# implementation of entity streamers for ALT:V MP. 3 | 4 | This is an updated version of my previous streamers that I released a few years ago: 5 | 6 | https://github.com/CoffeeGen/altv-object-streamer 7 | 8 | https://github.com/CoffeeGen/altv-textlabel-streamer 9 | 10 | https://github.com/CoffeeGen/altv-marker-streamer 11 | 12 | This version is updated to work with altV 9.x, it uses RML UI for textlabels and the client-side has mostly been re-written in TypeScript with a sort of factory pattern to direct each entity sync event to the proper streamer. 13 | 14 | These streamers are used on my Los Angeles Cops & Robbers server(after 2.0 launch) (https://invite.gg/lacnr). 15 | 16 | Special thanks to: 17 | - Heron for the entity sync and C# module. 18 | - Stuyk for his typescript boilerplate, which I used for the build commands and to set up typescript etc. 19 | - R0b for his RML UI nametags example. 20 | - altV MP Team <3 21 | - enisn for his PR to push it to nuget 22 | 23 | ## Installation 24 | - This resource makes use of the ``AltV.Net.EntitySync (v1.13.0)`` and ``AltV.Net.EntitySync.ServerEvent (v9.0.2)`` nuget package, make sure to install those prior to using this resource. 25 | - Copy ``server/Init.cs`` to your gamemode. 26 | - Make sure to add the following code to your gamemode's OnStart() method(entity sync won't work without it!): 27 | ```csharp 28 | AltStreamers.Init(); // you probably need to import the AltV.Streamers namespace. 29 | ``` 30 | - Copy ``client/build`` to your ``server-root/resources`` directory (you can rename the folder to whatever you want). 31 | - Copy-paste the rest of the .cs server files to your gamemode. You can also choose to only use those that you need and skip the rest. 32 | - Enjoy! 33 | 34 | ## Building the client 35 | The client is written in TypeScript, if you make changes to these files, you will have to re-build them to .js files. 36 | To rebuild them, simply type ``npm run build`` and it should output the new files in your ``build`` directory. 37 | 38 | ## Usage 39 | 40 | ### Objects 41 | The following global methods are available: 42 | ```csharp 43 | // Create a new object on the map, returns the created object. 44 | DynamicObject CreateDynamicObject( 45 | string model, Vector3 position, Vector3 rotation, int dimension = 0, bool isDynamic = false, bool frozen = true, 46 | uint? lodDistance = null, 47 | Rgb lightColor = null, bool onFire = false, TextureVariation? textureVariation = null, bool visible = true, 48 | uint streamRange = 150 49 | ); 50 | 51 | // Destroy a dynamnic object 52 | bool DestroyDynamicObject( DynamicObject obj ); 53 | 54 | // Get a dynamic object by entity ID 55 | T GetDynamicObjectByEntityId( ulong entityId ); 56 | 57 | // Destroy all dynamic objects of a given type 58 | void DestroyAllDynamicObjects( ); 59 | 60 | // Get the closest dynamic object of given type to the specified Vector3 position. 61 | (T obj, float distance) GetClosestDynamicObjectOfType( Vector3 pos ) 62 | 63 | // Destroy all created objects. 64 | void DestroyAllDynamicObjects( ); 65 | 66 | // Get a list of all created objects by type. 67 | List GetAllDynamicObjects( ) 68 | ``` 69 | 70 | Each object has its own set of methods that can be used to change properties: 71 | ```csharp 72 | // Get/set object's rotation 73 | Vector3 Rotation { get; set; } 74 | 75 | // Get/set object's position 76 | Vector3 Position { get; set; } 77 | 78 | // Get/set object's model 79 | string Model { get; set; } 80 | 81 | // Get/set LOD Distance (default null) 82 | uint? LodDistance { get; set; } 83 | 84 | // Get/set object's texture variation (default null) 85 | TextureVariation? TextureVariation { get; set; } 86 | 87 | // Get/set object's dynamic state (default null) 88 | bool? Dynamic { get; set; } 89 | 90 | // Get/set object's visibility state (default null) 91 | bool? Visible { get; set; } 92 | 93 | // Get/set object's on fire state (default null) (don't use this as of right now, it does create a fire but it's very small. requires further native testing). 94 | bool? OnFire { get; set; } 95 | 96 | // Get/set object's frozen state (default null) 97 | bool? Frozen { get; set; } 98 | 99 | // Get/set object's light color (default null) 100 | Rgb LightColor { get; set; } 101 | ``` 102 | 103 | #### Examples 104 | ```csharp 105 | // Create an object. 106 | DynamicObject obj = ObjectStreamer.CreateDynamicObject( "bkr_prop_biker_bblock_cor", new Vector3( -859.655f, -803.499f, 25.566f ), new Rotation( 0, 0, 0 ), 0 ); 107 | 108 | // Change object into a house. 109 | obj.Model = "lf_house_17_"; 110 | 111 | // Change position. 112 | obj.Position = new Position( 300f, 500f, 25f ); // Accepts both Vector3 and Position types. 113 | 114 | // Change rotation. 115 | obj.Rotation = new Rotation( 0f, 0f, 25f ); // Accepts both Vector3 and Rotation types. 116 | 117 | // Hide the object 118 | obj.Visible = false; 119 | 120 | // Set an object's texture variation 121 | obj.TextureVariation = TextureVariation.Nautical; 122 | 123 | // Set an object's light color 124 | obj.LightColor = new Rgb( 25, 49, 120 ); // random 125 | 126 | // Freeze an object 127 | obj.Frozen = true; 128 | 129 | // Destroy the object 130 | ObjectStreamer.DestroyDynamicObject( obj ); // has an overload method that accepts an ID instead of object instance. 131 | ``` 132 | 133 | ### World Objects (remove objects from GTA map) 134 | The following global methods are available: 135 | ```csharp 136 | // Remove an existing world object from the map(eg a rockstar object, NOT one you added yourself!) 137 | WorldObject DeleteWorldObject( string model, Vector3 position, float radius = 5, uint range = 50, bool visible = false ); 138 | ``` 139 | 140 | Each world object has its own set of methods that can be used to change properties: 141 | ```csharp 142 | // Get/set model 143 | string Model { get; set; } 144 | 145 | // Get/set radius in which to search for the object 146 | float Radius { get; set; } 147 | 148 | // Get/Set whether this one should be visible on the map or not (false = removes the object from the map) 149 | bool Visible { get; set; } 150 | ``` 151 | 152 | #### Examples 153 | ```csharp 154 | ObjectStreamer.DeleteWorldObject( "some_object_model", new Vector3( 123f, 456f, 789f ), 5 ); 155 | ``` 156 | 157 | ### Textlabels 158 | The textlabel streamer makes use of altV's newly implemented RML UI for high performance textlabels. 159 | 160 | The following global methods are available: 161 | ```csharp 162 | // Create a new textlabel on the map, returns the created textlabel. 163 | DynamicTextLabel CreateDynamicTextLabel( 164 | string text, Vector3 position, int dimension = 0, Rgba? color = null, int? scale = null, uint streamRange = 25 165 | ); 166 | 167 | // Destroy a textlabel by it's ID or textlabel instance. returns true if successful. 168 | bool DestroyDynamicTextLabel( ulong dynamicTextLabelId ); 169 | void DestroyDynamicTextLabel( DynamicTextLabel dynamicTextLabel ); 170 | 171 | // Get a textlabel by it's ID. returns the textlabel if successful or null if not. 172 | DynamicTextLabel GetDynamicTextLabel( ulong dynamicTextLabelId ); 173 | 174 | // Destroy all created textlabels. 175 | void DestroyAllDynamicTextLabels( ); 176 | 177 | // Get a list of all created textlabels. 178 | List GetAllDynamicTextLabels( ); 179 | ``` 180 | 181 | Each textlabel has it's own set of methods and properties that can be used: 182 | ```csharp 183 | // Get/set textlabel's position. 184 | Vector3 Position { get; set; } 185 | 186 | // Get/set scale of the textlabel (currently not functional). 187 | int? Scale { get; set; } 188 | 189 | // Get/set the textlabel's text. 190 | string Text { get; set; } 191 | 192 | // Get/set the textlabel's color. 193 | Rgba Color { get; set; } 194 | 195 | // Destroy the textlabel and all it's data. 196 | void Destroy( ); 197 | ``` 198 | 199 | #### Examples 200 | ```csharp 201 | // Create a textlabel. 202 | DynamicTextLabel textLabel = TextLabelStreamer.CreateDynamicTextLabel( "Some Text", new Vector3( -879.655f, -853.499f, 19.566f ), 0, new Rgba( 255, 255, 255, 255 ) ); 203 | 204 | // Change textlabel text. 205 | textLabel.Text = "Some other text"; 206 | 207 | // Change position. 208 | textLabel.Position = new Position( 300f, 500f, 25f ); // Accepts both Vector3 and Position types. 209 | 210 | // Set the textlabel's color 211 | textLabel.Color = new Rgba( 25, 49, 120, 255 ); // random 212 | 213 | // Destroy the textlabel 214 | TextLabelStreamer.DestroyDynamicTextLabel( textLabel ); // has an overload method that accepts an ID instead of textlabel instance. 215 | ``` 216 | 217 | 218 | ### Markers 219 | The following global methods are available: 220 | ```csharp 221 | // Create a new marker on the map, returns the created marker. 222 | DynamicMarker CreateDynamicMarker( 223 | MarkerType markerType, Vector3 position, Vector3 scale, Vector3? rotation = null, Vector3? direction = null, 224 | Rgba? color = null, 225 | bool? bobUpDown = false, bool? faceCamera = false, bool? rotate = false, string textureDict = null, 226 | string textureName = null, 227 | bool? drawOnEnter = false, int dimension = 0, uint streamRange = 50 228 | ); 229 | 230 | // Destroy an marker by it's ID or marker instance. returns true if successful. 231 | bool DestroyDynamicMarker( ulong dynamicMarkerId ); 232 | void DestroyDynamicMarker( DynamicMarker marker ); 233 | 234 | // Get an marker by it's ID. returns the marker if successful or null if not. 235 | DynamicMarker GetDynamicMarker( ulong dynamicMarkerId ); 236 | 237 | // Destroy all created markers. 238 | void DestroyAllDynamicMarkers( ); 239 | 240 | // Get a list of all created markers. 241 | List GetAllDynamicMarkers( ); 242 | ``` 243 | 244 | Each marker has it's own set of methods and properties that can be used: 245 | ```csharp 246 | // Get/set marker's rotation. 247 | Vector3 Rotation { get; set; } 248 | 249 | // Get/set marker's position. 250 | Vector3 Position { get; set; } 251 | 252 | // Get/set marker's texture dictionary 253 | string TextureDict { get; set; } 254 | 255 | // Get/set marker's texture name. 256 | string TextureName { get; set; } 257 | 258 | // Get/set whether the marker should rotate on the Y axis(heading). 259 | bool? Rotate { get; set; } 260 | 261 | // Get/set whether the marker should be drawn onto the entity when they enter it. 262 | bool? DrawOnEnter { get; set; } 263 | 264 | // Get/set whether the marker should rotate on the Y axis towards the player's camera. 265 | bool? FaceCamera { get; set; } 266 | 267 | // Get/set whether the marker should bob up and down. 268 | bool? BobUpDown { get; set; } 269 | 270 | // Get/set scale of the marker. 271 | Vector3 Scale { get; set; } 272 | 273 | // Get/set - Represents a heading on each axis in which the marker should face, alternatively you can rotate each axis independently with Rotation and set Direction axis to 0. 274 | Vector3 Direction { get; set; } 275 | 276 | // Get/set the current marker's type(see MarkerTypes enum). 277 | MarkerTypes MarkerType { get; set; } 278 | 279 | // Get/set marker color. (default white) 280 | Rgba? Color { get; set; } 281 | 282 | // Destroy the marker and all it's data. 283 | void Destroy( ); 284 | ``` 285 | 286 | #### Examples 287 | ```csharp 288 | // Create a marker. 289 | DynamicMarker marker = MarkerStreamer.CreateDynamicMarker( MarkerType.MarkerTypeVerticalCylinder, new Vector3( -879.655f, -853.499f, 19.566f ), new Vector3( 1 ), color: new Rgba( 125, 52, 21, 255 ) ); 290 | 291 | // Change marker type into plane model. 292 | marker.MarkerType = MarkerType.MarkerTypePlaneMode; 293 | 294 | // Change position. 295 | marker.Position = new Position( 300f, 500f, 25f ); // Accepts both Vector3 and Position types. 296 | 297 | // Change rotation. 298 | marker.Rotation = new Rotation( 0f, 0f, 25f ); // Accepts both Vector3 and Rotation types. 299 | 300 | // Set an marker's color 301 | marker.LightColor = new Rgba( 25, 49, 120, 255 ); // random 302 | 303 | // Destroy the marker 304 | MarkerStreamer.DestroyDynamicMarker( marker ); // has an overload method that accepts an ID instead of marker instance. 305 | ``` 306 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/markers/index.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import { Marker } from "./marker"; 4 | export class EntitySyncMarkerEndpoint { 5 | tick; 6 | entities; 7 | constructor() { 8 | this.tick = null; 9 | this.entities = new Map(); 10 | } 11 | onStreamIn(entityId, entityData) { 12 | let entity = this.entities.get(entityId); 13 | if (entity) { 14 | fillObjectPartially(entity, entityData); 15 | } 16 | else { 17 | entity = new Marker(entityData); 18 | } 19 | entity.streamed = true; 20 | this.entities.set(entityId, entity); 21 | if (this.tick === null) 22 | this.startTick(); 23 | } 24 | onStreamOut(entityId) { 25 | if (!this.entities.has(entityId)) 26 | return; 27 | const entity = this.entities.get(entityId); 28 | entity.streamed = false; 29 | } 30 | onUpdateData(entityId, data) { 31 | if (!this.entities.has(entityId)) 32 | return; 33 | let entity = this.entities.get(entityId); 34 | fillObjectPartially(entity, data); 35 | } 36 | onUpdatePosition(entityId, position) { 37 | if (!this.entities.has(entityId)) 38 | return; 39 | const entity = this.entities.get(entityId); 40 | entity.position = position; 41 | } 42 | onRemove(entityId) { 43 | if (!this.entities.has(entityId)) 44 | return; 45 | this.entities.delete(entityId); 46 | } 47 | startTick() { 48 | if (this.tick !== null) 49 | return; 50 | this.tick = alt.everyTick(() => { 51 | let count = 0; 52 | for (const [, entity] of this.entities) { 53 | if (entity.streamed) { 54 | entity.draw(); 55 | count++; 56 | } 57 | } 58 | if (count === 0) 59 | this.clearTick(); 60 | }); 61 | } 62 | clearTick() { 63 | if (this.tick === null) 64 | return; 65 | alt.clearEveryTick(this.tick); 66 | this.tick = null; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/markers/marker.js: -------------------------------------------------------------------------------- 1 | import { fillObjectPartially } from "../../../utils"; 2 | import * as natives from "natives"; 3 | export class Marker { 4 | bobUpDown; 5 | color; 6 | direction; 7 | drawOnEnter; 8 | faceCam; 9 | markerType; 10 | position; 11 | rotate; 12 | rotation; 13 | scale; 14 | streamed; 15 | textureDict; 16 | textureName; 17 | constructor(data) { 18 | fillObjectPartially(this, data); 19 | } 20 | draw() { 21 | natives.drawMarker(this.markerType, this.position.x, this.position.y, this.position.z, this.direction.x, this.direction.y, this.direction.z, this.rotation.x, this.rotation.y, this.rotation.z, this.scale.x, this.scale.y, this.scale.z, this.color.r, this.color.g, this.color.b, this.color.a, this.bobUpDown, this.faceCam, 2, this.rotate, this.textureDict, this.textureName, this.drawOnEnter); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/objects/async-models.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import * as natives from 'natives'; 3 | class AsyncModel { 4 | loadingModels = new Set(); 5 | loadedModels = new Map(); 6 | cancel(hash) { 7 | this.loadingModels.delete(hash); 8 | this.removeLoadedModel(hash); 9 | } 10 | async load(hash) { 11 | return new Promise(resolve => { 12 | if (natives.hasModelLoaded(hash)) { 13 | return resolve(true); 14 | } 15 | this.loadingModels.add(hash); 16 | natives.requestModel(hash); 17 | const interval = alt.setInterval(() => { 18 | if (!this.loadingModels.has(hash)) { 19 | return done(natives.hasModelLoaded(hash)); 20 | } 21 | if (natives.hasModelLoaded(hash)) { 22 | return done(true); 23 | } 24 | }, 25); 25 | const timeout = alt.setTimeout(() => { 26 | return done(natives.hasModelLoaded(hash)); 27 | }, 3000); 28 | const done = result => { 29 | alt.clearInterval(interval); 30 | alt.clearTimeout(timeout); 31 | if (this.loadingModels.has(hash)) 32 | this.addLoadedModel(hash); 33 | this.loadingModels.delete(hash); 34 | return resolve(result); 35 | }; 36 | }); 37 | } 38 | addLoadedModel(hash) { 39 | let counter = 0; 40 | if (this.loadedModels.has(hash)) 41 | counter = this.loadedModels.get(hash); 42 | this.loadedModels.set(hash, ++counter); 43 | } 44 | removeLoadedModel(hash) { 45 | if (!this.loadedModels.has(hash)) 46 | natives.setModelAsNoLongerNeeded(hash); 47 | let count = this.loadedModels.get(hash); 48 | count--; 49 | if (count > 0) { 50 | this.loadedModels.set(hash, count); 51 | return; 52 | } 53 | natives.setModelAsNoLongerNeeded(hash); 54 | this.loadedModels.delete(hash); 55 | } 56 | } 57 | export const asyncModel = new AsyncModel(); 58 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/objects/index.js: -------------------------------------------------------------------------------- 1 | import { fillObjectPartially } from "../../../utils"; 2 | import { DynamicObject } from "./object"; 3 | export class EntitySyncObjectEndpoint { 4 | entities; 5 | constructor() { 6 | this.entities = new Map(); 7 | } 8 | onStreamIn(entityId, entityData) { 9 | let entity = this.entities.get(entityId); 10 | if (entity) { 11 | fillObjectPartially(entity, entityData); 12 | } 13 | else { 14 | entity = new DynamicObject(entityData); 15 | } 16 | entity.create(); 17 | this.entities.set(entityId, entity); 18 | } 19 | onStreamOut(entityId) { 20 | if (!this.entities.has(entityId)) 21 | return; 22 | const entity = this.entities.get(entityId); 23 | entity.destroy(); 24 | } 25 | onUpdateData(entityId, data) { 26 | if (!this.entities.has(entityId)) 27 | return; 28 | let entity = this.entities.get(entityId); 29 | fillObjectPartially(entity, data); 30 | entity.update(); 31 | } 32 | onUpdatePosition(entityId, position) { 33 | if (!this.entities.has(entityId)) 34 | return; 35 | const entity = this.entities.get(entityId); 36 | entity.position = position; 37 | entity.update(); 38 | } 39 | onRemove(entityId) { 40 | if (!this.entities.has(entityId)) 41 | return; 42 | this.entities.delete(entityId); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/objects/object.js: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | import { asyncModel } from "./async-models"; 5 | export class DynamicObject { 6 | model; 7 | position; 8 | frozen; 9 | dynamic; 10 | rotation; 11 | lodDistance; 12 | textureVariation; 13 | visible; 14 | onFire; 15 | lightColor; 16 | velocity; 17 | handle; 18 | constructor(data) { 19 | fillObjectPartially(this, data); 20 | } 21 | async create() { 22 | let hash = alt.hash(this.model); 23 | await asyncModel.load(hash); 24 | this.handle = natives.createObjectNoOffset(hash, this.position.x, this.position.y, this.position.z, false, false, false); 25 | this.update(); 26 | } 27 | update() { 28 | if (this.handle === null) 29 | return; 30 | this.setPosition(); 31 | this.setRotation(); 32 | this.setLodDistance(); 33 | this.setTextureVariation(); 34 | this.setLightColor(); 35 | this.setDynamic(); 36 | this.setVisible(); 37 | this.setVelocity(); 38 | this.setFrozen(); 39 | this.setModel(); 40 | } 41 | destroy() { 42 | let hash = alt.hash(this.model); 43 | if (this.handle === null) { 44 | asyncModel.cancel(hash); 45 | return; 46 | } 47 | asyncModel.removeLoadedModel(hash); 48 | natives.deleteObject(this.handle); 49 | this.handle = null; 50 | } 51 | setRotation() { 52 | if (typeof this.rotation !== 'undefined') 53 | natives.setEntityRotation(this.handle, this.rotation.x, this.rotation.y, this.rotation.z, 0, true); 54 | } 55 | setPosition() { 56 | if (typeof this.position !== 'undefined') 57 | natives.setEntityCoordsNoOffset(this.handle, this.position.x, this.position.y, this.position.z, true, true, true); 58 | } 59 | setDynamic() { 60 | if (typeof this.dynamic !== 'undefined') 61 | natives.setEntityDynamic(this.handle, this.dynamic); 62 | } 63 | setModel() { 64 | let currentHash = natives.getEntityModel(this.handle); 65 | let newHash = alt.hash(this.model); 66 | if (newHash !== currentHash) { 67 | this.destroy(); 68 | this.create(); 69 | } 70 | } 71 | setLodDistance() { 72 | if (this.lodDistance !== null) 73 | natives.setEntityLodDist(this.handle, this.lodDistance); 74 | } 75 | setTextureVariation() { 76 | if (this.textureVariation !== null) 77 | natives.setObjectTextureVariation(this.handle, this.textureVariation); 78 | } 79 | setLightColor() { 80 | if (this.lightColor !== null) 81 | natives.setObjectLightColor(this.handle, true, this.lightColor.r, this.lightColor.g, this.lightColor.b); 82 | } 83 | setVelocity() { 84 | if (typeof this.velocity !== 'undefined') 85 | natives.setEntityVelocity(this.handle, this.velocity.x, this.velocity.y, this.velocity.z); 86 | } 87 | setVisible() { 88 | if (typeof this.visible !== 'undefined') { 89 | natives.setEntityVisible(this.handle, this.visible, true); 90 | natives.setEntityCollision(this.handle, this.visible, true); 91 | } 92 | } 93 | setFrozen() { 94 | if (typeof this.frozen !== 'undefined') 95 | natives.freezeEntityPosition(this.handle, this.frozen); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/textlabels/index.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import { TextLabel } from "./textlabel"; 4 | export class EntitySyncTextLabelEndpoint { 5 | tick; 6 | entities; 7 | rmlDocument; 8 | rmlContainer; 9 | constructor() { 10 | this.tick = null; 11 | this.entities = new Map(); 12 | this.rmlDocument = new alt.RmlDocument('./labels.rml'); 13 | this.rmlContainer = this.rmlDocument.getElementByID('label-container'); 14 | } 15 | onStreamIn(entityId, entityData) { 16 | let entity = this.entities.get(entityId); 17 | if (entity) { 18 | fillObjectPartially(entity, entityData); 19 | } 20 | else { 21 | entity = new TextLabel(entityData, this.rmlDocument); 22 | this.rmlContainer.appendChild(entity.rmlElement); 23 | } 24 | entity.streamIn(); 25 | this.entities.set(entityId, entity); 26 | if (this.tick === null) 27 | this.startTick(); 28 | } 29 | onStreamOut(entityId) { 30 | if (!this.entities.has(entityId)) 31 | return; 32 | const entity = this.entities.get(entityId); 33 | entity.streamOut(); 34 | } 35 | onUpdateData(entityId, data) { 36 | if (!this.entities.has(entityId)) 37 | return; 38 | let entity = this.entities.get(entityId); 39 | fillObjectPartially(entity, data); 40 | entity.onUpdate(); 41 | } 42 | onUpdatePosition(entityId, position) { 43 | if (!this.entities.has(entityId)) 44 | return; 45 | const entity = this.entities.get(entityId); 46 | entity.position = position; 47 | } 48 | onRemove(entityId) { 49 | if (!this.entities.has(entityId)) 50 | return; 51 | const entity = this.entities.get(entityId); 52 | this.rmlContainer.removeChild(entity.rmlElement); 53 | this.entities.delete(entityId); 54 | } 55 | startTick() { 56 | if (this.tick !== null) 57 | return; 58 | this.tick = alt.everyTick(() => { 59 | let count = 0; 60 | for (const [, entity] of this.entities) { 61 | if (entity.streamed) { 62 | entity.draw(); 63 | count++; 64 | } 65 | } 66 | if (count === 0) 67 | this.clearTick(); 68 | }); 69 | } 70 | clearTick() { 71 | if (this.tick === null) 72 | return; 73 | alt.clearEveryTick(this.tick); 74 | this.tick = null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/textlabels/labels.rml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Client Streamer Labels 4 | 31 | 32 | 33 |
34 | 35 |
36 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/textlabels/textlabel.js: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | export class TextLabel { 5 | text; 6 | scale; 7 | color; 8 | position; 9 | rmlElement; 10 | streamed; 11 | constructor(data, rmlDoc) { 12 | fillObjectPartially(this, data); 13 | this.onCreate(rmlDoc); 14 | } 15 | onCreate(rmlDoc) { 16 | this.rmlElement = rmlDoc.createElement("div"); 17 | this.rmlElement.addClass("label"); 18 | this.rmlElement.addClass('hide'); 19 | this.rmlElement.innerRML = this.text.replaceAll('\n', '
'); 20 | this.rmlElement.setProperty('color', `rgba( ${this.color.r}, ${this.color.g}, ${this.color.b}, ${this.color.a} );`); 21 | } 22 | streamIn() { 23 | this.rmlElement.removeClass('hide'); 24 | this.streamed = true; 25 | } 26 | streamOut() { 27 | this.rmlElement.addClass('hide'); 28 | this.streamed = false; 29 | } 30 | onUpdate() { 31 | this.rmlElement.innerRML = this.text.replaceAll('\n', '
'); 32 | this.rmlElement.setProperty('color', `rgba( ${this.color.r}, ${this.color.g}, ${this.color.b}, ${this.color.a} );`); 33 | } 34 | draw() { 35 | if (natives.isSphereVisible(this.position.x, this.position.y, this.position.z, 0.0099999998)) { 36 | if (this.rmlElement.hasClass('hide')) 37 | this.rmlElement.removeClass('hide'); 38 | const screen = alt.worldToScreen(this.position.x, this.position.y, this.position.z); 39 | let left = screen.x - (this.rmlElement.clientWidth / 2); 40 | let top = screen.y - (this.rmlElement.clientHeight / 2); 41 | this.rmlElement.setProperty("left", `${left}px`); 42 | this.rmlElement.setProperty("top", `${top}px`); 43 | } 44 | else { 45 | if (!this.rmlElement.hasClass('hide')) 46 | this.rmlElement.addClass('hide'); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/world-objects/index.js: -------------------------------------------------------------------------------- 1 | import { fillObjectPartially } from "../../../utils"; 2 | import { WorldObject } from "./worldObject"; 3 | export class EntitySyncWorldObjectEndpoint { 4 | entities; 5 | constructor() { 6 | this.entities = new Map(); 7 | } 8 | onStreamIn(entityId, entityData) { 9 | let entity = this.entities.get(entityId); 10 | if (entity) { 11 | fillObjectPartially(entity, entityData); 12 | } 13 | else { 14 | entity = new WorldObject(entityData); 15 | } 16 | entity.streamIn(); 17 | this.entities.set(entityId, entity); 18 | } 19 | onStreamOut(entityId) { 20 | if (!this.entities.has(entityId)) 21 | return; 22 | const entity = this.entities.get(entityId); 23 | entity.streamOut(); 24 | } 25 | onUpdateData(entityId, data) { 26 | if (!this.entities.has(entityId)) 27 | return; 28 | let entity = this.entities.get(entityId); 29 | fillObjectPartially(entity, data); 30 | } 31 | onUpdatePosition(entityId, position) { 32 | if (!this.entities.has(entityId)) 33 | return; 34 | const entity = this.entities.get(entityId); 35 | entity.position = position; 36 | } 37 | onRemove(entityId) { 38 | if (!this.entities.has(entityId)) 39 | return; 40 | this.entities.delete(entityId); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /client/build/entitysync/endpoints/world-objects/worldObject.js: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | export class WorldObject { 5 | model; 6 | position; 7 | radius; 8 | visible; 9 | constructor(data) { 10 | fillObjectPartially(this, data); 11 | } 12 | streamIn() { 13 | if (this.visible) 14 | natives.removeModelHide(this.position.x, this.position.y, this.position.z, this.radius, alt.hash(this.model), true); 15 | else 16 | natives.createModelHideExcludingScriptObjects(this.position.x, this.position.y, this.position.z, this.radius, alt.hash(this.model), true); 17 | } 18 | streamOut() { 19 | if (this.visible) 20 | natives.createModelHideExcludingScriptObjects(this.position.x, this.position.y, this.position.z, this.radius, alt.hash(this.model), true); 21 | else 22 | natives.removeModelHide(this.position.x, this.position.y, this.position.z, this.radius, alt.hash(this.model), true); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /client/build/entitysync/enums/endpoints.js: -------------------------------------------------------------------------------- 1 | export var EndpointType; 2 | (function (EndpointType) { 3 | EndpointType[EndpointType["Marker"] = 0] = "Marker"; 4 | EndpointType[EndpointType["TextLabel"] = 1] = "TextLabel"; 5 | EndpointType[EndpointType["DynamicObject"] = 2] = "DynamicObject"; 6 | EndpointType[EndpointType["WorldObject"] = 3] = "WorldObject"; 7 | })(EndpointType || (EndpointType = {})); 8 | -------------------------------------------------------------------------------- /client/build/entitysync/factory.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | export class EntitySyncFactory { 3 | endpoints; 4 | constructor() { 5 | this.endpoints = new Map(); 6 | } 7 | registerEndpoint(entityType, endpoint) { 8 | if (this.endpoints.has(entityType)) 9 | alt.logError(`[ERROR] EntitySyncFactory::registerEndpoint -> endpoint with type ${entityType} already exists, overwriting...`); 10 | this.endpoints.set(entityType, endpoint); 11 | } 12 | unregisterEndpoint(entityType) { 13 | this.endpoints.delete(entityType); 14 | } 15 | entityStreamIn(entityType, entityId, entityData) { 16 | if (!this.endpoints.has(entityType)) 17 | return; 18 | const endpoint = this.endpoints.get(entityType); 19 | endpoint.onStreamIn(entityId, entityData); 20 | } 21 | entityStreamOut(entityType, entityId) { 22 | if (!this.endpoints.has(entityType)) 23 | return; 24 | const endpoint = this.endpoints.get(entityType); 25 | endpoint.onStreamOut(entityId); 26 | } 27 | entityUpdatePosition(entityType, entityId, position) { 28 | if (!this.endpoints.has(entityType)) 29 | return; 30 | const endpoint = this.endpoints.get(entityType); 31 | endpoint.onUpdatePosition(entityId, position); 32 | } 33 | entityUpdateData(entityType, entityId, data) { 34 | if (!this.endpoints.has(entityType)) 35 | return; 36 | const endpoint = this.endpoints.get(entityType); 37 | endpoint.onUpdateData(entityId, data); 38 | } 39 | entityRemove(entityType, entityId) { 40 | if (!this.endpoints.has(entityType)) 41 | return; 42 | const endpoint = this.endpoints.get(entityType); 43 | endpoint.onRemove(entityId); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client/build/entitysync/index.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import { EntitySyncFactory } from "./factory"; 3 | import { EndpointType } from "./enums/endpoints"; 4 | import { EntitySyncMarkerEndpoint } from "./endpoints/markers"; 5 | import { EntitySyncTextLabelEndpoint } from "./endpoints/textlabels"; 6 | import { EntitySyncObjectEndpoint } from "./endpoints/objects"; 7 | import { EntitySyncWorldObjectEndpoint } from "./endpoints/world-objects"; 8 | const entitySyncFactory = new EntitySyncFactory(); 9 | entitySyncFactory.registerEndpoint(EndpointType.Marker, new EntitySyncMarkerEndpoint()); 10 | entitySyncFactory.registerEndpoint(EndpointType.TextLabel, new EntitySyncTextLabelEndpoint()); 11 | entitySyncFactory.registerEndpoint(EndpointType.DynamicObject, new EntitySyncObjectEndpoint()); 12 | entitySyncFactory.registerEndpoint(EndpointType.WorldObject, new EntitySyncWorldObjectEndpoint()); 13 | alt.onServer("entitySync:create", (entityId, entityType, position, currEntityData) => { 14 | entitySyncFactory.entityStreamIn(entityType, entityId, { ...currEntityData, position }); 15 | }); 16 | alt.onServer("entitySync:remove", (entityId, entityType) => { 17 | entitySyncFactory.entityStreamOut(entityType, entityId); 18 | }); 19 | alt.onServer("entitySync:updatePosition", (entityId, entityType, position) => { 20 | entitySyncFactory.entityUpdatePosition(entityType, entityId, position); 21 | }); 22 | alt.onServer("entitySync:updateData", (entityId, entityType, newEntityData) => { 23 | entitySyncFactory.entityUpdateData(entityType, entityId, newEntityData); 24 | }); 25 | alt.onServer("entitySync:clearCache", (entityId, entityType) => { 26 | entitySyncFactory.entityRemove(entityType, entityId); 27 | }); 28 | -------------------------------------------------------------------------------- /client/build/entitysync/interfaces.js: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /client/build/fonts/Inter-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDutchDev/altv-entity-streamers-os/1c9e4c038fbeac4ea946ac7aee84b77e1a4374fb/client/build/fonts/Inter-Bold.ttf -------------------------------------------------------------------------------- /client/build/index.js: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | alt.loadRmlFont("/fonts/Inter-Bold.ttf", "inter-bold", false, false); 3 | import './entitysync'; 4 | alt.log('[ENTITY STREAMER] Initialized!'); 5 | -------------------------------------------------------------------------------- /client/build/resource.cfg: -------------------------------------------------------------------------------- 1 | type : js 2 | 3 | client-main : index.js 4 | 5 | client-files : [ 6 | index.js, 7 | utils.js, 8 | fonts/*, 9 | entitysync/* 10 | ] -------------------------------------------------------------------------------- /client/build/utils.js: -------------------------------------------------------------------------------- 1 | export function fillObjectPartially(objToFill, newData) { 2 | for (const key in newData) { 3 | objToFill[key] = newData[key]; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "altv-entity-streamers-os", 3 | "version": "2.1.1", 4 | "description": "Entity streamers using alt:V's entity sync", 5 | "main": "", 6 | "scripts": { 7 | "tsc:w": "tsc -w --outDir build", 8 | "build": "npm run clean && tsc && npm run copy", 9 | "copy": "copyfiles \"src/**/*\" --exclude=**/*.ts --up 1 ./build", 10 | "clean": "rimraf build", 11 | "update": "altv-pkg d release", 12 | "windows": "npm run build && altv-server.exe", 13 | "linux": "npm run build && ./start.sh" 14 | }, 15 | "author": "Niels", 16 | "license": "ISC", 17 | "devDependencies": { 18 | "@altv/types-client": "^2.0.7", 19 | "@altv/types-natives": "^1.4.4", 20 | "@altv/types-shared": "^1.1.7", 21 | "@types/gulp": "^4.0.6", 22 | "@types/gulp-debug": "^2.0.31", 23 | "@types/node": "^14.6.1", 24 | "altv-pkg": "latest", 25 | "copyfiles": "^2.4.1", 26 | "gulp": "^4.0.2", 27 | "gulp-using": "^0.1.1", 28 | "rimraf": "^3.0.2", 29 | "typescript": "^4.0.2" 30 | }, 31 | "type": "module", 32 | "dependencies": { 33 | "@altv/types-worker": "^1.0.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/markers/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import * as natives from 'natives'; 3 | 4 | import { IEntitySyncEndpoint } from "../../interfaces"; 5 | import { fillObjectPartially } from "../../../utils"; 6 | import { IMarker, Marker } from "./marker"; 7 | 8 | export class EntitySyncMarkerEndpoint implements IEntitySyncEndpoint 9 | { 10 | private tick : any; 11 | private readonly entities : Map; 12 | 13 | constructor( ) { 14 | this.tick = null; 15 | this.entities = new Map(); 16 | } 17 | 18 | onStreamIn( entityId: number, entityData: IMarker ) { 19 | let entity = this.entities.get( entityId ); 20 | 21 | if( entity ) { 22 | fillObjectPartially( entity, entityData ); 23 | } 24 | else { 25 | entity = new Marker( entityData ); 26 | } 27 | 28 | entity.streamed = true; 29 | this.entities.set( entityId, entity ); 30 | 31 | if( this.tick === null ) 32 | this.startTick( ); 33 | } 34 | 35 | onStreamOut( entityId: number ) { 36 | if( !this.entities.has( entityId ) ) 37 | return; 38 | 39 | const entity = this.entities.get( entityId ); 40 | entity.streamed = false; 41 | } 42 | 43 | onUpdateData( entityId: number, data: IMarker ) { 44 | if( !this.entities.has( entityId ) ) 45 | return; 46 | 47 | let entity = this.entities.get( entityId ); 48 | fillObjectPartially( entity, data ); 49 | } 50 | 51 | onUpdatePosition( entityId: number, position: alt.Vector3 ) { 52 | if( !this.entities.has( entityId ) ) 53 | return; 54 | 55 | const entity = this.entities.get( entityId ); 56 | entity.position = position; 57 | } 58 | 59 | onRemove( entityId: number ) { 60 | if( !this.entities.has( entityId ) ) 61 | return; 62 | 63 | this.entities.delete( entityId ); 64 | } 65 | 66 | private startTick( ) { 67 | if( this.tick !== null ) 68 | return; 69 | 70 | this.tick = alt.everyTick( ( ) => { 71 | let count = 0; 72 | 73 | for( const [ , entity ] of this.entities ) { 74 | if( entity.streamed ) { 75 | entity.draw( ); 76 | count++; 77 | } 78 | } 79 | 80 | if( count === 0 ) 81 | this.clearTick(); 82 | } ); 83 | } 84 | 85 | private clearTick( ) { 86 | if( this.tick === null ) 87 | return; 88 | 89 | alt.clearEveryTick( this.tick ); 90 | this.tick = null; 91 | } 92 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/markers/marker.ts: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | 5 | export interface IMarker { 6 | markerType : number; 7 | position : alt.Vector3; 8 | direction : alt.Vector3; 9 | rotation : alt.Vector3; 10 | scale : alt.Vector3; 11 | color : alt.RGBA; 12 | bobUpDown : boolean; 13 | faceCam : boolean; 14 | rotate : boolean; 15 | textureDict ?: string; 16 | textureName ?: string; 17 | drawOnEnter : boolean; 18 | streamed : boolean; 19 | } 20 | 21 | export class Marker implements IMarker { 22 | bobUpDown: boolean; 23 | color: alt.RGBA; 24 | direction: alt.Vector3; 25 | drawOnEnter: boolean; 26 | faceCam: boolean; 27 | markerType: number; 28 | position: alt.Vector3; 29 | rotate: boolean; 30 | rotation: alt.Vector3; 31 | scale: alt.Vector3; 32 | streamed: boolean; 33 | textureDict: string; 34 | textureName: string; 35 | 36 | constructor( data : IMarker ) { 37 | fillObjectPartially( this, data ); 38 | } 39 | 40 | draw( ) { 41 | natives.drawMarker( 42 | this.markerType, 43 | this.position.x, this.position.y, this.position.z, 44 | this.direction.x, this.direction.y, this.direction.z, 45 | this.rotation.x, this.rotation.y, this.rotation.z, 46 | this.scale.x, this.scale.y, this.scale.z, 47 | this.color.r, this.color.g, this.color.b, this.color.a, 48 | this.bobUpDown, this.faceCam, 2, this.rotate, 49 | this.textureDict, this.textureName, this.drawOnEnter 50 | ); 51 | } 52 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/objects/async-models.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import * as natives from 'natives'; 3 | 4 | class AsyncModel { 5 | private loadingModels = new Set( ); 6 | private loadedModels : Map = new Map( ); 7 | 8 | cancel( hash : number ) { 9 | this.loadingModels.delete( hash ); 10 | this.removeLoadedModel( hash ); 11 | } 12 | 13 | async load( hash : number ) { 14 | return new Promise( resolve => { 15 | if( natives.hasModelLoaded( hash ) ) { 16 | return resolve( true ); 17 | } 18 | 19 | this.loadingModels.add( hash ); 20 | natives.requestModel( hash ); 21 | 22 | const interval = alt.setInterval( () => { 23 | if( !this.loadingModels.has( hash ) ) { 24 | return done( natives.hasModelLoaded( hash ) ); 25 | } 26 | 27 | if( natives.hasModelLoaded( hash ) ) { 28 | return done( true ); 29 | } 30 | }, 25 ); 31 | 32 | const timeout = alt.setTimeout( () => { 33 | return done( natives.hasModelLoaded( hash ) ); 34 | }, 3000 ); 35 | 36 | const done = result => { 37 | alt.clearInterval( interval ); 38 | alt.clearTimeout( timeout ); 39 | 40 | if( this.loadingModels.has( hash ) ) 41 | this.addLoadedModel( hash ); 42 | 43 | this.loadingModels.delete( hash ); 44 | 45 | return resolve( result ); 46 | }; 47 | } ); 48 | } 49 | 50 | addLoadedModel( hash : number ) { 51 | let counter = 0; 52 | 53 | if( this.loadedModels.has( hash ) ) 54 | counter = this.loadedModels.get( hash ); 55 | 56 | this.loadedModels.set( hash, ++counter ); 57 | } 58 | 59 | removeLoadedModel( hash : number ) { 60 | if( !this.loadedModels.has( hash ) ) 61 | natives.setModelAsNoLongerNeeded( hash ); 62 | 63 | let count = this.loadedModels.get( hash ); 64 | count--; 65 | 66 | if( count > 0 ) 67 | { 68 | this.loadedModels.set( hash, count ); 69 | return; 70 | } 71 | 72 | natives.setModelAsNoLongerNeeded( hash ); 73 | this.loadedModels.delete( hash ); 74 | } 75 | 76 | // unloadAllModels() { 77 | // for( let hash in this.loadedModels ) { 78 | // natives.setModelAsNoLongerNeeded( hash ); 79 | // } 80 | // 81 | // this.loadedModels.clear( ); 82 | // } 83 | } 84 | 85 | export const asyncModel = new AsyncModel(); 86 | -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/objects/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | import { IEntitySyncEndpoint } from "../../interfaces"; 4 | import { fillObjectPartially } from "../../../utils"; 5 | import { DynamicObject, IDynamicObject } from "./object"; 6 | 7 | export class EntitySyncObjectEndpoint implements IEntitySyncEndpoint 8 | { 9 | private readonly entities : Map; 10 | 11 | constructor( ) { 12 | this.entities = new Map(); 13 | } 14 | 15 | onStreamIn( entityId: number, entityData: IDynamicObject ) { 16 | let entity = this.entities.get( entityId ); 17 | 18 | if( entity ) { 19 | fillObjectPartially( entity, entityData ); 20 | } 21 | else { 22 | entity = new DynamicObject( entityData ); 23 | } 24 | 25 | entity.create( ); 26 | this.entities.set( entityId, entity ); 27 | } 28 | 29 | onStreamOut( entityId: number ) { 30 | if( !this.entities.has( entityId ) ) 31 | return; 32 | 33 | const entity = this.entities.get( entityId ); 34 | entity.destroy(); 35 | } 36 | 37 | onUpdateData( entityId: number, data: IDynamicObject ) { 38 | if( !this.entities.has( entityId ) ) 39 | return; 40 | 41 | let entity = this.entities.get( entityId ); 42 | 43 | fillObjectPartially( entity, data ); 44 | entity.update( ); 45 | } 46 | 47 | onUpdatePosition( entityId: number, position: alt.Vector3 ) { 48 | if( !this.entities.has( entityId ) ) 49 | return; 50 | 51 | const entity = this.entities.get( entityId ); 52 | 53 | entity.position = position; 54 | entity.update( ); 55 | } 56 | 57 | onRemove( entityId: number ) { 58 | if( !this.entities.has( entityId ) ) 59 | return; 60 | 61 | this.entities.delete( entityId ); 62 | } 63 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/objects/object.ts: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | import { asyncModel } from "./async-models"; 5 | 6 | export interface LightColor { 7 | r : number; 8 | g : number; 9 | b : number; 10 | } 11 | 12 | export interface IDynamicObject { 13 | model: string; 14 | position: alt.Vector3; 15 | frozen ?: boolean; 16 | dynamic ?: boolean 17 | rotation: alt.Vector3; 18 | lodDistance ?: number; 19 | textureVariation ?: number; 20 | visible ?: boolean; 21 | onFire ?: boolean; 22 | lightColor ?: LightColor; 23 | velocity ?: alt.Vector3; 24 | handle ?: number; 25 | 26 | create(); 27 | update(); 28 | destroy(); 29 | } 30 | 31 | export class DynamicObject implements IDynamicObject { 32 | model: string; 33 | position: alt.Vector3; 34 | frozen ?: boolean; 35 | dynamic ?: boolean 36 | rotation: alt.Vector3; 37 | lodDistance ?: number; 38 | textureVariation ?: number; 39 | visible ?: boolean; 40 | onFire ?: boolean; 41 | lightColor ?: LightColor; 42 | velocity ?: alt.Vector3; 43 | handle ?: number; 44 | 45 | constructor( data : IDynamicObject ) { 46 | fillObjectPartially( this, data ); 47 | } 48 | 49 | async create() { 50 | let hash = alt.hash( this.model ); 51 | 52 | await asyncModel.load( hash ); 53 | 54 | this.handle = natives.createObjectNoOffset( hash, this.position.x, this.position.y, this.position.z, false, false, false ); 55 | 56 | this.update(); 57 | } 58 | 59 | update( ) { 60 | if( this.handle === null ) 61 | return; 62 | 63 | this.setPosition( ); 64 | this.setRotation( ); 65 | this.setLodDistance( ); 66 | this.setTextureVariation( ); 67 | this.setLightColor( ); 68 | this.setDynamic( ); 69 | this.setVisible( ); 70 | this.setVelocity( ); 71 | // this.setOnFire( obj.entityId, obj.onFire ); 72 | this.setFrozen( ); 73 | this.setModel(); 74 | } 75 | 76 | destroy() { 77 | let hash = alt.hash( this.model ); 78 | 79 | if( this.handle === null ) 80 | { 81 | asyncModel.cancel( hash ); 82 | return; 83 | } 84 | 85 | asyncModel.removeLoadedModel( hash ); 86 | natives.deleteObject( this.handle ); 87 | this.handle = null; 88 | } 89 | 90 | private setRotation( ) { 91 | if( typeof this.rotation !== 'undefined' ) 92 | natives.setEntityRotation( this.handle, this.rotation.x, this.rotation.y, this.rotation.z, 0, true ); 93 | } 94 | 95 | private setPosition( ) { 96 | if( typeof this.position !== 'undefined' ) 97 | natives.setEntityCoordsNoOffset( this.handle, this.position.x, this.position.y, this.position.z, true, true, true ); 98 | } 99 | 100 | private setDynamic( ) { 101 | if( typeof this.dynamic !== 'undefined' ) 102 | natives.setEntityDynamic( this.handle, this.dynamic ); 103 | } 104 | 105 | private setModel( ) { 106 | let currentHash = natives.getEntityModel( this.handle ); 107 | let newHash = alt.hash( this.model ); 108 | 109 | if( newHash !== currentHash ) { 110 | this.destroy(); 111 | this.create(); 112 | } 113 | } 114 | 115 | private setLodDistance( ) { 116 | if( this.lodDistance !== null ) 117 | natives.setEntityLodDist( this.handle, this.lodDistance ); 118 | } 119 | 120 | private setTextureVariation( ) { 121 | if( this.textureVariation !== null ) 122 | natives.setObjectTextureVariation( this.handle, this.textureVariation ); 123 | } 124 | 125 | private setLightColor( ) { 126 | if( this.lightColor !== null ) 127 | natives.setObjectLightColor( this.handle, true, this.lightColor.r, this.lightColor.g, this.lightColor.b ); 128 | } 129 | 130 | private setVelocity( ) { 131 | if( typeof this.velocity !== 'undefined' ) 132 | natives.setEntityVelocity( this.handle, this.velocity.x, this.velocity.y, this.velocity.z ); 133 | } 134 | 135 | private setVisible( ) { 136 | if( typeof this.visible !== 'undefined' ) 137 | { 138 | natives.setEntityVisible( this.handle, this.visible, true ); 139 | natives.setEntityCollision( this.handle, this.visible, true ); 140 | } 141 | } 142 | 143 | private setFrozen( ) { 144 | if( typeof this.frozen !== 'undefined' ) 145 | natives.freezeEntityPosition( this.handle, this.frozen ); 146 | } 147 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/textlabels/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | import { IEntitySyncEndpoint } from "../../interfaces"; 4 | import { fillObjectPartially } from "../../../utils"; 5 | import { ITextLabel, TextLabel } from "./textlabel"; 6 | 7 | export class EntitySyncTextLabelEndpoint implements IEntitySyncEndpoint 8 | { 9 | private tick : any; 10 | private readonly entities : Map; 11 | 12 | private rmlDocument !: alt.RmlDocument; 13 | private rmlContainer !: alt.RmlElement; 14 | 15 | constructor( ) { 16 | this.tick = null; 17 | this.entities = new Map(); 18 | 19 | this.rmlDocument = new alt.RmlDocument( './labels.rml' ); 20 | this.rmlContainer = this.rmlDocument.getElementByID( 'label-container' ); 21 | } 22 | 23 | onStreamIn( entityId: number, entityData: TextLabel ) { 24 | let entity = this.entities.get( entityId ); 25 | 26 | if( entity ) { 27 | fillObjectPartially( entity, entityData ); 28 | } 29 | else { 30 | entity = new TextLabel( entityData, this.rmlDocument ); 31 | this.rmlContainer.appendChild( entity.rmlElement ); 32 | } 33 | 34 | entity.streamIn(); 35 | this.entities.set( entityId, entity ); 36 | 37 | if( this.tick === null ) 38 | this.startTick( ); 39 | } 40 | 41 | onStreamOut( entityId: number ) { 42 | if( !this.entities.has( entityId ) ) 43 | return; 44 | 45 | const entity = this.entities.get( entityId ); 46 | entity.streamOut(); 47 | } 48 | 49 | onUpdateData( entityId: number, data: ITextLabel ) { 50 | if( !this.entities.has( entityId ) ) 51 | return; 52 | 53 | let entity = this.entities.get( entityId ); 54 | fillObjectPartially( entity, data ); 55 | entity.onUpdate( ); 56 | } 57 | 58 | onUpdatePosition( entityId: number, position: alt.Vector3 ) { 59 | if( !this.entities.has( entityId ) ) 60 | return; 61 | 62 | const entity = this.entities.get( entityId ); 63 | entity.position = position; 64 | } 65 | 66 | onRemove( entityId: number ) { 67 | if( !this.entities.has( entityId ) ) 68 | return; 69 | 70 | const entity = this.entities.get( entityId ); 71 | this.rmlContainer.removeChild( entity.rmlElement ); 72 | 73 | this.entities.delete( entityId ); 74 | } 75 | 76 | private startTick( ) { 77 | if( this.tick !== null ) 78 | return; 79 | 80 | this.tick = alt.everyTick( ( ) => { 81 | let count = 0; 82 | 83 | for( const [ , entity ] of this.entities ) { 84 | if( entity.streamed ) { 85 | entity.draw(); 86 | count++; 87 | } 88 | } 89 | 90 | if( count === 0 ) 91 | this.clearTick(); 92 | } ); 93 | } 94 | 95 | private clearTick( ) { 96 | if( this.tick === null ) 97 | return; 98 | 99 | alt.clearEveryTick( this.tick ); 100 | this.tick = null; 101 | } 102 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/textlabels/labels.rml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Client Streamer Labels 4 | 31 | 32 | 33 |
34 | 35 |
36 | -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/textlabels/textlabel.ts: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | 5 | export interface ITextLabel { 6 | text : string; 7 | scale : number; 8 | color : alt.RGBA; 9 | position : alt.Vector3; 10 | rmlElement : alt.RmlElement; 11 | streamed : boolean; 12 | } 13 | 14 | export class TextLabel implements ITextLabel { 15 | text : string; 16 | scale : number; 17 | color : alt.RGBA; 18 | position : alt.Vector3; 19 | rmlElement : alt.RmlElement; 20 | streamed : boolean; 21 | 22 | constructor( data : ITextLabel, rmlDoc : alt.RmlDocument ) { 23 | fillObjectPartially( this, data ); 24 | this.onCreate( rmlDoc ); 25 | } 26 | 27 | onCreate( rmlDoc : alt.RmlDocument ) { 28 | this.rmlElement = rmlDoc.createElement( "div" ); 29 | 30 | this.rmlElement.addClass( "label" ); 31 | this.rmlElement.addClass( 'hide' ); 32 | this.rmlElement.innerRML = this.text.replaceAll( '\n', '
' ); 33 | this.rmlElement.setProperty( 'color', `rgba( ${ this.color.r }, ${ this.color.g }, ${ this.color.b }, ${ this.color.a } );` ); 34 | } 35 | 36 | streamIn( ) { 37 | this.rmlElement.removeClass( 'hide' ); 38 | this.streamed = true; 39 | } 40 | 41 | streamOut( ) { 42 | this.rmlElement.addClass( 'hide' ); 43 | this.streamed = false; 44 | } 45 | 46 | onUpdate( ) { 47 | this.rmlElement.innerRML = this.text.replaceAll( '\n', '
' ); 48 | this.rmlElement.setProperty( 'color', `rgba( ${ this.color.r }, ${ this.color.g }, ${ this.color.b }, ${ this.color.a } );` ); 49 | } 50 | 51 | draw() { 52 | if( natives.isSphereVisible( this.position.x, this.position.y, this.position.z, 0.0099999998 ) ) { 53 | if( this.rmlElement.hasClass( 'hide' ) ) 54 | this.rmlElement.removeClass( 'hide' ); 55 | 56 | const screen = alt.worldToScreen( this.position.x, this.position.y, this.position.z ); 57 | 58 | let left = screen.x - ( this.rmlElement.clientWidth / 2 ); 59 | let top = screen.y - ( this.rmlElement.clientHeight / 2 ); 60 | 61 | this.rmlElement.setProperty( "left", `${ left }px` ); 62 | this.rmlElement.setProperty( "top", `${ top }px` ); 63 | } 64 | else 65 | { 66 | if( !this.rmlElement.hasClass( 'hide' ) ) 67 | this.rmlElement.addClass( 'hide' ); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/world-objects/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | import { IEntitySyncEndpoint } from "../../interfaces"; 4 | import { fillObjectPartially } from "../../../utils"; 5 | import { IWorldObject, WorldObject } from "./worldObject"; 6 | 7 | export class EntitySyncWorldObjectEndpoint implements IEntitySyncEndpoint 8 | { 9 | private readonly entities : Map; 10 | 11 | constructor( ) { 12 | this.entities = new Map(); 13 | } 14 | 15 | onStreamIn( entityId: number, entityData: IWorldObject ) { 16 | let entity = this.entities.get( entityId ); 17 | 18 | if( entity ) { 19 | fillObjectPartially( entity, entityData ); 20 | } 21 | else { 22 | entity = new WorldObject( entityData ); 23 | } 24 | 25 | entity.streamIn( ); 26 | this.entities.set( entityId, entity ); 27 | } 28 | 29 | onStreamOut( entityId: number ) { 30 | if( !this.entities.has( entityId ) ) 31 | return; 32 | 33 | const entity = this.entities.get( entityId ); 34 | entity.streamOut(); 35 | } 36 | 37 | onUpdateData( entityId: number, data: IWorldObject ) { 38 | if( !this.entities.has( entityId ) ) 39 | return; 40 | 41 | let entity = this.entities.get( entityId ); 42 | fillObjectPartially( entity, data ); 43 | } 44 | 45 | onUpdatePosition( entityId: number, position: alt.Vector3 ) { 46 | if( !this.entities.has( entityId ) ) 47 | return; 48 | 49 | const entity = this.entities.get( entityId ); 50 | entity.position = position; 51 | } 52 | 53 | onRemove( entityId: number ) { 54 | if( !this.entities.has( entityId ) ) 55 | return; 56 | 57 | this.entities.delete( entityId ); 58 | } 59 | } -------------------------------------------------------------------------------- /client/src/entitysync/endpoints/world-objects/worldObject.ts: -------------------------------------------------------------------------------- 1 | import * as alt from "alt-client"; 2 | import { fillObjectPartially } from "../../../utils"; 3 | import * as natives from "natives"; 4 | 5 | 6 | export interface IWorldObject { 7 | model: string; 8 | position: alt.Vector3; 9 | radius: number; 10 | visible: boolean; 11 | 12 | streamIn(); 13 | streamOut(); 14 | } 15 | 16 | export class WorldObject implements IWorldObject { 17 | model: string; 18 | position: alt.Vector3; 19 | radius: number; 20 | visible: boolean; 21 | 22 | 23 | constructor( data : IWorldObject ) { 24 | fillObjectPartially( this, data ); 25 | } 26 | 27 | streamIn( ) { 28 | if( this.visible ) 29 | natives.removeModelHide( this.position.x, this.position.y, this.position.z, this.radius, alt.hash( this.model ), true ); 30 | else 31 | natives.createModelHideExcludingScriptObjects( this.position.x, this.position.y, this.position.z, this.radius, alt.hash( this.model ), true ); 32 | } 33 | 34 | streamOut( ) { 35 | if( this.visible ) 36 | natives.createModelHideExcludingScriptObjects( this.position.x, this.position.y, this.position.z, this.radius, alt.hash( this.model ), true ); 37 | else 38 | natives.removeModelHide( this.position.x, this.position.y, this.position.z, this.radius, alt.hash( this.model ), true ); 39 | } 40 | } -------------------------------------------------------------------------------- /client/src/entitysync/enums/endpoints.ts: -------------------------------------------------------------------------------- 1 | export enum EndpointType { 2 | Marker, 3 | TextLabel, 4 | DynamicObject, 5 | WorldObject 6 | } -------------------------------------------------------------------------------- /client/src/entitysync/factory.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | import { IEntitySyncEndpoint } from "./interfaces"; 4 | 5 | export class EntitySyncFactory { 6 | private endpoints : Map; 7 | 8 | constructor( ) { 9 | this.endpoints = new Map(); 10 | } 11 | 12 | registerEndpoint( entityType : number, endpoint : IEntitySyncEndpoint ) { 13 | if( this.endpoints.has( entityType ) ) 14 | alt.logError( `[ERROR] EntitySyncFactory::registerEndpoint -> endpoint with type ${ entityType } already exists, overwriting...` ); 15 | 16 | this.endpoints.set( entityType, endpoint ); 17 | } 18 | 19 | unregisterEndpoint( entityType : number ) { 20 | this.endpoints.delete( entityType ); 21 | } 22 | 23 | entityStreamIn( entityType : number, entityId : number, entityData : any ) { 24 | if( !this.endpoints.has( entityType ) ) 25 | return; 26 | 27 | const endpoint = this.endpoints.get( entityType ); 28 | endpoint.onStreamIn( entityId, entityData ); 29 | } 30 | 31 | entityStreamOut( entityType : number, entityId : number ) { 32 | if( !this.endpoints.has( entityType ) ) 33 | return; 34 | 35 | const endpoint = this.endpoints.get( entityType ); 36 | endpoint.onStreamOut( entityId ); 37 | } 38 | 39 | entityUpdatePosition( entityType : number, entityId : number, position : alt.Vector3 ) { 40 | if( !this.endpoints.has( entityType ) ) 41 | return; 42 | 43 | const endpoint = this.endpoints.get( entityType ); 44 | endpoint.onUpdatePosition( entityId, position ); 45 | } 46 | 47 | entityUpdateData( entityType : number, entityId : number, data : any ) { 48 | if( !this.endpoints.has( entityType ) ) 49 | return; 50 | 51 | const endpoint = this.endpoints.get( entityType ); 52 | endpoint.onUpdateData( entityId, data ); 53 | } 54 | 55 | entityRemove( entityType : number, entityId : number ) { 56 | if( !this.endpoints.has( entityType ) ) 57 | return; 58 | 59 | const endpoint = this.endpoints.get( entityType ); 60 | endpoint.onRemove( entityId ); 61 | } 62 | } -------------------------------------------------------------------------------- /client/src/entitysync/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | import { EntitySyncFactory } from "./factory"; 3 | import { EndpointType } from "./enums/endpoints"; 4 | import { EntitySyncMarkerEndpoint } from "./endpoints/markers"; 5 | import { EntitySyncTextLabelEndpoint } from "./endpoints/textlabels"; 6 | import { EntitySyncObjectEndpoint } from "./endpoints/objects"; 7 | import { EntitySyncWorldObjectEndpoint } from "./endpoints/world-objects"; 8 | 9 | const entitySyncFactory = new EntitySyncFactory(); 10 | entitySyncFactory.registerEndpoint( EndpointType.Marker, new EntitySyncMarkerEndpoint() ); 11 | entitySyncFactory.registerEndpoint( EndpointType.TextLabel, new EntitySyncTextLabelEndpoint() ); 12 | entitySyncFactory.registerEndpoint( EndpointType.DynamicObject, new EntitySyncObjectEndpoint() ); 13 | entitySyncFactory.registerEndpoint( EndpointType.WorldObject, new EntitySyncWorldObjectEndpoint() ); 14 | 15 | // when an object is streamed in 16 | alt.onServer( "entitySync:create", ( entityId: number, entityType: number, position: alt.Vector3, currEntityData: any ) => { 17 | entitySyncFactory.entityStreamIn( entityType, entityId, { ...currEntityData, position } ); 18 | } ); 19 | 20 | // when an object is streamed out 21 | alt.onServer( "entitySync:remove", ( entityId: number, entityType: number ) => { 22 | entitySyncFactory.entityStreamOut( entityType, entityId ); 23 | } ); 24 | 25 | // when a streamed in object changes position data 26 | alt.onServer( "entitySync:updatePosition", ( entityId: number, entityType: number, position: alt.Vector3 ) => { 27 | entitySyncFactory.entityUpdatePosition( entityType, entityId, position ); 28 | } ); 29 | 30 | // when a streamed in object changes data 31 | alt.onServer( "entitySync:updateData", ( entityId: number, entityType: number, newEntityData: any ) => { 32 | entitySyncFactory.entityUpdateData( entityType, entityId, newEntityData ); 33 | } ); 34 | 35 | // when a streamed in object needs to be removed 36 | alt.onServer( "entitySync:clearCache", ( entityId: number, entityType: number ) => { 37 | entitySyncFactory.entityRemove( entityType, entityId ); 38 | } ); 39 | -------------------------------------------------------------------------------- /client/src/entitysync/interfaces.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | export interface IEntitySyncEndpoint { 4 | onStreamIn( entityId : number, entityData : any ); 5 | onStreamOut( entityId : number ); 6 | onUpdatePosition( entityId : number, position : alt.Vector3 ); 7 | onUpdateData( entityId : number, data : any ); 8 | onRemove( entityId : number ); 9 | } -------------------------------------------------------------------------------- /client/src/fonts/Inter-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheDutchDev/altv-entity-streamers-os/1c9e4c038fbeac4ea946ac7aee84b77e1a4374fb/client/src/fonts/Inter-Bold.ttf -------------------------------------------------------------------------------- /client/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as alt from 'alt-client'; 2 | 3 | alt.loadRmlFont("/fonts/Inter-Bold.ttf", "inter-bold", false, false ); 4 | 5 | import './entitysync'; 6 | 7 | alt.log( '[ENTITY STREAMER] Initialized!' ); -------------------------------------------------------------------------------- /client/src/resource.cfg: -------------------------------------------------------------------------------- 1 | type : js 2 | 3 | client-main : index.js 4 | 5 | client-files : [ 6 | index.js, 7 | utils.js, 8 | fonts/*, 9 | entitysync/* 10 | ] -------------------------------------------------------------------------------- /client/src/utils.ts: -------------------------------------------------------------------------------- 1 | export function fillObjectPartially( objToFill : any, newData : any ) { 2 | for( const key in newData ) { 3 | objToFill[ key ] = newData[ key ]; 4 | } 5 | } -------------------------------------------------------------------------------- /client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "typeRoots": ["./node_modules/@types", "./node_modules/@altv"], 4 | "removeComments": true, 5 | "noUnusedLocals": false, 6 | "noUnusedParameters": false, 7 | "noImplicitReturns": true, 8 | "moduleResolution": "node", 9 | "resolveJsonModule": true, 10 | "allowJs": true, 11 | "emitDecoratorMetadata": true, 12 | "experimentalDecorators": true, 13 | "module": "ESNext", 14 | "target": "ESNext", 15 | "outDir": "./build", 16 | "rootDir": "./src", 17 | "allowSyntheticDefaultImports": true, 18 | }, 19 | "include": ["./src/**/*.ts"], 20 | "exclude": ["node_modules", "**/*.spec.ts", "build", "**/*.json"], 21 | "watchOptions": { 22 | "watchFile": "useFsEvents", 23 | "watchDirectory": "useFsEvents", 24 | "fallbackPolling": "dynamicPriority" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /server/AltV.CoffeeGen.EntityStreamersOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 1.0.0 6 | AltV.Streamers 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /server/DynamicObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Numerics; 4 | using AltV.Net.EntitySync; 5 | 6 | namespace AltV.Streamers; 7 | 8 | /// 9 | /// DynamicObject class that stores all data related to a single object 10 | /// 11 | public class DynamicObject : Entity, IDynamicObject 12 | { 13 | /// 14 | /// Set or get the current object's rotation (in degrees). 15 | /// 16 | public Vector3 Rotation 17 | { 18 | get 19 | { 20 | if( !TryGetData( "rotation", out Dictionary data ) ) 21 | return default; 22 | 23 | return new Vector3() 24 | { 25 | X = Convert.ToSingle( data[ "x" ] ), 26 | Y = Convert.ToSingle( data[ "y" ] ), 27 | Z = Convert.ToSingle( data[ "z" ] ), 28 | }; 29 | } 30 | set 31 | { 32 | // No data changed 33 | if( Rotation.X == value.X && Rotation.Y == value.Y && Rotation.Z == value.Z && 34 | value != new Vector3( 0, 0, 0 ) ) 35 | return; 36 | 37 | Dictionary dict = new Dictionary() 38 | { 39 | [ "x" ] = value.X, 40 | [ "y" ] = value.Y, 41 | [ "z" ] = value.Z, 42 | }; 43 | 44 | SetData( "rotation", dict ); 45 | } 46 | } 47 | 48 | /// 49 | /// Set or get the current object's model. 50 | /// 51 | public string Model 52 | { 53 | get 54 | { 55 | if( !TryGetData( "model", out string model ) ) 56 | return null; 57 | 58 | return model; 59 | } 60 | set 61 | { 62 | // No data changed 63 | if( Model == value ) 64 | return; 65 | 66 | SetData( "model", value ); 67 | } 68 | } 69 | 70 | /// 71 | /// Set or get LOD Distance of the object. 72 | /// 73 | public uint? LodDistance 74 | { 75 | get 76 | { 77 | if( !TryGetData( "lodDistance", out uint lodDist ) ) 78 | return null; 79 | 80 | return lodDist; 81 | } 82 | set 83 | { 84 | // if value is set to null, reset the data 85 | if( value == null ) 86 | { 87 | SetData( "lodDistance", null ); 88 | return; 89 | } 90 | 91 | // No data changed 92 | if( LodDistance == value ) 93 | return; 94 | 95 | SetData( "lodDistance", value ); 96 | } 97 | } 98 | 99 | /// 100 | /// Get or set the current texture variation, use null to reset it to default. 101 | /// 102 | public TextureVariation? TextureVariation 103 | { 104 | get 105 | { 106 | if( !TryGetData( "textureVariation", out int variation ) ) 107 | return null; 108 | 109 | return ( TextureVariation ) variation; 110 | } 111 | set 112 | { 113 | // if value is set to null, reset the data 114 | if( value == null ) 115 | { 116 | SetData( "textureVariation", null ); 117 | return; 118 | } 119 | 120 | // No data changed 121 | if( TextureVariation == value ) 122 | return; 123 | 124 | SetData( "textureVariation", ( int ) value ); 125 | } 126 | } 127 | 128 | /// 129 | /// Get or set the object's dynamic state. Some objects can be moved around by the player when dynamic is set to true. 130 | /// 131 | public bool Dynamic 132 | { 133 | get 134 | { 135 | if( !TryGetData( "dynamic", out bool isDynamic ) ) 136 | return false; 137 | 138 | return isDynamic; 139 | } 140 | set { SetData( "dynamic", value ); } 141 | } 142 | 143 | /// 144 | /// Set/get visibility state of object 145 | /// 146 | public bool Visible 147 | { 148 | get 149 | { 150 | if( !TryGetData( "visible", out bool visible ) ) 151 | return true; 152 | 153 | return visible; 154 | } 155 | set { SetData( "visible", value ); } 156 | } 157 | 158 | /// 159 | /// Set/get an object on fire, NOTE: does not work very well as of right now, fire is very small. 160 | /// 161 | public bool OnFire 162 | { 163 | get 164 | { 165 | if( !TryGetData( "onFire", out bool onFire ) ) 166 | return false; 167 | 168 | return onFire; 169 | } 170 | set { SetData( "onFire", value ); } 171 | } 172 | 173 | /// 174 | /// Freeze an object into it's current position. or get it's status 175 | /// 176 | public bool Frozen 177 | { 178 | get 179 | { 180 | if( !TryGetData( "frozen", out bool frozen ) ) 181 | return true; 182 | 183 | return frozen; 184 | } 185 | set { SetData( "frozen", value ); } 186 | } 187 | 188 | /// 189 | /// Move an object to a new XYZ location 190 | /// 191 | public Vector3 SlideToPosition 192 | { 193 | get 194 | { 195 | if( !TryGetData( "SlideToPosition", out Dictionary data ) ) 196 | return default; 197 | 198 | return new Vector3() 199 | { 200 | X = Convert.ToSingle( data[ "x" ] ), 201 | Y = Convert.ToSingle( data[ "y" ] ), 202 | Z = Convert.ToSingle( data[ "z" ] ), 203 | }; 204 | } 205 | set 206 | { 207 | // No data changed 208 | 209 | Dictionary dict = new Dictionary() 210 | { 211 | [ "x" ] = value.X, 212 | [ "y" ] = value.Y, 213 | [ "z" ] = value.Z, 214 | }; 215 | //Log.Important("SetData SlideToPosition "); 216 | SetData( "SlideToPosition", dict ); 217 | } 218 | } 219 | 220 | /// 221 | /// Set the light color of the object, use null to reset it to default. 222 | /// 223 | public Rgb LightColor 224 | { 225 | get 226 | { 227 | if( !TryGetData( "lightColor", out Dictionary data ) ) 228 | return null; 229 | 230 | return new Rgb( 231 | Convert.ToInt32( data[ "r" ] ), 232 | Convert.ToInt32( data[ "g" ] ), 233 | Convert.ToInt32( data[ "b" ] ) 234 | ); 235 | } 236 | set 237 | { 238 | // if value is set to null, reset the data 239 | if( value == null ) 240 | { 241 | SetData( "lightColor", null ); 242 | return; 243 | } 244 | 245 | // No data changed 246 | if( LightColor != null && LightColor.Red == value.Red && LightColor.Green == value.Green && 247 | LightColor.Blue == value.Blue ) 248 | return; 249 | 250 | Dictionary dict = new Dictionary 251 | { 252 | {"r", value.Red}, 253 | {"g", value.Green}, 254 | {"b", value.Blue} 255 | }; 256 | SetData( "lightColor", dict ); 257 | } 258 | } 259 | 260 | public DynamicObject( Vector3 position, Vector3 rotation, int dimension, uint range, ulong entityType ) : base( 261 | entityType, position, dimension, range ) 262 | { 263 | Rotation = rotation; 264 | } 265 | 266 | public void Destroy( ) 267 | { 268 | AltEntitySync.RemoveEntity( this ); 269 | } 270 | } -------------------------------------------------------------------------------- /server/IDynamicObject.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using AltV.Net.EntitySync; 3 | 4 | namespace AltV.Streamers; 5 | 6 | public interface IDynamicObject : IEntity 7 | { 8 | Vector3 Rotation { get; set; } 9 | string Model { get; set; } 10 | uint? LodDistance { get; set; } 11 | TextureVariation? TextureVariation { get; set; } 12 | bool Dynamic { get; set; } 13 | bool Visible { get; set; } 14 | bool OnFire { get; set; } 15 | bool Frozen { get; set; } 16 | Rgb LightColor { get; set; } 17 | 18 | void Destroy( ); 19 | } -------------------------------------------------------------------------------- /server/Init.cs: -------------------------------------------------------------------------------- 1 | using AltV.Net.EntitySync; 2 | using AltV.Net.EntitySync.ServerEvent; 3 | using AltV.Net.EntitySync.SpatialPartitions; 4 | 5 | namespace AltV.Streamers; 6 | 7 | public static class AltStreamers 8 | { 9 | public static ulong ENTITY_TYPE_MARKER = 0; 10 | public static ulong ENTITY_TYPE_TEXTLABEL = 1; 11 | public static ulong ENTITY_TYPE_DYNAMIC_OBJECT = 2; 12 | public static ulong ENTITY_TYPE_WORLD_OBJECT = 3; 13 | 14 | public static void Init() 15 | { 16 | AltEntitySync.Init( 4, ( threadId ) => 100, ( threadId ) => false, 17 | ( threadCount, repository ) => new ServerEventNetworkLayer( threadCount, repository ), 18 | ( entity, threadCount ) => ( entity.Type ), 19 | ( entityId, entityType, threadCount ) => ( entityType ), 20 | //( threadId ) => new LimitedGrid3( 50_000, 50_000, 100, 10_000, 10_000, 300 ), 21 | ( threadId ) => 22 | { 23 | //THREAD TEXT/MARKER 24 | if( threadId == ENTITY_TYPE_MARKER || threadId == ENTITY_TYPE_TEXTLABEL ) 25 | { 26 | return new LimitedGrid3( 50_000, 50_000, 100, 10_000, 10_000, 500 ); 27 | } 28 | //THREAD OBJECT 29 | else if( threadId == ENTITY_TYPE_DYNAMIC_OBJECT ) 30 | { 31 | return new LimitedGrid3( 50_000, 50_000, 125, 10_000, 10_000, 400 ); 32 | } 33 | 34 | //THREAD WORLD OBJECT 35 | else if( threadId == ENTITY_TYPE_WORLD_OBJECT ) 36 | { 37 | return new LimitedGrid3( 50_000, 50_000, 125, 10_000, 10_000, 400 ); 38 | } 39 | 40 | else 41 | { 42 | return new LimitedGrid3( 50_000, 50_000, 175, 10_000, 10_000, 300 ); 43 | } 44 | }, 45 | new IdProvider( ) 46 | ); 47 | } 48 | } -------------------------------------------------------------------------------- /server/MarkerStreamer.cs: -------------------------------------------------------------------------------- 1 | using AltV.Net.Data; 2 | using AltV.Net.EntitySync; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Numerics; 6 | 7 | namespace AltV.Streamers; 8 | 9 | /// 10 | /// Marker types. 11 | /// 12 | public enum MarkerType 13 | { 14 | MarkerTypeUpsideDownCone = 0, 15 | MarkerTypeVerticalCylinder = 1, 16 | MarkerTypeThickChevronUp = 2, 17 | MarkerTypeThinChevronUp = 3, 18 | MarkerTypeCheckeredFlagRect = 4, 19 | MarkerTypeCheckeredFlagCircle = 5, 20 | MarkerTypeVerticleCircle = 6, 21 | MarkerTypePlaneModel = 7, 22 | MarkerTypeLostMCDark = 8, 23 | MarkerTypeLostMCLight = 9, 24 | MarkerTypeNumber0 = 10, 25 | MarkerTypeNumber1 = 11, 26 | MarkerTypeNumber2 = 12, 27 | MarkerTypeNumber3 = 13, 28 | MarkerTypeNumber4 = 14, 29 | MarkerTypeNumber5 = 15, 30 | MarkerTypeNumber6 = 16, 31 | MarkerTypeNumber7 = 17, 32 | MarkerTypeNumber8 = 18, 33 | MarkerTypeNumber9 = 19, 34 | MarkerTypeChevronUpx1 = 20, 35 | MarkerTypeChevronUpx2 = 21, 36 | MarkerTypeChevronUpx3 = 22, 37 | MarkerTypeHorizontalCircleFat = 23, 38 | MarkerTypeReplayIcon = 24, 39 | MarkerTypeHorizontalCircleSkinny = 25, 40 | MarkerTypeHorizontalCircleSkinny_Arrow = 26, 41 | MarkerTypeHorizontalSplitArrowCircle = 27, 42 | MarkerTypeDebugSphere = 28, 43 | MarkerTypeDallorSign = 29, 44 | MarkerTypeHorizontalBars = 30, 45 | MarkerTypeWolfHead = 31 46 | } 47 | 48 | #region DynamicMarker 49 | 50 | /// 51 | /// DynamicMarker class that stores all data related to a single marker. 52 | /// 53 | public class DynamicMarker : Entity, IEntity 54 | { 55 | private ulong EntityType 56 | { 57 | get 58 | { 59 | if( !TryGetData( "entityType", out ulong type ) ) 60 | return 999; 61 | 62 | return type; 63 | } 64 | set 65 | { 66 | // No data changed 67 | if( EntityType == value ) 68 | return; 69 | 70 | SetData( "entityType", value ); 71 | } 72 | } 73 | 74 | /// 75 | /// Set or get the current marker's rotation (in degrees). 76 | /// 77 | public Vector3 Rotation 78 | { 79 | get 80 | { 81 | if( !TryGetData( "rotation", out Dictionary data ) ) 82 | return default; 83 | 84 | return new Vector3() 85 | { 86 | X = Convert.ToSingle( data[ "x" ] ), 87 | Y = Convert.ToSingle( data[ "y" ] ), 88 | Z = Convert.ToSingle( data[ "z" ] ), 89 | }; 90 | } 91 | set 92 | { 93 | // No data changed 94 | if( Rotation.X == value.X && Rotation.Y == value.Y && Rotation.Z == value.Z && 95 | value != new Vector3( 0, 0, 0 ) ) 96 | return; 97 | 98 | Dictionary dict = new Dictionary() 99 | { 100 | [ "x" ] = value.X, 101 | [ "y" ] = value.Y, 102 | [ "z" ] = value.Z, 103 | }; 104 | SetData( "rotation", dict ); 105 | } 106 | } 107 | 108 | /// 109 | /// Set a texture dictionary, pass null to remove. 110 | /// 111 | public string TextureDict 112 | { 113 | get 114 | { 115 | if( !TryGetData( "textureDict", out string textureDict ) ) 116 | return null; 117 | 118 | return textureDict; 119 | } 120 | set 121 | { 122 | if( value == null ) 123 | { 124 | SetData( "textureDict", null ); 125 | return; 126 | } 127 | 128 | // No data changed 129 | if( TextureDict == value ) 130 | return; 131 | 132 | SetData( "textureDict", value ); 133 | } 134 | } 135 | 136 | /// 137 | /// Texture name, only applicable if TextureDict is set. pass null to reset value. 138 | /// 139 | public string TextureName 140 | { 141 | get 142 | { 143 | if( !TryGetData( "textureName", out string textureName ) ) 144 | return null; 145 | 146 | return textureName; 147 | } 148 | set 149 | { 150 | if( value == null ) 151 | { 152 | SetData( "textureName", null ); 153 | return; 154 | } 155 | 156 | // No data changed 157 | if( TextureName == value ) 158 | return; 159 | 160 | SetData( "textureName", value ); 161 | } 162 | } 163 | 164 | /// 165 | /// Whether the marker should rotate on the Y axis(heading). 166 | /// 167 | public bool? Rotate 168 | { 169 | get 170 | { 171 | if( !TryGetData( "rotate", out bool rotate ) ) 172 | return false; 173 | 174 | return rotate; 175 | } 176 | set 177 | { 178 | // if value is set to null, reset the data 179 | if( value == null ) 180 | { 181 | SetData( "rotate", false ); 182 | return; 183 | } 184 | 185 | // No data changed 186 | if( Rotate == value ) 187 | return; 188 | 189 | SetData( "rotate", value ); 190 | } 191 | } 192 | 193 | /// 194 | /// Whether the marker should be drawn onto the entity when they enter it. 195 | /// 196 | public bool? DrawOnEnter 197 | { 198 | get 199 | { 200 | if( !TryGetData( "drawOnEnter", out bool drawOnEnter ) ) 201 | return false; 202 | 203 | return drawOnEnter; 204 | } 205 | set 206 | { 207 | // if value is set to null, reset the data 208 | if( value == null ) 209 | { 210 | SetData( "drawOnEnter", false ); 211 | return; 212 | } 213 | 214 | // No data changed 215 | if( DrawOnEnter == value ) 216 | return; 217 | 218 | SetData( "drawOnEnter", value ); 219 | } 220 | } 221 | 222 | /// 223 | /// Whether the marker should rotate on the Y axis towards the player's camera. 224 | /// 225 | public bool? FaceCamera 226 | { 227 | get 228 | { 229 | if( !TryGetData( "faceCam", out bool faceCamera ) ) 230 | return false; 231 | 232 | return faceCamera; 233 | } 234 | set 235 | { 236 | // if value is set to null, reset the data 237 | if( value == null ) 238 | { 239 | SetData( "faceCam", false ); 240 | return; 241 | } 242 | 243 | // No data changed 244 | if( FaceCamera == value ) 245 | return; 246 | 247 | SetData( "faceCam", value ); 248 | } 249 | } 250 | 251 | /// 252 | /// Whether the marker should bob up and down. 253 | /// 254 | public bool? BobUpDown 255 | { 256 | get 257 | { 258 | if( !TryGetData( "bobUpDown", out bool bobUpDown ) ) 259 | return false; 260 | 261 | return bobUpDown; 262 | } 263 | set 264 | { 265 | // if value is set to null, reset the data 266 | if( value == null ) 267 | { 268 | SetData( "bobUpDown", false ); 269 | return; 270 | } 271 | 272 | // No data changed 273 | if( BobUpDown == value ) 274 | return; 275 | 276 | SetData( "bobUpDown", value ); 277 | } 278 | } 279 | 280 | /// 281 | /// Set scale of the marker. 282 | /// 283 | public Vector3 Scale 284 | { 285 | get 286 | { 287 | if( !TryGetData( "scale", out Dictionary data ) ) 288 | return default; 289 | 290 | return new Vector3() 291 | { 292 | X = Convert.ToSingle( data[ "x" ] ), 293 | Y = Convert.ToSingle( data[ "y" ] ), 294 | Z = Convert.ToSingle( data[ "z" ] ), 295 | }; 296 | } 297 | set 298 | { 299 | // No data changed 300 | if( Scale.X == value.X && Scale.Y == value.Y && Scale.Z == value.Z && value != new Vector3( 0, 0, 0 ) ) 301 | return; 302 | 303 | Dictionary dict = new Dictionary() 304 | { 305 | [ "x" ] = value.X, 306 | [ "y" ] = value.Y, 307 | [ "z" ] = value.Z, 308 | }; 309 | SetData( "scale", dict ); 310 | } 311 | } 312 | 313 | /// 314 | /// Represents a heading on each axis in which the marker should face, alternatively you can rotate each axis independently with Rotation and set Direction axis to 0. 315 | /// 316 | public Vector3 Direction 317 | { 318 | get 319 | { 320 | if( !TryGetData( "direction", out Dictionary data ) ) 321 | return default; 322 | 323 | return new Vector3() 324 | { 325 | X = Convert.ToSingle( data[ "x" ] ), 326 | Y = Convert.ToSingle( data[ "y" ] ), 327 | Z = Convert.ToSingle( data[ "z" ] ), 328 | }; 329 | } 330 | set 331 | { 332 | // No data changed 333 | if( Direction.X == value.X && Direction.Y == value.Y && Direction.Z == value.Z && 334 | value != new Vector3( 0, 0, 0 ) ) 335 | return; 336 | 337 | Dictionary dict = new Dictionary() 338 | { 339 | [ "x" ] = value.X, 340 | [ "y" ] = value.Y, 341 | [ "z" ] = value.Z, 342 | }; 343 | SetData( "direction", dict ); 344 | } 345 | } 346 | 347 | /// 348 | /// Set or get the current marker's type(see MarkerTypes enum). 349 | /// 350 | public MarkerType MarkerType 351 | { 352 | get 353 | { 354 | if( !TryGetData( "markerType", out int markerType ) ) 355 | return default; 356 | 357 | return ( MarkerType ) markerType; 358 | } 359 | set 360 | { 361 | // No data changed 362 | if( MarkerType == value ) 363 | return; 364 | 365 | SetData( "markerType", ( int ) value ); 366 | } 367 | } 368 | 369 | /// 370 | /// Set marker color. 371 | /// 372 | public Rgba? Color 373 | { 374 | get 375 | { 376 | if( !TryGetData( "color", out Dictionary data ) ) 377 | return null; 378 | 379 | return new Rgba( 380 | Convert.ToByte( data[ "r" ] ), 381 | Convert.ToByte( data[ "g" ] ), 382 | Convert.ToByte( data[ "b" ] ), 383 | Convert.ToByte( data[ "a" ] ) 384 | ); 385 | } 386 | set 387 | { 388 | // if value is set to null, reset the data 389 | if( value == null ) 390 | { 391 | SetData( "color", null ); 392 | return; 393 | } 394 | 395 | // No data changed 396 | if( Color != null && Color?.R == value?.R && Color?.G == value?.G && Color?.B == value?.B && 397 | Color?.A == value?.A ) 398 | return; 399 | 400 | Dictionary dict = new Dictionary 401 | { 402 | {"r", Convert.ToInt32( value?.R )}, 403 | {"g", Convert.ToInt32( value?.G )}, 404 | {"b", Convert.ToInt32( value?.B )}, 405 | {"a", Convert.ToInt32( value?.A )} 406 | }; 407 | 408 | SetData( "color", dict ); 409 | } 410 | } 411 | 412 | public DynamicMarker( Vector3 position, int dimension, uint range, ulong entityType ) : base( entityType, position, 413 | dimension, range ) 414 | { 415 | EntityType = entityType; 416 | } 417 | 418 | /// 419 | /// Destroy this marker. 420 | /// 421 | public void Destroy( ) 422 | { 423 | AltEntitySync.RemoveEntity( this ); 424 | } 425 | } 426 | 427 | #endregion 428 | 429 | #region MarkerStreamer 430 | 431 | public static class MarkerStreamer 432 | { 433 | /// 434 | /// Create a new dynamic marker 435 | /// 436 | /// The type of marker to spawn. 437 | /// The position at which the marker should spawn at. 438 | /// The scale of the marker. 439 | /// The rotation of the marker. 440 | /// The direction of the marker. 441 | /// The color of the marker. 442 | /// Whether the marker should bob up and down. 443 | /// Whether the marker should face the entity's camera. 444 | /// Whether the marker should rotate on the Y axis only. 445 | /// An optional texture dictionary to apply to the marker. 446 | /// An optional texture name to apply to the marker. 447 | /// Whether it should draw the marker onto an entity that intersects with it. 448 | /// The dimension of the marker 449 | /// Stream distance of the marker, default is 100. 450 | /// 451 | public static DynamicMarker CreateDynamicMarker( 452 | MarkerType markerType, Vector3 position, Vector3 scale, Vector3? rotation = null, Vector3? direction = null, 453 | Rgba? color = null, 454 | bool? bobUpDown = false, bool? faceCamera = false, bool? rotate = false, string textureDict = null, 455 | string textureName = null, 456 | bool? drawOnEnter = false, int dimension = 0, uint streamRange = 50 457 | ) 458 | { 459 | DynamicMarker marker = new DynamicMarker( position, dimension, streamRange, AltStreamers.ENTITY_TYPE_MARKER ) 460 | { 461 | Rotation = rotation ?? new Vector3( 0 ), 462 | MarkerType = markerType, 463 | Direction = direction ?? new Vector3( 0 ), 464 | Scale = scale, 465 | Color = color ?? null, 466 | BobUpDown = bobUpDown ?? null, 467 | FaceCamera = faceCamera ?? null, 468 | Rotate = rotate ?? null, 469 | TextureDict = textureDict ?? null, 470 | TextureName = textureName ?? null, 471 | DrawOnEnter = drawOnEnter ?? null 472 | }; 473 | AltEntitySync.AddEntity( marker ); 474 | return marker; 475 | } 476 | 477 | /// 478 | /// Destroy a dynamic marker by it's ID. 479 | /// 480 | /// The ID of the marker. 481 | /// True if successful, false otherwise. 482 | public static bool DestroyDynamicMarker( ulong dynamicMarkerId ) 483 | { 484 | DynamicMarker marker = GetDynamicMarker( dynamicMarkerId ); 485 | 486 | if( marker == null ) 487 | return false; 488 | 489 | AltEntitySync.RemoveEntity( marker ); 490 | return true; 491 | } 492 | 493 | /// 494 | /// Destroy a dynamic marker. 495 | /// 496 | /// The marker instance to destroy. 497 | public static void DestroyDynamicMarker( DynamicMarker marker ) 498 | { 499 | AltEntitySync.RemoveEntity( marker ); 500 | } 501 | 502 | /// 503 | /// Get a dynamic marker by it's ID. 504 | /// 505 | /// The ID of the marker. 506 | /// The dynamic marker or null if not found. 507 | public static DynamicMarker GetDynamicMarker( ulong dynamicMarkerId ) 508 | { 509 | if( !AltEntitySync.TryGetEntity( dynamicMarkerId, 0, out IEntity entity ) ) 510 | { 511 | Console.WriteLine( 512 | $"[MARKER-STREAMER] [GetDynamicMarker] ERROR: Entity with ID {dynamicMarkerId} couldn't be found." ); 513 | return null; 514 | } 515 | 516 | if( !( entity is DynamicMarker ) ) 517 | return null; 518 | 519 | return ( DynamicMarker ) entity; 520 | } 521 | 522 | /// 523 | /// Destroy all created dynamic markers. 524 | /// 525 | public static void DestroyAllDynamicMarkers( ) 526 | { 527 | foreach( DynamicMarker marker in GetAllDynamicMarkers() ) 528 | { 529 | AltEntitySync.RemoveEntity( marker ); 530 | } 531 | } 532 | 533 | /// 534 | /// Get all created dynamic markers. 535 | /// 536 | /// A list of dynamic markers. 537 | public static List GetAllDynamicMarkers( ) 538 | { 539 | List markers = new List(); 540 | 541 | foreach( IEntity entity in AltEntitySync.GetAllEntities() ) 542 | { 543 | if( entity.Type != AltStreamers.ENTITY_TYPE_MARKER ) 544 | continue; 545 | 546 | DynamicMarker obj = GetDynamicMarker( entity.Id ); 547 | 548 | if( obj != null ) 549 | markers.Add( obj ); 550 | } 551 | 552 | return markers; 553 | } 554 | } 555 | 556 | #endregion -------------------------------------------------------------------------------- /server/ObjectStreamer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AltV.Net; 3 | using AltV.Net.EntitySync; 4 | using System.Collections.Generic; 5 | using System.Numerics; 6 | 7 | namespace AltV.Streamers; 8 | 9 | public enum TextureVariation 10 | { 11 | Pacific = 0, 12 | Azure = 1, 13 | Nautical = 2, 14 | Continental = 3, 15 | Battleship = 4, 16 | Intrepid = 5, 17 | Uniform = 6, 18 | Classico = 7, 19 | Mediterranean = 8, 20 | Command = 9, 21 | Mariner = 10, 22 | Ruby = 11, 23 | Vintage = 12, 24 | Pristine = 13, 25 | Merchant = 14, 26 | Voyager = 15 27 | } 28 | 29 | public class Rgb : IWritable 30 | { 31 | public int Red { get; set; } 32 | public int Green { get; set; } 33 | public int Blue { get; set; } 34 | 35 | public Rgb( int red, int green, int blue ) 36 | { 37 | Red = red; 38 | Green = green; 39 | Blue = blue; 40 | } 41 | 42 | public void OnWrite( IMValueWriter writer ) 43 | { 44 | writer.BeginObject(); 45 | writer.Name( "Red" ); 46 | writer.Value( Red ); 47 | writer.Name( "Green" ); 48 | writer.Value( Green ); 49 | writer.Name( "Blue" ); 50 | writer.Value( Blue ); 51 | writer.EndObject(); 52 | } 53 | } 54 | 55 | public static class ObjectStreamer 56 | { 57 | /// 58 | /// Create a new dynamic object. 59 | /// 60 | /// The object model name. 61 | /// The position to spawn the object at. 62 | /// The rotation to spawn the object at(degrees). 63 | /// The dimension to spawn the object in. 64 | /// (Optional): Set object dynamic or not. 65 | /// (Optional): Set object frozen. 66 | /// (Optional): Set LOD distance. 67 | /// (Optional): set light color. 68 | /// (Optional): set object on fire(DOESN'T WORK PROPERLY YET!) 69 | /// (Optional): Set object texture variation. 70 | /// (Optional): Set object visibility. 71 | /// (Optional): The range that a player has to be in before the object spawns, default value is 400. 72 | /// The newly created dynamic object 73 | public static DynamicObject CreateDynamicObject( 74 | string model, Vector3 position, Vector3 rotation, int dimension = 0, bool isDynamic = false, bool frozen = true, 75 | uint? lodDistance = null, 76 | Rgb lightColor = null, bool onFire = false, TextureVariation? textureVariation = null, bool visible = true, 77 | uint streamRange = 150 78 | ) 79 | { 80 | DynamicObject obj = new DynamicObject( position, rotation, dimension, streamRange, AltStreamers.ENTITY_TYPE_DYNAMIC_OBJECT ) 81 | { 82 | Model = model, 83 | Dynamic = isDynamic, 84 | Frozen = frozen, 85 | LodDistance = lodDistance ?? null, 86 | LightColor = lightColor ?? null, 87 | OnFire = onFire, 88 | TextureVariation = textureVariation ?? null, 89 | Visible = visible 90 | }; 91 | 92 | AltEntitySync.AddEntity( obj ); 93 | return obj; 94 | } 95 | 96 | public static WorldObject DeleteWorldObject( string model, Vector3 position, float radius = 5, uint range = 50, bool visible = false ) 97 | { 98 | WorldObject obj = new WorldObject( model, position, range, radius, visible, AltStreamers.ENTITY_TYPE_WORLD_OBJECT ); 99 | AltEntitySync.AddEntity( obj ); 100 | return obj; 101 | 102 | } 103 | 104 | /// 105 | /// Destroy a dynamic object. 106 | /// 107 | /// The object instance to destroy 108 | /// 109 | public static bool DestroyDynamicObject( DynamicObject obj ) 110 | { 111 | AltEntitySync.RemoveEntity( obj ); 112 | return true; 113 | } 114 | 115 | /// 116 | /// Get a dynamic object by it's ID. 117 | /// 118 | /// The ID of the entity. 119 | /// The dynamic object or null if not found. 120 | public static T GetDynamicObjectByEntityId( ulong entityId ) 121 | { 122 | if( !AltEntitySync.TryGetEntity( entityId, AltStreamers.ENTITY_TYPE_DYNAMIC_OBJECT, out IEntity entity ) ) 123 | { 124 | Console.WriteLine( $"[OBJECT-STREAMER] [GetDynamicObjectByEntityId] ERROR: Entity with ID {entityId} couldn't be found." ); 125 | return default; 126 | } 127 | 128 | if( !( entity is T ) ) 129 | return default; 130 | 131 | return ( T ) entity; 132 | } 133 | 134 | /// 135 | /// Destroy all created dynamic objects. 136 | /// 137 | public static void DestroyAllDynamicObjects( ) 138 | { 139 | foreach( T obj in GetAllDynamicObjects() ) 140 | { 141 | AltEntitySync.RemoveEntity( ( IEntity ) obj ); 142 | } 143 | } 144 | 145 | /// 146 | /// Get all created dynamic objects. 147 | /// 148 | /// A list of dynamic objects. 149 | public static List GetAllDynamicObjects( ) 150 | { 151 | List objects = new List(); 152 | 153 | foreach( IEntity entity in AltEntitySync.GetAllEntities() ) 154 | { 155 | if( entity.Type != AltStreamers.ENTITY_TYPE_DYNAMIC_OBJECT ) 156 | continue; 157 | 158 | T obj = GetDynamicObjectByEntityId( entity.Id ); 159 | 160 | if( obj != null ) 161 | objects.Add( obj ); 162 | } 163 | 164 | return objects; 165 | } 166 | 167 | public static (T obj, float distance) GetClosestDynamicObjectOfType( Vector3 pos ) 168 | { 169 | T obj = default; 170 | float distance = 5000; 171 | 172 | foreach( T o in GetAllDynamicObjects() ) 173 | { 174 | if( o is not T ) 175 | continue; 176 | 177 | float dist = Vector3.Distance( ( ( IEntity ) o ).Position, pos ); 178 | 179 | if( dist < distance ) 180 | { 181 | obj = o; 182 | distance = dist; 183 | } 184 | } 185 | 186 | return ( obj, distance ); 187 | } 188 | } -------------------------------------------------------------------------------- /server/TextLabelStreamer.cs: -------------------------------------------------------------------------------- 1 | using AltV.Net.Data; 2 | using AltV.Net.EntitySync; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Numerics; 6 | 7 | namespace AltV.Streamers; 8 | 9 | /// 10 | /// DynamicTextLabel class that stores all data related to a single textlabel 11 | /// 12 | public class DynamicTextLabel : Entity 13 | { 14 | private ulong EntityType 15 | { 16 | get 17 | { 18 | if( !TryGetData( "entityType", out ulong type ) ) 19 | return 999; 20 | 21 | return type; 22 | } 23 | set 24 | { 25 | // No data changed 26 | if( EntityType == value ) 27 | return; 28 | 29 | SetData( "entityType", value ); 30 | } 31 | } 32 | 33 | /// 34 | /// Set/get or get the current textlabel's scale. 35 | /// 36 | public float? Scale 37 | { 38 | get 39 | { 40 | if( !TryGetData( "scale", out float scale ) ) 41 | return null; 42 | 43 | return scale; 44 | } 45 | set { SetData( "scale", value ); } 46 | } 47 | 48 | /// 49 | /// Set/get the textlabel's text. 50 | /// 51 | public string Text 52 | { 53 | get 54 | { 55 | if( !TryGetData( "text", out string text ) ) 56 | return null; 57 | 58 | return text; 59 | } 60 | set { SetData( "text", value ); } 61 | } 62 | 63 | /// 64 | /// Set/get textlabel's color. 65 | /// 66 | public Rgba Color 67 | { 68 | get 69 | { 70 | if( !TryGetData( "color", out Dictionary data ) ) 71 | return default; 72 | 73 | return new Rgba() 74 | { 75 | R = Convert.ToByte( data[ "r" ] ), 76 | G = Convert.ToByte( data[ "g" ] ), 77 | B = Convert.ToByte( data[ "b" ] ), 78 | A = Convert.ToByte( data[ "a" ] ), 79 | }; 80 | } 81 | set 82 | { 83 | // No data changed 84 | if( Color.R == value.R && Color.G == value.G && Color.B == value.B && Color.A == value.A ) 85 | return; 86 | 87 | Dictionary dict = new Dictionary() 88 | { 89 | [ "r" ] = Convert.ToInt32( value.R ), 90 | [ "g" ] = Convert.ToInt32( value.G ), 91 | [ "b" ] = Convert.ToInt32( value.B ), 92 | [ "a" ] = Convert.ToInt32( value.A ), 93 | }; 94 | SetData( "color", dict ); 95 | } 96 | } 97 | 98 | public DynamicTextLabel( Vector3 position, int dimension, uint range, ulong entityType ) : base( entityType, 99 | position, dimension, range ) 100 | { 101 | EntityType = entityType; 102 | } 103 | 104 | /// 105 | /// Destroy this textlabel. 106 | /// 107 | public void Destroy( ) 108 | { 109 | AltEntitySync.RemoveEntity( this ); 110 | } 111 | } 112 | 113 | public static class TextLabelStreamer 114 | { 115 | /// 116 | /// Create a new dynamic textlabel. 117 | /// 118 | /// The text to be displayed. 119 | /// The position to spawn it at. 120 | /// The dimension to spawn it in. 121 | /// The color of the textlabel. 122 | /// The scale of the textlabel. 123 | /// Stream range, default is 30. 124 | /// The newly created dynamic textlabel. 125 | public static DynamicTextLabel CreateDynamicTextLabel( 126 | string text, Vector3 position, int dimension = 0, Rgba? color = null, int? scale = null, uint streamRange = 25 127 | ) 128 | { 129 | DynamicTextLabel textLabel = 130 | new DynamicTextLabel( position, dimension, streamRange, AltStreamers.ENTITY_TYPE_TEXTLABEL ) 131 | { 132 | Color = color ?? new Rgba( 255, 255, 255, 255 ), 133 | Text = text, 134 | Scale = scale ?? 1 135 | }; 136 | 137 | AltEntitySync.AddEntity( textLabel ); 138 | return textLabel; 139 | } 140 | 141 | /// 142 | /// Destroy a dynamic text label by it's ID. 143 | /// 144 | /// The ID of the text label. 145 | /// True if successful, false otherwise. 146 | public static bool DestroyDynamicTextLabel( ulong dynamicTextLabelId ) 147 | { 148 | DynamicTextLabel obj = GetDynamicTextLabel( dynamicTextLabelId ); 149 | 150 | if( obj == null ) 151 | return false; 152 | 153 | AltEntitySync.RemoveEntity( obj ); 154 | return true; 155 | } 156 | 157 | /// 158 | /// Destroy a dynamic text label. 159 | /// 160 | /// The text label instance to destroy. 161 | public static void DestroyDynamicTextLabel( DynamicTextLabel dynamicTextLabel ) 162 | { 163 | AltEntitySync.RemoveEntity( dynamicTextLabel ); 164 | } 165 | 166 | /// 167 | /// Get a dynamic text label by it's ID. 168 | /// 169 | /// The ID of the textlabel. 170 | /// The dynamic textlabel or null if not found. 171 | public static DynamicTextLabel GetDynamicTextLabel( ulong dynamicTextLabelId ) 172 | { 173 | if( !AltEntitySync.TryGetEntity( dynamicTextLabelId, 1, out IEntity entity ) ) 174 | { 175 | Console.WriteLine( 176 | $"[TEXTLABEL-STREAMER] [GetDynamicTextLabel] ERROR: Entity with ID {dynamicTextLabelId} couldn't be found." ); 177 | return null; 178 | } 179 | 180 | return ( DynamicTextLabel ) entity; 181 | } 182 | 183 | /// 184 | /// Destroy all created dynamic textlabels. 185 | /// 186 | public static void DestroyAllDynamicTextLabels( ) 187 | { 188 | foreach( DynamicTextLabel obj in GetAllDynamicTextLabels() ) 189 | { 190 | AltEntitySync.RemoveEntity( obj ); 191 | } 192 | } 193 | 194 | /// 195 | /// Get all created dynamic textlabels. 196 | /// 197 | /// A list of dynamic textlabels. 198 | public static List GetAllDynamicTextLabels( ) 199 | { 200 | List textLabels = new List(); 201 | 202 | foreach( IEntity entity in AltEntitySync.GetAllEntities() ) 203 | { 204 | if( entity.Type != AltStreamers.ENTITY_TYPE_TEXTLABEL ) 205 | continue; 206 | 207 | DynamicTextLabel textLabel = GetDynamicTextLabel( entity.Id ); 208 | 209 | if( textLabel != null ) 210 | textLabels.Add( textLabel ); 211 | } 212 | 213 | return textLabels; 214 | } 215 | } -------------------------------------------------------------------------------- /server/WorldObject.cs: -------------------------------------------------------------------------------- 1 | using AltV.Net.EntitySync; 2 | using System.Numerics; 3 | 4 | namespace AltV.Streamers 5 | { 6 | public class WorldObject : Entity, IEntity 7 | { 8 | /// 9 | /// The model of the object to search for 10 | /// 11 | public string Model 12 | { 13 | get 14 | { 15 | if( !TryGetData( "model", out string model ) ) 16 | return null; 17 | 18 | return model; 19 | } 20 | private set 21 | { 22 | // No data changed 23 | if( Model == value ) 24 | return; 25 | 26 | SetData( "model", value ); 27 | } 28 | } 29 | 30 | /// 31 | /// The radius in which to search for the object to be deleted 32 | /// 33 | public float Radius 34 | { 35 | get 36 | { 37 | if( !TryGetData( "radius", out uint radius ) ) 38 | return 0; 39 | 40 | return radius; 41 | } 42 | private set 43 | { 44 | SetData( "radius", value ); 45 | } 46 | } 47 | 48 | /// 49 | /// The radius in which to search for the object to be deleted 50 | /// 51 | public bool Visible 52 | { 53 | get 54 | { 55 | if( !TryGetData( "visible", out bool visible ) ) 56 | return true; 57 | 58 | return visible; 59 | } 60 | set 61 | { 62 | SetData( "visible", value ); 63 | } 64 | } 65 | 66 | public WorldObject( string model, Vector3 position, uint range, float radius, bool visible, ulong entityType ) : base( entityType, position, 0, range ) 67 | { 68 | Model = model; 69 | Radius = radius; 70 | Visible = visible; 71 | } 72 | 73 | /// 74 | /// Restore the world object. 75 | /// 76 | public void Restore( ) 77 | { 78 | AltEntitySync.RemoveEntity( this ); 79 | } 80 | } 81 | } 82 | --------------------------------------------------------------------------------