Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  sss
Language: C/C++
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
     printf("Hello World!");
     getchar();
     return 0;
}
import ui,app,chat,chr,net,player,item,skill,time,game,shop,chrmgr

class BuyAndSellBotDialog(ui.ScriptWindow):

     ItemID = 0
     State = 0
     
     def __init__(self):
          ui.ScriptWindow.__init__(self) 
          
          self.Board = ui.ThinBoard()
          self.Board.SetSize(218, 250)
          self.Board.SetCenterPosition()
          self.Board.AddFlag("movable")
          self.Board.Show()
          
          self.comp = Component()
          self.Header = self.comp.TextLine(self.Board, 'Buy & Sell Bot', 65, 8, self.comp.RGB(255, 255, 0))
          self.BarItems, self.ListBoxItems, ScrollItems = self.comp.ListBoxEx(self.Board, 10, 50, 170, 140)
          self.SkillIdNameLabel = self.comp.TextLine(self.Board, 'ID:        Name:', 16, 37, self.comp.RGB(255, 255, 255))
          
          self.Close = self.comp.Button(self.Board, '', 'Close', 183, 8, self.Board.Hide, 'd:/ymir work/ui/public/close_button_01.sub', 'd:/ymir work/ui/public/close_button_02.sub', 'd:/ymir work/ui/public/close_button_03.sub')
          self.Refresh = self.comp.Button(self.Board, '', 'Refresh', 163, 6, self.UpdateItemList, 'd:/ymir work/ui/game/guild/refresh_button_01.sub', 'd:/ymir work/ui/game/guild/refresh_button_02.sub', 'd:/ymir work/ui/game/guild/refresh_button_03.sub')
          self.StartButton = self.comp.Button(self.Board, 'Start', '', 70, 205, self.SetStatus, 'd:/ymir work/ui/public/large_button_01.sub', 'd:/ymir work/ui/public/large_button_02.sub', 'd:/ymir work/ui/public/large_button_03.sub')

          self.UpdateItemList()
          

     def UpdateItemList(self):
          if not shop.IsOpen():
               chat.AppendChat(7, "[M2-BOB] Please open a Shop first!")
               return

          self.ListBoxItems.RemoveAllItems()
          for i in xrange(shop.SHOP_SLOT_COUNT):
               ItemIndex = shop.GetItemID(i)
               if ItemIndex != 0:
                    ItemName = item.GetItemName(item.SelectItem(int(ItemIndex)))
                    self.ListBoxItems.AppendItem(Item(str(ItemIndex) + '    ' + ItemName))
                    
     def SetStatus(self):
          ItemIndex = self.ListBoxItems.GetSelectedItem()
          if ItemIndex:
               pass
          else:
               chat.AppendChat(7, "[M2-BOB] No Item selected!")
               return
               
          if not shop.IsOpen():
               chat.AppendChat(7, "[M2-BOB] Please open a Shop first!")
               return
          
          if self.State:
               self.State = 0
               self.StartButton.SetText("Start")
               self.SellRestItems()
          else:
               self.ItemID = int(ItemIndex.GetText().split("    ")[0])
               self.State = 1
               self.StartButton.SetText("Stop")
               
               
     def OnUpdate(self): 
          if self.State: 
               if shop.IsOpen(): 
                    for EachShopSlot in xrange(shop.SHOP_SLOT_COUNT): 
                         getShopItemID = shop.GetItemID(EachShopSlot) 
                         if getShopItemID == self.ItemID: 
                              price = shop.GetItemPrice(EachShopSlot)
                              if price <= player.GetMoney():
                                   net.SendShopBuyPacket(EachShopSlot) 
                                   break
                              else:
                                   self.State = 1
                                   self.StartButton.SetText("Stop")
          self.SellRestItems()
                                   
     def SellRestItems(self):
          for EachInventorySlot in xrange(45): 
               ItemIndex = player.GetItemIndex(EachInventorySlot) 
               if ItemIndex == self.ItemID: 
                    net.SendShopSellPacket(EachInventorySlot) 
               


