Items thrown at random coords

kimono

Well-known member
Hi, I've got this kind of Bonus stage. I wish that each time the statue is hit, a coin is thrown at a random coords between x= 0 - 320 and z= 170 -240:
yonWmKD.png

How I can make this statue throw coins at different places each time it being hit?
Thanks for your lights :) .
 
I use the spawntoss command for the coins in the pain anim of the statue but I still don't know how I can make them throw at random across the stage:
Code:
void spawnToss(void name, float dx, float dy, float dz, float Vx, float Vy, float Vz, void ani, int atk, int setMap)
{//Spawn and Toss entity with defined conditions (DEFAULT TOSS SCRIPT USED FOR ALL SPAWNED ENTITIES, LIKE ITENS)
	void self 		= getlocalvar("self");
	void type		= getentityproperty(self, "type");
	void hostile	= getentityproperty(self, "hostile");
	void candamage	= getentityproperty(self, "candamage");
	void vSpawn 	= spawn01(name, dx, dy, dz);
	int direction 	= getentityproperty(self, "direction");
	int map 		= getentityproperty(self, "map");

	if(direction == 0){
		Vx = -Vx;//Change direction to match facing
	}
	
	tossentity(vSpawn, Vy, Vx, Vz); //Toss entity with defined speed
	
	if(ani != NULL()){ //Spawn with a specific animation??
		changeentityproperty(vSpawn, "animation", openborconstant(ani));
	}
	
	if(atk != NULL()){ //This entity is used for attacks??
		void vAniID = getentityproperty(self, "animationID");
		int disable	= getentityproperty(self, "energycost", "disable", openborconstant(vAniID));
		
		changeentityproperty(vSpawn, "parent", self);
		changeentityproperty(vSpawn, "owner", self);
		changeentityproperty(vSpawn, "hostile", hostile);
		changeentityproperty(vSpawn, "candamage", candamage);
		setglobalvar("projectile"+self, vSpawn);
		setentityvar(vSpawn, "disable", disable);
		
		if(type == openborconstant("TYPE_ENEMY")){ //Is entity a enemy type?
			changeentityproperty(vSpawn, "type", openborconstant("TYPE_SHOT"));
		}
	}

	if(setMap != NULL()){
		changeentityproperty(vSpawn, "map", map);
	}
}

Code:
name		statue
health		80
nolife		1
nomove 		1
type		enemy
speed		0
nomove 		1 1
noquake		1
gfxshadow	1	1
death		1
setlayer	99
nodieblink 	3

animationscript		data/scripts/lescript.c
alternatepal 		data/chars/obstacles/statue/alt1.gif

load 	coin

anim	spawn
	delay 2
	offset	83 176
	bbox 38 64 66 112
	platform -38 182 84 84 150 150 20 110
	frame	data/chars/obstacles/statue/statue_vibration2.png

anim	idle
	offset	83 176
	bbox 38 64 66 112
	platform -38 182 84 84 150 150 20 110
	frame	data/chars/obstacles/statue/statue_vibration2.png
	
anim	pain
	delay	4
	offset	83 176
	bbox 38 64 66 112
	platform -38 182 84 84 150 150 20 110
	frame	data/chars/obstacles/statue/statue_vibration1.png
	@cmd   spawnToss "coin" 0 35 0 1 1 0	
	frame	data/chars/obstacles/statue/statue_vibration2.png	
	frame	data/chars/obstacles/statue/statue_vibration3.png	
	
anim	death
	loop 	1 3 4
	delay 	16
	offset	147 176
	platform 38 182 84 84 150 150 20 110
	flash carglass
	frame	data/chars/obstacles/statue/statue_death1.png
	frame	data/chars/obstacles/statue/statue_death2.png	
	frame	data/chars/obstacles/statue/statue_death3.png
	frame	data/chars/obstacles/statue/statue_death3.png

The demo (bonus stage set) for testing purpose:
https://drive.google.com/file/d/1jCCZyK0VNEQs6aYtOfYRh9FuPitSPmzb/view?usp=sharing
 
i have not analized Bwwd's code for random walk speed in depth, it seems to have random values in a range, if that is true it can be adapted to work with a "pain" animation that tosses the coins.
 
I must've missed this thread.

Anyways:
kimono said:
How I can make this statue throw coins at different places each time it being hit?

Your request has two impressions for me:
1. The statue drops coins from ceiling within defined limits.
2. The statue tosses coins from itself with random directions.

Which one do you want? :)
While waiting for answer, I need to tell that in #1, you can guarantee coins not to fall outside the limits while in #2, coins might fly outside limits.
 
while in #2, coins might fly outside limits.
Bloodbane there is a way to prevent it, you can adapt this function, which chooses a random position between the screensize and MIN and MAX z positions:

Code:
void randomteleonscreen()
{// Randomly teleports onscreen

    void self = getlocalvar("self"); //Get calling entity
    int XPos = openborvariant("xpos"); //Get screen edge's position
    int Screen = openborvariant("hResolution"); // Get screen width
    int Width = openborvariant("PLAYER_MAX_Z") - openborvariant("PLAYER_MIN_Z"); // Get width
    int iRx = rand()%(Screen/2) + Screen/2 ;
    int iRz;

	if (Width>0){
    iRz = rand()%(Width/2) + Width/2 ;
	}

    changeentityproperty(self, "position", iRx + XPos, iRz + openborvariant("PLAYER_MIN_Z")); //Randomly teleport
}

And, to prevent itens being stuck on walls, I use a second function:

Code:
void antiwallRandom(int Dist)
{// Checks if there is wall at defined distance (Dist)
// If there is wall, change to random position to avoid landing on walls
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   float H;

   if (Direction == 0){ //Is entity facing left?                  
      Dist = -Dist; //Reverse Dist to match facing
   }

   H = checkwall(x+Dist,z);
   if(H > y)
   {
	randomteleonscreen();

   }
}
This is what I use on War Machine's War Destroyer hyper move.

So its just a matter to adapt the functions above.
 
Bloodbane and O'Ilusionista: thanks guys for your lights. I wish that coins are dropped randomly each time the entity is hit within the limits of the stage.
I think the solution number 2 is better, because it's too bad to lose some coins outside the limits :) .
I will try your solution O Ilusionista, but as afar as I can see, the coins will be spawned at a random position, but not dropped from the entity, am I correct?
 
I will try your solution O Ilusionista, but as afar as I can see, the coins will be spawned at a random position, but not dropped from the entity, am I correct?
Yes, the code doesn't take your entity position into account. It will get the screen resolution (width) and the MINZ/MAXZ of your stage.
Which is what you asked for here:
x= 0 - 320 and z= 170 -240:

 
I've made script for both options but for some reason the #1 is not working properly  ???.
So as requested, I'll only share #2 since it's working.
Code:
anim	pain
@script
  if(frame==1){
    int iDx = rand()%25;
    int iDz = rand()%10;

    shooter2("coin", -30, 70, 0, iDx*0.1, 2, iDz*0.1);
  }
@end_script
	delay	4
	offset	83 176
	bbox 38 64 66 112
	platform -38 182 84 84 150 150 20 110
	frame	data/chars/obstacles/statue/statue_vibration1.png
	frame	data/chars/obstacles/statue/statue_vibration2.png	
	frame	data/chars/obstacles/statue/statue_vibration3.png

You can play around with 25 and 10 in rand()%25 and rand()%10 to adjust tossing power.
However, your shooter2 function must be replaced with this one below for it to work:
Code:
void shooter2(void vName, float fX, float fY, float fZ, float Vx, float Vy, float Vz)
{//Spawns projectile next to caller
 //vName: Model name of entity to be spawned in
 //fX: X location adjustment
 //fZ: Y location adjustment
 //fY: Z location adjustment
 //Vx: X speed
 //Vy: Y speed
 //Vz: Z speed

   void self = getlocalvar("self"); //Get calling entity
   int Direction = getentityproperty(self, "direction");
   void vSpawn; //Spawn object.
	
   vSpawn = spawn01(vName, fX, fY, fZ); //Spawn in projectile
   if (Direction == 0){ //Is entity facing left?                  
      Vx = -Vx; //Reverse Vx direction to match facing
   }

   changeentityproperty(vSpawn, "velocity", Vx, Vz, Vy);
    return vSpawn;
}

HTH
 
It's amazing what you manage to make with the code, thanks for this! Do you recommend me to place some walls to prevent the coins getting offscreen or beyond the zmin and max of the stage?
I've got the same problem with the smartbomb: some coins are thrown above the zmin value of the stage and that makes believe that the coins stay in the air.
 
Well, I posted yes before but after testing it, for some reason the coins can get thrown through wall  ??? .

I've got the same problem with the smartbomb: some coins are thrown above the zmin value of the stage and that makes believe that the coins stay in the air.

What kind of smartbomb is that?
 
It's the fireflybox smartbomb item. Maybye the coins need to bounce on the walls to stay on screen.
 
Back
Top Bottom