Page 1 of 1

Some help please

Posted: Tue Jul 06, 2004 5:48 am
by Galbuu

Code: Select all

function onUse(pUser, iUsed)
{
pUser.CustomTarget(0, "Who do you wish to execute?");
}

function onCallback0(pUser, myTarget)
{
	if(myTarget.x == iUsed.x && pUser.y == iUsed.y -1)
	{
	myTarget.direction = 8;
	myTarget.DoAction(0x11);
	myTarget.StartTimer(1500, 0, true);
	}
}

function onTimer(myTarget, timerID)
{
	if(timerID == 0)
	{
	myTarget.health -= 150;
	}
}
When I use this script I get an error saying iUsed is not defined. My question is how do I define iUsed as the same item in the onUse function?

Posted: Tue Jul 06, 2004 5:04 pm
by Xuri
The simple way:

Save the coordinates of the guillotine as custom tags on the character that uses the guillotine, then retrieve the tags again in the onCallBack-function.

The hard way:

Save the item-serial of the guillotine as custom tags on the character that uses the guillotine, then retrieve the serials and calculate the item-object from the serials in the onCallBack-function.
Example:

Code: Select all

pUser.SetTag( "guillotineserial1", pItem.GetSerial(1) ); 
pUser.SetTag( "guillotineserial2", pItem.GetSerial(2) ); 
pUser.SetTag( "guillotineserial3", pItem.GetSerial(3) ); 
pUser.SetTag( "guillotineserial4", pItem.GetSerial(4) ); 
then to retrieve it again:

Code: Select all

var Guillotine = CalcItemFromSer( pUser.GetTag( "guillotineserial1"), pUser.GetTag( "guillotineserial2"), pUser.GetTag( "guillotineserial3"),  pUser.GetTag( "guillotineserial4"));

Posted: Tue Jul 06, 2004 5:14 pm
by Galbuu
Now I get:

pUser.GetTag is not a function

Code: Select all

function onUse(pUser, iUsed)
{
pUser.CustomTarget(0, "Who do you wish to execute?");
pUser.SetTag("gx", iUsed.x);
pUser.SetTag("gy", iUsed.y);
}

function onCallback0(pUser, myTarget)
{

	if(myTarget.x == pUser.GetTag("gx") && pUser.y == pUser.GetTag("gy") -1)
	{
	myTarget.direction = 8;
	myTarget.DoAction(0x11);
	myTarget.StartTimer(1500, 0, true);
	}
}

function onTimer(myTarget, timerID)
{
	if(timerID == 0)
	{
	myTarget.health -= 150;
	}
}

Posted: Tue Jul 06, 2004 7:36 pm
by Xuri
onCallback uses "socket" and "target" as arguments.
i.e:

Code: Select all

function onCallback0( pSock, myTarget )
Then retrieve the character object from the socket like this:

Code: Select all

var puser = pSock.currentChar;