Jump to content

Automatic vehicle respawn script trouble...


Recommended Posts

Trouble again... I don't really know what the problem is...

function initVehicles() 
    local aV = getElementsByType ("vehicle") 
    for tK,tV in ipairs(aV) do 
        vx,vy,vz = getElementPosition(tV) 
        setVehicleRespawnPosition ( tV, vx, vy, vz ) 
        setVehicleRespawnDelay ( tV, 40000) 
    end 
end 
addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), initVehicles) 

Error is following:

ERROR: Couldn't packetize arguments list, invalid element specified.

ERROR: Couldn't packetize arguments list, invalid element specified.

Link to comment

This error happens when you try to transfer data between client and server (or vice versa), i.e. using triggerClientEvent or triggerServerEvent. This happens when you try to send something that the client won't be able to understand - e.g. an xmlnode (the client hasn't got the server's xml files loaded, and vice versa) or a client-side element being sent to the server (the server doesn't know about client-side elements). I can't see anywhere in your code snippet that does that - is there more code? It is only a warning though, the rest of the data will be sent, you'll just receive nil (or maybe 0) instead.

Link to comment

So that argument means it has to be synched? That can explain the time the error shows up, when someone joins...

But that's not the point... How can I fix it? Because I'm quite new, and I really would like an answer. (With explanation, in the wiki for example, I didn't even know why I had to type "source" all the time for example. Do know now though :P)

Link to comment

As eAi said, this code doesn't make any problems... You should pay more attention to the functions that synch data, eg. triggerClient/ServerEvent or setElementData. If you have more code that synch data between clients and server then show it and we may tell you what's wrong or tell us what you're trying to do so we could maybe give you alternative way.

Link to comment

Ok, this is all the info I can give for as far as I know:

I want the script to be able to let all vehicles to be automatically respawned without ours of typing. So now I have to type about 5 lines for each vehicle, I want it to do it automatically for me. So I created this code to make it alot easier.

Now I had a problem due to this, what I posted.

The code I provided is all, no additional synching or whatever, because I want the server to remember where to spawn the vehicles. And that should work. Well... Atleast that was what I thought... Appearently this needs to be synched..? And I wouldn't have the slightest idea how to... Since I'm new and all, and barely had any experience to any language similar to Lua. Ok PHP, HTML, GML... But still, lua looks extremely different...

So if anyone has another idea of how to script it (and please atleast post a bit of it if possible) please tell me. Then I can throw away my million lines of code that still do not cover even 1/3 of the vehicles... :/

Link to comment

im not very good at scripting so not sure how much help this will be :D

after looking through the BROPH resource i found that it uses a seperate function to respawn vehicles

i think if u take the setvehiclerespawnposition and setvehiclerespawndelay out of the first function and then try this

function vehicleExplode () 
    setTimer ( respawnVehicle, 2500, 1, source ) 
end 

addEventHandler ( "onVehicleExplode", root, vehicleExplode ) 

i think that will help but like i said im not sure. hope it helps :D

Link to comment

Respawning is not the only problem, I mean that's simple. What I'm looking for is a respawn that only respawns the started vehicles written down in the map file. So, if I spawn a car, it shouldn't respawn on destruction. It should disappear on destruction.

Although that is info from another post, that is the whole idea. I only want to start with the mapfile vehicles, and let them be the only respawning vehicles.

So I appreciate your help, but it's just not exactly what I'm looking for. ;)

Link to comment

You can do the same as in the "broph" resource but change from "root" to getResourceRootElement( getThisResource( ) ) in the event handler (broph.lua file line 265)

That will respawn only vehicles from your resource (including map file). If you want to destroy them completely from the game you'd have to check if the vehicle is in your map file.

Like:

addEventHandler( "onVehicleExplode", getRootElement( ), 
    function( ) 
        local parent = getElementParent( source ) 
        if getElementType( parent ) == "map" then 
            local parentRes = getElementParent( parent ) 
            if parentRes == getThisResource( ) then 
                setTimer( respawnVehicle, 5000, 1, source ) 
            else 
                setTimer( destroyElement, 5000, 1 source ) 
            end 
        else 
            setTimer( destroyElement, 5000, 1 source ) 
        end 
    end 
) 

(NOT TESTED)

Link to comment

There's a couple of missing "," in that code. Try:

  
addEventHandler( "onVehicleExplode", getRootElement( ), 
    function( ) 
        local parent = getElementParent( source ) 
        if getElementType( parent ) == "map" then 
            local parentRes = getElementParent( parent ) 
            if parentRes == getThisResource( ) then 
                setTimer( respawnVehicle, 5000, 1, source ) 
            else 
                setTimer( destroyElement, 5000, 1, source ) 
            end 
        else 
            setTimer( destroyElement, 5000, 1, source ) 
        end 
    end 
) 

Link to comment

if u just want the vehicles from map file to respawn u can use the consolecreatevehicle function in broph but there is one little thing to change

here is the function

function consoleCreateVehicle ( player, commandName, first, second, third ) 
    if ( player ) then 
        local id, x, y, z, r, d = 0, 0, 0, 0, 0, 5 
        local plate = false 
        r = getPlayerRotation ( player ) 
        x, y, z = getElementPosition ( player ) 
        x = x + ( ( math.cos ( math.rad ( r ) ) ) * d ) 
        y = y + ( ( math.sin ( math.rad ( r ) ) ) * d ) 
        if ( third ) then 
            id = getVehicleIDFromName ( first .. " " .. second ) 
            plate = third 
        elseif ( second ) then 
            if ( getVehicleIDFromName ( first .. " " .. second ) ) then 
                id = getVehicleIDFromName ( first .. " " .. second ) 
            else 
                id = getVehicleIDFromName ( first ) 
                if ( not id ) then 
                    id = tonumber ( first ) 
                end 
                plate = second 
            end          
        else 
            id = getVehicleIDFromName ( first ) 
            if ( not id ) then 
                id = tonumber ( first ) 
            end 
        end 
        local veh = false 
        if ( plate == false ) then 
            veh = createVehicle ( id, x, y, z, 0, 0, r ) 
            --toggleVehicleRespawn ( veh, false ) 
        else 
            veh = createVehicle ( id, x, y, z, 0, 0, r, plate ) 
            --toggleVehicleRespawn ( veh, false ) 
        end 
        if ( veh == false ) then  outputConsole ( "Failed to create vehicle.", player )  end 
    end 
end 

addCommandHandler ( "createvehicle", consoleCreateVehicle ) 

--toggleVehicleRespawn ( veh, false ) 

u just need to take the 2 little lines ( -- )out at start of line and then it wont respawn vehicles made with this function.

only problem is u need to figure out how broph creates vehicles from the map file. i am not sure if u have to write a function to do it or what. i think that it is done by the server itself but im just guessing as i cant see anything in the scripts that creates vehicles from the map. dont know if this is any help but everything ive done so far has been based around the BROPH resource.

u could also try looking at the FR resource. it has a number of freeroam functions in it as well

Link to comment

This code will respawn vehicle from map file (of the resource this code is pasted in).

It will destroy following vehicles:

- vehicles from other resources

- vehicles created in this resource which are not in the map file (eg. createVehicle)

addEventHandler( "onVehicleExplode", getRootElement( ), 
    function( ) 
        local parent = getElementParent( source ) 
        if getElementType( parent ) == "map" and getElementID( parent ) ~= "dynamic" then 
            local parentRes = getElementParent( parent ) 
            if parentRes == getResourceRootElement( getThisResource( ) ) then 
                setTimer( respawnVehicle, 5000, 1, source ) 
            else 
                setTimer( destroyElement, 5000, 1, source ) 
            end 
        else 
            setTimer( destroyElement, 5000, 1, source ) 
        end 
    end 
) 
  

Link to comment

Hmmm... Ok now I have another problem with the code. Caused it myself but still it's annoying...

So I used this code and it worked. Untill for today, where I rebuild almost my entire server to devide it in a couple of resources. Including a different map resource.

Now since the map is in another place, the code doesn't work anymore. The map works, the spawns work. Everything except the code. Anyone knows what could be wrong? Since I want to make this an actual gamemode, not a simple 1 map and 1 server gamemode. (that's why I wanted to automize in the second place...)

Thanks in advance,

Gamesnert.

Link to comment

Do you create the vehicles from map file? This code respawns vehicles that were "born" by map file and the map file is in the same resource as this code. If you want to respawn ALL the vehicle created by map files in other resources, use this one:

addEventHandler( "onVehicleExplode", getRootElement( ), 
    function( ) 
        local parent = getElementParent( source ) 
        if getElementType( parent ) == "map" and getElementID( parent ) ~= "dynamic" then 
            setTimer( respawnVehicle, 5000, 1, source ) 
        else 
            setTimer( destroyElement, 5000, 1, source ) 
        end 
    end 
) 

(NOT TESTED)

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