Skip to content
HotWeapon

Gameplay / HotWeapon

HotWeapon Class

Hot Weapon

The Hot Weapon function refers to the use and management mechanism of weapons in the game, which enables Player to use various types of weapons in combat.

  1. Shooting - When the player presses the fire button, the weapon will fire bullets or light.

  2. Loading - After each shoot, the next round of ammunition needs to be loaded into the chamber.

  3. When the magazine is empty, a new magazine needs to be replaced.

  4. Backlash - When shooting, recoil is generated, causing the crosshair to slightly shift.

Precautions

The function of this object can only take effect when the player is equipped.

Usage example: create a script named "HotWeaponSample1", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save it, search the local asset library for 80484, 4172, 4171 animation asset, and drag it into the priority loading directory in the object manager. Run the game, press 1, 2, 3, 4, and you will see a Hot Weapon setting parameter in the scene, add delegate, bind the key, and the effect of character reload. The code is as follows:

ts
@Component
 export default class HotWeaponSample1 extends Script {
     protected onStart(): void {
         // structure
         const hotWeapon = this.gameObject as HotWeapon;

         if (SystemUtil.isServer()) {
             hotWeapon.fireComponent.isFireOnScreenCenter = false
             hotWeapon.fireComponent.clipSize = 50
             hotWeapon.fireComponent.fireInterval = 0
             hotWeapon.fireComponent.multipleShot = 3
             hotWeapon.fireComponent.isFireOnScreenCenter = false
             hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
             // Set parameters
             hotWeapon.fireComponent.animationAssetId = "80484";
             hotWeapon.fireComponent.fireMode = HotWeaponFireMode.SingleFire;

             hotWeapon.aimEnabled = true;
             // Switching between first/third person aiming
             hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
             // Set the magnifying power for simulating aiming (only effective when aiming in first person, range 1-18)
             hotWeapon.aimComponent.aimingZoom = 16;
             hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;

             hotWeapon.loadEnabled = true;
             hotWeapon.loadComponent.loadDuration = 1
             hotWeapon.loadComponent.loadAfterFireEnabled = true;
             hotWeapon.loadComponent.animationAssetId = "4172";

             hotWeapon.reloadEnabled = true;
             hotWeapon.reloadComponent.reloadDuration = 2;
             hotWeapon.reloadComponent.animationAssetId = "4171";

             hotWeapon.recoilForceEnabled = true;
             hotWeapon.recoilForceComponent.minHorizontalOffset = 1;
             hotWeapon.recoilForceComponent.maxHorizontalOffset = 1;
             hotWeapon.recoilForceComponent.minVerticalOffset = 1;
             hotWeapon.recoilForceComponent.maxVerticalOffset = 1;
             hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
             hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
             hotWeapon.recoilForceComponent.minVerticalJitter = 1;
             hotWeapon.recoilForceComponent.maxVerticalJitter = 1;

             hotWeapon.accuracyOfFireEnabled = true;
             // The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
             hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
             // The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
             hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
             // Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
             hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
             // The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
             // The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
             // Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;

             hotWeapon.onEquip.add((owner) => { Console. log ("The callback will be triggered on the server side after the hot weapon equipment is ready")});
             hotWeapon.onUnequip.add(() => { console.log("onUnequippedServer") });

             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
             hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });

             hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
             hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });

             hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });

             hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
             hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });

             hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
             hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });

             mw.Event.addClientListener("weaponEquipment", (player) => {
                 // At present, the equipment method can only be called call
                 hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
             });
         } else if (SystemUtil.isClient()) {
             hotWeapon.onEquip.add(() => { console.log("onEquippedClient") });
             hotWeapon.onUnequip.add(() => { console.log("onUnequippedClient") });

             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });

             hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
             hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });

             hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });

             hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
             hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });

             hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });

             hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
             hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });

             // Equipment
             InputUtil.onKeyDown(Keys.One, () => {
                 mw.Event.dispatchToServer("weaponEquipment");
             });

             InputUtil.onKeyDown(Keys.Two, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                     hotWeapon.stopFire();
                 } else {
                     hotWeapon.startFire();
                 }
             });

               InputUtil.onKeyDown(Keys.Three, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                     hotWeapon.breakReload();
                 } else {
                     hotWeapon.reload(30);
                 }
             });

             InputUtil.onKeyDown(Keys.Four, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                     hotWeapon.breakLoad();
                 } else {
                     hotWeapon.load();
                 }
             });
         }
     }
 }
