Map Script Reference Snippets - nZombies-Time/nZombies-Rezzurrection GitHub Wiki
This page contains references to all nZombies related functions and features you can use in your map script. It will not cover all available functions as there are simply too many core gamemode functions that you can also use, but it will instead focus on the most map script-specific and useful functions and utilities.
For guides on how these utilities work, see Map Scripting.
Table of Contents
- Item Carry System
- Items
- Player
- Snippets
- Buildables
- Snippets
- Soul Collectors
- Snippets
- nzEE.Major
- Snippets
- nzEE.Cam
- Snippets
Item Carry System
See Item Carry System.
Items
Create Category
item = nzItemCarry:CreateCategory("id")
Creates an item object with this ID and returns the object. Overwrites any previous item with this ID.
Set Text
item:SetText("String")
Sets the text to display when players look at entities registered to this item.
Defaults to "Press E to pick up."
Set Has Text
item:SetHasText("String")
Sets the text to display when players look at entities registered to this item and they are already carrying an item of this ID.
Defaults to "You already have this."
Set Model
item:SetModel("models/path/model.mdl")
Optional. Sets the model to display on the HUD when an item of this ID is being carried.
Either Model or Icon has to be set for the item to be visible on the HUD!
Set Icon
item:SetIcon("materials/path/icon.png")
Optional. Sets the icon to display on the HUD when an item of this ID is being carried. If Model is set, this icon will be displayed on top of the model's icon as a little icon in its corner. Otherwise, this icon will become the full-size icon for this item.
Either Model or Icon has to be set for the item to be visible on the HUD!
Set Shared
item:SetShared(true/false)
If set to true, when any player picks up this item, all players get it in their inventory, and when used will remove from all player's inventories.
Set Drop On Downed
item:SetDropOnDowned(true/false)
If set to true, will call Drop Function (Set in ItemCarry/SetDropFunction) when the carrying player goes down.
Set Show Notification
item:SetShowNotification( true/false )
Sets whether the item will show a global notification to all players when any player picks it up. Shared items will not display avatar of the player who picked it up, but non-shared will.
Set Drop Function
item:SetDropFunction( function( self, player ) )
Sets the function to call when the player goes down and Drop On Downed is set to true. This is where you want to re-create the prop/model and re-register it to the object. Remember to remove the item from the player's inventory with ItemCarry/player/RemoveCarryItem.
Set Reset Function
item:SetResetFunction( function(self) )
Sets the function to call when calling item:Reset()
or when a player carrying the item disconnects with Drop On Downed set to false. This is where you want to create the initial models that can be picked up. You will want to call item:Reset()
when the game begins in your script, as this function should be responsible for initializing and resetting.
Set Condition
item:SetCondition( function( self, player ) )
Sets the function to determine whether the player can pick up items registered to this object. Should return true to allow, false to not.
Set Pickup Function
item:SetPickupFunction( function( self, player, entity ) )
Sets the function to call when a player picks up an entity registered to this item object. The entity picked up is entity
. If you overwrite this, remember to give the player the item with ItemCarry/player/GiveCarryItem and remove the entity.
Update
item:Update()
Networks all changes made to the object that the client needs to know. This includes Text, HasText, Icon, Model. You will want to call this after setting all the values as they are not networked by themselves.
Reset
item:Reset()
Runs the Reset function.
RegisterEntity
item:RegisterEntity( entity )
Registers an entity to this item object. When registered, this item will display text when looked at, and will run Condition and PickupFunction when interacted with. You will want to run this on all models/props that you want to be able to pick up in this item's category.
Get Entities
table = item:GetEntities()
Returns a table of all entities registered to this item object.
Player
Give Carry Item
player:GiveCarryItem("id")
Gives a player this item into their inventory.
Remove Carry Item
player:RemoveCarryItem("id")
Removes an item from this player's inventory.
Has Carry Item
player:HasCarryItem("id")
Returns true if the player is carrying this item, false otherwise.
Get Carry Items
table = player:GetCarryItems()
Returns a table of the IDs of all items this player is carrying.
Snippets
Creates a gascan similar to Breakout's and makes it able to be dropped. When gascanobject:Reset()
is called, it will spawn at a random position and angle in the table. You can add as many as you want.
local gascanpositions = {
{pos = Vector(1, 2, 3), ang = Angle(0, 0, 0)},
{pos = Vector(4, 5, 6), ang = Angle(0, 0, 0)},
{pos = Vector(7, 8, 9), 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()
Buildables
See Buildables.
Creation
workbench = ents.Create("buildable_table")
Buildable Tables are accessed by creating entities of the class buildable_table.
Add Valid Craft
workbench:AddValidCraft("id", table)
Adds a craftable item to this workbench's list of things that can be crafted at it. Takes a table containing crafting data, see Creating a Buildable.
Snippets
Adds the buildable Zombie Shield to your config, along with a table to craft it at and all parts. You can edit the positions and angles in shieldparts
, and add as many entries into each part's subtable as you want.
local shieldparts = {
[1] = { -- Fence
{pos = Vector(324, 348, 205), ang = Angle(15,-45,0)},
{pos = Vector(16, 523, 180), ang = Angle(-8, 0, 0)},
{pos = Vector(602, 741, 332), ang = Angle(5, 0, 0)},
{pos = Vector(-205, 377, 132), ang = Angle(-90, -90, 180)},
{pos = Vector(575, 887, 186), ang = Angle(45, 90, 90)},
},
[2] = { -- Radiator
{pos = Vector(1200, -669, 274), ang = Angle(0,43,0)},
{pos = Vector(935, -349, 379), ang = Angle(-90, -133, 180)},
{pos = Vector(1116, -250, 274), ang = Angle(0,0,0)},
{pos = Vector(1130, -1058, 269), ang = Angle(45,-90,0)},
{pos = Vector(803, -1775, 338), ang = Angle(0,0,0)},
},
[3] = { -- Posts
{pos = Vector(336, 570, 16), ang = Angle(0,0,0)},
{pos = Vector(338, 120, 37), ang = Angle(-10, 18, 45)},
{pos = Vector(560, 960, 134), ang = Angle(-90, -90, 180)},
{pos = Vector(1059, 906, 0), ang = Angle(0,75,0)},
{pos = Vector(1615, 953, -4), ang = Angle(0,90,0)},
}
}
local shield1 = nzItemCarry:CreateCategory("shield1")
shield1:SetModel("models/props_c17/fence01b.mdl")
shield1:SetText("Press E to pick up part.")
shield1:SetDropOnDowned(false)
shield1:SetShared(false)
shield1:SetResetFunction( function(self)
local poss = shieldparts[1]
local ran = poss[math.random(table.Count(poss))]
if ran and ran.pos and ran.ang then
local part = ents.Create("nz_script_prop")
part:SetModel("models/props_c17/fence01b.mdl")
part:SetPos(ran.pos)
part:SetAngles(ran.ang)
part:Spawn()
self:RegisterEntity( part )
end
end)
shield1:Update()
local shield2 = nzItemCarry:CreateCategory("shield2")
shield2:SetModel("models/props_c17/furnitureradiator001a.mdl")
shield2:SetText("Press E to pick up part.")
shield2:SetDropOnDowned(false)
shield2:SetShared(false)
shield2:SetResetFunction( function(self)
local poss = shieldparts[2]
local ran = poss[math.random(table.Count(poss))]
if ran and ran.pos and ran.ang then
local part = ents.Create("nz_script_prop")
part:SetModel("models/props_c17/furnitureradiator001a.mdl")
part:SetPos(ran.pos)
part:SetAngles(ran.ang)
part:Spawn()
self:RegisterEntity( part )
end
end)
shield2:Update()
local shield3 = nzItemCarry:CreateCategory("shield3")
shield3:SetModel("models/props_c17/playgroundtick-tack-toe_post01.mdl")
shield3:SetText("Press E to pick up part.")
shield3:SetDropOnDowned(false)
shield3:SetShared(false)
shield3:SetResetFunction( function(self)
local poss = shieldparts[3]
local ran = poss[math.random(table.Count(poss))]
if ran and ran.pos and ran.ang then
local part = ents.Create("nz_script_prop")
part:SetModel("models/props_c17/playgroundtick-tack-toe_post01.mdl")
part:SetPos(ran.pos)
part:SetAngles(ran.ang)
part:Spawn()
self:RegisterEntity( part )
end
end)
shield3:Update()
local buildabletbl = {
model = "models/weapons/w_zombieshield.mdl",
pos = Vector(0,0,60), -- (Relative to tables own pos)
ang = Angle(0,180,90), -- (Relative too)
parts = {
["shield1"] = {0,1}, -- Submaterials to "unhide" when this part is added
["shield2"] = {2}, -- id's are ItemCarry object IDs
["shield3"] = {3},
-- You can have as many as you want
},
usefunc = function(self, ply) -- When it's completed and a player presses E (optional)
if !ply:HasWeapon("nz_zombieshield") then
ply:Give("nz_zombieshield")
end
end,
text = "Press E to pick up Zombie Shield"
}
-- Put this inside mapscript.OnGameBegin()
local tbl = ents.Create("buildable_table")
tbl:AddValidCraft("Zombie Shield", buildabletbl)
tbl:SetPos(Vector(-771, -880, -2)) -- Change this position
tbl:SetAngles(Angle(0,-90,0)) -- Change this too
tbl:Spawn()
-- You can create multiple tables and give them all the same "buildabletbl" to allow
-- the shield to be crafted multiple places (but only one at a time)
shield1:Reset()
shield2:Reset()
shield3:Reset()
Soul Catchers
Creation
catcher = ents.Create("nz_script_soulcatcher")
Soul Catchers are just entities that will collect souls of nearby killed zombies. They are recommended to get SetNoDraw(true)
, but can also have a model.
Set Catch Function
catcher:SetCatchFunction( function(self) )
Sets the function that runs every time a soul is collected.
Set Complete Function
catcher:SetCompleteFunction( function(self) )
Sets the function that runs when all souls have been collected
Set Target Amount
catcher:SetTargetAmount( number )
Sets how many souls the catcher will need before it is completed.
Set Range
catcher:SetRange( number )
Sets the range in which souls are collected.
Set Enabled
catcher:SetEnabled( true/false )
Enables/Disables the catcher. It will not run while SetEnabled is set to false.
Set Release Override
catcher:SetReleaseOverride( function(self, zombie) )
Overrides the function that handles effect and actual collecting of souls. This can be used to make custom effects. Remember to call self:CollectSoul()
to make the catcher finish. It is recommended you do this at the end of the effect. You also need to use self:SetCurrentAmount(number)
to increment its count.
Set Current Amount
catcher:SetCurrentAmount( number )
Sets how many souls we currently have. This will not trigger CompleteFunction, call catcher:CollectSoul()
after to do this. Current amount is stored in catcher.CurrentAmount
.
Reset
catcher:Reset()
Sets current amount of souls to 0.
Snippets
Creates a Soul Collector that needs 20 kills within 400 units range while Electricity is on. When completed, it will open all doors that got the "hiddendoor" link set in the Door Tool.
local collector = ents.Create("nz_script_soulcatcher")
end
collector:SetNoDraw(true)
collector:SetPos(Vector(0,0,0)) -- Change this
collector:SetModel("models/hunter/blocks/cube025x025x025.mdl")
collector:Spawn()
collector:SetTargetAmount(20)
collector:SetRange(300)
collector:SetCompleteFunction( function(self)
nzDoors:OpenLinkedDoors("hiddendoor")
self:Remove()
end)
collector:SetCondition( function(self, z, dmg)
return nzElec.Active
end)