drktemplar Posted October 24, 2008 Author Share Posted October 24, 2008 I'm trying to work on a ranged damage spell. However I'm hung up on getting data back from the target. I created this test script just to get data to work with, but it has a problem and does nothing.I created a basic npc and put him in the map. I select him and its give me the message "your target is now…" and then when i use this script, nothing happens. However If i have myself targeted I can get the message. Any thoughts?Case 2pxp = GetPlayerX(Index)pyp = GetPlayerY(Index)txp = GetPlayerX(GetPlayerTarget(Index))typ = GetPlayerY(GetPlayerTarget(Index))Call BattleMsg(Index, "Your target is at "&txp&" by "&typ&" , and you are at "&pxp&" by "&pyp&".", BLUE, 0)Call BattleMsg(Index, "Your target variable is "&pt, BLUE, 0)*I get an error that says "Subscript Out of Range", not sure if that helps or not. Link to comment Share on other sites More sharing options...
DarkMazer Posted October 24, 2008 Share Posted October 24, 2008 GetPlayerTarget(index) will only return -1 if your target is an NPC, and GetPlayerTargetNpc(index) will tell you what an NPC's index is, so if you want to target only players, use GetPlayerTarget(index); if you want to target only NPCs, use GetPlayerTargetNPC(index), and if you want to target either, use something like:```Dim targettarget = GetPlayerTarget(index)If target > 0 Then 'do somethingElse target = GetPlayerTargetNPC(index) 'do somethingEnd If```Also, if that doesn't work either, it may be a bug in EE 2.7 preventing you from targeting an NPC properly. If that's the case, you need to find someone who can fix the source code for you. Link to comment Share on other sites More sharing options...
drktemplar Posted October 24, 2008 Author Share Posted October 24, 2008 Ok, I tried to include what you told me. But I still receive the same error. Here is the updated script. I might just be writing it incorrectly.Case 2pm = GetPlayerMP(Index)pt = GetPlayerTarget(Index)pxp = GetPlayerX(Index)pyp = GetPlayerY(Index)txp = GetPlayerX(GetPlayerTarget(Index))typ = GetPlayerY(GetPlayerTarget(Index))pd = 1If pt > 0 ThenCall SetPlayerHP(pt, GetPlayerHP(pt)-pd)Call SetPlayerMP(Index, pm - 10)Call BattleMsg(Index, "You have done "&pd&" damage to "&GetPlayerName(GetPlayerTarget(Index))&"!", BLUE, 0)Elsept = GetPlayerTargetNPC(Index)Call SetPlayerHP(pt, GetPlayerHP(pt)-pd)Call SetPlayerMP(Index, pm - 10)Call BattleMsg(Index, "You have done "&pd&" damage to "&GetPlayerName(GetPlayerTarget(Index))&"!", BLUE, 0)End IfExit Sub Link to comment Share on other sites More sharing options...
Bobosk Posted October 24, 2008 Share Posted October 24, 2008 ```Case 2If GetPlayerTarget(Index) > 0 ThenCall SetPlayerHP(GetPlayerTarget(index), GetPlayerHP(GetPlayerTarget(index) - 1)Call SetPlayerMP(Index, GetPlayerMP(index) - 10)Call BattleMsg(Index, "You have done 1 damage to " & GetPlayerName(GetPlayerTarget(Index)) & "!", Red, 0)ElseIf GetPlayerTarget(Index) = 0 ThenCall PlayerMsg(Index, "You need to target something to use this spell", Red)ElseCall SetMapNPCHP(GetPlayerMap(Index), GetPlayerTargetNPC(index), GetMapNPCHP(GetPlayerTargetNPC(Index)) - 1)Call SetPlayerMP(index, GetPlayerMP(index) - 10Call BattleMsg(Index, "You have done 1 damage to " & GetNPCName(GetMapNPCnumber(GetPlayerMap(index), GetPlayerTargetNPC(index))) & "!", Red, 0)End IfExit Sub``` Link to comment Share on other sites More sharing options...
drktemplar Posted October 24, 2008 Author Share Posted October 24, 2008 I used the above code, added the ")" where you missed it, and i get the same error. Link to comment Share on other sites More sharing options...
drktemplar Posted October 24, 2008 Author Share Posted October 24, 2008 Ok I got this sorta working now… however the npc does not show in the UI that he has taken damage (no life bar appears) and the npc doesn't react as if he was hurt (ie: attack player). Also the npc can go below 0 health and doesn't die.What am I missing? Link to comment Share on other sites More sharing options...
DarkMazer Posted October 25, 2008 Share Posted October 25, 2008 Instead of using SetMapNpcHP, you may want to try DamageNPC(index, NPCindex, damage). That should cause the NPC to react. I'm not sure if it'll use the default battle message or not, though. If it does something you don't want it to, then try adding SetMapNpcTarget(MapNum, NPCIndex, Target) and SendNPC(mapnum, NPCindex) to make it target the player. I'm not sure how to go about making the life bar appear, though. I can't figure out how to kill the NPC, either, besides hitting it with an attack after it's already at negative HP. Link to comment Share on other sites More sharing options...
drktemplar Posted October 27, 2008 Author Share Posted October 27, 2008 Ok that worked. Not only does the npc show a health bar and attack The player when hit, but also dies when the life reaches zero. However once that happens I get an error. "Subscript out of range". EDIT: This happens when the npc or player dies from this spell.Here is the code (sry for my indenting as I'm new to scripting, and no one has explained the correct way, instead just criticized me)pm = GetPlayerMP(Index)ptp = GetPlayerTarget(Index)ptn = GetPlayerTargetNPC(Index)pd = 5Call BattleMsg(Index, "PM = "±&", PTP = "&ptp&", PTN = "&ptn&", PD = "&pd&", NH = "&nh&"", GREEN, 0) 'this line is here for me to see what is going onIf ptp = 0 ThenCall BattleMsg(Index, "You need to target something to use this spell", BLUE, 0)ElseIf ptp > 0 ThenCall SetPlayerHP(GetPlayerTarget(index), GetPlayerHP(GetPlayerTarget(index)) - pd)'Call SetPlayerMP(Index, pm - 10) 'removed mp cost for testingCall SendMP(Index)Call BattleMsg(Index, "You have done "&pd&" damage to "&GetPlayerName(GetPlayerTarget(Index))&"!", Red, 0)ElseCall DamageNPC(Index, ptn, pd)Call SendNPC(GetPlayerMap(Index), GetPlayerTargetNPC(Index))'Call SetPlayerMP(Index, pm - 10) 'removed mp cost for testingCall BattleMsg(Index, "You have done "&pd&" damage to "&GetNPCName(GetMapNPCnumber(GetPlayerMap(index), GetPlayerTargetNPC(index))) & "!", Red, 0)End IfExit Sub Link to comment Share on other sites More sharing options...
DarkMazer Posted October 27, 2008 Share Posted October 27, 2008 I think the problem is the order you're calling the statements. Since you're calling DamageNPC first, the NPC will die before you can call the message saying that the NPC died, and since your target no longer exists, it'll try to find the name of something that doesn't exist anymore, the cause of the error. Try moving the DamageNPC call to the line after the BattleMsg call (right before the End If). That should fix it. Link to comment Share on other sites More sharing options...
drktemplar Posted October 27, 2008 Author Share Posted October 27, 2008 You were correct, switching the Call BattleMsg with Call Damage did it.Thank you Link to comment Share on other sites More sharing options...
drktemplar Posted October 28, 2008 Author Share Posted October 28, 2008 I got it working with a ranged requirement as well so i thought i would post it for anyone that wants to use it. Just change the variable for damage and range and you can easily customize this. Add in some animation and sound effect and your done.```'***************Range Damage Spell Example***************** Case 4 pm = GetPlayerMP(Index) pt = GetPlayerTarget(Index) ptn = GetPlayerTargetNPC(Index) pd = 5 range = 5 If pt = 0 Then Call BattleMsg(Index, "You need to target something to use this spell", WHITE, 0) ElseIf pt > 0 Then If GetPlayerX(GetPlayerTarget(index)) > (GetPlayerX(index) + Range) or GetPlayerY(GetPlayerTarget(index)) > (GetPlayerY(index) + Range) or GetPlayerX(GetPlayerTarget(index)) < (GetPlayerX(index) - Range) or GetPlayerY(GetPlayerTarget(index)) < (GetPlayerY(index) - Range) then Call BattleMSG(index, "Your target is to far away for that ability.", WHITE, 0) Else Call SetPlayerMP(Index, pm - 10) Call BattleMsg(Index, "You have done "&pd&" damage to "&GetPlayerName(GetPlayerTarget(Index))&"!", Red, 0) Call DamagePlayer(Index, pt, pd) Exit Sub End If Else If GetNPCX(GetplayerMap(index), GetPlayerTargetNPC(index)) > (GetPlayerX(index) + Range) or GetNPCY(GetplayerMap(index), GetPlayerTargetNPC(index)) > (GetPlayerY(index) + Range) or GetNPCX(GetplayerMap(index), GetPlayerTargetNPC(index)) < (GetPlayerX(index) - Range) or GetNPCY(GetplayerMap(index), GetPlayerTargetNPC(index)) < (GetPlayerY(index) - Range) then Call BattleMSG(index, "Your target is to far away for that ability.", WHITE,0) Else Call SetPlayerMP(Index, pm - 10) Call BattleMsg(Index, "You have done "&pd&" damage to "&GetNPCName(GetMapNPCnumber(GetPlayerMap(index), GetPlayerTargetNPC(index))) & "!", Red, 0) Call DamageNPC(Index, ptn, pd) Exit Sub End If End If Exit Sub``` 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