PDA

View Full Version : Custom 1 time NPC


Maceblade
10-31-2013, 09:29 PM
This may be an odd request, but I was looking at creating an NPC that hands out a reward to the first 10 hails and then depops forever, however I have no idea how to write it.

The only way I know how to do it is to create 10 seperate npc id's all controlled by triggers, when #1 is hailed it depops and spawns #2 etc and once #10 is hailed he depops forever. The only issue is I have no way to keep one person from doing multiple hails unless I can have it check for the item in inventory first.

I guess I was just looking to see if someone had an easier way to do this.

HnathBST
10-31-2013, 09:33 PM
This may be an odd request, but I was looking at creating an NPC that hands out a reward to the first 10 hails and then depops forever, however I have no idea how to write it.

The only way I know how to do it is to create 10 seperate npc id's all controlled by triggers, when #1 is hailed it depops and spawns #2 etc and once #10 is hailed he depops forever. The only issue is I have no way to keep one person from doing multiple hails unless I can have it check for the item in inventory first.

I guess I was just looking to see if someone had an easier way to do this.

I would say, create 1 npc. and use QGlobals to keep count of how many items he has handed out. right after he hands out his 10th item you depop him. I believe there is spawn tools in the quest perl. Though I don't know them or their syntax off the top of my head.

And, I would use an inventory check to make sure the person doesn't already have the item. I'm using QGlobals for a quest to hand out an armor package and it's a mess, I have a QGlobal for every PC that got an armor package on my server >.<

Maceblade
10-31-2013, 09:39 PM
Im weary on Qglobals bc I have yet to get it functioning with MaxCharLevel. I guess I could resort to a "flag" that would do it.

And thanks for the reply!

Kingly_Krab
10-31-2013, 09:40 PM
I have an idea, I'm going to put my server up really fast, write the code, and get back to you when I have it working or if I can't get it working.

Maceblade
10-31-2013, 09:43 PM
Thanks King! :-)

Akkadius
10-31-2013, 09:58 PM
This may be an odd request, but I was looking at creating an NPC that hands out a reward to the first 10 hails and then depops forever, however I have no idea how to write it.

The only way I know how to do it is to create 10 seperate npc id's all controlled by triggers, when #1 is hailed it depops and spawns #2 etc and once #10 is hailed he depops forever. The only issue is I have no way to keep one person from doing multiple hails unless I can have it check for the item in inventory first.

I guess I was just looking to see if someone had an easier way to do this.

Something like this should work:

sub EVENT_SAY{
if(!defined($qglobals{"TenTimeEvent"})){ $client->SetGlobal("TenTimeEvent", "10", 7, 'F'); }
my $CountToZero = (10 - $qglobals{"TenTimeEvent"});
if($text=~/hail/i){ quest::say("The fuck you want?"); $client->Message(15, quest::saylink("Make me a sammich", 1)); }
if($text=~/sammich/i){
if($qglobals{"TenTimeEvent"} > 0){
quest::say("WHAT?! Fine... But I will only do it " . $CountToZero . " more time(s)...");
$npc->SetGlobal("TenTimeEvent", ($qglobals{"TenTimeEvent"} - 1) , 7, 'F');
}else{
quest::say("Sorry man, I told you I wouldn't make you a sammich anymore...");
}
}
}

You need to have qglobals enabled on the npc (Set to 1) and it is set at a global scope, meaning any NPC can grab this qglobal variable if you tried to fetch it.

He sets it once and when the value of the qglobal has been subtracted to 0, he no longer will make a sammich :D

Maceblade
10-31-2013, 10:02 PM
haha thanks Akk I will now test out this here sammich maker!

HnathBST
10-31-2013, 10:34 PM
Something like this should work:

sub EVENT_SAY{
if(!defined($qglobals{"TenTimeEvent"})){ $client->SetGlobal("TenTimeEvent", "10", 7, 'F'); }
my $CountToZero = (10 - $qglobals{"TenTimeEvent"});
if($text=~/hail/i){ quest::say("The fuck you want?"); $client->Message(15, quest::saylink("Make me a sammich", 1)); }
if($text=~/sammich/i){
if($qglobals{"TenTimeEvent"} > 0){
quest::say("WHAT?! Fine... But I will only do it " . $CountToZero . " more time(s)...");
$npc->SetGlobal("TenTimeEvent", ($qglobals{"TenTimeEvent"} - 1) , 7, 'F');
}else{
quest::say("Sorry man, I told you I wouldn't make you a sammich anymore...");
}
}
}

You need to have qglobals enabled on the npc (Set to 1) and it is set at a global scope, meaning any NPC can grab this qglobal variable if you tried to fetch it.

He sets it once and when the value of the qglobal has been subtracted to 0, he no longer will make a sammich :D

I think you have $CountToZero incorrect. If the Qglobal is set to 10, $CountToZero = 10 - 10 = 0. So the NPC would say "I'm only doing it 0 more times". Unless my logic is wrong.

I would say:
sub EVENT_SAY{
if(!defined($qglobals{"TenTimeEvent"})){ $client->SetGlobal("TenTimeEvent", "10", 7, 'F'); }

if($text=~/hail/i){ quest::say("The fuck you want?"); $client->Message(15, quest::saylink("Make me a sammich", 1)); }
if($text=~/sammich/i){
if($qglobals{"TenTimeEvent"} > 0){
quest::say("WHAT?! Fine... But I will only do it " . ( $qglobals{"TenTimeEvent"} - 1). " more time(s)...");
$npc->SetGlobal("TenTimeEvent", ($qglobals{"TenTimeEvent"} - 1) , 7, 'F');
}else{
quest::say("Sorry man, I told you I wouldn't make you a sammich anymore...");
}
}
}

That eliminates the $CountToZero variable that was only used once for text anyway.

Maceblade
10-31-2013, 10:39 PM
H you were correct, only issue im having is that 1 person can bang out all 10 hails.

Akkadius
10-31-2013, 10:44 PM
H you were correct, only issue im having is that 1 person can bang out all 10 hails.

Mace, I came up with a quick example for you - the count part was a simple mistake because I was thinking of something different before I got to the below section (quickly) but simply illustrating what you can do.

To limit 1 per person, you have to add additional checking. In this case I would create a character scoped (Type 5) qglobal to keep folks from being able to hail more than once from their character:

sub EVENT_SAY{
if(!defined($qglobals{"TenTimeEvent"})){ $client->SetGlobal("TenTimeEvent", "10", 7, 'F'); }
my $CountToZero = ($qglobals{"TenTimeEvent"} - 1);
if($text=~/hail/i){ quest::say("The fuck you want?"); $client->Message(15, quest::saylink("Make me a sammich", 1)); }
if($text=~/sammich/i){
if($qglobals{"TenTimeEventChar"} == 1){
quest::say("You already got your reward!");
}
elsif($qglobals{"TenTimeEvent"} > 0){
quest::say("WHAT?! Fine... But I will only do it " . $CountToZero . " more time(s)...");
$npc->SetGlobal("TenTimeEvent", ($qglobals{"TenTimeEvent"} - 1) , 7, 'F');
$client->SetGlobal("TenTimeEventChar", 1 , 5, 'F');
}else{
quest::say("Sorry man, I told you I wouldn't make you a sammich anymore...");
}
}
}

I really suggest you read up on qglobals - they can be used often. :D

Maceblade
10-31-2013, 10:46 PM
I wasnt complaining at all Akk I appreciate everyones help and this is working perfectly! Thank you everyone I have soo many uses for this now with the reroll :-)

Kingly_Krab
10-31-2013, 10:47 PM
Here, Entity Variables work just as well, make sure to set the NPC's qglobal to 1!

EDIT: Entity Variables reset upon #repop of the NPC.
sub EVENT_SAY
{
if(!defined $qglobals{Won})
{
if($npc->GetEntityVariable("HailTest") >= 1 && $npc->GetEntityVariable("HailTest") <= 9)
{
if($text=~/Hail/i)
{
$npc->SetEntityVariable("HailTest", ($npc->GetEntityVariable("HailTest") + 1));
quest::shout2("$name has hailed me, " . (10 - $npc->GetEntityVariable("HailTest")) . " more people can win!");
quest::setglobal("Won", 1, 5, "F");
#quest::givecash(Copper, Silver, Gold, Platinum);
#quest::summonitem(1001, 1);
}
}
elsif(!$npc->GetEntityVariable("HailTest"))
{
if($text=~/Hail/i)
{
$npc->SetEntityVariable("HailTest", 1);
quest::shout2("$name has hailed me, " . (10 - $npc->GetEntityVariable("HailTest")) . " more people can win!");
quest::setglobal("Won", 1, 5, "F");
#quest::givecash(Copper, Silver, Gold, Platinum);
#quest::summonitem(1001, 1);
}
}
elsif($npc->GetEntityVariable("HailTest") > 9)
{
if($text=~/Hail/i)
{
$npc->Depop();
}
}
}
else
{
if($text=~/Hail/i)
{
plugin::Whisper("You may only win once!");
}
}
}

Akkadius
10-31-2013, 10:51 PM
Entity Variables don't persist beyond repop or zone, have to use something more persistent.

Kingly_Krab
10-31-2013, 10:53 PM
Entity Variables don't persist beyond repop or zone, have to use something more persistent.
The NPC cannot zone, but it can be repopped, I edited that in to my post.

EDIT: He could just set the NPC's respawn time to like 30 days or something so he could have time to delete it after the event ends.