SetModelScale, SetRunSpeed, SetWalkSpeed and SetModel aren't working!
5 replies, posted
Hello!
I've been modding for almost a year now working on 2 main projects, TTT Assassins, and the one that I'm having trouble with, Vampirism.
In recent months I have been rewriting the mod and trying to get it to function as intended, but I keep running into issues that I can't fix.
The main one that I'm having difficulty with is the Transformation mechanic; where a player can transform into a Vampire Lord like in Skyrim. I jumped into gmod, pressed the activation keys ([USE] + [RELOAD]) and it did the animation as well as print the message into chat like it was supposed to, but seemingly nothing else happens and I dont understand why. Perhaps someone can enlighten me?
Anyway, here's the code:
[CODE]
function SWEP:Transform()
self.PlayerModel = self.Owner:GetModel()
self.PlayerWalkSpeed = self.Owner:GetWalkSpeed()
self.PlayerSprintSpeed = self.Owner:GetRunSpeed()
if CombatMode == "Beast" or CombatMode == "Blood" then return end
if self.Owner:GetModel() != self.VampireModel then
self.Owner:SetModel(self.VampireModel)
end
self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_TAUNT_ZOMBIE )
self.Owner:SetModelScale( self.VampireScale, 2 )
if self.VampireScale > 1 then
self.Owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )
else
self.Owner:SetCollisionGroup( COLLISION_GROUP_NONE )
end
self.Owner:SetRunSpeed(self.VampSprintSpeed)
self.Owner:SetWalkSpeed(self.VampWalkSpeed)
self.Owner:ChatPrint("You have entered beast form!")
IsBeast = true
CombatMode = "Beast"
end[/CODE]
What I'm expecting to happen is as follows:
-The player grows 50% bigger over 2 seconds. - They don't
-The player gets 50% faster. - They don't
-The player does the zombie taunt animation. - They do
-The player's model changes to the vampire lord model. - They don't
-The player's collision group changes to that of a passable door (to prevent derpyness). - They don't (because they havent gotten any bigger)
-A message appears in chat stating that they have become "The beast". - It does.
As far as I can tell, I'm not doing anything wrong. But hey, that's likely not the case.
Probably a dumb question, but, are you calling the function serverside, right? Because on client, you cannot change collision group, walk speed etc.
Dont worry, I am. There isnt much in this SWEP that has to be called clientside. What's made this so hard for me to fix is that I had done this before in an older version of the SWEP that was never released because it didn't work in a way that I liked. I have no idea why it wont now. It's almost identical.
Actually, anything regarding the physics, has be ran on both the server and the client.
Anything like this:
SetModelScale
SetHullSize
SetWalkSpeed
SetRunSpeed
All need to be networked to every client. The server needs to also have the same information for proper calculations. The client is a prediction, and the server is the correct calculator. One cannot exist without the other.
Those commands affect the physics,
Client physics is absolutely separate from the server-side physics.
You need to write it in shared.
Maybe this works.
I haven't tested it and it may also be that perhaps is a shape error or so inside.
[CODE]
function SWEP:Transform()
self.PlayerModel = self.Owner:GetModel()
self.PlayerWalkSpeed = self.Owner:GetWalkSpeed()
self.PlayerSprintSpeed = self.Owner:GetRunSpeed()
self.PlayerViewOffset = self.Owner:GetViewOffset()
self.PlayerViewOffsetDucked = self.Owner:GetViewOffsetDucked()
if CombatMode == "Beast" or CombatMode == "Blood" then return end
if self.Owner:GetModel() != self.VampireModel then
self.Owner:SetModel(self.VampireModel)
self.Owner:SetupHands()
end
self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_TAUNT_ZOMBIE )
self.Owner:SetViewOffset(self.PlayerViewOffset*self.VampireScale)
self.Owner:SetViewOffsetDucked(PlayerViewOffsetDucked*self.VampireScale)
self.Owner:SetModelScale( self.VampireScale, 2 )
if self.VampireScale > 1 then
self.Owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )
else
self.Owner:SetCollisionGroup( COLLISION_GROUP_NONE )
end
self.Owner:ChatPrint("You have entered beast form!")
IsBeast = true
CombatMode = "Beast"
hook.Add( "TTTPlayerSpeed", "BoostSpeed", function( ply, slowed )
if ply == self.Owner and CombatMode == "Beast" then
return 1.5
end
end )
end
[/CODE]
[QUOTE]Actually, anything regarding the physics, has be ran on both the server and the client.
Anything like this:
SetModelScale
SetHullSize
SetWalkSpeed
SetRunSpeed
All need to be networked to every client. The server needs to also have the same information for proper calculations. The client is a prediction, and the server is the correct calculator. One cannot exist without the other.
Those commands affect the physics,
Client physics is absolutely separate from the server-side physics.
You need to write it in shared. [/QUOTE]
I tried that but to no avail. Though it helps to know that for improvements in the future.
[QUOTE]Maybe this works.
I haven't tested it and it may also be that perhaps is a shape error or so inside.
[CODE]function SWEP:Transform()
self.PlayerModel = self.Owner:GetModel()
self.PlayerWalkSpeed = self.Owner:GetWalkSpeed()
self.PlayerSprintSpeed = self.Owner:GetRunSpeed()
self.PlayerViewOffset = self.Owner:GetViewOffset()
self.PlayerViewOffsetDucked = self.Owner:GetViewOffsetDucked()
if CombatMode == "Beast" or CombatMode == "Blood" then return end
if self.Owner:GetModel() != self.VampireModel then
self.Owner:SetModel(self.VampireModel)
self.Owner:SetupHands()
end
self.Owner:DoAnimationEvent( ACT_GMOD_GESTURE_TAUNT_ZOMBIE )
self.Owner:SetViewOffset(self.PlayerViewOffset*self.VampireScale)
self.Owner:SetViewOffsetDucked(self.PlayerViewOffsetDucked*self.VampireScale)
self.Owner:SetModelScale( self.VampireScale, 2 )
if self.VampireScale > 1 then
self.Owner:SetCollisionGroup( COLLISION_GROUP_PASSABLE_DOOR )
else
self.Owner:SetCollisionGroup( COLLISION_GROUP_NONE )
end
self.Owner:ChatPrint("You have entered beast form!")
IsBeast = true
CombatMode = "Beast"
hook.Add( "TTTPlayerSpeed", "BoostSpeed", function( ply, slowed )
if ply == self.Owner and CombatMode == "Beast" then
return 1.5
end
end )
end[/CODE]
[/QUOTE]
Wow. That certainly looks promising. I see that you've hooked TTT playerspeed, which actually helps a bit with the TTT version of the SWEP. I'll tweak it for Sandbox and see if that improves the situation.
Edit: I had to tweak the code. You missed "self." in front of "PlayerViewOffsetDucked" and it freaked out.
[editline]30th July 2016[/editline]
It just spat this error out at me and the camera started rapidly moving up and down.
[CODE][ERROR] lua/includes/extensions/player.lua:223: attempt to call field 'Create' (a nil value)
1. SetupHands - lua/includes/extensions/player.lua:223
2. Transform - addons/the vampire/lua/weapons/vampire_redo.lua:229
3. unknown - addons/the vampire/lua/weapons/vampire_redo.lua:188
Bad sequence in GetSequenceName() for model 'error.mdl'!
[/CODE]
It seems to be flickering between the the defualt camera offset and the new one.
Sorry, you need to Log In to post a reply to this thread.