Difference between revisions of "Lua:nobuild"

From Fortress Forever Wiki
Jump to navigationJump to search
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==No Build Areas - "nogrens"==
+
{{Infobox manual/Header}}
 +
==No Build Areas - "nobuild"==
  
A "nogrens" area is defined as an area where grenades will not explode - hence "nogrens". To create a "nogrens" area in your map all you need to do is create a brush, click "tie to entity", choose trigger_ff_script, and then name it "nogrens". Then, in your map's .LUA file be sure to include base_teamplay.lua as such:
+
A "nobuild" area is defined as an area where a player is not allowed to build a dispenser or sentrygun - hence "nobuild". To create a "nobuild" area in your map all you need to do is create a brush, click "tie to entity", choose trigger_ff_script, and then name it "nobuild". Then, in your map's .LUA file be sure to include base_teamplay.lua as such:
  
 
<pre>-- Map's LUA file
 
<pre>-- Map's LUA file
  
-- Include nogrens functionality
+
-- Include nobuild functionality
 
IncludeScript( "base_teamplay" )</pre>
 
IncludeScript( "base_teamplay" )</pre>
  
 
===How It Works===
 
===How It Works===
The way a "nogrens" area works is that before the grenade goes to explode it checks to see just exactly what entities it is touching. It then asks those entity if it can explode. If any of the entities respond back with "false" then the grenade can not explode. The LUA function that answers the question if the grenade can explode is "canexplode" (as seen in the example) so if you want to override default "nogrens" behavior then your custom "nogrens" lua object will need to have a "canexplode" function.
+
The way a "nobuild" area works is that when the player tries to build the game checks to see just exactly what entities the player is touching. It then asks those entity if it the player can build. If any of the entities respond back with "false" then the player cannot build. The LUA function that answers the question if the player can build is "canbuild" (as seen in the example) so if you want to override default "canbuild" behavior then your custom "nobuild" lua object will need to have a "canbuild" function.
  
 
===Example===
 
===Example===
If you wanted red team to be able to throw grenades in an area (and have them explode) but blue team not be allowed to do that then you can do that. There are really only two changes you would need to make. First, name your "nogrens" area (in hammer) to something else - like "blue_nogrens". Then, modify your map's lua file thusly:
+
If you wanted red team to be able to build in an area but blue team not be allowed to do that then you can do that. There are really only two changes you would need to make. First, name your "nobuild" area (in hammer) to something else - like "blue_nobuild". Then, modify your map's lua file thusly:
  
<pre>
+
<pre>-- Map's LUA file
-- Map's LUA file
 
  
-- Define "blue_nogrens"
+
-- Define "blue_nobuild"
blue_nogrens = trigger_ff_script({})
+
blue_nobuild = trigger_ff_script({})
  
-- Let red team's grenades explode but not blue team's
+
-- Let red team build but not blud team
-- here we define the "canexplode" function
+
-- here we define the "canbuild" function
function blue_nogrens:canexplode( ent_id )  
+
function blue_nobuild:canbuild( ent_id )  
     if IsGrenade( ent_id ) then
+
     if IsPlayer( ent_id ) then
 
           -- Allow red team
 
           -- Allow red team
           if ( GetObjectsTeam( ent_id ) == RED_TEAM ) then
+
           if ( GetPlayerTeam( ent_id ) == RED_TEAM ) then
 
               return true
 
               return true
           else -- Disallow everyone other team
+
           else -- Disallow every other team
 
               return false
 
               return false
 
           end
 
           end
 
     end
 
     end
  
     -- Return normally for anything not a grenade
+
     -- Return normally for anything else
 
     return true
 
     return true
end
+
end</pre>
 
 
[[Category:LUA]]
 
  
</pre>
+
[[Category:Lua]]
 +
{{Infobox manual/Footer}}

Latest revision as of 16:15, 31 December 2007


No Build Areas - "nobuild"

A "nobuild" area is defined as an area where a player is not allowed to build a dispenser or sentrygun - hence "nobuild". To create a "nobuild" area in your map all you need to do is create a brush, click "tie to entity", choose trigger_ff_script, and then name it "nobuild". Then, in your map's .LUA file be sure to include base_teamplay.lua as such:

-- Map's LUA file

-- Include nobuild functionality
IncludeScript( "base_teamplay" )

How It Works

The way a "nobuild" area works is that when the player tries to build the game checks to see just exactly what entities the player is touching. It then asks those entity if it the player can build. If any of the entities respond back with "false" then the player cannot build. The LUA function that answers the question if the player can build is "canbuild" (as seen in the example) so if you want to override default "canbuild" behavior then your custom "nobuild" lua object will need to have a "canbuild" function.

Example

If you wanted red team to be able to build in an area but blue team not be allowed to do that then you can do that. There are really only two changes you would need to make. First, name your "nobuild" area (in hammer) to something else - like "blue_nobuild". Then, modify your map's lua file thusly:

-- Map's LUA file

-- Define "blue_nobuild"
blue_nobuild = trigger_ff_script({})

-- Let red team build but not blud team
-- here we define the "canbuild" function
function blue_nobuild:canbuild( ent_id ) 
     if IsPlayer( ent_id ) then
          -- Allow red team
          if ( GetPlayerTeam( ent_id ) == RED_TEAM ) then
               return true
          else -- Disallow every other team
               return false
          end
     end

     -- Return normally for anything else
     return true
end