• Print

Author Topic: New Zombie Idea ( help )  (Read 7974 times)

0 Members and 1 Guest are viewing this topic.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
New Zombie Idea ( help )
« on: June 06, 2012, 09:24:27 pm »
hi , well im working on a ZOMBIE RP Server.

and i have almost done , i just need 2 things that i dont know how to code.
( if someone know , please help me ;) )

* I Want to make a system that every 30 Minutes the server automatically start a " event " with a zombie music and also, with a BIG Zombie ( Antilon Guard )
* The Server Clean All Corpses
* Zombie's Drop ( Ammo or health kits )

Thanks !
« Last Edit: June 06, 2012, 09:29:05 pm by Schiaffino »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #1 on: June 06, 2012, 09:40:10 pm »
The first and third are easy.. i'll get you started with some code examples... none of it is tested so take with a grain of salt...


Code: [Select]
timer.Create("eventtimer", 1600, 0, EventFunction)

function EventFunction()
     WorldSound( "path/to/music", Vector( 0, 0, 0 ), 160, 100 )

     local ent = ents.Create("npc_antlionguard")
     ent:SetPos(Vector(0,0,0)) -- Change this to where you want the guard to spawn.
     ent:Spawn() -- This method spawns the guard.
end


Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: New Zombie Idea ( help )
« Reply #2 on: June 06, 2012, 09:47:58 pm »
    little question

 ent:SetPos(Vector(0,0,0)) -- Change this to where you want the guard to spawn.

 ( how can i know a location on the map with vectors ? )

and this function i create a new file on autorun/server ?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #3 on: June 06, 2012, 11:33:30 pm »
If you have wire installed you can drop down a GPS entity to get the location.. or you can run this in your console...

lua_run_cl Msg(Self:GetPos());

^^Once again.. not sure if that will work.. but something along those lines.. I don't have gmod out here in Afghanistan to test any of this myself.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: New Zombie Idea ( help )
« Reply #4 on: June 07, 2012, 02:15:58 pm »
i try this code

Code: Lua
  1. timer.Create("eventtimer", 1600, 0, EventFunction)
  2.  
  3. function EventFunction()
  4.      WorldSound( "sound\realplay\tank.mp3", Vector( 0, 0, 0 ), 160, 100 )
  5.      local ent = ents.Create("npc_antlionguard")
  6.      ent:SetPos(Vector(1159,769,-607)) -- Change this to where you want the guard to spawn.
  7.      ent:Spawn() -- This method spawns the guard.
  8. end

And i receive this message on the screen



Any idea :( ?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #5 on: June 07, 2012, 02:49:58 pm »
try moving the timer.Create line to after the function.

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: New Zombie Idea ( help )
« Reply #6 on: June 07, 2012, 02:54:08 pm »
( i try with another folder and work the sound )

but....

There's a posibility to:

( start the music for 20 seconds. )
and also if  there is a way to code that when the NPC Die ,remove the body ? and the music ?like ( self:Remove() for the corpse ? )
« Last Edit: June 07, 2012, 03:04:07 pm by Schiaffino »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #7 on: June 07, 2012, 03:08:59 pm »
The problem with corpse removal is that Source handles all corpse ragdolls on the client side. There is certainly a way to override that, sure, but that is something I've never played with so I don't know how to do it.

To do the music for 20 seconds before spawning the guard you would need to place another timer inside of the main function that called another function that spawned the guard. You would have to split it up into 2 functions..

1st - Starts music and starts the 20 second timer.
2nd - Spawns the antlion guard.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #8 on: June 07, 2012, 03:10:41 pm »
Also check out this gamemode hook. Here is how you can do things based on when an NPC is killed.
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7b43.html


You would have to include a check to see what NPC was killed as that hook is called every time an NPC is killed. It's really easy though.. if there is only ONE guard spawned on the map at a time.. just check to see if it's an antlion guard that dies! :)

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: New Zombie Idea ( help )
« Reply #9 on: June 07, 2012, 04:42:31 pm »
* I Create the second timer for the music and works :)

also i have a question for the npc kill action :)

Code: Lua
  1.  
  2. function GM:OnNPCKilled( victim, killer, weapon )
  3.    Msg( victim:GetClass()  .. " was killed by " .. killer:GetName().. " with a " .. weapon:GetClass() .. ".\n" )
  4. end
  5.  
  6.  

but how i can make that the victim is a constant value ? i mean just 1 value like

Code: Lua
  1.  
  2. victim = ('npc_anglionguard')
  3.  
  4.  

¿?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #10 on: June 07, 2012, 06:39:06 pm »
victim is a variable passed by the hook...

the way the OnNPCKilled hook works is whenever ANY NPC is killed it fires that hook and passes 3 variables..
1. victim = the NPC that was killed
2. killer = what killed it.. can be a player, or another NPC or an entity
3. weapon = the weapon used if applicable


what you will need to do to only make it work with npc_antlionguard is to add a check into the function.

Code: [Select]
if victim:GetClass() == "npc_antlionguard" then
    code here
end

or you could exit the hook on all other accounts by having this line...

Code: [Select]
if not victim:GetClass() == "npc_antlionguard" then return end

Also.. I would advise against using the GM:OnNPCKilled function.. instead hook it...




Code: [Select]
function MyNPCKilledFunction(victim, killer, weapon)
     if not victim:GetClass() == "npc_antlionguard" then return end
     your code here
end
hook.Add( "OnNPCKilled", "MyNPCKilledFunction", MyNPCKilledFunction )

Offline Schiaffino

  • Jr. Member
  • **
  • Posts: 88
  • Karma: 1
Re: New Zombie Idea ( help )
« Reply #11 on: June 07, 2012, 07:51:21 pm »
i finally put the code like this and work good

Code: Lua
  1.  
  2. function EventFunction()
  3.      WorldSound( "tank.mp3", Vector( 0, 0, 0 ), 160, 100 )
  4.      local ent = ents.Create("npc_antlionguard")
  5.      ent:SetPos(Vector(1159,769,-607)) -- Change this to where you want the guard to spawn.
  6.      ent:Spawn() -- This method spawns the guard.
  7. end
  8. timer.Create("eventtimer", 120, 0, EventFunction)
  9.  
  10. function GM:OnNPCKilled( victim, killer, weapon )
  11.  
  12. if victim:GetClass() == "npc_antlionguard" then
  13. Msg( victim:GetClass()  .. " was killed by " .. killer:GetName().. " with a " .. weapon:GetClass() .. ".\n" )
  14. end
  15. end
  16.  
  17.  

:)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: New Zombie Idea ( help )
« Reply #12 on: June 07, 2012, 09:22:26 pm »
I'm glad you got it to work, but the problem with overriding your gamemode function like that is compatibility with other things not to mention some unwanted side effects. Currently if you kill anything other than an antlion guard the hook wont fire since you only have code within the if statement for that parameter. You should hook it like I showed in my previous example. If for no other reason than it's good practice.

Only ever override a gamemode function if you want to remove all default behavior and replace it entirely with your own code.

  • Print