AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Scripting problems (https://forums.alliedmods.net/showthread.php?t=11504)

Hawkie 03-21-2005 12:30

Scripting problems
 
Hello, I am currently working on a script that lets people PM other people by a command. You should be able to do that by just typing "/PM Target Message" on the chat screen, but it will output it as a normal chat message in the chat menu. But when I type "say /PM Player Message" in the console, it works perfectly. I just need it to work directly from the chat screen. please help.

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() { register_plugin("Private Messaging", "1.0", "Hawkie") register_clcmd("say /PM", "cmd_pm") } public cmd_pm(id) { new name[33] new targetname[33] new Text[300] new Player[33] read_argv(2, Player, 32) read_argv(3, Text, 299) remove_quotes(Player) new userid = get_user_index(Player) get_user_name(userid,targetname,32) get_user_name(id,name,32) if(equal(Player, "") || equal(Text, "")) {  client_print(id, print_chat, "Usage: /PM <Player> <Message>")  return PLUGIN_HANDLED } else if(!userid) {  client_print(id, print_chat, "Error: Player not found")  return PLUGIN_HANDLED } else { client_print(userid, print_chat, "(PM) %s: %s", name, Text) client_print(id, print_chat, "You sent: %s to %s", Text, targetname) } return PLUGIN_HANDLED }

v3x 03-21-2005 15:39

Re: Scripting problems
 
Quote:

Originally Posted by Hawkie
Hello, I am currently working on a script that lets people PM other people by a command. You should be able to do that by just typing "/PM Target Message" on the chat screen, but it will output it as a normal chat message in the chat menu. But when I type "say /PM Player Message" in the console, it works perfectly. I just need it to work directly from the chat screen.

What do you mean?

Hawkie 03-21-2005 15:51

Re: Scripting problems
 
Quote:

Originally Posted by v3x
Quote:

Originally Posted by Hawkie
Hello, I am currently working on a script that lets people PM other people by a command. You should be able to do that by just typing "/PM Target Message" on the chat screen, but it will output it as a normal chat message in the chat menu. But when I type "say /PM Player Message" in the console, it works perfectly. I just need it to work directly from the chat screen.

What do you mean?

I mean, when you want to chat, you press "y". (Unless you havent changed the key for chatting) It should work to type /PM Target Message THERE, but it won't perform that command and will just output in the chat menu like "/PM Hawkie Hi".

Twilight Suzuka 03-21-2005 16:05

First off, http://forums.alliedmods.net/showthread.php?t=5037. I already did this.

Second off, you cannot read the second arg of a say command. It only has one arguement. Everything is in quotes, so it only has ONE.

Third, use cmd_target.

Ok lemme try to salvage this...

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_clcmd("say","handle_say") } public handle_say(id){     new buffer[256], buffer1[33], buffer2[33],buffer3[33];     read_argv(1,buffer,255);     parse(buffer, buffer1, 32, buffer2, 32, buffer3, 32);     if(!equali(buffer1,"/pm",3)) return PLUGIN_CONTINUE;     new tid = cmd_target(id,buffer2)     if(!tid) return PLUGIN_CONTINUE;     new name[33], tname[33]     get_user_name(id,name,32)     get_user_name(tid,tname,32)     client_print(tid, print_chat, "(PM) %s: %s", name, buffer3)     client_print(id, print_chat, "You sent: %s to %s", buffer3, tname)     return PLUGIN_HANDLED }

Hawkie 03-21-2005 17:10

Quote:

Originally Posted by Twilight Suzuka
First off, http://forums.alliedmods.net/showthread.php?t=5037. I already did this.

Second off, you cannot read the second arg of a say command. It only has one arguement. Everything is in quotes, so it only has ONE.

Third, use cmd_target.

Ok lemme try to salvage this...

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_clcmd("say","handle_say") } public handle_say(id){     new buffer[256], buffer1[33], buffer2[33],buffer3[33];     read_argv(1,buffer,255);     parse(buffer, buffer1, 32, buffer2, 32, buffer3, 32);     if(!equali(buffer1,"/pm",3)) return PLUGIN_CONTINUE;     new tid = cmd_target(id,buffer2)     if(!tid) return PLUGIN_CONTINUE;     new name[33], tname[33]     get_user_name(id,name,32)     get_user_name(tid,tname,32)     client_print(tid, print_chat, "(PM) %s: %s", name, buffer3)     client_print(id, print_chat, "You sent: %s to %s", buffer3, tname)     return PLUGIN_HANDLED }

Nice, thank you very much. You know, I am totally n00b at scripting so don't think I am totally stupid or dumb. :)

EDIT: Ohh, the private messaging works now, but the message will only conatain the first word, so that means you can't include any spaces. Any solutions for this?

Twilight Suzuka 03-21-2005 18:11

Really? I guess you could try strbreak, and break it to do this. Watch:

Code:
#include <amxmodx> #include <amxmisc> public plugin_init() {     register_clcmd("say","handle_say") }     public handle_say(id){     new buffer[256], buffer1[50], buffer2[200]     read_argv(1,buffer,255);     if(!equali(buffer,"/pm",3)) return PLUGIN_CONTINUE;     replace(buffer,255,"/pm","")     trim(buffer)         strbreak(buffer, buffer1, 50, buffer2, 199);     new tid = cmd_target(id,buffer1)     if(!tid) return PLUGIN_CONTINUE;     new name[33], tname[33]     get_user_name(id,name,32)     get_user_name(tid,tname,32)     client_print(tid, print_chat, "(PM) %s: %s", name, buffer2)     client_print(id, print_chat, "You sent: %s to %s", buffer2, tname)     return PLUGIN_HANDLED }

Hawkie 03-22-2005 08:16

It works 100% now, thanks for wasting time helping a n00b (me) :P


All times are GMT -4. The time now is 14:03.

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