Jump to content

In need of help #1 [Solved]


Shux

Recommended Posts

Hi,

So I was working on a little script, and the problem is, it doesn't work. I don't get any errors or anything, so yeah..

Code:

function onMapStarting(mapInfo) 
    if ( isInvisible[localPlayer] == false ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( getObjectScale( v ) == 0 ) then 
                setObjectScale(v, 1) 
                objects[v] = true 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188invisible",255,255,255,true) 
            end 
        end 
    elseif ( isInvisible[localPlayer] == true ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( objects[v] == true ) then 
                objects[v] = nil 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188visible",255,255,255,true) 
            end 
        end 
    end 
end 
addEventHandler("onClientMapStarting", root, onMapStarting) 

//UPDATE:

Here's the full code

Code:

local isInvisible = {} 
local objects = {} 
  
  
function toggleStatus() 
    if ( isInvisible[localPlayer] == true ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( getObjectScale(v) == 0 ) then 
                setObjectScale(v, 1) 
                objects[v] = true 
            end 
        end 
        outputChatBox("#406188[Visibility]: #FFFFFFAll invisible parts are now #00ff00visible",255,255,255,true) 
        isInvisible[localPlayer] = false 
    else 
        for i,v in ipairs(getElementsByType("object")) do 
            if  getObjectScale(v) == 1 and objects[v] then 
                setObjectScale(v, 0) 
                objects[v] = nil 
            end 
        end 
        outputChatBox("#406188[Visibility]: #FFFFFFAll visible parts are now #ff0000invisible",255,255,255,true) 
        isInvisible[localPlayer] = true 
    end 
end 
addCommandHandler("visibility", toggleStatus) 
  
  
function onMapStarting(mapInfo) 
    if ( isInvisible[localPlayer] == false ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( getObjectScale( v ) == 0 ) then 
                setObjectScale(v, 1) 
                objects[v] = true 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188invisible",255,255,255,true) 
            end 
        end 
    elseif ( isInvisible[localPlayer] == true ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( objects[v] == true ) then 
                objects[v] = nil 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188visible",255,255,255,true) 
            end 
        end 
    end 
end 
addEventHandler("onClientMapStarting", root, onMapStarting) 
  
addEventHandler("onClientResourceStart", root, 
    function() 
        for i,v in ipairs(getElementsByType("player")) do 
            bindKey("i","down","visibility") 
            isInvisible[v] = true 
        end 
    end 
) 
  
addEventHandler("onClientPlayerJoin",root, 
    function() 
        isInvisible[localPlayer] = true 
    end 
) 

Edited by Guest
Link to comment
  • Moderators

1: Use setElementAlpha instead of setObjectScale.

2: isInvisible table makes no sense, just use a boolean.

local isInvisible = true 
local isInvisible = false 

3: "onClientPlayerJoin" makes no sense, this is only for other players to join. Not for the localPlayer.

4: loop through the players at line 51, doesn't make sense.

6: "onClientMapStarting" is a custom race event, don't you need to enable it?

addEvent("onClientMapStarting",true) 

Link to comment

I tried this but it didn't work ( the bindKey part )

local isInvisible = true 
local objects = {} 
  
  
function toggleStatus() 
    if ( isInvisible == true ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( getObjectScale(v) == 0 ) then 
                setObjectScale(v, 1) 
                objects[v] = true 
            end 
        end 
        outputChatBox("#406188[Visibility]: #FFFFFFAll invisible parts are now #00ff00visible",255,255,255,true) 
        isInvisible = false 
    else 
        for i,v in ipairs(getElementsByType("object")) do 
            if  getObjectScale(v) == 1 and objects[v] then 
                setObjectScale(v, 0) 
                objects[v] = nil 
            end 
        end 
        outputChatBox("#406188[Visibility]: #FFFFFFAll visible parts are now #ff0000invisible",255,255,255,true) 
        isInvisible = true 
    end 
end 
addCommandHandler("visibility", toggleStatus) 
  
addEvent("onClientMapStarting",true) 
function onMapStarting(mapInfo) 
    if ( isInvisible == false ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( getObjectScale( v ) == 0 ) then 
                setObjectScale(v, 1) 
                objects[v] = true 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188invisible",255,255,255,true) 
            end 
        end 
    elseif ( isInvisible == true ) then 
        for i,v in ipairs(getElementsByType("object")) do 
            if ( objects[v] == true ) then 
                objects[v] = nil 
                outputChatBox("#406188[Visibility]: #FFFFFFPress #406188'i' #FFFFFFto make your objects #406188visible",255,255,255,true) 
            end 
        end 
    end 
end 
addEventHandler("onClientMapStarting", root, onMapStarting) 
  
addEventHandler("onClientResourceStart",root, 
    function () 
        bindKey("i","down","visbility") 
        isInvisible = true 
    end 
) 
  
addEventHandler("onClientPlayerJoin",root, 
    function() 
        bindKey("i","down","visibility") 
        isInvisible = true 
    end 
) 

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