Somerville 0 Posted April 4, 2008 Hi guys, I've got the following script: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0 ?(_unit = typeOf BLUE_TL) : goto "swatkick" ?(_unit = typeOf BLK_2) : goto "copkick" ?!(side player == WEST) : exit exit #swatkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit #copkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit But this doesn't work. It's basically designed to stop SWAT units from buying cops' weapons, and vice versa. Can anyone tell me what's wrong with this? Or if there's a better solution? Share this post Link to post Share on other sites
sickboy 13 Posted April 4, 2008 What is: BLUE_TL? I think you mean to do this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _unit = _this select 0 ?(typeOf _unit == BLUE_TL) : goto "swatkick" ?(typeOf _unit == BLK_2) : goto "copkick" exit #swatkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit #copkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit If BLUE_TL and BLK_2 are not variables, but rather unit classnames, use "BLUE_TL" Â and "BLK_2" Share this post Link to post Share on other sites
dachevs 1 Posted April 5, 2008 what about the isKindof command? Share this post Link to post Share on other sites
Serclaes 0 Posted April 5, 2008 Ok mate, you made some serious stuff there. I will go deep and try to explain everything from the basics up. The typeOf command, as written in the biki, returns a string. Thats the purpose of a function. The syntax looks like this: _StringClassOfMySoldier = typeOf ObjectMySoldier; ObjectMySoldier can be ANY object. But his class will be his classname (sounds logic). Hence, what you are doing wrong is here: typeOf _unit == BLUE_TL if you have a unit which classname is BLUE_TL (which is defined in the config), then: It needs to be a string. From here i cannot see whether BLUE_TL has just been forgotten to put in quotes or if its a global variable with a string behind it. So a solution, if you have a config with the corresponding classnames (BLUE_TL BLK_2). Your code should look like this (as sickboy suggested already): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0 ?(_unit = typeOf "BLUE_TL") : goto "swatkick" ?(_unit = typeOf "BLK_2") : goto "copkick" ?!(side player == WEST) : exit #swatkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit #copkick (_unit setpos (getpos back)) hint "You're not allowed there!" exit But let me say that this method is the WORST you could choose to reach what you want and this on multiple levels: 1. you are using SQS SQS is dirty. Look at your code, the function can be exited at 3 different locations, you jump from the beginning to the bottom. Thats not readable. Have a look on how it could be solved in SQF: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _Unit = _this select 0; if((side _Unit != west) && !isServer) ExitWith{hint "you are on the wrong side or not a server"}; _type = typeOf _Unit; if(_type = "BLUE_TL" || _type = "BLK_2") ExitWith {hint "you are not a SWAT unit, go home";}; 2. Kicking players away from something is not good. I'm very annoyed if i get teleported around. Heres what i suggest: create a civilian (he's the master of arms), add the action "buy weapons" to him. When launching the action it should execute such a code: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _masterOfArms = _this select 0; _unit = _this select 1; if((side _masterOfArms) != (side _unit)) ExitWith{}; if((typeOf _unit) == "SWATTrooper") Then { createDialog WEAPONSDLG; } else { titleCut "Sorry, cannot sell you those weapons"; }; Please note that this code is just a draft. You need to create dialog (since a dialog is much nicer to choose from). And this code expects an object which is a "SWATTrooper". For me this would a very nice feature where i feel like i would interact with the surroundings and have a logical explanation rather than being oddly teleported away. Share this post Link to post Share on other sites
Somerville 0 Posted April 9, 2008 I'm not a hugely advanced scripter - hence the use of SQS. However, I'm learning SQF slowly but surely The reason I can't really use the above suggestion is because I am using SPON Money. As such, you can't restrict one shopkeeper without restricting all of them. I've simply used a trigger now that doesn't transport you away, but closes the dialog if it's called and hints that he cannot sell you anything. The thing now is to stop civilians entering the police department. I dont' want them to die, though - perhaps a simple way to operate it would be similar to the above, simply by hinting that, when they try to buy weapons, they cannot because they're not a cop? I'll look into it though - but if anyone wants to offer any help, feel free - the more the merrier Share this post Link to post Share on other sites