Raised This Month: $ Target: $400
 0% 

Array Wont hold Value....


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-11-2005 , 20:13   Array Wont hold Value....
Reply With Quote #1

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 :/
Attached Files
File Type: sma Get Plugin or Get Source (coinmod.sma - 530 views - 28.6 KB)
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 09-11-2005 , 20:30  
Reply With Quote #2

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
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-11-2005 , 21:35  
Reply With Quote #3

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?
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Batman/Gorlag
Senior Member
Join Date: Aug 2005
Old 09-12-2005 , 00:40  
Reply With Quote #4

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.
__________________
GRR If only the amxmod programming were in Java.....
Java and C used to be two different languages, now Java is turning into another C. My logevent plugin
Batman/Gorlag is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-15-2005 , 19:19  
Reply With Quote #5

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.
Attached Files
File Type: sma Get Plugin or Get Source (coinmod.sma - 564 views - 32.4 KB)
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 09-15-2005 , 20:24  
Reply With Quote #6

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
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-15-2005 , 20:32  
Reply With Quote #7

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...
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 09-15-2005 , 20:34  
Reply With Quote #8

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.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-15-2005 , 20:43  
Reply With Quote #9

* turltes * got it to work
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 09-15-2005 , 20:45  
Reply With Quote #10

Code:
new coins = str_to_num(arg2)
Freecode 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 14:34.


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