Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  Attack Register  (Read 33993 times)

0 Members and 1 Guest are viewing this topic.

clobber

« on: 11, March 2014, 22:29:24 »
I want to make a script that registers wat kind of attack was used against the mob by the player and can then update the quest accordingly.

So far I have (as an attack type script within my mob):

Code: [Select]
local target = event.me
local weapon = event.ac


if weaponskill melee then
    if weapon = punch
    player:UpdateQuest("quest punch", "update!")
    elseif weapon = 1h
    player:UpdateQuest("quest 1h", "update!")
    elseif weapon = agility
    player:UpdateQuest("quest ag", "update!")
    else
    player:UpdateQuest("quest throwing", "update!")
    end
elseif weaponskill magic then
    if weapon = magicbullet
    player:UpdateQuest("quest mb", "update!")
    else
    player:UpdateQuest("quest probe", "update!")
    end
else
    if weapon = cause light wounds then
    player:UpdateQuest("quest clw", "update!")
    else
    player:UpdateQuest("quest mh", "update!")
    end
end

Now, I suppose where I'm getting a bit stuck is how different attacks are described and sensed. Can anyone help here?
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

_people_

« Reply #1 on: 11, March 2014, 23:05:50 »
event.activator on an attack or kill event is the object which initiated the action. It's a player (or another mob) if the object was killed via melee, the arrow if the mob was killed via archery/throw, or it's the spell object if a spell killed the mob.

If it's a melee attack, your job is simple. event.activator.type will be game.TYPE_PLAYER (or game.TYPE_MONSTER)

If it's a ranged attack, then event.activator will be the ammo and event.activator.owner will be the living object (player or monster) that shot/threw the ranged ammo.

For magic, event.activator.owner will also be the living object that initiated the attack. However, it can sometimes be more complex. For example, probe (while not an attack and you probably don't care about it in this case, it may throw you off later) calls the examine event. Also, you may want to determine which spell did the killing which would involve more scriptwork.

Keep in mind that there are other ways an object could die. When an object is killed via a Lua script, the scripter MUST specify another object which killed it. They could specify any type of object though so filter that input as well.

Also I believe that if the mob was killed by a conventional trap the event.activator would just be the trap object. Be careful with that, though - I'm not sure at what point the traps disappear so if you use any sort of coroutines then you'll have to make sure game:IsValid(event.activator) is still true.

I hope that was more information than you wanted. ;) Didn't I tell you how to do this a few weeks back or was that Obli?
« Last Edit: 11, March 2014, 23:10:36 by _people_ »
-- _people_ :)

clobber

« Reply #2 on: 12, March 2014, 09:07:03 »
Thanks! T'was I, but I wrote it on a piece of paper which is now several counties away :(

EDIT: What about distinguishing between punch and weapon?
« Last Edit: 13, March 2014, 21:28:21 by clobber »
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

_people_

« Reply #3 on: 14, March 2014, 16:36:46 »
Code: [Select]
weapon = player:GetEquipment(game.EQUIP_WEAPON1)
if weapon == nil then
  -- no weapon = punch
else
  -- weapon is the weapon object
end
-- _people_ :)

clobber

« Reply #4 on: 12, April 2014, 16:14:23 »
Where am I going wrong?

Code: [Select]
local target = event.me
local attack = event.activator

if attack == game.TYPE_PLAYER then
    local player = event.activator
    local weapon = player:GetEquipment(game.EQUIP_WEAPON1)
        if weapon == nil then
        player:UpdateQuest("Learning to Fight", "Updated!")
        else
        player:UpdateQuest("Your First Weapon", "Updated!")
end
end


I'm getting no error messages at all, but it won't update the quest.
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

_people_

« Reply #5 on: 12, April 2014, 19:22:28 »
Sounds like a syntax error (which would be revealed in the server console window) but I don't see anything at a glance that looks erroneous (your indentation looks off but that wouldn't cause an issue).
Perhaps make sure the script is being activated at all. Add a "pl:Write('EVENT:: ' .. event.activator.name .. ', ' .. event.me.name)" and see if everything checks out.
-- _people_ :)

clobber

