Help with Random Item script

esn23

Active member
So I wanted to use this random item script and know i have to expand on the script part.. I do not know how to write scripts could someone please help.. This is what I have so far....

name      RandItem
type      none
gfxshadow  1
lifespan  2
animationscript  data/scripts/enemy.c
load      Coin
load      Hp
load      Mp
load      1up
load      capbriti
load      dark_stari
load      dazzleri
load      elixiri
load      havoki
load      icemani
load      madroxi
load      MagmaI
load      meggani
load      NamorI
load      sunspoti
load      surgei
load      x23i


anim  idle
@script
    if(frame == 1){
      void self = getlocalvar("self");
      int r = rand()%30;

      if(r < -10){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
      } else if(r > 10){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
      }
    }
@end_script
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "Coin" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow1
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "Hp" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow2
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "Mp" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow3
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "1up" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow4
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "capbriti" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow5
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "dark_stari" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow6
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "elixiri" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow7
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "havoki" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow8
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "icemani" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow9
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "madroxi" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow10
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "MagmaI" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow11
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "meggani" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow12
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "NamorI" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow13
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "sunspoti" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow14
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "surgei" 0 0 0
  frame  data/chars/misc/empty.gif

anim  follow15
  delay  1
  offset  8 14
  frame  data/chars/misc/empty.gif
  delay  200
  @cmd  spawn01 "x23i" 0 0 0
  frame  data/chars/misc/empty.gif

Any help would be great to finish up this scipts thanks in advance..
 
Your code is using just 2 animations, this is why it doesn't works.

You can adapt my item script for this, using switch for each case.  Its here at tutorial section.

I can write that code but it will still takes time before I can Do it. And I would do prefer to make it using arrays.
 
that would be a huge help O :P  Im stuck when it comes to script and would like this in the game so that its a new experience each time.. Especially because i made the helpers op and want to make them rare... I knew that it needed a bit more to it for the script part but didn't know how to script it.. :P
 
bravo you say your not good at scripting but you have done a fantastic job with this its very similar with a entity I use in my mod so I tried to fix it up for you try my version and see if that works for you remember its untested and again great job.


Code:
name      RandItem
type      none
gfxshadow   1
lifespan   2
animationscript   data/scripts/enemy.c
load      Coin
load      Hp
load      Mp
load      1up
load      capbriti
load      dark_stari
load      dazzleri
load      elixiri
load      havoki
load      icemani
load      madroxi
load      MagmaI
load      meggani
load      NamorI
load      sunspoti
load      surgei
load      x23i


anim   idle
@script
void self = getlocalvar("self"); //get calling entity
int random = (openborvariant("elapsed_time")/2)%16+1; //random number from 1 to 16
    if(frame == 1)
	{
      if(random == 1){  //if random number is 1
          changeentityproperty(self, "animation", openborconstant("ANI_FREESPECIAL")); //move to freespecial
	  }else{ //if random number is not 1
          changeentityproperty(self, "animation", openborconstant("ANI_FREESPECIAL" + random)); //move to freespecial matching the random number
	  }
	}
@end_script
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   frame   data/chars/misc/empty.gif
   delay   200
   frame   data/chars/misc/empty.gif


anim FREESPECIAL
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "Hp" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL2
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "Mp" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL3
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "1up" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL4
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "capbriti" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL5
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "dark_stari" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL6
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "elixiri" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL7
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "havoki" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL8
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "icemani" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL9
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "madroxi" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL10
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "MagmaI" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL11
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "meggani" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL12
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "NamorI" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL13
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "sunspoti" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL14
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "surgei" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL15
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "x23i" 0 0 0
   frame   data/chars/misc/empty.gif


anim FREESPECIAL16
   delay   1
   offset   8 14
   frame   data/chars/misc/empty.gif
   delay   200
   @cmd   spawn01 "Coin" 0 0 0
   frame   data/chars/misc/empty.gif
 
I can say that this script is wonderful and works perfectly so far.. I just need to test if it works on enemies dropping stuff too.. Thanks again for this it helped out a lot
 
Glad i could help and remember @cmd commands can not be used in the same animation you used a @script command.
 
I am not trying to nitpick you, I am just trying to understand this:
int random = (openborvariant("elapsed_time")/2)%16+1;
What exactly prevents the negative values here?

Anyway, great work.

msmalik681 said:
Glad i could help and remember @cmd commands can not be used in the same animation you used a @script command.
Yes, you can. WD had fixed it some builds ago. I use it on my mod.
 
Its because i am not using the built in rand () fuction this uses:

time ÷ user_set_limit + 1

But due to strange bug the time has to be shared by 2 first thats why that part is in brackets.

And i could have swore when white dragon added that feature DC took it right back out as it broke something.  Maybe i remembered wrong.
 
Thanks for the explanation.
But what about the float values you will have here? Using time / 2 can give you some float values, not integers.
For example, 35/2 = 17.5. And there is not round function on that code.
 
Back
Top Bottom