Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open Shop on Attack
#1
Well, basically, when you hit attack (whatever button that may be for you.) on a shopkeeper, it'll queue up the shop that has the same name as the NPC.

Difficulty: Cut and Paste + For the love of all that is unholy, Understand.

First off, find: Function CanAttackNpc

Now there's a case with the four directions.
Each one contains this code:

Code:
If Npc(NpcNum).Behavior  NPC_BEHAVIOR_FRIENDLY And Npc(NpcNum).Behavior  NPC_BEHAVIOR_SHOPKEEPER Then
                            CanAttackNpc = True
                        Else
                            Call PlayerMsg(Attacker, "You cannot attack a " & Trim(Npc(NpcNum).Name) & "!", BrightBlue)
                        End If

Simple enough, it finds out what the NPC's behavior is, and acts accordingly.
Now, change it to this:
Code:
If Npc(NpcNum).Behavior  NPC_BEHAVIOR_FRIENDLY And Npc(NpcNum).Behavior  NPC_BEHAVIOR_SHOPKEEPER Then
                            CanAttackNpc = True
                        Else
                            If Npc(NpcNum).Behavior = NPC_BEHAVIOR_SHOPKEEPER Then
                                For i = 1 To MAX_SHOPS
                                    If Trim(Shop(i).Name) = Trim(Npc(NpcNum).Name) Then
                                        Call SendTrade(Attacker, i)
                                    End If
                                Next i
                            Else
                                Call PlayerMsg(Attacker, "You cannot attack a " & Trim(Npc(NpcNum).Name) & "!", BrightBlue)
                            End If
                        End If

Don't forget to Dim I.
Basically, if the NPC is a shopkeeper, it runs through every shop in the I loop, and checks each shop's name to the NPC's name. If it matches, it calls the shop. Simple enough eh?

So.. do that for all four directions. you might also want to remove the ability to call shops with /trade, and if you'd like, even remove the map's shop attribute, since you don't need it.

Again, it's just something simple I added a long time ago, and I figure most people here have as well, but this should help some of the newbies, right?

EDIT: almost forgot, you need to make sure the shop index is loaded when you have trade requests, or it'll call up the shop on the map. I'll post how later, but it's not that hard.. so you can always do it yourself.
Reply
#2
Should just save the shop number to the npc and skip the loop each time. It's smarter.
Reply
#3
I wasn't sure if it would be faster/less memory, since you'd still have to save a shop number to the NPC rec, and save/load it.
Reply
#4
It's one number, one byte that would be loaded. More than a byte if you have higher than 255 shops, but w/e.

What's loading one number as opposed to looping through 255 or more depending on your max shops?
Reply
#5
Alright, makes sense.

=(^.^)=
Reply
#6
The tut isn't bad, but it needs to be updated. Maybe when I get back from my wedding today, I'll help you out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)