AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get user's id? (https://forums.alliedmods.net/showthread.php?t=236694)

KneeGrow 03-09-2014 15:16

How to get user's id?
 
I gave pawn scripting my first shot but I'm struggling to understand about how to get a user's id from entering a command.
I was trying to write a code that will simply give you a shotgun by typing:
amx_giveshotgun <name> shotgun
Whenever I type in anything anywhere, it goes straight to printing to console
"you didn't type 'shotgun'"

The entire code is at the bottom.

Code:

public plugin_init(){
        register_plugin(PLUGIN,VERSION,AUTHOR);
        register_concmd("amx_giveshotgun","giveWeapon",ADMIN_KICK,"<target> <weaponid> enter 0-4");
}
public giveWeapon(id,key[]){

From what I know about defining methods, the parameters must be entered by the user. Which means, in this case, 'id' is just a variable. What I don't understand, or can't follow, is people somehow get the parameter id, to relate to the player initiating the command.

What do I do to set 'id' equal to the user's id so the method is returned to the right player?
I have looked at tutorials and other people's codes but none of them talk directly about getting a player's id

The code has no trouble compiling, but has trouble working.

Code:

#include <amxmodx>
#include <fun>
#include <amxmisc>

#define PLUGIN "giveWeapon"
#define VERSION "1.5"
#define AUTHOR "KneeGrow"

public plugin_init(){
        register_plugin(PLUGIN,VERSION,AUTHOR);
        register_concmd("amx_giveshotgun","giveWeapon",ADMIN_KICK,"<target> <weaponid> enter 0-4");
}
public giveWeapon(id,key[]){
        if(equali(key,"shotgun")){
                give_item(id,"weapon_shotgun");
                return PLUGIN_HANDLED;
        } else {
                console_print(id,"you didn't type 'shotgun'");
        }
        return PLUGIN_HANDLED;
       
}

and the way I've seen people deal with arrays has been hurting my brain since I'm used to reading java

YamiKaitou 03-09-2014 15:24

Re: How to get user's id?
 
You are doing it wrong.

public giveWeapon(id)

and then use read_argv to get the parameters

KneeGrow 03-09-2014 15:43

Re: How to get user's id?
 
how would i use read_argv?
make something like
new user[32];
read_argv(1,user,31);
??

YamiKaitou 03-09-2014 16:22

Re: How to get user's id?
 
Search, there are a few Introduction tutorials out there

imindfreak 03-09-2014 23:40

Re: How to get user's id?
 
PHP Code:

public giveWeapon(idlevelcid)
{
    
//Checks if the person calling function has access to this command
    
if(!cmd_access(id,level,cid,3))
        return 
PLUGIN_HANDLED;
    
//Initialize some new variables to hold data.
    
new target[32], weaponid[32];
    
//Store data from arguments into our new variables
    
read_argv(1target31 );
    
read_argv(2weaponid31 );
    
//Create a target for our command (the player)
    
new player cmd_targetidtarget);
    
//If !player, return the function immediately
    
if(!player
        return 
PLUGIN_HANDLED;
    
//New variables to hold Admin and Player's names (if you want to print or log activity).
    
new admin_name[32]; get_user_name(idadmin_namecharsmax(admin_name));
    new 
player_name[32]; get_user_name(playerplayer_namecharsmax(player_name));
    
    
//Rest of your function goes here.



Hope this helps, I think you can figure out the rest from here.


All times are GMT -4. The time now is 05:55.

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