• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

How to make monster to use a script?

Aloow

New Member
Joined
Nov 28, 2012
Messages
7
Reaction score
1
Hi,

I'm using The Forgotten Server - Version 0.2.14 (Mystic Spirit)

and I want a monster to use a script.

The script is the one from the policeman/guard npc that kills skulled players.

Now:
Added to monster.xml

<monster name="Tower" file="tower.xml"/>


Added to data/monster/tower.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Tower" nameDescription="a rat" race="blood" experience="5" speed="134" manacost="200">
    <health now="20" max="20"/>
    <look type="21" corpse="5964"/>
    <targetchange interval="2000" chance="0"/>
    <strategy attack="100" defense="0"/>
    <flags>
        <flag summonable="1"/>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag illusionable="1"/>
        <flag convinceable="1"/>
        <flag pushable="1"/>
        <flag canpushitems="0"/>
        <flag canpushcreatures="0"/>
        <flag targetdistance="1"/>
        <flag staticattack="90"/>
        <flag runonhealth="5"/>
    </flags>
    <defenses armor="25" defense="30">
        <defense name="guardian" interval="1000" chance="25" min="60" max="100">
            <attribute key="areaEffect" value="blueshimmer"/>
        </defense>
    </defenses>
    <elements>
        <element earthPercent="12"/>
        <element holyPercent="20"/>
        <element icePercent="-6"/>
        <element deathPercent="-10"/>
    </elements>
    <voices interval="5000" chance="10">
        <voice sentence="Meep!"/>
    </voices>
    <loot>
        <item id="2148" countmax="5" chance="35000"/><!-- gold coin -->
        <item id="3976" countmax="3" chance="35000"/><!-- worm -->
        <item id="2696" chance="36750"/><!-- cheese -->
        <item id="2687" countmax="2" chance="750"/><!-- cookies -->
    </loot>
</monster>


Added to data/spells/scripts/monster/guardian.lua

Code:
local level = 10  ----- change this to make the npc hit more/less---------------------|damage_min = (level * 2 + maglevel * 3) * min_multiplier |
local maglevel = 10  ----- change this to make the npc hit more/less -----------------|damage_max = (level * 2 + maglevel * 3) * max_multiplier |
local min_multiplier = 2.1  ----- change this to make the npc hit more/less ----------|damage_formula = math.random(damage_min,damage_max)      |
local max_multiplier = 4.2  ----- change this to make the npc hit more/less ---------------------------------------------------------------------
local check_interval = 5  ----- change this to the time between checks for a creature (the less time the more it will probably lag :S)
local radiusx = 7  ----- change this to the amount of squares left/right the NPC checks (default 7 so he checks 7 squares left of him and 7 squares right (the hole screen)
local radiusy = 5  ----- change this to the amount of squares left/right the NPC checks (default 5 so he checks 5 squares up of him and 5 squares down (the hole screen)
local Attack_message = "An Invader, ATTACK!!!"  ----- change this to what the NPC says when he sees a monster(s)
local town_name = "Archgard"  ----- the name of the town the NPC says when you say "hi"
local Attack_monsters = TRUE  ----- set to TRUE for the npc to attack monsters in his area or FALSE if he doesnt
local Attack_swearers = TRUE  ----- set to TRUE for the npc to attack players that swear near him or FALSE if he doesnt
local Attack_pkers = TRUE  ----- set to TRUE for the npc to attack players with white and red skulls or FALSE if he doesnt
local health_left = 10  ----- set to the amount of health the npc will leave a player with if they swear at him (ie at 10 he will hit the player to 10 health left)
local swear_message = "Take this!!!"  ----- change this to what you want the NPC to say when he attackes a swearer
local swear_words = {"shit", "fuck", "dick", "cunt"}  ----- if "Attack_swearers" is set to TRUE then the NPC will attack anyone who says a word in here. Remember to put "" around each word and seperate each word with a comma (,)
local hit_effect = CONST_ME_MORTAREA  ----- set this to the magic effect the creature will be hit with, see global.lua for more effects
local shoot_effect = CONST_ANI_SUDDENDEATH  ----- set this to the magic effect that will be shot at the creature, see global.lua for more effects
local damage_colour = TEXTCOLOR_RED  ----- set this to the colour of the text that shows the damage when the creature gets hit
------------------end of config------------------
local check_clock = os.clock()  ----- leave this
local focus = 0  ----- leave this

function msgcontains(txt, str)
  return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
msg = string.lower(msg)
health = getCreatureHealth(cid) - health_left
    if ((string.find(msg, 'hi'))) then
        selfSay('Hello ! I am a defender of '..town_name..'.')
        doNpcSetCreatureFocus(cid)
        focus = 0
    end

    if msgcontains(msg, 'time') then
        selfSay('The time is ' .. getWorldTime() .. '.')
    end
 
end

function getMonstersfromArea(pos, radiusx, radiusy, stack)
local monsters = { }
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}
local checking = {x = starting.x, y = starting.y, z = starting.z, stackpos = starting.stackpos}
    repeat
        creature = getThingfromPos(checking)
            if creature.itemid > 0 then
                if isCreature(creature.uid) == TRUE then
                    if isPlayer(creature.uid) == FALSE then
                        if Attack_monsters == TRUE then                          
                            table.insert (monsters, creature.uid)
                            check_clock = os.clock()                       
                        end
                    elseif isPlayer(creature.uid) == TRUE then
                        if Attack_pkers == TRUE then
                            if getPlayerSkullType(creature.uid) > 0 then
                                table.insert (monsters, creature.uid)
                                check_clock = os.clock()    
                            end
                        end
                    end
                end
            end
        if checking.x == pos.x-1 and checking.y == pos.y then
            checking.x = checking.x+2
        else 
            checking.x = checking.x+1
        end
        if checking.x > ending.x then
            checking.x = starting.x
            checking.y = checking.y+1
        end
    until checking.y > ending.y
        return monsters
end

function onCastSpell(cid, var)
if (Attack_monsters == TRUE and Attack_pkers == TRUE) or (Attack_monsters == TRUE and Attack_pkers == FALSE) or (Attack_monsters == FALSE and Attack_pkers == TRUE) then
    if (os.clock() - check_clock) > check_interval then    
        monster_table = getMonstersfromArea(getCreaturePosition(getNpcCid(  )), radiusx, radiusy, 253)
            if #monster_table >= 1 then
                selfSay('' .. Attack_message ..' ')
                    for i = 1, #monster_table do
                        doNpcSetCreatureFocus(monster_table[i])
                        local damage_min = (level * 2 + maglevel * 3) * min_multiplier
                        local damage_max = (level * 2 + maglevel * 3) * max_multiplier
                        local damage_formula = math.random(damage_min,damage_max)
                        doSendDistanceShoot(getCreaturePosition(getNpcCid(  )), getThingPos(monster_table[i]), shoot_effect)
                        doSendMagicEffect(getThingPos(monster_table[i]),hit_effect)   
                        doCreatureAddHealth(monster_table[i],-damage_formula)
                        check_clock = os.clock()
                        focus = 0
                    end
            elseif table.getn(monster_table) < 1 then
                focus = 0
                check_clock = os.clock()
            end  
    end
end
    focus = 0
end

Of course, it doesn't work.

I know I need to change those "npc" to the "creature".
I tried that but it crashed the server down.

I can see the blueshimmer, so I know the monster attempts to use the script.

Appreciate any help for my problem.

Regards,
Aloow
 
Last edited:
Back
Top