Log in

View Full Version : npc finds player and gives an item?


spider661
12-22-2008, 12:00 AM
i made a new spell that spawns a pet. not i wish to get the owner of that pet have the npc give the owner a random item then kill off the pet. how would i do that?

i know to kill the pet i make the owner cast reclaim energy.
i know how to pick a random item

what i dont know is how to get the pets owner and then make them call the script parts related to the client.

this is what im working with so far.


sub EVENT_SPAWN
{
quest::say("im up.");
$target = $npc->GetOwnerID();
$clientwho = $EntityList->GetClientByID($target);
$clientset->SummonItem(1333);
}


of course this don't work and its pissing me off been working on this for hours.. anyone go a clue on how to do this or a diff way to do it even?

what im trying to do is have a gift time when someone cast the spell on it it summons a invis pet (so he can run a script) gives a random item then despawns.. it dont even have to be a pet actually i would prefer that but i figure its easyer to get the pet owner then the person that caster the spell.

trevius
12-22-2008, 01:04 AM
Whenever I am trying anything new like that, I always test it by setting quest::say to report what the quest is actually getting. So, when you get the owner ID, I would add a quest::say after that to see exactly what ID it is getting, if any:

sub EVENT_SPAWN {
quest::say("im up.");
$target = $npc->GetOwnerID();
quest::say("My owner's ID is $target");
}

And then, if it returned nothing, then most likely the object isn't being used properly. If something is returned, then you need to know what kind of ID it is getting. Most likely it is getting the character's entity ID, which would be something like 222 (and can be verified by doing a #showstats on yourself). It could also be getting the character, which is a string of characters more like EBDSX=11ASDF13 or something (completely made that up). In this case, it should be getting the entity ID. So, now we need to get the client using that entity ID. Here is how to do that:

sub EVENT_SPAWN {
quest::say("im up.");
$target = $npc->GetOwnerID();
quest::say("My owner's ID is $target");
$getclient = $entity_list->GetClientByID($target);
quest::say("I got client $getclient");
}

Using says after each step will show where the script is failing, if it is. Next, you should be able to summon the item for them:

sub EVENT_SPAWN {
quest::say("im up.");
$target = $npc->GetOwnerID();
quest::say("My owner's ID is $target");
$getclient = $entity_list->GetClientByID($target);
quest::say("I got client $getclient");
$getclient->SummonItem(1333, 1);
quest::say("All Done");
}

That is basically the same thing you have already done, but it explains the steps of how I would do it and I think corrects a couple of mistakes in the script you posted.

If that doesn't work, you might be able to use something like this:

sub EVENT_SPAWN {
quest::say("im up.");
$target = $npc->GetOwnerName();
quest::say("My owner's name is $target");
$npc->SetTarget($target);
quest::say("Target has been set to $target");
quest::summonitem(1333);
quest::say("All Done");
}

Let me know if none of that helps. We can probably think of some way to do it. I am not at home atm, so I can't test any of it for you.

spider661
12-23-2008, 05:24 AM
thanks the first one worked..
ps.
the sec one did not work but its all good.