Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Zabijanie graczy. Wykorzystanie biblioteki HamSandwich.


LosT.

Rekomendowane odpowiedzi

Opublikowano

R
E
K
L
A
M
A




Witam Mpc Forumowiczów !

 

 

W dzisiejszym poradniku spróbujemy omówić sobie funkcję zabijające graczy w Counter-Strike. 
Głównym powodem, który skłania mnie do napisania tego poradnika, jest gro osób, które nie radzi sobie z wykorzystywaniem tych funkcji, zastosowaniem ich, znalezieniem konkretnej pomocy. 
Omówimy sobie jak wyglądają te funkcję, dlaczego warto jest stosować, do czego ich używać, oraz na jakiej zasadzie one działają. 
Skupimy się na bibliotece HamSandwich.

 

#1 - Funkcja cod_inflict_damage. 

Co widać na pierwszy rzut oka? 

Poza potrzebą dołączenia obowiązkowej biblioteki HamSandwich wymagane jest także dodanie biblioteki CodMod
Opcja wydaje się dobra tylko i wyłącznie na codmody, ale czy na pewno?


 

Przedstawmy sobie po krótcę wybraną funkcję.

Zaczynając od samego początku musimy dołączyć dwie biblioteki, wygląda to w ten sposób ->

 

#include <codmod>
#include <hamsandwich>

w tym momencie dołączyliśmy do naszego przykładowego pluginu dwie potrzebne nam biblioteki aby zastosować funkcję cod_inflict_damage.

Kolejnym krokiem przez nas wykonanym będzie zarejestrowanie całej funkcji a mianowicie "TakeDamage"

wygląda to w ten sposób ->

 

RegisterHam(Ham_TakeDamage, "player", "TakeDamage");

Co dalej?
Przejdźmy do samej interesującej nas funkcji. 

 

public TakeDamage(this, idinflictor, idattacker, Float:damage, damagebits)
{
	
	if(!is_user_connected(idattacker))
		return HAM_IGNORED; 
	
	if(!ma_klase[idattacker])
		return HAM_IGNORED;
		
	
	if(damagebits & DMG_BULLET)
	{	
		new weapon = get_user_weapon(idattacker);
		
		if(weapon == BROŃ)
			cod_inflict_damage(idattacker, this, 5.0, 0.0, idinflictor, damagebits);	
				
		return HAM_HANDLED;
	}
}

Tak wygląda dokładna składnia według dokumentacji. 

cod_inflict_damage(atakujacy, ofiara, Float:obrazenia, Float:czynnik_inteligencji=1.0, byt_uszkadzajacy=0, dodatkowe_flagi=0)

Głównym wykorzystaniem tej funkcji jest zadanie obrażeń z wykorzystaniem dodatkowej inteligencji do tych obrażeń.

Zróbmy to na przykładzie M4A1.


 

if(damagebits & DMG_BULLET)
	{	
		new weapon = get_user_weapon(idattacker);
		
		if(weapon == CSW_M4A1)
			cod_inflict_damage(idattacker, this, 5.0, 0.0, idinflictor, damagebits);	
				
		return HAM_HANDLED;
	}

Ten skrawek odpowiada nam za broń, w naszym przypadku jest to M4A1.

if(weapon == CSW_M4A1)

Tutaj natomiast nie mamy nic innego jak naszą składnie z wykorzystaniem dodatkowych obrażeń "5.0" oraz mnożnika inteligencji 0.0 - czyli inteligencja nie jest wykorzystywana, zostaje samo podniesienie obrażeń o 5.0 (czyli 5 dmg)

cod_inflict_damage(idattacker, this, 5.0, 0.0, idinflictor, damagebits);

Natomiast najczęściej stosuje się powyższą funkcję do różnego rodzaju rakiet, min, dynamitów i tym podobnych rzeczy spotykanych typowo na Call of Duty modzie. 

Mianowicie:

 

cod_inflict_damage(attacker, pid, 55.0, 0.5, ent, (1<<24));

Tutaj mamy wykorzystane dmg, na przykładzie "rakiety"

Rakieta posiada podstawowe obrażenia "55.0" oraz mnożnik inteligencji 0.5 (w tym przypadku 2 punkty inteligencji dają nam 1 punkt obrażeń co w finalnym rozrachunku ukazuje 50 obrażeń końcowych zakładając, ze maksymalnie statystyka inteligencji może zawierać 100pkt)


