PDA

View Full Version : Can you make a custom local type variable for quests?


Bellos
08-05-2010, 03:43 PM
Say kills or somthing and then once it hits 4 have an npc spawn.

if some can someone tell me how you define variables in perl?


How does this look?


$orcmysticsdead = 0;

sub EVENT_DEATH {
$orcmysticsdead = $orcmysticsdead + 1

if ($orcmysticsdead = 4){
quest::unique_spawn(999149,0,0,1652,1535,-9,heading=69)
}
}



is that the correct usage of

quest::unique_spawn(npc_type,grid,guildwarset,x,y, z,heading=0)

joligario
08-05-2010, 05:34 PM
The only way that counter would work is if there are several of those NPCs spawned already and no new NPCs of the same version spawn in between kills. If that is the case, then yes, the variable declaration is correct. Otherwise it seems you might be better off using quest globals. Also, the spawn definition is incorrect. The reason it says heading=0 is to let you either use a number or use nothing at all which will default to 0. And don't forget your condition check and semicolons..

$orcmysticsdead = $orcmysticsdead + 1;

if ($orcmysticsdead == 4){

quest::unique_spawn(999149,0,0,1652,1535,-9,69);

FYI: I am just basing off your script, not your title. The title asked for local variables. Remember, that local means only in your scope. This method "bleeds" over multiple scripts making it more global. Not the preferred method, but it can work.

Bellos
08-05-2010, 05:34 PM
Ok it works if i just use

sub EVENT_DEATH {

quest::spawn2(999147,0,0,1652,1535,-9,69)

}




ahh ok i have my orcs respawning fast for testing purposes. Thats probably why. Hmmm im not too firmiliar with qglobals. I guess ill have to try that

Bellos
08-05-2010, 05:40 PM
The only way that counter would work is if there are several of those NPCs spawned already and no new NPCs of the same version spawn in between kills. If that is the case, then yes, the variable declaration is correct. Otherwise it seems you might be better off using quest globals. Also, the spawn definition is incorrect. The reason it says heading=0 is to let you either use a number or use nothing at all which will default to 0. And don't forget your condition check and semicolons..

$orcmysticsdead = $orcmysticsdead + 1;

if ($orcmysticsdead == 4){

quest::unique_spawn(999149,0,0,1652,1535,-9,69);

FYI: I am just basing off your script, not your title. The title asked for local variables. Remember, that local means only in your scope. This method "bleeds" over multiple scripts making it more global. Not the preferred method, but it can work.

how do i make it local?

joligario
08-05-2010, 05:40 PM
Oh, it also seems I was editing my post while you were replying. Don't forget to check the update above.

EDIT: To make it local, you declare it in the scope you want to use it. To make it private, add the "my" identifier.

sub whatever {
my $localvariable = 0;

$localvariable = 25;
}

Using it that way makes a variable available to only this sub. Looking at what you are doing above, you do not want a local variable.

Bellos
08-05-2010, 05:45 PM
Oh, it also seems I was editing my post while you were replying. Don't forget to check the update above.

EDIT: To make it local, you declare it in the scope you want to use it. To make it private, add the "my" identifier.

sub whatever {
my $localvariable = 0;

$localvariable = 25;
}

Using it that way makes a variable available to only this sub. Looking at what you are doing above, you do not want a local variable.

oh ok

yeah i know declaring in the sub would reset it when the events triggered. I dunno it seems kind of buggy the way im doing it. I mean id need it to trigger correctly for each player. I think that means i have to do q globals right?

I tried that once and gave up cause i could never make it work lol.

joligario
08-05-2010, 05:48 PM
If you want it for each player, you have 2 options. Qglobals or tasks

If you want to use qglobals, ensure the NPC has quest globals enabled in the npc_types table.

Bellos
08-05-2010, 05:49 PM
If you want it for each player, you have 2 options. Qglobals or tasks

If you want to use qglobals, ensure the NPC has quest globals enabled in the npc_types table.

but can you spawn an NPC with tasks? I guess when that step is complete huh?

I forgot about that, thats much easier.

joligario
08-05-2010, 05:57 PM
Yes, you would spawn it in perl upon task completion.

If you want to use globals, this might be what you are trying to do:

(untested)
sub EVENT_DEATH {
if (defined($qglobals{orcpawndeath}) {
quest::setglobal("orcpawndeath",$qglobals{orcpawndeath}+1,0,"F");
}
else {
quest::setglobal("orcpawndeath",1,0,"F");
}
if ($qglobals{orcpawndeath} == 4) {
quest::setglobal("orcpawndeath",0,0,"F");
quest::unique_spawn(999149,0,0,1652,1535,-9,69);
}
}

joligario
08-05-2010, 10:32 PM
FYI: Now that I am awake and rereading this, I missed a closing ) on line 2

Bellos
08-06-2010, 08:20 AM
Yes, you would spawn it in perl upon task completion.

If you want to use globals, this might be what you are trying to do:

(untested)
sub EVENT_DEATH {
if (defined($qglobals{orcpawndeath}) {
quest::setglobal("orcpawndeath",$qglobals{orcpawndeath}+1,0,"F");
}
else {
quest::setglobal("orcpawndeath",1,0,"F");
}
if ($qglobals{orcpawndeath} == 4) {
quest::setglobal("orcpawndeath",0,0,"F");
quest::unique_spawn(999149,0,0,1652,1535,-9,69);
}
}

Ill give it a try and see if i can get it to work. I just realized i dont need it to be for each player, just server wide so whenever all 4 orcs are dead at the same time the mob spawns.

Lemme see if i understand what your doing here so i actually learn and dont have to beg people to write scripts for me lol.

If its defined you set it to orcpawndeath +1, if its not defined you just set it to 1, when it hits 4, you reset it and spawn the mob. Do i have to enter this variable in to the database at all or just enable the qglobals on the mob like you said before

joligario
08-06-2010, 09:25 AM
Yup, you are reading this correct. You don't enter variables into the database. Just enable the qglobals for the npc. If you don't want it per player, then just change the options from 0 to 2.

Bellos
08-06-2010, 11:10 AM
Yup, you are reading this correct. You don't enter variables into the database. Just enable the qglobals for the npc. If you don't want it per player, then just change the options from 0 to 2.

thats pretty simple, maybe it was character flags i was having trouble with lol, thanks man

Bellos
08-16-2010, 10:18 PM
Ok this is no longer working. I also tried to do the same thing with a different quest, different variable ect.. it doesnt work.

Can anyone help me fix it or either write it for me?

All i need is

Somthing to keep track of how many of a certain mob the player has killed.

If the player has killed 4, spawn another mob then reset so if the player kills 4 more it will respawn again.


Actually if any player in the zone kills 4 of the mob id like it to spawn so it doesnt get messed up by other people stealing mobs

Caryatis
08-17-2010, 12:41 AM
Here is a script I use for similar situations that doesnt require globals. This assumes that you want the NPCs to respawn when the last is dead(regardless of kill credit), however the mobs can still respawn normally as well.

You would have an invis controller NPC with this script...

sub EVENT_SPAWN
{
quest::settimer("start", 6);
}

sub EVENT_TIMER
{
if ($timer eq "start") {
quest::stoptimer("start");
my $counter = 0;
## Get all NPCs in zone
my @npcList = $entity_list->GetNPCList();
foreach $npcs(@npcList) {
## NPC ID you want to be all dead
if($npcs->GetNPCTypeID() == 999999) {
$counter = 1;
}
}
if($counter == 0) {
## NPCs to respawn
quest::spawn2(888888,0,0,x,y,z,h);
quest::spawn2(888888,0,0,x,y,z,h);
quest::spawn2(888888,0,0,x,y,z,h);
quest::spawn2(888888,0,0,x,y,z,h);
}
quest::settimer("start", 6);
}
}

Bellos
08-17-2010, 01:41 PM
Ok instead of respawning the npcs i can make a custom one spawn. ill try it out.

I just tried it, doesnt work.

Ok it works but not the way i need.

It keeps spawning the ancient evil as long as the npcs are dead. I need it to only spawn it once.

#invisible Ancient Evil Spawning NPC

sub EVENT_SPAWN
{
quest::settimer("start", 6);
}

sub EVENT_TIMER
{
if ($timer eq "start") {
quest::stoptimer("start");
my $counter = 0;
## Get all NPCs in zone
my @npcList = $entity_list->GetNPCList();
foreach $npcs(@npcList) {
## NPC ID you want to be all dead
if($npcs->GetNPCTypeID() == 999148) {
$counter = 1;
}
}
if($counter == 0) {
## NPCs to respawn
quest::spawn2(888888,0,0,1653.5,1537.6,-8.2,172.8);
}
quest::settimer("start", 6);
}
}

Caryatis
08-17-2010, 02:58 PM
At some point, its better to use your own brain than rely on others for everything. You seem like a very lazy person.

The script is all about checking if there are no mobs of a certain type spawned in the zone, a monkey could tweak the code so it would then check if another mob is up, or send a signal to another mob to do the spawning, or set a different length on the timer, etc.

Bellos
08-17-2010, 03:18 PM
At some point, its better to use your own brain than rely on others for everything. You seem like a very lazy person.

The script is all about checking if there are no mobs of a certain type spawned in the zone, a monkey could tweak the code so it would then check if another mob is up, or send a signal to another mob to do the spawning, or set a different length on the timer, etc.

not really lazy, just not experienced in all aspects of quests yet.

Kinda hard to change somthing to work when i dont know how to lol. To be quite honest i cannot see how the code does what it does. Ill just try to figure out a different way.