Jump to content

Help me in syntax


Recommended Posts

Posted
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 '=' 

Posted
    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) 

Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003

Posted

thanks(no errors now) but the command seems to not respond, added outputChatBox after key = 0 and key = nil and nothing :S

im trying to figure out my mistake but i dont even imagine what the error could be

Posted

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

Posted

key is like cur, if you know what i mean. I wont post full code coz it wont rly fix. All im trying to do is a toggable command to add and remove the handler

Posted

csiguusz's code is fine .

Show us the 'pirateBoat' function .

" Keep Thinking Different . " - Steve Jops

--------------------

Don't send me PMs asking for help, I Won't reply !

Posted
    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"

Posted

The second argument of addCommandHandler is the command name, not "nil" nor a number.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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