Change character outfit with LUA

  • #1, by cr34m3Friday, 07. March 2014, 18:53 10 years ago
    I’m creating a small minigame which utilises characters for some of the pieces. My question is twofold:

    1. How do I change the current outfit of a character with a LUA script? The equivalent of the interface’s “Change outfit of ‘CharacterA’ to ‘OutfitA’” or the console’s “SET OUTFIT CharacterA OutfitA”.
    2. I’ve noticed that the console has an issue when changing outfits where multiple characters have outfits with the same name. Will this be a problem in LUA or does the explicit link to a specific character sort it out?

    I’ve had a look at the Visionaire data structure, VCharacterCurrentOutfit links to Outfit but I’m not sure what/how to change to get this done. Any help will be appreciated.

    Newbie

    72 Posts


  • #2, by SimonSFriday, 07. March 2014, 20:33 10 years ago
    Hi,
    1) getObject("Characters[name_here]"):setValue(VCharacterCurrentOutfit, getObject("Outfits[new_outfit]"))
    2) Yes, it is a problem, you should always name them in a convention that shows to which character they belong. Alternatively you can select only from the Outfits of a specific character.
    getObject("Characters[name].CharacterOutfits[new_outfit]")

    Thread Captain

    1580 Posts

  • #3, by cr34m3Friday, 07. March 2014, 22:47 10 years ago
    Thanks Simon. It looks so simple (and obvious) now that I see it -- I almost feel silly for asking. smile

    While I get the idea behind character specific naming conventions, it does create a tad more work when you've got many characters with the same outfit type (e.g. schoolwear or formalwear). The specific character reference you mention at the end does however give me an idea of an automated workaround.

    Newbie

    72 Posts

  • #4, by afrlmeFriday, 07. March 2014, 23:04 10 years ago
    you can create a function with 2 vars, to use as a global command.
    local char, outfit
    
    function changeOutfit(c,o)
     char = getObject("Characters[" .. c .. "]") -- get character
     outfit = char:getObject(".CharacterOutfits[" .. o .. "]") -- get outfit
     char:setValue(VCharacterCurrentOutfit, outfit) -- set new outfit
    end
    

    to use: execute script action...
    changeOutfit("character name", "outfit name")


    P.S: untested code. add main script as a definition script.

    Imperator

    7278 Posts

  • #5, by gustyFriday, 14. March 2014, 22:24 10 years ago
    Is it possible to change outfit of current character to his "second outfit"? In the script there will be no name of character or name of outfit. It would be "Game.GameCurrentCharacter" and for outfit something like "number two in the row of outfits of current character". Hope you understand.

    Forum Fan

    159 Posts

  • #6, by afrlmeFriday, 14. March 2014, 22:38 10 years ago
    Hmm... not sure. The function I wrote above is very simple, & it is global meaning you can use it for all characters.

    technically you can use gamecurrentcharacter to return the name of the character but you would still need to provide the name of the outfit.

    in general most people, tend to create loads of outfits for their main character. I think Daedalic have more than 20+ for some of their characters. I don't remember the exact margin, but it was a lot.

    Imperator

    7278 Posts

  • #7, by gustyFriday, 14. March 2014, 22:58 10 years ago
    I'm absolute noob in matter of scripting. I just tried your definition script and execute script, but it didn't work. I'm not sure what is "c,o" and with what should I rewrite [" .. c .. "] and [" .. o .. "]. Is it for characters names? Let say I have 5 characters with names "charA", "charB", "charC", "charD" and "charE". And everyone of these characters have two outfits - "outfitA" and "outfitB". Now I want to change the outfit of currently played character to "outfitB". So the script would be like
     changeOutfit("Game.GameCurrentCharacter", "outfitB")
    , right?

    Forum Fan

    159 Posts

  • #8, by afrlmeFriday, 14. March 2014, 23:08 10 years ago
    it would be done like...
    changeOutfit("Tom", "OutfitB")
    


    c & o are just what I called the variables in which you entered the "string values" into the function. I can then get the values by using c or o in the function. C was for character & o was for outfit. I could have named them anything I liked to be honest.

    To change outfit of current character you could do...
    game:getLink(VGameCurrentCharacter):setValue(VCharacterCurrentOutfit, "outfitB") -- I'm not sure if this is correct as it's asking for t_link...
    
    -- so...
    
    game:getLink(VGameCurrentCharacter):setValue(VCharacterCurrentOutfit, "Game.GameCurrentCharacter.CharacterOutfits[outfitB]")
    
    -- or...
    
    game:getLink(VGameCurrentCharacter):setValue(VCharacterCurrentOutfit, getObject("Game.GameCurrentCharacter.CharacterOutfits[outfitB]")
    

    I think.

    Imperator

    7278 Posts

  • #9, by gustyFriday, 14. March 2014, 23:27 10 years ago
    It works! Thanks a lot smile

    Forum Fan

    159 Posts

  • #10, by afrlmeSaturday, 15. March 2014, 00:18 10 years ago
    which one? & no problem smile

    Imperator

    7278 Posts

  • #11, by gustySaturday, 15. March 2014, 01:09 10 years ago
    second one

    Forum Fan

    159 Posts