AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array Wont hold Value.... (https://forums.alliedmods.net/showthread.php?t=17923)

Zenith77 09-11-2005 20:13

Array Wont hold Value....
 
1 Attachment(s)
Ok....Coin Mod again...

ok the variable coins[33] ( which is a float ).... never seems to change...

NOTE: ( the array is to hold the index e.g coins[id] )

like when you connect its supposed to give you 5 coins..but when i type /coinstat its says [COIN MOD] You have 0 coins.


And...on the functins coinmod_addcoins and coinmod_removecoins when i type this commands in...

e.g coin_addcoins Zenith 2 it will say something like

[COIN MOD] ADMIN Zenith gave 50 coins to Zenith

and i have no clue why it does that nor why the variable coins[33] wont change at all :/

XxAvalanchexX 09-11-2005 20:30

arg2 is a string. So, the line that adds coins should look like this:

coins[target] += floatstr(arg2)

And the line that displays coins should look like this:

server_print( " [COIN MOD] ADMIN %s Added %f coins to player %s!", name, floatstr(arg2), victim )

Also, I think you should move get_user_name(id, victim, 31) down after you get the target and get the target's name instead of id's name.

Also, there are a lot of points where you compare coins[id] to an integer. Instead of coins[id] >= 25 it should be coins[id] >= 25.0

Zenith77 09-11-2005 21:35

Thnx avalanche! I changed all that...


And i think i know my problem...


this....

Code:
coins[id] = 5.5

should be this...

Code:
coins[id] = float(5.5)

right?

Batman/Gorlag 09-12-2005 00:40

Code:
coins[id] = 5.5

That's just fine, as long as you include a decimal place, the number is considered a float, no need for the extra float keyword.

Zenith77 09-15-2005 19:19

1 Attachment(s)
it still doesnt work :/ ...

I type /coinstat

" [COIN MOD] You have 0.000000 coins! "

Not only that wont work but the console_print doesnt do anything either :/

ok this version is the most updated ( working ) version.

Xanimos 09-15-2005 20:24

Quote:

Code:
new arg1[32], arg2[32], name[32], victim[32], target         get_user_name(id, name, 31)             read_argv(1, arg1, 31)         read_argv(2, arg2, 31)         str_to_num(arg2)                 target = cmd_target(id, arg1, 2)         get_user_name(target, victim, 31)         coins[target] += floatstr(arg2[31])

When you use str_to_num you usually have num = str_to_num.
But you dont us it anyways.
with
"coins[target] += floatstr(arg2[31])" you are starting at the 31st character of the string to get the float which is why its always 0.0000

You have two choices to fix
1) new Add = str_to_num(arg2)
//...
coins[target] += Add

2) remove line str_to_num(arg2)
//...
coins[target] += floatstr(arg2)

[Edit]
Quote:

Code:
server_print( " [COIN MOD] ADMIN %s Added %f coins to player %s!", name, arg2, victim )

arg2 is still a string ;p also why it would print 0.0000

Zenith77 09-15-2005 20:32

Ok someof what your saying doesn ot make since if i remove the [32] it will give me array must be indexed error...so should i make it like

arg2[0] so it starts at zero?


but i think i am going to go with the string to num solution...

Xanimos 09-15-2005 20:34

When using floatstr(arg2) you dont need the [] it knows that its a string. and will start at the beginning and go to the end of and and convert to float.

Zenith77 09-15-2005 20:43

* turltes * got it to work :)

Freecode 09-15-2005 20:45

Code:
new coins = str_to_num(arg2)


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

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