Giving something to an offline user

Ако имате затруднения при изработката/преработката на даден плъгин - пишете тук, ще се опитаме да ви помогнем!
Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 04 дек 2018, 22:04

Hi
As the title says, how I can give something to an offline user? by steamid.. for example, XP.

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5318
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 75 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Giving something to an offline user

Мнение от OciXCrom TM » 05 дек 2018, 14:29

It depends on how you save your data. Which saving method are you using? nVault?

Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 05 дек 2018, 23:00

Yes, im using nVault

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5318
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 75 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Giving something to an offline user

Мнение от OciXCrom TM » 06 дек 2018, 16:11

If you want to do it by SteamID, you must save the data by SteamID as well because you'll need to locate the SteamID in the nVault file that corresponds with the player.

To give XP to the player, you'll simple need to load the current XP he has and add the new amount to that number. Here's a simple example on how to give 100 XP to the player with SteamID STEAM_0:0:50153248, step by step:

Код: Избери всички

// Get the current XP from the SteamID
new iXP = nvault_get(g_iVault, "STEAM_0:0:50153248")

// Add 100 to the current XP
iXP += 100

// Create a string that will hold the XP because nVault data can't be saved as a number, it must be a string
new szXP[32]
num_to_str(iXP, szXP, charsmax(szXP))

// Save the data to nVault
nvault_set(g_iVault, "STEAM_0:0:50153248", szXP)
The same thing can be done in just one line of code if you're using AMXX 1.8.3 or a newer version:

Код: Избери всички

nvault_set(g_iVault, "STEAM_0:0:50153248", fmt("%i", nvault_get(g_iVault, "STEAM_0:0:50153248") + 100))

Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 06 дек 2018, 23:20

So is that correct?

Код: Избери всички

public CmdAddXPOff(iPlayer, level, cid)
{
	if(!cmd_access(iPlayer,level,cid,3)) return PLUGIN_HANDLED
	
	new szAuthID[35]
	get_user_authid(iPlayer,szAuthID,charsmax(szAuthID))
	
	read_argv(1,szAuthID,charsmax(szAuthID))
	
	new XP[32]
	read_argv(2,XP,charsmax(XP))
	
	new xpgiven = str_to_num(XP)
	
	new target[32]
	new player = cmd_target(iPlayer,target, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)
	
	if(target[iPlayer] == szAuthID[iPlayer])
	{
		new iXP = nvault_get(g_Vault,szAuthID)
		
		iXP += xpgiven
		
		new szXP[32]
		num_to_str(iXP,szXP,charsmax(szXP))
		
		nvault_set(g_Vault,szAuthID,szXP)
	}
}

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5318
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 75 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Giving something to an offline user

Мнение от OciXCrom TM » 07 дек 2018, 15:53

No, why are you trying to target a player if he is offline? cmd_target only works for online players. The SteamID is only a key stored in the nVault file, it's not an actual player that you can locate.

Also, you're getting the SteamID of the player who used the command for no reason.

This line also isn't correct:

Код: Избери всички

if(target[iPlayer] == szAuthID[iPlayer])
I don't know what you're trying to check here.

Here's what the code should look like:

Код: Избери всички

// amx_addxp <steamid> <xp>
public CmdAddXPOff(id, iLevel, iCid)
{
	// Check if the player has access and both arguments (<steamid> and <xp>) are provided
	if(!cmd_access(id, iLevel, iCid, 3))
		return PLUGIN_HANDLED
	
	// Grab the first argument which is <steamid>
	new szAuthID[35]
	read_argv(1, szAuthID, charsmax(szAuthID))
	
	// Grab the second argument which is <xp>
	new szXP[32]
	read_argv(2, szXP, charsmax(szXP))

	// Convert the argument to an integer
	new iXP = str_to_num(szXP)

	// Grab the current XP for the SteamID, add the XP from the command and store it in a string
	num_to_str(nvault_get(g_Vault,szAuthID) + iXP, szXP, charsmax(szXP))

	// Write the data in the nVault file
	nvault_set(g_Vault, szAuthID, szXP)

	// Print a message to the admin
	console_print(id, "* Gave %d XP to %s", iXP, szAuthID)
	
	return PLUGIN_HANDLED
}
You should also add a safety check to see if the player with that SteamID is connected or not.

Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 07 дек 2018, 18:11

Thanks, I ll try it

I was confused to check the target, thought that the cmd_target will work xd ( the first argument )

Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 01 яну 2019, 21:06

Ok.
I just tested it now, I had no server to test
It is giving the player LEVEL instead of XP.

