DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • April 19, 2018, 02:29:48 PM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Is It Possible To....  (Read 754 times)
0 Members and 1 Guest are viewing this topic.
TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« on: September 25, 2017, 07:49:59 PM »

Just a complete random curiousity question...

is it possible to set a Creature, in the Creature Editor...to attack only a certain gender...or only a certain race....or only a certain alignment character?
Logged
Stephen.Kise
Codemeister
****
Offline Offline

Posts: 390


So meme'd up.


View Profile
« Reply #1 on: September 26, 2017, 09:55:09 AM »

That is a very neat idea for something such as a highwayman that targets women. It very much is possible - however without a module to prevent the fight from starting, the creature has a chance to hit once, through the surprise attack mechanic. This can be done through an AI script (Be careful who you give creature editor). You would have to decide on what conditions the creature should attack. If you want it to attack women, you would want to check if $session['user']['sex'] is the constant SEX_FEMALE.

Code:
<?php
global $session$enemies$badguy;
if (
$session['user']['sex'] == SEX_FEMALE) {
    
//We want our highwayman to attack women, but not men. Return to continue the next round of fighting.
    
return;
}
foreach (
$enemies as $id => $enemy) {
    if (
$enemy['creaturename'] == $badguy['creaturename']) {
        unset(
$enemies[$id]);
        
//Remove the highwayman from the fight array. He should flee in group combat.
    
}
}
$badguy['creaturegold'] = 0;
$badguy['creatureexp'] = 0;
$badguy['dead'] = true;
// Remove the rewards, remove the creature from the fight.
output("The Highwayman notices a little too late that you are a male and flees!`n");
« Last Edit: September 26, 2017, 09:57:27 AM by Stephen.Kise » Logged

Slowly progressing fork with PHP 7 support: https://github.com/stephenKise/Legend-of-the-Green-Dragon
Cheap VPS Hosting (10$ credit!): https://m.do.co/c/acde75b086c5
TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #2 on: September 26, 2017, 12:26:03 PM »

That is a very neat idea for something such as a highwayman that targets women. It very much is possible - however without a module to prevent the fight from starting, the creature has a chance to hit once, through the surprise attack mechanic. This can be done through an AI script (Be careful who you give creature editor). You would have to decide on what conditions the creature should attack. If you want it to attack women, you would want to check if $session['user']['sex'] is the constant SEX_FEMALE.

Code:
<?php
global $session$enemies$badguy;
if (
$session['user']['sex'] == SEX_FEMALE) {
    
//We want our highwayman to attack women, but not men. Return to continue the next round of fighting.
    
return;
}
foreach (
$enemies as $id => $enemy) {
    if (
$enemy['creaturename'] == $badguy['creaturename']) {
        unset(
$enemies[$id]);
        
//Remove the highwayman from the fight array. He should flee in group combat.
    
}
}
$badguy['creaturegold'] = 0;
$badguy['creatureexp'] = 0;
$badguy['dead'] = true;
// Remove the rewards, remove the creature from the fight.
output("The Highwayman notices a little too late that you are a male and flees!`n");

Neat.  so this is not a module, but something which goes in the Creature Editor, right?

Because that is what I am looking for.

I am looking to create a few creatures that only attack men...and a few that attack only women.

As an extension to this, I also wanted to create a creature that only attacks a certain race...for example, only Elves or only Trolls, or only Humans or whatever.
Logged
Stephen.Kise
Codemeister
****
Offline Offline

Posts: 390


So meme'd up.


View Profile
« Reply #3 on: September 27, 2017, 12:22:07 PM »

That is a very neat idea for something such as a highwayman that targets women. It very much is possible - however without a module to prevent the fight from starting, the creature has a chance to hit once, through the surprise attack mechanic. This can be done through an AI script (Be careful who you give creature editor). You would have to decide on what conditions the creature should attack. If you want it to attack women, you would want to check if $session['user']['sex'] is the constant SEX_FEMALE.

Code:
<?php
global $session$enemies$badguy;
if (
$session['user']['sex'] == SEX_FEMALE) {
    
//We want our highwayman to attack women, but not men. Return to continue the next round of fighting.
    
return;
}
foreach (
$enemies as $id => $enemy) {
    if (
$enemy['creaturename'] == $badguy['creaturename']) {
        unset(
$enemies[$id]);
        
//Remove the highwayman from the fight array. He should flee in group combat.
    
}
}
$badguy['creaturegold'] = 0;
$badguy['creatureexp'] = 0;
$badguy['dead'] = true;
// Remove the rewards, remove the creature from the fight.
output("The Highwayman notices a little too late that you are a male and flees!`n");

Neat.  so this is not a module, but something which goes in the Creature Editor, right?

Because that is what I am looking for.

I am looking to create a few creatures that only attack men...and a few that attack only women.

As an extension to this, I also wanted to create a creature that only attacks a certain race...for example, only Elves or only Trolls, or only Humans or whatever.
Yes, you can drop this script into a creatures 'AI Script' field. Anyone with creature editor can edit an AI - so be VERY, VERY careful who you give creature editor to. It should be treated like the 'Run Raw SQL' or 'Megauser' superuser flags.
Logged

Slowly progressing fork with PHP 7 support: https://github.com/stephenKise/Legend-of-the-Green-Dragon
Cheap VPS Hosting (10$ credit!): https://m.do.co/c/acde75b086c5
TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #4 on: September 28, 2017, 01:00:47 AM »

Cool.  Have to try it.
Logged
TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #5 on: October 03, 2017, 06:44:15 AM »

Hummm, I do not see anywhere in the Creature Editor I can do this.

I should mention, at the moment, I am running 1.1.0 - is that matter?  Is this something that can only be done on higher versions?

Again, this was a curiousity question.


I now have a test server...and I am looking at the possibility of an upgrade, but ONLY if it can be done without breaking anything I already have in place.
Logged
TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #6 on: April 11, 2018, 03:40:47 PM »

OK, thanks Stephen, for turning me back onto this thread.

The AI given above worked, but you need to take out the first line the <?php line

Because it causes a parsing error.

Also, two things...not sure if anything could be done with this...

1. when doing auto-fighting...the monster DOES pull away after one round, as it should (I had a creature pull away from a female warrior....and one that pulled away from a male warrior to test this.  The one that pulls away from female does pull away from female and not male, likewise in reverse for the other.

That works.

2. If you kill in first round, you kill and get the full exp for killing.

3. If the creature pulls away, you still get the death message, which you probably should not get...since you did not kill the creatiure...also, if you are runing clan pyramids, and get the bonus for your clan having all three pyramids...you STILL DO get the exp bonus when the creature pulls away.

So...just a couple of subtle things, not a huge issue, but wondering if they can be dealt with.
Logged
Aeolus
Mod God
*****
Offline Offline

Posts: 1859


You're welcome.


View Profile WWW
« Reply #7 on: April 11, 2018, 03:50:30 PM »

The AI given above worked, but you need to take out the first line the <?php line

Because it causes a parsing error.

That's because it just runs the script that's there, it's not a brand new script that needs the <?php identifier, which is only included here to highlight the colours. Look up the eval() function for more information.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #8 on: April 11, 2018, 05:21:02 PM »

The AI given above worked, but you need to take out the first line the <?php line

Because it causes a parsing error.

That's because it just runs the script that's there, it's not a brand new script that needs the <?php identifier, which is only included here to highlight the colours. Look up the eval() function for more information.

ok.  I understand the php thing for the colors.  But there is no eval() function in the provided code.  Does the game engine use an eval() function as part of the AI, then?  If so, why doesn't it break when it hits the equal sign?  It does work, on my creature that is supposed to not withdraw against female warriors, that one does continue to stand with my female warrior...the one that is supposed to withdraw...does withdraw.

The only time this does NOT work is...if you happen to kill the creature that is supposed to withdraw....in the first round...then you still kill them.  That I understand, because the AI only executes after the first round.

Not sure what about the eval() function you are trying to have me understand here??
Logged
Aeolus
Mod God
*****
Offline Offline

Posts: 1859


You're welcome.


View Profile WWW
« Reply #9 on: April 12, 2018, 12:43:40 AM »

ok.  I understand the php thing for the colors.  But there is no eval() function in the provided code.  Does the game engine use an eval() function as part of the AI, then?  If so, why doesn't it break when it hits the equal sign?  It does work, on my creature that is supposed to not withdraw against female warriors, that one does continue to stand with my female warrior...the one that is supposed to withdraw...does withdraw.

The only time this does NOT work is...if you happen to kill the creature that is supposed to withdraw....in the first round...then you still kill them.  That I understand, because the AI only executes after the first round.

Not sure what about the eval() function you are trying to have me understand here??

That's because, yes, you input the code and the game engine eval's it itself. For reference, it's in lib/extended-battle.php file; search for the execute_ai_script() function.

I was merely explaining why eval() broke when you submitted the code with <?php and the resultant parsing error, not teaching how you to fix your code. As for that, I've no idea because I haven't looked at it.
Logged

TGTarheel
Codemeister
****
Offline Offline

Posts: 388


View Profile
« Reply #10 on: April 12, 2018, 05:53:26 AM »

ok.  I understand the php thing for the colors.  But there is no eval() function in the provided code.  Does the game engine use an eval() function as part of the AI, then?  If so, why doesn't it break when it hits the equal sign?  It does work, on my creature that is supposed to not withdraw against female warriors, that one does continue to stand with my female warrior...the one that is supposed to withdraw...does withdraw.

The only time this does NOT work is...if you happen to kill the creature that is supposed to withdraw....in the first round...then you still kill them.  That I understand, because the AI only executes after the first round.

Not sure what about the eval() function you are trying to have me understand here??

That's because, yes, you input the code and the game engine eval's it itself. For reference, it's in lib/extended-battle.php file; search for the execute_ai_script() function.

I was merely explaining why eval() broke when you submitted the code with <?php and the resultant parsing error, not teaching how you to fix your code. As for that, I've no idea because I haven't looked at it.

OK, gotcha.  Just wasn't exactly sure what you were wanting me to see, thanks for the better explanation.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
24 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search