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

Jump to content

  • 124 Pages +
  • « First
  • 69
  • 70
  • 71
  • 72
  • 73
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

EDuke32 Scripting  "CON coding help"

#2088

View PostHendricks266, on 17 October 2017 - 08:09 AM, said:

If you're using a switch style, you should update the vars directly in EVENT_TURNAROUND instead of using PRESSEDFIRE.

What is that SHOTGUNAMMO variable? I suspect you don't need it.


Thank you for the help. I've got it to work now like this:

gamevar SHOTGUNAMMO 0 1
gamevar choice 0 1
gamevar PWEAPON 0 1

onevent EVENT_TURNAROUND
{
	setvar RETURN -1
	ifvare PWEAPON 2
   	{
    	ifvare choice 0
    	{
    		ifvarl SHOTGUNAMMO 10
    		{
    			quote 36
    			break
    		}
    		setvar choice 1
    		sound SELECT_WEAPON
    		setvar WEAPON2_SHOOTS 1092
       		setvar WEAPON2_SHOTSPERBURST 10
       		setvar WEAPON2_FIRESOUND PISTOL_RICOCHET
       		setvar WEAPON2_FLAGS 17472 	
        	quote 34
    	}
    	else
    	{
    		setvar choice 0
    		sound SHOTGUN_COCK
    		setvar WEAPON2_SHOOTS SHOTGUN
    		setvar WEAPON2_SHOTSPERBURST 7
    		setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
    		setvar WEAPON2_FLAGS 1024
        	quote 35
    	} 
    }
}	    
endevent

onevent EVENT_DOFIRE
{
	ifvare PWEAPON 2
	{
		ifvare choice 1
		{
			ifvarl SHOTGUNAMMO 10
			{
				setvar choice 0
    			sound SHOTGUN_COCK
    			setvar WEAPON2_SHOOTS SHOTGUN
    			setvar WEAPON2_SHOTSPERBURST 7
    			setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
    			setvar WEAPON2_FLAGS 1024
        		quote 40
			}
		}
	}
}
endevent


I think I need the var SHOTGUNAMMO inorder to keep track of current ammo of the shotgun?. Can I do it without the var and without causing an out-of-sync error? I've btw also managed to get rid of the out-of-sync thing - I still don't see the big difference between using a var like I do to keep track of the players current weapon and a call to currentweapon, which was what caused it..

This post has been edited by thisbecasper: 17 October 2017 - 12:11 PM

0

User is online   Danukem 

  • Duke Plus Developer

#2089

View Postthisbecasper, on 17 October 2017 - 12:05 PM, said:

I think I need the var SHOTGUNAMMO inorder to keep track of current ammo of the shotgun?


Where you have

ifvarl SHOTGUNAMMO 10


you should be able to replace it with

ifvarl player[THISACTOR].ammo_amount 2 10

0

User is offline   Hendricks266 

  • Weaponized Autism

  #2090

View Postthisbecasper, on 17 October 2017 - 12:05 PM, said:

I think I need the var SHOTGUNAMMO inorder to keep track of current ammo of the shotgun?. Can I do it without the var and without causing an out-of-sync error? I've btw also managed to get rid of the out-of-sync thing - I still don't see the big difference between using a var like I do to keep track of the players current weapon and a call to currentweapon, which was what caused it..

The game already keeps track of things like ammo counts and current weapon. Attempting to circumvent this by using your own vars at best is a duplication of effort, and at worst is asking for a lot of trouble when you let them get out of sync.

Yeah, currentweapon was a mistake, it should only be used in HUD drawing events.

You're going to need to get comfortable with global scratch variables. While you're at it, take the time to indent your code correctly. (8 spaces per tab stop is unnecessary, use 4 at the max.)

definegamefuncname 36 Switch_Weapon_Function

gamevar temp 0 0

gamevar subweapon_choice 0 1

