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
Grave Digging
Author Message
Capes
Journeyman
*

Posts: 57
Likes Given: 0
Likes Received: 4 in 4 posts
Joined: Mar 2018
Reputation: 0



Post: #1
Grave Digging
Only tested in 0.56d
Here's a grave digging script.
Basically it allows a player to use a shovel on a grave to dig it up.
They may get goodies, disturb the dead, find something gross or have their shovel break.
This demonstrates the basic use of SERV.LIST (a basic array) functionality.
It also shows how an event can alter an items behavior.
Change GRAVE_RESET_DELAY to a lower number to test it.

PHP Code:
/////////////////////////////////////////////////////////////////////////////////////
//// GRAVE DIGGING - shovel & graves
//// By: Capes last modified - 2018-04-14
/////////////////////////////////////////////////////////////////////////////////////
[DEFNAME body_parts]
random_body_part {01b12 1 01b14 1 01b18 1 01b1a 1 01b1c 1 01cdd 1 01ce5 1 01ced 1 01cf0 1 01cef 1 01cee 1 01ce1 1 01ce9 1 01dad 1}

[
DEFNAME gravedigging_settings]
GRAVE_RESET_DELAY 600 //in secounds (10 mins)
////////////////////////////////////////////////////////////
////// shovel
////////////////////////////////////////////////////////////
[ITEMDEF 0f39]
DEFNAME=i_shovel
TYPE
=t_weapon_mace_pick
FLIP
=1
VALUE
=20
WEIGHT
=6.0
RESOURCES
=4 i_ingot_iron,2 i_log
SKILLMAKE
=Tinkering 20.0,t_tinker_tools
TEVENTS
=e_grave_digging        //<- this event adds gravedigging to shovel
CATEGORY=Items by Professions
SUBSECTION
=Miner
DESCRIPTION
=Shovel
DUPELIST
=0f3a
ON
=@Create
   HITPOINTS
={150 250}
   
UsesMax=50

[ITEMDEF 0f3a]
//shovel
DUPEITEM=0f39

///////////////////////////////////////////////////////
//// EVENTS e_grave_digging
////    - adding e_grave_digging to TEVENTS of any item provides 
////        this functionality
////    - defines ON=@TargOn_Ground handler
////    - prevents usage if mounted, to far away or if already dug up
////    - makes sure tile selected is i_grave
////    - lowers karma, then randomly picks an outcome
////        - outcomes - 
////        1 - you found nothing
////        2 - you have disturbed the dead, summons 1 undead
////        3 - you found a body part
////        4 - you found something
////    - reduces uses of item (assuming shovel defualts) with possible breakage
////    - stores src.targp in SERV.LIST._graves_dug_up (prevents further digging)
////    - fires a timerf in GRAVE_RESET_DELAY to remove cords from SERV.LIST._graves_dug_up
////        to allow this tile to be dug up again
///////////////////////////////////////////////////////
[TYPEDEF e_grave_digging]
ON=@TargOn_Ground
    
//is mounted quit
    
IF (<SRC.FINDLAYER.layer_horse>)    
        
