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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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 (:

  • Moderators
Posted

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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • 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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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

i must learn not to be an asshole

  • Moderators
Posted

Man you so..... that I have to upload my script.

You guys get it from here... the same script I write down on this topic. This one works other you are failing so badly to manage your scripts... 20 seconds for respawn.

http://www.2shared.com/file/O1iauaZe/re ... hicle.html

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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) 

i must learn not to be an asshole

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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

okay, okay, great programming guru, i'll remember your super smart advice!

i must learn not to be an asshole

  • 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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

of course, you made my scripting experience! probably, i'd never read this on wiki

i must learn not to be an asshole

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