jjBEHAVIORINTERFACE interface JJ2+

Base for script classes that act as object behaviors

Assign an instance of an implementing class to jjOBJ::behavior (or to a template in jjObjectPresets) to drive objects by it. Unlike a plain jjVOIDFUNCOBJ function, the class can keep its own data and define more methods the game calls when they are present:

  • void onDraw(jjOBJ@ obj) — draws the object, called after onBehave() unless drawing is skipped
  • bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) — decides what happens when a player or bullet hits an object with jjOBJ::scriptedCollisions set, returning false falls back to the global onObjectHit() function

Functions

void onBehave(jjOBJ@ obj)
Runs the behavior for an object, once per tick
void onDraw(jjOBJ@ obj)
Draws the object
bool onGetActive(jjOBJ@ obj) partially supported
Tells whether the object is active for a joining player
bool onIsRFBullet(jjOBJ@ obj) partially supported
Tells whether the object is a bullet of the RF missile kind
bool onIsSolid(jjOBJ@ obj) partially supported
Tells whether boxes treat the object as solid
bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force)
Called when the object is hit by a player or a bullet
void onSetActive(jjOBJ@ obj, bool setTo) partially supported
Sets whether the object is active for a joining player

Function documentation

void jjBEHAVIORINTERFACE::onBehave(jjOBJ@ obj)

Runs the behavior for an object, once per tick

Parameters
obj Object being driven

Called for every object whose jjOBJ::behavior is this instance. It is the only method an implementing class must define.

void jjBEHAVIORINTERFACE::onDraw(jjOBJ@ obj)

Draws the object

Parameters
obj The object being drawn

An optional method of a behavior class. The game calls it right after jjBEHAVIORINTERFACE::onBehave() each time the behavior runs, unless the object isn't drawn then, such as when jjOBJ::behave() is called with draw set to false. Code that only concerns how the object looks can go here to keep jjBEHAVIORINTERFACE::onBehave() tidier, but it may as well stay there.

bool jjBEHAVIORINTERFACE::onGetActive(jjOBJ@ obj)

Tells whether the object is active for a joining player

Parameters
obj The object in question
Returns Whether the object is active

An optional method of a behavior class, meant for objects placed in the level. Together with jjBEHAVIORINTERFACE::onSetActive() it lets a multiplayer server tell joining players which of these objects are still there, such as pickups already collected. Without it, the object counts as active while jjOBJ::isActive is true.

bool jjBEHAVIORINTERFACE::onIsRFBullet(jjOBJ@ obj)

Tells whether the object is a bullet of the RF missile kind

Parameters
obj The object in question
Returns Whether the object is an RF missile

An optional method of a behavior class. RF missiles get a special treatment of their speed when they're fired, a behavior that wraps BEHAVIOR::RFBULLET should return true to get the same treatment. Without the method, the object isn't treated as an RF missile.

bool jjBEHAVIORINTERFACE::onIsSolid(jjOBJ@ obj)

Tells whether boxes treat the object as solid

Parameters
obj The object in question
Returns Whether the object is solid for boxes

An optional method of a behavior class. Boxes, such as crates, monitors and other objects of similar behaviors, can rest on each other and can't be pushed through each other. Returning true puts objects with this behavior among them. It doesn't change whether players treat the object as solid. Without the method, the object isn't solid for boxes.

bool jjBEHAVIORINTERFACE::onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force)

Called when the object is hit by a player or a bullet

Parameters
obj The object that was hit
bullet The bullet that hit the object, null for a touch of a player
player The player who touched the object or fired the bullet, may be null for a bullet
force For a touch, 1 while the player attacks (a sugar rush or a special move) and 0 otherwise. For a bullet, the damage it deals.
Returns true if the method handled the hit, false to let the global onObjectHit() hook handle it

An optional method of a behavior class, the class counterpart of the global onObjectHit() hook, called under the same conditions: only for objects with jjOBJ::scriptedCollisions enabled and jjOBJ::playerHandling set to HANDLING::PICKUP or HANDLING::SPECIAL. Prefer it to the global hook, it only concerns objects with this behavior.

An object with HANDLING::PICKUP gets the call when a player touches it. To have it collected, set its behavior to BEHAVIOR::EXPLOSION2. An object with HANDLING::SPECIAL gets the call when a player touches or attacks it, or when a bullet hits it.

void jjBEHAVIORINTERFACE::onSetActive(jjOBJ@ obj, bool setTo)

Sets whether the object is active for a joining player

Parameters
obj The object in question
setTo Whether the object is active

An optional method of a behavior class, the counterpart of jjBEHAVIORINTERFACE::onGetActive(), called on the side of the joining player. Without it, an object that isn't active is deleted.