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
e_Carnivores - Making Carnivores hunt
Author Message
Capes
Journeyman
*

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



Post: #3
RE: e_Carnivores - Making Carnivores hunt
Thank you n1ghtwish!
Based on your suggestions I have made some changes.
- No longer am I modifying sphere_*.scp files directly. Instead all code is gunna be in a customs folder, that will override the original sphere_*.scp files.

To make this work - create a file.scp (call it what you want), place it in a custom folder, make sure sphere_tables.scp reflects & reads the folder/file last.
Copy/paste below into that file. Restart server.

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//// EVENT OVERRIDES
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////
///// HUNGER_RATE_DECAY_TIME = 120
//// (in secs)
//// 120 = every 2 mins at 20 mins per day cycle or reduced 10 times a day
//// so critter with mxfood=10 will eat once a day
/////////////////////////////////////////////////////
[DEFNAME hunger_settings]
HUNGER_RATE_DECAY_TIME = 120

[EVENTS e_Carnivores]
// weak carnivores.
ON=@CREATE
EVENTS +e_Hunger
f_setNeedsFood

[EVENTS e_Carnivores2]
// normal carnivores.
ON=@CREATE
EVENTS +e_Hunger
f_setNeedsFood

[EVENTS e_Carnivores3]
// strong carnivores.
ON=@CREATE
EVENTS +e_Hunger
f_setNeedsFood


/////////////////////////////////////////////////////
//// EVENT e_Hunger
//// -our event handler for ON=@ HUNGER/KILL/DEATH
//// -only executes when (hunger_in_effect) is set on animal
//// -1)sets a new brain to animal and possible buff/debuff based on e__Carnivores EVENTS
//// -2)resets brain to animal after killing (eating) so it doesn't hunt anymore
//// -3)cleans up mem from tags
/////////////////////////////////////////////////////
[EVENTS e_Hunger]
ON=@HUNGER //<-- triggered from f_Hunger_handler

IF !(<dTAG0.hunger_in_effect>)
return //no hunger_in_effect so quit
ENDIF
//change brain and do something special for given e_Carnivore's type
IF (<TEVENTS> & e_Carnivores)
//we are e_Carnivores (weak), do something

ELSEIF (<TEVENTS> & e_Carnivores2)
//we are e_Carnivores2 (normal), do something

ELSEIF (<TEVENTS> & e_Carnivores3)
//we are e_Carnivores3 (strong), do something

ENDIF
//we are hungry attack something
NPC = brain_berserk

ON=@KILL //<-- triggered after any kill
IF !(<dTAG0.hunger_in_effect>)
return //no hunger_in_effect so quit
ENDIF
//change back to animal brain, reset hunger lvl and restart timer
NPC = brain_animal
TAG0.hunger_lvl =<eval <FOOD>>
TIMERF <dDEF.HUNGER_RATE_DECAY_TIME> f_Hunger_handler

ON=@DEATH
IF !(<dTAG0.hunger_in_effect>)
return //no hunger_in_effect so quit
ENDIF
//clear hunger lvl tag & hunger in effect from mem
TAG0.hunger_lvl =
TAG0.hunger_in_effect =

/////////////////////////////////////////////////////
//// FUNCTION f_setNeedsFood
//// -prevents usage if not brain_animal (must be an animal)
//// -set hunger lvl & hunger in effect tags
//// -starts our hunger handler
/////////////////////////////////////////////////////
[FUNCTION f_setNeedsFood]
//only do if this is an animal
//set variable to store hunger level & set var to show hunger is in effect & start timer
IF (<NPC> == brain_animal)
TAG0.hunger_lvl = <eval <FOOD>>
//prevents other scripts from triggering our events
TAG0.hunger_in_effect = 1
TIMERF <dDEF.HUNGER_RATE_DECAY_TIME> f_Hunger_handler
ENDIF


/////////////////////////////////////////////////////
//// FUNCTION f_Hunger_handler
//// -recusive routine
//// -reduces hunger lvl by 1 each interval
//// -stops recursing and fires @HUNGER event of e_Hunger (events) above
/////////////////////////////////////////////////////
[FUNCTION f_Hunger_handler]
//reduce hunger lvl
TAG0.hunger_lvl -= 1

//if hungry fire hunger trigger and exit otherwise run timer-func again
IF (<dTAG0.hunger_lvl> == 0)
//trigger hunger event
TRIGGER @HUNGER
return
ENDIF
TIMERF <dDEF.HUNGER_RATE_DECAY_TIME> f_Hunger_handler

/////////////////////////////////////////////////////

Thanks
Capes

PS- it was suggested that ISEVENT be used but that only works on EVENTS added in ON=@CREATE of chardef, and TEVENTS is a separate list so I was forced to use (<TEVENTS> & e_Carnivores2).
(This post was last modified: 03-31-2018 01:41 AM by Capes.)
03-25-2018 05:21 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Capes's post
Post Reply 


Messages In This Thread
RE: e_Carnivores - Making Carnivores hunt - Capes - 03-25-2018 05:21 AM

Forum Jump:


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