Raised This Month: $51 Target: $400
 12% 

How to get user's id?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KneeGrow
Junior Member
Join Date: Mar 2014
Old 03-09-2014 , 15:16   How to get user's id?
Reply With Quote #1

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

Last edited by KneeGrow; 03-09-2014 at 15:21.
KneeGrow is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-09-2014 , 15:24   Re: How to get user's id?
Reply With Quote #2

You are doing it wrong.

public giveWeapon(id)

and then use read_argv to get the parameters
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 03-09-2014 at 15:25.
YamiKaitou is offline
KneeGrow
Junior Member
Join Date: Mar 2014
Old 03-09-2014 , 15:43   Re: How to get user's id?
Reply With Quote #3

how would i use read_argv?
make something like
new user[32];
read_argv(1,user,31);
??
KneeGrow is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 03-09-2014 , 16:22   Re: How to get user's id?
Reply With Quote #4

Search, there are a few Introduction tutorials out there
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 03-09-2014 , 23:40   Re: How to get user's id?
Reply With Quote #5

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.
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by imindfreak; 03-09-2014 at 23:40.
imindfreak is offline
Reply



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:35.


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