AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   1st plugin -> help (https://forums.alliedmods.net/showthread.php?t=210090)

lagayo 03-06-2013 07:38

1st plugin -> help
 
well, im learning c++ on school , almost 1 year of c++ programming, i ever wanted to make my own cs plugins, now that i know a programming language i think i can learn pawn, but i need some help to start, i already read lots of tutorials, and im trying to make my first plugin.

thats what i got so far:
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "give_he"
#define VERSION "1.0"
#define AUTHOR "Lagayo"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("amx_givehe","cmd_givehe"ADMIN_BAN,"<target>")
}


public 
cmd_givehe(id,level,cid)
{
    if (!
cmd_access(idlevelcid3))
        return 
PLUGIN_HANDLED


so got stuck on coding the comand(the hardest part and the one you need to learn some skills)
so im asking if anyone can finish this plugin, comenting EVERY line so i can understand it better ;)

Thank you

wangbochiang 03-06-2013 08:55

Re: 1st plugin -> help
 
you may search in forum,
I found a post just have likely question as you
https://forums.alliedmods.net/showthread.php?t=90236

try this see if it helps

jimaway 03-06-2013 08:58

Re: 1st plugin -> help
 
Code:
#include <amxmodx> #include <amxmisc> #include <fun> //fun module has the give_item native #define PLUGIN "give_he" #define VERSION "1.0" #define AUTHOR "Lagayo" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)           register_concmd("amx_givehe","cmd_givehe", ADMIN_BAN,"<target>") } public cmd_givehe(id,level,cid) {     if (!cmd_access(id, level, cid, 3))         return PLUGIN_HANDLED     new iPlayer, szTarget[16] //create an int for target id and array for target string     read_argv(1, szTarget, charsmax(szTarget)) //read first arg from command and store it in szTarget     iPlayer = cmd_target(id, szTarget, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS) //use cmd_target stock to get the target id     if (is_user_alive(iPlayer)) //this to check if cmd_target was successful and if the player is alive         give_item(iPlayer, "weapon_hegrenade") //give iPlayer a "weapon_hegrenade"     return PLUGIN_HANDLED //you should return this in the end of concmd so you wont get the invalid command error }

Alekkkk 03-06-2013 10:53

Re: 1st plugin -> help
 
lol guys , look at his code , he want to give grenade not to the person who use the command but to a target player..

you can look at this post https://forums.alliedmods.net/showpo...68&postcount=3

jimaway 03-06-2013 14:54

Re: 1st plugin -> help
 
yeah my bad lol
fixed now

guipatinador 03-06-2013 16:30

Re: 1st plugin -> help
 
PHP Code:

if (!cmd_access(idlevelcid3)) 

2 arguments instead of 3.

lagayo 03-06-2013 18:11

Re: 1st plugin -> help
 
Quote:

Originally Posted by jimaway (Post 1907638)
Code:
#include <amxmodx> #include <amxmisc> #include <fun> //fun module has the give_item native #define PLUGIN "give_he" #define VERSION "1.0" #define AUTHOR "Lagayo" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)           register_concmd("amx_givehe","cmd_givehe", ADMIN_BAN,"<target>") } public cmd_givehe(id,level,cid) {     if (!cmd_access(id, level, cid, 3))         return PLUGIN_HANDLED     new iPlayer, szTarget[16] //create an int for target id and array for target string     read_argv(1, szTarget, charsmax(szTarget)) //read first arg from command and store it in szTarget     iPlayer = cmd_target(id, szTarget, CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS) //use cmd_target stock to get the target id     if (is_user_alive(iPlayer)) //this to check if cmd_target was successful and if the player is alive         give_item(iPlayer, "weapon_hegrenade") //give iPlayer a "weapon_hegrenade"     return PLUGIN_HANDLED //you should return this in the end of concmd so you wont get the invalid command error }

it gives error on this line

PHP Code:

      give_item(iPlayer"weapon_hegrenade"//give iPlayer a "weapon_hegrenade" 

EDIT: Nvm i forgot to include <fun>.

But i got 2 warnings, any1 know why?

ConnorMcLeod 03-06-2013 18:39

Re: 1st plugin -> help
 
PHP Code:

#include <amxmodx>

#include <amxmisc> // stocks

// modules
#include <hamsandwich> // ExecuteHamB
#include <fun> // give_item

#define PLUGIN ""
#define VERSION "0.0.1"

public plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" )

    
register_concmd("amx_give_he""ConCmd_GiveHe"ADMIN_BAN"<#userid/partial_name/steamid>")
}

public 
ConCmd_GiveHeid lvlcmd )
{
    if( 
cmd_access(idlvlcmd/* 2 args required */ ) )
    {
        new 
szTarget[32], iTarget // <- name can be 32 letters
        
read_argv(1szTargetcharsmax(szTarget))

        
// #define CMDTARGET_OBEY_IMMUNITY (1<<0)
        // #define CMDTARGET_ALLOW_SELF    (1<<1)
        // #define CMDTARGET_ONLY_ALIVE    (1<<2)
        // #define CMDTARGET_NO_BOTS        (1<<3)
        // those defines inside amxmisc.inc
        
iTarget cmd_target(idszTargetCMDTARGET_ALLOW_SELF CMDTARGET_ONLY_ALIVE// allow self (compares to 'id) and restrict to alive players...

        
if( iTarget // bolean check
        
{
            
// then your specific code
            
if( !user_has_weapon(iTargetCSW_HEGRENADE) )
            {
                
give_item(iTarget"weapon_hegrenade")
            }
            else
            {
                
ExecuteHamB(Ham_GiveAmmoiTarget1"HEGrenade"999)
            }
        }
    }
    return 
PLUGIN_HANDLED // so engine doesn't send the command to dll and you don't get "Unknown command" in your console.


About differences between pawn and C++, you can read pawn tutorial : http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
On page : Pitfalls: differences from C.... ..... ..... ..... .... ..... ..... ...133
This tutorial is pawn generic, not amxx but you can still get some usefull information in it.

Here you can get usefull tutorials : https://forums.alliedmods.net/showthread.php?t=172936

See the part about optimizing plugins : http://wiki.amxmodx.org/Optimizing_P...X_Scripting%29
( pawn compiler is different from C )

Good luck.

jimaway 03-07-2013 09:26

Re: 1st plugin -> help
 
ConnorMcLeod you made the same mistake that i did originally, giving the grenade to id instead of iTarget

ConnorMcLeod 03-07-2013 12:26

Re: 1st plugin -> help
 
I don't know what you mean.


All times are GMT -4. The time now is 21:47.

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