So basically, is it possible to make a counter which can be displayed in-game, then everytime you kill an NPC it would add "1" to this counter, then start a new round when the counter reaches a desired number, also, how can I make rounds? Help appreciated
More information, should it be for more players, or only for one?
For players, you would have a team of say 4 people, then I need it so all their kills accumalate onto the counter.
Then like I said, when the counter reaches desired amount a new round would start.
Okay, that made it too difficult for me :s
Sorry, can't help ya D:
no worries, hope someone can though.
[lua]
if SERVER then
AddCSLuaFile("yourfile.lua")
function KillCounter( victim, killer, weapon )
if killer:GetNWInt("killcounter") >= 10 then
PrintMessage(HUD_PRINTTALK, "Person won " .. killer:GetName())
timer.Simple(3, function()
game.ConsoleCommand("changelevel gm_flatgrass\n")
end)
end
killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1)
end
hook.Add("OnNPCKilled","KillCounter", KillCounter)
else
function killcounter()
draw.WordBox( 8, ScrW() - 920, ScrH() - 98, "KillCount: "..LocalPlayer():GetNWInt("killcounter"),"ScoreboardText",Color(200,0,0,0),Color(255,255,255,255))
end
hook.Add("HUDPaint","KillCounter",killcounter)
end[/lua]
Place in lua/autorun/yourfile.lua
Possible to incorporate that into my init.lua?
[QUOTE=sphinxa279;22660840]Possible to incorporate that into my init.lua?[/QUOTE]
Yes
Server: Init.lua
[lua]
function KillCounter( victim, killer, weapon )
if killer:GetNWInt("killcounter") >= 10 then
PrintMessage(HUD_PRINTTALK, "Person won " .. killer:GetName())
timer.Simple(3, function()
game.ConsoleCommand("changelevel gm_flatgrass\n")
end)
end
killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1)
end
hook.Add("OnNPCKilled","KillCounter", KillCounter)
[/lua]
Client: cl_Init.lua
[lua]
function killcounter()
draw.WordBox( 8, ScrW() - 920, ScrH() - 98, "KillCount: "..LocalPlayer():GetNWInt("killcounter"),"ScoreboardText",Color(200,0,0,0),Color(255,255,255,255))
end
hook.Add("HUDPaint","KillCounter",killcounter)
[/lua]
Oh I see, what came after the else in the original function was client side and everything before was server side, thankyou, you just gave me a quick lesson, Informative for you. :smile:
[editline]06:25PM[/editline]
Mhmm, is it possible to detect what map you are playing on and run a function based on the map name?
[QUOTE=sphinxa279;22661227]Oh I see, what came after the else in the original function was client side and everything before was server side, thankyou, you just gave me a quick lesson, Informative for you. :smile:
[editline]06:25PM[/editline]
Mhmm, is it possible to detect what map you are playing on and run a function based on the map name?[/QUOTE]
Actually that else did nothing in the code, it would just have produced an error.
This also is an individual killcount.
For your question see [b][url=wiki.garrysmod.com/?title=game.GetMap]game.GetMap [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
[QUOTE=sphinxa279;22661227]
Mhmm, is it possible to detect what map you are playing on and run a function based on the map name?[/QUOTE]
Yes it is, it would look something like this.
[lua]
local map = [string.lower(game.GetMap())]
if map == "rp_downtown_v2" then game.ConsoleCommand("say hi\n")
end
[/lua]
Oh excellent, how would it be possible to incorporate that with Cubar's script he gave me, the same way Gmod.com has done the "I hate RP" Script?
[editline]06:59PM[/editline]
Because what I really want it to do, is once a player has gotten a certain amount of kills, it will go to another map DEPENDING on what map the gamemode is currently on.
[QUOTE=Crazy Quebec;22661770]Actually that else did nothing in the code, it would just have produced an error.
This also is an individual killcount.
For your question see [b][url=wiki.garrysmod.com/?title=game.GetMap]game.GetMap [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].[/QUOTE]
I was using if SERVER then if you saw, was for autorun, and it still worked. :wink:
Ah right, right. I misread that.
Cubar, for your changemap function, is it possible to use the lua wildcard so I can get a random map, for example: "zc_*"
Excellent, thanks Quebec.
[editline]09:33PM[/editline]
Excellent, one more question if you can answer so kindly, how would I make entites, such as item_ammo_357 spawn at a location in a hammer map, the thing is I want the items to spawn randomly across the map, possible with lua or easier to do in Hammer?
[QUOTE=sphinxa279;22665868]Excellent, thanks Quebec.
[editline]09:33PM[/editline]
Excellent, one more question if you can answer so kindly, how would I make entites, such as item_ammo_357 spawn at a location in a hammer map, the thing is I want the items to spawn randomly across the map, possible with lua or easier to do in Hammer?[/QUOTE]
Initpostentity and ents.Create("yourname") + SetPos + Spawning it :wink:
[lua]
local randompos = {
Vector(1694.0104, 458.9413, -0.9688),
Vector(1860.0646, 266.5132, -0.9687)
}
function InitSpawn()
local itemammo = ents.Create("item_ammo_357")
itemammo:SetPos(randompos[math.random(2)])
itemammo:Spawn()
end
hook.Add("InitPostEntity","spawnstuff",InitSpawn)[/lua]
[LUA]itemammo:SetPos(randompos[math.random(2)])[/LUA]
Instead of setting a position using math is it possible to set to a custom hammer entity to spawn at?
Then instead of using the item_ammo_357 I could put several ammo items into a table, and use the table after ents.Create, sorry if this didn't make sense, I'm tired :v:
Sorry if this bumps the thread but I'm awake now so I can explain a little better, I really want it so it does the function you have there, but having a table full of item entities such as:
[LUA]local ammo = {
("item_ammo_357"),
("another_ammo")
}[/LUA]
is that the right way to make a table full of entites, I also want these entities, instead of spawning at a random position to spawn at a hammer entity e.g "zc_ammo_spawn", so could I put that there instead of the whole randompos(math.random(2)) thing?
That table code is wrong, this one's correct
[lua]
local ammo = {
"item_ammo_357",
"anothera ammo",
"and another one"
}
[/lua]
For your other question:
[lua]
function InitAmmoSpawn()
local itemammo = ents.Create(table.Random(ammo))
itemammo:SetPos(ents.FindByClass("zc_ammo_spawn"):GetPos())
itemammo:Spawn()
end
hook.Add("InitPostEntity", "AmmoSpawn", InitAmmoSpawn)
[/lua]
Untested, but it should work
Excellent, thanks Loures, as you see I'm very new to Lua but at least I know the correct way to make a table, I'll try these as soon as I'm back on my main PC, Thanks![U][URL="http://www.facepunch.com/member.php?u=199317"][/URL][/U]
[QUOTE=Loures;22706901]That table code is wrong, this one's correct
[lua]
local ammo = {
"item_ammo_357",
"anothera ammo",
"and another one"
}
[/lua]
For your other question:
[lua]
function InitAmmoSpawn()
local itemammo = ents.Create(table.Random(ammo))
itemammo:SetPos(ents.FindByClass("zc_ammo_spawn"):GetPos())
itemammo:Spawn()
end
hook.Add("InitPostEntity", "AmmoSpawn", InitAmmoSpawn)
[/lua]
Untested, but it should work[/QUOTE]
That code won't work. Try this:
[lua]
function InitAmmoSpawn()
local itemammo = ents.Create(table.Random(ammo))
local spawn = table.Random(ents.FindByClass("zc_ammo_spawn"))
itemammo:SetPos(spawn:GetPos())
itemammo:Spawn()
end
hook.Add("InitPostEntity", "AmmoSpawn", InitAmmoSpawn)
[/lua]
Otherwise, it would have tried to call GetPos() on the table.
Oh snap, forgot about the FindBy functions returning tables, thanks for fixing GranPC :D
Got these:
[LUA]
Attempted to create unknown entity type zc_ammo_spawn!
Can't init zc_ammo_spawn
Attempted to create unknown entity type item_ammo_!
ERROR: Hook 'AmmoSpawn' Failed: lua\includes\extensions\table.lua:177: bad argument #2 to 'random' (interval is empty)
Removing Hook 'AmmoSpawn'
[/LUA]
The above code is in my init.lua, wrong place?
[editline]10:18PM[/editline]
These are in the init.lua
[LUA]local ammo = {
"item_ammo_",
"item_ammo_pistol",
"item_ammo_smg1",
"item_healthkit"
}
function InitAmmoSpawn()
local itemammo = ents.Create(table.Random(ammo))
local spawn = table.Random(ents.FindByClass("zc_ammo_spawn"))
itemammo:SetPos(spawn:GetPos())
itemammo:Spawn()
end
hook.Add("InitPostEntity", "AmmoSpawn", InitAmmoSpawn) [/LUA]
Attempted to create unknown entity type zc_ammo_spawn!
No entity with that name named in entities/entities/
Will it not find that entity in my hammer map to spawn at?
No, it has to be spawned in either lua entities or created in hammer as an entity.
I think there are already made entity's in gmod that you can spawn, or find on gmod.org!
It is created in hammer as an entity, I made a custom .fgd file
you have to create a lua version of the entity: [url]http://wiki.garrysmod.com/?title=Entity_Hooks#Point[/url] This will be the one you want.
Sorry, you need to Log In to post a reply to this thread.