Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 Hello,Is there a way to get the NPC slot number? The slot number of where each NPC is saved? The one shoen in menu 'F1 > Edit NPCs'.I asked a few people in shout box and they were very confused.I tried 'NPCnum', and 'GetMapNPCNumber(MapNum ,Index)' but it doesn't give me the right number. 'NPCnum' always gives me '0', and 'GetMapNPCNumber(MapNum ,Index)' always gives my '1'.I basically need a mechanism or a sub/function which can distinguish each NPC from the other. It shouldn't matter whether the NPC is attack-able or is friendly/scripted. Because the 'OnAttack' sub doesn't run when the NPC is friendly/scripted.I hope I'm not too confusing. Please help me in this little problem.-Thanks in advance. Link to comment Share on other sites More sharing options...
Owen F Posted September 4, 2009 Share Posted September 4, 2009 are you using NPCNum correctly? its mainly an if- kind of thingtheres no Get or anythinge.g> If NPCNum = 5 Then Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 OK. The NPC I am testing is in slot number 2 in the menu 'F1 > Edit NPCs'. It is a scripted NPC in case 2\. It is running my script. So at the top of Case 2 I added this:```If NPCnum = 2 Then Call PlayerMsg(Index, "asdasda", GREEN)End If```When I hit 'ctrl' it doesn't display the message, even though it should. But when I change the number from '2' to '0', it display's the message. I dunno if I'm still doing something wrong. :(-Thanks Link to comment Share on other sites More sharing options...
kris_hole Posted September 4, 2009 Share Posted September 4, 2009 thats because npcnum isnt defined… Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 @[THE-KRIS:> link=topic=51395.msg539206#msg539206 date=1252101498]> thats because npcnum isnt defined…if you mean```Dim NPCnum```Then it's already on top of case. Still the same problem.Should'nt NPCnum be connected to the source somehow. I mean, normall when a sub/function is used. The info gets passed to the source wich then returns you a value.-Thanks Link to comment Share on other sites More sharing options...
Godlord Posted September 4, 2009 Share Posted September 4, 2009 @Zamin:> OK. The NPC I am testing is in slot number 2 in the menu 'F1 > Edit NPCs'. It is a scripted NPC in case 2\. It is running my script. So at the top of Case 2 I added this:> ```> If NPCnum = 2 Then> Call PlayerMsg(Index, "asdasda", GREEN)> End If> > ```> When I hit 'ctrl' it doesn't display the message, even though it should. But when I change the number from '2' to '0', it display's the message. I dunno if I'm still doing something wrong. :(> > -ThanksTry GetPlayerTargetNPC, if you're attacking. I think OnAttack, ScriptedNPC and such set the target when you attack.```If GetPlayerTargetNPC(Index) < 1 Then Exit SubEnd IfIf GetPlayerTargetNpc(Index) = 2 Then Call PlayerMsg(Index, "You are attacking NPC 2.", BRIGHTGREEN)Else Call PlayerMsg(Index, "You aren't attacking NPC 2.", BRIGHTRED)End If```Regards, Godlord. Link to comment Share on other sites More sharing options...
kris_hole Posted September 4, 2009 Share Posted September 4, 2009 you cant just dim it, you have to give it a variable. Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 OK, I put that code in OnAttack sub. I also placed this under your code to check what I get:```Call PlayerMsg(Index, "NPC Number: " & GetPlayerTargetNpc(Index), BRIGHTRED)```My NPc which is in slot 1 is atackable on Map 1, 2nd NPC is scripted on Map 1 and the 3rd NPC is also attackable but on Map 2.I placed your code and the line mentioned in Sub OnAttack. When I attack the attack-able NPCs, the one in slots 1 and 3, I always get the following message:```Your aren't attacking NPC 2.NPC Number: 1```When I placed the above code in the sub ScriptedNPC in case 2, the case that my scripted NPC is using. This NPC is in slot #2\. The script doesn't run, in fact, because of the 'GetPlayerTargetNpc(Index)' script, my scripted NPC doesn't run its usual script.I hope I wasn't too confusing. Is there no way to get the NPc number right from where it is stored in source?> you cant just dim it, you have to give it a variable.What do you mean give it a variable? Like```Dim xx = NPCnum```Sorry, I'm just not understanding. :(-Thanks Link to comment Share on other sites More sharing options...
kris_hole Posted September 4, 2009 Share Posted September 4, 2009 yeh just like that. Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 @[THE-KRIS:> link=topic=51395.msg539257#msg539257 date=1252104568]> yeh just like that.Still gives me '0' man. This is so irritating :(-Thanks though Link to comment Share on other sites More sharing options...
kris_hole Posted September 4, 2009 Share Posted September 4, 2009 well npcnum doesnt exist unless you give it a value propperlydim npcnumnpcnum = GetPlayerTargetNpc(index) Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 @[THE-KRIS:> link=topic=51395.msg539274#msg539274 date=1252105437]> well npcnum doesnt exist unless you give it a value propperly> > dim npcnum> > npcnum = GetPlayerTargetNpc(index)Ok, so I did that and placed the following in the ScriptedNPC case 2, to check for my npc.```If NPCnum = 2 Then Call PlayerMsg(Index, "asdasda", GREEN)End IfCall PlayerMsg(index, "NPC Number 1: " & NPCnum, RED)```I get 'NPC Number 1: -1'So I NPCnum is '-1' when I hit 'ctrl' to the scripted npc. At least this isn't '0'. lolAny other ideas, lol.-Thanks. Link to comment Share on other sites More sharing options...
Robin Posted September 4, 2009 Share Posted September 4, 2009 MapNpcNum is used in a few subroutines, but it's **called**.You can't "find" the slot number, you need to know it. Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 @Robin:> MapNpcNum is used in a few subroutines, but it's **called**.> > You can't "find" the slot number, you need to know it.Ok so correct me if i'm wrong```GetMapNPCnumber(1,Index)```In this case, 1 is the map number. And this will simply return the npc number, which is unique in this entire map?This is so confusing. :(-Thanks Link to comment Share on other sites More sharing options...
balliztik1 Posted September 4, 2009 Share Posted September 4, 2009 The only way to find what NPC you're attacking is via Godlord's method: GetPlayerTargetNPC. You can't do this with scripted NPCs. You'll have to add that to the source. It's just a matter of adding another parameter to the MyScript execution of ScriptedNPCs.@Zamin:> Ok so correct me if i'm wrong> ```> GetMapNPCnumber(1,Index)> ```In this case, 1 is the map number. And this will simply return the npc number, which is unique in this entire map?> > This is so confusing. :(> > -ThanksIndex is likely your player index. You can't use that. You have to know the slot that the NPC is in to use that command, like Robin said. The "index" that command references is the NPC index. Link to comment Share on other sites More sharing options...
Zamin Posted September 4, 2009 Author Share Posted September 4, 2009 @Balliztik1:> The only way to find what NPC you're attacking is via Godlord's method: GetPlayerTargetNPC. You can't do this via scripting. You'll have to add that to the source. It's just a matter of adding another parameter to the MyScript execution of ScriptedNPCs.> > Index is likely your player index. You can't use that. You have to know the slot that the NPC is in to use that command, like Robin said. The "index" that command references is the NPC index.Sorry, this is the slot number in the menu 'F1 > Edit NPCs' or the meny 'F1 > Edit Map > Properties > NPC'. Just wanna be sure.-Thanks Link to comment Share on other sites More sharing options...
Bobosk Posted September 4, 2009 Share Posted September 4, 2009 Omg people.. [http://www.touchofdeathforums.com/smf/index.php/topic,28153.0.html](http://www.touchofdeathforums.com/smf/index.php/topic,28153.0.html)```NPCNUM = GetMapNpcNumber(GetPlayerMap(Index), GetPlayerTargetNPC(Index))Call PlayerMsg(Index, "Npcnum is " & NPCNUM, 15)``` Link to comment Share on other sites More sharing options...
balliztik1 Posted September 4, 2009 Share Posted September 4, 2009 @Zamin:> Sorry, this is the slot number in the menu 'F1 > Edit NPCs' or the meny 'F1 > Edit Map > Properties > NPC'. Just wanna be sure.> > -ThanksYes, that index. But if you already know it, then you aren't trying to find it, which gets you no where. Link to comment Share on other sites More sharing options...
Zamin Posted September 5, 2009 Author Share Posted September 5, 2009 @Bobosk:> Omg people.. [http://www.touchofdeathforums.com/smf/index.php/topic,28153.0.html](http://www.touchofdeathforums.com/smf/index.php/topic,28153.0.html)> > ```> NPCNUM = GetMapNpcNumber(GetPlayerMap(Index), GetPlayerTargetNPC(Index))> Call PlayerMsg(Index, "Npcnum is " & NPCNUM, 15)> > ```OK, I tried this. It works perfectly on NPC that you can attack. I did a few trial runs. It gives me the targetNPC as 1 for all attack-able NPCs. But I need it to work for a scripted NPC. And the targetNPC for a scripted NPC is 0.So when I use this command for the scripted NPC, it becomes this:GetMapNpcNumber(GetPlayerMap(Index), 0) because the targetNPC is 0, right?This is the problem, it doesn't read in 0\. As soon as 0 is entered in the GetMapNPCNumber Function, the script doesn't run. Is there a way for it to work for a scripted NPC? Thanks.@Balliztik1:> Yes, that index. But if you already know it, then you aren't trying to find it, which gets you no where.I am checking it using a .ini file. User put the NPC number by looking at the Edit NPCs menu, then I check whether the NPC the user is targeting is the same or not. If so then….-Thanks. Link to comment Share on other sites More sharing options...
Kimimaru Posted September 5, 2009 Share Posted September 5, 2009 @Zamin:> I am checking it using a .ini file. User put the NPC number by looking at the Edit NPCs menu, then I check whether the NPC the user is targeting is the same or not. If so then….Are you sure you're doing this part correctly? Link to comment Share on other sites More sharing options...
Zamin Posted September 5, 2009 Author Share Posted September 5, 2009 @Kimimaru:> Are you sure you're doing this part correctly?This is what I will do after I do know how to get the NPC number of a scripted NPC. And Ya, i think i know how to do it. But first things first, I need to read the targeted NPC's number.-Thanks Link to comment Share on other sites More sharing options...
Kimimaru Posted September 5, 2009 Share Posted September 5, 2009 I skimmed through the source and didn't find anything that would help. I'll try to take a more in-depth look at it tomorrow if no one else helps you solve your problem. Right now, I'm pretty tired since I've coded a lot today, sorry. Link to comment Share on other sites More sharing options...
Bobosk Posted September 5, 2009 Share Posted September 5, 2009 There's a tidbit in the Server-side source that doesn't make scriptedNPC's targets.. which can easily be fixed a few ways… but i think the easiest would be.```' Try to attack an NPC. For I = 1 To MAX_MAP_NPCS If CanAttackNpc(Index, I) Then ' Get the damage we can do Player(Index).TargetNPC = I Player(Index).TargetType = TARGET_TYPE_NPC If Not CanPlayerCriticalHit(Index) Then Damage = GetPlayerDamage(Index) - Int(NPC(MapNPC(GetPlayerMap(Index), I).num).DEF / 2) Call SendDataToMap(GetPlayerMap(Index), "sound" & SEP_CHAR & "attack" & END_CHAR) Else Damage = GetPlayerDamage(Index) + Int(Rnd * Int(GetPlayerDamage(Index) / 2)) + 1 - Int(NPC(MapNPC(GetPlayerMap(Index), I).num).DEF / 2) Call BattleMsg(Index, "You feel a surge of energy upon swinging!", BRIGHTCYAN, 0) Call SendDataToMap(GetPlayerMap(Index), "sound" & SEP_CHAR & "critical" & END_CHAR) End If```Find that Server-Side in the ModHandleData and simply put``` Player(Index).TargetNPC = I Player(Index).TargetType = TARGET_TYPE_NPC```above the "If CanAttackNpc(Index, I)" Link to comment Share on other sites More sharing options...
Zamin Posted September 5, 2009 Author Share Posted September 5, 2009 OK, it works. I checked it, it works like a charm :)-Thanks a lot man, credits wil be given. Even if its only 2 lines. =p Link to comment Share on other sites More sharing options...
balliztik1 Posted September 5, 2009 Share Posted September 5, 2009 I'd suggest against that. The way the targetting system works, if you did that, when you don't hit an NPC, you are still setting the player's target to the last NPC, instead of leaving it as is. If a player misses, then tries to cast a spell, for instance, unless they were trying to attack NPC 15, their target will be messed up. Furthermore, because of the way the server works, if it's a damaging spell, you'll get messages that you killed a non-existant NPC and that you received EXP for it. Sure, that's just an annoying message, but then the OnNPCDeath script triggers, which, without a substantial NPC to actually use, crashes the server.Setting the target to something that does not exist is not the way to go. The way to do this without interfering with the targeting system is to simply alter the Scripted NPC execution from the source code, like so:Find all instances of this line of code:```MyScript.ExecuteStatement "Scripts\Main.txt", "ScriptedNPC " & Attacker & "," & NPC(NPCnum).SpawnSecs```Replace with this:```MyScript.ExecuteStatement "Scripts\Main.txt", "ScriptedNPC " & Attacker & "," & NPC(NPCnum).SpawnSecs & "," & MapNpcNum```Currently, you'll find 8 of those in the source. Change each of them.Then, change your ScriptedNPC sub to this:```Sub ScriptedNPC(index, script, npcSlot)```And add this line to it:```NpcNum = GetMapNPCNumber(GetPlayerMap(index), npcSlot)```This way, you'll still get more specific NPC execution without altering the targeting system. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now