item drop coord help

Gurtag

Active member
hey guys, is there a way to set the spawn coord of a item, like destroying an obstacle wich is supose to spawn/drop an item/entity but want it to spawn at a specific position on the map.
also could you point me to a script for random intem drop?
 
To spawn an item at specific coords, you need to use script like this:
Code:
void spawn01(void vName, float fX, float fY, float fZ)
{
	//spawn01 (Generic spawner)
	//Damon Vaughn Caskey
	//07/06/2007
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location adjustment.
	//fY: Y location adjustment.
      //fZ: Z location adjustment.

	void self = getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.
	int  iDirection = getentityproperty(self, "direction");

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

	if (iDirection == 0){ //Is entity facing left?                  
          fX = -fX; //Reverse X direction to match facing.
	}

      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.
	changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
    
	return vSpawn; //Return spawn.
}

This function will spawn entity at coords relative to spawner
If you want it to spawn at specific position on the map, you'll need to create special function like this:
Code:
void spawnAt(void Name, float dx, float dy, float dz)
{ // Spawn an entity and place it at exact coords
   void self = getlocalvar("self");
   void Spawn;

   Spawn = spawn01(Name, 0, 0, 0);
   changeentityproperty(Spawn, "position", dx, dy, dz);
}

This function will spawn entity and place it exactly at defined coords. This function calls spawn01 function above, so you must have both.

could you point me to a script for random intem drop?

Here's an example of random item drop:
Code:
name		RandItem
type		none
gfxshadow	1
lifespan	2
animationscript	data/scripts/enemy.c
load		Money
load		Meat
load		Apple


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 "Money" 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 "Apple" 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 "Meat" 0 0 0
	frame	data/chars/misc/empty.gif

All possible item drops are loaded to ensure it's loaded prior to dropping

HTH
 
thanks a lot for the random function Bloodbane, btw could you post an example of how to implement the itemspawn? or where to declare the functions? i dont want to spwan the item on a entity by default but rater using item command or script on the level

what i was thinking is something like this

spawn  obstac
item  eneheal
ITEMCOORDS/or isert script here 50  1896 1900  so when the obstacle get destroyed, spawns the item at 50  1896 1900 coords
coords  1675  1896 0
at  0
 
Unfortunately, that script is meant for the entity
AFAIK there's no way to control item dropped by killed entities in level with script

I can imagine a workaround for this but before that, what is exactly you are trying to create here?
 
use itemalias {name} when enemy spawns item
then iuse it to detect the item in its spawn animation, then change its coords.
spawn enemy
item bone
itemalias bone2
coords 200 300

Then in spawn anim detect bone2 name, and change the coords with script in spawn animation.
  int XPos = openborvariant("xpos");
iName  = getentityproperty(self, "name");

  if(iName == "bone2" && Frame == 1 ){




    changeentityproperty(self, "position", 444 - XPos);


Its not entire script but parts that you need.
 
Bloodbane said:
Unfortunately, that script is meant for the entity
AFAIK there's no way to control item dropped by killed entities in level with script

I can imagine a workaround for this but before that, what is exactly you are trying to create here?

bWWd said:
use itemalias {name} when enemy spawns item
then iuse it to detect the item in its spawn animation, then change its coords.
spawn enemy
item bone
itemalias bone2
coords 200 300

Then in spawn anim detect bone2 name, and change the coords with script in spawn animation.
  int XPos = openborvariant("xpos");
iName  = getentityproperty(self, "name");

  if(iName == "bone2" && Frame == 1 ){




    changeentityproperty(self, "position", 444 - XPos);


Its not entire script but parts that you need.

thanks a lot for the suport guys, in a 2d climb level i have several obstacles that when destroyed wanted to spawn an entity at specific coordinates for endlevel purposes, after sevel test managed to achive my goals, though not exactly the way i posted here but it works nevertheless.
 
Back
Top Bottom