Guest User

Untitled

a guest
May 27th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. use os;
  2. use util;
  3. use cfgfile;
  4.  
  5. include ":brainAI:eventid";
  6. include ":brainAI:npcNerves";
  7. include ":brainAI:npcCommands";
  8. include ":brainAI:npcUtil";
  9. include ":merchants:merchant";
  10. include ":merchants:storage";
  11. include ":merchants:train";
  12.  
  13. include ":gumps:gumps";
  14. include ":gumps:gumps_ex";
  15. include ":gumps:requestgump";
  16.  
  17. include ":attributes:attributes";
  18.  
  19. CONST GCGUMP_X := 75;
  20. CONST GCGUMP_Y := 150;
  21. CONST TXT_CLR_FG := 0;
  22. CONST TXT_CLR_BG := 2100;
  23. CONST DEFAULT_RESTOCK_INTERVAL := 1200; // 20 minutes
  24.  
  25. program BrainNerve(params)
  26. var npc := params[1];
  27. //var nerve_name:= params[2];
  28. var event := params[3];
  29. //var settings := params[4];
  30. //var scripts := params[5];
  31. params := 0; // Not needed anymore.
  32.  
  33.  
  34. var forsale := CPM_GetMerchantContainer(npc, CPM_FORSALE, CP_CREATE);
  35.  
  36. var shopping_cart := CPM_GetMerchantContainer(npc, CPM_SHOPPINGCART, CP_CREATE);
  37.  
  38. var merchant_type := CPM_GetMerchantType(npc);
  39.  
  40. while ( npc )
  41. if ( event )
  42. case ( event.type )
  43. SYSEVENT_DOUBLECLICKED:
  44. DoubleClickEvent(npc, event, forsale, shopping_cart, merchant_type);
  45. break;
  46. default:
  47. break;
  48. endcase
  49.  
  50. event := 0;
  51. endif
  52.  
  53. SleepMS(5);
  54. event := Wait_For_Event(900000);
  55.  
  56. endwhile
  57. endprogram
  58.  
  59. function DoubleClickEvent(npc, byref event, forsale, shopping_cart, merchant_type)
  60. sendsysmessage (event.source, "dblclick started");
  61. var restock_interval;
  62.  
  63. if (GetObjProperty(npc,"RestockInterval"))
  64. restock_interval := CInt(GetObjProperty(npc,"RestockInterval"));
  65. else
  66. restock_interval := DEFAULT_RESTOCK_INTERVAL;
  67. endif
  68.  
  69. if (GetObjProperty(npc,"RestockedAt") + restock_interval < ReadGameClock())
  70. RestockInventory(merchant_type, forsale);
  71. endif
  72.  
  73. gumptest(npc, event.source, forsale, shopping_cart);
  74. return 1;
  75.  
  76. return 1;
  77. endfunction
  78.  
  79. function BuyStuff(npc, mobile, forsale, shopping_cart)
  80.  
  81. AI_Turn(npc, mobile, NETURN_TOWARD);
  82. var result := SendBuyWindow(mobile, forsale, npc, shopping_cart, 1);
  83. if ( result.errortext )
  84. PrintTextAbove(npc, "SendBuyWindow() error - "+result.errortext);
  85. endif
  86.  
  87. return 1;
  88. endfunction
  89.  
  90. function gumptest( npc, mobile, forsale, shopping_cart )
  91. var gflayout := {
  92. "page 0",
  93. "nodispose",
  94. "resizepic 0 0 5170 200 300",
  95. "text 40 40 50 0", // All radio-values are important and thus
  96. "text 40 80 50 1", // greater than any button-value [in this example: 1]
  97. "text 40 120 50 2",
  98. "text 40 160 50 3",
  99. "text 40 200 50 4",
  100. "button 100 40 249 248 1 0 1",
  101. "button 100 80 249 248 1 0 2",
  102. "button 100 120 249 248 1 0 3",
  103. "button 100 160 249 248 1 0 4",
  104. "button 100 200 249 248 1 0 5"
  105. };
  106. var gfdata := {"Buy",
  107. "Sell",
  108. "Train",
  109. "Sell Bag",
  110. "Sell All"
  111. };
  112.  
  113. var choice := SendDialogGump( mobile, gflayout, gfdata );
  114. var buyable := CPM_GetMerchantContainer(npc, CPM_BUYING, CP_CREATE);
  115. var his_choice;
  116.  
  117. var output;
  118. case ( choice[0] )
  119. 1: output := SendBuyWindow(mobile, forsale, npc, shopping_cart, 1);
  120. 2: output := SellStuff(mobile, buyable, npc, shopping_cart, 1);
  121. 3: output := TrainStuff(npc, mobile);
  122. 4: output := SellBag(npc,mobile);
  123. 5: output := SellAll(npc, mobile);
  124. default: output := "The player must have canceled the gump without doing anything";
  125.  
  126. // default means if the value is neither 1 nor any of the radio-values
  127. // [so the player canceled the gump without doing anything]. In this example it doesn't matter
  128. // whether you press the okay-button or not, the values are counted anyways. This is because
  129. // it is not important for this example. If you're writing a gump and want it to work correctly
  130. // you should embed a test if the okay-button was pressed
  131. // [like this: if ( choice[0] == 1 ) <- then the player has pressed the okay-button.
  132. // Why? You should know]
  133. endcase
  134.  
  135.  
  136.  
  137. endfunction
Add Comment
Please, Sign In to add comment