PS# Even when it gives him the LEVEL, his level stay the same. But on the top it shows his steamid and level. not the name :3
I put the saving method on steamid since long time ago, but it doesnt want to save in steamid, maybe this is the problem ?
Here is the code of level system im using ( I wanted to switch to your level system but it doesnt have top)

Код: Избери всички

 #include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <levels>
#include <nvault>
#include <sqlx>
#include <nvault_util>

#define TASK_SHOW_LEVEL 10113
#define MAXLEVEL 60

new const LEVELS[MAXLEVEL] = { 
200, // Needed on level 1
600, // Needed on level 2
1000, // Needed on level 3
1750, // Needed on level 4
2800, // Needed on level 5
3600, // Needed on level 6
4600, // Needed on level 7
6000, // Needed on level 8
7000, // Needed on level 9
8000, // Needed on level 10
9000, // Needed on level 11
10000, // Needed on level 12
12000, // Needed on level 13
14000, // Needed on level 14
16000, // Needed on level 15
18000, // Needed on level 16
20000, // Needed on level 17
22000, // Needed on level 18
24000, // Needed on level 19
26000, // Needed on level 20
27000, // Needed on level 21
33000, // Needed on level 22
35000, // Needed on level 23
38000, // Needed on level 24
40000, // Needed on level 25
43000, // Needed on level 26
46000, // Needed on level 27
50000, // Needed on level 28
60000, // Needed on level 29
70000, // Needed on level 30
80000, // Needed on level 31
90000, // Needed on level 32
100000, // Needed on level 33
110000, // Needed on level 34
120000, // Needed on level 35
130000, // Needed on level 36
140000, // Needed on level 37
150000, // Needed on level 38
160000, // Needed on level 39
170000, // Needed on level 40
180000, // Needed on level 41
190000, // Needed on level 42
200000, // Needed on level 43
210000, // Needed on level 44
220000, // Needed on level 45
230000, // Needed on level 46
240000, // Needed on level 47
250000, // Needed on level 48
260000, // Needed on level 49
270000, // Needed on level 50
280000, // Needed on level 51
290000, // Needed on level 52
300000, // Needed on level 53
400000, // Needed on level 54
500000, // Needed on level 55
600000, // Needed on level 56
700000, // Needed on level 57
800000, // Needed on level 58
900000, // Needed on level 59
1000000  // Needed on level 60
}; // Needed Xp on each Levels

new const szTables[][] = 
{
	"CREATE TABLE IF NOT EXISTS `mytable` ( `player_id` varchar(32) NOT NULL,`player_level` int(8) default NULL,`player_xp` int(16) default NULL,PRIMARY KEY (`player_id`) ) TYPE=MyISAM;"
}

new PlayerXp[33]
new PlayerLevel[33]
new Handle:g_hTuple;


new g_MsgScreenFade

new time_xp

new g_Vault
new g_kills[33]
new g_maxplayers, g_msgHudSync1
new savexp, save_type, xp_kill, xp_triple, enable_triple, triple_kills, xp_ultra, ultra_kills, enable_ultra, escape_xp, damage_hp, damage_xp

new mysqlx_host, mysqlx_user, mysqlx_db, mysqlx_pass

public plugin_init()
{
	register_plugin("[ZE] Levels XP", "1.5", "Raheem");

	save_type = register_cvar("levels_savetype","0"); // Save Xp to : 1 = MySQL, 0 = NVault.
	savexp = register_cvar("levels_save","1"); // Save Xp by : 2 = Name, 1 = SteamID, 0 = IP.
	xp_kill = register_cvar("levels_xp","10"); // How much xp gain if you killed someone?

	enable_triple = register_cvar("levels_triple","1"); // Enable Triple Kill bonus xp? 1 = Yes, 0 = No.
	xp_triple = register_cvar("levels_triple_xp","3"); // How much bonus xp give for Triple Kill?
	triple_kills = register_cvar("levels_triple_kills","3"); // How much kills needed to give bonus xp?
	enable_ultra = register_cvar("levels_ultra","1"); // Enable Ultra Kill bonus xp? 1 = Yes, 0 = No.
	xp_ultra = register_cvar("levels_ultra_xp","5"); // How much bonus xp give for Ultra Kill?
	ultra_kills = register_cvar("levels_ultra_kills","6"); // How much kills needed to give bonus xp?
	escape_xp = register_cvar("escape_xp_amount", "20") // How much XP given to Humans when escape success?
	damage_hp = register_cvar("required_damage_hp", "60") // The damage if the player made more than it he will awarded.
	damage_xp = register_cvar("damage_xp_amount", "2") //How much XP given to human who make damage more than damage_hp?
	time_xp = register_cvar("time_xp_amount", "20") // How much XP given to player when he play 9 minute?
	register_concmd ( "give_xp", "CmdAddXP", ADMIN_RCON, "<nick, #userid, authid | @all> <xp>" )
	register_concmd ( "remove_xp", "CmdRemoveXP", ADMIN_RCON, "<nick, #userid, authid | @all> <xp>" )
	register_concmd("amx_addxp", "CmdAddXPOff", ADMIN_RCON,"<steamid> <xp>")
	
	register_clcmd("say /top10", "showtop10")
	
	// SQLx cvars
	mysqlx_host = register_cvar ("levels_host", ""); // The host from the db
	mysqlx_user = register_cvar ("levels_user", ""); // The username from the db login
	mysqlx_pass = register_cvar ("levels_pass", ""); // The password from the db login
	mysqlx_db = register_cvar ("levels_dbname", ""); // The database name 

	// Events
	register_event("DeathMsg", "event_deathmsg", "a");
	register_event("StatusValue", "Event_StatusValue", "bd", "1=2")
	register_event("Damage", "on_damage", "b", "2!0", "3=0", "4!0")


	// Forwards //
	RegisterHam(Ham_Spawn, "player", "fwd_PlayerSpawn", 1);

	MySQLx_Init()

	g_msgHudSync1 = CreateHudSyncObj()
	g_maxplayers = get_maxplayers();
	g_MsgScreenFade = get_user_msgid( "ScreenFade" )
}

public plugin_cfg()
{
	//Open our vault and have g_Vault store the handle.
	g_Vault = nvault_open( "levels_v2" );

	//Make the plugin error if vault did not successfully open
	if ( g_Vault == INVALID_HANDLE )
		set_fail_state( "Error opening levels nVault, file does not exist!" );
}

public plugin_precache()
{
    precache_sound( "levelup_ZE/ze_levelup.wav" );
}

public plugin_natives()
{
	register_native("get_user_xp", "native_get_user_xp", 1);
	register_native("set_user_xp", "native_set_user_xp", 1);
	register_native("get_user_level", "native_get_user_level", 1);
	register_native("set_user_level", "native_set_user_level", 1);
	register_native("check_level_xp", "native_check_level", 1)
	register_native("get_user_max_level", "native_get_user_max_level", 1);
}

public plugin_end()
{
	//Close the vault when the plugin ends (map change\server shutdown\restart)
	nvault_close( g_Vault );
}

public client_connect(id)
{
	LoadLevel(id)

	if(is_user_connected(id))
	{
		set_task(540.0, "prizes", id, _, _, "b")
	}
}
// amx_addxp <steamid> <xp>
public CmdAddXPOff(id, iLevel, iCid)
{
	// Check if the player has access and both arguments (<steamid> and <xp>) are provided
	if(!cmd_access(id, iLevel, iCid, 3))
		return PLUGIN_HANDLED
	
	// Grab the first argument which is <steamid>
	new szAuthID[35]
	read_argv(1, szAuthID, charsmax(szAuthID))
	
	// Grab the second argument which is <xp>
	new szXP[256]
	read_argv(2, szXP, charsmax(szXP))

	// Convert the argument to an integer
	PlayerXp[id] = str_to_num(szXP)
	new iXP = str_to_num(szXP)

	// Grab the current XP for the SteamID, add the XP from the command and store it in a string
	num_to_str(nvault_get(g_Vault,szAuthID) + iXP, szXP, charsmax(szXP))

	// Write the data in the nVault file
	nvault_set(g_Vault, szAuthID, szXP)

	// Print a message to the admin
	console_print(id, "* Gave %d XP to %s", iXP, szAuthID)
	return PLUGIN_HANDLED
}
public prizes(id)
{
	set_user_xp(id, get_user_xp(id) + get_pcvar_num(time_xp))
	client_print_color(id, "!y[!gMZE] !g +%i XP For playing 9 Minutes in our server!y.", get_pcvar_num(time_xp))
	check_level_xp(id)
	
}

public client_disconnect(id)
{
	SaveLevel(id)

	PlayerXp[id] = 0;
	PlayerLevel[id] = 0;

	remove_task( TASK_SHOW_LEVEL + id );
	remove_task(id)
}

