Scripts / Is it possible ? ai attacking an entity

Author
Message
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 8th Feb 2016 23:30
Hi All,
I have only just started to play around with scripts so am learning, but I'm trying to create a horde type of attack, enemies attacking the main gate, so I have the enemies getting to the gate but cant work out how to have them identify they are within specific distance of the object and change to attack the object , I borrowed this from the forum, this gets the character to the gate. I think it was smallg - Thanks


Any help appreciated
if ai_soldier_state[e]=="idle" then

EntObjNogate = 32 -- gate entity's ID to move AI to

EntObjNo = g_Entity[e]['obj']; -- AI soldier entity number

ai_start_x[e] = g_Entity[EntObjNogate]['x'] -- gate object's X
ai_start_z[e] = g_Entity[EntObjNogate]['z'] -- gate object's Z
AISetEntityControl(EntObjNo,AI_MANUAL)
CharacterControlArmed(e)
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
else
end
end
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th Feb 2016 23:41 Edited at: 8th Feb 2016 23:45
use this https://forum.game-guru.com/outbound?url=https%3A%2F%2Fforum.game-guru.com%2Fthread%2F207801%3Fpage%3D12%23msg2538121

so your script will look like this

life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 9th Feb 2016 01:49
Thanks so much smallg, I went through your thread, bookmarked thanks,
I did try this script but I keep getting syntax errors, eof expected near end on multiple lines. I have tried to fix but am getting confused, could I ask you to comment the code you gave me so that I can learn what is doing what ?
Thanks for your patience
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th Feb 2016 12:24
ok well your script code wasnt a complete script so you need to remember to rename my code to match your file name
and i made a small mistake when i copy & paste the state definition, it should read 'ai_soldier_state[e]="idle"'
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 9th Feb 2016 22:16
Thanks again, I appreciate the time you've taken,
It was actually the function I was looking to learn from, but as you suggested to ignore it I will, I have the code not throwing any errors but nothing changes when its running, do I have to declare "ai_soldier_state[e]=="attack gate"" somewhere ?

Thanks
M
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 9th Feb 2016 23:58 Edited at: 10th Feb 2016 00:00
nothing changes because you need to put in what you want to happen in the new state - all i did was add the code to check the character is at the gate

as for the function... not sure what i can explain about it, basically it checks for the range first and then the angle of the character is within the given angle "allowance" (checking each side separately so i can adjust for the below 0 and above 360 cut off)

and yes you need to add your new state
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 10th Feb 2016 02:05 Edited at: 10th Feb 2016 02:21
Thanks SG but this has driven me bonkers, I don't quite get how transitioning from one animation to another can be so complex (to me at least), it seems no matter what I change the entity (the armed goblin) just runs to the gate (intended), rotates around and just keeps running on the spot (definitely not intended), I used the fantasycreature script as a base, here it is in full if you feel like tackling it but I understand if its too much grief. Thanks again for trying

PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 10th Feb 2016 02:51 Edited at: 10th Feb 2016 02:57
Not sure if this will help.
Quote: " it seems no matter what I change the entity (the armed goblin) just runs to the gate (intended), rotates around and just keeps running on the spot (definitely not intended), "


monte, it looks like you changed smallg's EntityLooking function at line 67.. in the above script..

from
if GetDistance(e,t) <= dis then -- this is the distance between entity and gate
to
if GetPlayerDistance(e,t) <= dis then -- this is the distance between entity and the player

it needs to be.. if GetDistance(e,t) <= dis then

Maybe the ai cannot get to within 150 units of the origin/centre of the gate? .
Try increasing the 150 distance value in..
if EntityLooking(e,EntObjNogate,150,25) == 1 then

[Update typo wrong function..]
Also smallg,s EntityLooking function calls for the GetDistance(e,t) function to get the distance between entity and gate, but I don't see it in the attached scripts.

Cheers
Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 10th Feb 2016 03:15
Thanks for taking a look perelect,

I did change line 67, thinking it was a typo because it keeps throwing a nil value, the area around the "gate" is unobstructed so I'm really confused as I still cant see where SG's script is calling for GetPlayerDistance(e,t) function so I didn't include it ?

Mother told me there would be days like this
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 10th Feb 2016 03:26

This is working for me.
notes in the script
Cheers

Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 10th Feb 2016 04:14
Thanks, that cleared the errors, much appreciated and I see the function you added, but, you know the bit,
if ai_soldier_state[e]=="attack gate" then
-- do something -- note: FireWeapon(e) only works on the player, as far as I know, so you need to script the damage to the gate. (2)
-- force ai to keep looking at 2
-- do something like hurt(2), reposition ai, delay, hurt(2), reposition ai, delay ....

That's what has been getting me all along, I'm wanting the entity to use the attack animation to attack the gate, knowing I would have to script the gate damage but the change in state from at the gate to attacking the gate has been the biggest issue,
I have tried,



With no joy...
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 10th Feb 2016 11:40
yep that's my mistake because i edited my original PlayerLooking() function which used GetPlayerDistance(e) so i obviously just substituted my GetDistance() function and forgot that wouldnt work if it's not included in the global, i shall fix it now so the function works on it's own as intended, thanks

i believe this is close to what you want to achieve

life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
monte
9
Years of Service
User Offline
Joined: 12th Apr 2015
Location:
Posted: 12th Feb 2016 01:55
I must thankyou both for going to a huge effort, smallg you have basically given me the script I was after, I watched your vid, and that is what I'm trying to achieve. I have added the script, made the changes required, distance, inside the gate co-ordinates and entity number and it still does not work for me, the ai doesn't stop as in line 32 and now the doors just fly open and they walk right on in.

So, I think I must have a bigger issue, no idea what but, I have just noticed that no other scripts are functioning in my scene at all, to add to it I have the "creating ai obstacles" bug so each time I test the scene it takes an eternity (feels like) to load up. I think I'm getting a message not to proceed...

I cant ask either of you for any more help than you have already given. I'm going to leave this one while I still have a small amount of sanity left but thanks again
M
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Feb 2016 22:09
sorry to hear that but yh AI code is not the best place to start, it's still annoying for me when they refuse to work as expected - sometimes it's not even anything we're doing wrong.

i did forget to mention the gate health needs to be higher as they are actually attacking it and doing damage (once it reaches below 100 it will open, can't remember if there was a reason for that, i think it may just have been to make sure it didnt go below 0 and stop the script from functioning?)
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-05-03 14:29:54
Your offset time is: 2024-05-03 14:29:54