Random item drop

mtrain

New member
I remember that there was a topic on the old lavalit forum about it. I want to get something like a @cmd spawnitem and put only it in the end of the enemy death animation. So when enemy dies he will summon a random item from item list that must be defined in separate script.c file. Maybe i have seen an example of script for random percentage spawn, but cant find it. Thank you)
 
I prefer setting random item drop in item instead of in enemy's DEATH animation.

Anyways, at least you need to define a list of possibly dropped items before setting script. Oh speaking of randomness, do you want equal chance for all items or one or 2 has more or lesser chance?
 
I have a list of 20 items (maybe later it will be more). Yes i want to make equal chance to all, i think it is easier ti make? At last we can make some of them empty, for more randomness.
 
Would this be general, or a different drop table per enemy?

The latter would be perfect in a game like Dungeons & Dragons and ClaFan. Especially if you make "rare" enemies spawn that have a high drop rate of 1ups or something?
 
Would this be general, or a different drop table per enemy?

I think if it is possible to make it for the general as i write at 1st post, it easily can be modified for other different drop types. For example, you have a script itemspawn that will contain a list of items, even with equal drop rate, you can copy it to itemspawnrare, and replace some items with rare and some items, maybe even biggest part of list with empty items.

I think i saw a thread with random enemy spawn, thats why i thought that can be rewrited for items as well.

I prefer setting random item drop in item instead of in enemy's DEATH animation.

But in this case i still need to set each enemy spawn with additional item line:

spawn Enemy
item Item
coords..
at..

Take in mind that there will be a huge amount of enemies in one level, it will take a lot of space in level.txt, so for me it will be easier to force item spawn after enemy`s death in his death anim. Easy thing is that all i need is to edit my item list as i want. So, is it still possible to make it that way?
 
name ItemSpawner1
type none
lifespan    1
onspawnscript @script
void initItems(void items)
{
void i = 0;
set(items,i++,"item1");
set(items,i++,"item2");
set(items,i++,"item3");
...Your scripts
}
void main()
{
void name;
void itemCount;
void items = array(0);

initItems(items);

itemCount = size(items);
void c = rand()%itemCount;
if(c<0)c=-c;
name = get(items,c);
//spawn name,your scripts....

}
@end_script
anim idle
Delay 100
offset 1 1
Frame none


How to use it

spawn enemy1
item itemSpawner1
at 0

 
Thank you, Volcanic for reply ;) But as i say setting itemspawner to each enemy in level#.txt is not suitable for me (it will be one additional line for each enemy).
But anyway, i solve random item drop with Bloodbanes script from Crime Buster, but edit it a little. Here it is:

void Ri(float fX, float fY, float fZ)
{//Spawns random item from list 1 next to caller.
//
//fX: X location adjustment.
//fZ: Y location adjustment.
//fY: Z location adjustment.

void self = getlocalvar("self"); //Get calling entity.
void vSpawn; //Spawn object.
void vName; //Spawn object's name.
        int  iR = rand()%10 + 10;

    if (iR >= 0 && iR < 5){
        vName = "Apple";
      } else if (iR >= 5 && iR < 10){
        vName = "Money";
      } else if (iR >= 10 && iR < 15){
        vName = "Diamond";
      } else if (iR >= 15 && iR < 20){
        vName = "Gold";
      }

clearspawnentry(); //Clear current spawn entry.
    setspawnentry("name", vName); //Acquire spawn entity by name.

      fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
      fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
      fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.

vSpawn = spawn(); //Spawn in entity.

changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.

return vSpawn; //Return spawn.
}

And it is work fine.

But here is another problem i am stuck with.

I cant spawn or summon anything in enemy`s death animation.

First i tied to make it with subentity

anim death
loop 0
subentity expl
summonframe 0 1 2 0 0
delay 30
offset 145 170
frame data/chars/misc/car1a.gif
delay 20
offset 147 173
frame data/chars/misc/car1.gif
delay 60
offset 145 170
frame data/chars/misc/car1a.gif
delay 20
offset 147 173
frame data/chars/misc/car1.gif
delay 10
offset 120 182
frame data/chars/misc/car.gif

It is strange but this isnt working in my mod, i tried to spawn explosion in the death animation, second form of boss, decoration after death, and tied it with spawn01 script, summonentity, castentity.. all of these doesnt work  only in death animation. If i declare all of those in any other animation it works fine, but not in death anim.

I use the latest build.

name rob
type enemy
health 40
speed 17
gfxshadow 1
nodieblink 1

icon data/chars/rob/i40.gif
diesound data/sounds/MalDeath2.wav

