[SOLVED] Loading pedestrian or farmer via lua code

Your forum for all discussions around Modding.
User avatar
yumi
Posts: 243
Joined: Sun Jun 19, 2016 5:48 pm
Contact:

[SOLVED] Loading pedestrian or farmer via lua code

Post by yumi »

Hello,

For a mod I'm working on I would like to instantiate a character like a farmer or eventually a pedestrian.
I'm trying to use this kind of code but without great result

Code: Select all

    self.x, self.y, self.z = getWorldTranslation(g_currentMission.player.rootNode);
    self.dx, self.dy, self.dz = localDirectionToWorld(g_currentMission.player.rootNode, 0, 0, 1);
    self.rotY = 0.73;
    self.x = self.x + (0.5 * index)

-- Tests using one of these 3 i3d
    sceneToLoad = Utils.loadSharedI3DFile("character/player/player01.i3d","dataS2/",false,false, true);
    --sceneToLoad =  Utils.loadSharedI3DFile("character/pedestrians/pigLoaded.i3d","dataS2/",false,false, true);
    --sceneToLoad =  Utils.loadSharedI3DFile("character/pedestrians/man01.i3d","dataS2/",false,false, true);
 
      self.farmerId = getChildAt( sceneToLoad, 0)
      if self.farmerId ~= nil then
        link(getRootNode(), self.farmerId)
        print("this is the farmerId: ".. self.farmerId) -- shows me an id
        setVisibility(self.farmerId, true)
        setTranslation(self.farmerId, self.x, self.y + 1, self.z)
        --setRotation(self.farmerId, self.dx, self.dy, self.dz);
        --setScale(farmerId, 5, 5, 5)
      else
        print("this is the farmerId: nil") -- shows me nil
      end
    
I see from traces that the I3D is loaded. With pigLoaded.i3d it works OK, but for the other ones (that I guess are animated i3D) I cannot see any visu except for player01 where I see a helmet.
Is there something special to do to load an animated i3d or another way to do so ?

Thanks for your answer.

EDIT:
I got answer from another forum to take a look at "Oxygendavid's" map Sandy Bay map. There are different pedestrians loaded by specific lua script. And it works ! at least I see pedestrian standing.
Now will try to make them move a little bit (without a spline)
moreRealistic fan !
FS19 "mr" on Old Farm Coutryside and Champs de France.
Give a try to ContractorMod!
Contractor Mod Beta version for FS22
All released mods source code is on Github