Realistic weapon problem (Zscript)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Realistic weapon problem (Zscript)

Postby Apeirogon » Mon Jan 01, 2018 6:46 am

What does it mean?
First of all, weapon condition. Its constructed just to shoot, not to shoot-shoot at point blank range-kick shit out from imps in melee-falls from cliff-using as seat near bonfire between maps or using as oar sometime. So
Code: Select allExpand view
fire:

}if(weapon_conditions_variable >= complex_function_that_sometimes_allow_to_shoot_using_waaaagh!_field_even_if_weapon_falling_apart_in_rust_dust)
{
...
}
else(return resolvestate("fail");)
return resolvestate(null);}

Spoiler:

Next, cleanliness of weapon.Its designed for operating in more-less clean conditions, not with dirt instead of lubricants and ash on barrel, which so old that see how neanderthals hunt mammoths. So
Code: Select allExpand view
if(weapon_cleanliness_variable >= some_constant_+/-_random_number)
{
...
}
else(return resolvestate("fail");)
return resolvestate(null);

Spoiler:

A-a-a-nd cartridges. From this, would seem, little thing depends so much. Bad reputation of M16 thanks to its cartridge. In combat operations "effective" managers send cheap cartridge, not quality and expensive that engineers and rifle was desired. So
Code: Select allExpand view
if(random_number >= some_small_number||countinv("cartridge_checker")==1)
{
...
}
else(giveinventory("misfire", 1); return resolvestate("fail");)
return resolvestate(null);

Spoiler:

And, of course, luck.
Code: Select allExpand view
if(random_number >= some_small_number)
{
finaly_a_spawnprojectile
}
else(giveinventory("misfire", 1); return resolvestate("fail");)
return resolvestate(null);

Spoiler:


And now questions.
How define all weapon_X_variable for every single weapon that present on map? Create struct for every weapon? How? Now I use console variable just to check how it working.
About ammo. If player dont find automatic cartridge checker it can manualy check all cartridge in inventory, misfire chance 2 out of 93. How make one pool for checked, "good" ammo and found, doubtful ammo from deepth of hell grounds?

And about reloading. How make it looks like in gears of war? If someone dont know how it looks, after pressing reload key player have two options.
First, do nothing and wait while character simple reload weapon.
Second, try catch moment and press reload key one more time. If player catch moment, reload will happen 0.5 quicker and all missing in magazine ammo achived temporary bonus damage.
If player try and fail press key in time, magazine stuck in weapon, character start trying kick it from weapon, everything will be bad in short, and reloading take 2 time longer.
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Realistic weapon problem (Zscript)

Postby Matt » Tue Jan 02, 2018 8:09 pm

If you define a weapon actor in ZScript you can have any variables you want:
Code: Select allExpand view
class PickyRifle:Weapon{
    int dirtinbarrel;
    int burntscuminbarrel;
    int dustinaction;
    int chambermetalfatigue;
    int boltspringmetalfatigue;
    int triggerspringmetalfatigue;
    int grimeinoil;
    int heat;
    bool gremlinstookadumpinthechamber;

    //etc.

...

    default{
        //stuff about your weapon
...
    }
    states{
        //ready, fire, altfire, reload, clean, jam, etc.
...
    }
}

and any and all changes made in-game will follow that particular weapon even when the player drops and picks back up (even in multiplayer - you have a dirty gun and your buddy has a clean gun, you drop yours, they drop theirs, you pick up theirs and they pick up yours, you've got clean and they've got dirty, no more residual inventory items!), or reloads, or changes levels, or dies and respawns.

Then you can just do stuff like this:
Code: Select allExpand view
states{
    fire:
        RIFL A 0{
            if(invoker.dirtinbarrel > 100){
                return resolvestate("toomuchdirttofire");
            }return resolvestate("nowcheckforammo");
        }
}

And, of course, you can even do this for ammo - make that a variable within the weapon itself and it too will carry with each individual weapon. (I've been thinking of doing a tutorial for this but I'm not sure if there's really any demand for it)


EDIT: For that reloading, at any time in the weapon state you can check "player.cmd.buttons" for input flags. The names of the flags are the same as the ones here and the bitwise operators are the same.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Realistic weapon problem (Zscript)

Postby Apeirogon » Wed Jan 03, 2018 8:54 am

But variables dont save on weapons.
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Realistic weapon problem (Zscript)

Postby Matt » Wed Jan 03, 2018 10:09 am

They do.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Realistic weapon problem (Zscript)

Postby Apeirogon » Wed Jan 03, 2018 10:26 am

Last year I try make sniper rifle with 4x scope using user variables on weapon, gzdoom told me somthing, for what in decent forum bans without hesitation.
Or its alreadi fixed?
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Realistic weapon problem (Zscript)

Postby Matt » Wed Jan 03, 2018 1:07 pm

By "user variables" do you mean the user_* stuff in Decorate? Those won't work (I think there's no way to call them in the weapon HUD states or something?), I'm talking about the variables you can define in ZScript.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Realistic weapon problem (Zscript)

Postby krokots » Thu Jan 04, 2018 6:39 am

Also If I remember in weapons you must refer to weapon variables as "invoker.variable". By default in inventory variables are owner's variables.
User avatar
krokots
 
Joined: 19 Jan 2010

Re: Realistic weapon problem (Zscript)

Postby Matt » Thu Jan 04, 2018 1:21 pm

I was thinking about doing this tutorial for a while but this thread got me to do it.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest