Moderators: Siobhan, Sebastian, Drocket
EVID_SPEECH:
if (event.text["stable"])
EVID_SPEECH:
if (event.text["buy"])
TurnToward (ev.source);
local parms := array;
parms[1] := me;
parms[2] := ev.source;
start_script ("buyitems", parms);
elseif (event.text["stable"])
item_cfg_file := ReadConfigFile (":" + guild_name + ":itemsforsale");
item_cfg_file := ReadConfigFile ("itemsforsale");
local theitem := CreateItemInBackpack (player, chosen_item.objtype, 1);
PrintTextAbovePrivate (shopkeep, "Thanks! Come again soon!", player);
var parms := { };
parms.+script := "::tamed";
item_cfg_file := ReadConfigFile ("itemsforsale");
use uo;
use os;
use util;
use cfgfile;
include "../pkg/guilds/guilds";
include "include/spawn";
var gump_layout := {};
var gump_data := {};
var string_counter := 1;
var item_cfg_file;
var players_gold;
program display_forsale_items (parms)
local shopkeep := parms[1];
local player := parms[2];
local guild_name := parms[3];
if (!shopkeep or !player or !guild_name)
return;
endif
if (GetObjProperty (player, "guildbuywindow") )
return;
endif
SetObjProperty (player, "guildbuywindow", 1);
item_cfg_file := ReadConfigFile ("itemforsale");
if (!item_cfg_file)
Syslog ("Can't open itemforsale cfgfile!");
PrintTextAbovePrivate (shopkeep, "Sorry, but I'm having a bit of a problem right now.", player);
EraseObjProperty (player, "guildbuywindow");
return;
endif
players_gold := player.gold;
PrintTextAbovePrivate (shopkeep, "Hello, there! What do you want?", player);
BuildDisplayGump (guild_name);
local gump_return := SendDialogGump (player, gump_layout, gump_data);
if (!gump_return and gump_return[0] != 0)
PrintTextAbovePrivate (shopkeep, "Please close other gumps first.", player);
EraseObjProperty (player, "guildbuywindow");
return;
elseif (gump_return[0] = 0)
PrintTextAbovePrivate (shopkeep, "OK, maybe next time then.", player);
EraseObjProperty (player, "guildbuywindow");
return;
endif
local intkeyarray := GetConfigIntKeys (item_cfg_file);
local thekey := intkeyarray[gump_return[0]];
local chosen_item := FindConfigElem (item_cfg_file, thekey);
if (!chosen_item)
Syslog ("Error finding key " + thekey);
PrintTextAbovePrivate (shopkeep, "Sorry, but I'm having a bit of a problem right now.", player);
EraseObjProperty (player, "guildbuywindow");
return;
endif
if (!player.spendgold (chosen_item.price ))
PrintTextAbovePrivate (shopkeep, "I'm sorry, but you can't afford that right now.", player);
EraseObjProperty (player, "guildbuywindow");
return;
endif
var npc_parms := struct;
npc_parms.+script := "::tamed";
set_critical(1);
var newpet := SpawnNPCAtLocation (chosen_item.npctemplate, shopkeep.x+1, shopkeep.y+1, "guess", parms);
if (!newpet)
PrintTextAbovePrivate (shopkeep, "Uh-oh... Where'd he go?", player);
set_critical (1);
return;
endif
SetObjProperty (newpet, "master", player.serial);
newpet.script := "::tamed";
RestartScript (newpet);
set_critical(0);
PrintTextAbovePrivate (shopkeep, "Thanks! Come again soon!", player);
EraseObjProperty (player, "guildbuywindow");
endprogram
///////////////////
// does thw grunt work of building the gump
///////////////////
function BuildDisplayGump (guild_name)
gump_layout := {
"page 0",
"nodispose",
"resizepic 20 20 2600 400 300",
"resizepic 60 60 5120 60 60",
"text 140 50 1327 0",
"text 140 100 1327 1",
"text 140 270 1327 2",
"text 280 270 0 3",
"text 200 240 0 4",
"page 1"
};
gump_data := {
"Item:",
"Price:",
"Your Gold:",
players_gold,
"Buy item",
};
string_counter := len (gump_data);
local pagenumber := 1;
local intkeyarray := GetConfigIntKeys (item_cfg_file);
local number_of_keys := len (intkeyarray);
foreach intkey in intkeyarray
local elem := FindConfigElem (item_cfg_file, intkey);
if (!elem)
Syslog ("Error finding " + guild_name + " key " + intkey);
endif
gump_layout.append ("tilepic 70 70 " + elem.graphic);
gump_layout.append ("text 200 50 0 " + string_counter);
gump_data.append (elem.desc_1);
string_counter := string_counter + 1;
gump_layout.append ("text 220 70 0 " + string_counter);
gump_data.append (elem.desc_2);
string_counter := string_counter + 1;
gump_layout.append ("text 200 100 0 " + string_counter);
gump_data.append (elem.price);
string_counter := string_counter + 1;
gump_layout.append ("text 100 140 0 " + string_counter);
gump_data.append (elem.line_1);
string_counter := string_counter + 1;
gump_layout.append ("text 100 160 0 " + string_counter);
gump_data.append (elem.line_2);
string_counter := string_counter + 1;
gump_layout.append ("text 100 180 0 " + string_counter);
gump_data.append (elem.line_3);
string_counter := string_counter + 1;
gump_layout.append ("button 180 245 2104 2103 1 0 " + (pagenumber));
if (pagenumber = 1)
if (number_of_keys > 1)
gump_layout.append ("button 365 200 5601 5605 0 2");
gump_layout.append ("page 2");
gump_layout.append ("button 60 200 5603 5607 0 1");
pagenumber := 2;
endif
elseif (pagenumber = number_of_keys)
gump_layout.append ("button 60 200 5603 5607 0 " + (pagenumber-1) );
else
pagenumber := pagenumber + 1;
gump_layout.append ("button 365 200 5601 5605 0 " + pagenumber);
gump_layout.append ("page " + pagenumber);
gump_layout.append ("button 60 200 5603 5607 0 " + (pagenumber-1) );
endif
endforeach
endfunction
use os;
use uo;
use npc;
use util;
use cfgfile;
include "include/client";
include "include/objtype";
include "include/eventid";
include "include/spawn";
include "include/attributes";
include "include/NPCBackpacks";
include "../pkg/npcs/speech";
include "../pkg/npcs/npc_util";
include "../pkg/npcs/npcinfo";
Const MAXFRIENDS := 3;
global pet := 0; // Pet to stable
global player := 0; // Whoever said "stable"
global me := Self ();
program stabler_AI ()
if ( me.name ["<random>"] )
DoStablerOnCreationSetup ();
endif
speech := 5;
EnableEvents (EVID_DAMAGED + EVID_ENGAGED);
EnableEvents (EVID_SPEECH, 1);
EnableEvents (EVID_ITEM_GIVEN);
WalkHome ();
var event;
while (me)
if (me.hidden)
me.hidden := 0;
endif
event := os::wait_for_event ( 120 );
if (event)
case (event.type)
EVID_ENGAGED:
EVID_DAMAGED:
SetVital (me, "Life", GetVitalMaximumValue (me, "Life"));
me.hidden := 1;
var hidetime := ReadGameClock ();
repeat
event := os::wait_for_event (120);
if (!me.hidden)
me.hidden := 1;
endif
until (hidetime + 120 < ReadGameClock());
me.hidden := 0;
EVID_SPEECH:
if (event.text["buy"])
player := event.source;
local parms := array;
TurnToward (player);
parms[1] := me;
parms[2] := player;
start_script ("buyitems", parms);
elseif (event.text["stable"])
player := event.source;
TurnToward (player);
Say ("Show me your pet.");
pet := Target (player);
if (pet)
if (pet.script["tamed"])
if (GetObjProperty (pet, "summoned") or GetObjProperty (pet, "totem"))
Say ("Any just what am i supposed to do with that?");
elseif (GetObjProperty (pet, "master") = player.serial)
var stableprice := GetStablePriceOfPet (pet);
Say ("I charge " + stableprice + " to take care of " + pet.name + ".");
if (player.spendgold (stableprice) )
Say ("Keep this ticket and give it to me when you want " + pet.name + " back.");
var ticket := CreateItemInBackpack (player, 0x14f0, 1);
ticket.usescript := "";
Save_Pet_Data (ticket, pet);
else
Say ("You don't have enough money!");
endif
else
say ("This is not a zoo!");
endif
elseif ( (pet.graphic = CID_HUMAN_MALE) or (pet.graphic = CID_HUMAN_FEMALE) )
Say ("Do I look like an Inn Keeper?!");
else
Say ("That is not your pet.");
endif
else
Say ("Never mind, then.");
endif
else
check_speech (event.text, event.source);
endif
EVID_ITEM_GIVEN:
TurnToward (event.source);
Load_Ticket_Data (event.source, event.item);
endcase
endif
endwhile
endprogram
///////////////////
// Called to save the pet data to the claim ticket
///////////////////
function Save_Pet_Data (byref ticket, byref pet)
DropAllItems (pet);
ticket.name := "Pet claim ticket for : " + pet.name;
ticket.usescript := "";
SetObjProperty (ticket, "petname", pet.name);
SetObjProperty (ticket, "pethp", CINT (GetVital (pet, "Life")*100));
SetObjProperty (ticket, "petmana", CINT (GetVital (pet, "Mana")/100));
SetObjProperty (ticket, "petgraphic", pet.graphic);
SetObjProperty (ticket, "petcolor", pet.color);
SetObjProperty (ticket, "pettemplate", pet.npctemplate);
//kill the pet
MoveCharacterToLocation (pet, 5288, 1176 , 0, MOVECHAR_FORCELOCATION);
ApplyRawDamage (pet, GetVital (pet, "Life") + 3);
endfunction
///////////////////
// creates a new NPC based on the data stored in the claim ticket
///////////////////
function Load_Ticket_Data (byref player, byref ticket)
if (ticket.objtype = 0x14f0 and GetObjProperty (ticket, "pettemplate") )
if (!canclaim (player,GetObjProperty (ticket, "pettemplate")))
Say ("You have no chance of controlling that!");
MoveItemToContainer (ticket, player.backpack);
return;
endif
var newpet := 0;
Say ("Oh, let me find " + GetObjProperty (ticket, "petname") + " for you. One moment, please.");
Sleep (3);
var parms := { };
parms.+script := "::tamed";
set_critical(1);
newpet := SpawnNPCAtLocation (GetObjProperty (ticket, "pettemplate"), me.x+1, me.y+1, "guess", parms);
if (!newpet)
Say ("Uh-oh... Where'd he go?");
set_critical (1);
return;
endif
SetVital (newpet, "Life", GetObjProperty (ticket, "pethp") * 100);
SetVital (newpet, "Mana", GetObjProperty (ticket, "petmana") * 100);
newpet.graphic := GetObjProperty (ticket, "petgraphic");
newpet.name := GetObjProperty (ticket, "petname");
newpet.color := GetObjProperty (ticket, "petcolor");
SetObjProperty (newpet, "color", GetObjProperty (ticket, "petcolor"));
SetObjProperty (newpet, "master", player.serial);
newpet.script := "::tamed";
RestartScript (newpet);
set_critical(0);
Say ("Take care of " + GetObjProperty (ticket, "petname") + " and be sure to feed it!");
DestroyItem (ticket);
else
TakeItem (player, ticket);
endif
endfunction
///////////////////
// makes sure that the player can control the pet that they're trying to claim
///////////////////
function CanClaim (byref player, pettemplate)
case (pettemplate)
"horse":
"horse2":
"horse3":
"horse4":
"horse5":
"forestostard":
"desertostard":
"llama":
return 1;
endcase
var elem := GetNpcTemplateElem (pettemplate);
var difficulty := CINT (GetConfigInt (elem, "tameskill"));
if (!difficulty)
return 0;
endif
if (difficulty < 50)
return 1;
elseif ((difficulty - 20) > GetAttribute (player, ATTRIBUTEID_TAMING))
return 0;
else
return 1;
endif
endfunction
///////////////////
// Drops all the items that the pet is carrying
///////////////////
function DropAllItems (byref pet)
var mypack := FindMyPack(pet.serial);
foreach myitems in enumerateitemsincontainer(mypack)
if (myitems.container.serial = mypack.serial)
moveitemtolocation (myitems, pet.x, pet.y, pet.z, 0);
sleepms(100);
endif
endforeach
if (pet.backpack)
mypack := pet.backpack;
foreach item in enumerateitemsincontainer(mypack)
if (item.container.serial = mypack.serial)
moveitemtolocation(item, pet.x, pet.y, pet.z, 0);
endif
endforeach
endif
endfunction
///////////////////
// The price to stable a pet is based on the difficulty of taming it
///////////////////
function GetStablePriceOfPet (pet)
var mobelem := GetNpcTemplateElem (pet.npctemplate);
var tameskill := CINT (mobelem.tameskill);
if (!tameskill)
return 250;
endif
if (tameskill <= 60)
return 30;
elseif (tameskill <= 70)
return 50;
elseif (tameskill <= 80)
return 100;
elseif (tameskill <= 90)
return 200;
elseif (tameskill <= 100)
return 300;
elseif (tameskill <= 110)
return 400;
else
return 500;
endif
return 1;
endfunction
///////////////////
// called when the NPC is first created, this function names
// them and clothes them
///////////////////
function DoStablerOnCreationSetup()
var newbackpack := CreateItemAtLocation (5288 , 1176 , 0, UOBJ_BACKPACK, 1);
EquipItem (me, newbackpack);
me.gender := RandomInt (2);
me.graphic := 400+me.gender;
me.name := RandomName (me);
me.title_suffix := " the stablemaster";
var parms := {};
parms[1]:= me;
parms[2]:= "poor";
set_priority( 1 );
start_script("::/misc/dressme", parms);
endfunction
NpcDesc Horse
Users browsing this forum: No registered users and 1 guest