Forum

> > CS2D > Scripts > A variable, bound to a player
Forums overviewCS2D overview Scripts overviewLog in to reply

English A variable, bound to a player

15 replies
To the start Previous 1 Next To the start

old A variable, bound to a player

LMB_10000
User Off Offline

Quote
Hello guys!
I want to make a variable, that will belong to a player. Not a global variable.

I have standart classes lua-script. And I want to make button on the map, that can be usable only by 1 class (Other classes can't use it).

I've tried to put something like this
<...>
if (sample.classes.class[id]==6) then
varname=1
<...>


But it's not local variable and when someone changes class, nobody can use button.

So, how can make a local variable and what should I put in trigger_if?

old Re: A variable, bound to a player

ohaz
User Off Offline

Quote
If you want player-specific variables, the usual way to go is to just create an array with a size of 32 and use the id to access it at the correct position.

old Re: A variable, bound to a player

LMB_10000
User Off Offline

Quote
Googled... Found an article... Used it... Made next:

<...>
array={}
for m = 0, 1 do
	array[m]=0
end
<...>
if (sample.classes.class[id]==2) then
array[m]=0
end
if (sample.classes.class[id]==3) then
array[m]=1
end
<...>


And now I have "table index is nil"

Just tell me what should I do to make this varable. I know NOTHING about arrays. I don't know, how to use it.
edited 2×, last 07.11.14 12:06:25 pm

old Re: A variable, bound to a player

LMB_10000
User Off Offline

Quote
I have 6 classes in my script.

I have some buttons on my map.

I want next:
Only class №6 can use them.

What should I put in lua and what should I put in trigger_if?

old Re: A variable, bound to a player

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
can = {}
addhook("join","CAN_HE_PRESS_BUTTONS")
function CAN_HE_PRESS_BUTTONS(id)
	can[id] = "No"
end

-- inside your class selection
if (sample.classes.class[id]==2) then
	can[id] = "Yes"
end

-- inside button use hook
if can[id] == "Yes" then
	msg"Yay, someone can press buttons"
end

old Re: A variable, bound to a player

Joni And Friends
User Off Offline

Quote
did you mean, you want only class==6 can using the button? so this the code..

1
2
3
4
5
6
7
8
9
10
11
12
btnpos={
           {x,y}
}

addhook("usebutton","_ub")
function _ub(id,x,y)
           for g=1,#btnpos do
               if (sample.classes.class[id]==6) and x==btnpos[g][1] and y==btnpos[g][2] then
                   --- your code here
                end
        end
end
edited 2×, last 08.11.14 01:36:51 pm

old Re: A variable, bound to a player

LMB_10000
User Off Offline

Quote
Joni, there isn't a code inside a button. I just have to be 'pressable' for class №6. Other classes just can't press it.

It's like a button that can switch on/off the light. And only class №6 can press it.

old Re: A variable, bound to a player

Joni And Friends
User Off Offline

Quote
Just adding trigger cmd on that script, change
1
--- your code here
With this..
1
parse("trigger <name of the trigger>")
You can manipulating that with code you want

old Re: A variable, bound to a player

Rainoth
Moderator Off Offline

Quote
1
for g=1,#btnpos then
Quote
"'do' expected near 'then'" in this line...

1
for g=1,#btnpos do

Doesn't require a genius to figure it out.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview