UPDATE: Nathan3197 said in [Resolve]Trying to implement a AFK system for zombies but im getting some issues.:
Sorex This works, but i only see this useful for MP. I don't see this working in Zombies, as I don't think the player wants to go AFK then to find out they are in spectator till they respawn with nothing. As the way iv had done it here (might clean up some of the mess to make it look neat) this keep the player alive with all the guns,perks,equipment etc. but the zombies won't be able to find the AFK player or hit them.
I did like how you automated it and check if the player has moved from a standing still.
now I have it working 100% the way I wanted.
onplayerconnect()
{
for (;;)
{
level waittill( "connecting", player );
player.clientid = level.clientid;
level.clientid++;
player thread AFK_listener();
}
}
AFK_listener()
{
level endon( "game_ended" );
self endon( "disconnect" );
self.PlayerNamet = self.name; // Get the player name
//self iprintln("^6AFKTEST"); // Debugging check if function is running
self.isAFK = false; // set isAFK to false
self.counter = 0; // Dont touch this
self.afkcooldown = 1; // cooldown untill player can turn on afk again
self.disToTurnoff = 10; // the amount of distance the player need to move before AFK mode will turn off
for(;;) // loop to check button presses
{
if(self.counter > 0 && self.isAFK == false ) // if counter is more then 0 & isafk false then run the countdown
{
self.counter-- // counter goes down everyscond
self IPrintLnBold("^1You have ^3" + self.counter +" ^1second until you can go ^2AFK ^3again"); // tells the player how long till they can go afk again
wait 1;
}
else if(self.counter == 0 && self.isAFK == false) // if couter is 0 then player can go afk
{
if (self adsbuttonpressed() && self ActionSlotFourButtonPressed()) // if ADS & 2/DpadDown is pressed then run this
{
self thread AFKON(); // runs afk on function
self.counter = self.afkcooldown; // reset counter to whatever afkcooldown is
wait 1; // to prevent spamming
}
}
if (self.isAFK == true) // if isAFK ture then check if the player has press or move any button
{
// If the Player presses any button ore move more then 10 units then AFKOFF will run.
if ( self adsbuttonpressed() | self ActionSlotFourButtonPressed() | self attackbuttonpressed() | self jumpbuttonpressed() | self meleeButtonPressed() | self throwbuttonpressed() | self actionslotonebuttonpressed() | self ActionSlotTwoButtonPressed() | self ActionSlotThreeButtonPressed() | self SprintButtonPressed() | self ChangeSeatButtonPressed() | self SecondaryOffhandButtonPressed() | self FragButtonPressed() | self UseButtonPressed() | Distance(self.old_origin, self.origin) >= self.disToTurnoff)
{
self thread AFKOFF(); // player runs AFKOFF function
}
}
wait 0.05;
}
}
AFKON()
{
self endon( "disconnect" );
self.old_origin = self.origin;
self.isAFK = true; // Set IS AFK TO TRUE
self.ignoreme = 1; // Zombies wont find the player
self enableInvulnerability(); // God mode is on
self iprintln("^6AFK ON"); // tell the player that they AFK
AllClientsPrint("^2"+self.PlayerNamet +"^7 is ^6AFK^7");
self Destroy();
//self IPrintLnBold(self.isAFK); // Debuging
}
AFKOFF()
{
self endon( "disconnect" );
self.isAFK = false; // set IS AFK TO FALSE
self.ignoreme = 0; // Zombies will find the player agian
self disableInvulnerability(); // God mode is off
self iprintln("^6AFK OFF"); // tell the player that they are not afk
AllClientsPrint("^2"+self.PlayerNamet +"^7 is ^1NOT ^6AFK^7");
//self IPrintLnBold(self.isAFK); // Debuging
self Destroy();
}
Original Post:
What im creating here:
When the player press ADS and another key/button they will enable afk mode which turn on Godmode and make the zombies ingore the player while standing still. This will auto turn off when the player presses any key / button. e.g moving or shooting.
Summary of the issue I'm having:
when i press ADS & Actionsslottwobutton (2 key) sometime it will trigger AFK ON and sometime it wont trigger AFK ON. same with when I want to trigger AFK OFF on any button press.
The only issue im having is when i trying to find if is there a buttonpress for the leftstick/WASD or trying to read the player move speed that is greater then 0;
my first attempt of making it work
OnPlayerSpawn()
{
self thread AFKTEST(); // player thread AFKTEST
}
AFKTEST()
{
self iprintln("^6AFKTEST"); // checking if function is working
self.isAFK = false; // set is AFK off
for(;;)
{
if( self adsbuttonpressed() && self actionslottwobuttonpressed() && self.isAFK == false) // if ADS button and Action slot two is pressed & isAFK = false then run this
{
self iprintln("^6AFK ON"); // Tell player that they are AFK
self.isAFK = true; // set isAFK to true
self.ignoreme = 1; // Make zombies not target the player
self enableInvulnerability(); // Turn on GOD mode
}
wait 0.50;
if (self adsbuttonpressed() && self actionslottwobuttonpressed() && self.isAFK == true || self attackbuttonpressed() | self jumpbuttonpressed() | self meleeButtonPressed() | self sprintbuttonpressed() | self fragbuttonpressed() | self throwbuttonpressed() | self actionslotonebuttonpressed() && self.isAFK == true) // if if ADS button and Action slot two is pressed & isAFK = false OR any other button been press then run this
{
self iprintln("^6AFK off"); // tell player that they are not AFK
self.isAFK = false; // set is AFK to false
self.ignoreme = 0; // Make the zombies target the player agian
self disableInvulnerability(); // disable GOD mode
}
wait 0.05;
}
}
I try this as well but found out it take bit longer for it to register a button press.
my second attempt of making it work.
OnPlayerSpawn()
{
self thread AFKTEST(); /// player thread AFKTEST
}
AFKTEST()
{
self iprintln("^6AFKTEST"); // checking if function is working
self.isAFK = false; // set is AFK off
for(;;)
{
if( self adsbuttonpressed() && self actionslottwobuttonpressed() && self.isAFK == false) // if ADS button and Action slot two is pressed & isAFK = false then run this
{
self iprintln("^6AFK ON"); // Tell player that they are AFK
self.isAFK = true; // set isAFK to true
self.ignoreme = 1; // Make zombies not target the player
self enableInvulnerability(); // Turn on GOD mode
}
wait 0.50;
if (self adsbuttonpressed() && self actionslottwobuttonpressed() && self.isAFK == true) // if if ADS button and Action slot two is pressed & isAFK = false then run this
{
self iprintln("^6AFK off"); // tell player that they are not AFK
self.isAFK = false; // set is AFK to false
self.ignoreme = 0; // Make the zombies target the player agian
self disableInvulnerability(); // disable GOD mode
}
else if (self attackbuttonpressed() && self.isAFK == true)
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
else if (self jumpbuttonpressed() && self.isAFK == true )
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
}
else if (self meleeButtonPressed() && self.isAFK == true )
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
}
else if (self throwbuttonpressed() && self.isAFK == true)
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
}
else if (self actionslotonebuttonpressed() && self.isAFK == true)
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
}
wait 0.05;
}
}
if I add this then it will constantly run AFK OFF.
else if (self GetVelocity() > && self.isAFK == true)// if player is moving & AFK is on then run this
{
self iprintln("^6AFK off");
self.isAFK = false;
self.ignoreme = 0;
self disableInvulnerability();
}
UPDATE:
I manage to make it work every keypress i had to change the wait at the end of the loop to 0.05 for it to pick up every button press. the only thing that I still haven't gotten to work is to turn the AFK off when the player walk,
Third attempt of making this work.
OnPlayerSpawn()
{
self thread AFKTEST(); //player run the AFKTEST function~~strikethrough text~~
}
AFKTEST()
{
self iprintln("^6AFKTEST"); // check if function is running
self.isAFK = false; // set isAFK to false
for(;;) // loop to check button presses
{
if (self.isAFK == false) // if AFK is False then run this
{
if (self adsbuttonpressed() && self actionslottwobuttonpressed()) // if ADS & 2/DpadDown is pressed then run this
{
self AFKON(); // player runs AFKON function
wait 1; // wait 1 second to prevent spamming
}
}
if (self.isAFK == true) // if AFK is true then run this
{
if (self adsbuttonpressed() && self actionslottwobuttonpressed()) // if ADS & 2/DpadDown is pressed then run this
{
self AFKOFF(); // player runs AFKOFF function
}
// check if any button has been press
else if (self attackbuttonpressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self jumpbuttonpressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self meleeButtonPressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self throwbuttonpressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self actionslotonebuttonpressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self SprintButtonPressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self FragButtonPressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self ChangeSeatButtonPressed())
{
self AFKOFF(); // player runs AFKOFF function
}
else if (self SecondaryOffhandButtonPressed())
{
self AFKOFF(); // player runs AFKOFF function
}
}
wait 0.05;
}
}
AFKON()
{
self.isAFK = true; // Set IS AFK TO TRUE
self.ignoreme = 1; // Zombies wont find the player
self enableInvulnerability(); // God mode is on
self iprintln("^6AFK ON"); // tell the player that they AFK
//self IPrintLnBold(self.isAFK); // Debuging
}
AFKOFF()
{
self.isAFK = false; // set IS AFK TO FALSE
self.ignoreme = 0; // Zombies will find the player agian
self disableInvulnerability(); // God mode is off
self iprintln("^6AFK off"); // tell the player that they are not afk
//self IPrintLnBold(self.isAFK); // Debuging
}