Making a variable that it changes for the player only and not for the script

Discuss all aspects related to modding Zandronum here.
Post Reply
Samuzero15tlh
Forum Regular
Posts: 258
Joined: Wed Sep 09, 2015 2:21 pm
Location: In home, sweet Home
Clan Tag: <skr>

Making a variable that it changes for the player only and not for the script

#1

Post by Samuzero15tlh » Wed Dec 02, 2015 11:08 pm

What if i want to make a variable that is changed by the player and it don't change the value in the script? I mean, In the script keeps with a same value but in the player, it changes.

Oh... Net Clientside :razz:
Last edited by Samuzero15tlh on Wed Dec 02, 2015 11:27 pm, edited 1 time in total.
Everyone wants happiness without pain, but you cant have a rainbow without a rain.

I'm working in the Shotgun Frenzy Plus mod in my free time.
Yes, I have a pet that helps me to build doom projects, the Pack-O-Daemon, ain't it cute?.

Spoiler: My Other zandro stuff! (Open)


Samuzero15tlh

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: Making a variable that it changes for the player only and not for the script

#2

Post by SwordGrunt » Thu Dec 03, 2015 6:55 am

You can make an array and have each player use one value (usually equal to the number of that player)

What are you trying to do? Why would you want a variable to be read differently by the player and the server? I can only imagine you want something that can be done with an array, but perhaps that's not what you're looking for.

In case you don't know, this is what it'd look like

Code: Select all

int myVar[8]; // supports up to 8 players. Raise it up to whatever amount you deem reasonable for your mod.
[...]

myVar[PlayerNumber()] = CheckInventory("Shell"); // stores the amount of shells the player has

[...]

Print(s:"You have \cd ",i:myVar[PlayerNumber()],s:" \cfshells left!"); // prints to the player activating the script the amount of shells he has

Edit: I wouldn't recommend using net clientside scripts that will affect ANYTHING other than the player activating them, OR that have any interaction at all with anything in a server script. This includes modifying variables set by a server script. Try arrays and see if it helps you out, otherwise I'm sure there's another way to get what you want done without the use of clientside scripts.
Last edited by SwordGrunt on Thu Dec 03, 2015 7:39 am, edited 1 time in total.

Samuzero15tlh
Forum Regular
Posts: 258
Joined: Wed Sep 09, 2015 2:21 pm
Location: In home, sweet Home
Clan Tag: <skr>

RE: Making a variable that it changes for the player only and not for the script

#3

Post by Samuzero15tlh » Thu Dec 03, 2015 1:43 pm

Net because it's executed with a bind puke (always), what im trying to do is a cyclic menu, but it needs a variable that it changes by the player only and not the server. Also im using the custom inventory.

I'd just noticed that Clientside sucks and its broken. :razz:
Last edited by Samuzero15tlh on Thu Dec 03, 2015 1:47 pm, edited 1 time in total.
Everyone wants happiness without pain, but you cant have a rainbow without a rain.

I'm working in the Shotgun Frenzy Plus mod in my free time.
Yes, I have a pet that helps me to build doom projects, the Pack-O-Daemon, ain't it cute?.

Spoiler: My Other zandro stuff! (Open)


Samuzero15tlh

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

RE: Making a variable that it changes for the player only and not for the script

#4

Post by ibm5155 » Thu Dec 03, 2015 2:09 pm

Clientside is doesn't sucks, it's just clientside, and it's not broken.
Think of it as a separated server that only the cliente can access the data.
So just take a look at this example:

Code: Select all

int i=0;

script 1 open{
	i = 30;
	print(d:i);
}

script 2 open clientside{
	delay(35);
	print(d:i);
}
the print inside script 1 will show 30, and the print inside script 2 will show zero, why? because when you set the value 30 to i, you're changing the server i value, so, the clientside i is not going to be changed, the only way the server can change it is calling a clientside script, like this one

Code: Select all


int i=0;

script 1 open{
	i = 30;
	acs_execute(3,0,30);
	print(d:i);
}

script 2 open clientside{
	delay(35);
	print(d:i);
}

script 3 (int a) clientside{
	i = a;
}

that way, both prints will show 30...
Clientside is only used for scripts that MUST not change the gameplay, just the graphics.

EDIT:
there's also a way to make a clientside script call a serverside script, so the cliente can pass a value to the serve (like the cliente pass 30 to server store in i, and then server prints 30), but, idk the specific acs call for this case

EDIT2: also, when you call an clientside script, all players will start the script, so you must check if the activator has the same tid as the consoleplayernumber, if not, call terminate(); (this way, only the player who called the script will execute it till the end)
Last edited by ibm5155 on Thu Dec 03, 2015 2:12 pm, edited 1 time in total.
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Samuzero15tlh
Forum Regular
Posts: 258
Joined: Wed Sep 09, 2015 2:21 pm
Location: In home, sweet Home
Clan Tag: <skr>

RE: Making a variable that it changes for the player only and not for the script

#5

Post by Samuzero15tlh » Thu Dec 03, 2015 3:33 pm

It's strange, but why it gives me a wrong answer?...

Code: Select all

#include "zcommon.acs"

int MenuOptions[6] = {0,1,2,3,4,5};

Int MenuPlayer[8];

Script 808 (Int Direction) Net
{
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
If(Direction == 1)
 {
 TakeInventory("MenuItem",1);
 HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
 }
 
Else If(Direction == 2)
 {
 GiveInventory("MenuItem",1);
 HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
 }
}

script 1 enter
{
    Thing_ChangeTID(0, 1000 + PlayerNumber());
}
The script 808 1 will lower the value and script 808 2 will raise it, but when you want to change the direction, it gives at the first execute the opposite operation and the second gives the correct operation. -.-
Everyone wants happiness without pain, but you cant have a rainbow without a rain.

