Raised This Month: $ Target: $400
 0% 

[help] Cod help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
natkemon
Member
Join Date: Dec 2008
Old 03-12-2011 , 01:09   [help] Cod help
Reply With Quote #1

I'm working on COD. I having trouble withe the xp saving and loading and the showhud function. the xp doesn't save so therefore it wont load. And i've tried to make the showhud stay visible permanently but it dissapears randomnly sometimes. I get this in the console :

Quote:
L 03/12/2011 - 14:02:41: Function is not present (function "showhud") (plugin "cod4.amxx")
L 03/12/2011 - 14:02:41: [AMXX] Run time error 10 (plugin "cod4.amxx") (native "set_task") - debug not enabled!
L 03/12/2011 - 14:02:41: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quote)
Sorry the script is very messy. can you please help me do this?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <nvault>

#define PLUGIN "COD4"
#define VERSION "2.4"
#define AUTHOR "FreeStylez`"

new const RANK[55] = 
{
    
0,
    
300
    
1200
    
2700
    
4800
    
7500
    
10800,
    
14700,
    
19200,
    
24300,
    
30000,
    
36500,
    
43800,
    
51900,
    
60800,
    
70500,
    
81000,
    
92300
    
104400,
    
117300,
    
131000,
    
145500,
    
160800,
    
176900,
    
193800,
    
211500,
    
230000,
    
249300,
    
269400,
    
290300,
    
312400,
    
335700,
    
360200,
    
385900,
    
412800,
    
440900,
    
470200,
    
500700,
    
532400,
    
565300,
    
599400,
    
634700,
    
671200,
    
708900,
    
747800,
    
829200,
    
871700,
    
915400,
    
960300,
    
1006400,
    
1053700,
    
1102200,
    
1151900,
    
1202800
}
new const 
RANKNAMES[55][] =
{
    
"Private First Class",
    
"Private First Class I",
    
"Private First Class II"
    
"Lance Corporal"
    
"Lance Corporal I",
    
"Lance Corporal II"
    
"Corporal"
    
"Corporal I",
    
"Corporal II"
    
"Sargeant",
    
"Sargeant I"
    
"Sargeant II"
    
"Staff Sargeant"
    
"Staff Sargeant I"
    
"Straff Sargeant II",
    
"Gunnery Sargeant"
    
"Gunnery Sargeant I"
    
"Gunnery Sargeant II"
    
"Master Sargeant",
    
"Master Sargeant I",
    
"Master Sargeant II",
    
"Master Gunnery Sergeant"
    
"Master Gunnery Sergeant I"
    
"Master Gunnery Sergeant II",
    
"2nd Lieutenant",
    
"2nd Lieutenant I",
    
"2nd Lieutenant II"
    
"1st Lieutenant"
    
"1st Lieutenant I"
    
"1st Lieutenant II"
    
"Captain",
    
"Captain I"
    
"Captain II"
    
"Major"
    
"Major I"
    
"Major II",
    
"Lt. Colonel",
    
"Lt. Colonel I",
    
"Lt. Colonel II",
    
"Colonel",
    
"Colonel I"
    
"Colonel II"
    
"Brigadier General",
    
"Brigadier General I",
    
"Brigadier General II"
    
"Major General",
    
"Major General I"
    
"Major General II",
    
"Lieutenant General",
    
"Lieutenant General I",
    
"Lieutenant General II"
    
"General",
    
"General I"
    
"General II"
    
"Commander"
}

new 
gXP[33], gLevel[33];
new 
XP_KillXP_Hs;
new 
g_vault;
new 
g_status_sync;

 public 
plugin_init()
 {
        
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("cod4_version"VERSIONFCVAR_SERVER);
    
set_cvar_string("cod4version"VERSION);
    
    
register_event("DeathMsg""eDeath""a");
    
register_event("RoundTime""on_round""b")
 
    
XP_Kill register_cvar("cod_kill""100");
    
XP_Hs register_cvar("cod_hs","200");
    
g_vault nvault_open("CODRANK");
    
    
    
register_clcmd"say /class""ClassMenu" );
 }
 
 public 
eDeath() 
{
    new 
attacker read_data(1);
    new 
victim read_data(2);
    new 
headshot read_data(3);
    new 
gPrintMSG[100];
    new 
gXPKill get_pcvar_num(XP_Kill);
    new 
gXPHs get_pcvar_num(XP_Hs);
 
    if( 
victim == attacker )
    return 
PLUGIN_HANDLED;
 
    if( !
headshot && victim != attacker )
    {
        
gXP[attacker] += gXPKill
        formatex
(gPrintMSGcharsmax(gPrintMSG), "You gained %d XP!"gXPKill);
    }
    else if( 
headshot && victim != attacker )
    {
        
gXP[attacker] += (gXPKill gXPHs);
        
formatex(gPrintMSGcharsmax(gPrintMSG), "You gained %d XP!^x01 (Headshot)", (gXPHs gXPKill));
    }
    
    Print(
attackergPrintMSG);
 
 
    
CheckLevel(attacker)
    
SaveData(attacker)
    
ShowHud(attacker)
    return 
PLUGIN_CONTINUE
}

public 
CheckLevel(id)
{
    if( 
gXP[id] >= RANK[gLevel[id]] )
    {
    Print(
id"[COD:MW2] Congratulations! You have been promoted to:^x01 %s^x03!"RANKNAMES[gLevel[id]]);
    
gLevel[id]++;
    }
}


public 
on_round(id)
{
    
LoadData(id)
    
CheckLevel(id)
    
ShowHud(id)
}

public 
ShowHud(id)
{


    if(
is_user_connected(id) && id>&& !is_user_bot(id))
    {

        new 
message[56]
        new 
next_level gLevel[id]+1
        
if(next_level>49)
            
next_level 49
        format
(message55,"[COD:MW2] Title: %s | Kills: %d/%d "RANKNAMES[gLevel[id]], gXP[id], RANK[gLevel[id]])
        
        
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("StatusText"), {000}, id);
        
write_byte(0);
        
write_string(message);
        
message_end();
        }
    
set_task(0.3"showhud"id)
}

public 
client_connect(id)
{
    
LoadData(id);
}

public 
client_disconnect(id)
{
    
SaveData(id);
    
gXP[id] = 0;
    
gLevel[id] = 0;
}



public 
SaveData(id
{
    new 
authid[32];
    
get_user_authid(idauthid31);
    
    new 
key[64], data[101];
    
    
format(key63"CODRANK-%s"authid);
    
format(data100"%i , %i"gXP[id],gLevel[id]);
    
    
nvault_set(nvault_open("CODRANK"), keydata);
}

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#",gXP[id],gLevel[id]);
    
nvault_get(g_vault,vaultkey,vaultdata,255);
 
    
replace_all(vaultdata255"#"" ");
 
    new 
gXP[32], gLevel[32];
 
    
parse(vaultdatagXP31gLevel31);
 
    
gXP[id] = str_to_num(gXP);
    
gLevel[id] = str_to_num(gLevel);
 
    return 
PLUGIN_CONTINUE;
}

public 
Load(id) {
    new 
authid[32];
    
get_user_authid(idauthid31);
    
    new 
key[64], data[101];
    
    new 
gexperience[8]
    
    
format(key63"CODRANK-%s"authid);
    
format(data100"%i , %i"gXP[id], gLevel[id]);
    
nvault_get(nvault_open("CODRANK"), keydata81);
    
    
replace_all(data100"#"" ");
    
    
parse(datagexperience7);
    
    
gXP[id] = str_to_num(gexperience);
}


 
 public 
ClassMenu(id)
 {
    new 
menu menu_create("\yChoose a class:""menu_handler")

    
menu_additem(menu"\w Grenadier [Assault]""1"0);
    
menu_additem(menu"\w First Recon [Sub Machine]""2"0);
    
menu_additem(menu"\w Overwatch [Light Machine Gun]""3"0);
    
menu_additem(menu"\w Scout Sniper""4"0);
    
menu_additem(menu"\w Riot Squad ""5"0);
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
 }
 
 public 
menu_handler(idmenuitem)
 {
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
1//grenadier
        
{
    
give_item(id"weapon_knife");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_aug");
    
give_item(id"ammo_556nato");
    
give_item(id"ammo_556nato");
    
give_item(id"ammo_556nato");
    
give_item(id"weapon_glock18");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
client_print(idprint_chat"You are now a Grenadier");
        
        }
        case 
2// First Recon
        
{
    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
give_item(id"weapon_ump45");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"weapon_glock18");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");

    
client_print(idprint_chat"You are now an Assault");
        }
        case 
3//Overwatch
    
{
    
strip_user_weapons(id);
    
give_item(id"weapon_knife");
    
give_item(id"weapon_hegrenade");
    
give_item(id"weapon_glock18");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"weapon_m3");
    
give_item(id"ammo_buckshot");
    
give_item(id"ammo_buckshot");
    
give_item(id"ammo_buckshot");
    
give_item(id"ammo_buckshot");
    
give_item(id"ammo_buckshot");

    
client_print(idprint_chat"You are now a Overwatch");
    }
        case 
4//Scout Snipist
    
{
    
give_item(id"weapon_knife");
    
give_item(id"weapon_hegrenade");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_scout");
    
give_item(id"ammo_762nato");
    
give_item(id"weapon_deagle");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
    
client_print(idprint_chat"You are now a Scout Snipist");
    }
        case 
5//Riot Control
    
{
    
give_item(id"weapon_knife");
    
give_item(id"weapon_hegrenade");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_flashbang");
    
give_item(id"weapon_knife");
    
give_item(id"weapon_shield");
    
give_item(id"weapon_deagle");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"ammo_50ae");
    
give_item(id"weapon_glock18");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"ammo_9mm");
    
give_item(id"weapon_usp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
give_item(id"ammo_45acp");
    
    
client_print(idprint_chat"You are now a Riot Controller");
    }
    }

    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
 }
 
 
 
 
 
 Print(
iPlayer, const sMsg[], any:...)
{
 static 
iiPlayer iPlayer get_Player();
 if ( !
) return;
 
 new 
sMessage[256];
 new 
len formatex(sMessagesizeof(sMessage) - 1"^x04[HNS Ranks]^x03 ");
 
vformat(sMessage[len], sizeof(sMessage) - lensMsg3);
 
sMessage[192] = '^0';
  
 static 
msgid_SayText;
 if ( !
msgid_SayText msgid_SayText get_user_msgid("SayText");
 
 new const 
team_Names[][] =
 {
  
"",
  
"TERRORIST",
  
"CT",
  
"SPECTATOR"
 
};
  
 new 
sTeam get_user_team(i);
 
 
team_Info(iiPlayerteam_Names[0]);
  
 
message_begin(iPlayer MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_SayText_iPlayer);
 
write_byte(i);
 
write_string(sMessage);
 
message_end();
  
 
team_Info(iiPlayerteam_Names[sTeam]);
}
team_Info(receiversendersTeam[])
{
 static 
msgid_TeamInfo;
 if ( !
msgid_TeamInfo msgid_TeamInfo get_user_msgid("TeamInfo");
 
 
message_begin(sender MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_TeamInfo_sender);
 
write_byte(receiver);
 
write_string(sTeam);
 
message_end();
}
get_Player()
{
 for ( new 
iPlayer 1iPlayer <= get_maxplayers(); iPlayer++ )
 {
  return 
iPlayer;
 }
 
 return 
0;
}
 
 
//////////FROM BF2 RANK MOD//////////

public on_ShowStatus(id//called when id looks at someone
{
    new 
name[32], pid read_data(2);
    new 
pidrank gLevel[pid];

    
get_user_name(pidname31);
    new 
color1 0color2 0;

    if (
get_user_team(pid) == 1)
        
color1 255;
    else
        
color2 255        
    
    set_hudmessage
(color1100color2, -1.00.3500.0120.0);    
    
ShowSyncHudMsg(idg_status_sync"%s^nLevel: %d"namegLevel[pidrank]+1);
}

public 
on_HideStatus(id)
{
    
ClearSyncHud(idg_status_sync);

natkemon is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-12-2011 , 01:40   Re: [help] Cod help
Reply With Quote #2

That text you get in console tells you to enable debug. If you can't even do that much yourself, then you gonna have hard time finishing this mod.

About bugs:
amxx code is case sensitive, so if you define function as ShowHud(id), then to call it with set_task you need to use "ShowHud", not "showhud".

Saving doesn't work because you have no idea what you are doing. You use different keys and different delimiters in saving and loading.
__________________
Impossible is Nothing
Sylwester is offline
Old 03-12-2011, 01:44
wrecked_
This message has been deleted by wrecked_. Reason: Sylwester explained it clearly
natkemon
Member
Join Date: Dec 2008
Old 03-12-2011 , 03:42   Re: [help] Cod help
Reply With Quote #3

i know how to debug. This is what comes up:

Quote:
L 03/12/2011 - 14:02:41: Function is not present (function "showhud") (plugin "cod4.amxx")
L 03/12/2011 - 14:02:41: [AMXX] Run time error 10 (plugin "cod4.amxx") (native "set_task") - debug not enabled!
L 03/12/2011 - 14:02:41: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quote]
and how would i go about fixing the save and load function?
natkemon is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-12-2011 , 04:08   Re: [help] Cod help
Reply With Quote #4

Quote:
Originally Posted by natkemon View Post
i know how to debug.
I doubt it.

Quote:
Originally Posted by natkemon View Post
and how would i go about fixing the save and load function?
I normally would recommend going with sql and covering cases that may produce errors, but it may be too much for you, so you can start with this:
PHP Code:
public SaveData(id)
{
    new 
key[32], data[101];
    
get_user_authid(idkey31);
    
format(data100"%d %d"gXP[id], gLevel[id]);
    
nvault_set(g_vaultkeydata);
}

public 
LoadData(id)
{
    new 
key[32], data[101];
    
get_user_authid(idkey31);
    
nvault_get(g_vaultkeydata100);

    new 
szXP[32], szLevel[32];
    
parse(dataszXP31szLevel31);
 
    
gXP[id] = str_to_num(szXP);
    
gLevel[id] = str_to_num(szLevel);
}

public 
plugin_end()
{
    
nvault_close(g_vault);

You need to save data only in client_disconnect and load data only in client_authorized.
__________________
Impossible is Nothing
Sylwester is offline
natkemon
Member
Join Date: Dec 2008
Old 03-12-2011 , 04:50   Re: [help] Cod help
Reply With Quote #5

Thanks. it worked.

Umm

How do I make it check that.. once it reaches the lvl commander... it counts 1 to prestige .. and then sets you back to private first class
natkemon is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-12-2011 , 05:07   Re: [help] Cod help
Reply With Quote #6

I don't know what do you mean with "counts 1 to prestige". If you want to do something once player reaches the highest rank, then you can do it in CheckLevel function when you increase level.
__________________
Impossible is Nothing
Sylwester is offline
natkemon
Member
Join Date: Dec 2008
Old 03-12-2011 , 08:44   Re: [help] Cod help
Reply With Quote #7

ok so for example... I reached commander for the first time. Prestige = 1... then it goes back to private first class

i reach commander the 2nd time.. prestige = 2..

i reach comander the 3rd time.. prestige = 3.. and etc..
natkemon is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 03-12-2011 , 09:19   Re: [help] Cod help
Reply With Quote #8

It's one of the most basic things. Do it yourself.
If you can't do it yourself then learn how to do it ( Pawn Picture Tutorial ).
__________________
Impossible is Nothing
Sylwester is offline
natkemon
Member
Join Date: Dec 2008
Old 03-12-2011 , 09:43   Re: [help] Cod help
Reply With Quote #9

This is what i've found out so far.. i dunno what next though

PHP Code:
#define Commander 0

   
if( gLevel[id] == Commander)
    {
    
// How do i make it set back to Private first class here? and make a prestige thing?
    

natkemon 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:35.


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