Solved Entity that spawns text when touched

Question that is answered or resolved.

kimono

Well-known member
Hi, I wish to create an object that spawns a text when the player is near it.
Anyone has created something that is similar? Thank you :)
 
I remember destination text showing when player is close from D&D : Rise of Warduke when I read that thread. Map demo also has similar feature.

However, later on I remembered that Cherry On Top has similar feature. When Cherro walks close to a PayApple, its price will appear showing how many coins player must pay there. Go to 2:53 to see one:

Which one do you want here :) ?
 
I wish to make something like this: the text appears when the player is near the object.
SFhKE38.png

Bloodbane: The text appearing in Map9 Demo is perfect :D.
 
Thanks  :)

Rise of Warduke and Map demo use sprites as destination names. These names simply hide when player is far and appear when player is close enough.

Price tag in PayApple comes from script.

For such text, destination names from Map demo can do the job. You might need to adjust its range to get desired range.
[Days later]

Okay, I better post how those names work. Here's QuestName from Map Demo:
Code:
name    	QuestName
type    	none
setlayer   	3
facing		1
palette		none
animationscript	data/scripts/marker.c


anim idle
@script
    void self = getlocalvar("self");
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");

    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    char Name = getentityproperty(self,"name");
    float Tx1 = getentityproperty(P1, "x");
    float Tz1 = getentityproperty(P1, "z");
    float Tx2 = getentityproperty(P2, "x");
    float Tz2 = getentityproperty(P2, "z");

    float Disx1 = Tx1 - x;
    float Disz1 = Tz1 - z;
    float Disx2 = Tx2 - x;
    float Disz2 = Tz2 - z;

    if(frame >= 1){
      if((Disx1*Disx1 + Disz1*Disz1 <= 900) || (Disx2*Disx2 + Disz2*Disz2 <= 900)){
        if(Name == "Forest1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
        } else if(Name == "Forest2"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
        } else if(Name == "Forest3"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW3"));
        } else if(Name == "Gunung1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW4"));
        } else if(Name == "Room1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW5"));
        } else if(Name == "Tavern1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW6"));
        } else if(Name == "Bridge1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW7"));
        } else if(Name == "Plains1"){
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW8"));
        }
      }
    }
@end_script
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif

anim follow1
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/forest1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/forest1.gif

anim follow2
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/forest2.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/forest2.gif

anim follow3
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/forest3.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/forest3.gif

anim follow4
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/gunung1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/gunung1.gif

anim follow5
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/room1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/room1.gif

anim follow6
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/tavern1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/tavern1.gif

anim follow7
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/bridge1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/bridge1.gif

anim follow8
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/names/plains1.gif
	@cmd	dename 30 30
	frame	data/chars/misc/names/plains1.gif

This dename function:
Code:
void dename(int Rx, int Rz)
{ // cancels showing name
    void self = getlocalvar("self");
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");

    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float Tx1 = getentityproperty(P1, "x");
    float Tz1 = getentityproperty(P1, "z");
    float Tx2 = getentityproperty(P2, "x");
    float Tz2 = getentityproperty(P2, "z");

    float Disx1 = Tx1 - x;
    float Disz1 = Tz1 - z;
    float Disx2 = Tx2 - x;
    float Disz2 = Tz2 - z;

    if(Disx1 < 0){
      Disx1 = -Disx1;
    } else if(Disx1 == NULL()){
      Disx1 = 200;
    }

    if(Disx2 < 0){
      Disx2 = -Disx2;
    } else if(Disx2 == NULL()){
      Disx2 = 200;
    }

    if(Disz1 < 0){
      Disz1 = -Disz1;
    } else if(Disz1 == NULL()){
      Disz1 = 200;
    }

    if(Disz2 < 0){
      Disz2 = -Disz2;
    } else if(Disz2 == NULL()){
      Disz2 = 200;
    } 

    if((Disx1*Disx1 + Disz1*Disz1 > Rx*Rx) && (Disx2*Disx2 + Disz2*Disz2 > Rx*Rx)){
      setidle(self, openborconstant("ANI_IDLE"));
    }
}