onevent EVENT_TURNAROUND
    setvar RETURN -1

    getplayer[THISACTOR].curr_weapon temp
    ifvare temp 2
    {
        ifvare subweapon_choice 0
        {
            ifvarl SHOTGUNAMMO 10
            {
                quote 36
                break
            }
            setvar subweapon_choice 1
            sound SELECT_WEAPON
            setvar WEAPON2_SHOOTS 1092
            setvar WEAPON2_SHOTSPERBURST 10
            setvar WEAPON2_FIRESOUND PISTOL_RICOCHET
            setvar WEAPON2_FLAGS 17472
            quote 34
        }
        else
        {
            setvar subweapon_choice 0
            sound SHOTGUN_COCK
            setvar WEAPON2_SHOOTS SHOTGUN
            setvar WEAPON2_SHOTSPERBURST 7
            setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
            setvar WEAPON2_FLAGS 1024
            quote 35
        }
    }
endevent

onevent EVENT_DOFIRE
    getplayer[THISACTOR].curr_weapon temp
    ifvare temp 2
    {
        ifvare subweapon_choice 1
        {
            getplayer[THISACTOR].ammo_amount SHOTGUN_WEAPON temp
            ifvarl temp 10
            {
                setvar subweapon_choice 0
                sound SHOTGUN_COCK
                setvar WEAPON2_SHOOTS SHOTGUN
                setvar WEAPON2_SHOTSPERBURST 7
                setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
                setvar WEAPON2_FLAGS 1024
                quote 40
            }
        }
    }
endevent


View PostTrooper Dan, on 17 October 2017 - 12:11 PM, said:

Where you have

ifvarl SHOTGUNAMMO 10


you should be able to replace it with

ifvarl player[THISACTOR].ammo_amount 2 10


He's using OldMP, which doesn't support quick structure access. Also, use SHOTGUN_WEAPON instead of the magic constant '2'.
0

User is online   Danukem 

  • Duke Plus Developer

#2091

View PostHendricks266, on 17 October 2017 - 12:15 PM, said:

Also, use SHOTGUN_WEAPON instead of the magic constant '2'.


Now you are just being pedantic. :rolleyes: There's no advantage to typing the label there except for readability, but anyone who has worked with the game very long knows which weapons the numbers correspond to.
0

User is offline   Hendricks266 

  • Weaponized Autism

  #2092

View PostTrooper Dan, on 17 October 2017 - 12:31 PM, said:

Now you are just being pedantic. :rolleyes: There's no advantage to typing the label there except for readability, but anyone who has worked with the game very long knows which weapons the numbers correspond to.

You're basically telling me "Who cares?", which is a pet peeve when I'm trying to get across something important. Your argument is a slippery slope to completely neglecting your code style, after all, you know what it does.

This stands opposed to every commit Helix or I have made regarding "enumifying" a set of magic constants.

Furthermore, what if you want to search for all code effecting the shotgun at once? The Unix utility for this is called grep, and you'll usually see it used as a verb. You'll have much more luck grepping for SHOTGUN_WEAPON than "2".
1

#2093

View PostHendricks266, on 17 October 2017 - 12:15 PM, said:

The game already keeps track of things like ammo counts and current weapon. Attempting to circumvent this by using your own vars at best is a duplication of effort, and at worst is asking for a lot of trouble when you let them get out of sync.

Yeah, currentweapon was a mistake, it should only be used in HUD drawing events.

You're going to need to get comfortable with global scratch variables. While you're at it, take the time to indent your code correctly. (8 spaces per tab stop is unnecessary, use 4 at the max.)

definegamefuncname 36 Switch_Weapon_Function

gamevar temp 0 0

gamevar subweapon_choice 0 1

onevent EVENT_TURNAROUND
    setvar RETURN -1

    getplayer[THISACTOR].curr_weapon temp
    ifvare temp 2
    {
        ifvare subweapon_choice 0
        {
            ifvarl SHOTGUNAMMO 10
            {
                quote 36
                break
            }
            setvar subweapon_choice 1
            sound SELECT_WEAPON
            setvar WEAPON2_SHOOTS 1092
            setvar WEAPON2_SHOTSPERBURST 10
            setvar WEAPON2_FIRESOUND PISTOL_RICOCHET
            setvar WEAPON2_FLAGS 17472
            quote 34
        }
        else
        {
            setvar subweapon_choice 0
            sound SHOTGUN_COCK
            setvar WEAPON2_SHOOTS SHOTGUN
            setvar WEAPON2_SHOTSPERBURST 7
            setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
            setvar WEAPON2_FLAGS 1024
            quote 35
        }
    }
