Jump to content

How to get a model rotated


RobbieG-NL

Recommended Posts

Posted

Hello,

Today I finally made this show my model in MTA (viewtopic.php?f=91&t=50434&p=493519). Unfortunately I can't get the seperate parts to be rotated in the correct way. I can only rotate the first part (line 2, by changing the 0 into another number for degrees). What I want to do is give the 4 seperate parts their own rotation. I'm pretty sure line 3 has something to do with it, but since I am a total idiot/n00b when it comes to coding, I'm not sure at all. Been trying for some hours now, in numerous ways, but so far, without any success. What am I missing here?

local modelsToReplace = {1915} 
local castleBasePosition, castleZRotation = {20, -1995, 5}, 0 --Located just west of Area 69. 
local castleObjects = {--{modelID, xOffset, yOffset, zOffset} 
    {1915, -129.182, 0, 0, 0, 0, 270}, 
    {1915, -129.182, -129.182, 0, 0, 0, 180}, 
    {1915, 0, -129.182, 0, 0, 0, 90}, 
    {1915, 0, 0, 0, 0, 0, 0}, 
} 
  
local function resourceStart() 
    local castle = createElement("castle", "castlea") 
    setElementPosition(castle, castleBasePosition[1], castleBasePosition[2], castleBasePosition[3]) 
    setElementRotation(castle, 0, 0, castleZRotation) 
     
    for i,v in ipairs(castleObjects) do 
        local x, y, z = (castleBasePosition[1] + v[2]), (castleBasePosition[2] + v[3]), (castleBasePosition[3] + v[4]) 
        local newObject = createObject(v[1], x, y, z, 0, 0, castleZRotation) 
        setElementParent(newObject, castle) 
    end 
     
    for i,v in ipairs(modelsToReplace) do 
        local texture = engineLoadTXD("castle.txd") 
        engineImportTXD(texture, v) 
        local colission = engineLoadCOL("castle.col") 
        local model = engineLoadDFF("castle.dff", 1915) 
        engineReplaceCOL(colission, v) 
        engineReplaceModel(model, v) 
        engineSetModelLODDistance(v, 500) 
    end 
     
    local castleBlip = createBlip(castleBasePosition[1], castleBasePosition[2], castleBasePosition[3], 19, 2, 255, 0, 0, 255, 0, 500) 
    setElementParent(castleBlip, castle) 
     
    --This is to reload the collision data when the local player gets near the castle 
    local streamingColShape = createColCircle(castleBasePosition[1], castleBasePosition[2], 250) 
    setElementParent(streamingColShape, castle) 
    addEventHandler("onClientColShapeHit", streamingColShape, streamInCastle) 
    --addEventHandler("onClientColShapeLeave", streamingColShape, streamOutCastle) 
     
end 
addEventHandler("onClientResourceStart", resourceRoot, resourceStart) 
  
--Streams the castle IN 
function streamInCastle(hitElement, dimensionMatch) 
    if hitElement ~= localPlayer or not dimensionMatch then 
        return 
    end 
     
    for i,v in ipairs(modelsToReplace) do 
        local texture = engineLoadTXD("castle.txd") 
        engineImportTXD(texture, v) 
        local colission = engineLoadCOL("castle.col") 
        local model = engineLoadDFF("castle.dff", 0) 
        engineReplaceCOL(colission, v) 
        engineReplaceModel(model, v) 
        engineSetModelLODDistance(v, 500) 
    end 
end 

BTW, debugscript is giving me no errors or anything.

Posted
local modelsToReplace = {1915} 
local castleBasePosition, castleZRotation = {20, -1995, 5}, 0 --Located just west of Area 69. 
local castleObjects = {--{modelID, xOffset, yOffset, zOffset} 
    {1915, -129.182, 0, 0, 0, 0, 270}, 
    {1915, -129.182, -129.182, 0, 0, 0, 180}, 
    {1915, 0, -129.182, 0, 0, 0, 90}, 
    {1915, 0, 0, 0, 0, 0, 0}, 
} 
  
local function resourceStart() 
    local castle = createElement("castle", "castlea") 
    setElementPosition(castle, castleBasePosition[1], castleBasePosition[2], castleBasePosition[3]) 
    setElementRotation(castle, 0, 0, castleZRotation) 
    
    for i,v in ipairs(castleObjects) do 
        local x, y, z = (castleBasePosition[1] + v[2]), (castleBasePosition[2] + v[3]), (castleBasePosition[3] + v[4]) 
        local newObject = createObject(v[1], x, y, z, 0, 0, v[7]) 
        setElementParent(newObject, castle) 
    end 
    
    for i,v in ipairs(modelsToReplace) do 
        local texture = engineLoadTXD("castle.txd") 
        engineImportTXD(texture, v) 
        local colission = engineLoadCOL("castle.col") 
        local model = engineLoadDFF("castle.dff", 1915) 
        engineReplaceCOL(colission, v) 
        engineReplaceModel(model, v) 
        engineSetModelLODDistance(v, 500) 
    end 
    
    local castleBlip = createBlip(castleBasePosition[1], castleBasePosition[2], castleBasePosition[3], 19, 2, 255, 0, 0, 255, 0, 500) 
    setElementParent(castleBlip, castle) 
    
    --This is to reload the collision data when the local player gets near the castle 
    local streamingColShape = createColCircle(castleBasePosition[1], castleBasePosition[2], 250) 
    setElementParent(streamingColShape, castle) 
    addEventHandler("onClientColShapeHit", streamingColShape, streamInCastle) 
    --addEventHandler("onClientColShapeLeave", streamingColShape, streamOutCastle) 
end 
addEventHandler("onClientResourceStart", resourceRoot, resourceStart) 
  
--Streams the castle IN 
function streamInCastle(hitElement, dimensionMatch) 
    if hitElement ~= localPlayer or not dimensionMatch then 
        return 
    end 
  
    for i,v in ipairs(modelsToReplace) do 
        local texture = engineLoadTXD("castle.txd") 
        engineImportTXD(texture, v) 
        local colission = engineLoadCOL("castle.col") 
        local model = engineLoadDFF("castle.dff", 0) 
        engineReplaceCOL(colission, v) 
        engineReplaceModel(model, v) 
        engineSetModelLODDistance(v, 500) 
    end 
end 

Try that.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Hahaha, nice. I've had something else working in the meantime, but that required me to copy/paste most of the script 4 times. This is a much cleaner way to do it. Thanks a million.

Got another question though: can I add interior objects in this same lua script? If so, how? Or would it be better to do that in a new file? Again, if so, how?

Posted

What do you mean by interior objects?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Lmao, never mind that. I figured it out.

By interior objects I meant the standard GTA interiors that are used in houses, for example: ID 14502

Turns out I can now simple add lines under the coordinates for ID's 1915. Thanks a lot. If you ever need a model of anything, just let me know and I'll do what I can for you. I can make them small in kb's or very detailed with more kb's. Any way you like it.

Thanks a lot for all your time, effort and patience.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...