I need help (Key Input).

Discussions about Coding and Scripting
Post Reply
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

I need help (Key Input).

Post by UTX »

I'm currently working on the code of a new Enforcer which has a flashlight equipped, which will be configurable to adjust brightness, colors and other more complex options like a rechargeable battery, similar to the flashlight from Half Life.
Now I'm struggling a little with the key inputs because they work but not as they should. I managed to make the flashlight turn on and off with the same key press, however, doing this activates all the flashlights from all Enforcers, not just the one that I am using, it also turns on an off when other weapons are equipped and that's not how it should works, I want it to turn itself on only for me and only when I have the enforcer equipped.
I'm posting on my phone so I can't add any code but anything helps, I would check key press functions from other weapons but I don't have any.
Spectra
Masterful
Posts: 542
Joined: Tue Jan 22, 2013 5:23 pm
Personal rank: Nullified!
Location: (X) Unable To Locate....

Re: I need help (Key Input).

Post by Spectra »

I/We won't get the solution to your problem unless you drop code here.

And btw Welcome to the Forums!
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: I need help (Key Input).

Post by JackGriffin »

If you are using the keypress for ActivateItem then you aren't subclassing your flashlight properly. You are running into a consistent problem in the unreal series in that item usage is a pain in the ass to make it work easily on the client without adding commands to the User.ini.

Rocky is right, we need to see your code. You can post publicly or send it to me privately if you'd rather not show it yet and we/I can help you. I'm working on this very thing myself for my Unreal coop server. I don't like how the flashlight beam lags on server so I'm going to disconnect it to be rendered client-side only if you are the owner.
So long, and thanks for all the fish
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: I need help (Key Input).

Post by UTX »

I am not using the standard activate, I'm making my own key binds to avoid issues.
I'm pretty sure the issue is in the mutator class that has the mutate function:

Code: Select all

Class Enforcer_Switch Extends Mutator; 

Function AddMutator (Mutator M) 
{ 
    If (M.IsA ('Enforcer_Switch')) Return; 
    Super.AddMutator (M); 
} 

Function Mutate (String MutateString, PlayerPawn Sender) 
{ 
    Local XEnforcer Other; 

    If (MutateString == "Enforcer_Flashlight") 
    { 
        ForEach AllActors (Class 'X.XEnforcer', Other) 
        { 
            If (Other.IsA (('XEnforcer')) Other.Flashlight (); // This is the function that activates the light. 
        } 
    } 
    If (NextMutator != None) NextMutator.Mutate (MutateString, Sender); 
} 

This mutator is called by the Enforcer itself, and I'm sure this is the issue because of that "ForEach AllActors" but I don't know how to make it work differently yet.

Edit.
I found the solution, exec functions!
I deleted the key binds and mutators and simply made it an exec function and it worked, I just need to add the function to the user.ini via mod menu.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: I need help (Key Input).

Post by JackGriffin »

Don't use IsA to iterate your changes. Change this line from

Code: Select all

If (Other.IsA (('XEnforcer')) Other.Flashlight (); // This is the function that activates the light. 
to

Code: Select all

if(Other.Class==Class'XEnforcer') Other.Flashlight (); // This is the function that activates the light. 
It's a grand idea to never use IsA unless you are given no real choice. IsA will grab all children of a class and since you just never know what might get reused by someone else you need to make sure your stuff doesn't affect someone else down the line.
So long, and thanks for all the fish
UTX
Skilled
Posts: 214
Joined: Fri Aug 28, 2015 3:39 am

Re: I need help (Key Input).

Post by UTX »

Thanks a lot Jack, I will make sure to try it out. In any case, I learnt about exec functions and that's cool.
Post Reply