Home   Help Search Login Register  

Author Topic: this is MY car, not yours  (Read 1870 times)

0 Members and 1 Guest are viewing this topic.

Offline myke13021

  • Contributing Member
  • **
  • Myke
this is MY car, not yours
« on: 20 Apr 2004, 14:27:59 »
hey peeps,

i'm looking for an (easy) way to assign Vehics to a specific unit. So no one else can use this car. i know it doesn't exist , but something like SetCarOwner and, to check if unit IS car owner...you might guess it, IsCarOwner.

I know it could be done with setting and checking variables, but this would make a it really complicated, as there are 20 units which could have a car, and each unit could have more than one car. you see the problem.

I guess i'll make it this way, unless one of you scripting gods can show me an easy (and flexible) way to do it.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:this is MY car, not yours
« Reply #1 on: 20 Apr 2004, 23:25:22 »
Greetings myke13021!

    Here is a concept:

         1)  Set all vehicles to "locked" in the editor or init (if this is possible).

         2) Make a trigger around the car (~ 5 meters) with whatever side you are using "Present" and in the activation line  use "car1 lock false" ( or if it would work "this lock false"). Then just press F2 to group that unit to that trigger so only that unit can get into that particular car. Then just use that format for each unit and car combination. ;)

     Always test my suggestions as they usually get posted from work so I cannot verify if it will really work. :P


                                                                                  Wadmann

Edited for clarity.
« Last Edit: 20 Apr 2004, 23:26:59 by Wadmann »
Check out my Camouflage Collection! New items added 31 July 2005.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #2 on: 20 Apr 2004, 23:37:53 »
thx Wadmann...i'm sure this would work fine...but i'm affraid not on the map i'm making.

The Vehicles aren't there from the beginning...they're createvehicled during the mission.

Look it like this...a guy goes to the Car dealer and buys a car...then the Salesman would pass the Car key to the guy so he (and only he) can unlock the car and use it.

If i understand the concept of functions correctly, this could be done with such a function (well, in fact 2 functions: setcarowner and iscarowner).

I already read some tutes about and all i could find about in the ED Depot and i can say....i have no clue how such a function could be written.

Surplus, during the game i would have the option to "steal a car" which request a new assignement of Car to Guy.

I could make it easily if there would be such commands as setcarowner and iscarowner....thats basically the only thing i need.

:edit:
even when i would try your concept, it would be a damn mess...i have 20 playable units...that would make 20 triggers lagging the game down
« Last Edit: 20 Apr 2004, 23:40:09 by myke13021 »

Black and White

  • Guest
Re:this is MY car, not yours
« Reply #3 on: 21 Apr 2004, 00:27:32 »
if u hav ever played the RTS3 mod then you would know how they use the lock and unlock function

what u should try is adding a action to the player/players when he/she gets whithin so far of the car...

it works for RTS3 and that doesn't lag it up without some serious numbers of units 50+ squads

but then i am running 2GHz :P

or you could try the same thing execpt instead of unlocking it you could do moveincargo

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #4 on: 21 Apr 2004, 01:16:20 »
@Black and White

You misunderstood me...i know how to lock/unlock cars...the problem is that i try to find an easy way son only the Carowner CAN lock/unlock the car...the problem with the suggest above is, the cars will be created during the game...there can be more than 1 car per player....other's player should be able to steal a car....as i said...easiest would be if there could be commands like setcarowner and iscarowner

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:this is MY car, not yours
« Reply #5 on: 21 Apr 2004, 11:21:19 »
hmm - i suppose you're "buy car" options will be executed
local on the machine, where the player who buys that car is.

Shall it be custom action or dialog - doesn't matter - both usually
run local.

Now all you have to do is: put the just created car into an array.
This array will contain all cars, a player has bought.

Then you could use either lock/unlock or setfuel 0/1 upon a check,
wether the car, the player wants to use is in this array or not.

Or another solution could be: after creating the car, use the same
script to exec another script for the car (will also only run there,
where it was created). That script would only have to check,
wether the player is in the car or not - if he's in: setfuel 1
if not: setfuel 0 (looping script with conditions + exit in case
the car's destroyed).

There are still some more ways to do what you want - the magic
key is simple: use ofp's weakness (things running only local
in some cases) as your strongness  ;)

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

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #6 on: 21 Apr 2004, 14:04:23 »
@Chris Death

hay i think you get me on the right way. I think the assign to array thing is the one i would try. But there comes new questions with.

How do i create an array for a unit.
How do i add new vehics to this array.
whats the syntax to check if car is in units array.

If you could help me with this, i would be a giant leap further.

Chris Death, your answers are helpful as usual...thx alot mate. ;D

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:this is MY car, not yours
« Reply #7 on: 21 Apr 2004, 14:56:35 »
OkieDokie here we go:

IMHO the setFuel method is the better one in your case,
as you could addAction a "start_engine" script, to be able
to drive that car.

First you need to initialize an array (best done in the init.sqs as
it runs for everyone at the start of the mission),
so the array will exist everywhere:

car_array = []

Then in the script, where you create the car, all you have to
do is:

car_array = car_array + [the_car_you_just_created]

:note - the car will only  be added local to the array of the
pc, where the script runs - each player will have the same
array, but it will only contain the cars created on his pc.

Now once a player approaches the car, the custom action
"start car" will show up

:note - best you gonna choose your own name for that action,
so that it will fit in to your idea - "unlock car" - "disable thief protection" - whateva  :)

Now the script, started by addAction offers an automatically
passed parameter: _this select 0 - which represents the object,
the action is being attached. Also there's another parameter,
which represents the id of the action itself: _this select 2
You can use this to remove the start action and to add another
one which allows you to enable the protection again.

It should look summit like that:

Code: [Select]
_car = _this select 0
_id = _this select 2
?(_car in car_array): goto "its_mine"
hint "huh - wtf - this ain't my car"
exit

#itsmine
_car removeAction _id
_car addAction ["protect car";"blablabla.sqs"]
_car setfuel 1

exit
Now the enable protection script:

Code: [Select]
_car = _this select 0
_id = _this select 2

_car removeAction _id
_car setfuel 0
_car addAction ["start car";"blablastuffandso.sqs"]

exit

:note - i haven't tested this yet, so i cannot tell you for sure that it works exactly that way, but if not, there are still some more
ways, using the local array method, where i'm sure one of 'em
will work.

Just one more method - not using addAction/removeAction:

have a looping script running for each player straight from the
beginning of the mission, which looks like that:

Code: [Select]
#start
?(vehicle player != player): goto #check_owner
~2
goto "start"

#check_owner
_car = vehicle player
?(!canMove _car): exit
_car setfuel 1

#in_car
~2
?(vehicle player == player): goto "in_car"
_car setfuel 0
goto "start"

:note - off course by this method, you need to add each vehicle,
which can be used by everyone to everyone's array - init.sqs  ;)

hope this helps

:edit - btw - i'm not sure if setFuel 0 will cause !canMove _car to
exit the script, but if so - just remove the line and it will still work.
It's only there to avoid running to many scripts - you could then
change it into a dammage check or so  ;)

~S~ CD
« Last Edit: 21 Apr 2004, 14:59:49 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 myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #8 on: 21 Apr 2004, 15:12:02 »
perfect....simply perfect.

Chris, you're the greatest....you didn't just showed me how to do it...you explained it in a way that i can finally see how array's work...sure, i used array's before, but didn't really understand how they work...now all make sense to me.

note to myself: add a special thanx section for Chris in the briefing  ;D

thx again mate...i can see clearly now  ;)

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:this is MY car, not yours
« Reply #9 on: 21 Apr 2004, 17:43:29 »
hold on myke

i just noticed three big mistakes i made in the second method  :-[

1) The script must not exit, in case the car is destroyed.

You know why - because the script is running for the player
and not for the car.

2) I totally forgot to include the condition, wether the player
is allowed to use the car or not  ::)

3) The condition to check if the player is still in the car was wrong

Code: [Select]
?(vehicle player == player): goto "in_car"
Off course it's the other way around, else nobody would be able
to drive that car, as the loop would break imidiately.


Code: [Select]
#start
?(vehicle player != player): goto #check_owner
~2
goto "start"

#check_owner
_car = vehicle player
?(_car in car_array): _car setfuel 1

#in_car
~2
?(vehicle player != player): goto "in_car"
_car setfuel 0
goto "start"

soz but the second method i wrote very quickly without thinking
too much about the script itself, but the method in general  :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 myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #10 on: 22 Apr 2004, 00:46:21 »
Chris Death...you're my hero.....i got it to work  :cheers:

I hope you don't mind when i say i didn't used your (absolutely excellent) scripts, but wrote my own. IMHO only this way i'm used to learn and getting better.

But you can be sure, without your help, i wouldn't have done yet.

Things i changed is, since i wont trust OFP about keeping arrays local (and since the buy vehicles scripts are executed on server), i just made an array for each playable unit.

Now only one thing is open...how can i remove a car from an array? I need this to implement in my deletedestroyedvehicles sript.

Basically i could leave the car in the array...wouldn't disturb there...but i think it looks "better scripted" when i remove it from there. Surplus during a game a unit could have a lot of vehics  ;D

If you can tell me the command and the syntax, then i'm done...it's just this little thing i nedd to make it look good :toocool:

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:this is MY car, not yours
« Reply #11 on: 22 Apr 2004, 01:27:07 »
Quote
I hope you don't mind when i say i didn't used your (absolutely excellent) scripts, but wrote my own. IMHO only this way i'm used to learn and getting better.

Well, i'm fine with that, as one of the main reasons, why i do
sometimes seem to confuse ppl with telling more than one
method to solve something, and more than they were asking
for. Too often i see ppl answering questions with a one-liner,
which would only work for exactly that only case, which somebody
was asking for, but upon left details, these don't work in later
situations.

I'm really glad of having inspired you to build your own solution  :)

OK, now back on track:

To remove an element of an array, you need to rebuild the array
but leave out the element, you want to remove.

There's a function by snYpir available at the ed-depot, but again
i want you to show the "do-it-yourself" way, so that you know
what you're doing there.

If you don't want to, i'll post the function first, and the explanation stuff behind then:

http://www.ofpec.com/editors/funcref.php?filter_func=5

(*let's hope you gonna see the same thing as me when following
the link this time  ;D *)


Now the "do-it-yourself" way:

let's say you have an array (car_array), consisting of 5 cars.

car_array = [car1,car2,car3,car4,car5]

Now you want to remove car3 from that array

You need to create a temporary array, where you put in all
cars from car_array which are not equal to car3
Last you only need to replace the contents of car_array by
the contents of the temp array.

Code: [Select]
_car = car3
;this is just for the example, in your case you will off course
find a way to assign the right car to variable _car - i'm sure 'bout
that  ;)

_temp_car_array = []
;here you initialize a temporary empty array

"if (_x != _car) then {_temp_car_array = _temp_car_array + [_x]}" forEach car_array
;here we put all cars from car_array except car3, into the temp_car_array


car_array = _temp_car_array
;voilla - here's your rebuilt car_array without car3

This should do the job then.

Forgive me, if i maybe rush in later to correct something i did
oversee atm  ;D but i think all's fine already. Ya know - sometimes thoughts have already gone 3 corners ahead, and
man doesn't see simple mistakes  :-[

good luck for encrypting this post  ;D

Nah - shouldn't be too hard for you to s 8)lve your last problem
now.

:edit - btw - if you gonna use the script, take care about the comments
i added for you in there, so that they don't screw up the script.
Anyway me thinks you know that already - just in case.

~S~ CD
« Last Edit: 22 Apr 2004, 01:29:15 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 myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #12 on: 22 Apr 2004, 02:08:54 »
perfect as usual...i just had to adapt it to my existing deletevehicle script...if you wou ld please please take a look at it to see if it's done correctly.

Code: [Select]
;delete broken vehics
?!(local server): exit
_vehic = _this select 0
_unit = _this select 1
#loop

?!(canmove _vehic) AND (isnull driver _vehic): goto "delete"
~10
goto "loop"

#delete
~60
?!(isnull driver): goto "loop"
_cararray = []
_removearray = []
?(_unit == civ1): _cararray = civ1cars
?(_unit == civ2): _cararray = civ2cars
?(_unit == civ3): _cararray = civ3cars
?(_unit == civ4): _cararray = civ4cars
?(_unit == civ5): _cararray = civ5cars
?(_unit == civ6): _cararray = civ6cars
?(_unit == civ7): _cararray = civ7cars
?(_unit == civ8): _cararray = civ8cars
?(_unit == civ9): _cararray = civ9cars
?(_unit == civ0): _cararray = civ0cars

if (_x != _vehic) then {_removearray = _removearray + [_x]} forEach _cararray

?(_unit == civ1): civ1cars = _removearray
?(_unit == civ2): civ2cars = _removearray
?(_unit == civ3): civ3cars = _removearray
?(_unit == civ4): civ4cars = _removearray
?(_unit == civ5): civ5cars = _removearray
?(_unit == civ6): civ6cars = _removearray
?(_unit == civ7): civ7cars = _removearray
?(_unit == civ8): civ8cars = _removearray
?(_unit == civ9): civ9cars = _removearray
?(_unit == civ0): civ0cars = _removearray

deletevehicle _vehic
exit

So this now contains the delete vehicle when broken and also the rmove from array part.

_vehic is the variable i get from the createvehicle script which is the car...(duh)
_unit is also passed by this createvehicle script and contains the unit name, given in the editor.
civXcars are the arrays i created in the init.sqs for each playable civilian


:edit:
i guess the quotes in the if then line are mistakes.
And this time i took the most of your script...why repairing it when it's not broken...thx for your time mate. :cheers:
« Last Edit: 22 Apr 2004, 02:12:04 by myke13021 »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:this is MY car, not yours
« Reply #13 on: 22 Apr 2004, 03:25:14 »
Quote
i guess the quotes in the if then line are mistakes.

Nope, they're required because of _x forEach stuff.

Alright, the script seems to be ok at a first look
hehe i always find the monkeys during the second look
*laughing-devil-smiley*

There's one thing, you could still change (well in summary it's
two things, but it's both the same):

Code: [Select]
?(_unit == civ1): _cararray = civ1cars
?(_unit == civ2): _cararray = civ2cars
?(_unit == civ3): _cararray = civ3cars
?(_unit == civ4): _cararray = civ4cars
?(_unit == civ5): _cararray = civ5cars
?(_unit == civ6): _cararray = civ6cars
?(_unit == civ7): _cararray = civ7cars
?(_unit == civ8): _cararray = civ8cars
?(_unit == civ9): _cararray = civ9cars
?(_unit == civ0): _cararray = civ0cars

and the second one:

Code: [Select]
?(_unit == civ1): civ1cars = _removearray
?(_unit == civ2): civ2cars = _removearray
?(_unit == civ3): civ3cars = _removearray
?(_unit == civ4): civ4cars = _removearray
?(_unit == civ5): civ5cars = _removearray
?(_unit == civ6): civ6cars = _removearray
?(_unit == civ7): civ7cars = _removearray
?(_unit == civ8): civ8cars = _removearray
?(_unit == civ9): civ9cars = _removearray
?(_unit == civ0): civ0cars = _removearray

This could be changed into a one-liner by using the if-then technique + an array, containing sub-arrays

hmm - just noticed it's already early in the morning, and if i
would continue with what i was going to show you, i would
have to type at least one hour (including checks + correction
of meself - duh).

In case of your actual script it's anyway easier to use the method
you already made, as it's just about 9 extra lines, you having here.

Just a quick explanation of what i meant, so that we can continue
that later if you're interested and if i got enough time left.
Maybe it will sound a bit complicated now, but believe me, once
you get it, you're becoming an MOA (master of arrays)  :D


you would have to create a major array, where you put all units
+ their affilated arrays into;

like that:

Code: [Select]
;first the minor arrays

civ1array = []
...
...
civ0array = []

;now the major array

civ_all_array = [[civ1,civ1array],[...and_so_on...],[civ0,civ0array]]

Instead of doing the ?(_unit == civX):_cararray = civXarray
seperately, you could now do it that way:

Code: [Select]
"if (_x select 0 == _unit) then {_cararray = _x select 1}" forEach civ_all_array

:note - each subarray of civ_all_array consists of a subarray, which again consists of a unit and an array (you still there? - lol)
Let me explain it straight and short;
If _unit would be civ3, then _cararray would be civ3array
_x represents the subarrays of civ_all_array
_x select 0 represents civ1 - civ0
_x select 1 represents civ1array - civ0array

btw - why did i say i ain't got enough time left right now, if i
do it then though? - Yeah it's because i like this brainburning
stuff in the morning sooo much  ;D

OK, now the stuff, needed to cut down the second part into
a one-liner.

:note - the next line is to be kept like it is, i'll just post it to
keep in mind where we are in the script now;

Code: [Select]
if (_x != _vehic) then {_removearray = _removearray + [_x]} forEach _cararray
After succesfull removing the car from _cararray, you need to
put it back into your major array. This is a bit more tricky now,
as you will need a new command for that:

array set [pos,stuff]

:note - pos is the position in the array and stuff is what you want
to put(replace/exchange) in there.

Code: [Select]
"if (_x select 0 == _unit) then {_x set [1,_cararray]}" forEach civ_all_array
It's the same technique, being used above with the only difference that we're using ARRAY SET stuff.

_x represents the subarrays of civ_all_array
_x select 0 represents civ1 - civ0
_x select 1 represents civ1array - civ0array

If _unit would be civ3, then civ3array would be replaced by _cararray.

OK, think that's all for now - wish you sweet dreams of arrays
and subarrays and civies and their civXarrays too  ;D  ;)

If you got any questions - no prob - i'm off work this week, but
not me mrs (*lol it's only my pc's and me in da house*)

It may look again a bit more complicated now, but trust me, it's
worth the effort to get familar with that - way more doors will
be open in ofp for your.

~S~ CD
« Last Edit: 22 Apr 2004, 03:39:32 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 myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #14 on: 22 Apr 2004, 04:22:25 »
OMFG....Chris...you make me terrible headache...lol

...this is really hard stuff....and as you say...it's early in the morning (5:00am here)....i have to get some sleep first before i'm able to follow your thoughts.

But as far i see now, i think there's some other stuff (scipts) i could shorten and make easier to handle by using array's and sub-array's...but not yet  ;)

i have to get more familiar with the whole array concept before i can think of tweaking my other scripts.

btw, my fav line in your last post is:

Quote
:note - each subarray of civ_all_array consists of a subarray, which again consists of a unit and an array (you still there? - lol)

naw...wasn't really there...lmao...maybe i should tell you, my brain has to translate this stuff first in german before i even can think of understanding it...but i'll learn it...and if it takes ages to.

And about your time...i hope i don't take too much of your precious time....at least not as much as your missus would get angry about ;D

Anyway, i'll sleep over this, read the whole thing tomorrow when i'm more awake than now....and if some questions are comin up...well, you can be sure i'll ask you about.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #15 on: 22 Apr 2004, 14:48:27 »
ok...now i'm awake and i re-read your last post.....hmm...i think i see through...and surely would do so, but..(there's always a "but") there are a few other scripts that i had to rework then.

And as you say, the way i did will work, i'll keep it this way for now since i have other things to implement first to my map.

But this will be one of the topmost points on my "Tweak and optimize" list.

Thx for your hel pChris, and...pfüeti  ;D

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:this is MY car, not yours
« Reply #16 on: 29 Apr 2004, 01:23:49 »
ok...the first part works...but now i get another problem where i need some help.

The first part..all that what was written before, works well..but now i have to turn around and the problem is....how do i determine in which array a car is in?
Or in other words: who's the car owner?

Ok, i got an array for each civilian in which every vehic he gets is stored

civ1cars
civ2cars
......
and so on

now i have a script which allows to steal a car, so i have to remove the car from his owners array and add it to the "new owner"...the second part (adding) i can handle, but for the first part (remove from previous owner) i need help.

So here's my final question:

How (and please a correct line with syntax and all ;D) do i determine in which array a car is and remove it from there?

Komuna

  • Guest
Re:this is MY car, not yours
« Reply #17 on: 29 Apr 2004, 10:32:03 »
Hey, mates!

I've just read this topic and I think that some of the code is unecessary:

Code: [Select]
if (_x != _vehic) then {_removearray = _removearray + [_x]} forEach _cararray
I see the point. You want to remove a car. Then, all you need is:

_car_array = _car_array - [_car1]

Yes, it is possible. Check out the Command Reference for "array-array" procedures.

About finding a car:
Code: [Select]
_List_of_arrays = ["car_array1","car_array2","car_array3",etc]
{IF (_car_to_be_removed in call _x) THEN {[_car_to_be_removed] call (_x+" = "+_x+" - _this")} } forEach _List_of_arrays
« Last Edit: 29 Apr 2004, 10:36:08 by Komuna »