
EDuke32 Scripting "CON coding help"
#264 Posted 02 September 2009 - 06:45 AM
Subtracting center coords from player coords to find distance to player: FAIL!
Yes, it is simpler computationally to use subtraction, but the result is not very accurate, so just use the Pythagorean theorem and do it correctly.
#265 Posted 02 September 2009 - 06:55 AM
DeeperThought, on Sep 2 2009, 03:45 PM, said:
Which I have no idea how to do........not that I need it. I once required sometihng like this for making my actor's climb walls correctly but I just had my actor check his angle to both wall points to see if he was within the wall and not just clipping it. It was also used to allow my actor to align correctly since he needed to know whether to add or subtract 512 of the walls angle (so he would end up flat against the wall)
My method is probably (most certainly) lame so I wont bother posting exactly what I did.
This post has been edited by Chip: 02 September 2009 - 07:03 AM
#266 Posted 02 September 2009 - 08:04 AM
As I am now working on this mod of mine, i must ask whether it is actually possible to change the camera angle for third-person view using CON code?
I just want to know before I pour weeks/months into this project. Failing that, I guess it could work if it were instead possible to change the angle the gun fired at, but I also am not sure that is possible.
This post has been edited by High Treason: 02 September 2009 - 08:04 AM
#267 Posted 02 September 2009 - 08:17 AM
#268 Posted 02 September 2009 - 12:45 PM
A^2 + B^2 = C^2
#269 Posted 02 September 2009 - 12:51 PM
Quote
#270 Posted 02 September 2009 - 12:59 PM
XThX2, on Sep 2 2009, 01:51 PM, said:
If you believe that you are applying it perfectly and it's not working, then you must think there is something wrong with EDuke32 that is preventing it from working. But if you really believed that, then surely you would have posted your perfect code to make your point.
#271 Posted 02 September 2009 - 01:42 PM
addvarvar x wx addvarvar y wy divvar x 2 divvar y 2 subvarvar x posx mulvarvar x x subvarvar y posy mulvarvar y y addvarvar x y sqrt x x addlogvar x
Well, the values don't match at different places, which I'm sure it's because of the usage of "coordinates" I can't think of a better way to make it.
#272 Posted 02 September 2009 - 03:43 PM
XThX2, on Sep 2 2009, 02:42 PM, said:
addvarvar x wx addvarvar y wy divvar x 2 divvar y 2 subvarvar x posx mulvarvar x x subvarvar y posy mulvarvar y y addvarvar x y sqrt x x addlogvar x
Well, the values don't match at different places, which I'm sure it's because of the usage of "coordinates" I can't think of a better way to make it.
That looks right! I have used code that does exactly the same thing and it has worked fine for me. It makes me wonder if an assumption has gone wrong farther back, like maybe you aren't using the right wall points.
#273 Posted 02 September 2009 - 04:10 PM
This post has been edited by XThX2: 02 September 2009 - 04:10 PM
#274 Posted 05 September 2009 - 07:37 AM
I'm certain I've seen one but I've just been through the wiki and can't find it. I hope I haven't imagined it.

This post has been edited by Chip: 05 September 2009 - 07:39 AM
#275 Posted 05 September 2009 - 08:15 AM
Chip, on Sep 5 2009, 08:37 AM, said:
I'm certain I've seen one but I've just been through the wiki and can't find it. I hope I haven't imagined it.

Just set the player's ftq to the quote number and set fta to the amount of time to display.
#277 Posted 06 September 2009 - 08:23 AM
I have 4 vectors with different values, but the minimum value gets out only from 2 last vectors? Help me to solve a problem:)
Example:
ARRAY[1] = 3000
ARRAY[2] = 400
ARRAY[3] = 1000
ARRAY[4] = 5000
Result of a code is value equal 1000
setvar tmp 1 whilevarn tmp 5 { setvarvar tmp2 tmp addvar tmp2 1 setvarvar tmp3 tmp2 addlogvar ARRAY[tmp] addlogvar ARRAY[tmp3] ifvarvarg ARRAY[tmp] ARRAY[tmp3] ifvarg ARRAY[tmp3] 0 setvarvar tmp5 ARRAY[tmp3] addlogvar tmp5 addvar tmp 1 }
This post has been edited by M210: 06 September 2009 - 08:26 AM
#278 Posted 06 September 2009 - 08:30 AM
#279 Posted 06 September 2009 - 08:49 AM
XThX2, on Sep 6 2009, 08:30 PM, said:
If it to remove, the code will cease to work and I need to receive the minimum distance every second instead of once
This post has been edited by M210: 06 September 2009 - 08:51 AM
#280 Posted 06 September 2009 - 09:28 AM
#281 Posted 06 September 2009 - 09:41 AM
DeeperThought, on Sep 5 2009, 05:15 PM, said:
I was going to reply saying that I don't think that would work for my code but after realizing that this was done through the get/set player/actor stuff it is sure to be exactly what I was after - thanks

setplayer[THISACTOR].ftq QUOTEVAR setplayer[THISACTOR].fta 99
#282 Posted 06 September 2009 - 09:41 AM
Now my code works fine, DeeperThought what are you think, whether this code of updating demands, my code have a errors?
setvar tmp 1 whilevarn tmp 3 { setvarvar tmp2 tmp setvar tmp3 2 whilevarn tmp3 5 { ifvarvarg ARRAY[tmp2] ARRAY[tmp3] { setvarvar tmp2 tmp3 } setvarvar tmp4 ARRAY[tmp] setarray ARRAY[tmp] ARRAY[tmp2] setarray ARRAY[tmp2] tmp4 addvar tmp3 1 } ifvarvarg ARRAY[1] ARRAY[2] { setvarvar minimum ARRAY[2] } else { setvarvar minimum ARRAY[1] } addvar tmp 1 } addlogvar minimum
This post has been edited by M210: 06 September 2009 - 10:11 AM
#283 Posted 06 September 2009 - 11:49 AM
Chip, on Sep 6 2009, 02:41 PM, said:

setplayer[THISACTOR].ftq QUOTEVAR setplayer[THISACTOR].fta 99
#284 Posted 07 September 2009 - 12:21 AM
What do I need to tamper with to change these things? I hope they can be meddled with or else i will have to go a very long way around.
Basically what I am trying to do is make it so when the player presses the back key (onevent MOVE_BACKWARD) it changes the angle of the player sprite and firing, but it can't just change the way the player is facing because that would effectively make him walk the same way he had been doing. Obviously I am working from a 2D perspective, so he will always face the exact same angle when walking a particular way - For example, it might always set his angle so he faces the left of the map, this wouldn't matter because it is only using 2 dimensions anyway.
This post has been edited by High Treason: 07 September 2009 - 12:22 AM
#285 Posted 07 September 2009 - 01:28 AM
getplayer[THISACTOR].angle angle1 addvar angle1 1024/subvar angle1 1024 setplayer[THISACTOR].angle angle1
This might work for you. Add/substract is to make him face left/right, in your case back and front (Or I assume it is.) Since the angle of player has changed, all the weapons will fire from that angle. (Unless coded otherwise)
#286 Posted 07 September 2009 - 01:37 AM
High Treason, on Sep 7 2009, 01:21 AM, said:
What do I need to tamper with to change these things? I hope they can be meddled with or else i will have to go a very long way around.
Basically what I am trying to do is make it so when the player presses the back key (onevent MOVE_BACKWARD) it changes the angle of the player sprite and firing, but it can't just change the way the player is facing because that would effectively make him walk the same way he had been doing. Obviously I am working from a 2D perspective, so he will always face the exact same angle when walking a particular way - For example, it might always set his angle so he faces the left of the map, this wouldn't matter because it is only using 2 dimensions anyway.
http://wiki.eduke32.com/wiki/Ang
Is that what you want? I'm confused by your post.
It sounds like you want the player to automatically turn around each time he reverses direction, like in Contra and a lot of other 2D games. That means he won't be able to run backwards, which I think is a shame, because running backwards while firing is useful. If I were coding it I would make use of the existing turn around key and allow moving backwards to function normally (albeit with an enforced corridor relative angle).
EDIT @XThX2: What do you imagine he is going to do with that code? If you are trying to help an inexperienced person by posting code, you should make sure that it actually works, otherwise it just creates more confusion.
This post has been edited by DeeperThought: 07 September 2009 - 01:41 AM
#287 Posted 07 September 2009 - 03:02 AM
Can't seem to get that working, I fiddled with it a fair amount but just end up with errors, I will keep messing about with it.
@deeperthought
The problem with ang is that it makes the player face that way, so he is moving in the same direction when pressing that key as he was when pressing the other key. Also it causes the camera to face the other way (through a wall usually) and thus I have to tell the camera which way to face in the same event, which usually works but causes occasional flickering.
I guess I could always come up with a weird control scheme where you press the up key to move the player in the direction he is facing and you use the arrow keys to select the way you want him to face, I have played games with a similar scheme but they were top-down view - in fact I think I will give this a go and see how it feels, but my natural instinct when playing a side-scroller (which i spend 80% of my time doing) is to use traditional sidescrolling controls, so it would take some getting used to and I imagine other people wouldn't be too happy with it either.
I'm actually quite enjoying playing about with the codes, even when I get things wrong, interesting results sometimes occur, such as today I somehow managed to disable the gravity and the player exploded as soon as the level started, then you could not start a new game or restart the level, no idea how I managed that by just be messing with the health bar code.
#288 Posted 07 September 2009 - 03:04 AM
onevent EVENT_MOVEFORWARD ifvare mykeypress 1 nullop else { getplayer[THISACTOR].ang angle addvar angle 1024 setplayer[THISACTOR].ang angle setvar mykeypress 1 } endevent onevent EVENT_MOVEBACKWARD ifvare mykeypress 2 nullop else { getplayer[THISACTOR].ang angle subvar angle 1024 setplayer[THISACTOR].ang angle setvar mykeypress 2 } endevent
Here's the working code, in any case. I've used my own variables. In case you might need, define these at defs.con or user.con.
gamevar mykeypress 0 1
gamevar angle 0 1
This post has been edited by XThX2: 07 September 2009 - 03:05 AM
#289 Posted 07 September 2009 - 06:43 AM
Eventually i did this;
onevent EVENT_DISPLAYREST setvar cameradist 200000 setplayer[THISACTOR].look_ang angle endevent onevent EVENT_GAME setplayer[THISACTOR].look_ang angle endevent onevent EVENT_TURNLEFT setvar angle 512 setplayer[THISACTOR].ang 1024 endevent onevent EVENT_TURNRIGHT setvar angle 1536 setplayer[THISACTOR].ang 0 endevent
For some reason I also have to do "setplayer[THISACTOR].look_ang angle" under EVENT_GAME or else a horrid flicker occurs, i figure this is somewhat inefficient, but it runs on my Athlon XP so it can't be that bad, the controls in this manner are surprisingly fluent (i think that's the word) - at the moment the camera is facing forward when the game starts, but I think I know how to fix that (rearrange the code a bit and probably define "angle" as 1536 at the top of the .con).
#290 Posted 07 September 2009 - 07:52 PM
This post has been edited by Ilovefoxes: 07 September 2009 - 07:53 PM
#291 Posted 07 September 2009 - 08:03 PM
Ilovefoxes, on Sep 7 2009, 08:52 PM, said:
Yeah, they both have statnum 10, which is weird. Try "ifspawnedby APLAYER" which is only true for the hologram.
EDIT: This should work also -- ifvarvarn THISACTOR player[THISACTOR].i // hologram if true
This post has been edited by DeeperThought: 07 September 2009 - 08:10 PM
#292 Posted 07 September 2009 - 08:11 PM
Ilovefoxes: it doesn't look like you can in a reliable way. You would be much better off intercepting EVENT_HOLODUKEON and spawning the sprite yourself.