Eventy (wydarzenia) SourceMod (część I)
Kowalsky
07.05.2015
HookEvent("player_death", Event_PlayerDeath);
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id zabitego new attacker = GetClientOfUserId(GetEventInt(event, "attacker")); // id atakujacego new assister = GetClientOfUserId(GetEventInt(event, "assister")); // id asystujacego new bool:headshot = GetEventBool(event, "headshot"); // czy headshot (1), czy nie (0) decl String:weapon[64] GetEventString(event, "weapon", weapon, sizeof(weapon)) // pobieranie nazwy broni do stringu }2. Otrzymywanie obrażeń:
HookEvent("player_hurt", Event_PlayerHurt);
public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id otrzymujacego obrazenia new attacker = GetClientOfUserId(GetEventInt(event, "attacker")); // id zadajacego obrazenia new health = GetEventInt(event, "health"); // ile HP pozostalo ofiarze new armor = GetEventInt(event, "armor"); // ile armoru pozostalo ofiarze decl String:weapon[64] GetEventString(event, "weapon", weapon, sizeof(weapon)) // pobieranie nazwy broni do stringu new dmg_health = GetEventInt(event, "dmg_health")); // ile HP zadal atak? new dmg_armor = GetEventInt(event, "dmg_armor")); // ile armoru zabral atak? new hitgroup = GetEventInt(event, "hitgroup")); // gdzie zostaly zadane obrazenia (hitbox) }3. Odrodzenia gracza:
HookEvent("player_spawned", Event_OnPlayerSpawned);
public Event_OnPlayerSpawned(Handle:event, const String:name[], bool:dontBroadcast) { new client = GetClientOfUserId(GetEventInt(event, "userid")); // id odrodzonego new bool:inrestart= GetEventBool(event, "inrestart"); // Czy przez restart rundy/gry? }4. Zaczęcie podkładania bomby:
HookEvent("bomb_beginplant", Event_BombBeginPlant);
public Event_BombBeginPlant(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id podkladajacego new site = GetEventInt(event, "site"); // id bobsite na ktorym zostanie podlozona bomba }5. Przerwanie podkładania bomby:
HookEvent("bomb_abortplant", Event_BombAbortPlant);
public Event_BombAbortPlant(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id podkladajacego new site = GetEventInt(event, "site"); // id bobsite na ktorym zostala podlozona bomba }6. Bomba podłożona:
HookEvent("bomb_planted", Event_BombPlanted);
public Event_BombPlanted(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id podkladajacego new site = GetEventInt(event, "site"); // id bobsite na ktorym zostala podlozona bomba }7. Bomba rozbrojona:
HookEvent("bomb_defused", Event_BombDefused);
public Event_BombDefused(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id rozbrajajacego new site = GetEventInt(event, "site"); // id bobsite na ktorym zostala podlozona bomba }8. Bomba wybuchła:
HookEvent("bomb_exploded", Event_BombExploded);
HookEvent("bomb_exploded", Event_BombExploded); public Event_BombExploded(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id podkladajacego new site = GetEventInt(event, "site"); // id bobsite na ktorym zostala podlozona bomba }9. Bomba upuszczona:
HookEvent("bomb_dropped", Event_BombDropped); public Event_BombDropped(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id upuszczajacego bombe }10. Bomba podniesiona:
HookEvent("bomb_pickup", Event_BombPickup);
public Event_BombPickup(Handle:event, const String:name[], bool:dontBroadcast) { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id podnoszacego bombe }
grankee
28.01.2016
Po co to wszystko tłumaczyć? Zasada jest prosta: szukamy danego eventu na tej stronie
https://wiki.alliedm...ffensive_Events
następnie patrzymy jakie dany event ma parametry.
Dla przykładu użyjemy eventu śmierci gracza:
player_death
Name: player_death Structure: short userid user ID who died short attacker user ID who killed short assister user ID who assisted in the kill string weapon weapon name killer used string weapon_itemid inventory item id of weapon killer used string weapon_fauxitemid faux item id of weapon killer used string weapon_originalowner_xuid bool headshot singals a headshot short dominated did killer dominate victim with this kill short revenge did killer get revenge on victim with this kill short penetrated number of objects shot penetrated before killing target
i teraz:
public OnPluginStart() { HookEvent("player_death", Event_PlayerDeath);//rejestrujemy event, pierwsze to nazwa eventu //ze strony wiki z eventami podanej wyżej, a drugie to nazwa funkcji, jaka ma być wykonana //kiedy event się wydarzy. } public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)//pierwsze to uchwyt eventu, potrzebny do pobrania argumentów, //drugie to nazwa eventu, w tym przypadku player_death //trzecie to hmmm? podpowie ktoś? { new userid = GetClientOfUserId(GetEventInt(event, "userid")); // id zabitego new attacker = GetClientOfUserId(GetEventInt(event, "attacker")); // id atakujacego new assister = GetClientOfUserId(GetEventInt(event, "assister")); // id asystujacego new bool:headshot = GetEventBool(event, "headshot"); // czy headshot (1), czy nie (0) decl String:weapon[64] GetEventString(event, "weapon", weapon, sizeof(weapon)) // pobieranie nazwy broni do stringu }
Przy każdym parametrze eventu mamy podany jego typ: short, long, float, string, bool...
Dla parametru string pobieramy wartość do zmiennej string jak w przykładzie:
String:weapon[64] GetEventString(event, "weapon", weapon, sizeof(weapon)) //gdzie: event - to uchwyt eventu przekazany jako parametr funkcji "weapon" - nazwa elementu struktury eventu podana przy tym evencie na w/w stronie, np.: struktura eventu smierci ma takie elementy jak wymieniłem wyzej podając skład struktury weapon - to zmienna string zadeklarowana wyzej sizeof(weapon) - to rozmiar tejże zmiennej
Dla reszty parametrów pobieramy jak w przykładzie wyżej, gdzie wyszczególnione są wszystkie elementy.
Uwaga: jeśli pobieramy czyjeś id z eventu musimy użyć funkcji
GetUserOfUserId()
ponieważ samo
GetEventInt(event, "userid")
zwraca nam userid, który nie jest w żadnym razie tym samym co id.
Aby pobrać id czyli numer entu gracza, należy użyć funkcji podanej wyżej, przykład:
new userid = GetClientOfUserId(GetEventInt(event, "userid"));
Myślę, że bardziej łopatologicznie i wędkowo się nie da.
Użytkownik grankee edytował ten post 28.01.2016 21:05