public fwd_PlayerSpawn(id)
{
	
	if(!is_user_alive(id))
		return;
	
	g_kills[id] = 0

	remove_task( TASK_SHOW_LEVEL + id );		

	set_task(0.1, "task_show_level", TASK_SHOW_LEVEL + id)
}

public event_deathmsg()
{	
	new g_attacker = read_data(1);
	new g_victim = read_data(2);
	
	new counted_triple = get_pcvar_num(xp_kill) + get_pcvar_num(xp_triple)
	new counted_ultra = get_pcvar_num(xp_kill) + get_pcvar_num(xp_ultra)
	
	if((1 <= g_attacker <= g_maxplayers))
	{
		if(g_victim != g_attacker)
		{
			g_kills[g_attacker]++;
			if(PlayerLevel[g_attacker] < MAXLEVEL-1) 
			{

				if ( g_kills[g_attacker] == get_pcvar_num(triple_kills) && get_pcvar_num(enable_triple) )
				{
					PlayerXp[g_attacker] += counted_triple
						
					set_hudmessage(0, 40, 255, 0.50, 0.33, 1, 2.0, 8.0)
					show_hudmessage(g_attacker, "+%i Triple Kill XP!", counted_triple)
				}
				else if ( g_kills[g_attacker] == get_pcvar_num(ultra_kills) && get_pcvar_num(enable_ultra) )
				{
					PlayerXp[g_attacker] += counted_ultra
						
					set_hudmessage(255, 30, 0, 0.50, 0.33, 1, 2.0, 8.0)
					show_hudmessage(g_attacker, "+%i Ultra Kill XP!", counted_ultra)
				}
				else
				{
					PlayerXp[g_attacker] += get_pcvar_num(xp_kill)
					
					set_hudmessage(0, 255, 50, 0.50, 0.33, 1, 2.0, 8.0)
					show_hudmessage(g_attacker, "+%i XP", get_pcvar_num(xp_kill))
				}
				
				check_level_xp(g_attacker)
			}
		}
	}
}

public ze_roundend()
{
	new Alive_Terrorists_Number = GetPlayersNum(CsTeams:CS_TEAM_T)
	new Alive_CT_Numbers = GetPlayersNum(CsTeams:CS_TEAM_CT)
	
	new iPlayers[32], iNum
	get_players(iPlayers, iNum, "ace", "CT")

	for (new i = 0; i < iNum; i++)
	{
		if(PlayerLevel[iPlayers[i]] < MAXLEVEL-1)
		{
			if((Alive_CT_Numbers > Alive_Terrorists_Number) && (Alive_Terrorists_Number == 0))
			{
				set_user_xp(iPlayers[i], get_user_xp(iPlayers[i]) + get_pcvar_num(escape_xp))
				client_print_color(iPlayers[i], "!y[!gMZE!y] !g+%i XP !yfor escaping.", get_pcvar_num(escape_xp))
			}
			check_level_xp(iPlayers[i])
		}
	}
}

public on_damage(id)
{
	static attacker,damage;
	
	attacker = get_user_attacker(id)
	damage = read_data(2)
	
	if (id == 0) return
	
	if(PlayerLevel[attacker] < MAXLEVEL-1)
	{
		if ((damage >= get_pcvar_num(damage_hp)) && is_user_connected(attacker) && (cs_get_user_team(attacker) == CS_TEAM_CT) && (attacker != id))
		{
			set_user_xp(attacker, get_user_xp(attacker) + get_pcvar_num(damage_xp))
			set_hudmessage(random(256), random(256), random(256), -1.0, 0.7, 1, 3.0, 8.0, 0.5, 0.5)
			show_hudmessage(attacker, "+%i XP", get_pcvar_num(damage_xp))
		}
		
		check_level_xp(attacker)
	}
}

public Event_StatusValue(id)
{
	new target = read_data(2)
  	if(target != id && target != 0)
  	{
		static sName[32];
		get_user_name(target, sName, 31)

		set_hudmessage(0, 255, 255, -1.0, 0.3, 0, 0.0, 6.0, 0.0, 0.0, 2)
		ShowSyncHudMsg(id, g_msgHudSync1, "| Spectating: %s |^n[Level: %i ǁ XP: %i / %i]", sName, PlayerLevel[target], PlayerXp[target], LEVELS[PlayerLevel[target]])
	}
}

