Hello everyone... I was just curious if anyone had a more efficient and equally as quick of a way to do an inventory system for my online rpg. My biggest concern is the ability to add special attributes. I sorta have that covered with the effects of each item... 5 effects, with separate values. The problem lies with the sheer number of them. In order to have a lot of unique weapons for example, I need slots. I have increase the memory allocation from $FFFF to higher and code some sort of automated indexing app to make and balance weapons. The problem is that it kinda limits the number and uniqueness of them. Any help is greatly appreciated.
; * note, icons and drawing were removed to make ; this executable without 5mb of images haha ;) Type item Field index% Field name$ Field item_type% Field icon_image Field model_index% Field texture_index% Field rarity% Field cost% Field REQ_LVL% Field REQ_RACE% Field REQ_STR% Field REQ_AGL% Field REQ_INT% Field Hides_hair Field Hides_legs Field Weapon_class Field Base_DMG Field Max_DMG Field Range Field Speed Field Armor_class Field Base_Def Field effect1% Field effect1_var% Field effect2% Field effect2_var% Field effect3% Field effect3_var% Field effect4% Field effect4_var% Field effect5% Field effect5_var% End Type Dim item_index($FFFF) Type inventory Field name$ Field row Field col Field index% Field window_x% Field window_y% Field active Field tot_rows% Field tot_cols% End Type Global mouse_has_item=False Global mouse_grab_item=0 Global inv_picked_name$="" Global inv_picked_row%="" Global inv_picked_col%="" Global inventory_window_open=-1 ; ########################################## ; ; Erase this non-important carp ; ; ########################################## Graphics3D 800,600,32,2 Global cube=CreateCube() Global camera=CreateCamera() Global light=CreateLight() RotateEntity light,45,0,0 PositionEntity cube,0,0,5 ;load_icons() Temp_Setup() While KeyDown(1)=False time=MilliSecs() RenderWorld() test_carp() If inventory_window_open=True Then Display_Inventory("My Inventory") If inventory_window_open=True Then Display_Inventory("Chest Inventory") If KeyHit(23)=True Then inventory_window_open=inventory_window_open * -1 Do_mouse() ctime=MilliSecs() - time Text 0,0,ctime Flip Wend Function test_carp() TurnEntity cube,0.5,0.5,0.5 End Function Function Temp_setup() For Makeshit=0 To $FFFF A.item=New item a\index%=makeshit a\name$="Item #" + Makeshit item_index(makeshit) = Handle(a) If makeshit > 0 Then a\icon_image=Rand(0,$FF) Else A\icon_image=0 Next ; For randomizer =1 To $FFFF ; get$= item_name$(Rand(1,$FFFF)) ; Next new_inventory("My Inventory",4,5,15,100) new_inventory("Chest Inventory",2,2,400,250) add_inventory("My Inventory",1,1,$0013) add_inventory("My Inventory",1,4,$0022) add_inventory("My Inventory",2,1,$FFFF) End Function ; ########################################## ; ; Client Interaction ; ; ########################################## Function Do_mouse() Local Mx=MouseX() Local My=MouseY() If inventory_window_open=True Then Item% = mouse_over_item("index") If item% <> 0 And mouse_has_item=False Then show_item_details(item%) If mouse_in_use=False Then If MouseHit(1)=True Then in_row%=mouse_over_item("row") in_col%=mouse_over_item("col") in_inventory$=Str$(mouse_over_item("inventory")) If mouse_has_item=False Then ; mouse_in_use=True Text 10,550,"Item selected:" + item_name(item%) DebugLog in_inventory$ + ", " + in_row% + ", " + in_col% If mouse_over_item("index") > 0 Then freeze_inventory(in_inventory$,in_row%,in_col%) mouse_has_item=True mouse_grab_item=mouse_over_item("index") inv_picked_name$=in_inventory$ inv_picked_row%=in_row% inv_picked_col%=in_col% DebugLog "Mouse has item? " + mouse_has_item + " and item is: " + mouse_grab_item End If Else If mouse_over_item("index") = 0 Then add_inventory(in_inventory$,in_row%,in_col%,mouse_grab_item) mouse_has_item=False remove_inventory(inv_picked_name$,inv_picked_row%,inv_picked_col%) inv_picked_name$="" inv_picked_row%="" inv_picked_col%="" End If End If End If If MouseHit(2)=True Then mouse_in_use=True in_row%=mouse_over_item("row") in_col%=mouse_over_item("col") in_inventory$=Str$(mouse_over_item("inventory")) DebugLog in_inventory$ + ", " + in_row% + ", " + in_col% remove_inventory(in_inventory$,in_row%,in_col%) End If mouse_in_use=False End If If mouse_has_item=True And mouse_grab_item > 0 Then Color 255,255,0 Rect Mx,My,50,50,1 ; DrawImage icon(item_icon(mouse_grab_item)),Mx,My End If End If End Function Function show_item_details(index%) Local Mx=MouseX() Local My=MouseY() Local I.item I = Object.item( item_index(index%) ) Color 50,50,50 Rect Mx,My,200,75,1 Color 255,255,255 Text Mx + 5, My + 5, "Item name: " + I\name$ Color 190,190,190 Text Mx + 5, My + 15, "Item index: " + I\index% Text Mx + 5, My + 25, "Item type: " + I\item_type% Text Mx + 5, My + 35, "Sell Value: " + I\cost% End Function Function mouse_over_item$(Need$) Local mx=MouseX() Local my=MouseY() For I.inventory=Each inventory IX = I\row * 50 - 50 + I\window_X IY = I\col * 50 - 50 + I\window_Y If Mx > IX And Mx < IX + 50 And My > IY And My < IY + 50 Then Color 255,0,0 Rect IX,IY,50,50,1 If Need$="index" Then Return I\index If Need$="row" Then Return I\row If Need$="col" Then Return I\col If Need$="inventory" Then Return I\name$ End If Next End Function Function remove_inventory(Name$,row%,col%) For I.inventory=Each inventory If I\name$ = Name$ And I\row%=row% And I\col%=col% Then I\index%=0 End If Next End Function Function add_inventory(Name$,row%,col%,index%) For I.inventory=Each inventory If I\name$ = Name$ And I\row%=row% And I\col%=col% Then I\index%=index% I\row%=row% I\col%=col% I\name$=Name$ End If Next End Function Function freeze_inventory(Name$,row%,col%) For I.inventory=Each inventory If I\name$ = Name$ And I\row%=row% And I\col%=col% I\active = True End If Next End Function Function Display_Inventory(name$) For I.inventory=Each inventory If I\Name$ = name$ Then Color 0,255,255 Rect I\window_x% + I\row * 50 - 50,I\window_y% + I\col * 50 - 50,50,50,1 ; DrawImage icon(item_icon(I\index%)),I\window_x% + I\row * 50 - 50,I\window_y% + I\col * 50 - 50 End If Next End Function Function new_inventory(name$,across%,down%,winx%,winy%) For rows%=1 To across% For cols% = 1 To down% I.inventory = New Inventory I\name$=name$ I\row=rows% I\col=cols% I\index$=0;Rand($00,$FFFF) I\window_x% = winx% I\window_y% = winy% I\Tot_rows% = across% I\Tot_cols% = down% Next Next End Function Function item_icon(index%) Local I.item I = Object.item( item_index(index%) ) Return I\icon_image% End Function Function icon(index%) ; Local I.icon ; I = Object.icon( icon_index(index%) ) ; Return I\image End Function Function item_name$(index%) Local I.item I = Object.item( item_index(index%) ) Return I\name$ End Function