@Component
 export default class HotWeaponSample1 extends Script {
     protected onStart(): void {
         // structure
         const hotWeapon = this.gameObject as HotWeapon;

         if (SystemUtil.isServer()) {
             hotWeapon.fireComponent.isFireOnScreenCenter = false
             hotWeapon.fireComponent.clipSize = 50
             hotWeapon.fireComponent.fireInterval = 0
             hotWeapon.fireComponent.multipleShot = 3
             hotWeapon.fireComponent.isFireOnScreenCenter = false
             hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
             // Set parameters
             hotWeapon.fireComponent.animationAssetId = "80484";
             hotWeapon.fireComponent.fireMode = HotWeaponFireMode.SingleFire;

             hotWeapon.aimEnabled = true;
             // Switching between first/third person aiming
             hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
             // Set the magnifying power for simulating aiming (only effective when aiming in first person, range 1-18)
             hotWeapon.aimComponent.aimingZoom = 16;
             hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;

             hotWeapon.loadEnabled = true;
             hotWeapon.loadComponent.loadDuration = 1
             hotWeapon.loadComponent.loadAfterFireEnabled = true;
             hotWeapon.loadComponent.animationAssetId = "4172";

             hotWeapon.reloadEnabled = true;
             hotWeapon.reloadComponent.reloadDuration = 2;
             hotWeapon.reloadComponent.animationAssetId = "4171";

             hotWeapon.recoilForceEnabled = true;
             hotWeapon.recoilForceComponent.minHorizontalOffset = 1;
             hotWeapon.recoilForceComponent.maxHorizontalOffset = 1;
             hotWeapon.recoilForceComponent.minVerticalOffset = 1;
             hotWeapon.recoilForceComponent.maxVerticalOffset = 1;
             hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
             hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
             hotWeapon.recoilForceComponent.minVerticalJitter = 1;
             hotWeapon.recoilForceComponent.maxVerticalJitter = 1;

             hotWeapon.accuracyOfFireEnabled = true;
             // The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
             hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
             // The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
             hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
             // Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
             hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
             // The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
             // The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
             // Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
             hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;

             hotWeapon.onEquip.add((owner) => { Console. log ("The callback will be triggered on the server side after the hot weapon equipment is ready")});
             hotWeapon.onUnequip.add(() => { console.log("onUnequippedServer") });

             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
             hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });

             hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
             hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });

             hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });

             hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
             hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });

             hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
             hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });

             mw.Event.addClientListener("weaponEquipment", (player) => {
                 // At present, the equipment method can only be called call
                 hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
             });
         } else if (SystemUtil.isClient()) {
             hotWeapon.onEquip.add(() => { console.log("onEquippedClient") });
             hotWeapon.onUnequip.add(() => { console.log("onUnequippedClient") });

             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });

             hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
             hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });

             hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });

             hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
             hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });

             hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });

             hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
             hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });

             // Equipment
             InputUtil.onKeyDown(Keys.One, () => {
                 mw.Event.dispatchToServer("weaponEquipment");
             });

             InputUtil.onKeyDown(Keys.Two, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                     hotWeapon.stopFire();
                 } else {
                     hotWeapon.startFire();
                 }
             });

               InputUtil.onKeyDown(Keys.Three, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                     hotWeapon.breakReload();
                 } else {
                     hotWeapon.reload(30);
                 }
             });

             InputUtil.onKeyDown(Keys.Four, () => {
                 // Start executing the operation
                 if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                     hotWeapon.breakLoad();
                 } else {
                     hotWeapon.load();
                 }
             });
         }
     }
 }

Hierarchy

Table of contents

Properties

