Jump to content

Help me in syntax


Recommended Posts

function allowORnot (player, key) 
    if isObjectInACLGroup("user."..getAccountName( getPlayerAccount( player ) ), aclGetGroup( "Pirate" ) ) then 
        if (key = nil) then 
        key = 0 
        removeEventHandler("onVehicleStartEnter", getRootElement(), pirateBoat) 
        end 
        elseif (key = 0) then 
        addEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat) 
        key = nil 
    end 
end 
addCommandHandler ("cannon", allowORnot) 

I don't see what I'm doing wrong, is it my syntax?

Error: Loading script failed restriction.lua:3: ')' expected near '=' 

Link to comment
    function allowORnot (player, key) 
        if isObjectInACLGroup("user."..getAccountName( getPlayerAccount( player ) ), aclGetGroup( "Pirate" ) ) then 
            if (key == nil) then 
            key = 0 
            removeEventHandler("onVehicleStartEnter", getRootElement(), pirateBoat) 
            end 
            elseif (key == 0) then 
            addEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat) 
            key = nil 
        end 
    end 
    addCommandHandler ("cannon", allowORnot) 

Link to comment

i want it with a command to remove and add events

removeEventHandler("onVehicleStartEnter", getRootElement(), pirateBoat) 
addEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat) 

like a toggable command not cannonopen, cannonclose

Link to comment
    function allowORnot (player, key) 
outputChatBox("check") 
        if isObjectInACLGroup("user."..getAccountName( getPlayerAccount( player ) ), aclGetGroup( "Pirate" ) ) then 
            if (key == nil) then 
            key = 0 
outputChatBox("go") 
            removeEventHandler("onVehicleStartEnter", getRootElement(), pirateBoat) 
            end 
            elseif (key == 0) then 
            addEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat) 
            key = nil 
outputChatBox("stop") 
        end 
    end 
    addCommandHandler ("cannon", allowORnot) 

csiguusz's code isn't fine , tried with checks, it "check" then "go" but doesnt go to "stop" and after that it just "check"

Link to comment

You can use a table.

local state = { } 
  
function allowORnot ( player ) 
    outputChatBox ( "check" ) 
    if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup( "Pirate" ) ) then 
        if ( state [ player ] ) then 
            state [ player ] = nil 
            outputChatBox ( "go" ) 
            removeEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat ) 
        else 
            state [ player ] = true 
            addEventHandler ( "onVehicleStartEnter", getRootElement(), pirateBoat ) 
            outputChatBox ( "stop" ) 
        end 
    end 
end 
addCommandHandler ( "cannon", allowORnot ) 

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