Raised This Month: $ Target: $400
 0% 

[L4D2] Getting Crashes From Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mortiegama
Senior Member
Join Date: Feb 2010
Old 04-23-2014 , 17:23   [L4D2] Getting Crashes From Plugin
Reply With Quote #1

I've tried several different ways to get this to work properly but I can't seem to figure out what is causing the crashes. If anyone has an idea of what looks wrong I would appreciate the help:

Code:
public OnMapStart()
{
    isMapRunning = true;
}

public OnEntityCreated(entity, const String:classname[])
{
    if (!isMapRunning || IsServerProcessing() == false) return;
    
    if (entity > MaxClients && IsValidEdict(entity) && StrEqual(classname, "infected"))
    {
        new integer = GetRandomInt(1, 5);
        CommonType[entity] = integer;
        
        #if DEBUG
        PrintToChatAll("Entity is a common infected, type %i.", integer);
        #endif
        
        if (integer != 5)
        {
            CommonSpawnTimer[entity] = CreateTimer(0.5, Timer_CommonSpawn, entity);
        }
    }
}

public Action:Timer_CommonSpawn(Handle:timer, any:entity)
{
    new common = EntRefToEntIndex(entity);
    
    if (common > 0 && IsValidEntity(common) && IsValidEdict(common))
    {
        switch (CommonType[entity])
        {
            case 1:
            {
            #if DEBUG
            PrintToChatAll("Zombie type small strong fast low.");
            #endif
            
            SetEntPropFloat(entity, Prop_Data, "m_flModelScale", 0.7);
            
            new iHPMin = GetConVarInt(cvarType1HPMin);
            new iHPMax = GetConVarInt(cvarType1HPMax);
            new iHP = GetRandomInt(iHPMin, iHPMax);
            SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHP);//Set max and 
            SetEntProp(entity, Prop_Data, "m_iHealth", iHP); //current health of Common to defined health.
            
            new Float:iSpeedMin = GetConVarFloat(cvarType1SpeedMin);
            new Float:iSpeedMax = GetConVarFloat(cvarType1SpeedMax);
            new Float:iSpeed = GetRandomFloat(iSpeedMin, iSpeedMax);
            SetEntDataFloat(entity, laggedMovementOffset, 1.0*iSpeed);
            }
            
            case 2:
            {
            #if DEBUG
            PrintToChatAll("Zombie type small weak quick sturdy.");
            #endif
            
            SetEntPropFloat(entity, Prop_Data, "m_flModelScale", 0.9);
            
            new iHPMin = GetConVarInt(cvarType2HPMin);
            new iHPMax = GetConVarInt(cvarType2HPMax);
            new iHP = GetRandomInt(iHPMin, iHPMax);
            SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHP);//Set max and 
            SetEntProp(entity, Prop_Data, "m_iHealth", iHP); //current health of Common to defined health.
            
            new Float:iSpeedMin = GetConVarFloat(cvarType2SpeedMin);
            new Float:iSpeedMax = GetConVarFloat(cvarType2SpeedMax);
            new Float:iSpeed = GetRandomFloat(iSpeedMin, iSpeedMax);
            SetEntDataFloat(entity, laggedMovementOffset, 1.0*iSpeed);
            }
            
            case 3:
            {
            #if DEBUG
            PrintToChatAll("Zombie type big tough quick weak.");
            #endif
            
            SetEntPropFloat(entity, Prop_Data, "m_flModelScale", 1.1);
            
            new iHPMin = GetConVarInt(cvarType3HPMin);
            new iHPMax = GetConVarInt(cvarType3HPMax);
            new iHP = GetRandomInt(iHPMin, iHPMax);
            SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHP);//Set max and 
            SetEntProp(entity, Prop_Data, "m_iHealth", iHP); //current health of Common to defined health.
            
            new Float:iSpeedMin = GetConVarFloat(cvarType3SpeedMin);
            new Float:iSpeedMax = GetConVarFloat(cvarType3SpeedMax);
            new Float:iSpeed = GetRandomFloat(iSpeedMin, iSpeedMax);
            SetEntDataFloat(entity, laggedMovementOffset, 1.0*iSpeed);
            }
            
            case 4:
            {
            #if DEBUG
            PrintToChatAll("Zombie type large titanic slow titanic.");
            #endif
            
            SetEntPropFloat(entity, Prop_Data, "m_flModelScale", 1.2);
            
            new iHPMin = GetConVarInt(cvarType4HPMin);
            new iHPMax = GetConVarInt(cvarType4HPMax);
            new iHP = GetRandomInt(iHPMin, iHPMax);
            SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHP);//Set max and 
            SetEntProp(entity, Prop_Data, "m_iHealth", iHP); //current health of Common to defined health.
            
            new Float:iSpeedMin = GetConVarFloat(cvarType4SpeedMin);
            new Float:iSpeedMax = GetConVarFloat(cvarType4SpeedMax);
            new Float:iSpeed = GetRandomFloat(iSpeedMin, iSpeedMax);
            SetEntDataFloat(entity, laggedMovementOffset, 1.0*iSpeed);
            }
        }
    }
        
    if (CommonSpawnTimer[entity] != INVALID_HANDLE)
    {
        KillTimer(CommonSpawnTimer[entity]);
        CommonSpawnTimer[entity] = INVALID_HANDLE;
    }
    
    return Plugin_Stop;
}