public task_show_level(task)
{
	new id = task - TASK_SHOW_LEVEL
	
	if(!is_user_alive(id))
		return;
	
	set_hudmessage(0, 255, 255, 0.02, 0.05, 0, 0.0, 0.3, 0.0, 0.0)
	ShowSyncHudMsg(id, g_msgHudSync1 , "[Level : %i ǁ XP : %i / %i]", PlayerLevel[id], PlayerXp[id], LEVELS[PlayerLevel[id]])
	
	set_task(0.1, "task_show_level", TASK_SHOW_LEVEL + id)		
}

public showtop10(id)
{
	new pos,key[64],data[64],timestamp
	new vault = nvault_util_open("levels_v2")
	new count = nvault_util_count(vault)
 
	new Array:stats,Trie:names
	stats = ArrayCreate(20)
	names = TrieCreate()
 
	new temp[20],knum[5]
	for (new i=1;i<=count;i++ )
	{
		pos = nvault_util_read(vault,pos,key,64,data,64,timestamp)
		formatex(temp,19,"%d %d",i,str_to_num(data))
		ArrayPushString(stats,temp)
		replace_all(key,64,"Level","")
		formatex(knum,4,"%d",i)
		TrieSetString(names,knum,key)
	}
 
	nvault_util_close(vault)
	ArraySort(stats,"sorter")
 
	new motd[1501],iLen;
	iLen = format(motd, sizeof motd - 1,"<body bgcolor=#000000><h3><font color=#48D532><pre>");
	iLen += format(motd[iLen], (sizeof motd - 1) - iLen,"%s %-22.22s  %s  %3s^n", "#", "Name", "SteamID", "Level")
 
	for(new x = 0; x < 10; x++)
	{
		new rank,name[32],srank[5]
		new pt = getter(stats,x,rank)
		formatex(srank,4,"%d",rank)
		TrieGetString(names,srank,name,31)
		/*new len = strlen(name) 
		if(len) 
		{ 
		    name[len-5] = 0
		}*/
		iLen += format(motd[iLen], (sizeof motd - 1) - iLen,"%d. %-22.22s    %d^n", x + 1, name, pt);
	}
	iLen += format(motd[iLen], (sizeof motd - 1) - iLen,"</body></h3></font></pre>")
 
	ArrayDestroy(stats)
	TrieDestroy(names)
	show_motd(id,motd, "Top 10");
}

public sorter(Array:array,item1,item2)
{
	
	new res1=getter(array,item1)
	new res2=getter(array,item2)
 
	if(res1<res2)
		return 1
 
	else if(res1>res2)
		return -1
	
 	return 0
}

getter(Array:array,item,&rank=0)
{
	new outa[32],temp[2][10],val
	ArrayGetString(array,item,outa,31)
	parse(outa,temp[0],9,temp[1],9)
	rank = str_to_num(temp[0])
	val = str_to_num(temp[1])
	return val
}


public CmdAddXP(iPlayer, level, cid)
{
	if(!cmd_access(iPlayer, level, cid, 3)) return PLUGIN_HANDLED;
	   
	new arg [32]
	read_argv (1, arg, 31) 
 
	new AddXP [32]
	read_argv (2, AddXP, charsmax (AddXP))
 
	new XPtoGive = str_to_num (AddXP)
	   
	new AdminName [32]
	new TargetName [32]
	get_user_name (iPlayer, AdminName, charsmax (AdminName))
	   
	if(arg[0]=='@')
	{ 
		if(equali(arg[1],"All") || equali(arg[1],"ALL"))
		{
			new players[32], totalplayers, All
			get_players(players, totalplayers)
		    
			for (new i = 0; i < totalplayers; i++)
			{
				All = players[i]
					   
				PlayerXp[All] += XPtoGive
			}
			check_level_xp(All)
			client_print_color(0, "!t[ADMIN] !g%s: !yGave !g%i XP !yto all !gPlayers!y!", AdminName, XPtoGive )
		}
		else if(equali(arg[1],"T") || equali(arg[1],"t"))
		{
			new players[32], totalplayers, T
			get_players(players, totalplayers)
		    
			for (new i = 0; i < totalplayers; i++)
			{
				if (get_user_team(players[i]) == 1)
				{
					T = players[i]
						   
					PlayerXp[T] += XPtoGive
				}
			}
			check_level_xp(T)
			client_print_color(0, "!t[ADMIN] !g%s: !yGave !g%i XP !yto all !gZombies!y!", AdminName, XPtoGive)
		}
		else if(equali(arg[1],"CT") || equali(arg[1],"ct"))
		{
			new players[32], totalplayers, CT
			get_players(players, totalplayers)
		    
			for(new i = 0; i < totalplayers; i++)
			{
				if(get_user_team(players[ i ] ) == 2)
				{
					CT = players[i]
						   
					PlayerXp[CT] += XPtoGive
				}
			}
			check_level_xp(CT)
			client_print_color(0, "!t[ADMIN] !g%s: !ygive !g%i XP !yto all !gHumans!y!", AdminName, XPtoGive)
		}
	}
	else
	{
		new iTarget = cmd_target(iPlayer, arg, 3)
		get_user_name (iTarget, TargetName, charsmax (TargetName))
		
		if(iTarget)
		{
			PlayerXp[iTarget] += XPtoGive
			
			check_level_xp(iTarget)
			if(is_user_admin(iPlayer))
				client_print_color(0, "!t[ADMIN] !g%s: !tGave !g%i XP to !g%s!y!", AdminName, XPtoGive, TargetName)
			client_print_color(iTarget, "!g[ADMIN] %s: !yGave %i XP to !gYOU!y!",AdminName, XPtoGive)
		}
	}
	return PLUGIN_HANDLED
}
 
public CmdRemoveXP (iPlayer, level, cid)
{
	if(!cmd_access(iPlayer, level, cid, 3)) return PLUGIN_HANDLED;
	   
	new arg [32]
	read_argv (1, arg, 31) 
 
	new RemoveXP [32]
	read_argv (2, RemoveXP, charsmax (RemoveXP))
 
	new XPtoRemove = str_to_num (RemoveXP)
	   
	new AdminName [32]
	new TargetName [32]
	get_user_name (iPlayer, AdminName, charsmax (AdminName))
	   
	if(arg[0]=='@')
	{ 
		if(equali(arg[1],"All") || equali(arg[1],"ALL"))
		{
			new players[32], totalplayers, All
			get_players(players, totalplayers)
		    
			for (new i = 0; i < totalplayers; i++)
			{
				All = players[i]
					   
				PlayerXp[All] -= XPtoRemove
			}
			check_level_xp(All)
			client_print_color(0, "!t[ADMIN] !g%s: !yRemoved !g%i XP from !yall !gPlayers!y!", AdminName, XPtoRemove)
		}
		else if(equali(arg[1],"T") || equali(arg[1],"t"))
		{
			new players[32], totalplayers, T
			get_players(players, totalplayers)
		    
			for (new i = 0; i < totalplayers; i++)
			{
				if (get_user_team(players[i]) == 1)
				{
					T = players[i]
						   
					PlayerXp[T] -= XPtoRemove
				}
			}
			check_level_xp(T)
			client_print_color( 0, "!t[ADMIN] !g%s: !yRemoved !g%i XP !yfrom all !gZombies!y!", AdminName, XPtoRemove)
		}
		else if(equali(arg[1],"CT") || equali(arg[1],"ct"))
		{
			new players[32], totalplayers, CT
			get_players(players, totalplayers)
		    
			for(new i = 0; i < totalplayers; i++)
			{
				if(get_user_team(players[ i ] ) == 2)
				{
					CT = players[i]
						   
					PlayerXp[CT] -= XPtoRemove
				}
			}
			check_level_xp(CT)
			client_print_color(0, "!t[ADMIN] !g%s: !yRemoved !g%i XP !yfrom all !gHumans!y!", AdminName, XPtoRemove)
		}
	}
	else
	{
		new iTarget = cmd_target(iPlayer, arg, 3)
		get_user_name (iTarget, TargetName, charsmax (TargetName))
		
		if(!iTarget)
			return PLUGIN_HANDLED
			
		PlayerXp[iTarget] -= XPtoRemove

		check_level_xp(iTarget)
		if(is_user_admin(iPlayer))
			client_print_color(0, "!t[ADMIN] !g%s: !yRemoved !g%i XP !yfrom !g%s!y!", AdminName, XPtoRemove, TargetName)
		client_print_color(iTarget, "!t[ADMIN] !g%s: !yRemoved !g%i XP !yfrom !gYOU", AdminName, XPtoRemove)

	}
	return PLUGIN_HANDLED
}
	
public MySQLx_Init()
{
	if (!get_pcvar_num(save_type))
		return;
	
	new szHost[64], szUser[32], szPass[32], szDB[128];
	
	get_pcvar_string( mysqlx_host, szHost, charsmax( szHost ) );
	get_pcvar_string( mysqlx_user, szUser, charsmax( szUser ) );
	get_pcvar_string( mysqlx_pass, szPass, charsmax( szPass ) );
	get_pcvar_string( mysqlx_db, szDB, charsmax( szDB ) );
	
	g_hTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
	
	for ( new i = 0; i < sizeof szTables; i++ )
	{
		SQL_ThreadQuery( g_hTuple, "QueryCreateTable", szTables[i])
	}
}

