Raised This Month: $ Target: $400
 0% 

Equality with array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[WbOF]LuZiFeR
AlliedModders Donor
Join Date: Jun 2004
Old 04-17-2005 , 06:05   Equality with array
Reply With Quote #1

A little noob-question

I use

Code:
new CC[15] get_user_ip(id,userip,31,1) geoip_country(userip,CC)

to catch a players country...

Now, i will compare this with a variable (i.e. "United States" )

Code:
if (CC == "United States") { }

But this is not the correct syntax (CC is a array i think)...

Because the following error occured:

Quote:
033 array must be indexed (variable name)
An array as a whole cannot be used in a expression; you must indicate
an element of the array between square brackets.
How is the correct syntax ?

I've read the Help-Files, but i don't understand some things...

thx in advance...
[WbOF]LuZiFeR is offline
Send a message via AIM to [WbOF]LuZiFeR
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 06:08  
Reply With Quote #2

Code:
new CC[15] get_user_ip(id,userip,31,1) new country = geoip_country(userip,CC) if(country == "United States") {     // .. }
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
[WbOF]LuZiFeR
AlliedModders Donor
Join Date: Jun 2004
Old 04-17-2005 , 06:19  
Reply With Quote #3

Thx for the fast answer, but it results in the same error:

Quote:
country_welcome.sma(10 : error 033: array must be indexed (variable "-unknown-")
Code now looks like this:

Code:
        register_cvar("sv_message","1")         g_message = get_cvar_num("sv_message")         new userip[32]         new CC[15]         get_user_ip(id,userip,31,1)         new countrygeo = geoip_country(userip,CC)          if(g_message == 1 && countrygeo == "United States")         { ....         }
[WbOF]LuZiFeR is offline
Send a message via AIM to [WbOF]LuZiFeR
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 06:24  
Reply With Quote #4

Oh, wow.. It worked just a minute ago.. I'll try to figure this out.

Edit:

Code:
public myFunc(id) {     new target = read_data(2)     new g_message = get_cvar_num("sv_message")     new ip[32]     new country[45]     get_user_ip(target,ip,31)     geoip_country(ip,country)     if(equal(country,"United States") && g_message == 1){         //...     }     return PLUGIN_HANDLED }
[EDITED]
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
[WbOF]LuZiFeR
AlliedModders Donor
Join Date: Jun 2004
Old 04-17-2005 , 07:40  
Reply With Quote #5

What does this function is returning back ?

And where do i set i.e. "United States" ?

Code:
if(myfunc(id)) == "United States") { }

??
[WbOF]LuZiFeR is offline
Send a message via AIM to [WbOF]LuZiFeR
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 07:45  
Reply With Quote #6

Grr, damnit.. Remind me not to post when I'm about to hit the Zzz's. It's that damned == "United States" part that is giving you the error about the index.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-17-2005 , 08:38  
Reply With Quote #7

To compare strings, you have to use the equal native:

Code:
if (equal(CC, "United States"))
{
   // blabla!
}
A string is a null-terminated array of characters. equal goes through all the characters in CC, and compares them to the corresponding characters in the other argmuent.
__________________
hello, i am pm
PM is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 08:43  
Reply With Quote #8

Now why didn't I think of that in the first place?

WbO, take a look @ my updated code above.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
[WbOF]LuZiFeR
AlliedModders Donor
Join Date: Jun 2004
Old 04-17-2005 , 09:37  
Reply With Quote #9

Thx for your efforts

Now it works fine YEEEHAAA....!!!
[WbOF]LuZiFeR is offline
Send a message via AIM to [WbOF]LuZiFeR
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-17-2005 , 09:39  
Reply With Quote #10

Quote:
Originally Posted by [WbOF
LuZiFeR]Thx for your efforts

Now it works fine YEEEHAAA....!!!
Whoa there cowboy!
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x 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 09:51.


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