Cały wygląd funkcji:

public DotykRakiety(ent)
{
	if (!is_valid_ent(ent))
		return;

	new attacker = entity_get_edict(ent, EV_ENT_owner);
	

	new Float:fOrigin[3];
	entity_get_vector(ent, EV_VEC_origin, fOrigin);	
	
	new iOrigin[3];
	for(new i=0;i<3;i++)
		iOrigin[i] = floatround(fOrigin[i]);
	
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY, iOrigin);
	write_byte(TE_EXPLOSION);
	write_coord(iOrigin[0]);
	write_coord(iOrigin[1]);
	write_coord(iOrigin[2]);
	write_short(sprite_blast);
	write_byte(32); 
	write_byte(20); 
	write_byte(0);
	message_end();

	new entlist[33];
	new numfound = find_sphere_class(ent, "player", 190.0, entlist, 32);
	
	for (new i=0; i < numfound; i++)
	{		
		new pid = entlist[i];
		
		if (!is_user_alive(pid) || get_user_team(attacker) == get_user_team(pid))
			continue;
		cod_inflict_damage(attacker, pid, 55.0, 0.5, ent, (1<<24));
	}
	remove_entity(ent);
}	

Natomiast nas interesuje tylko to:

for (new i=0; i < numfound; i++)
	{		
		new pid = entlist[i];
		
		if (!is_user_alive(pid) || get_user_team(attacker) == get_user_team(pid))
			continue;
		cod_inflict_damage(attacker, pid, 55.0, 0.5, ent, (1<<24));
	}

Czyli pętla oraz sprawdzenie czy użytkownik atakuje swój team, oraz czy jest żywy. 
Następnie zadanie konkretnych obrażeń. 


Podsumowując, do czego warto używać cod_inflict_damage? 

Przede wszystkim funkcja stosowana jest w zadawaniu obrażeń poprzez rakiety, dynamity, miny i inne tego typu rzeczy, nie jest przeznaczona do zadawania obrażeń przez broń, natomiast nie jest to błędem gdy użyjemy ją także w tym celu. 
Główną zaletą funkcji cod_inflict_damage jest statystyka inteligencji, która jest tutaj bezpośrednim "zwiększeniem" obrażeń, co przydaje się na Call of Duty modach. 

 

Na zakończenie dodaję zawartość biblioteki HamSandwich.inc oraz CodMod.inc

HamSandwich.inc

 

#if defined _hamsandwich_included
	#endinput
#endif
#define _hamsandwich_included

#include <ham_const>

#if AMXX_VERSION_NUM >= 175
	#pragma reqlib hamsandwich
	#if !defined AMXMODX_NOAUTOLOAD
		#pragma loadlib hamsandwich
	#endif
#else
	#pragma library hamsandwich
#endif

/**
 * Hooks the virtual table for the specified entity class.
 * An example would be: RegisterHam(Ham_TakeDamage, "player", "player_hurt");
 * Look at the Ham enum for parameter lists.
 *
 * @param function		The function to hook.
 * @param EntityClass	The entity classname to hook.
 * @param callback		The forward to call.
 * @param post			Whether or not to forward this in post.
 * @ 				Returns a handle to the forward.  Use EnableHamForward/DisableHamForward to toggle the forward on or off.
 */
native HamHook:RegisterHam(Ham:function, const EntityClass[], const Callback[], Post=0);

/**
 * Hooks the virtual table for the specified entity's class.
 * An example would be: RegisterHam(Ham_TakeDamage, id, "player_hurt");
 * Look at the Ham enum for parameter lists.
 * Note: This will cause hooks for the entire internal class that the entity is
 *       not exclusively for the provided entity.
 *
 * @param function		The function to hook.
 * @param EntityId		The entity classname to hook.
 * @param callback		The forward to call.
 * @param post			Whether or not to forward this in post.
 * @ 				Returns a handle to the forward.  Use EnableHamForward/DisableHamForward to toggle the forward on or off.
 */
native HamHook:RegisterHamFromEntity(Ham:function, EntityId, const Callback[], Post=0);


/**
 * Stops a ham forward from triggering.
 * Use the return value from RegisterHam as the parameter here!
 *
 * @param fwd			The forward to stop.
 */
native DisableHamForward(HamHook:fwd);

/**
 * Starts a ham forward back up.
 * Use the return value from RegisterHam as the parameter here!
 *
 * @param fwd			The forward to re-enable.
 */
