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.