viewing paste chkweigh2 | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/lighta/Documents/Myscript/RO/Servs/ra2/src/map
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: script.c
--- script.c Base (BASE)
+++ script.c Locally Modified (Based On LOCAL)
@@ -6115,48 +6115,47 @@
  *------------------------------------------*/
 BUILDIN_FUNC(checkweight)
 {
-   int nameid, amount, slots;
-   unsigned int weight;
+   int nameid, amount, slots, amount2=0;
+   unsigned int weight, i, nbargs;
    struct item_data* id = NULL;
    struct map_session_data* sd;
    struct script_data* data;
 
-   if( ( sd = script_rid2sd(st) ) == NULL )
-   {
+   if( ( sd = script_rid2sd(st) ) == NULL ){
        return 0;
    }
+   nbargs = script_lastdata(st)+1;
+   ShowInfo("nb args = %d\n",nbargs);
+   if(nbargs%2){
+       ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n");  // returns string, regardless of what it was
+       script_pushint(st,0);
+       return 1;
+   }
+   slots = pc_inventoryblank(sd); //nb of empty slot
 
-   data = script_getdata(st,2);
+   for(i=2; i<nbargs; i=i+2){
+       data = script_getdata(st,i);
    get_val(st, data);  // convert into value in case of a variable
-
-   if( data_isstring(data) )
-   {// item name
+       if( data_isstring(data) ){// item name
        id = itemdb_searchname(conv_str(st, data));
-   }
-   else
-   {// item id
+       } else {// item id
        id = itemdb_exists(conv_num(st, data));
    }
-
-   if( id == NULL )
-   {
-       ShowError("buildin_checkweight: Invalid item '%s'.\n", script_getstr(st,2));  // returns string, regardless of what it was
+       if( id == NULL ) {
+           ShowError("buildin_checkweight: Invalid item '%s'.\n", script_getstr(st,i));  // returns string, regardless of what it was
        script_pushint(st,0);
        return 1;
    }
-
    nameid = id->nameid;
-   amount = script_getnum(st,3);
 
-   if( amount < 1 )
-   {
+       amount = script_getnum(st,i+1);
+       if( amount < 1 ) {
        ShowError("buildin_checkweight: Invalid amount '%d'.\n", amount);
        script_pushint(st,0);
        return 1;
    }
 
-   weight = itemdb_weight(nameid)*amount;
-
+       weight += itemdb_weight(nameid)*amount; //total weight for all chk
    if( weight + sd->weight > sd->max_weight )
    {// too heavy
        script_pushint(st,0);
@@ -6169,11 +6168,118 @@
            // item is already in inventory, but there is still space for the requested amount
            break;
        case ADDITEM_NEW:
-           slots = pc_inventoryblank(sd);
+               if( itemdb_isstackable(nameid) ) {// stackable
+                   amount2++;
+                   if( slots < amount2 ) {
+                       script_pushint(st,0);
+                       return 0;
+                   }
+               }
+               else {// non-stackable
+                   amount2 += amount;
+                   if( slots < amount2){
+                       script_pushint(st,0);
+                       return 0;
+                   }
+               }
+               break;
+           case ADDITEM_OVERAMOUNT:
+               script_pushint(st,0);
+               return 0;
+       }
+   }
+   script_pushint(st,1);
+   return 0;
+}
 
+BUILDIN_FUNC(checkweight2)
+{
+        //variable sub checkweight
+        int32 nameid=-1, amount=-1;
+        int i=0, amount2=0, slots=0, weight=0;
+
+        //variable for array parsing
+        struct script_data* data_it;
+        struct script_data* data_nb;
+        const char* name_it;
+        const char* name_nb;
+        int32 id_it, id_nb;
+        int32 idx_it, idx_nb;
+        int32 idr_it, idr_nb;
+        int nb_it, nb_nb; //array size
+
+        TBL_PC *sd = script_rid2sd(st);
+        nullpo_retr(1,sd);
+
+        data_it = script_getdata(st, 2);
+        data_nb = script_getdata(st, 3);
+
+        if( !data_isreference(data_it) || !data_isreference(data_nb))
+        {
+                ShowError("script:checkweight3: parameter not a variable\n");
+                script_pushint(st,0);
+                return 1;// not a variable
+        }
+        id_it = reference_getid(data_it);
+        id_nb = reference_getid(data_nb);
+        idx_it = reference_getindex(data_it);
+        idx_nb = reference_getindex(data_nb);
+        name_it = reference_getname(data_it);
+        name_nb = reference_getname(data_nb);
+
+        if( not_array_variable(*name_it) || not_array_variable(*name_nb))
+        {
+                ShowError("script:checkweight3: illegal scope\n");
+                script_pushint(st,0);
+                return 1;// not supported
+        }
+        if(is_string_variable(name_it) || is_string_variable(name_nb)){
+                ShowError("script:checkweight3: illegal type, need int\n");
+                script_pushint(st,0);
+                return 1;// not supported
+        }
+        nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it));
+        nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb));
+        ShowInfo("nb_it=%d, nb_nb=%d\n",nb_it,nb_nb);
+        if(nb_it != nb_nb){
+                ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb);
+                script_pushint(st,-1);
+                return 1;// not supported
+        }
+
+        slots = pc_inventoryblank(sd);
+        for(i=0; i<nb_it-1; i++){
+            nameid = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it)));
+            if( itemdb_exists(nameid) == NULL )
+            {
+                    ShowError("buildin_checkweight3: Invalid item '%d'.\n", nameid);
+                    script_pushint(st,0);
+                    return 1;
+            }
+            amount = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb)));
+            if( amount < 0 )
+            {
+                ShowError("buildin_checkweight3: Invalid amount '%d'.\n", amount);
+                script_pushint(st,0);
+                return 1;
+            }
+            ShowInfo("nameid=%d amount=%d\n",nameid,amount);
+            weight += itemdb_weight(nameid)*amount;
+            if( weight + sd->weight > sd->max_weight )
+            {// too heavy
+                    script_pushint(st,0);
+                    return 0;
+            }
+            switch( pc_checkadditem(sd, nameid, amount) )
+            {
+                    case ADDITEM_EXIST:
+                        // item is already in inventory, but there is still space for the requested amount
+                            break;
+                    case ADDITEM_NEW:
            if( itemdb_isstackable(nameid) )
            {// stackable
-               if( slots < 1 )
+                                    amount2++;
+                                    if( slots < amount2 )
                {
                    script_pushint(st,0);
                    return 0;
@@ -6181,7 +6287,8 @@
            }
            else
            {// non-stackable
-               if( slots < amount )
+                                    amount2 += amount;
+                                    if( slots < amount2 )
                {
                    script_pushint(st,0);
                    return 0;
@@ -6192,9 +6299,11 @@
            script_pushint(st,0);
            return 0;
    }
+        }
 
    script_pushint(st,1);
    return 0;
+
 }
 
 /*==========================================
@@ -10119,6 +10228,11 @@
 
 /*==========================================
  * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
+ * @type
+ * 1 : make like after rebirth
+ * 2 : blvl,jlvl=1, skillpoint=0
+ *     3 : don't reset skill, blvl=1
+ * 4 : jlvl=0
  *------------------------------------------*/
 BUILDIN_FUNC(resetlvl)
 {
@@ -10134,7 +10248,7 @@
    return 0;
 }
 /*==========================================
- * �X�e�[�^�X���Z�b�g
+ * Reset a player status point
  *------------------------------------------*/
 BUILDIN_FUNC(resetstatus)
 {
@@ -17145,7 +17259,8 @@
    BUILDIN_DEF(rand,"i?"),
    BUILDIN_DEF(countitem,"v"),
    BUILDIN_DEF(countitem2,"viiiiiii"),
-   BUILDIN_DEF(checkweight,"vi"),
+   BUILDIN_DEF(checkweight,"vi*"),
+   BUILDIN_DEF(checkweight2,"rr"),
    BUILDIN_DEF(readparam,"i?"),
    BUILDIN_DEF(getcharid,"i?"),
    BUILDIN_DEF(getnpcid,"i?"),
Viewed 1388 times, submitted by lighta.