Duke4.net Forums: EDuke32 Scripting - Duke4.net Forums

Jump to content

  • 89 Pages +
  • « First
  • 87
  • 88
  • 89
  • You cannot start a new topic
  • You cannot reply to this topic

EDuke32 Scripting  "CON coding help"

User is offline   jimbob 

#2641

View PostMark, on 21 December 2020 - 06:35 AM, said:

Wait a minute...After all these years I never knew there was a usable button on the back of a pigtank. :blink:

Make a small sector behind the machine gun and put a stayput version of the enemy in that sector. Then use the findnearactor feature in the gun actor so that if the enemy gets killed first it is no longer found and the gun stops shooting. And if the gun gets "killed" first have that cactor the enemy into the non-stayput version. The only problem is if you need the gun to fire in any direction and not just mostly forward. It would still work but the enemy won't follow the gun direction. Also you would have to tag this enemy somehow different from the rest so they don't all get affected. Maybe a different pal.

yeah, you can press the nuke symbol and the tank will auto destruct ;) saving much ammo
i was thinking allong those line, but most eduke programming is beyond my capabilities at the moment.. for now i have a small sector and an stayput enemy, and made the gun destructable. placed a small wall crack and use that to blow the entire area killing everything. a cop out but for the moment it looks half decent. in the future i will make a custom dedicated machine gunner so the game can look for that actor and ignore all others. making the gun shoot in a 45 degree arc relative to the original angle is something to be added.

so how would i implement the findnearactor, something like findnearactor myactor 1, if 1 run code if 0 dont?

right now i have this coded, basically i hacked the floofflame code.
define MG42NPC		3951
define MG42ANPC		3952 // the a is for ambience, this gun is placed outside the playable areas to make the world seem bigger than it really is. 

action MG42STAND		0 1 5 1 0
action MG42FIRES		5 1 5 1 0
action MG42ASTAND		-1 1 5 1 0 
action MG42AFIRE		4 1 5 1 0

useractor notenemy MG42NPC 100 MG42STAND
  ifaction MG42FIRES
  {
 	ifactioncount 2 
	shoot SHOTSPARK1
	sound MG42FIRE
	ifrnd 64
	{
	shoot FIRELASER
	}
    ifactioncount 16
      action MG42STAND
  }
  ifaction MG42STAND
    ifrnd 8 // was 4
  {
    action MG42FIRES
    resetactioncount
else action MG42STAND
  }
  ifhitweapon       
  {
    debris SCRAP1 2 
    ifdead 
    {           
   sound VENT_BUST
      debris SCRAP1 10
      killit
    }

  }
enda

useractor notenemy MG42ANPC 100 MG42ASTAND // and the ambience version, basically the same but wont require an owner to run.
  ifaction MG42AFIRE
  {
 	ifactioncount 2 
	sound MG42FIRE
	ifrnd 64
	{
	shoot FIRELASER
	}
    ifactioncount 16
      action MG42ASTAND
  }
  ifaction MG42ASTAND
 ifcansee  ifp palive ifcanshoottarget
    ifrnd 16 // was 4
   {
    action MG42AFIRE
    resetactioncount
else action MG42ASTAND
  }
  ifhitweapon       
  {
    debris SCRAP1 2 
    ifdead 
    {           
      sound VENT_BUST
      debris SCRAP1 10
      killit
    }

  }
enda



so i'd probably add something like

gamevar MGNEAR 0 0

findnearactor MGGUNNER 512 MGNEAR

onevent MGNEAR 1

run code ( action MGSTAND, wich will loop in intervalls  )
else

action MGABANDONED or something ( same action as MGSTAND but wont run the shooting code )


i could also run a check if the gun is still 'alive' and if not callactor MGgunner roaming or something so he can abandon his position and change to a regular soldier.

This post has been edited by jimbob: 22 December 2020 - 10:48 AM

0

User is offline   Mark 

#2642

There are multiple ways of accomplishing the same thing and past experience has shown my way of coding can be sloppy or inefficient. I've only used findnearactor once early this year. If nobody else comes to the rescue with a better example I'll post my embarrassing blocks of code. Mine was a boombox and a gangster. The boombox detected if the gangster was nearby and alive. If he wasn't because he got shot and killed, the rest of the boombox code would not run. Also, if the gangster could not detect the boombox because it got "killed" the rest of the gangster code would not run. The problem with posting mine is that the findnearactor stuff is mingled in with music, dialog, sound effects, pal changes, quotes, etc... Its messy. :yucky:

This post has been edited by Mark: 22 December 2020 - 03:19 PM

0

User is offline   jimbob 

#2643

No worries, ill figure out how to make it work i just need to know how to properly set up and use findnearactor
0

User is offline   Danukem 

  • Duke Plus Developer

#2644

I recommend against using findnearactor because it has too many limitations. It's going to find the actor with the lowest sprite ID of the specified picnum within the specified range. So it doesn't allow you to narrow down a list of targets. For example, if an actor of that picnum is right behind the turret, and another is in front, findnearactor might find the one behind that it can't shoot anyway, and then the turret won't be able to shoot the one in front. Or, it can find an actor that is already dead and not a viable target.
0

User is offline   Reaper_Man 

  • Once and Future King

#2645

I can't follow your code and what you're trying to do exactly. As Dan said, findnearactor really sucks because it just finds A near actor, not the nearest actor. I use this code to find the actual nearest actor a lot:

setvar DISTANCE 2147483647 // Maximum integer value, you should use some sort of realistic maximum range
setvar ACTORTARGET -1

setvar ACTORI 0
for ACTORI sprofstat 1
{
	ifvare sprite[ACTORI].picnum MYACTOR
	{
		ldist ACTORCHECK THISACTOR ACTORI
		ifvarvarl ACTORCHECK DISTANCE
		{
			setvarvar DISTANCE ACTORCHECK
			setvarvar ACTORTARGET ACTORI
		}
	}
}

ifvare ACTORTARGET -1
	killit // Couldn't find a valid target, goodbye


This post has been edited by Reaper_Man: 22 December 2020 - 06:33 PM

0

User is offline   Danukem 

  • Duke Plus Developer

#2646

But you should use "spritesofstatus 1" instead of "allsprites" because currently that searches through every single sprite in the game, whereas statnum 1 is just a linked list of actors which will be a small fraction of that number.
1

User is offline   Reaper_Man 

  • Once and Future King

#2647

Good catch, I should pay more attention to which code I'm copying!
0

User is offline   jimbob 

#2648

View PostReaper_Man, on 22 December 2020 - 04:29 PM, said:

I can't follow your code and what you're trying to do exactly. As Dan said, findnearactor really sucks because it just finds A near actor, not the nearest actor. I use this code to find the actual nearest actor a lot:

setvar DISTANCE 2147483647 // Maximum integer value, you should use some sort of realistic maximum range
setvar ACTORTARGET -1

setvar ACTORI 0
for ACTORI allsprites
{
	ifvare sprite[ACTORI].picnum MYACTOR
	{
		ldist ACTORCHECK THISACTOR ACTORI
		ifvarvarl ACTORCHECK DISTANCE
		{
			setvarvar DISTANCE ACTORCHECK
			setvarvar ACTORTARGET ACTORI
		}
	}
}

ifvare ACTORTARGET -1
	killit // Couldn't find a valid target, goodbye

that bit of code was mostly mental note for myself, basically i wanted to create a variable MGNEAR and set that to one for yes, zero for no

If no, do nothing by calling an idle action

If yes, run active action wich runs/triggers the shooting code.
And if the operator dies, i planned on using callactor to call a different actor to lower the MGNEAR flag to zero.
0

User is offline   Sangman 

#2649

View PostDanukem, on 22 December 2020 - 04:49 PM, said:

But you should use "spritesofstatus 1" instead of "allsprites" because currently that searches through every single sprite in the game, whereas statnum 1 is just a linked list of actors which will be a small fraction of that number.


Another option, if it's only one specific enemy type that you want to check for, is to appendevent EVENT_SPAWN and add it to an array if it is that actor type. Then loop that array... it's a micro optimization in jimbob's scenario I'm guessing but just throwing that out there.
0

User is offline   jimbob 

#2650

i still cant make heads or tails of this :') i suck at this :P

yes, there wil be one dedicated enemy that occupies the fixed MG position, and will be in various positions on itself ( prone, standing, crouching ) wich means i cant make it one large sprite, given the size of the machinegun, and the size of the enemy it would make more than half of the sprite seethrough causing lots of clipping issues and a ton of useless data being wasted.

Attached thumbnail(s)

  • Attached Image: mg1.png
  • Attached Image: mg2.png
  • Attached Image: mg3.png

0

User is offline   jimbob 

#2651

well, i seem to have fixed it, now the gunner has to be alive, and on the MG for it to shoot

state checkoccupied
findnearsprite MGGUNNERSTAND ONMGDIST ONMG
ifvarn ONMG -1 { action MG42ASTAND break }  // run code as normal
else { action MG42ADONOTHING break }

ends

useractor notenemy MG42ANPC 100 MG42ASTAND
ifaction MG42AFIRE 
  {
 	ifactioncount 2 
	state checkoccupied
	shoot SHOTSPARK1
	sound MG42FIRE
	ifrnd 64
	{
	shoot FIRELASER
	}
    ifactioncount 16
      action MG42ASTAND
  }
ifaction MG42ASTAND state checkoccupied
  ifcansee  ifp palive ifcanshoottarget // only fire if can see the player
    ifrnd 16 // was 4
   {
ifvarn ONMG -1   
	 action MG42AFIRE
    resetactioncount
else
ifvarn ONMG -1  action MG42ASTAND
else action MG42ADONOTHING
  }
  ifhitweapon       
  {
    debris SCRAP1 2 
    ifdead 
    {           
      sound VENT_BUST
      debris SCRAP1 10
      killit
    }

  }
ifaction MG42ADONOTHING 
	{ 
	}
enda

added a few checks, for whatever reason it occasionally still went to the fire action and fire once or twice.

This post has been edited by jimbob: 08 January 2021 - 12:40 PM

0

Share this topic:


  • 89 Pages +
  • « First
  • 87
  • 88
  • 89
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options