Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Message loop
#1
I need to make a message display after it checks the inventory for a certain item. But I only want it to display once, currently, if it can't find that item, then it will display the message once for each inventory slot.

Any idea how to fix this?
Reply
#2
Edit... can't delete this.

Kite said almost the exact thing that i did...
Reply
#3
Put it after the loop instead of during?

Code:
If loop = false + no item = gay then
   sendmessage("Fag, no item!")
else
   sendmessage("You hand him the gay")
end if
Reply
#4
This is the sub I need it for:

Code:
Sub PlayerCreateGuild(ByVal Index As Long)
Dim Packet As String
Dim d As Integer

For d = 1 To MAX_INV
    If GetPlayerInvItemNum(Index, d) = 1 And GetPlayerInvItemValue(Index, d) >= 500000 Then
        Packet = "GUILDNPC" & END_CHAR
        Call SendDataTo(Index, Packet)
    ElseIf GetPlayerInvItemNum(Index, d) = 1 And GetPlayerInvItemValue(Index, d) < 500000 Then
        Call PlayerMsg(Index, "You need 500,000 gold to register a guild.", BrightRed)
    ElseIf GetPlayerInvItemNum(Index, d)  1 Then
        Call PlayerMsg(Index, "You need 500,000 gold to register a guild.", BrightRed)
    End If
Next d

End Sub
Reply
#5
Code:
If Item(GetPlayerInvItemnum(Index, d)).Type = ITEM_TYPE_CURRENCY and Trim$(Item(GetPlayerInvItemNum(Index, d)).Name) = "Gold" then


And get with me soon... i have an entire guild system setup that's exactly like what you're attempting to do... i'll let you have a look at it. Smile
Reply
#6
I've tried that, it still loops through the inventory, displaying the message for each slot.

I think someone once told me to use an exit for somewhere in there and that would fix it. I don't remember.
Reply
#7
After it finds the item... just do a

Code:
exit for
Reply
#8
That's what I thought. I added it in, if I don't have any money, it displays once, but if I have some, but not enough, it displays it twice. Going to try something real quick. I will let you know if it works.
Reply
#9
Probably a crappy way to do it but couldnt you just...

if they have enough stuff then you set a variable such as.... ENOUGHGOLD = 1

Then right before the exit sub you have something like...

if ENOUGHGOLD 1 Then

msg "You do not have enough money!"

something along those lines?
Reply
#10
I just added another exit for and it's fine. Sub is like this now:

Code:
Sub PlayerCreateGuild(ByVal Index As Long)
Dim Packet As String
Dim d As Integer

For d = 1 To MAX_INV
    If GetPlayerInvItemNum(Index, d) = 1 And GetPlayerInvItemValue(Index, d) >= 500000 Then
        Packet = "GUILDNPC" & END_CHAR
        Call SendDataTo(Index, Packet)
    ElseIf GetPlayerInvItemNum(Index, d) = 1 And GetPlayerInvItemValue(Index, d) < 500000 Then
        Call PlayerMsg(Index, "You need 500,000 gold to register a guild.", BrightRed)
        Exit For
    ElseIf GetPlayerInvItemNum(Index, d)  1 Then
        Call PlayerMsg(Index, "You need 500,000 gold to register a guild.", BrightRed)
        Exit For
    End If
Next d

End Sub
Reply
#11
You should add a for after the initial if line as well...

if you don't it's going to go through the loop again that many more times... and continue looking for it... even though it's already found it...
Reply
#12
Huh? Lol. Can you show me what you mean?
Reply
#13
Oh okay. Good point. Didn't notice that. Thanks alot guys. ^_^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)