The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NPCS - Town stones
Author Message
Soulless
Super Moderator
****

Posts: 335
Likes Given: 29
Likes Received: 49 in 27 posts
Joined: Jun 2012
Reputation: 12

Ye Olde Sphere

Post: #18
RE: NPCS - Town stones
here's my AI as of now. i feel like the weapon selection part could be simplified, but i wanted to make the npc as brilliant as possible. incase the project grows and he ends up looting random weapons/shields. checks for the strongest damage weapon + skill of npc factors into weapon selection. if the best weapon is 1 handed the npc then looks for the best shield in its bag and equips it. its missing a ranged weapon selection process but has a spot for it. the rest is stuff i gutted from the npc_ai script in the addon from the SCP pack.

as a side note, does anyone know how to make it so that an NPC will walk from one spot on the map to another. like say from britain graveyard to britain bank, id like him to run the whole way. anyone know how to do that?

Code:
[defname custom_ai_settings]
fearofdeath    60
healself    60

[events e_custom_AI]

on=@gethit
if ((<body>==c_man) || (<body>==c_woman)) && (<memoryfindtype.memory_war_targ>)
if (<distance <memoryfindtype.memory_war_targ.link.uid>> < 3)    //equip the best melee weapon i can find, enemy is close range
ref1=<uid>
ref2=<findlayer.1.uid>      //if i have a weapon in my hand start with it
if (strmatch(t_weapon*,<findlayer.2.type>) && (<findlayer.2.type>!=t_shield) && (<findlayer.2.type>!=t_weapon_bow) && (<findlayer.2.type>!=t_weapon_xbow)
ref2=<findlayer.2.uid>         //if i'm holding a two hand weapon start with that (not a shield or ranged weapon)
endif
forcont <findlayer.21.uid> 1
if (strmatch(t_weapon*,<type>) && (<type>!=t_weapon_arrow) && (<type>!=t_weapon_bolt) && (<type>!=t_weapon_bow) && (<type>!=t_weapon_xbow)
if !(<ref2>)              //if i'm not holding any weapons start with the first on you find in my bag
ref2=<uid>
endif
if <eval (<damavg <dam>>+(<ref1.<serv.skill.<skill>.key>>/10))> > <eval(<damavg <ref2.dam>>+(<ref1.<serv.skill.<ref2.skill>.key>>/10))>  
ref2=<uid>            //if this weapon is best so far that i have skill in, keep it in mind
endif
endif
endfor
if (<ref2>!=<findlayer.1.uid>) && (<ref2>!=<findlayer.2.uid>)
ref1.equip <ref2>        //equip the best weapon ive got (skill accounted for also)
endif
if (!<findlayer.2.uid>) || !(strmatch(t_weapon*,<findlayer.2.type>) //now that i'm holding my best weapon, if it's one handed see if i have a shield    
ref2=                //clear reference 2
if (<findlayer.2.type>==t_shield)
ref2=<findlayer.2.uid>
endif
forcont <findlayer.21.uid> 1
if (<type>==t_shield)        //if i don't have a shield equipped start with first one found in bag
if !(<ref2>)
ref2=<uid>
endif
if (<damavg <armor>> > <damavg <ref2.armor>>)
ref2=<uid>            //if this shield is the best so far, keep it in mind
endif        
endif
endfor
if (<ref2>)
ref1.equip <ref2>        //equip the best shield ive got
endif
endif


elseif (<distance <memoryfindtype.memory_war_targ.link.uid>> > 3)
return 0//i'm being attacked at range, if i have a bow or crossbow, equip it
endif

endif


if (<hits> < <eval (<str>*<def0.fearofdeath>)/100>)
    //if  !(<findid.i_potion_heal>)
        if (<src.uid> != <uid>)
        act = <src.uid>
        flee 20
        tag0.fleeing = 1
        damage <argn1> <argn2> <uid>
        return 1
        endif
    //endif
endif

//heal myself with a potion if i have one, when im below 'def.healself'% health
if (<hits> <= <eval (<maxhits>*<def0.healself>)/100>)
    if (<findid.i_potion_heal>)
    findid.i_potion_heal.useitem
    return 0
    endif
endif

//heal myself with magic if im able, when im below 'def.healself'% health
if (<hits> <= <eval (<maxhits>*<def0.healself>)/100>)
    if (<cancast s_greater_heal>)
    npccast s_greater_heal,<uid>
    endif
endif


//dispell conjured/summoned pets that are attacking me
if (<src.flags>&statf_conjured)
if (<mana> > <serv.spell.s_dispel.manause>)
src.spelleffect s_dispel,1500
src.sound snd_spell_dispel
mana -= <serv.spell.s_dispel.manause>
endif
endif

//attack the person dealing the most damage to me
local.mosthits = 0
local.most_dangerous_enemy = 0
for n 0 <eval <attacker> -1 >
  if (<attacker.<dlocal.n>.dam> > <local.mosthits>) && (<canseelos <attacker.<dlocal.n>>>)
    local.mosthits = <attacker.<dlocal.n>.dam>
    local.most_dangerous_enemy = <attacker.<dlocal.n>>
  endif
endfor
attack <local.most_dangerous_enemy>

on=@npcactfight
if (<tag0.fleeing>)
argn = -1
endif

[function damavg]
return <eval ((<argv[0]>+<argv[1]>)/2)>

[chardef c_icedragon]
name=IceDragon
id=c_man
dam=15,20
armor=//20
tevents=e_custom_ai

category=Custom
subsection=NPCs
description=IceDragon

on=@create
    npc=brain_human
    color=colors_skin
    str={151 165}
    dex={151 165}
    int={151 165}
    swordsmanship=100.0
    tactics=100.0
    magicresistance=100.0
    healing=100.0
    itemnewbie=i_hair_ponytail
    color=colors_hair
    itemnewbie=i_beard_goatee
    color=match_hair
    
on=@npcrestock
    item=i_platemail_gloves
    item=i_platemail_helm
    item=i_platemail_arms
    item=i_platemail_gorget
    item=i_platemail_chest
    item=i_platemail_leggings
    item=i_halberd
    item=i_cape
    color=0386
    item=i_tunic
    color=020
    item=i_kilt
    color=0386
    item=i_potion_heal
    item=i_potion_heal
(This post was last modified: 07-13-2012 02:16 AM by Soulless.)
07-13-2012 02:15 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Messages In This Thread
NPCS - Town stones - Soulless - 07-11-2012, 07:32 AM
RE: NPCS - Town stones - Skul - 07-11-2012, 08:09 AM
RE: NPCS - Town stones - Anarch Cassius - 07-11-2012, 08:17 AM
RE: NPCS - Town stones - Skul - 07-11-2012, 08:44 AM
RE: NPCS - Town stones - RanXerox - 07-11-2012, 08:56 AM
RE: NPCS - Town stones - Skul - 07-11-2012, 09:11 AM
RE: NPCS - Town stones - RanXerox - 07-11-2012, 09:24 AM
RE: NPCS - Town stones - Extreme - 07-11-2012, 09:33 AM
RE: NPCS - Town stones - Soulless - 07-11-2012, 03:35 PM
RE: NPCS - Town stones - Soulless - 07-12-2012, 10:37 AM
RE: NPCS - Town stones - Extreme - 07-12-2012, 10:45 AM
RE: NPCS - Town stones - Anarch Cassius - 07-12-2012, 11:55 AM
RE: NPCS - Town stones - Soulless - 07-12-2012, 12:14 PM
RE: NPCS - Town stones - Anarch Cassius - 07-12-2012, 01:02 PM
RE: NPCS - Town stones - Soulless - 07-12-2012, 06:15 PM
RE: NPCS - Town stones - darksun84 - 07-12-2012, 07:57 PM
RE: NPCS - Town stones - Soulless - 07-12-2012, 08:33 PM
RE: NPCS - Town stones - Soulless - 07-13-2012 02:15 AM
RE: NPCS - Town stones - Anarch Cassius - 07-13-2012, 02:14 PM
RE: NPCS - Town stones - Soulless - 07-13-2012, 02:21 PM
RE: NPCS - Town stones - Anarch Cassius - 07-13-2012, 02:24 PM
RE: NPCS - Town stones - Soulless - 07-13-2012, 03:08 PM
RE: NPCS - Town stones - Anarch Cassius - 07-13-2012, 03:28 PM
RE: NPCS - Town stones - RanXerox - 07-13-2012, 03:29 PM
RE: NPCS - Town stones - Anarch Cassius - 07-19-2012, 01:11 PM
RE: NPCS - Town stones - Soulless - 07-26-2012, 12:33 AM

Forum Jump:


User(s) browsing this thread: 8 Guest(s)