Hello. Long story short I am making a stance system.
The issue I’m having right now is how to properly execute basically. Right now, I’m going in with the mentality of making it configurable, but my biggest issue seems to be how would I store the value of the storage within the character/player, so when it’s changed I can check if the stance is matching up to the other persons. I am attempting to check out the usage of tables for the player, but I’m questioning how to make the values globally available without using too many G_'s.
Heres the script:
function StanceSwitch.Switches(Player, Count)
local CStance = nil
local Player = {
[CStance] = ""
}
local Stances = {
"Neutral Stance",
"Low-Stance",
"Face Aim"
}
if Count == 1 then
Player[CStance] = Stances[1]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceOneIdle)
Anim:Play()
elseif Count == 2 then
Player[CStance] = Stances[2]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceTwoIdle)
Anim:Play()
--[[elseif Count == 3 then
Player[Stance] = Stances[3]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceThreeIdle)
Anim:Play()]]
end
end
function StanceSwitch.BlockSwitches(Player, Count)
local BStance = nil
local Player = {
[BStance] = ""
}
local Stances = {
"Body-Block",
"Face-Block",
"UpperCut-Block"
}
if Count == 1 then
Player[BStance] = Stances[1]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceOneIdle)
Anim:Play()
elseif Count == 2 then
Player[BStance] = Stances[2]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceTwoIdle)
Anim:Play()
--[[elseif Count == 3 then
Player[Stance] = Stances[3]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceThreeIdle)
Anim:Play()]]
end
end
function StanceSwitch.StanceChecker(Player, HitPlayer)
local Stances = {
"Neutral Stance",
"Low-Stance",
"Face Aim"
}
local BlockStances = {
"Body-Block",
"Face-Block",
"UpperCut-Block"
}
if Player[CStance]["Neutral Stance"] and HitPlayer[BStance] ~= HitPlayer[BStance]["Body-Block"] then
return false
end
if Player[CStance]["Low-Stance"] and HitPlayer[BStance] ~= HitPlayer[BStance]["UpperCut-Block"] then
return false
end
end
The Stances table could be put outside the functions, that way it’s not constantly being (re)set.
Instead of putting the Player[BStance] = Stances[#] line in every if statement within the Switches and BlockSwitches functions, you could replace it with Player[BStance] = Stances[Count] outside of the if statements
You could probably do something similar for the getSingleAnimation and Anim:Play() lines
I’m not entirely sure the point of the Player parameter in the functions since you replace it each time anyways? An underscore (_) can be used to symbolize that it isn’t used (or better yet, don’t ask for it in the first place)
I feel as if the code displayed below could be made better, but I don’t want to attempt to do so without knowing what it is you’re doing with the returns
You may be able to make use of the fact that comparisons return a true/false value, and take out the (if statement) middleman. ex: return 4 == 4 and 5>3 [returns true]
if Player[CStance]["Neutral Stance"] and HitPlayer[BStance] ~= HitPlayer[BStance]["Body-Block"] then
return false
end
if Player[CStance]["Low-Stance"] and HitPlayer[BStance] ~= HitPlayer[BStance]["UpperCut-Block"] then
return false
end
Well, I’m not currently home, but I’m glad I saw this whilst I was outside.
The stance suggestion should’ve been a no-brainer for me, but thank you for saying that.
So, I shouldn’t just keep the checks and directly make them equal a specifc thing in the Stances, noted.
I’m a bit confused on this one, how would then save the table to the direct instance?
It relates to if the character’s stance is blocking the other characters, if not in my damage script, I’ll send the value through to tell the script the other player isn’t blocking in the correct stance and just do normal damage if they aren’t.
If this is confusing, hopefully once I’m home I’ll explain/ask or answer questions in a better manner.
I think there was some miscommunication, the Player parameter in the Switches (and BlockSwitches) function is being replaced by the variable Player two lines below it.
function StanceSwitch.Switches(Player, Count) -- Player parameter is here
local CStance = nil
local Player = { --Assigned Player variable is here, which replaces the above parameter
[CStance] = ""
}
--etc etc
end
Line 1’s Player variable in this example is being replaced by the Player = on Line 3, meaning Line 1’s Player argument/parameter isn’t needed/used
Alright, now that I’m back I think I have a few more questions about this. When suggested me this, I’m a bit confused on what you want to me do, since it’s not a long if statement, it’s an indivivual one for each Count. So would I be doing something like
Player[CStance] = Stances[1]
if Count == 1 then
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceOneIdle)
Anim:Play()
I’m just a bit confused by the wording, sorry for the extra questioning.
Also, the reasoning for the count == is to check something that’ll be sent from the client to the server, a number value, so that’s why I’m handling it the way I’m handling it.
I’m still updating the script, using tables for something like this would be too… I guess complicated as I began to attempt to execute the script, I just see a deal of issues such as not being able to put tables in instances, and things of that nature, so I moved onto attributes.
local FightStances = {
"Neutral Stance",
"Low-Stance",
"Face Aim"
}
local BlockStances = {
"Body-Block",
"Face-Block",
"UpperCut-Block"
}
local StanceSwitch = {}
function StanceSwitch.Switches(Player, Count)
local BStance
local CStance
if Count == 1 then
Player:SetAttribute("CStance", FightStances[1])
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceOneIdle)
Anim:Play()
elseif Count == 2 then
Player:SetAttribute("CStance", FightStances[2])
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceTwoIdle)
Anim:Play()
--[[elseif Count == 3 then
Player[Stance] = Stances[3]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.StanceThreeIdle)
Anim:Play()]]
end
end
function StanceSwitch.BlockSwitches(Player, Count)
if Count == 1 then
Player:SetAttribute("BStance", BlockStances[1])
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceOneIdle)
Anim:Play()
elseif Count == 2 then
Player:SetAttribute("BStance", BlockStances[2])
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceTwoIdle)
Anim:Play()
--[[elseif Count == 3 then
Player[Stance] = Stances[3]
local Anim, Length = AnimationModule.getSingleAnimation(Player.Character.Humanoid, script.Animations.BlockStances.StanceThreeIdle)
Anim:Play()]]
end
end
function StanceSwitch.StanceChecker(Player, HitPlayer)
if Player:GetAttribute("CStance") == "Neutral Stance" and HitPlayer:GetAttribute("BStance") ~= (HitPlayer:GetAttribute("BStance") == "Body-Block") then
return false
end
if Player:GetAttribute("CStance") == "Face Aim" and HitPlayer:GetAttribute("BStance") ~= (HitPlayer:GetAttribute("BStance") == "Face-Block") then
return false
end
if Player:GetAttribute("CStance") == "Low-Stance" and HitPlayer:GetAttribute("BStance") ~= (HitPlayer:GetAttribute("BStance") == "UpperCut-Block") then
return false
end
if Player:GetAttribute("CStance") == "Neutral Stance" and HitPlayer:GetAttribute("BStance") == "Body-Block" then
return true
end
if Player:GetAttribute("CStance") == "Face Aim" and HitPlayer:GetAttribute("BStance") == "Face-Block" then
return true
end
if Player:GetAttribute("CStance") == "Low-Stance" and HitPlayer:GetAttribute("BStance") == "UpperCut-Block" then
return true
end
end
return StanceSwitch
This is the new result, I’m just hoping this might work better.
EDIT: It definetely works, but would it be anti-exploitable?