Burst fire mode

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Hello everyone,

This is my first post to this particular forum, however, I used to frequent the mapping forums before my time was sucked away from me.

I have recently begun trying to teach myself uscript, and although I am learning, it is a much slower process than I had hoped for.

A former member of my team created code for an assault rifle for a tc/mod we are making, and I have been trying to fix the code for about the last week.

Thanks in great deal to Madnad, I have come extremely close to getting everything working. My only stopping point now is a fire mode.

The weapon in question has three fire modes, single shot, 5 round burst, and full auto. I have been unsuccessful in getting the burst mode to work properly. The closest I have come fires 5 bullets, but at such a high rate of speed that it is more like a shotgun than a automatic weapon. I believe this to be caused by the for loop in my ModeDoFire() function, but I have been unable to find a better way of doing it. I am currently trying to get a tick function to work, but I just don't know how to do what I am trying to do.

My current idea is to enable tick in ModeDoFire() and then fire the bullet in Tick() if deltatime is >= 0.15 (firerate), but I do not know how ot make the bullet fire there, and I'm not sure how MDF() and Tick() interact.

This weapon is supposed to fire 5 rounds per click, and i alreayd have bWaitForRelease = true.

If anyone can point me in the right direction, I would greatly appreciate it. I do not want anyone to write my code for me, but code examples of how to implement this would greatly help.

Thanks in advance to anyone who can help me.

Mike Winters
 

Kuhal

New Member
Jul 13, 2001
29
0
0
55
New Zealand
Visit site
Without a doubt you should do the burst mode through the tick event. Definitely on the right track there however I have never made a weapon - just mutators and game type mods thus far :)

Cheers
 

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Mr Evil- I wrote you an email regarding your reloading weapon code that you (I believe) posted to the Wiki. Have you made a decision regarding that yet? I'm holding off on re-writing my weapon code until I hear from you.

On a side note, is it 'legal' to have two timers running in a class? Right now, the code has a timer for reloading, and I have not yet tried adding a second timer to control the fire rate.

Thanks,

Mike
 

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Yeah, I have heard that states would be ANOTHER way of doing what I am wanting to do, but I haven't been able to find much in the way of tutorials about what states are (which I already am a little familiar with) and more importantly, how to code them. Do you know of one/any?

Thanks,

Mike
 

SlayerDragon

LLLLLLLLLLLLLLLLLADIES
Feb 3, 2003
7,666
0
36
40
MWGemini said:
Yeah, I have heard that states would be ANOTHER way of doing what I am wanting to do, but I haven't been able to find much in the way of tutorials about what states are (which I already am a little familiar with) and more importantly, how to code them. Do you know of one/any?

Thanks,

Mike

Using a state is really the only way to accomplish what you want. States allow latent functions - you can actually have time pass in states! \o/

I did this a while ago with some weapons I was working on. The Wiki has info on states.

http://wiki.beyondunreal.com/wiki/State

http://wiki.beyondunreal.com/wiki/UnrealScript_Language_Reference/States
 

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Thanks guys, I will look into this hopefully tonight or tomorrow. The code I have now, I have a timer, but it doesn't seem to be delaying the shots at all, so I'm going to try my hand with states and see what I can do with that.

Mike
 

Tynan

Person
Jan 13, 2003
130
0
0
The Gutter
www.planetunreal.com
Basic idea of what might work:

Code:
state BurstFiring
{
    ignores ModeDoFire;

    Begin:
    Fire();
    sleep(0.15);
    Fire();
    sleep(0.15);
    Fire();
    sleep(0.15);
    Fire();
    sleep(0.15);
    Fire();

    GoToState(none);
}

My exact syntax might be a bit off.
 
Last edited:

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Well, this has not been a very productive evening for me. In the code I have tried, I have tried timers, states, and even multiple commands. Nothing has worked.

I have come ot the conclusion that something in weaponfire's event modedofire is causing all the bullets to be fired simultaneously, because when I have tried do this loop, the timer (or state code) is not called until after all bullets are fired, which is not what it should be doing.

Code:
class AR_Burst extends AR_Fire;

event ModeDoFire()
{
    local int i;
    for (i=1;i<=BurstLength;i++)
    {
        super.ModeDoFire();
        //GotoState('BurstPause');

        //log("FireRate = "@firerate * 4);
        SetTimer(FireRate * 4, false);
    }
}

state BurstPause
{
Begin:
Sleep ( FireRate  * 4 );
log(firerate * 4);
GotoState('');
}

function Timer()
{
log("Timer has been called");
}

defaultproperties
{
BurstLength=5
}

This code is an extension of ar_fire, which extends reloadinstfire, which extends instantfire, which extends (obviously) weaponfire. The ONLY classes that have an event modedofire in the list I just typed is weaponfire and ar_burst. AR_Fire does not override or extend the event modedofire, but just uses the default fire function defined in weaponfire.

I have tried asking several people on IRC as well, to no avail.

If anyone has an idea as to why this is happening, or how to override weaponfire's modedofire so that it WONT fire all bullets simultaneously, I would greatly appreciate it, because I have run out of ideas. As you can see from the code above, I would *LIKE* for the burstlegth to be altered via one variable, and used in a loop, but if that is not possible, then so be it.

Thanks,

Mike
 

EvilDrWong

Every line of code elevates you
Jun 16, 2001
932
0
0
40
Inside the machine
Visit site
Code:
class BurstFire extends InstantFire;

event ModeDoFire()
{
	GotoState('Burst');
}

state burst
{
Begin:
	Super.ModeDoFire();
	Sleep(variable);
	Super.ModeDoFire();
	Sleep(variable);
	Super.ModeDoFire();
	GotoState('');
}
if that doesnt work ill eat my hat.
 

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Thank you, EvilDrWong, that worked. By taking that a step further, I was able to put a loop into the state and still have the burstlength be a variable.

Apparently my error was in looping in modedofire, when I should have been looping in state code. I'm not sure i understand why the results are so different for what is essentially the same code.

But I'm sure I'll figure it out eventually.

Thanks again to everyone who has helped me muddle through this one, and especially to Mr Evil, for allowing me to use his reloading weapon code.

Mike
 

NickR

New Member
Dec 27, 2002
65
0
0
UK
wiki.beyondunreal.com
Tynan said:
Sleep does not work outside of state code.

You cannot have latent functions in the normal code. They all have to execute instantaneously. Only state code can have time-based events.

Yeah that's true. But most of us knew that already.
 

MWGemini

Adrenaline Junkie
Jan 3, 2003
13
0
0
Raleigh, NC
www.crimsonstrife.com
Yeah, I'm still not sure I completely understand it, but if my understanding is correct, the code I had would execute all the super.moddofire commands in the loop before ever calling the state code because state code is treated differently.

Thanks for helping to clarify that for me, even though I probably still don't fully get it.

Mike
 

Wozzeck

New Member
Jun 1, 2004
6
0
0
Bumping this back up top.

Can't seem to use "Sleep" with UT2004, will not compile. Worked perfectly for UT2003. What's going on here?