summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt6
-rw-r--r--conf/Changelog.txt2
-rw-r--r--conf/script_athena.conf11
-rw-r--r--doc/script_commands.txt21
-rw-r--r--src/map/script.c53
-rw-r--r--src/map/script.h2
6 files changed, 75 insertions, 20 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 037d85419..7ea683182 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,6 +3,12 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
+2008/02/11
+ * Expanded the script command 'input': (bugreport:811) [FlavioJS]
+ - two new optional arguments 'min' and 'max'
+ - return value indicating if it's in the correct range
+ - config variables for the default value of the arguments:
+ 'input_min_value' and 'input_max_value' in script_athena.conf
2008/02/10
* Added two missing opt2 values, for Angelus and Bleeding status
* Fixed Warp Portal code sometimes producing errors/crashes in the case
diff --git a/conf/Changelog.txt b/conf/Changelog.txt
index 22aca2ff5..2354eb6d2 100644
--- a/conf/Changelog.txt
+++ b/conf/Changelog.txt
@@ -1,5 +1,7 @@
Date Added
+2008/02/11
+ * Added 'input_min_value' and 'input_max_value' to script_athena.conf. [FlavioJS]
2008/01/22
* Removed hom_setting&02 (ignore skill range) as this was fixed by Gravity
some time ago. [Skotlex]
diff --git a/conf/script_athena.conf b/conf/script_athena.conf
index 726786f00..f45af4bad 100644
--- a/conf/script_athena.conf
+++ b/conf/script_athena.conf
@@ -21,4 +21,15 @@ check_cmdcount: 655360
check_gotocount: 2048
+// Default value of the 'min' argument of the script command 'input'.
+// When the 'min' argument isn't provided, this value is used instead.
+// Defaults to 0.
+//input_min_value: 0
+
+// Default value of the 'max' argument of the script command 'input'.
+// When the 'max' argument isn't provided, this value is used instead.
+// Defaults to INT_MAX.
+//input_max_value: 2147483647
+input_max_value: 10000000
+
import: conf/import/script_conf.txt
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 1a9987587..865b82fe6 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -4,7 +4,7 @@
//= A reference manual for the eAthena scripting language.
//= Commands are sorted depending on their functionality.
//===== Version ===========================================
-//= 3.12.20071227
+//= 3.14.20080211
//=========================================================
//= 1.0 - First release, filled will as much info as I could
//= remember or figure out, most likely there are errors,
@@ -97,6 +97,8 @@
//= Corrected description of scope and npc variables. [FlavioJS]
//= 3.13.20080104
//= Updated 'setcell' desc to match latest code changes [ultramage]
+//= 3.14.20080211
+//= Updated 'input' (new arguments and return value). [FlavioJS]
//=========================================================
This document is a reference manual for all the scripting commands and functions
@@ -1303,7 +1305,7 @@ the Cancel button, this function will return 255 instead.
---------------------------------------
-*input <variable>;
+*input(<variable>{,<min>{,<max>}})
This command will make an input box pop up on the client connected to the
invoking character, to allow entering of a number or a string. This has many
@@ -1349,11 +1351,18 @@ allow the player to enter text. Otherwise, only numbers will be allowed.
close;
}
-Notice that in current SVN, you may not input a negative number with this
-command. This was done to prevent exploits in badly written scripts, which would
+Normally you may not input a negative number with this command.
+This is done to prevent exploits in badly written scripts, which would
let people, for example, put negative amounts of zeny into a bank script and
-receive free zeny as a result. Unfortunately it limits the uses of the 'input'
-command quite a bit.
+receive free zeny as a result.
+
+Since trunk r12192 the command has two optional arguments and a return value.
+The default value of 'min' and 'max' can be set with 'input_min_value' and
+'input_max_value' in script_athena.conf.
+For numeric inputs the value is capped to the range [min,max]. Returns 1 if
+the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
+For string inputs it returns 1 if the string was longer than 'max', -1 is
+shorter than 'min' and 0 otherwise.
---------------------------------------
diff --git a/src/map/script.c b/src/map/script.c
index 87d0d40b0..d10d8c935 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -189,6 +189,7 @@ DBMap* script_get_userfunc_db(){ return userfunc_db; }
struct Script_Config script_config = {
1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
+ 0, INT_MAX, // input_min_value/input_max_value
"OnPCDieEvent", //die_event_name
"OnPCKillEvent", //kill_pc_event_name
"OnNPCKillEvent", //kill_mob_event_name
@@ -3502,6 +3503,12 @@ int script_config_read(char *cfgName)
else if(strcmpi(w1,"check_gotocount")==0) {
script_config.check_gotocount = config_switch(w2);
}
+ else if(strcmpi(w1,"input_min_value")==0) {
+ script_config.input_min_value = config_switch(w2);
+ }
+ else if(strcmpi(w1,"input_max_value")==0) {
+ script_config.input_max_value = config_switch(w2);
+ }
else if(strcmpi(w1,"import")==0){
script_config_read(w2);
}
@@ -4635,30 +4642,43 @@ BUILDIN_FUNC(jobname)
return 0;
}
-/*==========================================
- *
- *------------------------------------------*/
+/// Get input from the player.
+/// For numeric inputs the value is capped to the range [min,max]. Returns 1 if
+/// the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
+/// For string inputs it returns 1 if the string was longer than 'max', -1 is
+/// shorter than 'min' and 0 otherwise.
+///
+/// input(<var>{,<min>{,<max>}}) -> <int>
BUILDIN_FUNC(input)
{
- TBL_PC *sd = script_rid2sd(st);
- struct script_data *data = script_getdata(st,2);
- int num = data->u.num;
- char *name=str_buf+str_data[num&0x00ffffff].str;
- char postfix = name[strlen(name)-1];
+ TBL_PC* sd;
+ struct script_data* data;
+ int uid;
+ char* name;
+ int min;
+ int max;
- if (!sd) return 0;
+ sd = script_rid2sd(st);
+ if( sd == NULL )
+ return 0;
+ data = script_getdata(st,2);
if( !data_isreference(data) ){
ShowError("script:input: not a variable\n");
script_reportdata(data);
+ st->state = END;
return 1;
}
+ uid = reference_getuid(data);
+ name = reference_getname(data);
+ min = (script_hasdata(st,3) ? script_getnum(st,3) : script_config.input_min_value);
+ max = (script_hasdata(st,4) ? script_getnum(st,4) : script_config.input_max_value);
if( !sd->state.menu_or_input )
{ // first invocation, display npc input box
sd->state.menu_or_input = 1;
st->state = RERUNLINE;
- if( postfix == '$' )
+ if( is_string_variable(name) )
clif_scriptinputstr(sd,st->oid);
else
clif_scriptinput(sd,st->oid);
@@ -4666,12 +4686,17 @@ BUILDIN_FUNC(input)
else
{ // take received text/value and store it in the designated variable
sd->state.menu_or_input = 0;
- if( postfix == '$' )
- set_reg(st,sd,num,name,(void*)sd->npc_str,script_getref(st,2));
+ if( is_string_variable(name) )
+ {
+ size_t len = strlen(sd->npc_str);
+ set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
+ script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
+ }
else
{
- sd->npc_amount = cap_value(sd->npc_amount, 0, INT_MAX);
- set_reg(st,sd,num,name,(void*)sd->npc_amount,script_getref(st,2));
+ int amount = sd->npc_amount;
+ set_reg(st, sd, uid, name, (void*)cap_value(amount,min,max), script_getref(st,2));
+ script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
}
}
return 0;
diff --git a/src/map/script.h b/src/map/script.h
index e879854f4..036036ccc 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -12,6 +12,8 @@ extern struct Script_Config {
unsigned warn_func_mismatch_paramnum : 1;
int check_cmdcount;
int check_gotocount;
+ int input_min_value;
+ int input_max_value;
const char *die_event_name;
const char *kill_pc_event_name;