PDA

View Full Version : Help Editing This Script!


ConstructionBoy
03-12-2016, 14:25
Hey guys, this is my first post but definately not my last. I downloaded this plugin (https://forums.alliedmods.net/showthread.php?p=2123938) and I want to edit it so that you can change your weapon size no greater than size 3 and no smaller than 0.5. This is what I did to it and all it does is say "Maximum weapon size is 3" even if I put the value at 1 or 2.

#include <sourcemod>
#include <sdktools>

#define VERSION "1.0"

public Plugin:myinfo =
{
name = "Change Weapon Size",
author = "Master Xykon",
description = "Change the size of weapons.",
version = VERSION,
url = ""
};

public OnPluginStart()
{
CreateConVar("sm_weaponsize_version", VERSION, "Change the Size of Weapons", FCVAR_REPLICATED|FCVAR_NOTIFY);
RegConsoleCmd("sm_weaponsize", WeaponSize);
RegConsoleCmd("sm_ws", WeaponSize);
}

public Action:WeaponSize(client, args)
{
if(!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
{
ReplyToCommand(client, "You must be alive to change your weapon size");
return Plugin_Handled;
}

if (args < 3)
{
ReplyToCommand(client, "Maximum weapon size is 3");
return Plugin_Handled;
}

if (args > 0.5)
{
ReplyToCommand(client, "Minimum weapon size is 0.5");
return Plugin_Handled;
}

new ClientWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
new String:cmdArg[22];
GetCmdArg(1, cmdArg, sizeof(cmdArg));
new Float:fArg = StringToFloat(cmdArg);
SetEntPropFloat(ClientWeapon, Prop_Send, "m_flModelScale", fArg);

return Plugin_Handled;
}

Drixevel
03-12-2016, 14:28
You have your math backwards, basic lesson:

'<' = less than
'>' = greater than
'<=' = less than or equal to
'>=' = more than or equal to



#include <sourcemod>
#include <sdktools>

#define VERSION "1.0"

public Plugin:myinfo =
{
name = "Change Weapon Size",
author = "Master Xykon",
description = "Change the size of weapons.",
version = VERSION,
url = ""
};

public OnPluginStart()
{
CreateConVar("sm_weaponsize_version", VERSION, "Change the Size of Weapons", FCVAR_REPLICATED|FCVAR_NOTIFY);
RegConsoleCmd("sm_weaponsize", WeaponSize);
RegConsoleCmd("sm_ws", WeaponSize);
}

public Action:WeaponSize(client, args)
{
if(!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
{
ReplyToCommand(client, "You must be alive to change your weapon size");
return Plugin_Handled;
}

char sBuffer[12];
GetCmdArgString(sBuffer, sizeof(sBuffer));
float fSize = StringToFloat(sBuffer);

if (fSize < 0.5)
{
ReplyToCommand(client, "Minimum weapon size is 0.5");
return Plugin_Handled;
}
if (fSize > 3.0)
{
ReplyToCommand(client, "Maximum weapon size is 3.0");
return Plugin_Handled;
}

new ClientWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
SetEntPropFloat(ClientWeapon, Prop_Send, "m_flModelScale", fSize);

return Plugin_Handled;
}

Miu
03-12-2016, 14:32
args is the number of arguments passed to the command, fArg would be where the weapon size is stored

WildCard65
03-12-2016, 14:34
Ya, I hate to say this but both of you are wrong in what's wrong with the script.
Correct code:


#include <sourcemod>
#include <sdktools>

#define VERSION "1.0"

public Plugin:myinfo =
{
name = "Change Weapon Size",
author = "Master Xykon",
description = "Change the size of weapons.",
version = VERSION,
url = ""
};

public OnPluginStart()
{
CreateConVar("sm_weaponsize_version", VERSION, "Change the Size of Weapons", FCVAR_REPLICATED|FCVAR_NOTIFY);
RegConsoleCmd("sm_weaponsize", WeaponSize);
RegConsoleCmd("sm_ws", WeaponSize);
}

public Action:WeaponSize(client, args)
{
if(!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
{
ReplyToCommand(client, "You must be alive to change your weapon size");
return Plugin_Handled;
}
else if (args < 1)
{
ReplyToCommand(client, "Usage: sm_weaponsize(sm_ws) [size]");
return Plugin_Handled;
}

new String:cmdArg[22];
GetCmdArg(1, cmdArg, sizeof(cmdArg));
new Float:fArg = StringToFloat(cmdArg);
if (fArg < 0.5)
{
ReplyToCommand(client, "Minimum weapon size is 0.5");
return Plugin_Handled;
}
else if (fArg > 3)
{
ReplyToCommand(client, "Maximum weapon size is 3.0");
return Plugin_Handled;
}
new ClientWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
SetEntPropFloat(ClientWeapon, Prop_Send, "m_flModelScale", fArg);

return Plugin_Handled;
}


Edit: Ninja'd by Miu

Drixevel
03-12-2016, 14:36
Another case of not reading the rest of the code. Regardless, if you took the command argument string and turned it into a number, the math was still backwards.

ConstructionBoy
03-12-2016, 14:40
Thanks guys for the quick responses I'll be testing the code shortly!

Edit: worked perfectly @WildCard65!