How would I make it so that players are only half invisible to a players in a certain team/in a certain group? - scripting

I was following the example in this question How would I make a player invisible only to certain players?, but I can't adapt it to my needs.
How would I make it so that players are only half invisible to a players in a certain team/in a certain group? And how do I make it so that fellow invisible players see invisible players?

Building on the code from the previous code sample, to make this work you only have to modify the last step where the server tells all of the clients to show or hide the players.
Since you are trying to satisfy two conditions :
Teammates can be seen, even when invisible, and
Invisible players can be seen when the you are also invisible
You need to add some conditions to keep track of what team people are on and who is actively invisible. When one of your teammates turns invisible, we only partially hide them. And when we, the local player, turn invisible we need to iterate over all of the hidden players and reveal them.
That code might look like this :
-- make a helper function to reveal / hide a player
local function setVisiblity(player, isHidden, showPartial)
local invisible = 1.0
local visible = 0.0
-- if showing partially, make invisibility slightly more visible
if (showPartial == true) then
invisible = 0.7
end
-- loop over all of the parts in a player's Character Model and hide them
for _, part in ipairs(player.Character:GetDescendants()) do
local shouldTogglePart = true
-- handle exceptions
if not (part:IsA("BasePart") or part:IsA("Decal")) then
shouldTogglePart = false
elseif part.Name == "HumanoidRootPart" then
shouldTogglePart = false
end
-- hide or show all the parts and decals
if shouldTogglePart then
part.Transparency = isHidden and invisible or visible
end
end
end
-- make a table to hold onto the hidden players
local invisiblePlayers = {} -- <playerName, playerObject>
TogglePlayerVisible.OnClientEvent:Connect(function(player, isHidden)
-- flip the visibility of the player that requested the change
local showPartial = false
-- keep track of who is visible / invisible
if (isHidden) then
invisiblePlayers[player.Name] = player
else
invisiblePlayers[player.Name] = nil
end
-- reveal the invisible players if it is you
if (player.Name == localPlayer.Name)
showPartial = true
-- if we are now invisible, reveal all the other invisible players, otherwise hide them
local canSeeOtherInvisibleUnits = false
if (isHidden) then
canSeeOtherInvisibleUnits = true
end
-- loop over the invisible players and reveal or hide them
for name, invisPlayer in pairs(invisiblePlayers) do
setVisible(player, canSeeOtherInvisibleUnits, true)
end
-- reveal the other player if we're on the same team
elseif (player.TeamColor == localPlayer.TeamColor)
showPartial = true
-- reveal the other player if we are currently invisible
elseif (invisiblePlayers[localPlayer.Name] ~= nil)
showPartial = true
end
-- toggle that player's invisibility
setVisiblity(player, isHidden, showPartial)
end)

Related

Getting MS-Access form to save invisible combo boxes as a null or 0 value in query and table

I don't know that how I have built my form is necessarily the best way that I can do it, but it was the way that I could get it to work, at least partially. I have built a form in ms-access 2007 that uses vba to either hide or make available certain combo boxes. The first choice and the one on which the rest of the form is based is a yes/no option, being that either the customer requires outside services for their job or not. Once that is selected the user can then choose from the outside service options(Which are the combo boxes, either visible or no based on the first choice). So this is where the problem comes in, I have code written so that if the user chooses no in the very first box the rest of the boxes are made invisible. However if the user chooses yes they must then choose values, again yes or no to either retain or remove other options for the remainder of the form.
What I am looking to do is to make it so that when the user returns to the form what choices they made are still there. So if they chose no then the form would basically be blank and if they had said yes initially than that answer along with only the other choices they made would be available.
What I am currently using is a simple if-then statement to make the boxes either visible or not.
Private Sub Combo36_AfterUpdate()
If Combo36.Value = "No" Then Me.Combo18.Visible = False
If Combo36.Value = "Yes" Then Me.Combo18.Visible = True
If Combo36.Value = "No" Then Me.Combo20.Visible = False
If Combo36.Value = "Yes" Then Me.Combo20.Visible = True
End Sub
Obviously I am not experienced with access and have stumbling my way through it. I am sorry if any of what I have said above is confusing. If clarity is needed please let me know.
Well for a start, "Flase" should be updated to "False".
Instead of storing and then repopulating the selected values it might be easier to turn the visibility of the whole form true/false based on selection which would keep the last values the user selected.
For showing visibility of the controls try:
Private Sub Combo36_Change()
If Me.Combo36.Value = "No" Then
Me.Combo18.Visible = False
Me.Combo20.Visible = False
ElseIf Me.Combo36.Value = "Yes" Then
Me.Combo18.Visible = True
Me.Combo20.Visible = True
End If
End Sub
Your initial code is okay, to be able to have the form retain the choices then copy the code you have under the Combo36_AfterUpdate() event into the Private Sub Form_Current() event. This will do it.

How to use VBA to show / hide multiple combinations of tables in MS Word? - explained further within

I have a word 2010 document with some basic VBA code attached to a number checkboxs that show / hide a sections throughout the document.
There are a number of these throughout the document however they all share the same basic code which appears to be working well enough (example below)
Private Sub PlanningBox_Click()
If PlanningBox.Value = False Then
ActiveDocument.Bookmarks("Planning").Range.Font.Hidden = True
Else
ActiveDocument.Bookmarks("Planning").Range.Font.Hidden = False
End If
End Sub
The issue i am having is that some of these sections then have checkboxes within them that show / hide further section which is fine, however if the user unchecks the first initial checkbox (hiding all sections) then re-checks it, it will open up the initial section again but not the ticked subsections - in order to do this they have to uncheck/check the subsection again. I know this seems minor but i need to ensure the form is as fluid and user acessible as possible..
For example let's say there is a single row table with the text 'Have you spoken to anyone for feedback?' (checkbox1) - the user will tick the check box which will unhide a section of text below giving directions, asking some questions, general blurb etc. At the bottom of this is another question 'Who did you speak to?" - and then multiple checkboxes 'mother','father', 'Child' (checkbox A,B,C,etc). Checking any of these boxes opens up a table with additional questions for each one selected, the user can check any number / combination of the checkboxes.
Now if the user unchecks the initial checkbox 1. all sections will be hidden no problem, but then if they then check it to reveal the section again the mother, father etc boxes remain ticked but will not reveal the sections without needing to be unticked/ticked again. Is there a way so that ticking the intial box will also reveal any previously unhidden sections again?
My knowledge of VBA is very limited, i have considered using If + ElseIF statements but my understanding is that i would need an ElseIf for every potential combination. Is there a more sophisticated way around this at all?
Hopefully i have articulated this well enough but happy to provide further information. Thank you for any assistance given
You could create a common routine that evaluates every checkbox and sets the corresponding section accordingly. Call that one routine whenever a checkbox is clicked.
Private Sub PlanningBox_Click()
SetRangeVisibility
End Sub
Private Sub SomeOtherBox_Click()
SetRangeVisibility
End Sub
Public Sub SetRangeVisibility()
If PlanningBox.Value = False Then
ActiveDocument.Bookmarks("Planning").Range.Font.Hidden = True
Else
ActiveDocument.Bookmarks("Planning").Range.Font.Hidden = False
End If
If SomeOtherBox.Value = False Then
ActiveDocument.Bookmarks("SomeOtherRange").Range.Font.Hidden = True
Else
ActiveDocument.Bookmarks("SomeOtherRange").Range.Font.Hidden = False
End If
' Etc...
End Sub
Further, if you use an array of check boxes you'd only need to write a single SomeBox_Click event procedure. Here is some information on Control Arrays in VBA.

Is there a way to set the order of images appear on a form?

I am working on a personal home inventory database. On one of the forms called Update Location, there is an image of the floor plan of the condo and then on top an image of location flag (pin icon) indicating where the location is in the condo.
For example:
Room: Den
Location: Top of desk
Flag is at point
LeftCoordinate.Value (X) and
TopCoordinate.Value (Y).
I have a toggle button then allows me to click on the map and sets a new X and Y position for the flag based on where I click on the map.
However, when I do this the flag image disappears behind the floor plan image until I click on another part of the form and then it is in the right spot. I am fairly new to VBA (especially in Access). Is there a way I can get the flag image on top?
I have tried searching Google but all the examples tend to be for one image and never an image over another image.
Private Sub Draw_Location_Icon()
Me.Painting = False
LeftStartPoint = 5292 ' 3.675" Left corner of floor plan attachment
TopStartPoint = 837 ' 0.5826" Top corner of floor plan attachment
IconHalfWidth = 180 ' 0.125" Half the icon width
IconFullHeight = 360 ' 0.250" Full height of icon
Me.Location_Icon.Visible = False
If Me.LeftCoordinate.Value > 0 Or Me.TopCoordinate.Value > 0 Then
Location_Icon.Left = LeftStartPoint - IconHalfWidth + Me.LeftCoordinate.Value
Location_Icon.Top = TopStartPoint - IconFullHeight + Me.TopCoordinate.Value
Me.Location_Icon.Visible = True
End If
Me.Painting = True
End Sub
As I stated currently the floor plan image is on top of the flag when I move the location flag but it is fine once I click on another part of the form. I would like the form to refresh with the floor plan on bottom and flag on top.
I am sure I am missing a small item to either set the orders of the image or perhaps I can get the VBA code to "click" somewhere else on the form and make the flag appear on top?
Any help is greatly appreciated.

