AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_info: Reading number command of the client, if "this" do "that" [...] (https://forums.alliedmods.net/showthread.php?t=82955)

SpeedHacker. 01-01-2009 19:30

get_user_info: Reading number command of the client, if "this" do "that" [...]
 
Hello,

I wanted a .sma plugin to read the color of the crosshair of a player (cl_crosshair_color), if "189 342 874" make the player
say "ExecScreen On" and if any other color rename the player to [ES-Off]"old name of the player":


PHP Code:

get_user_info(id"cl_crosshair_color",cl_crosshair_color31
if(
cl_crosshair_color == "152 132 854"){
client_print(id,print_chat,"[ ExecScreen On ]")
}
else{
client_cmd("name ^"[ES-Off]%s^"",name)
client_print(id,print_chat,"ExecScreen Off!")
client_print(id,print_console,"ExecScreen Off!")
client_print(id,print_notify,"ExecScreen Off!")
client_print(id,print_center,"ExecScreen Off!")


I tried but did not quite right :/

Bad_Bud 01-01-2009 19:39

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
You cannot check to see if two strings are equal to each other by using two equal signs, you must use something like...

PHP Code:

new ex_crosshair_color[32]
get_user_info(id"cl_crosshair_color",ex_crosshair_color31)
 
if(
equal(ex_crosshair_color,"189 342 874"))
     
client_print(id,print_chat,"[ ExecScreen On ]")
else
{
     new 
PlayerName[44]
     
get_user_name(id,PlayerName,43)
     
client_cmd("name ^"[ES-Off]%s^"",PlayerName)
     
client_print(id,print_chat,"ExecScreen Off!")



danielkza 01-01-2009 19:45

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
I believe you need to use query_client_cvar for that.

Bad_Bud 01-01-2009 19:48

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
What he said.

Also, it's not a bad idea to print out the string to make sure it was what you wanted.

SpeedHacker. 01-01-2009 21:22

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
Thank you!
It worked, but with each passing round the player to change nick, is [ES-Off] [ES-Off] "old name", [ES-Off] [ES-Off] [ES -
Off] "old name", ...
Is not making the name change only once?

PHP Code:

new ex_crosshair_color[32]
get_user_info(id"cl_crosshair_color",ex_crosshair_color31)
if(
equal(ex_crosshair_color,"152 132 854"))
     
client_print(id,print_chat,"[ ExecScreen On ]")
     new 
TAG[4]
     
get_user_name(id,TAG,4)
else if(
TAG<>[ES-Off])
{
     new 
PlayerName[44]
     
get_user_name(id,PlayerName,43)
     
client_cmd(id,"name ^"[ES-Off]%s^"",PlayerName)



Bad_Bud 01-01-2009 22:44

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
You'd have to remove it before you change their name.

I don't have access to AMXX right now, but look in AMXX help under core, and you should find some "replace" function where you pass a string through, and then something to look for in the string and what to replace it with.
An example would be:

Code:

replace(PlayerName,"[ES-Off]","")

SpeedHacker. 01-01-2009 23:16

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
But how would this in code:
PHP Code:

public ResetHud(id){  
new 
ex_crosshair_color[32]
get_user_info(id"cl_crosshair_color",ex_crosshair_color31)
 
if(
equal(ex_crosshair_color,"152 132 854"))
     
client_print(id,print_chat,"[ ExecScreen On ]")
else
{
     new 
PlayerName[44]
     
get_user_name(id,PlayerName,43)
      
client_cmd(id,"name ^"[ES-Off]%s^"",PlayerName)
}
    return 
PLUGIN_HANDLED 


Where is the replace it?
I don't know AMXX much, I know programming in C/C++ only :/

Bad_Bud 01-02-2009 06:42

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
I have items with specific models, and I store the model.mdl filename. I was pulling out the model from an entity, so it was returning a full path, such as "models/items/itemmodel.mdl". Since I only stored the last part, I had to cut out the first part. I ended up using replace, because I'm lazy, but I'll probably feel guilty and change it to string slicing later.

PHP Code:

replace(ItemsModels[0],48,"models/items/","")//Replaces "models/items" with "".
//Original string is ItemsModels[0], and the result overwrites whatever is in
//ItemsModels[0], making it contain "itemmodel.mdl" 

Another way to do this: http://forums.alliedmods.net/showthread.php?t=61367

You'll probably want to go with the replace option, because I think string slicing alters the flow of your plugin, kind of like a threaded query in sqlx.

You might be able to solve some future problems a lot quicker by consulting the function reference (the book on the bottom) and then expanding core at http://www.amxmodx.org/doc/

That's where you'll find explanations on replace, etc.

danielkza 01-02-2009 17:18

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
Quote:

Originally Posted by Bad_Bud (Post 736971)
You'll probably want to go with the replace option, because I think string slicing alters the flow of your plugin, kind of like a threaded query in sqlx.

What the hell are you smoking? String slicing does not do ANYTHING like that. Imagine how an array is stored:

|0|1|2|3|4|5|

String slicing just passes the array like it starts somewhere later
|3|4|5|

How could this alter the flow of anything?

Bad_Bud 01-02-2009 18:31

Re: get_user_info: Reading number command of the client, if "this" do "that" [...]
 
He's a beginner with AMXX.

PHP Code:

new str_to_cut[] = "Cut us here| Woah important info"
 
stock testfunc(str[])
{
     new 
containi(str,"|")
     
parse_me(str[i])
}
 
stock parse_me(str[])
{
     
// Do stuff on string AFTER pipe


To split the string, you have to finish your flow of code after it's split (in the parse_me function).

Someone just learning AMXX would probably want to keep everything flowing in the same function they started in, because it's easier to follow.

Also, if he was running a loop and wanted to compare two split strings with each other, he couldn't... not that he's wanting to, but he may run into a similar problem later.


All times are GMT -4. The time now is 09:18.

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