| View previous topic :: View next topic |
| Author |
Message |
Chainsaw Lumberjack


Joined: 20 Oct 2007 Age: 15 Posts: 2378 Location: Israel
|
Posted: Sat Oct 20, 2007 2:47 am Post subject: Help me script this hog? |
|
|
I'm almost done with the hog pet I'm making ( I'm finishing the one in the DEV bundle ), Now i can't code an entire script file myself, so i used the tundra bunny script instead.
Can someone please tell me which parts of the script i need to change to get the following results?:
Decrease the frequency in which sound is played.
Make it stop sniffing for items :P
( It won't pick them up , but it still tries to find them )
Make it attack. ( I'm guessing this has something to do with the model, so you'll have to download the entire folder to help me with that one. )
Here's the entire folder, so you can test it ( ZIP format , 16KB , Fixed... ):
http://xchainsaw1x.piranho.com/hog.obj.zip
Last edited by Chainsaw on Sun Oct 21, 2007 9:07 pm; edited 1 time in total |
|
| Back to top |
|
 |
Maxaxle Elite Gamer


Joined: 06 Oct 2007 Age: 15 Posts: 2717 Location: San Diego
|
|
| Back to top |
|
 |
Zefz Lead Designer


Joined: 16 Sep 2007 Posts: 2301 Location: Norway
|
Posted: Sun Oct 21, 2007 4:58 am Post subject: |
|
|
To make it pick up items, you need an pickup/drop items animation.
The same goes for attacks (Unless you use a damage on bump script).
| Code: |
//Damage on bump
IfBumped
SetTargetToWhoeverBumped
IfFacingTarget
IfTargetIsOnHatedTeam
IfTargetIsAlive
tmpargument = rand & 512 + 256
tmpdistance = DAMAGEPOKE
DamageTarget
//This deals 1-3 poke damage to the bumper
|
I don't think variable sound frequency is used in the new SDL_Mixer sound system. But the old one was set in tmpdistance:
| Code: |
tmpargument = 1 //Which sound to play
tmpargument = rand & 1500 + 9700 //Sound frequency
PlaySound
|
Finding items is done with an AI script. SetTargetToDistantBlahID, then making it move towards it, then making it pick them up, etc.
Think already some similar AI scripts exist somewhere... _________________ http://egoboo.sourceforge.net
"The pen is mightier than the sword- IF it is sharpened, dipped in poison and thrown really really hard at your target. But seriously, you are better off with a sword." |
|
| Back to top |
|
 |
bgbirdsey Developer

Joined: 25 Sep 2007 Posts: 862 Location: Minnesota
|
Posted: Sun Oct 21, 2007 7:36 am Post subject: |
|
|
I hope this is helpful and not too long.....
| Quote: | Make it stop sniffing for items
( It won't pick them up , but it still tries to find them ) |
One way of programming AIs is to think of the AI as a "state machine". A state machine knows how to do one kind of task for each state that it is in. For instance, being in the state "hungry" would cause the hog to look for food and eat it, which would change the state to "satisfied".
If you look at it this way, the only thing you have to do is to figure out what kinds of tasks you want your AI to perform (the states) and what might cause the AI to change its state. For instance,
| Code: | if the hog is not in follow mode and the ai times out, the hog switches to following its owner
if the hog is following its owner and an item of IDSZ [XXXX] is within the hog's block it sets a waypoint for the object and switches to the sniffing mode
if the hog is bumped by an enemy and the enemy is weak, it switches to attack mode
if the hog is bumped by an enemy and the enemy is strong, it switches to flee mode |
So, here, there are several states: attack, flee, follow, sniff. And a couple of events that cause transitions: bumped by enemy, timed out.
Egoboo has a built-in system for tracking states, the default states are
: Parry, Wander, Guard, Follow, Surround, Retreat, Charge, Combat. But almost none of the AIs actually use the functions IfStateIsParry (or IfStateIsXXXX, or whichever). So, you can just use numbers to keep track of your AIs states and assign attack=1, flee=2, follow=3, sniff=4, ...
To test for these states, you can use IfStateIs1, IfStateIs2, IfStateIs3, ..., and to set the state you can use
| Code: |
tmpargument = XX
SetState
|
The only tick, then, is to figure out how to put the code into the script that switches the states at the correct times, and the code that implements a given AI action
For instance, you could change the code to
| Code: | // ZZ> This function makes the character wanders around its enemy
IfSpawned
MakeCrushValid
SetTargetToWhoeverIsHolding
IfTargetIsAPlayer
SetOwnerToTarget
JoinTargetTeam
MakeNameKnown
IfGrabbed
MakeCrushInvalid
IfNameIsKnown
SetTargetToWhoeverIsHolding
IfTargetIsAPlayer
SetOldTarget
SetTargetToOwner
IfTargetIsOldTarget
tmpargument = 5
Else
tmpargument = 6
SendMessageNear
Else
SetTargetToWhoeverIsHolding
IfTargetIsAPlayer
SetOwnerToTarget
JoinTargetTeam
MakeNameKnown
tmpargument = 3
SendMessageNear
tmpargument = 4
SendMessageNear
SetTargetToSelf
SetTargetToTargetLeftHand
DropItems
tmpargument = 16
SendMessageNear
IfDropped
SetTargetToSelf
StopTargetMovement
UnkeepAction
IfUsed
SetTargetToWhoeverIsHolding
tmpargument = 25
SetTargetReloadTime
IfTargetIsAPlayer
// =Cuddles=
SetTargetToSelf
tmpargument = 7
SendMessageNear
// Level
tmpx = targetlevel
tmpy = 2
IfXIsMoreThanY
tmpx = 2
tmpargument = 8 + tmpx
SendMessageNear
// Stats
tmpx = targetlife > 9
tmpy = 2
IfXIsMoreThanY
tmpx = 3
tmpargument = 11 + tmpx
tmpx = selfstr > 8
tmpy = selfwis > 8
SendMessageNear
// Stats
tmpx = selfint > 8
tmpy = selfdex > 8
tmpdistance = targetexp
tmpargument = 15
SendMessageNear
IfCrushed
tmpx = selfx
tmpy = selfy
tmpdistance = selfz
tmpargument = 4
SpawnExactParticle
SpawnExactParticle
SpawnExactParticle
SpawnExactParticle
GoPoof
tmpargument = 2
SendMessageNear
IfCleanedUp // Respawn
IfTargetIsAlive // Make sure killer is away
tmpx = 1100 //
tmpy = targetdistance //
IfXIsLessThanY //
RespawnCharacter //
Else // Killer is far away
RespawnCharacter //
IfKilled // This reduces the height of the char
IfNameIsKnown
SetOldTarget
SetTargetToOwner
IfTargetIsAlive
tmpargument = 0
SendMessageNear
SetTargetToOldTarget
Else
tmpargument = 1
SendMessageNear
tmpargument = 30 // Dead height
SetBumpHeight //
tmpargument = 5 // Sound
tmpdistance = rand & 2047 + 12000 //
PlaySound //
IfAttacked // Don't take kindly to attackers
SetTargetToWhoeverAttacked //
tmpargument = 4 // Sound
tmpdistance = rand & 2047 + 9300 //
PlaySound //
tmpargument = 1 // the attack state
SetState
IfBumped // Scooch around
SetTargetToWhoeverBumped
IfTargetIsOnHatedTeam
tmpargument = 1 // the attack state
SetState
Else
tmpx = rand & 1023 + targetx - 512
tmpy = rand & 1023 + targety - 512
ClearWaypoints
AddWaypoint
IfTimeOut // This is done every so often
// Do clucking
GetContent
tmpx = tmpargument
tmpy = 0
IfXIsMoreThanY
tmpargument = tmpargument - 1
SetContent
tmpargument = rand & 3
tmpdistance = rand & 2047 + 10000
PlaySound
tmpargument = 12
Else
tmpx = rand & 15
tmpy = 7
IfXIsMoreThanY
tmpargument = tmpx > 1
SetContent
tmpargument = rand & 15 + 30
SetTime
// Handle the states here, so they process only every so often
IfHeld
// Don't bother moving around if held
GetState
Else
IfStateIs1 // Attack
IfTargetIsOnHatedTeam
tmpx = targetspeedx + targetx
tmpy = targetspeedy + targety
ClearWaypoints
AddWaypoint
Else
tmpargument = 3
SetState
IfStateIs2 // Flee
IfTargetIsOnHatedTeam
tmpx = selfx*2 - targetx
tmpy = selfy*2 - targety
Else
tmpargument = 3
SetState
IfStateIs3 // Follow
IfTargetIsOnHatedTeam
tmpargument = 2
SetState
Else
tmpx = targetx + targetspeedx
tmpy = targety + targetspeedy
IfStateIs4 // Sniff
// Is it carrying something?
SetTargetToSelf
SetTargetToTargetLeftHand
// Has an item, so bring it to owner
tmpx = rand & 511 - 256 + ownerx
tmpy = rand & 511 - 256 + ownery
Else
// No item, so find one
tmpargument = [NONE]
tmpdistance = BLAHITEMS
SetTargetToNearestBlahID
// Don't grab kursed items
IfTargetIsKursed
GetState
Else
// Get closer?
tmpx = targetdistance
tmpy = 20
IfXIsLessThanY
// Pick up the item
tmpargument = LATCHALTLEFT
PressLatchButton
tmpx = targetx
tmpy = targety
tmpturn = targetturnto
tmpdistance = 200
Compass
Else
// The item is bad, so follow the owner
tmpx = ownerx
tmpy = ownery
Else
// No items around, so follow owner
tmpx = ownerx
tmpy = ownery
ClearWaypoints //
AddWaypoint //
End // Finished with this character
|
|
|
| Back to top |
|
 |
Maxaxle Elite Gamer


Joined: 06 Oct 2007 Age: 15 Posts: 2717 Location: San Diego
|
|
| Back to top |
|
 |
Chainsaw Lumberjack


Joined: 20 Oct 2007 Age: 15 Posts: 2378 Location: Israel
|
Posted: Mon Oct 22, 2007 1:55 am Post subject: |
|
|
Thanks guys, you've been helpful.
I'm almost done, once i fix a few things I'll post it in the general forum, complete with it's own icons and three skins.
I'll try to come up with new sound if i can, right now it uses this annoying licking sound.
Sorry about the broken link, I'll defiantly have a working link once I'm done.
Here's a screenie:
( I made three skins: brownish red, azure and green. )
And that's how the icon will look, not my best, but meh.
By the way, i had trouble with removing the sniffing option, because it seemed to screw up it's movement.
I replaced the "tmpargument = [NONE]" under item finding
with "tmpargument = [ABCD]", and since there is no way it could have an item of ABCD type, it will never look for items. |
|
| Back to top |
|
 |
Maxaxle Elite Gamer


Joined: 06 Oct 2007 Age: 15 Posts: 2717 Location: San Diego
|
|
| Back to top |
|
 |
Zefz Lead Designer


Joined: 16 Sep 2007 Posts: 2301 Location: Norway
|
Posted: Mon Oct 22, 2007 2:12 am Post subject: |
|
|
Icon looks great to me .
Seems you have some script errors shown in your screenshot, dunno if you knew this, but check them out to fix em. _________________ http://egoboo.sourceforge.net
"The pen is mightier than the sword- IF it is sharpened, dipped in poison and thrown really really hard at your target. But seriously, you are better off with a sword." |
|
| Back to top |
|
 |
Agent of Dread lolwut?? (Moderator)


Joined: 23 Sep 2007 Age: 11 Posts: 4347 Location: FACEPLANT
|
Posted: Mon Oct 22, 2007 3:27 am Post subject: |
|
|
I got a script error with Zombor but he was perfectly playable. _________________ FACEPLANT |
|
| Back to top |
|
 |
bgbirdsey Developer

Joined: 25 Sep 2007 Posts: 862 Location: Minnesota
|
Posted: Mon Oct 22, 2007 3:53 am Post subject: |
|
|
| What was the error in parserr.txt? |
|
| Back to top |
|
 |
Agent of Dread lolwut?? (Moderator)


Joined: 23 Sep 2007 Age: 11 Posts: 4347 Location: FACEPLANT
|
Posted: Mon Oct 22, 2007 4:13 am Post subject: |
|
|
Yu-hu. _________________ FACEPLANT |
|
| Back to top |
|
 |
Chainsaw Lumberjack


Joined: 20 Oct 2007 Age: 15 Posts: 2378 Location: Israel
|
Posted: Mon Oct 22, 2007 8:47 pm Post subject: |
|
|
| bgbirdsey wrote: | | What was the error in parserr.txt? |
How do you check it?
i tried going to the error log but it had no relevant info.
And i can't find the file. |
|
| Back to top |
|
 |
Maxaxle Elite Gamer


Joined: 06 Oct 2007 Age: 15 Posts: 2717 Location: San Diego
|
|
| Back to top |
|
 |
Chainsaw Lumberjack


Joined: 20 Oct 2007 Age: 15 Posts: 2378 Location: Israel
|
Posted: Mon Oct 22, 2007 9:56 pm Post subject: |
|
|
The script error is the only thing that's keeping me from finishing it.
It doesn't affect the hog in any way, but it's still annoying.
I searched the entire Egoboo folder for that file. no results. |
|
| Back to top |
|
 |
Zefz Lead Designer


Joined: 16 Sep 2007 Posts: 2301 Location: Norway
|
Posted: Tue Oct 23, 2007 2:28 am Post subject: |
|
|
Open parserror.txt which is located in the basicdat folder. _________________ http://egoboo.sourceforge.net
"The pen is mightier than the sword- IF it is sharpened, dipped in poison and thrown really really hard at your target. But seriously, you are better off with a sword." |
|
| Back to top |
|
 |
|