Stránka 1 z 3

[POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 03 zář 2019 20:12
od RayCodeCSC
Zdravím, potreboval by som pomôcť so scriptingom v jazyku Pawn pre CS 1.6.

Chcem nascriptovať menu, v ktorom budú položky napr. Sila 1, Sila 2 atď... a každá táto položka bude dávať iný damage. Napr. Sila 1, keď si ju hráč kúpi, ňastaví mu to damage na 70.0.

Tu je script:

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>

new float:dmgSet = 50.0
new float:dmgSet2 = 230.0

public plugin_init()
{
	register_plugin("VIP Shop", "1.0", "RayCodeCSC")
	register_clcmd("say /vipshop", "vip_menu")
	register_clcmd("say /vs", "vip_menu")

	RegisterHam(Ham_TakeDamage, "player", "tkDamage")
	RegisterHam(Ham_TakeDamage, "player", "tkDamage2")
}

public vip_menu(id)
{
	new m = menu_create("Vyber si z menu:", "vip_menu_selection")

	menu_additem(m, "Sila 1")
	menu_additem(m, "Sila 2")

	menu_display(id, m)
}

vip_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			tkDamage(dmgSet)
		}

		case 1:
		{
			tkDamage2(dmgSet2)
		}
	}
}

public tkDamage(victim, attacker, inflictor, dmgSet)
{
	if(get_player_weapon(attacker) == CSW_KNIFE)
	{
		SetHamParamFloat(4, damage = dmgSet)
	}
}

public tkDamage2(victim, attacker, inflictor, dmgSet)
{
	if(get_player_weapon(attacker) == CSW_KNIFE)
	{
		SetHamParamFloat(4, damage = dmgSet2)
	}
}
Napíše mi to tieto chyby pri kompilovaní:

Kód: Vybrat vše

test.sma(10) : warning 213: tag mismatch
test.sma(53) : error 017: undefined symbol "get_player_weapon"
test.sma(55) : error 017: undefined symbol "damage"
test.sma(55) : warning 215: expression has no effect
test.sma(55) : error 001: expected token: ";", but found ")"
test.sma(55) : error 029: invalid expression, assumed zero
test.sma(55) : fatal error 107: too many error messages on one line
Takže otázka je: Ako sa pracuje s premennými? A ako mám teda zavolať funkciu?

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 03 zář 2019 21:44
od cruddYsek
Ahoj , děláš to moc komplikovaně , dělej vždy jeden Ham a určování dmg si dej třeba přes proměnné
Tady to máš opravené , jsou tam asi jen 3 warny :D

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>

new dmgSet_Activated[ 33 ]
new dmgSet2_Activated[ 33 ]
new dmgSet = 50
new dmgSet2 = 230

public plugin_init()
{
	register_plugin("VIP Shop", "1.0", "RayCodeCSC")
	register_clcmd("say /vipshop", "vip_menu")
	register_clcmd("say /vs", "vip_menu")

	RegisterHam(Ham_TakeDamage, "player", "Damage")
}

public vip_menu(id)
{
	new m = menu_create("Vyber si z menu:", "vip_menu_selection")

	menu_additem(m, "Sila 1")
	menu_additem(m, "Sila 2")

	menu_display(id, m)
}

public vip_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}
	switch(item)
	{
		case 0:
		{
			dmgSet_Activated[ id ] = 1
			dmgSet2_Activated[ id ] = 0
		}

		case 1:
		{
			dmgSet2_Activated[ id ] = 1
			dmgSet_Activated[ id ] = 0
		}
	}
	return PLUGIN_HANDLED;
}

public Damage( victim, inflictor, attacker, Float:damage, damage_bits, id )
{
	new weapon[ 33 ]
	weapon[ id ] = get_user_weapon(attacker)
	
	if(weapon[ id ] == CSW_KNIFE)
	{
		if(dmgSet_Activated[ id ] == 1)
		{
			SetHamParamFloat(4, dmgSet);
		}
		else if(dmgSet2_Activated[ id ] == 1)
		{
			SetHamParamFloat(4, dmgSet2);
		}
	}
}

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 03 zář 2019 23:00
od RayCodeCSC
Ďakujem ti :). Môžeš mi ešte vysvetliť, ktorá funckia čo robí? Napr. pri premennej si uvideol číslo 33, prečo práve 33 a nie napr. 5?

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 02:02
od RayCodeCSC
Mám tu pre teba ešte jednu úlohu.

Snažil som sa urobiť si Shop s vlastnými modelami zbraní. Ale nejako mi to nefunguje. Modely som stiahol z jedného pluginu, takže modely sú funkčné. Chyba je teda niekde v scripte.

Script:

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

new SetModelMoto[33] = 0
new SetModelMachete[33] = 0

