Hello everyone,
I am attempting to implement an AutoXP script into my PW that rewards players every 10 minutes for dialogue while playing. I attempt to use GoG's version, however I had a bug occur a few hours into use where the amounts were being given quicker than the pre-set ten minute mark.
CODE SNIP----------------------------------
//!!!IMPORTANT!!//
//!!Be sure to "Build" you module after making any changes to this script!!
//Set timer for chat check and movement detection. After this time has expired
//for both checks then the AFK effect type will be applied.
//Default: 600 seconds(10 minutes)
const int TIMER = 600;//Seconds
//If using the RP XP option, decreasing the chat timer will mean that players
//will have to chat more often to recieve the XP reward.
const int CHAT_TIMER = 600;//Seconds
//Available AFK types:
//1 = Repeating floating text on player.
//2 = A visual effect will be applied to the player.
//3 = Transport player to an object in AFK area.
//4 = Boot player.
//5 = Play Animation(looping type only).
const int AFK_TYPE = 1;
//Options for AFK_TYPE 1:
//Enter message that you want to float over the players head when he/she is AFK.
//Default: "AFK"
const string AFK_FLOATING_MESSAGE = "AFK";
//Change the color of the floating text. Options for colors:
//STRING_COLOR_BLACK
//STRING_COLOR_BLUE
//STRING_COLOR_GREEN
//STRING_COLOR_PINK
//STRING_COLOR_RED
//STRING_COLOR_ROSE
//STRING_COLOR_WHITE
const string FLOATY_COLOR = STRING_COLOR_BLUE;
//Allow floaty text with all AFK types. Default: FALSE
const int FLOATY_TEXT_ALWAYS = FALSE;
//Option for AFK_TYPE 2:
//Enter desired VFX number or constant. Default: VFX_DUR_FLAG_GOLD
const int AFK_EFFECT = VFX_DUR_FLAG_GOLD;
//AFK OBJECT. This object is used for AFK_TYPE 2 and AFK_TYPE 3.
//Simply pick any placeable of your choosing and give it the tag below.
//Also make sure the object is checked "plot".If using the object for TYPE 2 you
//can put it in any area. If using it for TYPE 3 place it in the AFK area that
//players will be teleported to.
//Note for AFK_TYPE 3: This option sets a location on the player that they can
//be auto-ported back to. However should the player log out and log back in or
//if the server crashes, this location will be lost. Therefore you should have
//an alternate way of leaving the AKF area.
//Default: "GOGS_AFK_OBJECT"
const string AFK_OBJECT = "GOGS_AFK_OBJECT";
//Additional note for AFK type 3: I have made it so that a player who is in the
//AFK area must type something/anything in the chat bar for them to return to
//their stored location. This is to prevent other players from simply pushing
//the player around and causing a change in location which would teleport them.
//A repeating message is sent to the player until they type something.
//Message:
const string AFK_AREA_MESSAGE = "Type anything in the chat bar to be ported back to saved location.";
//Select color of message. Same color options as above apply.
const string AREA_MESSAGE_COLOR = STRING_COLOR_RED;
//Option for AFK_TYPE 5:
//Enter desired looping animation constant for the AFK animation.
//Default: ANIMATION_LOOPING_SIT_CROSS
const int AFK_ANIMATION = ANIMATION_LOOPING_SIT_CROSS;
//Send a message to the party members of the player that is AFK. This will
//display a message once when the player has gone AFK and once when the player
//is no longer AFK.
//If TRUE, message will be displayed to all party members. DEFAULT: TRUE
const int SEND_FACTION_MESSAGE = TRUE;
//Select color of message. Same color options as above apply.
const string FACTION_MESSAGE_COLOR = STRING_COLOR_PINK;
//Options for awarding RP XP. Basically, if the player is not AFK and has
//chatted within the last timer delay, the player will receive XP.
//Set to TRUE to give RP XP.
const int RP_XP_REWARD = TRUE;
//Set desired amount of XP to give every cycle.
const int XP_AMOUNT = 10;
////////////////////////////END CONFIGURABLE OPTIONS////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void SendAFKFactionMessage(object oPC)
{
int iActive = GetLocalInt(oPC, "AFK_ACTIVE");
string sName = GetName(oPC);
string sMessage;
if (iActive == TRUE) sMessage = sName + " has gone AFK.";
else sMessage = sName + " is no longer AFK.";
object oMember = GetFirstFactionMember(oPC);
while (GetIsObjectValid(oMember))
{
SendMessageToPC(oMember, StringToRGBString(sMessage, FACTION_MESSAGE_COLOR));
oMember = GetNextFactionMember(oPC);
}
}
////////////////////////////////////////////////////////////////////////////////
void CheckNoAFK(object oPC)
{
location lPC = GetLocation(oPC);
location lCheck = GetLocalLocation(oPC, "AFK_LOC_CHECK");
int iChatty = GetLocalInt(oPC, "CHATTY");
if (iChatty == TRUE || lPC != lCheck)
{
if (AFK_TYPE == 1)
{
SetLocalInt(oPC, "AFK_ACTIVE", FALSE);
if (SEND_FACTION_MESSAGE == TRUE) SendAFKFactionMessage(oPC);
}
if (AFK_TYPE == 2)
{
effect eEffect = GetFirstEffect(oPC);
while (GetIsEffectValid(eEffect))
{
if (GetEffectCreator(eEffect)== GetObjectByTag("GOGS_AFK_OBJECT"))
{
RemoveEffect(oPC, eEffect);
}
eEffect = GetNextEffect(oPC);
}
SetLocalInt(oPC, "AFK_ACTIVE", FALSE);
if (SEND_FACTION_MESSAGE == TRUE) SendAFKFactionMessage(oPC);
}
if (AFK_TYPE == 3)
{
location lLoc = GetLocalLocation(oPC, "AFK_RETURN_LOC");
if (iChatty == TRUE)
{
SetLocalInt(oPC, "AFK_ACTIVE", FALSE);
if (SEND_FACTION_MESSAGE == TRUE) SendAFKFactionMessage(oPC);
DelayCommand(2.0, AssignCommand(oPC, ActionJumpToLocation(lLoc)));
}
else
{
SendMessageToPC(oPC, StringToRGBString(AFK_AREA_MESSAGE, AREA_MESSAGE_COLOR));
DelayCommand(3.0, CheckNoAFK(oPC));
}
}
if (AFK_TYPE == 5)
{
SetLocalInt(oPC, "AFK_ACTIVE", FALSE);
if (SEND_FACTION_MESSAGE == TRUE) SendAFKFactionMessage(oPC);
}
}
else
{
DelayCommand(3.0, CheckNoAFK(oPC));
if (AFK_TYPE == 1 || FLOATY_TEXT_ALWAYS == TRUE)
{
string sAFK = StringToRGBString(AFK_FLOATING_MESSAGE, FLOATY_COLOR);
FloatingTextStringOnCreature(sAFK, oPC);
}
}
}
////////////////////////////////////////////////////////////////////////////////
void RunAFKType(object oPC)
{
if (AFK_TYPE == 1)
{
//
}
if (AFK_TYPE == 2)
{
object oAFKObject = GetObjectByTag(AFK_OBJECT);
AssignCommand(oAFKObject, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectVisualEffect(AFK_EFFECT)), oPC));
}
if (AFK_TYPE == 3)
{
SetLocalLocation(oPC, "AFK_RETURN_LOC", GetLocation(oPC));
AssignCommand(oPC, ActionJumpToObject(GetObjectByTag(AFK_OBJECT)));
}
if (AFK_TYPE == 4)
{
//SendMessageToPC(oPC, "Boot!");//Used for testing in single player.
BootPC(oPC);
}
if (AFK_TYPE == 5)
{
AssignCommand(oPC, ActionPlayAnimation(AFK_ANIMATION, 1.0, 10000.0));
}
SetLocalInt(oPC, "AFK_ACTIVE", TRUE);
if (SEND_FACTION_MESSAGE == TRUE) SendAFKFactionMessage(oPC);
CheckNoAFK(oPC);
}
////////////////////////////////////////////////////////////////////////////////
void ChatCheck(object oPC)
{
int iChatty = GetLocalInt(oPC, "CHATTY");
if (iChatty != TRUE)
{
SetLocalInt(oPC, "CHATTY", TRUE);
DelayCommand(IntToFloat(CHAT_TIMER), SetLocalInt(oPC, "CHATTY", FALSE));
}
}
////////////////////////////////////////////////////////////////////////////////
void RunAFKDetection(object oPC)
{
location lPC = GetLocation(oPC);
location lCheck = GetLocalLocation(oPC, "AFK_LOC_CHECK");
int iAFKActive = GetLocalInt(oPC, "AFK_ACTIVE");
int iChatty = GetLocalInt(oPC, "CHATTY");
if (lPC == lCheck && iChatty != TRUE && iAFKActive != TRUE)
{
RunAFKType(oPC);
}
SetLocalLocation(oPC, "AFK_LOC_CHECK", lPC);
if (iChatty == TRUE && RP_XP_REWARD == TRUE) GiveXPToCreature(oPC, XP_AMOUNT);
DelayCommand(IntToFloat(TIMER), RunAFKDetection(oPC));
}
////////////////////////////////////////////////////////////////////////////////
void GOGsAFKDetector(object oPC)
{
DelayCommand(10.0, RunAFKDetection(oPC));
}
/*
Example "OnPlayerChat" script:
//::////////////////////////////////////////////////////////////////////////////
//::A bunch of stuff here.....
//:://///////////////////////////////////////////////////////////////////////////
#include "?
?"
#include "gogs_afk_inc" <------Add this line to your script!
void main()
{
object oPC = GetPCChatSpeaker();
ChatCheck(oPC) <------Add this line to your script!
OtherStuff.......
Ect........
Ect...........
}
Example "OnClientEnter" script:
//::////////////////////////////////////////////////////////////////////////////
//::A bunch of stuff here.....
//:://///////////////////////////////////////////////////////////////////////////
#include "?
?"
#include "gogs_afk_inc" <------Add this line to your script!
void main()
{
object oPC = GetEnteringObject();
GOGsAFKDetector(oPC) <------Add this line to your script!
OtherStuff.......
Ect........
Ect...........
}
*/
---------------------CODE SNIP
If there are any suggestions please let me know.