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

Jump to content

  • 124 Pages +
  • « First
  • 102
  • 103
  • 104
  • 105
  • 106
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

EDuke32 Scripting  "CON coding help"

User is offline   Reaper_Man 

  • Once and Future King

#3078

All things are good, wasn't trying to dunk on you or anything, it was just some very confusing code. A couple of things looking at the stuff you just posted:

Your .hitag stuff is somewhat unsafe, as hitags can be altered between spawn and actor code execution. I'm pretty sure this is really only the case for hardcoded actors, but for best practices you should capture the .hitag in an event like EVENT_SPAWN. That way you also aren't checking it every gametic, which isn't exactly an expensive operation, but the fewer commands in a given tic the better. You can do this with the .cstat as well.

appendevent EVENT_SPAWN
{
	ifactor LOCKPLAYER
	{
		cstat 32768
		set COUNT 0 // not necessary, but done for safety

		geta .hitag FOUNDHITAG
		seta .hitag 0
	}
}
endevent


Since you are using your own counter COUNT, you could change "ifcount 10240" to "ife COUNT 10240" for consistency. Also for consistency, I reversed the conditionals of the first if statement, as the 1st var should be the one that is changing and you're comparing it against the 2nd which is generally a static value. You can also combine repeated code into a state.

defstate killlock
{
	set ONPARA 0
	killit
}
ends

useractor notenemy LOCKPLAYER
{
	add COUNT 1
	set ONPARA 1

	ife COUNT FOUNDHITAG
		state killlock
	else
	ife COUNT 10240
		state killlock
}
enda


Are there other values for ONPARA set other than 0 or 1? If not then you could simplify your APLAYER code by removing the second if statement like so:

ife ONPARA 1
{
	setp .movement_lock 15
	setp .weapon_pos 20
}
else
	setp .movement_lock 0


That said, if anything else does use .movement_lock, then this will interfere with that. One way around it is having ONPARA use a third value to mean it's "at rest", where 1 means it should lock and 0 means it should release the lock. Something like:

ife ONPARA 1
{
	setp .movement_lock 15
	setp .weapon_pos 20
}
else
ife ONPARA 0
{
	setp .movement_lock 0
	set ONPARA -1
}

0

User is offline   jimbob 

#3079

no, there arent any other things using a different way to lock the player, everytime i need to lock the player i use onpara
i should probably change onpara to just lockplayer to make it more clear for anyone reading it, it kinda evolved from one simple time i wanted to lock the player to multiple uses over time. i'll put in the updated code, thanks a lot :) i should also take more heed to wich var is triggered when and in what order.

Quote

wasn't trying to dunk on you or anything
no worries, i know my code is questionable at best :') i tinker around until i get the result i want and then i move on to the next thing so a lot could be done a lot more efficiënt and reliable probably but if it works, it works i guess

This post has been edited by jimbob: 09 November 2022 - 07:18 AM

0

User is offline   VGames 

  • Extra Crispy

#3080

Is there a way to check if the floor is moving that a sprite is sitting on? I feel like there should be. Or maybe I should just check if the sprite is moving on its x or y axis after it should have stopped moving.

This post has been edited by VGames: 14 November 2022 - 07:12 PM

0

User is offline   Danukem 

  • Duke Plus Developer

#3081

View PostVGames, on 14 November 2022 - 06:56 PM, said:

Is there a way to check if the floor is moving that a sprite is sitting on? I feel like there should be. Or maybe I should just check if the sprite is moving on its x or y axis after it should have stopped moving.


How you check will be different depending on whether the sector is actually moving, or whether there is a conveyer belt, which is texture panning plus a simulated movement effect.
0

User is offline   VGames 

  • Extra Crispy

#3082

I’m referring to the floor in Spin Cycle. How do I make an actor detect if it’s on the floor that’s spinning around in that giant room?
0

User is offline   Reaper_Man 

  • Once and Future King

#3083

Without loading up the map I can't confirm, but I'm pretty positive the floors in Spin Cycle are conveyors, rather than actual "rotating sectors". There are a couple of game events that capture moving sectors, EVENT_MOVESECTOR and EVENT_MOVEEFFECTORS, but you'd have to test if either of these are triggered by conveyors. My instinct says no, because MOVESECTOR is for actual moving sectors (IE subway cars), and MOVEEFFECTORS is for vertical movement of elevators and doors.

Assuming neither of these events work, what I'd do is loop through sprofstat STAT_EFFECTOR to fine the SEs, check their tags to see if they match the conveyor tag number, then check if THISACTOR is in the same sector, and if so then you'll have confirmed it's on the conveyor. You may need to check other properties than .lotag, such as .xvel or .extra, as tags and other information gets applied in a way the engine understands on map load.
0

User is online   oasiz 

  • Dr. Effector

#3084

It's a rotated sector.

Doing a conveyor would require tons of splits in order to align the texture's firstwall in a convincing way to make it look like it's spinning.
0

User is offline   VGames 

  • Extra Crispy

#3085

So what Reaper man said wouldn’t work?
0

User is offline   Aleks 

#3086

View Postoasiz, on 15 November 2022 - 10:03 AM, said:

It's a rotated sector.

Doing a conveyor would require tons of splits in order to align the texture's firstwall in a convincing way to make it look like it's spinning.

Also conveyors tend to offset the sprites a bit, so after a few loops (well, I imagine in Spin Cycle it would take more than just a few loops due to how wide it is) they would end up stuck on the sides.
0

User is online   oasiz 

  • Dr. Effector

#3087

Each sector movement effect is essentially just a macro at source level for wall movement in unison, the concept of "moving sectors" doesn't exactly exist.
When a sector is moved, rotated, etc.. sprites are also iterated on the same tick.

This extends to things like doors, rotating cogs, sliding doors, trains, etc..

Conveyors in turn simply change a sector's x/y panning in order to move a texture visually.
Sprites are handled like that as well.

I believe for conveyors it also uses x/y velocity on SE sprite (that gets reset) to get some distances that are used for sprite coordinates during interpolation itself.

If you were to take a snapshot of a map with moving sectors, you wouldn't be able to tell which bits are dynamic and which are static based on map data alone, that's where you need code.
(To be clear, there are some values left behind, if you're familiar with the effect itself then some sprite/sector struct members like .extra may store temp data that may give away it's state... always case by case basis)
0

User is offline   Reaper_Man 

  • Once and Future King

#3088

View PostVGames, on 15 November 2022 - 10:42 AM, said:

So what Reaper man said wouldn’t work?

No, they're just saying it's not a conveyor (my mistake). As it's a moving sector, I think EVENT_MOVESECTOR would capture it so I'd still try there first, and if you can't detect it in a way that makes sense, the for loop should still work as well.
0

User is offline   VGames 

  • Extra Crispy

#3089

View PostReaper_Man, on 15 November 2022 - 11:47 AM, said:

No, they're just saying it's not a conveyor (my mistake). As it's a moving sector, I think EVENT_MOVESECTOR would capture it so I'd still try there first, and if you can't detect it in a way that makes sense, the for loop should still work as well.


Ok thanks I’ll se what I can do.
0

User is offline   VGames 

  • Extra Crispy

#3090

Oh one other question I’ve been meaning to ask and keep forgetting. Is there a way to track frame rate? I’d like to be able to check if it’s dropped below a certain amount like 30 frames or something. Just wondering
0

User is offline   Danukem 

  • Duke Plus Developer

#3091

View PostVGames, on 15 November 2022 - 12:12 PM, said:

Oh one other question I’ve been meaning to ask and keep forgetting. Is there a way to track frame rate? I’d like to be able to check if it’s dropped below a certain amount like 30 frames or something. Just wondering


Yeah there is literally a predefined read-only framerate gamevar.

https://wiki.eduke32.../wiki/Framerate
1

User is offline   VGames 

  • Extra Crispy

#3092

Yeah I just found it. Sorry
1

User is offline   Danukem 

  • Duke Plus Developer

#3093

View PostVGames, on 15 November 2022 - 06:20 AM, said:

I’m referring to the floor in Spin Cycle. How do I make an actor detect if it’s on the floor that’s spinning around in that giant room?


I was going to suggest having the sprites check for the presence of an SE0 in their sector, and then do whatever it is you want them to do if that comes back positive. But that's not enough because the SE0 has a hitag channel and the rotating can be off or on.

If it's the _movement_ that is the issue, you can write code that resets the coords of the sprites that would work independently of the cause of the movement, so you wouldn't need to detect the sector movement at all. If you are trying to keep the sprites in place, you would probably also need to lock down their visible coords in EVENT_ANIMATESPRITES (in addition to their actual coords), because otherwise they will appear to shake as the game moves them and then their actor code resets them 30 times per second.

If you ever do want to detect the presence of SEs in a sector, or any other kinds of sprites for that matter, here are a couple of useful references:

https://wiki.eduke32.../Headspritestat

https://wiki.eduke32.com/wiki/Statnum

You can set up a loop that traverses a linked list of sprites sharing a statnum, which is way more efficient than looping through all sprites. You could also loop through sprites in the sector, depending on your needs (see headspritesect)
1

User is offline   VGames 

  • Extra Crispy

#3094

Is there any way to force the Nightvision goggles to turn on and off without the player having to press the button? I wanted to make the nightvision goggles turn on when the sector you are in has a very low shade value and turn off when the sector is more lit up. I tried making a new night vision effect when the player presses the nightvision button by cancelling out the original usenightvision event and setting up some variables to handle all the effects but changing the palette to 3 only makes the screen green and doesn't make the enemies light up like the original night vision effect does. Any ideas or is this impossible?
1

User is offline   Danukem 

  • Duke Plus Developer

#3095

View PostVGames, on 18 November 2022 - 02:17 PM, said:

Is there any way to force the Nightvision goggles to turn on and off without the player having to press the button? I wanted to make the nightvision goggles turn on when the sector you are in has a very low shade value and turn off when the sector is more lit up. I tried making a new night vision effect when the player presses the nightvision button by cancelling out the original usenightvision event and setting up some variables to handle all the effects but changing the palette to 3 only makes the screen green and doesn't make the enemies light up like the original night vision effect does. Any ideas or is this impossible?


