Garry's Mod

Garry's Mod

nZombies - A Nazi Zombies Gamemode [Content Pack]
Hidden 30. nov. 2016 kl. 14:47
Help with Map Scripts
I'm having a LOT of difficulty with adding items that the player can carry around and place down.
In this case, a ladder that players can pick up at "Spawn" and place it in the "Diner".
local gascanpositions = { {pos = Vector(396, -146, 73), ang = Angle(0, 0, 0)} } local gascanobject = nzItemCarry:CreateCategory("gascan") gascanobject:SetModel("models/props_junk/gascan001a.mdl") gascanobject:SetText("Press E to pick up the Gas Can.") gascanobject:SetDropOnDowned(true) gascanobject:SetDropFunction( function(self, ply) scriptgascan = ents.Create("nz_script_prop") scriptgascan:SetModel("models/props_junk/gascan001a.mdl") scriptgascan:SetPos(ply:GetPos()) scriptgascan:SetAngles(Angle(0,0,0)) scriptgascan:Spawn() self:RegisterEntity( scriptgascan ) end) gascanobject:SetResetFunction( function(self) local ran = gascanpositions[math.random(table.Count(gascanpositions))] if ran and ran.pos and ran.ang then scriptgascan = ents.Create("nz_script_prop") scriptgascan:SetModel("models/props_junk/gascan001a.mdl") scriptgascan:SetPos(ran.pos) scriptgascan:SetAngles(ran.ang) scriptgascan:Spawn() self:RegisterEntity( scriptgascan ) end end) gascanobject:Update() local dinerroofhole = ents.FindByName("diner_ceiling_door")[1] local dinerladder = ents.FindByName("diner_ladder")[1] local scriptdinerladder = ents.Create("nz_script_prop") scriptdinerladder:SetPos(Vector(-2147, 2734, 184)) scriptdinerladder:SetAngles(Angle(0, 90, 0)) scriptdinerladder:SetModel("models/props/cs_assault/ladderaluminium128.mdl") scriptdinerladder:SetNoDraw(true) scriptdinerladder:SetNWString("NZText", "Missing Parts.") scriptdinerladder:SetNWString("NZRequiredItem", "gascan") scriptdinerladder:SetNWString("NZHasText", "Press E to Add Part.") scriptdinerladder:Spawn() scriptdinerladder:Activate() -- Function when it is used (E) scriptdinerladder.OnUsed = function( self, ply ) if ply:HasCarryItem("item_ladder1") then -- Only if we picked up the ladder ply:RemoveCarryItem("item_ladder1") dinerladder:Fire("Enable") dinerladder:Fire("EnableCollision") dinerroofhole:Fire("Disable") end end

(it says "gascan" because i was so frustrated i just copied it from the wiki)
But the gas can simply doesn't spawn in. And i have it in OnGameBegin().
< >
Viser 1-15 af 17 kommentarer
Zet0r  [udvikler] 30. nov. 2016 kl. 15:19 
That is not supposed to be in OnGameBegin. That there is just supposed to be outside any mapscript function. After doing that, in OnGameBegin call gascanobject:Reset() - that causes the ResetFunction to be run (which is where you should create the prop). Also localize scriptgascan if you have not already outside the code shown.

The creation of the ladder however should be in OnGameBegin. Generally anything you need to set up code-wise (items, logic, etc) can be called outside OnGameBegin, then inside it is where you do map-related stuff (since it takes place after the cleanup)
Sidst redigeret af Zet0r; 30. nov. 2016 kl. 15:21
Hidden 30. nov. 2016 kl. 15:27 
You mean none of this code is supposed to be in OnGameBegin?
Hidden 30. dec. 2016 kl. 6:38 
By the way, How can i set "trigger_hurt" to harm the zombies (if possible at all)?
Zet0r  [udvikler] 30. dec. 2016 kl. 6:51 
Oprindeligt skrevet af (uλ) Hidden:
By the way, How can i set "trigger_hurt" to harm the zombies (if possible at all)?
You can't, but I want to have them do this eventually. Well I guess you can if you code it, but I don't yet know what code is needed to do this.
Hidden 30. dec. 2016 kl. 7:03 
Can the Damage Walls be turned ON and OFF via the logic mechanism?
Zet0r  [udvikler] 30. dec. 2016 kl. 7:04 
Oprindeligt skrevet af (uλ) Hidden:
Can the Damage Walls be turned ON and OFF via the logic mechanism?
Nope, could probably make them do that. You can also use a map script to enable and disable it and its damage just by setting the networkvars.
Hidden 2. jan. 2017 kl. 11:40 
And until such a function is added, how do i set these networkvars? Excuse me if i'm asking too many questions. I'm making an nZombies map.
Sidst redigeret af Hidden; 2. jan. 2017 kl. 11:41
Zet0r  [udvikler] 2. jan. 2017 kl. 11:59 
Oprindeligt skrevet af (uλ) Hidden:
And until such a function is added, how do i set these networkvars? Excuse me if i'm asking too many questions. I'm making an nZombies map.
Look into the files of the entities and look for NetworkVars. The strings at the end will turn into functions with Get* and Set* in front. You can look through most of the code for examples and how they're used. Find the damage wall entity in the /entities/ folder.
Hidden 8. jan. 2017 kl. 8:28 
Quick question: Which brush entities can zombies go through when passing through barricades (appart from func_illusionary)? Also, how do i activate a specific func_button when the power gets turned on?
Zet0r  [udvikler] 8. jan. 2017 kl. 9:06 
func_buttons are Hammer based entities, so you'll need to use Entity:Fire() on them, with the inputs as they are listed on the Valve Developer Wiki. For buttons you'll probably want button:Fire("Lock") and button:Fire("Unlock"). Not sure which brush entities Zombies can go through, you might want to look at Player Clips. Barricades are Lua entities, not brush entities. They work by just doing self:SetSolid(SOLID_NONE) whenever a zombie passes through.
Hidden 8. jan. 2017 kl. 9:12 
As for "When the power gets turned on"?
Hidden 8. jan. 2017 kl. 10:45 
I'm a bit confused (i'm somewhat new to lua). i need you to be a bit more specific.

Here's what i wrote:

local powerbutton = ents.FindByName("powerstation_test_button")[1] if IsElec() then powerbutton:Fire("Press") end hook.Add("ElectricityOn", "IsElec", func)
Zet0r  [udvikler] 8. jan. 2017 kl. 11:04 
http://wiki.garrysmod.com/page/Hook_Library_Usage

Remember code only runs the moment it runs - your if IsElec statement is only checked once and only checked the moment the code is ran (map script is loaded)
Hidden 8. jan. 2017 kl. 11:25 
local powerbutton = ents.FindByName("powerstation_test_button")[1] hook.Add("ElectricityOn", "IsElec", function() powerbutton:Fire("Press") )

Will this work?
Sidst redigeret af Hidden; 8. jan. 2017 kl. 11:26
< >
Viser 1-15 af 17 kommentarer
Per side: 1530 50