Jump to content

Car spawn


Recommended Posts

Posted

Hi,

I have set many cars in the map.

But in the gamemode, if a car exploded, how can i do that the car comes back at the spawn place?

Regards,

Nick

  • Moderators
Posted

I can help you. I am right now at school....

Afther school I will send you a script that can respawn these cars

greets IIYAMA

Posted
I can help you. I am right now at school....

Afther school I will send you a script that can respawn these cars

greets IIYAMA

Thanks you!

Thats great ;D

  • Moderators
Posted

---meta-- call this "meta.xml"

<meta> 
    <info author="NONE" description="respawn" version="1" type="script" /> 
    <script src="respawn.lua" /> 
</meta> 

--server--call this "respawn.lua"

  
function respawn() 
    for i,vehicle in ipairs(getElementsByType("vehicle")) do 
        toggleVehicleRespawn(vehicle, true) 
        setVehicleRespawnDelay(vehicle, 20000) 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), respawn) 

Put the meta and the server script inside a folder.

> setVehicleRespawnDelay(vehicle, 20000)

20000 = 20 seconds for respawn.

Posted
---meta-- call this "meta.xml"

<meta> 
    <info author="NONE" description="respawn" version="1" type="script" /> 
    <script src="respawn.lua" /> 
</meta> 

--server--call this "respawn.lua"

  
function respawn() 
    for i,vehicle in ipairs(getElementsByType("vehicle")) do 
        toggleVehicleRespawn(vehicle, true) 
        setVehicleRespawnDelay(vehicle, 20000) 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), respawn) 

Put the meta and the server script inside a folder.

> setVehicleRespawnDelay(vehicle, 20000)

20000 = 20 seconds for respawn.

Thanks for your reaction, but it doesn't work here.

The car dont spawn back :(

  • Moderators
Posted

ofcourse it works, when the vehicle has been destroyed.

Do you know how to use a script?

Posted

Yes,

The first one you save us meta.xml

The second one as respawn.lua

You take it into a .zip file and in the resource folder.

In the commando (if the server is running) you do "refresh"

Then he said, new resource added: "carspawn"

Then you do the command "start carspawn"

He said, "Carspawn started"

Then i destroy a vehicle in the gameplay, (with my weapon i blow the vehicle up)

And he doesn't spawn back?

Sorry for my bad english (:

Posted

try this:

addEventHandler("onVehicleExplode",root,function() 
    toggleVehicleRespawn(source, true) 
    setVehicleRespawnDelay(source, 10000) -- Respawn it in 10 seconds 
end) 

Posted
well for me my script just works fine afther 20 seconds.

Ya, but it seems like he wants it for when the vehicle just explode...

Not sure

  • Moderators
Posted

If your script also does not work, it means that you made a mistake with putting the script inside your folder and start it.

You started the script?

YES folder or .zip > meta and script.

NO .zip > folder > meta and script

Posted

ok, first of all, If you make a map in map editor, and saved it then it would make a resource...

after all of that, you should edit the meta.xml and add

="server.lua" type="server" />

then make another file and call it "server.lua", in this file put this:

addEventHandler("onVehicleExplode",root,function() 
    toggleVehicleRespawn(source, true) 
    setVehicleRespawnDelay(source, 10000) -- Respawn it in 10 seconds 
end) 

Posted

to Jaysds1, i mean my code

function onStart() 
    -- car spawn 
    for i, v in ipairs (getElementsByType("vehicle")) do 
        toggleVehicleRespawn(v, true) 
        setVehicleRespawnDelay(v, 5000) 
        setVehicleIdleRespawnDelay(v, 5000) 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart) 

doesn't work. Vehicles aren't respawning.

ps. onVehicleExplode event triggers only when car is wrecked. i need respawn not only on wreck, but also idle

Posted

to IIYAMA, can you just write where's the problem? why single resource is working, but integrating the code to my main .lua file gives no result?

edited: okay, i got it. when main resource starts, vehicles need time to spawn and the "vehicle" element table is just EMPTY, so the fucntions apply to no elements. setting timer solves this problem.

function onStart() 
    -- car spawn 
    setTimer (function() 
        for i, v in ipairs (getElementsByType("vehicle")) do 
            toggleVehicleRespawn(v, true) 
            setVehicleRespawnDelay(v, 5000) 
            setVehicleIdleRespawnDelay(v, 5000) 
        end 
    end, 1000,1) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart) 

  • Moderators
Posted
to IIYAMA, can you just write where's the problem? why single resource is working, but integrating the code to my main .lua file gives no result?

Well it means the one that integrading this code did something wrong, because the code is the same...

I have to remind you to use debugscript for checking the folder you put it in. I haven't seen in your reaction what whent wrong with it.

  • Moderators
Posted

I am not a pro scripter, I am more a beginner/normal.

But debugscript is a very handy tool.

1. give your self andmin.

2. write "/debug 3" for understanding all the trouble in the server.

(wiki) debug *

0: Custom message

1: Error message

2: Warning message

3: Information message (default)

It is also handy for testing scripts, you can use outputDebugString inside your scripts.

Put it in a line that needs to be checked and call your string like that.

https://wiki.multitheftauto.com/wiki/OutputDebugString

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