Raised This Month: $76 Target: $400

Need Help my first plugin

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Junior Member
Join Date: Feb 2018
Old 02-19-2018 , 06:43   Need Help my first plugin
Reply With Quote #1

Hi Guys am new in scripting i tried to create a plugin to Set custom score to any user in the game, and my plugin show a Bad Load in the game but its been compiled perfectly .

Here is my code :

PHP Code:
/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <fun>
#include <cstrike>
#include <dodx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0"
#define AUTHOR  "Author"

public plugin_init()
// Add your code here...

//if (!cmd_access(index, user_frags, user_deaths, 2))
    //    return PLUGIN_HANDLED 
    //new user_name = get_user_name(user_index)
//console_print("[AMXX] %s Has score changed !", user_name)

4nTi is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 02-19-2018 , 16:37   Re: Need Help my first plugin
Reply With Quote #2

I see you are using both dodx and cstrike.
dod : Day Of Defeat
cstrike: Counter-Strike

Unfortunately it's not this easy to get the arguments supplied with the command. You have to account for everything the user can do wrong with the command.
I finished your plugin and added some commentary to help you understand what's going on.
If you have more questions don't hesitate to ask.
Also, this section is for Modules C#/C++. What you have is a Plugin written in PAWN.
So if your question is regarding plugin scripting, put it here:

#include <amxmodx> // core functionality, required. #include <amxmisc> // cmd_access(), show_activity(). #include <fun> // set_user_frags() #include <cstrike> // cs_set_user_deaths() #define PLUGIN  "New Plug-In" #define VERSION "1.0" #define AUTHOR  "Author" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("amx_setscore", "cmdSetScore", ADMIN_BAN) } public cmdSetScore(id, level, cid){     if (!cmd_access(id, level, cid, 2)) // This will check if you have access to this command and if there are 2 or more arguments required to run the function.         return PLUGIN_HANDLED     // Now we have to read the argument supplied with the command.     // First we need a variable to store the argument in string-form.     // Player name 31 chars and you need one extra cell for the null-termination.     new temparg[32];     // Then we have to actually read the argument.     read_argv(1, temparg, charsmax(temparg)); // In this case we read the first argument which will contain our target player. /* Flags: *  1 - obey immunity *  2 - allow yourself *  4 - must be alive *  8 - can't be bot #define CMDTARGET_OBEY_IMMUNITY (1<<0) #define CMDTARGET_ALLOW_SELF    (1<<1) #define CMDTARGET_ONLY_ALIVE    (1<<2) #define CMDTARGET_NO_BOTS      (1<<3) */     // This function will try to work out the target you're after by matching what you wrote with details from the players (name & userid).     new target = cmd_target(id, temparg, CMDTARGET_OBEY_IMMUNITY|CMDTARGET_ALLOW_SELF)     if ( ! target ) { // You might have multiple matches or no matches at all, you have to account for that.         client_print(id, print_console, "Multiple or no target."); // Perhaps a small error message so the command user understands why the command didn't work.         return PLUGIN_HANDLED     }     // If the code reaches here we have a target, we can continue.     // We are now done with the target so we can reuse the temparg[] variable for something new.     read_argv(2, temparg, charsmax(temparg)); // Like reading the frags number.     // You can then use str_to_num() to convert the number in string format to an integer which the function will accept.     set_user_frags(target, str_to_num(temparg));     if ( read_argc() > 2 ) { // check if there are more than 2 arguments, since you did allow only 2 arguments earlier.         read_argv(3, temparg, charsmax(temparg)); // And lastly get the argument for the deaths.         cs_set_user_deaths(target, str_to_num(temparg)) // ... and set them using an integer.     }     new id_name[32], target_name[32];     get_user_name(id, id_name, charsmax(id_name)) // Get the name of id (the person using the command)     get_user_name(target, target_name, charsmax(target_name)) // Get the name of the target of the command.     // There's even a function that will print out the activity based on your cvar setting.     show_activity(id, id_name, "changed the score of %s.", target_name); /* // Show admins activity // 0 - disabled // 1 - show without admin name // 2 - show with name amx_show_activity 0 */          return PLUGIN_HANDLED }

Last edited by Black Rose; 02-19-2018 at 16:50.
Black Rose is offline
Send a message via Skype™ to Black Rose

Thread Tools
Display Modes

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 20:38.

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