AlliedModders

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

ianglowz 12-28-2008 09:10

Menu help.
 
1 Attachment(s)
Can anyone edit this code so the menu will show after the player connect?

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <fun>
#define MAXCLASSES 5
new const CLASSES[MAXCLASSES][] = {
    
"None",
    
"Dog",
    
"Cat",
    
"Horse",
    
"Tiger"
}
new const 
LEVELS[6] = {
    
100
    
200
    
400
    
800,
    
1600,
    
3200
}
new 
PlayerXP[33],PlayerLevel[33],PlayerClass[33]
new 
XP_Kill,XP_Knife,XP_Hs,SaveXP,g_vault
public plugin_init()
{
    
register_plugin("XpMod""1.0""fxfighter")
 
    
register_event("DeathMsg""eDeath""a"
    
register_event("ResetHUD","on_spawn","be"
    
    
SaveXP register_cvar("SaveXP","1")
    
XP_Kill=register_cvar("XP_per_kill""20")
    
XP_Hs=register_cvar("XP_hs_bonus","20")
    
XP_Knife=register_cvar("XP_knife_bonus","20")
    
g_vault nvault_open("animod")
 
    
register_clcmd("say /class""ChangeClass")
    
register_clcmd("say_team /class""ChangeClass")
    
register_clcmd("say /xp""ShowHud")
    
register_clcmd("say_team /xp""ShowHud")
}
public 
eDeath(  ) 
{
    new 
attacker read_data)
    new 
headshot read_data)
    new 
clipammoweapon get_user_weapon(attacker,clip,ammo);
 
    
PlayerXP[attacker] += get_pcvar_num(XP_Kill)
 
    if(
headshot)
    
PlayerXP[attacker] += get_pcvar_num(XP_Hs)
 
    if(
weapon == CSW_KNIFE)
    
PlayerXP[attacker] += get_pcvar_num(XP_Knife)
 
 
    while(
PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]])
    {
    
client_print(attackerprint_chat"[XpMod] Congratulations! You are a level %i %s!",PlayerLevel[attacker],CLASSES[PlayerClass[attacker]])
    
PlayerLevel[attacker] += 1
    
}

    
ShowHud(attacker)
    
SaveData(attacker)
}

public 
ShowHud(id)
{
    
set_hudmessage(255000.750.0106.015.0)
    
show_hudmessage(id"Level: %i^nXP: %i^nClass: %s",PlayerLevel[id],PlayerXP[id],CLASSES[PlayerClass[id]])
}
public 
ChangeClass(id)
{
    new 
menu menu_create("Class Menu" "Class_Handle");
    
menu_additem(menu ,"Dog""1" 0);
    
menu_additem(menu ,"Cat""2" 0);
    
menu_additem(menu ,"Horse""3" 0);
    
menu_additem(menu ,"Tiger""4" 0);
 
    
menu_setprop(menu MPROP_EXIT MEXIT_ALL);
 
    
menu_display(id menu 0);
 
    return 
PLUGIN_CONTINUE;
}
public 
Class_Handle(id menu item
{
    if(
item == MENU_EXIT
    {
 
        
menu_destroy(menu);
 
    }
 
    new 
szCommand[6] , szName[64];
    new 
access callback;
 
    
menu_item_getinfo(menu item access szCommand szName 63 callback);
 
    new 
str_to_num(szCommand)
    if(
PlayerClass[id] != i)
    {
        
PlayerClass[id] = i
        client_print
(id,print_chat,"You are now a %s",CLASSES[i])
    }
    else
    {
        
client_print(id,print_chat,"You are alredy a %s",CLASSES[i])
    }
 
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE
}
public 
client_connect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
LoadData(id)
    }
}
public 
client_disconnect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
SaveData(id)
    }
    
PlayerXP[id] = 0
    PlayerLevel
[id] = 0
    PlayerClass
[id] = 0
}
public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
nvault_set(g_vault,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
 
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-Mod",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
nvault_get(g_vault,vaultkey,vaultdata,255)
 
    
replace_all(vaultdata255"#"" ")
 
    new 
playerxp[32], playerlevel[32]
 
    
parse(vaultdataplayerxp31playerlevel31)
 
    
PlayerXP[id] = str_to_num(playerxp)
    
PlayerLevel[id] = str_to_num(playerlevel)
 
    return 
PLUGIN_CONTINUE
}
public 
on_spawn(id)
{
    if (
PlayerLevel[id] <= 2
    {               
//
    
set_user_health(id135);  
    }
    
    if (
PlayerLevel[id] == 4
    {               
//
    
set_user_health(id185);  
    }
    
    if (
PlayerLevel[id] >= 6
    {               
//
    
set_user_health(id255);  
    }


Have present who helping me.:)

AntiBots 12-28-2008 09:17

Re: Menu help.
 
public client_putinserver(id)
set_task(5.0, "ChangeClass", id)

AntiBots 12-28-2008 09:22

Re: Menu help.
 
Cleint dont is in server in client_connect. They call then the player do the first connection to the server.

ianglowz 12-28-2008 09:22

Re: Menu help.
 
Can you edit my code?I don't know where to put that code.

SnoW 12-28-2008 09:23

Re: Menu help.
 
Hmmm, still... I don't know about that, that 5sec is pretty weak, you could use TeamInfo so you get the menu when you pick CT or T, also it would be better cause if you go spec you shouldn't be able to decide class.

Edit:
"Cleint dont is in server in client_connect. They call then the player do the first connection to the server. "
You didn't read my whole post, I said that's what you want, but you can't call it there. After that I gave the right way.

AntiBots 12-28-2008 09:24

Re: Menu help.
 
Quote:

Originally Posted by ianglowz (Post 734431)
Can you edit my code?I don't know where to put that code.

PHP Code:

public client_connect(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
 
        
LoadData(id)
    }
}
 
public 
client_putinserver(id)
{
    if(
get_pcvar_num(SaveXP) == 1)
    {
        
set_task(5.0"ChangeClass"id)
    }



ianglowz 12-28-2008 09:25

Re: Menu help.
 
SnoW,just put your code.I think your code more good.Because I want the menu out when client join the team.

@AntiBots
Thx for that code.

ianglowz 12-28-2008 09:26

Re: Menu help.
 
@AntiBots
Testing.

SnoW 12-28-2008 09:26

Re: Menu help.
 
That's still bad way, also you should do it always, the
Code:

if(get_pcvar_num(SaveXP) == 1)
shouldn't be there, classes can be used is the save xp on or not.

ianglowz 12-28-2008 09:28

Re: Menu help.
 
SnoW,I give you to edit my code.Hope it working.:)

@AntiBots.
Thx,but now no people entering my server because my server is lagging now.


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

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