accuracyOfFireComponent: HotWeaponAccuracyOfFireComponent
Shooting accuracy function.
aimComponent: HotWeaponAimComponent
Aim function.
fireComponent: HotWeaponFireComponent
Shoot function.
loadComponent: HotWeaponLoadComponent
Loading function.
onEquip: MulticastDelegateInterface<(EquipOwner: $Nullable<Actor>) => void>
Execute binding function when equipping hot weapons
onUnequip: MulticastDelegateInterface<() => void>
Execute binding function during server uninstallation. See property onEquipped for usage example
recoilForceComponent: HotWeaponRecoilForceComponent
Rear sitting force function.
reloadComponent: HotWeaponReloadComponent
Bullet replacement function.
click

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void> other
Event callback before object destruction
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Monitor custom attribute synchronization events
onDestroyDelegate: MulticastDelegate<() => void> other
Event callback after object destruction
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
Monitor system replicated events

Accessors

accuracyOfFireEnabled(): boolean other
Whether the shoot accuracy component is enabled.
aimEnabled(): boolean other
Whether the aim component is enabled.
loadEnabled(): boolean other
Has the loading component been activated.
recoilForceEnabled(): boolean other
Determine whether the recoil component has been activated.
reloadEnabled(): boolean other
Whether the reload component is enabled.
click

Accessors

actorFlagValue(): number other
Get object tags
actorLevel(): number other
Obtain Actor Level
assetId(): string other
Retrieve the UID of the resource currently being used by the object
gameObjectId(): string other
Get the unique identification of an object (a string that uniquely identifies an object).
isDestroyed(): boolean other
Has the current object been destroyed
isReady(): boolean other
Current object status
localTransform(): Transform other
Local transformation of the current object
name(): string other
Return the current object name
netStatus(): NetStatus other
Get the current object synchronization status
parent(): GameObject other
Retrieve the current parent object
tag(): string other
Get the tag of the current object
worldTransform(): Transform other
Current object world transformation

Methods

breakLoad(): void other
Interrupt the loading.
breakReload(): void other
Interrupt and reload
cloneComponentsData(otherHotWeapon: HotWeapon): void other
Copy all component data from the incoming Hot Weapon logical object to the current Hot Weapon.
equip(character: Character, slotName: HumanoidSlotType): void other
Equip hot weapons to the designated slot position of the character
getBulletLocWhileSpawnOnScreenCenter(): Vector other
When using the screen center to generate bullet projectile mode, obtain the location of the bullet projectile generated
getCurrentOwner(): Character other
Get the owner of the current Hot Weapon
getCurrentState(): HotWeaponState other
Obtain the current status of the hot weapon
getDefaultCrossHairSize(maxShootRange: number): number other
Pass in the maximum range and obtain the default crosshair size
getShootDirWithDispersion(StartLoc: Vector, ShootRange: number): Vector other
Get the bullet's flight direction in the mode of generate bullets not in the screen center
load(): void other
Loading the chamber
reload(bulletSize: number): void other
Reload
startFire(): void other
FireStarter
stopFire(): void other
Stop firing
unequip(): void other
Unload hot weapons.
click

Methods

addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> other
Add a script component
asyncGetChildByName(name: string): Promise<GameObject> other
Asynchronous search for sub objects based on their names
asyncReady(): Promise<GameObject> other
Return after the object is ready
clone(gameObjectInfo?: GameObjectInfo): GameObject other
Copy Objects
destroy(): void other
delete object
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector other
Get the size of the object's bounding box
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void other
Obtain object boundaries
getChildByGameObjectId(gameObjectId: string): GameObject other
Search for sub objects based on gameObjectid
getChildByName(name: string): GameObject other
Search for sub objects by name
getChildByPath(path: string): GameObject other
Find sub objects according to path
getChildren(): GameObject[] other
Obtain sub objects
getChildrenBoundingBoxCenter(outer?: Vector): Vector other
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])
getChildrenByName(name: string): GameObject[] other
Search for all sub objects by name
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> other
Get the component of the specified type
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> other
Get property of script component
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] other
Get all component of the specified type
getCustomProperties(): string[] other
Get all customize property
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType other
Get customize property
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getVisibility(): boolean other
Obtain whether the object is displayed
isPrefabActor(): boolean other
Return whether the current object is a prefabricated body
moveBy(velocity: Vector, isLocal?: boolean): void other
Smoothly move an object over time according to a given velocity vector
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly move from the current position to the target position within the specified time
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other
Rotate the object smoothly over time according to the given rotation amount
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current rotation to the target rotation within the specified time
scaleBy(scale: Vector, isLocal?: boolean): void other
Smoothly scale objects over time using a given scaling vector per second
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current scale to the target scale within the specified time
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void other
Set whether the object localTransform is relative to the parent object or the world
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void other
Set custom attributes
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void other
Set whether the object is displayed
stopMove(): void other
Interrupt further movement of moveTo() and moveBy()
stopRotate(): void other
Interrupt further rotation from rotateTo() or rotateBy()
stopScale(): void other
Interrupt further scale from ScaleTo() or ScaleBy()
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> other
Asynchronous search for GameObject through gameObjectid
asyncGetGameObjectByPath(path: string): Promise<GameObject> other
Asynchronously find objects through path
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> other
Asynchronous construction of an object
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void other
Batch set position
findGameObjectById(gameObjectId: string): GameObject other
Search for objects through gameObjectid
findGameObjectByName(name: string): GameObject other
Search for objects by name
findGameObjectsByName(name: string): GameObject[] other
Search for objects by name
findGameObjectsByTag(tag: string): GameObject[] other
Get objects through customize tag
getGameObjectByPath(path: string): GameObject other
Search for objects through paths
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> other
Construct an object

Properties

accuracyOfFireComponent

accuracyOfFireComponent: HotWeaponAccuracyOfFireComponent

Shooting accuracy function.

This function can be regarded as a function component of hotheapon, which is only used for Hot Weapon.

Example usage: Create a script called "HotWeaponAofSample", place it in the object manager, open the script, enter the following code to save, run the game, the code is as follows:

ts
@Component
export default class HotWeaponAofSample extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.accuracyOfFireEnabled = true;
            // The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
            hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
            // The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
            hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
            // Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
            hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
            // The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
            // The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
            // Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
        } else if (SystemUtil.isClient()) {
            hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
        }
    }
}
@Component
export default class HotWeaponAofSample extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.accuracyOfFireEnabled = true;
            // The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
            hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
            // The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
            hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
            // Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
            hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
            // The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
            // The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
            // Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
            hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
        } else if (SystemUtil.isClient()) {
            hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
        }
    }
}

aimComponent

aimComponent: HotWeaponAimComponent

Aim function.

Usage example: create a script named "HotWeaponAimSample1", place it in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponAimSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.aimEnabled = true;
            hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
            hotWeapon.aimComponent.aimingZoom = 16;
            hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        }
    }
}
@Component
export default class HotWeaponAimSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.aimEnabled = true;
            hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
            hotWeapon.aimComponent.aimingZoom = 16;
            hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        }
    }
}

fireComponent

fireComponent: HotWeaponFireComponent

Shoot function.

Example usage: Create a script named "HotWeaponFireSample1", place it in the child node of the object manager's hot weapon, open the script, enter the following code to save, run the game, the code is as follows:

ts
@Component
 export default class HotWeaponFireSample1 extends Script {
     protected onStart(): void {
         // structure
         const hotWeapon = this.gameObject as HotWeapon;

         if (SystemUtil.isServer()) {
             hotWeapon.fireComponent.isFireOnScreenCenter = false;
             hotWeapon.fireComponent.clipSize = 50;
             hotWeapon.fireComponent.fireInterval = 0;
             hotWeapon.fireComponent.multipleShot = 3;
             hotWeapon.fireComponent.isFireOnScreenCenter = false;
             hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
             // Set parameters
             hotWeapon.fireComponent.animationAssetId = "80484";
             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
             hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
         }
     }
 }
@Component
 export default class HotWeaponFireSample1 extends Script {
     protected onStart(): void {
         // structure
         const hotWeapon = this.gameObject as HotWeapon;

         if (SystemUtil.isServer()) {
             hotWeapon.fireComponent.isFireOnScreenCenter = false;
             hotWeapon.fireComponent.clipSize = 50;
             hotWeapon.fireComponent.fireInterval = 0;
             hotWeapon.fireComponent.multipleShot = 3;
             hotWeapon.fireComponent.isFireOnScreenCenter = false;
             hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
             // Set parameters
             hotWeapon.fireComponent.animationAssetId = "80484";
             hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
             hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
             hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
         }
     }
 }

