AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problems with getting data/setting data (https://forums.alliedmods.net/showthread.php?t=22285)

slmclarengt 12-23-2005 00:47

Problems with getting data/setting data
 
Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> public plugin_init()     {     register_plugin("Easy Plugin Tester", ".9b", "slmclarengt(sleeper)")     register_concmd("amx_testplugin", "testPlugin", ADMIN_BAN, "Saves money, team & map to be reverted") } public testPlugin(id)     {     /*     new temp[128]     read_argv(1,temp,5)     new id=str_to_num(temp) // let's make 'id'     */         new map[64]     get_mapname(map, 63)         new directory[60]     get_configsdir(directory, 59)         new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - testPlugin': Phase 1: Variables - Passed")         for (new a = 1; a <= get_playersnum(); a++)         {         get_user_team(a, teams[a], 2)                 get_user_authid(a, authid[a], 31) // get authid         money[a] = cs_get_user_money(a) // save the money of index 'a' player         get_user_name(a, names[a], 32) // initialize names[a] to user's name         frags[a] = get_user_frags(a) // get frags         deaths[a] = get_user_deaths(a)// get deaths                 // format to %configdir%/info.txt - starts with: name, authid, money, team         format("%s/info.txt", 75, "%s %s %d %s %d %d", directory, names[a], authid[a], money[a], teams[a], frags[a], deaths[a])     }         console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")         client_print(0, print_chat, "Money/team/map have been saved - changing map and reverting back")     client_print(0, print_chat, "Map is changing back to %s in 15 seconds!", map)         set_task(15.0,"changemap()",0) // change map in 15 seconds     set_task(45.0, "revertBack(0)", 0) // call "revertBack" after 45 seconds!         return PLUGIN_CONTINUE } public changemap() {     new map[64]     get_mapname(map, 64)         server_cmd("changelevel %s", map) }     public revertBack(id)     {     new directory[60]     get_configsdir(directory, 59)         new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - revertBack': Phase 1: Variables - Passed")         for( new i = 1; i <= get_playersnum(); i++ )         {         get_user_team(i, teams[i], 2)         get_user_authid(i, authid[i], 31) // get authid         money[i] = cs_get_user_money(i) // save the money of index i player         frags[i] = get_user_frags(i)         deaths[i] = get_user_deaths(i)                 read_file("%s/info.txt", i, names[i], 32, names[i+1][i]) // read/save         read_file("%s/info.txt", i, authid[i], 31, authid[i]) // read/save         read_file("%s/info.txt", i, money[i], 31, money[i]) // read/save         read_file("%s/info.txt", i, teams[i], 2, teams[i]) // read/save         read_file("%s/info.txt", i, frags[i], 127, frags[i]) // read/save         read_file("%s/info.txt", i, deaths[i], 127, deaths[i]) // read/save                 while (is_user_connecting(i) == 1)             {             if (is_user_connected(i) == 1)                 {                 //set their info back                 cs_set_user_team(i, teams[i])                 cs_set_user_deaths(i, deaths[i])                 set_user_frags(i, frags[i])                 cs_set_user_money(i, money[i], 1)                                 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                 show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                         }         }             }     console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")     console_print(0, "All passed")         return PLUGIN_HANDLED } public plugin_end() {     if (task_exists())     {         remove_task()     }     return PLUGIN_HANDLED }

Maybe you can figure out what this plugin will do b/c I do not feel like explaining it as I am hesitant as to releasing it.

It will have no compilation errors/warnings but it gives me run-time errors especially with my arrays being filled by my for loop in my "testPlugin" function.

Here is one of the errors I have received:
Code:

L 12/22/2005 - 21:45:42: [AMXX] Displaying debug trace (plugin "tester.amxx")
L 12/22/2005 - 21:45:42: [AMXX] Run time error 4: index out of bounds (array "names[32]") (indexed "[2]")
L 12/22/2005 - 21:45:42: [AMXX]    [0] tester.sma::testPlugin (line 28)


Cheap_Suit 12-23-2005 00:52

Code:
names[33][32]
The first array is for the player's id, and the second is for the name string

slmclarengt 12-23-2005 01:37

I dont get how this will help. It crashed my server...

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> public plugin_init()     {     register_plugin("Easy Plugin Tester", ".9b", "slmclarengt(sleeper)")     register_concmd("amx_testplugin", "testPlugin", ADMIN_BAN, "Saves money, team & map to be reverted") } public testPlugin()     {     /*     new temp[128]     read_argv(1,temp,5)     new id=str_to_num(temp) // let's make 'id'     */         new map[64]     get_mapname(map, 64)         new directory[60]     get_configsdir(directory, 60)         new authid[32], money[32], teams[2], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - testPlugin': Phase 1: Variables - Passed")         for (new a = 1; a <= get_maxplayers(); a++)         {         get_user_team(a, teams[a], 2)                 get_user_authid(a, authid[a], 34) // get authid         money[a] = cs_get_user_money(a) // save the money of index 'a' player         get_user_name(a, names[a], 32) // initialize names[a] to user's name         frags[a] = get_user_frags(a) // get frags         deaths[a] = get_user_deaths(a)// get deaths                 // format to %configdir%/info.txt - starts with: name, authid, money, team         format("%s/info.txt", 75, "%s %s %d %s %d %d", directory, names[a], authid[a], money[a], teams[a], frags[a], deaths[a])     }         console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")         client_print(0, print_chat, "Money/team/map have been saved - changing map and reverting back")     client_print(0, print_chat, "Map is changing back to %s in 15 seconds!", map)         set_task(15.0,"server_cmd('changelevel %s', map)",0) // change map in 15 seconds     set_task(45.0, "revertBack", 0) // call "revertBack" after 45 seconds!         return PLUGIN_CONTINUE } public revertBack(id)     {           new map[64]     get_mapname(map, 64)         new directory[60]     get_configsdir(directory, 60)         new authid[32], money[32], teams[2], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - revertBack': Phase 1: Variables - Passed")         for( new i = 1; i <= get_maxplayers(); i++ )         {         get_user_team(i, teams[i], 2)         get_user_authid(i, authid[i], 34) // get authid         money[i] = cs_get_user_money(i) // save the money of index i player         frags[i] = get_user_frags(i)         deaths[i] = get_user_deaths(i)                 read_file("%s/info.txt", i, names[i], 32, names[i+1][i]) // read/save         read_file("%s/info.txt", i, authid[i], 32, authid[i]) // read/save         read_file("%s/info.txt", i, money[i], 32, money[i]) // read/save         read_file("%s/info.txt", i, teams[i], 2, teams[i]) // read/save         read_file("%s/info.txt", i, frags[i], 128, frags[i]) // read/save         read_file("%s/info.txt", i, deaths[i], 128, deaths[i]) // read/save                 if (is_user_connecting(i) == 1)             {             if (is_user_connected(i) == 1)                 {                 cs_set_user_team(i, teams[i])                 cs_set_user_deaths(i, deaths[i])                 set_user_frags(i, frags[i])                 cs_set_user_money(i, money[i], 1)                                 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                 show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                      }         }             }     console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")         return PLUGIN_HANDLED }

XxAvalanchexX 12-23-2005 02:59

VelocityByAim

slmclarengt 12-23-2005 13:11

Quote:

Originally Posted by XxAvalanchexX

I don't get how that helps me. Nowhere in my code do I reference needing to find at what velocity a player is looking...

slmclarengt 12-23-2005 13:47

This is a working version of the testPlugin function. However, I think I need help on the second part, the revertBack function. It seems as if it never gets called, even after my set_task for 45 seconds to call it.

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> public plugin_init()     {     register_plugin("Easy Plugin Tester", ".9b", "slmclarengt(sleeper)")     register_concmd("amx_testplugin", "testPlugin", ADMIN_BAN, "Saves money, team & map to be reverted") } public testPlugin()     {     /*     new temp[128]     read_argv(1,temp,5)     new id=str_to_num(temp) // let's make 'id'     */         new map[64]     get_mapname(map, 64)         new directory[60]     get_configsdir(directory, 60)         new authid[32], money[32], teams[2], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - testPlugin': Phase 1: Variables - Passed")         for (new a = 1; a <= get_playersnum(); a++)         {         get_user_team(a, teams[a], 2)                 get_user_authid(a, authid[a], 34) // get authid         money[a] = cs_get_user_money(a) // save the money of index 'a' player         get_user_name(a, names[a], 32) // initialize names[a] to user's name         frags[a] = get_user_frags(a) // get frags         deaths[a] = get_user_deaths(a)// get deaths                 // format to %configdir%/info.txt - starts with: name, authid, money, team         format("%s/info.txt", 75, "%s %s %d %s %d %d", directory, names[a], authid[a], money[a], teams[a], frags[a], deaths[a])     }         console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")         client_print(0, print_chat, "Money/team/map have been saved - changing map and reverting back")     client_print(0, print_chat, "Map is changing back to %s in 15 seconds!", map)         set_task(15.0,"changemap",0) // change map in 15 seconds     set_task(45.0, "revertBack", 0) // call "revertBack" after 45 seconds!         return PLUGIN_CONTINUE } public changemap() {     new map[64]     get_mapname(map, 64)         server_cmd("changelevel %s", map) }     public revertBack(id)     {     new directory[60]     get_configsdir(directory, 60)         new authid[32], money[32], teams[2], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - revertBack': Phase 1: Variables - Passed")         for( new i = 1; i <= get_playersnum(); i++ )         {         get_user_team(i, teams[i], 2)         get_user_authid(i, authid[i], 34) // get authid         money[i] = cs_get_user_money(i) // save the money of index i player         frags[i] = get_user_frags(i)         deaths[i] = get_user_deaths(i)                 read_file("%s/info.txt", i, names[i], 32, names[i+1][i]) // read/save         read_file("%s/info.txt", i, authid[i], 32, authid[i]) // read/save         read_file("%s/info.txt", i, money[i], 32, money[i]) // read/save         read_file("%s/info.txt", i, teams[i], 2, teams[i]) // read/save         read_file("%s/info.txt", i, frags[i], 128, frags[i]) // read/save         read_file("%s/info.txt", i, deaths[i], 128, deaths[i]) // read/save                 if (is_user_connecting(i) == 1)             {             if (is_user_connected(i) == 1)                 {                 cs_set_user_team(i, teams[i])                 cs_set_user_deaths(i, deaths[i])                 set_user_frags(i, frags[i])                 cs_set_user_money(i, money[i], 1)                                 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                 show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                      }         }             }     console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")     console_print(0, "All passed")         return PLUGIN_HANDLED } public plugin_end() {     if (task_exists())     {         remove_task()     }     return PLUGIN_HANDLED }

v3x 12-23-2005 15:14

Well, there's no ID being passed through the task hooked to revertBack so if it's not displaying the HUD message, that's why.


Also, you need to do length-1 in these functions:
Code:
new map[64] get_mapname(map, 64) new directory[60] get_configsdir(directory, 60) // etc.

So it'd be:
Code:
new map[64] get_mapname(map, 63) new directory[60] get_configsdir(directory, 59) // etc.

slmclarengt 12-23-2005 15:20

i knew that but I do not know why I did not instantiate it :roll: - thanks v3x
luckily i didn't keep getting indices out of bounds because i set the length to high. It could have given me buffer problems as well. I believe this code is nearly flawless:

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> public plugin_init()     {     register_plugin("Easy Plugin Tester", ".9b", "slmclarengt(sleeper)")     register_concmd("amx_testplugin", "testPlugin", ADMIN_BAN, "Saves money, team & map to be reverted") } public testPlugin(id)     {     /*     new temp[128]     read_argv(1,temp,5)     new id=str_to_num(temp) // let's make 'id'     */         new map[64]     get_mapname(map, 63)         new directory[60]     get_configsdir(directory, 59)         new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - testPlugin': Phase 1: Variables - Passed")         for (new a = 1; a <= get_playersnum(); a++)         {         get_user_team(a, teams[a], 2)                 get_user_authid(a, authid[a], 31) // get authid         money[a] = cs_get_user_money(a) // save the money of index 'a' player         get_user_name(a, names[a], 32) // initialize names[a] to user's name         frags[a] = get_user_frags(a) // get frags         deaths[a] = get_user_deaths(a)// get deaths                 // format to %configdir%/info.txt - starts with: name, authid, money, team         format("%s/info.txt", 75, "%s %s %d %s %d %d", directory, names[a], authid[a], money[a], teams[a], frags[a], deaths[a])     }         console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")         client_print(0, print_chat, "Money/team/map have been saved - changing map and reverting back")     client_print(0, print_chat, "Map is changing back to %s in 15 seconds!", map)         set_task(15.0,"changemap()",0) // change map in 15 seconds     set_task(45.0, "revertBack(0)", 0) // call "revertBack" after 45 seconds!         return PLUGIN_CONTINUE } public changemap() {     new map[64]     get_mapname(map, 64)         server_cmd("changelevel %s", map) }     public revertBack(id)     {     new directory[60]     get_configsdir(directory, 59)         new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - revertBack': Phase 1: Variables - Passed")         for( new i = 1; i <= get_playersnum(); i++ )         {         get_user_team(i, teams[i], 2)         get_user_authid(i, authid[i], 31) // get authid         money[i] = cs_get_user_money(i) // save the money of index i player         frags[i] = get_user_frags(i)         deaths[i] = get_user_deaths(i)                 read_file("%s/info.txt", i, names[i], 32, names[i+1][i]) // read/save         read_file("%s/info.txt", i, authid[i], 31, authid[i]) // read/save         read_file("%s/info.txt", i, money[i], 31, money[i]) // read/save         read_file("%s/info.txt", i, teams[i], 2, teams[i]) // read/save         read_file("%s/info.txt", i, frags[i], 127, frags[i]) // read/save         read_file("%s/info.txt", i, deaths[i], 127, deaths[i]) // read/save                 while (is_user_connecting(i) == 1)             {             if (is_user_connected(i) == 1)                 {                 //set their info back                 cs_set_user_team(i, teams[i])                 cs_set_user_deaths(i, deaths[i])                 set_user_frags(i, frags[i])                 cs_set_user_money(i, money[i], 1)                                 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                 show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                      }         }             }     console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")     console_print(0, "All passed")         return PLUGIN_HANDLED } public plugin_end() {     if (task_exists())     {         remove_task()     }     return PLUGIN_HANDLED }

slmclarengt 12-25-2005 16:10

1 Attachment(s)
the most recent revisions in the top post as well as in the attached SMA.

Alright, as for a description as to what this plugin is "trying" to do:

1. Saves money of the player
2. Saves team of the player
3. Saves Frags of the player
4. Saves Deaths of the player
5. Changes map to the exact same map (using the task)
6. Sets money back
7. Sets team back
8. Sets frags back
9. Sets deaths back

Steps 1-9 (except 5) use arrays in for loops in order to accomplish saving and reading data.

- and then that leaves all the players happy so that it seems as if they never left.

Basically, the whole point of the this plugin is to help us (coders) to save all the data/set all the data back and map back so that we can test our plugin without angering the players.

Please help me help all the coders.

slmclarengt 01-16-2006 14:37

1 Attachment(s)
Recent untested version:

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> #define TEAM_T 1 #define TEAM_CT 2 public plugin_init()     {     register_plugin("Easy Plugin Tester", ".9b", "slmclarengt(sleeper)")     register_concmd("amx_testplugin", "testPlugin", ADMIN_BAN, "Saves money, team & map to be reverted") } public testPlugin(id)     {       new map[64]     get_mapname(map, 63)         new directory[60]     get_configsdir(directory, 59)         new info[400]     new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - testPlugin': Phase 1: Variables - Passed")         for (new a = 1; a <= get_playersnum(); a++)         {         get_user_team(a, teams[a], 2) // get team         get_user_authid(a, authid[a], 31) // get authid         money[a] = cs_get_user_money(a) // save the money of index 'a' player         get_user_name(a, names[a], 32) // initialize names[a] to user's name         frags[a] = get_user_frags(a) // get frags         deaths[a] = get_user_deaths(a)// get deaths                 // format to message - starts with: name, authid, money, team         format(info, 399, "%s %s %d %s %d %d", names[a], authid[a], money[a], teams[a], frags[a], deaths[a])                 // write the data stored in array info into data.txt to be read later         write_file("%s/data.txt", info)     }     // debug prints     console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")     console_print(0, "%s is the config directory", directory)         set_task(15.0,"changemap()",0) // change map in 15 seconds!         client_print(0, print_chat, "Money/team/map have been saved - changing map and reverting back")     client_print(0, print_chat, "Map is changing back to %s in 15 seconds!", map)         set_task(45.0, "revertBack(id)", 0) // call "revertBack" in 45 seconds!         return PLUGIN_CONTINUE } public changemap()     {     new map[64]     get_mapname(map, 63)         server_cmd("changelevel %s", map) } public revertBack(id)     {     new directory[60]     get_configsdir(directory, 59)         new authid[32], money[32], teams[3], names[33][32], frags[128], deaths[128]         console_print(0, "DEBUG 'tester - revertBack': Phase 1: Variables - Passed")         for( new i = 1; i <= get_playersnum(); i++ )         {         // I don't know why I even put this stuff here         // forgot comments to explain why I need this...         // I do not think I need this         /*         get_user_team(i, teams[i], 2) // save teams         get_user_authid(i, authid[i], 31) // get authid         money[i] = cs_get_user_money(i) // save the money of index i player         frags[i] = get_user_frags(i) // save frags         deaths[i] = get_user_deaths(i) // save deaths         */                 read_file("%s/data.txt", i, names[i], 32, names[i+1][i]) // read/save         read_file("%s/data.txt", i, authid[i], 31, authid[i]) // read/save         read_file("%s/data.txt", i, money[i], 31, money[i]) // read/save         read_file("%s/data.txt", i, teams[i], 2, teams[i]) // read/save         read_file("%s/data.txt", i, frags[i], 127, frags[i]) // read/save         read_file("%s/data.txt", i, deaths[i], 127, deaths[i]) // read/save                 while (is_user_connected(i) == 1)             {             while (get_user_team(i) == TEAM_CT || get_user_team(i) == TEAM_T)                 {                 //set their info back                 cs_set_user_team(i, teams[i])                 cs_set_user_deaths(i, deaths[i])                 set_user_frags(i, frags[i])                 cs_set_user_money(i, money[i], 1)                                 set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                 show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                                   if (get_user_team(i) != teams[i])                     {                     set_cvar_num("sv_restart", 1)                     cs_set_user_team(i, teams[i])                     cs_set_user_deaths(i, deaths[i])                     set_user_frags(i, frags[i])                     cs_set_user_money(i, money[i], 1)                                         set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 12.0)                     show_hudmessage(id, "Your Money/Team/Frags/Death have been restored!")                   }             }         }     }     set_cvar_num("sv_restart", 5) // restart round to make sure changes take effect         console_print(0, "DEBUG 'tester - testPlugin': Phase 2: After for loop - Passed")     console_print(0, "All passed")         return PLUGIN_HANDLED } public plugin_end()     {     if (task_exists())         {         remove_task()     }     return PLUGIN_HANDLED }


All times are GMT -4. The time now is 16:10.

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