• logo_cipsoft
    Nowe serwery zostały otwarte 19 Lut 2025:
    Noctalia (Open PvP) Ignitera (Open PvP) us_logo Xybra (Open PvP)

Creaturescripts System prowokacji potwor?w - wymagana optymalizacja [LUA]

Status
Zamknięty.

Oskar

Forum friend
Dołączył
Styczeń 24, 2009
Posty
2256
Liczba reakcji
331
Przygod? zaczynamy w folderze creaturescripts.
Tworzymy plik Combat.lua i wklejamy:
PHP:
monsters = {'ghastly dragon','son of verminor','infernalist','black knight','hero','braindeath','crystal spider','killer caiman','earth elemental','adept of the cult','marid','efreet','monk','dragon hatchling','mutated human','carniphila','tortoise','gang member','poacher','elf','goblin scavenger','goblin','crazed beggar','crab','panda','bug','spider','snake'}
--ghastly - 1, son of verminor - 1, infernalist - 1, bk - 0, hero - 1, braindeath - 1, crystal spider - 1, killer - 1, earth elemental - 1, adept - 0, marid - 1, efreet - 1, monk - 1, dragon - 1, mutated - 1, carniphila - 1, tortoise - 1, gang - 1, poacher - 1, elf - 1, goblin - 1, goblin - 1, crazed - 1, crab - 1, panda - 1, bug - 1, spider - 1, snake - 1

function onCombat(cid, target)
	if isMonster(cid) and isInArray(monsters, getCreatureName(cid):lower()) then
		if isPlayer(target) then
			if getPlayerStorageValue(target, cid) == -1 then
				return false
			else
				if getCreatureSpeed(cid) == 0 then
					return doChangeSpeed(cid, getCreatureBaseSpeed(cid))
				end
				return true
			end
		elseif isSummon(target) then
			if getCreatureSpeed(cid) == 0 then
				doChangeSpeed(cid, getCreatureBaseSpeed(cid))
			end
			if getPlayerStorageValue(getCreatureMaster(target), cid) == -1 then
				return false
			else
				return true
			end
		end
	elseif isMonster(target) and isSummon(target) == false and isPlayer(cid) and isInArray(monsters, getCreatureName(target):lower()) then
		if getPlayerStorageValue(cid, target) == -1 then
			if getCreatureSpeed(target) == 0 then
				doChangeSpeed(target, getCreatureBaseSpeed(target))
			end
			return doPlayerSetStorageValue(cid, target, 0)
		end
	end
return true
end

function onKill(cid, target, lastHit)
if isMonster(target) and isPlayer(cid) and isInArray(monsters, getCreatureName(target):lower()) then
	if getPlayerStorageValue(cid, target) == 0 then
		doPlayerSetStorageValue(cid, target, -1)
	end
