Jump to content

How to work with else if?


Deadmau5

Recommended Posts

I have a big problem... my script always returns error if i use this

  
function putplayerteamneu( ) 
    local serial = getPlayerSerial (source ) 
    if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Member" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Members" ) ) 
        setElementData( source, "pptts.acl", "Members") 
    else if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Moderator" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Moderators" ) ) 
        setElementData( source, "pptts.acl", "Moderator") 
    else if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Owner" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Server Owners" ) ) 
        setElementData( source, "pptts.acl", "Owner") 
        setElementData( source, "pptts.canusemakeadmin", true) 
    else if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Admin" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Admins" ) ) 
        setElementData( source, "pptts.acl", "Admin") 
    else if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "VIP" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "VIP" ) ) 
        setElementData( source, "pptts.acl", "VIP") 
    else 
        setPlayerTeam ( source, getTeamFromName( "Players" ) ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), putplayerteamneu ) 
  

Because don't i close it with the else if?

Pls help with this =(

Link to comment

http://www.lua.org/manual/5.1/

  
function putplayerteamneu( ) 
    local serial = getPlayerSerial (source ) 
    if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Member" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Members" ) ) 
        setElementData( source, "pptts.acl", "Members") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Moderator" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Moderators" ) ) 
        setElementData( source, "pptts.acl", "Moderator") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Owner" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Server Owners" ) ) 
        setElementData( source, "pptts.acl", "Owner") 
        setElementData( source, "pptts.canusemakeadmin", true) 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Admin" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Admins" ) ) 
        setElementData( source, "pptts.acl", "Admin") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "VIP" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "VIP" ) ) 
        setElementData( source, "pptts.acl", "VIP") 
    else 
        setPlayerTeam ( source, getTeamFromName( "Players" ) ) 
    end 
end 
addEventHandler ( "onPlayerJoin", root, putplayerteamneu ) 
  

Edited by Guest
Link to comment
function putplayerteamneu( ) 
    local serial = getPlayerSerial (source ) 
    if isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Member" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Members" ) ) 
        setElementData( source, "pptts.acl", "Members") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Moderator" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Moderators" ) ) 
        setElementData( source, "pptts.acl", "Moderator") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Owner" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Server Owners" ) ) 
        setElementData( source, "pptts.acl", "Owner") 
        setElementData( source, "pptts.canusemakeadmin", true) 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "Admin" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "Admins" ) ) 
        setElementData( source, "pptts.acl", "Admin") 
    elseif isObjectInACLGroup ( "serial." .. serial, aclGetGroup ( "VIP" ) ) then 
        setPlayerTeam ( source, getTeamFromName( "VIP" ) ) 
        setElementData( source, "pptts.acl", "VIP") 
    else 
        setPlayerTeam ( source, getTeamFromName( "Players" ) ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), putplayerteamneu ) 

Link to comment

Muchas gracias :D

//EDIT: Now i need a makeadmin command...

But why this dont work?

function adminCMD(player, otherplayer, level) 
    if getElementData(player, "pptts.canusemakeadmin") then -- the shared logic 
        if otherplayer then 
            local serial = getPlayerSerial(otherplayer) 
            local thegroup = aclGetGroup(getElementData(otherplayer, "pptts.acl")) 
            local otherplayername = getPlayerName( otherplayer ) 
            local playername = getPlayerName(player) 
            if level == "Nichts" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                outputChatBox(playername.. "hat dir deine Rechte entzogen!", otherplayer) 
                outputChatBox("Du hast" ..otherplayername "die Rechte entzogen!",player) 
            elseif level == "Member" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData(otherplayer, "pptts.acl", "Member") 
                aclGroupAddObject( aclGetGroup("Member"), "serial."..otherplayername) 
                outputChatBox(playername.. "hat dich zum Member gemacht!", otherplayer) 
                outputChatBox("Du hast" ..otherplayername "zum Member gemacht!",player) 
            elseif level == "Moderator" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData(otherplayer, "pptts.acl", "Moderator") 
                aclGroupAddObject( aclGetGroup("Moderator"), "serial."..otherplayername) 
                outputChatBox(playername.. "hat dich zum Moderator gemacht!", otherplayer) 
                outputChatBox("Du hast" ..otherplayername "zum Moderator gemacht!",player) 
            elseif level == "Admin" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData(otherplayer, "pptts.acl", "Admin") 
                aclGroupAddObject( aclGetGroup("Admin"), "serial."..otherplayername) 
                outputChatBox(playername.. "hat dich zum Admin gemacht!", otherplayer) 
                outputChatBox("Du hast" ..otherplayername "zum Admin gemacht!",player) 
            elseif level == "VIP" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData(otherplayer, "pptts.acl", "VIP") 
                aclGroupAddObject( aclGetGroup("VIP"), "serial."..otherplayername) 
                outputChatBox(playername.. "hat dich zum VIP gemacht!", otherplayer) 
                outputChatBox("Du hast" ..otherplayername "zum VIP gemacht!",player) 
            else 
                outputChatBox("NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player) 
            end 
        else 
            outputChatBox("NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player) 
        end 
    end 
end 
addCommandHandler("makeadmin", adminCMD) 

Edited by Guest
Link to comment

Try

function findPlayer( name ) 
    if type( name ) == 'string' then 
        local matches = { } 
        for _, v in pairs( getElementsByType( "player" ) ) do 
            if getPlayerName( v ) == name then 
                return v 
            end 
            local playerName = getPlayerName( v ):gsub( "#%x%x%x%x%x%x", "" ) 
            playerName = playerName:lower( ) 
            if playerName:find( name:lower( ), 0 ) then 
                table.insert( matches, v ) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        end 
        return false 
    end  
end 
  
function adminCMD( player, _,otherplayer, level ) 
    if getElementData( player, "pptts.canusemakeadmin" ) then -- the shared logic 
        local otherplayer = findPlayer( otherplayer ) 
        if isElement( otherplayer ) then 
            local serial = getPlayerSerial( otherplayer ) 
            local thegroup = aclGetGroup( getElementData( otherplayer, "pptts.acl" ) ) 
            local otherplayername = getPlayerName( otherplayer ) 
            local playername = getPlayerName( player ) 
            if level == "Nichts" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                outputChatBox( playername.. "hat dir deine Rechte entzogen!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "die Rechte entzogen!",player ) 
            elseif level == "Member" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData( otherplayer, "pptts.acl", "Member") 
                aclGroupAddObject( aclGetGroup("Member"), "serial."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Member gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Member gemacht!",player ) 
            elseif level == "Moderator" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData( otherplayer, "pptts.acl", "Moderator") 
                aclGroupAddObject( aclGetGroup("Moderator"), "serial."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Moderator gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Moderator gemacht!",player ) 
            elseif level == "Admin" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData(otherplayer, "pptts.acl", "Admin") 
                aclGroupAddObject( aclGetGroup("Admin"), "serial."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Admin gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Admin gemacht!",player ) 
            elseif level == "VIP" then 
                aclGroupRemoveObject ( thegroup, "serial." ..serial ) 
                setElementData( otherplayer, "pptts.acl", "VIP" ) 
                aclGroupAddObject( aclGetGroup("VIP"), "serial."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum VIP gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum VIP gemacht!",player ) 
            else 
                outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
            end 
        else 
            outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
        end 
    end 
end 
addCommandHandler( "makeadmin", adminCMD ) 

And lock in /debugscript 3.

Try again i update.

Link to comment

You mean

resource.SERIAL?

or user.SERIAL?

//EDIT: So i need to make an extra mysql table for example where the serials are saved?

//EDIT2: Why the f*ck i don't use user.SERIAL xD?

Thnx at all :)

//EDIT3: Any way to script-connect an user to his account?

Like

LoginPlayer(player thePlayer, account theAccount)?

//EDIT4: Sry for the much edits, but now i have a big problem... It shows me anytime the USAGE text :S

function adminCMD( player, otherplayer, level ) 
    if getElementData( player, "pptts.canusemakeadmin" ) then -- the shared logic 
        local otherplayer = findPlayer( otherplayer ) 
        if otherplayer then 
            local serial = getPlayerSerial( otherplayer ) 
            local thegroup = aclGetGroup( getElementData( otherplayer, "pptts.acl" ) ) 
            --local otherplayername = getPlayerName( otherplayer ) 
            local playername = getPlayerName( player ) 
            if level == "Nichts" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                outputChatBox( playername.. "hat dir deine Rechte entzogen!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "die Rechte entzogen!",player ) 
            elseif level == "Member" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "Member") 
                aclGroupAddObject( aclGetGroup("Member"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Member gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Member gemacht!",player ) 
            elseif level == "Moderator" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "Moderator") 
                aclGroupAddObject( aclGetGroup("Moderator"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Moderator gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Moderator gemacht!",player ) 
            elseif level == "Admin" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData(otherplayer, "pptts.acl", "Admin") 
                aclGroupAddObject( aclGetGroup("Admin"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Admin gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Admin gemacht!",player ) 
            elseif level == "VIP" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "VIP" ) 
                aclGroupAddObject( aclGetGroup("VIP"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum VIP gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum VIP gemacht!",player ) 
            else 
                outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
            end 
        else 
            outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
        end 
    end 
end 
addCommandHandler( "makeadmin", adminCMD ) 

Link to comment

The second argument of addCommandHandler server-side it's the commandName.

function adminCMD( player, commandName, otherplayer, level ) 
    if getElementData( player, "pptts.canusemakeadmin" ) then -- the shared logic 
        local otherplayer = findPlayer( otherplayer ) 
        if otherplayer then 
            local serial = getPlayerSerial( otherplayer ) 
            local thegroup = aclGetGroup( getElementData( otherplayer, "pptts.acl" ) ) 
            --local otherplayername = getPlayerName( otherplayer ) 
            local playername = getPlayerName( player ) 
            if level == "Nichts" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                outputChatBox( playername.. "hat dir deine Rechte entzogen!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "die Rechte entzogen!",player ) 
            elseif level == "Member" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "Member") 
                aclGroupAddObject( aclGetGroup("Member"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Member gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Member gemacht!",player ) 
            elseif level == "Moderator" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "Moderator") 
                aclGroupAddObject( aclGetGroup("Moderator"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Moderator gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Moderator gemacht!",player ) 
            elseif level == "Admin" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData(otherplayer, "pptts.acl", "Admin") 
                aclGroupAddObject( aclGetGroup("Admin"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum Admin gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum Admin gemacht!",player ) 
            elseif level == "VIP" then 
                aclGroupRemoveObject ( thegroup, "user." ..serial ) 
                removeAccount( serial ) 
                addAccount( serial, "l0l7h15p455w0rd15uncr4ck4bl3" ) 
                setElementData( otherplayer, "pptts.acl", "VIP" ) 
                aclGroupAddObject( aclGetGroup("VIP"), "user."..otherplayername ) 
                outputChatBox( playername.. "hat dich zum VIP gemacht!", otherplayer ) 
                outputChatBox( "Du hast" ..otherplayername "zum VIP gemacht!",player ) 
            else 
                outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
            end 
        else 
            outputChatBox( "NUTZUNG: /makeadmin [spieler] [Nichts/Member/Moderator/Admin/VIP]", player ) 
        end 
    end 
end 
addCommandHandler( "makeadmin", adminCMD ) 

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