Well first of all I would set heat_on to 1 in the player struct

https://wiki.eduke32.com/wiki/Heat_on

I don't think that changes the gamepalette though so you would probably have to do that as well. However setting that struct probably takes care of the enemies/items not lighting up
1

User is offline   VGames 

  • Extra Crispy

#3096

View PostDanukem, on 18 November 2022 - 02:28 PM, said:

Well first of all I would set heat_on to 1 in the player struct

https://wiki.eduke32.com/wiki/Heat_on

I don't think that changes the gamepalette though so you would probably have to do that as well. However setting that struct probably takes care of the enemies/items not lighting up



ah ok maybe that's what I was missing. Also am I supposed to be using the setgamepalette command to change palettes?

This post has been edited by VGames: 18 November 2022 - 03:02 PM

1

User is offline   Reaper_Man 

  • Once and Future King

#3097

Doing a quick test, it seems like the issue is forcing heat_on without any available heat_amount. If you check or set non-zero heat_amount before forcing heat_on to 1, enemies light up as expected. Otherwise if it's 0, the gamepal changes to 2 so everything visibly turns green, but the actual night vision logic doesn't fire and enemies don't glow.

Side note, setgamepalette is deprecated and no longer required, you can change the gamepal via player[].palette directly now.
1

#3098

Is using a global var for general calcs safe as long as the define/get/function/set are back to back?
1

User is offline   Danukem 

  • Duke Plus Developer

#3099

View Postlllllllllllllll, on 20 November 2022 - 12:43 PM, said:

Is using a global var for general calcs safe as long as the define/get/function/set are back to back?


Yes. And they don't have to be back to back, you just need to make sure that nothing is changing the global var in between your uses unbeknownst to you. The main thing to be wary of is spawning stuff, since that fires off events that you may have code on which potentially changes the global var.
1

User is offline   Reaper_Man 

  • Once and Future King

#3100

In a word: Yes.

If you have a series of math commands run on a gamevar, the value of that gamevar will not unexpectedly change between commands even if the gamevar is reused elsewhere. CON commands are instructions executed in sequence order, so any use of or command using that gamevar before or after the block of code you're looking at won't effect it.

CON will always execute in the order that it's written, meaning that code that is written earlier in sequence will always execute before any other code later on down the line, whether in the same file or files loaded after it. The caveat here is code processing in game events, and without going into a really in-depth and kind of confusing explanation, keep in mind that events always execute in a specific order, and code within those events processes following the same sequential execution.

The execution of code and setting of data will also be dependent on the quasi-random execution order of a sprite's ID. Sprites will process their code individually in order of their sprite ID, so if you have 2 of the same actors which run the same code and both check for or set a gamevar's value, and the actor doing the checking happens to execute before the actor doing the setting because it was assigned a lower sprite ID, it won't be until the next gametic when the checker will "see" the value the setter set.

edit: lol

This post has been edited by Reaper_Man: 20 November 2022 - 02:28 PM

1

User is offline   VGames 

  • Extra Crispy

#3101

Is there any way to mess around with the Pig Recon Vehicle and how it spawns the PigCop when it crashes? There isn't any code in the CON files for this vehicle unlike the Pig Tank so I figured its hardcoded. Would I need to create an entirely new Pig Recon enemy?
1

#3102

I think you can use event_EGS to modify the spawned actor. Something like

ifactor PIGCOP
ifspawnedby RECON
2

User is offline   Reaper_Man 

  • Once and Future King

#3103

Yup, you can capture the spawn in several different events and alter the spawned actor that way. EVENT_EGS would work, that captures sprites spawned during gameplay. I tend to prefer EVENT_SPAWN to modify actors at spawn time, as it's more generic and will effect ones placed in a map as well as spawns at runtime.
1

#3104

You'll be able to spoof a spawn chance in the same way. The chance to killit will be the chance not to spawn (and need to add -1 to total enemy count)
1

User is offline   VGames 

  • Extra Crispy

#3105

Oh ok yeah. I didn’t even think of going through the pigcop and checking if it was spawned by the recon. I’ve added 2 new pigcop variants and I only want the tank and the recon to spawn the original pigcop. But since the original pigcop has a chance to spawn one of the new pigcops and then get removed when it’s spawned sometimes one of the 2 new pigcop variants gets spawned instead when the tank or recon are destroyed. Thanks for the tip. This will help. I’ll have the pigcop spawned by the recon spawn my pigcop clone and remove itself which will then allow the pigcop clone to immediately turn into the original pigcop.
1

User is offline   Reaper_Man 

  • Once and Future King

#3106

Instead of spawning and killing, you can use cactor to simply change which actor type the current actor is.
1

User is offline   VGames 

  • Extra Crispy

#3107

View PostReaper_Man, on 22 November 2022 - 06:04 AM, said:

Instead of spawning and killing, you can use cactor to simply change which actor type the current actor is.


Yeah I guess I could do that instead. Good idea.
0

Share this topic:


  • 124 Pages +
  • « First
  • 102
  • 103
  • 104
  • 105
  • 106
  • Last »
  • 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