Mirage Source
Message loop - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17)
+---- Thread: Message loop (/showthread.php?tid=478)



Message loop - Matt - 16-12-2006

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?


- Obsidian - 16-12-2006

Edit... can't delete this.

Kite said almost the exact thing that i did...


- Robin - 16-12-2006

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



- Matt - 16-12-2006

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



- Obsidian - 16-12-2006

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


- Matt - 16-12-2006

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.


- Obsidian - 16-12-2006

After it finds the item... just do a

Code:
exit for



- Matt - 16-12-2006

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.


- halla - 16-12-2006

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?


- Matt - 16-12-2006

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



- Obsidian - 16-12-2006

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...


- Matt - 16-12-2006

Huh? Lol. Can you show me what you mean?


- Matt - 16-12-2006

Oh okay. Good point. Didn't notice that. Thanks alot guys. ^_^