Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make Item Command - Client Command
#8
Sonire Wrote:To make it spawn straight into the inventory just do this:

Server side, find this line
Code:
'Call SpawnItem(Val(Parse(2)), Val(Parse(3)), Val(Parse(4)), Val(Parse(5)), Val(Parse(6))...

...


Oh well, beat me to it. I did it slightly different than the way you have but I did make the modifications to spawn weapons and such in numerous amounts, using the MAX_MAP_ITEMS constant as my cutoff variable. Anyways, that code looks like it work, but here's mine:

Client Side
Code:
If Mid(MyText, 1, 5) = "/make" Then
                If Len(MyText) > 5 Then
                    Dim ItemNum As Long
                    
                    ChatText = Mid(MyText, 7, Len(MyText) - 1)
                    
                    ' Retrieve the item number from the text
                    For i = 1 To Len(ChatText)
                        If Mid(ChatText, i, 1)  " " Then
                            ItemNum = ItemNum & Mid(ChatText, i, 1)
                        Else
                            Exit For
                        End If
                    Next i
                    
                    ' See if they have chosen an amount, else just make 1 item
                    If Len(ChatText) - i > 0 Then
                        ChatText = Mid(ChatText, i + 1, Len(ChatText) - i)
                        Call SendMakeItem(Val(Trim(ItemNum)), Val(Trim(ChatText)))
                    Else
                        Call SendMakeItem(Val(Trim(ItemNum)), 1)
                    End If
                    MyText = ""
                    Exit Sub
                Else
                    Call AddText("Usage: ", AlertColor)
                    Call AddText(vbTab & "Spawn 1 item: /make ", AlertColor)
                    Call AddText(vbTab & "Spawn Multiple items: /make  ", AlertColor)
                    MyText = ""
                    Exit Sub
                End If
            End If

Code:
Sub SendMakeItem(ByVal ItemNum As Long, ByVal ItemAmount As Long)
Dim packet As String

    packet = "SPAWNITEM" & SEP_CHAR & MyIndex & SEP_CHAR & ItemNum & SEP_CHAR & ItemAmount & SEP_CHAR & GetPlayerMap(MyIndex) & SEP_CHAR & GetPlayerX(MyIndex) & SEP_CHAR & GetPlayerY(MyIndex) & SEP_CHAR & END_CHAR
    Call SendData(packet)
End Sub

Server Side:
Code:
'::::::::::::::::::::::
    ':: Spawn a Map Item ::
    '::::::::::::::::::::::
    If LCase(Parse(0)) = "spawnitem" Then
        Dim ItN As Long
        Dim ItemVal As Long
        Dim MapN As Long
        Dim MapX As Long
        Dim MapY As Long
        
        ItN = Val(Parse(2))
        ItemVal = Val(Parse(3))
        MapN = Val(Parse(4))
        MapX = Val(Parse(5))
        MapY = Val(Parse(6))
        
        If GetPlayerAccess(Val(Parse(1))) < 3 Then
            Call PlayerMsg(Val(Parse(1)), "Admin only function!", AlertColor)
            Exit Sub
        End If
        
        If Item(ItN).Type = ITEM_TYPE_WEAPON Then
            If ItemVal > MAX_MAP_ITEMS Then ItemVal = MAX_MAP_ITEMS
                
            For i = 1 To ItemVal
                Call SpawnItem(ItN, ItemVal, MapN, MapX, MapY)
            Next i
        ElseIf Item(ItN).Type = ITEM_TYPE_ARMOR Then
            If ItemVal > MAX_MAP_ITEMS Then ItemVal = MAX_MAP_ITEMS
                
            For i = 1 To ItemVal
                Call SpawnItem(ItN, ItemVal, MapN, MapX, MapY)
            Next i
        ElseIf Item(ItN).Type = ITEM_TYPE_SHIELD Then
            If ItemVal > MAX_MAP_ITEMS Then ItemVal = MAX_MAP_ITEMS
                
            For i = 1 To ItemVal
                Call SpawnItem(ItN, ItemVal, MapN, MapX, MapY)
            Next i
        ElseIf Item(ItN).Type = ITEM_TYPE_HELMET Then
            If ItemVal > MAX_MAP_ITEMS Then ItemVal = MAX_MAP_ITEMS
                
            For i = 1 To ItemVal
                Call SpawnItem(ItN, ItemVal, MapN, MapX, MapY)
            Next i
        Else
            Call SpawnItem(ItN, ItemVal, MapN, MapX, MapY)
        End If
        
        Call GlobalMsg(GetPlayerName(Parse(1)) & " uses his divine power to create an item!", GlobalColor)
        Call AddLog(GetPlayerName(Parse(1)) & " created an item.", ADMIN_LOG)
        Exit Sub
    End If

However I did not code the functions for spawning the items right into the inventory, but if I do I think i'll be wise to add another variable. Based on that variable the server will decide whether to spawn the item on to the map, or to the inventory. I also realize that code above could be a lot shorter using some "Or" statement instead of that method. That way is just easier for me to understand lol.

There's probably a million and 1 ways to expand on this so if anyone is willing, feel free to do so Big Grin

NOTE: I am in the midst of completely changing the potion system to that's why there is no potion support. But if you want it, it's as easy as (A) Making your potions stackable items or (B) copying my weapon/shield/armor/helmet code above, and using it for a few more ElseIf Statements.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)