if g_alien_items == nil then g_alien_items = 10 end if g_robot_items == nil then g_robot_items = 10 end if g_animal_items == nil then g_animal_items = 10 end if g_special_items == nil then g_special_items = 10 end if g_RPG_Gold == nil then g_RPG_Gold = 0 end g_state = {} local py = 0 local item_number = 0 local item_name = {} local sell_price = {} local item_order = {} local video_length = 0 --idk what the video code was for so you can play a video first if you make this longer --please note if you add more items you need to also adjust the buying code below (line 97ish) --display name to show in shop (so we can keep the ugly dev names) item_name[1] = "Alien Artifacts" item_name[2] = "Salvaged Robot Parts" item_name[3] = "Hunted Animal Skins" item_name[4] = "Rare Artifacts" --match to names above sell_price[1] = 200 sell_price[2] = 200 sell_price[3] = 300 sell_price[4] = 700 --need this so we know what order they are in when selling item_order[1] = "g_alien_items" item_order[2] = "g_robot_items" item_order[3] = "g_animal_items" item_order[4] = "g_special_items" pressed = 0 function alien_items_station_init(e) g_state[e] = "greet" end function alien_items_station_main(e) if g_state[e] == "greet" then if PlayerLooking(e,200,20) == 1 then RotateToPlayer(e) if GetTimer(e) < video_length then PlayVideo(e,0) else StopVideo(e,0) py = 68 Text(27,py,1,"This Station buys") item_number = 0 repeat item_number = item_number + 1 if item_name[item_number] ~= nil then py = py + 3 Text(27,py,1,"["..item_number.."] "..item_name[item_number].." for "..sell_price[item_number].." Credits per unit") end until item_name[item_number] == nil Text(27,py+3,1,"Press E to shop") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 SetFreezeAngle(0,g_PlayerAngY,g_PlayerAngZ) SetFreezePosition(g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) g_state[e] = "selling" end end else StartTimer(e) end elseif g_state[e] == "selling" then --TransportToFreezePosition() --remove if you dont want player to be frozen in place (shop will automatically close when out of range) --TransportToFreezePositionOnly() --allows player to look around py = 68 Text(27,py,1,"This Station buys") item_number = 0 repeat item_number = item_number + 1 if item_name[item_number] ~= nil then py = py + 3 Text(27,py,1,"["..item_number.."] "..item_name[item_number].." for "..sell_price[item_number].." Credits per unit") if g_Scancode > 0 then if g_Scancode-1 == item_number and pressed == 0 then pressed = 1 if item_order[item_number] == "g_alien_items" then if g_alien_items > 0 then PlaySound(e,1) g_alien_items = g_alien_items - 1 g_RPG_Gold = g_RPG_Gold + sell_price[item_number] end elseif item_order[item_number] == "g_robot_items" then if g_robot_items > 0 then PlaySound(e,1) g_robot_items = g_robot_items - 1 g_RPG_Gold = g_RPG_Gold + sell_price[item_number] end elseif item_order[item_number] == "g_animal_items" then if g_animal_items > 0 then PlaySound(e,1) g_animal_items = g_animal_items - 1 g_RPG_Gold = g_RPG_Gold + sell_price[item_number] end elseif item_order[item_number] == "g_special_items" then if g_special_items > 0 then PlaySound(e,1) g_special_items = g_special_items - 1 g_RPG_Gold = g_RPG_Gold + sell_price[item_number] end end end end end until item_name[item_number] == nil Text(27,py+3,1,"Select desired item to sell by pressing corresponding number shown in [ ]") Text(27,py+3,1,"Press E to stop sellings") if (g_KeyPressE == 1 and pressed == 0) or GetPlayerDistance(e) > 200 then pressed = 1 g_state[e] = "greet" end end if g_Scancode == 0 then pressed = 0 end Text(1,1,1,"You have") Text(1,4,1,g_alien_items.." x "..item_name[1]) Text(1,7,1,g_robot_items.." x "..item_name[2]) Text(1,10,1,g_animal_items.." x "..item_name[3]) Text(1,13,1,g_special_items.." x "..item_name[4]) Text(1,16,1,g_RPG_Gold.." Credits") end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end