S.Eagle Posted December 27, 2009 Posted December 27, 2009 I tried to spawn vehicles at a random location using math.rand(a,b) , but I sometimes have the problem that the vehicles get stuck in each other. So I've chosen a few preset locations for the vehicles to spawn. But I have absolutely no clue how to make that the vehicles only spawn at those locations. I couldn't really find anything usefull. So how do I make a vehicle spawn at either location a or location b? Thnaks in advance.
robhol Posted December 27, 2009 Posted December 27, 2009 You can make a table containing coordinates (in other tables) and then select a random index from the first table. locations= { {1,2,3}, {4,5,6}, {7,8,9} } random_location = locations[ math.random(1, #locations) ]
eAi Posted December 28, 2009 Posted December 28, 2009 I'm sounding like a broken record about this, but you should specify positions in map files. See https://wiki.multitheftauto.com/wiki/Writing_Gamemodes#Map_Files
50p Posted December 28, 2009 Posted December 28, 2009 I'm sounding like a broken record about this, but you should specify positions in map files.See https://wiki.multitheftauto.com/wiki/Writing_Gamemodes#Map_Files Yeah, no idea why people still use tables for spawn locations and other stuff like markers, vehicles, etc...
Buffalo Posted December 28, 2009 Posted December 28, 2009 The reason I don't use map files is that they need to be downlaoded seperately.
eAi Posted December 28, 2009 Posted December 28, 2009 They don't. You distribute resources as zip files.
Buffalo Posted December 28, 2009 Posted December 28, 2009 I mean you need to download map to clients separately; objects created in script don't need to be downloaded. Furthermore, downloading like 500kb-2mb every time you enter the server is very tiring.
50p Posted December 29, 2009 Posted December 29, 2009 I mean you need to download map to clients separately; objects created in script don't need to be downloaded. Furthermore, downloading like 500kb-2mb every time you enter the server is very tiring. How do you think your script tells every player there is an object or a vehicle spawned in that specific place? They "download" (receive) the data which server sends to them to tell them where the vehicles, objects, markers, other players, etc. are located.
eAi Posted December 29, 2009 Posted December 29, 2009 Map files aren't sent to clients. They're sent much more optimally when you use a map file than when you create them from a script. Each script object you create is (potentially) a new packet of data to be sent, map data is sent when the player joins in much larger packets. It's also much faster as you don't have a whole load of calls to script functions. Basically, don't do it.
S.Eagle Posted December 29, 2009 Author Posted December 29, 2009 Ok, so I have placed a few vehicles in a map file. Now, I only want one of them to spawn, randomly. How do I proceed?
50p Posted December 29, 2009 Posted December 29, 2009 Ok, so I have placed a few vehicles in a map file. Now, I only want one of them to spawn, randomly. How do I proceed? If you add vehicles with tag then you can't. You can use your own tag (say, ) and use getElementsByType function to get all the elements of that type (randomVehSpawn in this case) and than create your vehicle at one of those places. This is not ideal because you'll still have to use createVehicle.
eAi Posted December 29, 2009 Posted December 29, 2009 That might be a feature that's worth supporting officially - a 'start-not-spawned' flag. Even so, this is the preferred method as the positions can be set using the editor.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now