-- webPets Library Player Scripts -- PROPERTIES Define Properties() -- local storage of pet information for player petList = {} end -- webPetsLoadPets -- Submits a WebRequest to the server to retrieve a player's pet list Trigger webPetsGetPetList() request = {} request.url = "http://sanctuary.org/~ego/pets/getPlayerPets.rhtml?player_id=" .. self.id request.method = "GET" request.trigger = "webPetsHandlePetList" request.body = "" request.headers = {} WebRequest(self, request) end -- webPetsHandleLoadPets -- Handles the response from a WebRequest for a player's pet list Trigger webPetsHandlePetList(response, body, userdata) Debug("Received Response - R:%d, B:%s", response, body) -- Parse the XML response tab, msg, line, column, index = XmlParse(body) -- Report xml error if tab == nil then Debug("xml error [%s]%d:%d:%d ", msg, line, column, index) else -- Extract pet data from the LOM table for i,v in ipairs(tab) do if (v.tag == "pet") then Debug("%s %s %s %s", v.attr.id, v.attr.name, v.attr.isActive, v.attr.assetid) table.insert(self.petList, {["id"] = v.attr.id, ["name"] = v.attr.name, ["isactive"] = v.attr.isActive, ["assetid"] = v.attr.assetid}) end end end end -- webPetsCreatePet -- Creates pet from the petlist Trigger webPetsCreatePet(pet_id) CreateObjectById(self.petList[pet_id].assetid, self.x+1, self.y+1) end -- webPetsActivatePet -- Submits a request to activate a pet to the server Trigger webPetsActivatePet(pet_id) request = {} request.url = "http://sanctuary.org/~ego/pets/setActiveStatusPet.rhtml?pet_id=" .. pet_id .. "&active_status=true" request.method = "GET" request.trigger = "webPetsHandlePetActivation" request.body = "" request.headers = {} WebRequest(self, request) end -- webPets Library -- HandlePetActivation -- Handles the response from a WebRequest to activate a pet Trigger webPetsHandlePetActivation(response, body, userdata) Debug("Received Response - R:%d, B:%s", response, body) -- Parse the XML response tab, msg, line, column, index = XmlParse(body) -- Report xml error if tab == nil then Debug("xml error [%s]%d:%d:%d ", msg, line, column, index) -- If response indicates success, send a success trigger to be handled elseif (tab.attr.status == "success") then SendTo(self, "activatePetSuccess", 0, tab.attr.pet_id) -- If response indicates failure, send a fail trigger to be handled else SendTo(self, "activatePetFail", 0, tab.attr.pet_id) end end -- webPets Library -- DismissPet -- Submits a request to dismiss a pet to the server Trigger webPetsDismissPet(pet_id) request = {} request.url = "http://sanctuary.org/~ego/pets/setActiveStatusPet.rhtml?pet_id=" .. pet_id .. "&active_status=false" request.method = "GET" request.trigger = "webPetsHandlePetDismiss" request.body = "" request.headers = {} WebRequest(self, request) end -- webPets Library -- HandlePetDismiss -- Handles the response from a WebRequest to dismiss a pet Trigger webPetsHandlePetDismiss(response, body, userdata) Debug("Received Response - R:%d, B:%s", response, body) -- Parse the XML response tab, msg, line, column, index = XmlParse(body) -- Report xml error if tab == nil then Debug("xml error [%s]%d:%d:%d ", msg, line, column, index) SendTo(self, "dismissPetFail", 0, 0) -- If response indicates success, send trigger to be handled elseif (tab.attr.status == "success") then SendTo(self, "dismissPetSuccess", 0, tab.attr.pet_id) -- If response indicates failure, send trigger to be handled else SendTo(self, "dismissPetFail", 0, tab.attr.pet_id) end end