| Mirage Source http://web.miragesource.net/forums/ |
|
| 2 Spell Additions http://web.miragesource.net/forums/viewtopic.php?f=210&t=1717 |
Page 1 of 2 |
| Author: | Da Undead [ Sun Apr 22, 2007 4:23 pm ] |
| Post subject: | 2 Spell Additions |
Originally Coded By: NexSteve and Da Undead Originally For: Elysium Debugged Converted to Mirage By: Da Undead //\\PART 1//\\ Difficulty: 1/10 (C & P) Description: Adds a spell option to where you sacrifice hp for mp. .::Client Side::. modTypes Find: Code: Public Const SPELL_TYPE_SUBSP = 5 After, add: Code: Public Const SPELL_TYPE_SACRIFICE = 6 Done with modTypes Done with Client-Side .::Server Side::. modTypes Find: Code: Public Const SPELL_TYPE_SUBSP = 5 After Add: Code: Public Const SPELL_TYPE_SACRIFICE = 6 Very bottom of modTypes, add: Code: Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long Rand = Low + ((Rnd * (High - Low)) \ 1) End Function Done with modTypes Open modGameLogic Find: Code: If Player(index).TargetType = TARGET_TYPE_PLAYER Then If IsPlaying(n) Then If GetPlayerHP(n) > 0 And GetPlayerMap(index) = GetPlayerMap(n) And GetPlayerLevel(index) >= 10 And GetPlayerLevel(n) >= 10 And Map(GetPlayerMap(index)).Moral = MAP_MORAL_NONE And GetPlayerAccess(index) <= 0 And GetPlayerAccess(n) <= 0 Then ' If GetPlayerLevel(n) + 5 >= GetPlayerLevel(Index) Then ' If GetPlayerLevel(n) - 5 <= GetPlayerLevel(Index) Then Call MapMsg(GetPlayerMap(index), GetPlayerName(index) & " casts " & Trim(Spell(SpellNum).Name) & " on " & GetPlayerName(n) & ".", BrightBlue) Select Case Spell(SpellNum).Type Case SPELL_TYPE_SUBHP Damage = (GetPlayerMAGI(index) / \) + Spell(SpellNum).Data1) - GetPlayerProtection(n) If Damage > 0 Then Call AttackPlayer(index, n, Damage) Else Call PlayerMsg(index, "The spell was to weak to hurt " & GetPlayerName(n) & "!", BrightRed) End If Case SPELL_TYPE_SUBMP Call SetPlayerMP(n, GetPlayerMP(n) - Spell(SpellNum).Data1) Call SendMP(n) Case SPELL_TYPE_SUBSP Call SetPlayerSP(n, GetPlayerSP(n) - Spell(SpellNum).Data1) Call SendSP(n) After that and before end select, add: Code: Case SPELL_TYPE_SACRIFICE DamageDelt = Rand(5, 1) If GetPlayerHP(index) < 40 Then Call PlayerMsg(index, "Your health is so low you can't take anymore!", BrightRed) Exit Sub End If Select Case DamageDelt Case 0 Call SetPlayerHP(index, GetPlayerHP(index) - 14) Damage = 14 Call AttackNpc(index, n, Damage) Case 1 Call SetPlayerHP(index, GetPlayerHP(index) - 27) Damage = 27 Call AttackNpc(index, n, Damage) Case 2 Call SetPlayerHP(index, GetPlayerHP(index) - 4) Damage = 4 Call AttackNpc(index, n, Damage) Case 3 Call SetPlayerHP(index, GetPlayerHP(index) - 18) Damage = 18 Call AttackNpc(index, n, Damage) Case 4 Call SetPlayerHP(index, GetPlayerHP(index) - 37) Damage = 37 Call AttackNpc(index, n, Damage) Case 5 Call PlayerMsg(index, "You body's power can't stand to lose more blood.", BrightRed) End Select Find: Code: If Npc(MapNpc(GetPlayerMap(index), n).Num).Behavior <> NPC_BEHAVIOR_FRIENDLY And Npc(MapNpc(GetPlayerMap(index), n).Num).Behavior <> NPC_BEHAVIOR_SHOPKEEPER Then Call MapMsg(GetPlayerMap(index), GetPlayerName(index) & " casts " & Trim(Spell(SpellNum).Name) & " on a " & Trim(Npc(MapNpc(GetPlayerMap(index), n).Num).Name) & ".", BrightBlue) Select Case Spell(SpellNum).Type Case SPELL_TYPE_ADDHP MapNpc(GetPlayerMap(index), n).HP = MapNpc(GetPlayerMap(index), n).HP + Spell(SpellNum).Data1 Case SPELL_TYPE_SUBHP Damage = (GetPlayerMAGI(index) \ 4) + Spell(SpellNum).Data1) - (Npc(MapNpc(GetPlayerMap(index), n).Num).DEF \ 2) If Damage > 0 Then Call AttackNpc(index, n, Damage) Else Call PlayerMsg(index, "The spell was to weak to hurt " & Trim(Npc(MapNpc(GetPlayerMap(index), n).Num).Name) & "!", BrightRed) End If Case SPELL_TYPE_ADDMP MapNpc(GetPlayerMap(index), n).MP = MapNpc(GetPlayerMap(index), n).MP + Spell(SpellNum).Data1 Case SPELL_TYPE_SUBMP MapNpc(GetPlayerMap(index), n).MP = MapNpc(GetPlayerMap(index), n).MP - Spell(SpellNum).Data1 Case SPELL_TYPE_ADDSP MapNpc(GetPlayerMap(index), n).SP = MapNpc(GetPlayerMap(index), n).SP + Spell(SpellNum).Data1 Case SPELL_TYPE_SUBSP MapNpc(GetPlayerMap(index), n).SP = MapNpc(GetPlayerMap(index), n).SP - Spell(SpellNum).Data1 After, before end select, add: Code: Case SPELL_TYPE_SACRIFICE DamageDelt = Rand(1, 5) If GetPlayerHP(index) < 40 Then Call PlayerMsg(index, "Your health is so low you can't take anymore!", BrightRed) Exit Sub End If Select Case DamageDelt Case 0 Call SetPlayerHP(index, GetPlayerHP(index) - 14) Damage = 14 Call AttackNpc(index, n, Damage) Case 1 Call SetPlayerHP(index, GetPlayerHP(index) - 27) Damage = 27 Call AttackNpc(index, n, Damage) Case 2 Call SetPlayerHP(index, GetPlayerHP(index) - 4) Damage = 4 Call AttackNpc(index, n, Damage) Case 3 Call SetPlayerHP(index, GetPlayerHP(index) - 18) Damage = 18 Call AttackNpc(index, n, Damage) Case 4 Call SetPlayerHP(index, GetPlayerHP(index) - 37) Damage = 37 Call AttackNpc(index, n, Damage) Case 5 Call PlayerMsg(index, "You body's power can't stand to lose more blood.", BrightRed) End Select Find: Code: Sub CastSpell(ByVal index As Long, ByVal SpellSlot As Long) Dim SpellNum As Long, MPReq As Long, i As Long, n As Long, Damage As Long After Damage As Long, add: Code: , DamageDelt As Integer End of modGameLogic. End of Server-Side ------------------------------------------------------------------------------------- //\\PART 2//\\ Description: Spends SP for MP. Add this both client and server side for modTypes after the 'SPELL_TYPE_SACRIFICE = 8' : Code: Public Const SPELL_TYPE_SPFORMP = 7 And this goes after/before the sacrifice cases on modGameLogic(SERVER) on both places : Code: Case SPELL_TYPE_SPFORMP
Dim Minus As Long If GetPlayerSP(index) < 10 Then Call PlayerMsg(index, "You can't take anymore SP away because you dont have enough!" Exit Sub End if Minus = Rand(100, 1) Call SetPlayerSP(index, GetPlayerSP(index) - Minus) Call SetPlayerMP(index, GetPlayerMP(index) + Minus) ----------------------------------------- Any problems or questions, post here |
|
| Author: | Spodi [ Sun Apr 22, 2007 5:48 pm ] |
| Post subject: | |
Heres a new Rand for you because that one makes me cry: Code: Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long Rand = Low + ((Rnd * (High - Low)) \ 1) End Function - Don't need Randomize - You're working with and returning a variant - You're making a loop and constantly "hoping it hits", which would freeze for hours if you specify high values with small gaps - It will go into an infinite loop if you specify the low as higher than the high - I ran the code Rand(2000000000, 1999999999) compiled with all optimizations ticked... and about 10 minutes later, its still running :lol: Also, just want to add, stuff like this: Code: (Int(GetPlayerMAGI(index) / 4) Can be written: Code: (GetPlayerMAGI(index) \ 4)
Its faster since what you're doing is taking the extra processing to do floating-point division, then to remove that floating point with the Int(), so \ 4 just does straight integer division (much faster). |
|
| Author: | Da Undead [ Sun Apr 22, 2007 7:13 pm ] |
| Post subject: | |
Thankyou spodi, updated tut |
|
| Author: | William [ Sun Apr 22, 2007 8:00 pm ] |
| Post subject: | |
You also need to update. Code: DamageDelt = Rand(5, 1) To: Code: DamageDelt = Rand(1, 5)
|
|
| Author: | Da Undead [ Sun Apr 22, 2007 8:41 pm ] |
| Post subject: | |
What that for? |
|
| Author: | William [ Sun Apr 22, 2007 8:53 pm ] |
| Post subject: | |
Well the random function states that it starts with Low and ends with High. So the most obviouse way to write it would be 1, 5. |
|
| Author: | Spodi [ Sun Apr 22, 2007 10:12 pm ] |
| Post subject: | |
My bad, the one I gave you went Low/High, while your original was High/Low. |
|
| Author: | Nexarcon [ Sun Apr 22, 2007 11:02 pm ] |
| Post subject: | |
Oh, it's spelt Sacrifice btw. |
|
| Author: | Da Undead [ Mon Apr 23, 2007 12:10 am ] |
| Post subject: | |
Spodi wrote: My bad, the one I gave you went Low/High, while your original was High/Low.
Oh well, i updated it to 5, 1 and spelling doesn't matter :p |
|
| Author: | Da Undead [ Mon Apr 23, 2007 12:23 am ] |
| Post subject: | |
UPDATED TUT! Added SP for MP in //\\PART 2//\\ (BOTTOM) of first post. |
|
| Author: | Rezeyu [ Sun May 20, 2007 7:37 pm ] |
| Post subject: | |
Da Undead wrote: Spodi wrote: and spelling doesn't matter :p Actually, it should... Because you defined the spell in your server as: Code: Public Const SPELL_TYPE_SACRIFISE = 6 And in the CastSpell sub, you're looking for this: Code: Case SPELL_TYPE_SACRIFICE
Correct me if I'm wrong of course. |
|
| Author: | Da Undead [ Sun May 20, 2007 8:45 pm ] |
| Post subject: | |
Oh nice catch, updated |
|
| Author: | CuChulainn [ Sun Aug 12, 2007 9:06 am ] |
| Post subject: | Re: 2 Spell Additions |
Also, you forgot to mention that you have to add stuff in the client side spell editor as well |
|
| Page 1 of 2 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|