XP Based Plugin - Tutorial!

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

And btw, i only want 1 class to get more runspeed per level...

let me guess, should it be like this;

Code: Select all

public Event_CurWeapon(id) {
   if(PlayerClass[id] == CLASS_RUN) {
      new Float:Speed = 320.0+(PlayerLevel[id]*50)
      set_user_maxspeed(id, Float:Speed)
   }
}
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

Okay, for gravity

Code: Select all

new Float:pGrav = 1.00-(g_PlayerLevel[id]*0.08)
set_user_gravity(id,pGrav);
Every level, he will be 8% lighter.

For speed

Code: Select all

public plugin_init() {
    //...
    register_event("CurWeapon", "Event_CurWeapon", "be", "1=1"); // we need to do this becuase speed resets to default whenever the weapon is changed.
}
public Event_CurWeapon(id) {
    new Float:pSpeed = 320+(g_PlayerLevel*35)
    set_user_maxspeed(id,pSpeed);
}
320 is default speed (from what I know) then +35 per level, which makes the total speed, at level 10, 770. =P

Next up HP and AP

Code: Select all

new g_PlayerHP[33]
new g_PlayerAP[33]
public plugin_init() {
    //...
    register_event("ResetHUD", "ResetHUD", "be");
}
public ResetHUD(id) {
    if(!is_user_connected(id) || !is_user_alive(id) || !is_user_bot(id)) return PLUGIN_HANDLED;
    //Do whatever checks you want here

    set_task(0.5,"SetStats",id);
}
public SetStats(id) {
    new iHP, iAP
    iHP = g_PlayerLevel[id]*25
    iAP = g_PlayerLevel[id]*10

    if(g_PlayerHP[id] < 100) g_PlayerHP = 100
    if(g_PlayerAP[id] < 100) g_PlayerAP = 100 // Cuzz I like starting with full armor

    g_PlayerHP[id] += iHP
    g_PlayerAP[id] += iAP

    set_user_health(id, g_PlayerHP[id]);
    cs_set_user_armor(id, g_PlayerAP[id], CsArmorType:2);
}
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

but nothing of these codes work :O :O :O :O:O :O
i did now it was ResetHUD
the function
register_event(ResetHUD, ResetHud)

public ResetHUD // this is the problem
it should be:
public ResetHud //such a small difference i didnt eaven notice
one good advice

==> never use the same name as you register something with

always do it like => register_event(ResetHUD, hud_reset)
the name is a bit different, but it solves many bugs like reserved names
That won't do anything, it doesn't matter if your hooked function is the same as the event.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

I really don't know if someone already said this.

But in the DeathMsg event, where it gives the plyers their XP. You need to change the Event flags to "ae" otherwise players could type kill and get xp.

Code: Select all

register_event("DeathMsg", "DeathMsg", "ae"
OR

You need to check if the player is alive before giving XP.

Code: Select all

if(is_user_alive(attacker))
{
     //givexp
}
sry but

Code: Select all

register_event("DeathMsg", "DeathMsg", "a")
works for me too
but if you were smart enough
you would - the killer's xp if he kills a team mate since the kill command is killing someone from your own team ;)
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

hmm...
can someone make it so that when a user connects to the server (and he has saved xp)
when he spawns, i want it to show him the menu of classes to choose from instead of him sticking with the class he had before...
use it to do wiht something in the client_connect thingy?
Make the menu.

Then go like so.

public client_connect(id)
{
PlayerClass[id] = CLASS_NOTHING
GotoMenu(id)
}
I don't think they can be shown a menu, while their veiwing a loading screen.

client_connect is called when he gets on the server
when the motd is showed
client_connect is called before that, you're thinking of client_putinserver
so whose right about client_connect and client_putinserver?
Yeah my mistake. I was tired.

client_putinserver is what you want.
pssssh, use client_authorized to reset his class, then when round starts pop up the menu to give him to option to choose class. =/
*cought involves client_authorized and HLTV*
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

Hrm. -.- my xp saves on disconnect, but doesn't save after map change. Any way to fix this?

Code: Select all

public server_changeleve(map[])
{
     // Code...
}
I forget is this is called with the level command that disconnects all players, or the one where it keeps all the clients. You might want to take a try with it (there are other ways of course ^^).
O.o
Okay This is what you probably should do, becuase it also accounts for server crashes, power outages, blah, blah, blah. Okay?

client_disconnect(id) should save xp
HLTV should save XP
client_authorized(id) should load xp, this is called after they are completely connected and the ID is valid, sometimes client_connect doesn't work, authorized always works.

If you have it like that, then the player's xp should always be saved. and theres never anything to worry about really.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

Maybe someone can add givexp function ?
I am really new to amxx scripting but here is something that I thought about based on this tutorial.

Code: Select all

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <vault> 
 
//let's say you did everything else in this tutorial..
 
public GiveXP(id, level, cid)
{
if (!cmd_access(id, level, cid, 3))
return PLUGIN_CONTINUE
new Arg1[24], Arg2[11]
 
read_argv(1, Arg1, 23)
read_argv(2, Arg2, 10)
 
new Target = cmd_target(id, Arg1, 8)
new XPAmount = str_to_num(Arg2)
 
new authid[32]; 
get_user_authid(id,authid,31); 
 
new vaultkey[64], vaultdata[64];
 
format(vaultkey,63,"ANIMAL-%s-xp",authid); 
get_vaultdata(vaultkey,vaultdata,63); 
new OrgXP = str_to_num(vaultdata); 
 
 
new TargetName[32]
get_user_name(Target,TargetName,31)
 
if (!Target)
{ 
console_print(id, "Sorry, player %s could not be found or be targetted!", TargetName)
return PLUGIN_CONTINUE
} 
else
{
if (XPAmount > 0 && XPAmount <= 9999999999)
{
XPAmount = XPAmount + OrgXP
 
format(vaultkey,63,"ANIMAL-%s-xp",authid); 
format(vaultdata,63,"%d",XPAmount); 
set_vaultdata(vaultkey,vaultdata);
 
console_print(id, "Player %s XP was changed to %d ", TargetName, XPAmount)
}
}
return PLUGIN_CONTINUE
} 
ok that's it... I am not sure it's working though since it's only my 4th day amxx scripting
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

You should try reading the wiki and some other basic coding tutorials before trying to edit this tutorial to create your own full plugin..
Attachments
utmod.sma.zip
(1.76 KiB) Downloaded 17 times
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

does anyone have a script like this but in NVAULT?
if you do can you share it please (or post a new tutorial on how to code in nvault)? because im trying to learn how to code in Nvault. TY
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: XP Based Plugin - Tutorial!

Post by Archive-Poster »

Code: Select all

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#define MAXCLASSES 5
new const CLASSES[MAXCLASSES][] = {
 "None",
 "Dog",
 "Cat",
 "Horse",
 "Cow"
}
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("Mod", "1.0", "Fxfighter")
 
 register_event("DeathMsg", "eDeath", "a") 
 
 SaveXP = register_cvar("SaveXP","1")
 XP_Kill=register_cvar("XP_per_kill", "20")
 XP_Knife=register_cvar("XP_hs_bonus","20")
 XP_Hs=register_cvar("XP_knife_bonus","20")
 g_vault = nvault_open("VAULT")
 
 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 iVictim = read_data( 2 )
 new weapon, hitplace, attacker = get_user_attacker(iVictim,weapon,hitplace)
 
 PlayerXP[attacker] += get_pcvar_num(XP_Kill)
 
 if(hitplace == HIT_HEAD)
  PlayerXP[attacker] += get_pcvar_num(XP_Hs)
 
 if(weapon == CSW_KNIFE)
  PlayerXP[attacker] += get_pcvar_num(XP_Knife)
 
 
 if(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]])
  PlayerLevel[attacker] += 1
 
 ShowHud(attacker)
 SaveData(attacker)
}
public ShowHud(id)
{
set_hudmessage(255, 0, 0, 0.01, 0.2, 0, 6.0, 12.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 ,"Cow", "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 , 5 , szName , 63 , callback);
 
 new i = 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)
  client_print(id, print_chat, "[Mod] XP Loaded!")
 }
}
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(vaultdata, 255, "#", " ")
 
 new playerxp[32], playerlevel[32]
 
 parse(vaultdata, playerxp, 31, playerlevel, 31)
 
 PlayerXP[id] = str_to_num(playerxp)
 PlayerLevel[id] = str_to_num(playerlevel)
 
 return PLUGIN_CONTINUE
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest