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

Jump to content

  • 124 Pages +
  • « First
  • 75
  • 76
  • 77
  • 78
  • 79
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

EDuke32 Scripting  "CON coding help"

User is offline   Salvation 

#2273

I'm currently a little bit of stuck with my CON code. About 2,5 years ago i copy/pasted a ironsight code from AMC TC and made it work. However, the ironsight works only if im holding TURNAROUND key down. I want it to be like one click will activate the iron sight and second will de-activate it, so i wont have to hold that button down all the time.

Here is the code:

onevent EVENT_DRAWWEAPON

ifvarand TEMP4 268435456  // Is the player holding the Alternate Fire key down?
ifvare player[THISACTOR].curr_weapon 3 // M4A1 Carbine Iron Sight
	{
	  setplayer[THISACTOR].runspeed 42100
	  setvar RETURN -1
	  setvar x 160
	  setvarvar WEAP_DISPLAY_TEMP2 WEAPSWAYX
	  divvar WEAP_DISPLAY_TEMP2 2
	  subvarvar x WEAP_DISPLAY_TEMP2
	  setvar y 140
	  setvarvar WEAP_DISPLAY_TEMP3 WEAPSWAYY
	  divvar WEAP_DISPLAY_TEMP3 2
	  subvarvar y WEAP_DISPLAY_TEMP3
	  setvarvar WEAP_DISPLAY_TEMP4 weapon_xoffset // setvar the weapon x sway to displaytemp4
	  divvar WEAP_DISPLAY_TEMP4 2 // divide it by 2 
	  addvarvar x WEAP_DISPLAY_TEMP4 // add it to x
	  subvar x 5 // offset it by 5
	  subvar y 40
	  setvar x 160
	  subvarvar x WEAPSWAYX
	  subvar x 10
	  addvarvar x weapon_xoffset
	  setvar y 142
	  subvarvar y WEAPSWAYY
	  rotatesprite x y 52500  0 3825 shade pal 0 0 0 xdim ydim // iron sight
		break
	}
  getplayer[THISACTOR].weapon_pos WEAP_DISPLAY_TEMP2
  mulvar WEAP_DISPLAY_TEMP2 -20
  setvar tilenum 2536
  rotatesprite x y 2536 WEAP_DISPLAY_TEMP2 tilenum shade pal 0 0 0 xdim ydim
  
  setplayer[THISACTOR].runspeed RUNNINGSPEED

endevent


TURNAROUND key has been disabled:

onevent EVENT_TURNAROUND 
setvar RETURN -1 
endevent


This one will disable the crosshair once iron sight has been activated:

onevent EVENT_DISPLAYCROSSHAIR

 ifvare player[THISACTOR].curr_weapon 3
 ifvarand TEMP4 268435456
	{
	  setvar RETURN -1
	}
endevent




0

#2274

I use time variables which keep for how much time a key is pressed, and the desired function is triggered or toggled when the timer is equal to 1:


gamevar  turnaround_keytime 0 1
gamevar  sight_on 0 1
...

ifvarand TEMP4  268435456
   { addvar turnaround_keytime 1 }
  else
   { setvar  turnaround_keytime 0 }

ifvare turnaround_keytime 1
   { xorvar sight_on 1 }

ifvare sight_on 1
  { /* your code here */ }
....


This post has been edited by RichardStorm: 28 May 2018 - 11:21 AM

0

User is offline   Kyanos 

#2275

Where is TEMP4 being set, I don't see how this code does anything with event turnaround returning -1.

I would simplify this, make a variable ALT_FIRE = 1, set it to ALT_FIRE = ALT_FIRE * -1; if turnaround key is pressed, ezpz toggle switch, check to see if it's positive or negative then draw the proper weapon, do the proper things...

This post has been edited by Drek: 28 May 2018 - 11:26 AM

0

#2276

I think TEMP4 stores input.bits ...
1

User is offline   Kyanos 

#2277

I'm just catching that this is based on AMC TC code which I know nothing about, cue up that simpsons gif, I'm turning around and walking away from this conversation. Good luck.
0

#2278

Is there a way to get the current hp of the last actor you've dealt damage to?

This post has been edited by thisbecasper: 28 May 2018 - 03:29 PM

0

#2279

View Postthisbecasper, on 28 May 2018 - 02:41 PM, said:

Is there a way to get the current hp of the last actor you've dealt damage to?

Or when I look at them? I really have a hard time of figuring out how to get the sprite ID or whatever of what I'm interacting with...

This post has been edited by thisbecasper: 28 May 2018 - 04:51 PM

