Keeping weapons in deathmatch?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Ænima
Addicted to Zandronum
Posts: 3523
Joined: Tue Jun 05, 2012 6:12 pm

Keeping weapons in deathmatch?

#1

Post by Ænima » Thu Jun 14, 2012 2:42 pm

Is there any way to force the behavior of sv_keepweapons in a deathmatch game so that players keep their weapons after dying? (like in coop)

It's because I'm making a mod where players must buy their weapons like in WolfTeam or Combat Arms.

I'd prefer to not have to make ACS arrays for every weapon to store whether a player has purchased a certain weapon. There has to be a simpler way.
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­
Doom64: Unabsolved: New weapons, monsters, and gameplay features for coop !


ZandroSkins
: a pack made by our community

Theshooter7
Forum Regular
Posts: 262
Joined: Wed Jun 06, 2012 2:15 am

RE: Keeping weapons in deathmatch?

#2

Post by Theshooter7 » Thu Jun 14, 2012 2:49 pm

Other than ACS or co-op mode hacks, no there isn't. :/ If Zandronum supports the RESPAWN script type you might be able to make something work with that, but you'll still be using ACS one way or another.
Image

User avatar
Ænima
Addicted to Zandronum
Posts: 3523
Joined: Tue Jun 05, 2012 6:12 pm

RE: Keeping weapons in deathmatch?

#3

Post by Ænima » Thu Jun 14, 2012 3:07 pm

Yeah I figured i'd have to use a RESPAWN script with something like

Code: Select all

if (HasSaiga[playernumber()] ==1)
GiveInventory("Saiga",1);
... for every weapon. :/
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­
Doom64: Unabsolved: New weapons, monsters, and gameplay features for coop !


ZandroSkins
: a pack made by our community

Theshooter7
Forum Regular
Posts: 262
Joined: Wed Jun 06, 2012 2:15 am

RE: Keeping weapons in deathmatch?

#4

Post by Theshooter7 » Thu Jun 14, 2012 3:38 pm

Ew, you don't need 1000 arrays just for that! You can use a 2D array like so:

Code: Select all

int Equipment[32][NUM_WEAPONS_AMMO_ETC];
...
#define WEAP_SAIGA 0
...
if(Equipment[PlayerNumber()][WEAP_SAIGA] >= 1)
GiveInventory("Saiga",1);
...
etc.
For ammo and such, you can do a for loop through the ammo values of the second bracket, and just give whatever was there (assuming you are storing ammo, as giving 0 ammo doesn't give the player any ammo now does it? :V)
Last edited by Theshooter7 on Thu Jun 14, 2012 3:40 pm, edited 1 time in total.
Image

User avatar
Ænima
Addicted to Zandronum
Posts: 3523
Joined: Tue Jun 05, 2012 6:12 pm

RE: Keeping weapons in deathmatch?

#5

Post by Ænima » Thu Jun 14, 2012 6:35 pm

Oh yeahhhh. A matrix. I forgot about those.

I also tried using string arrays, but for some reason, trying to use them with CheckWeapon and SetWeapon doesn't work.
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­
Doom64: Unabsolved: New weapons, monsters, and gameplay features for coop !


ZandroSkins
: a pack made by our community

Theshooter7
Forum Regular
Posts: 262
Joined: Wed Jun 06, 2012 2:15 am

RE: Keeping weapons in deathmatch?

#6

Post by Theshooter7 » Thu Jun 14, 2012 7:52 pm

Ænima wrote:I also tried using string arrays, but for some reason, trying to use them with CheckWeapon and SetWeapon doesn't work.
Because that counts as dynamic string usage, I believe. Don't quote me on that, however.
Image

Konda
Forum Regular
Posts: 487
Joined: Thu Jun 07, 2012 5:22 pm

RE: Keeping weapons in deathmatch?

#7

Post by Konda » Sat Jun 16, 2012 9:57 am

Code: Select all

if(hasSSG) GiveInventory("SuperShotgun", 1); //I don't like this :(

There is no need for 1000 if checks. Here is a simplified version of the code above:

Code: Select all

GiveInventory("SuperShotgun", hasSSG);
In the end, you could add a 2D array (matrix) where one row has all the weapons' names and the other row has the values whether the weapon has been purchased:

Code: Select all

#define NUM_WEPS 3
int weps[2][NUM_WEPS] =
{
    {"Shotgun", "SuperShotgun", "Chaingun"},   //Strings are defined as integers in ACS
    {1, 0, 1}
};

script 999 RESPAWN
{
    for(int i = 0; i < NUM_WEPS; i++) GiveInventory(weps[1,i], weps[2,i]);
}
See? Simple as that.
Last edited by Konda on Sat Jun 16, 2012 11:43 am, edited 1 time in total.

Code: Select all

<Synert> fuck
<Synert> plugged in my memory stick and got a bsod

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Keeping weapons in deathmatch?

#8

Post by Ijon Tichy » Mon Jun 18, 2012 12:16 pm

Crap shit out time goooo

Edit: Basically, what it does is, on ENTER and DEATH, it'll save the amount of weapons and ammo you have for WEAPONS and AMMO (through saveWeapons) into a 2D array specificall for storing those values, and when you respawn, it'll load those values from the 2D array and give you weapons and ammo based off the values it pulls out.
I'm not very good at explaining code in English. Look at saveWeapons and loadWeapons, that's where everything happens.
Spoiler: DA SAUCE (Open)

Code: Select all

#define WEPCOUNT  8
#define AMMOCOUNT 4

#define WEPSAVE_ENTER   343
#define WEPSAVE_DEATH   344
#define WEPSAVE_RESPAWN 345

int WEAPONS[WEPCOUNT] =
{
    "Chainsaw",
    "Pistol",
    "Shotgun",
    "SuperShotgun",
    "Chaingun",
    "RocketLauncher",
    "PlasmaRifle",
    "BFG9000",
};

int AMMO[AMMOCOUNT] =
{
    "Clip",
    "Shell",
    "RocketAmmo",
    "Cell"
};

int playerWeps[32][WEPCOUNT];
int playerAmmo[32][AMMOCOUNT];
int wepOut[32];

function void saveWeapons(void)
{
    int pln = PlayerNumber();
    int i;

    wepOut[pln] = -1;

    for (i = 0; i < WEPCOUNT; i++)
    {
        playerWeps[pln][i] = CheckInventory(WEAPONS[i]);

        if (CheckWeapon(WEAPONS[i]) )
        {
            wepOut[pln] = i;
        }
    }
    for (i = 0; i < AMMOCOUNT; i++)
    {
        playerAmmo[pln][i] = CheckInventory(AMMO[i]);
    }
}

function void loadWeapons(void)
{
    int pln = PlayerNumber();
    int i;

    for (i = 0; i < WEPCOUNT; i++)
    {
        TakeInventory(WEAPONS[i], CheckInventory(WEAPONS[i]));
        GiveInventory(WEAPONS[i], playerWeps[pln][i]);
    }

    for (i = 0; i < AMMOCOUNT; i++)
    {
        TakeInventory(AMMO[i], CheckInventory(AMMO[i]));
        GiveInventory(AMMO[i], playerAmmo[pln][i]);
    }

    if (wepOut[pln] != -1)
    {
        SetWeapon(WEAPONS[wepOut[pln]]);
    }
}


script WEPSAVE_ENTER enter
{
    saveWeapons();
}

script WEPSAVE_DEATH death
{
    saveWeapons();
}

script WEPSAVE_RESPAWN respawn
{
    loadWeapons();
}
Completely untested, by the way. (edit: okay, cursory testing done)

Edit2: Added a little extra - it saves the weapon you're holding, if it's in WEAPONS. loadWeapons will SetWeapon to that weapon - it should be trivial to add an argument that controls that behaviour.
Last edited by Ijon Tichy on Mon Jun 18, 2012 12:33 pm, edited 1 time in total.

User avatar
Ænima
Addicted to Zandronum
Posts: 3523
Joined: Tue Jun 05, 2012 6:12 pm

RE: Keeping weapons in deathmatch?

#9

Post by Ænima » Mon Jun 18, 2012 1:03 pm

Wow, that's a good idea. I wouldn't have thought of doing it that way.

Mind if I test that code and possibly use it if it works?

Edit: Does Zandronum support named scripts? I know GZDoom does.
Last edited by Ænima on Mon Jun 18, 2012 1:12 pm, edited 1 time in total.
­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­
Doom64: Unabsolved: New weapons, monsters, and gameplay features for coop !


ZandroSkins
: a pack made by our community

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Keeping weapons in deathmatch?

#10

Post by Ijon Tichy » Mon Jun 18, 2012 1:14 pm

Doesn't support named scripts yet.

also do whatever the hell you want with it

Post Reply