Jump to content
Sign in to follow this  
cupcake_actual

Local Global variable issue

Recommended Posts

Ok, this is a "hum-dinger".

 

I have a mission that is Team vs Team Death Match. The mission is using R3F Logistics "creation factory". the sector control game mode is also being used. The goal, is to use the R3F 

creation factory to build up your "castle", which you must defend. For those familiar with R3F, the creation factory has a "credits" type deal that can be implemented. all the stuff in

the crate cost credits.  To win you must deplete the other teams "respawn tickets". you can do this by killing them off, or controling the majority of sectors, pretty straight forward stuff.

The problems that i am having are with Global/Local variables.

 

First things first. The crate used as the R3f Factory has this in the init:

 

nul = [bluebox, 100, west, "LIGHT"] execVM "R3F_LOG\USER_FUNCT\init_creation_factory.sqf"; this allowdamage false;

 

 bluebox being the name of the crate. the crate for opfor is named redbox, with the same code in its init "redbox" instead of "bluebox" of course.

 the problem with this is that when a player JIP it reruns this code apparently, adding more credits to the crate. I only need this to run once on mission start. clueless

 

 the next issue, awards given for capturing a sector. When a player captures the sector it should add 20 credits to their teams creation factory, and 2 respawn tickets.

 This seems to work fine but sometimes other players dont see the change in credits, some do. also, it seems to be doubling the numbers. instead of just 2 respawn tickets it gives 4 and 40 credits instead of just 20.

 I have a sector control module set up, this is all working fine. each sector is named sector1, sector2 and so on.. i have a trigger set up to execute the addition of credits and tickets as such

 

 Trigger:

 

 repeated

 condition: sector1 getVariable "owner" == west;

 activation: nul = []execVM "bluebox.sqf";  [west, 2] call BIS_fnc_respawnTickets;

 

 this works fine, but as i said it is doubling the numbers of respawn tickets and credits and credits do not seem to be globally shared. sometimes the player can go check the crate after taking a sector and see either 0 credits or no change.

 

 "bluebox.sqf"

 

private ["_credits"]; 

credits = bluebox getVariable "R3F_LOG_CF_credits"; 

credits = credits + 20;  bluebox setVariable ["R3F_LOG_CF_credits", credits, true];

 

the issue is that it seems all of this isn't happening server side, which it should be. I am lost on the global/local variable part of this. Does anyone see anything completely wrong with this? im sure its mostly syntax errors

 

Share this post


Link to post
Share on other sites

Try to call this whole code server side only.

For. eg on the box

Use

this allowdamage false;
 if (isServer) then {
nul = [bluebox, 100, west, "LIGHT"] execVM "R3F_LOG\USER_FUNCT\init_creation_factory.sqf";
};

The rest in the same way.

You get that double  because the init field of object is executed by server + more time every connected player.

allowdamage is local need to be executed for every one.

Share this post


Link to post
Share on other sites

Thanks for the response davidoss.

 

I've put this in the init.sqf

 

if (isServer) then {
nul = [bluebox, 100, west, "LIGHT"] execVM "R3F_LOG\USER_FUNCT\init_creation_factory.sqf";
};

 

but im only able to access the creation factory in the editor. putting it on the server, im not able to access it.

 

I changed my triggers for sector rewards to this:

 

repeatedly

condition: sector1 getVariable "owner" == west;

activation: nul = []execVM "bluebox.sqf";

 

in the bluebox.sqf i added the [west, 2] call BIS_fnc_respawnTickets;

This does work. it adds 2 respawn tickets and along with the other stuff, adds credits. though i haven't tested it on the server.

 

Its seems like when i move the init from the bluebox to the init.sqf, its not identifying the bluebox. like i said, in the editor, i can use the creation factory, but when i put it onthe server i dont get the option. 

Share this post


Link to post
Share on other sites

if i just put this in the init.sqf

 

nul = [bluebox, 50, west, "LIGHT"] execVM "R3F_LOG\...sqf"; 

 

it works.. kinda. in the editor and on the server.. kinda

 

After taking a sector, the "bluebox.sqf" is called as above

 

if (isServer) then {private ["_credits"]; _credits = bluebox getVariable "R3F_LOG_CF_credits"; _credits = _credits + 20; bluebox setVariable ["R3F_LOG CF_credits", _credits, true;

[west, 2] call BIS_fnc_respawnTickets;};

 

this works in the editor for adding credits to the box and 2 respawn tickets. However on the server, it only adds respawn tickets. then for that player they cannot access the creation factory.( well they can, but the credits have been removed, so they cant get anything from it)

switching to another player slot, you can access the creation factory, but no more credits have been added.

 

adding the "if (isServer) then {" to the line for the bluebox in the init.sqf does not allow any player to access the creation factory on the server, only in the editor. 

 

so confusing...

Share this post


Link to post
Share on other sites

..wait, should i create say a "blueboxinit.sqf" and put this code in it? then on the box's init put []execVM "blueboxinit.sqf";? 

 

i think the problem is the nul = part of the r3f box. the credit value is being updated when a sector is captured. doesn't nul mean its nothing? so its updating a value of nothing?  man this is crazy

Share this post


Link to post
Share on other sites

Well i just check the init_creation_factory.sqf and there are a condition

if (!isDedicated) then {};

that minds the whole system is not affecting server
That minds i was wrong about this.
Server cant execute that code. Clients only + HC
 
That push me to look for any documentation for that system.
And there are all explained.
 
http://team-r3f.org/madbull/logistics/EN_DOCUMENTATION.pdf
 
Although this is kinda easy.
 
Put the lines inside init field of bluebox:

nul = [bluebox, west, "LIGHT"] execVM "R3F_LOG\USER_FUNCT\init_creation_factory.sqf"; this allowdamage false;
if (isServer) then {
bluebox setVariable ["R3F_LOG_CF_credits", 100,true];
};

This should do the trick.

 

With the trigger the same trick

 

 Trigger:
 
 repeated
 condition:
sector1 getVariable "owner" == west
 activation:
 if (isServer) then {
private ["_credits"];
_credits = bluebox getVariable "R3F_LOG_CF_credits";
_credits = _credits + 20;
bluebox setVariable ["R3F_LOG_CF_credits", _credits,true];
[west, 2] call BIS_fnc_respawnTickets;
};

i assume you can go forward with that.

Share this post


Link to post
Share on other sites

thanks davidoss

 

I actually cut out the credit system for the moment, it was driving me mad. but I'm going to try this and see if it works, ill let you know

 

thanks again.

 

EDIT: im pretty sure this is working. thanks again.

Share this post


Link to post
Share on other sites

sry but i tried everything and not working for me.

i'm in a MP-dedicated-JIP-respawn situation, factory get initial credits, but after trigger add them, when i open factory, no credits are diplayed, and if i buy something script crash leaving me in "creation" whitout end.
any idea?
thanks !

EDIT **** SOLVED
 

Spoiler

i added in my mission INIT.sqf:
Garsenal setVariable ["R3F_LOG_CF_credits", 6666,true];

then trigger calls this script  :

if (isServer) then {

//private ["_credits"];
_Gcredits = Garsenal getVariable "R3F_LOG_CF_credits";
uiSleep 1;
_Gcredits = _Gcredits + 100000;
uiSleep 1;
Garsenal setVariable ["R3F_LOG_CF_credits", _Gcredits,true];

};


, really thanks to DAVIDOSS for pointing me in the right direction !
thank man !

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×