Home   Help Search Login Register  

Author Topic: Problem with money script. HELP!  (Read 8017 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...)

 

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #15 on: 05 Sep 2006, 19:34:11 »
I see, i made a mistake when creating the array and it's subarrays;


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

in init.sqs should be changed into:

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

~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 #16 on: 05 Sep 2006, 20:47:28 »
I just noticed another mistake i made:

The onActivation line of the trigger:

Code: [Select]
cash_array select temp_count set [3,temp_cash]; cash_update = false; publicVariable "cash_update"

should be changed into:

Code: [Select]
cash_array select temp_count set [2,temp_cash]; cash_update = false; publicVariable "cash_update"

Look: cash_array looks now like this:

[[unit1,cash,0],[uni2,cash,1],[unit3,cash,2]]

Now my mistake was i did change the counter (3rd element of the subarray).
But i should change the cash (second element of the subarray).

~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 #17 on: 06 Sep 2006, 17:32:22 »
 I again copy / paste the codes...

 when script was executed there came a error :  'cash_update]l#l': error missing (     :blink:

 (again got a screenshot)

 P.S   you said:

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

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

is that  ecec supposed be exec   :scratch:
« Last Edit: 07 Sep 2006, 18:26:25 by tommi »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #18 on: 06 Sep 2006, 18:37:18 »
Yes it's supposed to be exec  :)

~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 Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Problem with money script. HELP!
« Reply #19 on: 07 Sep 2006, 18:08:05 »
Not 100% sure but the following line might be in error:

"publicVariable _x" forEach [cash_update,temp_count;cash_update]

I would suspect the last entry in the array, the emboldened part, try removing it.

I think it might be superfluous, however MP stuff is not my thing.

If the second instance of cash_update is correct then it might just need the semi-colon changed to a comma.


Planck
I know a little about a lot, and a lot about a little.

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #20 on: 07 Sep 2006, 18:19:24 »
Quote
Not 100% sure but the following line might be in error:

"publicVariable _x" forEach [cash_update,temp_count;cash_update]

I would suspect the last entry in the array, the emboldened part, try removing it.

 that one diden't work...

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Problem with money script. HELP!
« Reply #21 on: 07 Sep 2006, 18:27:33 »
Please be more precise, what did you try and what happened.

I meant for you to change:

"publicVariable _x" forEach [cash_update,temp_count;cash_update]

to

"publicVariable _x" forEach [cash_update,temp_count]

If that is what you did and it didn't work......what error message did you get after?


Planck
I know a little about a lot, and a lot about a little.

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #22 on: 07 Sep 2006, 18:32:43 »


 I changed 

"publicVariable _x" forEach [cash_update,temp_count;cash_update]

to

"publicVariable _x" forEach [cash_update,temp_count]

and got a error messege :
 
 'publicVariable _xl#l': Error publicVariable : type Bool, expected String


Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Problem with money script. HELP!
« Reply #23 on: 07 Sep 2006, 18:37:51 »
I would wait and till CD comes back on the site for a definitive answer here.....as I said MP stuff is not really my thing.

In the meantime you could try instead:

publicVariable "_x" forEach [cash_update,temp_count]

 :dunno:


Planck
I know a little about a lot, and a lot about a little.

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #24 on: 07 Sep 2006, 18:43:37 »
 I tried  publicVariable "_x" forEach [cash_update,temp_count]...
 it di not work

 I understand MP stuff is not really your thing....

 thanks anyway  ;)

 I'll try different variations of   publicVariable "_x" forEach [cash_update,temp_count]   :D

 

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #25 on: 07 Sep 2006, 19:39:17 »
OK, i found the buggers in the publicVariable statement;

I sent twice the variable: cash_update
and i forgot: temp_cash instead.

"publicVariable _x" forEach ["temp_cash","temp_count","cash_update"]

There where the quotation marks missing.
PublicVariable "varname"
It's a string and i did just pv the pure variable name.

~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 #26 on: 08 Sep 2006, 13:34:37 »
 OK now there dosen't come 'cash_update]l#l': error missing ( any more... thats good

 when I killed the first enemy the script was fine, but when I killed the second enemy unit there came a error messege:

'cash_array select temp_count setl#l [2,temp_cash]; cash_update = false; publicVariable "cash_array": Error Zero divisor

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #27 on: 08 Sep 2006, 14:23:49 »
 :scratch: i did nowhere say that you should publicVariable "cash_array", or did i?

You've put that by yourself me guess.

PublicVariable "cash_update"

But thinking about it, this trigger is running global, so you can leave the publicVariable "cash_update"
out of it also. But you must let remain the command: cash_update = false.

Either this version:

Code: [Select]
cash_array select temp_count set [2,temp_cash]; cash_update = false; publicVariable "cash_update"
or this one:

Code: [Select]
cash_array select temp_count set [2,temp_cash]; cash_update = false
:edit - well for better overview i'll make a sumarry of what we have now:

init.sqs
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"

Init field of each unit:
Code: [Select]
this addEventHandler ["killed",{_this exec {cash_update.sqs}}]

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 + 40}" forEach cash_array

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

Trigger:
Code: [Select]
size: 0/0
activation: none / repeatedly
condition: cash_update
onActivation: cash_array select temp_count set [2,temp_cash]; cash_update = false

OK, i hope i sorted all errors out now.

~S~ CD
« Last Edit: 08 Sep 2006, 14:49:51 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 #28 on: 08 Sep 2006, 15:12:56 »
I dont know WTF is wrong with the Trigger...     :blink:

 I have onActivation: cash_array select temp_count set [2,temp_cash]; cash_update = false

 still getting a error messege: 'cash_array select temp_count setl#l [2,temp_cash]; cash_update = false : Error Zero divisor 

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #29 on: 08 Sep 2006, 16:00:08 »
 :scratch: I can't try it out but maybe it doesn't work to use the set command on a subarray in that way.

OK try this workaround:

Code: [Select]
temp_array = cash_array select temp_count; temp_array set [2,temp_cash]; cash_array set [temp_count,temp_array]; cash_update = false
maybe this helps  :)

~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 #30 on: 08 Sep 2006, 16:34:28 »
still the same error: ... : Error Zero divisor

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #31 on: 08 Sep 2006, 17:07:28 »
OK, then i need to have a look into it when i'm back home.

Meanwhile you could try to debug;

make that radio-alpha trigger, which i suggested a few posts
ago and show me, what is displayed:

Code: [Select]
Trigger:
activation: radio alpha / repeated
condition: this
onActivation: hint format ["%1\n\n%2\n\n%3\n\n%4",cash_array,temp_cash,temp_count,temp_array]

Maybe you can arrange posting a screenshot or attach one to your post.

~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 #32 on: 08 Sep 2006, 17:57:08 »
 So, here are the screen shots...  The resolution of the pic is a bit bad, but you can still see it
« Last Edit: 19 Aug 2009, 21:56:20 by Mandoble »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #33 on: 08 Sep 2006, 18:41:08 »
OK, from what i can see in the screens, the subarrays of cash_array consist of 4 elements instead of
3 (how it's supposed to be). I need to make further investigations in that when back home (5 to 6 hours).

There is probably some detail i've overseen or you have mixed up something - i will find out tonight.  ;)

If it's not a problem, could you upload the scripts: cash_update and init.sqs, so that i can try it with
your stuff instead of writing or copy/pasting it myself?
That way we can ensure that their aren't differences what we are talking about and i have one more
error source available for debugging.  :)

~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 #34 on: 08 Sep 2006, 18:50:18 »
Here thay come: init.sqs and cash_update.sqs
I have about 70 scripts on the mission directory so tell me if send the wrong scripts
(mostly buy weapons scripts)

theres 4 players on west and 4 on east  (w1 w2 w3 w4  e1 e2 e3 e4)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #35 on: 08 Sep 2006, 19:30:19 »
Yep, it seems i found the error;

The array SET command i've been using wrong -  :whistle:

In init.sqs replace the line:

Code: [Select]
(cash_array select _i) set [3,_i]
with:

Code: [Select]
(cash_array select _i) set [2,_i]
And in the trigger:

replace the line in onActivation field:

Code: [Select]
cash_array select temp_count set [2,temp_cash]; cash_update = false

with that line:

Code: [Select]
cash_array select temp_count set [1,temp_cash]; cash_update = false

I hope it works now.

btw - i've seen in your init.sqs another mistake:

you publicVariable something and in next line you say it is 0
It should be the other way around - first assign value to variable and second broadcast
it to network.
But you don't need to publicVariable anything in init.sqs since the script is being
executed global.
Only in case you want to create random numbers (server side only) and then broadcast
them to clients.

~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 #36 on: 09 Sep 2006, 08:45:49 »
 If you mean the 2 lines in the init.sqs :

publicvariable "playerse"
playerse = 0

publicvariable "playersw"
playersw = 0


they are supposed to be 0
its a counter how many units have been killed

Offline tommi

  • Members
  • *
Re: Problem with money script. HELP!
« Reply #37 on: 09 Sep 2006, 08:51:50 »
I insert the codes and now it works well before respawn... after I die and then respawn it dosen't work

 the good thing is no: error messeges
