Raised This Month: $32 Target: $400
 8% 

Request to help fix errors in this plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rishabhc43
Junior Member
Join Date: Sep 2017
Old 09-22-2017 , 03:57   Request to help fix errors in this plugin
Reply With Quote #1

I had a plugin request for having weapons such as m4a1s usp cz75 etc, in the offline mode.

https://forums.alliedmods.net/showthread.php?t=301007

Thanks to nhnkl159 for making such a plugin. Anyways, there were some bugs and errors and he isn't free right now to handle it and told me to ask for help here. I am not familiar with sourcepawn/sourcemod language and hence need ur help. Remember that this plugin was meant for use in steam offline mode.

I have posted the script. Can someone fix the errors in this plugin?

The plugin runs only on the latest sourcemod. Type '!weapons' to open up preference for buy menu.
1. USP doesn't load out even after setting its preference.
2. Weapons whose preference is not set, buying it drops one more weapon of the same type. For eg. if m4a4/m4a1s is not set, buying m4a4 will drop an extra m4a4. But after setting m4a4 or m4a1s, it doesn't drop.
3.There is a double buying animation. For eg. if m4a1s is set, then buying it will show animation of m4a4 and then m4a1s.
4. The preference needs to be set after every time the plugin is loaded. I want to save the preference of every client so that they need not set it again.

Quote:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "nhnkl159"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <clientprefs>

#pragma newdecls required

Handle gS_DeagleCookie = INVALID_HANDLE;
Handle gS_USPCookie = INVALID_HANDLE;
Handle gS_M4Cookie = INVALID_HANDLE;
Handle gS_TerroristCookie = INVALID_HANDLE;
Handle gS_CTCookie = INVALID_HANDLE;

char gS_DeagleWeapon[MAXPLAYERS + 1][24];
char gS_M4Weapon[MAXPLAYERS + 1][24];
char gS_USPWeapon[MAXPLAYERS + 1][24];
char gS_TWeapon[MAXPLAYERS + 1][24];
char gS_CTWeapon[MAXPLAYERS + 1][24];

char gS_SomeShit[MAXPLAYERS + 1][24];

public Plugin myinfo =
{
name = "[CS:GO] Offline Weapons",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};

public void OnPluginStart()
{
RegConsoleCmd("sm_weapons", Cmd_Weapons, "Weapons menu list");

gS_DeagleCookie = RegClientCookie("offlineweapons_pistol", "", CookieAccess_Private);
gS_M4Cookie = RegClientCookie("offlineweapons_m4", "", CookieAccess_Private);
gS_USPCookie = RegClientCookie("offlineweapons_usp", "", CookieAccess_Private);
gS_TerroristCookie = RegClientCookie("offlineweapons_terror", "", CookieAccess_Private);
gS_CTCookie = RegClientCookie("offlineweapons_ct", "", CookieAccess_Private);
}

public void OnClientCookiesCached(int client)
{
if (IsValidClient(client))
{
return;
}

GetClientCookie(client, gS_DeagleCookie, gS_DeagleWeapon[client], 24);
GetClientCookie(client, gS_M4Cookie, gS_M4Weapon[client], 24);
GetClientCookie(client, gS_USPCookie, gS_USPWeapon[client], 24);
GetClientCookie(client, gS_TerroristCookie, gS_TWeapon[client], 24);
GetClientCookie(client, gS_CTCookie, gS_CTWeapon[client], 24);
}

public Action CS_OnBuyCommand(int client, const char[] weapon)
{
if( !IsValidClient( client )) return Plugin_Continue;

if( !GetEntProp( client, Prop_Send, "m_bInBuyZone" )) {
return Plugin_Continue;
}

CreateTimer(0.5, GiveWeapons_Timer, client);

Format(gS_SomeShit[client], 24, weapon);

return Plugin_Continue;
}

public Action GiveWeapons_Timer(Handle Timer, any client)
{
char real_name[64];
CS_GetTranslatedWeaponAlias(gS_SomeShit[client], real_name, sizeof real_name);

CSWeaponID id = CS_AliasToWeaponID(real_name);

if (id == CSWeapon_NONE)
return Plugin_Continue;

if (id == CSWeapon_DEAGLE)
{
if (StrEqual(gS_DeagleWeapon[client], ""))
{
GivePlayerItem(client, "weapon_deagle");
return Plugin_Continue;
}
RemovePlayerSecondary(client);
GivePlayerItem(client, gS_DeagleWeapon[client]);
PrintToChat(client, gS_DeagleWeapon[client]);
}

if (id == CSWeapon_USP)
{
if (StrEqual(gS_USPWeapon[client], ""))
{
GivePlayerItem(client, "weapon_p2000");
return Plugin_Continue;
}
RemovePlayerSecondary(client);
GivePlayerItem(client, gS_USPWeapon[client]);
PrintToChat(client, gS_USPWeapon[client]);
}

if (id == CSWeapon_FIVESEVEN)
{
if (StrEqual(gS_CTWeapon[client], ""))
{
GivePlayerItem(client, "weapon_fiveseven");
return Plugin_Continue;
}
RemovePlayerSecondary(client);
GivePlayerItem(client, gS_CTWeapon[client]);
PrintToChat(client, gS_CTWeapon[client]);
}

if (id == CSWeapon_TEC9)
{
if (StrEqual(gS_TWeapon[client], ""))
{
GivePlayerItem(client, "weapon_tec9");
return Plugin_Continue;
}
RemovePlayerSecondary(client);
GivePlayerItem(client, gS_TWeapon[client]);
PrintToChat(client, gS_TWeapon[client]);
}

if(id == CSWeapon_M4A1)
{
if (StrEqual(gS_M4Weapon[client], ""))
{
GivePlayerItem(client, "weapon_m4a1");
return Plugin_Continue;
}
RemovePlayerPrimary(client);
GivePlayerItem(client, gS_M4Weapon[client]);

}
return Plugin_Continue;
}

public Action Cmd_Weapons(int client, int args)
{
if (!IsValidClient(client))
{
return Plugin_Handled;
}

PrintToChat(client, gS_DeagleWeapon[client]);
PrintToChat(client, gS_M4Weapon[client]);

Menu menu = new Menu(MenuHandler_WeaponClasses);
menu.SetTitle("Choose weapon class");
menu.AddItem("pistols", "Pistols");
menu.AddItem("m4", "Rifles");
menu.ExitButton = true;
menu.Display(client, 30);

return Plugin_Handled;
}


public int MenuHandler_WeaponClasses(Menu menu, MenuAction action, int client, int itemchoosed)
{
if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Select)
{
char gS_Buffer[256];
menu.GetItem(itemchoosed, gS_Buffer, 256);

Menu newmenu = new Menu(MenuHandler_Weapon);
newmenu.SetTitle("Choose your favorite");

int gS_Team = GetClientTeam(client);

if(StrEqual(gS_Buffer, "pistols"))
{
if(gS_Team == 2)
{
newmenu.AddItem("tec9", "Tec-9");
}
else if(gS_Team == 3)
{
newmenu.AddItem("usp", "USP-S");
newmenu.AddItem("p2000", "P2000");
newmenu.AddItem("five", "Five-SeveN");
}

newmenu.AddItem("cz", "CZ75-Auto");
newmenu.AddItem("deagle", "Desert Eagle");
newmenu.AddItem("revolver", "R8 Revolver");
}

if(StrEqual(gS_Buffer, "m4"))
{
newmenu.AddItem("m4a1s", "M4A1-S");
newmenu.AddItem("m4a4", "M4A4");
}

newmenu.ExitBackButton = true;
newmenu.Display(client, 30);
}
}

public int MenuHandler_Weapon(Menu menu, MenuAction action, int client, int itemchoosed)
{
if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Select)
{
char gS_Buffer[256];
menu.GetItem(itemchoosed, gS_Buffer, 256);
if (StrEqual(gS_Buffer, "deagle"))
{
SetClientCookie(client, gS_DeagleCookie, "weapon_deagle");
Format(gS_DeagleWeapon[client], 24, "weapon_deagle");
PrintToChat(client, gS_DeagleWeapon[client]);
}
if (StrEqual(gS_Buffer, "revolver"))
{
SetClientCookie(client, gS_DeagleCookie, "weapon_revolver");
Format(gS_DeagleWeapon[client], 24, "weapon_revolver");
PrintToChat(client, gS_DeagleWeapon[client]);
}

if (StrEqual(gS_Buffer, "usp"))
{
SetClientCookie(client, gS_USPCookie, "weapon_usp_silencer");
Format(gS_USPWeapon[client], 24, "weapon_usp_silencer");
PrintToChat(client, gS_USPWeapon[client]);
}
if (StrEqual(gS_Buffer, "tec9"))
{
SetClientCookie(client, gS_TerroristCookie, "weapon_tec9");
Format(gS_TWeapon[client], 24, "weapon_tec9");
PrintToChat(client, gS_TWeapon[client]);
}
if (StrEqual(gS_Buffer, "p2000"))
{
SetClientCookie(client, gS_USPCookie, "weapon_p2000");
Format(gS_USPWeapon[client], 24, "weapon_p2000");
PrintToChat(client, gS_USPWeapon[client]);
}
if (StrEqual(gS_Buffer, "five"))
{
SetClientCookie(client, gS_CTCookie, "weapon_fiveseven");
Format(gS_CTWeapon[client], 24, "weapon_revolver");
PrintToChat(client, gS_CTWeapon[client]);
}
if (StrEqual(gS_Buffer, "cz"))
{
if(GetClientTeam(client) == 2)
{
SetClientCookie(client, gS_TerroristCookie, "weapon_cz75a");
Format(gS_TWeapon[client], 24, "weapon_cz75a");
}
else if(GetClientTeam(client) == 3)
{
SetClientCookie(client, gS_CTCookie, "weapon_cz75a");
Format(gS_CTWeapon[client], 24, "weapon_cz75a");
}
PrintToChat(client, gS_M4Weapon[client]);
}

if (StrEqual(gS_Buffer, "m4a4"))
{
SetClientCookie(client, gS_M4Cookie, "weapon_m4a1");
Format(gS_M4Weapon[client], 24, "weapon_m4a1");
PrintToChat(client, gS_M4Weapon[client]);
}

if (StrEqual(gS_Buffer, "m4a1s"))
{
SetClientCookie(client, gS_M4Cookie, "weapon_m4a1_silencer");
Format(gS_M4Weapon[client], 24, "weapon_m4a1_silencer");
PrintToChat(client, gS_M4Weapon[client]);
}
PrintToChat(client, gS_Buffer);
}
else if (action == MenuAction_Cancel && itemchoosed == MenuCancel_ExitBack)
{
Cmd_Weapons(client, 0);
}
}

stock bool IsValidClient(int client, bool alive = false, bool bots = false)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)) && (bots == false && !IsFakeClient(client)))
{
return true;
}
return false;
}


stock void RemovePlayerPrimary(int client)
{
int iWeapon = -1;
while((iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY)) != INVALID_ENT_REFERENCE)
{
RemovePlayerItem(client, iWeapon);
AcceptEntityInput(iWeapon, "kill");
}
}

stock void RemovePlayerSecondary(int client)
{
int iWeapon = -1;
while((iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY)) != INVALID_ENT_REFERENCE)
{
RemovePlayerItem(client, iWeapon);
AcceptEntityInput(iWeapon, "kill");
}
}
rishabhc43 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 00:08.


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