Quantcast

Jump to content

» «
Photo

[DOC] LUA scripting help

168 replies to this topic
FunGt
  • FunGt

    GTA-Modding.com

  • Members
  • Joined: 10 Jun 2005
  • Italy

#1

Posted 23 December 2008 - 03:09 PM Edited by FunGt, 05 July 2009 - 04:50 PM.

CODE
GK: Please post any help relating to LUA here, any topics that arent posted here will be locked.

-no requests

thanks


Post here problems releated to LUA, the new script language that we can use with Alice by Alexander. I'm not the one that can help, I created this topic to keep the forum tidy.


Useful links:

Ricksta
  • Ricksta

    Homeboy

  • Members
  • Joined: 17 Sep 2006

#2

Posted 23 December 2008 - 03:24 PM

Ok i am trying to make a gravity toggle, this is as far as I have got but it only turns gravity off when I press tab, it doesn't turn it back off when i press tab again.

Note: Template was from TRASE's clear wanted level script.


CODE
---------- GTA IV Alice "Clear Wanted Level" script example ----------
---------- © -TR45e- 2008 ----------
-- Save key is TAB
--global variables
PLAYER_ID, PLAYER_INDEX, PLAYER_CHAR, SAVEDONE, TIMER = 0

function InitScript()
-- blah-blah-blah
Wait(10000)
end

function WaitForPlayerPoolCreation()
while (IsPlayerPoolCreated() == 0) do
 Wait(2000)
end
end

function WaitForValidPlayer()
PLAYER_CHAR = 0
repeat
 CallNative("GET_PLAYER_ID")
PLAYER_ID = GetIntResult()
if (PLAYER_ID >= 0) then
PushInt(PLAYER_ID)
CallNative("CONVERT_INT_TO_PLAYERINDEX")
PLAYER_INDEX = GetIntResult()
PushInt(PLAYER_INDEX)
   PushVarPtr()
CallNative("GET_PLAYER_CHAR")
PLAYER_CHAR = GetIntParam(1)
if (PLAYER_CHAR <= 0) then
  Wait(1000)
end  
end
until (PLAYER_CHAR > 0)  
end

function gravityon()
SAVEDONE = 0
TIMER = 0
PushInt(1)
CallNative("SET_GRAVITY_OFF")
Wait(1000)
while (SAVEDONE == 0) and (TIMER < 10000) do
 TIMER = TIMER + 100
Wait(100)
SAVEDONE = GetIntResult()
end
end

function gravityoff()
SAVEDONE = 0
TIMER = 0
PushInt(0)
CallNative("SET_GRAVITY_OFF")
Wait(1000)
while (SAVEDONE == 0) and (TIMER < 10000) do
 TIMER = TIMER + 100
Wait(100)
SAVEDONE = GetIntResult()
end
end

function main()
InitScript()
while true do
 if (IsKeyPressed(9) == 1) then
WaitForPlayerPoolCreation()
   WaitForValidPlayer()
   if (IsKeyPressed(9) == 1) then
  gravityon()
  Wait(10)
end
 end  
Wait(10)
end
end

function main()
InitScript()
while true do
 if (IsKeyPressed(9) == 1) then
WaitForPlayerPoolCreation()
   WaitForValidPlayer()
   if (IsKeyPressed(9) == 1) then
  gravityon()
  Wait(10)
end
 end  
Wait(10)
end
end

-- start
main();

Intosia
  • Intosia

    I'm random! ^^

  • Members
  • Joined: 11 Dec 2008

#3

Posted 23 December 2008 - 03:24 PM Edited by Intosia, 23 December 2008 - 03:26 PM.

You cant have 2 Main() functions....

Anyway, nothing works for me though...

-TRASE-
  • -TRASE-

    Punk-ass Bitch

  • Members
  • Joined: 07 Feb 2008

#4

Posted 23 December 2008 - 03:26 PM

Ok. i want to ask about Natives.

When i see
CODE
SET_PLAYER_INVINCIBLE=[SIZE=7]2[/SIZE], False


