• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Help with code Please (SOLVED)

Newbie Spellweaver
Joined
Oct 19, 2023
Messages
13
Reaction score
5
Need help with this code it count downs before quit, switch char/server. The code does a countdown but 1 to 5 instead of 5 to 1
Untitled - Help with code Please (SOLVED) - RaGEZONE Forums


Code:
if(lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER &&    lpObj->CloseCount > 0)
        {
            if(lpObj->CloseCount > 5)
            {
                if(lpObj->CloseType == 1)
                {
                    if(gObjectManager.CharacterGameClose(lpObj->Index) == 1)
                    {
                        GCCloseClientSend(lpObj->Index,1);
                    }
                }
                else if(lpObj->CloseType == 0)
                {
                    GCCloseClientSend(lpObj->Index,0);
                }
                else if(lpObj->CloseType == 2)
                {
                    GCCloseClientSend(lpObj->Index,2);
                }
            }
            else
            {
                gNotice.GCNoticeSend(lpObj->Index,1,0,0,0,0,0,gMessage.GetMessage(MSG_SERVER, 4),(lpObj->CloseCount-0));
            }
            lpObj->CloseCount++;
        }
 

Attachments

  • Untitled - Help with code Please (SOLVED) - RaGEZONE Forums
    Untitled.png
    1.8 MB · Views: 20
Newbie Spellweaver
Joined
Oct 27, 2017
Messages
11
Reaction score
4
Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    if (lpObj->CloseCount >= 5) { // Alterado de > para >= to include 5 in the countdown
        if (lpObj->CloseType == 1) {
            if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                GCCloseClientSend(lpObj->Index, 1);
            }
        } else if (lpObj->CloseType == 0) {
            GCCloseClientSend(lpObj->Index, 0);
        } else if (lpObj->CloseType == 2) {
            GCCloseClientSend(lpObj->Index, 2);
        }
    } else {
        int countdown = 5 - lpObj->CloseCount + 1; // Calculate countdown from 5 to 1
        gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
    }
    lpObj->CloseCount--;
}


The main changes made to the code are:

The condition if (lpObj->CloseCount > 5) was changed to if (lpObj->CloseCount >= 5) to include the value 5 in the countdown.

The countdown calculation has been adjusted to subtract lpObj->CloseCount from 5 and add 1 so that the count is 5 to 1.

Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    if (lpObj->CloseCount >= 5) { // Alterado de > para >= to include 5 in the countdown
        if (lpObj->CloseType == 1) {
            if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                GCCloseClientSend(lpObj->Index, 1);
            }
        } else if (lpObj->CloseType == 0) {
            GCCloseClientSend(lpObj->Index, 0);
        } else if (lpObj->CloseType == 2) {
            GCCloseClientSend(lpObj->Index, 2);
        }
    } else {
        int countdown = 5 - lpObj->CloseCount + 1; // Calculate countdown from 5 to 1
        gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
    }
    lpObj->CloseCount--;
}


The main changes made to the code are:

The condition if (lpObj->CloseCount > 5) was changed to if (lpObj->CloseCount >= 5) to include the value 5 in the countdown.

The countdown calculation has been adjusted to subtract lpObj->CloseCount from 5 and add 1 so that the count is 5 to 1.


Work?
 
Last edited:
Upvote 0
Newbie Spellweaver
Joined
Oct 19, 2023
Messages
13
Reaction score
5
Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    if (lpObj->CloseCount >= 5) { // Alterado de > para >= to include 5 in the countdown
        if (lpObj->CloseType == 1) {
            if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                GCCloseClientSend(lpObj->Index, 1);
            }
        } else if (lpObj->CloseType == 0) {
            GCCloseClientSend(lpObj->Index, 0);
        } else if (lpObj->CloseType == 2) {
            GCCloseClientSend(lpObj->Index, 2);
        }
    } else {
        int countdown = 5 - lpObj->CloseCount + 1; // Calculate countdown from 5 to 1
        gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
    }
    lpObj->CloseCount--;
}


The main changes made to the code are:

The condition if (lpObj->CloseCount > 5) was changed to if (lpObj->CloseCount >= 5) to include the value 5 in the countdown.

The countdown calculation has been adjusted to subtract lpObj->CloseCount from 5 and add 1 so that the count is 5 to 1.




Work?
Now it does start at 5 but stops counting down and stops switch char/server and quit dont work
Untitled - Help with code Please (SOLVED) - RaGEZONE Forums
 
Upvote 0
Newbie Spellweaver
Joined
Oct 27, 2017
Messages
11
Reaction score
4
Now it does start at 5 but stops counting down and stops switch char/server and quit dont work
View attachment 244448
Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    int countdown = 5; // 

    while (countdown >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Index, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Index, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Index, 2);
            }
        } else {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
        }

        lpObj->CloseCount++;
        countdown--;
    }
}


In this code, I added a while loop that starts a countdown at 5 and decrements the countdown value on each iteration. The program will continue counting from 5 to 1 and perform actions based on the specified conditions. After a countdown, it will end the program.
 
Upvote 0
Newbie Spellweaver
Joined
Oct 19, 2023
Messages
13
Reaction score
5
Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    int countdown = 5; //

    while (countdown >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Index, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Index, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Index, 2);
            }
        } else {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
        }

        lpObj->CloseCount++;
        countdown--;
    }
}


In this code, I added a while loop that starts a countdown at 5 and decrements the countdown value on each iteration. The program will continue counting from 5 to 1 and perform actions based on the specified conditions. After a countdown, it will end the program.
Code:
if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    int countdown = 5; //

    while (countdown >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Index, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Index, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Index, 2);
            }
        } else {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
        }

        lpObj->CloseCount++;
        countdown--;
    }
}


