"How do I ZScript?"
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Re: "How do I ZScript?"
Is there any function to scan the player's view for targets and then return valid targets in an array? Trying to create a weapon that targets several enemies at once. Or is there a better/smarter way to go about this than an array?
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: "How do I ZScript?"
So I ended up writing this:Is there a way to do this without keeping all those inputs twice, but also not requiring me to enter all 7 values each and every time?
Code: Select all
...
void drawwepcounter(
int input,
int posx,int posy,
string zero="",string one="",string two="",string three="",
string four="",string five="",string six=""
){
string types[7]={ //let's pretend this works for brevity's sake
zero,one,two,three,four,five,six
};
...
if(result!="")drawimage(result,...
Last edited by Matt on Sat Jul 08, 2017 1:40 am, edited 1 time in total.
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: "How do I ZScript?"
What are you trying to achieve from that?
- Major Cooke
- Posts: 8212
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
- Contact:
Re: "How do I ZScript?"
Vaecrius: Make a struct and have the struct pass in as the parameter of your function.
Example:
Or you could have it all be just 'in out' in your code but that might get a little messy.
Example:
Code: Select all
Struct D4ManualLootParameters
{
private bool initialized;
Class<Actor> mo;
int UpgradeDropChance, UpgradeDropAlways;
int CrateDropChance, CrateDropAmount, CrateDropAlways;
int CashChainsawPinata, CashAmount;
void Init(Class<Actor> th = null, int upchance = -1, int updrop = 0, int cdchance = 0, int cdamt = 0, int cddrop = 0, int ccp = 0, int ca = 0)
{
mo = th;
UpgradeDropChance = upchance;
UpgradeDropAlways = updrop;
CrateDropChance = cdchance;
CrateDropAmount = cdamt;
CrateDropAlways = cddrop;
CashChainsawPinata = ccp;
CashAmount = ca;
initialized = true;
}
bool CheckInit()
{
return initialized;
}
}
// Now have a function accept it somewhere on an actor.
// You only need 'in out' if you intend on modifying it directly with the function. 'in' is required for passing structs last I tried.
void Add(in out D4ManualLootParameters Loot)
{
//...
}
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: "How do I ZScript?"
Thanks, MC, though it looks like it'll necessarily be a few more steps than what I've got.
I'm trying to set up a function that reads an integer and displays a different sprite depending on the value. It's mostly for weapon fire settings so I almost never have more than 3 or 4 (including "not applicable" so practically only 3).
I'm trying to set up a function that reads an integer and displays a different sprite depending on the value. It's mostly for weapon fire settings so I almost never have more than 3 or 4 (including "not applicable" so practically only 3).
- zrrion the insect
- Posts: 2432
- Joined: Thu Jun 25, 2009 1:58 pm
- Location: Time Station 1: Moon of Glendale
Re: "How do I ZScript?"
I am attempting to check the inventory of every player but I am getting the error "Return type mismatch." What could be causing that?
Code: Select all
for (int i = AAPTR_PLAYER1; i < AAPTR_PLAYER8; i << 1)
{
if (CountInv("clip", i) >= 3)
{
//thing
break;
}
else
{
//other thing
}
}
Re: "How do I ZScript?"
We'll need to see the entire function to determine that, since return type mismatch errors can only really be debugged when the return type is known.
- zrrion the insect
- Posts: 2432
- Joined: Thu Jun 25, 2009 1:58 pm
- Location: Time Station 1: Moon of Glendale
Re: "How do I ZScript?"
It is returning names, I forgot to return a name outside of any for/if and now that I've put that there it is working correctly.
Code: Select all
override name myname()
{
for (int i = AAPTR_PLAYER1; i < AAPTR_PLAYER8; i << 1)
{
if (CountInv("clip", i) >= 3)
{
return 'name';
break;
}
else
{
return 'othername';
}
}
return 'finalname';//I forgot to include this one, forgetting this breaks it
}
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: "How do I ZScript?"
How do you read a user cvar from inside a statusbar (or anything with a ui scope)?
Re: "How do I ZScript?"
Code: Select all
class MyHUD : BaseStatusBar
{
override void NewGame()
{
if (CPlayer)
{
AttachToPlayer(CPlayer);
}
}
void DrawSomething(void)
{
if (CPlayer && CPlayer.mo)
{
// check a CVar
CVar myCVar = CVar.GetCVar("cl_mycvar", CPlayer);
if (myCVar)
{
// do stuff
}
}
}
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: "How do I ZScript?"
Thanks, I'll give it a try.
EDIT: Doesn't work. Always returns true if found. Is there any way to get the actual value?
Is there a way to rotate an image in a status bar (ideally arbitrarily but 90-degrees would be helpful too)?
EDIT: Doesn't work. Always returns true if found. Is there any way to get the actual value?
Is there a way to rotate an image in a status bar (ideally arbitrarily but 90-degrees would be helpful too)?
- Rip and Tear
- Posts: 187
- Joined: Tue May 02, 2017 3:54 pm
Re: "How do I ZScript?"
Is it possible to create a custom action function that is available to all actors?
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: "How do I ZScript?"
Mark the function as static and pass the actor to it as a parameter. Example:
Code: Select all
class Blah : Actor
{
static int GetBlah (Actor mobj)
{
return mobj != null ? mobj.health + Random(1, 10) : 0;
}
}
class DoomImp2 : DoomImp
{
override void PostBeginPlay ()
{
Super.PostBeginPlay();
int blah = Blah.GetBlah(self);
Console.Printf("%d", blah);
}
}
- Major Cooke
- Posts: 8212
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
- Contact:
Re: "How do I ZScript?"
Inheriting from actor isn't necessary, I don't think. You will need the play keyword though.
Alternatively a struct can be used.
Alternatively a struct can be used.
- Matt
- Posts: 9696
- Joined: Sun Jan 04, 2004 5:37 pm
- Preferred Pronouns: They/Them
- Operating System Version (Optional): Debian Bullseye
- Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
- Contact:
Re: "How do I ZScript?"
1. How do I set up an inventory item that does not inherit from Weapon or Ammo (or a key) so that it would be given with ID(K)FA?
2. Is there a way to override or somehow get around an Ammo item's get-parent function so that you can have something like:
MyAmmo0:Ammo
MyAmmo1:MyAmmo0
MyAmmo2:MyAmmo0
in which MyAmmo1 and MyAmmo2 are distinct items?
2. Is there a way to override or somehow get around an Ammo item's get-parent function so that you can have something like:
MyAmmo0:Ammo
MyAmmo1:MyAmmo0
MyAmmo2:MyAmmo0
in which MyAmmo1 and MyAmmo2 are distinct items?