Code Snippets Discussion

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Razor
Lunatic
Lunatic
Posts: 453
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Code Snippets Discussion

Post by Razor »

Hi, I would ile to see here discussion about all Code Snippets. Just simple quote and paste here if you want to discuss sth ;>

Razor
Lunatic
Lunatic
Posts: 453
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Code Snippets Discussion

Post by Razor »

Passager Discussion wrote:
Pyro 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! I didnt know SET_CHAR_OBJECTIVE worked with players. I actually thought about trying but never tried, I forgot doing so :P
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:

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
Conversation:
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 strange :evil:
Gustavob wrote:O lol I just noticed I didnt have the while loop and levelend. It happens frequently to me (forgetting the levelend) actually :P
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.

BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Re: Code Snippets Discussion

Post by BenMillard »

This approach seems less useful than the natural way a forum normally works, imho.

Razor
Lunatic
Lunatic
Posts: 453
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Code Snippets Discussion

Post by Razor »

i dont like comment mess in snippets. Whi i have to read 3 pages of comments if i just can search for snippets? If sb has problem with script can paste it here. Also it eliminates post like "nice one, great job" etc.

BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Re: Code Snippets Discussion

Post by BenMillard »

Normally someone posts an idea or a script, people comment and improve it. Then the original message gets updated. Or it adds a link to a web page which published a tutorial about it.

Anyway, let's try your way out:
  1. I have a comment on the above player passenger script.
  2. How do I add my thoughts to that discussion?
  3. I can't edit that message.
  4. So I guess I make a new post here?
Gustavob & Pyro, I've had that compiler bug. It was due to filename being too long or containing a special character.

(I wonder what happens now...)

User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Re: Code Snippets Discussion

Post by Gustavob »

BenMillard wrote: Gustavob & Pyro, I've had that compiler bug. It was due to filename being too long or containing a special character.
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 sometimes
You just lost the game.

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

T.M. wrote:Who wants random car remap?! :D 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]
i have a code that really generates random numbers and i dont understand why u use nested ifs. why not just if(var=val)?
yur sa'nok ngeyä

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

because i cant do "CHANGE_CAR_REMAP(auto, var)" ;)

and that if(var = val) has nothing to do with this actually... i wouldnt need that if at all if i could just type "CHANGE_CAR_REMAP(auto, var)"

btw dare to post your random number generator? :o
Last edited by T.M. on 26 Nov 2011, 18:02, edited 2 times in total.

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

i will try to. you can see a random generator on bc_awkward cargo and a random multicolor sprayshop in tiny face off army(at least most of the spray shop code is in an external mis file).

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.
Last edited by elypter on 25 Nov 2011, 19:29, edited 1 time in total.
yur sa'nok ngeyä

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

random generator != random car remap generator.

i couldnt even see a spray shop in tiny face off. stop wasting my time and show your code if you have some points to make regarding my code.
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
Please show the code that makes a random number depending on GMP file.. because i dont believe GTA2 supports such.

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

tiny face off army ofc, and yes it is. and leveldesign not gmp file.
yur sa'nok ngeyä

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

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.

it doesnt really matter if it changes on each map: its still the same every time you play the map.
elypter wrote:tiny face off army ofc, and yes it is. and leveldesign not gmp file.
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.

when are you going to post your code? :roll:

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

T.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.
i never said that
T.M. wrote: when are you going to post your code? :roll:
all my maps have script included and are hosted on the map page

http://gta2dare.omnitude.net/maplist/li ... ap=tyfo.7z

there is even a link for direct view of .mis and subs folder
yur sa'nok ngeyä

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

Is this it? I couldnt find any match to "shop", but "rand" found this:

Code: Select all

SET temp = ( rand / 3 )
SET temp = ( temp * 3 )
SET rand = ( rand - temp )
How is that random? youre doing exactly this:

Code: Select all

SET rand = ( rand MOD 3)
I used exactly that method on my code at the first place, but realised its pointless since taking something from already randomized stack doesnt make it any more random, e.g. the remap colors are already random colors, doesnt matter which order it take from it, user wont see a difference, and on top of that: i cycle the randomizer value each frame, so that will make it feel more random since it gives different result depending when you call that subroutine.

btw, that 3 liner code of yours doesnt seem to even do anything in your script! no other references to "rand" variable.

Edit: btw i found out recently editplus supports mis style code folding, you might be interested; www.editplus.com
Last edited by T.M. on 26 Nov 2011, 00:53, edited 1 time in total.

User avatar
B-$hep
Immortal
Posts: 543
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: Estonia - Finland

Re: Code Snippets

Post by B-$hep »

T.M. wrote:Edit: btw i found out recently editplus supports mis style code folding, you might be interested; http://www.editplus.com

My ScriptPad also supports folding. I can add support for any folding case if needed.
And it's freeware.

Who of the GTA2 modders will buy shareware app? I think no-one.
Always wear safety glasses while programming.

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

B-$hep wrote:My ScriptPad also supports folding. I can add support for any folding case if needed.
And it's freeware.
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:Who of the GTA2 modders will buy shareware app? I think no-one.
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.

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets Discussion

Post by elypter »

CarThief wrote:Cause explosion on Player when pressing Car Horn:

Code: Select all

...
sounds interesting. i could make a powerup for this on tiny face off army if i'm getting to update it next time
yur sa'nok ngeyä

User avatar
Alberto
Hitman
Hitman
Posts: 115
Joined: 19 Jan 2012, 20:13
GH nick: Raef/ RaefGH
Location: Calgary.

Code Snippets

Post by Alberto »

can i create 2 phones in one map?
cuz when i compile it says symbol already declared answer_phone:
The fuck you looking at?

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets Discussion

Post by T.M. »

you cant declare same named variable twice.

User avatar
elypter
Immortal
Posts: 1121
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets Discussion

Post by elypter »

http://gtamp.com/forum/viewtopic.php?p=7189#p7189

good to have that in the code snippets but could you at least post the author of the script...
yur sa'nok ngeyä

Post Reply