justn Posted October 23, 2014 Share Posted October 23, 2014 (edited) 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 October 24, 2014 by Guest Link to comment
Moderators IIYAMA Posted October 23, 2014 Moderators Share Posted October 23, 2014 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
justn Posted October 23, 2014 Author Share Posted October 23, 2014 When it was server-side and i used "onMapStarting" it worked.. x: i forgot to replace the table for isInvisible and I also forgot to remove the loop at line 51 v: Link to comment
justn Posted October 24, 2014 Author Share Posted October 24, 2014 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
rtx Posted October 24, 2014 Share Posted October 24, 2014 Typo @ line 51 - bindKey("i","down","visbility") Also remove the 'onClientPlayerJoin' event handler because it's being triggered everytime a player, other than the local player, joins the server. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now