Author Topic: Understanding Default Gun Code  (Read 1972 times)



All questions currently answered



*questions are in normal text
*answers are in quotes


[ANSWERED]  What units is muzzleVelocity measured in? Studs per millisecond?
Quote
1 torque unit is equal to 2 studs.

A 1x1 plate is 0.5x0.5x0.2 torque units.
and what units is lifetime of a projectile measured in? seconds?
Quote
milliseconds

[ANSWERED]  Regarding these:
Code: [Select]
datablock ItemData(GunItem)
Code: [Select]
datablock ShapeBaseImageData(gunImage)
Is it ok to use GunItem and gunImage in another weapon's server.cs the same way it is used here? Also, what would you call GunItem and gunImage: local variables, objects, strings, idk?
Quote
No, doing so will overwrite the gun
Quote
They're objects; specifically, datablocks of class ItemData and ShapeBaseImageData

[ANSWERED]  I'm not sure if I'm interpreting this script correctly, but the default gun code seems to intentionally have a .15 delay from the time you click to the time it fires (is it in seconds?). Why on earth would you want a delay like that? You'd want it to fire at the same time you click, right? Take a look at the code:
        
Code: [Select]
       stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "Fire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.14;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
Quote
the reason it's there is because you don't want people equipping and dequipping constantly and firing every time, like rapid fire.

[ANSWERED]  I'm also wondering what this section of code does (I'm pretty sure it's for some kind of animation, but what exactly does that animation do, and what's with the getDamagePercent line?):
Code: [Select]
function gunImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}
Quote
when the gun is fired
    if the player firing it is alive
        Play the animation that shifts their hand up
    Call the generic onFire method
end
Quote
It checks damage, similar to health
Instead of a "health" number starting at 100 and going to 0 when you're dead, the game uses a "damage" level which starts at 0 and goes to 100
So a damagePercent of 1 (which is equivalent to 100%) means the player is dead, less than that, they're still alive
« Last Edit: August 20, 2014, 06:31:15 PM by Farad »

but the default gun code seems to intentionally have a .15 delay from the time you click to the time it fires
(I don't mess with weapons much so I'm not entire sure this is right, but it seems logical)
0.15 is the time between "activate" state and "ready" state
Activate is when you activate (fire) the weapon
Ready is when the weapon has finished doing everything and is "ready" to be fired again
So 0.15 is the minimum time between firings

nope, read below

I'm also wondering what this section of code does:
when the gun is fired
    if the player firing it is alive
        Play the animation that shifts their hand up
    Call the generic onFire method
end

what's with the getDamagePercent line?
It checks damage, similar to health
Instead of a "health" number starting at 100 and going to 0 when you're dead, the game uses a "damage" level which starts at 0 and goes to 100
So a damagePercent of 1 (which is equivalent to 100%) means the player is dead, less than that, they're still alive
« Last Edit: August 20, 2014, 03:46:01 PM by Headcrab Zombie »

0.15 is the delay from when you equip the weapon to when it's ready to fire. in a perfect world there would be no delay, but since latency exists, firing will be delayed depending on what your ping is.

It checks damage, similar to health
Instead of a "health" number starting at 100 and going to 0 when you're dead, the game uses a "damage" level which starts at 0 and goes to 100
So a damagePercent of 1 (which is equivalent to 100%) means the player is dead, less than that, they're still alive
Is that why some poorly scripted guns keep firing or reloading even when the player is dead? wow it all seems to make sense now, thanks. oh and also, is the .15 in seconds?

0.15 is the delay from when you equip the weapon to when it's ready to fire. in a perfect world there would be no delay, but since latency exists, firing will be delayed depending on what your ping is.
Wouldn't there be a little less of a delay if the .15 was changed to 0?

Is that why some poorly scripted guns keep firing or reloading even when the player is dead? wow it all seems to make sense now, thanks. oh and also, is the .15 in seconds?
It could be part of the problem, as well as not stopping the firing/reloading in an onDeath callback
But that function there only plays the animation, it has nothing to do with actually firing a projectile or anything else like that

Wouldn't there be a little less of a delay if the .15 was changed to 0?
The problem is latency
Because of latency, you would still have a delay between equipping and using the weapon, the only difference is people with faster internet/located closer to server would have a shorter delay. So you put in a delay of 150 and everyone is equal (as long as you're not over 150 ping)
« Last Edit: August 20, 2014, 03:55:57 PM by Headcrab Zombie »

ok I've got another question regarding these:
Code: [Select]
datablock ItemData(GunItem)
Code: [Select]
datablock ShapeBaseImageData(gunImage)
Is it ok to use the names GunItem and gunImage in another weapon's server.cs the same way it is used here?
Also, what would you call GunItem and gunImage: local variables, objects, strings?

and still need to know, is the .15 delay in seconds?

Is it ok to use the names GunItem and gunImage in another weapon's server.cs the same way it is used here?
No, doing so will overwrite the gun

Also, what would you call GunItem and gunImage: local variables, objects, strings?
They're objects; specifically, datablocks of class ItemData and ShapeBaseImageData

and still need to know, is the .15 delay in seconds?
Oh, sorry. Yeah, it is

The problem is latency
Because of latency, you would still have a delay between equipping and using the weapon, the only difference is people with faster internet/located closer to server would have a shorter delay. So you put in a delay of 150 and everyone is equal (as long as you're not over 150 ping)
the reason it's there is because you don't want people equipping and dequipping constantly and firing every time, like rapid fire.

New question:
What units is muzzleVelocity measured in? Studs per millisecond?
and what units is lifetime of a projectile measured in? seconds?

What units is muzzleVelocity measured in? Studs per millisecond?
I'm not sure.
It would be measured in "Torque Units" which are equal to 2 (I believe) or 4 (maybe) studs, over some unit of time (seconds seems most reasonable)

and what units is lifetime of a projectile measured in? seconds?
milliseconds

It would be measured in "Torque Units" which are equal to 2 (I believe) or 4 (maybe) studs

1 torque unit is equal to 2 studs.

A 1x1 plate is 0.5x0.5x0.2 torque units.