When player is close to Questname, it will change animation to reveal which name it is showing. If player walks away after that, dename function will revert Questname back to IDLE. Or IOW it cancels showing name.

Note: Rz parameter is redundant
 
For kimono's request, it requires different approach since the dialogue moves together with screen unlike questname who stays still on its coords.
The simplest way is to use different entity for the dialogue and have questname spawns and removes the former.

Here's dialoger, alternate version of questname:
Code:
name    	Dialoger
type    	none
facing		1
palette		none
animationscript	data/scripts/animation/marker.c
load		VampDial
load		MumDial


anim	idle
@script
    void self = getlocalvar("self");
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");
    int Range = 100;

    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    char Name = getentityproperty(self,"name");
    float Tx1 = getentityproperty(P1, "x");
    float Tz1 = getentityproperty(P1, "z");
    float Tx2 = getentityproperty(P2, "x");
    float Tz2 = getentityproperty(P2, "z");

    float Disx1 = Tx1 - x;
    float Disz1 = Tz1 - z;
    float Disx2 = Tx2 - x;
    float Disz2 = Tz2 - z;

    if(frame >= 1){
      if((Disx1*Disx1 + Disz1*Disz1 <= Range*Range) || (Disx2*Disx2 + Disz2*Disz2 <= Range*Range)){
        if(Name == "Vampire"){
          void Dialg = spawn06("VampDial", 240, 0, 204);

          setentityvar(self, 1, Dialg);
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
        } else if(Name == "Mummy"){
          void Dialg = spawn06("MumDial", 240, 0, 204);

          setentityvar(self, 1, Dialg);
          changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
        }
      }
    }
@end_script
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif

anim	follow1
	loop	1
	delay	5
	offset	240 120
	frame	data/chars/misc/empty.gif
	@cmd	dename 100
	frame	data/chars/misc/empty.gif

Unlike questname, a dialogue is spawned before changing into FOLLOW1 animation. Spawned dialogue is stored in entity variable.
dename function is modified into this:
Code:
void dename(int Rx)
{ // cancels showing name
    void self = getlocalvar("self");
    void P1 = getplayerproperty(0, "entity");
    void P2 = getplayerproperty(1, "entity");

    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    float Tx1 = getentityproperty(P1, "x");
    float Tz1 = getentityproperty(P1, "z");
    float Tx2 = getentityproperty(P2, "x");
    float Tz2 = getentityproperty(P2, "z");

    float Disx1 = Tx1 - x;
    float Disz1 = Tz1 - z;
    float Disx2 = Tx2 - x;
    float Disz2 = Tz2 - z;

    if(Disx1 < 0){
      Disx1 = -Disx1;
    } else if(Disx1 == NULL()){
      Disx1 = 200;
    }

    if(Disx2 < 0){
      Disx2 = -Disx2;
    } else if(Disx2 == NULL()){
      Disx2 = 200;
    }

    if(Disz1 < 0){
      Disz1 = -Disz1;
    } else if(Disz1 == NULL()){
      Disz1 = 200;
    }

    if(Disz2 < 0){
      Disz2 = -Disz2;
    } else if(Disz2 == NULL()){
      Disz2 = 200;
    } 

    if((Disx1*Disx1 + Disz1*Disz1 > Rx*Rx) && (Disx2*Disx2 + Disz2*Disz2 > Rx*Rx)){
      void Dial = getentityvar(self, 1);

      if(Dial){
        killentity(Dial);
      }
      setidle(self, openborconstant("ANI_IDLE"));
    }
}

This one removes spawned dialogue before reverting to IDLE animation.
 
Bloodbane: Your dialog spawn script is excellent! I set to 60 pixels distance here. This is great that this dialog spawn doesn't break the fight, we can continue to move and the dialog disappears when the player is far away. Simply perfect ;)

Maybye, with some creativity, this script may have other use for spawning some entities according to the player distance.
 
Back
Top Bottom