Raised This Month: $ Target: $400
 0% 

[Resolved] read_argv and contain help plz!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-06-2006 , 21:51   [Resolved] read_argv and contain help plz!
Reply With Quote #1

Hi, I am trying to have it so you type "/goto <playername>" and you will go to that players origin. I want it so you don't have to type their full name in though, just some of it. Right now when I type "/goto <their name>" nothing happens. When I just type "/goto", it takes me to 0,0,0 i'm guessing and it shouldn't do anything when I type just /goto.

Here is my code so far...
Code:
public gotoPlayer(id) {     new nameArg[32];     read_argv(1, nameArg, 31);         new players[32];     new num;     get_players(players, num, "a");     for(new i = 1; i <= num; i++) {         new name[32];         get_user_name(i, name, 31)         if(contain(name, nameArg)) {             new nameid;             new origin[3];             nameid = get_user_index(name);             get_user_origin(nameid, origin, 0);             set_user_origin(id, origin);             client_print(id, print_chat, "[CSM] You have gone to %s's position.", name);         } else {             client_print(id, print_chat, "[CSM] Nobody has the name you entered.");         }     } }

Last edited by hlstriker; 12-07-2006 at 09:53. Reason: Resolved
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-06-2006 , 22:07   Re: read_argv and contain help plz!
Reply With Quote #2

Code:
public gotoPlayer(id) {     new arg1[32], origin[3], name[32]         read_argv(1, arg1, 31)         new player = cmd_target(id, arg1)         if(!player) return PLUGIN_HANDLED         get_user_origin(player, origin, 0)     set_user_origin(id, origin)     get_user_name(player, name, 31)         client_print(id, print_chat, "[CSM] You have gone to %s's position", name) }
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-06-2006 , 22:20   Re: read_argv and contain help plz!
Reply With Quote #3

Hey, that doesn't seem to work. Maybe I am reading the wrong arg?

Here is my register_clcmd...
Code:
public plugin_init() {     register_clcmd("say /goto", "gotoPlayer"); }
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-06-2006 , 22:28   Re: read_argv and contain help plz!
Reply With Quote #4

You have to hook onto say with clcmd and then check 2 args. Arg1 should be "/goto" and if it is, check the second arg.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-06-2006 , 22:47   Re: read_argv and contain help plz!
Reply With Quote #5

Here is what I have and it still doesn't work

Code:
public gotoPlayer(id) {     new arg2[32], arg3[32], origin[3], name[32];     read_argv(2, arg2, 31);     read_argv(3, arg3, 31);         if(!(arg2 == "/goto")) {         return PLUGIN_HANDLED;     }         new player = cmd_target(id, arg3);         if(!player) {         client_print(id, print_chat, "[CSM] That player cannot be found.");         return PLUGIN_HANDLED;     }         get_user_origin(player, origin, 0);     set_user_origin(id, origin);     get_user_name(player, name, 31);         client_print(id, print_chat, "[CSM] You have gone to %s's position", name);         return PLUGIN_CONTINUE; }

Last edited by hlstriker; 12-06-2006 at 22:50.
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-06-2006 , 23:04   Re: read_argv and contain help plz!
Reply With Quote #6

Come to think of it, I am not 100% sure you can read two arguments after say like that, and since I'm not willing to test for it at the moment, here is a different method. See if you can change it to your liking.

Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say", "hook_say") } public hook_say(id) {     new arg1[37], origin[3], name[32]         read_args(arg1, 36)         if(!equal(arg1, "/goto", 5)) return PLUGIN_CONTINUE         new player = cmd_target(id, arg1[5])         if(!player) return PLUGIN_CONTINUE         get_user_origin(player, origin, 0)     set_user_origin(id, origin)     get_user_name(player, name, 31)         client_print(id, print_chat, "[CSM] You have gone to %s's position", name) }

EDIT: Try changing to:
read_argv(1, ...)
read_argv(2, ...)
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-07-2006 , 00:15   Re: read_argv and contain help plz!
Reply With Quote #7

I've tryed everything I could think of the last few hours, and I can't seem to get it to work .
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-07-2006 , 00:44   Re: read_argv and contain help plz!
Reply With Quote #8

Tested and works. There ya go:

Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say", "hook_say") } public hook_say(id) {     new arg1[37], origin[3], name[32]         read_args(arg1, 36) //register everything after "say" as a string     remove_quotes(arg1) //remove the quotes to make working with arg1 easier     //if /goto is not said, return plugin_continue to allow regular chatting     if(contain(arg1, "/goto") == -1) return PLUGIN_CONTINUE         new player = cmd_target(id, arg1[6])         if(!player)     {         client_print(id, print_chat, "[CSM] Client with this name not found.", name)         return PLUGIN_HANDLED     }         get_user_origin(player, origin, 0)     set_user_origin(id, origin)     get_user_name(player, name, 31)         client_print(id, print_chat, "[CSM] You have gone to %s's position", name)         return PLUGIN_CONTINUE }

Last edited by stupok; 12-07-2006 at 00:51.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-07-2006 , 09:52   Re: read_argv and contain help plz!
Reply With Quote #9

Thanks very much +karma

I didn't know it added quotes @_@
hlstriker 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 06:59.


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