temp
This commit is contained in:
parent
2113b5ae29
commit
2da34bd382
@ -9,14 +9,29 @@ import {
|
|||||||
import { nativeEvents } from './native.events'
|
import { nativeEvents } from './native.events'
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
|
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
|
||||||
|
return nativeEvents.includes(eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
public testRegister(
|
||||||
|
event: string,
|
||||||
|
callback: (player: PlayerMp, ...args: unknown[]) => void,
|
||||||
|
) {
|
||||||
|
rpc.register(event, async (data, info) => {
|
||||||
|
callback(info.player as PlayerMp, ...data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public register<EventName extends RageFW_ServerEvent>(
|
public register<EventName extends RageFW_ServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerEventCallback<EventName>,
|
callback: RageFW_ServerEventCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
if (nativeEvents.includes(eventName)) {
|
if (this.isNativeEvent(eventName)) {
|
||||||
mp.events.add(eventName, callback)
|
mp.events.add(eventName, callback)
|
||||||
} else {
|
} else {
|
||||||
rpc.register(eventName, callback as rpc.ProcedureListener)
|
rpc.register(eventName, async (data: any[], info) => {
|
||||||
|
return callback(info.player as PlayerMp, data)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,3 +69,9 @@ export const fw = {
|
|||||||
event: new Server(),
|
event: new Server(),
|
||||||
player: new Player(),
|
player: new Player(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fw.event.register('ggfdgfd', player => {})
|
||||||
|
|
||||||
|
fw.event.registerMany({
|
||||||
|
trailerAttached: player => {},
|
||||||
|
})
|
||||||
|
@ -9,9 +9,8 @@ export type RageFW_ServerEvent =
|
|||||||
| keyof RageFW_ICustomServerEvent
|
| keyof RageFW_ICustomServerEvent
|
||||||
| keyof IServerEvents
|
| keyof IServerEvents
|
||||||
|
|
||||||
export type RageFW_ServerEventCallback<
|
export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
||||||
K extends keyof RageFW_ICustomServerEvent | keyof IServerEvents,
|
K extends keyof RageFW_ICustomServerEvent
|
||||||
> = K extends keyof RageFW_ICustomServerEvent
|
|
||||||
? (
|
? (
|
||||||
player: PlayerMp,
|
player: PlayerMp,
|
||||||
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
||||||
|
Loading…
Reference in New Issue
Block a user