AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   help with xp (https://forums.alliedmods.net/showthread.php?t=12569)

Belsebub 04-18-2005 10:39

help with xp
 
i made this plugin of the xp tutorial but it doesn't seem to change the class because when i kill if i have any class it prints the

client_print(0,print_chat,"* [DEBUG] %i dont get any xp because he has no class",attacker)

and the /changeanimal command dont works either


my code:
Code:
 #include <amxmodx>  #include <amxmisc>  #include <engine>  #include <cstrike>  #include <fun>  //----------------------------------------------------------------------------------------------  #define NONE           0  #define DOG             1  #define CAT           2  #define HORSE         3  #define COW           4  new PlayerClass[33]  new PlayerXP[33]  new PlayerLevel[33]  new const classes[5][] = {     "None",     "Dog",     "Cat",     "Horse",     "Cow"  }  new msgtext  new const levels[10] = {     100,     200,     400,     800,     1600,     3200,     6400,     12800,     25600,     51200  }  //----------------------------------------------------------------------------------------------  public plugin_init()  {     register_plugin("Animal Mod", "1.0", "XunTric")     register_cvar("XP_per_kill", "20")     register_event("DeathMsg", "DeathMsg", "a")     register_event("ResetHUD", "ResetHud", "b")     msgtext = get_user_msgid("StatusText")     register_menucmd(register_menuid("menu_ChooseAnimal"),1023,"DoChooseAnimal")     register_clcmd("say /changeanimal","ChooseAnimal")     register_clcmd("say_team /changeanimal", "ChooseAnimal")  }  //----------------------------------------------------------------------------------------------  public ChooseAnimal(id)  {       new menu[] = "Animal Mod: Choose Animal^n^n1. Dog^n2. Cat^n3. Horse^n4. Cow"     new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4           show_menu(id, keys, menu, -1, "menu_ChooseAnimal")     }  //--------------------------------------------------------------------------------------------  public DoChooseAnimal(id,key) {     if(key == 0) {             if(PlayerClass[id] == DOG) {                 client_print(id, print_chat, "[Animal Mod] You are already a Dog! Choose something else!")                 ChooseAnimal(id)                 return PLUGIN_CONTINUE             }             PlayerClass[id] = DOG             client_print(id, print_chat, "[Animal Mod] You are now a Dog!")         }     if(key == 1) {             if(PlayerClass[id] == CAT) {                 client_print(id, print_chat, "[Animal Mod] You are already a Cat! Choose something else!")                 ChooseAnimal(id)                 return PLUGIN_CONTINUE             }             PlayerClass[id] = CAT             client_print(id, print_chat, "[Animal Mod] You are now a Cat!")         }     if(key == 2) {             if(PlayerClass[id] == HORSE) {                 client_print(id, print_chat, "[Animal Mod] You are already a Horse! Choose something else!")                 ChooseAnimal(id)                 return PLUGIN_CONTINUE             }             PlayerClass[id] = HORSE             client_print(id, print_chat, "[Animal Mod] You are now a Horse!")         }     if(key == 3) {             if(PlayerClass[id] == COW) {                 client_print(id, print_chat, "[Animal Mod] You are already a Cow! Choose something else!")                 ChooseAnimal(id)                 return PLUGIN_CONTINUE             }             PlayerClass[id] = COW             client_print(id, print_chat, "[Animal Mod] You are now a Cow!")         }     ShowHUD(id)     return PLUGIN_HANDLED  }  //----------------------------------------------------------------------------------------------  public ResetHUD(id)  {     if(PlayerClass[id] == NONE) {         ChooseAnimal(id)         return PLUGIN_HANDLED     }     return PLUGIN_HANDLED }  //----------------------------------------------------------------------------------------------  public DeathMsg()  {     new attacker = read_data(1)     new victim = read_data(2)     client_print(0,print_chat,"* [DEBUG] %i killed %i",attacker,victim)     if(PlayerClass[attacker] == NONE) {         client_print(0,print_chat,"* [DEBUG] %i dont get any xp because he has no class",attacker)         return PLUGIN_CONTINUE     }     if(!is_user_connected(attacker) || attacker == victim) {         return PLUGIN_CONTINUE     }     PlayerXP[attacker] += get_cvar_num("XP_per_kill")     client_print(0,print_chat,"* [DEBUG] %i receives %i XP, now has %i",attacker, get_cvar_num("XP_per_kill"), PlayerXP[attacker])     if(PlayerXP[attacker] >= levels[PlayerLevel[attacker]]) {         ++PlayerLevel[attacker]         client_print(attacker, print_chat, "[Animal Mod] Congratulations! You are now level %i!", PlayerLevel[attacker])         ShowHUD(attacker)     }     ShowHUD(attacker)     return PLUGIN_CONTINUE  }  //----------------------------------------------------------------------------------------------  public ShowHUD(id)  {     new HUD[51]     format(HUD, 50, "[%s]Level: %i XP: %i ", classes[PlayerClass[id]], PlayerLevel[id], PlayerXP[id])     message_begin(MSG_ONE, msgtext, {0,0,0}, id)     write_byte(0)     write_string(HUD)     message_end()     return  }  //----------------------------------------------------------------------------------------------  public client_connect(id)  {     PlayerClass[id] = NONE     PlayerXP[id] = 0     PlayerLevel[id] = 0  }  //----------------------------------------------------------------------------------------------  public client_putinserver(id)  {     set_task(1.0, "ChooseAnimal", id)  }

XunTric 04-18-2005 13:45

Looks like you mixed my and PM's code.. :P

Ill look thru it, but one thing i saw now is that you open the choose animal menu on client_putinserver. You dont need this because on ResetHUD it checks if the user has no class. This event is called when client gets in server, when they spawn and when they die...

EDIT:

Ok i think i found the problem.
On your menu, the keys starts on 1.
They should start on 0,.

You can start on 1, but then you need a MENU_KEY_0 at the end of the key numbers... (As XxAvalanchexX said in tutorial thread)

So it should look like this:
Code:
    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3

or like this:
Code:
    new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_0;

Havnt tested the second choise yet, I use the the first one i said (the one that starts on 0) on my plugin, and it works fine.

Belsebub 04-18-2005 13:46

yea i mixed your codes :D

and i forgot that ResetHUD Dont seem to work either

XunTric 04-18-2005 13:52

Try what I said, and now ResetHUD should work too :P

EDIT:
Since you dont have a exit option in your menu, use the first menu keys I told ya (the one that starts on 0)...
Or you could always add a exit option and use the one XxAvalanchexX said.

Belsebub 04-18-2005 15:16

nope still doen't work :cry:

XunTric 04-18-2005 15:27

Half of it is PM's code.
There are many ways to make a XP plugin, I got my way, and PM got his way.

You havnt changed so much in the code, so you can copy and paste my full code in the tutorial and change the stuff you want...
If you want more help from me though...


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

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