Author Topic: Is it possible to make a random animation script?  (Read 638 times)

For example,i made 10 diffrent animations for the same gun.
And i want all of them to play in a random order evertime the gun reloads.
Sometimes it will be a MLG style magazine thorwing reload,sometimes normal reload.
You get the point.
Visolator told me its not possible to make it but i decided to ask the forums anyways.
 :P

It really isn't. Because weapon animations can only be played through sequences you're limited to only one possible animation per system of sequences.

well, i think you could do it, but you'd need a separate weapon image for each reload animation

for example, once the primary image is at the "reload" sequence, it calls a function that randomly selects a number 1-10, runs through a series of if-thens and fires ohhh say 7, which is the mlg reload, and mounts the mlg reload image that is dedicated to playing through specific reload sequences, and then re-mounts the primary image when it's done

so hypothetically it's possible but overall not very practical imo

I think name your animations reload1, reload2, etc

Function ranReload()
{
     Return "reload"@getRandom(0,4);
}


Later

State sequence = ranreload();

I may be wrong in syntax, but something along those lines should work

I think name your animations reload1, reload2, etc

Function ranReload()
{
     Return "reload"@getRandom(0,4);
}


Later

State sequence = ranreload();

I may be wrong in syntax, but something along those lines should work
That doesn't work, it'll get a single random number at the time you create the datablock and always use that.

The state system doesn't support random animations at all, probably because of de-sync reasons.

its possible but not practical

here is a concept of how to choose one of 4 random reload animations
Code: [Select]
stateName[0] = "Ready";

...

stateName[5] = "ReloadCheck1A";
stateScript[5] = "ReloadCheck1";
stateTimeoutValue[5] = 0.01;
stateTransitionOnTimeout[5] = "ReloadCheck1B";

stateName[6] = "ReloadCheck1B";
stateTransitionOnNoAmmo[6] = "ReloadCheck2A";
stateTransitionOnAmmo[6] = "Reload1";

stateName[7] = "Relaod1";
stateSequence[7] = "Reload1";
stateTimeoutValue[7] = 0.3;
stateTransitionOnTimeout[7] = "Done";

stateName[8] = "ReloadCheck2A";
stateScript[8] = "ReloadCheck2";
stateTimeoutValue[8] = 0.01;
stateTransitionOnTimeout[8] = "ReloadCheck2B";

stateName[9] = "ReloadCheck2B";
stateTransitionOnNoAmmo[9] = "ReloadCheck3A";
stateTransitionOnAmmo[9] = "Reload2";

stateName[10] = "Relaod2";
stateSequence[10] = "Reload2";
stateTimeoutValue[10] = 0.3;
stateTransitionOnTimeout[10] = "Done";

stateName[11] = "ReloadCheck3A";
stateScript[11] = "ReloadCheck3";
stateTimeoutValue[11] = 0.01;
stateTransitionOnTimeout[11] = "ReloadCheck3B";

stateName[12] = "ReloadCheck3B";
stateTransitionOnNoAmmo[12] = "Reload4";
stateTransitionOnAmmo[12] = "Reload3";

stateName[13] = "Relaod3";
stateSequence[13] = "Reload3";
stateTimeoutValue[13] = 0.3;
stateTransitionOnTimeout[13] = "Done";

stateName[14] = "Relaod4";
stateSequence[14] = "Reload4";
stateTimeoutValue[14] = 0.3;
stateTransitionOnTimeout[14] = "Done";

stateName[15] = "Done";

...
};
function reloadGun::onReloadCheck1(%db,%pl,%slot)
{
%pl.reloadAnim = getRandom(1,4);
if(%pl.reloadAnim == 1)
%pl.setImageAmmo(0,1);
else
%pl.setImageAmmo(0,0);
}
function reloadGun::onReloadCheck2(%db,%pl,%slot)
{
if(%pl.reloadAnim == 2)
%pl.setImageAmmo(0,1);
else
%pl.setImageAmmo(0,0);
}
function reloadGun::onReloadCheck3(%db,%pl,%slot)
{
if(%pl.reloadAnim == 3)
%pl.setImageAmmo(0,1);
else
%pl.setImageAmmo(0,0);
}

+Start at ReloadCheck1A
+call the stateScript ReloadCheck1
  -chooses a random number
  -if the number is 1 set image ammo to loaded
  -if the number is not 1 set image ammo to not loaded
+the next state happens after a 0.01 second delay
  -if the imageAmmo is loaded go to that reload animation
  -if not go to the next reload check
etc.
« Last Edit: January 10, 2016, 09:56:12 PM by Swollow »