0

User is offline   Danukem 

  • Duke Plus Developer

#2280

View PostRichardStorm, on 28 May 2018 - 06:11 AM, said:

Well i knew nothing about APLAYER thing; also, i cannot get why you shoot two bullets, but it seems to work very well ( and it never double press a button).

I tried some variations on your code, but your version is the only that works fine. Thanks :(


The code fires 2 bullets at slightly different heights. One fires from the base of the sprite and one fires a little above. The code was made for laser blasters, which are considerably larger than bullets. What would happen sometimes without the second bullet is the top half of the laser would hit the switch but it would not register as a hit. The reason it does not count as a double press is hard coding in Duke 3D. Without that hard coding, the shotgun would double press buttons whenever an even number of pellets hit.
0

User is offline   Danukem 

  • Duke Plus Developer

#2281

 thisbecasper, on 28 May 2018 - 04:31 PM, said:

Or when I look at them? I really have a hard time of figuring out how to get the sprite ID or whatever of what I'm interacting with...


What I do in my mods is constantly have the player hitscan and save the sprite id each tic so I know what is currently being scanned. But sometimes you are "looking at" an enemy even though it is not hitscanned (e.g. the hitscan is missing the enemy a little to the left or right). One way to address that issue is by having enemies set themselves as the looking target when the hitscan target is empty and certain conditions are met (ifcansee ifp pfacing...)
1

#2282

 Trooper Dan, on 28 May 2018 - 07:24 PM, said:

What I do in my mods is constantly have the player hitscan and save the sprite id each tic so I know what is currently being scanned.

I'm really sorry, but I have no clue what you mean by this. I would really like to get access to the data of the actor I'm looking at, I just don't know how it works in the code....
0

User is offline   Salvation 

#2283

It worked! Many thanks! I have spend many hours of getting that thing worked but i didn't get it. Now it works.



 RichardStorm, on 28 May 2018 - 11:20 AM, said:

I use time variables which keep for how much time a key is pressed, and the desired function is triggered or toggled when the timer is equal to 1:


gamevar  turnaround_keytime 0 1
gamevar  sight_on 0 1
...

ifvarand TEMP4  268435456
   { addvar turnaround_keytime 1 }
  else
   { setvar  turnaround_keytime 0 }

ifvare turnaround_keytime 1
   { xorvar sight_on 1 }

ifvare sight_on 1
  { /* your code here */ }
....


0

#2284

 thisbecasper, on 29 May 2018 - 05:29 AM, said:

I'm really sorry, but I have no clue what you mean by this. I would really like to get access to the data of the actor I'm looking at, I just don't know how it works in the code....

Maybe a concrete example can help:
onevent EVENT_GAME
  ifp pfacing
    getactor[THISACTOR].extra actorhp
endevent

Would this show the hp of the enemy I'm looking at. Does THISACTOR refer to the sprite ID of the actor duke is facing, because it is in a pfacing branch?

This post has been edited by thisbecasper: 29 May 2018 - 07:33 AM

0

#2285

I've got the healthbar to work, kinda - so thank you!

REMOVED

This post has been edited by thisbecasper: 10 July 2018 - 02:17 AM

0

User is offline   Zaxtor 

#2286

You know the SE Lotag 49 is Point Light and SE lotag 50 is Spotlight.
50 - makes spotlight that casts a shadow.
49 - point light (do not cast shadow)


But is there any def or con codes to make sprites act like that?
To make sprites emitting light radius like projectiles etc does.
I'm sure in projectile is hard coded.
Same for fires, atomic health etc.
0

User is offline   Danukem 

  • Duke Plus Developer

#2287

 Zaxtor, on 21 July 2018 - 07:28 PM, said:

But is there any def or con codes to make sprites act like that?



The only way I know how to do it is spawn a new SE, set it up appropriately, and then link it to the actor and make it fixed to the actor's coordinates. And don't forget to make the SE go away if the sprite dies or is deleted.

An example of this is shown in a video I linked in the very first post of the EDuke32 2.0 and Polymer thread back in 2009:


0

User is offline   Zaxtor 

#2288

I see, kinda a customized SE-like sprite like AMC mod has?
0

User is offline   Danukem 

  • Duke Plus Developer

#2289

 Zaxtor, on 21 July 2018 - 08:11 PM, said:

I see, kinda a customized SE-like sprite like AMC mod has?


It's literally an SE that is constantly being set to the location of the sprite which you want to glow. I'm guessing that AMC uses the same idea.
0

User is offline   Zaxtor 

#2290

Sprite I wanna make glow doesn't move and nor die.
Is a portal.
0

User is offline   Danukem 

  • Duke Plus Developer

#2291

If your mod has multiple playable characters and you want them all to have Duke's full functionality, then each character needs its own set of tiles for fists and such. I don't want Duke's fist displaying to hit the nuke button if I am using Bombshell. But, as far as I know, I can't just swap out his fist tile for a different one when Bombshell is selected. If I could just swap in a different tile (e.g. by just setting a variable for the tile in EVENT_DISPLAYFIST) that would be amazing, and that feature would come in handy (no pun intended) for many things, like stomping enemies, swiping a keycard, and more. Alas, what I end up doing is writing new display code for the other character's sprites to emulate the Duke version.

Currently I contemplate doing that for hitting the nuke button. I found this in the source for Duke:

 int const fistY       = klabs(pPlayer->look_ang) / 9;
    int const fistZoom    = clamp(65536 - (sintable[(512 + (fistInc << 6)) & 2047] << 2), 40920, 90612);
    int const fistYOffset = 194 + (sintable[((6 + fistInc) << 7) & 2047] >> 9);
    int const fistPal     = P_GetHudPal(pPlayer);
    int       wx[2]       = { windowxy1.x, windowxy2.x };

    rotatesprite((-fistInc + 222 + (fix16_to_int(g_player[screenpeek].inputBits->q16avel) >> 5)) << 16, (fistY + fistYOffset) << 16,
                 fistZoom, 0, FIST, fistShade, fistPal, 2, wx[0], windowxy1.y, wx[1], windowxy2.y);


I'm not sure how to translate that into CON code. I could eventually do it, with some learning and trial and error, but maybe there is someone around here who could do it much more easily than I. If so, I would really appreciate it!
1

User is offline   Mblackwell 

  • Evil Overlord

#2292

 Trooper Dan, on 22 July 2018 - 06:19 PM, said:

If your mod has multiple playable characters and you want them all to have Duke's full functionality, then each character needs its own set of tiles for fists and such. I don't want Duke's fist displaying to hit the nuke button if I am using Bombshell. But, as far as I know, I can't just swap out his fist tile for a different one when Bombshell is selected. If I could just swap in a different tile (e.g. by just setting a variable for the tile in EVENT_DISPLAYFIST) that would be amazing, and that feature would come in handy (no pun intended) for many things, like stomping enemies, swiping a keycard, and more. Alas, what I end up doing is writing new display code for the other character's sprites to emulate the Duke version.

Currently I contemplate doing that for hitting the nuke button. I found this in the source for Duke:

 int const fistY       = klabs(pPlayer->look_ang) / 9;
    int const fistZoom    = clamp(65536 - (sintable[(512 + (fistInc << 6)) & 2047] << 2), 40920, 90612);
    int const fistYOffset = 194 + (sintable[((6 + fistInc) << 7) & 2047] >> 9);
    int const fistPal     = P_GetHudPal(pPlayer);
    int       wx[2]       = { windowxy1.x, windowxy2.x };

    rotatesprite((-fistInc + 222 + (fix16_to_int(g_player[screenpeek].inputBits->q16avel) >> 5)) << 16, (fistY + fistYOffset) << 16,
                 fistZoom, 0, FIST, fistShade, fistPal, 2, wx[0], windowxy1.y, wx[1], windowxy2.y);


I'm not sure how to translate that into CON code. I could eventually do it, with some learning and trial and error, but maybe there is someone around here who could do it much more easily than I. If so, I would really appreciate it!




It's late so forgive any errors, but this should be about right if I didn't fall asleep while typing (it is possible!):


set y1 player[].look_ang
div y1 9
abs y1

set z1 65536
set z2 player[].fist_incs
shiftl z2 6
add z2 512
and z2 2047
sin z2 z2
sub z1 z2
clamp z1 40920 90612


set y2 player[].fist_incs
add y2 6
shiftl y2 7
and y2 2047
sin y2 y2
shiftr y2 9
add y2 194

set x1 input[].q16avel
shiftr x1 5
set x2 player[].fist_incs
inv x2
add x2 222
add x1 x2
shiftl x1 16

add y1 y2
shiftl y1 16

rotatesprite x1 y1 z1 0 FIST gs actor[player[].i].pal 2050 windowx1 windowy1 windowx2 windowy2

3

User is offline   Danukem 

  • Duke Plus Developer

#2293

It works perfectly! There was an extra backswing at first, because I forgot to include the line which caps the movement at fist_incs 32, but otherwise it worked correctly right out of the box. Thanks a million!

By the way, the following commands you used above are not listed at all in the Eduke32 wiki "full command list":

abs
clamp
inv

EDIT: There is one little thing...the avel stuff is no bueno. If you factor in input.q16avel, all that does is make the fist disappear when the player is pressing movement keys (I guess because it is throwing off the coordinates big time and causing it to draw off screen). But it works fine if the input isn't included. I wonder why the heck that is in the source.

Final code in my project ended up like this:

appendevent EVENT_DISPLAYFIST

ife pchar 1
{
	set RETURN -1
	// thanks to Mblackwell for fist CON code, adapted from Duke source
	set y player[].look_ang
	div y 9
	abs y

	set z 65536
	set z2 player[].fist_incs
	ifg z2 32 set z2 32
	shiftl z2 6
	add z2 512
	and z2 2047
	sin z2 z2
	sub z z2
	clamp z 40920 90612

	set y2 player[].fist_incs
	ifg y2 32 set y2 32
	add y2 6
	shiftl y2 7
	and y2 2047
	sin y2 y2
	shiftr y2 9
	add y2 194

	set x player[].fist_incs
	ifg x 32 set x 32
	inv x
	add x 222
	shiftl x 16
	add y y2
	shiftl y 16

	rotatesprite x y z 0 SHELLYFIST gs sprite[player[].i].pal 2050 0 0 xdim ydim
}
endevent


This post has been edited by Trooper Dan: 23 July 2018 - 02:29 AM

3

User is offline   Mblackwell 

  • Evil Overlord

#2294

Glad you got it working. Coolness.
0

#2295

How do I get the holoduke (or any other item) to execute its code even though duke hasn't seen the item? I want it to spawn monsters, but it only does so after Ive walked up to it (not preferable).
0

User is offline   Danukem 

  • Duke Plus Developer

#2296

 thisbecasper, on 14 August 2018 - 11:10 AM, said:

How do I get the holoduke (or any other item) to execute its code even though duke hasn't seen the item? I want it to spawn monsters, but it only does so after Ive walked up to it (not preferable).


This should work:

appendevent EVENT_GAME

     ifactor HOLODUKE ifn sprite[].statnum 1 changespritestat THISACTOR 1

endevent

0

#2297

 Trooper Dan, on 14 August 2018 - 11:16 AM, said:

This should work:

appendevent EVENT_GAME

     ifactor HOLODUKE ifn sprite[].statnum 1 changespritestat THISACTOR 1

endevent



I should say that I'm using the eduke old-mp build, and maybe that's why it wont run your code.

GAME.CON: In event `EVENT_GAME':
GAME.CON:37: error: expected a keyword but found `ifn'.
GAME.CON:37: error: expected a keyword but found `sprite'.
GAME.CON:37: error: expected a keyword but found `.statnum'.
GAME.CON:37: error: expected a keyword but found `1'.


EDIT: I've got it to work - but thanks! I was basically doing the same thing, but under actor holoduke (and that just doesn't work :-P )

This post has been edited by thisbecasper: 14 August 2018 - 11:53 AM

0

User is offline   Danukem 

  • Duke Plus Developer

#2298

Yeah, changing the statnum to 1 in the actor code is pointless since the actor code doesn't run unless the statnum is already 1.
0

#2299

Now another thing: I want the spawners to only spawn a monster by a chance, but it seems the spawn pattern is the same (I have multiple spawners, and each has a 50% chance to spawn a monster every fifth second). Somehow it makes sense, that the rng is doing the same exact thing every run, but I really need some "real" randomness...
0

User is offline   Danukem 

  • Duke Plus Developer

#2300

View Postthisbecasper, on 14 August 2018 - 02:42 PM, said:

Now another thing: I want the spawners to only spawn a monster by a chance, but it seems the spawn pattern is the same (I have multiple spawners, and each has a 50% chance to spawn a monster every fifth second). Somehow it makes sense, that the rng is doing the same exact thing every run, but I really need some "real" randomness...


The only way I know how to "fix" that also breaks sync in multiplayer.
1

#2301

Is there a way for duke to be ignored by monsters? In this coop game mode, when one dies, he will stay on the ground, dead, waiting for someone to revive him. I'd like the monsters to switch from the duke they killed to the other player naturally...
0

#2302

And lastly, the FFIRE doesn't do what it should I think... I set it to 0, but I can still kill my bot in coop mode. Doesn't "friendly fire off" work on bots, or am I doing something wrong here?
0

Share this topic:


  • 124 Pages +
  • « First
  • 75
  • 76
  • 77
  • 78
  • 79
  • 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