Code Snippets Discussion
Posted: 28 May 2010, 13:38
Hi, I would ile to see here discussion about all Code Snippets. Just simple quote and paste here if you want to discuss sth ;>
Passager Discussion wrote:Nice one! I didnt know SET_CHAR_OBJECTIVE worked with players. I actually thought about trying but never tried, I forgot doing soPyro wrote:Player passengers in cars...Code: Select all
STORE_CAR_CHARACTER_IS_IN ( p1 , p1_current_car ) IF ( ( CHECK_CHAR_CURR_WEAPON ( p2 , ELECTRO_BATON ) ) AND ( IS_CHAR_PRESSING_HORN ( p1 ) ) ) SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p1_current_car ) ENDIF
Nice one again.
EDIT: Tried to compile, but it crashes the official compiler and gta2_mispadvike.exe compiler freezes at "Checking Compiler Output". Probably because of the set_objective to player thing :I
Still, here's the script:Conversation:Code: Select all
PLAYER_PED player1 = ( 52.5 , 179.5 , 2.0 ) -1 270 PLAYER_PED player2 = ( 52.5 , 179.5 , 2.0 ) -1 270 counter loop = 1 CAR_DATA p1_current_car CAR_DATA p2_current_car LEVELSTART IF ( CHECK_CHARACTER_HEALTH ( player1 , 0 ) ) SET_CHAR_GRAPHIC_TYPE ( player1 , DUMMY_GRAPHIC , -1 ) ENDIF IF (CHECK_CHARACTER_HEALTH(player2,0)) SET_CHAR_GRAPHIC_TYPE (player2,DUMMY_GRAPHIC,-1) ENDIF IF (CHECK_CHARACTER_HEALTH(player1,0)) GIVE_WEAPON (player1,ELECTRO_BATON,20) ENDIF IF (CHECK_CHARACTER_HEALTH(player2,0)) GIVE_WEAPON (player2,ELECTRO_BATON,20) ENDIF IF (IS_CHARACTER_IN_ANY_CAR(player1)) STORE_CAR_CHARACTER_IS_IN (player1, p1_current_car) ENDIF IF ( ( CHECK_CHAR_CURR_WEAPON ( player2 , ELECTRO_BATON ) ) AND ( IS_CHAR_PRESSING_HORN ( player1 ) ) ) SET_CHAR_OBJECTIVE ( player2 , ENTER_CAR_AS_PASSENGER , p1_current_car ) ENDIF IF (IS_CHARACTER_IN_ANY_CAR(player2)) STORE_CAR_CHARACTER_IS_IN (player2, p2_current_car) ENDIF IF ( ( CHECK_CHAR_CURR_WEAPON ( player1 , ELECTRO_BATON ) ) AND ( IS_CHAR_PRESSING_HORN ( player2 ) ) ) SET_CHAR_OBJECTIVE ( player1 , ENTER_CAR_AS_PASSENGER , p2_current_car ) ENDIF
Pyro wrote:The code is fine (even though you didn't put it in a WHILE loop) and compiles for me. But I had the same problem before if you remember and for some reason it won't compile any new scripts I make even with the most basic code (same error as before and the one you have). I used this code in a MIS file I know compiles and works.
This compiling bug is very strangeGustavob wrote:O lol I just noticed I didnt have the while loop and levelend. It happens frequently to me (forgetting the levelend) actually
It still didnt compiled, but I saved it in another file and now it compiled. No time to test atm, I will test it tomorrow. Maybe the size of the name was too big (player passengers.mis) or it just couldnt have spaces at script names.
Yup, script files cant have more than 32 characters in its name (including .SCR extension) and cant have spaces and probably accents (àáóòéèúùíì etc) etc, but it still happens even if script name is alright sometimesBenMillard wrote: Gustavob & Pyro, I've had that compiler bug. It was due to filename being too long or containing a special character.
i have a code that really generates random numbers and i dont understand why u use nested ifs. why not just if(var=val)?T.M. wrote:Who wants random car remap?! lool. ahahaha epic.
I had to use binary tree to speed it up around 3x compared to without it!
NOTE: you must call this subroutine after you had created a car named "auto" !
Note: its not actually a binary tree because MIS syntax doesnt support ELSE's at all. (lol). I also tried to optimize it by using GOSUB after CHANGE_CAR_REMAP, but it actually made it slower!
[mis]
random_car_remap:
if(randomizer < 16) // 0-15
if(randomizer < 8) // 0-7
if(randomizer < 4) // 0-3
if(randomizer < 2)
if(randomizer = 0)
CHANGE_CAR_REMAP(auto, 0)
ENDIF
if(randomizer = 1)
CHANGE_CAR_REMAP(auto, 1)
ENDIF
ENDIF
if(randomizer >= 2)
if(randomizer = 2)
CHANGE_CAR_REMAP(auto, 2)
ENDIF
if(randomizer = 3)
CHANGE_CAR_REMAP(auto, 3)
ENDIF
ENDIF
ENDIF
if(randomizer >= 4) // 4-7
if(randomizer < 6)
if(randomizer = 4)
CHANGE_CAR_REMAP(auto, 4)
ENDIF
if(randomizer = 5)
CHANGE_CAR_REMAP(auto, 5)
ENDIF
ENDIF
if(randomizer >= 6)
if(randomizer = 6)
CHANGE_CAR_REMAP(auto, 6)
ENDIF
if(randomizer = 7)
CHANGE_CAR_REMAP(auto, 7)
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 8) // 8-15
if(randomizer < 12) // 8-11
if(randomizer < 10)
if(randomizer = 8)
CHANGE_CAR_REMAP(auto, 8)
ENDIF
if(randomizer = 9)
CHANGE_CAR_REMAP(auto, 9)
ENDIF
ENDIF
if(randomizer >= 10)
if(randomizer = 10)
CHANGE_CAR_REMAP(auto, 10)
ENDIF
if(randomizer = 11)
CHANGE_CAR_REMAP(auto, 11)
ENDIF
ENDIF
ENDIF
if(randomizer >= 12) // 12-15
if(randomizer < 14)
if(randomizer = 12)
CHANGE_CAR_REMAP(auto, 12)
ENDIF
if(randomizer = 13)
CHANGE_CAR_REMAP(auto, 13)
ENDIF
ENDIF
if(randomizer >= 14)
if(randomizer = 14)
CHANGE_CAR_REMAP(auto, 14)
ENDIF
if(randomizer = 15)
CHANGE_CAR_REMAP(auto, 15)
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 16) // 16-31
if(randomizer < 24) // 16-23
if(randomizer < 20) // 16-19
if(randomizer < 18)
if(randomizer = 16)
CHANGE_CAR_REMAP(auto, 16)
ENDIF
if(randomizer = 17)
CHANGE_CAR_REMAP(auto, 17)
ENDIF
ENDIF
if(randomizer >= 18)
if(randomizer = 18)
CHANGE_CAR_REMAP(auto, 18)
ENDIF
if(randomizer = 19)
CHANGE_CAR_REMAP(auto, 19)
ENDIF
ENDIF
ENDIF
if(randomizer >= 20) // 20-23
if(randomizer < 22)
if(randomizer = 20)
CHANGE_CAR_REMAP(auto, 32) // different
ENDIF
if(randomizer = 21)
CHANGE_CAR_REMAP(auto, 21)
ENDIF
ENDIF
if(randomizer >= 22)
if(randomizer = 22)
CHANGE_CAR_REMAP(auto, 22)
ENDIF
if(randomizer = 23)
CHANGE_CAR_REMAP(auto, 23)
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 24) // 24-31
if(randomizer < 28) // 24-27
if(randomizer < 26)
if(randomizer = 24)
CHANGE_CAR_REMAP(auto, 24)
ENDIF
if(randomizer = 25)
CHANGE_CAR_REMAP(auto, 25)
ENDIF
ENDIF
if(randomizer >= 26)
if(randomizer = 26)
CHANGE_CAR_REMAP(auto, 26)
ENDIF
if(randomizer = 27)
CHANGE_CAR_REMAP(auto, 27)
ENDIF
ENDIF
ENDIF
if(randomizer >= 28) // 28-31
if(randomizer < 30)
if(randomizer = 28)
CHANGE_CAR_REMAP(auto, 34) // different
ENDIF
if(randomizer = 29)
CHANGE_CAR_REMAP(auto, 29)
ENDIF
ENDIF
if(randomizer >= 30)
if(randomizer = 30)
CHANGE_CAR_REMAP(auto, 35) // different
ENDIF
if(randomizer = 31)
CHANGE_CAR_REMAP(auto, 31)
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
// make so sequential calls will have different remap too:
++randomizer
if(randomizer > 31)
SET randomizer = 0
ENDIF
RETURN
[/mis]
[mis]
// Usage:
COUNTER randomizer = 0
FORWARD random_car_remap:
COUNTER done = 0
LEVELSTART
WHILE_EXEC(done = 0)
/////////////////////
// put this if you want to make it even more random:
++randomizer
if(randomizer > 31)
SET randomizer = 0
ENDIF
////
// rest of your code here
////
ENDWHILE
LEVELEND
// you can paste random_car_remap: subroutine here
[/mis]
Please show the code that makes a random number depending on GMP file.. because i dont believe GTA2 supports such.it requires a pseudo random input. that input is different on each map and depends on the level design, so for that post i would have to explain a bit
sorry, couldnt find from there either, in fact i dont even have that mis file, but luckily i could decompile it and no shops there at all.elypter wrote:tiny face off army ofc, and yes it is. and leveldesign not gmp file.
i never said thatT.M. wrote:so you call hardcoded number random? i thought of using some other than zero intial value, but thought it would be pointless since it would always start from the same value. so i just use zero instead.
all my maps have script included and are hosted on the map pageT.M. wrote: when are you going to post your code?
Code: Select all
SET temp = ( rand / 3 )
SET temp = ( temp * 3 )
SET rand = ( rand - temp )
Code: Select all
SET rand = ( rand MOD 3)
T.M. wrote:Edit: btw i found out recently editplus supports mis style code folding, you might be interested; http://www.editplus.com
editplus code folding is epic: it detects the tabs (or 4 spaces) and adds folding options regarding to that. (i think its because it doesnt recognize the language so its the default code folding method). i was quite surprised how well it actually works with any language! although, as ive seen, almost nobody here uses proper indenting on their mis scripts... and you cant indent multiple lines at once in mispad, unlike in editplus, it even converts 4 spaces into tab automatically (if you indent them). it has like million other useful features i still keep finding out!B-$hep wrote:My ScriptPad also supports folding. I can add support for any folding case if needed.
And it's freeware.
heh. its not just for gta2. ive been using it for years and it has never pissed me off, unlike every other tool around the world such as notepad++ and other free/opensource software there is.B-$hep wrote:Who of the GTA2 modders will buy shareware app? I think no-one.
sounds interesting. i could make a powerup for this on tiny face off army if i'm getting to update it next timeCarThief wrote:Cause explosion on Player when pressing Car Horn:Code: Select all
...