public QueryCreateTable( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) 
{ 
	if( iFailState == TQUERY_CONNECT_FAILED 
	|| iFailState == TQUERY_QUERY_FAILED ) 
	{ 
		log_amx( "%s", szError ); 
		
		return;
	} 
}

SaveLevel(id)
{ 
	new szAuth[33];
	new szTOP[33];
	new szKey[64];

	if ( get_pcvar_num(savexp) == 0 )
	{
		get_user_ip( id, szAuth , charsmax(szAuth), 1);
		formatex( szKey , 63 , "%s-IP" , szAuth);
	}
	else if ( get_pcvar_num(savexp) == 1 )
	{
		get_user_authid( id , szAuth , charsmax(szAuth) );
		get_user_name( id, szTOP , charsmax(szTOP) );
		formatex( szKey , 63 , "%s                                      %s" , szTOP, szAuth);
	}
	else if ( get_pcvar_num(savexp) == 2 )
	{
		get_user_name( id, szAuth , charsmax(szAuth) );
		formatex( szKey , 63 , "%s-NAME" , szAuth);
	}

	if ( !get_pcvar_num(save_type) )
	{
		new szData[256];
	
		formatex( szData , 255 , "%i#%i#" , PlayerLevel[id], PlayerXp[id] );
		
		nvault_set( g_Vault , szKey , szData );
	}
	else
	{	
		static szQuery[ 128 ]; 

		formatex( szQuery, 127, "REPLACE INTO `mytable` (`player_id`, `player_level`, `player_xp`) VALUES ('%s', '%d', '%d');", szAuth , PlayerLevel[id], PlayerXp[id] );
		
		SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
	}
}

LoadLevel(id)
{
	new szAuth[33];
	new szTOP[33];
	new szKey[40];

	if ( get_pcvar_num(savexp) == 0 )
	{
		get_user_ip( id, szAuth , charsmax(szAuth), 1);
		formatex( szKey , 63 , "%s-IP" , szAuth);
	}
	else if ( get_pcvar_num(savexp) == 1 )
	{
		get_user_authid( id , szAuth , charsmax(szAuth) );
		get_user_name( id, szTOP , charsmax(szTOP) );
		formatex( szKey , 63 , "%s%s" , szTOP, szAuth);
	}
	else if ( get_pcvar_num(savexp) == 2 )
	{
		get_user_name( id, szAuth , charsmax(szAuth) );
		formatex( szKey , 63 , "%s-NAME" , szAuth);
	}

	if ( !get_pcvar_num(save_type) )
	{
		new szData[256];

		formatex(szData , 255, "%i#%i#", PlayerLevel[id], PlayerXp[id]) 
			
		nvault_get(g_Vault, szKey, szData, 255) 

		replace_all(szData , 255, "#", " ")
		new xp[32], level[32] 
		parse(szData, level, 31, xp, 31) 
		PlayerLevel[id] = str_to_num(level)
		PlayerXp[id] = str_to_num(xp)  
	}
	else
	{
		static szQuery[ 128 ], iData[ 1 ]; 
		formatex( szQuery, 127, "SELECT `player_level`, `player_xp` FROM `mytable` WHERE ( `player_id` = '%s' );", szAuth ); 
     
		iData[ 0 ] = id;
		SQL_ThreadQuery( g_hTuple, "QuerySelectData", szQuery, iData, 1 );
	}
}

public QuerySelectData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) 
{ 
	if( iFailState == TQUERY_CONNECT_FAILED 
	|| iFailState == TQUERY_QUERY_FAILED ) 
	{ 
		log_amx( "%s", szError );
		
		return;
	} 
	else 
	{ 
		new id = iData[ 0 ];
		
		new ColLevel = SQL_FieldNameToNum(hQuery, "player_level") 
		new ColXp = SQL_FieldNameToNum(hQuery, "player_xp")
		
		while (SQL_MoreResults(hQuery)) 
		{
			PlayerLevel[id] = SQL_ReadResult(hQuery, ColLevel);
			PlayerXp[id] = SQL_ReadResult(hQuery, ColXp);
					
			SQL_NextRow(hQuery)
		}
	} 
}

public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime ) 
{ 
	if( iFailState == TQUERY_CONNECT_FAILED 
	|| iFailState == TQUERY_QUERY_FAILED ) 
	{ 
		log_amx( "%s", szError ); 
		
		return;
	} 
}

