AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't find the problem! :S (https://forums.alliedmods.net/showthread.php?t=12702)

BioHazardousWaste 04-22-2005 00:12

Can't find the problem! :S
 
Hey All

I've been working on this problem for a while now... Right now it's midnight, and I started around 21:00 (9:00PM). I can't figure it out, and i'm going to bed; but maybe someone can help me. The problem I think is something to do with vault. It ocuurs hen I load someones exp. The save debug messages look fine. But when I load it the debugs are bad. (e.x. "Exp data () loaded for user: (username)" "Current exp = 0" )

I cannot figure this out, because the code seems perfect to me. Here it is, there's a lot but i'll try only to post what's relevant.

Code:
//Admin Function To Give User Exp. public SetExp(id, lvl, cid) {     //authenticicate     if(!cmd_access(id,lvl,cid,2) )         return PLUGIN_CONTINUE         //read parameters from command     new strTargetID[2], strExp[8]     new TargetID, Exp         read_argv(1, strTargetID, 2)     read_argv(2, strExp, 8)         TargetID = str_to_num (strTargetID)     Exp = str_to_num (strExp)         //set and save player's exp     PlayerExp[TargetID] = Exp     SaveExp(TargetID)         //debug     client_print(id, print_console, "Set user's exp to %i", PlayerExp[TargetID])         CheckLevel(TargetID)         return PLUGIN_HANDLED } //Admin Procedure To Load Someone's Exp public GetExp(id,lvl,cid) {     //authenticicate     if(!cmd_access(id,lvl,cid,1) )         return PLUGIN_CONTINUE             //read parameters from command     new strTargetID[2]     new TargetID     read_argv(1, strTargetID, 2)     TargetID = str_to_num(strTargetID)         //get name     new TargetName[34]     get_user_name(TargetID, TargetName, 33)         //show exp     LoadExp(TargetID)     client_print(id, print_console, "%s (%i) currenty has %i exp!", TargetName, TargetID, PlayerExp[TargetID])         return PLUGIN_HANDLED } //Save Exp Procedure public SaveExp(id) {             //get user AuthID     new AuthID[34], key[99], data[99]     get_user_authid(id, AuthID, 33)         format(key, 98, "%s_exp", AuthID)     format(data, 98, "%s", PlayerExp[id])     set_vaultdata (key, data)         //Debug     client_print (0, print_console, "Exp data saved for user: %s", AuthID) } //Load Exp Procedure public LoadExp(id) {     //get user AuthID     new AuthID[34], value[9]     new key[99]         get_user_authid(id, AuthID, 33)         format(key, 98, "%s_exp", AuthID)         get_vaultdata(key, value, 8)     PlayerExp[id] = str_to_num(value)         //Debug     client_print (0, print_console, "Exp data (%s) loaded for user: %s", value, AuthID)     client_print (0, print_console, "Current exp = %i", PlayerExp[id]) }

I always get () as the data in the debug message, which sets exp to 0.
For interests sake, I can save and load the players alliance fine:

Code:
//Save Alliance public SaveAlliance(id) {     //get user AuthID     new AuthID[34]     new key[99], data[99]     get_user_authid(id, AuthID, 33)         format(key, 98, "%s_alliance", AuthID)     format(data, 98, "%i", PlayerAlliance[id])     set_vaultdata (key, data)         //Debug     client_print (0, print_console, "Alliance data (%s) saved for user: %s", data, AuthID)     } //Load Alliance public LoadAlliance(id) {     //get user AuthID     new AuthID[34], value[9]     new key[99]         get_user_authid(id, AuthID, 33)         format(key, 98, "%s_alliance", AuthID)         get_vaultdata(key, value, 8)     PlayerAlliance[id] = str_to_num(value)         //Debug     client_print (0, print_console, "Alliance data (%s) loaded for user: %s", value, AuthID) } //Menu to choose new alliance (shows old alliance too) public SetAlliance(id, key) {     //key will start at zero     if (key == 0)     {         PlayerAlliance[id] = 1         client_print(id, print_chat, "You will now train for the Zionists!")         SaveAlliance(id)           }     else if (key == 1)     {         PlayerAlliance[id] = 2         client_print(id, print_chat, "You will now train for the Machines!")         SaveAlliance(id)     } else if (key == 2)     {          PlayerAlliance[id] = 3         client_print(id, print_chat, "You will now train for the Exiles!")         SaveAlliance(id)     }     else if (key == 3)     {         return PLUGIN_HANDLED     }     SaveAlliance(id)     return PLUGIN_HANDLED }

