Problems with movement code

FehaFeha Join Date: 2006-11-16 Member: 58633Members
edited December 2012 in Modding
<div class="IPBDescription">I run into a dead-end with modifying the player-movement</div>Ok, so I am trying to create a mod ,or rather update one I made pre build 180 (during which it worked), where I have to modify the players movement when they enter a trigger entity (currently only testing in readyroom and not with aliens or marines).
The trigger entity works perfectly fine, as I decided to make my own rather than use the standard Trigger entity, but when a player enters this volume and the modified movement-code runs, I start to see some very strange behaviour.

The screen pretends my movement-code is working, and then almost immediatelly reverts me to where I would have been if nothing had changed.
Sort of like when prediction code/clientside movement differs from a server, and the server continously (but with a slight delay inbetween) tells your client that it is doing it wrong, causing a rubber-banding effect.

However, using "if Server then printstuff end", I have made sure that my code, in fact, does run on the server as well, and instead I get to be extremely confused as to what is causing my problem.


My mod implements a structure similar to combat mode mod (sneak peaked a little on its source code), where I have a file named modname_Player.lua, which contains all my overrides and new methods for a player. When the game starts, the first scripts that run is my modname_Server/Client, which script.loads the real ones first, and proceeds by then loading mod-related scripts, in my case modname_Shared.lua.
That file then loads my trigger volume entity, and modname_Player.lua, and everything seems to work perfectly fine.

in modname_Player.lua, I try to override ComputeForwardVelocity and/or ModifyVelocity, tried both,
so that they look akin to this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local oldComputeForwardVelocity
oldComputeForwardVelocity = Class_ReplaceMethod( "Player", "ComputeForwardVelocity",
    function(self, input)
        if (self:GetIsInTrigger()) then
            return self:GetModdedVelocity(input)
        end
        
        return oldComputeForwardVelocity(self, input)
    end
)<!--c2--></div><!--ec2-->
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local oldModifyVelocity
oldModifyVelocity = Class_ReplaceMethod( "Player", "ModifyVelocity",
    function(self, input, velocity)
        //Shared.Message("ModifyVelocity")
        if self:GetIsInTrigger() then
            modVelocity = self:GetModdedVelocity(input)
            velocity.x = modVelocity.x
            velocity.y = modVelocity.y
            velocity.z = modVelocity.z
        end
        
        return oldModifyVelocity(self, input, velocity)
    end
)<!--c2--></div><!--ec2-->
As you can see both uses a method I added to the player (self:GetModdedVelocity(input)), and through prints I am sure it runs on both server and client, and that it does return the wanted velocities, so this shouldnt be the issue.
The actually effect they have only seem to differ in that the modifyvelocity override causes a <b>much</b> stronger effect (I get a higher velocity, guesstimating it to around 10* as much), but its still the same apart from that.


I got no clue what I am doing wrong, and I implore anyone who has an idea to please help me, I really hit a dead-end with this for a few days now, and I am starting to grow frustrated.




On a side-note:
Anyone know of a way to draw a texture anywhere in the map through code? Or maybe how to at least re-texture a model. Would be useful for making my triggers visible as they are not meant to be invisible. Right now I am using some cinematics that i'm thinking of creating with a script to produce as a face of variable position, width and height
I cant model at all, and is currently using "models/system/editor/location.model" in the editor, but I rather dont use gray boxes in a real map when the mod is finished.

Comments

  • VitdomVitdom Join Date: 2012-04-30 Member: 151345Members, Reinforced - Supporter, Reinforced - Silver, Reinforced - Gold, Reinforced - Diamond, Reinforced - Shadow, WC 2013 - Shadow
    edited December 2012
    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->The screen pretends my movement-code is working, and then almost immediatelly reverts me to where I would have been if nothing had changed.
    Sort of like when prediction code/clientside movement differs from a server, and the server continously (but with a slight delay inbetween) tells your client that it is doing it wrong, causing a rubber-banding effect.<!--QuoteEnd--></div><!--QuoteEEnd-->
    This sounds like something that would happen if you attempt to use a speed hack. Maybe it has something to do with this?

    <!--quoteo(post=2031345:date=Nov 21 2012, 07:02 PM:name=Max)--><div class='quotetop'>QUOTE (Max @ Nov 21 2012, 07:02 PM) <a href="index.php?act=findpost&pid=2031345"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->The "Too many moves to process in a frame" message is nothing new. It was always doing that, it just wasn't displaying the message. The other message about the client underflowing the time credit or sending a move too far in the future are part of the server-side verification of the client input. This is necessary to prevent speed hacking. Some of these messages will get logged under normal circumstances, but I left them in there so we could make sure that legitimate players were not being affected by the anti-speed hacking code.<!--QuoteEnd--></div><!--QuoteEEnd-->
    This "anti-speed hacking code" was apparently added shortly after the release.
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    But since this is a mod, both serverside and clientside running on listenserver, why would it try to nerf any movements I try to apply to an object?
    Also, I dont get any of those messages.

    PS: no it isnt a speedhack mod, or else using a map-placed trigger entity would be a very odd thing to do :)
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    *Bump*

    I really need some help with this, been stuck way too long for it to be a fun challenge anymore :(
  • FehaFeha Join Date: 2006-11-16 Member: 58633Members
    Ok Solved! Adding how if people find this thread on a later date, and need the <a href="http://xkcd.com/979/" target="_blank">wisdom of the ancients</a>

    So I decided to start work on this again, and I seem to finally have cracked the issue. Sure I had tested and noticed that my code did run on the server, however, as my problem really reminded me of when you only change clients movement, I decided to do further testing now.
    I realised that although my code did run on the server, maybe there was a deeper problem causing this. So I started printing out if it ran serverside, clientside or predictionside, and with that, the values that I was receiving, and noticed that certain parts of my code argued that I were not in any water serverside. I followed this thread deeper and deeper until I noticed I had accidently made a slight mistake when I used a certain line:

    <b>Server.ForAllPlayers(self.DoEntity)</b>

    What I forgot, was to give the "self" reference to my function, and instead it thought its self was the player. A quick fix later, and my working line is now like this:

    <b>Server.ForAllPlayers(function(ent) self:DoEntity(ent) end)</b>


    The reason client worked all the time, was because I used an entirely different line for that:
    self:DoEntity(Client.GetLocalPlayer())



    Now I just have to figure out how to do a similar line for the predictside part of my code.
Sign In or Register to comment.