• Guides
  • Scripting
  • Visual Scripting
  • Equipment Limit

Equipment Limit


Equipment limit is a common mechanism in RPG games. For example, you stipulate that players can only carry one weapon and one piece of armour. Or in an FPS game, the player can only hold one weapon at a time. Switching to another weapon requires the player to remove the current weapon. These effects are all equipment limit. This part is introduction of using ECA, the Lua can be known at Lua API – Equipment limit.

Equipment Attributes and Type Storage

For picking up an equipment, if the player unit does not have this type of equipment, it will be equipped directly.

If the unit already has this type of equipment, then the equipment picked up at this time will be discarded directly. You can define this automatic discard as system discard.

The first part is data storage. You need to define the model, name, icon, etc. of each equipment in the object editor. You also need to add a custom attribute 'type'.


Pick up items

When the player unit picks up the item, you create two local variables 'unit' and 'item' to cache the player unit and the item obtained.


Then, using the custom attribute 'type' of the item to determine whether the unit has this type of item.


If it is True, discard the item and add a custom value 'SystemDiscard' to the item, to distinguish between system discarding and player manual discarding, in preparation for removing the special effect when the player manually discards items.

If it is False, it means the player does not have this type of item. The player gains this item successfully. And add the custom key value of the item to the unit, because you will need to display the corresponding special effect according to the item's type.


Effects generation

To display the special effect, you can use custom events.

You can transmit information by sending custom events and receiving custom events. After gaining new equipment, you can send a custom event, and perform the function of displaying the corresponding special effects by receiving the custom event.

Before executing the received event, it is necessary to define the special effects corresponding to each equipment.

Because the special effects of weapons need to move with the unit, and projectiles in CliCli cannot achieve this effect at present, so create modifiers as the carrier of special effects of weapons.

Then in Object Editor, create a custom attribute 'projectType' under each weapon to store the modifier corresponding to the weapon.

The special effect of the armour does not need to follow the unit to move, so you can directly create a projectile as the carrier of the special effect.


Then, you only need to call the special effect creation function, according to the type of the item passed by the custom event. The corresponding special effects of the equipment will be created.


Effects display

In function library, you need three functions corresponding to weapons, armour 1 and armour 2.

For the function of displaying special effect of weapons, adding the weapon modifier to the unit, and start a looped timer to continuously check whether the equipment is removed. If it is removed, stop the timer and remove the modifier.


The logic of displaying the special effect of armour 1 is similar to weapons' special effect.The difference is that armour 1 special effect will be created once every second timer runs. And destroy the projectile after 2 seconds


For the function of displaying special effect of armour2, we create a projectile for the unit and use a local projectile variable 'project' to store the electric ball.

In order to achieve the effect of the electric ball rotating around the unit, we need to define a local angle variable 'angle', to store the angle that the electric ball needs to be offset in the next frame.


We use a frame timer (a timer executed every 0.03 seconds) to check whether the equipment is removed.

If it is removed, we stop the timer and remove the projectile.


Otherwise, we calculate the location point of the electric ball. Set the angle of the electric ball to be the angle of last frame minus 6, Then, set the location point of the projectile to offset the player unit by 100 toward 'angle'.


Discard items

Similar to picking up items, when a unit loses an item using 'unit' and 'item' to cache the unit and the lost item. Then, you need to determine the type of discard according to the custom value SystemDiscard.

If it is automatically discarded, remove the custom key value 'SystemDiscard' from the item, to avoid affecting the next judgment.

Otherwise, it means the item is manually discarded by the player unit. You get the custom key value of the item and delete it from the unit, as the unit no longer holds this equipment. When delete this custom value, the corresponding special effects will be automatically deleted.