native EnableHamForward(HamHook:fwd);

/**
 * Executes the virtual function on the entity.
 * Look at the Ham enum for parameter lists.
 *
 * @param function		The function to call.
 * @param id			The id of the entity to execute it on.
 */
native ExecuteHam(Ham:function, this, any:...);

/**
 * Executes the virtual function on the entity, this will trigger all hooks on that function.
 * Be very careful about recursion!
 * Look at the Ham enum for parameter lists.
 *
 * @param function		The function to call.
 * @param id			The id of the entity to execute it on.
 */
native ExecuteHamB(Ham:function, this, any:...);

/**
 * Gets the return status of the current hook.
 * This is useful to determine what return natives to use.
 *
 * @				The current status of the hook (such as HAM_SUPERCEDE).
 */
native GetHamReturnStatus();

/**
 * Gets the return value of a hook for hooks that return integers or booleans.
 *
 * @param output		The variable to store the value in.
 */
native GetHamReturnInteger(&output);

/**
 * Gets the return value of a hook for hooks that return float.
 *
 * @param output		The variable to store the value in.
 */
native GetHamReturnFloat(&Float:output);

/**
 * Gets the return value of a hook for hooks that return Vectors.
 *
 * @param output		The variable to store the value in.
 */
native GetHamReturnVector(Float:output[3]);

/**
 * Gets the return value of a hook for hooks that return entities.
 *
 * @param output		The variable to store the value in. Will be -1 on null.
 */
native GetHamReturnEntity(&output);

/**
 * Gets the return value of a hook for hooks that return strings.
 *
 * @param output		The buffer to store the string in.
 * @param size			The string size of the buffer.
 */
native GetHamReturnString(output[], size);

/**
 * Gets the original return value of a hook for hooks that return integers or booleans.
 *
 * @param output		The variable to store the value in.
 */
native GetOrigHamReturnInteger(&output);

/**
 * Gets the original return value of a hook for hooks that return floats.
 *
 * @param output		The variable to store the value in.
 */
native GetOrigHamReturnFloat(&Float:output);

/**
 * Gets the original return value of a hook for hooks that return Vectors.
 *
 * @param output		The variable to store the value in.
 */
native GetOrigHamReturnVector(Float:output[3]);

/**
 * Gets the original return value of a hook for hooks that return entities.
 *
 * @param output		The variable to store the value in. -1 on null.
 */
native GetOrigHamReturnEntity(&output);

/**
 * Gets the original return value of a hook for hooks that return strings.
 *
 * @param output		The buffer to store the string in.
 * @param size			The size of the buffer.
 */
native GetOrigHamReturnString(output[], size);


/**
 * Sets the return value of a hook that returns an integer or boolean.
 * This needs to be used in conjunction with HAM_OVERRIDE or HAM_SUPERCEDE.
 *
 * @param value				The value to set the return to.
 */
native SetHamReturnInteger(value);

/**
 * Sets the return value of a hook that returns a float.
 * This needs to be used in conjunction with HAM_OVERRIDE or HAM_SUPERCEDE.
 *
 * @param value				The value to set the return to.
 */
native SetHamReturnFloat(Float:value);

/**
 * Sets the return value of a hook that returns a Vector.
 * This needs to be used in conjunction with HAM_OVERRIDE or HAM_SUPERCEDE.
 *
 * @param value				The value to set the return to.
 */
native SetHamReturnVector(const Float:value[3]);

/**
 * Sets the return value of a hook that returns an entity.  Set to -1 for null.
 * This needs to be used in conjunction with HAM_OVERRIDE or HAM_SUPERCEDE.
 *
 * @param value				The value to set the return to.
 */
native SetHamReturnEntity(value);

/**
 * Sets the return value of a hook that returns a string.
 * This needs to be used in conjunction with HAM_OVERRIDE or HAM_SUPERCEDE.
 *
 * @param value				The value to set the return to.
 */
native SetHamReturnString(const value[]);


/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are integers.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamInteger(which, value);

/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are floats.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamFloat(which, Float:value);

/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are Vectors.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamVector(which, const Float:value[3]);

/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are entities.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamEntity(which, value);

/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are strings.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamString(which, const output[]);

/**
 * Sets a parameter on the fly of the current hook.  This has no effect in post hooks.
 * Use this on parameters that are trace result handles.
 *
 * @param which				Which parameter to change.  Starts at 1, and works up from the left to right.  1 is always "this".
 * @param value				The value to change it to.
 */