Using varying labels in Userform code

I have a simulator with two userforms that transfer information back and forth between each other (one is MainForm, and the other is CreatureFinder).
When one of the deck slot buttons on MainForm is pushed (all 20 of which correspond to a creature in either your or the enemy's deck), it opens CreatureFinder so that you can choose which creature goes in the slot (and it also lets you edit certain parameters, like the creature's level).
The code shortened for simplicity:
If CreatureNumberLabel.Text = "1" Then
MainForm.YourCreature1Skill1Label.Text = Skill1Label.Text
MainForm.YourCreature1Skill2Label.Text = Skill2Label.Text
MainForm.YourCreature1Skill3Label.Text = Skill3Label.Text
End If
I want to remove the If Then statement, and to change "YourCreature1" to "YourCreature" & whatever value CreatureNumberLabel.Text is set to.
Should it be VBA, you can skip the
If CreatureNumberLabel.Text = "1" Then
And just type:
MainForm.Controls("YourCreature" & CreatureNumberLabel.Text & "Skill1Label").Text = Skill1Label.Text
And so on with Skill2Label.Text, Skill3Label.Text, etc...
You can use some kind of control arrays. On form load, create array(s) for controls and assign its elements (this is 20 lines of code per array), afterwards you can use them like next:
Dim CreatureNum As Integer = CInt(CreatureNumberLabel.Text) 'don't forget validation
MainFormYourCreatureSkillLabelArray(CreatureNum).Text = SkillLabel(CreatureNum).Text

hiding / showing sections for forms depending on date

just a query more than anything. Not sure if im allowed to just ask a question on here without submitting code? but anyway here goes.
Wondering whether it is possible in Excel using vba to show/hide sections of a form depending on what date it is. The form i'm creating will be used for audits and each month a different audit is completed. The form will be used as described below.
Workbook opens ---- user enters a patient id number (lookup function used to retrieve data from database(I DON'T NEED HELP WITH THIS BIT) ----- user chooses yes / no from dropdown
yes - shows relevant form depending on date
no - leaves form as is.
Can't think of a suitable way to tackle set the form up and dont know how to show/hide sections so any suggestions would be grateful.
Your question is a little open-ended and clearly there isn't a definitive answer. Here are some of my intial thoughts:
If your forms only vary slightly (i.e. 90% the same and only 10% is variable) and it is only a certain section(s) of the form that varies, then maybe create each section and then selectively hide.
For example, suppose I have a section that is different depending upon whether the user is male of female. I could build both sections and then show / hide as follows:
If gender = "Male" Then
Rows("10:20").EntireRow.Hidden = True //Assume you built male section in rows 10 to 20
Range("20:30").EntireRow.Hidden = false //Assume you built female section in 20 to 30
Else // replicate code for female scenario
Rows("10:20").EntireRow.Hidden = False
Rows("20:30").EntireRow.Hidden = True
End if
If your forms vary a lot (i.e. only 10% static and 90% variable) my experience is that you are better off building each form separately in a different worksheet and then displaying accordingly:
If gender = "Male" Then
Worksheets("maleForm").Visible = True
Else
Worksheets("femaleForm").Visible = True
End if
If your input fields differ then you can consider disabling certain fields selectively:
If gender = "Male" Then
Worksheets("myForm").OLEObjects("lipstickDropDown").Enabled = False //Using Control Toolbox items e.g. textbox, combobox etc...
Worksheets("myForm").OLEObjects("beerDropDown").Enabled = True
Else
Worksheets("myForm").OLEObjects("lipstickDropDown").Enabled = True
Worksheets("myForm").OLEObjects("beerDropDown").Enabled = False
End if
If I can add to this later I will do. Does any of this help you out?