From ae25dd22d5662bf1bbf285da7b7e5e16e0181c2e Mon Sep 17 00:00:00 2001 From: Sergej Kajzer Date: Fri, 8 Mar 2024 08:21:07 +0300 Subject: [PATCH 1/4] articles/events changes --- docs/articles/events/client/index.md | 8 ++++++ .../events/server/any-resource-error.md | 15 +++++++++++ .../events/server/any-resource-start.md | 15 +++++++++++ .../events/server/any-resource-stop.md | 15 +++++++++++ .../{ => server}/before-player-connect.md | 0 .../articles/events/server/console-command.md | 23 +++++++++++++++++ .../events/server/entity-enter-colshape.md | 21 ++++++++++++++++ .../events/server/entity-leave-colshape.md | 21 ++++++++++++++++ docs/articles/events/server/explosion.md | 23 +++++++++++++++++ docs/articles/events/server/index.md | 17 +++++++++++++ .../events/server/net-owner-change.md | 19 ++++++++++++++ docs/articles/toc.yml | 25 +++++++++++++++++-- 12 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 docs/articles/events/client/index.md create mode 100644 docs/articles/events/server/any-resource-error.md create mode 100644 docs/articles/events/server/any-resource-start.md create mode 100644 docs/articles/events/server/any-resource-stop.md rename docs/articles/events/{ => server}/before-player-connect.md (100%) create mode 100644 docs/articles/events/server/console-command.md create mode 100644 docs/articles/events/server/entity-enter-colshape.md create mode 100644 docs/articles/events/server/entity-leave-colshape.md create mode 100644 docs/articles/events/server/explosion.md create mode 100644 docs/articles/events/server/index.md create mode 100644 docs/articles/events/server/net-owner-change.md diff --git a/docs/articles/events/client/index.md b/docs/articles/events/client/index.md new file mode 100644 index 00000000..010e2a95 --- /dev/null +++ b/docs/articles/events/client/index.md @@ -0,0 +1,8 @@ +# Server Events + +## List + +[Full list of client events.](https://docs.altv.mp/js/api/alt-client.IClientEvent.html) + +## Documentation + diff --git a/docs/articles/events/server/any-resource-error.md b/docs/articles/events/server/any-resource-error.md new file mode 100644 index 00000000..21a240fc --- /dev/null +++ b/docs/articles/events/server/any-resource-error.md @@ -0,0 +1,15 @@ +# anyResourceError + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on('anyResourceError', (resourceName) => { + console.error(`Resource ${resourceName} has an error.`); +}); +``` diff --git a/docs/articles/events/server/any-resource-start.md b/docs/articles/events/server/any-resource-start.md new file mode 100644 index 00000000..f630268a --- /dev/null +++ b/docs/articles/events/server/any-resource-start.md @@ -0,0 +1,15 @@ +# anyResourceStart + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on('anyResourceStart', (resourceName) => { + console.log(`Resource ${resourceName} has started.`); +}); +``` diff --git a/docs/articles/events/server/any-resource-stop.md b/docs/articles/events/server/any-resource-stop.md new file mode 100644 index 00000000..995dbcf3 --- /dev/null +++ b/docs/articles/events/server/any-resource-stop.md @@ -0,0 +1,15 @@ +# anyResourceStop + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on('anyResourceStop', (resourceName) => { + console.log(`Resource ${resourceName} has stopped.`); +}); +``` diff --git a/docs/articles/events/before-player-connect.md b/docs/articles/events/server/before-player-connect.md similarity index 100% rename from docs/articles/events/before-player-connect.md rename to docs/articles/events/server/before-player-connect.md diff --git a/docs/articles/events/server/console-command.md b/docs/articles/events/server/console-command.md new file mode 100644 index 00000000..5fcce9ca --- /dev/null +++ b/docs/articles/events/server/console-command.md @@ -0,0 +1,23 @@ +# consoleCommand + +## A General Overview + + You can find information about the types here. (click to redirect) + +## 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}`); +}); +``` diff --git a/docs/articles/events/server/entity-enter-colshape.md b/docs/articles/events/server/entity-enter-colshape.md new file mode 100644 index 00000000..beebeeef --- /dev/null +++ b/docs/articles/events/server/entity-enter-colshape.md @@ -0,0 +1,21 @@ +# entityEnterColshape + +## A General Overview + + You can find information about the types here. (click to redirect) + +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) { + console.log(`Player ${entity.name} entered colshape ${colshape.id}`); + } +}); +``` diff --git a/docs/articles/events/server/entity-leave-colshape.md b/docs/articles/events/server/entity-leave-colshape.md new file mode 100644 index 00000000..2d899e4e --- /dev/null +++ b/docs/articles/events/server/entity-leave-colshape.md @@ -0,0 +1,21 @@ +# entityLeaveColshape + +## A General Overview + + You can find information about the types here. (click to redirect) + +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}`); + } +}); +``` diff --git a/docs/articles/events/server/explosion.md b/docs/articles/events/server/explosion.md new file mode 100644 index 00000000..6c79b702 --- /dev/null +++ b/docs/articles/events/server/explosion.md @@ -0,0 +1,23 @@ +# explosion + +## A General Overview + + You can find information about the types here. (click to redirect) + +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); +}); +``` diff --git a/docs/articles/events/server/index.md b/docs/articles/events/server/index.md new file mode 100644 index 00000000..2a7bdcbb --- /dev/null +++ b/docs/articles/events/server/index.md @@ -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) \ No newline at end of file diff --git a/docs/articles/events/server/net-owner-change.md b/docs/articles/events/server/net-owner-change.md new file mode 100644 index 00000000..47aa45b2 --- /dev/null +++ b/docs/articles/events/server/net-owner-change.md @@ -0,0 +1,19 @@ +# netOwnerChange + +## A General Overview + + You can find information about the types here. (click to redirect) + +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"}`); + } +}); +``` diff --git a/docs/articles/toc.yml b/docs/articles/toc.yml index adfa7716..7c173897 100644 --- a/docs/articles/toc.yml +++ b/docs/articles/toc.yml @@ -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: From 02a8e7789ac03d37cd06437e0019fd4c28c2e982 Mon Sep 17 00:00:00 2001 From: Sergej Kajzer Date: Thu, 14 Mar 2024 03:08:36 +0300 Subject: [PATCH 2/4] example fixes --- .../events/server/before-player-connect.md | 29 ------------------- .../events/server/entity-enter-colshape.md | 2 +- .../events/server/entity-leave-colshape.md | 2 +- .../events/server/net-owner-change.md | 2 +- 4 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 docs/articles/events/server/before-player-connect.md diff --git a/docs/articles/events/server/before-player-connect.md b/docs/articles/events/server/before-player-connect.md deleted file mode 100644 index 6ffece49..00000000 --- a/docs/articles/events/server/before-player-connect.md +++ /dev/null @@ -1,29 +0,0 @@ -# beforePlayerConnect - -## A General Overview - - You can find information about the types here. (click to redirect) - -This event is where servers can kick users before the actual connection. For example, if the player is banned. - -## Example - -```js -import alt from "alt-server"; - -alt.on('beforePlayerConnect', (connectionInfo) => { - alt.log(connectionInfo.branch); // Prints out the current branch. - alt.log(connectionInfo.authToken); // Prints out the authToken. - alt.log(connectionInfo.build); // Prints out the current build number. - alt.log(connectionInfo.cdnUrl); // Prints out the URL of the CDN. - alt.log(connectionInfo.hwidExHash); // Prints out the ExHash of the client's HWID. - alt.log(connectionInfo.hwidHash); // Prints out the Hash of the client's HWID. - alt.log(connectionInfo.isDebug); // Prints out whether the client is in debug mode. - alt.log(connectionInfo.passwordHash); // Prints out a hash of the password that was used to connect to the server. - alt.log(connectionInfo.socialID); // Prints out the social ID of the client. - - if(connectionInfo.passwordHash !== alt.hashServerPassword('myPassword')) { - return false; - } -}); -``` diff --git a/docs/articles/events/server/entity-enter-colshape.md b/docs/articles/events/server/entity-enter-colshape.md index beebeeef..a0bf644c 100644 --- a/docs/articles/events/server/entity-enter-colshape.md +++ b/docs/articles/events/server/entity-enter-colshape.md @@ -14,7 +14,7 @@ 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) { + if (entity.type instanceof alt.Player) { console.log(`Player ${entity.name} entered colshape ${colshape.id}`); } }); diff --git a/docs/articles/events/server/entity-leave-colshape.md b/docs/articles/events/server/entity-leave-colshape.md index 2d899e4e..624787d1 100644 --- a/docs/articles/events/server/entity-leave-colshape.md +++ b/docs/articles/events/server/entity-leave-colshape.md @@ -14,7 +14,7 @@ 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) { + if (entity instanceof alt.Player) { console.log(`Player ${entity.name} left colshape ${colshape.id}`); } }); diff --git a/docs/articles/events/server/net-owner-change.md b/docs/articles/events/server/net-owner-change.md index 47aa45b2..bd4f470f 100644 --- a/docs/articles/events/server/net-owner-change.md +++ b/docs/articles/events/server/net-owner-change.md @@ -12,7 +12,7 @@ Triggered when netOwner of the entity changes. import alt from "alt-server"; alt.on("netOwnerChange", (entity, owner, oldOwner) => { - if (entity.type === alt.BaseObjectType.Ped) { + if (entity instanceof alt.Ped) { alt.log(`Ped ${entity.id} has a new owner: ${owner ? owner.id : "null"}, old owner: ${oldOwner ? oldOwner.id : "null"}`); } }); From edc9193c02f59692bc8ae8eec9d40fb624d4f2d6 Mon Sep 17 00:00:00 2001 From: Sergej Kajzer Date: Thu, 14 Mar 2024 03:22:33 +0300 Subject: [PATCH 3/4] more events --- .../server/player-changed-vehicle-seat.md | 15 +++++++++++++++ .../events/server/player-connect-denied.md | 15 +++++++++++++++ docs/articles/events/server/player-connect.md | 15 +++++++++++++++ docs/articles/events/server/player-damage.md | 17 +++++++++++++++++ docs/articles/events/server/player-death.md | 17 +++++++++++++++++ .../articles/events/server/player-disconnect.md | 15 +++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 docs/articles/events/server/player-changed-vehicle-seat.md create mode 100644 docs/articles/events/server/player-connect-denied.md create mode 100644 docs/articles/events/server/player-connect.md create mode 100644 docs/articles/events/server/player-damage.md create mode 100644 docs/articles/events/server/player-death.md create mode 100644 docs/articles/events/server/player-disconnect.md diff --git a/docs/articles/events/server/player-changed-vehicle-seat.md b/docs/articles/events/server/player-changed-vehicle-seat.md new file mode 100644 index 00000000..3bb86f9d --- /dev/null +++ b/docs/articles/events/server/player-changed-vehicle-seat.md @@ -0,0 +1,15 @@ +# playerChangedVehicleSeat + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerChangedVehicleSeat", (player, vehicle, oldSeat, seat) => { + console.log(`${player.name} changed seat from ${oldSeat} to ${seat} in vehicle ${vehicle.id}`); +}); +``` diff --git a/docs/articles/events/server/player-connect-denied.md b/docs/articles/events/server/player-connect-denied.md new file mode 100644 index 00000000..099d326d --- /dev/null +++ b/docs/articles/events/server/player-connect-denied.md @@ -0,0 +1,15 @@ +# playerConnectDenied + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerConnectDenied", (reason, name, ip, passwordHash, isDebug, branch, version, cdnURL, discordId) => { + console.log(`Player ${name} with IP ${ip} was denied to connect. Reason: ${reason}`); +}); +``` diff --git a/docs/articles/events/server/player-connect.md b/docs/articles/events/server/player-connect.md new file mode 100644 index 00000000..fbdfb3bc --- /dev/null +++ b/docs/articles/events/server/player-connect.md @@ -0,0 +1,15 @@ +# playerConnect + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerConnect", (player) => { + console.log(`${player.name} (RSC ID: ${player.socialID}) connected`); +}); +``` diff --git a/docs/articles/events/server/player-damage.md b/docs/articles/events/server/player-damage.md new file mode 100644 index 00000000..cdf28bc4 --- /dev/null +++ b/docs/articles/events/server/player-damage.md @@ -0,0 +1,17 @@ +# playerDamage + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerDamage", (victim, attacker, healthDamage, armourDamage, weaponHash) => { + let attackerName = attacker ? attacker.name : "Environment"; + + console.log(`${victim.name} was damaged by ${attackerName} with weapon ${weaponHash}. Health damage: ${healthDamage}, Armour damage: ${armourDamage}`); +}); +``` diff --git a/docs/articles/events/server/player-death.md b/docs/articles/events/server/player-death.md new file mode 100644 index 00000000..7092a840 --- /dev/null +++ b/docs/articles/events/server/player-death.md @@ -0,0 +1,17 @@ +# playerDamage + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerDeath", (victim: Player, killer, weaponHash) => { + let killerName = killer ? killer.name : "Environment"; + + console.log(`${victim.name} was killed by ${killerName} with weapon ${weaponHash}`); +}); +``` diff --git a/docs/articles/events/server/player-disconnect.md b/docs/articles/events/server/player-disconnect.md new file mode 100644 index 00000000..2ca25643 --- /dev/null +++ b/docs/articles/events/server/player-disconnect.md @@ -0,0 +1,15 @@ +# playerDisconnect + +## A General Overview + + You can find information about the types here. (click to redirect) + +## Example + +```js +import alt from "alt-server"; + +alt.on("playerDisconnect", (player, reason) => { + console.log(`${player.name} has disconnected from the server (reason: ${reason})`); +}); +``` From 1ad043639a395befa5b39e07a96a0e36f76fee6c Mon Sep 17 00:00:00 2001 From: Sergej Kajzer Date: Thu, 14 Mar 2024 03:24:04 +0300 Subject: [PATCH 4/4] add events to index --- docs/articles/events/server/index.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/articles/events/server/index.md b/docs/articles/events/server/index.md index 2a7bdcbb..bd23a7be 100644 --- a/docs/articles/events/server/index.md +++ b/docs/articles/events/server/index.md @@ -14,4 +14,10 @@ - [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) \ No newline at end of file +- [netOwnerChange](https://docs.altv.mp/js/articles/events/server/netOwnerChange.html) +- [playerChangedVehicleSeat](https://docs.altv.mp/js/articles/events/server/playerChangedVehicleSeat.html) +- [playerConnect](https://docs.altv.mp/js/articles/events/server/playerConnect.html) +- [playerConnectDenied](https://docs.altv.mp/js/articles/events/server/playerConnectDenied.html) +- [playerDamage](https://docs.altv.mp/js/articles/events/server/playerDamage.html) +- [playerDeath](https://docs.altv.mp/js/articles/events/server/playerDeath.html) +- [playerDisconnect](https://docs.altv.mp/js/articles/events/server/playerDisconnect.html) \ No newline at end of file