I’m trying to randomise the event ‘drawShop’ so that it’s about a 25% chance to activate it on touch. (For Eclipse Advance v3.0)

What part of this code would I modify to change it from ‘always open gui’ to ‘25% chance to open gui_shop’?

Public Sub DrawShop()

Dim I As Long, X As Long, Y As Long, itemNum As Long, ItemPic As Long, Left As Long, Top As Long, Amount As Long, colour As Long

Dim Width As Long, Height As Long

' render the window

Width = GUIWindow(GUI_SHOP).Width

Height = GUIWindow(GUI_SHOP).Height

'EngineRenderRectangle Tex_GUI(23), GUIWindow(GUI_SHOP).x, GUIWindow(GUI_SHOP).y, 0, 0, width, height, width, height, width, height

RenderTexture Tex_GUI(20), GUIWindow(GUI_SHOP).X, GUIWindow(GUI_SHOP).Y, 0, 0, Width, Height, Width, Height

' render the shop items


	 itemNum = Shop(InShop).TradeItem(I).Item

	 If itemNum > 0 And itemNum <= MAX_ITEMS Then

		 ItemPic = Item(itemNum).Pic

		 If ItemPic > 0 And ItemPic <= numitems Then

			 Top = GUIWindow(GUI_SHOP).Y + ShopTop + ((ShopOffsetY + 32) * ((I - 1) \ ShopColumns))

			 Left = GUIWindow(GUI_SHOP).X + ShopLeft + ((ShopOffsetX + 32) * (((I - 1) Mod ShopColumns)))

			 'EngineRenderRectangle Tex_Item(itempic), left, top, 0, 0, 32, 32, 32, 32, 32, 32

			 RenderTexture Tex_Item(ItemPic), Left, Top, 0, 0, 32, 32, 32, 32

			 ' If item is a stack - draw the amount you have

			 If Shop(InShop).TradeItem(I).ItemValue > 1 Then

				 Y = GUIWindow(GUI_SHOP).Y + Top + 22

				 X = GUIWindow(GUI_SHOP).X + Left - 4

				 Amount = CStr(Shop(InShop).TradeItem(I).ItemValue)

				 ' Draw currency but with k, m, b etc. using a convertion function

				 If CLng(Amount) < 1000000 Then

					 colour = White

				 ElseIf CLng(Amount) > 1000000 And CLng(Amount) < 10000000 Then

					 colour = Yellow

				 ElseIf CLng(Amount) > 10000000 Then

					 colour = BrightGreen

				 End If

				 RenderText Font_Default, ConvertCurrency(Amount), X, Y, colour

			 End If

		 End If

	 End If


' draw buttons

For I = 23 To 23

	 ' set co-ordinate

	 X = GUIWindow(GUI_SHOP).X + Buttons(I).X

	 Y = GUIWindow(GUI_SHOP).Y + Buttons(I).Y

	 Width = Buttons(I).Width

	 Height = Buttons(I).Height

	 ' check for state

	 If Buttons(I).state = 2 Then

		 ' we're clicked boyo

		 'EngineRenderRectangle Tex_Buttons_c(Buttons(i).PicNum), x, y, 0, 0, width, height, width, height, width, height

		 RenderTexture Tex_Buttons_c(Buttons(I).PicNum), X, Y, 0, 0, Width, Height, Width, Height

	 ElseIf (GlobalX >= X And GlobalX <= X + Buttons(I).Width) And (GlobalY >= Y And GlobalY <= Y + Buttons(I).Height) Then

		 ' we're hoverin'

		 'EngineRenderRectangle Tex_Buttons_h(Buttons(i).PicNum), x, y, 0, 0, width, height, width, height, width, height

		 RenderTexture Tex_Buttons_h(Buttons(I).PicNum), X, Y, 0, 0, Width, Height, Width, Height

		 ' play sound if needed

		 If Not lastButtonSound = I Then

			 PlaySound Sound_ButtonHover, -1, -1

			 lastButtonSound = I

		 End If


		 ' we're normal

		 'EngineRenderRectangle Tex_Buttons(Buttons(i).PicNum), x, y, 0, 0, width, height, width, height, width, height

		 RenderTexture Tex_Buttons(Buttons(I).PicNum), X, Y, 0, 0, Width, Height, Width, Height

		 ' reset sound if needed

		 If lastButtonSound = I Then lastButtonSound = 0

	 End If


' draw item descriptions


End Sub

cheers ;)

You’ll need to be server-side where it handles the actual event, not on the client where it draws it. Even if you disable drawing it, the shop would be open.

Alright, where could I add a randomiser in this code then? :D

' Check for a shop, and if so open it

	    If .Type = TILE_TYPE_SHOP Then

		    x = .Data1

		    If x > 0 Then ' shop exists?

			    If Len(Trim$(Shop(x).Name)) > 0 Then ' name exists?

				    SendOpenShop index, x

				    TempPlayer(index).InShop = x ' stops movement and the like

			    End If

		    End If

	    End If

That’s the tile type, not the event! I would find it for you, but I’m at work so I have to do this from what I can remember, so not sure where exactly the code you need is located.

How about this:

Case Evt_OpenShop

				    Call SendOpenShop(index, .Data(1))

				    TempPlayer(index).InShop = .Data(1)

				    GoTo EventQuit

or this:

Sub SendOpenShop(ByVal index As Long, ByVal shopNum As Long)

    Dim Buffer As clsBuffer

    Set Buffer = New clsBuffer

    Buffer.WriteLong SOpenShop

    Buffer.WriteLong shopNum

    SendDataTo index, Buffer.ToArray()

    Set Buffer = Nothing

End Sub

also, I must be tripping, because I thought the comment in the code i posted earlier would mean that was it. I mean,

’ Check for a shop, and if so open it

the open it part, couldn’t that be edited?

The code you posted earlier was for the Tile Attribute that opens a shop, the new code you posted is the stuff that handles an event, which is what you asked for.

Anyway, here’s the changed code that opens it 1/4 times (25%):

Case Evt_OpenShop

    ' Let's randomize this!

    If Rand(1,4) = 1 ' It should only be 1 in 1 out of 4 cases, so ~25%ish

     Call SendOpenShop(index, .Data(1))

     TempPlayer(index).InShop = .Data(1)

    End If

    GoTo EventQuit

Thanks for the help.

Log in to reply