| Blockland Forums > Modification Help |
| Weapon Scripting |
| (1/1) |
| RFW2:
Hello. Im goint to show you what each value in the default gun's script does. This will hopefully help you start you off in learning how to script. Remember, you can find most of these values in other scripts, so if you wanted to make a machine gun, you could pick any script that you think is a bit like what you want, and edit it, the same way you will do here. Ok, here is the code: --- Code: ---//gun.cs - // This is just here for show. anything with "//" to the left of it, tourque knows to ignore. //audio datablock AudioProfile(gunShot1Sound) //This is here to say that what is below it is all about the gun fire sound(or "gunShot1) { filename = "./gunShot1.wav"; // this is the name of the file you want to play when the gun is fired. The "./" means it is in the same folder as the script. You could put a file location, like "C:/Blockland/add-ons/Weapon_Gun" here, but that would be pointless. But this can be useful to get a file from another weapon, instead of making a whole new datablock. description = AudioClose3d; preload = true; }; datablock AudioProfile(bulletHitSound) //this is the same but for the sound when the bullet hits something. { filename = "./bulletHit.wav"; //the name of the sound description = AudioClose3d; // preload = true; }; //shell datablock DebrisData(gunShellDebris) //the same, but with the gun shell, that pops out of the gun when you fire it(not the bullet) { shapeFile = "./gunShell.dts"; //the name of the file lifetime = 2.0; //how long it stays before dissapearing minSpinSpeed = -400.0; //the minimum speed that it will spin in the air maxSpinSpeed = 200.0; //the maximum speed it will spin in the air elasticity = 0.5; friction = 0.2; numBounces = 3; // the maximum number of bounces it will do befor it dissapears staticOnMaxBounce = true; snapOnMaxBounce = false; fade = true; gravModifier = 2; //how much gravity affects it }; //muzzle flash effects datablock ParticleData(gunFlashParticle) //one piece of the emmiter that appears when the gun is fired.. { dragCoefficient = 3; gravityCoefficient = -0.5; inheritedVelFactor = 0.2; constantAcceleration = 0.0; lifetimeMS = 25; //how long it lasts lifetimeVarianceMS = 15; //how long that time could vary by textureName = "base/data/particles/star1"; //the texture name for each individual "piece" of the emmiter spinSpeed = 10.0; //the speed it spins at spinRandomMin = -500.0; //the minimum speed the random thing can set it to spinRandomMax = 500.0; //the same, but the maximum colors[0] = "0.9 0.9 0.0 0.9"; //the different colors different "pieces" can be colors[1] = "0.9 0.5 0.0 0.0"; sizes[0] = 0.5; //the different sizes sizes[1] = 1.0; useInvAlpha = false; }; datablock ParticleEmitterData(gunFlashEmitter) //the actuall emmiter that uses the pieces that were set above { ejectionPeriodMS = 3; //how long the emmiter lasts periodVarianceMS = 0; //the amount the above amount can vary by ejectionVelocity = 1.0; //the speed it... moves? velocityVariance = 1.0; //the amount the above amount can vary ejectionOffset = 0.0; //the offset of the emitter thetaMin = 0; thetaMax = 90; phiReferenceVel = 0; phiVariance = 360; overrideAdvance = false; particles = "gunFlashParticle"; /the piece it uses to make the emmiter(AKA the thing above this bit of script). uiName = "Gun Flash"; //The name of the emitter ingame }; datablock ParticleData(gunSmokeParticle) //one piece of the smoke { dragCoefficient = 3; gravityCoefficient = -0.5; //how much gravity affects it. A negative number is like it being lighter than the air. inheritedVelFactor = 0.2; constantAcceleration = 0.0; lifetimeMS = 525; lifetimeVarianceMS = 55; textureName = "base/data/particles/cloud"; //the name of the texture it uses. spinSpeed = 10.0; //the speed it spins at spinRandomMin = -500.0; //the minimum random speed it can spin at spinRandomMax = 500.0; //the same as the above, but the maximum colors[0] = "0.5 0.5 0.5 0.9"; /the different colors it can be colors[1] = "0.5 0.5 0.5 0.0"; sizes[0] = 0.15; //the different sizes it can be sizes[1] = 0.15; useInvAlpha = false; }; datablock ParticleEmitterData(gunSmokeEmitter) //the emmiter that uses the piece that was created above { ejectionPeriodMS = 3; //how long it lasts periodVarianceMS = 0; //how much the above can vary ejectionVelocity = 1.0; //the speed it moves at velocityVariance = 1.0; //how much the above can vary ejectionOffset = 0.0; //the offset it is spawned at thetaMin = 0; thetaMax = 90; phiReferenceVel = 0; phiVariance = 360; overrideAdvance = false; particles = "gunSmokeParticle"; //the name of the particle it uses to make the emitter uiName = "Gun Smoke"; //the name of the emmiter ingame }; datablock ParticleData(gunExplosionParticle) //you get the idea. All the values below are the same as the ones a bit earlier { dragCoefficient = 8; gravityCoefficient = 1; inheritedVelFactor = 0.2; constantAcceleration = 0.0; lifetimeMS = 700; lifetimeVarianceMS = 400; textureName = "base/data/particles/cloud"; spinSpeed = 10.0; spinRandomMin = -50.0; spinRandomMax = 50.0; colors[0] = "0.9 0.9 0.9 0.3"; colors[1] = "0.9 0.5 0.6 0.0"; sizes[0] = 0.25; sizes[1] = 0.75; useInvAlpha = true; }; datablock ParticleEmitterData(gunExplosionEmitter) //the same here { ejectionPeriodMS = 1; periodVarianceMS = 0; ejectionVelocity = 2; velocityVariance = 1.0; ejectionOffset = 0.0; thetaMin = 89; thetaMax = 90; phiReferenceVel = 0; phiVariance = 360; overrideAdvance = false; particles = "gunExplosionParticle"; useEmitterColors = true; uiName = "Gun Hit Dust"; }; datablock ParticleData(gunExplosionRingParticle) //and here { dragCoefficient = 8; gravityCoefficient = -0.5; inheritedVelFactor = 0.2; constantAcceleration = 0.0; lifetimeMS = 50; lifetimeVarianceMS = 35; textureName = "base/data/particles/star1"; spinSpeed = 500.0; spinRandomMin = -500.0; spinRandomMax = 500.0; colors[0] = "1 1 0.0 0.9"; colors[1] = "0.9 0.0 0.0 0.0"; sizes[0] = 1; sizes[1] = 0; useInvAlpha = false; }; datablock ParticleEmitterData(gunExplosionRingEmitter) //and also here... { lifeTimeMS = 50; ejectionPeriodMS = 3; periodVarianceMS = 0; ejectionVelocity = 0; velocityVariance = 0.0; ejectionOffset = 0.0; thetaMin = 89; thetaMax = 90; phiReferenceVel = 0; phiVariance = 360; overrideAdvance = false; particles = "gunExplosionRingParticle"; useEmitterColors = true; uiName = "Gun Hit Flash"; }; datablock ExplosionData(gunExplosion) //the explosion the bullet makes when it hits something { //explosionShape = ""; //the shape of the explosion soundProfile = bulletHitSound; //the sound to play when the bullet hits something lifeTimeMS = 150; //how long the explosin lasts particleEmitter = gunExplosionEmitter; //the emitter to use when the explosin happens particleDensity = 5; particleRadius = 0.2; emitter[0] = gunExplosionRingEmitter; faceViewer = true; explosionScale = "1 1 1"; //the scale of the explosion shakeCamera = false; //wether to shake the camera or not camShakeFreq = "10.0 11.0 10.0"; //how much to shake the camera camShakeAmp = "1.0 1.0 1.0"; //??? camShakeDuration = 0.5; //how long the shake lasts camShakeRadius = 10.0; // Dynamic light lightStartRadius = 0; lightEndRadius = 2; lightStartColor = "0.3 0.6 0.7"; lightEndColor = "0 0 0"; }; AddDamageType("Gun", '<bitmap:add-ons/Weapon_Gun/CI_gun> %1', '%2 <bitmap:add-ons/Weapon_Gun/CI_gun> %1',0.2,1); //what type of damge to add. Im not really sure how this works datablock ProjectileData(gunProjectile) { projectileShapeName = "./bullet.dts"; //the shape of the projectile directDamage = 30; //how much damage it does directDamageType = $DamageType::Gun; radiusDamageType = $DamageType::Gun; brickExplosionRadius = 0; brickExplosionImpact = true; //destroy a brick if we hit it directly? brickExplosionForce = 10; //how much forse is used to proppel the brick brickExplosionMaxVolume = 1; //max volume of bricks that we can destroy brickExplosionMaxVolumeFloating = 2; //max volume of bricks that we can destroy if they aren't connected to the ground impactImpulse = 400; verticalImpulse = 400; explosion = gunExplosion; //what explosion to use particleEmitter = ""; //bulletTrailEmitter; //the emitter that is trailing from the bullet muzzleVelocity = 90; //the speed of the projectile. Max speed is 200 velInheritFactor = 1; armingDelay = 00; lifetime = 4000; //how long the bullet lasts for fadeDelay = 3500; //how long the bullet goes before starting to fade bounceElasticity = 0.5; bounceFriction = 0.20; isBallistic = false; gravityMod = 0.0; //how much gravity affects it hasLight = false; lightRadius = 3.0; lightColor = "0 0 0.5"; uiName = "Gun Bullet"; //the ingame name of the bullet }; ////////// // item // ////////// datablock ItemData(GunItem) { category = "Weapon"; // Mission editor category className = "Weapon"; // For inventory system // Basic Item Properties shapeFile = "./pistol.dts"; //the shape of the gun rotate = false; //wether to rotate the shape or not mass = 1; density = 0.2; elasticity = 0.2; friction = 0.6; emap = true; //gui stuff uiName = "Gun"; //the name of the gun ingame iconName = "./icon_gun"; //the name of the icon doColorShift = true; //wether to change the color of the icon colorShiftColor = "0.25 0.25 0.25 1.000"; //what color to change the icon to // Dynamic properties defined by the scripts image = gunImage; canDrop = true; }; //////////////// //weapon image// //////////////// datablock ShapeBaseImageData(gunImage) { // Basic Item properties shapeFile = "./pistol.dts"; emap = true; // Specify mount point & offset for 3rd person, and eye offset // for first person rendering. mountPoint = 0; offset = "0 0 0"; eyeOffset = 0; //"0.7 1.2 -0.5"; rotation = eulerToMatrix( "0 0 0" ); // When firing from a point offset from the eye, muzzle correction // will adjust the muzzle vector to point to the eye LOS point. // Since this weapon doesn't actually fire from the muzzle point, // we need to turn this off. correctMuzzleVector = true; // Add the WeaponImage namespace as a parent, WeaponImage namespace // provides some hooks into the inventory system. className = "WeaponImage"; // Projectile && Ammo. item = BowItem; ammo = " "; projectile = gunProjectile; projectileType = Projectile; casing = gunShellDebris; shellExitDir = "1.0 -1.3 1.0"; shellExitOffset = "0 0 0"; shellExitVariance = 15.0; shellVelocity = 7.0; //melee particles shoot from eye node for consistancy melee = false; //raise your arm up or not armReady = true; doColorShift = true; colorShiftColor = gunItem.colorShiftColor;//"0.400 0.196 0 1.000"; //casing = " "; // Images have a state system which controls how the animations // are run, which sounds are played, script callbacks, etc. This // state system is downloaded to the client so that clients can // predict state changes and animate accordingly. The following // system supports basic ready->fire->reload transitions as // well as a no-ammo->dryfire idle state. // Initial start up state stateName[0] = "Activate"; stateTimeoutValue[0] = 0.15; stateTransitionOnTimeout[0] = "Ready"; stateSound[0] = weaponSwitchSound; stateName[1] = "Ready"; stateTransitionOnTriggerDown[1] = "Fire"; stateAllowImageChange[1] = true; stateSequence[1] = "Ready"; stateName[2] = "Fire"; stateTransitionOnTimeout[2] = "Smoke"; stateTimeoutValue[2] = 0.14; stateFire[2] = true; stateAllowImageChange[2] = false; stateSequence[2] = "Fire"; stateScript[2] = "onFire"; stateWaitForTimeout[2] = true; stateEmitter[2] = gunFlashEmitter; stateEmitterTime[2] = 0.05; stateEmitterNode[2] = "muzzleNode"; stateSound[2] = gunShot1Sound; stateEjectShell[2] = true; stateName[3] = "Smoke"; stateEmitter[3] = gunSmokeEmitter; stateEmitterTime[3] = 0.05; stateEmitterNode[3] = "muzzleNode"; stateTimeoutValue[3] = 0.01; stateTransitionOnTimeout[3] = "Reload"; stateName[4] = "Reload"; stateSequence[4] = "Reload"; stateTransitionOnTriggerUp[4] = "Ready"; stateSequence[4] = "Ready"; }; function gunImage::onFire(%this,%obj,%slot) { if(%obj.getDamagePercent() < 1.0) %obj.playThread(2, shiftAway); Parent::onFire(%this,%obj,%slot); } --- End code --- This is all I can do for now. Im posting it anyway. Please tell me if there is something Ive got wrong. And I hope this helps |
| takato14:
Sounds more like the title for someone who NEEDS help and is asking for it. Change the title. first post :P |
| Navigation |
| Message Index |