Talis Posted November 11, 2013 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 7 Reputation: 2 Joined: 11/06/13 Last Seen: November 25, 2013 Share Posted November 11, 2013 File Name: Script command: Dynprompt File Submitter: Talis File Submitted: 08 Nov 2013 File Category: Source Modifications Content Author: Talis Works like prompt(), but lets you specify return values by adding a pipe symbol. Examples: dynprompt("Menu Entry"); Return Value: 1 @menu: 1 @menustr$: Menu Entry @menunum: 1 dynprompt("^EE0000Menu Entry^000000|Test"); Return Value: 1 @menu: 1 @menustr$: Test @menunum: 1 dynprompt("Shazam|5 Shazam"); Return Value: 5 @menu: 1 @menustr$: 5 Shazam @menunum: 5 Script example: // Dynprompt usage - Advanced example// Probably the best way to use thisfunction script dynprompt_sample3 { // The real power of dynprompt is that you can specify the return value for each menu element. // The return value is a atoi of the string following the pipe | - the full string can be accessed through @menustr$ // The atoi val can also be accessed through @menunum // If you want to use both number & string, the number has to come first else atoi won't work // Use the pipe character | to denote the return value - best to work with numbers, but strings work as well set .@menu$[0], "^009900Hello!^000000|1Hello"; set .@menu$[1], "^0000EEInfo~^000000|2Info"; set .@menu$[2], "^222222Test.^000000|3Test"; // This time we'll just add a element based on a condition if(.@somecondition) set .@menu$[3], "^EE0000- Admin -^000000|4Admin"; set .@menu$[4], "^990099G'bye^000000|5Bye"; // Lets implode & switch/case switch(dynprompt(implode(.@menu$, ":"))) { case 1: mes "Oh, Hello to you too!"; break; case 2: mes "You want info? How about the time?"; mes gettimestr("%Y-%m/%d %H:%M:%S",21); mes "Also, you selected option #" + @menu; // @menu still works break; case 3: mes "Debug info:"; mes "@menu is " + @menu; mes "@menustr$ is " + @menustr$; mes "@menunum is " + @menunum; break; case 4: mes "Wow, a admin!"; break; case 5: mes "Bye bye~"; break; case 255: // Cancel button mes "Hey, don't ignore me!!"; break; } close;} I havn't tested it yet in production, but so far I havn't been able to encounter any issues with it. Also, I do all my eAthena devving on a windows box so I can't guarantee that it'll work with linux. Performance of dynprompt is going to be naturally worse than prompt, select or menu, but it might perform equally well in a dynamic setting if you take into consideration the array looping usually required - but I have not yet done any benchmarking or anything, so don't take my word for it. ( and to be honest, being able to create super clean code using switch / case is worth a tiny performance hit for me ) I hope it will make your scripting less painful - it sure has for me! Click here to download this file Quote Link to comment Share on other sites More sharing options...
Akinari Posted November 11, 2013 Group: Members Topic Count: 32 Topics Per Day: 0.01 Content Count: 247 Reputation: 207 Joined: 10/23/12 Last Seen: March 2, 2022 Share Posted November 11, 2013 Perhaps you might not mind placing the command in src/custom/script.inc and script_def.inc? Example: http://rathena.org/board/topic/88908-script-command-getrandmob/ Just trying to push people to use what's available. Quote Link to comment Share on other sites More sharing options...
Talis Posted November 12, 2013 Group: Members Topic Count: 1 Topics Per Day: 0.00 Content Count: 7 Reputation: 2 Joined: 11/06/13 Last Seen: November 25, 2013 Author Share Posted November 12, 2013 Perhaps you might not mind placing the command in src/custom/script.inc and script_def.inc? Example: http://rathena.org/board/topic/88908-script-command-getrandmob/ Just trying to push people to use what's available. Hey, I hope I won't be stepping on anyones toes, but I actually dev on a pretty customized version of eAthena, which doesn't have that functionality, else I would definitely make use of it. Looking at the example you linked, it should be really easy actually for people to make use of the custom folder functionality. I didn't provide diffs, just raw source, so the only thing that changes is where you copy & paste it to, right? Hm .. I might put up a new zip file soon where I mention that it can be put either in script.c or in script.inc So.. If you have the custom folder, throw it in the script.inc and script_def.inc instead of directly into script.c! Quote Link to comment Share on other sites More sharing options...
Akinari Posted November 12, 2013 Group: Members Topic Count: 32 Topics Per Day: 0.01 Content Count: 247 Reputation: 207 Joined: 10/23/12 Last Seen: March 2, 2022 Share Posted November 12, 2013 Yes, it's very simple I know. Just trying to get people to use it and get use to it, that way it starts to come natural for simple additions like script commands and at commands. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.