I'm working in the Shotgun Frenzy Plus mod in my free time.
Yes, I have a pet that helps me to build doom projects, the Pack-O-Daemon, ain't it cute?.

Spoiler: My Other zandro stuff! (Open)


Samuzero15tlh

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

RE: Making a variable that it changes for the player only and not for the script

#6

Post by SwordGrunt » Thu Dec 03, 2015 4:57 pm

I don't know if I understand the way you're trying to do the menu, but the issue you're reporting sounds like a typo in script execution. I don't see how it'd execute the opposite operation if you're puking it with the correct argument.

Catastrophe
Retired Staff / Community Team Member
Posts: 2569
Joined: Sat Jun 02, 2012 2:44 am

RE: Making a variable that it changes for the player only and not for the script

#7

Post by Catastrophe » Thu Dec 03, 2015 9:56 pm

Samuzero15tlh wrote: It's strange, but why it gives me a wrong answer?...

Code: Select all

#include "zcommon.acs"

int MenuOptions[6] = {0,1,2,3,4,5};

Int MenuPlayer[8];

Script 808 (Int Direction) Net
{
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
If(Direction == 1)
 {
 TakeInventory("MenuItem",1);
 HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
 }
 
Else If(Direction == 2)
 {
 GiveInventory("MenuItem",1);
 HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
 }
}

script 1 enter
{
    Thing_ChangeTID(0, 1000 + PlayerNumber());
}
The script 808 1 will lower the value and script 808 2 will raise it, but when you want to change the direction, it gives at the first execute the opposite operation and the second gives the correct operation. -.-
Have you tried waiting an entire minute before puking 808? There might be a completely different script you haven't posted that's still setting up some values which might mess up the logic of this script.

Also when you say it gives you an "opposite operation" do you mean it gives you "MenuItem" when you do puke 808 1 the first time? Because that's impossible from the code I'm seeing.
Last edited by Catastrophe on Thu Dec 03, 2015 9:57 pm, edited 1 time in total.

User avatar
Vincent(PDP)
Forum Regular
Posts: 527
Joined: Thu Mar 14, 2013 7:35 pm
Location: Sweden
Clan: My DOOM site
Clan Tag: <MDS>
Contact:

RE: Making a variable that it changes for the player only and not for the script

#8

Post by Vincent(PDP) » Fri Dec 04, 2015 9:03 am

Try this:

Code: Select all

Script 808 (Int Direction) Net
{
If(Direction == 1)
{
TakeInventory("MenuItem",1);
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
}

Else If(Direction == 2)
{
GiveInventory("MenuItem",1);
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
HudMessage(d:MenuPlayer[playernumber()]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
}
}
You can't do this only once:

Code: Select all

MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
You need to check the player's inventory EVERYTIME you make a change to it (adding, taking, etc.), or else your MenuPlayer array won't update until you execute the script the next time.
The reason why it goes in the "opposite" direction is because you change the player's inventory, but you don't notify your MenuPlayer array about it until next time you execute the script.

This is what your script does at the moment:

Direction 1, first puke:
Set player menu position (CheckInventory)
Decrease inventory
View the previous position (since the array is not notified about the decrease)

Direction 2, second puke:
Set player menu position to the decreased value
Increase inventory
View the previous position (which is the decreased value due to no update)

Direction 2, third puke:
Set player menu position to the increased value
Increase once more
View the previous position (the previously increased value)

So try my script above, it should solve it. :)
Last edited by Vincent(PDP) on Fri Dec 04, 2015 9:11 am, edited 1 time in total.
//Visual Vincent ( Vincent (PDP) )
- My DOOM site Team

My projects:
Spoiler: (Open)
Doom Writer
Escape From The Laboratory - Done
Escape From The Laboratory Part 2
Parkskolan Zombie Horde Map (ZM10) - Done
In game Admin Commands for Zandronum.
Achievement Mod for Zandronum
Stats mod

Samuzero15tlh
Forum Regular
Posts: 258
Joined: Wed Sep 09, 2015 2:21 pm
Location: In home, sweet Home
Clan Tag: <skr>

RE: Making a variable that it changes for the player only and not for the script

#9

Post by Samuzero15tlh » Fri Dec 04, 2015 12:49 pm

Im taking off my hat in front of you!

Code: Select all

Str MenuOptions[6] = {"A","B","C","D","E","F"};

Int MenuPlayer[8];

Script 808 (Int Direction) Net
{
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
If(Direction == 1)
{
TakeInventory("MenuItem",1);
If(MenuPlayer[PlayerNumber()] < 1) Giveinventory("MenuItem",5);
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
HudMessage(s:MenuOptions[MenuPlayer[playernumber()]]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
}

Else If(Direction == 2)
{
GiveInventory("MenuItem",1);
If(MenuPlayer[PlayerNumber()] > 5) Takeinventory("MenuItem",6);
MenuPlayer[playernumber()] = CheckActorInventory(1000 + PlayerNumber(),"MenuItem");
HudMessage(s:MenuOptions[MenuPlayer[playernumber()]]; HUDMSG_FADEOUT, 1,0,0.5,0.65,3.0);
}
}

script 1 enter
{
Thing_ChangeTID(0, 1000 + PlayerNumber());
}
That worked so good! Thanks everyone!
PD:I put the code just for educational pruposes.
Everyone wants happiness without pain, but you cant have a rainbow without a rain.

I'm working in the Shotgun Frenzy Plus mod in my free time.
Yes, I have a pet that helps me to build doom projects, the Pack-O-Daemon, ain't it cute?.

Spoiler: My Other zandro stuff! (Open)


Samuzero15tlh

Post Reply