Welcome to Open Carnage

A resource for Halo 1 modding and tech, with unique means of rewarding individual content creation and support. Have a wander to see why we're worth the time! EST. 2012

Sign in to follow this  
Followers 0
Deafboy91

Help With LUA Script

Hello,

 

Not sure where to post.

 

So I'm bit need help with lua script. Transferred from events.txt. I done write it up and console said failed to load gunner_race.lua

It about player spawned with driveable gunner which will do both race and gunning rocket.

When player exit vehicle, server will respawned hog and force player to return it to gunner seat.

Once player die, server will delete vehicle assigned to player and have it respawn when player respawn. (avoid create too many hogs)

Also when player left the server, it will delete vehicle assigned to him.

 

**New that not include events.txt where if server respawned and forced player to get in gunner at bad location which will stuck such as wall. I tried to set variable for coordination x, y, z then wait for 3 second that set separate variable of coordination. Then if both variables of x, y, and z are equal then that will be mostly likely stuck. Which server will kill player whom are stuck.

 

So any idea what wrong with it?

 

Thanks in advance and sorry for noob english.

DB

 

lua script

api_version = "1.4.0.0"
game_running = false

local clock = os.clock
local function sleep(n)
  local t0 = clock()
  while clock() - t0 <= n do end
end

function OnScriptLoad()
    register_callback(cb['EVENT_GAME_START'], "GameStart")
    register_callback(cb['EVENT_GAME_END'], "GameEnd")
	register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
	register_callback(cb['EVENT_VEHICLE_EXIT'], "ExitVehicle")
	register_callback(cb['EVENT_DIE'], "PlayerDied")
	register_callback(cb['EVENT_LEAVE'], "PlayerLeave")
end


function OnScriptUnload()
 
end


function GameStart() 
	if(get_var(1, $mode) == "RRv2") then
		excute_command('disable_all_objects 0 1')
		excute_command('Rider_ejection 0')
		game_running = true 
	end
end
	

function GameEnd() 
	if(game_running == 1) then
		execute_command('disable_all_objects 0 0')
		execute_command('Rider_ejection 1')
		game_running = false
	end
end


function OnPlayerSpawn(PlayerIndex)
	if(game_running == 1) then
		execute_command('wdel ' ..PlayerIndex..)
		execute_command('spawn vehi "vehicles\rwarthog\rwarthog" ' ..PlayerIndex..)
		execute_command('venter ' ..PlayerIndex.. ' 0')
		execute_command('venter ' ..PlayerIndex.. ' 2')
	end
end

function ExitVehicle(PlayerIndex)
	if(game_running == 1) then
		execute_command('vdel ' ..PlayerIndex..)
		execute_command('spawn vehi "vehicles\rwarthog\rwarthog" ' ..PlayerIndex..)
		execute_command('venter ' ..PlayerIndex.. ' 0')
		execute_command('venter ' ..PlayerIndex.. ' 2')
		sleep(3)
		local xcoord = get_var(PlayerIndex, "$x")
		local ycoord = get_var(PlayerIndex, "$y")
		local zcoord = get_var(PlayerIndex, "$z")
		sleep(5)
		local xcoord2 = get_var(PlayerIndex, "$x")
		local ycoord2 = get_var(PlayerIndex, "$y")
		local zcoord2 = get_var(PlayerIndex, "$z")
			if(xcoord == xcoord2) then
				if (ycoord == ycoord2) then
					if (zcoord == zcoord2) then
						execute_command('kill ' ..PlayerIndex.. )
						say(PlayderIndex,"You were killed because you stuck after hog respawn.")
					end
				end
			end
		end
	end
end


function PlayerDied(PlayerIndex)
	if(game_running == 1) then
		execute_command('vdel ' ..PlayerIndex..)
	end
end
	

function PlayerLeave(PlayerIndex)
	if(game_running == 1) then
		execute_command('vdel ' ..PlayerIndex..)
	end
end

Events.txt (this transferred to lua script)

event_start $mode:RRv2 'disable_all_objects 0 1;Rider_ejection 0'
event_end $mode:RRv2 'disable_all_objects 0 0;Rider_ejection 1'
event_spawn $mode:RRv2 'wdel $n 0;wait 50;spawn vehi "vehicles\rwarthog\rwarthog" $n;venter $n 0;venter $n 2'
event_vexit $mode:RRv2 'w8 1;vdel $n;spawn vehi "vehicles\rwarthog\rwarthog" $n;venter $n 0;venter $n 2'
event_die $mode:RRv2 'w8 1;vdel $n'
event_leave $mode=RRv2 'w8 1;vdel 0'

KlGKKLH.png


System specs: Fatal1ty P67 Pro. with i7-2600k 4.5GHz, 16GB RAM, Windows 10 Pro 64-bit, Nvidia GTX 970 4GB SC

Share this post


Link to post
Share on other sites

Members of Open Carnage never see off-site ads.

So any idea what wrong with it?

It's good that you ask for help.

 

-- Line 26
if(get_var(1, $mode) == "RRv2") then
On line 26, you forgot quotations for "$mode".

 

-- Line 45
execute_command('wdel ' ..PlayerIndex..)
execute_command('spawn vehi "vehicles\rwarthog\rwarthog" ' ..PlayerIndex..)

-- Line 54
execute_command('vdel ' ..PlayerIndex..)
execute_command('spawn vehi "vehicles\rwarthog\rwarthog" ' ..PlayerIndex..)

-- Line 69
execute_command('kill ' ..PlayerIndex.. )

-- Line 81
execute_command('vdel ' ..PlayerIndex..)

-- Line 88
execute_command('vdel ' ..PlayerIndex..)

