PDA

View Full Version : Notes to improve stability



ZERO
01-19-2012, 03:57 AM
I am collecting quotes here for personal use in helping to find better code methods to reduce the occurrence of the left hand glitch. Although I have found a way to minimize impact I am looking for ways to adjust existing code to further improve stability.

---------- Post added at 03:42 AM ---------- Previous post was at 03:32 AM ----------

Recommendations:

Using RemoveEdict() is generall a bad idea, since it's not very
safe to use and loves to crash the server under certain cirumstances.

AcceptEntityInput(entity, "Kill"); should be safer.


Maybe RemovePlayerItem function instead of entity input kill?


"Cleanly" removing an entity.
Instead of creating timers (createTimer) to remove an entity this just fires the kill event from the entity's event queue. Using this you don't have to have a separate timer doing multiple checks on the entity when you want to remove it.


public killEntityIn(entity, Float:seconds)
{
if(IsValidEdict(entity))
{
// send "kill" event to the event queue
new String:addoutput[64];
Format(addoutput, sizeof(addoutput), "OnUser1 !self:kill::%f:1",seconds);
SetVariantString(addoutput);
AcceptEntityInput(entity, "AddOutput");
AcceptEntityInput(entity, "FireUser1");
}
}


The Input "Kill" calls the function UTIL_Remove afaik,
it marks the entity as deleted, but does not immediately remove the entity, it will be removed on next frame, so it's still valid until then.

UTIL_Remove is safe because it for example checks if a driver is in a vehicle and exits the driver first before it removes the vehicle and probably other kind of checks for other entities too.

Any Timer or AddOutput Workarounds aren't needed.

---------- Post added at 03:57 AM ---------- Previous post was at 03:42 AM ----------

/**
* Savly detaches a clients weapon, to remove it as example.
* The client will select his last weapon when detached.
*
* @param client Client Index.
* @param weapon Entity Index of the weapon, you'd like to detach.
* @return True on success, false otherwise.
*/

Client_DetachWeapon(client, weapon)

/**
* Removes a weapon from a client.
*
* @param client Client Index.
* @param className Weapon Classname String.
* @param firstOnly If false it loops trough the whole weapon list and deletes all weapons that match the specified classname.
* @param clearAmmo If true, the ammo the client carries for that weapon will be set to 0 (primary and secondary).
* @return True on success, false otherwise.
*/

Client_RemoveWeapon(client, const String:className[], bool:firstOnly=true, bool:clearAmmo=false)

/**
* Removes all weapons of a client.
* You can specify a weapon it shouldn't remove and if to
* clear the player's ammo for a weapon when it gets removed.
*
* @param client Client Index.
* @param exclude If not empty, this weapon won't be removed from the client.
* @param clearAmmo If true, the ammo the player carries for all removed weapons are set to 0 (primary and secondary).
* @return Number of removed weapons.
*/

Client_RemoveAllWeapons(client, const String:exclude[]="", bool:clearAmmo=false)

/**
* Checks if a client has a specific weapon.
*
* @param client Client Index.
* @param className Weapon Classname.
* @return True if client has the weapon, otherwise false.
*/

Client_HasWeapon(client, const String:className[])



I will try to reprogram dragon fly using some of that code instead. I will also update the left hand fix to use these methods as a test to see if it continues working. :wtg:

ZERO
01-19-2012, 01:56 PM
I am now updating all programs to use

Client_DetachWeapon(client, weapon)

dragon fly already has it now