The alliance code works fine, saves, loads and displays like it should. The experience code at the top does not. Can someone tell me why?

OFFTOPIC:
How does the set_hudmessage function work?

This code displays the message at the top left of the screen:
Code:
set_hudmessage(255, 255, 255, 2, 1, 0, 6.0, 25.0, 0.1, 0.2, 4)

While this code displays it at the bottom right
Code:
set_hudmessage(255, 255, 255, 2.0, 1.0, 1, 6.0, 25.0, 0.1, 0.2, 4)

The only difference I see is the latter one has decimals, and has the effect set to 1. That shouldn't make such a huge difference should it?

slurpycof 04-22-2005 02:34

in this
Code:
public SaveExp(id) {             //get user AuthID     new AuthID[34], key[99], data[99]     get_user_authid(id, AuthID, 33)         format(key, 98, "%s_exp", AuthID)     format(data, 98, "%s", PlayerExp[id])     set_vaultdata (key, data)         //Debug     client_print (0, print_console, "Exp data saved for user: %s", AuthID) }

you are formatting data to use a number as a string. You should do a num_to_str before you store it.
Code:
//Save Exp Procedure public SaveExp(id) {             //get user AuthID     new AuthID[34], key[99], data[99],tmp_PlayerExp[32]     get_user_authid(id, AuthID, 33)         num_to_str(PlayerExp[id],tmp_PlayerExp,31)     format(key, 98, "%s_exp", AuthID)     format(data, 98, "%s", tmp_PlayerExp)     set_vaultdata (key, data)         //Debug     client_print (0, print_console, "Exp data saved for user: %s", AuthID) }

BioHazardousWaste 04-22-2005 07:58

Thanx man :)

That worked, but now i'm confused as hell. Why don't I have to do that with Alliance as well? It works fine. Anyways, now I am getting array index out of bounds errors like you wouldn't believe. I'll work on it after school, but if anything pops into your head please post.

When I join the server (in console)
Quote:

Smooth Criminal | Tunes connected
Smooth Criminal | Tunes is joining the Terrorist force
Player #0 lost a level. They are now level #0
Exp data (0) loaded for user: STEAM_0:1:2037446
Current exp = 0
Alliance data (0) loaded for user: STEAM_0:1:2037446
Scoring will not start until both teams have players
] ma_Playeres
Unknown command: ma_Playeres
Type 'amx_langmenu' in the console to display a menu where you can choose your language
] ma_Players
The following 1337 players are online now:
#1 - Smooth Criminal | Tunes - STEAM
When I Join the Server (in server):
ok so as i type this post it works.. i'll scroll up and find it:

Quote:

L 04/22/2005 - 07:47:33: [AMXX] Run time error 4 (index out of bounds) on line 63 (file "ma_playerdata.inc").
line 63 = num_to_str(PlayerExp[id],tmp_PlayerExp,31)

hmmm :S the only array in there is PlayerExp[id] which goes from 0 to 32

XxAvalanchexX 04-22-2005 14:07

Code:
//read parameters from command new strTargetID[2], strExp[8] new TargetID, Exp       read_argv(1, strTargetID, 2) read_argv(2, strExp, 8)
Memory problems!

Remember to save the last character for the string terminator. Increase your strTargetID size to 3 and your strExp size to 9, but leave your read_argv's the same.

BioHazardousWaste 04-22-2005 16:21

ahh.. didn't know that, thanx. Also, i'm still wondering about how the coords work on set_hudmessage. I need top left, top center, and top right. It would be nice if someone could explain the system to me though.

v3x 04-22-2005 16:26

There's a plugin that will help you get the coords. :)


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

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