What's new

Spells Tower Attack

Status
Not open for further replies.

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Oto skrypt, kt?ry napisa?em dla zabicia czasu.

Tworzymy plik o nazwie tower.lua w data/spells/scripts i wklejamy:
PHP:
local function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
		if tile.itemid ~= 0 and not isCreature(tile.uid) then
			if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
				return false
			end
		end
end
return true
end

local config = {
				storage = 2000,
				max_towers = 1, --maksymalna ilo?? wie?
				name = 'tower', --nazwa NPCta
				time = 30, --w sekundach
				}
				
function onTargetTile(cid, pos)
if isWalkable(pos, true, true, true) then
	local npc = doCreateNpc(config.name, pos, false)
	doCreatureSetStorage(npc, config.storage, cid)
	doPlayerSetStorageValue(cid, config.storage, (getPlayerStorageValue(cid, config.storage) <= 0 and 1 or getPlayerStorageValue(cid, config.storage) + 1))
	return addEvent(function()
							pos.stackpos = STACKPOS_TOP_CREATURE
							if getThingFromPos(pos).uid == 0 then
								return true
							end
							if getCreatureName(getThingFromPos(pos).uid):lower() == config.name:lower() then
								doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage) - 1)
								return doRemoveCreature(getThingFromPos(pos).uid)
							end end,
							config.time * 1000,
							cid, pos, config)
	
end
return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_BIGCLOUDS)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGYBALL)
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
if getPlayerStorageValue(cid, config.storage) >= config.max_towers then
	return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Posiadasz maksymalna ilosc wie?yczek.')
end
return doCombat(cid, combat, var)
end
Do spells.xml doklejamy:
PHP:
<rune name="Test" id="2268" mana="0" allowfaruse="1" exhaustion="0" blocktype="solid" event="script" value="test.lua"/>

Idziemy do data/NPC/scripts, tworzymy plik tower.lua i wklejamy:
PHP:
local damage = {
				['fire'] = {COMBAT_FIREDAMAGE,CONST_ME_FIREAREA,CONST_ANI_FIRE},
				['ice'] = {COMBAT_ICEDAMAGE,CONST_ME_ICEATTACK,CONST_ANI_ICE},
				['earth'] = {COMBAT_EARTHDAMAGE,CONST_ME_CARNIPHILA,CONST_ANI_EARTH},
				['energy'] = {COMBAT_ENERGYDAMAGE,CONST_ME_ENERGYHIT,CONST_ANI_ENERGY},
				['death'] = {COMBAT_DEATHDAMAGE,CONST_ME_MORTAREA,CONST_ANI_SUDDENDEATH},
				['holy'] = {COMBAT_HOLYDAMAGE,CONST_ME_HOLYDAMAGE,CONST_ANI_HOLY},
				['physical'] = {COMBAT_PHYSICALDAMAGE,CONST_ME_GROUNDSHAKER,CONST_ANI_LARGEROCK},
				['drown'] = {COMBAT_DROWNDAMAGE,CONST_ME_WATERSPLASH,CONST_ANI_SMALLICE}
				}
local types = {'fire','ice','earth','energy','death','holy','physical','drown'}

local keywordHandler, t, h = KeywordHandler:new(), 0, 0
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid)        	npcHandler:onCreatureAppear(cid)        	end
function onCreatureDisappear(cid)     	npcHandler:onCreatureDisappear(cid) 	    end

local config = {
				storage = 2000,
				range = 5, --zasieg wiezyczki
				player_range = 8, --odleg?o?? na jak? mo?e odej?? gracz by wieza nie znikla
				----
				damage = {300,500}, --obrazenia {min, max}
				interval = 2, --w sekundach
				type = '', --typ obra?e?, do wyboru 'fire', 'ice', 'earth', 'energy', 'death', 'holy', 'physical', 'drown'
				----
				interval_healing = 3, --po ile atak?w ma ulecza?, na przyk?ad: atak (1), atak (2), atak (3), leczenie, atak (1) ...
				healing = {10,25} --leczenie {od, do}
				}
function onThink()                    	npcHandler:onThink()                 		
local cid = getCreatureStorage(getNpcCid(), config.storage)
if isPlayer(cid) then
	if getDistanceBetween(getThingPos(getNpcCid()), getThingPos(cid)) > config.player_range then
		doRemoveCreature(getNpcCid())
		return doPlayerSetStorageValue(cid, config.storage, 0)
	end
else
	return doRemoveCreature(getNpcCid())
end 
if getCreatureTarget(cid) == 0 then
	t = 0
	return true
end
if getDistanceBetween(getThingPos(getNpcCid()), getThingPos(getCreatureTarget(cid))) > config.range then
	return true
end
if t == 0 and h <= config.interval_healing then
	local v = damage[config.type]
	if not v then
		local s = types[math.random(#types)]
		v = damage[s]
	end
		if h == config.interval_healing then
			doTargetCombatHealth(getNpcCid(), cid, COMBAT_HEALING, config.healing[1], config.healing[2], CONST_ME_MAGIC_BLUE)
			h = 0
			t = 1
			return doSendDistanceShoot(getThingPos(getNpcCid()), getThingPos(cid), CONST_ANI_ENERGYBALL)
		end
		doTargetCombatHealth(getNpcCid(), getCreatureTarget(cid), v[1], -config.damage[1], -config.damage[2], v[2])
		doSendDistanceShoot(getThingPos(getNpcCid()), getThingPos(getCreatureTarget(cid)), v[3])
		h = h + 1
		t = 1
elseif t > 0 and t <= config.interval then
	t = t + 1
else
	t = 0
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
W data/NPC robimy plik tower.xml i wklejamy:
PHP:
<?xml version="1.0"?>
<npc name="Tower" floorchange="0" speed="0" hidehealth="1" walkable="0" script="tower.lua">
    <health now="150" max="150"/>
    <look type="333"/>
</npc>


Jak to dzia?a zapytacie?
Ot?? u?ywaj?c runy (w tym przypadku 2268 czyli SD) gdziekolwiek w zasi?gu wzroku, pojawi si? nam wie?yczka, kt?ra b?dzie nam pomaga? w walce.
Bazowo jest ustawione, i? atakuje co 2 sekundy ze wszystkich ?ywio??w (losowo??), a co 3 tury zaprzestaje ataku by nas uleczy?. Wie?a po 30 sekundach znika.
Og?lnie skrypt jest banalny i prosty, ale wystarczy troch? umiej?tno?ci i mn?stwo wyobra?ni by stworzy? z tego co? naprawd? godnego uwagi.
 

szymek24s

Active User
Joined
Oct 24, 2008
Messages
79
Reaction score
9
Odp: Tower Attack

Hm zrobi?em tak samo ale mi nie dzia?a.Skrypty z 8.54 raczej powinny dzia?a? na 8.6?
 
Last edited:

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Tower Attack

Edytowa?em pierwszy post. Przekopiuj skrypt spells do siebie.
Wszelkie propozycje czy b??dy zg?asza? w temacie.
 

szymek24s

Active User
Joined
Oct 24, 2008
Messages
79
Reaction score
9
Odp: Tower Attack

Ok dzia?a dzi?ks ;). Tylko ma?y problemik.Po up?ywie tych 30 sekund nie znika.
 
Last edited:

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Tower Attack

PHP:
local function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
    pos.stackpos = i
    local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
end
return true
end

local config = {
                storage = 2000,
                max_towers = 1, --maksymalna ilo?? wie?
                name = 'tower', --nazwa NPCta
                time = 30, --w sekundach
                }
                
function onTargetTile(cid, pos)
if isWalkable(pos, true, true, true) then
    local npc = doCreateNpc(config.name, pos, false)
    doCreatureSetStorage(npc, config.storage, cid)
    doPlayerSetStorageValue(cid, config.storage, (getPlayerStorageValue(cid, config.storage) <= 0 and 1 or getPlayerStorageValue(cid, config.storage) + 1))
    return addEvent(function()
                            if npc == 0 then
                                return true
                            end
                            if getCreatureName(npc):lower() == config.name:lower() then
                                doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage) - 1)
                                return doRemoveCreature(npc)
                            end end,
                            config.time * 1000,
                            cid, config, npc)
    
end
return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_BIGCLOUDS)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGYBALL)
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(cid, var)
if getPlayerStorageValue(cid, config.storage) >= config.max_towers then
    return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Posiadasz maksymalna ilosc wie?yczek.')
end
return doCombat(cid, combat, var)
end
Niech spr?buje.

#2 down
U mnie wszystko dzia?a przy pierwotnym skrypcie, wi?c gdzie widzisz to niedopatrzenie?
 
Last edited:

szymek24s

Active User
Joined
Oct 24, 2008
Messages
79
Reaction score
9
Odp: Tower Attack

Ni, w dalszym ci?gu nic.Nie wiem co jest nie tak, nie wywala ?adnego b??du.
 

Lopus

Advanced User
Joined
Jun 17, 2011
Messages
206
Reaction score
9
Odp: Tower Attack

nie wywala? Bo go po prostu nie ma, jest to zwyk?? niedopatrzenie, kt?re mistrz Oskar na pewno znajdzie.

Co do skryptu to na prawd? dobrze Ci wyszed? i jest on oryginalny.
 

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Tower Attack

Od?wie?am
Notka moderatorska:

Nie uwa?asz ?e zrobienie tego jako summon zamiast jako npc by?o by lepszym rozwi?zaniem? //dubler
 
Last edited by a moderator:

kamilojox

User
Joined
Sep 12, 2011
Messages
28
Reaction score
1
Odp: Tower Attack

Nie no pe?na powaga ;) Kole? jak ty takie fajne skrypty robisz ?? :D
 

Ronnix

Active User
Joined
Jul 25, 2008
Messages
145
Reaction score
8
Odp: Tower Attack

Pozwole sobie odkopac temat poniewaz mam problem/pytanie/sprawe/prosbe? chyba wszystko naraz:D

Otoz chcialbym prosic o przerobienie skryptu aby zamiast wierzy pojawial sie jakis monster ktory by za nami chodzil i dzialal jako healer ale nie atakowal by monsterkow;p

czy jest ktos w stanie zrobic cos takiego? oczywiscie monster znikalby po 30sekundach a jego hp roslo by wraz z naszym lvlem, powiedzmy o 10hp co poziom:D
 

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Tower Attack

Nie jest to trudne do wykonania, ale z mojej strony na darmow? pomoc niestety liczy? ju? nie ma co.
 

DanJ93

ElfBot Helper
Joined
Jan 18, 2009
Messages
2,631
Reaction score
200
Odp: Tower Attack

Zmie?cie z
PHP:
<rune name="Test" id="2268" mana="0" allowfaruse="1" exhaustion="0" blocktype="solid" event="script" value="test.lua"/>
na
PHP:
<rune name="Test" id="2268" mana="0" allowfaruse="1" exhaustion="0" blocktype="solid" event="script" value="tower.lua"/>
 

Ronnix

Active User
Joined
Jul 25, 2008
Messages
145
Reaction score
8
Odp: Tower Attack

OK poradzilem sobie z tym na swoj sposob, jednak gdy zainstalowalem ten skrypt w swoim ots, stowrzylem pierwsza lepsza postacia tego Towera po czym zrobilem reset serwera i teraz za kazdym razem gdy chce zrobic Tower pokazuje mi ze posiadam juz maksymalna ich liczbe. Tak jakby zapisalo fakt ze juz go stworzylem... da sie to jakos naprawic?
 

zakius

Senior User
Joined
May 25, 2008
Messages
869
Reaction score
52
Odp: Tower Attack

onLogout zeruj tego storaga
ewentualnie onStartup zeruj tego storaga wszystkim graczom przez odpowiednie zapytanie do bazy
 

Guuraal

Advanced User
Joined
Apr 11, 2012
Messages
191
Reaction score
8
Odp: Tower Attack

a czy w spells.xml

zamiast <rune name="Test" id="2268" mana="0" allowfaruse="1" exhaustion="0" blocktype="solid" event="script" value="test.lua"/>

Nie powinno by? tower.lua ? xd
 

Encor

New User
Joined
May 11, 2012
Messages
5
Reaction score
0
Odp: Tower Attack

Bardzo fajny czar . Mo?e mi si? przyda dzieki :)
 

Wildhells

Senior User
Joined
Feb 4, 2012
Messages
2,346
Reaction score
119
Odp: Tower Attack

@vexler222
Forum jest od pomocy nikt nie b?dzie specjalnie pisa? na GG. Stw?rz temat i opisz sw?j problem, a nie.

@topic
Skrypt dzia??, testowa?em, ale bardziej pasuje na OTSy typu Fun / Evo. Nic skomplikowanego, a ca?kiem przydatne.
 

KiCKERS

Active User
Joined
Apr 15, 2012
Messages
70
Reaction score
4
Odp: Tower Attack

Wielkie dzi?ki, przyda si? :p
Pozdrawiam Kickers.
 
Status
Not open for further replies.
Top