Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:20 Der er 14 kommentarer og
1 løsning

hvasd betyder den her fejl mon??

jeg får følgende fejlmeddelelse når jeg prøver at compile mit workspace i ms c++ 6.0:

C:\\games\\Half-Life\\SDK\\SourceCode\\dlls\\game.h(19) : error C2628: \'CRoundRules\' followed by \'void\' is illegal (did you forget a \';\'?)

Er der nogen som har en ide om hvad det kan skyldes?
Så vidt jeg kan se mangler der ikke det omtalte \";\"
Avatar billede disky Nybegynder
05. november 2001 - 12:21 #1
den betyder du har et void et forkert sted.

post koden der laver ballade.
Avatar billede wisen Nybegynder
05. november 2001 - 12:22 #2
prøv lige at poste linie 19 i game.h ....
Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:27 #3
ok... det bliver en lang sag :)
--------------
Linje 19 i game.h:

extern void GameDLLInit( void );
--------------

den kode som jeg har tilføjet:


#include \"extdll.h\"
#include \"util.h\"
#include \"cbase.h\"
#include \"player.h\"
#include \"weapons.h\"
#include \"gamerules.h\"
#include \"roundrules.h\"
#include \"game.h\"

//Define the model names (This aids us when we compare models):

#define RED_MODEL \"redguy\"
#define BLUE_MODEL \"blueguy\"

//Define the time restraints:

#define ROUNDTIME_LIMIT 360 // 6 minutes (6*60)
#define ROUNDTIME_SETUP 30 // 30 secs
#define ROUNDTIME_CHECK 10 // 10 secs
#define ROUNDTIME_DELAY 10 // 10 secs

//Scoring defines:

#define TSCORE_TEAM1 2 // team1 gets 2 points
#define TSCORE_TEAM2 2 // team2 gets 2 points
#define TSCORE_DRAW 0 // team1&2 get 0 points

#define ISCORE_NORMAL 1 // player gets 1 frag
#define ISCORE_SUICIDE -1 // player loses 1 frag
#define ISCORE_TEAM -1 // player loses 1 frag

//Lets also add the \'externs\' we will be using:

extern DLL_GLOBAL BOOL g_fGameOver;

extern int gmsgTeamScore; // teamname-frags-deaths
extern int gmsgGameMode; // gamemode-updates scoreboard
extern int gmsgSayText; // saytext (used to display messages)
extern int gmsgTeamInfo; // teaminfo (sends team names to client)
extern int gmsgDeathMsg; // death messages
extern void respawn(entvars_t *pev, BOOL fCopyCorpse); // needed to respawn players

/*
=========================================================================
            | Restart Round |
=========================================================================
In this function you should reset any vars used during the round,
as well as clean up the map (eg reset doors, glass, etc)
*/
void CRoundRules::RestartRound ( void )
{
    m_RoundState = ROUND_NOTSTARTED;
    m_flRoundTime = gpGlobals->time + ROUNDTIME_SETUP;
}

/*
=========================================================================
            | Check Round Start |
=========================================================================
This checks for the start of a valid round
*/

void CRoundRules::CheckRoundStart (void)
{
    int iRed = 0;
    int iBlue = 0;
    int iSpc = 0;
    BOOL roundstart = TRUE;
    BOOL roundstate = TRUE;

    // loop through all clients, count number of players on each team
    for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
   
        if ( plr )
        {
            const char *pTeamName = plr->TeamID();
            if (FStrEq(pTeamName, TEAM_RED))
                iRed++;
            else if (FStrEq(pTeamName, TEAM_BLUE))
                iBlue++;
            else if (FStrEq(pTeamName, TEAM_SPECTATOR))
                iSpc++;
            else
                ALERT(at_console, \"Unknown Team <%s>\\n\", pTeamName);
        }
    }

    if ((iRed==0)||(iBlue==0))
        roundstart = FALSE;
    else
        roundstate = TRUE;

    if (roundstart)
    {
        // start the round
        m_RoundState = ROUND_STARTED;
        // set the time of the round 
        m_flRoundTime = gpGlobals->time + ROUNDTIME_LIMIT;
        // check for winner in 10 secs
        m_flCheckRound = gpGlobals->time + ROUNDTIME_CHECK; 
        // respawn everyone
        for ( int i = 1; i <= gpGlobals->maxClients; i++ )
        {
            CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
            if (plr)
                respawn (plr->pev, FALSE);
        }
    }
    else // cant start the round yet...wait half of the setup time
        m_flRoundTime = gpGlobals->time + (ROUNDTIME_SETUP / 2);
}

