Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use os;
- use util;
- use cfgfile;
- include ":brainAI:eventid";
- include ":brainAI:npcNerves";
- include ":brainAI:npcCommands";
- include ":brainAI:npcUtil";
- include ":merchants:merchant";
- include ":merchants:storage";
- include ":merchants:train";
- include ":gumps:gumps";
- include ":gumps:gumps_ex";
- include ":gumps:requestgump";
- include ":attributes:attributes";
- CONST GCGUMP_X := 75;
- CONST GCGUMP_Y := 150;
- CONST TXT_CLR_FG := 0;
- CONST TXT_CLR_BG := 2100;
- CONST DEFAULT_RESTOCK_INTERVAL := 1200; // 20 minutes
- program BrainNerve(params)
- var npc := params[1];
- //var nerve_name:= params[2];
- var event := params[3];
- //var settings := params[4];
- //var scripts := params[5];
- params := 0; // Not needed anymore.
- var forsale := CPM_GetMerchantContainer(npc, CPM_FORSALE, CP_CREATE);
- var shopping_cart := CPM_GetMerchantContainer(npc, CPM_SHOPPINGCART, CP_CREATE);
- var merchant_type := CPM_GetMerchantType(npc);
- while ( npc )
- if ( event )
- case ( event.type )
- SYSEVENT_DOUBLECLICKED:
- DoubleClickEvent(npc, event, forsale, shopping_cart, merchant_type);
- break;
- default:
- break;
- endcase
- event := 0;
- endif
- SleepMS(5);
- event := Wait_For_Event(900000);
- endwhile
- endprogram
- function DoubleClickEvent(npc, byref event, forsale, shopping_cart, merchant_type)
- sendsysmessage (event.source, "dblclick started");
- var restock_interval;
- if (GetObjProperty(npc,"RestockInterval"))
- restock_interval := CInt(GetObjProperty(npc,"RestockInterval"));
- else
- restock_interval := DEFAULT_RESTOCK_INTERVAL;
- endif
- if (GetObjProperty(npc,"RestockedAt") + restock_interval < ReadGameClock())
- RestockInventory(merchant_type, forsale);
- endif
- gumptest(npc, event.source, forsale, shopping_cart);
- return 1;
- return 1;
- endfunction
- function BuyStuff(npc, mobile, forsale, shopping_cart)
- AI_Turn(npc, mobile, NETURN_TOWARD);
- var result := SendBuyWindow(mobile, forsale, npc, shopping_cart, 1);
- if ( result.errortext )
- PrintTextAbove(npc, "SendBuyWindow() error - "+result.errortext);
- endif
- return 1;
- endfunction
- function gumptest( npc, mobile, forsale, shopping_cart )
- var gflayout := {
- "page 0",
- "nodispose",
- "resizepic 0 0 5170 200 300",
- "text 40 40 50 0", // All radio-values are important and thus
- "text 40 80 50 1", // greater than any button-value [in this example: 1]
- "text 40 120 50 2",
- "text 40 160 50 3",
- "text 40 200 50 4",
- "button 100 40 249 248 1 0 1",
- "button 100 80 249 248 1 0 2",
- "button 100 120 249 248 1 0 3",
- "button 100 160 249 248 1 0 4",
- "button 100 200 249 248 1 0 5"
- };
- var gfdata := {"Buy",
- "Sell",
- "Train",
- "Sell Bag",
- "Sell All"
- };
- var choice := SendDialogGump( mobile, gflayout, gfdata );
- var buyable := CPM_GetMerchantContainer(npc, CPM_BUYING, CP_CREATE);
- var his_choice;
- var output;
- case ( choice[0] )
- 1: output := SendBuyWindow(mobile, forsale, npc, shopping_cart, 1);
- 2: output := SellStuff(mobile, buyable, npc, shopping_cart, 1);
- 3: output := TrainStuff(npc, mobile);
- 4: output := SellBag(npc,mobile);
- 5: output := SellAll(npc, mobile);
- default: output := "The player must have canceled the gump without doing anything";
- // default means if the value is neither 1 nor any of the radio-values
- // [so the player canceled the gump without doing anything]. In this example it doesn't matter
- // whether you press the okay-button or not, the values are counted anyways. This is because
- // it is not important for this example. If you're writing a gump and want it to work correctly
- // you should embed a test if the okay-button was pressed
- // [like this: if ( choice[0] == 1 ) <- then the player has pressed the okay-button.
- // Why? You should know]
- endcase
- endfunction
Add Comment
Please, Sign In to add comment