then, I'm not sure does it added the cash to the palyers account. If  w2 killes e3 it should add the cash to w2cash

w1cash
w2cash
w3cash
w4cash                                          :confused:

e1cash
e2cash
e3cash
e4cash

are the names of the accounts. own account for every player   :2c:
 


Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #38 on: 09 Sep 2006, 11:00:06 »
I've been sitting more than 4 hours on that but no end in sight.

Like you said, to make it work once without error messages it wasn't
that hard (copying the latest codes from here did the job).

But problem is that the array is loosing relation to the unit.


I added a second trigger like the cash_update but for man_update
and put the victim back into the right position of the array but
it idn't work yet: it always ends up with: c0o noid blablaVojak2

I've tried to implement a respawn script but with not success yet.

Look problem is that you can say:
Code: [Select]
!alive unit as condition and it works
but
Code: [Select]
alive unit will not become true after the unit got killed.
I forgot on that totally and since i yesterday first time tried it ingame (the multiplayer
version) i didn't notice it.

OK, the problem with alive/not alive unit i got solved by using the call format command
in combination with the editor given names (like w1) as strings.
I also added a fourth element to the subarrays - each unit has now [unitname,cash,counter,"editorname"]
but to that later, when i solved the last part.

The array still remains with the: blabla#noid Vojak2 instead of the unit - but i'm on it.  ;)


about the scores: forget about w1cash etc.
You got an array, which consists for a subarray for each unit. This subarray features the unit, the cash,
and the position in the array (counter).

You could now add a custom action to each unit to check score and use the same way like
in cash_update.sqs to determine the cash of the unit which is executing the script.
An addAction script is running locally on the pc where you execute it btw.

Or you can for example globally display the score of everybody - the cash is in every case in
subarray select 2.

~S~ CD
« Last Edit: 09 Sep 2006, 12:22:03 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 Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #39 on: 09 Sep 2006, 13:28:40 »
Well, what shall i say?  :scratch:

I've got it.  :)

OK, due to some circumstances (ofp engine - lol) i had to make some
changes but i will post you everything again including an explanation
what you're doing where.

Step 1:

Into each unit's init field put this:

Code: [Select]
"w1" exec "killed_alive.sqs"; this addEventHandler ["killed",{_this exec {cash_update.sqs}}]
this is the init field of the unit being named: w1
the "w1" you must change accordingly to their unit's editor names



Step 2:

Init.sqs

Code: [Select]
cash_array = []
temp_cash = 0
temp_count = 0
temp_counta = 0
cash_update = false
man_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 [2,_i]

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

cash_start = true


In init.sqs you create cash_array and for each unit which is alive of given units [w1,w2,etc.] a subarray = [unit,0,0]
Then an loop with an increasing number will make the third element of the subarrays into a reference number for
later use of the subarrays.
Also at the begin of init.sqs all necessary variables will be initialized.



Step 3:

Create two triggers:

Trigger 1:

Code: [Select]
size: 0/0 - repeatedly
condition: cash_update
onActivation: cash_array select temp_count set [1,temp_cash]; cash_update = false

Trigger 2:

Code: [Select]
size: 0/0 - repeatedly
condition: man_update
onActivation: cash_array select temp_counta set [0,temp_unit]; man_update = false

Trigger 1 instantly updates the score for the unit which killed another unit.
It's condition cash_update becomes true by the script cash_update.sqs and
once the trigger has done it's work, it sets cash_update back to false.
Trigger 2 works same way as trigger 1 with the difference that this trigger
puts the respawned unit back into it's subarray position in cash_array.



Step 4:

cash_update.sqs

Code: [Select]
@!cash_update

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

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

This script is executed by the eventhandler "killed" and it gets automatically passed
parameters: _this select 0 = the victim and _this select 1 = the killer
The script assigns the actual cash of the killer to the variable: temp_cash and then adds
40 to it. Also it assigns the counter to the variable: temp_count.
Then cash_update becomes true and the three variables get broadcast to everybody. -> trigger 1
At the beginning of the script is a condition: @!cash_update - this condition avoids
that two units who died in nearly same time, are mixing up the global variables



Step 5:

killed_alive.sqs

Code: [Select]
_name = _this
_man = call format ["%1",_name]
_temp_counta = 0

@cash_start

"if (_man == _x select 0) then {_temp_counta = _x select 2}" forEach cash_array

#loop


@(call format ["!alive %1",_name])

@(call format ["alive %1",_name])

call format ["%1 addEventHandler [{killed},{_this exec {cash_update.sqs}}]",_name]

@!man_update

