Jump to content

What's wrong with this script: model (re)placement?


RobbieG-NL

Recommended Posts

Hello,

Last week I've finished a model I've been creating (a castle) to place into the Full Theft Auto server. There is a script involved that is meant to put the model in a fixed position. I've edited a script that's used for another model of mine, to work for this castle. But for some reason it only shows the original model 1915 (a pokerchip) on the place where the castle should be. Can somebody tell me where I made a mistake and how to correct it? I've been trying and trying, but nothing worked for me so far.

Also, Id like to add 3 more locations for that model in the same script. And I'd also like to add 144 interiors in this script. If you feel like it, please let me know how to add the rest of the coordinates with the corresponding model ID's. Any help will be much appreciated.

local modelToReplace = 1915 
local castleBasePosition, castleBaseRotation = {20, -1995, 5}, 0 --Located west of Los Santos beach. 
  
local function resourceStart() 
   local castle = createElement("castle", "castle") 
   setElementPosition(v, castleBasePosition[1], castleBasePosition[2], castleBasePosition[3]) 
   setElementRotation(castle, 0, 0, castleBaseRotation) 
    
   local castleBase = createObject(modelToReplace, castleBasePosition[1], castleBasePosition[2], castleBasePosition[3]) 
   setElementRotation(castleBase, 0, 0, castleBaseRotation) 
   setElementParent(castleBase, castle) 
    
   local texture = engineLoadTXD("castle/castle.txd") 
   engineImportTXD(texture, modelToReplace) 
   local colission = engineLoadCOL("castle/castle.col") 
   local model = engineLoadDFF("castle/castle.dff", modelToReplace) 
   engineReplaceCOL(colission, modelToReplace) 
   engineReplaceModel(model, modelToReplace) 
   engineSetModelLODDistance(modelToReplace, 500) 
    
   local vBlip = createBlip(20, -1995, castleBasePosition[3], 53, 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) 
  
function streamIncastle(hitElement, dimensionMatch) 
   if hitElement ~= localPlayer or not dimensionMatch then 
      return 
   end 
    
   local texture = engineLoadTXD("castle/castle.txd") 
   engineImportTXD(texture, modelToReplace) 
   local colission = engineLoadCOL("castle/castle.col") 
   local model = engineLoadDFF("castle/castle.dff", modelToReplace) 
   engineReplaceCOL(colission, modelToReplace) 
   engineReplaceModel(model, modelToReplace) 
   engineSetModelLODDistance(modelToReplace, 500) 
end 

Link to comment

The error I get is that it only shows the original model 1915, which is a pokerchip. This script works fine (in un-edited version) for another model I made: a race track.

Replacing this model with a simpler script works fine, but then I have to place it on the map with runcode.

This is the simpler script that works:

function loadCastle() 
    local texture = engineLoadTXD("Castle.txd") 
    engineImportTXD(texture, 1915) 
    local collision = engineLoadCOL("Castle.col") 
    local model = engineLoadDFF("Castle.dff", 1915) 
    engineReplaceCOL(collision, 1915) 
    engineReplaceModel(model, 1915) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(), loadCastle) 

But with this script I need to use a code via runcode to place it on the map: srun castle = createObject(1915, 20, -1995, 5, 0, 0, 0)

Link to comment

Indeed it did. The other stuff is a term set by BinaryHead, the main scripter of the Full Theft Auto server. Here is his post about that:

if someone else than me is going to do this, write a function to create and destroy (the destroy function is optional in this case, as destroyElement will suffice here, too) a castle and return the created castle as custom element with all the objects that belong to it as children. the function should take the position, interior, dimension and rotation as arguments.

so we can in theory create an unlimited amount of castles and change its position easily. it's okay if you just make a call to the create function in the script with the position given by robbie, so that a castle will be created by default at his given position. so if someone else is going to write that little script, please do it like this, thanks.

Link to comment

This is the info given to me by "debugscript 3":

WARNING: castle\castle.lua:12: Load error @ 'engineLoadTXD'(unable to load "castle/castle.txd']

WARNING: castle\castle.lua:13: Bad 'txd' pointer @ 'engineImportTXD'(1)

WARNING: castle\castle.lua: 14: Load error @ 'engineLoadCOL' (Unable to load "castle/castle.col']

WARNING: castle\castle.lua: 15: Load error @ 'engineLoadDFF' (Unable to load "castle/castle.dff']

WARNING: castle\castle.lua: 16: Bad 'col' pointer @ 'engineImportCOL'(1)

WARNING: castle\castle.lua: 17: Bad 'dff' pointer @ 'engineImportModel'(1)

WARNING: castle\castle.lua: 21: Bad argument @ 'setElementParent'

WARNING: castle\castle.lua: 26: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]

BTW, I've removed line 6, since it doesn't seem to serve any purpose and it gave me an error as well.

Edited by Guest
Link to comment

Lol, I found out why: I had to replace line 13 (local texture = engineLoadTXD("castle/castle.txd")) with this: local texture = engineLoadTXD("castle.txd")

Same with the lines for the col and dff (15 and 16). So it works now ^^ Thanks a lot for the input. I've got a new question though, but I will try to figure it out myself first. Thanks a lot so far :)

Link to comment

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...