 |
| Regular |
Joined: Wed Jan 16, 2008 8:50 pm Posts: 60
|
Can someone take a look at the below code and help me out. The code works fine, for the most part, however I can't figure out the value1 and value2. The problem comes when I try to use a currency for item1 and/or Item2 and I set a value for either. I.E. Code: Call Blacksmithing(index, 1, 5, 2, 5, 3, false, 1) If it fails, it gives me the failure message, however the inventory doesn't update showing that they have lost those items.
SPOILER: (click to show)
Code: Sub Blacksmithing(index, Item1, value1, Item2, value2, reward, stackable, chance) Dim emptyslot As String Dim item1slot As String Dim item2slot As String Dim i As Byte Dim x As Integer Dim Dice1 As Byte Dim Slevel As Integer Dim StackReward As Integer Dim RewardSlot As Byte
' IMPORTANT NOTES ' -stackable should be set to "True" if reward is a currency item. ' -the values of item1 and item2 should be 0 if they are not currency.
emptyslot = 0 'signifys that emptyslot was not found item1slot = 0 'signifys that the item was not found item2slot = 0 'signifys that the item was not found i = 1 Do While i <= 24 x = GetPlayerInvItemNum(index, i) If x = 0 Then If emptyslot = 0 Then emptyslot = i End If End If If x = Item1 Then If item1slot = 0 Then item1slot = i End If End If If x = Item2 Then If item2slot = 0 Then item2slot = i End If End If i = i + 1 Loop ' this section checks to make sure the player has the required items and space. If emptyslot <> 0 Then If item1slot <> 0 Then If item2slot <> 0 Then If GetPlayerInvItemValue(index, item1slot) >= value1 And GetPlayerInvItemValue(index, item2slot) >= value2 Then Dice1 = (Int((100 - 1 + 1) * Rnd + 1)) Slevel = GetPlayerenchanting(index) chance = (Int(((Slevel) * 100) / (chance))) If Dice1 <= chance Then i = 1 Do While i <= 24 If GetPlayerInvItemNum(index, i) = reward Then StackReward = 0 If GetPlayerInvItemValue(index, i) >= 1 Then RewardSlot = i StackReward = 1 i = 25 End If End If i = i + 1 Loop If value1 = 0 Then value1 = 1 End If If value2 = 0 Then value2 = 1 End If value1 = GetPlayerInvItemValue(index, item1slot) - value1 value2 = GetPlayerInvItemValue(index, item2slot) - value2 Call PlayerMsg(index, "You successfully created a new item.", 14) If value1 <= 0 Then Call SetPlayerInvItemNum(index, item1slot, 0) Call SetPlayerInvItemValue(index, item1slot, 0) Else Call SetPlayerInvItemValue(index, item1slot, value1) End If If value2 <= 0 Then Call SetPlayerInvItemNum(index, item2slot, 0) Call SetPlayerInvItemValue(index, item2slot, 0) Else Call SetPlayerInvItemValue(index, item2slot, value2) End If If stackable = "True" Then If StackReward = 0 Then Call SetPlayerInvItemNum(index, emptyslot, reward) Call SetPlayerInvItemValue(index, emptyslot, 1) Call SendInventoryUpdate(index, item1slot) Call SendInventoryUpdate(index, item2slot) Call SendInventoryUpdate(index, emptyslot) Else Call SetPlayerInvItemValue(index, RewardSlot, GetPlayerInvItemValue(index, RewardSlot) + 1) Call SendInventoryUpdate(index, item1slot) Call SendInventoryUpdate(index, item2slot) Call SendInventoryUpdate(index, RewardSlot) End If Else Call SetPlayerInvItemNum(index, emptyslot, reward) Call SetPlayerInvItemValue(index, emptyslot, 1) Call SendInventoryUpdate(index, item1slot) Call SendInventoryUpdate(index, item2slot) Call SendInventoryUpdate(index, emptyslot) End If Else Call SetPlayerInvItemValue(index, item1slot, value1 - 1) Call SetPlayerInvItemValue(index, item2slot, value2 - 1) Call PlayerMsg(index, "You failed to create a new item.", 12) If value1 <= 0 Then Call SetPlayerInvItemNum(index, item1slot, 0) Call SetPlayerInvItemValue(index, item1slot, 0) Call SendInventoryUpdate(index, item1slot) Else Call SetPlayerInvItemValue(index, item1slot, value1) End If If value2 <= 0 Then Call SetPlayerInvItemNum(index, item2slot, 0) Call SetPlayerInvItemValue(index, item2slot, 0) Call SendInventoryUpdate(index, item2slot) Else Call SetPlayerInvItemValue(index, item2slot, value2) End If End If Else Call PlayerMsg(index, "You do not have the valid resources to create this item.", 12) End If Else Call PlayerMsg(index, "You do not have the valid resources to create this item.", 12) End If Else Call PlayerMsg(index, "You do not have the valid resources to create this item.", 12) End If Else Call PlayerMsg(index, "Your inventory is full!", 12) End If End Sub
Another question, when I cast the spell that calls this sub, it works correctly the first time, but it won't let me cast the spell again unless I reset the server, or reload spells. Here is the code I am using for the spell. Nothing too complex. I use 4 scroll bars to set the items I want to use, the item made, and the stat requirement.
SPOILER: (click to show)
Code: If Spell(SpellNum).Type = SPELL_TYPE_enchanting Then Call Blacksmithing(index, Spell(SpellNum).Item1, 5, Spell(SpellNum).Item2, 5, Spell(SpellNum).Item3, False, Spell(SpellNum).enchantNeeded) Exit Sub End If
*Edit* P.S., I'm using MS2.
|
|