endevent

onevent EVENT_DOFIRE
    getplayer[THISACTOR].curr_weapon temp
    ifvare temp 2
    {
        ifvare subweapon_choice 1
        {
            getplayer[THISACTOR].ammo_amount SHOTGUN_WEAPON temp
            ifvarl temp 10
            {
                setvar subweapon_choice 0
                sound SHOTGUN_COCK
                setvar WEAPON2_SHOOTS SHOTGUN
                setvar WEAPON2_SHOTSPERBURST 7
                setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
                setvar WEAPON2_FLAGS 1024
                quote 40
            }
        }
    }
endevent



He's using OldMP, which doesn't support quick structure access. Also, use SHOTGUN_WEAPON instead of the magic constant '2'.


It makes sense that you can do it like this, without declaring a new var. Regarding indentation: Yeah, it happens when I copy paste into duke4net, it's good in sublime text :rolleyes:
If I don't use my SHOTGUNAMMO like I coded, and instead like in your code, It doesn't work - It's like it doesn't register the current ammo at all, maybe I'm missing some declaration?
- Is there a way to change the color of the crosshair together with weapon-switches?? Can't seem to find anything about it online.

This post has been edited by thisbecasper: 17 October 2017 - 01:02 PM

0

User is online   Danukem 

  • Duke Plus Developer

#2094

View PostHendricks266, on 17 October 2017 - 12:35 PM, said:

You're basically telling me "Who cares?", which is a pet peeve when I'm trying to get across something important. Your argument is a slippery slope to completely neglecting your code style, after all, you know what it does.

This stands opposed to every commit Helix or I have made regarding "enumifying" a set of magic constants.

Furthermore, what if you want to search for all code effecting the shotgun at once? The Unix utility for this is called grep, and you'll usually see it used as a verb. You'll have much more luck grepping for SHOTGUN_WEAPON than "2".


This is an interesting discussion, well worth having, and I have an open mind about it. You make a good point about the search, although it's not quite as bad as you make it out to be (it would take several different searches to round up all the shotgun references, but one could certainly do a lot better than searching for "2").

I don't agree that using constants instead of defined labels necessarily leads one down a slippery slope to completely neglecting code style. Empirically that's just false. I also think that coding at the source level may require different standards. For one thing, the source code could potentially be used for a different Build game. In any case, I regard the weapon numbers differently from, say, tile numbers. I would never use "2000" in the place of "PIGCOP", and not just because of readability -- in theory you could move PIGCOP to a different tile and it would more or less work the same (although there would be some issues because there is hardcoded stuff for tile 2000 in the source!). But putting SHOTGUN_WEAPON on a slot other than 2 would require changing a lot of stuff.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#2095

For me labels are a huge advantage.

But there will be a difference once dynamicremap is implemented for weapons.

This post has been edited by Fox: 17 October 2017 - 01:01 PM

0

#2096

It's time for me to attempt to make gun-game mode. I need to make a player be limited with only one weapon which changes as the player gets or loses kills. So how do I get amount of kills of a player?
0

User is online   Danukem 

  • Duke Plus Developer

#2097

View Postthisbecasper, on 17 October 2017 - 07:48 PM, said:

It's time for me to attempt to make gun-game mode. I need to make a player be limited with only one weapon which changes as the player gets or loses kills. So how do I get amount of kills of a player?


Here's your basic kill count: http://wiki.eduke32....i/Actors_killed

If you want a system where the player can lose kills, then you'll need to make your own counter.
0

#2098

View PostTrooper Dan, on 17 October 2017 - 11:05 PM, said:

Here's your basic kill count: http://wiki.eduke32....i/Actors_killed

If you want a system where the player can lose kills, then you'll need to make your own counter.

Sorry, I'm talking multiplayer only - Idk if that's the same counter?
0

#2099

View Postthisbecasper, on 18 October 2017 - 01:35 AM, said:

Sorry, I'm talking multiplayer only - Idk if that's the same counter?

I think I've found what I've been looking for by looking at the pages related to the one you linked, so thanks!
0

#2100

