Skip to content

CreateItemOnObject Wrapper for use with DelayCommand

Don't I post a lot on these forums :D

Does anyone have a good scripting solution for using Delay Comand with CreateItemOnObject?

Think I need a custom wrapper for it.

Comments

  • NeverwinterWightsNeverwinterWights Member Posts: 339
    edited September 2023
    You can either create a function and add it to your script library (if you have one) which would be a good idea if you are going to use it in multiple scripts, or you can just add it specifically to the script you need it for.

    A function like this added to your library (note: this method does require you to "#include" your library script at the top of the script you use your custom functions in) could work:
    void DelayCreateItemOnObject(string sItemTemplate, object oTarget, int nStackSize=1, string sNewTag="");
    void DelayCreateItemOnObject(string sItemTemplate, object oTarget, int nStackSize=1, string sNewTag="")
    {
        CreateItemOnObject(sItemTemplate, oTarget, nStackSize, sNewTag);
    }
    
    And then using the above in a script would look like:
    #include "_my_mod_library"
    
    void main()
    {
        object oPC = GetLastUsedBy();
        DelayCommand(5.0, DelayCreateItemOnObject("item resref", oPC));
    }
    

    Or if you want to just add it to a script that you need it for, you just add it to the top, above the void main():
    void DelayCreateItemOnObject(string sItemTemplate, object oTarget, int nStackSize=1, string sNewTag="")
    {
        CreateItemOnObject(sItemTemplate, oTarget, nStackSize, sNewTag);
    }
    
    void main()
    {
        object oPC = GetLastUsedBy();
        DelayCommand(5.0, DelayCreateItemOnObject("item resref", oPC));
    }
    

    Hope it helps.
  • MelkiorMelkior Member Posts: 204
    What @NeverwinterWights said. There's a script I use that that purpose which is exactly the same except that it's named CreateItemOnObjectVoid because its entire purpose is to turn the CreateItemOnObject command into a void type so that it can be used in something like DelayCommand.
Sign In or Register to comment.