Hey everyone! I am new to lua/gLua and I am still learning so please don't judge :(
Anyways so basically I have a timer for a gamemode called The Purge and when the purge starts I want it to remove vehicles that are currently on the map and make it so they can't really spawn it til the purge is over. Is this possible and if so how would I do this?
Thanks.
LtExcalibur
Find all vehicles in the beginning of your timer with like ents.GetAll() or something. Loop through it and if it's a vehicle remove it. Disallow spawning cars with the PlayerSpawnVehicle hook. (return false to disallow), assuming your "gamemode" doesn't use some other method for spawning. Like non spawn menu based.
[QUOTE=crazyscouter;45704924]Find all vehicles in the beginning of your timer with like ents.GetAll() or something. Loop through it and if it's a vehicle remove it. Disallow spawning cars with the PlayerSpawnVehicle hook. (return false to disallow), assuming your "gamemode" doesn't use some other method for spawning. Like non spawn menu based.[/QUOTE]
How would I make it check if its a vehicle though with ents.GetAll(). Sorry still a newb :P
also if you don't want to talk to me about this over facepunch, feel free to accept my friend request on steam.
Entity:IsVehicle()
[QUOTE=crazyscouter;45705115]Entity:IsVehicle()[/QUOTE]
Damn I am really stupid. Could you give me an example of this or code to help out? I didn't do this right at all XD
[editline]16th August 2014[/editline]
Bamp. Can anyone still help me on this since I've been trying to test and figure out. Thanks
Look into "for loops" and how they function.
[QUOTE=The Beta;45705887]Look into "for loops" and how they function.[/QUOTE]
Yea I know I've been trying some stuff and it isn't working so pretty much I need some code to put into this since I am pretty much confused as hell lol
You should show us what you have so we can help instead of asking for us to just give you code.
[CODE]for k, v in pairs(ents.GetAll()) do
if v:IsVehicle() then
v:Remove()
end
end[/CODE]
And
[lua]
hook.Add("PlayerSpawnVehicle", "DisallowSpawningOfVehicles", function() -- Adds the hook "PlayerSpawnVehicle" with the name of "DisallowSpawningOfVehicles" (This does not affect anything!) Then the function,
return false -- Returns false whenever someone tries to spawn a vehicle. (This means they will not be able to spawn it.
end) -- Ends the hook. The ")" is important as the hook was started with "("
[/lua]
Next time you hit a problem like this, I suggest you do some re-search on the wiki:
[url]http://maurits.tv[/url] -- Outdated, but has alot of examples.
[url]http://wiki.garrysmod.com[/url] -- More updated wiki, but has few examples and does not have alot of documentation.
[QUOTE=KevinnTCG;45711700][CODE]for k, v in pairs(ents.GetAll()) do
if v:IsVehicle() then
v:Remove()
end
end[/CODE][/QUOTE]
Going to put this on loop now. ;P
[editline]17th August 2014[/editline]
Okay thanks for the help everyone so now what I want to do is make it so it plays a sound when the timer hits 0:20 or whatever. Here is the code:
[CODE] draw.SimpleTextOutlined("The Purge Starts in", "William_Bebas_S27", ScrW()/2, 5, Color(255,255,255,255), TEXT_ALIGN_CENTER,0,1, Color( 100,0,0,255))
if PURGEtime == PurgePlayPurgeSoundStart then
surface.PlaySound( PurgeStartSound )
end[/CODE]
Glad I found this script on Facepunch since I am learning Lua as I go along :D
Sorry, you need to Log In to post a reply to this thread.