Spawn a manhack every X second on a special location(s).
4 replies, posted
Hello Facepunch.
Im trying to spawn a manhack on X amount of seconds on a special location(s).
I know i have to make a timer and an ents.Create("npc_manhack")
So anybody that could post a code to spawn a manhack every X seconds on a special location(s)?
Thank you.
[lua]SpawnPos = { --Create a table to be used later on
Vector( 111, 111, 111 ), --First value, replace with your own vector
Vector( 222, 222, 222 ), --Second value, replace with your own vector
Vector( 333, 333, 333 ) --Third value, replace with your own value, add more positions if needed
} --Stop table
function SpawnThem()
Interval = 5 --Amount of time between spawns in seconds, can be edited to a higher or lower value
Limit = 0 --Limit of manhacks, 0 is infinite amount
timer.Create( "Manhack_Timer", Interval, Limit, function() --Create a timer using the value defined above
local hack = ents.Create( "npc_manhack" ) --Define "hack" as the manhack
hack:Spawn() --Spawn the manhacks
hack:SetPos(table.Random(SpawnPos)) --Set the positions of them using the table from before
end ) --End timer
end --End function
function StopThem()
timer.Destroy( "Manhack_Timer" ) --Destroy (stop) the timer spawning the manhacks
end
concommand.Add("Manhack_Timer_Start", SpawnThem) --Typing "Manhack_Timer_Start" in console will start the timer
concommand.Add("Manhack_Timer_Stop", StopThem) --Typing "Manhack_Timer_Stop" in console will stop the timer[/lua]
Commented for convenience, this should be dropped in either:
[code]<your_username>/garrysmod/garrysmod/lua
or
<your_username>/garrysmod/garrysmod/lua/autorun[/code]
If you choose to not put it in autorun, when you load garrysmod and are in-game, you must type:
[code]lua_openscript nameofscript.lua[/code]
[QUOTE=LuckyLuke;24157144][lua]SpawnPos = { --Create a table to be used later on
Vector( 111, 111, 111 ), --First value, replace with your own vector
Vector( 222, 222, 222 ), --Second value, replace with your own vector
Vector( 333, 333, 333 ) --Third value, replace with your own value, add more positions if needed
} --Stop table
function SpawnThem()
Interval = 5 --Amount of time between spawns in seconds, can be edited to a higher or lower value
Limit = 0 --Limit of manhacks, 0 is infinite amount
timer.Create( "Manhack_Timer", Interval, Limit, function() --Create a timer using the value defined above
local hack = ents.Create( "npc_manhack" ) --Define "hack" as the manhack
hack:Spawn() --Spawn the manhacks
hack:SetPos(table.Random(SpawnPos)) --Set the positions of them using the table from before
end ) --End timer
end --End function
function StopThem()
timer.Destroy( "Manhack_Timer" ) --Destroy (stop) the timer spawning the manhacks
end
concommand.Add("Manhack_Timer_Start", SpawnThem) --Typing "Manhack_Timer_Start" in console will start the timer
concommand.Add("Manhack_Timer_Stop", StopThem) --Typing "Manhack_Timer_Stop" in console will stop the timer[/lua]
Commented for convenience, this should be dropped in either:
[code]<your_username>/garrysmod/garrysmod/lua
or
<your_username>/garrysmod/garrysmod/lua/autorun[/code]
If you choose to not put it in autorun, when you load garrysmod and are in-game, you must type:
[code]lua_openscript nameofscript.lua[/code][/QUOTE]
Thank you il try this now. Also i have a gamemode for this to be runnen in so il stick it in init.
To get custom positions, load the map(s) you wish to use this script on, and go to suitable positions where you want manhacks to spawn, when you have found the right positions type:
[code]getpos[/code]
In console, you should recieve something like this:
[img]http://i36.tinypic.com/nfodw1.png[/img]
The highlighted bit is the only thing you're interested in, so copy and paste that into your code, and your new vector should look something like this:
[lua]Vector(0.000000 0.000000 576.597900)[/lua]
Now, of course that won't work, because you have not seperated the numbers with commas, so just simply insert commas between the first and second, and second and third, and then you are done, finished example:
[lua]Vector(0.000000, 0.000000, 576.597900)[/lua]
[QUOTE=LuckyLuke;24157789]To get custom positions, load the map(s) you wish to use this script on, and go to suitable positions where you want manhacks to spawn, when you have found the right positions type:
[code]getpos[/code]
In console, you should recieve something like this:
[img]http://i36.tinypic.com/nfodw1.png[/img]
The highlighted bit is the only thing you're interested in, so copy and paste that into your code, and your new vector should look something like this:
[lua]Vector(0.000000 0.000000 576.597900)[/lua]
Now, of course that won't work, because you have not seperated the numbers with commas, so just simply insert commas between the first and second, and second and third, and then you are done, finished example:
[lua]Vector(0.000000, 0.000000, 576.597900)[/lua][/QUOTE]
Yea i know :) Thank you very much for being so friendly.
Also it works perfectly. Thank you.
Sorry, you need to Log In to post a reply to this thread.