Hi there!
So I've been starting to mess around with the LUA scripting aspect of GG after getting, somewhat the hang of the engine otherwise.
I am by no means, as you would say, any good at this what so ever. But learning it is the fun bit in my opinion. Absolutely come with feedback and improvements, I know a lot of this probably already exists out there already, but as I said I'm new to this.
All of these scripts depends on another function which detects if player is looking at an object, it is made by Smallg and can be found here: https://forum.game-guru.com/thread/207801?page=1HERE
So enough of all that, here are the aforementioned scripts:
Text on use
g_name = {}
function textonuse_init_name(e,name)
g_name[e] = name
end
function textonuse_main(e)
if PlayerLooking(e, 50,5) == 1 and g_KeyPressE == 0 then TextCenterOnX(50,68,1,"Hold E to interact")
end
if PlayerLooking(e, 100,10) == 1 and g_KeyPressE == 1
then TextCenterOnX(50,68,1,g_name[e])
end
end
This script allows you to push "E" on an entity and it will display the entities name, my reason for making this was a simple note reading system. In the current code you see up there in prompts you to "Hold E to interact"(You can change that) and that text will then change to the name of the entity when you hold down E, which would be the contents of said note.
Put the script in your scriptbank and call it "textonuse.lua". Add the script to the item and make sure it is not static!
Better doors
function door2_init(e)
end
function door2_main(e)
if PlayerLooking(e,100,30) == 1 and g_PlayerHealth > 0 then
GetEntityPlayerVisibility(e)
if 1 then
if g_Entity[e]['activated'] == 0 then
if g_Entity[e]['haskey'] == -1 then
SetActivated(e,1)
else
if g_Entity[e]['plrvisible'] == 1 then
if g_Entity[e]['haskey'] == 1 then
if GetGamePlayerStateXBOX() == 1 then
Prompt("The door is locked. Press Y button to unlock door")
else
Prompt("The door is locked. Press E key to unlock door")
end
if g_KeyPressE == 1 then
SetActivated(e,1)
end
else
Prompt("The door is locked. Find a key to unlock door")
end
end
end
else
if g_Entity[e]['activated'] == 1 then
-- door is unlocked and closed
if g_Entity[e]['plrvisible'] == 1 then
if GetGamePlayerStateXBOX() == 1 then
Prompt("Press Y button to open door")
else
Prompt("Press E to open door")
end
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
SetAnimation(0)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
SetActivated(e,2)
ActivateIfUsed(e)
PlaySound(e,0)
StartTimer(e)
g_Entity[e]['timer'] = g_Time
door_pressed = 1
end
end
else
if g_Entity[e]['activated'] == 2 then
-- door is open
if g_Entity[e]['plrvisible'] == 1 then
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
SetAnimation(1)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
SetActivated(e,1)
PlaySound(e,1)
CollisionOn(e)
door_pressed = 1
end
end
end
end
end
end
end
if g_Entity[e]['activated'] == 2 then
-- door collision off after 1 second
if GetTimer(e)>1000 then
CollisionOff(e)
end
end
if g_KeyPressE == 0 then
door_pressed = 0
end
end
Just the regular door script, but using the PlayerLooking function mentioned earlier.
This should be called "door2.lua".
Manual Health Pickup
function health_manual_init(e)
end
function health_manual_main(e)
if PlayerLooking(e,50,5) == 1 and g_PlayerHealth > 0 then
TextCenterOnX(50,68,1,"Press E to heal yourself")
if g_KeyPressE == 1 then
PlaySound(e,0)
AddPlayerHealth(e)
Destroy(e)
ActivateIfUsed(e)
end
end
end
Makes it so that you get a prompt when you are looking at the health item, same as with the text on use. And you use E to consume the item instead of automatically picking it up when close. This should be called "health_manual.lua".
Hopefully this is of some use to someone, I would love some feedback on them. I am having fun learning scripting in GG and will continue with that, so this list will most likely get expanded and improved. If you have any suggestions/requests on what I should work on next tell me below.
K. Bye!