Advertisement
julioCCs

GTA iV - Simple effect example

Sep 15th, 2012
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.93 KB | None | 0 0
  1. 'http://www.facebook.com/GtaIVScripting
  2. 'https://www.youtube.com/user/GTAScripting
  3.  
  4. ' Effect example by JulioNIB
  5. ' my english is "game/tv learned", sorry for the possible errors
  6.  
  7. Imports System ' basic imports
  8. Imports GTA ' basic imports
  9. Imports System.Windows.Forms ' needed to have access to "keys" enumeration, for example
  10.  
  11. Public Class MBisonExample
  12.     Inherits Script
  13.    
  14.     Public Sub New()
  15.         Me.interval = 10 ' the script interval for "tick" event, not used on this example
  16.     End Sub
  17.    
  18.     ' this just make easier to print a msg on the screen   
  19.     private sub msg(sMsg as string, time as int32)
  20.         Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", sMsg, time, 1)
  21.         ' Native.Function.Call executes an gta native function, in this example it calls PRINT_STRING_WITH_LITERAL_STRING_NOW
  22.         ' "STRING", sMsg, time, 1 are the parameters of the function
  23.     end sub
  24.        
  25.     ' this is an event, when the player press one key, this is called and you can see what key is pressed
  26.     ' basically used to set hotkeys
  27.     Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
  28.         if (e.key = keys.mbutton) then example ' if the key is middle mouse button (mbutton), calls the function "example"
  29.     End Sub
  30.    
  31.     Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
  32.         ' this can be used when you need to activate the hotkey only when the user releases the key
  33.     end sub
  34.    
  35.     ' this is the method that does the job
  36.     private sub example
  37.         ' check if the player is in a vehicle
  38.         ' if true, exits the function
  39.         ' you can use player.character.isInVehicle instead
  40.         if exists(player.character.currentvehicle) then exit sub
  41.         ' one more thing, "player" is an object that represents the user, "character" is an object that represents the
  42.         ' pedestrian, "currentvehicle" is an object that represents the ped's vehicle
  43.         ' the "exists()" is a function that checks if an object exists, in this case, check if "currentvehicle" exists 
  44.        
  45.         ' "dim" defines an variable, an variable can be an number (int16, int32, double), an game object (animationset, vehicle, ped, etc), an string, etc
  46.         ' the Dim variables are only visible inside the block where it is, an method, an If, an While, etc
  47.         dim animSet as animationset = new animationset("missfinale2d") ' defines an animationset, that is needed to execute the "playanimation"
  48.             ' and determines the category of the animation ("missfinale2d")
  49.         dim effectRH, effectLH as int32 ' to store the result of the function that make the effects on hands
  50.         dim vecAux as vector3 ' to be used in "applyforce" as second parameter, defining the rotation of the force
  51.         dim c as int16 = 1 ' just a counter to control the duration of the "fly"
  52.        
  53.         vecAux.z = 2 ' defines the Z rotation of the force (Roll? i dont remember now)
  54.         ' this vecAux can be replaced by an (vector3.worldup * 2) in the function calls, will result in the same
  55.        
  56.         ' "makeproofto" defines some proofTo habilities, in this case he is like god
  57.         ' parameters: Bullets, Fire, Explosions, FallingDamage, MeleeAttacks
  58.         player.character.makeproofto(true, true, true, true, true)
  59.        
  60.         ' calls the native function that starts the effect in hands
  61.         ' the parameters are: effect name(ambient_fire_generic), pedestrian(Player.Character), offeset[x, y, z], rotation[x, y, z], ped bone and scale of the effect
  62.         effectRH = Native.Function.Call(of int32)("START_PTFX_ON_PED_BONE", "ambient_fire_generic", Player.Character, 0, 0, 0, 0, 0, 0, Bone.righthand, 1.0)
  63.         effectLH = Native.Function.Call(of int32)("START_PTFX_ON_PED_BONE", "dest_sparking_wires", Player.Character, 0, 0, 0, 0, 0, 0, Bone.lefthand, 0.5)
  64.        
  65.         ' starts the animation using the "task" object, we can use "animation" object instead
  66.         ' parameters: animSet(the category "missfinale2d"), the animation "jump_on_heli_alt", speed, flags
  67.         ' animationflags.unknown01 makes the ped dont return to his original position
  68.         ' animationflags.Unknown06 makes him stop on last frame of the animation
  69.         player.character.task.playanimation(animSet, "jump_on_heli_alt", 100.0, animationflags.unknown01 or animationflags.Unknown06)
  70.         ' wait an half second
  71.         wait(500)
  72.        
  73.         ' just show a message on screen for 2 seconds
  74.         msg("Die...", 2000)
  75.        
  76.         ' this is an loop, what is inside him will be executed while the condition is true
  77.         ' the condition is: the counter be less than 15
  78.         ' or else the middle mouse button key is pressed
  79.         while (c < 15) orelse game.iskeypressed(keys.mbutton)
  80.             wait(10) ' just an delay, helps to control the speed of the move and dont freeze the game ^^
  81.            
  82.             if not game.iskeypressed(keys.mbutton) then ' when the user just do a single click
  83.                 player.character.velocity = (player.character.direction * 20) ' makes the player move on the direction that he is
  84.                 ' "* 20" makes he goes more fast
  85.             else
  86.                 ' if the user is holding middle mouse button key
  87.                 ' will make it moves in the direction of the camera
  88.                 player.character.heading = game.currentcamera.heading ' heading is like direction but its in degrees
  89.                 player.character.velocity = (game.currentcamera.direction * 20)
  90.             end if
  91.            
  92.             ' here we get all peds that are close to player, checks if they are touching, if true, burn and thrown them
  93.             ' "world.getpeds()" is who finds the peds
  94.             ' params: position(player.character.position + player.character.direction), radius(3.0)
  95.             for each p as ped in world.getpeds(player.character.position, 3.0)
  96.                 if exists(p) andalso (player.character.istouching(p)) then
  97.                     p.velocity = player.character.direction * 10 ' push
  98.                     p.isonfire = true ' burn
  99.                 end if
  100.             next
  101.            
  102.             ' almost the same of above, but here i get and check the vehicles
  103.             for each v as vehicle in world.getvehicles(player.character.position, 5.0)
  104.                 if exists(v) andalso player.character.istouching(v) then                   
  105.                     v.applyforce(player.character.direction * 2, vecAux) ' apply the force
  106.                     ' first param is the direction of the force, second is the "rotation"
  107.                 end if
  108.             next
  109.            
  110.             c += 1 ' increases the counter
  111.         end while
  112.        
  113.         ' stop the effects, in this case is needed basically why the effect is permanent or too long
  114.         ' this is absolutely needed when you have to start various times the same effects
  115.         ' if you dont stop, the game will stop creating the effect after some time :(, and you will need to reopen the game
  116.         Native.Function.Call("STOP_PTFX", effectRH)
  117.         Native.Function.Call("STOP_PTFX", effectLH)
  118.        
  119.         ' at this moment the player is in air, frozen because of the use of the "animationflags.Unknown06" in animation
  120.         ' to fix it i call another animation that will make the player land on ground and roll
  121.         animSet = new animationset("jump_std")
  122.         player.character.task.playanimation(animSet, "jump_land_roll", 100.0, animationflags.unknown01)
  123.        
  124.         ' just a delay
  125.         wait(1000)
  126.         ' makes the player mortal again
  127.         player.character.makeproofto(false, false, false, false, false)
  128.     end sub
  129. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement