Check if the User who fired the RemoteEvent is in Group then Continue - roblox

I want to create an "Admin Panel" for my Roblox Game.
As already in the title saying, If a RemoteEvent is fired to do a certain thing, I want to check if the User is in the Provided GroupId and then only Continue. If the user is not in the group who fired the RemoteEvent/Executed the Command, then cancel the Request or do nothing.
^ I am doing it to prevent Exploiters Firing RemoteEvents and abuse the Commands even tho they are not an Admin/In the Group
Is there any way to do it like that?

You can check if a player is in a certain group using Player:isInGroup(GroupID).
local RemoteEvent = Instance.new("RemoteEvent"); -- This shall be your RemoteEvent.
RemoteEvent.OnServerEvent:Connect(function(player)
if not player:IsInGroup(123456) then return false end; -- If the player is not in the group, the function will not continue.
-- Your code here.
end)

Related

Anylogic detect that agent stopped on conveyor

is there any easy way to detect that agent stopped on a roller conveyor because there are other agents ahead? I tried to use dynamic variable and conditional event but it is consuming too much performence. I donĀ“t want to go for dynamically checking condition (with cyclic event) because I have some bad experience with it.
Thanks!
Try this:
Create a LinkedList<YourAgentType> agentsOnConveyor.
Whenever an agent enters the conveyor, call agentsOnConveyor.addLast(agent). When it leaves, call agentsOnConveyor.removeFirst(agent).
Now you have a linked representation of the agents on the conveyor.
Last, you use the "on stopped" field in the conveyor and pass the message "upstream" through the linked list, i.e. use a for-loop from the first to the last entry and send them a msg "conveyor stopped".
You may still need to check if the individual agent is moving itself or has also stopped, but it might put you on a working path

Roblox - detect if mesh is hit by hand

I am not sure where to start so asking for some help. I want to create a script that detect if a certain mesh is hit by players right hand. Every time the mesh is hit I want to increase points for player by 1.
Anyone who can nudge me in the right direction here?
Thanks!
EDIT:
I have added this script in StarterCharacterScripts:
game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
local part1 = workspace.CoinsClouds["Meshes/SackOfGoldNoCoins1"]
part1.Touched:Connect(function(hit)
if hit.Name == "RightHand" then
print(hit.Name)
end
end)
end)
This will register when I bump into the part with the right hand, BUT it will register it 5-20 times in a split second every time I bump into the part with the right hand. See attached image. Anyone know why? I would like it to register only once when the right hand is bumped against the part, or even better, only when the user punch the part/mesh. I have tried to add a wait after RightHand is found, but that doesn't work.
PS! I don't know if this is the right way to script it...
Below is an example of the code you would use. It will check if your part is touched by either the right or left hand and it will run whatever is inside of your if statement, in this case it will increase whatever your score is by 1.
local part = workspace.Part -- reference the part here
local debounce = false --used to check for debounce
part.Touched:Connect(function(hit)
if hit.Name == "RightHand" or "LeftHand" then -- checks if a hand touched it
if not debounce then --Check that debounce variable is not true
debounce = true --currently touching the part
print("hit")
wait(1)
debounce = false
end
end
end)
In relation to your new question it is to do with debounce. Roblox has an entire article on it here: https://developer.roblox.com/en-us/articles/Debounce
Basically you would have to add a new if statement to check that the player isn't already touching this part if it is it wont repeat the what is inside the if statement. The code sample above has been edited to work with debounce.

How to make transparent Form get mouse enter events?

I want to create a Delphi application that does something interesting when the user moves his mouse over the top-left corner of the screen. I thought about it and plan to do it with the following strategy:
Create a very small 3x3 Form and make it transparent and always on top. Also make it with no title bar or border.
Define mouse enter event for the Form.
I use the following code for step 1:
procedure TopLeftForm.FormCreate(Sender: TObject);
begin
FormStyle := fsStayOnTop;
self.TransparentColor := true;
self.TransparentColorValue := self.Color;
self.BorderStyle := bsNone;
end;
The problem is that I found that when the Form is transparent, it can't capture mouse enter events. I could make the Form not transparent in order to get mouse enter events, but that way users can see the Form at the top-left screen corner, which is not what I want.
What's your suggestions to my problem?
What you want is a 'Hook' that can give you information about mouse events without the events being intended for your program. It's too big a topic to be able to give you a how-to in one go, but these two links should be helpful:
Understanding how to use Windows Hooks
Mouse Hook Tutorial with Delphi codes
Why use a Windows Hook?
The Windows environment is designed around messages being passed around. Typically, a program is only interested in messages that are sent directly to its own windows. Trying to make sure that your application has a window that will get the messages blocks other applications from receiving those messages when they are in the same location under yours, and if another window is over yours then you won't get the messages. If you want to know about activity that's happening that wouldn't normally be sent to you - for example, a mouse click outside of your application's window. To enable applications to have visibility of events that are not destined for itself, a windows hook can be used.
There are different types of hooks, depending on what you want to access. A mouse hook is appropriate for what you have specified here. The system maintains a 'Hook Chain' for all of the hooks that have been installed - it will be your responsibility to pass the messages on down the chain, and to uninstall yourself from the chain.
To access the messages, your hook function will look something like this (code taken from the 2nd link above and adapted):
function MouseHookHandler(ACode: Integer; WParam: WParam; LParam: LParam): LResult; stdcall;
var
vMouseInfo: PMouseHookStruct;
begin
if ACode < 0 then
Result := CallNextHookEx(Data^.MouseHook, ACode, WParam, LParam)
else
begin
vMouseInfo := PMouseHookStruct(Pointer(LParam));
PostMessage(Data^.AppHandle, WM_CUSTOM_MOUSE, vMouseInfo^.pt.X, vMouseInfo^.pt.Y);
// we dont want to block the mouse messages
Result := CallNextHookEx(nil, ACode, WParam, LParam);
end;
end;
In your hook function:
ACode is dependent on the type of hook and indicates the event
wParam and lParam have a meaning specific to the event
To pass the message on, you should call CallNextHookEx - however for some hooks, the message will always be passed on regardless.
Hooks can be installed as Global hooks - meaning they intercept messages on all threads running in the same Desktop / WinStation as the calling thread. So, if you have multiple users connected via RD, for example, the hook is specific to one of those desktops only.

