Mirage Source
http://miragesource.net/forums/

How Could I...
http://miragesource.net/forums/viewtopic.php?f=201&t=4329
Page 1 of 12

Author:  DarkC [ Mon Sep 15, 2008 11:32 pm ]
Post subject:  How Could I...

I'm trying to make a code that checks a player's inventory, and if they have a certain item in their inventory and they type something, then it activates. I hope that makes sense...But I don't know how to check a player's inventory and check the items they have's names.

Can anyone tell me how to do that?

Author:  Lea [ Mon Sep 15, 2008 11:34 pm ]
Post subject:  Re: How Could I...

make a text command that send a packet to the server. In that packet handler server side, check the person has the item in their inventory (there is already a function that does that, HasItem) and do whatever you want to do if they have it.

should be pretty easy, depending on what you want to do.

Author:  DarkC [ Mon Sep 15, 2008 11:48 pm ]
Post subject:  Re: How Could I...

Never used HasItem before...So would this work? I'm use MS4, and I have this in modHandleData

I'm still learning VB6, so please excuse my mistakes. Up till now, I've just edited other people's code to fit what I need. This is my first code that I've started from scratch...

Author:  Lea [ Mon Sep 15, 2008 11:57 pm ]
Post subject:  Re: How Could I...

DarkC wrote:
Never used HasItem before...So would this work? I'm use MS4, and I have this in modHandleData

I'm still learning VB6, so please excuse my mistakes. Up till now, I've just edited other people's code to fit what I need. This is my first code that I've started from scratch...

Code:
        ' :::::::::::::::::
        ' :: AIDA Packet ::
        ' :::::::::::::::::
        Case CAida
        If HasItem(Index) = "AIDA" Then
            Call Aida(Index)
        Exit Sub


Look at the definition of the function, you're using it wrong.

It returns a boolean, and it takes the item number as an arguement

If HasItem(Index, ItemNum) Then
...

Author:  DarkC [ Tue Sep 16, 2008 12:05 am ]
Post subject:  Re: How Could I...

So then this should work, correct? Thanks for your help. And it'll check if they have the item that is number 200 right?

(this is in modGameLogic in the Client)
Code:
        ' AIDA command
        If Mid$(MyText, 1, 5) = "/aida" Then
            MyText = Mid$(MyText, 5, Len(MyText) - 4)
            Call SendData(CAida & END_CHAR)
        End If
            MyText = ""
        Exit Sub
    End If


(this is in modHandleData in the server)
Code:
        ' :::::::::::::::::
        ' :: AIDA Packet ::
        ' :::::::::::::::::
        Case CAida
        If HasItem(Index, 200) Then
            Call Aida(Index)
        Exit Sub

Author:  Lea [ Tue Sep 16, 2008 12:22 am ]
Post subject:  Re: How Could I...

Looks fine, should work.

Author:  DarkC [ Tue Sep 16, 2008 12:55 am ]
Post subject:  Re: How Could I...

Alrighty...Thanks allot.

Now, when I try to compile the code. It's giving me an error on this...It was working fine before I added the AIDA code, I added the AIDA code above the CKillPlayer code, if that matters. It's highlighting "Case CKillPlayer" and giving me this error "Case Without Select Case". What do I do to fix it? It was working fine before...

Code:
        ' ::::::::::::::::::::::::
        ' :: Kill Player Packet ::
        ' ::::::::::::::::::::::::
Case CKillPlayer
' Prevent hacking
If GetPlayerAccess(Index) < ADMIN_CREATOR Then
Call HackingAttempt(Index, "Admin Cloning")
Exit Sub
End If

n = FindPlayer(Parse(1))

If n <> Index Then
If n > 0 Then
'Sends messages out
Call PlayerMsg(n, "You have been killed by an admin.", BrightRed)
Call GlobalMsg(GetPlayerName(n) & " has been killed by an admin.", BrightRed)
'Warp to starting map
Call PlayerWarp(n, START_MAP, START_X, START_Y)
Call SetPlayerPK(Index, NO)
Else
Call PlayerMsg(Index, "Player is not online.", White)
End If
Else
Call PlayerMsg(Index, "You cannot kill yourself!", White)
End If

Exit Sub

Author:  Lea [ Tue Sep 16, 2008 1:03 am ]
Post subject:  Re: How Could I...

You need an End If to close off the If statement in your AIDA packet.

Author:  DarkC [ Tue Sep 16, 2008 1:19 am ]
Post subject:  Re: How Could I...

Thank you once again, that fixed it...But now I have a new problem when I compile it. lol

I'm getting an error in this part of my code.
Code:
Public Sub Aida()
    SetPlayerVital(Index, HP) = GetPlayerMaxVital(Index, HP) + 5000
End Sub


It's highlighting "SetPlayerVital(Index, HP) =" and saying "Argument not optional". I've never gotten that error before, so I have no clue what it means. =/

Author:  Nean [ Tue Sep 16, 2008 1:20 am ]
Post subject:  Re: How Could I...

DarkC wrote:
Thank you once again, that fixed it...But now I have a new problem when I compile it. lol

I'm getting an error in this part of my code.
Code:
Public Sub Aida()
    SetPlayerVital(Index, HP) = GetPlayerMaxVital(Index, HP) + 5000
End Sub


It's highlighting "SetPlayerVital(Index, HP) =" and saying "Argument not optional". I've never gotten that error before, so I have no clue what it means. =/


Try putting MyIndex, instead of index.

Author:  DarkC [ Tue Sep 16, 2008 1:23 am ]
Post subject:  Re: How Could I...

I put MyIndex, and it's giving me the same error.

Author:  Lea [ Tue Sep 16, 2008 1:39 am ]
Post subject:  Re: How Could I...

MyIndex is only client side

You're using the function wrong again, pay attention!

Author:  DarkC [ Tue Sep 16, 2008 1:44 am ]
Post subject:  Re: How Could I...

What am I doing wrong? I looked and I don't get it...How can I tell what the correct way of using it is?

Author:  Jacob [ Tue Sep 16, 2008 1:45 am ]
Post subject:  Re: How Could I...

Argument not optional - Check what you need to pass to that function

Author:  DarkC [ Tue Sep 16, 2008 1:48 am ]
Post subject:  Re: How Could I...

Then like this? Sorry about all the trouble. :(

Code:
Public Sub Aida()
    SetPlayerVital(Index, HP, GetPlayerMaxVital) = 5000
End Sub

Author:  Lea [ Tue Sep 16, 2008 2:08 am ]
Post subject:  Re: How Could I...

You don't set functions equal to anything.

Author:  DarkC [ Tue Sep 16, 2008 2:09 am ]
Post subject:  Re: How Could I...

Well when I don't have a = in there somewhere, it makes the text read and says it exspects a = .

Author:  Lea [ Tue Sep 16, 2008 2:16 am ]
Post subject:  Re: How Could I...

That's a nusiance of VB6.

Add "Call" before it

Or remove the outermost parentheses.

Author:  DarkC [ Tue Sep 16, 2008 2:22 am ]
Post subject:  Re: How Could I...

Ok...I added call to it, and now it's highlighting GetPlayerMaxVital and giving the same error. :oops:

Author:  Rian [ Tue Sep 16, 2008 2:35 am ]
Post subject:  Re: How Could I...

Then do the same thing to fix it.

Author:  Lea [ Tue Sep 16, 2008 2:36 am ]
Post subject:  Re: How Could I...

GetPlayerMaxVital is a function, and it takes arguements. Check it's definition.

Author:  DarkC [ Tue Sep 16, 2008 2:44 am ]
Post subject:  Re: How Could I...

But how can I have it be Called when it's in the parentheses? Because doesn't it have to be there? Because that's where the Value is supposed to be in the SetPlayerVital...

Author:  Rian [ Tue Sep 16, 2008 2:48 am ]
Post subject:  Re: How Could I...

Functions don't need a call. You can just do

GetPlayerMaxVital(index, whatever, whatever)

Author:  Anthony [ Tue Sep 16, 2008 2:50 am ]
Post subject:  Re: How Could I...

Does your code still look like this?
Code:
Public Sub Aida()
    SetPlayerVital(Index, HP, GetPlayerMaxVital) = 5000
End Sub


If so, look at the SetPlayerVital sub.

Code:
Sub SetPlayerVital(ByVal Index As Long, ByVal Vital As Vitals, ByVal Value As Long)


Just that part is all that really matters.

You are setting it to the Index (which would be your player number), which vital do you want to set, then the value you want to set it to. Make sense?

So if you want to set your vital hp to 5000 then your code should look like this.

Code:
Public Sub Aida()
    Call SetPlayerVital(Index, Vitals.HP, 5000)
End Sub


I am not exactly sure what you are trying to do?

Author:  DarkC [ Tue Sep 16, 2008 2:52 am ]
Post subject:  Re: How Could I...

Never mind! Thank you, Anthony. That helped me perfectly.

Thank you all for your help.

Page 1 of 12 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/