AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Resolved] read_argv and contain help plz! (https://forums.alliedmods.net/showthread.php?t=48194)

hlstriker 12-06-2006 21:51

[Resolved] read_argv and contain help plz!
 
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.");         }     } }

stupok 12-06-2006 22:07

Re: read_argv and contain help plz!
 
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) }

hlstriker 12-06-2006 22:20

Re: read_argv and contain help plz!
 
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"); }

stupok 12-06-2006 22:28

Re: read_argv and contain help plz!
 
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.

hlstriker 12-06-2006 22:47

Re: read_argv and contain help plz!
 
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; }

stupok 12-06-2006 23:04

Re: read_argv and contain help plz!
 
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, ...)

hlstriker 12-07-2006 00:15

Re: read_argv and contain help plz!
 
I've tryed everything I could think of the last few hours, and I can't seem to get it to work :(.

stupok 12-07-2006 00:44

Re: read_argv and contain help plz!
 
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 }

hlstriker 12-07-2006 09:52

Re: read_argv and contain help plz!
 
Thanks very much :) +karma

I didn't know it added quotes @_@


All times are GMT -4. The time now is 06:59.

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