In this code, I added a while loop that starts a countdown at 5 and decrements the countdown value on each iteration. The program will continue counting from 5 to 1 and perform actions based on the specified conditions. After a countdown, it will end the program.
Now it did work, but it happened too fast like in 1 secon 5 to 1 pops out
Untitled - Help with code Please (SOLVED) - RaGEZONE Forums
 
Upvote 0
Newbie Spellweaver
Joined
Oct 27, 2017
Messages
11
Reaction score
4
Now it did work, but it happened too fast like in 1 secon 5 to 1 pops out
View attachment 244449

Code:
#include <stdio.h>
#include <unistd.h>

if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    int countdown = 5; // Initializes the countdown to 5

    while (countdown >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Index, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Index, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Index, 2);
            }
        } else {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
        }

        lpObj->CloseCount++;
        countdown--;

        // Pause for 1 second
        sleep(1);
    }
}

If the countdown is going by too quickly and you want to add a delay between each countdown, you can use the sleep function to pause the program for a specific period of time. Here is the tweaked code with a 1 second delay between each count.

Adding the sleep(1) function will cause the program to pause for 1 second between each countdown, making the countdown more visible and easier to follow. Make sure you include the appropriate libraries and compile the code correctly for your environment.

The code I added with #include <stdio.h> and #include <unistd.h> is part of an example to illustrate the use of the sleep function. These lines of code are not necessary in the context of your original code, and may have been added by mistake.

If your original code already includes these headers, you don't need to add them again. They are part of the C standard library and provide functionality such as standard input/output and timing breaks.

Therefore, if your original code already includes these headers, you can use the sleep function directly without any problems. Otherwise, you can simply remove these includes (#include <stdio.h> and #include <unistd.h>) and just use the sleep function in your original code.
 
Upvote 0
Newbie Spellweaver
Joined
Oct 19, 2023
Messages
13
Reaction score
5
Code:
#include <stdio.h>
#include <unistd.h>

if (lpObj->Connected >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    int countdown = 5; // Initializes the countdown to 5

    while (countdown >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Index, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Index, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Index, 2);
            }
        } else {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), countdown);
        }

        lpObj->CloseCount++;
        countdown--;

        // Pause for 1 second
        sleep(1);
    }
}

If the countdown is going by too quickly and you want to add a delay between each countdown, you can use the sleep function to pause the program for a specific period of time. Here is the tweaked code with a 1 second delay between each count.

Adding the sleep(1) function will cause the program to pause for 1 second between each countdown, making the countdown more visible and easier to follow. Make sure you include the appropriate libraries and compile the code correctly for your environment.

The code I added with #include <stdio.h> and #include <unistd.h> is part of an example to illustrate the use of the sleep function. These lines of code are not necessary in the context of your original code, and may have been added by mistake.

If your original code already includes these headers, you don't need to add them again. They are part of the C standard library and provide functionality such as standard input/output and timing breaks.

Therefore, if your original code already includes these headers, you can use the sleep function directly without any problems. Otherwise, you can simply remove these includes (#include <stdio.h> and #include <unistd.h>) and just use the sleep function in your original code.
where can i get the unistd could not compile
 
Upvote 0
Newbie Spellweaver
Joined
Oct 27, 2017
Messages
11
Reaction score
4
onde posso obter o unistd não consegui compilar
I'm giving basic tips, I've never worked with this type of code, but I'll give you an alternative solution.

Code:
#include <hora.h>

if (lpObj->Conectado >= OBJECT_LOGGED && lpObj->Type == OBJECT_USER && lpObj->CloseCount > 0) {
    contagem regressiva = 5; // Initializes the countdown to 5

    enquanto (contagem regressiva >= 1) {
        if (lpObj->CloseCount > 5) {
            if (lpObj->CloseType == 1) {
                if (gObjectManager.CharacterGameClose(lpObj->Index) == 1) {
                    GCCloseClientSend(lpObj->Índice, 1);
                }
            } else if (lpObj->CloseType == 0) {
                GCCloseClientSend(lpObj->Índice, 0);
            } else if (lpObj->CloseType == 2) {
                GCCloseClientSend(lpObj->Índice, 2);
            }
        } outro {
            gNotice.GCNoticeSend(lpObj->Index, 1, 0, 0, 0, 0, 0, gMessage.GetMessage(MSG_SERVER, 4), contagem regressiva);
        }

        lpObj->CloseCount--;
        contagem regressiva--;

        // Pause for 1 second
        relógio_t hora_inicial = relogio();
        while ((clock() - start_time) / CLOCKS_PER_SEC <1);
    }
}

add me on discord: jj.trancoso
 
Upvote 0
Newbie Spellweaver
Joined
Oct 19, 2023
Messages
13
Reaction score
5
If someone needs this is the FIX

/;

Sources Character Close Count - MuEMU by Emershow​


Add in ServerInfo.cpp below SetItemAcceptHarmonySwitch


this->m_CharacterCloseCount = GetPrivateProfileInt(section,"CharacterCloseCount",0,path);

Add in ServerInfo.h below int SetItemAcceptHarmonySwitch


int m_CharacterCloseCount;

In function void CObjectManager::CharacterGameCloseSet(int aIndex,int type) // OK

find lpObj->CloseCount = 1; then change to


lpObj->CloseCount = gServerInfo.m_CharacterCloseCount;

Finnaly go to GameServer - Common.dat and add below SetItemAcceptHarmonySwitch = 0


CharacterCloseCount = 10



Credits: Emershow
 
Last edited by a moderator:
Upvote 0
Back
Top