The following method runs every .1 second to process weapon restrictions. Optimizations to this method may correct some bugs: (from War3Source_Engine_Weapon)
Code:
public Action:DeciSecondTimer(Handle:h,any:a){
timerskip--;
if(timerskip<1){
timerskip=10;
for(new client=1;client<=MaxClients;client++){
/*if(true){ //test
new wpnent = GetCurrentWeaponEnt(client);
if(FindSendPropOffs("CWeaponUSP","m_bSilencerOn")>0){
SetEntData(wpnent,FindSendPropOffs("CWeaponUSP","m_bSilencerOn"),true,true);
}
}*/
if(hasAnyRestriction[client]&&ValidPlayer(client,true)){
new String:name[32];
GetClientName(client,name,sizeof(name));
//PrintToChatAll("ValidPlayer %d",client);
new wpnent = GetCurrentWeaponEnt(client);
//PrintIfDebug(client," weapon ent %d %d",client,wpnent);
//new String:WeaponName[32];
//if(IsValidEdict(wpnent)){
// }
//PrintIfDebug(client," %s res: (%s) weapon: %s",name,weaponsAllowed[client],WeaponName);
// if(strlen(weaponsAllowed[client])>0){
if(wpnent>0&&IsValidEdict(wpnent)){
if (CheckCanUseWeapon(client,wpnent)){
//allow
}
else
{
//RemovePlayerItem(client,wpnent);
//PrintIfDebug(client," drop");
SDKCall(hSDKWeaponDrop, client, wpnent, false, false);
AcceptEntityInput(wpnent, "Kill");
//UTIL_Remove(wpnent);
}
}
else{
//PrintIfDebug(client,"no weapon");
//PrintToChatAll("no weapon");
}
// }
}
}
}
}
Here it is again with the code cleaned:
Code:
public Action:DeciSecondTimer(Handle:h,any:a)
{
timerskip--;
if(timerskip<1)
{
timerskip=10;
for(new client=1;client<=MaxClients;client++)
{
if(hasAnyRestriction[client]&&ValidPlayer(client,true))
{
new String:name[32];
GetClientName(client,name,sizeof(name));
new wpnent = GetCurrentWeaponEnt(client);
if(wpnent>0&&IsValidEdict(wpnent))
{
if(CheckCanUseWeapon(client,wpnent)){
//allow
}
else
{
SDKCall(hSDKWeaponDrop, client, wpnent, false, false);
AcceptEntityInput(wpnent, "Kill");
}
}
}
}
}
}
So here is the clusterfuck of wtf programing we have today. First part of the issue here is we have code that is designed to run on mutiple games which logically leads to errors. Sorry but it is best to use the best code for each game even if it takes more time. We already know that the code used above is not ideal for weapon removal. This is why we always try to remove the weapon before this code can activate b/c if it does it creates a glitch/crash. The ultimate solution would be to implement the correct weapon removal code here to correct the issue.
Next we have the issue of the timerskip--; part. Holy lazy fucking shit! So as we know this code runs every .1 seconds but you will see that this is here to make it so that it will skip 9 times and then run. So we get this:
0.0 seconds = run timerskip=10
0.1 seconds = skip timerskip=9
0.2 seconds = skip timerskip=8
0.3 seconds = skip timerskip=7
0.4 seconds = skip timerskip=6
0.5 seconds = skip timerskip=5
0.6 seconds = skip timerskip=4
0.7 seconds = skip timerskip=3
0.8 seconds = skip timerskip=2
0.9 seconds = skip timerskip=1
1.0 seconds = run timerskip=10
So how often does the program run? EVERY SECOND! So why they fuck not set the timer to 1 second. I will now tell you and I hope your sitting down. The programer decided this while working on the method but was too lazy to go back to the timer to change 0.1 to 1.0! YES that is the high qualtity programing we got here! Now I do not know who worked on this part of war3 if I remember correctly there was some other programers before Ownz took over everything b/c I doubt he would have done this as I know he is better than this.
So we will be fixing that shit.
Now onto order of fucking operations... yes we are reading from an array hasAnyRestriction[] beofre checking if the dam client we are checking for IS EVEN VALID while we are INSIDE OF A LOOP!!!!!!!
BUT IT GETS BETTER! We also have:
Code:
new String:name[32];
GetClientName(client,name,sizeof(name));
Which does, you guessed it NOTING. Not only is the string not being initilized as decl but it is totally worthless. WE ARE CREATING 32 slot arrays for every player in the server and storing their names in them every second for NO REASON. So that shit will be deleted!
One thing that is clear from reading over the sourcecode now that I actually know how to program. This shit is fucked up all over the pace. So here is the plan, after all the races get reprogramed I will then update to the latest war3 release. I will then go though every single line of all the war3 programes and reprogram every single one of them until 100% of all the code is fucking logicall and correct.
As I do not have any idea how to use the svn shit I will then just package my modified source and post it over on war3 for them to use to fix it for everyone. Hopefully they use it. If not at least our server will be really fucking stable.