Jump to content

Help with a script


Benevolence

Recommended Posts

Posted

So this gravity gun script has a toggle script. I want to add the check if player is admin in the script itself and not permissions in acl, just to make it easier and shiz.

function toggleGGun(player) 
if (exports.global:isPlayerAdmin(sourcePlayer) then 
if not (sourcePlayer) then 
outputChatBox("You don't have permission to use this command.", thePlayer, 255, 194, 14) 
else 
    local on = not exports.gravity_gun:isGravityGunEnabled(player) 
    exports.gravity_gun:togglePlayerGravityGun(player,on) 
    outputChatBox("gravity gun "..(on and "on" or "off"),player) 
    addCommandHandler("ggun",toggleGGun) 
    else 
addCommandHandler("ggun",toggleGGun) 
end 

I've failed. Gives an error like expected to close 'if' near 'else'

Can other people connect to your server? Use this tool to check:

http://nightly.mtasa.com/ports/

1484762903.png

Formerly known as Tank07.

Posted (edited)
function toggleGGun(player) 
if exports.global:isPlayerAdmin(player) then 
    local on = not exports.gravity_gun:isGravityGunEnabled(player) 
    exports.gravity_gun:togglePlayerGravityGun(player,on) 
    outputChatBox("gravity gun "..(on and "on" or "off"),player) 
else 
outputChatBox("You don't have permission to use this command.", player, 255, 194, 14) 
     end 
end 
addCommandHandler("ggun",toggleGGun) 

Try with that.

Edited by Guest

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

This is retarded, it was working fine then randomly after I edited the text on chat like ggun is on, etc, it stopped working. I un-did it, etc and shiz now its giving me same thing. On line 2 'then' expected near ')' But I already added )?

function toggleGGun(player) 
if exports.global:isPlayerAdmin(player)) then 
    local on = not exports.gravitygun:isGravityGunEnabled(player) 
    exports.gravitygun:togglePlayerGravityGun(player,on) 
    outputChatBox("Gravity gun has been "..(on and "enabled." or "disabled."),player) 
else 
outputChatBox("You don't have permission to use this command.", player, 255, 194, 14) 
     end 
end 
addCommandHandler("ggun",toggleGGun) 

Can other people connect to your server? Use this tool to check:

http://nightly.mtasa.com/ports/

1484762903.png

Formerly known as Tank07.

Posted

You have an extra ")" in line 2, remove it.

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

Who's asking for help? you or me? if you remove it, it won't make any error.

P.S: I'm sure you added the ")" because Cadu12 said so, right?

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
    function toggleGGun(player) 
    if exports.global:isPlayerAdmin(player) then 
        local on = not exports.gravitygun:isGravityGunEnabled(player) 
        exports.gravitygun:togglePlayerGravityGun(player,on) 
        if on then 
                     outputChatBox("Gravity gun has been enabled",player) 
        else 
                     outputChatBox("Gravity gun has been disabled",player) 
       end  
    else 
    outputChatBox("You don't have permission to use this command.", player, 255, 194, 14) 
         end 
    end 
    addCommandHandler("ggun",toggleGGun) 

try this

btw wtf was that outputChatBox in line 8..

or is it some 1337 scripting technique?

Posted
function toggleGGun(player) 
if (exports.global:isPlayerAdmin(sourcePlayer) then 
if not (sourcePlayer) then 
outputChatBox("You don't have permission to use this command.", thePlayer, 255, 194, 14) 
else 
    local on = not exports.gravity_gun:isGravityGunEnabled(player) 
    exports.gravity_gun:togglePlayerGravityGun(player,on) 
    outputChatBox("gravity gun "..(on and "on" or "off"),player) 
    addCommandHandler("ggun",toggleGGun) 
    else 
addCommandHandler("ggun",toggleGGun) 
end 

I didnt said that, only i said you missed ")". Look at line 2. Quote is from 1 st

Ingame nick: Cadu12

Posted

Yes, but after you said that, I fixed the error, then he got confused I guess.

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
    function toggleGGun(player) 
    if exports.global:isPlayerAdmin(player) then 
        local on = not exports.gravitygun:isGravityGunEnabled(player) 
        exports.gravitygun:togglePlayerGravityGun(player,on) 
        if on then 
                     outputChatBox("Gravity gun has been enabled",player) 
        else 
                     outputChatBox("Gravity gun has been disabled",player) 
       end  
    else 
    outputChatBox("You don't have permission to use this command.", player, 255, 194, 14) 
         end 
    end 
    addCommandHandler("ggun",toggleGGun) 

try this

btw wtf was that outputChatBox in line 8..

or is it some 1337 scripting technique?

It works, thank you.

Can other people connect to your server? Use this tool to check:

http://nightly.mtasa.com/ports/

1484762903.png

Formerly known as Tank07.

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