public OnMapEnd()
{
    isMapRunning = false;
}
Full SP is attached.
Attached Files
File Type: sp Get Plugin or Get Source (L4D2 Nightmarish Common.sp - 477 views - 9.6 KB)
__________________
Mortiegama is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-24-2014 , 08:36   Re: [L4D2] Getting Crashes From Plugin
Reply With Quote #2

I'm guess, you are trying mess entities, which are "flushed" on map start.
And you are using EntityRef wrong way.

Entity References (SourceMod)
PHP Code:
callback(entity)
{
    
CreateTimer(5.0delayEntIndexToEntRef(entity));
}

public 
Action:delay(Handle:timerany:ref)
{
    new 
entity EntRefToEntIndex(ref);

    if(
entity == INVALID_ENT_REFERENCE)
    {
        return;
    }

    
// Do math


Code:
SetEntDataFloat(entity, laggedMovementOffset, 1.0*iSpeed);

Not need find offsets...
SetEntPropFloat(entity, Prop_Data, "m_flLaggedMovementValue", 1.0*iSpeed);
*edit
And you are storing timer to very big array "CommonSpawnTimer" ? You are using entity index as array index...

*edit
and you are using KillTImer in Timer callback...

Last edited by Bacardi; 04-24-2014 at 08:41.
Bacardi is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 04-24-2014 , 08:37   Re: [L4D2] Getting Crashes From Plugin
Reply With Quote #3

Incorrect
PHP Code:
CommonSpawnTimer[entity] = CreateTimer(0.5Timer_CommonSpawnentity); 
Should be:
PHP Code:
CommonSpawnTimer[entity] = CreateTimer(0.5Timer_CommonSpawnEntIndexToEntRefentity), TIMER_FLAG_NO_MAPCHANGE ); 
Note: Your timer don't have to return anything since its a single fire timer.. it will close handle himself.

EDIT EDIT:Bacardi i love u!!!
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 04-24-2014 at 08:38.
GsiX is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-24-2014 , 09:16   Re: [L4D2] Getting Crashes From Plugin
Reply With Quote #4

Quote:
Originally Posted by GsiX View Post
...
EDIT EDIT:Bacardi i love u!!!
akward . Hi to you too.

I made few changes... my style.
Spoiler
Bacardi is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 04-24-2014 , 10:10   Re: [L4D2] Getting Crashes From Plugin
Reply With Quote #5

I'd use SDKHook_SpawnPost hook instead of a timer.
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Mortiegama
Senior Member
Join Date: Feb 2010
Old 04-25-2014 , 09:30   Re: [L4D2] Getting Crashes From Plugin
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
akward . Hi to you too.

I made few changes... my style.
Spoiler
I took your code here, modified it slightly, and threw it into my plugin. I'm not getting crashes anymore which is great! Only problem I'm experiencing is with this line:

Code:
SetEntPropFloat(entity, Prop_Data, "m_flLaggedMovementValue", SPEED);
I've tried everything I can but all I get is error outputs concerning that.

Code:
Native "SetEntPropFloat" reported: Property "m_flLaggedMovementValue" not found (entityX)
I've tried using SetEntProp and Prop_Send instead of Prop_Data but nothing.
__________________
Mortiegama 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 01:04.


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