PDA

View Full Version : [CoD2] If user press F then sprint



Toxys
1st November 2020, 01:41
How can I change the player's speed if he press F key? I know how to detect if player pressed F but I can't change the player's speed:


self endon("disconnect");

while(1)
{
if(self useButtonPressed())
{
self iprintlnBold("Sprint activated!");
}
wait 10;
}

IzNoGoD
1st November 2020, 09:18
Most mods do it by giving the user a different weapon with no model/potatoe.

Which is why you see your gun disappear.

For libcod, you can set a per-player speed (player setg_speed(newspeed)). Make sure to set the client-side g_speed cvar too or else you have a laggy user.
Dont forget to reset it at the end of the sprint time.

Toxys
1st November 2020, 13:06
Ummm sadly I don't using libcod yet. But I trying to figure out.

It seems to work fine but I'm not sure that's the right way and if I'm die while sprinting then I have infinite sprint so the g_speed cvar isn't change back.


init()
{
self endon("disconnect");

while(1)
{
if(self useButtonPressed())
{
self endon("death");
self setclientcvar("g_speed","300");
self iprintlnBold("Sprint activated!!");
wait 10;
self setclientcvar("g_speed","190");
wait 20;
}
}
}

IzNoGoD
1st November 2020, 16:55
download some mod that has sprint in it. Look at how it's handled there.

maxdamage99
2nd November 2020, 05:08
Ummm sadly I don't using libcod yet. But I trying to figure out.

It seems to work fine but I'm not sure that's the right way and if I'm die while sprinting then I have infinite sprint so the g_speed cvar isn't change back.


init()
{
self endon("disconnect");

while(1)
{
if(self useButtonPressed())
{
self endon("death");
self setclientcvar("g_speed","300");
self iprintlnBold("Sprint activated!!");
wait 10;
self setclientcvar("g_speed","190");
wait 20;
}
}
}

really, download released mod, test, check, look script (how work)
exists few methods for make "player sprint", but before talk about it you need understand some

https://killtube.org/showthread.php?3035-SPRINT-Mod-For-MeatBot-COD2&highlight=sprint
https://killtube.org/showthread.php?3053-Sprinting-with-weapon-in-COD2&highlight=sprint
https://killtube.org/showthread.php?2245-RELEASE-Demon-Mod-2-0&highlight=sprint

Toxys
2nd November 2020, 12:18
Yes, I saw all of them but I want to activate once after useButtonPressed and not just the "change weapon" method I want to give at least 400x speed just for 10 seconds and the player can't cancel the sprint.

maxdamage99
3rd November 2020, 06:30
Yes, I saw all of them but I want to activate once after useButtonPressed and not just the "change weapon" method I want to give at least 400x speed just for 10 seconds and the player can't cancel the sprint.


onPlayerSpawned() //function when player spawned
{
/* ... */

self.isSprint = false;
self setclientcvar("g_speed", "190"); //libcod: self setg_speed(190);

/* ... */
}

init()
{
self endon("disconnect");

if (!isDefined(self.isSprint))
self.isSprint = false;

while(1)
{
if (self useButtonPressed() && !self.isSprint)
self thread Sprint();

wait .025;
}
}

Sprint()
{
self endon("disconnect");
self endon("dead"); //put your event ind when player dead from codeCallBack_PlayerKilled(), killed_player, player_killed idc :)

self.isSprint = true;
self setclientcvar("g_speed", "300"); //libcod: self setg_speed(300);
self iprintlnBold("Sprint activated!!");

wait 10;

self setclientcvar("g_speed", "190"); //libcod: self setg_speed(190);

//wait 10; //sprint cooldown if you need, coldown reset if player dead

self.isSprint = false;
}