getplayer[THISACTOR].frag gets the players number of frags in a multiplayer game. If you suicide your score decrements by adding one to fraggedself, because the score is the difference between "frag" and "fraggedself". Can't seem to find a structure member that is the score, so how do I make variable that is equal to score? I suppose you can't make it like this: gamevar score ("frag" - "fraggedself") 1...
0

User is offline   Hendricks266 

  • Weaponized Autism

  #2101

This is another example of a case where there is no need to keep your own per-player gamevar. Resist the urge to use those unless you are inventing your own quantity.

gamevar killcount 0 0
gamevar temp 0 0

state getkillcount
    getplayer[THISACTOR].frag killcount
    getplayer[THISACTOR].fraggedself temp
    subvarvar killcount temp
ends


Call state getkillcount before any code section that needs it, and it will populate the killcount variable.
0

User is online   Danukem 

  • Duke Plus Developer

#2102

View PostHendricks266, on 18 October 2017 - 10:31 AM, said:

This is another example of a case where there is no need to keep your own per-player gamevar. Resist the urge to use those unless you are inventing your own quantity.


I think he had come to that same conclusion, if his last post was any indication. When I posted, I had no idea he was working on a multiplayer mod, which is why I thought he might need his own counter.
0

#2103

View PostHendricks266, on 18 October 2017 - 10:31 AM, said:

This is another example of a case where there is no need to keep your own per-player gamevar. Resist the urge to use those unless you are inventing your own quantity.

gamevar killcount 0 0
gamevar temp 0 0

state getkillcount
    getplayer[THISACTOR].frag killcount
    getplayer[THISACTOR].fraggedself temp
    subvarvar killcount temp
ends


Call state getkillcount before any code section that needs it, and it will populate the killcount variable.


This works! I have yet to understand how all of this works... Although I think im slowly understanding bits and pieces, so THANK YOU. Three more questions if I may...: How do I place a sprite or character in the dead center of the screen? Is there a way to make sure a character is drawn in the middle between the crosshair and hud regardless of aspect ratio and resolution? How do I place a quote in a specifik spot on the screen when I have the, let's say, the shotgun equipped (The quote should be displayed as long as the shotgun is equipped)? (It's only the part of being able to draw a quote to the screen that has be troubled)

This post has been edited by thisbecasper: 18 October 2017 - 03:32 PM

0

User is offline   Hendricks266 

  • Weaponized Autism

  #2104

You can do those things in EVENT_DISPLAYREST using the screentext and rotatesprite. If you use rotatesprite at (160, 100) it should be right in the center.

If that sprite will be _part_ of the crosshair, I believe putting that part in EVENT_DISPLAYCROSSHAIR instead will turn it off along with the crosshair, if disabled.
0

#2105

The eduke wiki has been down the hole day. Do you guys know anything about it or have an alternative site to learn how to mod?
0

User is offline   Hendricks266 

  • Weaponized Autism

  #2106

View Postthisbecasper, on 19 October 2017 - 10:42 AM, said:

The eduke wiki has been down the hole day. Do you guys know anything about it or have an alternative site to learn how to mod?

Thanks for letting us know, it's likely a quick fix. You can always try Google Cache or archive.org.
0

User is offline   Kyanos 

#2107

It's on the wayback machine at archive.org
https://web.archive..../wiki/Main_Page
0

User is offline   TerminX 

  • el fundador

  #2108

Fixed.
1

#2109

Holy shit guys. You're better than christmas and birthday combined to me LOL, THANKS!
- How come I can't upvote replies? "You've reached maximum amount of upvotes" it says. (Haven't upvoted anything yet)

This post has been edited by thisbecasper: 19 October 2017 - 12:08 PM

0

User is offline   Hendricks266 

  • Weaponized Autism

  #2110

View Postthisbecasper, on 19 October 2017 - 12:04 PM, said:

- How come I can't upvote replies? "You've reached maximum amount of upvotes" it says. (Haven't upvoted anything yet)

You'll get that permission once you reach 50 posts. You're close.
0

#2111

View PostFox, on 05 August 2009 - 06:38 AM, said:

I am trying to make an heat-seeking weapon... although every time I shoot two times and the first shot kill the enemy, the sprites is deleted and them the second shot has an invalid sprite ID. How does can I check if an ID actually exists as specific sprite?

You still have the code for a heatseeking weapon?? :rolleyes:
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#2112

That's a 8 years old post. I have a code, but it's for a specific use.
0

#2113

View PostFox, on 19 October 2017 - 02:12 PM, said:

That's a 8 years old post. I have a code, but it's for a specific use.

I would still be interested in seeing how one manages to shoot a projectile that follows the closest player or the originally aimed at (if possible), but if you cba, it's all cool :rolleyes:.

Something completely different:
I want to do something to the player (in this example I just set the rpg max ammo to 60), when the player kills another player actor. I thought it would work like this:

gamevar killer 0 1

actor APLAYER ...

(...)

ifdead
  {
    getplayer[THISACTOR].wackedbyactor killer
    setplayer[killer].max_ammo_amount 4 60


Buuuuuuut it doesn't...
0

User is offline   Hendricks266 

  • Weaponized Autism

  #2114

ifdead
{
    getplayer[THISACTOR].wackedbyactor temp
    getactor[temp].picnum temp2
    ifvare temp2 APLAYER
    {
        getactor[temp].yvel temp2
        setplayer[temp2].max_ammo_amount RPG_WEAPON 60
    }

0

#2115

View PostHendricks266, on 19 October 2017 - 04:43 PM, said:

ifdead
{
    getplayer[THISACTOR].wackedbyactor temp
    getactor[temp].picnum temp2
    ifvare temp2 APLAYER
    {
        getactor[temp].yvel temp2
        setplayer[temp2].max_ammo_amount RPG_WEAPON 60
    }



It works, but it was intended to increment different variables so that with each kill, your weapon got stronger or something:

ifdead
  {
    getplayer[THISACTOR].wackedbyactor killer
    getactor[killer].picnum tempkiller
    ifvare tempkiller APLAYER
    {
    	getactor[killer].yvel tempkiller
    	addvar rpgammo 10
    	setplayer[tempkiller].max_ammo_amount RPG_WEAPON rpgammo
    }


Right now I think it perfoms the "addvar rpgammo 10" many many times, because the ifdead maybe works like whiledead also? If I get a kill with this code i get 1410-something maxammo. I only want it to do once everytime a player dies. And how do I alter another players variable? Becuase in fact, I'd want to set the killers maxammo to the originally maxammo plus (the times the killer have gotten a kill) * (10)..

This post has been edited by thisbecasper: 20 October 2017 - 02:17 AM

0

User is online   Danukem 

  • Duke Plus Developer

#2116

Yeah, "ifdead" does work like while dead, so any "ifdead" condition that triggers the ammo bonus should be nested inside an "ifhitweapon" check, to insure that only the killing blow is counted. This means you should make a state that does the bonusing and call it only after appropriate "ifdead" instances.
0

#2117

View PostTrooper Dan, on 20 October 2017 - 10:02 AM, said:

Yeah, "ifdead" does work like while dead, so any "ifdead" condition that triggers the ammo bonus should be nested inside an "ifhitweapon" check, to insure that only the killing blow is counted. This means you should make a state that does the bonusing and call it only after appropriate "ifdead" instances.


I can see the point in making states here, although I simply can't make it to work...

state updatevalue
{
	getplayer[THISACTOR].wackedbyactor killer
    getactor[killer].picnum tempkiller
    ifvare tempkiller APLAYER
    {
    		ifhitweapon
    		{
    			addvar rpgsammo 10
    		}
    		getactor[killer].yvel tempkiller
    		setplayer[tempkiller].max_ammo_amount RPG_WEAPON rpgsammo
    }
}
ends

---

 ifdead
  {
    state updatevalue


I am drawing the rpgsammo through digitalnumberz so I can keep track of it as I'm killing players and dying to players. No matter what it wont increment, and it also just sets the maxammo to whatever the value the variable was declared with in the first place. Actually I'm doubting that I'm using ifhitweapon correct, because when I place the two lines below into the if-statement together with "addvar rpgsammo 10", it wont even set maxammoamount :rolleyes:

This post has been edited by thisbecasper: 20 October 2017 - 02:17 PM

0

Share this topic:


  • 124 Pages +
  • « First
  • 69
  • 70
  • 71
  • 72
  • 73
  • 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