@overextended/ox_lib
Advanced tools
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../common/game/Entity/index.ts"],"mappings":";;;;aAMK,mBAAA;;EAEH,UAAA;EAFG;EAIH,MAAM;AAAA;AAAA,uBAGc,UAAA;EAAA;WAEX,IAAA;EAFqB;EAAA,SAIrB,KAAA;EAAA,UACC,QAAA;EAGiE;EAA9D,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,IAAA,GAAO,mBAAA,GAAsB,OAAA;EA+B9B;EALhC,IAAA,CAAK,GAAA,UAAa,KAAA,YAAc,OAAA;EA0C7B;EArCH,IAAA,CAAK,GAAA,UAAa,KAAA,YAAc,OAAA;EAqC7B;EAhCT,GAAA,aAAA,CAAiB,GAAA,WAAc,CAAA;EA1C7B;EA+CF,GAAA,CAAI,GAAA;EA5CD;EAiDH,IAAA,CAAA;EA9CU;EAAA,IAmDN,MAAA,CAAA;EAAA,UAID,SAAA,CAAU,MAAA;EAab,SAAA,CAAA,GAAS,OAAA;EAIT,SAAA,CAAU,CAAA,UAAW,CAAA,UAAW,CAAA,UAAW,QAAA,YAAkB,WAAA,YAAqB,SAAA;EAIlF,QAAA,CAAA;EAIA,UAAA,CAAA;EAIA,UAAA,CAAW,OAAA;EAIX,gBAAA,CAAA;EAIA,gBAAA,CAAiB,MAAA;AAAA"} | ||
| {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../common/game/Entity/index.ts"],"mappings":";;;;aAMK,mBAAA;;EAEH,UAAA;EAFG;EAIH,MAAM;AAAA;AAAA,uBAGc,UAAA;EAAA;WAEX,IAAA;EAFqB;EAAA,SAIrB,KAAA;EAAA,UACC,QAAA;EAGiE;EAA9D,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,IAAA,GAAO,mBAAA,GAAsB,OAAA;EAiC9B;EALhC,IAAA,CAAK,GAAA,UAAa,KAAA,YAAc,OAAA;EA0C7B;EArCH,IAAA,CAAK,GAAA,UAAa,KAAA,YAAc,OAAA;EAqC7B;EAhCT,GAAA,aAAA,CAAiB,GAAA,WAAc,CAAA;EA5C7B;EAiDF,GAAA,CAAI,GAAA;EA9CD;EAmDH,IAAA,CAAA;EAhDU;EAAA,IAqDN,MAAA,CAAA;EAAA,UAID,SAAA,CAAU,MAAA;EAab,SAAA,CAAA,GAAS,OAAA;EAIT,SAAA,CAAU,CAAA,UAAW,CAAA,UAAW,CAAA,UAAW,QAAA,YAAkB,WAAA,YAAqB,SAAA;EAIlF,QAAA,CAAA;EAIA,UAAA,CAAA;EAIA,UAAA,CAAW,OAAA;EAIX,gBAAA,CAAA;EAIA,gBAAA,CAAiB,MAAA;AAAA"} |
@@ -15,2 +15,3 @@ import "../../../_virtual/_rolldown/runtime.js"; | ||
| async set(key, value, mode) { | ||
| if (mode && !this.netId) mode = void 0; | ||
| if (mode === 1 && !allowStateBagReplication || mode === 2) { | ||
@@ -51,4 +52,5 @@ if (mode === 2 && this.type !== "Player") throw new Error("Setting synced-states is not supported for non-player entities."); | ||
| const isPlayer = this.type === "Player"; | ||
| const playerId = isPlayer && this.playerId; | ||
| this.#handle = handle; | ||
| this.netId = isPlayer ? GetPlayerServerId(NetworkGetEntityOwner(handle)) : NetworkGetNetworkIdFromEntity(handle); | ||
| this.netId = playerId ? isServer ? playerId : GetPlayerServerId(playerId) : NetworkGetNetworkIdFromEntity(handle); | ||
| this.statebag = this.netId ? `${isPlayer ? "player" : "entity"}:${this.netId}` : `localEntity:${handle}`; | ||
@@ -55,0 +57,0 @@ if (!this.netId || isServer && !isPlayer) EnsureEntityStateBag(handle); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","names":["#handle"],"sources":["../../../../common/game/Entity/index.ts"],"sourcesContent":["import { Vector3 } from '@overextended/core/vector';\nimport { context } from '../..';\n\nconst isServer = context === 'server';\nconst allowStateBagReplication = isServer || !GetConvarBool('sv_stateBagStrictMode', false);\n\nenum StateBagReplication {\n /** The value is replicated to the server and all relevant clients. */\n REPLICATED = 1,\n /** The value is synced between the server and entity owner. Player only. */\n SYNCED = 2,\n}\n\nexport abstract class GameEntity {\n #handle: number = 0;\n readonly type: string = '';\n /** The entity's network id. */\n readonly netId: number = 0;\n protected statebag: string = '';\n\n /** Writes a value to the entity's state. Replicated values are validated by the server. */\n public async set(key: string, value: unknown, mode?: StateBagReplication): Promise<boolean> {\n if ((mode === 1 && !allowStateBagReplication) || mode === 2) {\n if (mode === 2 && this.type !== 'Player') {\n throw new Error('Setting synced-states is not supported for non-player entities.');\n }\n\n if (!isServer) {\n const ok = await import('../../../client/callback').then(\n (m) =>\n m.triggerServerCallback('ox_lib:requestSetStateBag', null, this.statebag, key, value) as Promise<boolean>,\n );\n\n return ok ? this.set(key, value) : false;\n }\n\n emitNet('ox_lib:setStateBagValue', this.netId, key, value);\n }\n\n // @ts-ignore\n const packed = msgpack_pack(value);\n SetStateBagValue(this.statebag, key, packed, packed.length, mode === 1);\n\n return true;\n }\n\n /** Writes a replicated value to the entity's state. Client-set values are validated by the server. */\n public async setr(key: string, value: unknown) {\n return this.set(key, value, 1);\n }\n\n /** Writes a synced value to the entity's state. Client-set values are validated by the server. */\n public async sets(key: string, value: unknown) {\n return this.set(key, value, 2);\n }\n\n /** Returns a value from the entity's state. */\n public get<T = unknown>(key: string): T | undefined {\n return GetStateBagValue(this.statebag, key);\n }\n\n /** Returns if a key exists in the entity's state. */\n public has(key: string) {\n return !!StateBagHasKey(this.statebag, key);\n }\n\n /** Returns an array of all keys in the entity's state. */\n public keys(): string[] {\n return GetStateBagKeys(this.statebag);\n }\n\n /** The entity's script handle */\n public get handle() {\n return this.#handle;\n }\n\n protected setHandle(handle: number) {\n const isPlayer = this.type === 'Player';\n\n this.#handle = handle;\n // @ts-ignore\n this.netId = isPlayer ? GetPlayerServerId(NetworkGetEntityOwner(handle)) : NetworkGetNetworkIdFromEntity(handle);\n this.statebag = this.netId ? `${isPlayer ? 'player' : 'entity'}:${this.netId}` : `localEntity:${handle}`;\n\n if (!this.netId || (isServer && !isPlayer)) {\n EnsureEntityStateBag(handle);\n }\n }\n\n public getCoords() {\n return Vector3.fromArray(GetEntityCoords(this.handle));\n }\n\n public setCoords(x: number, y: number, z: number, deadFlag = false, ragdollFlag = false, clearArea = false) {\n SetEntityCoords(this.handle, x, y, z, true, deadFlag, ragdollFlag, clearArea);\n }\n\n public getModel() {\n return GetEntityModel(this.handle);\n }\n\n public getHeading() {\n return GetEntityHeading(this.handle);\n }\n\n public setHeading(heading: number) {\n SetEntityHeading(this.handle, heading);\n }\n\n public getRoutingBucket() {\n return isServer ? GetEntityRoutingBucket(this.handle) : (this.get('bucket') ?? 0);\n }\n\n public setRoutingBucket(bucket: number) {\n if (!isServer) return;\n\n SetEntityRoutingBucket(this.handle, bucket);\n this.set('bucket', bucket, 1);\n }\n}\n"],"mappings":";;;;AAGA,MAAM,WAAW,YAAY;AAC7B,MAAM,2BAA2B,YAAY,CAAC,cAAc,yBAAyB,KAAK;AAS1F,IAAsB,aAAtB,MAAiC;CAC/B,UAAkB;CAClB,OAAwB;;CAExB,QAAyB;CACzB,WAA6B;;CAG7B,MAAa,IAAI,KAAa,OAAgB,MAA8C;EAC1F,IAAK,SAAS,KAAK,CAAC,4BAA6B,SAAS,GAAG;GAC3D,IAAI,SAAS,KAAK,KAAK,SAAS,UAC9B,MAAM,IAAI,MAAM,iEAAiE;GAGnF,IAAI,CAAC,UAMH,OAAO,MALU,OAAO,qCAA4B,MACjD,MACC,EAAE,sBAAsB,6BAA6B,MAAM,KAAK,UAAU,KAAK,KAAK,CACxF,IAEY,KAAK,IAAI,KAAK,KAAK,IAAI;GAGrC,QAAQ,2BAA2B,KAAK,OAAO,KAAK,KAAK;EAC3D;EAGA,MAAM,SAAS,aAAa,KAAK;EACjC,iBAAiB,KAAK,UAAU,KAAK,QAAQ,OAAO,QAAQ,SAAS,CAAC;EAEtE,OAAO;CACT;;CAGA,MAAa,KAAK,KAAa,OAAgB;EAC7C,OAAO,KAAK,IAAI,KAAK,OAAO,CAAC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
| {"version":3,"file":"index.js","names":["#handle"],"sources":["../../../../common/game/Entity/index.ts"],"sourcesContent":["import { Vector3 } from '@overextended/core/vector';\nimport { context } from '../..';\n\nconst isServer = context === 'server';\nconst allowStateBagReplication = isServer || !GetConvarBool('sv_stateBagStrictMode', false);\n\nenum StateBagReplication {\n /** The value is replicated to the server and all relevant clients. */\n REPLICATED = 1,\n /** The value is synced between the server and entity owner. Player only. */\n SYNCED = 2,\n}\n\nexport abstract class GameEntity {\n #handle: number = 0;\n readonly type: string = '';\n /** The entity's network id. */\n readonly netId: number = 0;\n protected statebag: string = '';\n\n /** Writes a value to the entity's state. Replicated values are validated by the server. */\n public async set(key: string, value: unknown, mode?: StateBagReplication): Promise<boolean> {\n if (mode && !this.netId) mode = undefined;\n \n if ((mode === 1 && !allowStateBagReplication) || mode === 2) {\n if (mode === 2 && this.type !== 'Player') {\n throw new Error('Setting synced-states is not supported for non-player entities.');\n }\n\n if (!isServer) {\n const ok = await import('../../../client/callback').then(\n (m) =>\n m.triggerServerCallback('ox_lib:requestSetStateBag', null, this.statebag, key, value) as Promise<boolean>,\n );\n\n return ok ? this.set(key, value) : false;\n }\n\n emitNet('ox_lib:setStateBagValue', this.netId, key, value);\n }\n\n // @ts-ignore\n const packed = msgpack_pack(value);\n SetStateBagValue(this.statebag, key, packed, packed.length, mode === 1);\n\n return true;\n }\n\n /** Writes a replicated value to the entity's state. Client-set values are validated by the server. */\n public async setr(key: string, value: unknown) {\n return this.set(key, value, 1);\n }\n\n /** Writes a synced value to the entity's state. Client-set values are validated by the server. */\n public async sets(key: string, value: unknown) {\n return this.set(key, value, 2);\n }\n\n /** Returns a value from the entity's state. */\n public get<T = unknown>(key: string): T | undefined {\n return GetStateBagValue(this.statebag, key);\n }\n\n /** Returns if a key exists in the entity's state. */\n public has(key: string) {\n return !!StateBagHasKey(this.statebag, key);\n }\n\n /** Returns an array of all keys in the entity's state. */\n public keys(): string[] {\n return GetStateBagKeys(this.statebag);\n }\n\n /** The entity's script handle */\n public get handle() {\n return this.#handle;\n }\n\n protected setHandle(handle: number) {\n const isPlayer = this.type === 'Player';\n const playerId = isPlayer && ((this as any).playerId as number);\n this.#handle = handle;\n // @ts-expect-error\n this.netId = playerId ? (isServer ? playerId : GetPlayerServerId(playerId)) : NetworkGetNetworkIdFromEntity(handle);\n this.statebag = this.netId ? `${isPlayer ? 'player' : 'entity'}:${this.netId}` : `localEntity:${handle}`;\n\n if (!this.netId || (isServer && !isPlayer)) {\n EnsureEntityStateBag(handle);\n }\n }\n\n public getCoords() {\n return Vector3.fromArray(GetEntityCoords(this.handle));\n }\n\n public setCoords(x: number, y: number, z: number, deadFlag = false, ragdollFlag = false, clearArea = false) {\n SetEntityCoords(this.handle, x, y, z, true, deadFlag, ragdollFlag, clearArea);\n }\n\n public getModel() {\n return GetEntityModel(this.handle);\n }\n\n public getHeading() {\n return GetEntityHeading(this.handle);\n }\n\n public setHeading(heading: number) {\n SetEntityHeading(this.handle, heading);\n }\n\n public getRoutingBucket() {\n return isServer ? GetEntityRoutingBucket(this.handle) : (this.get('bucket') ?? 0);\n }\n\n public setRoutingBucket(bucket: number) {\n if (!isServer) return;\n\n SetEntityRoutingBucket(this.handle, bucket);\n this.set('bucket', bucket, 1);\n }\n}\n"],"mappings":";;;;AAGA,MAAM,WAAW,YAAY;AAC7B,MAAM,2BAA2B,YAAY,CAAC,cAAc,yBAAyB,KAAK;AAS1F,IAAsB,aAAtB,MAAiC;CAC/B,UAAkB;CAClB,OAAwB;;CAExB,QAAyB;CACzB,WAA6B;;CAG7B,MAAa,IAAI,KAAa,OAAgB,MAA8C;EAC1F,IAAI,QAAQ,CAAC,KAAK,OAAO,OAAO,KAAA;EAEhC,IAAK,SAAS,KAAK,CAAC,4BAA6B,SAAS,GAAG;GAC3D,IAAI,SAAS,KAAK,KAAK,SAAS,UAC9B,MAAM,IAAI,MAAM,iEAAiE;GAGnF,IAAI,CAAC,UAMH,OAAO,MALU,OAAO,qCAA4B,MACjD,MACC,EAAE,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AAe,KAAK,MAAM;CACnC;CAEA,aAAoB;EAClB,OAAO,iBAAiB,KAAK,MAAM;CACrC;CAEA,WAAkB,SAAiB;EACjC,iBAAiB,KAAK,QAAQ,OAAO;CACvC;CAEA,mBAA0B;EACxB,OAAO,WAAW,uBAAuB,KAAK,MAAM,IAAK,KAAK,IAAI,QAAQ,KAAK;CACjF;CAEA,iBAAwB,QAAgB;EACtC,IAAI,CAAC,UAAU;EAEf,uBAAuB,KAAK,QAAQ,MAAM;EAC1C,KAAK,IAAI,UAAU,QAAQ,CAAC;CAC9B;AACF"} |
+3
-3
| { | ||
| "name": "@overextended/ox_lib", | ||
| "version": "3.36.4", | ||
| "version": "3.37.0", | ||
| "description": "JS/TS wrapper for ox_lib exports", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
| "format": "oxfmt", | ||
| "prepublishOnly": "bun run format & bun run compile" | ||
| "prepublishOnly": "bun run compile" | ||
| }, | ||
@@ -78,2 +78,2 @@ "dependencies": { | ||
| } | ||
| } | ||
| } |
363807
0.07%2883
0.07%