loadComponent

loadComponent: HotWeaponLoadComponent

Loading function.

Example usage: Create a script named "HotWeaponLoadSample1", place it in the object manager, open the script, enter the following code to save, run the game, the code is as follows:

ts
@Component
export default class HotWeaponLoadSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.loadEnabled = true;
            hotWeapon.loadComponent.loadDuration = 1
            hotWeapon.loadComponent.loadAfterFireEnabled = true;
            hotWeapon.loadComponent.animationAssetId = "4172";

            hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Server") });
            hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Server") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Client") });
            hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Client") });
        }
    }
}
@Component
export default class HotWeaponLoadSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.loadEnabled = true;
            hotWeapon.loadComponent.loadDuration = 1
            hotWeapon.loadComponent.loadAfterFireEnabled = true;
            hotWeapon.loadComponent.animationAssetId = "4172";

            hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Server") });
            hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Server") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Client") });
            hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Client") });
        }
    }
}

onEquip

onEquip: MulticastDelegateInterface<(EquipOwner: $Nullable<Actor>) => void>

Execute binding function when equipping hot weapons

This delegate can be executed at both ends. When you call on the server, the character will execute customize binding functions on the server when Hot Weapon are on the equipment; When calling on the client, the custom binding function will be executed on the client when the character is equipped with a hot weapon.

Usage example: create a script named "HotWeaponSample2", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample2 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.onEquip.add((owner) => { Console. log ("The callback will be triggered on the server side after the hot weapon equipment is ready")});
            hotWeapon.onUnequip.add(() => { console.log("onUnequipServer") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.onEquip.add(() => { console.log("onEquip Client") });
            hotWeapon.onUnequip.add(() => { console.log("onUnequip Client") });
        }
    }
}
@Component
export default class HotWeaponSample2 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.onEquip.add((owner) => { Console. log ("The callback will be triggered on the server side after the hot weapon equipment is ready")});
            hotWeapon.onUnequip.add(() => { console.log("onUnequipServer") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.onEquip.add(() => { console.log("onEquip Client") });
            hotWeapon.onUnequip.add(() => { console.log("onUnequip Client") });
        }
    }
}

onUnequip

onUnequip: MulticastDelegateInterface<() => void>

Execute binding function during server uninstallation. See property onEquipped for usage example


recoilForceComponent

recoilForceComponent: HotWeaponRecoilForceComponent

Rear sitting force function.

Usage example: create a script named "HotWeaponRecoverForceSample", place it in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponRecoilForceSample extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.recoilForceEnabled = true;
            hotWeapon.recoilForceComponent.minHorizontalOffset = 1
            hotWeapon.recoilForceComponent.maxHorizontalOffset = 1
            hotWeapon.recoilForceComponent.minVerticalOffset = 1
            hotWeapon.recoilForceComponent.maxVerticalOffset = 1
            hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
            hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
            hotWeapon.recoilForceComponent.minVerticalJitter = 1;
            hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
        }
        hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForce") });
    }
}
@Component
export default class HotWeaponRecoilForceSample extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.recoilForceEnabled = true;
            hotWeapon.recoilForceComponent.minHorizontalOffset = 1
            hotWeapon.recoilForceComponent.maxHorizontalOffset = 1
            hotWeapon.recoilForceComponent.minVerticalOffset = 1
            hotWeapon.recoilForceComponent.maxVerticalOffset = 1
            hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
            hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
            hotWeapon.recoilForceComponent.minVerticalJitter = 1;
            hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
        }
        hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForce") });
    }
}

reloadComponent

reloadComponent: HotWeaponReloadComponent

Bullet replacement function.

Usage example: create a script named "HotWeaponReloadSample1", place it in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponReloadSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {

            hotWeapon.reloadEnabled = true;
            hotWeapon.reloadComponent.reloadDuration = 2;
            hotWeapon.reloadComponent.animationAssetId = "4171";

            hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Server") });
            hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Server") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Client") });
            hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Client") });
        }
    }
}
@Component
export default class HotWeaponReloadSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {

            hotWeapon.reloadEnabled = true;
            hotWeapon.reloadComponent.reloadDuration = 2;
            hotWeapon.reloadComponent.animationAssetId = "4171";

            hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Server") });
            hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Server") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Client") });
            hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Client") });
        }
    }
}

Accessors

accuracyOfFireEnabled

get accuracyOfFireEnabled(): boolean other

set accuracyOfFireEnabled(isEnabled): void other

Whether the shoot accuracy component is enabled.

Returns

booleanHas the shooting accuracy component been enabled

Set whether to enable the shooting accuracy component.

Default enabled

Parameters

isEnabled booleanEnable status of shoot accuracy component

aimEnabled

get aimEnabled(): boolean other

set aimEnabled(value): void other

Whether the aim component is enabled.

Returns

booleanHas the aiming component been enabled

Set whether to enable the aiming component.

Default enabled

Parameters

value booleanAim component enable status

loadEnabled

get loadEnabled(): boolean other

set loadEnabled(isEnabled): void other

Has the loading component been activated.

Returns

booleanWhether the loading component is opened

Set whether to open the loading component.

Default enabled

Parameters

isEnabled booleanLoading component enable status

recoilForceEnabled

get recoilForceEnabled(): boolean other

set recoilForceEnabled(isEnabled): void other

Determine whether the recoil component has been activated.

Returns

booleanHas the recoil component been activated

Set whether to open the rear seat force component.

Default enabled

Parameters

isEnabled booleanRear seat force component enable status

reloadEnabled

get reloadEnabled(): boolean other

set reloadEnabled(isEnabled): void other

Whether the reload component is enabled.

Returns

booleanWhether the reload component is enabled

Set whether to enable the ammunition replacement component.

Default enabled

Parameters

isEnabled booleanEnable status of reload component

Methods


breakLoad

breakLoad(): void other

Interrupt the loading.

Usage example: create a script named "HotWeaponSample10", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample10 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                   hotWeapon.breakLoad();
               } else {
                   hotWeapon.load();
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample10 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                   hotWeapon.breakLoad();
               } else {
                   hotWeapon.load();
               }
           });
       }
    }
}

breakReload

breakReload(): void other

Interrupt and reload

Usage example: create a script named "HotWeaponSample9", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, run the game, press the "2" key, Hot Weapon reload, and stop reload. The code is as follows:

ts
@Component
export default class HotWeaponSample9 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                   hotWeapon.breakReload();
               } else {
                   hotWeapon.reload(30);
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample9 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                   hotWeapon.breakReload();
               } else {
                   hotWeapon.reload(30);
               }
           });
       }
    }
}

cloneComponentsData

cloneComponentsData(otherHotWeapon): void other

Copy all component data from the incoming Hot Weapon logical object to the current Hot Weapon.

Parameters

otherHotWeapon HotWeaponData source.

Precautions

The agent delegate binding event cannot be copied. After the copy is completed, there is a short delay in data sync to the client.


equip

equip(character, slotName): void other

Equip hot weapons to the designated slot position of the character

Parameters

character CharacterThe equipment object of this weapon
slotName HumanoidSlotTypeThe slot name to be equipped on the character

If you want to equip weapons on a character, you need to call this function on the server. The client call will not report an error, but it will not take effect.

Usage example: Create a script called "HotWeaponSample", place it in the object manager as a hot weapon object sub level, and select a weapon resource to place in the hot weapon sub level (remember to open the weapon resource properties panel and set collision to off). Open the script, enter the following code to save, run the game, press the E key, and a Hot Weapon equipment will be put on the right hand of the character. The code is as follows:

ts
@Component
export default class HotWeaponSample extends Script {
    protected onStart(): void {

       const hotWeapon = this.gameObject as HotWeapon;

       if (SystemUtil.isServer()) {
           mw.Event.addClientListener("weaponEquipment", (player) => {
               // At present, the equipment method can only be called call
               hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
           });
       }

       if (SystemUtil.isClient()) {
           // Equipment
           InputUtil.onKeyDown(Keys.One, () => {
               mw.Event.dispatchToServer("weaponEquipment");
           });
           InputUtil.onKeyDown(Keys.Two, () => {
               hotWeapon.unequip();
           });
       }
    }
}
@Component
export default class HotWeaponSample extends Script {
    protected onStart(): void {

       const hotWeapon = this.gameObject as HotWeapon;

       if (SystemUtil.isServer()) {
           mw.Event.addClientListener("weaponEquipment", (player) => {
               // At present, the equipment method can only be called call
               hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
           });
       }

       if (SystemUtil.isClient()) {
           // Equipment
           InputUtil.onKeyDown(Keys.One, () => {
               mw.Event.dispatchToServer("weaponEquipment");
           });
           InputUtil.onKeyDown(Keys.Two, () => {
               hotWeapon.unequip();
           });
       }
    }
}

Usage example: create a script named "HotWeaponSample", open the script, enter the following code to save, this example is to dynamically load the Hot Weapon and weapon model asset, do not need to configuration in the right column, run the game, and send a Hot Weapon equipment to the right hand of the character. The code is as follows:

ts
@Component
export default class weapon extends Script {

   private hotweapon:HotWeapon;
   private gun:Model;

   protected async onStart(): Promise<void> {
       if(SystemUtil.isServer()) {
           this.hotweapon = await GameObject.asyncSpawn<HotWeapon>("HotWeapon",{
               replicates:true,
               transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
           });
           this.gun = await GameObject.asyncSpawn<Model>("44980",{
               replicates:true,
               transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
           });
           this.gun.parent = this.hotweapon;
           this.gun.setCollision(PropertyStatus.Off);
           Player.onPlayerJoin.add(()=>{
               Player.getAllPlayers().forEach(element => {
                   this.player = element.character;
               });
               this.hotweapon.equip(this.player,HumanoidSlotType.RightHand);
          })
       }
   }
}
@Component
export default class weapon extends Script {

   private hotweapon:HotWeapon;
   private gun:Model;

   protected async onStart(): Promise<void> {
       if(SystemUtil.isServer()) {
           this.hotweapon = await GameObject.asyncSpawn<HotWeapon>("HotWeapon",{
               replicates:true,
               transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
           });
           this.gun = await GameObject.asyncSpawn<Model>("44980",{
               replicates:true,
               transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
           });
           this.gun.parent = this.hotweapon;
           this.gun.setCollision(PropertyStatus.Off);
           Player.onPlayerJoin.add(()=>{
               Player.getAllPlayers().forEach(element => {
                   this.player = element.character;
               });
               this.hotweapon.equip(this.player,HumanoidSlotType.RightHand);
          })
       }
   }
}

getBulletLocWhileSpawnOnScreenCenter

getBulletLocWhileSpawnOnScreenCenter(): Vector other

When using the screen center to generate bullet projectile mode, obtain the location of the bullet projectile generated

Returns

VectorGenerate location of bullet projectile

Precautions

The server does not have a character camera component

Usage example: create a script named "HotWeaponSample5", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample5 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;
        if (SystemUtil.isClient()) {
            const bulletLoc = hotWeapon.getBulletLocWhileSpawnOnScreenCenter()
            // Omission: Generate projectiles
        }
    }
}
@Component
export default class HotWeaponSample5 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;
        if (SystemUtil.isClient()) {
            const bulletLoc = hotWeapon.getBulletLocWhileSpawnOnScreenCenter()
            // Omission: Generate projectiles
        }
    }
}

getCurrentOwner

getCurrentOwner(): Character other

Get the owner of the current Hot Weapon

Returns

CharacterCurrent owner of Hot Weapon

Usage example: create a script named "HotWeaponSample6", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, run the game, and obtain the current Hot Weapon owner code as follows:

ts
@Component
export default class HotWeaponSample6 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;
        const hotWeaponOwner = hotWeapon.getCurrentOwner()
    }
}
@Component
export default class HotWeaponSample6 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;
        const hotWeaponOwner = hotWeapon.getCurrentOwner()
    }
}

