Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Fix Object Entity Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Oct 25, 2023
1 parent f2b2e2a commit 167e453
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 5.3.1
```
- Fix Object Entity Selection
```

## 5.3.0
```
- Update configs, and resource builder to toml only
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altv-athena",
"version": "5.3.0",
"version": "5.3.1",
"description": "a roleplay framework for alt:V",
"author": "stuyk",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/core/client/streamers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as alt from 'alt-client';
import { SYSTEM_EVENTS } from '@AthenaShared/enums/system.js';
import { IObject } from '@AthenaShared/interfaces/iObject.js';

export type CreatedObject = IObject & { createdObject?: alt.Object };
export type CreatedObject = IObject & { createdObject?: alt.LocalObject | alt.Object };

const clientObjects: { [uid: string]: CreatedObject } = {};
const serverObjects: { [uid: string]: CreatedObject } = {};
Expand Down
21 changes: 16 additions & 5 deletions src/core/client/systems/entitySelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MARKER_TYPE } from '@AthenaShared/enums/markerTypes.js';
import { SYSTEM_EVENTS } from '@AthenaShared/enums/system.js';
import { Interaction } from '@AthenaShared/interfaces/interaction.js';
import { KEY_BINDS } from '@AthenaShared/enums/keyBinds.js';
import { CreatedObject } from '@AthenaClient/streamers/object.js';

export type ValidEntityTypes = 'object' | 'pos' | 'npc' | 'player' | 'vehicle' | 'interaction';
export type TargetInfo = {
Expand Down Expand Up @@ -197,7 +198,18 @@ const Internal = {
AthenaClient.menu.vehicle.open(targetVehicle);
break;
case 'object':
const object = alt.Object.all.find((x) => x.scriptID === selection.id);
let object = alt.Object.all.find((x) => x.scriptID === selection.id);
let createdObject;

if (!object) {
const localObject = AthenaClient.streamers.object.getFromScriptId(selection.id);
if (localObject.createdObject) {
createdObject = localObject.createdObject
}
} else {
createdObject = {...object.getStreamSyncedMeta('object') as Object, createdObject: object };
}

if (typeof object === 'undefined') {
break;
}
Expand All @@ -224,12 +236,11 @@ const Internal = {
break;
}

const objectInstance = AthenaClient.streamers.object.getFromScriptId(selection.id);
if (typeof objectInstance === 'undefined') {
break;
if (!createdObject) {
return;
}

AthenaClient.menu.object.open(objectInstance);
AthenaClient.menu.object.open(createdObject);
break;
case 'pos':
break;
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/controllers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SYSTEM_EVENTS } from '../../shared/enums/system.js';
import { IObject } from '../../shared/interfaces/iObject.js';
import { sha256Random } from '../utility/hash.js';
import { ControllerFuncs } from './shared.js';
import { deepCloneObject } from '@AthenaShared/utility/deepCopy.js';

const globalObjects: Array<IObject & { object: alt.Object }> = [];

Expand Down Expand Up @@ -59,6 +60,7 @@ export function append(objectData: IObject): string {
newObject.object.collision = false;
}

newObject.object.setStreamSyncedMeta('object', objectData);
globalObjects.push(newObject);
return objectData.uid;
}
Expand Down Expand Up @@ -200,6 +202,7 @@ export function updatePosition(uid: string, pos: alt.IVector3, player: alt.Playe

globalObjects[index].pos = pos;
globalObjects[index].object.pos = new alt.Vector3(pos);
globalObjects[index].object.setStreamSyncedMeta('object', deepCloneObject(globalObjects[index]));
return true;
}

Expand All @@ -216,6 +219,7 @@ export function updateModel(uid: string, model: string, player: alt.Player = und

globalObjects[index].model = model;
globalObjects[index].object.model = model;
globalObjects[index].object.setStreamSyncedMeta('object', deepCloneObject(globalObjects[index]));
return true;
}

Expand Down

0 comments on commit 167e453

Please sign in to comment.