Duke4.net Forums: Need coding help - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Need coding help  "Enemies, usable objects.."

#1

Hello!

It's halloween-time again and like every year a haunted house-idea pops into my mind. I started a map years ago, with some custom sounds (used from the old "The Lasthalf Of Darkness" dos game) but I lost interest in it. I recreated the parts I made last year but then lost interest in it.
But not I'm full on it again. Problem is: I need coding help.

My problems:
- I've made an enemy "fakeghost". I want it to charge the player and then disappear. But my AI-Code doesn't seem to do that, since the ghost is just wobbling around.
- I want to make a knight armour stand where you can walk around and see that from different angles. It's just not working.
- I'm going for an adventure-style gameplay, where you can look at objects. But there's a problem with the actors. If you press the use key (space) the standard duke-sounds are coming up and my custom sounds aren't played. At least not everytime. You can hold down the key but that makes the sound repeat lateron. Secondly the spacebar is interpreted to be pressed repeatedly insted of just one time. I dont't exactly know how to explain this.. I've made a picture pickup. You take that thing and then you hang it in place and a door opens. When you hang it, a quote is displayed and a sound played. If you press use again, you take a "look" at this picture and a different quote ist displayed / different sound is played. Problem is: When you plress the use key the picture is on the wall and immediately the other quote is displayed. There don't seems to be a pause after every keypress.

- Also is there a way to let duke start without a weapon? Besides putting him on hurtrail?

//Picture that should be lookable
useractor notenemy AQUARELLE2 20
cstat 273
spritepal 0
ifp pfacing
	ifpdistl 1024
	{
		ifhitspace
		{
			sound QUOTE136
			quote 136
		}
	}
enda

//The fakeghost
define FAKEGHOST 3980
action FAKEGHOST_ANIMATIONS  0  7  1  1  8
move FAKEGHOSTVELS 96 -30

ai AIFAKEGHOST_GETPLAYER  FAKEGHOST_ANIMATIONS FAKEGHOSTVELS seekplayer

useractor enemy FAKEGHOST

  ifai NO           
  {                   
    ai AIFAKEGHOST_GETPLAYER 
  }
	ifpdistl 512
	{
		palfrom 16 255 255 255
		killit
	}

enda

//Knight Armour
define KNIGHT 3400
action KNIGHTSTAND  0 1 5 1 1
define KNIGHTSTAND_SPEED 64
move KNIGHTSTAND_SPEED

useractor notenemy KNIGHT
cstat 256
 ifai NO           
  {  
	action KNIGHTSTAND
	}
enda



I hope you get what I mean since I'm not a native english speaker.
For better understanding, here's a little video showing my problems.

Thanks, guys!

https://youtu.be/3V6JCKS23AE



Edit: Video is dark. I mean, really really dark.

This post has been edited by BrOiler1985: 16 October 2016 - 08:08 AM

2

User is offline   Darkus 

#2

For the ghost, I see two possibilities, choose one you like:

1) At the 'ai' definition, replace 'seekplayer' by 'faceplayer':

ai AIFAKEGHOST_GETPLAYER FAKEGHOST_ANIMATIONS FAKEGHOSTVELS faceplayer


2) Or if you want to keep 'seekplayer', add 'ifcansee' above 'ifpdistl 512':

        ifcansee
        ifpdistl 512
        {
                palfrom 16 255 255 255
                killit
        }



For the armour, corrected move definition, added -1 health (invincible), and corrected animation:

//Knight Armour
define KNIGHT 3400
action KNIGHTSTAND  0 1 5 1 1
move KNIGHTSTAND_SPEED 64

useractor notenemy KNIGHT -1
 ifaction NO           
  { cstat 257
    action KNIGHTSTAND
  }
enda


Quote

If you press the use key (space) the standard duke-sounds are coming up and my custom sounds aren't played.