« Reply #6 on: 12, April 2014, 20:20:22 »
The server console comments that it's activated with return code 0 and no error message.
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

_people_

« Reply #7 on: 12, April 2014, 20:29:38 »
Oh, I missed an easy one.

"if attack == game.TYPE_PLAYER" -- Attack is not an object type, it is the object itself. game.TYPE_PLAYER, OTOH, is a type, which is really just a number with a special name. So "attack" is an object which will never == a number.

You want "if attack.type == game.TYPE_PLAYER then"
-- _people_ :)

clobber

« Reply #8 on: 13, April 2014, 17:14:18 »
Success! For punching at least. I haven't tested further because I've reached a new problem - it updates the quest, but doesn't finish it. IIRC from a previous thread I made, GetQuest won't help much with this, nor will SetQuestStatus.

How do I get it so that it marks the quest as complete?
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

_people_

« Reply #9 on: 15, April 2014, 11:38:00 »
qb:Finish(questnr) I think.
-- _people_ :)

clobber

« Reply #10 on: 15, April 2014, 20:26:36 »
Code: [Select]
local target = event.me
local attack = event.activator

require("quest_builder")
local qb = QuestBuilder

-- Quests --
    qb:AddQuest("Learning to Fight", game.QUEST_NORMAL, nil, nil, nil, nil, 1,
            questGoal, questReward)
    qb:AddQuest("Your First Weapon", game.QUEST_NORMAL, nil, nil, nil, nil, 1,
            questGoal, questReward)

if attack.type == game.TYPE_PLAYER then
        local player = event.activator
        local questnr = qb:Build(player)           
        local qstat = qb:GetStatus(questnr)       
    local weapon = player:GetEquipment(game.EQUIP_WEAPON1)
        if weapon == nil then
        qb:FinishQuest(questnr)
        else
        player:UpdateQuest("Your First Weapon", "Updated!")
end
end

Apparently, qb:FinishQuest returns a nil value?
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

smacky

« Reply #11 on: 15, April 2014, 20:41:09 »
It doesn't return nil. It is nil. There is no such method as qb:FinishQuest(). RTFM: https://www.daimonin.org/daipedia/UtilityScriptQuestBuilderReference#qbFinish

clobber

« Reply #12 on: 16, April 2014, 19:57:44 »
Huhm... I suppose that'll do for now.

Ok, so next step is registering thrown objects and then the ranged attacks. I've tried the name of the object and some different types to no avail. Any suggestions?
Code: [Select]
event.activator == "t_star"
event.activator == "throwing star"
event.activator == game.TYPE_MMISSILE
event.activator == game.TYPE_THROWN_OBJ
event.activator == game.TYPE_MISC_OBJ
« Last Edit: 16, April 2014, 20:49:05 by clobber »
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

smacky

« Reply #13 on: 16, April 2014, 21:55:55 »
Oh, I missed an easy one.

"if attack == game.TYPE_PLAYER" -- Attack is not an object type, it is the object itself. game.TYPE_PLAYER, OTOH, is a type, which is really just a number with a special name. So "attack" is an object which will never == a number.

You want "if attack.type == game.TYPE_PLAYER then"

Same thing. So test event.activator.name or event.activator.type, etc.

clobber

« Reply #14 on: 17, April 2014, 08:10:09 »
Ahah! good plan :)
Posted by Clobber

Collector Of Burnt out torches, 0 and Counting.

,-.  ___ ,-.
 \/ .   .  \ / 
(___O___)
 /  \      /   )
 ( ||       || )
  000     000
Woof, Woof!

Quote from: Longir
I use caution, fear is a distraction

Tags:
 

Related Topics

  Subject / Started by Replies Last post
0 Replies
6937 Views
Last post 17, January 2006, 17:13:01
by michtoen
3 Replies
1150 Views
Last post 08, February 2009, 12:40:53
by smacky
8 Replies
3006 Views
Last post 20, June 2009, 05:19:31
by l00natyk
4 Replies
1181 Views
Last post 24, September 2009, 21:43:25
by Nobbit
3 Replies
5041 Views
Last post 24, September 2012, 23:32:24
by ddhanna