Forum

> > CS2D > Scripts > Connect(?) two script in one?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Connect(?) two script in one?

17 replies
To the start Previous 1 Next To the start

old Connect(?) two script in one?

MixTape
User Off Offline

Quote
Hi, i have two scripts, first is shop with points and second is classes system. I dlike to make items that can be buy by one class, but i dont know, i must connect two scripts in one or what? Hooks? I think about it, but it doesnt work :P.

One script(classes):
Spoiler >


and shop
Spoiler >


And i think about it:

1
2
3
AddItem("Totem", 50, function(id)
     parse("equip "..id.." 54")
end)

to
(code in shop)
1
2
3
4
5
if (sample.classes.class[id]==1) then
AddItem("Totem", 50, function(id)
     parse("equip "..id.." 54")
end)
end
I know this code is stupid but im newbie

old Re: Connect(?) two script in one?

GeoB99
Moderator Off Offline

Quote
If you mean connecting by meaning merging two scripts in a one script is a bad idea and not good at all. Just keep two scripts as separated files as possible otherwise it'll just could lead to bugs.

old Re: Connect(?) two script in one?

Rainoth
Moderator Off Offline

Quote
You can do what you wrote.
It's not a bad thing, what user GeoB99 meant was that having separate files for your scripts is cleaner and more organized.
If you want to use functions from one script in the other, just load both scripts. As long as you're not CALLING the function before everything is load up, it's okay.
You can load scripts in sequential order in order to prevent this:
1
2
dofile("sys/lua/scriptWithFunctions.lua")
dofile("sys/lua/scriptWhereYouUseFunctions)
In other words, just load 'shop' first and 'classes' second.

old Re: Connect(?) two script in one?

GeoB99
Moderator Off Offline

Quote
What exactly you don't know?
user Rainoth already gave infos what to do. Keeping these files separate is a good thing and you don't have to be annoyed all the time by checking every hook, function, etc. and the code to fix every error, so your things are more structured. Saying that I dislike making items for class is another thing and this is up to you.

If you don't know where to put these two dofile lines, you must add these two lines in server.lua file. You can find that file in Counter-Strike 2D\sys\lua path.

P.S: Also don't use translators please. Translating a word is okay but still translators sucks sometimes because they might fail at translating a word correctly also translating a whole phrase is more worse and not allowed here.

old Re: Connect(?) two script in one?

THEMUD
User Off Offline

Quote
What Rainoth said is that you can run a secondary script with your first script. (You can run two in one, Nescafe)

And what he wrote is containing this code:
1
dofile("sys/lua/scriptname.lua")

Which this is the code that you use to run a secondary script in one script. As you do in server.lua.
So, if you want to run another script from only one script. You must put that code above in your script.

You can contact me at Skype if you want more help.

old Re: Connect(?) two script in one?

MixTape
User Off Offline

Quote
@user GeoB99: I was translated only words, not all sentences.
I know where i must put the code, i have this files in autorun, its okay? Like to @user Yashukiller: said me. But i can use a functions from one script in second when i have it in autorun?

If not, i dont understand what he write here:

dofile("sys/lua/scriptWithFunctions.lua") - shop and points
dofile("sys/lua/scriptWhereYouUseFunctions) - classes

or what? I


And can u help me with code? How to do ITEM for one class? It shows only one class and other can't see it.

I was thinking about this code from classes

1
if (sample.classes.class[id]==1) then
to add before item code

1
2
3
AddItem("Totem", 50, function(id)
     parse("equip "..id.." 54")
end)

Sorry if i dont understand simple actions.

old Re: Connect(?) two script in one?

Rainoth
Moderator Off Offline

Quote
Quote
But I can use a functions from one script in second when i have it in autorun?


Yes, if both scripts are successfully added, you can use functions from both scripts. That's what I was trying to say it. What I tried to say was that u cannot call a function if it's not added yet.
Like:
Script 1:
MyFunction()
Script 2:
function MyFunction()
     print"You will get an error if you call this function before loading the Script 2"
end

old Re: Connect(?) two script in one?

MixTape
User Off Offline

Quote
I think i understand it now, but im not sure So.. Classes must be first, becouse from classes i take functions.. And better is use dofile("sys/lua/scriptname.lua") than autorun becouse i can change whose script must be first!

And, i think u re make mistake.
1
print"You will get an error if you call this function before loading the Script 2"

not script 1?

old Re: Connect(?) two script in one?

Rainoth
Moderator Off Offline

Quote
Great. You understood it. It might not exactly apply to all scripts but it's a nice safety measure.

I said it correctly because Script 2 is where you get functions and Script 1 is where you use them

old Re: Connect(?) two script in one?

MixTape
User Off Offline

Quote
Okay so next step, help me with code, please

It's example item from the shop and how do it only for one class with X id?

1
2
3
AddItem("Totem", 50, function(id)
     parse("equip "..id.." 54")
end)

I know i must edit and use this line with tag player but i dont know how.
1
if (sample.classes.class[id]==9) then

Maybe start can be..?
1
2
3
if player (sample.classes.class[id]==9) then
--code for show item--
--code item--

In thread topic u have all scripts.

old Re: Connect(?) two script in one?

Rainoth
Moderator Off Offline

Quote
Lets see. Well one way would be to change the code to not work that way, another solution would be to disable this item for those that shouldn't be having it or not sell it.

// Meh it would be more logical to disable the button but it's a bit of work and I'm lazy so just change into this:

1
2
3
4
5
6
7
AddItem("Totem - Only for class 9", 50, function(id)
	if sample.classes.class[id] == 9 then
		parse("equip "..id.." 54")
	else
		msg2(id,"You're not class 9")
	end
end)

Didn't bother to look into it more but if other classes 'buy' that item and lose money, add a command to give 50 points after 'else'

old Re: Connect(?) two script in one?

MixTape
User Off Offline

Quote
Do u think can(i have enought skills) i make it with disable button? I think no becouse i trying with this

1
2
3
4
5
6
7
8
AddItem("(Totem", 50, function(id)
     if sample.classes.class[id] == 9 then
	      item.name = "Totem"
          parse("equip "..id.." 54")
     else
          msg2(id,"You're not class 9")
     end
end)

I was combine a lot with this function but i cant. I must try it later and i will write what i did.

Edit: And for now, when i dont have disable button i will change this code to: (add money after esle)
1
2
3
4
5
6
7
8
AddItem("Totem", 50, function(id)
     if sample.classes.class[id] == 9 then
          parse("equip "..id.." 54")
     else
          msg2(id,"You're not class 9")
		  SetPoints(id, playerData[id].points+50)
     end
end)
edited 1×, last 31.07.15 05:07:51 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview