AlliedModders

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

devilicioux 09-16-2013 14:57

Hook Saytext Help
 
It might look like a strange scripting help request
but what i am trying to do is divide the saytext by player character by character
Like we just hook test and print like

PHP Code:

format (strText191"%s"message

what i want is to print like | after each character of the message ..lol dont even have a clue how to do that.

2 things now.

1) Suppose i say hello
it should print in chat like |h|e|l|l|o|

2) Suppose i say "hey how are you"
it prints in chat like |hey |how |are |you

Anyone got ideas ?

Black Rose 09-16-2013 15:42

Re: Hook Saytext Help
 
There's no practical use for the code that would be needed to do these things.
Therefor you should ask what you really need.
(Use formatex instead of format)

Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 6", "", "");         new string[10] = "hello";     new string2[20];         for ( new i = 0 ; string[i] && i * 2 + 1 < charsmax(string2) ; i++ ) {         string2[i * 2] = '|';         string2[i * 2 + 1] = string[i];     }     string2[strlen(string2)] = '|';         server_print("string: %s^nstring2: %s", string, string2); }

Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 6", "", "");         new string[10] = "hello";     new string2[20];         for ( new i = 0, o = 0 ; string[i] && o + 1 < charsmax(string2) ; i++, o += 2 ) {         string2[o] = '|';         string2[o + 1] = string[i];     }     string2[strlen(string2)] = '|';         server_print("string: %s^nstring2: %s", string, string2); }

Code:

string: hello
string2: |h|e|l|l|o|

Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 6", "", "");         new string[20] = "hey how are you";     new string2[40] = "|";         for ( new i = 0, o = 1 ; string[i] && o + 1 < charsmax(string2) ; i++, o++ ) {         string2[o] = string[i];         if ( string[i] == ' ' )             string2[++o] = '|';     }         server_print("string: %s^nstring2: %s", string, string2); }

Code:

string: hey how are you
string2: |hey |how |are |you


Black Rose 09-17-2013 15:26

Re: Hook Saytext Help
 
"x03" is not a character constant. You are basically printing that as text.

How do you display the text?

Code:
            if(++o%2==0)             { string2[++o] = 4; }             else if(++o%3==0)             { string2[++o] = 3; }             else             { string2[++o] = 1; }
This will increment o for every check AND every string input. Even if the actual statement returns false it's already too late. You would therefor end up with the following:
"Test string"
->
"Test ^0^4string"
or
"Test ^0^0^3string"
or
"Test ^0^0^1string"

This will of course print "Test " since strings are null terminated meaning the function printing the message will stop reading the input once it hits ^0 (a.k.a. 0, null or EOS).

Only increment once.
Code:
            if(++o%2==0)             { string2[o] = 4; }             else if(o%3==0)             { string2[o] = 3; }             else             { string2[o] = 1; }

If you ever are in doubt when using strings, print them like an array to debug.
Code:
    new c, string[] = "whatever";     for ( new i = 0 ; i < sizeof string ; i++) {         c = string[i];         server_print("%d: %c(%d)", i, c == 0 || c == 10 || c == 13 ? ' ' : c, c);     }
This will tell you exactly where it went wrong so you know what to look for in the code.

devilicioux 09-17-2013 17:21

Re: Hook Saytext Help
 
Thanks man learning so much from your posts and explanations !! Finally .. :) Credits to you :) Plugin Working fine now.
HaiL Black Rose :mrgreen:


All times are GMT -4. The time now is 19:02.

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