Aller au contenu

Photo

Activate Item on a placeable then do something [Resolved]


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Morbane

Morbane
  • Members
  • 1 883 messages
 I have a on activate script that is supposed to spawn a placeable when used on another placeable - the following code does not work :

void main()
{
     object oItem = GetObjectByTag("antipathy");	
     object oHole = GetObjectByTag("key_hole");
    if(GetItemActivated() == oItem && GetItemActivatedTarget() == oHole)
   {	
       CreateObject(OBJECT_TYPE_PLACEABLE, "true_crypt", GetLocation(GetWaypointByTag("wp_true_crypt")));	
   }
}

Any sort of help or suggestions are welcome - including script examples :innocent:

Modifié par Morbane, 24 septembre 2011 - 02:06 .


#2
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Are you creating a placeable or a waypoint?

#3
The Fred

The Fred
  • Members
  • 2 516 messages
That looks like it should work... if you have only one item, and one hole. This might not be your problem, but even if not it's better to use GetTag() to check the tag of the item instead, like so:
object oItem = GetItemActivated();
if(GetTag(oItem) == "antipathy")
{
...
}

This way you are saying, "Is the item a such-and-such" and "Is the target a hole" rather than "Is the item THIS such-and-such" etc. Otherwise it would only worked if you used the first item on the first hole. In fact, you could just use tagbased scripting for the item, so that the script only fires if it is indeed a such-and-such in the first place.

#4
Morbane

Morbane
  • Members
  • 1 883 messages
OK - this activation script is tag based - and "antipathy: is an item with a UniquePower Touch. I am trying to use it on a placeable that is tagged "key_hole" - when that happens, I would like to spawn another placeable at a waypoint.

#5
Morbane

Morbane
  • Members
  • 1 883 messages
#include "x2_inc_switches"

void main()
{
int nEvent = GetUserDefinedItemEventNumber();

// Spells might continue to their spell scripts. All other events are
// completely handled by this script.
if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT )
SetExecutedScriptReturnValue();

case X2_ITEM_EVENT_ACTIVATE:
{ // The item's CastSpell Activate or CastSpell UniquePower was just activated.
object oItemUser = GetItemActivator();
object oItem = GetItemActivated();
object oTarget = GetItemActivatedTarget();
location lTarget = (GetIsObjectValid( oTarget) ? GetLocation( oTarget) : GetItemActivatedTargetLocation());
if( !GetIsObjectValid( oItemUser) || !GetIsObjectValid( oItem))
{ SetExecutedScriptReturnValue( X2_EXECUTE_SCRIPT_CONTINUE);
return;
}

// This is where you put your Unique power activation modifications.
if(oTarget == GetObjectByTag("key_hole"))
{
CreateObject(OBJECT_TYPE_PLACEABLE, "true_crypt", lTarget);
}
}

}

That got it working - googled tag scripting