try 'stopsound' (I don't know if that works)

                ifhitspace
                {
                        stopsound DUKE_SEARCH
                        stopsound DUKE_SEARCH2
                        sound QUOTE136
                        quote 136
                }


Quote

- Also is there a way to let duke start without a weapon? Besides putting him on hurtrail?


You can create an isolated sector with HURTRAIL texture, put the player start point in it, and add a one-way teleporter that lead at your map start point.

Quote

Problem is: When you plress the use key the picture is on the wall and immediately the other quote is displayed. There don't seems to be a pause after every keypress.

You can also use different 'action' names in the same actor: one that display messages, and one to make you wait before you can use them again,

example:

definitions:
action ANIMDO1 0
action ANIMWAIT 0

Place this inside your actor code:
ifaction ANIMDO1 // when in 'normal' animation
{ ifp pfacing
  ifpdistl 1024
  ifhitspace
  { 'do something'  // your actions here
    action ANIMWAIT // change to the 'waiting' animation
  }
}
else ifaction ANIMWAIT  // when in 'waiting' animation
{ ifactioncount 60  // delay
  action ANIMDO1    // go back to normal state
}

4

#3

Thanks so much! That works. A little fiddling aroud here and there and now it works like it should!
1

User is offline   Danukem 

  • Duke Plus Developer

#4

This is nice to see; this is the way asking for and receiving scripting help is supposed to work. Someone has made an effort and is actively working on a problem, asks for specific help and gets it, then implements it and verifies it.

Every now and then some lazy jackass (NOT you, obviously) will appear on the forums and ask for tutorials without actually doing any work. Trying to help those people is almost always a waste of time, because they won't make any effort and then they bitch about the tutorials not being good enough. The next time someone like that shows up, I hope I can remember to show them this thread.
4

#5

Thanks @TrooperDan. I'm not that much into the coding-stuff.. but I really want to understand it. I'll try before I ask.

After browsing the wiki.. I kinda don't understand that event stuff. Is there a way of drawing a sprite on the hud besides rotatesprite / myos and the other event driven stuff?
If not, with the events I figured EVENT_GAME would be the event I'm needing. But I really don't understand how to call that from my actor.

Thought it would be cool if a symbol would show up when the player faces an object that he can interact with. Like an eye when the player can look at a picture or something and a hand when he can use something.
0

User is offline   Danukem 

  • Duke Plus Developer

#6

View PostBrOiler1985, on 17 October 2016 - 12:34 PM, said:

Thought it would be cool if a symbol would show up when the player faces an object that he can interact with. Like an eye when the player can look at a picture or something and a hand when he can use something.


For that you have to use a display event, such as EVENT_DISPLAYREST. What you are describing exists in some released mods, such as the AMC TC by JBlade.

What I do for features like this:

create a per-player variable (example: gamevar INTERACT 0 1)

put some code in a display event which will display a certain tile number if that variable is non-zero. Example:

onevent EVENT_DISPLAYREST

ifvarn INTERACT 0 
  rotatesprite 160 100 65536 0 HANDPIC 0 0 0 0 0 xdim ydim

endevent


You can test it by setting INTERACT in the console with setvar.

Now to make it actually work in game, you have actors or the player set that var to a non-zero value >0 when certain conditions are met. In the player actor code, you make the var count down to zero by decrementing it every tic if it is > 0. Thus, when the conditions are not met, the display will stop after a moment.
0

#7

And again, thank you very much! That was a lot easier as I thought. Works like a charm!
0

#8

Hello, it's me again.

I stumbled over another problem. I want to make an fx-actor that plays a sound and prints a quote when you touch it. When hitag is 1 the actor behaves like every other object I made (eye-symbol is displayed and you need to press use to interact).
But I want to make this thing dynamic. The quote that should be displayed is the actors lotag. But quote doesn't seem to work with gamevars. When I was looking around I found a function calld quotevar, but that doesn't seem to exist anymore. Is it deprecated / removed?

My code:
//SOUNDQUOTE
eventloadactor SOUNDQUOTE
cstat 32768
getactor[THISACTOR].hitag hitquo
getactor[THISACTOR].lotag lotquo
setactor[THISACTOR].hitag 0
setactor[THISACTOR].lotag 0
enda

useractor notenemy SOUNDQUOTE -1 IDLE
cstat 16
ifaction IDLE
{ 
	ifvare hitquo 1
	{
		ifp pfacing
		ifcansee
		ifpdistl 1024
		{
			ifvare takeuse 1
				setvar takeuse 0
			setvar lookat 1
			ifhitspace
			{
				stopsound DUKE_SEARCH
				stopsound DUKE_SEARCH2
				quote lotquo
				soundvar lotquo
				action BUSY
			}
		}
	}
	else
		ifpdistl 512
		{
			quote lotquo
			soundvar lotquo
			killit
		}
}
else ifaction BUSY  
{
    ifactioncount 60
    action IDLE
}
enda



Thanks!

This post has been edited by BrOiler1985: 28 October 2016 - 12:10 AM

0

#9

Got it! I don't think it's very elegant, but it works :D

//SOUNDQUOTE
eventloadactor SOUNDQUOTE
cstat 32768
getactor[THISACTOR].hitag hitquo
getactor[THISACTOR].lotag lotquo
setactor[THISACTOR].hitag 0
setactor[THISACTOR].lotag 0
enda

useractor notenemy SOUNDQUOTE -1 IDLE
cstat 32768
ifaction IDLE
{ 
	ifvare hitquo 1
	{
		ifp pfacing
		ifcansee
		ifpdistl 1024
		{
			ifvare takeuse 1
				setvar takeuse 0
			setvar lookat 1
			ifhitspace
			{
				redefinequote 2222 %d
				qsprintf 2222 lotquo
				stopsound DUKE_SEARCH
				stopsound DUKE_SEARCH2
				quote 2222
				soundvar lotquo
				action BUSY
			}
		}
	}
	else
		ifpdistl 512
		{
			redefinequote 2222 %d
			qsprintf 2222 lotquo
			quote 2222
			soundvar lotquo
			killit
		}
}
else ifaction BUSY  
{
    ifactioncount 60
    action IDLE
}

0

User is offline   Danukem 

  • Duke Plus Developer

#10

What you have there is fine, but you can make it a little easier on yourself by directly setting the fta and ftq members of the player struct. ftq is the quote number, and fta is the number of tics it will display.

For example, this code will make quote 100 display for 90 tics (3 seconds) if no quote is already displaying:


ife player[].fta 0
{
  setp[].ftq 100
  setp[].fta 90
}


EDIT: And of course a gamevar could be used to set fta or ftq

This post has been edited by Trooper Dan: 28 October 2016 - 03:33 PM

1

#11

Hey Guys!

Firstly @TrooperDan, Thank you! Will try that out!

Here's a little quick update on my project. Happy Halloween everyone. I have two questions:
Is there a way to have a reliable counter in the game? I currently use Darkus' incredebly cool flashlight code But I want that thing to run on batteries. Which would work, if I reliably could decrease my battery-gamevar.
I tried putting a counter-thing in the players actor-code, but since the code's switching between different actions, the counter doesn't always count down.

ifvare flashlighton 1
{
	ifactioncount 60
	{
		ifvarg battery 0
			subvar battery 2
		else
		{
			sound BUTTONCLICK
			setactor[isflashlight].hitag 0 // Light off
			setvar flashlighton 0
		}
	}
	resetactioncount
}


My second problem is the folowing. I made a doorlocker thing. Which run's on keys. There are different keys depending on their palete. That works fine.
Now I made some drawers, whicht the player can open. You can determine what's inside with setting the lotag and the palete of the sprite.
If I set the lotag to spawn one of my keys, it kinda works, but the actors' palette doesn't seem to be set. You can see that in the video. The key has pal 1 (silver key) but a key with pal 0 (golden key) is spawned.
Any ideas how to fix that?


//The DRAWER
eventloadactor DRAWER
getactor[THISACTOR].lotag lotact
getactor[THISACTOR].pal palact
setactor[THISACTOR].lotag 0
enda

useractor notenemy DRAWER -1 IDLE
ifvare lotact 0
	setvar lotact -1
ifaction IDLE
{ 
    ifp pfacing
	ifcansee
    ifpdistl 1024
    {
        {
			ifvare lookat 1
				setvar lookat 0
			setvar takeuse 1
            ifhitspace
            {
				stopsound DUKE_SEARCH
				stopsound DUKE_SEARCH2
				sound DROPEN
				setvar opendrawer 1
				ifvare DRSPAWN -1
				{
					espawnvar lotact
					setvarvar DRSPAWN RETURN
					setactor[DRSPAWN].pal palact	
					setvarvar DRAWCONTENT lotact
					setvarvar DRAWPAL palact
				}
                action BUSY
            }
        }
    }
}
else ifaction VIEW
{
    lockplayer 5
	ifhitspace
    {
		stopsound DUKE_SEARCH
		stopsound DUKE_SEARCH2
		setvar opendrawer 0					
		sound DRCLOSE
		setvar DRAWCONTENT -1
		setvar DRAWPAL -1
		action BUSY
    }
}
else ifaction BUSY
{
	ifactioncount 15
	{
		ifvare opendrawer 1
		{
			action VIEW
		}
		else
			action IDLE
	}
}
enda


I also borrowed XTHX2s footstep-code from the Hellduke-TC. Hope that's okay, XTHX2.

Thanks, guys!



Direct to youtube

Edit: A lot of the textures are just placeholders e.g. the drawer. The cheesy voiceactiong is a placeholder too.

This post has been edited by BrOiler1985: 31 October 2016 - 09:04 AM

2

User is online   Hendricks266 

  • Weaponized Autism

  #12

The code looks correct as far as setting the pal goes. I would temporarily add an "addlogvar palact" before the setactor[DRSPAWN].pal to make completely sure the right value is getting set. You can check it in the log or in the console.

I would make sure you have your tiles and pals defined correctly. Are you using an ART tile, or a hightile? If you have any def code for that tile or the tint of pal 1, please paste it here.
1

User is offline   Danukem 

  • Duke Plus Developer

#13

For the battery counter, you don't need to use action count. If you want the counter to take a long time to decrement, just start it at a really high number and then decrement it every tic.

For the spawning pal, make sure that palact is a per-actor gamevar (declare it as gamevar palact 0 2 )
2

#14

Thanks for the quick answers, you two.

Here's the def-code. It works when I put the keysprite in the map and set the pal.
texture 4013 {
   pal 0 { file "DATA/SPRITES/KEY.PNG" }
   pal 1 { file "DATA/SPRITES/KEY_SILVER.PNG" }
   pal 2 { file "DATA/SPRITES/KEY_BRONZE.PNG" }
   pal 3 { file "DATA/SPRITES/KEY_BLACK.PNG" }
}


Maybe the key-actor is the problem?
useractor notenemy KEY -1
ifp pfacing
ifcansee
ifpdistl 1024
{
	ifvare lookat 1
		setvar lookat 0
	setvar takeuse 1
    ifhitspace
    {
        stopsound DUKE_SEARCH
        stopsound DUKE_SEARCH2
        palfrom 16 0 64 0
		ifvare palact 1
		{
		    sound QUOTE1027
			quote 1027
			addvar gotkey_silver 1
		}
		else ifvare palact 2
		{
		    sound QUOTE1028
			quote 1028
			addvar gotkey_bronze 1
		}
		else ifvare palact 3
		{
		    sound QUOTE1029
			quote 1029
			addvar gotkey_black 1
		}
		else
		{
		    sound QUOTE1026
			quote 1026
			addvar gotkey 1
		}
        killit
    }
}
enda


I'll try decrementing with tics for the flashlight.

This post has been edited by BrOiler1985: 31 October 2016 - 10:48 AM

0

User is online   Hendricks266 

  • Weaponized Autism

  #15

The "palact" gamevar won't automatically propagate to an actor you spawn, unless you "setactorvar[DRSPAWN].palact palact", but there is no point when you can replace "ifvare palact" with "ifspritepal" within actor KEY.
1

#16

Hey!

Thanks again. The issue(s) have been resolved.
After thinking about it a little I figured that the palette-problem is caused by setactor[THISACTOR].pal palact not being in the actual actor code, but in the eventloadcator section.

For the flashlight i set a new counter in the EVENT_GAME-event. Hooray!
0

User is offline   Mark 

#17

Halloween 2017 is approaching. Are you still working on this project? I hope so.
0

User is offline   Mark 

#18

Halloween 2020 is approaching. :P Are you still working on this project? I hope so.
0

User is offline   Danukem 

  • Duke Plus Developer

#19

Broiler hasn't posted anything about this project in almost 4 years. He can ask to have the thread unlocked if he wants to continue it. Or just use a different thread.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked


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