Home   Help Search Login Register  

Author Topic: Problem with money script. HELP!  (Read 9101 times)

0 Members and 1 Guest are viewing this topic.

Offline tommi

  • Members
  • *
Problem with money script. HELP!
« on: 01 Sep 2006, 15:40:09 »
Hi all...

 I'm working on a Counter-Strike mod and I need help with a money script.  :banghead:
 
 This is abit hard to explain but this is what i want: if you kill a enemy you will get 5$ to your acount. I tried something like this: 

e1cash = e1cash +5;
e2cash = e2cash +5;
e3cash = e3cash +5;
e4cash = e4cash +5;

So, when a enemy was killed the script added 5$ to all east players. I want that the 5$ will be added only to the killer.  ???    How do I do this?

 I hope you understood  what I mean  :)

 You can e-mail me at:   sniper_ofp@hotmail.com
 


Offline rhysduk

  • Former Staff
  • ****
Re: Problem with money script. HELP!
« Reply #1 on: 01 Sep 2006, 16:18:30 »
You need a killed eventhandler i think.

Try this here There was something in the Ed Depot once but cant find it.

Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Problem with money script. HELP!
« Reply #2 on: 01 Sep 2006, 16:35:34 »
first of all, welcome to OFPEC!

rhys is correct, best bet would be a killed eventhandler added to enemy units. if you put it into the enemy unit's init box, it would look something like this:

Code: [Select]
this addeventhandler ["killed", {my_cash = my_cash + 5}]
where my_cash is a global variable for the player's cash.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #3 on: 01 Sep 2006, 18:54:44 »
And for your secondary question: how to add the cash only to the killer i'd recommend you
to use arrays with subarrays

Warning!!!!! - it's probably getting a little bit complicated now !!!!!

If you have an init.sqs put: cash_array = [] inside.


*** read what i added at the end of my post afterwards before going on ***

If not then put the code into your very first unit's init field, which you placed onto the map:

If the very first unit you placed onto the map is also included to the cash system, put the following code into it's
init field:

cash_array = [[this,0]

:note - the init fields of units use the 'first being placed / first being executed' system, because of this
you need to initialize the cash_array by the first unit's init field.

*** ----------------------------------------------------------------------------------------- ***

Now into each unit which should take part in the cash system put the following code into it's init field:

cash_array = cash_array + [[this,0]]


Now the eventhandler:

this addEventHandler ["killed",{"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 5; _x set [1,temp_cash]}" forEach cash_array}]

If this unit gets killed, it will determine which unit of cash_array is the killer and will add 5 to the second element of
the subarray where the killer unit is inside.


A unit's init field should look then like this:
cash_array = cash_array + [[this,0]]; this addEventHandler ["killed",{"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 5; _x set [1,temp_cash]}" forEach cash_array}]


OK, explanation:

Now you have an array: cash_array, which look like this in theory:

[[unit1,0],[unit2,0],[unit3,0]]

This array features 3 elements where each element again features 2 subelements: the unit itself and a number.
You can access an element of this cash_array by: cash_array select x

:note - x stands for a number from 0 to 2 (while 0 is the first element and 2 the last one).


If you want to find out what is the score of let's say unit 2 you need to store element 2 (cash_array select 1) into
a temporary array: temp_array = cash_array select 1

Now you can access the numeric value by: temp_array select 1

-----------------------------------------------------------------------------------------------------------------------------------------------

I hope you didn't get lost somewhere inbetween here.  :D

:edit - !!!!!!!! wait wait wait !!!!!!!!!

I just figured out that not always the first unit's init field, being placed on the map first
will become executed first.
East units go for West units.

This means the very first East unit being placed executes it's init field before any West unit does.
So if you have placed all West units before and later add East units, still the first init field to be
executed is the one of the first East unit you placed.

This further means that you need to initialize your cash_array by the first East unit you've placed.

~S~ CD
« Last Edit: 01 Sep 2006, 20:20:00 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #4 on: 02 Sep 2006, 11:56:57 »
 
 I added  "cash_array = []" to the init.sqs
 
 and for the players :

 cash_array = cash_array + [[this,0]]; this addEventHandler ["killed",{"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash =  temp_cash + 5; _x set [1,temp_cash]}" forEach cash_array}]

(for the first unit: cash_array = [[this,0] )
 
  but it looks like it dosen't work
 what did I do wrong                       :banghead:

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #5 on: 02 Sep 2006, 15:05:56 »
Well, since i yesterday figured out the curiosity that east units init fields get
executed before west units init fields i made another test aswell.

When initializing cash_array = [] by init.sqs the units init fields get executed first, so
they will be adding them to the array which doesn't exist at that time.

Take the line out of init.sqs.

btw - you mixed something up anyway:

you said in init.sqs: cash_array = []

and in first units init field you said: cash_array = [[this,0]]

You just need one of these two variants.

In your mission it happens now that way:

unit's init fields get executed and fill the array
afterwards the array gets cleared by init.sqs
so remove it from init.sqs and everything should be fine.

Also take care about what i added by editing my first post - east before west  ;)

Just another question: is it supposed to be for multiplayer or for singleplayer?

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #6 on: 02 Sep 2006, 18:19:03 »
 
 It's for multiplayer....
 
 4 players on west side and 4 on east side

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #7 on: 03 Sep 2006, 07:14:41 »
 I did as you said and now it executes the script...  :good:

 but there comes a error messege to the up left corner, it's very long so I cant see the beginning and the end  :blink:

 "if (_this select 1 == _x select 0) then l# l {temp_cash = (_x select 1); temp_cash = temp_cash + 40; _x set [1,temp_cash]}': Error select  T

That  T at the end is beginning of temp_cash... I think   :dunno:

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #8 on: 04 Sep 2006, 15:41:54 »
I suspect the single quotation mark at the and of your line: ' where there should be a " but
i'm not sure if this just appears like that from the error message.

Could you maybe copy/paste your code into here if this was not the reason?

Does the error come up when trying it alone or with more participants in a multiplayer session?

Also later (when the basics are working fine) we must work on something to make it 100% multiplayer able,
but it's too early by now.  ;)

:also in advance i'd like to ask you if all of the units taking part are playable and if there is a probability of any
of the units not appearing in the mission (AI off and unit not being selected in player selection screen)?

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #9 on: 04 Sep 2006, 16:05:36 »

  units init field :
 
cash_array = cash_array + [[this,0]];this addEventHandler [""killed"",{""if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 40; _x set [1,temp_cash]}"" forEach cash_array}];

 the init.sqs does not have : cash_array = []
 
 the first EAST unit has : cash_array = [[this,0]];this addEventHandler [""killed"",{""if (_this select 1 == _x select 0) then {temp_cash = (_x select 1); temp_cash = temp_cash + 40; _x set [1,temp_cash]}"" forEach cash_array}];

 error messege : 'if (_this select 1 == _x select 0) then l# l {temp_cash = (_x select 1); temp_cash = temp_cash + 40; _x set [1,temp_cash]}': Error select:  T
 
  (got a screenshot of that)

 The error comes on multiplayer and singleplayer

 I could try it without AI, but how I can execute the script then?

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #10 on: 04 Sep 2006, 16:36:33 »
 :scratch: - By just looking at it i cannot find anything (6 more hours an i get access to ofp).

Maybe in the meantime i find something by starring at it.  :blink:

One thing i noticed what you don't need in init fields is the ; at the end of a line.

You need that in description.ext files or in functions (while i'm not sure with functions on that).

Remove them, they tell the engine that another command will follow.

Also when testing it make sure that the unit with the: cash_array = [[this,0]] appears in the game at missionstart.

For another test create a trigger:

size: 0/0
activation: radio alpha / repeated
condition: this
onActivation: hint format ["%1",cash_array]

Then start the mission and hit radio-alpha.
You should see then the content of the array:

["East alpha black1",0],["East alpha black2",0]

Off course you will see other unitnames but it should look something like that.  ;)

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #11 on: 05 Sep 2006, 13:29:11 »
Well, i couldn't find anything wrong with the code.

Maybe you have some typo somewhere in there.

I've attachd a working example with the player, 3 west and 2 east units.

When you shoot one guy you get + 5

Everybody is setcaptive true to let them not react on eachother.

Radio trigger alpha shows the array repeatedly.

You will find the mission on desert island.

~S~ CD
« Last Edit: 20 Aug 2009, 20:50:37 by hoz »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #12 on: 05 Sep 2006, 15:18:34 »
 
 Sorry Chris... my mistke  :whistle:
 I added cash_array = [[this,0]] to the second east unit. that was the problem...
 now it works well

 thanks a lot   :)

  :thumbsup:
 
 now need to just make it MP able  8)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #13 on: 05 Sep 2006, 17:04:23 »
OK, for making it multiplayer compatible we have now to turn around the whole thing.

You need to name now eeach unit: (let's say; e1,e2,e3,.... for the east units and w1,w2,w3,... for the west units)

Then we must create the cash_array in init.sqs and not in init fields of units:

Code: [Select]
;init.sqs

cash_array = []
temp_cash = 0
temp_count = 0
cash_update = false

"if (alive _x) then {cash_array = cash_array + [_x,0,0]}" foreach [w1,w2,w3,w4,e1,e2,e3,e4]

_i = 0
_count = count cash_array

#loop

(cash_array select _i) set [3,_i]

_i = _i + 1
?(_i < _count): goto "loop"

Now into each unit's init field you only put:

this addEventHandler ["killed",{_this ecec {cash_update.sqs}}]

Then create a script: cash_update.sqs

Code: [Select]
;cash_update.sqs

@!cash_update
"if (_this select 1 == _x select 0) then {temp_cash = (_x select 1);temp_count = (_x select 2); temp_cash = temp_cash + 5}" forEach cash_array

cash_update = true
"publicVariable _x" forEach [cash_update,temp_count;cash_update]
exit

Then create a trigger:

size: 0/0
activation: none / repeatedly
condition: cash_update
onActivation: cash_array select temp_count set [3,temp_cash]; cash_update = false; publicVariable "cash_update"

This should do the job now.  :)

I've set this up at work without having ofp beside me, so forgive me if something is mixed up now.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #14 on: 05 Sep 2006, 19:24:04 »
OK, again a error messege:

at start of mission:  '(cash_array select _i) set [3,_i]-#[; error set: type number, expected array

when executed : 'cash_array select temp_count set [3,temp_cash]l#l; cash_update = false; publicVariable "cash_update"  ': Error set type object, expected array
 
I think to problem is in the init.sqs   :dunno:
 
(I  copy / paste the codes...)