end
return true
end
Plik Think.lua i wklejamy:
PHP:
function onThink(cid)
if isMonster(cid) then
	local s = {-1,1}
	local pos, target, targets, distance = getCreaturePosition(cid), getCreatureTarget(cid), getMonsterTargetList(cid), getConfigValue('distanceBetweenPlayerAndMonster')
	if target ~= 0 then
		if isPlayer(target) then
			if getPlayerStorageValue(target, cid) == -1 then
				doChangeSpeed(cid, -getCreatureSpeed(cid))
				doMonsterChangeTarget(cid)
				if getCreatureStorage(cid, cid) ~= 0 then
					if math.random(1,2) == 1 then
						pos.x = pos.x + s[math.random(#s)]
					else
						pos.y = pos.y + s[math.random(#s)]
					end
					doTeleportThing(cid, getClosestFreeTile(cid, pos))
					doCreatureSetStorage(cid, cid, 0)
					addEvent(function(cid) if isCreature(cid) and getCreatureTarget(cid) ~= 0 and getCreatureStorage(getCreatureTarget(cid), cid) == -1 then doCreatureSetStorage(cid, cid, -1) end end, 1000, cid)
				end
			else
				if getCreatureSpeed(cid) == 0 then
					doChangeSpeed(cid, getCreatureBaseSpeed(cid))
				end
			end
		elseif isSummon(target) and getPlayerStorageValue(getCreatureMaster(target), cid) == -1 then
			if getCreatureSpeed(cid) == 0 then
				doChangeSpeed(cid, getCreatureBaseSpeed(cid))
			end
			doPlayerSetStorageValue(getCreatureMaster(target), cid, 0)
			doMonsterChangeTarget(cid)
		end
	else
		if getCreatureSpeed(cid) == 0 then
			doChangeSpeed(cid, getCreatureBaseSpeed(cid))
		end
	end
	if #targets > 0 then
		for k, v in ipairs(targets) do
			if getDistanceBetween(getCreaturePosition(cid), getCreaturePosition(v)) <= distance then
				if isPlayer(v) and getPlayerStorageValue(v, cid) == -1 then
					doPlayerSetStorageValue(v, cid, 0)
				elseif isSummon(v) and getPlayerStorageValue(getCreatureMaster(v), cid) == -1 then
					doPlayerSetStorageValue(getCreatureMaster(v), cid, 0)
				end
				if getCreatureSpeed(cid) == 0 then
					doChangeSpeed(cid, getCreatureBaseSpeed(cid))
				end
			else
				if isPlayer(v) and getPlayerStorageValue(v, cid) == 0 then
					if getCreatureSpeed(cid) == 0 then
						doChangeSpeed(cid, getCreatureBaseSpeed(cid))
					end
				elseif isSummon(v) and getPlayerStorageValue(getCreatureMaster(v), cid) == 0 then
					if getCreatureSpeed(cid) == 0 then
						doChangeSpeed(cid, getCreatureBaseSpeed(cid))
					end
				end
			end
		end
	else
		if getCreatureSpeed(cid) == 0 then
			doChangeSpeed(cid, getCreatureBaseSpeed(cid))
		end
	end
end
return true
end
Do creaturescripts.xml wklejamy:
PHP:
<event type="think" name="Thinks" event="script" value="Think.lua"/>
<event type="kill" name="Killss" event="script" value="Combat.lua"/>
Do login.lua dodajemy:
PHP:
registerCreatureEvent(cid, 'Killss')

Ko?czymy w?dr?wk? po tym folderze i kierujemy si? do data/lib/050-function.lua i wklejamy tam:
PHP:
function isSummon(cid)
	return getCreatureMaster(cid) ~= cid or false
end

Do config.lua dodajemy:
PHP:
distanceBetweenPlayerAndMonster = 2

Teraz folder monsters
Do ka?dego potwora, kt?rego trzeba sprowokowa? dodajemy (pod </flags>):
PHP:
<script>
	<event name="Combats"/>
	<event name="Thinks"/>
</script>

Z ka?dego takowego potwora usuwamy ataki (poza fizycznym i conditionami), na przyk?adzie Son of Verminor:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="son of verminor" nameDescription="son of verminor" race="venom" experience="5900" speed="240">
	<health now="8500" max="8500"/>
	<look type="19" corpse="1496"/>
	<targetchange interval="5000" chance="10"/>
	<strategy attack="100" defense="0"/>
	<flags>
		<flag attackable="1"/>
		<flag hostile="1"/>
		<flag convinceable="1"/>
		<flag canpushitems="1"/>
		<flag canpushcreatures="1"/>
		<flag targetdistance="1"/>
		<flag staticattack="90"/>
		<flag runonhealth="0"/>
	</flags>
	<script>
		<event name="Combats"/>
		<event name="Thinks"/>
	</script>
	<attacks>
		<attack name="melee" interval="2000" skill="155" attack="50" poison="-200"/>
		<attack name="Square" interval="1031" target="0"/>
		<attack name="SoV" interval="1006" target="0"/>
		<attack name="poison" interval="1012" chance="12" range="1" min="-150" max="-200">
			<attribute key="areaEffect" value="greenbubble"/>
			<attribute key="shootEffect" value="poison"/>
		</attack>
	</attacks>
	<defenses armor="35" defense="40" >
		<defense name="outfit" interval="1052" chance="12" monster="rat" duration="4000">
			<attribute key="areaEffect" value="redshimmer"/> 
	 	</defense>
		<defense name="outfit" interval="1065" chance="12" monster="larva" duration="4000">
			<attribute key="areaEffect" value="redshimmer"/> 
		</defense>
		<defense name="outfit" interval="1016"  chance="12" monster="scorpion" duration="4000">
			<attribute key="areaEffect" value="redshimmer"/> 
	 	</defense>
	</defenses>
	<elements>
		<element firePercent="10"/>
		<element energyPercent="20"/>
	</elements>
	<immunities>
		<immunity earth="1"/>
		<immunity paralyze="1"/>
		<immunity invisible="1"/>
		<immunity lifedrain="1"/>
	</immunities>
</monster>
Jak wida? u?ywa on nowych czar?w, wi?c idziemy do data/spells/scripts i tworzymy tam dwa pliki o nazwach Square.lua oraz SoV.lua i wklejamy kolejno:
PHP:
local config = {
				['son of verminor'] = {ch = 11, c = COMBAT_DEATHDAMAGE, min = -220, max = -270, e = CONST_ME_SMALLCLOUDS},
				['carniphila'] = {ch = 11, c = COMBAT_EARTHDAMAGE, min = -40, max = -130, e = CONST_ME_POISONAREA},
				['infernalist'] = {ch = 14, ef = CONST_ANI_ENERGYBALL, c = COMBAT_MANADRAIN, min = -53, max = -120, e = CONST_ME_TELEPORT}
				}

function onTargetTile(cid, pos)
local v = config[getCreatureName(cid):lower()]
pos.stackpos = STACKPOS_TOP_CREATURE
local creature = getThingFromPos(pos).uid
	if v and isCreature(getCreatureTarget(cid)) then
		if isPlayer(getCreatureTarget(cid)) and getPlayerStorageValue(getCreatureTarget(cid), cid) ~= -1 then
			doSendMagicEffect(pos, v.e)
		elseif isMonster(getCreatureTarget(cid)) then
			doSendMagicEffect(pos, v.e)
		end
		if isPlayer(creature) and getPlayerStorageValue(creature, cid) ~= -1 then
			doSendMagicEffect(pos, v.e)
			if v.c == COMBAT_MANADRAIN then
				doTargetCombatMana(cid, creature, v.min, v.max, v.e)
				doSendDistanceShoot(getCreaturePosition(cid), getCreaturePosition(getCreatureTarget(cid)), v.ef)
			else
				doTargetCombatHealth(cid, creature, v.c, v.min, v.max, v.e)
			end
		elseif isMonster(creature) and creature ~= cid then
			doSendMagicEffect(pos, v.e)
			if v.c == COMBAT_MANADRAIN then
				doTargetCombatMana(cid, creature, v.min, v.max, v.e)
				doSendDistanceShoot(getCreaturePosition(cid), getCreaturePosition(getCreatureTarget(cid)), v.ef)
			else
				doTargetCombatHealth(cid, creature, v.c, v.min, v.max, v.e)
			end
		end
	end
end

local combat = createCombatObject()

local area = createCombatArea(AREA_SQUARE1X1)
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")
setCombatArea(combat, area)

function onCastSpell(cid, var)
local v = config[getCreatureName(cid):lower()]
if math.random(100) <= v.ch then
	if math.random(100000) <= 5000 then v.ch = v.ch + 1 end
	return doCombat(cid, combat, var)
end
return true
end
PHP:
local config = {
				['son of verminor'] = {ch = 14, c = COMBAT_POISONDAMAGE, min = -350, max = -390, e = CONST_ME_POISONAREA}
				}

function onTargetTile(cid, pos)
local v = config[getCreatureName(cid):lower()]
pos.stackpos = STACKPOS_TOP_CREATURE
local creature = getThingFromPos(pos).uid
	if v and isCreature(getCreatureTarget(cid)) then
		if isPlayer(getCreatureTarget(cid)) and getPlayerStorageValue(getCreatureTarget(cid), cid) ~= -1 then
			doSendMagicEffect(pos, v.e)
		elseif isMonster(getCreatureTarget(cid)) then
			doSendMagicEffect(pos, v.e)
		end
		if isPlayer(creature) and getPlayerStorageValue(creature, cid) ~= -1 then
			doTargetCombatHealth(cid, creature, v.c, v.min, v.max, v.e)
		elseif isMonster(creature) and creature ~= cid then
			doTargetCombatHealth(cid, creature, v.c, v.min, v.max, v.e)
		end
	end
end

local combat = createCombatObject()

local area = createCombatArea(AREA_SQUARE1X1)
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")
setCombatArea(combat, area)

function onCastSpell(cid, var)
local v = config[getCreatureName(cid):lower()]
if math.random(100) <= v.ch then
	if math.random(100000) <= 5000 then v.ch = v.ch + 1 end
	return doCombat(cid, combat, var)
end
return true
end
Do spells.xml dodajemy:
PHP:
<instant name="Square" words="Square" selftarget="1" event="script" value="Monster_Attacks/square.lua"/>
<instant name="SoV" words="SoV" selftarget="1" event="script" value="Monster_Attacks/SoV.lua"/>


To tylko na przyk?adzie Son of Verminor, dla ka?dego potwora trzeba niestety robi? nowe czary (uroki LUA), dlaczego? Ano dlatego, ?e zwracaj?c false w funkcji onCombat potw?r i tak u?ywa czar?w.

Skrypt wymaga optymalizacji, nie testowa?em na wi?kszej ilo?ci potwor?w ani?eli ~40 naraz.
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Kolejny Tw?j pi?kny skrypt :D. Troch? zgibane z tymi czarami 10/10. Mog? da? propozycje kolejnego skryptu :D?


@down
hmmm niech pomy?le....Akurat brakuje mi do otsa "Furi". Skrypt polega? by na tym ?e:
-hp i mana zmniejszaj? si? o 100%
-zmienia si? wygl?d postaci(looktype)
-hity z czar?w/sworda zwi?kszaj? si? o 50%
-trwa to 100sekud
-i oczywi?cie ?eby to by? czar :D
+ duperele typu ?e si? wy??cza po lognieciu i inne rzeczy, kt?re mog?y by powodowa? bugi.

W miar? prosty skrypt, przynajmniej tak uwa?am jestem pocz?tkuj?cym skrypterem.
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Oczywi?cie, daj propozycj?, gdy? akurat nie mam co robi?.
Co do skryptu, czary nie s? obowi?zkowe, ale je?li chcecie by potw?r by? ca?kowicie neutralny wobec gracza to zr?bcie te ataki.

#down
Tak, wiem o tym, ?e w C++ to znacznie ?atwiejsze, ale ja nie potrafi? programowa? w tym j?zyku, wi?c ograniczam si? do LUA i funkcji w nim zawartych.
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

No prosz? Oskar. Coraz to nowsze, lepsze skrypty z twojej strony. :) Podziwiam wytrwa?o?? i oby tak dalej.
Nie chc? ?le oceni? tego skryptu, ale w C++ by?oby naprawd? znacznie pro?ciej. Z tego co pami?tam ze swojego drugiego projektu (r?wnie? o tematyce DB) to by?o naprawd? niewiele linijek, a i przy okazji mo?na by?o zrobi?, aby potw?r przechodzi? przez gracza, kt?rego "nie mo?e" zaatakowa?.

#Up
Szanuje wyb?r, ale mo?e jednak popr?buj co? w C++. Nie jest to takie ci??kie jak si? zdaje. Metod? pr?b i b??d?w mo?na sporo osi?gn??. Np. taki oto skrypt. :) Najwa?niejsze przy edytowaniu ?r?de? naszego OTS, to znajomo?? ich. Czyli trzeba wiedzie?, co znajduj? si? w player.cpp, co w vocations.cpp, game.cpp itp. Moim zdaniem jest to 40% sukcesu przy OTS.
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Ten skrypt nowy mi nie dziala na tfs 0.3.6pl1 ale ten dzia?a
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Kolejny Tw?j pi?kny skrypt :D. Troch? zgibane z tymi czarami 10/10. Mog? da? propozycje kolejnego skryptu :D?
@down
hmmm niech pomy?le....Akurat brakuje mi do otsa "Furi". Skrypt polega? by na tym ?e:
-hp i mana zmniejszaj? si? o 100%
-zmienia si? wygl?d postaci(looktype)
-hity z czar?w/sworda zwi?kszaj? si? o 50%
-trwa to 100sekud
-i oczywi?cie ?eby to by? czar :D
+ duperele typu ?e si? wy??cza po lognieciu i inne rzeczy, kt?re mog?y by powodowa? bugi.
W miar? prosty skrypt, przynajmniej tak uwa?am jestem pocz?tkuj?cym skrypterem.

PHP:
local config = {
				procent_hp_mp = 200,
				storage = 1254,
				looktype = 123,
				procent_sily = 50,
				time = 100 --w sekundach
				}

local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, config.time * 1000)
setConditionParam(condition, CONDITION_PARAM_STAT_MAXHEALTHPERCENT, config.procent_hp_mp)
setConditionParam(condition, CONDITION_PARAM_STAT_MAXMANAPERCENT, config.procent_hp_mp)

function onCastSpell(cid, var)
doAddCondition(cid, condition)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
doSetCreatureOutfit(cid, {lookType = config.looktype}, config.time * 1000)
doPlayerSetStorageValue(cid, config.storage, config.procent_sily)
return addEvent(function()
					if isPlayer(cid) and getPlayerStorageValue(cid, config.storage) ~= -1 then
						doPlayerSetStorageValue(cid, config.storage, -1)
					end end,
					config.time * 1000,
					cid, config)
end

PHP:
function onCombat(cid, target)
if isMonster(target) or isPlayer(cid) then
	registerCreatureEvent(target,"VitalityChange")
	registerCreatureEvent(cid,"VitalityChange")
end
return true
end

function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(cid) and isCreature(attacker) and getPlayerStorageValue(cid, storage) ~= -1 then
	value = value * ((getPlayerStorageValue(cid, storage) + 100) / 100)
	return doTargetCombatHealth(cid, attacker, combat, -value, -value, CONST_ME_NONE)
end
end
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Dzi?ki Skrypt i mi si? przyda reput leci :)
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Kolejny ?adny skrypt 10/10 reput leci. Chcesz jeszcze 1 propozycje? A i opisz co gdzie wklei? nie ka?dy wie :).

Du?o ludzi ma problem z Kage bunshin no jutsu(klony):
-oczywi?cie czar
-po wpisaniu kage bunshin no jutsu pojawiaj? si? potworki z wygl?dem takim jaki my mamy aktualnie w??czony
-klony maj? 15% naszego hp i naszej si?y
-zale?y mi na tym ?eby nie trzeba by?o robi? moobkow w Monsters.xml i w folderze
I opisz co gdzie wklei? w poprzednim tez.
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Tak chc? jeszcze jedn? propozycj?. Edytuj? ten post, gdy sko?cz?.

#up
To C++, ja si? w tym nie bawi?.

#edit
Hah... Jednak C++ nie jest wymagane ^^
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Kt?r? dok?adniej rzecz trzeba robi? w C++? Opisz co gdzie wkleic w "furi".


System wojny wiosek, mam nadziej? ?e za?atwi Tw?j niedosyt. System polega na tym ?e w jednej wiosce stoi npc Red Team a w drugiej wiosce stoi npc Blue Team:
-Oby dwoje npc teleportowali by gracza na dane wsp??rz?dne
-Ci co wejd? na wojn? od blue npc nie mog? si? bi?, tylko tych co weszli od red npc
-Aby i?? na wojn? trzeba mie? konto premium i 300lvl
-Na wojn? od jednego npc mo?e wej?? 10 os?b(czyli na wojnie b?dzie 20 os?b)
-Je?eli nie b?dzie 20 os?b gracze s? teleportowani przed npc z kt?rego teleportowali si? na wojne
-Je?eli kto? zginie podczas tej wojny nie traci lvla
-Ka?dy kto padnie jest teleportowany w to miejsce co w punkcie pierwszym
-Wojna trwa tak d?ugo a? kt?ra? dru?yna nie b?dzie mia?a 20 zabi?
-W ka?d? sobot? o godzinie 15 wy?wietla si? napis"Npc w?a?nie si? zrespi?y mo?na zaczyna? wojn?!" i oczywi?cie respi? si? te npc na mapie i o godzinie 20 znikaj?
-Czyli mo?na zrobi? wi?cej ni? jedn? walk?

uu ale si? rozpisa?em :D Je?eli kt?rej? cz??ci nie da si? zrobi? usu? j?. Bardzo zale?y mi na tym skrypcie, du?o os?b we?mie go na swoje otsy :D
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

@Up
Zrobi?e? sobie z Oskara swojego osobistego skryptera za free?
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Musze przyzna?, ale chcia? propozycje to mu j? da?em :D
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

@Oskar

A do tej furii to gdzie to wkleic?
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Chcialbym zamowic skrypt na klonowanie sie , tak jak wyzej kage bunshin no jutsu

po uzyciu czaru pojawiaja sie 4 potworki z taka sama nazwa co przywolywacz i takim samym outfitem
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Skrypt z tematu bardzo fajny, dobrze napisany. A to, ?e nie bawisz si? w c++ kogo obchodzi? Je?li umiesz poradzi? sobie d?u?sz? drog? to i t? kr?tsz? da?by? rad?.:)
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

a jak przerobic Twoj skrypt aby potwor nie atakowal kazdego gracza tylko np 5 roznych potworow zaatakowalo by np po koleji z innym storage,i storage value?
np stoja kolo siebie 3 potworki i gdy zabijemy jednego mamy storage 12345 i storage value 2 gdy zabijemy drugiego mamy storage 12345 i storage value 3 i gdy trzeciego to mamy storage 12345 i storage value 4.
 
Ostatnia edycja:
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

Skrypt fajny ale nie lepiej by?o by ci zrobi? taki sam system w kilkunastu linijkach w c++? zostaw lua ;d to sie nie przyda zacznij zabawe z c++!
 
Odp: System prowokacji potwor?w - wymagana optymalizacja [LUA]

#up
Wiem o tym, ?e w C++ by?oby ?atwiej, dlatego w?a?nie zacz??em zabaw? z C++. Dopiero si? ucz?, ale zaczynam wy?apywa? co niekt?re ciekawostki z tego? j?zyka. Znaczy si? samo C++ jest proste, ale wykorzystanie go w silniku TFSa, to ju? trudniejsza sprawa, gdy? nie wiem jakimi sta?ymi tam si? operuje, gdzie si? nimi operuje i jak.
 
Status
Zamknięty.
Do góry