diff --git a/docs/angelscript/game/client-examples/convar-ref.md b/docs/angelscript/game/client-examples/convar-ref.md new file mode 100644 index 00000000..ebd343f6 --- /dev/null +++ b/docs/angelscript/game/client-examples/convar-ref.md @@ -0,0 +1,27 @@ +--- +title: ConVar Reference +weight: 10 +--- + +# ConVar Reference + +This script demonstrates ConVar refences. These are the preferred way to interact with ConVars, and the only way to interact with ones registered outside of your script. + +```as +[ClientCommand("cl_example_cvarref")] +void MyCvarRefDemo(const CommandArgs@ args) +{ + ConVarRef intensity("r_portal_light_intensity"); + + Msg("is r_protal_light_intensity valid? " + intensity.GetBool() + "\n"); + Msg("current val: " + intensity.GetFloat() + "\n"); + + intensity.SetValue(1); + Msg("New val: " + intensity.GetFloat() + "\n"); + + ConVarRef invalid_cvar("my_invalid_thingy"); + Msg("is my_invalid_thingy valid? " + invalid_cvar.IsValid() + "\n"); +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/client/cvar_ref.as) diff --git a/docs/angelscript/game/client-examples/meta.json b/docs/angelscript/game/client-examples/meta.json new file mode 100644 index 00000000..e16b8a47 --- /dev/null +++ b/docs/angelscript/game/client-examples/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Client Examples", + "weight": 10 +} diff --git a/docs/angelscript/game/client-examples/persistant-storage.md b/docs/angelscript/game/client-examples/persistant-storage.md new file mode 100644 index 00000000..4aa3b0ea --- /dev/null +++ b/docs/angelscript/game/client-examples/persistant-storage.md @@ -0,0 +1,47 @@ +--- +title: Persistant Storage +weight: 20 +--- + +# Persistant Storage + +This script demonstrates how to use the persistent storage API. This implementation closely mirrors the VScript implementation, and the two scripting systems share a backend. + +This system may be used to store data in a common area where both VScript and AngelScript can access it. + +> [!NOTE] +> This data is NOT networked and is only stored locally! + +```as +[ClientCommand("cl_example_storage_show", "Example of how to show script storage data")] +void ShowScriptStorage(CommandArgs@ args) +{ + // Create a storage scope that references "myTest" + StorageScope s("myTest"); + + // Display the values + Msg("int " + s.GetInt("int") + "\n"); + Msg("float " + s.GetFloat("float") + "\n"); + Msg("string " + s.GetString("string") + "\n"); +} + +[ClientCommand("cl_example_storage_set", "Example of how to set script storage")] +void SetScriptStroage(CommandArgs@ args) +{ + // Set the values. These will persist across map loads and game restarts, until set or cleared again + StorageScope s("myTest"); + s.SetInt("int", 1234); + s.SetFloat("float", 21.25); + s.SetString("string", "Hello world"); +} + +[ClientCommand("cl_example_storage_clear", "Clear stuff")] +void ScriptStorageClear(CommandArgs@ args) +{ + // Clear all entries in the myTest storage scope + StorageScope s("myTest"); + s.ClearAll(); +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/client/persistent_storage.as) diff --git a/docs/angelscript/game/examples.md b/docs/angelscript/game/examples.md new file mode 100644 index 00000000..b0e392d5 --- /dev/null +++ b/docs/angelscript/game/examples.md @@ -0,0 +1,36 @@ +--- +title: Examples +weight: 10 +--- + +# Examples + +This page contains a list of examples on how to use AngelScript with Strata Source games themselves. + +To use the examples, create a new file inside the `(game folder)/code` folder (create the folder if it does not exist yet). `game folder` is Strata Source game sepecific, example for Portal 2: Community Edition: `p2ce`. The scripts have to be saved with the extension `.as`. + +Below are examples covering several topics implemented into the latest (as of `5114609d`) Strata Source version for Portal 2: Community Edition. These examples originated from the [StrataSource/sample-content](https://github.com/StrataSource/sample-content) repository and can also be viewed from there under the `code` folder. + +If you don't understand the difference between `Client`, `Server`, and `Shared`, please check out "Client - Server model"(../guide/chapter1#client---server-model)(FIX ME WHEN GUIDE PUSHED!) section in the Beginner's Guide. + +## Client + +### [ConVar Reference](./client-examples/convar-ref) + +### [Persistant Storage](./client-examples/persistant-storage) + +## Server + +### [Entity Iteratiors](./server-examples/entity-iterators) + +### [Custom Entity](./server-examples/custom-entity) + +### [Game Event System](./server-examples/game-event-system) + +### [Physics Object](./server-examples/physics-object) + +## Shared + +### [Custom Commands](./shared-examples/custom-commands) + +### [Core Event Types](./shared-examples/core-events) diff --git a/docs/angelscript/game/meta.json b/docs/angelscript/game/meta.json index 45754fe1..3d2afe48 100644 --- a/docs/angelscript/game/meta.json +++ b/docs/angelscript/game/meta.json @@ -1,5 +1,4 @@ { "title": "Game", - "type": "angelscript", - "weight": 0 + "weight": 10 } diff --git a/docs/angelscript/game/server-examples/custom-entity.md b/docs/angelscript/game/server-examples/custom-entity.md new file mode 100644 index 00000000..482acef4 --- /dev/null +++ b/docs/angelscript/game/server-examples/custom-entity.md @@ -0,0 +1,55 @@ +--- +title: Custom Entity +weight: 20 +--- + +# Custom Entity + +This script demonstrates a custom entity that spawns itself and removes itself when an input is triggered. + +> [!WARNING] +> As of writing for current Strata Source version `5114609d`, outputs for entities are not currently implemented and will not work if defined. + +```as +[Entity("prop_remove_self")] +class PropRemoveSelf : CBaseAnimating +{ + string m_szModelName = "models/gibs/airboat_broken_engine.mdl"; + + void Precache() override + { + PrecacheModel( m_szModelName ); + } + + void Spawn() override + { + Precache(); + SetModel( m_szModelName ); + + SetSolid( SOLID_BBOX ); + + Vector vBounds = Vector( 20, 20, 20 ); + SetCollisionBounds( -vBounds, vBounds ); + } + + [Input("UtilRemove")] + void InputUtilRemove( const InputData &in data ) + { + Msg("Removing ourselves\n"); + + CBaseAnimating@ anim = cast(this); + CBaseEntity@ ent = cast(anim); + util::Remove(ent); + } + + [Input("ClassRemove")] + void InputClassRemove( const InputData &in data ) + { + Msg("Removing ourselves\n"); + + Remove(); + } +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/server/entity_remove.as) diff --git a/docs/angelscript/game/server-examples/entity-iterators.md b/docs/angelscript/game/server-examples/entity-iterators.md new file mode 100644 index 00000000..13d90788 --- /dev/null +++ b/docs/angelscript/game/server-examples/entity-iterators.md @@ -0,0 +1,48 @@ +--- +title: Entity Iteratiors +weight: 10 +--- + +# Entity Iteratiors + +This script demonstrates entity iterators. This system is nearly identical to the VScript system, except that the global object is named differently. + +```as +[ServerCommand("sv_test_entity_iterator", "")] +void EntityIteratorExample(CommandArgs@ args) +{ + // Print a list of all func_brushes in the map + Msg("All func_brushes in this map:\n"); + for (auto@ ent = EntityList().First(); @ent != null; @ent = EntityList().Next(ent)) { + if (ent.GetClassname() != "func_brush") + continue; + Msg(" " + ent.GetEntityIndex() + ": " + ent.GetClassname() + " " + ent.GetDebugName() + "\n"); + } + + // Find the player entity to base our search on + auto@ player = EntityList().FindByClassname(null, "player"); + + if (@player != null) { + Msg("Entities within 128 units of the player:\n"); + + // Search through all entities within 128 units of the player. + // note that we're repeatedly calling FindInSphere, and not using Next() + CBaseEntity@ ent = null; + while ((@ent = EntityList().FindInSphere(ent, player.GetAbsOrigin(), 128)) != null) { + Msg(" " + ent.GetClassname() + " " + ent.GetDebugName() + "\n"); + } + + // Search for func_brush entities within 2048 units of the player + Msg("func_brush entities within 2048 units of the player:\n"); + @ent = null; + while ((@ent = EntityList().FindByClassnameWithin(ent, "func_brush", player.GetAbsOrigin(), 2048)) != null) { + Msg(" " + ent.GetClassname() + " " + ent.GetDebugName() + "\n"); + } + } + else { + Msg("Unable to find player entity\n"); + } +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/server/entity_iterator.as) diff --git a/docs/angelscript/game/server-examples/game-event-system.md b/docs/angelscript/game/server-examples/game-event-system.md new file mode 100644 index 00000000..567baaeb --- /dev/null +++ b/docs/angelscript/game/server-examples/game-event-system.md @@ -0,0 +1,63 @@ +--- +title: Game Event System +weight: 30 +--- + +# Game Event System + +This script demonstrates how to use the GameEventManager system to fire and listen for game events. + +Game events are optionally networked and are ordinarily used to communicate server data to the client for display on the UI. + +Event networking is unidirectional, always going from server -> client. Events fired on the client-side are not sent to the server. Events on the server may also be fired with the 'bBroadcast' parameter set to false to prevent them from being networked. + +```as +[ServerCommand("sv_firegameevent_server", "")] +void sv_firegameevent_server(const CommandArgs@ args) +{ + GameEvent@ event = GameEventManager().CreateEvent("player_spawn"); + + event.SetBool("BoolValue", true); + event.SetInt("IntValue", 42); + event.SetUint64("UInt64Value", 18446744073709551615); + event.SetFloat("FloatValue", 3.141592); + event.SetString("StringValue", "suspicious imposter"); + + GameEventManager().FireEvent(event); +} + +[ServerCommand("sv_firegameevent_client", "")] +void sv_firegameevent_client(const CommandArgs@ args) +{ + GameEvent@ event = GameEventManager().CreateEvent("player_spawn"); + + event.SetBool("BoolValue", true); + event.SetInt("IntValue", 42); + event.SetUint64("UInt64Value", 18446744073709551615); + event.SetFloat("FloatValue", 3.141592); + event.SetString("StringValue", "suspicious imposter"); + + GameEventManager().FireEventClientSide(event); +} + +[GameEvent("player_spawn")] +void OnPlayerSpawn(const GameEvent@ event) +{ + Msg("Player spawned got fired\n"); + + Msg("We got bool value of: " + event.GetBool("BoolValue") + "\n"); + Msg("We got int value of: " + event.GetInt("IntValue") + "\n"); + Msg("We got uint64 value of: " + event.GetUint64("UInt64Value") + "\n"); + Msg("We got float value of: " + event.GetFloat("FloatValue") + "\n"); + Msg("We got string value of: " + event.GetString("StringValue") + "\n"); + + + Msg("Should be empty: " + event.IsEmpty("DoesNotExistAtAll") + "\n"); + Msg("Should be not empty: " + event.IsEmpty("BoolValue") + "\n"); + + Msg("Is Reliable: " + event.IsReliable() + "\n"); + Msg("Is Local: " + event.IsLocal() + "\n"); +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/server/game_event_system.as) diff --git a/docs/angelscript/game/server-examples/meta.json b/docs/angelscript/game/server-examples/meta.json new file mode 100644 index 00000000..b6f66763 --- /dev/null +++ b/docs/angelscript/game/server-examples/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Server Examples", + "weight": 20 +} diff --git a/docs/angelscript/game/server-examples/physics-object.md b/docs/angelscript/game/server-examples/physics-object.md new file mode 100644 index 00000000..0ff4751d --- /dev/null +++ b/docs/angelscript/game/server-examples/physics-object.md @@ -0,0 +1,31 @@ +--- +title: Physics Object +weight: 40 +--- + +# Physics Object + +This script demonstrates how to access and modify physics objects. + +```as +// Applies a random impulse to cubes when you trip and stub your toe +[GameEvent("player_hurt")] +void MyCommand(const GameEvent@ event) +{ + // Find all prop_weighted_cube + CBaseEntity@ ent = null; + while ((@ent = EntityList().FindByClassname(ent, "prop_weighted_cube")) != null) { + Msg("Bumped cube " + ent.GetDebugName() + "\n"); + auto@ obj = ent.GetPhysicsObject(); + if (@obj != null) { + // Wake the object; cubes will go to sleep when powered by a laser or after chillin for a while. + obj.Wake(); + + // Apply random velocity and angular impulse + obj.AddVelocity(RandomVector(-2000, 2000), RandomVector(-5000, 5000)); + } + } +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/server/physics_object.as) diff --git a/docs/angelscript/game/shared-examples/core-events.md b/docs/angelscript/game/shared-examples/core-events.md new file mode 100644 index 00000000..bfb42adc --- /dev/null +++ b/docs/angelscript/game/shared-examples/core-events.md @@ -0,0 +1,36 @@ +--- +title: Core Event Types +weight: 20 +--- + +# Core Event Types + +This script demonstrates/tests various core event types. These are invoked during the game init process. + +```as +[LevelInitPreEntity] +void OnLevelInitPreEntity() +{ + Msg("level init pre-entity\n"); +} + +[LevelInitPostEntity] +void OnLevelInitPostEntity() +{ + Msg("level init post-entity\n"); +} + +[LevelShutdownPreEntity] +void OnLevelShutdownPreEntity() +{ + Msg("Level shutdown pre-entity\n"); +} + +[LevelShutdownPostEntity] +void OnLevelShutdownPostEntity() +{ + Msg("Level shutdown post-entity\n"); +} +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/shared/init_events.as) diff --git a/docs/angelscript/game/shared-examples/custom-commands.md b/docs/angelscript/game/shared-examples/custom-commands.md new file mode 100644 index 00000000..7299ea24 --- /dev/null +++ b/docs/angelscript/game/shared-examples/custom-commands.md @@ -0,0 +1,31 @@ +--- +title: Custom Commands +weight: 10 +--- + +# Custom Commands + +This script demonstrates how to use ServerCommand and ClientCommand attributes to register custom commands. + +```as +#if SERVER +[ServerCommand("sv_example_server_command", "A fun and awesome server command")] +void MyCommand(const CommandArgs@ args) +{ + Msg("This is my server command, called from the server\n"); +} +#endif + +#if CLIENT +[ClientCommand("cl_example_client_command", "A fun and awesome cheat client command", FCVAR_CHEAT)] +void MyClientCommand(const CommandArgs@ args) +{ + if (args.ArgC() < 2) + Msg("Woah, pass more args to see something epic!"); + else + Msg("Arg0 " + args.Arg(0) + ", Arg1 " + args.Arg(1)); +} +#endif +``` + +[Link to Original `sample-content` Example File](https://github.com/StrataSource/sample-content/blob/main/code/shared/custom_commands.as) diff --git a/docs/angelscript/game/shared-examples/meta.json b/docs/angelscript/game/shared-examples/meta.json new file mode 100644 index 00000000..4fc701a8 --- /dev/null +++ b/docs/angelscript/game/shared-examples/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Shared Examples", + "weight": 30 +} diff --git a/docs/angelscript/hammer/classes.md b/docs/angelscript/hammer/classes.md index 65bded1b..118fa44d 100644 --- a/docs/angelscript/hammer/classes.md +++ b/docs/angelscript/hammer/classes.md @@ -1,5 +1,6 @@ --- title: Classes +weight: 20 --- # Classes diff --git a/docs/angelscript/hammer/enums.md b/docs/angelscript/hammer/enums.md index 940f0d3c..38a9d22b 100644 --- a/docs/angelscript/hammer/enums.md +++ b/docs/angelscript/hammer/enums.md @@ -1,5 +1,6 @@ --- title: Enums +weight: 30 --- # Enums diff --git a/docs/angelscript/hammer/examples.md b/docs/angelscript/hammer/examples.md new file mode 100644 index 00000000..60bceea2 --- /dev/null +++ b/docs/angelscript/hammer/examples.md @@ -0,0 +1,14 @@ +--- +title: Hammer Examples +weight: 10 +--- + +# Hammer Examples + +This page contains various examples of how to use AngelScript to create new brush types in the Strata Hammer Editor. + +To use the examples, create a new file inside the `hammer/scripts` folder (create the folder if it does not exist yet). The scripts have to be saved with the extension `.as`. Afterwards, the new brush types can be used by first selecting the `Block Tool` within Hammer and then changing the `Categories` combo-box in the right bar to `Scriptable`. The combo-box `Objects` below then contains the new scripted brushes. + +## [Example Wedge](./examples/wedge) + +## [Example Spike](./examples/spike) diff --git a/docs/angelscript/hammer/examples/meta.json b/docs/angelscript/hammer/examples/meta.json new file mode 100644 index 00000000..45723bb7 --- /dev/null +++ b/docs/angelscript/hammer/examples/meta.json @@ -0,0 +1,4 @@ +{ + "title": "Hammer Examples", + "weight": 20 +} diff --git a/docs/angelscript/hammer/examples/spike.md b/docs/angelscript/hammer/examples/spike.md new file mode 100644 index 00000000..377ed125 --- /dev/null +++ b/docs/angelscript/hammer/examples/spike.md @@ -0,0 +1,173 @@ +--- +title: Example Spike +weight: 20 +--- + +# Example Spike (`script_spike.as`) + +```as +[Solid("script_spike")] +class ExampleSpike : ScriptSolid +{ + GUIData[]@ GetGuiData() const + { + return { GUIData( Label, "Spike" ), GUIData( Divider ), GUIData( TextBox, "Sides", 4 ) }; // Script gui layout + } + + void GuiUpdated(const dictionary@ dict) + { + sides = int(dict["Sides"]); // Value is stored with the same name as TextBox + if (sides < 3) + sides = 3; + print("new side count: " + sides); + } + + float DEG2RAD( float ang ) + { + return ang * (3.14159265358979323846 / 180.f); + } + + void polyMake( float x1, float y1, float x2, float y2, int npoints, float start_ang, Vector[]@ pmPoints ) + { + int point; + float angle = start_ang, angle_delta = 360.0f / float(npoints); + float xrad = (x2-x1) / 2, yrad = (y2-y1) / 2; + + // make centerpoint for polygon: + float xCenter = x1 + xrad; + float yCenter = y1 + yrad; + + for( point = 0; point < npoints; point++, angle += angle_delta ) + { + if( angle > 360 ) + angle -= 360; + + pmPoints[point][0] = /*rint*/(xCenter + (sin(DEG2RAD(angle)) * xrad)); + pmPoints[point][1] = /*rint*/(yCenter + (cos(DEG2RAD(angle)) * yrad)); + } + + pmPoints[point][0] = pmPoints[0][0]; + pmPoints[point][1] = pmPoints[0][1]; + } + + CMapClass@ CreateMapSolid( const BoundBox@ box, TextureAlignment align ) + { + float fWidth = (box.maxs[0] - box.mins[0]) / 2; + float fDepth = (box.maxs[1] - box.mins[1]) / 2; + float fHeight = (box.maxs[2] - box.mins[2]) / 2; + print("Sides: " + sides + "; Width: " + fWidth + "; Depth: " + fDepth + "; Height: " + fHeight); + + Vector origin; + box.GetBoundsCenter(origin); + + Vector[] pmPoints; + pmPoints.resize(64); + polyMake(origin[0] - fWidth, origin[1] - fDepth, origin[0] + fWidth, origin[1] + fDepth, sides, 0, pmPoints); + + CMapFace NewFace; + CMapSolid@ pSolid = CMapSolid(); + + for(int i = 0; i < sides+1; i++) + { + // YWB rounding??? + pmPoints[i][2] = /*rint*/(origin[2] - fHeight); + } + + NewFace.CreateFace(pmPoints, -sides); + pSolid.AddFace(NewFace); + + // other sides + Vector[] Points; + Points.resize(3); + + // get centerpoint + Points[0][0] = origin[0]; + Points[0][1] = origin[1]; + // YWB rounding??? + Points[0][2] = rint(origin[2] + fHeight); + + for(int i = 0; i < sides; i++) + { + Points[1][0] = pmPoints[i][0]; + Points[1][1] = pmPoints[i][1]; + Points[1][2] = pmPoints[i][2]; + + Points[2][0] = pmPoints[i+1][0]; + Points[2][1] = pmPoints[i+1][1]; + Points[2][2] = pmPoints[i+1][2]; + + NewFace.CreateFace(Points, 3); + pSolid.AddFace(NewFace); + } + + pSolid.CalcBounds(false); + pSolid.InitializeTextureAxes(align, INIT_TEXTURE_ALL | INIT_TEXTURE_FORCE); + return pSolid; + } + + void DrawPreview( Render@ render, const BoundBox@ box ) + { + float fWidth = (box.maxs[0] - box.mins[0]) / 2; + float fDepth = (box.maxs[1] - box.mins[1]) / 2; + float fHeight = (box.maxs[2] - box.mins[2]) / 2; + + Vector origin; + box.GetBoundsCenter(origin); + + Vector[] pmPoints; + pmPoints.resize(64); + polyMake(origin[0] - fWidth, origin[1] - fDepth, origin[0] + fWidth, origin[1] + fDepth, sides, 0, pmPoints); + + for(int i = 0; i < sides+1; i++) + { + // YWB rounding??? + pmPoints[i][2] = /*rint*/(origin[2] - fHeight); + } + + MeshBuilder builder; + builder.Start(GetDefaultTextureName(), MATERIAL_POLYGON, sides); + + for(int i = sides; i > 0; --i) + { + builder.Position(pmPoints[i]); + builder.Normal(vec3_origin); + builder.TexCoord( 0, 0, 0 ); + builder.AdvanceVertex(); + } + + builder.Draw(); + + Vector[] Points; + Points.resize(3); + + // get centerpoint + Points[0][0] = origin[0]; + Points[0][1] = origin[1]; + // YWB rounding??? + Points[0][2] = rint(origin[2] + fHeight); + + for(int i = 0; i < sides; i++) + { + Points[1][0] = pmPoints[i][0]; + Points[1][1] = pmPoints[i][1]; + Points[1][2] = pmPoints[i][2]; + + Points[2][0] = pmPoints[i+1][0]; + Points[2][1] = pmPoints[i+1][1]; + Points[2][2] = pmPoints[i+1][2]; + + builder.Start(GetDefaultTextureName(), MATERIAL_TRIANGLES, 1); + for(int j = 0; j < 3; j++) + { + builder.Position(Points[j]); + builder.Normal(vec3_origin); + builder.TexCoord( 0, 0, 0 ); + builder.AdvanceVertex(); + } + builder.Draw(); + } + } + + int sides; +}; +``` diff --git a/docs/angelscript/hammer/example.md b/docs/angelscript/hammer/examples/wedge.md similarity index 59% rename from docs/angelscript/hammer/example.md rename to docs/angelscript/hammer/examples/wedge.md index 6b1eda26..71a58698 100644 --- a/docs/angelscript/hammer/example.md +++ b/docs/angelscript/hammer/examples/wedge.md @@ -1,14 +1,9 @@ --- -title: Examples +title: Example Wedge +weight: 10 --- -# Examples - -This page contains various examples of how to use AngelScript to create new brush types in the Strata Hammer Editor. - -To use the examples create a new file inside the `hammer/scripts` folder (create the folder if it does not exist yet). The scripts have to be saved with the extension `.as`. Afterwards, the new brush types can be used by first selecting the `Block Tool` within Hammer and then changing the `Categories` combo-box in the right bar to `Scriptable`. The combo-box `Objects` below then contains the new scripted brushes. - -## `ExampleWedge` (`script_wedge.as`) +# Example Wedge (`script_wedge.as`) ```as [Solid("script_wedge")] @@ -293,173 +288,3 @@ class ExampleWedge : ScriptSolid } }; ``` - - -## `ExampleSpike` (`script_spike.as`) - -```as -[Solid("script_spike")] -class ExampleSpike : ScriptSolid -{ - GUIData[]@ GetGuiData() const - { - return { GUIData( Label, "Spike" ), GUIData( Divider ), GUIData( TextBox, "Sides", 4 ) }; // Script gui layout - } - - void GuiUpdated(const dictionary@ dict) - { - sides = int(dict["Sides"]); // Value is stored with the same name as TextBox - if (sides < 3) - sides = 3; - print("new side count: " + sides); - } - - float DEG2RAD( float ang ) - { - return ang * (3.14159265358979323846 / 180.f); - } - - void polyMake( float x1, float y1, float x2, float y2, int npoints, float start_ang, Vector[]@ pmPoints ) - { - int point; - float angle = start_ang, angle_delta = 360.0f / float(npoints); - float xrad = (x2-x1) / 2, yrad = (y2-y1) / 2; - - // make centerpoint for polygon: - float xCenter = x1 + xrad; - float yCenter = y1 + yrad; - - for( point = 0; point < npoints; point++, angle += angle_delta ) - { - if( angle > 360 ) - angle -= 360; - - pmPoints[point][0] = /*rint*/(xCenter + (sin(DEG2RAD(angle)) * xrad)); - pmPoints[point][1] = /*rint*/(yCenter + (cos(DEG2RAD(angle)) * yrad)); - } - - pmPoints[point][0] = pmPoints[0][0]; - pmPoints[point][1] = pmPoints[0][1]; - } - - CMapClass@ CreateMapSolid( const BoundBox@ box, TextureAlignment align ) - { - float fWidth = (box.maxs[0] - box.mins[0]) / 2; - float fDepth = (box.maxs[1] - box.mins[1]) / 2; - float fHeight = (box.maxs[2] - box.mins[2]) / 2; - print("Sides: " + sides + "; Width: " + fWidth + "; Depth: " + fDepth + "; Height: " + fHeight); - - Vector origin; - box.GetBoundsCenter(origin); - - Vector[] pmPoints; - pmPoints.resize(64); - polyMake(origin[0] - fWidth, origin[1] - fDepth, origin[0] + fWidth, origin[1] + fDepth, sides, 0, pmPoints); - - CMapFace NewFace; - CMapSolid@ pSolid = CMapSolid(); - - for(int i = 0; i < sides+1; i++) - { - // YWB rounding??? - pmPoints[i][2] = /*rint*/(origin[2] - fHeight); - } - - NewFace.CreateFace(pmPoints, -sides); - pSolid.AddFace(NewFace); - - // other sides - Vector[] Points; - Points.resize(3); - - // get centerpoint - Points[0][0] = origin[0]; - Points[0][1] = origin[1]; - // YWB rounding??? - Points[0][2] = rint(origin[2] + fHeight); - - for(int i = 0; i < sides; i++) - { - Points[1][0] = pmPoints[i][0]; - Points[1][1] = pmPoints[i][1]; - Points[1][2] = pmPoints[i][2]; - - Points[2][0] = pmPoints[i+1][0]; - Points[2][1] = pmPoints[i+1][1]; - Points[2][2] = pmPoints[i+1][2]; - - NewFace.CreateFace(Points, 3); - pSolid.AddFace(NewFace); - } - - pSolid.CalcBounds(false); - pSolid.InitializeTextureAxes(align, INIT_TEXTURE_ALL | INIT_TEXTURE_FORCE); - return pSolid; - } - - void DrawPreview( Render@ render, const BoundBox@ box ) - { - float fWidth = (box.maxs[0] - box.mins[0]) / 2; - float fDepth = (box.maxs[1] - box.mins[1]) / 2; - float fHeight = (box.maxs[2] - box.mins[2]) / 2; - - Vector origin; - box.GetBoundsCenter(origin); - - Vector[] pmPoints; - pmPoints.resize(64); - polyMake(origin[0] - fWidth, origin[1] - fDepth, origin[0] + fWidth, origin[1] + fDepth, sides, 0, pmPoints); - - for(int i = 0; i < sides+1; i++) - { - // YWB rounding??? - pmPoints[i][2] = /*rint*/(origin[2] - fHeight); - } - - MeshBuilder builder; - builder.Start(GetDefaultTextureName(), MATERIAL_POLYGON, sides); - - for(int i = sides; i > 0; --i) - { - builder.Position(pmPoints[i]); - builder.Normal(vec3_origin); - builder.TexCoord( 0, 0, 0 ); - builder.AdvanceVertex(); - } - - builder.Draw(); - - Vector[] Points; - Points.resize(3); - - // get centerpoint - Points[0][0] = origin[0]; - Points[0][1] = origin[1]; - // YWB rounding??? - Points[0][2] = rint(origin[2] + fHeight); - - for(int i = 0; i < sides; i++) - { - Points[1][0] = pmPoints[i][0]; - Points[1][1] = pmPoints[i][1]; - Points[1][2] = pmPoints[i][2]; - - Points[2][0] = pmPoints[i+1][0]; - Points[2][1] = pmPoints[i+1][1]; - Points[2][2] = pmPoints[i+1][2]; - - builder.Start(GetDefaultTextureName(), MATERIAL_TRIANGLES, 1); - for(int j = 0; j < 3; j++) - { - builder.Position(Points[j]); - builder.Normal(vec3_origin); - builder.TexCoord( 0, 0, 0 ); - builder.AdvanceVertex(); - } - builder.Draw(); - } - } - - int sides; -}; -``` diff --git a/docs/angelscript/hammer/global-functions.md b/docs/angelscript/hammer/global-functions.md index f8c462ca..73b8f85e 100644 --- a/docs/angelscript/hammer/global-functions.md +++ b/docs/angelscript/hammer/global-functions.md @@ -1,60 +1,61 @@ --- title: Global Functions +weight: 40 --- # Global Functions This page outlines the various Strata Hammer AngelScript global functions. -### `FindMaterial` +## `FindMaterial` ```as Material@ FindMaterial(const string&in name) ``` -### `GetDefaultTextureName` +## `GetDefaultTextureName` ```as string GetDefaultTextureName() ``` -### `abs` +## `abs` ```as float abs(float) ``` -### `acos` +## `acos` ```as float acos(float) ``` -### `asin` +## `asin` ```as float asin(float) ``` -### `atan` +## `atan` ```as float atan(float) ``` -### `atan2` +## `atan2` ```as float atan2(float, float) ``` -### `ceil` +## `ceil` ```as float ceil(float) ``` -### `closeTo` +## `closeTo` ```as bool closeTo(float, float, float = 0.00001f) @@ -62,25 +63,25 @@ bool closeTo(float, float, float = 0.00001f) bool closeTo(double, double, double = 0.0000000001) ``` -### `cos` +## `cos` ```as float cos(float) ``` -### `cosh` +## `cosh` ```as float cosh(float) ``` -### `floor` +## `floor` ```as float floor(float) ``` -### `fpFromIEEE` +## `fpFromIEEE` ```as float fpFromIEEE(uint) @@ -88,7 +89,7 @@ float fpFromIEEE(uint) double fpFromIEEE(uint64) ``` -### `fpToIEEE` +## `fpToIEEE` ```as uint fpToIEEE(float) @@ -96,85 +97,85 @@ uint fpToIEEE(float) uint64 fpToIEEE(double) ``` -### `fraction` +## `fraction` ```as float fraction(float) ``` -### `getExceptionInfo` +## `getExceptionInfo` ```as string getExceptionInfo() ``` -### `join` +## `join` ```as string join(const string[]&in, const string&in) ``` -### `log` +## `log` ```as float log(float) ``` -### `log10` +## `log10` ```as float log10(float) ``` -### `pow` +## `pow` ```as float pow(float, float) ``` -### `print` +## `print` ```as void print(const string&in) ``` -### `rint` +## `rint` ```as float rint(float) ``` -### `sin` +## `sin` ```as float sin(float) ``` -### `sinh` +## `sinh` ```as float sinh(float) ``` -### `sqrt` +## `sqrt` ```as float sqrt(float) ``` -### `tan` +## `tan` ```as float tan(float) ``` -### `tanh` +## `tanh` ```as float tanh(float) ``` -### `throw` +## `throw` ```as void throw(const string&in) diff --git a/docs/angelscript/hammer/global-properties.md b/docs/angelscript/hammer/global-properties.md index cc0500c5..df1e57ca 100644 --- a/docs/angelscript/hammer/global-properties.md +++ b/docs/angelscript/hammer/global-properties.md @@ -1,30 +1,31 @@ --- title: Global Properties +weight: 50 --- # Global Properties This page outlines the various Strata Hammer AngelScript global properties. -### `vec3_angle` +## `vec3_angle` ```as const QAngle vec3_angle ``` -### `vec3_invalid` +## `vec3_invalid` ```as const Vector vec3_invalid ``` -### `vec3_origin` +## `vec3_origin` ```as const Vector vec3_origin ``` -### `vec4_origin` +## `vec4_origin` ```as const Vector4D vec4_origin diff --git a/docs/angelscript/hammer/meta.json b/docs/angelscript/hammer/meta.json index 740a1055..1dbff017 100644 --- a/docs/angelscript/hammer/meta.json +++ b/docs/angelscript/hammer/meta.json @@ -1,3 +1,4 @@ { - "title": "Hammer" + "title": "Hammer", + "weight": 20 } diff --git a/docs/angelscript/index.md b/docs/angelscript/index.md new file mode 100644 index 00000000..362ccef6 --- /dev/null +++ b/docs/angelscript/index.md @@ -0,0 +1,21 @@ +--- +title: AngelScript +weight: 0 +--- + +# AngelScript + +Welcome to the AngelScript section of the Strata Source wiki! + +AngelScript is a scripting system developed outside of Strata Source to provide a interface between the user and the game internals allowing for developing various custom game functionality without the need for source code access. For more information on AngelScript itself, please visit the [official site](https://www.angelcode.com/angelscript/). + +AngelScript is under the same umbrela as [VScript](https://developer.valvesoftware.com/wiki/VScript), the original scripting system developed by Valve, but has been developed as a seperate system away from VScript. Like with VScript, AngelScript runs with the currently loaded game map. AngelScript has been implemented both into the game and the Hammer level editor for Strata Source. + +> [!NOTE] +> If you are new to using AngelScript, it is recommended for you to follow the Beginner's Guide. + +## Beginner's Guide(./guide) FIX ONCE `index.md` IS SUPPORTED AND NEW BEGINNER'S GUIDE IS ADDED + +## [Game Examples](./game/examples) + +## [Hammer Examples](./hammer/examples) diff --git a/docs/angelscript/reference/meta.json b/docs/angelscript/reference/meta.json new file mode 100644 index 00000000..87779403 --- /dev/null +++ b/docs/angelscript/reference/meta.json @@ -0,0 +1,5 @@ +{ + "title": "Reference", + "type": "angelscript", + "weight": 0 +} diff --git a/dumps/angelscript_client_p2ce.json b/dumps/angelscript_client_p2ce.json index debcdc1f..b7fc3d61 100644 --- a/dumps/angelscript_client_p2ce.json +++ b/dumps/angelscript_client_p2ce.json @@ -9826,6 +9826,11 @@ "name": "CBaseEntity" }, "method": [ + { + "name": "CBaseAnimating", + "declaration": "CBaseAnimating()", + "documentation": null + }, { "name": "LookupAttachment", "declaration": "int LookupAttachment(const string&in attachmentName)", @@ -10808,6 +10813,11 @@ "name": "CBaseAnimating" }, "method": [ + { + "name": "CBaseCombatWeapon", + "declaration": "CBaseCombatWeapon()", + "documentation": null + }, { "name": "PrimaryAttack", "declaration": "void PrimaryAttack()", @@ -11257,6 +11267,11 @@ "name": "CBaseEntity" }, "method": [ + { + "name": "CLight", + "declaration": "CLight()", + "documentation": null + }, { "name": "GetInnerAngle", "declaration": "float GetInnerAngle() const", diff --git a/dumps/angelscript_server_p2ce.json b/dumps/angelscript_server_p2ce.json index 77e03087..b7242266 100644 --- a/dumps/angelscript_server_p2ce.json +++ b/dumps/angelscript_server_p2ce.json @@ -9832,6 +9832,11 @@ "name": "CBaseEntity" }, "method": [ + { + "name": "CBaseAnimating", + "declaration": "CBaseAnimating()", + "documentation": null + }, { "name": "LookupAttachment", "declaration": "int LookupAttachment(const string&in attachmentName)", @@ -10814,6 +10819,11 @@ "name": "CBaseAnimating" }, "method": [ + { + "name": "CBaseCombatWeapon", + "declaration": "CBaseCombatWeapon()", + "documentation": null + }, { "name": "PrimaryAttack", "declaration": "void PrimaryAttack()", @@ -11263,6 +11273,11 @@ "name": "CBaseEntity" }, "method": [ + { + "name": "CLight", + "declaration": "CLight()", + "documentation": null + }, { "name": "GetInnerAngle", "declaration": "float GetInnerAngle() const",