Weapon Drop Overview

Weapon Drop Overview

DCurrent

Site Owner, OpenBOR Project Leader
Staff member
There's a lot of confusion about how OpenBOR handles weapon items, and why the system works the way it does. Hopefully we can clear some of that up.

DC
 
Last edited:
X and Y don't change, so effectively they're the item's current position. Z is 100,000.

DC
I noticed whenever my character transforms into the EX mode (weaponframe), and after I quit the game and came back, the z value of the stage is screwed up as my character can walk off the screen. I could not figure out the cause of it. Now I just saw this Z is 100,000? I did not see it mentioned in the manual or how to change it. How can I change this value for weaponframe function? Thank you

Edit: Above problem was in 4.0 (7612) build.
I just tested it in 6.3.9.x.x and it worked fine. I guess that's a bug in 4.0 build. I also have another problem in 4.0 that works fine in 6.3.9.x.x build. I think it is a bug. I'll report both with code in 4.0 topic later
 
Last edited:
Ok, Thanks @DCurrent, it's very clear now I was about to ask this in help xd.

But where I have to apply each those scripts? in animationscript? onspawnscript? ondrawscript?

Can I apply them as a function on frame?

Code:
anim    follow4
    loop    0
    offset    140 143
    delay    1
    frame    data/chars/helicopter/idle2a.gif
    delay    240
    @cmd    dasher 0 -0.5 0 1
    frame    data/chars/helicopter/idle2a.gif
    @cmd    dasher 0 0 0 1
    @cmd   SpawnEnemyWieldingWeapon "Bryan_" 0 0 0 0 "Tube" # I think in something like this
    frame    data/chars/helicopter/idle2a.gif
    delay    240
    @cmd    dasher 0 -0.5 0 1
    frame    data/chars/helicopter/idle2a.gif

Here is the code of SpawnEnemyWieldingWeapon :
C:
#import "data/scripts/animationscripts/spawn/spawn.c"

void SpawnEnemyWieldingWeapon(void vName, float fX, float fY, float fZ, int parent, void weapon)
{
    void self = getlocalvar("self"); //Get calling entity.
    void vSpawn; //Spawn object.
    void spawnWeapon;
    int WeapNumber;
    int iDirection = getentityproperty(self, "direction");

    clearspawnentry(); //Clear current spawn entry.
    setspawnentry("name", vName); //Acquire spawn entity by name.

    if (iDirection == 0){ //Is entity facing left?                 
        fX = -fX; //Reverse X direction to match facing.
    }

    fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
    fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
    fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
 
    vSpawn = spawn(); //Spawn in entity.

    changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
    changeentityproperty(vSpawn, "direction", iDirection); //Set direction.

    spawnWeapon = spawn01(weapon, fX, fY, 0);
    changeentityproperty(spawnWeapon, "x", getentityproperty(vSpawn, "x"));
    changeentityproperty(spawnWeapon, "y", getentityproperty(vSpawn, "y"));
    changeentityproperty(spawnWeapon, "z", openborconstant("ITEM_HIDE_POSITION_Z"));
    changeentityproperty(spawnWeapon, "spawntype", openborconstant("SPAWN_TYPE_WEAPON"));
    changeentityproperty(vSpawn, "weapon_item", spawnWeapon);
    WeapNumber = getentityproperty(spawnWeapon, "weapnum");
    changeentityproperty(vSpawn, "weapon", WeapNumber);

    if(parent==1){
        void CandamageP  = getentityproperty(self, "candamage");
        void HostileP  = getentityproperty(self, "candamage");
        changeentityproperty(vSpawn, "candamage", CandamageP);
        changeentityproperty(vSpawn, "hostile", HostileP);
    }
   
    return vSpawn; //Return spawn.
}

But the log throws me "Can't find openbor constant 'ITEM_HIDE_POSITION_Z' " What I should use instead?

I'm using: OpenBoR v3.0 Build , Compile Date: May 12 2023
 
But the log throws me "Can't find openbor constant 'ITEM_HIDE_POSITION_Z' " What I should use instead?

I already answered this earlier in the discussion. It's 100,000.

Since you are using an earlier version that doesn't have the constant, I recommend defining one yourself:

C:
#define WEAPON_ITEM_HIDDEN_POS_Z 100000

Note you don't strictly have to use same value the engine defaults to, so long as the camera can't see it.

DC
 
But where I have to apply each those scripts? in animationscript? onspawnscript? ondrawscript?
When working with weapons, at least in 3.0, they doesn't use spawnscript because there isn't a spawn to begin with - the change happens instantly.

If you need something which works like a spawnscript, you need to use a different type of event:

onmodelcopyscript {path}

This command defines which script is run when entity change its model (weapon). This should be used in weapon models whenever you have spawn scripts since there is no spawn in weapon models.
==For script coding reference==
self: Caller (the new model).
old: previous model.

void old = getlocalvar("old");
void self = getlocalvar("self");
 
Back
Top Bottom