Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs events section rework #300

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/articles/events/client/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Server Events

## List

[Full list of client events.](https://docs.altv.mp/js/api/alt-client.IClientEvent.html)

## Documentation

15 changes: 15 additions & 0 deletions docs/articles/events/server/any-resource-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# anyResourceError

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_anyResourceError" target="_blank"> You can find information about the types here. (click to redirect) </a>

## Example

```js
import alt from "alt-server";

alt.on('anyResourceError', (resourceName) => {
console.error(`Resource ${resourceName} has an error.`);
});
```
15 changes: 15 additions & 0 deletions docs/articles/events/server/any-resource-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# anyResourceStart

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_anyResourceStart" target="_blank"> You can find information about the types here. (click to redirect) </a>

## Example

```js
import alt from "alt-server";

alt.on('anyResourceStart', (resourceName) => {
console.log(`Resource ${resourceName} has started.`);
});
```
15 changes: 15 additions & 0 deletions docs/articles/events/server/any-resource-stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# anyResourceStop

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_anyResourceStop" target="_blank"> You can find information about the types here. (click to redirect) </a>

## Example

```js
import alt from "alt-server";

alt.on('anyResourceStop', (resourceName) => {
console.log(`Resource ${resourceName} has stopped.`);
});
```

This comment was marked as resolved.

File renamed without changes.
23 changes: 23 additions & 0 deletions docs/articles/events/server/console-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# consoleCommand

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_consoleCommand" target="_blank"> You can find information about the types here. (click to redirect) </a>

## Example

```js
import alt from "alt-server";

alt.on("consoleCommand", (name, ...args) => {
console.log(`Console command ${name} was executed with the following arguments: ${args.join(", ")}`);

// example console command handle
if (name === "hello") {
console.log("Hello from consoleCommand event!");
return;
}

console.error(`Unknown console command ${name}`);
});
```
21 changes: 21 additions & 0 deletions docs/articles/events/server/entity-enter-colshape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# entityEnterColshape

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_entityEnterColshape" target="_blank"> You can find information about the types here. (click to redirect) </a>

Triggered when an entity enters a colshape.

## Example

```js
import alt from "alt-server";

let colshape = new alt.ColshapeSphere(new alt.Vector3(0, 0, 71), 5, 10);

alt.on("entityEnterColshape", (colshape, entity) => {
if (entity.type === alt.BaseObjectType.Player) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your example is js but you use ts enums

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then maybe there is a point to add them to alt exports?

or is there another workaround to detect entity type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also check entity type like this:

entity instanceof alt.Player

console.log(`Player ${entity.name} entered colshape ${colshape.id}`);
}
});
```
21 changes: 21 additions & 0 deletions docs/articles/events/server/entity-leave-colshape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# entityLeaveColshape

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_entityLeaveColshape" target="_blank"> You can find information about the types here. (click to redirect) </a>

Triggered when an entity enters a colshape.

## Example

```js
import alt from "alt-server";

let colshape = new alt.ColshapeSphere(new alt.Vector3(0, 0, 71), 5, 10);

alt.on("entityLeaveColshape", (colshape, entity) => {
if (entity.type === alt.BaseObjectType.Player) {
console.log(`Player ${entity.name} left colshape ${colshape.id}`);
}
});
```
23 changes: 23 additions & 0 deletions docs/articles/events/server/explosion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# explosion

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_explosion" target="_blank"> You can find information about the types here. (click to redirect) </a>

Triggered when an explosion occurs by players. Behavior can be cancelled by returning `false`.

## Example

```js
import alt from "alt-server";

function canPlayerCreateExplosion(player) {
// Your logic here

return true;
}

alt.on("explosion", (source, type, pos, fx, target) => {
return canPlayerCreateExplosion(source, type, pos, fx, target);
});
```
17 changes: 17 additions & 0 deletions docs/articles/events/server/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Server Events

## List

[Full list of server events.](https://docs.altv.mp/js/api/alt-server.IServerEvent.html)

## Documentation

- [anyResourceError](https://docs.altv.mp/js/articles/events/server/anyResourceError.html)
- [anyResourceStart](https://docs.altv.mp/js/articles/events/server/anyResourceStart.html)
- [anyResourceStop](https://docs.altv.mp/js/articles/events/server/anyResourceStop.html)
- [beforePlayerConnect](https://docs.altv.mp/js/articles/events/server/beforePlayerConnect.html)
- [consoleCommand](https://docs.altv.mp/js/articles/events/server/consoleCommand.html)
- [entityEnterColshape](https://docs.altv.mp/js/articles/events/server/entityEnterColshape.html)
- [entityLeaveColshape](https://docs.altv.mp/js/articles/events/server/entityLeaveColshape.html)
- [explosion](https://docs.altv.mp/js/articles/events/server/explosion.html)
- [netOwnerChange](https://docs.altv.mp/js/articles/events/server/netOwnerChange.html)
19 changes: 19 additions & 0 deletions docs/articles/events/server/net-owner-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# netOwnerChange

## A General Overview

<a href="https://docs.altv.mp/js/api/alt-server.IServerEvent.html#_altmp_altv_types_alt_server_IServerEvent_netOwnerChange" target="_blank"> You can find information about the types here. (click to redirect) </a>

Triggered when netOwner of the entity changes.

## Example

```js
import alt from "alt-server";

alt.on("netOwnerChange", (entity, owner, oldOwner) => {
if (entity.type === alt.BaseObjectType.Ped) {
alt.log(`Ped ${entity.id} has a new owner: ${owner ? owner.id : "null"}, old owner: ${oldOwner ? oldOwner.id : "null"}`);
}
});
```
25 changes: 23 additions & 2 deletions docs/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,29 @@
- name: Events
href: events/index.md
items:
- name: beforePlayerConnect
href: events/before-player-connect.md
- name: Client Events
href: events/client/index.md
- name: Server Events
href: events/server/index.md
items:
- name: anyResourceError
href: events/server/any-resource-error.md
- name: anyResourceStart
href: events/server/any-resource-start.md
- name: anyResourceStop
href: events/server/any-resource-stop.md
- name: beforePlayerConnect
href: events/server/before-player-connect.md
- name: consoleCommand
href: events/server/console-command.md
- name: entityEnterColshape
href: events/server/entity-enter-colshape.md
- name: entityLeaveColshape
href: events/server/entity-leave-colshape.md
- name: explosion
href: events/server/explosion.md
- name: netOwnerChange
href: events/server/net-owner-change.md
- name: Player
href: player/index.md
items:
Expand Down
Loading