Jump to content

new ride.lua with LIB


Recommended Posts

Hello, I'm trying to make this ride.lua with a LIB. Which one the of the 2 versions do you think would be better?

ride.lua without LIB

Spoiler



quest ride begin
	state start begin
		function GetRideInfo(vnum)
			if ride.ride_info==nil then
				ride.ride_info = {
					[71114]= { ["mount_vnum"] = 20110,	["duration"] = 60*60*24*365,		["bonus_id"] = apply.DEF_GRADE_BONUS,	["bonus_value"] = 30,	["req_level"] = 30,	},
					[71116]= { ["mount_vnum"] = 20111,	["duration"] = 60*60*24*365,		["bonus_id"] = apply.DEF_GRADE_BONUS,		["bonus_value"] = 50,	["req_level"] = 30,	},-- Lupo Selvatico
					[71118]= { ["mount_vnum"] = 20112,	["duration"] = 60*60*24*365,		["bonus_id"] = apply.ATT_GRADE_BONUS,		["bonus_value"] = 40,	["req_level"] = 30,	},
					[71120]= { ["mount_vnum"] = 20113,	["duration"] = 60*60*24*365,		["bonus_id"] = apply.ATT_GRADE_BONUS,	["bonus_value"] = 70,	["req_level"] = 30,	},
				}
			end
			return ride.ride_info[vnum]
		end

		function Ride(vnum, remain_time)
			local mount_info = ride.GetRideInfo(vnum)
			if mount_info==nil then return end

			if pc.level < mount_info["req_level"] then
				syschat("Your level is too low.")
			else

				if 112 == pc.get_map_index() then -- duel map
					return
				end

				if remain_time==0 then
					if mount_info["duration"] <= 0 then
						if item.is_available0() then
							remain_time = item.get_socket(0)
						else
							remain_time = 60
						end
					else
						remain_time = mount_info["duration"]
					end
				end

				-- syschat("duration "..remain_time)
				-- syschat("socket1 "..item.get_socket(1))
				-- syschat("socket2 "..item.get_socket(2))
				pc.mount(mount_info["mount_vnum"], remain_time)
				pc.mount_bonus(mount_info["bonus_id"], mount_info["bonus_value"], remain_time)
			end
		end

		when login begin
			local vnum, remain_time = pc.get_special_ride_vnum()
			--syschat("remain_time "..remain_time)
			if vnum==0 then return end

			local mount_info = ride.GetRideInfo(vnum)
			if mount_info==nil then return end

			ride.Ride(vnum, remain_time)
		end

		when
			71114.use or 71116.use or 71118.use or 71120.use
		begin
			if pc.is_polymorphed() then
				syschat("Can't ride polymorphed.")
			elseif not pc.is_riding() then
				if horse.is_summon() then
					horse.unsummon()
				end
				ride.Ride(item.vnum, 0)
			else
				pc.unmount()
			end
		end

	end
end

 

 

I think i made some mistakes here but i can't understand where becuase it is not working

rideLIB.lua

Spoiler



rideLIB = {};

rideLIB.Settings(vnum) = function()
	if (rideLIB.data == nil) then
		rideLIB.data = {
			[71114]= {
			["mount_vnum"] = 20110,					["req_level"] = 30,
			["bonus_id_1"] = apply.DEF_GRADE_BONUS,	["bonus_value_1"] = 50,
			["bonus_id_2"] = apply.NONE,			["bonus_value_2"] = 0,
			["bonus_id_3"] = apply.NONE,			["bonus_value_3"] = 0, },
			
			[71116]= {
			["mount_vnum"] = 20111,					["req_level"] = 30,
			["bonus_id_1"] = apply.CRITICAL_PCT,	["bonus_value_1"] = 50,
			["bonus_id_2"] = apply.NONE,			["bonus_value_2"] = 0,
			["bonus_id_3"] = apply.NONE,			["bonus_value_3"] = 0, },
			
			[71118]= {
			["mount_vnum"] = 20112,					["req_level"] = 30,
			["bonus_id_1"] = apply.ATTBONUS_ORC,	["bonus_value_1"] = 50,
			["bonus_id_2"] = apply.NONE,			["bonus_value_2"] = 0,
			["bonus_id_3"] = apply.NONE,			["bonus_value_3"] = 0, },
			
			[71120]= {
			["mount_vnum"] = 20113,					["req_level"] = 30,
			["bonus_id_1"] = apply.ATT_GRADE_BONUS,	["bonus_value_1"] = 70,
			["bonus_id_2"] = apply.NONE,			["bonus_value_2"] = 0,
			["bonus_id_3"] = apply.NONE,			["bonus_value_3"] = 0, },
		}
	end
	
	return rideLIB.data[vnum]
end


rideLIB.Ride(vnum, remain_time) = function()
	local mount_info = rideLIB.Settings(vnum)
	if mount_info == nil then 
		return 
	end

	if pc.level < mount_info["req_level"] then
		syschat("Your level is too low.")
	else

	if 112 == pc.get_map_index() then -- duel map
		return
	end


	if remain_time == 0 then
		if 86400 <= 0 then
			if item.is_available0() then
				remain_time = item.get_socket(0)
			else
				remain_time = 60
			end
		else
			remain_time = 86400
		end
	end

	if mount_info["bonus_value_3"] > 0 then
		pc.mount(mount_info["mount_vnum"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_1"], mount_info["bonus_value_1"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_2"], mount_info["bonus_value_2"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_3"], mount_info["bonus_value_3"], remain_time)
		return
	elseif mount_info["bonus_value_2"] > 0 then
		pc.mount(mount_info["mount_vnum"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_1"], mount_info["bonus_value_1"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_2"], mount_info["bonus_value_2"], remain_time)
		return
	else
		pc.mount(mount_info["mount_vnum"], remain_time)
		pc.mount_bonus(mount_info["bonus_id_1"], mount_info["bonus_value_1"], remain_time)
	end

end

 

ride.lua with lib

Spoiler



quest ride begin
	state start begin

		when login begin
			local vnum, remain_time = pc.get_special_ride_vnum()
			if vnum == 0 then 
				return
			end
			local mount_info = rideLIB.Settings(vnum)
			if mount_info == nil then
				return
			end
			
			rideLIB.Ride(vnum, remain_time)
		end

		when
			71114.use or 71116.use or 71118.use or 71120.use 
		begin
			if pc.is_polymorphed() then
				syschat("Cant ride polymorphed.")
			elseif not pc.is_riding() then
				if horse.is_summon() then
					horse.unsummon()
				end
				rideLIB.Ride(item.vnum, 0)
			else
				pc.unmount()
			end
		end

	end
end

 

 

Edited by Cripplez
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.