antigravity -40

grabdistance 45

candamage obstacle player npc
projectilehit obstacle enemy npc

aggression 300

throw 7 5

#aimove chasex

globalmap 0

animationscript data/scripts/slambb.c

alternatepal data/chars/rob/p/B1.gif
alternatepal data/chars/rob/p/B2.gif
alternatepal data/chars/rob/p/B3.gif
alternatepal data/chars/rob/p/B4.gif
alternatepal data/chars/rob/p/B5.gif

palette data/chars/rob/103.gif

score 300 4

load ExpL
load Flask


anim death
subentity expl
summonframe 1 1 2 0 0
loop 0
offset 290 275
        bbox 264 53 53 224
delay  10
        frame data/chars/rob/w/103.gif
@cmd tosser "Flask" 110 160 0 2 4 0
@cmd    spawn01 "ExpL" 180 1 1
        frame data/chars/rob/w/103.gif
@cmd RSpawn 1 100 1
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif
        frame data/chars/rob/w/103.gif

As you see, i used 4 methods of spawn in death anim, but no one works, enemy just blink as always after fall and disappears. I saw that was a method by utunnels, to set a spawned entity to an obstacle or npc, but i think it will cause the wrong enemy counting in groups. How to properly spawn anything i want during death animation? What is the problem?

And 2nd question is about random palette of spawning enemy:

Here is the script i get by modifying random item drop script:

void main() {
void self = getlocalvar("self"); //Get calling entity.
void  iMap;
      int  iR = rand()%5 + 5;

    if (iR >= 0 && iR < 2){
        iMap == 1;
      } else if (iR >= 2 && iR < 4){
        iMap == 2;
      } else if (iR >= 4 && iR < 6){
        iMap == 3;
      } else if (iR >= 6 && iR < 8){
        iMap == 4;
      } else if (iR >= 8 && iR < 10){
        iMap == 5;
      }

changeentityproperty(self, "map", iMap); //Set map.
}

And here is the enemy`s header:

name Galsia
type enemy
health 40
speed 25
gfxshadow 1
nodieblink 1

#-----MAP
onspawnscript data/scripts/map5.c
#-----MAP


icon data/chars/Galsia/i40.gif
diesound data/sounds/MalDeath1.wav

grabdistance 45

candamage obstacle player npc
projectilehit obstacle enemy npc

aggression 300

throw 7 5

#aimove chasex

globalmap 0

alternatepal data/chars/Galsia/p/B1.gif
alternatepal data/chars/Galsia/p/B2.gif
alternatepal data/chars/Galsia/p/B3.gif
alternatepal data/chars/Galsia/p/B4.gif
alternatepal data/chars/Galsia/p/B5.gif

palette data/chars/Galsia/p/B1.gif

But it doesnt work. I read a manual and think that "map" variable is recognize only alternate maps defined with remap. And change header to this:

name Galsia
type enemy
health 40
speed 25
gfxshadow 1
nodieblink 1

#-----MAP
onspawnscript data/scripts/map5.c
#-----MAP


icon data/chars/Galsia/i40.gif
diesound data/sounds/MalDeath1.wav

grabdistance 45

candamage obstacle player npc
projectilehit obstacle enemy npc

aggression 300

throw 7 5

#aimove chasex

globalmap 0

remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B1.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B2.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B3.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B4.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B5.gif

But it still doesnt work. I think the problem is in 16bit mode. 8bit mode works with remaps, 16bit mode works woth alternatepals, but last is not recognized by script as map (instead of remap). Is there a solution for this?
 
For random remaps, I use this script:

@script
if(frame == 0){
void self = getlocalvar("self");
int map = rand()%5;
if(map < 0)
{
-map == map;
}
changeentityproperty(self, "map", map);
}
@end_script

Put it in anim spawn. And yes, it does work in 16-bit.
 
  if (iR >= 0 && iR < 5){
        vName = "Apple";
      } else if (iR >= 5 && iR < 10){
        vName = "Money";
      } else if (iR >= 10 && iR < 15){
        vName = "Diamond";
      } else if (iR >= 15 && iR < 20){
        vName = "Gold";
      }

This could be done using Switch, no?
 
For random remaps, I use this script:

NickyP, i have tried it, and it have no effect. All enemies have same palette - the first one (default). Here is the code:

name Galsia
type enemy
health 40
speed 25
gfxshadow 1
nodieblink 1

#-----MAP
#onspawnscript data/scripts/map5.c
#-----MAP


icon data/chars/Galsia/i40.gif
diesound data/sounds/MalDeath1.wav

grabdistance 45

candamage obstacle player npc
projectilehit obstacle enemy npc

aggression 300

throw 7 5

#aimove chasex

globalmap 0

remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B1.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B2.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B3.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B4.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B5.gif

anim spawn
@script
  if(frame == 0){
  void self = getlocalvar("self");
  int map = rand()%5;
  if(map < 0)
  {
  -map == map;
  }
  changeentityproperty(self, "map", map);
  }
  @end_script
loop 0
offset 285 285
        delay 9
        frame data/chars/Galsia/sp1.gif
        frame data/chars/Galsia/sp2.gif
        frame data/chars/Galsia/sp3.gif

And is it possible to make it with alternatepal using?

if (iR >= 0 && iR < 5){
        vName = "Apple";
      } else if (iR >= 5 && iR < 10){
        vName = "Money";
      } else if (iR >= 10 && iR < 15){
        vName = "Diamond";
      } else if (iR >= 15 && iR < 20){
        vName = "Gold";
      }

This could be done using Switch, no?

O Ilusionista, can you explain, i dont understand?

Maybe you guys also know what to make with spawn on death problem?
 
About unable to spawn on DEATH, have you tried using a slightly older build? see if the problem still there.

And about maps, before we talk about this script, can you set Galsia to use any of those maps in game? with map command that is.
 
before we talk about this script, can you set Galsia to use any of those maps in game? with map command that is.

Map command works only with alternatepals, like this:

alternatepal data/chars/Galsia/p/B1.gif
alternatepal data/chars/Galsia/p/B2.gif
alternatepal data/chars/Galsia/p/B3.gif
alternatepal data/chars/Galsia/p/B4.gif
alternatepal data/chars/Galsia/p/B5.gif

If i assign maps with remaps like this:

remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B1.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B2.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B3.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B4.gif
remap data/chars/Galsia/p/B1.gif data/chars/Galsia/p/B5.gif

there is no effect, Galsias appear with same default palette.

About unable to spawn on DEATH, have you tried using a slightly older build? see if the problem still there.

I have tried 3 different older build but the result is same, nothing spawns on death animation. :'(
 
magggas, thank you!!) That`s it) There was no falldie, so according to manual it was 0 by default

0 = fall, blink on ground then disappear without playing DEATH at all (default)

Setting falldie 2 solve the problem) Thank you again)

So, a random map question is still open ???
 
hmm.. even changeentityproperty(self, "map", 3); dont assign 3d map from the list, i think that thing is in 16 bit mode. It is not reckognize remap functions
 
I have tried using level script like this:
spawn Chinese
@script
void main()
{
    void self = getlocalvar("self");
    int  iMap;
    int  iR = rand()%10 + 10;

    if (iR >= 0 && iR < 5){
      iMap = 0;
    } else if (iR >= 5 && iR < 10){
      iMap = 1;
    } else if (iR >= 10 && iR < 15){
      iMap = 2;
    } else {
      iMap = 3;
    }
    changeentityproperty(self, "map", iMap); //Set map.
}
@end_script
coords 370 475
at 5

And it works so the problem must be in Galsia's palettes.
Hmmm.... can you set Galsia to use map 3 (for instance) in level text?
 
Thank you, BB a lot :D  Comparing to yours i found a problem and it was == operator, i correct it to = and it working now.

Here is how map5.c script is looking:

void main() {
void self = getlocalvar("self"); //Get calling entity.
void  iMap;
      int  iR = rand()%5 + 5;

    if (iR >= 0 && iR < 2){
        iMap = 1;
      } else if (iR >= 2 && iR < 4){
        iMap = 2;
      } else if (iR >= 4 && iR < 6){
        iMap = 3;
      } else if (iR >= 6 && iR < 8){
        iMap = 4;
      } else if (iR >= 8 && iR < 10){
        iMap = 5;
      }

changeentityproperty(self, "map", iMap); //Set map.
}

spawned with onspawnscript data/scripts/map5.c in the enemy header.

and this is how it was:

void main() {
void self = getlocalvar("self"); //Get calling entity.
void  iMap;
      int  iR = rand()%5 + 5;

    if (iR >= 0 && iR < 2){
        iMap == 1;
      } else if (iR >= 2 && iR < 4){
        iMap == 2;
      } else if (iR >= 4 && iR < 6){
        iMap == 3;
      } else if (iR >= 6 && iR < 8){
        iMap == 4;
      } else if (iR >= 8 && iR < 10){
        iMap == 5;
      }

changeentityproperty(self, "map", iMap); //Set map.
}

Both problems are solved  8)
 
Back
Top Bottom