GTAMP.com

Grand Theft Auto Media Press
It is currently Mon May 20, 2013 3:58 am

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Code Snippets Discussion
PostPosted: Fri May 28, 2010 1:38 pm 
Offline
Lunatic

Joined: Sat Jul 19, 2008 2:14 pm
Posts: 421
Location: Poland / Szczecin
Hi, I would ile to see here discussion about all Code Snippets. Just simple quote and paste here if you want to discuss sth ;>


Top
 Profile  
 
PostPosted: Fri May 28, 2010 1:46 pm 
Offline
Lunatic

Joined: Sat Jul 19, 2008 2:14 pm
Posts: 421
Location: Poland / Szczecin
Passager Discussion wrote:
Pyro wrote:
Player passengers in cars...
Code:
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:
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.


Top
 Profile  
 
PostPosted: Sat May 29, 2010 4:47 pm 
Offline

Joined: Sat May 16, 2009 6:14 am
Posts: 781
Location: London, UK
This approach seems less useful than the natural way a forum normally works, imho.

_________________
Multiplayer Levels | Mission Code Tutorials | Multiplayer Videos


Top
 Profile  
 
PostPosted: Sat May 29, 2010 5:20 pm 
Offline
Lunatic

Joined: Sat Jul 19, 2008 2:14 pm
Posts: 421
Location: Poland / Szczecin
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.


Top
 Profile  
 
PostPosted: Sun May 30, 2010 12:35 am 
Offline

Joined: Sat May 16, 2009 6:14 am
Posts: 781
Location: London, UK
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...)

_________________
Multiplayer Levels | Mission Code Tutorials | Multiplayer Videos


Top
 Profile  
 
PostPosted: Sun May 30, 2010 12:39 am 
Offline
User avatar

Joined: Mon May 18, 2009 9:40 pm
Posts: 390
Location: Nowhere.
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.


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 12:08 am 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
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!

Syntax: [ Download ] [ Hide ]
Using GTA2 Script Syntax Highlighting
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
 
Parsed in 0.044 seconds, using GeSHi 1.0.8.10



Syntax: [ Download ] [ Hide ]
Using GTA2 Script Syntax Highlighting
// 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

 
Parsed in 0.021 seconds, using GeSHi 1.0.8.10


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ä


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 11:32 am 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
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

_________________
My GTA2 related projects:


Last edited by T.M. on Sat Nov 26, 2011 6:02 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 2:40 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
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.

_________________
yur sa'nok ngeyä


Last edited by elypter on Fri Nov 25, 2011 7:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 2:51 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
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.

Quote:
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.

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 7:30 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
tiny face off army ofc, and yes it is. and leveldesign not gmp file.

_________________
yur sa'nok ngeyä


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 8:29 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
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:

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Fri Nov 25, 2011 9:58 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
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ä


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Sat Nov 26, 2011 12:48 am 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
Is this it? I couldnt find any match to "shop", but "rand" found this:
Code:
SET temp = ( rand / 3 )
SET temp = ( temp * 3 )
SET rand = ( rand - temp )

How is that random? youre doing exactly this:
Code:
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

_________________
My GTA2 related projects:


Last edited by T.M. on Sat Nov 26, 2011 12:53 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Sat Nov 26, 2011 11:03 am 
Offline
User avatar

Joined: Fri Apr 24, 2009 9:43 pm
Posts: 407
Location: Estonia
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.


Top
 Profile  
 
 Post subject: Re: Code Snippets
PostPosted: Sat Nov 26, 2011 2:30 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
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.

_________________
My GTA2 related projects:


Top
 Profile  
 
PostPosted: Sat May 19, 2012 7:21 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
CarThief wrote:
Cause explosion on Player when pressing Car Horn:
Code:
...

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ä


Top
 Profile  
 
 Post subject: Code Snippets
PostPosted: Thu Jun 28, 2012 12:39 am 
Offline
Hitman
User avatar

Joined: Thu Jan 19, 2012 8:13 pm
Posts: 115
Location: X95GO9M4IA48
can i create 2 phones in one map?
cuz when i compile it says symbol already declared answer_phone:

_________________
I.R.C Explanation : viewtopic.php?f=19&t=539
GTA2 DTD : viewtopic.php?f=5&t=546
Raef


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 9:04 am 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 825
Location: F21B3EED
you cant declare same named variable twice.

_________________
My GTA2 related projects:


Top
 Profile  
 
PostPosted: Mon Oct 15, 2012 6:10 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 933
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ä


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group