Qc file and sprites. Created 8 years ago2016-11-25 20:18:03 UTC by abbadon abbadon

Created 8 years ago2016-11-25 20:18:03 UTC by abbadon abbadon

Posted 8 years ago2016-11-25 20:18:03 UTC Post #332455
Hi everyone. I have a single question of which I did not find a good answer. How are sprites and its scale being set up into the qc file of a model?, how to make that muzzleflash3 will be used instead of muzzleflash2?. I ask because I did the qc for my mod's weapons and models almost 9 years ago and after breaking three times some stuff here and there I found myself unable to find a clue about how all this is made into the qc file.

Thanks in anticipation.
Posted 8 years ago2016-11-25 22:22:27 UTC Post #332457
Muzzle flashes are displayed using events 5001 (attachment 0), 5011 (attachment 1), 5021 (attachment 2), 5031 (attachment 3).
The muzzleflash to use is determined by the event options. 0 uses muzzleflash1.spr, 1 uses muzzleflash2.spr, 2 uses muzzleflash3.spr.

The option value is moduled twice: first by 10 and then by 3, in effect constraining the value to [ -2, 2 ]. It can be negative because performing modulo on negative values produces negative values. So make sure you never use negative values there.

The scale of the sprite is encoded in the option as well. The scale is value / 10 * 0.1, so a value of 10 uses muzzleflash1.spr:
10 % 10 = 0
0 % 3 = 0
scale = 10 / 10 = 1

A value of 11 would be scale 1, muzzleflash2.spr:
11 % 10 = 1
1 % 3 = 1
11 / 10 = 1

So as a rule of thumb:
Scale * 10 + muzzleflash
So if you want a scale of 3, muzzleflash2.spr:
3 * 10 + 1 = 31
31 % 10 = 1
1 % 3 = 1
31 / 10 = 3

Scale can only be a whole number because it's converted to an integer, see R_MuzzleFlash for the function that is used. You should also be able to find the code that handles the events and passes them into R_MuzzleFlash in entity.cpp, function HUD_StudioEvent.
Posted 8 years ago2016-11-26 09:25:59 UTC Post #332463
Ok, so taking event 5001 as an example, and its numbers as letters ( A=5, B=first 0, C=second 0, and D=1), we have:

A= Event
B= Type of muzzleflash 1,2,3,etc.
C= Attachment
D= Scale

Is it right?
Posted 8 years ago2016-11-26 09:31:55 UTC Post #332464
The event number is just that, a number. You don't encode information in it.
Events have the event id and an options string. The attachment is decided by the event id.

See this for the code that takes the event and creates the muzzleflash: https://github.com/ValveSoftware/halflife/blob/master/cl_dll/entity.cpp#L348
Posted 8 years ago2016-11-26 09:40:11 UTC Post #332466
I see, the D number determines if what is shown is a spark, or if the code plays a sound.

D=1 Sprite
D=2 Effect
D=4 Sound

But for the B number, is it what says the sprite to use?
Posted 8 years ago2016-11-26 10:24:45 UTC Post #332467
Like i said, the event number is just a number, you don't encode any special information in it. The game runs code for a particular event, but it doesn't change what it does based on the numbers in it. Valve may have decided on this numbering convention for their events, but it doesn't mean that all events will follow it.

If you need to show muzzle flashes, use the events for them. If you need a spark effect, use its event, and if you need to play a sound, use the event for it. Don't assume that all events that end in a particular number will do the same thing.

See this enum for which events are commonly used: https://github.com/SamVanheer/HLEnhanced/blob/master/game/shared/ScriptEvent.h#L21
Posted 8 years ago2016-11-26 14:40:39 UTC Post #332468
Ok, kinda got it. I will use that info. Thanks Solokiller!! :)

EDIT: I feel quite dumb now, I have noticed some diferences between qc files between monster and weapon models.

Most of them, the ones that fired weapons (mp5, shotguns) are using the event 5001, that is, muzzleflash on attachpent 1, or the turret, that uses the same event 5001 aswell. But the difference is two numbers that follow the event. i.e:

{EVENT 5001 0 "51"}

I have discovered that the "0" goes for the frame on which the sprite is shown, but the last number is what varies the most:

Python uses 31
Turret uses 51
MP5 uses 50
Hgrunt uses 50

So my question is, are the sprites defined by this number?, also, if not, what means the 50 the 51 and the 31 numbers?
Posted 8 years ago2016-11-26 15:29:53 UTC Post #332469
That's the option string i was talking about.
Posted 8 years ago2016-11-26 15:38:02 UTC Post #332470
Ooooooh, my english... :nya: I have read all again and my sillyness level reaches GOD mode.
Posted 7 years ago2016-11-27 13:42:35 UTC Post #332472
This is just to help others:

Example:
{event 5001 0 51}
5001 The event itself, it is hardcoded.

5001 Nuber "0" equals "attachment 0", "1" is for atrachment "1", etc.

0 The 0 between 5001 and 51 is the frame on which the event is played.

51 Is the scale on which the sprite is shown (read more above).

51 Equals to "muzzleflash2.spr". So, if you want muzzleflash1.spr the number must be "0", if you want muzzleflash3.spr you must use number "2". etc.

Brackets are programmers stuff, don't mess with them, they bite.

Thanks Solokiller!!, you're the best :)
Posted 7 years ago2016-11-27 14:01:15 UTC Post #332473
The event number doesn't hold any meaning as to what the event will do. Just because the third number is a 0 doesn't mean that it will always affect attachment 0.
It's very important that you understand this because there are events that also have similar numbers and don't have anything to do with attachments.

Other than that what you said is correct :)
Posted 7 years ago2016-11-27 20:04:45 UTC Post #332474
Crap. I was wrong again. I have seen in my player.qc that left hand has attachment 0 assigned with event 5001 in its fire animation, and also right hand has attachment 1 assigned for its fire animation, so I made a simple association that is, clearly, wrong. Thanks for point me to it! :)

In fact muzzleflashes are limited to 4 attachments, as you did say:

5001 attachment 0
5011 attachment 1
5021 attachment 2
5031 attachmdnt 3

I mean, it is hardcoded. Again, I did MUST have read carefully your post... I have to start using Google translator!! haha.
Posted 7 years ago2016-11-27 20:06:46 UTC Post #332475
Yeah, there are only up to 4 attachments supported. That's a hardcoded limit that cannot be changed without breaking compatibility with all mods, so it's stuck that way. The muzzleflashes are also hardcoded, like every other thing in existence.
I suppose you could add more attachments if you expand the studiomodel format with new data structures, but that's going to be a mess even in the best case.
You must be logged in to post a response.