getCurrentState

getCurrentState(): HotWeaponState other

Obtain the current status of the hot weapon

Returns

HotWeaponStateCurrent Hot Weapon status

Usage example: create a script named "HotWeaponSample11", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample11 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       // Hot weapons need to be equipped first, see method equipment
       const status = hotWeapon.getCurrentState();
    }
}
@Component
export default class HotWeaponSample11 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       // Hot weapons need to be equipped first, see method equipment
       const status = hotWeapon.getCurrentState();
    }
}

getDefaultCrossHairSize

getDefaultCrossHairSize(maxShootRange): number other

Pass in the maximum range and obtain the default crosshair size

Parameters

maxShootRange numberMaximum range
default: 100
range: [0100000] type: floating-point number

Returns

numberDefault crosshair size (shooting accuracy half angle value)

Usage example: create a script named "HotWeaponSample3", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample3 extends mw.Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as mw.HotWeapon;
        if (SystemUtil.isClient()) {
            // Enter the range and obtain the accurate center spread size
            const crossHairSize = hotWeapon.getDefaultCrossHairSize(1000)
            // Omitted: Update UI center position
        }
    }
}
@Component
export default class HotWeaponSample3 extends mw.Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as mw.HotWeapon;
        if (SystemUtil.isClient()) {
            // Enter the range and obtain the accurate center spread size
            const crossHairSize = hotWeapon.getDefaultCrossHairSize(1000)
            // Omitted: Update UI center position
        }
    }
}

getShootDirWithDispersion

getShootDirWithDispersion(StartLoc, ShootRange): Vector other

Get the bullet's flight direction in the mode of generate bullets not in the screen center

Parameters

StartLoc VectorBullet generate position
ShootRange numberMaximum range
default: 100
range: [0, 100000] type: floating-point number

Returns

VectorThe actual flight direction of the bullet

Precautions

This function can input the ray direction emitted from the offset screen center

Precautions

The server does not have a character camera component


load

load(): void other

Loading the chamber

Usage example: create a script named "HotWeaponSample10", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample10 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                   hotWeapon.breakLoad();
               } else {
                   hotWeapon.load();
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample10 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
                   hotWeapon.breakLoad();
               } else {
                   hotWeapon.load();
               }
           });
       }
    }
}

reload

reload(bulletSize): void other

Reload

Parameters

bulletSize numberBullet count
range: [1, ClipSize] type: integer

Usage example: create a script named "HotWeaponSample9", place it in the sub level of the Hot Weapon object in the object manager, open the script, enter the following code to save, run the game, press the "2" key, Hot Weapon reload, and stop reload. The code is as follows:

ts
@Component
export default class HotWeaponSample9 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                   hotWeapon.breakReload();
               } else {
                   hotWeapon.reload(30);
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample9 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
                   hotWeapon.breakReload();
               } else {
                   hotWeapon.reload(30);
               }
           });
       }
    }
}

startFire

startFire(): void other

FireStarter

Example usage: Create a script named "HotWeaponSample8", place it in the object manager as a hot weapon object child, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample8 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                   hotWeapon.stopFire();
               } else {
                   hotWeapon.startFire();
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample8 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                   hotWeapon.stopFire();
               } else {
                   hotWeapon.startFire();
               }
           });
       }
    }
}

stopFire

stopFire(): void other

Stop firing

Example usage: Create a script named "HotWeaponSample8", place it in the object manager as a hot weapon object child, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponSample8 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                   hotWeapon.stopFire();
               } else {
                   hotWeapon.startFire();
               }
           });
       }
    }
}
@Component
export default class HotWeaponSample8 extends Script {
    protected onStart(): void {
       const hotWeapon = this.gameObject as HotWeapon;
       if (SystemUtil.isClient()) {
           // Hot weapons need to be equipped first, see method equipment
           InputUtil.onKeyDown(Keys.Two, () => {
               // Start executing the operation
               if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
                   hotWeapon.stopFire();
               } else {
                   hotWeapon.startFire();
               }
           });
       }
    }
}

unequip

unequip(): void other

Unload hot weapons.