On line 45, 46, 54, 55, 69, 81, and 88 you should remove the .. on the right side of each ..PlayerIndex.. as the interpreter doesn't see anything after the .. to combine with PlayerIndex.

Lastly, you should also remove the extra "end" on line 76. You seemed to have mistaken line 66 as the beginning of a block.

Doing everything I mentioned above of these should make your script no longer fail to load (if it doesn't, post the new script and I'll see if you missed anything), but there's two other problems you might want to fix.

Lua is interpreting the backslashes in your script as escape characters. You will need to replace all backslashes in your script with two backslashes so the Lua interpreter knows it's a backslash.

e.g.: spawn vehi "vehicles\rwarthog\rwarthog" should be spawn vehi "vehicles\\rwarthog\\rwarthog"

This problem doesn't necessarily make your script unreadable, but it will cause errors as the Lua interpreter will misread the strings.

Server scripts are handled on the same thread as the server, thus using your sleep() function will block the thread, making the server unresponsive until the sleep() function finishes. I recommend you also check out the timer system. http://xhalo.tk/lua-scripting

The syntax is timer(milliseconds,callback[,optional arguments...]) and you return true to repeat the timer or false to not repeat the timer.

 

Here's an example:

 

function SomeFunction()
    timer(1000,"SaySomethingInOneSecond","hi")
end

function SaySomethingInOneSecond(what_to_say)
    say_all(what_to_say)
    return false -- do not repeat the function
end
Edited by 002

Share this post


Link to post
Share on other sites

Thanks for reply,

 

I managed to get it working. However, while testing it I attempted to get stuck and nothing happened. (supposed to get killed if both coordination variables I set are matched between five seconds).

Look at start line 52 with ExitVehicle function along with timers.

 

http://privatepaste.com/3c1fa9e25c

 

 

Cheers,

DB

 

 


KlGKKLH.png


System specs: Fatal1ty P67 Pro. with i7-2600k 4.5GHz, 16GB RAM, Windows 10 Pro 64-bit, Nvidia GTX 970 4GB SC

Share this post


Link to post
Share on other sites

The reason why it may be stuck is that you're using local variables xcoord, ycoord, and zcoord, which are lost once the function that declared it has completed. You should pass these on these as arguments into your next timer if you want to use them in the FiveSecond function.

Example:

-- Line 71
timer(5000,"FiveSecond",PlayerIndex,xcoord,ycoord,zcoord)

-- Line 76
function FiveSecond(PlayerIndex,xcoord,ycoord,zcoord)

Let me know how that works.

Share this post


Link to post
Share on other sites

Hello,

 

It ran great edited with some of your advice. However there's still a problem I can't figure out.

 

For starter, while using this script on a specified gametype, sometimes players get stuck respawn the hog outside of map or wall. Player quit while timer was still counting which caused a server crash. I think that was bug where term "Quit" on scoreboard stuck even through player already quit.

 

Here meh window log, I don't turn log on to collect from server.

Dunno if helpful.

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	haloded.exe
  Application Version:	1.0.10.621
  Application Timestamp:	537267fc
  Fault Module Name:	haloded.exe
  Fault Module Version:	1.0.10.621
  Fault Module Timestamp:	537267fc
  Exception Code:	c0000005
  Exception Offset:	000fc8d3
  OS Version:	6.2.9200.2.0.0.400.8
  Locale ID:	1033
  Additional Information 1:	5861
  Additional Information 2:	5861822e1919d7c014bbb064c64908b2
  Additional Information 3:	1a2a
  Additional Information 4:	1a2aa8e38ac8adbb6fe1e594fa623c2e

Here's the updated script: http://privatepaste.com/f78267b6f5


KlGKKLH.png


System specs: Fatal1ty P67 Pro. with i7-2600k 4.5GHz, 16GB RAM, Windows 10 Pro 64-bit, Nvidia GTX 970 4GB SC

Share this post


Link to post
Share on other sites

I have seen this "Quit" bug only once before in phasor servers: when fall damage is set to  zero or false instead of a very small amount: odl_multiplier(0.001).

 

at the end of your script,

function PlayerLeave(PlayerIndex)
	if(game_running == true) then
		execute_command('vdel ' ..PlayerIndex)
	end
end

You might need to do 2 checks: determine if the player index is valid, and determine if their vehicle is valid, then delete/destroy the valid vehicle.
 
Instead of checking the players coordinates on exit as you do, I run a global timer (phasor) once per second:

function Check_All_Players(ids, count)
    if game_started then
        for i=0,15 do
            if getplayer(i) then
                local m_objectId = getplayerobjectid(i)
                local m_vehicleId = getplayervehicleid(i)
                if m_objectId then
                    local m_object = getobject(m_objectId)
                    if m_object then
                        local m_vehicle = getobject(readdword(m_object + 0x11C))
                        if m_vehicle then
                            m_object = m_vehicle
                        end                
                        local OutOfMap = readbit(m_object + 0x10, 21)
                        if OutOfMap then
                            if m_vehicleId ~= 0xFFFFFFFF then
                                destroyobject(m_vehicleId)
                            end
                            kill(i)    
                            privatesay(i, "The server killed you because you were stuck.")
                        end
                    end                                
                end    
            end
        end    
        return true
    else
        return false
    end        
end

function getplayervehicleid(player) -- returns vehicle object id player is in
    local m_objectId = getplayerobjectid(player)
    if m_objectId then return readdword(getobject(m_objectId) + 0x11C) end
end

Notice the offset: OutOfMap = readbit(m_object + 0x10, 21) - not sure if you can use it in SAPP -  If the player and/or players vehicle is out of the map, I first check to see if it's valid then destroy it, then kill the player

 

Hope this helps in some small way

Edited by NerveBooger

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.