Close session of choice in unified service desk

We have multiple sessions i-e four sessions opened in USD. I need to close without clicking on 'X' on the session.
Can it be possible to have 4 buttons on the toolbar and by clicking the third button will close the third session in USD?
This should be possible provided that Microsoft's documentation is valid. Even if it is possible, it would be crude, limited, and difficult to implement/maintain without writing custom code. I highly recommend a "close current session" button that simply closes the foreground session. Through configuration however, here's how you could theoretically do what you're asking.
Create a Close button for each session, considering your max number of sessions, let's say 4. On start of a new session, a series of actions fires in an attempt to locate a Close button upon which to attach the session close command, based on logic like this:
Does Global Context variable Session1ID have data?
If not, place the new session ID in Session1ID.
Does Global Context variable Session2ID have data?
Is the new session ID already stored in Session1ID?
If not, place the new session ID in Session2ID.
Does Global Context variable Session3ID have data?
Is the new session ID already stored in Session1ID or Session2ID?
If not, place the new session ID in Session3ID.
Does Global Context variable Session4ID have data?
Is the new session ID already stored in Session1ID, Session2ID, or Session3ID?
If not, place the new session ID in Session4ID.
The buttons themselves could be made visible or enabled based on whether their Session ID is in Global Context.
On click of any of these buttons, let's say #3, the following would occur:
Close Session command using Session3ID
Nullify value of Session3ID, making it available for the next attempt to attach a session ID.
I foresee a few problems with this. You may encounter issues reading from and writing to Global Context variables while inside of a session. Furthermore, you may encounter issues with closing background sessions by their ID.
Further still, closing sessions out-of-sequence would cause new sessions to attach to buttons in a disorderly-looking fashion, creating a bad user experience. Let's say you need to start six sessions (A, B, C, D, E, and F). You have to close the two sessions in the middle (B and C) before starting the last two due to your limit of 4. With A on button 1 and D on button 4, you start sessions E and F which attach to buttons 2 and 3. Now your four buttons correspond to sessions A, E, F, and D, while the session tabs themselves are in the order that you opened them: A, D, E, F. This would be a bad user experience. (I don't believe that you can manipulate the order in which buttons appear using replacement parameters. Button Order is likely to be configuration integers only.)
Hopefully, this clarifies the elegance of a simpler solution: Create a "Close Current Session" button that is only enabled or visible while you have a session.

Override 'Cancel' in event procedures

There is data validation in my MS Word user form which returns the focus to the textbox where the user entered something incorrect. Now I am trying to accommodate the user's change of mind: instead of correcting the entry, I want him to be able to exit the form (click the Exit command button), in which case the entry would be discarded. I suppose that a solution would start with not using the text box's exit event. I little help from someone who knows the answer would save me a lot of testing time, perhaps to find out that I can't do it.
Does anyone know?
I understand that you are handling the Exit event of the Textbox, setting the Cancel output parameter if the data is not valid.
There's a tricky but simple solution that permits to keep that working and still have an Exit button. It permits to activate the handler of the Exit button without requiring the focus to leave the Textbox. This way you can unload the Form safely in this handler.
Try this it works pretty smoothly:
1- Set the property TakeFocusOnClick of the Exit command button to False. You can do that at design time in the property-sheet, or at run-time i.e. at UserForm_Activate
2- just unload the form when the Exit button is clicked:
Private Sub ExitButton_Click()
Unload Me
End Sub
#A.S.H provided the key to the solution below. His point is that it is possible to call another event procedure while Cancel is active in the Exit procedure of a control. That other procedure can be used to rectify the condition in the first control which is triggering the Cancel, thereby enabling an orderly exit. The all-enabling condition is that the control on whose click event the rectifying procedure is to run must not take the focus when clicked (meaning it can run without triggering an exit from the control stuck on Cancel). I have added code to the exit procedure to set CmdExit.TakeFocusOnClick = False when a Cancel condition arises there. Now, ...
Private Sub CmdExit_Click()
' 12 May 2017
' if CmdExit can't take the focus it can't be the ActiveControl
If Not ActiveControl Is CmdExit Then
Select Case ActiveControl.Name
Case "Cbx107"
Cbx107.Value = ""
Case "Tbx53"
Tbx53.Value = "0"
End Select
With CmdExit
If Not .TakeFocusOnClick Then
.TakeFocusOnClick = True
.SetFocus
End If
End With
End If
' now CmdExit is the ActiveControl
MsgMe "Cmd Exit: ActiveControl = " & ActiveControl.Name
Me.Hide
End Sub