Duck Game

Duck Game

View Stats:
꧁Kritzy꧂ 10 Mar, 2018 @ 12:50pm
What is the code for the sniper's reload?
I used a program similar to ILSpy and found the code for the sniper. But when copying the code, changing it a bit and testing it, it doesn't reload.

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using DuckGame;
using System.Text;

namespace MyMod.src
{
[EditorGroup("guns")]
public class AWP : Gun
{
public StateBinding _loadStateBinding = new StateBinding(nameof(_loadState), -1, false, false);
public StateBinding _angleOffsetBinding = new StateBinding(nameof(_angleOffset), -1, false, false);
public StateBinding _netLoadBinding = (StateBinding)new NetSoundBinding(nameof(_netLoad));
public NetSoundEffect _netLoad = new NetSoundEffect(new string[1]
{
"loadSniper"
});
public int _loadState = -1;
public int _loadAnimation = -1;
public float _angleOffset;

public AWP(float xval, float yval)
: base(xval, yval)
{
this.ammo = 10;
this._ammoType = (AmmoType)new ATHighCalSniper();
this._type = "gun";
this.graphic = new Sprite("textures/AWPLightning", 0.0f, 0.0f);
this.center = new Vec2(16f, 7f);
this.collisionOffset = new Vec2(-8f, -5f);
this.collisionSize = new Vec2(16f, 9f);
this._holdOffset = new Vec2(3f, 0.0f);
this._barrelOffsetTL = new Vec2(35f, 5f);
this._fireSound = GetPath("sounds/awp1.wav");
this._fireSoundPitch = -0.2f;
this._kickForce = 3f;
this._manualLoad = true;
}

public override void Update()
{
base.Update();
if (this._loadState > -1)
{
if (this.owner == null)
{
if (this._loadState == 3)
this.loaded = true;
this._loadState = -1;
this._angleOffset = 0.0f;
this.handOffset = Vec2.Zero;
}
if (this._loadState == 0)
{
if (Network.isActive)
{
if (this.isServerForObject)
this._netLoad.Play(1f, 0.0f);
}
else
SFX.Play("loadSniper", 1f, 0.0f, 0.0f, false);
++this._loadState;
}
else if (this._loadState == 1)
{
if ((double)this._angleOffset < 0.159999996423721)
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0.25f, 0.25f);
else
++this._loadState;
}
else if (this._loadState == 2)
{
this.handOffset.x += 0.8f;
if ((double)this.handOffset.x > 4.0)
{
++this._loadState;
this.Reload(true);
this.loaded = false;
}
}
else if (this._loadState == 3)
{
this.handOffset.x -= 0.8f;
if ((double)this.handOffset.x <= 0.0)
{
++this._loadState;
this.handOffset.x = 0.0f;
}
}
else if (this._loadState == 4)
{
if ((double)this._angleOffset > 0.0399999991059303)
{
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0.0f, 0.25f);
}
else
{
this._loadState = -1;
this.loaded = true;
this._angleOffset = 0.0f;
}
}
}
if (this.loaded && this.owner != null && this._loadState == -1)
this.laserSight = true;
else
this.laserSight = false;
}

public override void OnPressAction()
{
if (this.loaded)
{
base.OnPressAction();
}
else
{
if (this.ammo <= 0 || this._loadState != -1)
return;
this._loadState = 0;
this._loadAnimation = 0;
}
}

public override void Draw()
{
float angle = this.angle;
if ((int)this.offDir > 0)
this.angle -= this._angleOffset;
else
this.angle += this._angleOffset;
base.Draw();
this.angle = angle;
}
}
}

Help plz
Last edited by ꧁Kritzy꧂; 11 Mar, 2018 @ 1:42pm
Originally posted by Azrael:
try this, if that doesnt work, something with your mod's messed up.
namespace DuckGame.YourModName {

public class AWP : Sniper {

public AWP(float xval, float yval)
: base(xval, yval)
{
this.ammo = 10;
this._ammoType = (AmmoType)new ATHighCalSniper();
//leave that one out since you don't change anything this._type = "gun";
this.graphic = new Sprite("textures/AWPLightning", 0.0f, 0.0f);
this.center = new Vec2(16f, 7f);
this.collisionOffset = new Vec2(-8f, -5f);
this.collisionSize = new Vec2(16f, 9f);
this._holdOffset = new Vec2(3f, 0.0f);
this._barrelOffsetTL = new Vec2(35f, 5f);
this._fireSound = GetPath("sounds/awp1.wav");
this._fireSoundPitch = -0.2f;
this._kickForce = 3f;
this._manualLoad = true;
}
}
}
< >
Showing 1-15 of 15 comments
Azrael 11 Mar, 2018 @ 7:14am 
steam is making reading this a bit hard, but I think the problem is that you're calling base.update() (which does all the reloading related stuff) AND make the same function again, so you're basically double-reloading (or double-increasing the reloadstate?)
꧁Kritzy꧂ 11 Mar, 2018 @ 1:42pm 
Originally posted by Nerdyyy:
steam is making reading this a bit hard, but I think the problem is that you're calling base.update() (which does all the reloading related stuff) AND make the same function again, so you're basically double-reloading (or double-increasing the reloadstate?)
Well, it DOES say base.Update() and stuff, but then how do i fix this?


Originally posted by Nerdyyy:
steam is making reading this a bit hard
(Fixed it, does it make it easier?)
Azrael 13 Mar, 2018 @ 12:32pm 
Originally posted by Kritzy:
Originally posted by Nerdyyy:
steam is making reading this a bit hard, but I think the problem is that you're calling base.update() (which does all the reloading related stuff) AND make the same function again, so you're basically double-reloading (or double-increasing the reloadstate?)
Well, it DOES say base.Update() and stuff, but then how do i fix this?


Originally posted by Nerdyyy:
steam is making reading this a bit hard
(Fixed it, does it make it easier?)

1. just remove the base.update() OR your code you probably copied from DG code (?)
2. nope. it's ok though, thanks for trying
꧁Kritzy꧂ 13 Mar, 2018 @ 1:50pm 
Originally posted by Nerdyyy:
your code you probably copied from DG code (?
Correct

Originally posted by Nerdyyy:
1. just remove the base.update()
Tried, but no success... Also, everytime i try and start up Duck Game after i edited my entire mod won't work. Like, everything just doesn't appear. (The game doesn't crash or something, but the mod doesn't load the sruff in.)
Last edited by ꧁Kritzy꧂; 13 Mar, 2018 @ 1:51pm
Azrael 15 Mar, 2018 @ 5:37am 
I'm too lazy to compare the two, so have you added anything after copying the DG code?

cause if not, you could just delete the overridden update function entirely, so it uses the base.update one automatically. if the issue still persists then, tell me, then we'll have to go through onpressaction too
꧁Kritzy꧂ 15 Mar, 2018 @ 8:01am 
Originally posted by Nerdyyy:
have you added anything after copying the DG code?
Only edited some names i know can be edited, nothing else

Originally posted by Nerdyyy:
I'm too lazy to compare the two, so have you added anything after copying the DG code?

cause if not, you could just delete the overridden update function entirely, so it uses the base.update one automatically.
Didn't work...

Originally posted by Nerdyyy:
if the issue still persists then, tell me, then we'll have to go through onpressaction too
Still didn't work...


The problem is, that after making changes to the mod and loading it up again, the mod doesn't work anymore. You need to restart in order for the mod to work, and even then it doesn't load the sniper. The other weapons in the mod that i already made work fine, but this one doesn't get added...
Last edited by ꧁Kritzy꧂; 15 Mar, 2018 @ 8:01am
The author of this thread has indicated that this post answers the original topic.
Azrael 17 Mar, 2018 @ 6:40am 
try this, if that doesnt work, something with your mod's messed up.
namespace DuckGame.YourModName {

public class AWP : Sniper {

public AWP(float xval, float yval)
: base(xval, yval)
{
this.ammo = 10;
this._ammoType = (AmmoType)new ATHighCalSniper();
//leave that one out since you don't change anything this._type = "gun";
this.graphic = new Sprite("textures/AWPLightning", 0.0f, 0.0f);
this.center = new Vec2(16f, 7f);
this.collisionOffset = new Vec2(-8f, -5f);
this.collisionSize = new Vec2(16f, 9f);
this._holdOffset = new Vec2(3f, 0.0f);
this._barrelOffsetTL = new Vec2(35f, 5f);
this._fireSound = GetPath("sounds/awp1.wav");
this._fireSoundPitch = -0.2f;
this._kickForce = 3f;
this._manualLoad = true;
}
}
}
꧁Kritzy꧂ 17 Mar, 2018 @ 7:53am 
Originally posted by Nerdyyy:
try this, if that doesnt work, something with your mod's messed up.
namespace DuckGame.YourModName {

public class AWP : Sniper {

public AWP(float xval, float yval)
: base(xval, yval)
{
this.ammo = 10;
this._ammoType = (AmmoType)new ATHighCalSniper();
//leave that one out since you don't change anything this._type = "gun";
this.graphic = new Sprite("textures/AWPLightning", 0.0f, 0.0f);
this.center = new Vec2(16f, 7f);
this.collisionOffset = new Vec2(-8f, -5f);
this.collisionSize = new Vec2(16f, 9f);
this._holdOffset = new Vec2(3f, 0.0f);
this._barrelOffsetTL = new Vec2(35f, 5f);
this._fireSound = GetPath("sounds/awp1.wav");
this._fireSoundPitch = -0.2f;
this._kickForce = 3f;
this._manualLoad = true;
}
}
}
Thanks! That did the trick. Weird, i tried this before and it didn't work... O well.

My only 2 questions are:

1. Can you change the sound of the reloading?
2. Can you make the reload take longer?

Thanks for helping me this far :senpai:
Azrael 17 Mar, 2018 @ 8:22am 
private string ReloadSoundName = "";

public override void Update()
{
base.Update();
if (this._loadState > -1)
{
if (this.owner == null)
{
if (this._loadState == 30)
{
base.loaded = true;
}
this._loadState = -1;
this._angleOffset = 0f;
base.handOffset = Vec2.Zero;
}
if (this._loadState == 0)
{
if (Network.isActive)
{
if (base.isServerForObject)
{
this._netLoad.Play(1f, 0f);
}
}
else
{
SFX.Play(ReloadSoundName, 1f, 0f, 0f, false);
}
this._loadState++;
}
else if (this._loadState == 10)
{
if (this._angleOffset < 0.16f)
{
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0.2f, 0.15f);
}
else
{
this._loadState++;
}
}
else if (this._loadState == 20)
{
base.handOffset.x += 0.4f;
if (base.handOffset.x > 4f)
{
this._loadState++;
this.Reload(true);
base.loaded = false;
}
}
else if (this._loadState == 30)
{
base.handOffset.x -= 0.4f;
if (base.handOffset.x <= 0f)
{
this._loadState++;
base.handOffset.x = 0f;
}
}
else if (this._loadState == 40)
{
if (this._angleOffset > 0.04f)
{
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0f, 0.15f);
}
else
{
this._loadState = -1;
base.loaded = true;
this._angleOffset = 0f;
}
}
}
if (base.loaded && this.owner != null && this._loadState == -1)
{
base.laserSight = true;
}
else
{
base.laserSight = false;
}
}

maybe this works? if yes, you probably just had a typo all along.
꧁Kritzy꧂ 17 Mar, 2018 @ 8:54am 
Originally posted by Nerdyyy:
private string ReloadSoundName = "";

public override void Update()
{
base.Update();
if (this._loadState > -1)
{
if (this.owner == null)
{
if (this._loadState == 30)
{
base.loaded = true;
}
this._loadState = -1;
this._angleOffset = 0f;
base.handOffset = Vec2.Zero;
}
if (this._loadState == 0)
{
if (Network.isActive)
{
if (base.isServerForObject)
{
this._netLoad.Play(1f, 0f);
}
}
else
{
SFX.Play(ReloadSoundName, 1f, 0f, 0f, false);
}
this._loadState++;
}
else if (this._loadState == 10)
{
if (this._angleOffset < 0.16f)
{
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0.2f, 0.15f);
}
else
{
this._loadState++;
}
}
else if (this._loadState == 20)
{
base.handOffset.x += 0.4f;
if (base.handOffset.x > 4f)
{
this._loadState++;
this.Reload(true);
base.loaded = false;
}
}
else if (this._loadState == 30)
{
base.handOffset.x -= 0.4f;
if (base.handOffset.x <= 0f)
{
this._loadState++;
base.handOffset.x = 0f;
}
}
else if (this._loadState == 40)
{
if (this._angleOffset > 0.04f)
{
this._angleOffset = MathHelper.Lerp(this._angleOffset, 0f, 0.15f);
}
else
{
this._loadState = -1;
base.loaded = true;
this._angleOffset = 0f;
}
}
}
if (base.loaded && this.owner != null && this._loadState == -1)
{
base.laserSight = true;
}
else
{
base.laserSight = false;
}
}

maybe this works? if yes, you probably just had a typo all along.
Nope, when adding the path to the sound (Which is sounds/<Sound here>) it still plays the normal sound effect.
Azrael 17 Mar, 2018 @ 9:04am 
sorry, forgot this:

(this goes in public AWP(float xval, float yval) : ...)
_netLoad = "AgainThatSameSoundEffectYouUseForReloading"
Azrael 17 Mar, 2018 @ 9:05am 
also, does it work in terms of making the reload slower?
꧁Kritzy꧂ 17 Mar, 2018 @ 9:09am 
Originally posted by Nerdyyy:
sorry, forgot this:

(this goes in public AWP(float xval, float yval) : ...)
_netLoad = "AgainThatSameSoundEffectYouUseForReloading"
Where? If i put it right after the AWP(Float xval....) It gives a lot of errors, but if i put it next to all the this.<lines of code> there is another error.
Originally posted by Nerdyyy:
also, does it work in terms of making the reload slower?
Nope
Last edited by ꧁Kritzy꧂; 17 Mar, 2018 @ 9:09am
Azrael 17 Mar, 2018 @ 9:17am 
what error is there?
you put it next to all the other lines of course, inside the constructor's body
꧁Kritzy꧂ 17 Mar, 2018 @ 10:02am 
Originally posted by Nerdyyy:
what error is there?
you put it next to all the other lines of course, inside the constructor's body
idk. If you need i can give the updated code
< >
Showing 1-15 of 15 comments
Per page: 1530 50