Jump to content

Whats wrong with this code?


megaman54

Recommended Posts

Hello! I made a admin area and script for it. It checks if the player who enter the area is in "Admins" team.

So here is the problem: it kicks the player out of the area even if the player is in the Admins team, it doesnt give any errors or anything relating to errors. Code:

function detectorDetect(thePlayer) 
    if(getPlayerTeam" class="kw2">getPlayerTeam(thePlayer) == "Admins")then 
    outputChatBox("Welcome!", thePlayer, 0, 255, 0) 
    else 
    setElementPosition(thePlayer, 247, 1833, 5) 
    setElementRotation(thePlayer, 269) 
    outputChatBox("You are not allowed to come here!", thePlayer, 255, 0, 0) 
    end 
end 
addEventHandler("onColShapeHit", detector, detectorDetect) 

I hope someone can help me. :?

Link to comment
  • Moderators

Ok so try that and tell me if HIT appear in your chatbox when you enter in the ColShape

  
function detectorDetect(thePlayer) 
    outputChatBox("HIT") 
    if ( getPlayerTeam(thePlayer) == "Admins")then 
        outputChatBox("Welcome!", thePlayer, 0, 255, 0) 
    else 
        setElementPosition(thePlayer, 247, 1833, 5) 
        setElementRotation(thePlayer, 269) 
        outputChatBox("You are not allowed to come here!", thePlayer, 255, 0, 0) 
    end 
end 
addEventHandler("onColShapeHit", detector, detectorDetect) 
  
  

EDIT: I paste the code again

EDIT2: IDK why but the code in lua was bugged so I put it in text format -_-

Link to comment
  • Moderators

Yeah I think it's better

put this a the top of your lua file:

  
teamAdmin = createTeam( "Admin" ) 
  
function enterInTeam( thePlayer, commandName ) 
    if teamAdmin then 
        setPlayerTeam ( thePlayer, teamAdmin ) 
    end 
end 
addComandHandler("enterteam", enterInTeam, false, false ) 
  
  

Then restart your server and tape /enterteam then try to enter in your colshape

Link to comment

It does work, you are doing it wrong, if i'm right getPlayerTeam returns an element and to get the team name you must use getTeamName, so would be.

function detectorDetect(thePlayer) 
    outputChatBox("HIT") 
    if ( getTeamName(getPlayerTeam(thePlayer)) == "Admins")then 
        outputChatBox("Welcome!", thePlayer, 0, 255, 0) 
    else 
        setElementPosition(thePlayer, 247, 1833, 5) 
        setElementRotation(thePlayer, 269) 
        outputChatBox("You are not allowed to come here!", thePlayer, 255, 0, 0) 
    end 
end 
addEventHandler("onColShapeHit", detector, detectorDetect) 

Link to comment
  • Moderators
It does work, you are doing it wrong, if i'm right getPlayerTeam returns an element and to get the team name you must use getTeamName, so would be.

function detectorDetect(thePlayer) 
    outputChatBox("HIT") 
    if ( getTeamName(getPlayerTeam(thePlayer)) == "Admins")then 
        outputChatBox("Welcome!", thePlayer, 0, 255, 0) 
    else 
        setElementPosition(thePlayer, 247, 1833, 5) 
        setElementRotation(thePlayer, 269) 
        outputChatBox("You are not allowed to come here!", thePlayer, 255, 0, 0) 
    end 
end 
addEventHandler("onColShapeHit", detector, detectorDetect) 

you right and I miss a little s at Admin so replace that line:

  
teamAdmin = createTeam( "Admins" ) 
  

And now it will work perfectly

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...