Jump to content

Not even sure why this doesnt work?


Xeno

Recommended Posts

Im making a gate, that will only open for a certain team, the gate opens but it seems to open for all teams, here is the code,

function gateOpen() 
if getTeamFromName("Subway Clan(2)") and getTeamFromName("Beginners(1)") then 
moveObject ( gate, 1000, 808, -1342, 7 ) 
  
setTimer( moveObject,3000,1,gate, 1000,808,-1342,15.-- s8) -->
else 
end 
end 
addEventHandler("onMarkerHit", marker1, gateOpen) 
addEventHandler("onMarkerHit", marker2, gateOpen) 

I would appreciate it if someone help me, thanks.

Link to comment
eh ok you put that he had to be in 2 teams and where ois the markers defined ?

Wich team you want it for ?

I had them already, but didn't put them in the script,

local marker1 = createMarker(810, -1341, 13, 'cylinder', 3.0, 0, 0, 0, 0) 
local marker2 = createMarker(806, -1341, 13, 'cylinder', 3.0, 0, 0, 0, 0) 
  
  

Link to comment

You are just checking if these teams exists, not if the player team is one of these.

function gateOpen(hitElement) 
if (getElementType(hitElement) == "player") then 
    hitPlayer = hitElement 
elseif (getElementType(hitElement) == "vehicle") then 
    hitPlayer = getVehicleController(hitElement) 
end 
local playerTeam = getPlayerTeam(hitPlayer) 
if (not playerTeam) then return end 
local teamName = getTeamName(playerTeam) 
if (teamName == "Subway Clan(2)" or teamName == "Beginners(1)") then 
moveObject ( gate, 1000, 808, -1342, 7 ) 
setTimer( moveObject, 3000, 1, gate, 1000, 808, -1342, 15) 
    end 
end 
addEventHandler("onMarkerHit", marker1, gateOpen) 
addEventHandler("onMarkerHit", marker2, gateOpen) 

Link to comment
You are just checking if these teams exists, not if the player team is one of these.
function gateOpen(hitElement) 
if (getElementType(hitElement) == "player") then 
    hitPlayer = hitElement 
elseif (getElementType(hitElement) == "vehicle") then 
    hitPlayer = getVehicleController(hitElement) 
end 
local playerTeam = getPlayerTeam(hitPlayer) 
if (not playerTeam) then return end 
local teamName = getTeamName(playerTeam) 
if (teamName == "Subway Clan(2)" or teamName == "Beginners(1)") then 
moveObject ( gate, 1000, 808, -1342, 7 ) 
setTimer( moveObject, 3000, 1, gate, 1000, 808, -1342, 15) 
    end 
end 
addEventHandler("onMarkerHit", marker1, gateOpen) 
addEventHandler("onMarkerHit", marker2, gateOpen) 

Thats fantastic and it works great. Would this also work?

function setposOnLogin() 
local teamName = getTeamName(playerTeam) 
if (teamName == "Subway Clan(2)") then 
spawnPlayer(...ect) 
end 
addEventHandler("onPlayerLogin", getRootElement(), setposOnLogin) 
  

Link to comment
function setposOnLogin() 
local playerTeam = getPlayerTeam(source) -- This was missing. 
if (not playerTeam) then return end 
local teamName = getTeamName(playerTeam) 
if (teamName == "Subway Clan(2)") then 
       spawnPlayer(...ect) 
    end -- this was missing. 
end 
addEventHandler("onPlayerLogin", getRootElement(), setposOnLogin) 

Link to comment
function setposOnLogin() 
local playerTeam = getPlayerTeam(source) -- This was missing. 
if (not playerTeam) then return end 
local teamName = getTeamName(playerTeam) 
if (teamName == "Subway Clan(2)") then 
       spawnPlayer(...ect) 
    end -- this was missing. 
end 
addEventHandler("onPlayerLogin", getRootElement(), setposOnLogin) 

Thanks mate. I owe you one.

Link to comment
function gateOpen(hitElement) 
   local hitPlayer = (getElementType(hitElement) == "player" and hitElement ) or (getElementType(hitElement) == "vehicle" and getVehicleController(hitElement)) 
   local playerTeam = getPlayerTeam(hitPlayer) 
   if (not playerTeam) then return end 
   local teamName = getTeamName(playerTeam) 
   if (teamName == "Subway Clan(2)" or teamName == "Beginners(1)") then 
       moveObject ( gate, 1000, 808, -1342, 7 ) 
       setTimer( moveObject, 3000, 1, gate, 1000, 808, -1342, 15) 
   end 
end 
addEventHandler("onMarkerHit", marker1, gateOpen) 
addEventHandler("onMarkerHit", marker2, gateOpen) 

Optimised code, it should work. Not tested.

Edited by Guest
Link to comment
function gateOpen(hitElement) 
   local hitPlayer = (getElementType(hitElement) == "player" and hitElement ) or (getElementType(hitElement) == "vehicle" and getVehicleController(hitElement)) 
   local playerTeam = getPlayerTeam(hitPlayer) 
   if (not playerTeam) then return end 
   local teamName = getTeamName(playerTeam) 
   if (teamName == "Subway Clan(2)" or teamName == "Beginners(1)") then 
       moveObject ( gate, 1000, 808, -1342, 7 ) 
       setTimer( moveObject, 3000, 1, gate, 1000, 808, -1342, 15) 
   end 
end 
addEventHandler("onMarkerHit", marker1, gateOpen) 
addEventHandler("onMarkerHit", marker2, gateOpen) 

Optimised code, it should work. Not tested.

Thanks muchly :D

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...