Aller au contenu

Photo

Fixing an core Script


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Gralamin

Gralamin
  • Members
  • 45 messages
Actually, none of this seems to work right. Here is the whole one.

Pastebin version: http://pastebin.com/f6ff46f12

Suggestions?
Edit: Also, I forgot to mention, but I would be including stuff to ensure this fires only once, it just isn't included yet

Modifié par Gralamin, 22 novembre 2009 - 12:42 .


#2
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
I think you have to put
resource[89] rOldItem;
resource[89] rNewItem;

Also you don't need that dummy variable. You can just say:
UT_AddItemToInventory( newItem);

Modifié par Axe_Murderer, 22 novembre 2009 - 12:19 .


#3
Gralamin

Gralamin
  • Members
  • 45 messages

Axe_Murderer wrote...

I think you have to put
resource[89] rOldItem;
resource[89] rNewItem;

Also you don't need that dummy variable. You can just say:
UT_AddItemToInventory( newItem);


The first part stops it from even compiling.

Edit: I forgot the break, trying to fix that.
Edit2: Break doesn't fix it. Still crashing.

Edit 3:
Attempting to do it one set at a time.

Modifié par Gralamin, 22 novembre 2009 - 01:10 .


#4
Sunjammer

Sunjammer
  • Members
  • 925 messages
dascript arrays are dynamic not fixed length.

One suggestion I would have is dump all the resources into a 2da (simply to clean up your code if nothing else).

I've tested an abreviated version of your script from a trigger and that works fine: there wasan item recevied message and then they were removed (since I don't have the blueprints nothing was created in their stead).  However the important thing is that the script didn't crash.

Incidentally ignore the EVENT_TYPE_ENTER and that was there so I could test it on both a trigger and the module.

#include "utility_h"

void ReplacePair(resource rOldItem, resource rNewItem)
{      
    int nNumItems = UT_CountItemInInventory(rOldItem);
    if(nNumItems > 0)
    {
        int n;
        for(n = 0; n < nNumItems; n++)
        {
            UT_RemoveItemFromInventory(rOldItem);
            UT_AddItemToInventory(rNewItem);
        }
    }
}

void main()
{   
    object oHero = GetHero();
    
    event evCurrent = GetCurrentEvent();
    switch(GetEventType(evCurrent))
    {
        case EVENT_TYPE_ENTER:
        case EVENT_TYPE_MODULE_LOAD:
        {      
            DisplayFloatyMessage(oHero, "Starting", FLOATY_MESSAGE, 0xFFFFFF, 5.0);

            // DEBUG: force the PC to have some "old Items
            UT_AddItemToInventory(R"gen_im_arm_hel_mas_jug.uti");
            UT_AddItemToInventory(R"gen_im_arm_hel_mas_jug.uti");
            UT_AddItemToInventory(R"gen_im_arm_bot_mas_jug.uti");
            
            resource[] rOldItem;
            resource[] rNewItem;   
            
            rOldItem[0] = R"gen_im_arm_hel_mas_jug.uti";
            rOldItem[1] = R"gen_im_arm_bot_mas_jug.uti";
            rOldItem[2] = R"gen_im_arm_glv_mas_jug.uti";
            rOldItem[3] = R"gen_im_arm_cht_mas_jug.uti";

            rNewItem[0] = R"gral_list_arm_hel_mas_jug.uti";
            rNewItem[1] = R"gral_list_arm_bot_mas_jug.uti";
            rNewItem[2] = R"gral_list_arm_glv_mas_jug.uti";
            rNewItem[3] = R"gral_list_arm_cht_mas_jug.uti";

            int nIndex;
            for(nIndex = 0; nIndex < GetArraySize(rOldItem); nIndex++)
            {
                ReplacePair(rOldItem[nIndex], rNewItem[nIndex]);
            }
            
            DisplayFloatyMessage(oHero, "Finished", FLOATY_MESSAGE, 0xFFFFFF, 5.0);
            break;
        }
    }            
         
    HandleEvent(evCurrent, RESOURCE_SCRIPT_MODULE_CORE);
}

It might be worth posting your entire script.

Modifié par Sunjammer, 22 novembre 2009 - 01:21 .


#5
Sunjammer

Sunjammer
  • Members
  • 925 messages
Now you've posted the full script I suspect adding items to an inventory in the EVENT_TYPE_INVENTORY_ADDED is a receipe for an infinite loop especially given the logic you are using. 

EDIT: ignore the above I appear to be talking nonsense!

Modifié par Sunjammer, 22 novembre 2009 - 01:52 .


#6
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
I also noticed there is a missing break at the end of your EVENT_TYPE_MODULE_LOAD case.


#7
Gralamin

Gralamin
  • Members
  • 45 messages
Thanks for the help, working on the suggestions now.

Modifié par Gralamin, 22 novembre 2009 - 02:18 .


#8
Gralamin

Gralamin
  • Members
  • 45 messages
New version of the script: Is working, with a few problems

1) Equipped Items are not replaced

2) Items looted or bought from merchants do not seem to be changed



http://pastebin.com/m58e32729