Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make Item Command - Client Command
#1
Difficulty 1/5
Understanding 2/5 - must posses knowledge of code

What this does is allow GM's (or whatever access level you specify) to create items while in game.

CLIENT SIDE

in modClientTCP add the following:
Code:
Sub SendMakeItem(ByVal ItemNum As Long)
Dim Packet As String

    Packet = "SPAWNITEM" & SEP_CHAR & MyIndex & SEP_CHAR & ItemNum & SEP_CHAR & 1 & SEP_CHAR & GetPlayerMap(MyIndex) & SEP_CHAR & GetPlayerX(MyIndex) & SEP_CHAR & GetPlayerY(MyIndex) & SEP_CHAR & END_CHAR
    Call SendData(Packet)
End Sub
Explanation: this sends the packet to the server with your index number (for checking), and the item data. Where you see the "SEP_CHAR & 1 & SEP_CHAR" you can specify any number here you want. I chose 1 just for the heck of it. The server will only spawn 1 item regardless, unless spawning a stackable item such as gold.

in Sub HandleKeyPresses FIND the following:
Code:
' Editing shop request
            If Mid(MyText, 1, 9) = "/editshop" Then
                Call SendRequestEditShop
                MyText = ""
                Exit Sub
            End If

after the "End If" add the following:
Code:
If Mid(MyText, 1, 5) = "/make" Then
                If Len(MyText) > 5 Then
                    ChatText = Mid(MyText, 6, Len(MyText) - 1)
                    Call SendMakeItem(Val(Trim(ChatText)))
                Else
                    Call AddText("Usage: /make ", AlertColor)
                End If
                MyText = ""
                Exit Sub
            End If
Explanation: This is the command to tell the client to send the above packet. You must use the following to create an item:
Code:
/make #
Note: # is the item number. On my server, gold is item number 1. So using "/make 1" would spawn 1 gold piece under me. The amount spawned can be changed (as stated above).

SERVER SIDE
in modHandleData add the following before the last "End Sub":
Code:
'::::::::::::::::::::::
    ':: Spawn a Map Item ::
    '::::::::::::::::::::::
    If LCase(Parse(0)) = "spawnitem" Then
        If GetPlayerAccess(Val(Parse(1))) < 3 Then
            Call PlayerMsg(Val(Parse(1)), "Admin only function!", AlertColor)
            Exit Sub
        End If
        
        Call SpawnItem(Val(Parse(2)), Val(Parse(3)), Val(Parse(4)), Val(Parse(5)), Val(Parse(6)))
        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
Explanation:
1. Checks to see if the "MyIndex" is of access level 3 or higher, if not it exits the sub.
2. It spawns the item using the data sent by the packet.
3. Sends a message to everyone stating that a GM has created an item, just for kicks.
4. Logs the action. If you have log handler's this will be useful when the logs are checked to make sure that someone hasn't used a hacked client to create an item. Though, the global message will give them away anyways.

That's it. If anyone has problems just post them. I ran it twice and tried it all and it seemed to work fine. Don't worry about using numbers that are out of range... it just doesn't create the item, and doesn't cause the server/client to crash.

This can be greatly optimized and when I do get around to adding on to this function I will update this post. Enjoy Smile
Reply
#2
Does it spawn the item on the map, or into the player's inventory?
Reply
#3
Quote:Note: # is the item number. On my server, gold is item number 1. So using "/make 1" would spawn 1 gold piece under me. The amount spawned can be changed (as stated above).
Big Grin
Reply
#4
To give a better answer than Quake, it spawns directly under the player, on the map. No one can take the item, unless you've changed something, while that person is standing on the item.

I had the whole "drop party" thing in mind when I did this.
Reply
#5
Maybe this should be expanded upon and made to spawn the item in the players inventory. You know, like most commercial games and such.
Reply
#6
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)))
I'll give you a hint, that code is in the packet you just added to your server while following Leighland's Tuorial Wink

Anyways, comment or remove the line I posted above, and replace it with this:
Code:
Call GiveItem(Parse(1), Val(Parse(2)), Val(Parse(3)))

Now I also noticed that you can only spawn 1 item at a time, which isn't a bad thing unless you want to spawn a currency. That's where these modifications come in handy. You should already know that these belong client. Just replace what you added while following Leighland's tutorial.

Code:
' Spawn Item
            If Mid(MyText, 1, 5) = "/make" Then
                If Len(MyText) > 5 Then
                    ChatText = Mid(MyText, 6, Len(MyText) - 1)
                    ' Find The Item Number to Spawn
                    i = Val(Mid(MyText, 7, 3)) ' Your Item Number MUST be 3 digits. 001 - 999
                    ' Find The Desired Amount to Spawn
                    n = Val(Mid(MyText, 11, 3)) ' Change the 3 to a 4 if you want to spawn into the thousands
                    
                    Call SendMakeItem(i, n)
                Else
                    Call AddText("Usage: /make  ", AlertColor)
                End If
                MyText = ""
                Exit Sub
            End If

Code:
Sub SendMakeItem(ByVal ItemNum As Long, ByVal ItemVal As Long)
Dim Packet As String

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


There, now you can choose which item number and HOW MANY of that item will be spawned. Example

/make 001 500 - That would spawn 500 of item 1 (gold in my case)
Yes, each value must be triple digits. Though, the code is commented and tells you more about that Wink
Reply
#7
Good job. I was actually suggesting for him to improve upon the tut, but hey, it's good to see you're actually getting better with the code Sonire. ^_^
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)