Page 1 of 1

Releasing a Totem

Posted: Fri Apr 06, 2012 6:05 pm
by gundamwing84
Hey guys, i was wondering how i would set this script so that when you release a totem, it returns to your backpack, rather than just dropping to the floor where it was?

here is the if statement for it

Code: Select all

	if (totem)
		set_critical (1);
		var it := CreateItemAtLocation (me.x, me.y, me.z, totem, 1, me.realm);
		if (!it)
			say ("*Argh*");
			set_critical (0);
			return;
		endif

		it.decayat := 0;
		it.movable := 1;
		it.name := me.name;
		it.usescript := ":dundee:totem";
		it.color := CINT (GetObjProperty (me, "totemcolor"));
		SetObjProperty (it, "critter", me.npctemplate);
		if (GetObjProperty (it, "color"))
			SetObjProperty (it, "critcolor", GetObjProperty (it, "color"));
		else
			SetObjProperty (it, "critcolor", me.color);
		endif
		SetObjProperty (it, "critgraphic", me.graphic);
		SetObjProperty (it, "totemhp", CINT (GetVital (me, "Life")/100));

		if (GetObjProperty (me, "ownerserial"))
			SetObjProperty (it, "ownerserial", GetObjProperty (me, "ownerserial"));
			SetObjProperty (it, "ownername", GetObjProperty (me, "ownername"));
			SetObjProperty (it, "oldname", GetObjProperty (me, "oldname"));
		endif

		Drop ();
		PlaySoundEffect (me, SFX_SPELL_DISPEL);
		PlayStationaryEffect (me.x, me.y, me.z, FX_SMOKE, 0xA, 0xA, 0, me.realm);
		KillMe ();
		set_critical(0);
		return;
	endif
any help is appreciated :)

Re: Releasing a Totem

Posted: Fri Apr 06, 2012 6:19 pm
by mr bubbles
Try changing this line

Code: Select all

 var it := CreateItemAtLocation (me.x, me.y, me.z, totem, 1, me.realm);
to

Code: Select all

// As im not sure if the owner is declared earlier in your script
var owner := SystemFindObjectBySerial( GetObjProperty (me, "ownerserial"));
var it := CreateItemInBackpack( owner, totem, 1 );

Re: Releasing a Totem

Posted: Fri Apr 06, 2012 7:36 pm
by gundamwing84
ok when saying "release" the totems just go onto "say ("*Argh*");", they dont return to my backpack :( im not sure whats causing that :s

Code: Select all

	if (totem)
		set_critical (1);
		// As im not sure if the owner is declared earlier in your script
		var owner := SystemFindObjectBySerial( GetObjProperty (me, "ownerserial"));
		var it := CreateItemInBackpack( owner, totem, 1 );
		if (!it)
			say ("*Argh*");
			set_critical (0);
			return;
		endif

Re: Releasing a Totem

Posted: Fri Apr 06, 2012 7:46 pm
by mr bubbles
gundamwing84 wrote:ok when saying "release" the totems just go onto "say ("*Argh*");", they dont return to my backpack im not sure whats causing that :s
Means 'it' isnt being created successfully. Most Probably because 'owner' can't be found.

Does the totem have the "ownerserial" on it? If so then maybe you have to do

var owner := SystemFindObjectBySerial( CInt(GetObjProperty (me, "ownerserial")));

If that fails then add some Print() to see what's happening. I would do it like this

Code: Select all

// As im not sure if the owner is declared earlier in your script
Print("ownerserial : "+GetObjProperty (me, "ownerserial"));
var owner := SystemFindObjectBySerial( GetObjProperty (me, "ownerserial"));
Print("owner ref : "+owner);
var it := CreateItemInBackpack( owner, totem, 1 );
Print("it ref : "+it);

Re: Releasing a Totem

Posted: Fri Apr 06, 2012 8:32 pm
by Agata
ownerserial is for .own'ed items. You need the master property

Code: Select all

if (totem)
      set_critical (1);
      // As im not sure if the owner is declared earlier in your script
      var owner := SystemFindObjectBySerial( GetObjProperty (me, "master"));
      var it := CreateItemInBackpack( owner, totem, 1 );
      if (!it)
         say ("*Argh*");
         set_critical (0);
         return;
      endif

Re: Releasing a Totem

Posted: Fri Apr 06, 2012 8:46 pm
by gundamwing84
Thankyou very much agata that done the trick! thanks to both of you for all the help, much appreciated :)