View Full Version : NPC / Mob Variable
Robregen
05-24-2011, 09:39 PM
Is there a variable that would returns the name of the npc that triggered the Event?
Like for example. If one of the guard attack a newbie mob (a large rat). Guard would say "Time to die a large rat!".
So far I haven't been able to find the right variable to script it. I thought maybe $mname would do it but instead it returns the name of the npc instead of the mob that triggered it. Something like "Time to die Guard_Soyler0001!" instead of the actual "Time to die a large rat!"
Robregen
05-24-2011, 09:50 PM
Looks like $targetname would do it. Sometime the name does not show up and sometime it shows up as a_large_rat000. Be cool if that underscore and zeros were left out. lol. I could probably try to pause the npc to give it time to target or put in $combatstate==0.
Congdar
05-24-2011, 09:52 PM
$npc->GetHateTop()->GetName();
or GetCleanName() should strip the _000
I didn't test it, but something close to this.
Robregen
05-24-2011, 10:47 PM
yeah I test it with getcleanname() and doesn't take out the _000. Perhaps I don't have it arrange in right. $targetname works half the time tho. better than none at all. quest::pause() doesn't really work. it just pause the npc after the kill.
joligario
05-25-2011, 12:26 AM
GetCleanName()
I ran into that a long time ago with $targetname, and I can't remember what my workaround was. I'll look for it again later and let you know what I did.
quest::pause()
What did you expect it to do?
Robregen
05-25-2011, 12:58 AM
I was hoping that it would pause the npc long enough to give itself some time to target the mob instead of prematurely before the quest::say.
joligario
05-25-2011, 01:56 AM
I'm not at my system to check, but I thought pause was for the grids/waypoints system. You could always use a timer to introduce a pause.
Robregen
05-25-2011, 02:17 AM
right, it is fun to learn the perl questing and to experiment with them. I managed to make the south qeynos campfire event where npcs would stand near the fire at night then make it move during the day. So livelike, I'm loving it. Anyway if you find getcleanname() and how I would use it, that would be great. I can probably dig up something in the quests folder to see if I can find something.
Robregen
05-25-2011, 02:54 PM
Hmm I haven't had much luck with this kind of coding. Any thing wrong with this code? Guard doesn't say anything at all when in combat.
sub EVENT_COMBAT {
if($combat_state == 1){
my $cur_target = $npc->GetHateTop()->GetTarget();
if($cur_target) {
my $target_name = $cur_target->GetCleanName();
quest::say("Time to die $target_name!");
}
}
}
Congdar
05-25-2011, 03:17 PM
my $cur_target = $npc->GetHateTop();
should be good enough. If you then do GetTarget() it probly just goes points back to npc.
Robregen
05-25-2011, 03:26 PM
wow, that works like a charm. this code works like it should for those that had trouble:
sub EVENT_COMBAT {
if($combat_state == 1){
my $cur_target = $npc->GetHateTop();
if($cur_target) {
my $target_name = $cur_target->GetCleanName();
quest::say("Time to die $target_name!");
}
}
}
Thanks Congdar!!!
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.