![]() |
|
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Home
Downloads Contact Mod Basics Pack Files Decl Files Decl Editor Commands Cvars The Code Exporting Models Model Decls Skins Lighting Bump Maps Materials Articulated Figures AF Editor Walk IK Sounds Sound Editor Particles Particle Editor FX GUIs GUI Editor Maps DOOMEdit Editor Keys Light Editor EntityDefs MapDefs PDAs PDA Editor Scripts Map Scripts Weapon Scripts AI Scripts Script Editor |
Weapon scripts can do everything that map scripts can, they just don't have as many objects
to fondle.
The most confusing thing about a weapon script is probably the fact that it's an object of type idWeapon. That means you don't have to specify an object name when you send an event, because it sends the event to itself. Seasoned C++ programmers will recognize it as the hidden this pointer. Normally you would say $something.hide(); but when the function is defined in an object, you can just say hide(); and it will automatically know what the object is. In the case of a weapon script, the object is the weapon itself. You will see this again when looking at AI scripts (the object will be the monster). Let's analyze the weapon_pistol.script for a bit. Right after the #define section, we forward declare the weapon_pistol object, and say it's going to inherit from weapon_base. The inheritance allows us to put some common functions in weapon_base and have them available to all weapons. We specify what variables and functions are going to be in our weapon. After the object definition, we find declarations for all the functions we said we were going to have. When a weapon is selected (with an impulse command or by picking it up), the init function is called on the weapon object. Generally this will read some default values from the weapon entityDef and set the weapon state to "Raise". Weapon States
The weaponState function is the key to driving the weapon code. This function controls transitioning from various weapon states, which are defined by member functions in the weapon object. The first parameter is the name of the state to switch to (which should be a function name), the second parameter is the number of frames over which to blend the animation during the state change. A good example of a state change is in weapon_pistol::Reload. The function starts the reload animation and waits for it to finish. It then adds some bullets to the clip and transitions to the Idle state. The animDone function takes a blend count as the second argument. In this case the blend count is 4, so it will return true when there are only 4 frames left in the animation to play. We pass this same value to the weaponState function so it knows that there are still 4 frames left to play in the current animation. The weaponState function stores this information so when the idle animation starts playing, the first 4 frames are blended with the last 4 frames of the previous animation (which was reload). This animation blending allows smooth transitions between completely different animations without really ugly jerky movements. Handy Weapon Functions
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Copyright © 2004 id software |