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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Realistic weapon problem (Zscript)

Post by Apeirogon »

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 all

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 all

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 all

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 all

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
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Realistic weapon problem (Zscript)

Post by Matt »

If you define a weapon actor in ZScript you can have any variables you want:

Code: Select all

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 all

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
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Realistic weapon problem (Zscript)

Post by Apeirogon »

But variables dont save on weapons.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Realistic weapon problem (Zscript)

Post by Matt »

They do.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Realistic weapon problem (Zscript)

Post by Apeirogon »

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
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Realistic weapon problem (Zscript)

Post by Matt »

By "user variables" do you mean [wiki=User_variable]the user_* stuff in Decorate[/wiki]? Those won't work (I think there's no way to call them in the weapon HUD states or something?), I'm talking about [wiki=ZScript_variables]the variables you can define in ZScript[/wiki].
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Realistic weapon problem (Zscript)

Post by krokots »

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
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Realistic weapon problem (Zscript)

Post by Matt »

I was thinking about doing this tutorial for a while but this thread got me to do it.
Post Reply

Return to “Scripting”