• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Need Help Create an object in a location

Southsider

Landlubber
Good day vatos. I was trying to figure out how to create an object in a location. My code:

Code:
object LoadObjectInLoc;

void LoadTestModel()
{
    int     n;
    aref    randItem;
    aref al;
   
    FindLocator("Havana_town", "patrol7", &al, true); // Find locator coordinates
           
    n = Items_FindItem("blade7", &randItem); // Load object model and directory
           
    Items_LoadModel(&LoadObjectInLoc,  randItem); // Create an object

    SendMessage(&LoadObjectInLoc, "lffffffffffff", MSG_MODEL_SET_POSITION, makeFloat(al.x), makeFloat(al.y), makeFloat(al.z), makeFloat(al.vx.x), makeFloat(al.vx.y), -makeFloat(al.vx.z), makeFloat(al.vy.x), makeFloat(al.vy.y), -makeFloat(al.vy.z), makeFloat(al.vz.x), makeFloat(al.vz.y), -makeFloat(al.vz.z)); // Set object position

    Log_Info("Test loaded, Coords: " + makeInt(al.x) + " " + makeInt(al.y) + " " + makeInt(al.z) + ", Model: " + randItem.model);
   
}

Then I call "LoadTestModel()" function and... nothing. Engine establish correct coordinates and correct object model, but the object is not visible on these coordinates. What could be the problem? Or am I doing something wrong?
 
I use 2 ways of adding an object.

1 place a randitem locator in the location by using the TOOL. (Add it to the locator.gm file)
In the locations file something like:

Locations[n].locators_radius.randitem.randitem1 = 0.01; (small radius only if it shouldn't be picked up)
Locations[n].items.randitem1 = "door_M11";

2 place the 3D-model in the locations folder.
In the locations file something like:
Locations[n].models.always.l5 = "lever1_down";

Method 2 require COL-files to look good. Method 1 can sometimes work without them.
 
I use 2 ways of adding an object.

1 place a randitem locator in the location by using the TOOL. (Add it to the locator.gm file)
In the locations file something like:

Locations[n].locators_radius.randitem.randitem1 = 0.01; (small radius only if it shouldn't be picked up)
Locations[n].items.randitem1 = "door_M11";

2 place the 3D-model in the locations folder.
In the locations file something like:
Locations[n].models.always.l5 = "lever1_down";

Method 2 require COL-files to look good. Method 1 can sometimes work without them.

Yeah. It's working ways, but I would like to make a universal function that puts objects in the coordinates.

@Southsider: What game are you working with?

AoP2
 
Yeah. It's working ways, but I would like to make a universal function that puts objects in the coordinates.
What exactly do you want to accomplish in the end?
If we know your end goal, it would be easier to make suggestions.

Most our suggestions are based on PotC, though most likely the majority of the related tricks apply to AoP2 as well.
 
What exactly do you want to accomplish in the end?
If we know your end goal, it would be easier to make suggestions.

Most our suggestions are based on PotC, though most likely the majority of the related tricks apply to AoP2 as well.

I want to make a function that will put the object on the specified coordinates. In my code, something is missing.
 
I want to make a function that will put the object on the specified coordinates. In my code, something is missing.
But why do you want to do that? Do you want to fill in x,y,z coordinates in code and then have an object generated there (such as a treasure chest)?
Or do you want something to be permanently part of the location (not a box or an item that can be picked up)?

PotC has the convenient feature that "locators" can be generated through code so you can indeed use whatever x,y,z coordinates you want without editing the GM file.
But I'm pretty sure that is exclusively a feature in the PotC Build Mod, so chances are that you won't be able to use that.
 
But why do you want to do that?

Because this is a very handy function to place the object at any time (quest or something else)

Or do you want something to be permanently part of the location (not a box or an item that can be picked up)?

Yeah, you understood me correctly. This should be a static model (like a barrels, planks or some another scenery objects). Making this through the TOOL - isn't very practical, cause it should be possible to add or delete an object, when it's needed.

As I understand it, can use the following functions:

Code:
Items_LoadModel(&LoadObjectInLoc, randItem);
This function loads the model to add.

Code:
SendMessage(&LoadObjectInLoc, "lffffffffffff", MSG_MODEL_SET_POSITION, makeFloat(al.x), makeFloat(al.y), makeFloat(al.z), makeFloat(al.vx.x), makeFloat(al.vx.y), -makeFloat(al.vx.z), makeFloat(al.vy.x), makeFloat(al.vy.y), -makeFloat(al.vy.z), makeFloat(al.vz.x), makeFloat(al.vz.y), -makeFloat(al.vz.z));
And this function sets the coordinates and rotation angles for loaded model.

The problem is that the model doesn't appear in the game, though it's loaded correctly and it got the desired coordinates. I opened this topic to find out the reason of this problem. I have a lot alternative ways, but I would like to solve this particular question.
 
Making this through the TOOL - isn't very practical, cause it should be possible to add or delete an object, when it's needed.
Using @Jack Rackham's suggestion does allow you to remove/add such items "on the fly".
The only disadvantage is that it requires a reload of the current scene, but I don't think anyone ever found a good way around that.

There is some PotC main quest code from the unmodded game that does somehow manage to place an item on a locator while remaining in the same scene.
So in theory I do believe it must be possible to do it, but somebody would need to investigate how to make that work.

The problem is that the model doesn't appear in the game, though it's loaded correctly and it got the desired coordinates.
Does it remain in place after you leave the location? If so, does it show when you re-enter the location?
That is often the issue: That such models only show up after a reload of the location.
The simplest solution is always to ensure the model is already there before the player actually enters the relevant location.
 
I take a close look the code and understand this: The function, which uses the engine, is responsible for the placement of objects in a scene. It's spelled out in the Modules folder and compilated in one of several file *.dll. If realize my idea, using the PROGRAM folder - will not work.

So I came to the conclusion - add objects to the location, can only using "randitem" locators, as Jack Rackham have described.
 
Back
Top