Ertzel Posted December 21, 2009 Author Share Posted December 21, 2009 Im trying to make all my spells ingame scripted, because I want to have a real Mage system where u need a Wand or Staff equipped, and a rune in your inventory to cast spells.So right now I modified a script Soul posted a while ago for someone and it looks like this``` Case 2 Target = GetPlayerTarget(index) NPCTarget = GetPlayerTargetNPC(index) If GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 13 Then If CanTake(Index, 12, 1) Then If Target > 0 Then Call SetPlayerHP(Target, GetPlayerHP(Target) - 1) If GetPlayerHP(Target) = 0 Then Call OnDeath(Target) End If ElseIf NPCTarget > 0 Then Call DamageNPC(index, NPCTarget, GetMapNpcHP(GetPlayerMap(index), NPCTarget)) End If End If End IfExit Sub```The problem is, you can see I set the damage as 1\. But when I hit a NPC with over 1,000 HP it died in one hit…I only have 20 Magic, and the spell is suppose to do 1 damage, so how can I kill a NPC with over 1k HP...I know how Soul first made this is a bigger code to be posted at the bottom of your main, and have a special way to call it and everything. But I don't want it like that because some of my spells will need certain wands to use, or an extra rune, but some wont so I want to do a custom script per spell.So can anyone tell me why its not doing the 1 damage like it should and its just straight out killing the NPC in one hit every time. Link to comment Share on other sites More sharing options...
Admiral Refuge Posted December 21, 2009 Share Posted December 21, 2009 I'm pretty sure it's this:```Call DamageNPC(index, NPCTarget, GetMapNpcHP(GetPlayerMap(index), NPCTarget))```You're damaging the npc by the exact amount of HP the npc has.I'm pretty sure I wrote a huge scripted spell core awhile ago that takes range, npcs, etc, into consideration; that would make a good template for you.Let me find it.I would recommend setting more conditions though, regardless of which template you use, so it checks to see what the NPC type if (for instance, you can currently kill scripted npcs, friendly npcs, etc), as well as the map type (you can kill in a safe zone, etc), among other things.EDIT: Yeah, here ya go: http://www.touchofdeathforums.com/smf/index.php/topic,40424.0.htmlI've found better methods of doing things since then (I think I implement those methods into the leveling-spells system, if you want to see what I did there), but this system should work fine. Another thing I may recommend, for my code, is to swap the targetting system for dmgspells, to have it instead of:```If GetPlayerTarget(index) < 0 Then `Else `End If```````Maybe have:```If GetPlayerTarget(index) > 0 Then `Else `End If``````` Link to comment Share on other sites More sharing options...
Ertzel Posted December 21, 2009 Author Share Posted December 21, 2009 Thx so much Admiral, Ill try using your script now instead.I can just add the If Cantakes and stuff in each scripted spell before the Call to cast the spell now to make it worth with my rune system.Ok, I tried using this, and the script itsself works, but when I tried to modify it to fit how my mage system is, everything works but one..This is what I put as my Scripted Spell```Case 1 If GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 13 Or 199 Then If CanTake(Index, 12, 1) Then Call TakeItem(Index, 12, 1)Call dmgspell(index, 5, Rand(30,50), 5, 3, "None") Else Call PlayerMsg(Index, "You need Damage Runes to cast this spell", RED) End If Else Call PlayerMsg(Index, "You must have a mage weapon equiped to cast spells", RED) End IfExit Sub```It casts the spell if I have one of those 2 weapons on, and if I have Runes in my inventory, if I don't have runes it gives me the message saying I need them.But if I don't have one of the 2 weapons equipped then the server gives me a a error saying Subscript out of range, line 7, column 0, and nothing under code. Link to comment Share on other sites More sharing options...
Admiral Refuge Posted December 22, 2009 Share Posted December 22, 2009 I didn't actually look at the logic of this code, but as far as syntax is, this is wrong:```If GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 13 Or 199 Then```It should be:```If GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 13 Or GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 199 Then```Sadscript reads if-then statements like this:If (X > 4) Or (Y = 2) Then'stuffEnd IfThe way you were trying to do it, was:If (X = 4) Or (2) Then Link to comment Share on other sites More sharing options...
Ertzel Posted December 22, 2009 Author Share Posted December 22, 2009 Thats not the problem, Like I said, the spell works fine and casts.I can cast it fine using Item 13, or item 99 with the way I put it, the problem is when I don't have one of the 2 weapons equipped and try to cast a spell, thats when I get the error.It still gives me the error after changing to what you said also. Link to comment Share on other sites More sharing options...
Admiral Refuge Posted December 22, 2009 Share Posted December 22, 2009 Ahh, I see.Are your runes stackable?Who's CanTake functions are you using?The only thing I can think of, is that sadscript is too stupid to understand how to read the if-statement for CanTake; maybe this could work?"If CanTake(Index, 12, 1) = True Then"You may be getting the error, because it tries to GetPlayerInvItemNum of an item that doesn't exist. So you may have to check if anything is in the weapon slot first, before trying to get the number of that weapon slot. Link to comment Share on other sites More sharing options...
Ertzel Posted December 22, 2009 Author Share Posted December 22, 2009 Ok now your confusing me.Im using a modified version of Godlords Inventory Script to work with stackable and none stackable items.What does the error to do with the weapon have to do with If CanTake(Index, 12, 1) = True Then..That part works, if you have no runes (item 12) it gives u the message in the code to tell you that.So that means the CanTake is working fine so thats not the problem.> You may be getting the error, because it tries to GetPlayerInvItemNum of an item that doesn't exist. So you may have to check if anything is in the weapon slot first, before trying to get the number of that weapon slot.Isn't that what this is..``` If GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index))) = 13 Or 199 Then```Thats checking if the weapon is in the slot, and if it is the spell casts, the problem is when it is not in the slot it gives an error.So it is checking if the 2 weapons are in there and thats working. Link to comment Share on other sites More sharing options...
Admiral Refuge Posted December 22, 2009 Share Posted December 22, 2009 Sorry; things have been stressful with the holidays coming up, which is effecting my performance online :icon_crap:Just so I'm clear:Everything works _except_ for when you don't have item 13 or 199 equipped?As for the second-part of the code, the error I was saying, is something along the lines of this (I'll try to explain it better):GetPlayerWeaponSlot(Index) returns 0 if the player is not using a weapon.So GetPlayerInvItemNum may try to execute like so, if the player has nothing equipped:GetPlayerInvItemNum(Index, 0) since the GetPlayerWeaponSlot will return 0.Passing a "0" in for GetPlayerInvItemNum will cause a subscript out of range error.So if you try to use the function like so:GetPlayerInvItemNum(Index, Int(GetPlayerWeaponSlot(Index)))It will end up causing a subscript out of range if the player isn't using a weapon.If the player has a weapon equipped that isn't 13 or 199, there's no reason your code shouldn't work _unless_ your player has _no_ weapon equipped. Link to comment Share on other sites More sharing options...
Ertzel Posted December 23, 2009 Author Share Posted December 23, 2009 So do you know how to fix it do not cause the error? Link to comment Share on other sites More sharing options...
Admiral Refuge Posted December 24, 2009 Share Posted December 24, 2009 @Ertzel:> So do you know how to fix it do not cause the error?Just check if the player is wearing a weapon first; maybe something like this:```Case 1 Dim PlayerWeapon PlayerWeapon = Int(GetPlayerWeaponSlot(Index)) If PlayerWeapon > 0 Then ' Is there a weapon in the weaponslot? If GetPlayerInvItemNum(Index, PlayerWeapon) = 13 Or 199 Then ' Check for the items If CanTake(Index, 12, 1) Then ' Player have runes? Call TakeItem(Index, 12, 1) Call dmgspell(index, 5, Rand(30,50), 5, 3, "None") ' Run the dmgspell Else ' No runes Call PlayerMsg(Index, "You need Damage Runes to cast this spell", RED) End If Else ' Weapon not 13 or 199 Call PlayerMsg(Index, "You must have a mage weapon equiped to cast spells", RED) End If Else ' No weapon at all Call PlayerMsg(Index, "You must have a mage weapon equiped to cast spells", RED) End IfExit Sub```Didn't test it, but it should work. 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