Events

This page describes server-side events

Gamemode start

start()

Details
Example
Details

Remarks

Arguments

Type

Description

Example
oak.event('start', () => {
console.log('[info] connection started')
oak.log('[info] oakwood-node connected')
})

Server console

console(text)

Details
Example
Details

Remarks

Executed on server console input.

Arguments

Type

Description

string

Text

Example
// TODO

Unknown chat command

unknownCommand(pid, text)

Details
Example
Details

Remarks

Arguments

Type

Description

player

Player ID

string

Command Used

Example
oak.event('unknownCommand', (pid, text) => {
oak.chatSend(pid, `[error] unknown command: ${text}`)
})

Gamemode stop

stop()

Details
Example
Details

Remarks

Happens when the server is shut down.

Arguments

Type

Description

Example
oak.event('start', () => {
console.log('[info] connection stopped')
})

Player connect

playerConnect(pid)

Details
Example
Details

Remarks

Best place to spawn the player.

Arguments

Type

Description

player

Player ID

Example
oak.event('playerConnect', async pid => {
console.log('[info] player connected', pid)
oak.chatBroadcast(`[info] player ${await oak.playerNameGet(pid)} connected.`)
oak.playerModelSet(pid, "Tommy.i3d")
oak.playerPositionSet(pid, [-1774.59301758, -4.88487052917, -2.40491962433 ])
oak.playerHealthSet(pid, 200)
oak.hudFadeout(pid, 1, 500, 0xFFFFFF)
oak.hudFadeout(pid, 0, 500, 0xFFFFFF)
oak.playerSpawn(pid)
})

Player disconnect

playerDisconnect(pid)

Details
Example
Details

Remarks

Happens when the player disconnects or times out.

There's no way to find out if the player timed out as of right now. This will be added later on.

Arguments

Type

Description

player

Player ID

Example
oak.event('playerDisconnect', async pid => {
oak.chatBroadcast(`[info] player ${await oak.playerNameGet(pid)} disconnected.`)
})

Player death

playerDeath(pid)

Details
Example
Details

Remarks

Arguments

Type

Description

player

Player ID

Example
oak.event('playerDeath', async pid => {
oak.chatSend(pid, `[info] you died! Get a new life!`)
oak.playerModelSet(pid, "Tommy.i3d")
oak.playerPositionSet(pid, [-1774.59301758, -4.88487052917, -2.40491962433 ])
oak.playerHealthSet(pid, 200)
oak.hudFadeout(pid, 1, 500, 0xFFFFFF)
oak.hudFadeout(pid, 0, 500, 0xFFFFFF)
oak.playerSpawn(pid)
})

Player hit

playerhit(pid, atkr, float)

Details
Example
Details

Remarks

Happens when attacker lands a hit on another player.

Arguments

Type

Description

player

Player ID

player

Attacker ID

float

Damage Dealt

Example
// TODO

Vehicle player use

vehicleUse(veh, pid, success, seatId, enterOrLeave)

Details
Example
Details

Remarks

Success is true if car is unlocked, we can also provide which seat he wants to enter or whether he wants to enter or leave the vehicle.

Arguments

Type

Description

vehicle

Vehicle ID

player

Player ID

int

Success State

int

Seat ID

int

Enter or Leave State

Example
oak.event("vehicleUse", async (veh, pid, success, seatId, enterOrLeave) => {
if (success) return;
oak.hudMessage(pid, "This vehicle is locked!", 0xff0000)
})

Player key

playerKey(pid, vkey, down)

Details
Example
Details

Remarks

Executed on player key press. The key codes are documented at MSDN page.

Arguments

Type

Description

player

Player ID

int

Virtual Key

int

Is Key Down

Example
// TODO