//======================Natives======================//

// Native: get_user_xp
public native_get_user_xp(id)
{
	return PlayerXp[id];
}
// Native: set_user_xp
public native_set_user_xp(id, amount)
{
	PlayerXp[id] = amount;
}
// Native: get_user_level
public native_get_user_level(id)
{
	return PlayerLevel[id];
}
// Native: set_user_xp
public native_set_user_level(id, amount)
{
	PlayerLevel[id] = amount;
}
// Native: Gets user level by Xp
public native_get_user_max_level(id)
{
	return LEVELS[PlayerLevel[id]];
}

//Native: Update User Level

public native_check_level(id)
{
	if(PlayerLevel[id] < MAXLEVEL-1)
	{
		while(PlayerXp[id] >= LEVELS[PlayerLevel[id]])
		{
			PlayerLevel[id]++;
			
			static name[32] ; get_user_name(id, name, charsmax(name));
			client_cmd(id,"spk levelup_ZE/ze_levelup.wav")
			
			message_begin(MSG_ONE_UNRELIABLE, g_MsgScreenFade, {0,0,0}, id)
			write_short(15000)    // Duration
			write_short(0)    // Hold time
			write_short(0)    // Fade type
			write_byte (random(256))        // Red
			write_byte (random(256))    // Green
			write_byte (random(256))        // Blue
			write_byte (150)    // Alpha
			message_end()
			
			client_print_color(0, "!y[!gMZE!y] !g%s !yReached Level !g%i!y.", name, PlayerLevel[id]);
		}
	} 
}

//==================================================//

//======================STOCKS======================//

stock GetPlayersNum(CsTeams:iTeam) {
    new iNum;
    for( new i = 1; i <= get_maxplayers(); i++ ) {
        if(is_user_connected(i) && is_user_alive(i) && cs_get_user_team(i) == iTeam)
            iNum++;
    }
    return iNum;
}

stock client_print_color(const id, const input[], any:...)  
{  
    new count = 1, players[32];  
    static msg[191];  
    vformat(msg, 190, input, 3);  

    replace_all(msg, 190, "!g", "^x04"); // Green Color  
    replace_all(msg, 190, "!y", "^x01"); // Default Color  
    replace_all(msg, 190, "!t", "^x03"); // Team Color  

    if (id) players[0] = id; else get_players(players, count, "ch");  
    {  
        for (new i = 0; i < count; i++)  
        {  
            if (is_user_connected(players[i]))  
            {  
                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);  
                write_byte(players[i]);  
                write_string(msg);  
                message_end();  
            }  
        }  
    }  
}

//==================================================//

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5318
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 75 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Giving something to an offline user

Мнение от OciXCrom TM » 02 яну 2019, 01:45

If the lack of top is the only reason you're not using my plugin - it's not a problem. Now that I added MySQL support, a top15 option will be added as well very soon (within the next few days). I suggest you switch to it, because the one you're using right now is hardcoded and poorly coded, which is not a very good idea.

Anyways, about your problem:

Код: Избери всички

// Convert the argument to an integer
PlayerXp[id] = str_to_num(szXP)
This code will take the XP amount that was specified in the command and will give it to the admin who used the command. Remove it.

You should look at how the XP is saved in nVault first:

Код: Избери всички

new szData[256];
formatex( szData , 255 , "%i#%i#" , PlayerLevel[id], PlayerXp[id] );
nvault_set( g_Vault , szKey , szData );
As you can see, "%i#%i#" is used, where the first "%i" is the level and the second "%i" is the player's XP.

This means you need to enter both the level and the XP you want to give the player. This is another reason why the plugin is bad. It should save only the XP and determine the level based on the XP, but instead it manually saves them which can result to wrong XP and level.

So, in order to do this, you'll either need to rewrite the entire XP saving and loading part, or change the command to give_xp <steamid> <level> <xp>, or determine the level automatically based on the <xp> parameter, or simply switch to my plugin. The last 2 options are the best choice.

Потребителски аватар

Автор на темата
X3.!
Foreigner
Foreigner
Мнения: 25
Регистриран: 30 ное 2018, 20:46
Се отблагодари: 1 път

Giving something to an offline user

Мнение от X3.! » 02 яну 2019, 13:30

Then im just gonna wait for your plugin next update

May you add give the xp to an offline user, and remove xp as well (in the next version) ?

Отговори

Върни се в “Помощ в скриптирането”

Кой е на линия

Потребители, разглеждащи този форум: Няма регистрирани потребители и 3 госта