native SetHamParamTraceResult(which, tr_handle);


/**
 * Returns whether or not the function for the specified Ham is valid.
 * Things that would make it invalid would be bounds (an older module version
 *  may not have all of the functions), and the function not being found in
 *  the mod's hamdata.ini file.
 *
 * @param function		The function to look up.
 * @				true if the function is valid, false otherwise.
 */
native bool:IsHamValid(Ham:function);

/**
 * This is used to compliment fakemeta's {get,set}_pdata_{int,float,string}.
 * This requires the mod to have the pev and base fields set in hamdata.ini.
 * Note this dereferences memory! Improper use of this will crash the server.
 * This will return an index of the corresponding cbase field in private data.
 * Returns -1 on a null entry.
 *
 * @param id			The entity to examine the private data.
 * @param offset		The windows offset of the data.
 * @param linuxdiff		The linux difference of the data.
 * @param macdiff		The mac os x difference of the data.
 * @				The index of the corresponding pdata field. -1 for none set.
 */
native get_pdata_cbase(id, offset, linuxdiff=5, macdiff=5);

/**
 * This is used to compliment fakemeta's {get,set}_pdata_{int,float,string}.
 * This requires the mod to have the pev and base fields set in hamdata.ini.
 * This will set the corresponding cbase field in private data with the index.
 * Pass -1 to null the entry.
 *
 * @param id			The entity to examine the private data.
 * @param offset		The windows offset of the data.
 * @param value			The index to store, -1 for invalid
 * @param linuxdiff		The linux difference of the data.
 * @param macdiff		The mac os x difference of the data.
 */
native set_pdata_cbase(id, offset, value, linuxdiff=5, macdiff=5);

/**
 * This is similar to the get_pdata_cbase, however it does not dereference memory.
 * This is many times slower than get_pdata_cbase, and this should only be used 
 * for testing and finding of offsets, not actual release quality plugins.
 * This will return an index of the corresponding cbase field in private data.
 * Returns -1 on a null entry. -2 on an invalid entry.
 *
 * @param id			Entry to examine the private data.
 * @param offset		The windows offset of the data.
 * @param linuxdiff		The linux difference of the data.
 * @param macdiff		The mac os x difference of the data.
 * @				The index of the corresponding pdata field, -1 for null, -2 for invalid.
 */
native get_pdata_cbase_safe(id, offset, linuxdiff=5, macdiff=5);




// This is the callback from the module, this handles any fatal errors.
// This will in turn call the "HamFilter(Ham:id, HamError:err, const reason[])" public, if it exists.
// Return PLUGIN_HANDLED from within the HamFilter to stop the plugin from failing.
// Any other return value will fail the plugin.
// You do not need to have a HamFilter, if there is none, all fatal errors will fail the plugin.
// Do not modify this!
public __fatal_ham_error(Ham:id, HamError:err, const reason[])
{
	
	new func=get_func_id("HamFilter", -1);
	new bool:fail=true;
	
	if (func != -1 && callfunc_begin_i(func, -1)==1)
	{
		callfunc_push_int(_:id);
		callfunc_push_int(_:err);
		callfunc_push_str(reason, false);
		if (callfunc_end()==PLUGIN_HANDLED)
		{
			fail=false;
		}
	}
	if (fail)
	{
		set_fail_state(reason);
	}
	
}

 


CodMod.inc

 

#if defined _codmod_included
  #endinput
#endif
#define _codmod_included

#define COD_CONTINUE 0

#define COD_STOP 4

#define DMG_CODSKILL (1<<31)



native cod_get_user_xp(id);
/*------------------------------
Zwraca doswiadczenie gracza
------------------------------*/

native cod_get_user_level(id);
/*------------------------------
Zwraca poziom gracza
------------------------------*/


native cod_set_user_xp(id, wartosc);
/*------------------------------
Ustawia doswiadczenie gracza
------------------------------*/


native cod_get_user_class(id);
/*------------------------------
Zwraca klase gracza
------------------------------*/


native cod_set_user_class(id, klasa, zmien=0);
/*------------------------------
Ustawia klase gracza, 
jezeli zmien=1 zmienia ja natychmiast
------------------------------*/


native cod_get_user_perk(id, &wartosc=0);
/*------------------------------
Zwraca perk gracza, 
oraz przypisuje zmiennej wartosc wartosc perku
------------------------------*/


