Author Topic: "Get Random" script, Need help.  (Read 952 times)

So i'm currently making call out sounds for the frag grenade, i've made 6 sounds of a soldier calling out "frag out mother forgeters" etc, so here is the script guide me the rest of the way:
// Initial start up state
   stateName[0]         = "Activate";
   stateTimeoutValue[0]      = 0.1;
   stateTransitionOnTimeout[0]   = "Ready";
   stateSequence[0]      = "ready";
   stateSound[0]               = weaponSwitchSound;

   stateName[1]         = "Ready";
   stateTransitionOnTriggerDown[1]   = "Pindrop";
   stateAllowImageChange[1]   = true;

   stateName[2]         = "Pindrop";
   stateTransitionOnTimeout[2]   = "Pinfallen";
   stateAllowImageChange[2]   = false;
   stateTimeoutValue[2]      = 0.2;
   stateSound[2]            = NewFragGrenadeFireSound;
   stateSequence[2]                = "Pinpull";
   stateEjectShell[2]       = true;
   stateScript[2] = "onPinDrop";

   stateName[3]         = "Pinfallen";
   stateTransitionOnTriggerDown[3]   = "Charge";
   stateAllowImageChange[3]   = false;
   
   stateName[4]                    = "Charge";
   stateTransitionOnTimeout[4]   = "Armed";
   stateTimeoutValue[4]            = 0.7;
   stateWaitForTimeout[4]      = false;
   stateTransitionOnTriggerUp[4]   = "AbortCharge";
   stateScript[4]                  = "onCharge";
   stateAllowImageChange[4]        = false;
   
   stateName[5]         = "AbortCharge";
   stateTransitionOnTimeout[5]   = "Pinfallen";
   stateTimeoutValue[5]      = 0.3;
   stateWaitForTimeout[5]      = true;
   stateScript[5]         = "onAbortCharge";
   stateAllowImageChange[5]   = false;

   stateName[6]         = "Armed";
   stateTransitionOnTriggerUp[6]   = "Fire";
   stateAllowImageChange[6]   = false;

   stateName[7]         = "Fire";
   stateTransitionOnTimeout[7]   = "Done";
   stateTimeoutValue[7]      = 0.5;
   stateFire[7]         = true;
   stateSequence[7]      = "fire";
   stateScript[7]         = "onFire";
   stateWaitForTimeout[7]      = true;
   stateAllowImageChange[7]   = false;

   stateName[8]               = "Done";
   stateScript[8]               = "onDone";

};
Now i've seen a Get random (1, 6) script on files like death yell files, but how would i implement that in here? and please correct me if i gave you the wrong part of the script, Thanks you guys.

In the onFire part of the script (not state sequence, which is what you have posted), add a switch with getRandom(1, 6) as the variable to be checked, then in each case play sound at the players position somehow, do a search for the play 3d sound function.
« Last Edit: May 03, 2014, 03:05:22 PM by boodals 2 »

the only "OnFire" part that i can find is in the strip of code that i posted i cant find it anywhere else, i can post the whole script and maby you can find it?

Take a look at other weapon add-ons, you are looking for a function.

Code: [Select]
datablock AudioProfile(pickSwing1)
{
   filename    = "./sound/pickswing/pickswing1.wav";
   description = AudioClosest3d;
   preload = true;
};

datablock AudioProfile(pickSwing2)
{
   filename    = "./sound/pickswing/pickswing2.wav";
   description = AudioClosest3d;
   preload = true;
};

datablock AudioProfile(pickSwing3)
{
   filename    = "./sound/pickswing/pickswing3.wav";
   description = AudioClosest3d;
   preload = true;
};

function MiningPickaxeImage::onFire(%this,%obj,%slot)
{
parent::onFire(%this,%obj,%slot);

serverPlay3D(pickSwing @ getRandom(1,3),%obj.getPosition());

%obj.playThread(2,"armAttack");
}

Took this from my mining addon, this is probably what you're looking for.

OK i found it! its way the hell at the bottom of the script. "TheBlackParrot" is it ok if i rip some of your script out? if so is this exactly what i need to put in the script?

parent::onFire(%this,%obj,%slot);

   serverPlay3D(pickSwing @ getRandom(1,3),%obj.getPosition());

Don't forget that you will need a string for that part.. I'm not so sure if that still works with one word unless it finds it as an object

"pickSwing" @ getRandom(1,3)

It would still work just fine without quote marks. If you want to be completely sure, first map the name to an ID using nameToID) and then check with isObject before playing the sound.