
EDuke32 Scripting "CON coding help"
#2087 Posted 17 October 2017 - 08:09 AM
What is that SHOTGUNAMMO variable? I suspect you don't need it.
#2088 Posted 17 October 2017 - 12:05 PM
Hendricks266, on 17 October 2017 - 08:09 AM, said:
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
#2089 Posted 17 October 2017 - 12:11 PM
thisbecasper, on 17 October 2017 - 12:05 PM, said:
Where you have
ifvarl SHOTGUNAMMO 10
you should be able to replace it with
ifvarl player[THISACTOR].ammo_amount 2 10
#2090 Posted 17 October 2017 - 12:15 PM
thisbecasper, on 17 October 2017 - 12:05 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
Trooper Dan, on 17 October 2017 - 12:11 PM, said:
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'.
#2091 Posted 17 October 2017 - 12:31 PM
Hendricks266, on 17 October 2017 - 12:15 PM, said:
Now you are just being pedantic.

#2092 Posted 17 October 2017 - 12:35 PM
Trooper Dan, on 17 October 2017 - 12:31 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".
#2093 Posted 17 October 2017 - 12:50 PM
Hendricks266, on 17 October 2017 - 12:15 PM, said:
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

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
#2094 Posted 17 October 2017 - 12:52 PM
Hendricks266, on 17 October 2017 - 12:35 PM, said:
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.
#2095 Posted 17 October 2017 - 01:00 PM
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
#2096 Posted 17 October 2017 - 07:48 PM
#2097 Posted 17 October 2017 - 11:05 PM
thisbecasper, on 17 October 2017 - 07:48 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.
#2098 Posted 18 October 2017 - 01:35 AM
Trooper Dan, on 17 October 2017 - 11:05 PM, said:
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?
#2099 Posted 18 October 2017 - 02:48 AM
thisbecasper, on 18 October 2017 - 01:35 AM, said:
I think I've found what I've been looking for by looking at the pages related to the one you linked, so thanks!
#2100 Posted 18 October 2017 - 05:28 AM
#2101 Posted 18 October 2017 - 10:31 AM
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.
#2102 Posted 18 October 2017 - 10:45 AM
Hendricks266, on 18 October 2017 - 10:31 AM, said:
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.
#2103 Posted 18 October 2017 - 03:30 PM
Hendricks266, on 18 October 2017 - 10:31 AM, said:
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
#2104 Posted 18 October 2017 - 04:58 PM
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.
#2105 Posted 19 October 2017 - 10:42 AM
#2106 Posted 19 October 2017 - 11:24 AM
thisbecasper, on 19 October 2017 - 10:42 AM, said:
Thanks for letting us know, it's likely a quick fix. You can always try Google Cache or archive.org.
#2107 Posted 19 October 2017 - 11:25 AM
#2109 Posted 19 October 2017 - 12:04 PM
- 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
#2110 Posted 19 October 2017 - 12:39 PM
thisbecasper, on 19 October 2017 - 12:04 PM, said:
You'll get that permission once you reach 50 posts. You're close.
#2111 Posted 19 October 2017 - 12:48 PM
Fox, on 05 August 2009 - 06:38 AM, said:
You still have the code for a heatseeking weapon??

#2112 Posted 19 October 2017 - 02:12 PM
#2113 Posted 19 October 2017 - 02:42 PM
Fox, on 19 October 2017 - 02:12 PM, said:
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

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...
#2114 Posted 19 October 2017 - 04:43 PM
ifdead { getplayer[THISACTOR].wackedbyactor temp getactor[temp].picnum temp2 ifvare temp2 APLAYER { getactor[temp].yvel temp2 setplayer[temp2].max_ammo_amount RPG_WEAPON 60 }
#2115 Posted 20 October 2017 - 01:56 AM
Hendricks266, 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