native cod_set_user_perk(id, perk, wartosc=-1, pokaz_info=1);
/*------------------------------
Ustawia perk gracza. 
Jezeli wartosc = -1,
wartosc perku bedzie losowa.
Jezeli perk = -1 perk
bedzie losowy
------------------------------*/


native cod_get_user_health(id, zdrowie_zdobyte=1, zdrowie_klasy=1, zdrowie_bonusowe=1);
/*------------------------------
Zwraca punkty statystyki zdrowie
------------------------------*/


native cod_set_user_bonus_health(id, wartosc);
/*------------------------------
Ustawia dodatkowe punkty statystyki zdrowie
------------------------------*/


native cod_get_user_intelligence(id, inteligencja_zdobyta=1, inteligencja_klasy=1, inteligencja_bonusowa=1);
/*------------------------------
Zwraca punkty statystyki inteligencja
------------------------------*/


native cod_set_user_bonus_intelligence(id, wartosc);
/*------------------------------
Ustawia dodatkowe punkty statystyki inteligencja
------------------------------*/


native cod_get_user_trim(id, kondycja_zdobyta=1, kondycja_klasy=1, kondycja_bonusowa=1);
/*------------------------------
Zwraca punkty statystyki kondycja
------------------------------*/


native cod_set_user_bonus_trim(id, wartosc);
/*------------------------------
Ustawia dodatkowe punkty statystyki kondycja
------------------------------*/


native cod_get_user_stamina(id, wytrzymalosc_zdobyta=1, wytrzymalosc_klasy=1, wytrzymalosc_bonusowa=1);
/*------------------------------
Zwraca punkty statystyki wytrzymalosc
------------------------------*/


native cod_set_user_bonus_stamina(id, wartosc);
/*------------------------------
Ustawia dodatkowe punkty statystyki wytrzymalosc
------------------------------*/


native cod_inflict_damage(atakujacy, ofiara, Float:obrazenia, Float:czynnik_inteligencji=1.0, byt_uszkadzajacy=0, dodatkowe_flagi=0);
/*------------------------------
Zadaje obrazenia z uwzglednieniem inteligencji
------------------------------*/


native cod_get_perkid(const nazwa_perku[]);
/*------------------------------
Zwaca numer perku o podanej nazwie
------------------------------*/


native cod_get_perks_num();
/*------------------------------
Zwaca ilosc perkow
------------------------------*/


native cod_get_perk_name(perk, Return[], len);
/*------------------------------
Kopiuje nazwe perku do Return
------------------------------*/


native cod_get_perk_desc(perk, Return[], len);
/*------------------------------
Kopiuje opis perku do Return
------------------------------*/


native cod_get_classid(const nazwa_klasy[]);
/*------------------------------
Zwaca numer klasy o podanej nazwie
------------------------------*/


native cod_get_classes_num();
/*------------------------------
Zwaca ilosc klas
------------------------------*/

native cod_get_class_name(perk, Return[], len);
/*------------------------------
Kopiuje nazwe klasy do Return
------------------------------*/


native cod_get_class_desc(perk, Return[], len);
/*------------------------------
Kopiuje opis klasy do Return
------------------------------*/


native cod_give_weapon(id, bron);
/*------------------------------
Daje okreslona bron oraz pozwala na jej posiadanie
------------------------------*/


native cod_take_weapon(id, bron);
/*------------------------------
Zabiera okreslona bron oraz zabrania jej posiadania
------------------------------*/


native cod_set_user_shield(id, wartosc);
/*------------------------------
Ustawia tarcze gracza. 
------------------------------*/


native cod_set_user_nightvision(id, wartosc);
/*------------------------------
Ustawia noktowizor gracza. 
------------------------------*/


native cod_register_perk(const nazwa[], const opis[], min_wartosc=0, max_wartosc=0);
/*------------------------------
Rejestruje nowy perk oraz zwraca jego numer
------------------------------*/


native cod_register_class(const nazwa[], const opis[], bronie, punkty_zdrowia, punkty_kondycji, punkty_inteligencji, punkty_wytrzymalosci);
/*------------------------------
Rejestruje nowa klase oraz zwraca jej numer
------------------------------*/	


native cod_get_level_xp(poziom);
/*------------------------------
Zwraca ilosc potrzebnego doswiadczenia do przejscia danego poziomu
------------------------------*/


forward cod_perk_changed(id, perk);
/*------------------------------
Forward wysylany do wszystkich pluginow w momencie zmiany perku
------------------------------*/


forward cod_class_changed(id, klasa);
/*------------------------------
Forward wysylany do wszystkich pluginow w momencie zmiany klasy
------------------------------*/


forward cod_perk_enabled(id, wartosc, perk);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowany jest perk w momencie aktywacji
------------------------------*/


forward cod_perk_disabled(id, perk);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowany jest perk w momencie dezaktywacji
------------------------------*/


forward cod_perk_used(id);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowany jest perk w momencie uzycia perku
------------------------------*/


forward cod_class_enabled(id, klasa);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowana jest kasa w momencie aktywacji
------------------------------*/


forward cod_class_disabled(id, klasa);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowana jest kasa w momencie dezaktywacji
------------------------------*/

forward cod_class_skill_used(id);
/*------------------------------
Forward wysylany do pluginu z ktorego zarejestrowana jest kasa w momencie uzycia umiejetnosci klasy
------------------------------*/

 

 

 

 

#2 - Funkcja SetHamParamFloat

 

 

 

Jedna z najciekawszych funkcji, najczęściej zdecydowanie przeze mnie stosowana i polecana. 
Jednakże aby ją stosować obowiązkowe jest ustawienie post na 0

 

Tak wygląda dokładna składnia według dokumentacji. 

SetHamParamFloat(which, Float:value)

gdzie:

which - który z parametrów licząc od lewej ma być zmieniony
Float:value - wartość na jaką ma być zmieniony parametr

Przykładowym prostym sposobem użycia tej funkcji jest: 

if(weapon == CSW_SCOUT && damage > 20.0)
			SetHamParamFloat(4, float(get_user_health(this)*4));

w tym przypadku, broń jaką operujemy to scout. Broń ta ma natychmiast zabić gracza przez jakikolwiek strzał w niego, dodatkowo na końcu dodany jest mnożnik razy 4, dla pewności gdyby wystąpił jakiś "opór" w postaci kevlaru, wytrzymałości itp.

if(damagebits & DMG_HEGRENADE)
		SetHamParamFloat(4, float(get_user_health(this)*4));

natomiast tutaj naszą bronią jest granat, który w momencie wybuchu ma mieć taki sam skutek jak w przypadku powyżej. 

if(weapon == CSW_M4A1 && damage > 20.0)
                         SetHamParamFloat(4, 1.0)

tutaj natomiast nasza broń ma zadawać takie obrażenia finalnie. (1.0)

 

 

 

 

 

#3 - Funkcja KillPlayer

Funkcja bardzo ciekawa i interesująca szczególnie za sprawą swoich zalet jakich jest dosyć pokaźna ilość. 
Głównymi zaletami jest jej niezawodność, poprawnie wyświetla "ikony" zabicia, dodaje nam odpowiednio zabicie do rankingu oraz tablicy ogólnych wyników, ustawia konkretny byt jakim zabijamy, poprawnie pokazuje część ciała w jakiej wykonało się zabicie, nic tylko używać. Jedyną "wadą" tej funkcji jest fakt, że nie pokazuje zadanych obrażeń.

Napisałem celowo "wadą" gdyż to tylko "wada" wizualna, dla osób, które lubią takie rzeczy jak pokazywanie obrażeń natomiast jest to też dobra sprawa pod względem niezawodności ponieważ żaden plugin modyfikujący obrażenia nie przerwie działania tej funkcji, a więc na spory plus ! 

Cały wygląd funkcji:

KillPlayer(id,inflictor,attacker,weapon,body,shouldgib,damagebits)
{
	if(weapon > 30 || !is_user_alive(id) || !is_user_connected(attacker))	return
	
	const GrenadeWeapon = 1<<CSW_HEGRENADE | 1<<CSW_C4 | 1<<CSW_SMOKEGRENADE | 1<<CSW_FLASHBANG
	const m_LastHitGroup = 75
	const m_bitsDamageType = 76
	const m_fHasTakenHighDamage = 107
	static DeathMsgId
	new msgblock,weaponname[32],effect
	if (!DeathMsgId)	DeathMsgId = get_user_msgid("DeathMsg")
	
	set_pdata_int(id,m_LastHitGroup,body,5)
	set_pdata_int(id,m_bitsDamageType,damagebits,5)
	set_pdata_int(id,m_fHasTakenHighDamage,1,5)
	set_pev(id,pev_dmg_inflictor,inflictor)
	msgblock = get_msg_block(DeathMsgId)
	set_msg_block(DeathMsgId, BLOCK_SET)
	ExecuteHamB(Ham_Killed,id,attacker,shouldgib)
	set_msg_block(DeathMsgId, msgblock)
	if(is_user_alive(id))	return
	
	effect = pev(id,pev_effects)
	if(effect & 128)	set_pev(id,pev_effects,effect-128)
	
	new len
	if(get_weaponname(weapon,weaponname,31))
	{
		if(~GrenadeWeapon & 1<<weapon) len = 7
		else weaponname = "grenade"
	}
	else if(weapon == 2)	weaponname = "tracktrain"
	else	weaponname = "world"
	
	emessage_begin(MSG_ALL, DeathMsgId)
	ewrite_byte(attacker)
	ewrite_byte(id)
	ewrite_byte(body == HIT_HEAD ? 1:0)
	ewrite_string(weaponname[len])
	emessage_end()
}

Parametry:

• id - osoba, którą będziemy usiłowali zabić. [1 - 32]
• inflictor - byt którym zabijamy.
• attacker - obiekt, który ma zostać zabity. [1 - 32]
• weapon - oznaczenie broni, która będzie użyta.
• body - część ciała w którą trafiliśmy.
• shouldgib - sposób w jaki ma zostać pokazane ciało po śmierci [GIB_*]
• damagebits - spowodowanie śmierci [DMG_*]

Przykładowy sposób wykorzystania funkcji:

KillPlayer(2,X,1,CSW_HEGRENADE,HIT_GENERIC,0,1<24)

Gracz o ID = 1, zabija gracza o ID = 2 za pomocą granatu o ID = X.

 

Podsumowując, do czego warto używać KillPlayer? 

 

Przede wszystkim stawiamy tutaj na niezawodność ponad wszystko, uniwersalizm oraz kompatybilność, ponieważ śmierć gracza w tej funkcji możemy wyłapać czy to przez Ham_Killed czy to przez event DeathMsg także funkcja jak najbardziej znakomita.

yyj6bCh.png
"Żaden etyczny inżynier oprogramowania nie zgodzi się napisać procedury zniszczBagdad.
Jego poczucie etyki domaga się, aby napisał procedurę
zniszczMiasto, a Bagdad przekazał jako parametr"
 
~
Nathaniel Borenstein 

  • 2 tygodnie później...
Opublikowano

Cały kod KillPlayer zerżnięty z a*xx.pl  xD

procz tego poradnik bardzo przydatny. szkoda, ze tak malo osob na tym forum zagląda do tego działu.

Jeśli odpowiadasz mi, bądź masz do mnie pytanie, oznacz mnie. Wtedy masz pewność, że Ci odpowiem.


7ltRHSP.png


 


Mentoruje w zarabianu przez internet: subsms, ppa, ppi, ppd, skracanie

  • 2 tygodnie później...
  • 3 tygodnie później...
Opublikowano

Cały kod KillPlayer zerżnięty z a*xx.pl  xD

procz tego poradnik bardzo przydatny. szkoda, ze tak malo osob na tym forum zagląda do tego działu.

Nie tyle zerżnięty co z prywatnych zbiorów od autora otrzymany, akurat z nim mam kontakt i często korzystam z jego rozwiązań odnośnie KillPlayer, dlatego postanowiłem skorzystać z jego pomocy przy tym, gdyż osobiście z tego nie korzystam a sprawa świetna. 

Tylko czasem sprites nawala. 

 

 

 

Słabo ..

Słabo ..

Słabo ..

Słabo ..

Spam..

 

Spam.. 

 

Spam..

 

Spam..

 

 

widzialem juz to gdzies, kiedys ale przydatne

 

Gdzie? 

Bo akurat pisany od zera przeze mnie :) 

 

Mogłeś chociaż źródło napisać, co do poradnika przydatne. 

Okej. 

Nasz klient nasz Pan.

 

www.Głowa-LosTa.com / MPCForum.pl.

yyj6bCh.png
"Żaden etyczny inżynier oprogramowania nie zgodzi się napisać procedury zniszczBagdad.
Jego poczucie etyki domaga się, aby napisał procedurę
zniszczMiasto, a Bagdad przekazał jako parametr"
 
~
Nathaniel Borenstein 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...