SRC.SYSMESSAGE You can't dig up a grave while mounted!
        return 1
    ENDIF
    //to far away quit
    IF (<src.distance <src.targp>> > 1)         
        SRC.SYSMESSAGE Your to far away.
        return 1
    ENDIF
    //already dug up
    IF ((<SERV.LIST._graves_dug_up.FINDELEM <src.targp>> != -1) &&(<eval <SERV.LIST._graves_dug_up.COUNT>> != 0))
        SRC.SYSMESSAGE This grave has already been dug up.
        return 1
    ENDIF    

    //only do if (dispid=i_grave)
    IF (<serv.map(<src.targp.x>,<src.targp.y>).statics.0.dispid> == i_grave)
        //dig up grave, add loot, lose karma
        local._karma = <eval <src.karma>>
        local._karma -= 10
        src.karma = <dlocal._karma>
        SRC.SYSMESSAGE @37 You have lost some karma
        
        //get random number 0-3
        local._rnd_num = <eval RAND(4)>
        //respond to random number (maybe replace with a doswitch)
        IF (<eval <local._rnd_num>> == 0)
            //you found nothing
            SRC.SYSMESSAGE You dig but find nothing.
        ELSEIF (<local._rnd_num> == 1)
            //you have disturbed the dead
            SRC.SYSMESSAGE @30 You dig and disturb the dead.
            SERV.NEWNPC {c_zombie 1 c_skeleton 1 c_ghoul 1} 
            NEW.P = <src.targp.x>,<src.targp.y>,<eval <src.targp.z>+1>
        ELSEIF (<local._rnd_num> == 2)
            //you found a body part
            SERV.NEWITEM random_body_part
            SRC.SYSMESSAGE @30 Gross you found a body part.
            NEW.BOUNCE
        ELSE
            //you found something
            SERV.NEWITEM {poor_gold_pile 1 random_jewelry 1 random_jewel 1}    
            SRC.SYSMESSAGE @70 You found <NEW.name>.
            NEW.BOUNCE
        ENDIF
        
        //reduce shovel uses
        USESCUR --
        IF (<USESCUR><=0)
            DESTROY 1 
            SRC.SYSMESSAGE Your shovel broke.
        ENDIF
        
        //store cords & remove cords sometime laiter
        SERV.LIST._graves_dug_up.ADD <src.targp>
        timerf <dDEF.GRAVE_RESET_DELAY> f_remove_grave_dugup_flag <src.targp>        
                
        return 1    //<-- don'
t run other events ie minning stuff
    
ENDIF



///////////////////////////////////////////////////////
//// FUYNCTION     f_remove_grave_dugup_flag <args>
////    Param - <args> = expecting a <P> string equivelent
////        - removes given cords<args> from SERV.LIST._graves_dug_up
////        - this assumes the cords given in <args> exists
///////////////////////////////////////////////////////
[FUNCTION f_remove_grave_dugup_flag]
    
//find the element that holds the cords, and remove it
    
SERV.LIST._graves_dug_up.<eval <SERV.LIST._graves_dug_up.FINDELEM <args>>>.REMOVE


///////////////////////////////////////////////////////////////
////    Grave Tiles
///////////////////////////////////////////////////////////////
[MULTIDEF m_grave_ns]
//ID=98967F
NAME=Grave
TYPE
=t_multi
CATEGORY
=Multis
SUBSECTION
=Misc
DESCRIPTION
=Grave (north south)
MULTIREGION=0,0,0,0
COMPONENT
=00edf,0,0
COMPONENT
=00ee1,0,-1

[MULTIDEF m_grave_ew]
//ID=98967F
NAME=Grave
TYPE
=t_multi
CATEGORY
=Multis
SUBSECTION
=Misc
DESCRIPTION
=Grave (north south)
MULTIREGION=0,0,0,0
COMPONENT
=00ee0,0,0
COMPONENT
=00ee2,-1,0

[ITEMDEF 0edf]
DEFNAME=i_grave
CATEGORY
=Decoration Dungeons and The Dead
SUBSECTION
=Graves Gravestones
DESCRIPTION
=Grave
//TAG._can_be_dug = 1
DUPELIST=0ee0,0ee1,0ee20ed3 //<- these are also considered ID=0edf when querried OR i_grave
ON=@CREATE
    ATTR
=08010

[ITEMDEF 0ee0]
//grave
DUPEITEM=0edf
ON
=@CREATE
    ATTR
=08010

[ITEMDEF 0ee1]
//grave
DUPEITEM=0edf
ON
=@CREATE
    ATTR
=08010

[ITEMDEF 0ee2]
//grave
DUPEITEM=0edf
ON
=@CREATE
    ATTR
=08010
    
[ITEMDEF 0ed3]
//grave
DUPEITEM=0edf
ON
=@CREATE
    ATTR
=08010



[EOF


Capes
04-14-2018 10:10 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Capes's post
Post Reply 


Forum Jump:


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