Aller au contenu

Photo

Help with a console command, please!


  • Veuillez vous connecter pour répondre
1 réponse à ce sujet

#1
Divino Zarathos

Divino Zarathos
  • Members
  • 18 messages
Hi all!
This is my first Toolset script: I'm trying to create a custom runscript command to add items(specifying amount also) into party inventory but there are some syntax issues that I cannot resolve. Here is the code:

void main()
{
    string sVar     = GetLocalString(GetModule(), "RUNSCRIPT_VAR");
    int nFind       = FindSubString(sVar, " ");
   
    string sArg0;
    string sArg1;
    if (nFind > 0)
    {
        sArg0 = SubString(sVar, 0, nFind) + ".uti";
        sArg1 = SubString(sVar, (nFind + 1), GetStringLength(sVar));
    }
    else
    {        
        sArg0 = SubString(sVar, 0, GetStringLength(sVar)) + ".uti";
        sArg1 = "1";
    }
            
    resource rItemFileName = sArg0;
    int nStackSize = StringToInt(sArg1);
   
    if ((nStackSize < 0) || (nStackSize > 99))
        nStackSize = 1;
   
    CreateItemOnObject(rItemFileName, OBJECT_SELF, nStackSize);
}

The error obviously concerns the string containing the item name and it's conversion to resource type.
I've read some tutorial but I can't still figure out how to create a resource from a given string variable because I want to enter the item name manually and adding a little "R" before doesn't do the job.

I've seen a lot of examples about CreateItemOnObject, but it's always used with a declared string:
CreateItemOnObject(R"item_name.uti", OBJECT_SELF, nStackSize);

Can someone help me please? Thanks!

#2
Phaenan

Phaenan
  • Members
  • 315 messages
Well, basically it's ain't possible to convert a string into a resource at runtime. Not at the moment, at least. There is no function to that end, or type-casting, or anything. :o

Modifié par Phaenan, 15 février 2010 - 01:04 .