new isDamaged_model_Moto[33] = 0
new isDamaged_model_Machete[33] = 0

new MotoValueDamage = 9999999
new MacheteValueDamage = 60

new p_ModelMotor[] = "models/shopper/motorovka/motorovka.mdl"
new v_ModelMotor2[] = "models/shopper/motorovka/motorovka2.mdl"

new p_ModelMachete[] = "models/shopper/machete/machete.mdl"
new v_ModelMachete2[] = "models/shopper/machete/machete2.mdl"

public plugin_init()
{
	register_plugin("Shop", "1.0", "RayCodeCSC")

	register_clcmd("say /shopper", "shop_menu")

	register_event("CurWeapon", "new_models", "be", "1=1")

	RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public plugin_precache()
{
	precache_model(p_ModelMotor)
	precache_model(v_ModelMotor2)

	precache_model(p_ModelMachete)
	precache_model(v_ModelMachete2)
}

public shop_menu(id)
{
	new menu = menu_create("Vyber si z menu:", "shop_menu_selection")

	menu_additem(menu, "Maceta")
	menu_additem(menu, "Motorova pila")

	menu_display(id, menu)
}

public shop_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			give_item(id, "weapon_knife")
			SetModelMachete[id] == 1
			isDamaged_model_Machete[id] == 1
		}

		case 1:
		{
			give_item(id, "weapon_knife")
			SetModelMoto[id] == 1
			isDamaged_model_Moto[id] == 1
		}
	}
}

public new_models(id)
{
	if(read_data(2) == CSW_KNIFE)
	{
		if(SetModelMoto[id] == 1)
		{
			set_pev(id, pev_viewmodel2, v_ModelMotor2)
			set_pev(id, pev_weaponmodel2, p_ModelMotor)
		}
		else if(SetModelMachete[id] == 1)
		{
			set_pev(id, pev_viewmodel2, v_ModelMachete2)
			set_pev(id, pev_weaponmodel2, p_ModelMachete)
		}
	}
}

public isDamaged(victim, attacker, inflictor, Float:damage, damage_bits, id)
{
	if(get_user_weapon(id) == CSW_KNIFE)
	{
		if(isDamaged_model_Moto[id] == 1)
		{
			SetHamParamFloat(4, MotoValueDamage)
		}
		else if(isDamaged_model_Machete[id] == 1)
		{
			SetHamParamFloat(4, MacheteValueDamage)
		}
	}
}
Ešte dodám: Kompilácia prebehla v poriadku (len na pár warnou).

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 18:06
od cruddYsek
Ahoj , zkus tohle

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

new SetMoto[33] = 0
new SetMachete[33] = 0

new MotoValueDamage = 9999999
new MacheteValueDamage = 60

new p_ModelMotor[] = "models/shopper/motorovka/motorovka.mdl"
new v_ModelMotor2[] = "models/shopper/motorovka/motorovka2.mdl"

new p_ModelMachete[] = "models/shopper/machete/machete.mdl"
new v_ModelMachete2[] = "models/shopper/machete/machete2.mdl"

public plugin_init()
{
	register_plugin("Shop", "1.0", "RayCodeCSC")

	register_clcmd("say /shopper", "shop_menu")

	register_event("CurWeapon", "new_models", "be", "1=1")

	RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public plugin_precache()
{
	precache_model(p_ModelMotor)
	precache_model(v_ModelMotor2)

	precache_model(p_ModelMachete)
	precache_model(v_ModelMachete2)
}

public shop_menu(id)
{
	new menu = menu_create("Vyber si z menu:", "shop_menu_selection")

	menu_additem(menu, "Maceta")
	menu_additem(menu, "Motorova pila")

	menu_display(id, menu)
}

public shop_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			give_item(id, "weapon_knife")
			SetMachete[id] = 1
			SetMoto[id] = 0
		}

		case 1:
		{
			give_item(id, "weapon_knife")
			SetMoto[id] = 1
			SetMachete[id] = 0
		}
	}
	return PLUGIN_HANDLED;
}

public new_models(id)
{
	new wpid = get_user_weapon( id );
	
	switch( wpid )
	{
		case CSW_KNIFE:
		{
			if(SetMoto[id] == 1)
			{
				set_pev(id, pev_viewmodel2, v_ModelMotor2)
				set_pev(id, pev_weaponmodel2, p_ModelMotor)
			}
			else if(SetMachete[id] == 1)
			{
				set_pev(id, pev_viewmodel2, v_ModelMachete2)
				set_pev(id, pev_weaponmodel2, p_ModelMachete)
			}
		}
	}
}

public isDamaged(victim, attacker, inflictor, Float:damage, damage_bits, id)
{
	if(get_user_weapon(id) == CSW_KNIFE)
	{
		if(SetMoto[id] == 1)
		{
			SetHamParamFloat(4, MotoValueDamage);
		}
		else if(SetMachete[id] == 1)
		{
			SetHamParamFloat(4, MacheteValueDamage);
		}
	}
}
Zkus si přejmenovat modely třeba na v_motorovka , p_motorovka , popřípadě zčekni konzoli

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 19:15
od RayCodeCSC
Skúsim, ďakujem.

A môžeš mi prosím ťa vysvetli´t tie výrazy čo znamenajú? Napr. prečo sa používa [33], a nie napr. [11], na čo slúži switch (resp. kedy ho možno použiť) atď....?

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 19:27
od Javierko
Jde to trochu i modernizovat, abys to nemusel všechno ručně vypisovat... (untested)
V SourcePawnu by to kompletně šlo dělat dynamicky.

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

enum _:g_eModels
{
	Model_Motor,
	Model_Machete,
}

enum _:g_eModelInfo
{
	p_Model[64],
	v_Model[64],
	Float:Model_Damage
}

new const g_szModelList[g_eModels][g_eModelInfo] =
{
	{ "models/shopper/motorovka/motorovka.mdl", "models/shopper/motorovka/motorovka2.mdl", 9999.0 },
	{ "models/shopper/machete/machete.mdl", "models/shopper/machete/machete2.mdl", 60.0 }
}

new g_iPlayerWeapon[33]

public plugin_init()
{
	register_plugin("Shop", "1.0", "RayCodeCSC")

	register_clcmd("say /shopper", "shop_menu")

	register_event("CurWeapon", "new_models", "be", "1=1")

	RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public plugin_precache()
{
	for(new i = 0; i < sizeof(g_szModelList); i++)
	{
		precache_model(g_szModelList[i][p_Model])
		precache_model(g_szModelList[i][v_Model])
	}
}

public shop_menu(id)
{
	new menu = menu_create("Vyber si z menu:", "shop_menu_selection")

	menu_additem(menu, "Maceta")
	menu_additem(menu, "Motorova pila")

	menu_display(id, menu)
}

public shop_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			give_item(id, "weapon_knife")
			g_iPlayerWeapon[id] = Model_Machete
		}

		case 1:
		{
			give_item(id, "weapon_knife")
			g_iPlayerWeapon[id] = Model_Motor
		}
	}
	
	return PLUGIN_HANDLED;
}

public new_models(id)
{
	new wpid = get_user_weapon(id)
	
	switch(wpid)
	{
		case CSW_KNIFE:
		{
			set_pev(id, pev_viewmodel2, g_szModelList[g_iPlayerWeapon[id]][v_Model])
			set_pev(id, pev_weaponmodel2, g_szModelList[g_iPlayerWeapon[id]][p_Model])
		}
	}
}

public isDamaged(victim, attacker, inflictor, Float:damage, damage_bits, id)
{
	if(get_user_weapon(id) == CSW_KNIFE)
	{
		SetHamParamFloat(4, g_szModelList[g_iPlayerWeapon[id]][Model_Damage])
	}
}

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 19:51
od RayCodeCSC
Fu... tak to asi radšej zostanem u premenných, a budem to ručne vypisovať :P. Tomu spôsobu s premennými aspoň trocha chápem, ako to funguje, ale tomu tvojmu už vôbec nie :D.

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 21:01
od RayCodeCSC
Tak som teda vyskúšal to, čo mi napísal cruddYsek, a nefunguje to. Keď som prehodil modeli zbraní (zmenil názvy a cestu), tak po pripojení na Server mi to model zmenilo, ale na to menu to vôbec nereaguje. Takže keď stlačím napr. "1. Motorova pila", tak sa nič nestane. Trocha som upravil kód, pretože predtým mi to hádzalo 7 warning-ou, po úprave sú tam len 3. Osobne si myslím, že ten môj kód nie je zlý, a že sa dá použiť aj ten. Takže chyba bude niekde buď v register_event, alebo sa tam menia modeli úplne inak.

Držal som sa podľa tohoto návodu.

Aktuálni script:

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

new SetModelMoto[33] = 0
new SetModelMachete[33] = 0

new isDamaged_model_Moto[33] = 0
new isDamaged_model_Machete[33] = 0

new MotoValueDamage = 9999999
new MacheteValueDamage = 60

new const p_ModelMotor[] = "models/shopper/motorovka/motorovka.mdl"
new const v_ModelMotor2[] = "models/shopper/motorovka/motorovka2.mdl"

new const p_ModelMachete[] = "models/shopper/machete/machete.mdl"
new const v_ModelMachete2[] = "models/shopper/machete/machete2.mdl"

public plugin_init()
{
	register_plugin("Shop", "1.0", "RayCodeCSC")

	register_clcmd("say /shopper", "shop_menu")

	register_event("CurWeapon", "new_models", "be", "1=1")

	RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public plugin_precache()
{
	precache_model(p_ModelMotor)
	precache_model(v_ModelMotor2)

	precache_model(p_ModelMachete)
	precache_model(v_ModelMachete2)
}

public shop_menu(id)
{
	new menu = menu_create("Vyber si z menu:", "shop_menu_selection")

	menu_additem(menu, "Maceta")
	menu_additem(menu, "Motorova pila")

	menu_display(id, menu)
}

public shop_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			give_item(id, "weapon_knife")
			SetModelMachete[id] = 1
			isDamaged_model_Machete[id] = 1
		}

		case 1:
		{
			give_item(id, "weapon_knife")
			SetModelMoto[id] = 1
			isDamaged_model_Moto[id] = 1
		}
	}
}

public new_models(id)
{
	if(read_data(2) == CSW_KNIFE)
	{
		if(SetModelMoto[id] == 1)
		{
			set_pev(id, pev_viewmodel2, p_ModelMotor)
			set_pev(id, pev_weaponmodel2, v_ModelMotor2)
		}
		else if(SetModelMachete[id] == 1)
		{
			set_pev(id, pev_viewmodel2, p_ModelMachete)
			set_pev(id, pev_weaponmodel2, v_ModelMachete2)
		}
	}
}

public isDamaged(victim, attacker, inflictor, Float:damage, damage_bits, id)
{
	if(get_user_weapon(id) == CSW_KNIFE)
	{
		if(isDamaged_model_Moto[id] == 1)
		{
			SetHamParamFloat(4, MotoValueDamage)
		}
		else if(isDamaged_model_Machete[id] == 1)
		{
			SetHamParamFloat(4, MacheteValueDamage)
		}
	}
}

Re: [POMOC] Ako scriptovať v jazyku Pawn?

Napsal: 04 zář 2019 21:29
od Javierko

Kód: Vybrat vše

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <fakemeta>

enum _:g_eModels
{
	Model_Motor,
	Model_Machete,
}

enum _:g_eModelInfo
{
	p_Model[64],
	v_Model[64],
	Float:Model_Damage
}

new const g_szModelList[g_eModels][g_eModelInfo] =
{
	{ "models/shopper/motorovka/motorovka.mdl", "models/shopper/motorovka/motorovka2.mdl", 9999.0 },
	{ "models/shopper/machete/machete.mdl", "models/shopper/machete/machete2.mdl", 60.0 }
}

new g_iPlayerWeapon[33]
new bool:g_bSelected[33]

public plugin_init()
{
	register_plugin("Shop", "1.0", "RayCodeCSC")

	register_clcmd("say /shopper", "shop_menu")

	register_event("CurWeapon", "new_models", "be", "1=1")

	RegisterHam(Ham_TakeDamage, "player", "isDamaged")
}

public client_connect(id)
{
	g_bSelected[id] = false
}

public plugin_precache()
{
	for(new i = 0; i < sizeof(g_szModelList); i++)
	{
		precache_model(g_szModelList[i][p_Model])
		precache_model(g_szModelList[i][v_Model])
	}
}

public shop_menu(id)
{
	new menu = menu_create("Vyber si z menu:", "shop_menu_selection")

	menu_additem(menu, "Maceta")
	menu_additem(menu, "Motorova pila")

	menu_display(id, menu)
}

public shop_menu_selection(id, menu, item)
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	switch(item)
	{
		case 0:
		{
			give_item(id, "weapon_knife")
			g_iPlayerWeapon[id] = Model_Machete
			
			g_bSelected[id] = true
		}

		case 1:
		{
			give_item(id, "weapon_knife")
			g_iPlayerWeapon[id] = Model_Motor
			
			g_bSelected[id] = true
		}
	}
	return PLUGIN_HANDLED;
}

public new_models(id)
{
	if(g_bSelected[id])
	{
		new wpid = get_user_weapon(id)
		
		switch(wpid)
		{
			case CSW_KNIFE:
			{
				set_pev(id, pev_viewmodel2, g_szModelList[g_iPlayerWeapon[id]][v_Model])
				set_pev(id, pev_weaponmodel2, g_szModelList[g_iPlayerWeapon[id]][p_Model])
			}
		}
	}
}

public isDamaged(victim, attacker, inflictor, Float:damage, damage_bits, id)
{
	if(get_user_weapon(id) == CSW_KNIFE)
	{
		SetHamParamFloat(4, g_szModelList[g_iPlayerWeapon[id]][Model_Damage])
	}
}