No enemy, no guns!

Post your scripting questions / solutions here

Moderator: Moderators

Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

No enemy, no guns!

Post by Krane »

I have a placed mp bot (not spawned) that comes with his weapon. I want him to holster everytime he cannot see me :) , got it? See me, pickup the weapon (and shoot me, that's ok)..Don't see me, holster...

I'm making him run a thread:

while (is_enemy_visible == 0)
{
self holster
}

end


Needless to say it's not working...

Help :? !
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Try this (self is your bot):

Code: Select all

while(isAlive self)
{
  if(isAlive self.enemy && self cansee self.enemy 4000 90)
    self unholster
  else
    self holster
  waitframe
}
4000 is the vision distance, 90 the fov (in degrees).
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

hmm.. "cansee", pretty cool :shock: ! hmmm...self.enemy...is this work? hmmm...cool :roll: !

Hmm..I got your point jv, thanks for the answer :D !

..But wait :shock: !: Can you use if and else together w/o brackets? Perhaps the right way is:

while(isAlive self)
{
? if(isAlive self.enemy && self cansee self.enemy 4000 90)
{
? ? self unholster
}
? else
{
? ? self holster
}
? waitframe
}

Hmmm...but anyway, I think that will be enough :D !

Cheers, m8 :D !
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Yeah if it's only 1 line you can use if and else (or while / for) without a { and } pair... a bit illogical I agree :? but it works :)
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Hmmm...one line don't need {}...cool :shock: !

btw, why the bots walks like in slow motion when they are playing the "walkto" and they are unholster? I send a bot to a destination, like:

self walkto $wherever
self waittill movedone

...and, if they are unholster, they walk in slow motion...btw, I'm using a custom bot, he uses the oss_man model, he's german and use the p38 (the ossman model don't hold the p38 properly :cry: )...

:D
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Hmmm... it's working but...when they suppose to unholster, they do this rifle anim w/ no weapons at all, instead of picking up the p38..( I give them only the p38)

Image

:? :? :? :? :? :?
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Hey jv, check this out :shock: :

I put your thread to run. As I told before, it works but they play this animation above (pic) instead of arming themselfs w/ the pistol...

Then my phone rings! I answered and keep talking for about 5 min. When I saw the screen again my fps was getting lower and lower...and was going to 7 fps when I had to quit :shock: UUUOOOAAAA!!! :roll:

So I made this:

Code: Select all

while(isAlive self) 
{ 
? if!(isAlive self.enemy && self cansee self.enemy 4000 90) 
? ? self holster 
? else 
? ? self unholster 
? waitframe 
} 
I've made them to do the oposite:holster when they don't see me, instead of unholster when they see me! Sounds the same but, for the bots, the first method makes they check every frame for enemies...I think that's why the fps was getting lower and lower...Anyway, now the fps stays the same :shock:

But why they play this "holding an invisible rifle" animation instead of picking up the p38 they have??? :?:
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Well first of all I wouldn't know what caused the fps drop, but it seems unlikely the change you made fixed it :?

As anything between parens ( and ) is executed first in a line,

!(isAlive self.enemy && self cansee self.enemy 4000 90)

would first evaluate

(isAlive self.enemy && self cansee self.enemy 4000 90)

to 1 or 0 and then the ! would simply change the 1 to a 0 or vice versa.

So basically the conditions checked by the game are exactly the same in either method...

Anyway I think the root of your problems is a slight misunderstanding of the holster and unholster commands. If you tell an AI to holster, he won't hold any weapons untill you tell him to unholster again. Hence, in yoru case, you shouldn't want your AI to hoster, but change his weapon to a p38 instead.

Now I gotta confess that I have little experience with changing a weapon 'on-the-fly', but I think it's best to use the gun command:

Code: Select all

while(isAlive self)
{
  if!(isAlive self.enemy && self cansee self.enemy 4000 90)
    self gun "weapons/p38.tik"
  else
    self gun "weapons/kar98.tik"
  waitframe
}
If this doesn't work, use the weapon command instead, like this:

Code: Select all

while(isAlive self)
{
  if!(isAlive self.enemy && self cansee self.enemy 4000 90)
    self weapon "walter p38"
  else
    self weapon "mauser kar 98k"
  waitframe
}
Be advised however that this may actually alter the equipment of the AI (depending on which TIKI you are using).

Anyhow it's probably a good idea to improve the script a bit, so that the guy doesn't 'get' a new weapon each frame.

You could for example try this:

Code: Select all

while(isAlive self)
{
  if !(isAlive self.enemy && self cansee self.enemy 4000 90)
  {
    self weapon "walter p38"
    while (isAlive self && !(isAlive self.enemy && self cansee self.enemy 4000 90))
      waitframe
  }
  else
  {
    self weapon "mauser kar 98k"
    while (isAlive self && isAlive self.enemy && self cansee self.enemy 4000 90)
      waitframe
  }
  //waitframe // shouldn't need this no more :)
}
I got a bit confused along the way :oops: so you might have to swap the p38 and mauser lines 8-)
Image
omniscient
Major General
Posts: 694
Joined: Tue Sep 16, 2003 12:02 am

Post by omniscient »

i dunno if this works. but could u just take it away and give it to him, instead of holstering and unholstering. wouldnt it automatically switch.
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

omniscient, giving and taking weapons have the same effect as holster and unholster...

Jv, the first method indeed makes the fps drop and the second don't! why? simple!

Suppose I tell you: "Jv, call me if you feel sick and I'll help you!". I'm asking you to check for the condition "feel sick". You'll check yourself to see if you're feeling sick (jv:"hmm, I'm fine right now, so I'm not gonna call Krane")

Now, suppose I tell you: "Jv, If you DON'T feel sick. DON'T call me!". You are going to check if you're NOT sick (jv:"hmm, this is the case, I'm feeling fine!") and you're going to "not-call"( whatever this action is) me every frame! Got it? Every frame you'll perform an action, instead of not doing anything every frame!

If you tell the bots: " If you see an enemy, unholster!" they will unholster only if they see you. But if you tell him: "If you don't see an enemy (which HAPPENS every frame) holster".they will holster (or every other action u tell they to do) EVERY FRAME!!!!

I'm not good on explanations but this makes a lot of sense for me!

Gee, I'm geting desperate w/ this :roll: !

I place a bot in a map tell him to holster and, when in a battle, they don't get their weapon :? :? :? :?

btw, before asking me, here's the relevant part of the tik:
server
{
classname Actor
german
setsize "-16 -16 0" "16 16 92"
health 100
weapon "Walter P38"
}
Looks like, if you give them the command "holster", they forget about this part of the tik :?

This is getting anoying :shock: !

Edit: My time is running out! BUUUUAAAA'!!!!!! :cry:
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Krane wrote:Jv, the first method indeed makes the fps drop and the second don't! why? simple!

Suppose I tell you: "Jv, call me if you feel sick and I'll help you!". I'm asking you to check for the condition "feel sick". You'll check yourself to see if you're feeling sick (jv:"hmm, I'm fine right now, so I'm not gonna call Krane")

Now, suppose I tell you: "Jv, If you DON'T feel sick. DON'T call me!". You are going to check if you're NOT sick (jv:"hmm, this is the case, I'm feeling fine!") and you're going to "not-call"( whatever this action is) me every frame! Got it? Every frame you'll perform an action, instead of not doing anything every frame!

If you tell the bots: " If you see an enemy, unholster!" they will unholster only if they see you. But if you tell him: "If you don't see an enemy (which HAPPENS every frame) holster".they will holster (or every other action u tell they to do) EVERY FRAME!!!!

I'm not good on explanations but this makes a lot of sense for me!
Nice try but you're making a fundamental mistake :) Both methods discussed will do either the 'holster' or 'unholster' command every frame... the game will always execute either the command in the 'if' section or the command in the 'else' section: there is no way it will skip both.

So the fps drops you reported are probably a result of the holster command requireing more cpu usuage than the unholster command, or vice versa.

Anyway try using the more advanced script I posted to get rid of the fps drops altogether:

Code: Select all

while(isAlive self)
{
  if !(isAlive self.enemy && self cansee self.enemy 4000 90)
  {
    self weapon "walter p38"
    while (isAlive self && !(isAlive self.enemy && self cansee self.enemy 4000 90))
      waitframe
  }
  else
  {
    self weapon "mauser kar 98k"
    while (isAlive self && isAlive self.enemy && self cansee self.enemy 4000 90)
      waitframe
  }
  //waitframe // shouldn't need this no more :)
} 
If you use this code, you shouldn't have any holstering problems whatsoever :)
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

Thanks jv!

But I'm having this error:

while (isAlive self && !(isAlive self.enemy && self cansee self.enemy 4000 90)) (global/citizens_anim.scr, 2840)
while (isAlive self && !(isAlive self.enemy && self ^

^~^~^ Script Error: fov must be in range 0 <= fov <= 360


The # 4000 is the fov, right? So I changed to 360 and the error is gone :shock: !

I didn't understand pretty much well the "mauser kar 98k" part of the thread :? ; what's happen is that they are getting the rifle instead of the pistol...btw, they are starting unholster so I puttted self holster after the self thread awareness (our thread :) !)

routine_1:

self thread awareness
self holster

while(isalive self)
{
//all the s*** here
}
end
But I think when I come too close to them, they were changing to pistols :roll: :roll: ...Anyway, what these numbers means?

Oh, and how to make them holster after killing me (or after I hide)?
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Ops I must have confused the fov and distance arguments for the cansee command :oops:
Image
Krane
Lieutenant General
Posts: 782
Joined: Sat May 31, 2003 4:18 pm
Location: California, USA
Contact:

Post by Krane »

jv_map wrote:Nice try but you're making a fundamental mistake :) Both methods discussed will do either the 'holster' or 'unholster' command every frame...
Nana, if the first condition is met, they unholster but if the 2nd condition is met, the do nothing...That were pretty visible, they were walking like the had parkinson or so...lol :lol: !

But your new thread indeed is NOT droping the fps :D !txs

Switching the 4000 and the 90 is indeed far better! :D

Now how to make them holster after the butchery?
Image
M&M
General
Posts: 1427
Joined: Sun Sep 14, 2003 1:03 am
Location: egypt
Contact:

Post by M&M »

kill them :P
Image
Post Reply