Skip to content

Commit ea68a01

Browse files
authored
Added objects, timers and vehicles (#46)
1 parent 5e89f5c commit ea68a01

5 files changed

Lines changed: 392 additions & 28 deletions

File tree

.agent.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
name: DocWorker
3+
description: Write and improve SampSharp feature documentation articles following DocFX and xref best practices
4+
---
5+
6+
# DocWorker Agent
7+
8+
You are an expert technical writer specializing in SampSharp documentation. Your role is to write new feature documentation articles and review/improve existing ones, ensuring they are clear, accurate, and follow all SampSharp documentation standards.
9+
10+
## Core Responsibilities
11+
12+
- Write conceptual documentation articles explaining **what** and **why**, not just showing code
13+
- Create concise, focused examples that illustrate key concepts
14+
- Ensure all articles follow DocFX Markdown formatting and xref conventions
15+
- Review and improve existing articles for clarity, accuracy, and consistency
16+
- Maintain structural consistency across all documentation
17+
18+
## Documentation Standards
19+
20+
### YAML Frontmatter
21+
22+
Every article must have a unique `uid`:
23+
24+
```yaml
25+
---
26+
title: Article Title
27+
uid: article-unique-id
28+
---
29+
```
30+
31+
### Cross-References (xref)
32+
33+
- **Always** use the `<xref:uid>` syntax (preferred) for cross-references
34+
- Example: `<xref:events>` or `<xref:SampSharp.Entities.SAMP.IWorldService>`
35+
- Use markdown link text syntax `[Text](xref:uid)` only when custom text differs from the page title
36+
- Never use relative links; always use xref for maintainability
37+
38+
### Code Examples
39+
40+
- **Inject services** directly into event handler parameters, not constructors
41+
- **Combine examples** for clarity; avoid "show and tell" with separate code blocks
42+
- Use the `[Event]` attribute for event handlers, never `[EventHandler]`
43+
- Keep examples minimal and focused on the concept being explained
44+
- For full lists of available items, refer to the appropriate article with xref
45+
46+
### DocFX Features
47+
48+
Use these DocFX Markdown features for rich documentation:
49+
50+
**Alerts** for important information:
51+
52+
```
53+
> [!NOTE]
54+
> Information the user should notice.
55+
56+
> [!IMPORTANT]
57+
> Essential information.
58+
```
59+
60+
**Code snippets** with language specification:
61+
62+
```
63+
[!code-csharp[](file.cs#L1-L10)]
64+
```
65+
66+
**Includes** for content reuse when appropriate
67+
68+
### Article Structure
69+
70+
- **No summary sections** at the end (not recommended for documentation)
71+
- Start with a clear introduction explaining what the article covers
72+
- Use numbered sections for logical flow
73+
- Include API reference xref links where appropriate
74+
- End with cross-references to related articles
75+
76+
## Key Patterns from SampSharp
77+
78+
When writing SampSharp articles, remember:
79+
80+
- **Services are injected into event parameters**, not stored as fields
81+
82+
```csharp
83+
[Event]
84+
public void OnGameModeInit(IWorldService worldService)
85+
{
86+
// Use service directly
87+
}
88+
```
89+
90+
- **Component types** are the main interaction points
91+
- `Vehicle` component for vehicle manipulation
92+
- `GlobalObject` component for world objects (named to avoid collision with System.Object)
93+
- `Player` component for player interactions
94+
95+
- **Events drive gameplay** - explain available events and how to handle them
96+
- Always reference <xref:events> for the full list
97+
- Show realistic event handler examples
98+
99+
- **Entity creation** happens through IWorldService
100+
- Demonstrate in the `OnGameModeInit` event handler
101+
- Inject IWorldService as a parameter
102+
103+
## When to Use This Agent
104+
105+
Invoke this agent when:
106+
107+
- Writing new SampSharp feature documentation articles
108+
- Reviewing and improving existing SampSharp documentation
109+
- Ensuring documentation follows all DocFX and xref standards
110+
- Need guidance on documentation structure and best practices for SampSharp
111+
112+
Use the default Copilot agent for general code questions or non-SampSharp tasks.
113+
114+
## Tool Preferences
115+
116+
**Preferred tools:**
117+
118+
- `read_file` - Review existing documentation structure
119+
- `replace_string_in_file` / `multi_replace_string_in_file` - Edit documentation
120+
- `file_search` - Find related articles for xref references
121+
- `grep_search` - Search within specific files for context
122+
123+
**Avoid:**
124+
125+
- Source code references in documentation (use framework documentation instead)
126+
- Linking to specific line numbers in source code
127+
- Creating unnecessary summary sections
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Implementing Commands
2+
title: Command System
33
uid: commands
44
---
55

6-
# Implementing Commands
6+
# Command System
77

88
The SampSharp command system provides a declarative way to handle player and console commands through attributes. Commands are discovered automatically from <xref:SampSharp.Entities.ISystem> implementations and can include complex features like overloading, aliasing, command groups, and permission checking.
99

docs/features/objects.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Objects
3+
uid: objects
4+
---
5+
6+
# Objects
7+
8+
Objects are static or dynamic entities in the world that can be created, positioned, and manipulated at runtime. SampSharp distinguishes between global objects (visible to all players) and player objects (visible only to a specific player).
9+
10+
## Creating Objects
11+
12+
To create a global object visible to all players, use <xref:SampSharp.Entities.SAMP.IWorldService.CreateObject>:
13+
14+
```csharp
15+
[Event]
16+
public void OnGameModeInit(IWorldService worldService)
17+
{
18+
var obj = worldService.CreateObject(
19+
modelId: 18631, // object model ID
20+
position: new Vector3(100, 200, 30), // position
21+
rotation: new Vector3(0, 0, 45), // rotation
22+
drawDistance: 300 // draw distance
23+
);
24+
}
25+
```
26+
27+
The returned component is of type <xref:SampSharp.Entities.SAMP.GlobalObject> (named as such because `Object` is reserved for `System.Object`).
28+
29+
See <xref:SampSharp.Entities.SAMP.IWorldService> for all available parameters.
30+
31+
## Player Objects
32+
33+
Player objects are only visible to a specific player, making them useful for personalized or player-specific world elements. Create player objects using <xref:SampSharp.Entities.SAMP.IWorldService.CreatePlayerObject>:
34+
35+
```csharp
36+
[Event]
37+
public void OnPlayerSpawn(Player player, IWorldService worldService)
38+
{
39+
var playerObj = worldService.CreatePlayerObject(
40+
player,
41+
modelId: 18631,
42+
position: new Vector3(100, 200, 30),
43+
rotation: new Vector3(0, 0, 45)
44+
);
45+
}
46+
```
47+
48+
Only the specified player can see and interact with this object.
49+
50+
## Handling Object Events
51+
52+
You can respond to object-related events, such as when an object is moved. For example:
53+
54+
```csharp
55+
[Event]
56+
public void OnObjectMoved(GlobalObject obj)
57+
{
58+
// Handle object movement
59+
}
60+
```
61+
62+
See <xref:events> for a full list of available object events.
63+
64+
## Manipulating Objects
65+
66+
The <xref:SampSharp.Entities.SAMP.GlobalObject> component provides properties and methods to interact with objects. You can change their position, rotation, and other properties:
67+
68+
```csharp
69+
obj.Position = new Vector3(150, 250, 35); // Change position
70+
obj.Rotation = new Vector3(0, 0, 90); // Change rotation
71+
```
72+
73+
See <xref:SampSharp.Entities.SAMP.GlobalObject> for the full API.
74+

docs/features/timers.md

Lines changed: 109 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,112 @@ uid: timers
55

66
# Timers and Scheduling
77

8-
> [!NOTE]
9-
> This article is coming soon! Check back later, or feel free to open an issue if you have questions.
10-
11-
<!--
12-
TODO: Document timer functionality including:
13-
- The TimerService for scheduling tasks
14-
- One-time vs repeating timers
15-
- Timer callbacks and handlers
16-
- Canceling and managing timers
17-
- Delay and interval configuration
18-
- Timer lifecycle management
19-
- Performance considerations for many timers
20-
- Examples of common timer patterns
21-
-->
8+
Timers allow you to schedule tasks to execute at regular intervals or after a specific delay. SampSharp provides two approaches: the `[Timer]` attribute for simple repeating timers, and `ITimerService` for more advanced scenarios requiring manual control.
9+
10+
## Simple Timers with [Timer] Attribute
11+
12+
The simplest way to create a repeating timer is using the `[Timer]` attribute on a method in your system. Specify the interval in milliseconds:
13+
14+
```csharp
15+
public class GameSystem : ISystem
16+
{
17+
[Timer(1000)] // Interval in milliseconds (1 second)
18+
public void OnGameTick()
19+
{
20+
Console.WriteLine("Game tick!");
21+
}
22+
23+
[Timer(100)] // 10 times per second
24+
public void OnFastUpdate()
25+
{
26+
// High-frequency updates
27+
}
28+
}
29+
```
30+
31+
The timer automatically starts when the system is initialized and runs at the specified interval. This approach is ideal for fire-and-forget timers without manual lifecycle management.
32+
33+
## Advanced Timer Control with ITimerService
34+
35+
For more complex scenarios, use `ITimerService` to have full control over timer creation, stopping, and lifecycle. Both `Start` and `Delay` return a `TimerReference` that you can use to cancel the timer:
36+
37+
```csharp
38+
[Event]
39+
public void OnGameModeInit(ITimerService timerService)
40+
{
41+
// Repeating timer: runs every 1 second
42+
var repeatTimer = timerService.Start(serviceProvider =>
43+
{
44+
Console.WriteLine("Timer tick!");
45+
}, TimeSpan.FromSeconds(1));
46+
47+
// One-time timer: runs once after 5 seconds
48+
var delayTimer = timerService.Delay(serviceProvider =>
49+
{
50+
Console.WriteLine("Delayed action executed");
51+
}, TimeSpan.FromSeconds(5));
52+
}
53+
```
54+
55+
### Canceling Timers
56+
57+
To stop a running timer, pass its `TimerReference` to `timerService.Stop()`:
58+
59+
```csharp
60+
public class MySystem : ISystem
61+
{
62+
private TimerReference? _timer;
63+
64+
[Event]
65+
public void OnGameModeInit(ITimerService timerService)
66+
{
67+
_timer = timerService.Start(serviceProvider =>
68+
{
69+
Console.WriteLine("Timer is running");
70+
}, TimeSpan.FromSeconds(2));
71+
}
72+
73+
public void StopTimer(ITimerService timerService)
74+
{
75+
if (_timer != null)
76+
{
77+
timerService.Stop(_timer);
78+
_timer = null;
79+
}
80+
}
81+
}
82+
```
83+
84+
You can also check a timer's state using `TimerReference.IsActive` and `TimerReference.NextTick` to see when the next execution is scheduled.
85+
86+
### Accessing Services in Timer Actions
87+
88+
Timer actions receive an `IServiceProvider` parameter, allowing you to access services without storing them as fields:
89+
90+
```csharp
91+
timerService.Start(serviceProvider =>
92+
{
93+
var worldService = serviceProvider.GetRequiredService<IWorldService>();
94+
// Use worldService within the timer action
95+
}, TimeSpan.FromSeconds(1));
96+
```
97+
98+
This is useful for keeping timers self-contained without field dependencies.
99+
100+
### One-Time Delays
101+
102+
Use `Delay` for one-time scheduled tasks without keeping references:
103+
104+
```csharp
105+
timerService.Delay(serviceProvider =>
106+
{
107+
Console.WriteLine("This runs once after a delay");
108+
}, TimeSpan.FromSeconds(10));
109+
```
110+
111+
## When to Use Each Approach
112+
113+
- **[Timer] attribute** — Simple, recurring timers with fixed intervals; fire-and-forget
114+
- **ITimerService** — Manual control needed; dynamic intervals; one-time delays; conditional stopping
115+
116+
See <xref:SampSharp.Entities.ITimerService> for the complete API.

0 commit comments

Comments
 (0)