/*
=========================================================================
            | Check Round End |
=========================================================================
This checks for the end of a round
*/
void CRoundRules::CheckRoundEnd ( void )
{

    int iRed = 0;
    int iBlue = 0;
    int iSpc = 0;
    BOOL roundstart = TRUE;

    // loop through all clients, count number of players on each team
    for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
   
        if ( plr->IsAlive() )
        { 
            const char *pTeamName = plr->TeamID();
            if (FStrEq(pTeamName, TEAM_RED))
                iRed++;
            else if (FStrEq(pTeamName, TEAM_BLUE))
                iBlue++;
            else
                ALERT(at_console, \"Unknown Team <%s>\\n\", pTeamName);
        }
    }

    if ((iRed == 0) && (iBlue != 0)) // everyone dead team1
        RoundEnd ( ALL_TEAM1_KILLED );
    else if ((iBlue == 0)&&(iRed != 0)) // everyone dead team2
        RoundEnd ( ALL_TEAM2_KILLED );
    else if ((iBlue == 0)&&(iRed == 0)) // everyone dead
        RoundEnd( DRAW );
    else
        m_flCheckRound = gpGlobals->time + 10.0;

    if ( m_flRoundTime <= gpGlobals->time )
        RoundEnd ( TIME_UP );
}

/*
=========================================================================
            | CRoundRules Constructor |
=========================================================================
This is the constructor...how *exciting*
*/

CRoundRules :: CRoundRules()
{
    m_flRoundTime = gpGlobals->time + ROUNDTIME_SETUP;
    m_flCheckRound = -1;
    m_RoundState = ROUND_NOTSTARTED;
}

/*
=========================================================================
                | Think |
=========================================================================
Heres another biggie...This is the heart of the round rules
system (How many times have I said that?) Basically, I do a
switch for the m_RoundState then depending on what time it is,
I call other functions. Simple?
*/

void CRoundRules :: Think ( void )
{
    ///// Check game rules /////
    switch (m_RoundState)
    {
    case ROUND_NOTSTARTED:
        if ( m_flRoundTime <= gpGlobals->time)
            CheckRoundStart() ;
        break;
    case ROUND_STARTED:
        if ( m_flRoundTime <= gpGlobals->time)
            RoundEnd ( TIME_UP );
        if ( m_flCheckRound <= gpGlobals->time )
            CheckRoundEnd ();
        break;
    case ROUND_END:
        if ( m_flRoundTime <= gpGlobals->time )
            RestartRound();
        break;
    default:
        ALERT(at_console, \"Unknown Round State\\n\");
    }

    if ( g_fGameOver ) // someone else quit the game already
    {
        CHalfLifeMultiplay::Think();
        return;
    }
}

/*
=========================================================================
                | Round End |
=========================================================================
This function is used to delay in between rounds, inform people
of who won award points, put people in observer mode and update scores. I
apply the same concept as the Think() I switch the reason, and depending
on what it equals, I do different things.
*/

void CRoundRules::RoundEnd ( int reason )
{
    switch (reason)
    {
    default:
    case TIME_UP:
        // inform of time up
        // you can use UTIL_ClientPrintAll() or a HudMessage()
        break;
    case DRAW:
        // inform of draw
        break;
    case ALL_TEAM1_KILLED:
        // award points to team2
        // inform of win
        break;
    case ALL_TEAM2_KILLED:
        // award points to team1
        // inform of win
        break; 
    }

    m_RoundState = ROUND_END;
    m_flRoundTime = gpGlobals->time + ROUNDTIME_DELAY;
   
    // loop through all clients, put them in observer mode
    for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
        if (plr)
        {
            // plr->your observer code();
        }
    }
   
    UpdateScores(); // if you need to use this function
}
----------

håber i kan finde ud af det.... formateringen af koden er nok blevet lidt messy nu :)
Avatar billede disky Nybegynder
05. november 2001 - 12:28 #4
Det er .h filen ikke .cpp filen vi skal se :)
Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:31 #5
her er så header filen :)

// Round flow control enums:


enum
{
    ROUND_NOTSTARTED = 0, // round is preparing to start
    ROUND_STARTED, // round is going
    ROUND_END, // round is stopped (prepare to prepare?)
};

// Scoring enums:

enum
{
    TIME_UP = 0, // time up--draw
    ALL_TEAM1_KILLED, // team 2 win
    ALL_TEAM2_KILLED, // team 1 win
    DRAW, // draw (ie both teams empty)
};

// We need to put these here to be able to check the team names in other files:

#define TEAM_RED \"Red\" // red team
#define TEAM_BLUE \"Blue\" // blue team
#define TEAM_SPEC \"Spectator\" // im lazy sometimes
#define TEAM_SPECTATOR \"Spectator\" // observer

//Declare class

class CRoundRules : public CHalfLifeMultiplay
{
public:
    CRoundRules();

    // adds ability to add new client commands:
    virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd );
    // when a player changes names, models, etc...we find out what happened:
    virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer );
    // make it teamplay to the rest of the code (ie other files)
    virtual BOOL IsTeamplay( void ) { return TRUE; }
    // used to check for team damage or damage amongst other players
    virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker );
    // check the relationship between two players
    virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget );
    // returns the team name of the player (TeamID())
    virtual const char *GetTeamID( CBaseEntity *pEntity );
    // dont allow auto aim---ever
    virtual BOOL ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target ) { return FALSE; }
    // used for scoring--if your gamerules made it so you had one VIP team (eg TFC)
    // and an enemy player killed your VIP, check here and award more points.
    virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled );
    // Start up screens, sending \'Player has joined\' messages, etc
    virtual void InitHUD( CBasePlayer *pl );
    // alert everyone when someone dies.
    virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor );
    // Return the name of your game as it appears in the HL Game browser
    virtual const char *GetGameDescription( void ) { return \"Simple RoundRules\"; }
    // Update the scoreboard, I find this useful if you have several gamerules and
    // wish the scoreboard to display different Scoreboard names and/or setups
    virtual void UpdateGameMode( CBasePlayer *pPlayer );
    // Player has been killed, award points, prepare the death message
    virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor );
    // this is the guts of the round based gameplay system, it is short and simple
    // but controls the flow of the game
    virtual void Think ( void );
    // gets the name of the team of index teamIndex. I dont think I use this
    virtual const char *GetIndexedTeamName( int teamIndex );
    // checks if the team name is a valid one and returns TRUE/FALSE according so
    virtual BOOL IsValidTeam( const char *pTeamName );
    // sets the Default player team (simple enough?) I set the default team to \'Spectator\'
    const char *SetDefaultPlayerTeam( CBasePlayer *pPlayer );
    // changes the players team to whatever pTeamName is
    virtual void ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib );
    // You\'ll need these for equiping players
    virtual void PlayerSpawn( CBasePlayer *pPlayer );
    // In my gamerules, players couldnt respawn
    virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ) { return FALSE; }
    // client disconnected, use this to check if they were the VIP
    virtual void ClientDisconnected( edict_t *pClient );
    // I dont want players to drop weapons
    virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ) { return GR_PLR_DROP_GUN_NO; }
    // or ammo, when they die
    virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ) { return GR_PLR_DROP_AMMO_NO; }
   
// New functions added:

    //Checks for the end of a round
    virtual void CheckRoundEnd ( void );
    //checks for the start of a round (ie...are there enough people to start?)
    virtual void CheckRoundStart ( void );
    //end the round, inform the players with reason
    virtual void RoundEnd ( int reason );
    //restart the round (this is a bit misleading) it is actually resetting the map for play
    virtual void RestartRound ( void );
    //this is a nice hack...it updates the score board
    virtual void UpdateScores ( void );
   
//New variables:

    //used for round timing
    float m_flRoundTime;
    //used for during round timing
    float m_flCheckRound;
    //holds current state of round
    int m_RoundState;

//Makes these private:
// I rewrote the original valve function...you will want to do the same

private:
    const char *TeamWithFewestPlayers( void );

}

Avatar billede borrisholt Novice
05. november 2001 - 12:31 #6
Ikke alle C++ compilere accepterer at du skriver void i mellem paranteserne, når du ingen argumenter har til din funktion/procedure. Tror bestem det er DET der er problæemet.

Prøv at erstatte linge 19 med
extern void GameDLLInit();


Jens B
Avatar billede wisen Nybegynder
05. november 2001 - 12:33 #7
... der mangler et semikolon efter den sidste \"}\" i klassedefinitionen...
Avatar billede wisen Nybegynder
05. november 2001 - 12:33 #8
Altså allersidst....
Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:34 #9
Jens B: Har prøvet det, men det hjælper ikke :)
Avatar billede jakoba Nybegynder
05. november 2001 - 12:35 #10
passer det virkelig med en if-else der ænder 2 forskellige booleans?

    if ((iRed==0)||(iBlue==0))
        roundstart = FALSE;
    else
        roundstate = TRUE;

kunne det være en af dem er ulovlige eller udefineret bagefter?
Avatar billede wisen Nybegynder
05. november 2001 - 12:37 #11
Takker for point :)
Avatar billede borrisholt Novice
05. november 2001 - 12:39 #12
kaptajnkemo  >> Fair .... Men det jeg skrev kan nu også være et problem, i ANDRE situationer .. Så prøv at undgå det ! :-)

Jens B
Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:41 #13
tak for hjælpen!

Det var det forbandede semikolon :)
Avatar billede wisen Nybegynder
05. november 2001 - 12:42 #14
Ja, den har desvære som regel ret :)
Avatar billede kaptajnkemo Nybegynder
05. november 2001 - 12:53 #15
borrisholt> Det kan du have ret i.... skal prøve :)

er stadig helt ny i c++
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester