EDuke32 Scripting "CON coding help"
#2749 Posted 19 June 2021 - 01:45 PM
#2750 Posted 19 June 2021 - 11:29 PM
#2751 Posted 16 August 2021 - 11:20 AM
state navigate // navigate to the waypoint.
findnearactor WAYPOINT 20480 TEMP // piece of code straight from the eduke32 wiki. modified for a rudimentary waypoint system.
ifvarvare MHITAG COUNT // make sure the waypoint he is going to is the next sequential one, so he doesnt backtrack.
ifvarn TEMP -1
{
getactor[TEMP].x MX
getactor[TEMP].y MY
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar MX x
subvarvar MY y
getangle ANGVAR MX MY
setactor[THISACTOR].ang ANGVAR
}
// here starts my own changes to make the system do what i need.
// if the actor is within the accepted distance from the waypoint, make him aim for the next one by adding one to the count.
findnearactor WAYPOINT 512 TEMP
ifvarn TEMP -1
{
addvar COUNT 1
}
ends
the actor runs state navigate every once in a while during his seek state where he tries to find the player, the waypoint or an enemy. it needs a lot of work though. just asking of im on the right track with this. it needs a lot of work to make it somewhat more sophisticated but right now its just used to make soldiers move in a general direction instead of rather randomly around the map, or follow the player a round like a line of lemmings.
#2752 Posted 16 August 2021 - 11:34 AM
As for whether you are on the right track, you are kind of on the way to making looping waypoints like the pigcop recon cars. Make sure you read the tag off of the waypoint so that you can compare it to the enemy's counter.
#2753 Posted 16 August 2021 - 11:49 AM
Danukem, on 16 August 2021 - 11:34 AM, said:
As for whether you are on the right track, you are kind of on the way to making looping waypoints like the pigcop recon cars. Make sure you read the tag off of the waypoint so that you can compare it to the enemy's counter.
i will make a simple useractor that will move towards the waypoint at all times to check if it works. and you're right. i should really try to get one thing working before adding too much at the same time.
#2754 Posted 17 August 2021 - 02:37 AM
tate navigate // navigate to the waypoint.
findnearactor WAYPOINT 409600 TEMP
getactor[TEMP].hitag MHITAG // TEMP is in this case the waypoint actor.
ifvarvare MHITAG COUNT // make sure the waypoint he is going to is the next sequential one, so he doesnt backtrack.
// IE only find nearactor with a hightag the count currently has, one at a time.
ifvarn TEMP -1 // the actor should only care about the waypoint if both statements return true.
{
getactor[TEMP].x MX
getactor[TEMP].y MY
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar MX x
subvarvar MY y
getangle ANGVAR MX MY
setactor[THISACTOR].ang ANGVAR
}
// here starts my own changes to make the system do what i need.
// if the actor is within the accepted distance from the waypoint, make him aim for the next one by adding one to the count.
findnearactor WAYPOINT 512 TEMP2
getactor[TEMP].hitag MHITAG
ifvarn TEMP2 -1
ifvarvare MHITAG COUNT // add 1 to count only if the current waypoint has the same value as the one where the player was moving towards,
// used to prevent a retrigger causing the count to rise 1 every tick the actor is within the set distance
{
addvar COUNT 1
spawn EXPLOSION2 // just to check if he reaches the correct point, and does not re-trigger the count. set off fireworks one you reach your goal.
break // force restart of the subroutine
}
ends
i tried putting a ifvarvarn MHITAG COUNT { break } after the actual getting the angle code but that didnt seem to work, if i place a waypoint between the actor, and it has not the correct hitag the actor will then ignore the one that does have the correct hitag, this makes figure 8 forms impossible, wich is something i could live with, but surely there is a way around it.
i was thinking allong the lines of running a search through the spriteid's until it finds the correct one before proceeding.
but my actor does not follow a simple path i layed out start to finish, so thats a win.
This post has been edited by jimbob: 17 August 2021 - 02:41 AM
#2755 Posted 18 August 2021 - 11:59 AM
For pathing, if you are going to do a search at all (which may not be necessary depending on how you set things up), then you should start the search using statnum with a loop using commands such as headspritestat/whilevarn/nextspritestat. In the loop you can check picnum, distance, tags, or whatever you want.
#2756 Posted 19 August 2021 - 06:47 AM
how could i set up a pathing system without doing a search for the correct pathnode? afaik no matter wich way tou slice it you are going to have to do a check to see if there is a pathnode within range, get wich node it is and make sure that the AI is going to the next sequential one in order to avoid it backtracking or going the wrong direction. my reasoning was to do a check ( findnearactor ) then check if it is the correct pathnode ( does it have Hitag 0? ) and if so move to that. then increment the search for hitag value +1 once it reaches the correct pathnode ( ignoring others in its patch because they do not equal the hitag value, wich is important because the closest he just reached will need to be ignored so he can immediatly fixate on the next one. )
#2757 Posted 19 August 2021 - 12:44 PM
jimbob, on 19 August 2021 - 06:47 AM, said:
When I get some time I will put an example on the wiki (remind me if the weekend goes by and its still not there). Otherwise, if I post some code for you here, it will just be lost in time like so many other code snippets.
EDIT: You could also start the loop with "for spritesofstatus 1" which might be easier for you to get your head around:
https://wiki.eduke32.com/wiki/For
This post has been edited by Danukem: 19 August 2021 - 12:55 PM
#2758 Posted 19 August 2021 - 09:16 PM
https://wiki.eduke32.../Headspritestat
My example shows how to set up the loop. But instead of counting, what you want to do is check picnum (for the waypoint actor), then check its tag. If your moving actor has already latched onto a waypoint, you don't need to keep running the loop unless it is close enough to require going to the next one, or in case something has gone wrong.
#2759 Posted 20 August 2021 - 12:05 AM
#2760 Posted 20 August 2021 - 04:42 AM
Attached File(s)
-
con code tricks.7z (141.1K)
Number of downloads: 433
#2762 Posted 21 August 2021 - 08:06 AM
Danukem, on 19 August 2021 - 12:44 PM, said:
EDIT: You could also start the loop with "for spritesofstatus 1" which might be easier for you to get your head around:
https://wiki.eduke32.com/wiki/For
ive gotten it to work for like 80%, the actor moves towards the right point, ignores other points with a 'wrong' hitag value and clearly reaches the destination ( it sets off an explosion ) but then just keeps going in that direction, the loop doesnt seem to restart with the new COUNT +1 :/ the code could be heavily condensed with this method though.
TEMP in this context is the waypoint, and THISACTOR is whoever needs to go to the waypoint.
state navigate // navigate to the waypoint.
for TEMP sprofstat 1 { getactor[TEMP].hitag MHITAG ldist xydist THISACTOR TEMP }
ifvarvare MHITAG COUNT // make sure the waypoint he is going to is the next sequential one, so he doesnt backtrack.
// IE only find nearactor with a hightag the count currently has, one at a time.
{
getactor[TEMP].x MX
getactor[TEMP].y MY
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar MX x
subvarvar MY y
getangle ANGVAR MX MY
setactor[THISACTOR].ang ANGVAR
ifl xydist 512
ifvarvare MHITAG COUNT // add 1 to count only if the current waypoint has the same value as the one where the player was moving towards,
// used to prevent a retrigger causing the count to rise 1 every tick the actor is within the set distance
{
addvar COUNT 1
spawn EXPLOSION2
break // force restart of the subroutine
}
}
ends
maybe it needs an actor side restart? say if the xydist is lower than 512 run the state again in the actors code?
This post has been edited by jimbob: 21 August 2021 - 08:09 AM
#2763 Posted 21 August 2021 - 10:21 AM
That would explain why it keeps going straight -- you increment COUNT but then no sprites in the map actually have the next hitag of 1.
Also, you need to check for the picnum before checking tags, because right now ANY sprite of statnum 1 with the right hitag will be seen as a target.
#2764 Posted 22 August 2021 - 03:21 PM
for now my code works for like 90% again, it sees the waypoint sprite, gets the angle, moves towards it, when he reaches it does an explosion and then again just keeps going straight. i used some setactor flag to change the pal for some steps so i can visually check what the actor is doing.
anyway, here's my piece of frankencode, im going to bed, not feeling too great meaning i cant focus right.
onevent EVENT_LOADACTOR
// switch sprite[].picnum // other way of checking the picnum, seems needlessly complicated.
// case WAYPOINT
ifactor WAYPOINT
{
getactor[].hitag MHITAG
getactor[].lotag MLOTAG
// setactor[].hitag ZERO // resetting to zero seems counter intuitive to what i need.
// setactor[].lotag ZERO
}
// break
// endswitch
endevent
state navigate
for TEMP sprofstat 1
ife sprite[TEMP].picnum 5427
{
setactor[THISACTOR].pal 2 // if found the node, turn angry and try to grab it.
getav[TEMP].HITAG MHITAG
ldist xydist THISACTOR TEMP
}
ifvarvare MHITAG COUNT // make sure the waypoint he is going to is the next sequential one, so he doesnt backtrack.
//IE only find nearactor with a hightag the count currently has, one at a time.
// ife sprite[TEMP].hitag COUNT
{
getactor[TEMP].x MX
getactor[TEMP].y MY
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar MX x
subvarvar MY y
getangle ANGVAR MX MY
setactor[THISACTOR].ang ANGVAR
{
getav[TEMP].HITAG MHITAG
ldist xydist THISACTOR TEMP
}
}
else break
ifl xydist 512
ife sprite[TEMP].hitag COUNT
// ifvarvare MHITAG COUNT
// add 1 to count only if the current waypoint has the same value as the one where the player was moving towards,
// used to prevent a retrigger causing the count to rise 1 every tick the actor is within the set distance
{
setactor[THISACTOR].pal 1 // visual check, does he reach the point and stay in this line of code?
// it apears not. he immediatly turns to spritepal 2 again after briefly flashing blue.
/// IE once the nasty node has been grabbed and destroyed move to the next one.
addvar COUNT 1
spawn EXPLOSION2
break // force restart of the subroutine
}
break
ends
This post has been edited by jimbob: 22 August 2021 - 03:22 PM
#2765 Posted 22 August 2021 - 04:34 PM
#2766 Posted 28 August 2021 - 02:48 PM
Danukem, on 22 August 2021 - 04:34 PM, said:
adding logvars helped, managed to track down the issue and now have a working system.
state navigate
for temp sprofstat 1
ife sprite[temp].picnum WAYPOINT
{
getav[THISACTOR].COUNT COUNT
getactor[temp].htowner NODE
getactor[temp].hitag FOUNDHITAG
ifvarvare FOUNDHITAG COUNT
{
addlogvar COUNT
addlogvar FOUNDHITAG
addlogvar NODE
}
ifvarvare FOUNDHITAG COUNT
{
{
getactor[NODE].x MX
getactor[NODE].y MY
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar MX x
subvarvar MY y
getangle ANGVAR MX MY
setactor[THISACTOR].ang ANGVAR
{
getactor[temp].htowner NODE
getav[NODE].FOUNDHITAG FOUNDHITAG
ldist xydist THISACTOR temp
}
ifl xydist 512
{
addvar COUNT 1
}
}
}
}
ends
#2767 Posted 09 September 2021 - 05:30 AM
another way would be a line of sight check, i tried that but for whatever reason they always seem to come back positive. :/
#2768 Posted 09 September 2021 - 10:42 AM
You can check for an activator being triggered using that.
Make sure that you test your ability to detect the activation separately from your code that makes the actors wait. I would use ifhitspace to trigger the waiting mechanic first just to make sure it works properly, then change it to trigger on the activator once you have it working. Otherwise if you test everything at once and then the inevitable failures occur you won't know where it is breaking.
#2769 Posted 09 September 2021 - 11:01 AM
This post has been edited by jimbob: 09 September 2021 - 11:02 AM
#2770 Posted 09 September 2021 - 11:20 AM
#2771 Posted 23 September 2021 - 11:56 AM
To shut it down i must "disable" scope by clicking turnaround off and then switch weapon.
Here is the code:
onevent EVENT_DISPLAYROOMS
ifvare currentweapon 3
//ifvare player[THISACTOR].curr_weapon 3 // if player has weapon m4 selected
getinput[THISACTOR].bits TEMP1
ifvarand TEMP1 268435456
{ addvar turnaround_keytime 1 }
else
{ setvar turnaround_keytime 0 }
ifvare turnaround_keytime 1
{ xorvar sight_on 1 }
ifvare sight_on 1
{
setaspect 32768 52428 // activate the 4x scope
}
endevent
What should i do to do following: If i have scope and i switch weapon which does not have scope code the setaspect will return as it is before scoping?
#2772 Posted 23 September 2021 - 05:07 PM
onevent EVENT_DISPLAYROOMS
ifvare currentweapon 3
{
getinput[THISACTOR].bits TEMP1
ifvarand TEMP1 268435456
addvar turnaround_keytime 1
else
setvar turnaround_keytime 0
ifvare turnaround_keytime 1
xorvar sight_on 1
}
else
setvar sight_on 0
ifvare sight_on 1
setaspect 32768 52428 // activate the 4x scope
endevent
#2773 Posted 24 September 2021 - 02:31 PM
However i encountered another issue...
I have also another weapon that requires scope, it is in place of the shrinker. I tried to copy-paste the code you described above with only change that currentweapon -> 6
---> Result is that now both scopes does not work. The setaspect -effect is visible only on a 1 microsecond.
I do onevent EVENT_DISPLAYROOMS
---> then i paste code
endevent
Sorry to bother you like this. I thought that this code will work in a weapon like a weapon as long as i change the currentweapon -value. So what i should do so that the code can be modified to work in a more than a one weapon.
EDIT: I FOUND THE SOLUTION!
just a quick testing and felt that this one works: Switch the place of currentweapon and put a few { } more and made a rows for currentweapon 6.
onevent EVENT_DISPLAYROOMS
{
getinput[THISACTOR].bits TEMP1
ifvarand TEMP1 268435456
addvar turnaround_keytime 1
else
setvar turnaround_keytime 0
ifvare turnaround_keytime 1
xorvar sight_on 1
}
else
setvar sight_on 0
ifvare sight_on 1
ifvare currentweapon 3
{
setaspect 32768 52428 // activate the 4x scope
}
ifvare sight_on 1
ifvare currentweapon 6
{
setaspect 32768 52428 // activate the 4x scope
}
endevent
This post has been edited by Salvation: 24 September 2021 - 03:04 PM
#2774 Posted 24 September 2021 - 07:00 PM
Just FYI, if you have a series of if statements with only a single command within them, you don't need brackets:
ifvare sight_on 1
ifvare currentweapon 6
setaspect 32768 52428You could also tighten up your if logic at the end:
ifvare sight_on 1
{
ifvare currentweapon 3
setaspect 32768 52428 // activate the 4x scope
ifvare currentweapon 6
setaspect 32768 52428 // activate the 4x scope
}I'd also argue that the key press processing being in the same block of code as the aspect ratio stuff is bad practice. You want your code to do one thing, and only one thing. So here's what I'd do:
appendevent EVENT_TURNAROUND
{
geti .bits TEMP1
ifand TEMP1 268435456
add turnaround_keytime 1
else
set turnaround_keytime 0
ife turnaround_keytime 1
xor sight_on 1
}
endevent
onevent EVENT_DISPLAYROOMS
{
ife sight_on 1
{
ife currentweapon 3
setaspect 32768 52428
else
ife currentweapon 6
setaspect 32768 52428
else
set sight_on 0
}
}
endevent
#2775 Posted 29 September 2021 - 10:24 AM
#2776 Posted 29 September 2021 - 12:37 PM
appendevent EVENT_TURNAROUND
{
xor sight_on 1
}
endeventSince you don't need the additional code capturing the key press.
#2777 Posted 01 October 2021 - 07:52 AM
How can I check if there's a wall between 2 different coords in the game? I think that is something like "ifcansee".
#2778 Posted 01 October 2021 - 09:54 AM
RPD Guy, on 01 October 2021 - 07:52 AM, said:
How can I check if there's a wall between 2 different coords in the game? I think that is something like "ifcansee".
https://wiki.eduke32.com/wiki/Cansee
Do you know how to set in variables?
If you are trying to make 2 actors check if they can see each other, remember that their xyz is the bottom center of the sprite.
This post has been edited by bullerbullerseven: 01 October 2021 - 09:56 AM

Help
Duke4.net
DNF #1
Duke 3D #1


