Jump to content
Sign in to follow this  
Guest

weapon licensing script error.

Recommended Posts

Guest

unit buy gun:

this AddAction ["<t color="#F6FF00"">" +"buy gun", "buy.sqf];

unit buy weapon license:

this AddAction ["<t color="#F6FF00"">" +"buy weapon license", "weaponLicense.sqf];

buy.sqf script:

if (money1 < 2000) then

{

hint format ["you do not have enough money %1",player];

}

if(weaponLicense == 1) then {

money1 = money1 - 2000;

_this select 1 addWeapon "hgun_P07_F";

hint format ["you bought a gun %1!",name player];

}

else{

hint["Sorry, no license..."]

}

};

weaponLicense.sqf script:

weaponLicense = 1;

hint format ["You bought a weapon license!", name player]; //money is not being taken away from the player yet.

init.sqf script:

money1 = 1000000;

weaponLicense = 0; //this means that the player does not have a weapon license.

Edited by Guest

Share this post


Link to post
Share on other sites

So what does -showscripterrors say? I can only see you're missing a semicolon in the else hint, and you shouldn't use hint [array] but hint "string" instead, unless using hint format.

Share this post


Link to post
Share on other sites
Guest

it says something along the lines of error missing ; at line 5.

---------- Post added at 14:59 ---------- Previous post was at 14:24 ----------

it says something along the lines of error missing ; at line 5.

I changed the buy.sqf file:

if (money1 < 2000) then

{

hint "you do not have enough money %1";

if(weaponLicense == 1) then

{

money1 = money1 - 2000;

_this select 1 addWeapon "hgun_P07_F";

hint "you bought a gun %1!";

}

}

else

{

hint "Sorry, you don't have a license...";

}

there are no errors now but how would i save the license buying so the script works?

Share this post


Link to post
Share on other sites
Guest
hint "you bought a gun %1!";
}

hint "you bought a gun %1!";
};

I fixed that already, thanks anyways. :)

there are no errors now but how would i save the license buying so the script works?

Edited by Guest

Share this post


Link to post
Share on other sites

You mean permanently saving licenses to players even after they relog etc? That'd probably require an SQL database. Don't know anything about that though.

Share this post


Link to post
Share on other sites
Guest
You mean permanently saving licenses to players even after they relog etc? That'd probably require an SQL database. Don't know anything about that though.

Hmm, well. I'll take a look at it.

btw, Can't you just save the player's stats on the server itself?

Share this post


Link to post
Share on other sites

Hey did you figure this out already? Cause I found when working with money and stuff you should always use functions :D so what you should do is

Functionsmain.sqf

rat_fnc_gun_lic = {
if(weaponLicense == 1) then {hint "You already have this license!";};
if(money1 >= 2000) then {
	weaponLicense = 1;
	money1 = money1 - 2000;
};
if(money1 < 2000) then {hint "You don't have enought money";};
};

In same file just below as a seperate function

rat_fnc_gun_buy = {
if(money1 >= 2000) then {
	if(weaponLicense == 1) then {
		_this select 1 addWeapon "hgun_P07_F";
		money1 = money1 - 2000;
		hint format ["you bought a gun %1!",name player];
	};
};
if(money1 < 2000 then {hint "Sorry You don't have enough money!";};
if(weaponLicense == 0) then {hint "Sorry you didn't buy the licnese!";};
};

Functions\bankexec.sqf

_handler = [] execVM "Functions\bankvar.sqf";
waitUntil {scriptDone _handler};

Functions\bankvar.sqf

StartGeld = 100000;
money1   = StartGeld;
weaponLicense = 0;

init.sqf

call compile preProcessFileLineNumbers "Functions\Functionsmain.sqf";

Your two addActions should now look like

_menu = this addAction ["<t color=""#F6FF00"">" +"Buy License", {call rat_fnc_gun_lic ;}];

_menu = this addAction ["<t color=""#F6FF00"">" +"Buy Weapon", {call rat_fnc_gun_buy ;}];

Share this post


Link to post
Share on other sites
Guest
Hey did you figure this out already? Cause I found when working with money and stuff you should always use functions :D so what you should do is

Functionsmain.sqf

rat_fnc_gun_lic = {
if(weaponLicense == 1) then {hint "You already have this license!";};
if(money1 >= 2000) then {
	weaponLicense = 1;
	money1 = money1 - 2000;
};
if(money1 < 2000) then {hint "You don't have enought money";};
};

In same file just below as a seperate function

rat_fnc_gun_buy = {
if(money1 >= 2000) then {
	if(weaponLicense == 1) then {
		_this select 1 addWeapon "hgun_P07_F";
		money1 = money1 - 2000;
		hint format ["you bought a gun %1!",name player];
	};
};
if(money1 < 2000 then {hint "Sorry You don't have enough money!";};
if(weaponLicense == 0) then {hint "Sorry you didn't buy the licnese!";};
};

Functions\bankexec.sqf

_handler = [] execVM "Functions\bankvar.sqf";
waitUntil {scriptDone _handler};

Functions\bankvar.sqf

StartGeld = 100000;
money1   = StartGeld;
weaponLicense = 0;

init.sqf

call compile preProcessFileLineNumbers "Functions\Functionsmain.sqf";

Your two addActions should now look like

_menu = this addAction ["<t color=""#F6FF00"">" +"Buy License", {call rat_fnc_gun_lic ;}];

_menu = this addAction ["<t color=""#F6FF00"">" +"Buy Weapon", {call rat_fnc_gun_buy ;}];

Sir, You just mindfucked me.

haha, I'll try it out and report back. thanks a thousand. :)

Share this post


Link to post
Share on other sites
Sir, You just mindfucked me.

haha, I'll try it out and report back. thanks a thousand. :)

Haha if you need help man add me on my steam

Share this post


Link to post
Share on other sites
Functions\bankexec.sqf

_handler = [] execVM "Functions\bankvar.sqf";
waitUntil {scriptDone _handler};

Functions\bankvar.sqf

StartGeld = 100000;
money1   = StartGeld;
weaponLicense = 0;

You don't reference the use of bankexec.sqf. Those two files are also unnecessary, as you are spawning a thread, and a loop, only to initialize the variables. That initialization can be put at the top of your Functions.sqf before any functions, as its compiled on mission init. Or, if for some reason you do need to wait for whatever code you eventually add for initialization (ex, looking up a database), instead of creating two sqf files, just add one more functions to your main functions file that can spawn and wait for your DB calls or whatever. more you can get precompiled the better, it'll save you lag later

Share this post


Link to post
Share on other sites

This is actually the method that almost all life missions use? So I don't know what you are getting at, It works for him and me :D

Share this post


Link to post
Share on other sites
This is actually the method that almost all life missions use? So I don't know what you are getting at, It works for him and me :D

I was pointing out that theres no point in making it more complex and take more cycles to run than it needs. Why go point A-B-C-D when you only needed to go A-B? KISS.

Just because notoriously slow and poorly coded missions do it, doesn't mean you should stop thinking before you code and do the same :D

Just a thought. They say theres a thousand ways to skin a cat (that really is a screwed up saying isnt it...)

Edited by dr_strangepete

Share this post


Link to post
Share on other sites

Poorly Coded? TCG, and anarchy in tk? Not poorly coded I know you are talking about the bankexec, you need this for somreason I tried without it and it wouldn't work. JS Thansk for the input but a lot is needed man... I think this is a bit more complex than you think.

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  

×