Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Change character outfit with LUA

  • #1, by cr34m3 12 years ago Zitieren
    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.
  • #2, by SimonS 12 years ago Zitieren
    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]")
  • #3, by cr34m3 12 years ago Zitieren
    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.
  • #4, by afrlme 12 years ago Zitieren
    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.
  • #5, by gusty 12 years ago Zitieren
    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.
  • #6, by afrlme 12 years ago Zitieren
    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.
  • #7, by gusty 12 years ago Zitieren
    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?
  • #8, by afrlme 12 years ago Zitieren
    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.
  • #9, by gusty 12 years ago Zitieren
    It works! Thanks a lot smile
  • #10, by afrlme 12 years ago Zitieren
    which one? & no problem smile
  • #11, by gusty 12 years ago Zitieren
    second one