class Item(ui.ListBoxEx.Item):
     def __init__(self, fileName):
          ui.ListBoxEx.Item.__init__(self)
          self.canLoad=0
          self.text=fileName
          self.textLine=self.__CreateTextLine(fileName)          

     def __del__(self):
          ui.ListBoxEx.Item.__del__(self)

     def GetText(self):
          return self.text

     def SetSize(self, width, height):
          ui.ListBoxEx.Item.SetSize(self, 6*len(self.textLine.GetText()) + 4, height)

     def __CreateTextLine(self, fileName):
          textLine=ui.TextLine()
          textLine.SetParent(self)
          textLine.SetPosition(0, 0)
          textLine.SetText(fileName)
          textLine.Show()
          return textLine     
               
class Component:
     def Button(self, parent, buttonName, tooltipText, x, y, func, UpVisual, OverVisual, DownVisual):
          button = ui.Button()
          if parent != None:
               button.SetParent(parent)
          button.SetPosition(x, y)
          button.SetUpVisual(UpVisual)
          button.SetOverVisual(OverVisual)
          button.SetDownVisual(DownVisual)
          button.SetText(buttonName)
          button.SetToolTipText(tooltipText)
          button.Show()
          button.SetEvent(func)
          return button
          
     def HideButton(self, parent, buttonName, tooltipText, x, y, func, UpVisual, OverVisual, DownVisual):
          button = ui.Button()
          if parent != None:
               button.SetParent(parent)
          button.SetPosition(x, y)
          button.SetUpVisual(UpVisual)
          button.SetOverVisual(OverVisual)
          button.SetDownVisual(DownVisual)
          button.SetText(buttonName)
          button.SetToolTipText(tooltipText)
          button.SetEvent(func)
          return button

     def ToggleButton(self, parent, buttonName, tooltipText, x, y, funcUp, funcDown, UpVisual, OverVisual, DownVisual):
          button = ui.ToggleButton()
          if parent != None:
               button.SetParent(parent)
          button.SetPosition(x, y)
          button.SetUpVisual(UpVisual)
          button.SetOverVisual(OverVisual)
          button.SetDownVisual(DownVisual)
          button.SetText(buttonName)
          button.SetToolTipText(tooltipText)
          button.Show()
          button.SetToggleUpEvent(funcUp)
          button.SetToggleDownEvent(funcDown)
          return button

     def EditLine(self, parent, editlineText, x, y, width, heigh, max):
          SlotBar = ui.SlotBar()
          if parent != None:
               SlotBar.SetParent(parent)
          SlotBar.SetSize(width, heigh)
          SlotBar.SetPosition(x, y)
          SlotBar.Show()
          Value = ui.EditLine()
          Value.SetParent(SlotBar)
          Value.SetSize(width, heigh)
          Value.SetPosition(8, 2)
          Value.SetMax(max)
          Value.SetLimitWidth(width)
          Value.SetMultiLine()
          Value.SetText(editlineText)
          Value.SetIMEFlag(3)
          Value.Show()
          return SlotBar, Value
          
     def OnlyEditLine(self, parent, width, heigh, x, y, editlineText, max):
          Value = ui.EditLine()
          if parent != None:
               Value.SetParent(parent)
          Value.SetSize(width, heigh)
          Value.SetPosition(x, y)
          Value.SetMax(max)
          Value.SetText(editlineText)
          Value.SetNumberMode()
          Value.Show()
          return Value

     def TextLine(self, parent, textlineText, x, y, color):
          textline = ui.TextLine()
          if parent != None:
               textline.SetParent(parent)
          textline.SetPosition(x, y)
          if color != None:
               textline.SetFontColor(color[0], color[1], color[2])
          textline.SetText(textlineText)
          textline.SetOutline()
          textline.Show()
          return textline

     def RGB(self, r, g, b):
          return (r*255, g*255, b*255)

     def SliderBar(self, parent, sliderPos, func, x, y):
          Slider = ui.SliderBar()
          if parent != None:
               Slider.SetParent(parent)
          Slider.SetPosition(x, y)
          Slider.SetSliderPos(sliderPos)
          Slider.Show()
          Slider.SetEvent(func)
          return Slider

     def ExpandedImage(self, parent, x, y, img):
          image = ui.ExpandedImageBox()
          if parent != None:
               image.SetParent(parent)
          image.SetPosition(x, y)
          image.LoadImage(img)
          image.Show()
          return image
          
     def ComboBoxFunc(self, parent, text, x, y, width, func):
          combo = ui.ComboBox()
          if parent != None:
               combo.SetParent(parent)
          combo.SetPosition(x, y)
          combo.SetSize(width, 15)
          combo.SetCurrentItem(text)
          combo.SetEvent(func)
          combo.Show()
          return combo
          
     def ComboBox(self, parent, text, x, y, width):
          combo = ui.ComboBox()
          if parent != None:
               combo.SetParent(parent)
          combo.SetPosition(x, y)
          combo.SetSize(width, 15)
          combo.SetCurrentItem(text)
          combo.Show()
          return combo

     def ThinBoard(self, parent, moveable, x, y, width, heigh, center):
          thin = ui.ThinBoard()
          if parent != None:
               thin.SetParent(parent)
          if moveable == TRUE:
               thin.AddFlag('movable')
               thin.AddFlag('float')
          thin.SetSize(width, heigh)
          thin.SetPosition(x, y)
          if center == TRUE:
               thin.SetCenterPosition()
          thin.Show()
          return thin

     def Gauge(self, parent, width, color, x, y):
          gauge = ui.Gauge()
          if parent != None:
               gauge.SetParent(parent)
          gauge.SetPosition(x, y)
          gauge.MakeGauge(width, color)
          gauge.Show()
          return gauge
          
     def ListBoxEx(self, parent, x, y, width, heigh):
          bar = ui.Bar()
          if parent != None:
               bar.SetParent(parent)
          bar.SetPosition(x, y)
          bar.SetSize(width + 20, heigh)
          bar.SetColor(1996488704)
          bar.Show()
          ListBox = ui.ListBoxEx()
          ListBox.SetParent(bar)
          ListBox.SetPosition(0, 0)
          ListBox.SetViewItemCount(7)
          ListBox.SetSize(width, heigh)
          ListBox.Show()
          scroll = ui.ScrollBar()
          scroll.SetParent(bar)
          scroll.SetPosition(width + 5, 0)
          scroll.SetScrollBarSize(heigh)
          scroll.Show()
          ListBox.SetScrollBar(scroll)
          return (bar, ListBox, scroll)

     def ListBoxEx2(self, parent, x, y, width, heigh):
          bar = ui.Bar()
          if parent != None:
               bar.SetParent(parent)
          bar.SetPosition(x, y)
          bar.SetSize(width + 20, heigh)
          bar.SetColor(1996488704)
          bar.Show()
          ListBox = ui.ListBoxEx()
          ListBox.SetParent(bar)
          ListBox.SetPosition(0, 0)
          ListBox.SetViewItemCount(5)
          ListBox.SetSize(width, heigh)
          ListBox.Show()
          scroll = ui.ScrollBar()
          scroll.SetParent(bar)
          scroll.SetPosition(width + 5, 0)
          scroll.SetScrollBarSize(heigh)
          scroll.Show()
          ListBox.SetScrollBar(scroll)
          return (bar, ListBox, scroll)     
          
     def FileListBox(self, parent, x, y, width, heigh, count):
          ListBox = ui.ListBoxEx()
          ListBox.SetParent(parent)
          ListBox.SetPosition(x, y)
          ListBox.SetViewItemCount(count)
          ListBox.SetSize(width, heigh)
          ListBox.Show()
          scroll = ui.ScrollBar()
          scroll.SetParent(ListBox)
          scroll.SetPosition(width - 20, 0)
          scroll.SetScrollBarSize(heigh)
          scroll.Show()
          ListBox.SetScrollBar(scroll)
          return ListBox, scroll
          
     def ReadingListBox(self, parent, x, y, width, heigh, count):
          bar = ui.Bar()
          if parent != None:
               bar.SetParent(parent)
          bar.SetPosition(x, y)
          bar.SetSize(width + 20, heigh)
          bar.Show()
          ListBox = ui.ListBoxEx()
          ListBox.SetParent(bar)
          ListBox.SetPosition(10, 13)
          ListBox.SetViewItemCount(count)
          ListBox.SetSize(width, heigh)
          ListBox.Show()
          return bar, ListBox     
     
x = BuyAndSellBotDialog()
x.Show()
          
Comments: