PDA

View Full Version : GiveOP, first plugin problem


GeehFox
10-08-2014, 03:21
Hello there, I'm trying to make a new plug in to edit the admin.cfg file, in order to insert the specified player's name, flag, and such.
I thought I did everything correctly, and managed to fix some of the issues, but some still remain, and I think it would be nice to know what I've done wrong, exactly (First time from Assembly to Sourcemod-C-like thing :oops:)

#include <sourcemod>

public Plugin:myinfo =
{
name = "GiveOP",
author = "Geeh",
description = "Gives OP powers using /giveop",
version = "1.0",
url = "http://www.foxyfriends.eu/"
};

public OnPluginStart();
{
RegAdminCmd("sm_giveop", Command_GiveOP, ADMFLAG_SLAU);
}

public Action:Command_GiveOP(client, args)
{
new String:arg1[32], String:arg2[32];
new flag;
new MAX_NAME_LENGHT;
MAX_NAME_LENGHT = 256;

if (args >= 2 && GetCmdArg(2, arg2, sizeof(arg2)))
{
flag = arg2;
}
new target = FindTarget(client, arg1);
if (target == -1)
{
return Plugin_Handled;
}
//Get name
new String:name[MAX_NAME_LENGHT];
//Get Steam ID
new String:steamid[MAX_NAME_LENGHT];
GetClientAuthString(ProcessTargetString(name) , String:steamid, TRUE);
GetClientName(target, name, sizeof(name));
//Initialize File
decl String:path[PLATFORM_MAX_PATH][128];
//File stream
BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"admin.cfg");
new Handle:fileHandle=OpenFile("addons/sourcemod/configs/admin.cfg", "a");
//Writing to file
WriteFileLine(fileHandle,"Plugin/n{/n"$name"/n{"auth" "$steamid"/n"identity" "$steamid"/n"flags" "$flag"/n}}";
CloseHandle(fileHandle);
return Plugin_Handled;
}

Errors:
giveop.sp<12> : error 010: invalid function or declaration
giveop.sp<26> : error 006: must be assigned to an array
giveop.sp<37> : error 092: number of arguments does not match definition
giveop.sp<38> : warning 224: indeterminate array size in "sizeof" expression <symbol "">
giveop.sp<42> : error 048: array <s do not match
giveop.sp<45> : error 001: expected token: ",", but found "$"
giveop.sp<45> : error 029: invalid expression, assumed zero
giveop.sp<45> : warning 214: expression has no effect
giveop.sp<45> : error 001: expected token: ";", but found "-string-"
giveop.sp<45> : fatal error 127: too many error messages on one line

ddhoward
10-08-2014, 04:50
None of that looks like appropriate AMX Mod X functions or anything. It looks like you are trying to create a Sourcemod plugin (for Source, HL2 games), rather than an AMX Mod X plugin (for GoldSrc, HL1 games). If this is the case, please be aware that you have posted this thread in the forum for scripting help for AMX Mod X plugins. I am going to continue with this post under the assumption that you meant to post it in the Sourcemod section.

public OnPluginStart();
Why is there a ; after OnPluginStart() ?

RegAdminCmd("sm_giveop", Command_GiveOP, ADMFLAG_SLAU);
Slau? Do you perhaps mean ADMFLAG_SLAY? Also, are you aware that this will allow any admin with the slay flag to give anyone ANY other flag?

flag = arg2;
arg2 is a string, and flag is an int. This does not work. Perhaps you meant to declare 'flag' as a string?


GetClientAuthString(ProcessTargetString(name) , String:steamid, TRUE);
You are running 'name' through ProcessTargetString through GetClientAuthString, even though you A) already have the target in the 'target' variable, and B) know that 'name' is completely blank, as you've just declared it without putting anything into it. Why not just use 'target' as the first argument for GetClientAuthString?

MAX_NAME_LENGHT
First off, this is misspelled, and secondly, MAX_NAME_LENGTH is already a defined value in clients.inc. You do not need to define it again.

WriteFileLine(fileHandle,"Plugin/n{/n"$name"/n{"auth" "$steamid"/n"identity" "$steamid"/n"flags" "$flag"/n}}";

You need to escape the quotation marks. Otherwise, the compiler thinks that the literal string that you want to write is finished, and that you've put a bunch of gibberish after it. See how the colors here change? That means that you've ended the string by using a " character.

Further, that is not how Sourcemod places information into strings. https://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)

Also, you didn't use a closing paren before the semicolon.

WriteFileLine(fileHandle,"Plugin\n{\n\"%s\"\n{\"auth\" \"steam\"\n\"identity\" \"%s\"\n\"flags\" \"%s\"\n}}", name, steamid, flag);

Also, I'm not sure what steps you have taken to ensure that the line you are injecting is placed BEFORE the file's final closing '}' brace. Actually... it appears that you are trying to create your own section after the Admins{} section, called "Plugin". I am not sure that this will work. I am fairly certain that it will not, although I could be wrong.

GeehFox
10-08-2014, 06:30
Sorry for posting this in the wrong forum, but I have to say I can hardly tell due to this forum style. Besides the two misspelled words (except LENGTH, which was done on purpose to edit the maximum length, but I guess I'll use the normal length.), I didn't care to check the variable types. Thank you for your help.
Even though most of the issues have been fixed, some still remain.

xf117
10-09-2014, 03:12
If you want to work with default sourcemod config file, you probably want to get yourself situated with KeyValues (https://wiki.alliedmods.net/KeyValues_%28SourceMod_Scripting%29). Otherwise, you gonna end up in total unreadable mess of a config.

Powerlord
10-09-2014, 10:21
Honestly, if you find yourself needing to edit admins.cfg or admins_simple.ini programmatically, you may want to look at using one of the SQL Admins plugins that also ship with SourceMod.