|
Posted by metlslime on 2007/08/08 04:57:56 |
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer. |
|
|
Kinn,
Got Most Things Working For The Infantry Gun
#1727 posted by aDaya on 2015/09/30 18:24:04
Now there's a last thing, and it's about def.qc, where it stores the weapon slots. Taking http://www.insideqc.com/qctut/qctut-7.shtml as face value, I put "17" as a value for my weapon. Now thing is, it opens the grenade launcher icon, while I want it to be on the 4th (NG) one. I tried "5", but it also adds me the Nailgun when I pick up my weapon on the testmap. Tried other values like 3 and 7 but I always have other weapons added on pickup. How can I deal with this?
Copy Paste
#1728 posted by Preach on 2015/09/30 19:44:59
If you want it to be on the nailgun slot, copy the value that the nailgun has there. You basically have to replace the nailgun by stealing its slot, copying the values etc. If you want the nailgun as an alternative then you need to do a lot more complicated stuff, for starters just replace everything to do with the nailgun with your new code.
Cf. Scourge Of Armagon, With Proxymine Launcher
#1729 posted by aDaya on 2015/09/30 20:52:47
I looked at said sourcecode (both weapons.qc and hipdef.qc) and the weapon switching code is the exact same (see http://pastebin.com/7bUga8cy ). Even with that I still can't choose the gun by pressing 4. What the hell!
Parms Abuse
#1730 posted by Kinn on 2015/09/30 21:46:20
Cheers chaps, that post by Preach was the stuff I was looking for
Data
#1731 posted by necros on 2015/09/30 21:54:24
your code says 'if i have the nailgun, switch to the infantry gun, otherwise switch to the nailgun' which makes no sense.
Source Of Confusion
#1732 posted by Preach on 2015/09/30 23:34:56
There are lots of places to get confused in the weapons code. The first is the difference between .items and .weapons.
You'll have spotted the way that the IT_ codes are taken from the sequence of doubling numbers:
1,2,4,8....
That's to make each of them have a single 1 digit in binary:
0001,0010,0100,1000...
This lets you add a set of them together into one number, and get the bit flags back afterwards:
1101 = 1000+0100+0001 - the point is that you can work out what "single digit numbers" to put on the right, just by looking at the number on the left. It wouldn't work with just any set of numbers (the trick is called bitflags if you want to google it).
So that's how .items work, it can store all the items the player has picked up in a single number, just because of how the bitflags add up. On the other hand, the .weapon field only needs to be able to store one weapon at a time, so there's no reason it couldn't use 1,2,3,4,5 as the codes for the weapons. It basically uses the same codes as .items out of expedience.
Well...ok, that last bit is not strictly true, but it's a very useful way to think about the QC code in isolation. Enter the second confusing thing about the .items and .weapon system: as well as being the way that the QC handles the player inventory, these fields have "side effects" which affect the HUD. So the binary digits which are 1 for the .items value turn on weapon slots. When .weapon is the equal to the value of one of the item slots, that weapon is lit up on the HUD.
So the side effects stuff is a bit hard to keep track of, but it gets worse. The third confusing thing is that the expansion packs wanted to alter the HUD, but originally it all works automatically as "side effects". So if you run engines in -hipnotic or -rogue mode, the HUD changes behaviour! Different numbers of weapons/powerups appear, an extra field called .items2 controls some behaviour...it's a real hacky mess.
So I return to my original suggestion. Initially, just make a weapon that replaces the nailgun. This will be challenging enough to get to grips with, and once you've done that, you'll be in a much better shape to understand the changes in the hipnotic code and how to bring the nailgun back.
Found A Way To Keep Both
#1733 posted by aDaya on 2015/10/01 00:04:21
By pretty much writing 4 possibilites, depending on what the player holds. "No weapons" shows up when pressing 4 with either the nailgun or the infantry gun hold, but for now I don't care.
Now, the absolute final thing: how do I make the hitscan attack draw a small trailpuff like Q2 Weapon Factory's Mega Chaingun? I've been told to make some sort of loop to make it happen, but that only made things more confusing for me. Any help on that one?
Parms Follow-up Post
#1734 posted by Preach on 2015/10/01 00:37:31
In my parms blog post a short way above, I linked to a bug that can cause you to lose runes when you load a save file and then decide to restart the level instead. I've devised a way to work around this bug in QC, and posted it tonight:
https://tomeofpreach.wordpress.com/2015/09/30/fixing-runes-and-restart-with-qc/
There's not much insight to it besides fixing the bug, but you should go and copy-paste the code anyway...
High Level Smoke Puff Trail
#1735 posted by necros on 2015/10/01 05:07:56
use this shotgun tempentity code to create the puff:
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_GUNSHOT);
WriteCoord (MSG_BROADCAST, org_x);
WriteCoord (MSG_BROADCAST, org_y);
WriteCoord (MSG_BROADCAST, org_z);
look at code for temp entity stuff, the last 3 lines are the x y z coords and org_? is the vector variable.
create a loop that iterates along the vector generated by the traceline that is detecting damage for hits and such at regular intervals and spawn the temp entity from the above code (make a vector variable called 'org' as referenced in the code).
to iterate, get the vector and normalize() it then multiply that unit vector by increasing amounts until you are past the end point.
#1736 posted by aDaya on 2015/10/01 11:19:06
That's the thing though, I know mostly nothing about programming, and your reply just make me ask more questions, like "How do I write such a loop and where do I implement it?" and "Wouldn't this effect be too big considering I want to control the particles amount and spread?" and "Wouldn't using gunshot impact effect look bad in Darkplaces, considering it replaces the puff with an actual bullet impact GFX?"
#1737 posted by necros on 2015/10/01 17:36:40
http://www.tutorialspoint.com/cprogramming/c_while_loop.htm
float len = vlen(endpos - startpos);
while(len > 0)
{
//do whatever effects here
len = len - 16; //do it spaced out by 16 units
}
#1738 posted by Kinn on 2015/10/02 19:18:51
Another "been a while since I did this shizzle" question:
What QC compiler are the kool kids using now, is it FTEQCC? If so, where is the homepage/link to latest version pls? (google throws up a host of dead/shady links)
#1739 posted by JneeraZ on 2015/10/02 19:21:15
I just use whatever tools are on ericw's page ...
http://ericwa.github.io/tyrutils-ericw/
Warrenm
#1740 posted by Kinn on 2015/10/02 19:31:11
Ah yes, for map compiling absolutely - but what I was wondering is what QC compiler is the current hotness.
Kinn
#1741 posted by mfx on 2015/10/02 19:37:05
Mfx
#1742 posted by Kinn on 2015/10/02 20:12:35
Noice, that's just the ticket
#1743 posted by JneeraZ on 2015/10/02 20:31:51
Oh lord, sorry. :) Reading, hard, blugh...
A Gun That Winds Up, Shoots, Wind Downs
#1744 posted by aDaya on 2015/10/12 23:23:47
So I've been trying to code my weapon today, and it's a Gatling Gun composed of 3 states: a wind up, a shooting loop, and a wind down.
The programming's supposed to be like this: weapon.qc holds the code to play sounds, and player.qc holds the animation (the W_Attack part in weapons.qc calls the starting animation in player.qc, "player_gatlup1"), and both of them are supposed to sync.
weapons.qc: http://pastebin.com/kJ1mMtqC
player.qc: http://pastebin.com/Bnf4ThZ1
Problem is, in weapons.qc, I want the Gatling Wind Up part to go on for 0.9 second no matter what, and then switch to Gatling Shoot. And it seems like self.attack_finished isn't the way to go, but after the help I got I got more confused because I haven't been told of a workaround.
Would somebody be kind enough to help me on this?
Spin Up
#1745 posted by Preach on 2015/10/13 04:28:20
The traditional way would be to have a series of animation functions leading to the firing sequence:
player_gatlup1
player_gatlup2
...
player_gatlup9
and only player_gatlup9 sends you to player_gatlshot1. For this approach, I'd probably ditch W_GatlingSpinUp and import the sound cue into player_gatlup1. As an important side note, you don't need these lines:
self.nextthink = time + 0.1;
self.attack_finished = time + 0.9;
in your player_gatlup1 function. nextthink is set automatically to time + 0.1 when you start a function with the prologue [$light1, player_gatlup2], and as the later code sets the attack_finished time that portion is redundant.
Hopefully from there things should start to work, it is something that there's no natural example of in the Quake code so the approach isn't obvious. I called this the traditional way - once you've got that bit working, there is a way to reduce the number of functions back down, but perhaps for another day...
Preach
#1746 posted by aDaya on 2015/10/13 15:37:52
Thanks, that made the weapon functionnal, but when I hold the shoot button, it indeed does the windup animation, but if I continue holding, it shoots a bullet, then does the wind down animation while still playing the gatling gun wind up sound on a loop. The windup, shoot a bullet, winddown routine goes on a loop until I let go of the button, when it'll imediately snaps back to its starting position while playing the gatling gun wind down sound once (the self.attacked_finished = time+0.9 is still in effect here).
Here's my reworked code from what you've said: http://pastebin.com/QbC7R7nT
OK, My Apologies
#1747 posted by Preach on 2015/10/13 20:09:04
I have a theory on what's happening. If the theory is true then I was wrong, the self.attacked_finished = time + 0.9 is doing important work I hadn't recognised, and I shouldn't have told you to remove it.
My theory is that you're not getting the wind-down animation, just jumping to the top of the wind-up animation, because your attack_finished time you set in player_gatlup1 just runs out when you make it to player_gatlshot1, and then the rest of the code decides that it's time to launch a new attack from player_gatlup1. So I think you should try putting some more self.attacked_finished = time + 0.9 in all the attack sequences, plus perhaps the last of the spinup functions.
As a side note, watch out for the function W_CheckNoAmmo. Although it looks like it's just returning some information to your function, it actually has a side effect of changing your weapon instantly! This will mean it skips your wind-down animation if you run out of ammo. Put a simpler check like self.currentammo > 0 in its place, and perform the weapon switching on the last frame of the wind-down instead.
Some More Problems...
#1748 posted by aDaya on 2015/10/13 21:43:10
I added the self.attack_finished = time + 0.9 lines to the last 3 frames of the gatling spin up part, deleted "return" as a condition result for self.currentammo > 0 and instead put it in the gatling down's function once frame 34 is played (the last one, for when the weapon winds down).
Now if I just press the fire key once or hold it, the weapon spins up, and after it finishes its animation it shoots once (the fire animation's not playing like before), then goes back to its first frame, and the gatling firing loop sound plays once. I have to wait 0.9 second -it seems- to be able to fire again.
Geez, how did Team Fortress Software able to code the Assault Canon properly for QWTF?
Patience Young Grasshopper
#1749 posted by Preach on 2015/10/13 22:29:15
They wrote the code for the assault cannon exactly like this, except they did all the cursing in private and didn't show anyone until they'd got it to work.
One of the things that I've spotted:
void() player_gatldown1 =[$nailatt1, player_run ]
The bit that says player_run there means that 1 frame after you've started the spindown animation, you skip straight to "everything is normal" mode, besides waiting for the attack_finished counter to run down. You should change that bit to player_gatldown1 so that it keeps looping back to the same function. Of course, it will never return to "everything is normal" mode unless you add a line which runs player_run(); once the animation has completed, so add that too.
Are you getting a chain of shots in-between spinning up and spinning down, so long as you hold fire? I hope that's all working now...
#1750 posted by aDaya on 2015/10/13 22:39:32
I can only get one shot either by just hitting the button once or holding it.
After I did what you suggested, it can only fire once like I said (it did it before) and then the winddown function loops at one frame at a time, and I can't do anything weapon-wise until I pick up an item.
code: http://pastebin.com/wFj7j1cJ
|
|
You must be logged in to post in this thread.
|
Website copyright © 2002-2024 John Fitzgibbons. All posts are copyright their respective authors.
|
|