this mean in the script there needs to be two PushInt?

and what do false/true mean? if TRUE is it mean that i can toggle it on or off?

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#5

Posted 23 December 2008 - 03:27 PM

[Q]:If I want Spawn something, Ex: Ctrl+1 To get A weapon,What code did i use?

[Q|2]:What is the List Of the Pressed Key?

-TRASE-
  • -TRASE-

    Punk-ass Bitch

  • Members
  • Joined: 07 Feb 2008

#6

Posted 23 December 2008 - 03:28 PM

Ricksta, add another function to enable the gravity



Intosia
  • Intosia

    I'm random! ^^

  • Members
  • Joined: 11 Dec 2008

#7

Posted 23 December 2008 - 03:28 PM

QUOTE (-TRASE- @ Dec 23 2008, 15:26)
Ok. i want to ask about Natives.

When i see
CODE
SET_PLAYER_INVINCIBLE=[SIZE=7]2[/SIZE], False


this mean in the script there needs to be two PushInt?

and what do false/true mean? if TRUE is it mean that i can toggle it on or off?

I can be Int or Floats. The first would be Player_ID, the second a Int (True/False). But you can only guess what the params should be i guess...

That True or False means if the function returns a value or not. Its all in the Readme.txt btw...

Ricksta
  • Ricksta

    Homeboy

  • Members
  • Joined: 17 Sep 2006

#8

Posted 23 December 2008 - 03:33 PM

QUOTE (-TRASE- @ Dec 23 2008, 15:28)
Ricksta, add another function to enable the gravity

How? I'm thick as sh*t!
I don't even see a D or 13 for TAB on you're script so how are you even using TAB to get rid of the police? sad.gif this is hard.

sjaak327
  • sjaak327

    Big Homie

  • Feroci Racing
  • Joined: 01 Dec 2008
  • None

#9

Posted 23 December 2008 - 03:46 PM

IsKeyPressed(9) is the part where you define the key in this case tab =9, for instance backspace would be 8 if I'm not mistaken.

That code might need to be cleaned up, as there are still parts of the orignal save function there that surely aren't needed to clear your wanted level smile.gif




FunGt
  • FunGt

    GTA-Modding.com

  • Members
  • Joined: 10 Jun 2005
  • Italy

#10

Posted 23 December 2008 - 03:53 PM

QUOTE (sjaak327 @ Dec 23 2008, 16:46)
IsKeyPressed(9) is the part where you define the key in this case tab =9, for instance backspace would be 8 if I'm not mistaken.

That code might need to be cleaned up, as there are still parts of the orignal save function there that surely aren't needed to clear your wanted level smile.gif

Where can I find the list of IsKeyPressed numbers? How can I know what number to choose for a keyboard button?

-TRASE-
  • -TRASE-

    Punk-ass Bitch

  • Members
  • Joined: 07 Feb 2008

#11

Posted 23 December 2008 - 03:53 PM Edited by -TRASE-, 23 December 2008 - 03:56 PM.

Turning gravity is sure working, and its f*cking hilarius! biggrin.gif biggrin.gif biggrin.gif biggrin.gif but i cant turn it off... i used

CODE

function gravon()
 PushInt(1)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end

function Sgravoff()
 PushInt(0)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end


gravoff didnt work. no lua errors

Alexander Blade
  • Alexander Blade

    Come As You Are

  • Members
  • Joined: 05 Nov 2006

#12

Posted 23 December 2008 - 04:01 PM

QUOTE (FunGt @ Dec 23 2008, 15:53)
QUOTE (sjaak327 @ Dec 23 2008, 16:46)
IsKeyPressed(9) is the part where you define the key in this case tab =9, for instance backspace would be 8 if I'm not mistaken.

That code might need to be cleaned up, as there are still parts of the orignal save function there that surely aren't needed to clear your wanted level smile.gif

Where can I find the list of IsKeyPressed numbers? How can I know what number to choose for a keyboard button?

try to search for "Virtual Key Codes"

Flaii
  • Flaii

    Player Hater

  • Members
  • Joined: 21 Dec 2008

#13

Posted 23 December 2008 - 04:17 PM

QUOTE (-TRASE- @ Dec 23 2008, 15:53)
Turning gravity is sure working, and its f*cking hilarius! biggrin.gif biggrin.gif biggrin.gif biggrin.gif but i cant turn it off... i used

CODE

function gravon()
 PushInt(1)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end

function Sgravoff()
 PushInt(0)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end


gravoff didnt work. no lua errors

Can you post the full code?

I want to try it out and see how its built.

ZomBuster
  • ZomBuster

    Player Hater

  • Members
  • Joined: 04 Dec 2008

#14

Posted 23 December 2008 - 04:17 PM

No wait this is what you need for the keys

http://delphi.about....ide/l/blvkc.htm

adhome
  • adhome

    Crackhead

  • Members
  • Joined: 06 Dec 2008

#15

Posted 23 December 2008 - 05:02 PM Edited by adhome, 23 December 2008 - 05:12 PM.

Perhaps we can fist find out, how to spawn a car (by Name or index)

I found this interesting functions:
GET_SPAWN_COORDINATES_FOR_CAR_NODE=6, False
GET_CAR_MODEL=2, False
CREATE_CAR=6, False
GET_RANDOM_CAR_NODE=9, True
GET_RANDOM_CAR_MODEL_IN_MEMORY=3, False

CREATE_CAR_GENERATOR=15, False is perhaps to complicated.

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#16

Posted 23 December 2008 - 05:02 PM

Doesn't work
QUOTE
---------- GTA IV Alice "WeaponSpawn" script example ----------
---------- © Alexander Blade 2008 ----------
--Numpad 1 to spawn weapon
--global variables
  PLAYER_ID, PLAYER_INDEX, PLAYER_CHAR = 0

function InitScript()
  -- blah-blah-blah
  Wait(10000)
end

function WaitForPlayerPoolCreation()
  while (IsPlayerPoolCreated() == 0) do
    Wait(2000)
  end
end

function WaitForValidPlayer()
  PLAYER_CHAR = 0
  repeat
    CallNative("GET_PLAYER_ID")
PLAYER_ID = GetIntResult()
if (PLAYER_ID >= 0) then
  PushInt(PLAYER_ID)
  CallNative("CONVERT_INT_TO_PLAYERINDEX")
  PLAYER_INDEX = GetIntResult()
  PushInt(PLAYER_INDEX)
      PushVarPtr()
  CallNative("GET_PLAYER_CHAR")
  PLAYER_CHAR = GetIntParam(1)
  if (PLAYER_CHAR <= 0) then
    Wait(1000)
  end 
end
  until (PLAYER_CHAR > 0) 
end

function SetPlayerProperties()
  PushInt(PLAYER_INDEX)
  PushInt(1)
  CallNative("ENABLE_MAX_AMMO_CAP")
  GiveWeapon(6)
end

function main()
  InitScript()
  while true do
    if (IsKeyPressed(60) == 1) then
  WaitForPlayerPoolCreation()
    WaitForValidPlayer()
    if (IsKeyPressed(60) == 1) then
    giveweapon()
    Wait(2000)
  end
  end 
Wait(300)
end
end

-- start
main();

Doesn't do anything

Andrew
  • Andrew

  • Andolini Mafia Family
  • Joined: 21 Jul 2003
  • None

#17

Posted 23 December 2008 - 05:07 PM

Good idea FunGT. I've edited the top post to mention that any outside of this topic get locked.

alecto123
  • alecto123

    Player Hater

  • Members
  • Joined: 19 Dec 2008

#18

Posted 23 December 2008 - 05:39 PM

QUOTE (Flaii @ Dec 23 2008, 16:17)
QUOTE (-TRASE- @ Dec 23 2008, 15:53)
Turning gravity is sure working, and its f*cking hilarius!  biggrin.gif   biggrin.gif   biggrin.gif   biggrin.gif   but i cant turn it off... i used

CODE

function gravon()
 PushInt(1)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end

function Sgravoff()
 PushInt(0)
 CallNative("SET_GRAVITY_OFF")
 Wait(1000)
end


gravoff didnt work. no lua errors

Can you post the full code?

I want to try it out and see how its built.

Maybe it would work if you create a separate script to enable gravity using a different key.

Intosia
  • Intosia

    I'm random! ^^

  • Members
  • Joined: 11 Dec 2008

#19

Posted 23 December 2008 - 06:02 PM

QUOTE (ZomBuster @ Dec 23 2008, 16:17)
No wait this is what you need for the keys

http://delphi.about....ide/l/blvkc.htm

Watched out those codes are in HEX make em DEC smile.gif

berbatov
  • berbatov

    Player Hater

  • Members
  • Joined: 15 Dec 2008

#20

Posted 23 December 2008 - 06:03 PM

"ENABLE_SHADOWS=$009b9eb0" in natives config file..

so is there a way closing shadows now pls ? ( i have no idea lua scripting smile.gif )

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#21

Posted 23 December 2008 - 06:15 PM

Yes!My Weapon Spawner Are Completed!
If you Want It ,Just Say,I don Want Banned

Flaii
  • Flaii

    Player Hater

  • Members
  • Joined: 21 Dec 2008

#22

Posted 23 December 2008 - 06:45 PM

QUOTE (aceship @ Dec 23 2008, 18:15)
Yes!My Weapon Spawner Are Completed!
If you Want It ,Just Say,I don Want Banned

I'm interested, post it here or send me a PM with it, thanks!

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#23

Posted 23 December 2008 - 06:51 PM Edited by aceship, 28 December 2008 - 05:47 PM.

QUOTE
---------- GTA IV Alice "WeaponSpawn" script example ----------
---------- © Alexander Blade 2008 ----------
--middle button to spawn weapon
--global variables
  PLAYER_ID, PLAYER_INDEX, PLAYER_CHAR = 0

function InitScript()
  -- blah-blah-blah
  Wait(10000)
end

function WaitForPlayerPoolCreation()
  while (IsPlayerPoolCreated() == 0) do
    Wait(2000)
  end
end

function WaitForValidPlayer()
  PLAYER_CHAR = 0
  repeat
    CallNative("GET_PLAYER_ID")
PLAYER_ID = GetIntResult()
if (PLAYER_ID >= 0) then
  PushInt(PLAYER_ID)
  CallNative("CONVERT_INT_TO_PLAYERINDEX")
  PLAYER_INDEX = GetIntResult()
  PushInt(PLAYER_INDEX)
      PushVarPtr()
  CallNative("GET_PLAYER_CHAR")
  PLAYER_CHAR = GetIntParam(1)
  if (PLAYER_CHAR <= 0) then
    Wait(1000)
  end 
end
  until (PLAYER_CHAR > 0) 
end

function GiveWeapon(Num)
  PushInt(PLAYER_CHAR)
  PushInt(Num)
  CallNative("HAS_CHAR_GOT_WEAPON")
  if (GetIntResult() == 0)
  then
    PushInt(PLAYER_CHAR)
    PushInt(Num)
    PushInt(30000)
    PushInt(0)
    CallNative("GIVE_WEAPON_TO_CHAR")
  else
    PushInt(PLAYER_CHAR)
PushInt(Num)
PushInt(30000)
CallNative("SET_CHAR_AMMO")
  end
end

function SetPlayerProperties()
  PushInt(PLAYER_INDEX)
  PushInt(0)
  CallNative("ENABLE_MAX_AMMO_CAP")
  GiveWeapon(6)
end
 
function main()
  InitScript()
  while true do
    if (IsKeyPressed(04) == 1) then
  WaitForPlayerPoolCreation()
      WaitForValidPlayer()
      if (IsKeyPressed(04) == 1) then
    SetPlayerProperties()
    Wait(2000)
  end
    end 
Wait(300)
  end
end

-- start
main();

if you want
Chance Giveweapon(Num)
Num:
QUOTE

Giveweapon(num)
1:Baseball bat
2:Pool Cue
3:Knife
4:Grenade
5:Molotov
6:Rocket
7:Glock Pistol
8:don't know yet
9:deagle
10:Shotgun
11:barreta shotgun
12:uzi
13:mp5
14:ak
Edit:
15:m4
16:Sniper rifle
17:M401a Sniper
18:rocket launcher

Thanks for ilidan for the quick respond

Edit:
QUOTE

21:episodic_1
|       
44:episodic_24


FunGt
  • FunGt

    GTA-Modding.com

  • Members
  • Joined: 10 Jun 2005
  • Italy

#24

Posted 23 December 2008 - 06:52 PM

QUOTE (aceship @ Dec 23 2008, 19:15)
Yes!My Weapon Spawner Are Completed!
If you Want It ,Just Say,I don Want Banned

Upload here.

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#25

Posted 23 December 2008 - 06:55 PM Edited by aceship, 23 December 2008 - 07:28 PM.

already Posted,
[Q]how to change The ammo,it seems to be unlimited when use it
[Q2]Can i use a combo like this?:
QUOTE

(IsKeyPressed(11) == 1) And (IsKeyPressed(30) == 1) then

Oh,Can Anyone search the Unused0 and episodic_1-24 Weapon code?
It can be a discovery for who Editing the weapon

adhome
  • adhome

    Crackhead

  • Members
  • Joined: 06 Dec 2008

#26

Posted 23 December 2008 - 07:24 PM Edited by adhome, 23 December 2008 - 08:10 PM.

Found SET_TIME_SCALE and I set it to 10.0
It wasa great. You run very fast and alle Cars drive fast and so....
With low parameter all was in slow motion. Looks very great.

I tried a script with float variable. But i get allways error 1 on start game.

How can i use float variable ?

CODE

DELETED beacause it was wrong


PushFloat(2.0)
CallNative("SET_TIME_SCALE")

was working!

aceship
  • aceship

    Just An Indonesian Scripter

  • Members
  • Joined: 20 Dec 2008

#27

Posted 23 December 2008 - 07:30 PM Edited by aceship, 23 December 2008 - 07:37 PM.

I think You should change The "Save everywhere" Title,It can Make People Confused,
Edit:
What is"EXPLODE_CHAR_HEAD"
Is this exploding the character Head?
it will Be a ZOMBIE Game!

Shadow-Link
  • Shadow-Link

    Li'l G Loc

  • Members
  • Joined: 01 Dec 2004

#28

Posted 23 December 2008 - 07:42 PM Edited by Prince-Link, 23 December 2008 - 07:52 PM.

Does anyone know how to get the Car the player is currently driving?

I've tried this code:
CODE

function getPlayerCar()
 PLAYER_CAR = 0
 repeat
   PushInt(PLAYER_CHAR)
   PushVarPtr()
   CallNative("GET_CAR_CHAR_IS_USING")
   PLAYER_CAR = GetIntParam(1)
   if (PLAYER_CAR <= 0) then
     Wait(1000)
   end
 until (PLAYER_CAR > 0)
end


With a global var: PLAYER_CAR

EDIT: Nevermind it works smile.gif

adhome
  • adhome

    Crackhead

  • Members
  • Joined: 06 Dec 2008

#29

Posted 23 December 2008 - 07:50 PM Edited by adhome, 23 December 2008 - 08:10 PM.

Found my misstake. In Top I must write "=0"

I will release a corrected version in other Forum. Will look and feel great (;

http://www.gtaforums...howtopic=386995

BeatFK
  • BeatFK

    Kill the Beat My man

  • Members
  • Joined: 17 Dec 2008

#30

Posted 23 December 2008 - 08:29 PM

aceship, I don't understand exactly how your LUA works.


I have created a "WeaponSpawn.lua" in my Alice folder and copy your code inside


and then what do I have to do ?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users