Author Topic: How to -all npcs are dead- basic script for a quest reward?  (Read 3055 times)

How to -all npcs are dead- basic script for a quest reward?
« on: February 20, 2017, 11:23:34 am »
I'm trying to figure out this. First of all I'm using TLA SDK not Reloaded.
There is a quest that gives you a secret location that has 2 maps. One is the map where all the action goes on, and the other, is the place where you get the reward.
Thing is. You talk to a npc in the second map and says you have killed all the mobs. Then it tries to find any mob alive in map 1. If not, the quest is completed.

Slowhand made a tutorial for something similar as this but it wont work because 2238 has a different modus operandi. So unfortunately it's not a good example for me. (Ihave actually used his script in 2238 SDK and works just perfect)

I have found some script in my SDK that aparently is for a quest of hunting molerats. Once you kill all moles (considering you are the quest-taker) the script checks if they are all alive. If they're all dead killed by you, the quest-taker, it gets a local var that lets you ask for the reward. But that's not really accurate. Because If you come with a friend and he kills the rats, you won't ever get any reward. So, the thing is, I need to get the correct, simplest way possible to get this working. Like, kill rats, start counter, once they are all dead (lets say 3) the script gets the LVAR "allkilled" and the reward is available throught the dialog in map 2.


JovankaB

  • Guest
Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #1 on: February 20, 2017, 12:47:26 pm »
Mobs need to have CRITTER_EVENT_DEAD set.
When any of them dies, you check if there are any mobs left in the map.
If no alive mobs left - you check who is the "owner" of the map. It has to be stored in map data when map is created.
Then you update quest var of the map owner with meaning like e.g. 0 - mobs not killed, 1 - mobs killed
Map owner is the one who took quest of course.

Don't use counter when the quest says "kill all".
If later you add some mobs to the map and forget to update the script, your game will have a bug.
If instead of counting you check if there are any mobs left in the map, it won't matter.

See first tent quest for example - _Rat and _RatDead functions
https://github.com/rotators/fo2238/blob/master/Server/scripts/quest_first_tent.fos#L201

It's not SDK but it's not that different (getting map data might be different because of mapdata_h.fos, I don't know how it looks in SDK).
« Last Edit: February 20, 2017, 01:05:58 pm by JovankaB »

Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #2 on: February 22, 2017, 12:22:39 pm »
Got it done!! Yeeeeeehooow! It was so easy!
Guys if anyone is using TLA SDK like myself, I imported map data from 2238. (wish I was IN8 or higher to write something similar by myself. Meanwhile, I used the code from 2238's SDK)
Then, inside your map script (the map where you define where and when is created) you have to set up the mobs AI. In my case, I just imported inside my map script all the code from "mob.fos". In _MobInit set up the EVENT_DEAD so when the mob is dead, it will jump straight to the function that says what happens when it's dead. In the case of the code from mob.fos, there is already a EVENT_DEAD defined. You just have to "redirect it" to your function. For example _MobIsDead. Then set up the vars.
And it's working perfectly. Just as much as I wanted to.

As I said, I would love to write things all by myself. But for now I will be peeking other's code. Hope you don't mind.

Thanks so much for the info JovankaB

JovankaB

  • Guest
Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #3 on: February 22, 2017, 06:00:29 pm »
Congratulations, I'm glad you managed to do it ;D

2238 source code was opened for people to use it, so I doubt anyone will mind if you copy some scripts.
Personally I will be happy if some of my past work will find some use.
« Last Edit: February 23, 2017, 03:19:39 am by JovankaB »

Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #4 on: February 24, 2017, 01:37:17 am »
I have another question related to the map owner thing.

I'm trying to make some functionality to my house system. You make a private house location where you can cook or craft. You can, ofcourse, bring others adding them to the terminal. The thing is, I made some sad and basic "dismantling system" too.
Basically you can delete the location triggering the function by dialog. That's easy. Problem comes when anybody else can delete it too. Not only yourself. Pretty troll. And I wanted to demand being the owner of the map.
I wrote it but it didn't work. There is something I'm missing and I need to understand.

Here is the code:
Code: [Select]
void r_DeleteLoc(Critter& player, Critter@ npc)
{
    Map@ map = player.GetMap();

    if(!valid(map))
    {
        player.Say(SAY_NETMSG, "Invalid map.");
        return;
    }

    Location@ location = map.GetLocation();
    if(!valid(location))
    {
        player.Say(SAY_NETMSG, "Invalid location.");
        return;

    }

    uint ownerId = GetRootMapData(map.GetLocation(), MAP_DATA_OWNER);
    if(ownerId == 0)
    {
    player.SayMsg(SAY_NETMSG, TEXTMSG_TEXT, STR_BASE_NOTOWNER);
    }
else
    {
       
DeleteLocation(location.Id);
    player.AddItem(PID_BASE1KIT, 1);
    player.SayMsg(SAY_NETMSG, TEXTMSG_TEXT, STR_BASE_DISMANTLED);

        return;
    }
#endif

}


STR_BASE_NOTOWNER and STR_BASE_DISMANTLED are the text lines triggered when you try to delete the base.

The result of this, is I can delete the location wether I am or not the owner.

JovankaB

  • Guest
Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #5 on: February 24, 2017, 02:18:30 pm »
The last "if" statement has a bug. You checked if map ownerId is 0 not if it's the same as player's id.

It should be:

if (ownerId == player.Id)
{
 // delete location code
}
else
{
// sorry it's not your location
}
« Last Edit: February 24, 2017, 02:28:26 pm by JovankaB »

Re: How to -all npcs are dead- basic script for a quest reward?
« Reply #6 on: February 27, 2017, 11:25:22 am »
Oh my god haha, true  :-\ Thank you