Jump to content

Scripting help to identify creature by name


Sam.

Recommended Posts

So I have very little scripting experience, but I want to add a block to my character's script that will cause him to attack every creature with a specified name that he sees. Let's use "Squirrel" as an example. I thought this would be it, but it doesn't work. I assume I'm failing to grasp something fundamental here...

IF
	CharName("Squirrel",LastSeenBy(Myself))
THEN
	RESPONSE #100
		Attack(LastSeenBy(Myself))
END

What's the right way to approach this problem?

Link to comment

Try Name(S:Name*,O:Object*) instead. "S:Name*" is the script name of the creature, so it probably doesn't work correctly on creatures without a script name (as in the case of the squirrel).

First in your tp2 (only if the cre does not yet have a script name at offset 280, like e.g squirrel)

 

COPY_EXISTING ~squirr.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

COPY_EXISTING ~squirl.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

And in your script

 

IF

See("Squirrel")

HPGT("Squirrel",0)

THEN

RESPONSE #100

Attack("Squirrel")

END

Link to comment

 

Try Name(S:Name*,O:Object*) instead. "S:Name*" is the script name of the creature, so it probably doesn't work correctly on creatures without a script name (as in the case of the squirrel).

First in your tp2 (only if the cre does not yet have a script name at offset 280, like e.g squirrel)

 

COPY_EXISTING ~squirr.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

COPY_EXISTING ~squirl.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

And in your script

 

IF

See("Squirrel")

HPGT("Squirrel",0)

THEN

RESPONSE #100

Attack("Squirrel")

END

 

Thank you both. This method worked well enough, but I did have to modify the CRE files to add the Script Name. I was hoping not to have to modify other files to get this to work. Is it not possible to use the creature's actual name instead of the script name?

Link to comment

 

 

Try Name(S:Name*,O:Object*) instead. "S:Name*" is the script name of the creature, so it probably doesn't work correctly on creatures without a script name (as in the case of the squirrel).

First in your tp2 (only if the cre does not yet have a script name at offset 280, like e.g squirrel)

 

COPY_EXISTING ~squirr.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

COPY_EXISTING ~squirl.cre~ ~override~

WRITE_ASCII 0x280 ~Squirrel~

 

And in your script

 

IF

See("Squirrel")

HPGT("Squirrel",0)

THEN

RESPONSE #100

Attack("Squirrel")

END

 

Thank you both. This method worked well enough, but I did have to modify the CRE files to add the Script Name. I was hoping not to have to modify other files to get this to work. Is it not possible to use the creature's actual name instead of the script name?

 

Not for this purpose where the target is *object* as Argent77 stated earlier.

Quote *An object parameter is a special case - it can be either a literal string (a death variable, such as "Gnoll3"), a object reference (e.g. Player1) or an object identifier. An object identifier can apply to a whole group/category of creatures. The format is [EA.FACTION.TEAM.GENERAL.RACE.CLASS.SPECIFIC.GENDER.ALIGNMNT.SUBRACE.AVCLASS.CLASSMSK], though some engines do not accept the faction and team specifiers. Each field within the identifier is from the associated IDS file.*

 

Squirrel is an odd case, most creatures have an identifier of one type or another.

 

I have to say I use DV's for my scripts quite often and I assign them to creatures that do not have one - if I do, I try to be very careful not to come up with something odd but simply use cre-filename = script name. I have not run into trouble with this approach so far. So in case of squirrels (if you really intend to use this) you would need to extend DV assignment and script a bit as there are more than one squirrel cretures in the game.

Link to comment

argent's touched on it a couple of times, but using objects effectively is really going to be the way to go for targeting multiple creatures, especially if they're not unique. While it's a bit dated, I still think the Ding0's scripting guide is still a good place to get started. The object type especially--the old [EA.GENERAL.RACE.CLASS.SPECIFIC.GENDER.ALIGN]--is usually the way to try and do what you're talking about.

 

Alternatively, if it really is a small handful of named/special creatures you could name them all and do blocks like

IF
  OR(3)
    Name("adam",LastSeenBy(Myself))
    Name("bob",LastSeenBy(Myself))
    Name("chuck",LastSeenBy(Myself))
  !StateCheck(LastSeenBy(Myself),STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    Attack(LastSeenBy(Myself))
END
Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...