[ZSCRIPT] Mikk's Dumb Questions
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!)
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
[ZSCRIPT] Mikk's Dumb Questions
Hi! I've encountered a slight problem with something I'm working on, I've noticed that upon death ZScript Variables defined on a player are reset upon respawn. Is there any way to solve this? Or do I have to revert to Global variables...
Say for example my player has one 1D array and one variable defined, these are read and manipulated by ACS' [wiki]GetUserVariable[/wiki] & [wiki]SetUserVariable[/wiki]. In this case, the player can rest at a certain points in a level (in a hub, I should add), the current levelnum and id of the rest point are stored in the player's lastbonfire array, however, these variables are cleared upon respawn which makes this system arguably useless...
Say for example my player has one 1D array and one variable defined, these are read and manipulated by ACS' [wiki]GetUserVariable[/wiki] & [wiki]SetUserVariable[/wiki]. In this case, the player can rest at a certain points in a level (in a hub, I should add), the current levelnum and id of the rest point are stored in the player's lastbonfire array, however, these variables are cleared upon respawn which makes this system arguably useless...
Last edited by Mikk- on Fri Dec 15, 2017 5:09 pm, edited 1 time in total.
-
- Posts: 1337
- Joined: Tue Jul 15, 2003 4:18 pm
Re: [ZSCRIPT] Variables reset upon respawn
Possibly dumb question: Is the player actually respawning (as you would in DM/Coop), or is the game restoring from the autosave that gets generated when you start a level?
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Variables reset upon respawn
The player is actually respawning, the maps have allowrespawn enabled in MAPINFO
-
- Lead GZDoom+Raze Developer
- Posts: 49182
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZSCRIPT] Variables reset upon respawn
The player which respawns is a completely new actor which will not get the values of the previous version transferred to it.
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Variables reset upon respawn
Ah, I was worried it was as such. Is there any workaround, or some such way to transfer the values to the newly spawned player actor?Graf Zahl wrote:The player which respawns is a completely new actor which will not get the values of the previous version transferred to it.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZSCRIPT] Variables reset upon respawn
Would storing the variables on an undepletable inventory inside the player work?
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Variables reset upon respawn
That sounds like it could work, but I don't really know how to store and access variables on an inventory item - ZScript is all so very new and confusing to me!
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZSCRIPT] Variables reset upon respawn
Try this.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Variables reset upon respawn
Brilliant! thanks Nash! Now I've hit another roadblock... How can I access these variables through an Event Handler? Specifically PlayerEntered, PlayerDied and PlayerRespawned. Event handlers are like black magic.
So far I have:
What I want this handler to do is:
So far I have:
Code: Select all
class Souls_Player : ClericPlayer
{
default
{
Player.StartItem "Souls_BonfireInfo";
}
}
class Souls_BonfireInfo : Inventory
{
int souls_lastbonfire[2];
int souls_returning;
Default
{
Inventory.MaxAmount 1;
+INVENTORY.UNDROPPABLE;
+INVENTORY.HUBPOWER;
+INVENTORY.UNTOSSABLE;
}
}
// Very basic and non-functional event handler
// l o l
class Souls_Handler : EventHandler
{
override void PlayerEntered(PlayerEvent e)
{
if(e.IsReturn)
{
}
}
override void PlayerDied(PlayerEvent e)
{
}
Override void PlayerRespawned(PlayerEvent e)
{
}
}
Code: Select all
1. Upon death, set player "Souls_Returning" to true
2. Upon Respawn, Teleport_NewMap to "Souls_LastBonfire[1]"
3. Upon Entry (& e.IsReturn) to clear the Souls_Returning value
4. Teleport the player to "Souls_LastBonfire[0]"
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZSCRIPT] Variables reset upon respawn
Hey sorry for the late reply. Here I show you how to access your variables from an Event Handler.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Variables reset upon respawn
Thank you so so much Nash! This will help me immensely! Regarding your challenge, I think I've come up with a neat solution (I think)
Code: Select all
class Souls_Player : ClericPlayer
{
default
{
Player.StartItem "Souls_PlayerInfo";
}
int GetSoulInfo(int variable)
{
let pVar = Souls_PlayerInfo(FindInventory("Souls_PlayerInfo"));
if (pVar)
{
switch(variable)
{
case LAST_BONFIRE_NUM:
return pVar.souls_lastbonfire[0];
case LAST_BONFIRE_MAP:
return pVar.souls_lastbonfire[1];
case PLAYER_RETURNING:
return pVar.souls_returning;
}
}
return 0;
}
void SetSoulInfo(int variable, int amount)
{
let pVar = Souls_PlayerInfo(FindInventory("Souls_PlayerInfo"));
if (pVar)
{
switch(variable)
{
case LAST_BONFIRE_NUM:
pVar.souls_lastbonfire[0] = amount;
break;
case LAST_BONFIRE_MAP:
pVar.souls_lastbonfire[1] = amount;
break;
case PLAYER_RETURNING:
pVar.souls_returning = amount;
break;
}
}
}
}
class Souls_PlayerInfo : Inventory
{
int souls_lastbonfire[2];
int souls_returning;
Default
{
Inventory.MaxAmount 1;
+INVENTORY.UNDROPPABLE;
+INVENTORY.HUBPOWER;
+INVENTORY.UNTOSSABLE;
}
}
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZSCRIPT] Variables reset upon respawn
Good job! Hope you have fun learning ZScript. It's not as scary as some people make it out to be. :D
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Mikk's Dumb Questions
Okay so I'm just gonna turn this thread into a (possibly) dumb questions thread about various ZScript features and other such stuff.
In light of this; is it possible to create a GLSL shader that looks similar to the Black Phantoms of Dark Souls?
In light of this; is it possible to create a GLSL shader that looks similar to the Black Phantoms of Dark Souls?
Spoiler:I don't know much about shaders, I do however know that they can do some cool shit like that FillSpectre shader - which is actually what gave me the idea.
-
- Posts: 5032
- Joined: Sun Nov 14, 2010 12:59 am
Re: [ZSCRIPT] Mikk's Dumb Questions
It's better to create a separate thread for each problem, instead of piling them up in a single thread. There's a reason, after all, for the editing forum organization that took place recently.Mikk- wrote:Okay so I'm just gonna turn this thread into a (possibly) dumb questions thread about various ZScript features and other such stuff.
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: [ZSCRIPT] Mikk's Dumb Questions
Oh, okay! I didn't want to clog up the editing forums, that's all.