temp_counta = _temp_counta
temp_unit = call format ["%1",_name]

man_update = true
"publicVariable _x" forEach ["temp_counta","temp_unit","man_update"]

goto "loop"


At the beginning of this script the editor name (e.g: w1) will be copied to _name
and the unit itself to _man (this is used to keep the variables local to the
script). Also a local _temp_counta for the script only is created to make a
reference for the unit's subarray position in cash_array.
Then the script waits for the condition cash_start, which will be made true
in init.sqs after initializing a working cash_array.

In the loop the script checks for the editor-name of the unit, wether it's alive or not.
If the unit is not alive, the script will wait until it has respawned.
Once respawned the unit and the reference counter will be copied into temp_unit
and temp_counta.
Then man_update will be set to true and all three become broadcasted to
network. -> trigger 2


Well that should it be.  :)

I could not test it in multiplayer environment so i cannot tell you that it's 100%
testet, but based on my experience it should work now.
Also there could probably come a problem in case 2 units get really killed almost
in same time because of publicVariable taking longer than the time between the
two kills - this is game engine related.

I've also attached a working example mission.

~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 #40 on: 09 Sep 2006, 15:04:01 »
Still a problem with the accounts
I had killed 2 enemy units so I should have got +80$... but when I tried to buy a beretta 92f for 100$ I got a messege : You don't have enough money
(the start cash is 50$)   :confused:

here are couple of scripts that might help  (the buy scripts and start cash script)






Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #41 on: 09 Sep 2006, 17:25:11 »
I told you that the cash of each unit is inside the according subarray of cash_array.

Look, cash_array looks like this:

[[w1,0,0],[w2,0,1],[w3,0,2],[w4,0,3],[e1,0,4],[e2,0,5],[e3,0,6],[e4,0,7]]

This is now an array consisting of 8 subarrays, each featuring 3 informations:

1) The unit

2) Their unit's cash

3) A number which indicates the position of the subarray in cash_array


At start of the mission the cash of each unit is at 0 here, while you have
another variable (e.g: e1cash) which you set to 50.
If you want the start cash to be 50, then you should not make it to
0 in init.sqs but to 50 btw.

Where do you transfer the head-bounty from the unit's array to it's
proposed variable (e1cash for e1)?

If your other scripts are all setup to cooperate with a variable e.g. e1cash
then we need to implement it (this would just make a few changes in
cash_update.sqs)


Also i noticed that the performance we saved with that array/subarray method,
you've put into the other scripts. I mean the way how you ask in the script
everything seperately for each playername.

For example it doesn't matter wether the player is unit w1 or w2 or e4, you only
need to add the actions to the player and not to it's editorname (this would save
you alot of lines inside your scripts).

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

Just one thing i'd expect from you too;
do your homework and try to find out by yourself, what my code
is doing. Start with using radio-triggers to let you display some variables
or arrays so that you figure out what happens when.
I just have to say this because i see how you waiste holy performance in
the other scripts by running the same commands over and over again.

I would feel stupid in just making a mission for somebody (or a part of a
mission), without this guy having understood what i told him.  :)

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


:edit - and another thing i noticed is that you made it for players only
If i know this from beginning, i could have saved alot of work too with
an easier way for the respawn check script.
However, i will not again change everything, maybe later when this is
finished i'll think one more time about it.

~S~ CD
« Last Edit: 09 Sep 2006, 18:08:13 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 #42 on: 09 Sep 2006, 19:42:41 »
I made little changes to the cash_update.sqs and now it works very well.  :thumbsup:

thanks very much.... I couldn't done this without your help.  :)
now I realy understand what the scripts do...

I have read my homework  :yes:


Well, what shall i say?  :scratch:

I've got it.   :check:

now I know how much time it takes to do and try diffirent things

SO NOW IT WORKS PERFECT

I'll have your name in readme in the part : special thanks to...



Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Problem with money script. HELP!
« Reply #43 on: 09 Sep 2006, 20:56:56 »
 :) good to see you got the endspurt on your own

If anything from the code is still not clear, or if you run
into further problems with it, feel free to ask again.

I hope you didn't get me wrong in my last post i did
just want to point out where's the line between the
guy who makes the mission and the guy who helps.

When i was on my weekly shopping tour today i knew
exactly how much money is in cash_array select 0 (on second
position of the sub-array), but don't ask me how much
i got in my pockets (before and after shopping).  :D

~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 h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem with money script. HELP!
« Reply #44 on: 10 Sep 2006, 09:53:11 »
Tut tut..

Keep the discussion on topic, please.
Those screenshots do not relate directly to the problem and only invite discussion about the mission, a discussion that should be held elsewhere..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.