Raised This Month: $51 Target: $400
 12% 

[HELP] OnGameFrame problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zakt4n
Member
Join Date: Jul 2011
Old 09-05-2011 , 13:58   [HELP] OnGameFrame problem
Reply With Quote #1

I'm getting this error:
Code:
L 09/05/2011 - 14:32:21: [SM] Displaying call stack trace for plugin ".smx":
L 09/05/2011 - 14:32:21: [SM]   [0]  Line 193, rdmpower.sp::OnGameFrame()
L 09/05/2011 - 14:32:21: [SM] Plugin encountered error 11: Invalid memory access
What is the problem with my code:
Code:
public OnGameFrame()
{
    for (new i=1;i<=MaxClients;i++)
    {
        decl color[4];
        decl toSend[MaxClients];
        decl pCount;
        decl team;
        decl health;
        if (IsClientInGame(i) && IsPlayerAlive(i))
        {
            team = GetClientTeam(i);
            for (new x=1;x<=MaxClients && GetClientTeam(x) == team;x++)
            {
                pCount++;
                toSend[pCount] = x;
            }
            color[3] = 255;
            health = GetClientHealth(i);
            if (health > 99){color[0] = 95;color[1] = 251;color[2] = 0;}
            else if (health < 99 && health > 70){color[0] = 249;color[1] = 149;color[2] = 0;}
            else if (health < 69 && health > 50){color[0] = 228;color[1] = 116;color[2] = 3;}
            else if (health < 49 && health > 20){color[0] = 235;color[1] = 75;color[2] = 0;}
            else if (health < 19 && health > 0){color[0] = 255;color[1] = 0;color[2] = 0;}
            decl Float:origin[3];
            origin[2] += 60;
            GetClientAbsOrigin(i, origin);TE_Start("BeamRingPoint");TE_WriteVector("m_vecCenter", origin);TE_WriteFloat("m_flStartRadius", 40.0);TE_WriteFloat("m_flEndRadius", 45.0);TE_WriteNum("m_nModelIndex", lgtning);TE_WriteNum("m_nHaloIndex", lgtning);TE_WriteNum("m_nStartFrame", 0);TE_WriteNum("m_nFrameRate", 100);TE_WriteFloat("m_fLife", 3.0);TE_WriteFloat("m_fWidth", 45.0);TE_WriteFloat("m_fEndWidth", 45.0);TE_WriteFloat("m_fAmplitude", 0.0);TE_WriteNum("r", color[0]);TE_WriteNum("g", color[1]);TE_WriteNum("b", color[2]);TE_WriteNum("a", color[3]);TE_WriteNum("m_nSpeed", 5);TE_WriteNum("m_nFlags",    0);TE_WriteNum("m_nFadeLength", 100);TE_Send(toSend, pCount);
        }
    }
}
Thanks for everyone!
zakt4n is offline
mjmfighter
Member
Join Date: Jun 2010
Old 09-05-2011 , 14:04   Re: [HELP] OnGameFrame problem
Reply With Quote #2

What line is 193?

Also, its never good to have more than one statement per line. It makes it hard to debug.

Im guessing the error is somewhere in here:

PHP Code:
GetClientAbsOrigin(iorigin);TE_Start("BeamRingPoint");TE_WriteVector("m_vecCenter"origin);TE_WriteFloat("m_flStartRadius"40.0);TE_WriteFloat("m_flEndRadius"45.0);TE_WriteNum("m_nModelIndex"lgtning);TE_WriteNum("m_nHaloIndex"lgtning);TE_WriteNum("m_nStartFrame"0);TE_WriteNum("m_nFrameRate"100);TE_WriteFloat("m_fLife"3.0);TE_WriteFloat("m_fWidth"45.0);TE_WriteFloat("m_fEndWidth"45.0);TE_WriteFloat("m_fAmplitude"0.0);TE_WriteNum("r"color[0]);TE_WriteNum("g"color[1]);TE_WriteNum("b"color[2]);TE_WriteNum("a"color[3]);TE_WriteNum("m_nSpeed"5);TE_WriteNum("m_nFlags",    0);TE_WriteNum("m_nFadeLength"100);TE_Send(toSendpCount); 
make each of these statements on its own line and then see which one is giving an error. Thats probably where your problem will be and you can fix it.
mjmfighter is offline
zakt4n
Member
Join Date: Jul 2011
Old 09-05-2011 , 14:08   Re: [HELP] OnGameFrame problem
Reply With Quote #3

Is not, dont have any error in an effect. but here it go:
Code:
public OnGameFrame()
{
    for (new i=1;i<=MaxClients;i++)
    {
        decl color[4];
        decl toSend[MaxClients];
        decl pCount;
        decl team;
        decl health;
        if (IsClientInGame(i) && IsPlayerAlive(i))
        {
            team = GetClientTeam(i);
            for (new x=1;x<=MaxClients && GetClientTeam(x) == team;x++)
            {
                pCount++;
                toSend[pCount] = x;
            }
            color[3] = 255;
            health = GetClientHealth(i);
            if (health > 99){color[0] = 95;color[1] = 251;color[2] = 0;}
            else if (health < 99 && health > 70){color[0] = 249;color[1] = 149;color[2] = 0;}
            else if (health < 69 && health > 50){color[0] = 228;color[1] = 116;color[2] = 3;}
            else if (health < 49 && health > 20){color[0] = 235;color[1] = 75;color[2] = 0;}
            else if (health < 19 && health > 0){color[0] = 255;color[1] = 0;color[2] = 0;}
            decl Float:origin[3];
            origin[2] += 60;
            GetClientAbsOrigin(i, origin);
            TE_Start("BeamRingPoint");
            TE_WriteVector("m_vecCenter", origin);
            TE_WriteFloat("m_flStartRadius", 40.0);
            TE_WriteFloat("m_flEndRadius", 45.0);
            TE_WriteNum("m_nModelIndex", lgtning);
            TE_WriteNum("m_nHaloIndex", lgtning);
            TE_WriteNum("m_nStartFrame", 0);
            TE_WriteNum("m_nFrameRate", 100);
            TE_WriteFloat("m_fLife", 3.0);
            TE_WriteFloat("m_fWidth", 45.0);
            TE_WriteFloat("m_fEndWidth", 45.0);
            TE_WriteFloat("m_fAmplitude", 0.0);
            TE_WriteNum("r", color[0]);
            TE_WriteNum("g", color[1]);
            TE_WriteNum("b", color[2]);
            TE_WriteNum("a", color[3]);
            TE_WriteNum("m_nSpeed", 5);
            TE_WriteNum("m_nFlags",    0);
            TE_WriteNum("m_nFadeLength", 100);
            TE_Send(toSend, pCount);
        }
    }
}

line 193:
Code:
                pCount++;
zakt4n is offline
mjmfighter
Member
Join Date: Jun 2010
Old 09-05-2011 , 14:16   Re: [HELP] OnGameFrame problem
Reply With Quote #4

its probably the for loop. i dont think you can have the && inside a for loop. Try something like this instead:

PHP Code:
            if(GetClientTeam(x) == team)
            {
                for (new 
x=1;x<=MaxClients;x++)
                {
                    
pCount++;
                    
toSend[pCount] = x;
                }
            } 
mjmfighter is offline
zakt4n
Member
Join Date: Jul 2011
Old 09-05-2011 , 14:22   Re: [HELP] OnGameFrame problem
Reply With Quote #5

but i need to put the pCount++ and toSend[pCount] = x only for a team clients.
See if this can:
Code:
            team = GetClientTeam(i);
            for (new x=1;x<=MaxClients;x++)
            {
                if (GetClientTeam(x) == team)
                {
                    pCount++;
                    toSend[pCount] = x;
                }
            }
zakt4n is offline
mjmfighter
Member
Join Date: Jun 2010
Old 09-05-2011 , 14:24   Re: [HELP] OnGameFrame problem
Reply With Quote #6

yeah i just relized my way wouldnt work because x isnt declared. your way would work.
mjmfighter is offline
zakt4n
Member
Join Date: Jul 2011
Old 09-05-2011 , 14:29   Re: [HELP] OnGameFrame problem
Reply With Quote #7

it keep sending the same error
zakt4n is offline
mjmfighter
Member
Join Date: Jun 2010
Old 09-05-2011 , 14:48   Re: [HELP] OnGameFrame problem
Reply With Quote #8

maybe its because you are not checking to see if that client is in the game or not.

PHP Code:
            team GetClientTeam(i);
            for (new 
x=1;x<=MaxClients;x++)
            {
                if (
IsClientConnected(x) && IsClientInGame(x) && GetClientTeam(x) == team)
                {
                    
pCount++;
                    
toSend[pCount] = x;
                }
            } 
also, you might need to declare pCount = 0; or whatever value u need it to be.
mjmfighter is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 09-05-2011 , 14:56   Re: [HELP] OnGameFrame problem
Reply With Quote #9

You didn't initialize the pCount integer. use new instead of decl to set it to 0 initially.
if you just use decl pCount; and pCount++ you try to increase some garbage data.
__________________
Peace-Maker is offline
zakt4n
Member
Join Date: Jul 2011
Old 09-05-2011 , 16:34   Re: [HELP] OnGameFrame problem
Reply With Quote #10

now it is giving me this error:
Code:
L 09/05/2011 - 17:23:56: [SM] Native "GetClientTeam" reported: Client 2 is not in game
L 09/05/2011 - 17:23:56: [SM] Displaying call stack trace for plugin "rdmpower.smx":
L 09/05/2011 - 17:23:56: [SM]   [0]  Line 194, rdmpower.sp::OnGameFrame()
zakt4n is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode