Quote:
Originally Posted by LenHard
PHP Code:
#include <sourcemod>
#include <sdkhooks>
#pragma semicolon 1
#pragma newdecls required
int gI_Weapon = 0;
public void OnMapStart()
{
gI_Weapon = 0;
CreateTimer(300.0, Timer_Repeat, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public void OnClientPutInServer(int client)
{
if (!IsFakeClient(client)) {
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponDecideUse);
}
}
public Action Timer_Repeat(Handle hTimer)
{
++gI_Weapon;
}
public Action OnWeaponDecideUse(int client, int iWeapon)
{
if (IsValidEdict(iWeapon) && IsClientInGame(client))
{
char[] sWeapon = new char[32];
GetEdictClassname(iWeapon, sWeapon, 32);
switch (gI_Weapon)
{
case 1: // Ak only
{
if (sWeapon[7] != 'a' && sWeapon[8] != 'k')
return Plugin_Handled;
}
case 2: // Next weapon
{
// etc...
}
}
}
return Plugin_Continue;
}
This is what you requested?
|
You have the right idea but I see a lot of things wrong with your code.
Here are some notes about your code that you should take in:
1. If you're not passing any data on a timer handle, you don't need to put "INVALID_HANDLE" in there. Just simply use an underscore like this: CreateTimer(1.0, Timer_Callback, _, TIMER_REPEAT);
2. ++i is equivalent to i + 2. You should be using i++ instead.
3. Change the following:
PHP Code:
char[] sWeapon = new char[32];
GetEdictClassname(iWeapon, sWeapon, 32);
To the following:
PHP Code:
char sWeapon[32];
GetEdictClassname(iWeapon, sWeapon, sizeof(sWeapon));
4. You already assigned "g_iWeapon" to 0 in your global declaration. No need to do it again on OnMapStart(). Also, simply declaring it as "int g_iWeapon;" is basically saying that it's already 0.
5. You can make the following a lot easier by changing it from:
PHP Code:
if (sWeapon[7] != 'a' && sWeapon[8] != 'k')
To the following:
PHP Code:
if (StrContains(sWeapon, "ak47", false) != -1)
Here's my revision:
PHP Code:
#include <sourcemod>
#include <sdkhooks>
#pragma semicolon 1
#pragma newdecls required
int g_iWeapon;
public void OnMapStart()
{
g_iWeapon = 0;
CreateTimer(300.0, TimerChangeWeapon, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public void OnClientPutInServer(int client)
{
if (IsValidClient(client))
{
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponUse);
}
}
public Action TimerChangeWeapon(Handle timer)
{
g_iWeapon++;
}
public Action OnWeaponUse(int client, int weapon)
{
if (IsValidClient(client))
{
char sWeapon[32];
GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
switch (g_iWeapon)
{
case 1: // Ak only
{
if (StrContains(sWeapon, "ak47", false) != -1)
{
return Plugin_Handled;
}
}
case 2: // Next weapon
{
// etc...
}
}
}
return Plugin_Continue;
}
stock bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsClientInKickQueue(client) && IsPlayerAlive(client) && !IsFakeClient(client));
}
__________________