Jump to content

Script is working, and shows it is. [aka SOLVED]


Recommended Posts

Hi again all,

Another problem... Now about an "emergency saving system" for mabako's map editor. (since it won't save now and then, I made this just in case :P)

The problem is: I let it look where the script has gone wrong, and print that in the server screen. For some reason, the script below gave the last possible error:

"Error: Not all necessary variables could be saved! Save aborted!"

Now if you watch closely, I already wanted to check what was wrong, and put xmlSaveFile just in front of the error. I look in the file, and I see... No errors..? What is quite strange, because it DOES return false, and DOES give the error in the server window.

Can anyone see what I did do wrong? (probably something stupid again... xD)

function saveVehicleLocation(thePlayer) 
    if (isPlayerInVehicle(thePlayer)) then 
        local vehicle=getPlayerOccupiedVehicle(thePlayer) 
        local model=getVehicleID(vehicle) 
        local x,y,z=getElementPosition(vehicle) 
        local rx,ry,rz=getVehicleRotation(vehicle) 
        rz=(360-rz) 
         
        local xmlFile=xmlLoadFile("vehicles.xml") 
        if xmlFile then 
            local newVehicleLine=xmlCreateSubNode(xmlFile,"vehicle") 
            if newVehicleLine then 
                local sucMod=xmlNodeSetAttribute(newVehicleLine,"model",model) 
                local sucX=xmlNodeSetAttribute(newVehicleLine,"posX",x) 
                local sucY=xmlNodeSetAttribute(newVehicleLine,"posY",y) 
                local sucZ=xmlNodeSetAttribute(newVehicleLine,"posZ",z) 
                local sucRX=xmlNodeSetAttribute(newVehicleLine,"rotX",rx) 
                local sucRY=xmlNodeSetAttribute(newVehicleLine,"rotY",ry) 
                local sucRZ=xmlNodeSetAttribute(newVehicleLine,"rotZ",rz) 
                if (sucMod and sucX and sucY and sucZ and secRX and sucRY and sucRZ) then 
                    xmlSaveFile(xmlFile) 
                    return true 
                else 
                    xmlSaveFile(xmlFile) 
                    outputDebugString("Error: Not all necessary variables could be saved! Save aborted!") 
                    return false 
                end 
            else 
                outputDebugString("Error: New vehicle line was not created!") 
            end 
        else 
            outputDebugString("Error: File could not be opened!") 
            return false 
        end 
    else 
        return nil 
    end 
end  

A final note: This code is being called by another resource, my commands part. Although I don't think there should be any problem in there, I post it just to be sure:

call(getResourceFromName("total-war-XMLdb"),"saveVehicleLocation",thePlayer) 

And the reason for the strange resource name? That's just so not the ENTIRE gamemode has to start over by 1 change, but only the section XMLdb for example.

Edited by Guest
Link to comment

I think, after working through it, that I have the solution of the problem.

When you call a script in LUA, it has the bug that LUA thinks this function is somewhat loaded INSIDE the script that calls it, which means you would have to put your XML file in the resource which calls the function.

Since this is a theory of mine, which I developed after a few tests, I would like to hear your result.

This disabled my anticheat, by the way. It made it impossible to work correctly with multiple resources.

Link to comment

Although it did look like that was the solution, it wasn't... :(

There HAS to be something with "if (sucMod and sucX and sucY and sucZ and secRX and sucRY and sucRZ) then"(or the places where they're defined) I think... The rest works perfectly! It saves the file correctly and everything... Only wrong message... (and it only saved because I added that to test which var was wrong ... NONE... :/)

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