Raised This Month: $ Target: $400
 0% 

Problem with entity replace(remove entity sometims)


Post New Thread Reply   
 
Thread Tools Display Modes
Pawemol12
Member
Join Date: Jun 2012
Location: Poland - Wojnowice
Old 07-31-2012 , 15:29   Re: Problem with entity replace(remove entity sometims)
Reply With Quote #11

O.o You are the best :d But what gives you stock? i still dont know. Now i triing these functions. // Mark the entity to kill, but this will be delayed to the next frame, so it's still valid -- I dont understand this. Where you get next frame?

@Edit:

I have wrong message

Your function removes all entities, but count good

And i must improve your function like this:
Code:
zmien_m60_i_granatnik() {
    new Float:countM60 = float(GetEntityCountByClassName("weapon_rifle_m60_spawn"));
    new Float:countGrenadeLauncher = float(GetEntityCountByClassName("weapon_grenade_launcher_spawn"));

    if (countM60 > countGrenadeLauncher) {
        ReplaceWeaponByAnotherWeapon("weapon_rifle_m60_spawn", "weapon_grenade_launcher_spawn", "models/w_models/weapons/w_grenade_launcher.mdl", GRENADE_LAUNCHER, RoundFloat((countM60 - countGrenadeLauncher) / 2));
    }
    else if (countGrenadeLauncher > countM60) 
    {
        ReplaceWeaponByAnotherWeapon("weapon_grenade_launcher_spawn", "weapon_rifle_m60_spawn", "models/w_models/weapons/w_m60.mdl", M60, RoundFloat((countGrenadeLauncher - countM60) / 2));
    }
}
My function only after restarting rounds take away almost all of the entity. Your removes all even after a reboot of the map. Two other features I added to smlib.

Btw. When the command function has a admin entity normally turn.

Except that all the entity are new. For example, with three M60 gets a grenade launcher.

@next edit:

This bug is when example grenade launcher are 3, but m60 is 1. Now i know what i should do.

Last edited by Pawemol12; 07-31-2012 at 16:50.
Pawemol12 is offline
Pawemol12
Member
Join Date: Jun 2012
Location: Poland - Wojnowice
Old 07-31-2012 , 17:30   Re: Problem with entity replace(remove entity sometims)
Reply With Quote #12

Berni, where is your post? It was on my post. Bug in forum, O.o, or you delete this?

@Edit:
Sry for double post, I looked for first page

Berni, now I correct code and add 3 seconds timer, after map start and round start. Now my code look like:

Function in plugin:
Code:
static zmien_m60_i_granatnik() 
{
    new countM60 = GetEntityCountByClassName("weapon_rifle_m60_spawn");
    new countGrenadeLauncher = GetEntityCountByClassName("weapon_grenade_launcher_spawn");
    if (countM60 > countGrenadeLauncher) 
    {
        new wynik = countM60 - countGrenadeLauncher;
        if (wynik <= 0)
        {
            wynik = 1;
        }
        ReplaceWeaponByAnotherWeapon("weapon_rifle_m60_spawn", "weapon_grenade_launcher_spawn", "models/w_models/weapons/w_grenade_launcher.mdl", GRENADE_LAUNCHER, wynik);
    }
    else if (countGrenadeLauncher > countM60) 
    {
        new wynik = countGrenadeLauncher - countM60;
        if (wynik <= 0)
        {
            wynik = 1;
        }
        ReplaceWeaponByAnotherWeapon("weapon_grenade_launcher_spawn", "weapon_rifle_m60_spawn", "models/w_models/weapons/w_m60.mdl", M60, wynik);
    }
}
In smlib:
Code:
stock ReplaceWeaponByAnotherWeapon(const String:classNameToFind[], const String:classNameToCreate[], const String:model[], weaponId, max)
{
    new x;

    new entity = 65;
    while ((entity = FindEntityByClassname(entity, classNameToFind)) != INVALID_ENT_REFERENCE && x < max) 
    {

        new Float:location[3];
        new Float:angles[3];

        Entity_GetAbsOrigin(entity, location);
        GetEntPropVector(entity, Prop_Send, "m_angRotation", angles);

        // Mark the entity to kill, but this will be delayed to the next frame, so it's still valid
        Entity_Kill(entity);

        new newEntity = CreateEntityByName(classNameToCreate);
        Entity_SetModel(newEntity, model);
        SetEntProp(newEntity, Prop_Send, "m_weaponID", weaponId);
        TeleportEntity(newEntity, location, angles, NULL_VECTOR);
        DispatchKeyValue(newEntity, "count", "1");
        DispatchSpawn(newEntity);

        x++;
    }
    
}
Code:
stock GetEntityCountByClassName(const String:className[])
{
    new count=0;

    new entity = -1;
    while ((entity = FindEntityByClassname(entity, className)) != INVALID_ENT_REFERENCE) {
        count++;
    }

    return count;
}
And now all work good. But i must check it a few times.

Last edited by Pawemol12; 07-31-2012 at 17:53.
Pawemol12 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:24.


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