Thanks for the help squeek. However, I guess I just don't understand enough about the lua to get this to work. What I am trying to do is mainly use that getorigin to compare the position of the flag at any given moment to where the flag spawns at. If the flag is there I would like a switch to become usable, and if it is not obviously make the switch unusable. Since I didn't know how to tell the switch to lock or unlock through the lua I tried just changing it to only work for a team that isn't in that map (kGreen or kYellow). However as much as I try I can not get this to work.
Here is my lua code to do this. If any one could take a look and tell me what I am doing wrong. I am sure there are a lot of mistakes to it. So don't hold back on ripping it apart.
Code:
button_common = func_button:new({ team = Team.kUnassigned })
function button_common:allowed( allowed_entity )
if IsPlayer( allowed_entity ) then
local player = CastToPlayer( allowed_entity )
if player:GetTeamId() == self.team then
return EVENT_ALLOWED
end
end
return EVENT_DISALLOWED
end
-- TODO this doesn't work
function button_common:onfailuse( use_entity )
if IsPlayer( use_entity ) then
local player = CastToPlayer( use_entity )
BroadCastMessageToPlayer( player, "#FF_NOTALLOWEDBUTTON" )
end
end
AddSchedule("CheckFlag", 1, getflagorigin)
function getflagorigin()
local flag = GetInfoScriptByName( "red_flag")
local pos = flag:GetOrigin()
if pos.x == 319 then
if pos.y == -297 then
if pos.z == 237 then
red_button_lower = button_common:new({ team = Team.kBlue })
else
red_button_lower = button_common:new({ team = Team.kGreen })
end
else
red_button_lower = button_common:new({ team = Team.kGreen })
end
else
red_button_lower = button_common:new({ team = Team.kGreen })
end
end
As of right now I am just hard coding the original location of where the flag is suppose to spawn. If I can get this to work I will have it find the cordinates on map startup and set them to a variable and compare it to that. That way the flag can be moved in hammer without having to edit the lua everytime. Again thank you for any help you guys can give me.