Garry's Mod

Garry's Mod

nZombies - A Nazi Zombies Gamemode [Content Pack]
Hidden 2016 年 11 月 30 日 下午 2: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().
< >
正在显示第 1 - 15 条,共 17 条留言
Zet0r  [开发者] 2016 年 11 月 30 日 下午 3: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)
最后由 Zet0r 编辑于; 2016 年 11 月 30 日 下午 3:21
Hidden 2016 年 11 月 30 日 下午 3:27 
You mean none of this code is supposed to be in OnGameBegin?
Hidden 2016 年 12 月 30 日 上午 6:38 
By the way, How can i set "trigger_hurt" to harm the zombies (if possible at all)?
Zet0r  [开发者] 2016 年 12 月 30 日 上午 6:51 
引用自 (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 2016 年 12 月 30 日 上午 7:03 
Can the Damage Walls be turned ON and OFF via the logic mechanism?
Zet0r  [开发者] 2016 年 12 月 30 日 上午 7:04 
引用自 (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 2017 年 1 月 2 日 上午 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.
最后由 Hidden 编辑于; 2017 年 1 月 2 日 上午 11:41
Zet0r  [开发者] 2017 年 1 月 2 日 上午 11:59 
引用自 (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 2017 年 1 月 8 日 上午 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  [开发者] 2017 年 1 月 8 日 上午 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 2017 年 1 月 8 日 上午 9:12 
As for "When the power gets turned on"?
Hidden 2017 年 1 月 8 日 上午 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  [开发者] 2017 年 1 月 8 日 上午 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 2017 年 1 月 8 日 上午 11:25 
local powerbutton = ents.FindByName("powerstation_test_button")[1] hook.Add("ElectricityOn", "IsElec", function() powerbutton:Fire("Press") )

Will this work?
最后由 Hidden 编辑于; 2017 年 1 月 8 日 上午 11:26
< >
正在显示第 1 - 15 条,共 17 条留言
每页显示数: 1530 50