DragonPrime - LoGD Resource Community

Coding Support => Coding Support Desk => Topic started by: TGTarheel on September 25, 2017, 07:49:59 PM



Title: Is It Possible To....
Post by: TGTarheel 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?


Title: Re: Is It Possible To....
Post by: Sunday 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");


Title: Re: Is It Possible To....
Post by: TGTarheel 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.


Title: Re: Is It Possible To....
Post by: Sunday 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.


Title: Re: Is It Possible To....
Post by: TGTarheel on September 28, 2017, 01:00:47 AM
Cool.  Have to try it.


Title: Re: Is It Possible To....
Post by: TGTarheel 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.


Title: Re: Is It Possible To....
Post by: TGTarheel 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.


Title: Re: Is It Possible To....
Post by: Aeolus 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.


Title: Re: Is It Possible To....
Post by: TGTarheel 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??


Title: Re: Is It Possible To....
Post by: Aeolus 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.


Title: Re: Is It Possible To....
Post by: TGTarheel 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.

© 2018 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines