123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892 |
- // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
- // For more information, see LICENCE in the main folder
- //#define DEBUG_DISP
- //#define DEBUG_DISASM
- //#define DEBUG_RUN
- //#define DEBUG_HASH
- //#define DEBUG_DUMP_STACK
- #include "../common/cbasetypes.h"
- #include "../common/malloc.h"
- #include "../common/md5calc.h"
- #include "../common/lock.h"
- #include "../common/nullpo.h"
- #include "../common/showmsg.h"
- #include "../common/strlib.h"
- #include "../common/timer.h"
- #include "../common/utils.h"
- #include "map.h"
- #include "path.h"
- #include "clif.h"
- #include "chrif.h"
- #include "itemdb.h"
- #include "pc.h"
- #include "status.h"
- #include "storage.h"
- #include "mob.h"
- #include "npc.h"
- #include "pet.h"
- #include "mapreg.h"
- #include "homunculus.h"
- #include "instance.h"
- #include "mercenary.h"
- #include "intif.h"
- #include "skill.h"
- #include "status.h"
- #include "chat.h"
- #include "battle.h"
- #include "battleground.h"
- #include "party.h"
- #include "guild.h"
- #include "atcommand.h"
- #include "log.h"
- #include "unit.h"
- #include "pet.h"
- #include "mail.h"
- #include "script.h"
- #include "quest.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #ifndef WIN32
- #include <sys/time.h>
- #endif
- #include <time.h>
- #include <setjmp.h>
- #include <errno.h>
- ///////////////////////////////////////////////////////////////////////////////
- //## TODO possible enhancements: [FlavioJS]
- // - 'callfunc' supporting labels in the current npc "::LabelName"
- // - 'callfunc' supporting labels in other npcs "NpcName::LabelName"
- // - 'function FuncName;' function declarations reverting to global functions
- // if local label isn't found
- // - join callfunc and callsub's functionality
- // - use script_op2name in the DEBUG_DISASM block
- // - remove dynamic allocation in add_word()
- // - remove GETVALUE / SETVALUE
- // - clean up the set_reg / set_val / setd_sub mess
- //
- // struct script_state* st;
- //
- /// Returns the script_data at the target index
- #define script_getdata(st,i) ( &((st)->stack->stack_data[(st)->start + (i)]) )
- /// Returns if the stack contains data at the target index
- #define script_hasdata(st,i) ( (st)->end > (st)->start + (i) )
- /// Returns the index of the last data in the stack
- #define script_lastdata(st) ( (st)->end - (st)->start - 1 )
- /// Pushes an int into the stack
- #define script_pushint(st,val) push_val((st)->stack, C_INT, (val))
- /// Pushes a string into the stack (script engine frees it automatically)
- #define script_pushstr(st,val) push_str((st)->stack, C_STR, (val))
- /// Pushes a copy of a string into the stack
- #define script_pushstrcopy(st,val) push_str((st)->stack, C_STR, aStrdup(val))
- /// Pushes a constant string into the stack (must never change or be freed)
- #define script_pushconststr(st,val) push_str((st)->stack, C_CONSTSTR, (val))
- /// Pushes a nil into the stack
- #define script_pushnil(st) push_val((st)->stack, C_NOP, 0)
- /// Pushes a copy of the data in the target index
- #define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i))
- #define script_isstring(st,i) data_isstring(script_getdata(st,i))
- #define script_isint(st,i) data_isint(script_getdata(st,i))
- #define script_getnum(st,val) conv_num(st, script_getdata(st,val))
- #define script_getstr(st,val) conv_str(st, script_getdata(st,val))
- #define script_getref(st,val) ( script_getdata(st,val)->ref )
- // Note: "top" functions/defines use indexes relative to the top of the stack
- // -1 is the index of the data at the top
- /// Returns the script_data at the target index relative to the top of the stack
- #define script_getdatatop(st,i) ( &((st)->stack->stack_data[(st)->stack->sp + (i)]) )
- /// Pushes a copy of the data in the target index relative to the top of the stack
- #define script_pushcopytop(st,i) push_copy((st)->stack, (st)->stack->sp + (i))
- /// Removes the range of values [start,end[ relative to the top of the stack
- #define script_removetop(st,start,end) ( pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) )
- //
- // struct script_data* data;
- //
- /// Returns if the script data is a string
- #define data_isstring(data) ( (data)->type == C_STR || (data)->type == C_CONSTSTR )
- /// Returns if the script data is an int
- #define data_isint(data) ( (data)->type == C_INT )
- /// Returns if the script data is a reference
- #define data_isreference(data) ( (data)->type == C_NAME )
- /// Returns if the script data is a label
- #define data_islabel(data) ( (data)->type == C_POS )
- /// Returns if the script data is an internal script function label
- #define data_isfunclabel(data) ( (data)->type == C_USERFUNC_POS )
- /// Returns if this is a reference to a constant
- #define reference_toconstant(data) ( str_data[reference_getid(data)].type == C_INT )
- /// Returns if this a reference to a param
- #define reference_toparam(data) ( str_data[reference_getid(data)].type == C_PARAM )
- /// Returns if this a reference to a variable
- //##TODO confirm it's C_NAME [FlavioJS]
- #define reference_tovariable(data) ( str_data[reference_getid(data)].type == C_NAME )
- /// Returns the unique id of the reference (id and index)
- #define reference_getuid(data) ( (data)->u.num )
- /// Returns the id of the reference
- #define reference_getid(data) ( (int32)(reference_getuid(data) & 0x00ffffff) )
- /// Returns the array index of the reference
- #define reference_getindex(data) ( (int32)(((uint32)(reference_getuid(data) & 0xff000000)) >> 24) )
- /// Returns the name of the reference
- #define reference_getname(data) ( str_buf + str_data[reference_getid(data)].str )
- /// Returns the linked list of uid-value pairs of the reference (can be NULL)
- #define reference_getref(data) ( (data)->ref )
- /// Returns the value of the constant
- #define reference_getconstant(data) ( str_data[reference_getid(data)].val )
- /// Returns the type of param
- #define reference_getparamtype(data) ( str_data[reference_getid(data)].val )
- /// Composes the uid of a reference from the id and the index
- #define reference_uid(id,idx) ( (int32)((((uint32)(id)) & 0x00ffffff) | (((uint32)(idx)) << 24)) )
- #define not_server_variable(prefix) ( (prefix) != '$' && (prefix) != '.' && (prefix) != '\'')
- #define not_array_variable(prefix) ( (prefix) != '$' && (prefix) != '@' && (prefix) != '.' && (prefix) != '\'' )
- #define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' )
- #define FETCH(n, t) \
- if( script_hasdata(st,n) ) \
- (t)=script_getnum(st,n);
- #define SCRIPT_BLOCK_SIZE 512
- enum { LABEL_NEXTLINE=1,LABEL_START };
- /// temporary buffer for passing around compiled bytecode
- /// @see add_scriptb, set_label, parse_script
- static unsigned char* script_buf = NULL;
- static int script_pos = 0, script_size = 0;
- #define GETVALUE(buf,i) ((int)MakeDWord(MakeWord((buf)[i],(buf)[i+1]),MakeWord((buf)[i+2],0)))
- #define SETVALUE(buf,i,n) ((buf)[i]=GetByte(n,0),(buf)[i+1]=GetByte(n,1),(buf)[i+2]=GetByte(n,2))
- // String buffer structures.
- // str_data stores string information
- static struct str_data_struct {
- enum c_op type;
- int str;
- int backpatch;
- int label;
- int (*func)(struct script_state *st);
- int val;
- int next;
- } *str_data = NULL;
- static int str_data_size = 0; // size of the data
- static int str_num = LABEL_START; // next id to be assigned
- // str_buf holds the strings themselves
- static char *str_buf;
- static int str_size = 0; // size of the buffer
- static int str_pos = 0; // next position to be assigned
- // Using a prime number for SCRIPT_HASH_SIZE should give better distributions
- #define SCRIPT_HASH_SIZE 1021
- int str_hash[SCRIPT_HASH_SIZE];
- // Specifies which string hashing method to use
- //#define SCRIPT_HASH_DJB2
- //#define SCRIPT_HASH_SDBM
- #define SCRIPT_HASH_ELF
- static DBMap* scriptlabel_db=NULL; // const char* label_name -> int script_pos
- static DBMap* userfunc_db=NULL; // const char* func_name -> struct script_code*
- static int parse_options=0;
- DBMap* script_get_label_db(){ return scriptlabel_db; }
- DBMap* script_get_userfunc_db(){ return userfunc_db; }
- // Caches compiled autoscript item code.
- // Note: This is not cleared when reloading itemdb.
- static DBMap* autobonus_db=NULL; // char* script -> char* bytecode
- struct Script_Config script_config = {
- 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
- 0, INT_MAX, // input_min_value/input_max_value
- "OnPCDieEvent", //die_event_name
- "OnPCKillEvent", //kill_pc_event_name
- "OnNPCKillEvent", //kill_mob_event_name
- "OnPCLoginEvent", //login_event_name
- "OnPCLogoutEvent", //logout_event_name
- "OnPCLoadMapEvent", //loadmap_event_name
- "OnPCBaseLvUpEvent", //baselvup_event_name
- "OnPCJobLvUpEvent", //joblvup_event_name
- "OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
- "OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area)
- };
- static jmp_buf error_jump;
- static char* error_msg;
- static const char* error_pos;
- static int error_report; // if the error should produce output
- // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
- // [Eoe / jA 1080, 1081, 1094, 1164]
- enum curly_type {
- TYPE_NULL = 0,
- TYPE_IF,
- TYPE_SWITCH,
- TYPE_WHILE,
- TYPE_FOR,
- TYPE_DO,
- TYPE_USERFUNC,
- TYPE_ARGLIST // function argument list
- };
- #define ARGLIST_UNDEFINED 0
- #define ARGLIST_NO_PAREN 1
- #define ARGLIST_PAREN 2
- static struct {
- struct {
- enum curly_type type;
- int index;
- int count;
- int flag;
- struct linkdb_node *case_label;
- } curly[256]; // 右カッコの情報
- int curly_count; // 右カッコの数
- int index; // スクリプト内で使用した構文の数
- } syntax;
- const char* parse_curly_close(const char* p);
- const char* parse_syntax_close(const char* p);
- const char* parse_syntax_close_sub(const char* p,int* flag);
- const char* parse_syntax(const char* p);
- static int parse_syntax_for_flag = 0;
- extern int current_equip_item_index; //for New CARDS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
- int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
- int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
- int potion_target=0;
- c_op get_com(unsigned char *script,int *pos);
- int get_num(unsigned char *script,int *pos);
- typedef struct script_function {
- int (*func)(struct script_state *st);
- const char *name;
- const char *arg;
- } script_function;
- extern script_function buildin_func[];
- static struct linkdb_node* sleep_db;// int oid -> struct script_state*
- uint32 crctab[256];
- /*==========================================
- * ローカルプロトタイプ宣言 (必要な物のみ)
- *------------------------------------------*/
- const char* parse_subexpr(const char* p,int limit);
- void push_val(struct script_stack *stack,int type,int val);
- int run_func(struct script_state *st);
- enum {
- MF_NOMEMO, //0
- MF_NOTELEPORT,
- MF_NOSAVE,
- MF_NOBRANCH,
- MF_NOPENALTY,
- MF_NOZENYPENALTY,
- MF_PVP,
- MF_PVP_NOPARTY,
- MF_PVP_NOGUILD,
- MF_GVG,
- MF_GVG_NOPARTY, //10
- MF_NOTRADE,
- MF_NOSKILL,
- MF_NOWARP,
- MF_PARTYLOCK,
- MF_NOICEWALL,
- MF_SNOW,
- MF_FOG,
- MF_SAKURA,
- MF_LEAVES,
- MF_RAIN, //20
- // 21 free
- MF_NOGO = 22,
- MF_CLOUDS,
- MF_CLOUDS2,
- MF_FIREWORKS,
- MF_GVG_CASTLE,
- MF_GVG_DUNGEON,
- MF_NIGHTENABLED,
- MF_NOBASEEXP,
- MF_NOJOBEXP, //30
- MF_NOMOBLOOT,
- MF_NOMVPLOOT,
- MF_NORETURN,
- MF_NOWARPTO,
- MF_NIGHTMAREDROP,
- MF_RESTRICTED,
- MF_NOCOMMAND,
- MF_NODROP,
- MF_JEXP,
- MF_BEXP, //40
- MF_NOVENDING,
- MF_LOADEVENT,
- MF_NOCHAT,
- MF_NOEXPPENALTY,
- MF_GUILDLOCK,
- MF_TOWN,
- MF_AUTOTRADE,
- MF_ALLOWKS,
- MF_MONSTER_NOTELEPORT,
- MF_PVP_NOCALCRANK, //50
- MF_BATTLEGROUND
- };
- const char* script_op2name(int op)
- {
- #define RETURN_OP_NAME(type) case type: return #type
- switch( op )
- {
- RETURN_OP_NAME(C_NOP);
- RETURN_OP_NAME(C_POS);
- RETURN_OP_NAME(C_INT);
- RETURN_OP_NAME(C_PARAM);
- RETURN_OP_NAME(C_FUNC);
- RETURN_OP_NAME(C_STR);
- RETURN_OP_NAME(C_CONSTSTR);
- RETURN_OP_NAME(C_ARG);
- RETURN_OP_NAME(C_NAME);
- RETURN_OP_NAME(C_EOL);
- RETURN_OP_NAME(C_RETINFO);
- RETURN_OP_NAME(C_USERFUNC);
- RETURN_OP_NAME(C_USERFUNC_POS);
- // operators
- RETURN_OP_NAME(C_OP3);
- RETURN_OP_NAME(C_LOR);
- RETURN_OP_NAME(C_LAND);
- RETURN_OP_NAME(C_LE);
- RETURN_OP_NAME(C_LT);
- RETURN_OP_NAME(C_GE);
- RETURN_OP_NAME(C_GT);
- RETURN_OP_NAME(C_EQ);
- RETURN_OP_NAME(C_NE);
- RETURN_OP_NAME(C_XOR);
- RETURN_OP_NAME(C_OR);
- RETURN_OP_NAME(C_AND);
- RETURN_OP_NAME(C_ADD);
- RETURN_OP_NAME(C_SUB);
- RETURN_OP_NAME(C_MUL);
- RETURN_OP_NAME(C_DIV);
- RETURN_OP_NAME(C_MOD);
- RETURN_OP_NAME(C_NEG);
- RETURN_OP_NAME(C_LNOT);
- RETURN_OP_NAME(C_NOT);
- RETURN_OP_NAME(C_R_SHIFT);
- RETURN_OP_NAME(C_L_SHIFT);
- default:
- ShowDebug("script_op2name: unexpected op=%d\n", op);
- return "???";
- }
- #undef RETURN_OP_NAME
- }
- #ifdef DEBUG_DUMP_STACK
- static void script_dump_stack(struct script_state* st)
- {
- int i;
- ShowMessage("\tstart = %d\n", st->start);
- ShowMessage("\tend = %d\n", st->end);
- ShowMessage("\tdefsp = %d\n", st->stack->defsp);
- ShowMessage("\tsp = %d\n", st->stack->sp);
- for( i = 0; i < st->stack->sp; ++i )
- {
- struct script_data* data = &st->stack->stack_data[i];
- ShowMessage("\t[%d] %s", i, script_op2name(data->type));
- switch( data->type )
- {
- case C_INT:
- case C_POS:
- ShowMessage(" %d\n", data->u.num);
- break;
- case C_STR:
- case C_CONSTSTR:
- ShowMessage(" \"%s\"\n", data->u.str);
- break;
- case C_NAME:
- ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script_op2name(str_data[data->u.num].type));
- break;
- case C_RETINFO:
- {
- struct script_retinfo* ri = data->u.ri;
- ShowMessage(" %p {var_function=%p, script=%p, pos=%d, nargs=%d, defsp=%d}\n", ri, ri->var_function, ri->script, ri->pos, ri->nargs, ri->defsp);
- }
- break;
- default:
- ShowMessage("\n");
- break;
- }
- }
- }
- #endif
- /// Reports on the console the src of a script error.
- static void script_reportsrc(struct script_state *st)
- {
- struct block_list* bl;
- if( st->oid == 0 )
- return; //Can't report source.
- bl = map_id2bl(st->oid);
- if( bl == NULL )
- return;
- switch( bl->type )
- {
- case BL_NPC:
- if( bl->m >= 0 )
- ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
- else
- ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
- break;
- default:
- if( bl->m >= 0 )
- ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map[bl->m].name, bl->x, bl->y);
- else
- ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl));
- break;
- }
- }
- /// Reports on the console information about the script data.
- static void script_reportdata(struct script_data* data)
- {
- if( data == NULL )
- return;
- switch( data->type )
- {
- case C_NOP:// no value
- ShowDebug("Data: nothing (nil)\n");
- break;
- case C_INT:// number
- ShowDebug("Data: number value=%d\n", data->u.num);
- break;
- case C_STR:
- case C_CONSTSTR:// string
- ShowDebug("Data: string value=\"%s\"\n", data->u.str);
- break;
- case C_NAME:// reference
- if( reference_tovariable(data) )
- {// variable
- const char* name = reference_getname(data);
- if( not_array_variable(*name) )
- ShowDebug("Data: variable name='%s'\n", name);
- else
- ShowDebug("Data: variable name='%s' index=%d\n", name, reference_getindex(data));
- }
- else if( reference_toconstant(data) )
- {// constant
- ShowDebug("Data: constant name='%s' value=%d\n", reference_getname(data), reference_getconstant(data));
- }
- else if( reference_toparam(data) )
- {// param
- ShowDebug("Data: param name='%s' type=%d\n", reference_getname(data), reference_getparamtype(data));
- }
- else
- {// ???
- ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script_op2name(data->type));
- ShowDebug("Please report this!!! - str_data.type=%s\n", script_op2name(str_data[reference_getid(data)].type));
- }
- break;
- case C_POS:// label
- ShowDebug("Data: label pos=%d\n", data->u.num);
- break;
- default:
- ShowDebug("Data: %s\n", script_op2name(data->type));
- break;
- }
- }
- /*==========================================
- * エラーメッセージ出力
- *------------------------------------------*/
- static void disp_error_message2(const char *mes,const char *pos,int report)
- {
- error_msg = aStrdup(mes);
- error_pos = pos;
- error_report = report;
- longjmp( error_jump, 1 );
- }
- #define disp_error_message(mes,pos) disp_error_message2(mes,pos,1)
- /// Checks event parameter validity
- static void check_event(struct script_state *st, const char *evt)
- {
- if( evt != NULL && *evt != '\0' && !stristr(evt,"::On") ){
- ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",evt);
- script_reportsrc(st);
- }
- }
- /*==========================================
- * Hashes the input string
- *------------------------------------------*/
- static unsigned int calc_hash(const char* p)
- {
- unsigned int h;
- #if defined(SCRIPT_HASH_DJB2)
- h = 5381;
- while( *p ) // hash*33 + c
- h = ( h << 5 ) + h + ((unsigned char)TOLOWER(*p++));
- #elif defined(SCRIPT_HASH_SDBM)
- h = 0;
- while( *p ) // hash*65599 + c
- h = ( h << 6 ) + ( h << 16 ) - h + ((unsigned char)TOLOWER(*p++));
- #elif defined(SCRIPT_HASH_ELF) // UNIX ELF hash
- h = 0;
- while( *p ){
- unsigned int g;
- h = ( h << 4 ) + ((unsigned char)TOLOWER(*p++));
- g = h & 0xF0000000;
- if( g )
- {
- h ^= g >> 24;
- h &= ~g;
- }
- }
- #else // athena hash
- h = 0;
- while( *p )
- h = ( h << 1 ) + ( h >> 3 ) + ( h >> 5 ) + ( h >> 8 ) + (unsigned char)TOLOWER(*p++);
- #endif
- return h % SCRIPT_HASH_SIZE;
- }
- /*==========================================
- * str_data manipulation functions
- *------------------------------------------*/
- /// Looks up string using the provided id.
- const char* get_str(int id)
- {
- Assert( id >= LABEL_START && id < str_size );
- return str_buf+str_data[id].str;
- }
- /// Returns the uid of the string, or -1.
- static int search_str(const char* p)
- {
- int i;
- for( i = str_hash[calc_hash(p)]; i != 0; i = str_data[i].next )
- if( strcasecmp(get_str(i),p) == 0 )
- return i;
- return -1;
- }
- /// Stores a copy of the string and returns its id.
- /// If an identical string is already present, returns its id instead.
- int add_str(const char* p)
- {
- int i, h;
- int len;
- h = calc_hash(p);
- if( str_hash[h] == 0 )
- {// empty bucket, add new node here
- str_hash[h] = str_num;
- }
- else
- {// scan for end of list, or occurence of identical string
- for( i = str_hash[h]; ; i = str_data[i].next )
- {
- if( strcasecmp(get_str(i),p) == 0 )
- return i; // string already in list
- if( str_data[i].next == 0 )
- break; // reached the end
- }
- // append node to end of list
- str_data[i].next = str_num;
- }
- // grow list if neccessary
- if( str_num >= str_data_size )
- {
- str_data_size += 128;
- RECREATE(str_data,struct str_data_struct,str_data_size);
- memset(str_data + (str_data_size - 128), '\0', 128);
- }
- len=(int)strlen(p);
- // grow string buffer if neccessary
- while( str_pos+len+1 >= str_size )
- {
- str_size += 256;
- RECREATE(str_buf,char,str_size);
- memset(str_buf + (str_size - 256), '\0', 256);
- }
- safestrncpy(str_buf+str_pos, p, len+1);
- str_data[str_num].type = C_NOP;
- str_data[str_num].str = str_pos;
- str_data[str_num].next = 0;
- str_data[str_num].func = NULL;
- str_data[str_num].backpatch = -1;
- str_data[str_num].label = -1;
- str_pos += len+1;
- return str_num++;
- }
- /// Appends 1 byte to the script buffer.
- static void add_scriptb(int a)
- {
- if( script_pos+1 >= script_size )
- {
- script_size += SCRIPT_BLOCK_SIZE;
- RECREATE(script_buf,unsigned char,script_size);
- }
- script_buf[script_pos++] = (uint8)(a);
- }
- /// Appends a c_op value to the script buffer.
- /// The value is variable-length encoded into 8-bit blocks.
- /// The encoding scheme is ( 01?????? )* 00??????, LSB first.
- /// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
- static void add_scriptc(int a)
- {
- while( a >= 0x40 )
- {
- add_scriptb((a&0x3f)|0x40);
- a = (a - 0x40) >> 6;
- }
- add_scriptb(a);
- }
- /// Appends an integer value to the script buffer.
- /// The value is variable-length encoded into 8-bit blocks.
- /// The encoding scheme is ( 11?????? )* 10??????, LSB first.
- /// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
- static void add_scripti(int a)
- {
- while( a >= 0x40 )
- {
- add_scriptb((a&0x3f)|0xc0);
- a = (a - 0x40) >> 6;
- }
- add_scriptb(a|0x80);
- }
- /// Appends a str_data object (label/function/variable/integer) to the script buffer.
- ///
- /// @param l The id of the str_data entry
- // 最大16Mまで
- static void add_scriptl(int l)
- {
- int backpatch = str_data[l].backpatch;
- switch(str_data[l].type){
- case C_POS:
- case C_USERFUNC_POS:
- add_scriptc(C_POS);
- add_scriptb(str_data[l].label);
- add_scriptb(str_data[l].label>>8);
- add_scriptb(str_data[l].label>>16);
- break;
- case C_NOP:
- case C_USERFUNC:
- // ラベルの可能性があるのでbackpatch用データ埋め込み
- add_scriptc(C_NAME);
- str_data[l].backpatch = script_pos;
- add_scriptb(backpatch);
- add_scriptb(backpatch>>8);
- add_scriptb(backpatch>>16);
- break;
- case C_INT:
- add_scripti(abs(str_data[l].val));
- if( str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce)
- add_scriptc(C_NEG);
- break;
- default: // assume C_NAME
- add_scriptc(C_NAME);
- add_scriptb(l);
- add_scriptb(l>>8);
- add_scriptb(l>>16);
- break;
- }
- }
- /*==========================================
- * ラベルを解決する
- *------------------------------------------*/
- void set_label(int l,int pos, const char* script_pos)
- {
- int i,next;
- if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
- { //Prevent overwriting constants values and parameters [Skotlex]
- disp_error_message("set_label: invalid label name",script_pos);
- return;
- }
- if(str_data[l].label!=-1){
- disp_error_message("set_label: dup label ",script_pos);
- return;
- }
- str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
- str_data[l].label=pos;
- for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
- next=GETVALUE(script_buf,i);
- script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
- SETVALUE(script_buf,i,pos);
- i=next;
- }
- }
- /// Skips spaces and/or comments.
- const char* skip_space(const char* p)
- {
- if( p == NULL )
- return NULL;
- for(;;)
- {
- while( ISSPACE(*p) )
- ++p;
- if( *p == '/' && p[1] == '/' )
- {// line comment
- while(*p && *p!='\n')
- ++p;
- }
- else if( *p == '/' && p[1] == '*' )
- {// block comment
- p += 2;
- for(;;)
- {
- if( *p == '\0' )
- return p;//disp_error_message("script:skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
- if( *p == '*' && p[1] == '/' )
- {// end of block comment
- p += 2;
- break;
- }
- ++p;
- }
- }
- else
- break;
- }
- return p;
- }
- /// Skips a word.
- /// A word consists of undercores and/or alfanumeric characters,
- /// and valid variable prefixes/postfixes.
- static
- const char* skip_word(const char* p)
- {
- // prefix
- switch( *p )
- {
- case '@':// temporary char variable
- ++p; break;
- case '#':// account variable
- p += ( p[1] == '#' ? 2 : 1 ); break;
- case '\'':// instance variable
- ++p; break;
- case '.':// npc variable
- p += ( p[1] == '@' ? 2 : 1 ); break;
- case '$':// global variable
- p += ( p[1] == '@' ? 2 : 1 ); break;
- }
- while( ISALNUM(*p) || *p == '_' )
- ++p;
- // postfix
- if( *p == '$' )// string
- p++;
- return p;
- }
- /// Adds a word to str_data.
- /// @see skip_word
- /// @see add_str
- static
- int add_word(const char* p)
- {
- char* word;
- int len;
- int i;
- // Check for a word
- len = skip_word(p) - p;
- if( len == 0 )
- disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alfanumeric characters, and valid variable prefixes/postfixes.", p);
- // Duplicate the word
- CREATE(word, char, len+1);
- memcpy(word, p, len);
- word[len] = 0;
-
- // add the word
- i = add_str(word);
- aFree(word);
- return i;
- }
- /// Parses a function call.
- /// The argument list can have parenthesis or not.
- /// The number of arguments is checked.
- static
- const char* parse_callfunc(const char* p, int require_paren)
- {
- const char* p2;
- const char* arg=NULL;
- int func;
- func = add_word(p);
- if( str_data[func].type == C_FUNC ){
- // buildin function
- add_scriptl(func);
- add_scriptc(C_ARG);
- arg = buildin_func[str_data[func].val].arg;
- } else if( str_data[func].type == C_USERFUNC || str_data[func].type == C_USERFUNC_POS ){
- // script defined function
- int callsub = search_str("callsub");
- add_scriptl(callsub);
- add_scriptc(C_ARG);
- add_scriptl(func);
- arg = buildin_func[str_data[callsub].val].arg;
- if( *arg == 0 )
- disp_error_message("parse_callfunc: callsub has no arguments, please review it's definition",p);
- if( *arg != '*' )
- ++arg; // count func as argument
- } else
- disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p);
- p = skip_word(p);
- p = skip_space(p);
- syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
- syntax.curly[syntax.curly_count].count = 0;
- if( *p == ';' )
- {// <func name> ';'
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- } else if( *p == '(' && *(p2=skip_space(p+1)) == ')' )
- {// <func name> '(' ')'
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
- p = p2;
- /*
- } else if( 0 && require_paren && *p != '(' )
- {// <func name>
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- */
- } else
- {// <func name> <arg list>
- if( require_paren ){
- if( *p != '(' )
- disp_error_message("need '('",p);
- ++p; // skip '('
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
- } else if( *p == '(' ){
- syntax.curly[syntax.curly_count].flag = ARGLIST_UNDEFINED;
- } else {
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- }
- ++syntax.curly_count;
- while( *arg ) {
- p2=parse_subexpr(p,-1);
- if( p == p2 )
- break; // not an argument
- if( *arg != '*' )
- ++arg; // next argument
- p=skip_space(p2);
- if( *arg == 0 || *p != ',' )
- break; // no more arguments
- ++p; // skip comma
- }
- --syntax.curly_count;
- }
- if( *arg && *arg != '?' && *arg != '*' )
- disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script_config.warn_func_mismatch_paramnum);
- if( syntax.curly[syntax.curly_count].type != TYPE_ARGLIST )
- disp_error_message("parse_callfunc: DEBUG last curly is not an argument list",p);
- if( syntax.curly[syntax.curly_count].flag == ARGLIST_PAREN ){
- if( *p != ')' )
- disp_error_message("parse_callfunc: expected ')' to close argument list",p);
- ++p;
- }
- add_scriptc(C_FUNC);
- return p;
- }
- /*==========================================
- * 項の解析
- *------------------------------------------*/
- const char* parse_simpleexpr(const char *p)
- {
- int i;
- p=skip_space(p);
- if(*p==';' || *p==',')
- disp_error_message("parse_simpleexpr: unexpected expr end",p);
- if(*p=='('){
- if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST )
- ++syntax.curly[i].count;
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
- if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST &&
- syntax.curly[i].flag == ARGLIST_UNDEFINED && --syntax.curly[i].count == 0
- ){
- if( *p == ',' ){
- syntax.curly[i].flag = ARGLIST_PAREN;
- return p;
- } else
- syntax.curly[i].flag = ARGLIST_NO_PAREN;
- }
- if( *p != ')' )
- disp_error_message("parse_simpleexpr: unmatch ')'",p);
- ++p;
- } else if(ISDIGIT(*p) || ((*p=='-' || *p=='+') && ISDIGIT(p[1]))){
- char *np;
- i=strtoul(p,&np,0);
- add_scripti(i);
- p=np;
- } else if(*p=='"'){
- add_scriptc(C_STR);
- p++;
- while( *p && *p != '"' ){
- if( (unsigned char)p[-1] <= 0x7e && *p == '\\' )
- {
- char buf[8];
- size_t len = skip_escaped_c(p) - p;
- size_t n = sv_unescape_c(buf, p, len);
- if( n != 1 )
- ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf);
- p += len;
- add_scriptb(*buf);
- continue;
- }
- else if( *p == '\n' )
- disp_error_message("parse_simpleexpr: unexpected newline @ string",p);
- add_scriptb(*p++);
- }
- if(!*p)
- disp_error_message("parse_simpleexpr: unexpected eof @ string",p);
- add_scriptb(0);
- p++; //'"'
- } else {
- int l;
- // label , register , function etc
- if(skip_word(p)==p)
- disp_error_message("parse_simpleexpr: unexpected character",p);
- l=add_word(p);
- if( str_data[l].type == C_FUNC || str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS)
- return parse_callfunc(p,1);
- p=skip_word(p);
- if( *p == '[' ){
- // array(name[i] => getelementofarray(name,i) )
- add_scriptl(search_str("getelementofarray"));
- add_scriptc(C_ARG);
- add_scriptl(l);
-
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
- if( *p != ']' )
- disp_error_message("parse_simpleexpr: unmatch ']'",p);
- ++p;
- add_scriptc(C_FUNC);
- }else
- add_scriptl(l);
- }
- return p;
- }
- /*==========================================
- * 式の解析
- *------------------------------------------*/
- const char* parse_subexpr(const char* p,int limit)
- {
- int op,opl,len;
- const char* tmpp;
- p=skip_space(p);
- if(*p=='-'){
- tmpp=skip_space(p+1);
- if(*tmpp==';' || *tmpp==','){
- add_scriptl(LABEL_NEXTLINE);
- p++;
- return p;
- }
- }
- tmpp=p;
- if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
- p=parse_subexpr(p+1,10);
- add_scriptc(op);
- } else
- p=parse_simpleexpr(p);
- p=skip_space(p);
- while((
- (op=C_OP3,opl=0,len=1,*p=='?') ||
- (op=C_ADD,opl=8,len=1,*p=='+') ||
- (op=C_SUB,opl=8,len=1,*p=='-') ||
- (op=C_MUL,opl=9,len=1,*p=='*') ||
- (op=C_DIV,opl=9,len=1,*p=='/') ||
- (op=C_MOD,opl=9,len=1,*p=='%') ||
- (op=C_LAND,opl=2,len=2,*p=='&' && p[1]=='&') ||
- (op=C_AND,opl=6,len=1,*p=='&') ||
- (op=C_LOR,opl=1,len=2,*p=='|' && p[1]=='|') ||
- (op=C_OR,opl=5,len=1,*p=='|') ||
- (op=C_XOR,opl=4,len=1,*p=='^') ||
- (op=C_EQ,opl=3,len=2,*p=='=' && p[1]=='=') ||
- (op=C_NE,opl=3,len=2,*p=='!' && p[1]=='=') ||
- (op=C_R_SHIFT,opl=7,len=2,*p=='>' && p[1]=='>') ||
- (op=C_GE,opl=3,len=2,*p=='>' && p[1]=='=') ||
- (op=C_GT,opl=3,len=1,*p=='>') ||
- (op=C_L_SHIFT,opl=7,len=2,*p=='<' && p[1]=='<') ||
- (op=C_LE,opl=3,len=2,*p=='<' && p[1]=='=') ||
- (op=C_LT,opl=3,len=1,*p=='<')) && opl>limit){
- p+=len;
- if(op == C_OP3) {
- p=parse_subexpr(p,-1);
- p=skip_space(p);
- if( *(p++) != ':')
- disp_error_message("parse_subexpr: need ':'", p-1);
- p=parse_subexpr(p,-1);
- } else {
- p=parse_subexpr(p,opl);
- }
- add_scriptc(op);
- p=skip_space(p);
- }
- return p; /* return first untreated operator */
- }
- /*==========================================
- * 式の評価
- *------------------------------------------*/
- const char* parse_expr(const char *p)
- {
- switch(*p){
- case ')': case ';': case ':': case '[': case ']':
- case '}':
- disp_error_message("parse_expr: unexpected char",p);
- }
- p=parse_subexpr(p,-1);
- return p;
- }
- /*==========================================
- * 行の解析
- *------------------------------------------*/
- const char* parse_line(const char* p)
- {
- const char* p2;
- p=skip_space(p);
- if(*p==';') {
- // if(); for(); while(); のために閉じ判定
- p = parse_syntax_close(p + 1);
- return p;
- }
- if(*p==')' && parse_syntax_for_flag)
- return p+1;
- p = skip_space(p);
- if(p[0] == '{') {
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- syntax.curly[syntax.curly_count].count = -1;
- syntax.curly[syntax.curly_count].index = -1;
- syntax.curly_count++;
- return p + 1;
- } else if(p[0] == '}') {
- return parse_curly_close(p);
- }
- // 構文関連の処理
- p2 = parse_syntax(p);
- if(p2 != NULL)
- return p2;
- p = parse_callfunc(p,0);
- p = skip_space(p);
- if(parse_syntax_for_flag) {
- if( *p != ')' )
- disp_error_message("parse_line: need ')'",p);
- } else {
- if( *p != ';' )
- disp_error_message("parse_line: need ';'",p);
- }
- // if, for , while の閉じ判定
- p = parse_syntax_close(p+1);
- return p;
- }
- // { ... } の閉じ処理
- const char* parse_curly_close(const char* p)
- {
- if(syntax.curly_count <= 0) {
- disp_error_message("parse_curly_close: unexpected string",p);
- return p + 1;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
- syntax.curly_count--;
- // if, for , while の閉じ判定
- p = parse_syntax_close(p + 1);
- return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
- // switch() 閉じ判定
- int pos = syntax.curly_count-1;
- char label[256];
- int l;
- // 一時変数を消す
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 無条件で終了ポインタに移動
- sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 現在地のラベルを付ける
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos, p);
- if(syntax.curly[pos].flag) {
- // default が存在する
- sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- // 終了ラベルを付ける
- sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos, p);
- linkdb_final(&syntax.curly[pos].case_label); // free the list of case label
- syntax.curly_count--;
- return p+1;
- } else {
- disp_error_message("parse_curly_close: unexpected string",p);
- return p + 1;
- }
- }
- // 構文関連の処理
- // break, case, continue, default, do, for, function,
- // if, switch, while をこの内部で処理します。
- const char* parse_syntax(const char* p)
- {
- const char *p2 = skip_word(p);
- switch(*p) {
- case 'B':
- case 'b':
- if(p2 - p == 5 && !strncasecmp(p,"break",5)) {
- // break の処理
- char label[256];
- int pos = syntax.curly_count - 1;
- while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_SWITCH) {
- sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
- break;
- }
- pos--;
- }
- if(pos < 0) {
- disp_error_message("parse_syntax: unexpected 'break'",p);
- } else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- p = skip_space(p2);
- if(*p != ';')
- disp_error_message("parse_syntax: need ';'",p);
- // if, for , while の閉じ判定
- p = parse_syntax_close(p + 1);
- return p;
- }
- break;
- case 'c':
- case 'C':
- if(p2 - p == 4 && !strncasecmp(p,"case",4)) {
- // case の処理
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
- disp_error_message("parse_syntax: unexpected 'case' ",p);
- return p+1;
- } else {
- char label[256];
- int l,v;
- char *np;
- if(syntax.curly[pos].count != 1) {
- // FALLTHRU 用のジャンプ
- sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 現在地のラベルを付ける
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos, p);
- }
- // switch 判定文
- p = skip_space(p2);
- if(p == p2) {
- disp_error_message("parse_syntax: expect space ' '",p);
- }
- // check whether case label is integer or not
- v = strtol(p,&np,0);
- if(np == p) { //Check for constants
- p2 = skip_word(p);
- v = p2-p; // length of word at p2
- memcpy(label,p,v);
- label[v]='\0';
- v = search_str(label);
- if (v < 0 || str_data[v].type != C_INT)
- disp_error_message("parse_syntax: 'case' label not integer",p);
- v = str_data[v].val;
- p = skip_word(p);
- } else { //Numeric value
- if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
- p++;
- p = skip_word(p);
- if(np != p)
- disp_error_message("parse_syntax: 'case' label not integer",np);
- }
- p = skip_space(p);
- if(*p != ':')
- disp_error_message("parse_syntax: expect ':'",p);
- sprintf(label,"if(%d != $@__SW%x_VAL) goto __SW%x_%x;",
- v,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- // 2回parse しないとダメ
- p2 = parse_line(label);
- parse_line(p2);
- syntax.curly_count--;
- if(syntax.curly[pos].count != 1) {
- // FALLTHRU 終了後のラベル
- sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- }
- // check duplication of case label [Rayce]
- if(linkdb_search(&syntax.curly[pos].case_label, (void*)v) != NULL)
- disp_error_message("parse_syntax: dup 'case'",p);
- linkdb_insert(&syntax.curly[pos].case_label, (void*)v, (void*)1);
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
-
- parse_line(label);
- syntax.curly_count--;
- syntax.curly[pos].count++;
- }
- return p + 1;
- } else if(p2 - p == 8 && !strncasecmp(p,"continue",8)) {
- // continue の処理
- char label[256];
- int pos = syntax.curly_count - 1;
- while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
- syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
- break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
- break;
- }
- pos--;
- }
- if(pos < 0) {
- disp_error_message("parse_syntax: unexpected 'continue'",p);
- } else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- p = skip_space(p2);
- if(*p != ';')
- disp_error_message("parse_syntax: need ';'",p);
- // if, for , while の閉じ判定
- p = parse_syntax_close(p + 1);
- return p;
- }
- break;
- case 'd':
- case 'D':
- if(p2 - p == 7 && !strncasecmp(p,"default",7)) {
- // switch - default の処理
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
- disp_error_message("parse_syntax: unexpected 'default'",p);
- } else if(syntax.curly[pos].flag) {
- disp_error_message("parse_syntax: dup 'default'",p);
- } else {
- char label[256];
- int l;
- // 現在地のラベルを付ける
- p = skip_space(p2);
- if(*p != ':') {
- disp_error_message("parse_syntax: need ':'",p);
- }
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- // 無条件で次のリンクに飛ばす
- sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // default のラベルを付ける
- sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly[syntax.curly_count - 1].flag = 1;
- syntax.curly[pos].count++;
- }
- return p + 1;
- } else if(p2 - p == 2 && !strncasecmp(p,"do",2)) {
- int l;
- char label[256];
- p=skip_space(p2);
- syntax.curly[syntax.curly_count].type = TYPE_DO;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- // 現在地のラベル形成する
- sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count++;
- return p;
- }
- break;
- case 'f':
- case 'F':
- if(p2 - p == 3 && !strncasecmp(p,"for",3)) {
- int l;
- char label[256];
- int pos = syntax.curly_count;
- syntax.curly[syntax.curly_count].type = TYPE_FOR;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- syntax.curly_count++;
- p=skip_space(p2);
- if(*p != '(')
- disp_error_message("parse_syntax: need '('",p);
- p++;
- // 初期化文を実行する
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
- // 条件判断開始のラベル形成する
- sprintf(label,"__FR%x_J",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- p=skip_space(p);
- if(*p == ';') {
- // for(;;) のパターンなので必ず真
- ;
- } else {
- // 条件が偽なら終了地点に飛ばす
- sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- }
- if(*p != ';')
- disp_error_message("parse_syntax: need ';'",p);
- p++;
- // ループ開始に飛ばす
- sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 次のループへのラベル形成する
- sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- // 次のループに入る時の処理
- // for 最後の ')' を ';' として扱うフラグ
- parse_syntax_for_flag = 1;
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
- parse_syntax_for_flag = 0;
- // 条件判定処理に飛ばす
- sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // ループ開始のラベル付け
- sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- return p;
- }
- else if( p2 - p == 8 && strncasecmp(p,"function",8) == 0 )
- {// internal script function
- const char *func_name;
- func_name = skip_space(p2);
- p = skip_word(func_name);
- if( p == func_name )
- disp_error_message("parse_syntax:function: function name is missing or invalid", p);
- p2 = skip_space(p);
- if( *p2 == ';' )
- {// function <name> ;
- // function declaration - just register the name
- int l;
- l = add_word(func_name);
- if( str_data[l].type == C_NOP )//## ??? [FlavioJS]
- str_data[l].type = C_USERFUNC;
- // if, for , while の閉じ判定
- p = parse_syntax_close(p2 + 1);
- return p; }
- else if(*p2 == '{')
- {// function <name> <line/block of code>
- char label[256];
- int l;
- syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- ++syntax.curly_count;
- // Jump over the function code
- sprintf(label, "goto __FN%x_FIN;", syntax.curly[syntax.curly_count-1].index);
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- ++syntax.curly_count;
- parse_line(label);
- --syntax.curly_count;
- // Set the position of the function (label)
- l=add_word(func_name);
- if( str_data[l].type == C_NOP )//## ??? [FlavioJS]
- str_data[l].type = C_USERFUNC;
- set_label(l, script_pos, p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- strdb_put(scriptlabel_db, get_str(l), (void*)script_pos);
- return skip_space(p);
- }
- else
- {
- disp_error_message("expect ';' or '{' at function syntax",p);
- }
- }
- break;
- case 'i':
- case 'I':
- if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
- // if() の処理
- char label[256];
- p=skip_space(p2);
- if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_IF;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
- syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- return p;
- }
- break;
- case 's':
- case 'S':
- if(p2 - p == 6 && !strncasecmp(p,"switch",6)) {
- // switch() の処理
- char label[256];
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(add_str("set"));
- add_scriptc(C_ARG);
- add_scriptl(add_str(label));
- p=parse_expr(p);
- p=skip_space(p);
- if(*p != '{') {
- disp_error_message("parse_syntax: need '{'",p);
- }
- add_scriptc(C_FUNC);
- return p + 1;
- }
- break;
- case 'w':
- case 'W':
- if(p2 - p == 5 && !strncasecmp(p,"while",5)) {
- int l;
- char label[256];
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_WHILE;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- // 条件判断開始のラベル形成する
- sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- // 条件が偽なら終了地点に飛ばす
- sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- return p;
- }
- break;
- }
- return NULL;
- }
- const char* parse_syntax_close(const char *p) {
- // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
- int flag;
- do {
- p = parse_syntax_close_sub(p,&flag);
- } while(flag);
- return p;
- }
- // if, for , while , do の閉じ判定
- // flag == 1 : 閉じられた
- // flag == 0 : 閉じられない
- const char* parse_syntax_close_sub(const char* p,int* flag)
- {
- char label[256];
- int pos = syntax.curly_count - 1;
- int l;
- *flag = 1;
- if(syntax.curly_count <= 0) {
- *flag = 0;
- return p;
- } else if(syntax.curly[pos].type == TYPE_IF) {
- const char *bp = p;
- const char *p2;
- // if 最終場所へ飛ばす
- sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 現在地のラベルを付ける
- sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly[pos].count++;
- p = skip_space(p);
- p2 = skip_word(p);
- if(!syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) {
- // else or else - if
- p = skip_space(p2);
- p2 = skip_word(p);
- if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
- // else - if
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- *flag = 0;
- return p;
- } else {
- // else
- if(!syntax.curly[pos].flag) {
- syntax.curly[pos].flag = 1;
- *flag = 0;
- return p;
- }
- }
- }
- // if 閉じ
- syntax.curly_count--;
- // 最終地のラベルを付ける
- sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- if(syntax.curly[pos].flag == 1) {
- // このifに対するelseじゃないのでポインタの位置は同じ
- return bp;
- }
- return p;
- } else if(syntax.curly[pos].type == TYPE_DO) {
- int l;
- char label[256];
- const char *p2;
- if(syntax.curly[pos].flag) {
- // 現在地のラベル形成する(continue でここに来る)
- sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- }
- // 条件が偽なら終了地点に飛ばす
- p = skip_space(p);
- p2 = skip_word(p);
- if(p2 - p != 5 || strncasecmp(p,"while",5))
- disp_error_message("parse_syntax: need 'while'",p);
- p = skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- // 開始地点に飛ばす
- sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 条件終了地点のラベル形成する
- sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- p = skip_space(p);
- if(*p != ';') {
- disp_error_message("parse_syntax: need ';'",p);
- return p+1;
- }
- p++;
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- // 次のループに飛ばす
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // for 終了のラベル付け
- sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- // while 条件判断へ飛ばす
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // while 終了のラベル付け
- sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
- int pos = syntax.curly_count-1;
- char label[256];
- int l;
- // 戻す
- sprintf(label,"return;");
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // 現在地のラベルを付ける
- sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else {
- *flag = 0;
- return p;
- }
- }
- /*==========================================
- * 組み込み関数の追加
- *------------------------------------------*/
- static void add_buildin_func(void)
- {
- int i,n;
- const char* p;
- for( i = 0; buildin_func[i].func; i++ )
- {
- // arg must follow the pattern: (v|s|i|r|l)*\?*\*?
- // 'v' - value (either string or int or reference)
- // 's' - string
- // 'i' - int
- // 'r' - reference (of a variable)
- // 'l' - label
- // '?' - one optional parameter
- // '*' - unknown number of optional parameters
- p = buildin_func[i].arg;
- while( *p == 'v' || *p == 's' || *p == 'i' || *p == 'r' || *p == 'l' ) ++p;
- while( *p == '?' ) ++p;
- if( *p == '*' ) ++p;
- if( *p != 0){
- ShowWarning("add_buildin_func: ignoring function \"%s\" with invalid arg \"%s\".\n", buildin_func[i].name, buildin_func[i].arg);
- } else if( *skip_word(buildin_func[i].name) != 0 ){
- ShowWarning("add_buildin_func: ignoring function with invalid name \"%s\" (must be a word).\n", buildin_func[i].name);
- } else {
- n = add_str(buildin_func[i].name);
- str_data[n].type = C_FUNC;
- str_data[n].val = i;
- str_data[n].func = buildin_func[i].func;
- }
- }
- }
- /*==========================================
- * 定数データベースの読み込み
- *------------------------------------------*/
- static void read_constdb(void)
- {
- FILE *fp;
- char line[1024],name[1024],val[1024];
- int n,type;
- sprintf(line, "%s/const.txt", db_path);
- fp=fopen(line, "r");
- if(fp==NULL){
- ShowError("can't read %s\n", line);
- return ;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0]=='/' && line[1]=='/')
- continue;
- type=0;
- if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
- sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
- n=add_str(name);
- if(type==0)
- str_data[n].type=C_INT;
- else
- str_data[n].type=C_PARAM;
- str_data[n].val= (int)strtol(val,NULL,0);
- }
- }
- fclose(fp);
- }
- /*==========================================
- * エラー表示
- *------------------------------------------*/
- static const char* script_print_line(StringBuf* buf, const char* p, const char* mark, int line)
- {
- int i;
- if( p == NULL || !p[0] ) return NULL;
- if( line < 0 )
- StringBuf_Printf(buf, "*% 5d : ", -line);
- else
- StringBuf_Printf(buf, " % 5d : ", line);
- for(i=0;p[i] && p[i] != '\n';i++){
- if(p + i != mark)
- StringBuf_Printf(buf, "%c", p[i]);
- else
- StringBuf_Printf(buf, "\'%c\'", p[i]);
- }
- StringBuf_AppendStr(buf, "\n");
- return p+i+(p[i] == '\n' ? 1 : 0);
- }
- void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos)
- {
- // エラーが発生した行を求める
- int j;
- int line = start_line;
- const char *p;
- const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
- StringBuf buf;
- for(p=src;p && *p;line++){
- const char *lineend=strchr(p,'\n');
- if(lineend==NULL || error_pos<lineend){
- break;
- }
- for( j = 0; j < 4; j++ ) {
- linestart[j] = linestart[j+1];
- }
- linestart[4] = p;
- p=lineend+1;
- }
- StringBuf_Init(&buf);
- StringBuf_AppendStr(&buf, "\a\n");
- StringBuf_Printf(&buf, "script error on %s line %d\n", file, line);
- StringBuf_Printf(&buf, " %s\n", error_msg);
- for(j = 0; j < 5; j++ ) {
- script_print_line(&buf, linestart[j], NULL, line + j - 5);
- }
- p = script_print_line(&buf, p, error_pos, -line);
- for(j = 0; j < 5; j++) {
- p = script_print_line(&buf, p, NULL, line + j + 1 );
- }
- ShowError("%s", StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- }
- /*==========================================
- * スクリプトの解析
- *------------------------------------------*/
- struct script_code* parse_script(const char *src,const char *file,int line,int options)
- {
- const char *p,*tmpp;
- int i;
- struct script_code* code = NULL;
- static int first=1;
- char end;
- if( src == NULL )
- return NULL;// empty script
- memset(&syntax,0,sizeof(syntax));
- if(first){
- add_buildin_func();
- read_constdb();
- first=0;
- }
- script_buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char));
- script_pos=0;
- script_size=SCRIPT_BLOCK_SIZE;
- str_data[LABEL_NEXTLINE].type=C_NOP;
- str_data[LABEL_NEXTLINE].backpatch=-1;
- str_data[LABEL_NEXTLINE].label=-1;
- // who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
- if( options&SCRIPT_USE_LABEL_DB )
- scriptlabel_db->clear(scriptlabel_db, NULL);
- parse_options = options;
- if( setjmp( error_jump ) != 0 ) {
- //Restore program state when script has problems. [from jA]
- int i;
- const int size = ARRAYLENGTH(syntax.curly);
- if( error_report )
- script_error(src,file,line,error_msg,error_pos);
- aFree( error_msg );
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- for(i=LABEL_START;i<str_num;i++)
- if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
- for(i=0; i<size; i++)
- linkdb_final(&syntax.curly[i].case_label);
- return NULL;
- }
- parse_syntax_for_flag=0;
- p=src;
- p=skip_space(p);
- if( options&SCRIPT_IGNORE_EXTERNAL_BRACKETS )
- {// does not require brackets around the script
- if( *p == '\0' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
- {// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- return NULL;
- }
- end = '\0';
- }
- else
- {// requires brackets around the script
- if( *p != '{' )
- disp_error_message("not found '{'",p);
- p = skip_space(p+1);
- if( *p == '}' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
- {// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- return NULL;
- }
- end = '}';
- }
- // clear references of labels, variables and internal functions
- for(i=LABEL_START;i<str_num;i++){
- if(
- str_data[i].type==C_POS || str_data[i].type==C_NAME ||
- str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
- ){
- str_data[i].type=C_NOP;
- str_data[i].backpatch=-1;
- str_data[i].label=-1;
- }
- }
- while( syntax.curly_count != 0 || *p != end )
- {
- if( *p == '\0' )
- disp_error_message("unexpected end of script",p);
- // labelだけ特殊処理
- tmpp=skip_space(skip_word(p));
- if(*tmpp==':' && !(!strncasecmp(p,"default:",8) && p + 7 == tmpp)){
- i=add_word(p);
- set_label(i,script_pos,p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- strdb_put(scriptlabel_db, get_str(i), (void*)script_pos);
- p=tmpp+1;
- p=skip_space(p);
- continue;
- }
- // 他は全部一緒くた
- p=parse_line(p);
- p=skip_space(p);
- add_scriptc(C_EOL);
- set_label(LABEL_NEXTLINE,script_pos,p);
- str_data[LABEL_NEXTLINE].type=C_NOP;
- str_data[LABEL_NEXTLINE].backpatch=-1;
- str_data[LABEL_NEXTLINE].label=-1;
- }
- add_scriptc(C_NOP);
- // trim code to size
- script_size = script_pos;
- RECREATE(script_buf,unsigned char,script_pos);
- // default unknown references to variables
- for(i=LABEL_START;i<str_num;i++){
- if(str_data[i].type==C_NOP){
- int j,next;
- str_data[i].type=C_NAME;
- str_data[i].label=i;
- for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
- next=GETVALUE(script_buf,j);
- SETVALUE(script_buf,j,i);
- j=next;
- }
- }
- }
- #ifdef DEBUG_DISP
- for(i=0;i<script_pos;i++){
- if((i&15)==0) printf("%04x : ",i);
- ShowMessage("%02x ",script_buf[i]);
- if((i&15)==15) printf("\n");
- }
- ShowMessage("\n");
- #endif
- #ifdef DEBUG_DISASM
- {
- int i = 0,j;
- while(i < script_pos) {
- ShowMessage("%06x ",i);
- j = i;
- switch(get_com(script_buf,&i)) {
- case C_EOL: printf("C_EOL"); break;
- case C_INT: printf("C_INT %d",get_num(script_buf,&i)); break;
- case C_POS:
- ShowMessage("C_POS 0x%06x",*(int*)(script_buf+i)&0xffffff);
- i += 3;
- break;
- case C_NAME:
- j = (*(int*)(script_buf+i)&0xffffff);
- ShowMessage("C_NAME %s",j == 0xffffff ? "?? unknown ??" : get_str(j));
- i += 3;
- break;
- case C_ARG: ShowMessage("C_ARG"); break;
- case C_FUNC: ShowMessage("C_FUNC"); break;
- case C_ADD: ShowMessage("C_ADD"); break;
- case C_SUB: ShowMessage("C_SUB"); break;
- case C_MUL: ShowMessage("C_MUL"); break;
- case C_DIV: ShowMessage("C_DIV"); break;
- case C_MOD: ShowMessage("C_MOD"); break;
- case C_EQ: ShowMessage("C_EQ"); break;
- case C_NE: ShowMessage("C_NE"); break;
- case C_GT: ShowMessage("C_GT"); break;
- case C_GE: ShowMessage("C_GE"); break;
- case C_LT: ShowMessage("C_LT"); break;
- case C_LE: ShowMessage("C_LE"); break;
- case C_AND: ShowMessage("C_AND"); break;
- case C_OR: ShowMessage("C_OR"); break;
- case C_XOR: ShowMessage("C_XOR"); break;
- case C_LAND: ShowMessage("C_LAND"); break;
- case C_LOR: ShowMessage("C_LOR"); break;
- case C_R_SHIFT: ShowMessage("C_R_SHIFT"); break;
- case C_L_SHIFT: ShowMessage("C_L_SHIFT"); break;
- case C_NEG: ShowMessage("C_NEG"); break;
- case C_NOT: ShowMessage("C_NOT"); break;
- case C_LNOT: ShowMessage("C_LNOT"); break;
- case C_NOP: ShowMessage("C_NOP"); break;
- case C_OP3: ShowMessage("C_OP3"); break;
- case C_STR:
- j = strlen(script_buf + i);
- ShowMessage("C_STR %s",script_buf + i);
- i+= j+1;
- break;
- default:
- ShowMessage("unknown");
- }
- ShowMessage(CL_CLL "\n");
- }
- }
- #endif
- CREATE(code,struct script_code,1);
- code->script_buf = script_buf;
- code->script_size = script_size;
- code->script_vars = NULL;
- return code;
- }
- /// Returns the player attached to this script, identified by the rid.
- /// If there is no player attached, the script is terminated.
- TBL_PC *script_rid2sd(struct script_state *st)
- {
- TBL_PC *sd=map_id2sd(st->rid);
- if(!sd){
- ShowError("script_rid2sd: fatal error ! player not attached!\n");
- script_reportsrc(st);
- st->state = END;
- }
- return sd;
- }
- /// Dereferences a variable/constant, replacing it with a copy of the value.
- ///
- /// @param st Script state
- /// @param data Variable/constant
- void get_val(struct script_state* st, struct script_data* data)
- {
- const char* name;
- char prefix;
- char postfix;
- TBL_PC* sd = NULL;
- if( !data_isreference(data) )
- return;// not a variable/constant
- name = reference_getname(data);
- prefix = name[0];
- postfix = name[strlen(name) - 1];
- //##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS]
- if( !reference_toconstant(data) && not_server_variable(prefix) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {// needs player attached
- if( postfix == '$' )
- {// string variable
- ShowWarning("script:get_val: cannot access player variable '%s', defaulting to \"\"\n", name);
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- else
- {// integer variable
- ShowWarning("script:get_val: cannot access player variable '%s', defaulting to 0\n", name);
- data->type = C_INT;
- data->u.num = 0;
- }
- return;
- }
- }
- if( postfix == '$' )
- {// string variable
- switch( prefix )
- {
- case '@':
- data->u.str = pc_readregstr(sd, data->u.num);
- break;
- case '$':
- data->u.str = mapreg_readregstr(data->u.num);
- break;
- case '#':
- if( name[1] == '#' )
- data->u.str = pc_readaccountreg2str(sd, name);// global
- else
- data->u.str = pc_readaccountregstr(sd, name);// local
- break;
- case '.':
- {
- struct linkdb_node** n =
- data->ref ? data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- &st->script->script_vars;// npc variable
- data->u.str = (char*)linkdb_search(n, (void*)reference_getuid(data));
- }
- break;
- case '\'':
- {
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].svar;
- data->u.str = (char*)linkdb_search(n, (void*)reference_getuid(data));
- }
- break;
- default:
- data->u.str = pc_readglobalreg_str(sd, name);
- break;
- }
- if( data->u.str == NULL || data->u.str[0] == '\0' )
- {// empty string
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- else
- {// duplicate string
- data->type = C_STR;
- data->u.str = aStrdup(data->u.str);
- }
- }
- else
- {// integer variable
- data->type = C_INT;
- if( reference_toconstant(data) )
- {
- data->u.num = reference_getconstant(data);
- }
- else if( reference_toparam(data) )
- {
- data->u.num = pc_readparam(sd, reference_getparamtype(data));
- }
- else
- switch( prefix )
- {
- case '@':
- data->u.num = pc_readreg(sd, data->u.num);
- break;
- case '$':
- data->u.num = mapreg_readreg(data->u.num);
- break;
- case '#':
- if( name[1] == '#' )
- data->u.num = pc_readaccountreg2(sd, name);// global
- else
- data->u.num = pc_readaccountreg(sd, name);// local
- break;
- case '.':
- {
- struct linkdb_node** n =
- data->ref ? data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- &st->script->script_vars;// npc variable
- data->u.num = (int)linkdb_search(n, (void*)reference_getuid(data));
- }
- break;
- case '\'':
- {
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].ivar;
- data->u.num = (int)linkdb_search(n, (void*)reference_getuid(data));
- }
- break;
- default:
- data->u.num = pc_readglobalreg(sd, name);
- break;
- }
- }
- return;
- }
- struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct linkdb_node** ref);
- /// Retrieves the value of a reference identified by uid (variable, constant, param)
- /// The value is left in the top of the stack and needs to be removed manually.
- void* get_val2(struct script_state* st, int uid, struct linkdb_node** ref)
- {
- struct script_data* data;
- push_val2(st->stack, C_NAME, uid, ref);
- data = script_getdatatop(st, -1);
- get_val(st, data);
- return (data->type == C_INT ? (void*)data->u.num : (void*)data->u.str);
- }
- /*==========================================
- * Stores the value of a script variable
- * Return value is 0 on fail, 1 on success.
- *------------------------------------------*/
- static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct linkdb_node** ref)
- {
- char prefix = name[0];
- if( is_string_variable(name) )
- {// string variable
- const char* str = (const char*)value;
- switch (prefix) {
- case '@':
- return pc_setregstr(sd, num, str);
- case '$':
- return mapreg_setregstr(num, str);
- case '#':
- return (name[1] == '#') ?
- pc_setaccountreg2str(sd, name, str) :
- pc_setaccountregstr(sd, name, str);
- case '.': {
- char* p;
- struct linkdb_node** n;
- n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
- p = (char*)linkdb_erase(n, (void*)num);
- if (p) aFree(p);
- if (str[0]) linkdb_insert(n, (void*)num, aStrdup(str));
- }
- return 1;
- case '\'': {
- char *p;
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].svar;
- p = (char*)linkdb_erase(n, (void*)num);
- if (p) aFree(p);
- if( str[0] ) linkdb_insert(n, (void*)num, aStrdup(str));
- }
- return 1;
- default:
- return pc_setglobalreg_str(sd, name, str);
- }
- }
- else
- {// integer variable
- int val = (int)value;
- if(str_data[num&0x00ffffff].type == C_PARAM)
- {
- if( pc_setparam(sd, str_data[num&0x00ffffff].val, val) == 0 )
- {
- if( st != NULL )
- {
- ShowError("script:set_reg: failed to set param '%s' to %d.\n", name, val);
- script_reportsrc(st);
- st->state = END;
- }
- return 0;
- }
- return 1;
- }
- switch (prefix) {
- case '@':
- return pc_setreg(sd, num, val);
- case '$':
- return mapreg_setreg(num, val);
- case '#':
- return (name[1] == '#') ?
- pc_setaccountreg2(sd, name, val) :
- pc_setaccountreg(sd, name, val);
- case '.': {
- struct linkdb_node** n;
- n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
- if (val == 0)
- linkdb_erase(n, (void*)num);
- else
- linkdb_replace(n, (void*)num, (void*)val);
- }
- return 1;
- case '\'':
- {
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].ivar;
- if( val == 0 )
- linkdb_erase(n, (void*)num);
- else
- linkdb_replace(n, (void*)num, (void*)val);
- return 1;
- }
- default:
- return pc_setglobalreg(sd, name, val);
- }
- }
- }
- int set_var(TBL_PC* sd, char* name, void* val)
- {
- return set_reg(NULL, sd, reference_uid(add_str(name),0), name, val, NULL);
- }
- void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct linkdb_node **ref)
- {
- set_reg(st, sd, reference_uid(add_str(varname),elem), varname, value, ref);
- }
- /// Converts the data to a string
- const char* conv_str(struct script_state* st, struct script_data* data)
- {
- char* p;
- get_val(st, data);
- if( data_isstring(data) )
- {// nothing to convert
- }
- else if( data_isint(data) )
- {// int -> string
- CREATE(p, char, ITEM_NAME_LENGTH);
- snprintf(p, ITEM_NAME_LENGTH, "%d", data->u.num);
- p[ITEM_NAME_LENGTH-1] = '\0';
- data->type = C_STR;
- data->u.str = p;
- }
- else if( data_isreference(data) )
- {// reference -> string
- //##TODO when does this happen (check get_val) [FlavioJS]
- data->type = C_CONSTSTR;
- data->u.str = reference_getname(data);
- }
- else
- {// unsupported data type
- ShowError("script:conv_str: cannot convert to string, defaulting to \"\"\n");
- script_reportdata(data);
- script_reportsrc(st);
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- return data->u.str;
- }
- /// Converts the data to an int
- int conv_num(struct script_state* st, struct script_data* data)
- {
- char* p;
- long num;
- get_val(st, data);
- if( data_isint(data) )
- {// nothing to convert
- }
- else if( data_isstring(data) )
- {// string -> int
- // the result does not overflow or underflow, it is capped instead
- // ex: 999999999999 is capped to INT_MAX (2147483647)
- p = data->u.str;
- errno = 0;
- num = strtol(data->u.str, NULL, 10);// change radix to 0 to support octal numbers "o377" and hex numbers "0xFF"
- if( errno == ERANGE
- #if LONG_MAX > INT_MAX
- || num < INT_MIN || num > INT_MAX
- #endif
- )
- {
- if( num <= INT_MIN )
- {
- num = INT_MIN;
- ShowError("script:conv_num: underflow detected, capping to %ld\n", num);
- }
- else//if( num >= INT_MAX )
- {
- num = INT_MAX;
- ShowError("script:conv_num: overflow detected, capping to %ld\n", num);
- }
- script_reportdata(data);
- script_reportsrc(st);
- }
- if( data->type == C_STR )
- aFree(p);
- data->type = C_INT;
- data->u.num = (int)num;
- }
- #if 0
- // FIXME this function is being used to retrieve the position of labels and
- // probably other stuff [FlavioJS]
- else
- {// unsupported data type
- ShowError("script:conv_num: cannot convert to number, defaulting to 0\n");
- script_reportdata(data);
- script_reportsrc(st);
- data->type = C_INT;
- data->u.num = 0;
- }
- #endif
- return data->u.num;
- }
- //
- // Stack operations
- //
- /// Increases the size of the stack
- void stack_expand(struct script_stack* stack)
- {
- stack->sp_max += 64;
- stack->stack_data = (struct script_data*)aRealloc(stack->stack_data,
- stack->sp_max * sizeof(stack->stack_data[0]) );
- memset(stack->stack_data + (stack->sp_max - 64), 0,
- 64 * sizeof(stack->stack_data[0]) );
- }
- /// Pushes a value into the stack
- #define push_val(stack,type,val) push_val2(stack, type, val, NULL)
- /// Pushes a value into the stack (with reference)
- struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct linkdb_node** ref)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = type;
- stack->stack_data[stack->sp].u.num = val;
- stack->stack_data[stack->sp].ref = ref;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a string into the stack
- struct script_data* push_str(struct script_stack* stack, enum c_op type, char* str)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = type;
- stack->stack_data[stack->sp].u.str = str;
- stack->stack_data[stack->sp].ref = NULL;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a retinfo into the stack
- struct script_data* push_retinfo(struct script_stack* stack, struct script_retinfo* ri)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = C_RETINFO;
- stack->stack_data[stack->sp].u.ri = ri;
- stack->stack_data[stack->sp].ref = NULL;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a copy of the target position into the stack
- struct script_data* push_copy(struct script_stack* stack, int pos)
- {
- switch( stack->stack_data[pos].type )
- {
- case C_CONSTSTR:
- return push_str(stack, C_CONSTSTR, stack->stack_data[pos].u.str);
- break;
- case C_STR:
- return push_str(stack, C_STR, aStrdup(stack->stack_data[pos].u.str));
- break;
- case C_RETINFO:
- ShowFatalError("script:push_copy: can't create copies of C_RETINFO. Exiting...\n");
- exit(1);
- break;
- default:
- return push_val2(
- stack,stack->stack_data[pos].type,
- stack->stack_data[pos].u.num,
- stack->stack_data[pos].ref
- );
- break;
- }
- }
- /// Removes the values in indexes [start,end[ from the stack.
- /// Adjusts all stack pointers.
- void pop_stack(struct script_state* st, int start, int end)
- {
- struct script_stack* stack = st->stack;
- struct script_data* data;
- int i;
- if( start < 0 )
- start = 0;
- if( end > stack->sp )
- end = stack->sp;
- if( start >= end )
- return;// nothing to pop
- // free stack elements
- for( i = start; i < end; i++ )
- {
- data = &stack->stack_data[i];
- if( data->type == C_STR )
- aFree(data->u.str);
- if( data->type == C_RETINFO )
- {
- struct script_retinfo* ri = data->u.ri;
- if( ri->var_function )
- {
- script_free_vars(ri->var_function);
- aFree(ri->var_function);
- }
- aFree(ri);
- }
- data->type = C_NOP;
- }
- // move the rest of the elements
- if( stack->sp > end )
- {
- memmove(&stack->stack_data[start], &stack->stack_data[end], sizeof(stack->stack_data[0])*(stack->sp - end));
- for( i = start + stack->sp - end; i < stack->sp; ++i )
- stack->stack_data[i].type = C_NOP;
- }
- // adjust stack pointers
- if( st->start > end ) st->start -= end - start;
- else if( st->start > start ) st->start = start;
- if( st->end > end ) st->end -= end - start;
- else if( st->end > start ) st->end = start;
- if( stack->defsp > end ) stack->defsp -= end - start;
- else if( stack->defsp > start ) stack->defsp = start;
- stack->sp -= end - start;
- }
- ///
- ///
- ///
- /*==========================================
- * スクリプト依存変数、関数依存変数の解放
- *------------------------------------------*/
- void script_free_vars(struct linkdb_node **node)
- {
- struct linkdb_node* n = *node;
- while( n != NULL)
- {
- const char* name = get_str((int)(n->key)&0x00ffffff);
- if( is_string_variable(name) )
- aFree(n->data); // 文字型変数なので、データ削除
- n = n->next;
- }
- linkdb_final( node );
- }
- void script_free_code(struct script_code* code)
- {
- script_free_vars( &code->script_vars );
- aFree( code->script_buf );
- aFree( code );
- }
- /// Creates a new script state.
- ///
- /// @param script Script code
- /// @param pos Position in the code
- /// @param rid Who is running the script (attached player)
- /// @param oid Where the code is being run (npc 'object')
- /// @return Script state
- struct script_state* script_alloc_state(struct script_code* script, int pos, int rid, int oid)
- {
- struct script_state* st;
- CREATE(st, struct script_state, 1);
- st->stack = (struct script_stack*)aMalloc(sizeof(struct script_stack));
- st->stack->sp = 0;
- st->stack->sp_max = 64;
- CREATE(st->stack->stack_data, struct script_data, st->stack->sp_max);
- st->stack->defsp = st->stack->sp;
- CREATE(st->stack->var_function, struct linkdb_node*, 1);
- st->state = RUN;
- st->script = script;
- //st->scriptroot = script;
- st->pos = pos;
- st->rid = rid;
- st->oid = oid;
- st->sleep.timer = INVALID_TIMER;
- return st;
- }
- /// Frees a script state.
- ///
- /// @param st Script state
- void script_free_state(struct script_state* st)
- {
- if(st->bk_st)
- {// backup was not restored
- ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- }
- if( st->sleep.timer != INVALID_TIMER )
- delete_timer(st->sleep.timer, run_script_timer);
- script_free_vars(st->stack->var_function);
- aFree(st->stack->var_function);
- pop_stack(st, 0, st->stack->sp);
- aFree(st->stack->stack_data);
- aFree(st->stack);
- st->pos = -1;
- aFree(st);
- }
- //
- // 実行部main
- //
- /*==========================================
- * コマンドの読み取り
- *------------------------------------------*/
- c_op get_com(unsigned char *script,int *pos)
- {
- int i = 0, j = 0;
- if(script[*pos]>=0x80){
- return C_INT;
- }
- while(script[*pos]>=0x40){
- i=script[(*pos)++]<<j;
- j+=6;
- }
- return (c_op)(i+(script[(*pos)++]<<j));
- }
- /*==========================================
- * 数値の所得
- *------------------------------------------*/
- int get_num(unsigned char *script,int *pos)
- {
- int i,j;
- i=0; j=0;
- while(script[*pos]>=0xc0){
- i+=(script[(*pos)++]&0x7f)<<j;
- j+=6;
- }
- return i+((script[(*pos)++]&0x7f)<<j);
- }
- /*==========================================
- * スタックから値を取り出す
- *------------------------------------------*/
- int pop_val(struct script_state* st)
- {
- if(st->stack->sp<=0)
- return 0;
- st->stack->sp--;
- get_val(st,&(st->stack->stack_data[st->stack->sp]));
- if(st->stack->stack_data[st->stack->sp].type==C_INT)
- return st->stack->stack_data[st->stack->sp].u.num;
- return 0;
- }
- /// Ternary operators
- /// test ? if_true : if_false
- void op_3(struct script_state* st, int op)
- {
- struct script_data* data;
- int flag = 0;
- data = script_getdatatop(st, -3);
- get_val(st, data);
- if( data_isstring(data) )
- flag = data->u.str[0];// "" -> false
- else if( data_isint(data) )
- flag = data->u.num;// 0 -> false
- else
- {
- ShowError("script:op_3: invalid data for the ternary operator test\n");
- script_reportdata(data);
- script_reportsrc(st);
- script_removetop(st, -3, 0);
- script_pushnil(st);
- return;
- }
- if( flag )
- script_pushcopytop(st, -2);
- else
- script_pushcopytop(st, -1);
- script_removetop(st, -4, -1);
- }
- /// Binary string operators
- /// s1 EQ s2 -> i
- /// s1 NE s2 -> i
- /// s1 GT s2 -> i
- /// s1 GE s2 -> i
- /// s1 LT s2 -> i
- /// s1 LE s2 -> i
- /// s1 ADD s2 -> s
- void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
- {
- int a = 0;
- switch(op){
- case C_EQ: a = (strcmp(s1,s2) == 0); break;
- case C_NE: a = (strcmp(s1,s2) != 0); break;
- case C_GT: a = (strcmp(s1,s2) > 0); break;
- case C_GE: a = (strcmp(s1,s2) >= 0); break;
- case C_LT: a = (strcmp(s1,s2) < 0); break;
- case C_LE: a = (strcmp(s1,s2) <= 0); break;
- case C_ADD:
- {
- char* buf = (char *)aMallocA((strlen(s1)+strlen(s2)+1)*sizeof(char));
- strcpy(buf, s1);
- strcat(buf, s2);
- script_pushstr(st, buf);
- return;
- }
- default:
- ShowError("script:op2_str: unexpected string operator %s\n", script_op2name(op));
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- script_pushint(st,a);
- }
- /// Binary number operators
- /// i OP i -> i
- void op_2num(struct script_state* st, int op, int i1, int i2)
- {
- int ret;
- double ret_double;
- switch( op )
- {
- case C_AND: ret = i1 & i2; break;
- case C_OR: ret = i1 | i2; break;
- case C_XOR: ret = i1 ^ i2; break;
- case C_LAND: ret = (i1 && i2); break;
- case C_LOR: ret = (i1 || i2); break;
- case C_EQ: ret = (i1 == i2); break;
- case C_NE: ret = (i1 != i2); break;
- case C_GT: ret = (i1 > i2); break;
- case C_GE: ret = (i1 >= i2); break;
- case C_LT: ret = (i1 < i2); break;
- case C_LE: ret = (i1 <= i2); break;
- case C_R_SHIFT: ret = i1>>i2; break;
- case C_L_SHIFT: ret = i1<<i2; break;
- case C_DIV:
- case C_MOD:
- if( i2 == 0 )
- {
- ShowError("script:op_2num: division by zero detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- else if( op == C_DIV )
- ret = i1 / i2;
- else//if( op == C_MOD )
- ret = i1 % i2;
- break;
- default:
- switch( op )
- {// operators that can overflow/underflow
- case C_ADD: ret = i1 + i2; ret_double = (double)i1 + (double)i2; break;
- case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
- case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
- default:
- ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- script_pushnil(st);
- return;
- }
- if( ret_double < (double)INT_MIN )
- {
- ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- ret = INT_MIN;
- }
- else if( ret_double > (double)INT_MAX )
- {
- ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- ret = INT_MAX;
- }
- }
- script_pushint(st, ret);
- }
- /// Binary operators
- void op_2(struct script_state *st, int op)
- {
- struct script_data* left;
- struct script_data* right;
- left = script_getdatatop(st, -2);
- right = script_getdatatop(st, -1);
- get_val(st, left);
- get_val(st, right);
- // automatic conversions
- switch( op )
- {
- case C_ADD:
- if( data_isint(left) && data_isstring(right) )
- {// convert int-string to string-string
- conv_str(st, left);
- }
- else if( data_isstring(left) && data_isint(right) )
- {// convert string-int to string-string
- conv_str(st, right);
- }
- break;
- }
- if( data_isstring(left) && data_isstring(right) )
- {// ss => op_2str
- op_2str(st, op, left->u.str, right->u.str);
- script_removetop(st, -3, -1);// pop the two values before the top one
- }
- else if( data_isint(left) && data_isint(right) )
- {// ii => op_2num
- int i1 = left->u.num;
- int i2 = right->u.num;
- script_removetop(st, -2, 0);
- op_2num(st, op, i1, i2);
- }
- else
- {// invalid argument
- ShowError("script:op_2: invalid data for operator %s\n", script_op2name(op));
- script_reportdata(left);
- script_reportdata(right);
- script_reportsrc(st);
- script_removetop(st, -2, 0);
- script_pushnil(st);
- st->state = END;
- }
- }
- /// Unary operators
- /// NEG i -> i
- /// NOT i -> i
- /// LNOT i -> i
- void op_1(struct script_state* st, int op)
- {
- struct script_data* data;
- int i1;
- data = script_getdatatop(st, -1);
- get_val(st, data);
- if( !data_isint(data) )
- {// not a number
- ShowError("script:op_1: argument is not a number (op=%s)\n", script_op2name(op));
- script_reportdata(data);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- i1 = data->u.num;
- script_removetop(st, -1, 0);
- switch( op )
- {
- case C_NEG: i1 = -i1; break;
- case C_NOT: i1 = ~i1; break;
- case C_LNOT: i1 = !i1; break;
- default:
- ShowError("script:op_1: unexpected operator %s i1=%d\n", script_op2name(op), i1);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- script_pushint(st, i1);
- }
- /// Executes a buildin command.
- /// Stack: C_NAME(<command>) C_ARG <arg0> <arg1> ... <argN>
- int run_func(struct script_state *st)
- {
- struct script_data* data;
- int i,start_sp,end_sp,func;
- end_sp = st->stack->sp;// position after the last argument
- for( i = end_sp-1; i > 0 ; --i )
- if( st->stack->stack_data[i].type == C_ARG )
- break;
- if( i == 0 )
- {
- ShowError("script:run_func: C_ARG not found. please report this!!!\n");
- st->state = END;
- script_reportsrc(st);
- return 1;
- }
- start_sp = i-1;// C_NAME of the command
- st->start = start_sp;
- st->end = end_sp;
- data = &st->stack->stack_data[st->start];
- if( data->type == C_NAME && str_data[data->u.num].type == C_FUNC )
- func = data->u.num;
- else
- {
- ShowError("script:run_func: not a buildin command.\n");
- script_reportdata(data);
- script_reportsrc(st);
- st->state = END;
- return 1;
- }
- if(str_data[func].func){
- if (str_data[func].func(st)) //Report error
- script_reportsrc(st);
- } else {
- ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(str_data[func].type));
- script_reportsrc(st);
- st->state = END;
- }
- // Stack's datum are used when re-running functions [Eoe]
- if( st->state == RERUNLINE )
- return 0;
- pop_stack(st, st->start, st->end);
- if( st->state == RETFUNC )
- {// return from a user-defined function
- struct script_retinfo* ri;
- int olddefsp = st->stack->defsp;
- int nargs;
- pop_stack(st, st->stack->defsp, st->start);// pop distractions from the stack
- if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO )
- {
- ShowWarning("script:run_func: return without callfunc or callsub!\n");
- script_reportsrc(st);
- st->state = END;
- return 1;
- }
- script_free_vars( st->stack->var_function );
- aFree(st->stack->var_function);
- ri = st->stack->stack_data[st->stack->defsp-1].u.ri;
- nargs = ri->nargs;
- st->pos = ri->pos;
- st->script = ri->script;
- st->stack->var_function = ri->var_function;
- st->stack->defsp = ri->defsp;
- memset(ri, 0, sizeof(struct script_retinfo));
- pop_stack(st, olddefsp-nargs-1, olddefsp);// pop arguments and retinfo
- st->state = GOTO;
- }
- return 0;
- }
- /*==========================================
- * script execution
- *------------------------------------------*/
- void run_script_main(struct script_state *st);
- void run_script(struct script_code *rootscript,int pos,int rid,int oid)
- {
- struct script_state *st;
- if( rootscript == NULL || pos < 0 )
- return;
- // TODO In jAthena, this function can take over the pending script in the player. [FlavioJS]
- // It is unclear how that can be triggered, so it needs the be traced/checked in more detail.
- // NOTE At the time of this change, this function wasn't capable of taking over the script state because st->scriptroot was never set.
- st = script_alloc_state(rootscript, pos, rid, oid);
- run_script_main(st);
- }
- void script_stop_sleeptimers(int id)
- {
- struct script_state* st;
- for(;;)
- {
- st = (struct script_state*)linkdb_erase(&sleep_db,(void*)id);
- if( st == NULL )
- break; // no more sleep timers
- script_free_state(st);
- }
- }
- /*==========================================
- * 指定ノードをsleep_dbから削除
- *------------------------------------------*/
- struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
- {
- struct linkdb_node *retnode;
- if( n == NULL)
- return NULL;
- if( n->prev == NULL )
- sleep_db = n->next;
- else
- n->prev->next = n->next;
- if( n->next )
- n->next->prev = n->prev;
- retnode = n->next;
- aFree( n );
- return retnode; // 次のノードを返す
- }
- /*==========================================
- * sleep用タイマー関数
- *------------------------------------------*/
- int run_script_timer(int tid, unsigned int tick, int id, intptr data)
- {
- struct script_state *st = (struct script_state *)data;
- struct linkdb_node *node = (struct linkdb_node *)sleep_db;
- TBL_PC *sd = map_id2sd(st->rid);
- if((sd && sd->status.char_id != id) || (st->rid && !sd))
- { //Character mismatch. Cancel execution.
- st->rid = 0;
- st->state = END;
- }
- while( node && st->sleep.timer != -1 ) {
- if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
- script_erase_sleepdb(node);
- st->sleep.timer = INVALID_TIMER;
- break;
- }
- node = node->next;
- }
- if(st->state != RERUNLINE)
- st->sleep.tick = 0;
- run_script_main(st);
- return 0;
- }
- /// Detaches script state from possibly attached character and restores it's previous script if any.
- ///
- /// @param st Script state to detach.
- /// @param dequeue_event Whether to schedule any queued events, when there was no previous script.
- static void script_detach_state(struct script_state* st, bool dequeue_event)
- {
- struct map_session_data* sd;
- if(st->rid && (sd = map_id2sd(st->rid))!=NULL)
- {
- sd->st = st->bk_st;
- sd->npc_id = st->bk_npcid;
- if(st->bk_st)
- {
- //Remove tag for removal.
- st->bk_st = NULL;
- st->bk_npcid = 0;
- }
- else if(dequeue_event)
- {
- npc_event_dequeue(sd);
- }
- }
- else if(st->bk_st)
- {// rid was set to 0, before detaching the script state
- ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%d, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- script_reportsrc(st->bk_st);
- script_free_state(st->bk_st);
- st->bk_st = NULL;
- }
- }
- /// Attaches script state to possibly attached character and backups it's previous script, if any.
- ///
- /// @param st Script state to attach.
- static void script_attach_state(struct script_state* st)
- {
- struct map_session_data* sd;
- if(st->rid && (sd = map_id2sd(st->rid))!=NULL)
- {
- if(st!=sd->st)
- {
- if(st->bk_st)
- {// there is already a backup
- ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- }
- st->bk_st = sd->st;
- st->bk_npcid = sd->npc_id;
- }
- sd->st = st;
- sd->npc_id = st->oid;
- }
- }
- /*==========================================
- * スクリプトの実行メイン部分
- *------------------------------------------*/
- void run_script_main(struct script_state *st)
- {
- int cmdcount=script_config.check_cmdcount;
- int gotocount=script_config.check_gotocount;
- TBL_PC *sd;
- struct script_stack *stack=st->stack;
- struct npc_data *nd;
- script_attach_state(st);
- nd = map_id2nd(st->oid);
- if( nd && map[nd->bl.m].instance_id > 0 )
- st->instance_id = map[nd->bl.m].instance_id;
- if(st->state == RERUNLINE) {
- run_func(st);
- if(st->state == GOTO)
- st->state = RUN;
- } else if(st->state != END)
- st->state = RUN;
- while(st->state == RUN)
- {
- enum c_op c = get_com(st->script->script_buf,&st->pos);
- switch(c){
- case C_EOL:
- if( stack->defsp > stack->sp )
- ShowError("script:run_script_main: unexpected stack position (defsp=%d sp=%d). please report this!!!\n", stack->defsp, stack->sp);
- else
- pop_stack(st, stack->defsp, stack->sp);// pop unused stack data. (unused return value)
- break;
- case C_INT:
- push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos));
- break;
- case C_POS:
- case C_NAME:
- push_val(stack,c,GETVALUE(st->script->script_buf,st->pos));
- st->pos+=3;
- break;
- case C_ARG:
- push_val(stack,c,0);
- break;
- case C_STR:
- push_str(stack,C_CONSTSTR,(char*)(st->script->script_buf+st->pos));
- while(st->script->script_buf[st->pos++]);
- break;
- case C_FUNC:
- run_func(st);
- if(st->state==GOTO){
- st->state = RUN;
- if( gotocount>0 && (--gotocount)<=0 ){
- ShowError("run_script: infinity loop !\n");
- script_reportsrc(st);
- st->state=END;
- }
- }
- break;
- case C_NEG:
- case C_NOT:
- case C_LNOT:
- op_1(st ,c);
- break;
- case C_ADD:
- case C_SUB:
- case C_MUL:
- case C_DIV:
- case C_MOD:
- case C_EQ:
- case C_NE:
- case C_GT:
- case C_GE:
- case C_LT:
- case C_LE:
- case C_AND:
- case C_OR:
- case C_XOR:
- case C_LAND:
- case C_LOR:
- case C_R_SHIFT:
- case C_L_SHIFT:
- op_2(st, c);
- break;
- case C_OP3:
- op_3(st, c);
- break;
- case C_NOP:
- st->state=END;
- break;
- default:
- ShowError("unknown command : %d @ %d\n",c,st->pos);
- st->state=END;
- break;
- }
- if( cmdcount>0 && (--cmdcount)<=0 ){
- ShowError("run_script: infinity loop !\n");
- script_reportsrc(st);
- st->state=END;
- }
- }
- if(st->sleep.tick > 0) {
- //Restore previous script
- script_detach_state(st, false);
- //Delay execution
- sd = map_id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish]
- st->sleep.charid = sd?sd->status.char_id:0;
- st->sleep.timer = add_timer(gettick()+st->sleep.tick,
- run_script_timer, st->sleep.charid, (intptr)st);
- linkdb_insert(&sleep_db, (void*)st->oid, st);
- }
- else if(st->state != END && st->rid){
- //Resume later (st is already attached to player).
- if(st->bk_st) {
- ShowWarning("Unable to restore stack! Double continuation!\n");
- //Report BOTH scripts to see if that can help somehow.
- ShowDebug("Previous script (lost):\n");
- script_reportsrc(st->bk_st);
- ShowDebug("Current script:\n");
- script_reportsrc(st);
- script_free_state(st->bk_st);
- st->bk_st = NULL;
- }
- } else {
- //Dispose of script.
- if ((sd = map_id2sd(st->rid))!=NULL)
- { //Restore previous stack and save char.
- if(sd->state.using_fake_npc){
- clif_clearunit_single(sd->npc_id, 0, sd->fd);
- sd->state.using_fake_npc = 0;
- }
- //Restore previous script if any.
- script_detach_state(st, true);
- if (sd->state.reg_dirty&2)
- intif_saveregistry(sd,2);
- if (sd->state.reg_dirty&1)
- intif_saveregistry(sd,1);
- }
- script_free_state(st);
- st = NULL;
- }
- }
- int script_config_read(char *cfgName)
- {
- int i;
- char line[1024],w1[1024],w2[1024];
- FILE *fp;
- fp=fopen(cfgName,"r");
- if(fp==NULL){
- ShowError("file not found: [%s]\n", cfgName);
- return 1;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0] == '/' && line[1] == '/')
- continue;
- i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
- if(i!=2)
- continue;
- if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
- script_config.warn_func_mismatch_paramnum = config_switch(w2);
- }
- else if(strcmpi(w1,"check_cmdcount")==0) {
- script_config.check_cmdcount = config_switch(w2);
- }
- else if(strcmpi(w1,"check_gotocount")==0) {
- script_config.check_gotocount = config_switch(w2);
- }
- else if(strcmpi(w1,"input_min_value")==0) {
- script_config.input_min_value = config_switch(w2);
- }
- else if(strcmpi(w1,"input_max_value")==0) {
- script_config.input_max_value = config_switch(w2);
- }
- else if(strcmpi(w1,"import")==0){
- script_config_read(w2);
- }
- }
- fclose(fp);
- return 0;
- }
- static int do_final_userfunc_sub (DBKey key,void *data,va_list ap)
- {
- struct script_code *code = (struct script_code *)data;
- if(code){
- script_free_vars( &code->script_vars );
- aFree( code->script_buf );
- aFree( code );
- }
- return 0;
- }
- static int do_final_autobonus_sub (DBKey key,void *data,va_list ap)
- {
- struct script_code *script = (struct script_code *)data;
- if( script )
- script_free_code(script);
- return 0;
- }
- void script_run_autobonus(const char *autobonus, int id, int pos)
- {
- struct script_code *script = (struct script_code *)strdb_get(autobonus_db, autobonus);
- if( script )
- {
- current_equip_item_index = pos;
- run_script(script,0,id,0);
- }
- }
- void script_add_autobonus(const char *autobonus)
- {
- if( strdb_get(autobonus_db, autobonus) == NULL )
- {
- struct script_code *script = parse_script(autobonus, "autobonus", 0, 0);
- if( script )
- strdb_put(autobonus_db, autobonus, script);
- }
- }
- /*==========================================
- * 終了
- *------------------------------------------*/
- int do_final_script()
- {
- #ifdef DEBUG_HASH
- if (battle_config.etc_log)
- {
- FILE *fp = fopen("hash_dump.txt","wt");
- if(fp) {
- int i,count[SCRIPT_HASH_SIZE];
- int count2[SCRIPT_HASH_SIZE]; // number of buckets with a certain number of items
- int n=0;
- int min=INT_MAX,max=0,zero=0;
- double mean=0.0f;
- double median=0.0f;
- ShowNotice("Dumping script str hash information to hash_dump.txt\n");
- memset(count, 0, sizeof(count));
- fprintf(fp,"num : hash : data_name\n");
- fprintf(fp,"---------------------------------------------------------------\n");
- for(i=LABEL_START; i<str_num; i++) {
- unsigned int h = calc_hash(get_str(i));
- fprintf(fp,"%04d : %4u : %s\n",i,h, get_str(i));
- ++count[h];
- }
- fprintf(fp,"--------------------\n\n");
- memset(count2, 0, sizeof(count2));
- for(i=0; i<SCRIPT_HASH_SIZE; i++) {
- fprintf(fp," hash %3d = %d\n",i,count[i]);
- if(min > count[i])
- min = count[i]; // minimun count of collision
- if(max < count[i])
- max = count[i]; // maximun count of collision
- if(count[i] == 0)
- zero++;
- ++count2[count[i]];
- }
- fprintf(fp,"\n--------------------\n items : buckets\n--------------------\n");
- for( i=min; i <= max; ++i ){
- fprintf(fp," %5d : %7d\n",i,count2[i]);
- mean += 1.0f*i*count2[i]/SCRIPT_HASH_SIZE; // Note: this will always result in <nr labels>/<nr buckets>
- }
- for( i=min; i <= max; ++i ){
- n += count2[i];
- if( n*2 >= SCRIPT_HASH_SIZE )
- {
- if( SCRIPT_HASH_SIZE%2 == 0 && SCRIPT_HASH_SIZE/2 == n )
- median = (i+i+1)/2.0f;
- else
- median = i;
- break;
- }
- }
- fprintf(fp,"--------------------\n min = %d, max = %d, zero = %d\n mean = %lf, median = %lf\n",min,max,zero,mean,median);
- fclose(fp);
- }
- }
- #endif
- mapreg_final();
- scriptlabel_db->destroy(scriptlabel_db,NULL);
- userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
- autobonus_db->destroy(autobonus_db, do_final_autobonus_sub);
- if(sleep_db) {
- struct linkdb_node *n = (struct linkdb_node *)sleep_db;
- while(n) {
- struct script_state *st = (struct script_state *)n->data;
- script_free_state(st);
- n = n->next;
- }
- linkdb_final(&sleep_db);
- }
- if (str_data)
- aFree(str_data);
- if (str_buf)
- aFree(str_buf);
- return 0;
- }
- /*==========================================
- * 初期化
- *------------------------------------------*/
- int do_init_script()
- {
- userfunc_db=strdb_alloc(DB_OPT_DUP_KEY,0);
- scriptlabel_db=strdb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA),50);
- autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
- mapreg_init();
-
- return 0;
- }
- int script_reload()
- {
- userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
- scriptlabel_db->clear(scriptlabel_db, NULL);
- if(sleep_db) {
- struct linkdb_node *n = (struct linkdb_node *)sleep_db;
- while(n) {
- struct script_state *st = (struct script_state *)n->data;
- script_free_state(st);
- n = n->next;
- }
- linkdb_final(&sleep_db);
- }
- mapreg_reload();
- return 0;
- }
- //-----------------------------------------------------------------------------
- // buildin functions
- //
- #define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
- #define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
- #define BUILDIN_FUNC(x) int buildin_ ## x (struct script_state* st)
- /////////////////////////////////////////////////////////////////////
- // NPC interaction
- //
- /// Appends a message to the npc dialog.
- /// If a dialog doesn't exist yet, one is created.
- ///
- /// mes "<message>";
- BUILDIN_FUNC(mes)
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_scriptmes(sd, st->oid, script_getstr(st, 2));
- return 0;
- }
- /// Displays the button 'next' in the npc dialog.
- /// The dialog text is cleared and the script continues when the button is pressed.
- ///
- /// next;
- BUILDIN_FUNC(next)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- st->state = STOP;
- clif_scriptnext(sd, st->oid);
- return 0;
- }
- /// Ends the script and displays the button 'close' on the npc dialog.
- /// The dialog is closed when the button is pressed.
- ///
- /// close;
- BUILDIN_FUNC(close)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- st->state = END;
- clif_scriptclose(sd, st->oid);
- return 0;
- }
- /// Displays the button 'close' on the npc dialog.
- /// The dialog is closed and the script continues when the button is pressed.
- ///
- /// close2;
- BUILDIN_FUNC(close2)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- st->state = STOP;
- clif_scriptclose(sd, st->oid);
- return 0;
- }
- /// Counts the number of valid and total number of options in 'str'
- /// If max_count > 0 the counting stops when that valid option is reached
- /// total is incremented for each option (NULL is supported)
- static int menu_countoptions(const char* str, int max_count, int* total)
- {
- int count = 0;
- int bogus_total;
- if( total == NULL )
- total = &bogus_total;
- ++(*total);
- // initial empty options
- while( *str == ':' )
- {
- ++str;
- ++(*total);
- }
- // count menu options
- while( *str != '\0' )
- {
- ++count;
- --max_count;
- if( max_count == 0 )
- break;
- while( *str != ':' && *str != '\0' )
- ++str;
- while( *str == ':' )
- {
- ++str;
- ++(*total);
- }
- }
- return count;
- }
- /// Displays a menu with options and goes to the target label.
- /// The script is stopped if cancel is pressed.
- /// Options with no text are not displayed in the client.
- ///
- /// Options can be grouped together, separated by the character ':' in the text:
- /// ex: menu "A:B:C",L_target;
- /// All these options go to the specified target label.
- ///
- /// The index of the selected option is put in the variable @menu.
- /// Indexes start with 1 and are consistent with grouped and empty options.
- /// ex: menu "A::B",-,"",L_Impossible,"C",-;
- /// // displays "A", "B" and "C", corresponding to indexes 1, 3 and 5
- ///
- /// NOTE: the client closes the npc dialog when cancel is pressed
- ///
- /// menu "<option_text>",<target_label>{,"<option_text>",<target_label>,...};
- BUILDIN_FUNC(menu)
- {
- int i;
- const char* text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- // TODO detect multiple scripts waiting for input at the same time, and what to do when that happens
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
- struct script_data* data;
- if( script_lastdata(st) % 2 == 0 )
- {// argument count is not even (1st argument is at index 2)
- ShowError("script:menu: illegal number of arguments (%d).\n", (script_lastdata(st) - 1));
- st->state = END;
- return 1;
- }
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i < script_lastdata(st); i += 2 )
- {
- // menu options
- text = script_getstr(st, i);
- // target label
- data = script_getdata(st, i+1);
- if( !data_islabel(data) )
- {// not a label
- StringBuf_Destroy(&buf);
- ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i);
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- // append option(s)
- if( text[0] == '\0' )
- continue;// empty string, ignore
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- //TODO what's the maximum number of options that can be displayed and/or received? -> give warning
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- st->state = END;
- }
- else
- {// goto target label
- int menu = 0;
- sd->state.menu_or_input = 0;
- if( sd->npc_menu <= 0 )
- {
- ShowDebug("script:menu: unexpected selection (%d)\n", sd->npc_menu);
- st->state = END;
- return 1;
- }
- // get target label
- for( i = 2; i < script_lastdata(st); i += 2 )
- {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- if( sd->npc_menu > 0 )
- {// Invalid selection
- ShowDebug("script:menu: selection is out of range (%d pairs are missing?) - please report this\n", sd->npc_menu);
- st->state = END;
- return 1;
- }
- if( !data_islabel(script_getdata(st, i + 1)) )
- {// TODO remove this temporary crash-prevention code (fallback for multiple scripts requesting user input)
- ShowError("script:menu: unexpected data in label argument\n");
- script_reportdata(script_getdata(st, i + 1));
- st->state = END;
- return 1;
- }
- pc_setreg(sd, add_str("@menu"), menu);
- st->pos = script_getnum(st, i + 1);
- st->state = GOTO;
- }
- return 0;
- }
- /// Displays a menu with options and returns the selected option.
- /// Behaves like 'menu' without the target labels.
- ///
- /// select(<option_text>{,<option_text>,...}) -> <selected_option>
- ///
- /// @see menu
- BUILDIN_FUNC(select)
- {
- int i;
- const char* text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- st->state = END;
- }
- else
- {// return selected option
- int menu = 0;
- sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- pc_setreg(sd, add_str("@menu"), menu);
- script_pushint(st, menu);
- st->state = RUN;
- }
- return 0;
- }
- /// Displays a menu with options and returns the selected option.
- /// Behaves like 'menu' without the target labels, except when cancel is
- /// pressed.
- /// When cancel is pressed, the script continues and 255 is returned.
- ///
- /// prompt(<option_text>{,<option_text>,...}) -> <selected_option>
- ///
- /// @see menu
- BUILDIN_FUNC(prompt)
- {
- int i;
- const char *text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- pc_setreg(sd, add_str("@menu"), 0xff);
- script_pushint(st, 0xff);
- st->state = RUN;
- }
- else
- {// return selected option
- int menu = 0;
- sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- pc_setreg(sd, add_str("@menu"), menu);
- script_pushint(st, menu);
- st->state = RUN;
- }
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- // ...
- //
- /// Jumps to the target script label.
- ///
- /// goto <label>;
- BUILDIN_FUNC(goto)
- {
- if( !data_islabel(script_getdata(st,2)) )
- {
- ShowError("script:goto: not a label\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- st->pos = script_getnum(st,2);
- st->state = GOTO;
- return 0;
- }
- /*==========================================
- * user-defined function call
- *------------------------------------------*/
- BUILDIN_FUNC(callfunc)
- {
- int i, j;
- struct script_retinfo* ri;
- struct script_code* scr;
- const char* str = script_getstr(st,2);
- scr = (struct script_code*)strdb_get(userfunc_db, str);
- if( !scr )
- {
- ShowError("script:callfunc: function not found! [%s]\n", str);
- st->state = END;
- return 1;
- }
- for( i = st->start+3, j = 0; i < st->end; i++, j++ )
- {
- struct script_data* data = push_copy(st->stack,i);
- if( data_isreference(data) && !data->ref )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' && name[1] == '@' )
- data->ref = st->stack->var_function;
- else if( name[0] == '.' )
- data->ref = &st->script->script_vars;
- }
- }
- CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri);
- st->pos = 0;
- st->script = scr;
- st->stack->defsp = st->stack->sp;
- st->state = GOTO;
- st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
- return 0;
- }
- /*==========================================
- * subroutine call
- *------------------------------------------*/
- BUILDIN_FUNC(callsub)
- {
- int i,j;
- struct script_retinfo* ri;
- int pos = script_getnum(st,2);
- if( !data_islabel(script_getdata(st,2)) && !data_isfunclabel(script_getdata(st,2)) )
- {
- ShowError("script:callsub: argument is not a label\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- for( i = st->start+3, j = 0; i < st->end; i++, j++ )
- {
- struct script_data* data = push_copy(st->stack,i);
- if( data_isreference(data) && !data->ref )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' && name[1] == '@' )
- data->ref = st->stack->var_function;
- }
- }
- CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri);
- st->pos = pos;
- st->stack->defsp = st->stack->sp;
- st->state = GOTO;
- st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
- return 0;
- }
- /// Retrieves an argument provided to callfunc/callsub.
- /// If the argument doesn't exist
- ///
- /// getarg(<index>{,<default_value>}) -> <value>
- BUILDIN_FUNC(getarg)
- {
- struct script_retinfo* ri;
- int idx;
- if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO )
- {
- ShowError("script:getarg: no callfunc or callsub!\n");
- st->state = END;
- return 1;
- }
- ri = st->stack->stack_data[st->stack->defsp - 1].u.ri;
- idx = script_getnum(st,2);
- if( idx >= 0 && idx < ri->nargs )
- push_copy(st->stack, st->stack->defsp - 1 - ri->nargs + idx);
- else if( script_hasdata(st,3) )
- script_pushcopy(st, 3);
- else
- {
- ShowError("script:getarg: index (idx=%d) out of range (nargs=%d) and no default value found\n", idx, ri->nargs);
- st->state = END;
- return 1;
- }
- return 0;
- }
- /// Returns from the current function, optionaly returning a value from the functions.
- /// Don't use outside script functions.
- ///
- /// return;
- /// return <value>;
- BUILDIN_FUNC(return)
- {
- if( script_hasdata(st,2) )
- {// return value
- struct script_data* data;
- script_pushcopy(st, 2);
- data = script_getdatatop(st, -1);
- if( data_isreference(data) )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' && name[1] == '@' )
- {// scope variable
- if( !data->ref || data->ref == st->stack->var_function )
- get_val(st, data);// current scope, convert to value
- }
- else if( name[0] == '.' && !data->ref )
- {// script variable, link to current script
- data->ref = &st->script->script_vars;
- }
- }
- }
- else
- {// no return value
- script_pushnil(st);
- }
- st->state = RETFUNC;
- return 0;
- }
- /// Returns a random number from 0 to <range>-1.
- /// Or returns a random number from <min> to <max>.
- /// If <min> is greater than <max>, their numbers are switched.
- /// rand(<range>) -> <int>
- /// rand(<min>,<max>) -> <int>
- BUILDIN_FUNC(rand)
- {
- int range;
- int min;
- int max;
- if( script_hasdata(st,3) )
- {// min,max
- min = script_getnum(st,2);
- max = script_getnum(st,3);
- if( max < min )
- swap(min, max);
- range = max - min + 1;
- }
- else
- {// range
- min = 0;
- range = script_getnum(st,2);
- }
- if( range <= 1 )
- script_pushint(st, min);
- else
- script_pushint(st, rand()%range + min);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(warp)
- {
- int ret;
- int x,y;
- const char* str;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- str = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if(strcmp(str,"Random")==0)
- ret = pc_randomwarp(sd,3);
- else if(strcmp(str,"SavePoint")==0 || strcmp(str,"Save")==0)
- ret = pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
- else
- ret = pc_setpos(sd,mapindex_name2id(str),x,y,0);
- if( ret ) {
- ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y);
- script_reportsrc(st);
- }
- return 0;
- }
- /*==========================================
- * エリア指定ワープ
- *------------------------------------------*/
- static int buildin_areawarp_sub(struct block_list *bl,va_list ap)
- {
- int x,y;
- unsigned int map;
- map=va_arg(ap, unsigned int);
- x=va_arg(ap,int);
- y=va_arg(ap,int);
- if(map == 0)
- pc_randomwarp((TBL_PC *)bl,3);
- else
- pc_setpos((TBL_PC *)bl,map,x,y,0);
- return 0;
- }
- BUILDIN_FUNC(areawarp)
- {
- int x,y,m;
- unsigned int index;
- const char *str;
- const char *mapname;
- int x0,y0,x1,y1;
- mapname=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- str=script_getstr(st,7);
- x=script_getnum(st,8);
- y=script_getnum(st,9);
- if( (m=map_mapname2mapid(mapname))< 0)
- return 0;
- if(strcmp(str,"Random")==0)
- index = 0;
- else if(!(index=mapindex_name2id(str)))
- return 0;
- map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1,BL_PC, index,x,y);
- return 0;
- }
- /*==========================================
- * areapercentheal <map>,<x1>,<y1>,<x2>,<y2>,<hp>,<sp>
- *------------------------------------------*/
- static int buildin_areapercentheal_sub(struct block_list *bl,va_list ap)
- {
- int hp, sp;
- hp = va_arg(ap, int);
- sp = va_arg(ap, int);
- pc_percentheal((TBL_PC *)bl,hp,sp);
- return 0;
- }
- BUILDIN_FUNC(areapercentheal)
- {
- int hp,sp,m;
- const char *mapname;
- int x0,y0,x1,y1;
- mapname=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- hp=script_getnum(st,7);
- sp=script_getnum(st,8);
- if( (m=map_mapname2mapid(mapname))< 0)
- return 0;
- map_foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp);
- return 0;
- }
- /*==========================================
- * warpchar [LuzZza]
- * Useful for warp one player from
- * another player npc-session.
- * Using: warpchar "mapname",x,y,Char_ID;
- *------------------------------------------*/
- BUILDIN_FUNC(warpchar)
- {
- int x,y,a;
- const char *str;
- TBL_PC *sd;
-
- str=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- a=script_getnum(st,5);
- sd = map_charid2sd(a);
- if( sd == NULL )
- return 0;
- if(strcmp(str, "Random") == 0)
- pc_randomwarp(sd, 3);
- else
- if(strcmp(str, "SavePoint") == 0)
- pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, 3);
- else
- pc_setpos(sd, mapindex_name2id(str), x, y, 3);
-
- return 0;
- }
- /*==========================================
- * Warpparty - [Fredzilla] [Paradox924X]
- * Syntax: warpparty "to_mapname",x,y,Party_ID,{"from_mapname"};
- * If 'from_mapname' is specified, only the party members on that map will be warped
- *------------------------------------------*/
- BUILDIN_FUNC(warpparty)
- {
- TBL_PC *sd;
- TBL_PC *pl_sd;
- struct party_data* p;
- int type;
- int mapindex;
- int i, j;
- const char* str = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- int p_id = script_getnum(st,5);
- const char* str2 = NULL;
- if ( script_hasdata(st,6) )
- str2 = script_getstr(st,6);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- p = party_search(p_id);
- if(!p)
- return 0;
-
- if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
- return 0;
-
- type = ( strcmp(str,"Random")==0 ) ? 0
- : ( strcmp(str,"SavePointAll")==0 ) ? 1
- : ( strcmp(str,"SavePoint")==0 ) ? 2
- : ( strcmp(str,"Leader")==0 ) ? 3
- : 4;
- for (i = 0; i < MAX_PARTY; i++)
- {
- if( !(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id )
- continue;
- if( str2 && strcmp(str2, map[pl_sd->bl.m].name) != 0 )
- continue;
- if( pc_isdead(pl_sd) )
- continue;
- switch( type )
- {
- case 0: // Random
- if(!map[pl_sd->bl.m].flag.nowarp)
- pc_randomwarp(pl_sd,3);
- break;
- case 1: // SavePointAll
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
- break;
- case 2: // SavePoint
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
- break;
- case 3: // Leader
- for(j = 0; j < MAX_PARTY && !p->party.member[j].leader; j++);
- if (j == MAX_PARTY || !p->data[j].sd) //Leader not found / not online
- return 0;
- mapindex = p->data[j].sd->mapindex;
- x = p->data[j].sd->bl.x;
- y = p->data[j].sd->bl.y;
- for (j = 0; j < MAX_PARTY; j++)
- {
- pl_sd = p->data[j].sd;
- if (!pl_sd)
- continue;
- if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
- continue;
- pc_setpos(pl_sd,mapindex,x,y,3);
- }
- break;
- case 4: // m,x,y
- if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp)
- pc_setpos(pl_sd,mapindex_name2id(str),x,y,3);
- break;
- }
- }
- return 0;
- }
- /*==========================================
- * Warpguild - [Fredzilla]
- * Syntax: warpguild "mapname",x,y,Guild_ID;
- *------------------------------------------*/
- BUILDIN_FUNC(warpguild)
- {
- TBL_PC *sd;
- TBL_PC *pl_sd;
- struct guild* g;
- struct s_mapiterator* iter;
- int type;
- const char* str = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- int gid = script_getnum(st,5);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- g = guild_search(gid);
- if( g == NULL )
- return 0;
-
- if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
- return 0;
-
- type = ( strcmp(str,"Random")==0 ) ? 0
- : ( strcmp(str,"SavePointAll")==0 ) ? 1
- : ( strcmp(str,"SavePoint")==0 ) ? 2
- : 3;
- iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
- {
- if( pl_sd->status.guild_id != gid )
- continue;
- switch( type )
- {
- case 0: // Random
- if(!map[pl_sd->bl.m].flag.nowarp)
- pc_randomwarp(pl_sd,3);
- break;
- case 1: // SavePointAll
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
- break;
- case 2: // SavePoint
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
- break;
- case 3: // m,x,y
- if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp)
- pc_setpos(pl_sd,mapindex_name2id(str),x,y,3);
- break;
- }
- }
- mapit_free(iter);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(heal)
- {
- TBL_PC *sd;
- int hp,sp;
-
- sd = script_rid2sd(st);
- if (!sd) return 0;
-
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- status_heal(&sd->bl, hp, sp, 1);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(itemheal)
- {
- TBL_PC *sd;
- int hp,sp;
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_hp = hp;
- potion_sp = sp;
- return 0;
- }
-
- sd = script_rid2sd(st);
- if (!sd) return 0;
- pc_itemheal(sd,sd->itemid,hp,sp);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(percentheal)
- {
- int hp,sp;
- TBL_PC* sd;
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_per_hp = hp;
- potion_per_sp = sp;
- return 0;
- }
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_percentheal(sd,hp,sp);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(jobchange)
- {
- int job, upper=-1;
- job=script_getnum(st,2);
- if( script_hasdata(st,3) )
- upper=script_getnum(st,3);
- if (pcdb_checkid(job))
- {
- TBL_PC* sd;
-
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_jobchange(sd, job, upper);
- }
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(jobname)
- {
- int class_=script_getnum(st,2);
- script_pushconststr(st,job_name(class_));
- return 0;
- }
- /// Get input from the player.
- /// For numeric inputs the value is capped to the range [min,max]. Returns 1 if
- /// the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
- /// For string inputs it returns 1 if the string was longer than 'max', -1 is
- /// shorter than 'min' and 0 otherwise.
- ///
- /// input(<var>{,<min>{,<max>}}) -> <int>
- BUILDIN_FUNC(input)
- {
- TBL_PC* sd;
- struct script_data* data;
- int uid;
- const char* name;
- int min;
- int max;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- data = script_getdata(st,2);
- if( !data_isreference(data) ){
- ShowError("script:input: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- uid = reference_getuid(data);
- name = reference_getname(data);
- min = (script_hasdata(st,3) ? script_getnum(st,3) : script_config.input_min_value);
- max = (script_hasdata(st,4) ? script_getnum(st,4) : script_config.input_max_value);
- if( !sd->state.menu_or_input )
- { // first invocation, display npc input box
- sd->state.menu_or_input = 1;
- st->state = RERUNLINE;
- if( is_string_variable(name) )
- clif_scriptinputstr(sd,st->oid);
- else
- clif_scriptinput(sd,st->oid);
- }
- else
- { // take received text/value and store it in the designated variable
- sd->state.menu_or_input = 0;
- if( is_string_variable(name) )
- {
- int len = (int)strlen(sd->npc_str);
- set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
- script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
- }
- else
- {
- int amount = sd->npc_amount;
- set_reg(st, sd, uid, name, (void*)cap_value(amount,min,max), script_getref(st,2));
- script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
- }
- st->state = RUN;
- }
- return 0;
- }
- /// Sets the value of a variable.
- /// The value is converted to the type of the variable.
- ///
- /// set(<variable>,<value>) -> <variable>
- BUILDIN_FUNC(set)
- {
- TBL_PC* sd = NULL;
- struct script_data* data;
- int num;
- const char* name;
- char prefix;
- data = script_getdata(st,2);
- if( !data_isreference(data) )
- {
- ShowError("script:set: not a variable\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- num = reference_getuid(data);
- name = reference_getname(data);
- prefix = *name;
- if( not_server_variable(prefix) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {
- ShowError("script:set: no player attached for player variable '%s'\n", name);
- return 0;
- }
- }
- if( is_string_variable(name) )
- set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2));
- else
- set_reg(st,sd,num,name,(void*)script_getnum(st,3),script_getref(st,2));
- // return a copy of the variable reference
- script_pushcopy(st,2);
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- /// Array variables
- ///
- /// Returns the size of the specified array
- static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct linkdb_node** ref)
- {
- int32 ret = idx;
- if( isstring )
- {
- for( ; idx < 128; ++idx )
- {
- char* str = (char*)get_val2(st, reference_uid(id, idx), ref);
- if( str && *str )
- ret = idx + 1;
- script_removetop(st, -1, 0);
- }
- }
- else
- {
- for( ; idx < 128; ++idx )
- {
- int32 num = (int32)get_val2(st, reference_uid(id, idx), ref);
- if( num )
- ret = idx + 1;
- script_removetop(st, -1, 0);
- }
- }
- return ret;
- }
- /// Sets values of an array, from the starting index.
- /// ex: setarray arr[1],1,2,3;
- ///
- /// setarray <array variable>,<value1>{,<value2>...};
- BUILDIN_FUNC(setarray)
- {
- struct script_data* data;
- const char* name;
- int32 start;
- int32 end;
- int32 id;
- int32 i;
- TBL_PC* sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:setarray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:setarray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- end = start + script_lastdata(st) - 2;
- if( end > 127 )
- end = 127;
- if( is_string_variable(name) )
- {// string array
- for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data));
- }
- else
- {// int array
- for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)script_getnum(st,i), reference_getref(data));
- }
- return 0;
- }
- /// Sets count values of an array, from the starting index.
- /// ex: cleararray arr[0],0,1;
- ///
- /// cleararray <array variable>,<value>,<count>;
- BUILDIN_FUNC(cleararray)
- {
- struct script_data* data;
- const char* name;
- int32 start;
- int32 end;
- int32 id;
- void* v;
- TBL_PC* sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:cleararray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:cleararray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- if( is_string_variable(name) )
- v = (void*)script_getstr(st, 3);
- else
- v = (void*)script_getnum(st, 3);
- end = start + script_getnum(st, 4);
- if( end > 127 )
- end = 127;
- for( ; start <= end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2));
- return 0;
- }
- /// Copies data from one array to another.
- /// ex: copyarray arr[0],arr[2],2;
- ///
- /// copyarray <destination array variable>,<source array variable>,<count>;
- BUILDIN_FUNC(copyarray)
- {
- struct script_data* data1;
- struct script_data* data2;
- const char* name1;
- const char* name2;
- int32 idx1;
- int32 idx2;
- int32 id1;
- int32 id2;
- void* v;
- int32 i;
- int32 count;
- TBL_PC* sd = NULL;
- data1 = script_getdata(st, 2);
- data2 = script_getdata(st, 3);
- if( !data_isreference(data1) || !data_isreference(data2) )
- {
- ShowError("script:copyarray: not a variable\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// not a variable
- }
- id1 = reference_getid(data1);
- id2 = reference_getid(data2);
- idx1 = reference_getindex(data1);
- idx2 = reference_getindex(data2);
- name1 = reference_getname(data1);
- name2 = reference_getname(data2);
- if( not_array_variable(*name1) || not_array_variable(*name2) )
- {
- ShowError("script:copyarray: illegal scope\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// not supported
- }
- if( is_string_variable(name1) != is_string_variable(name2) )
- {
- ShowError("script:copyarray: type mismatch\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// data type mismatch
- }
- if( not_server_variable(*name1) || not_server_variable(*name2) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- count = script_getnum(st, 4);
- if( count > 128 - idx1 )
- count = 128 - idx1;
- if( count <= 0 || (id1 == id2 && idx1 == idx2) )
- return 0;// nothing to copy
- if( id1 == id2 && idx1 > idx2 )
- {// destination might be overlapping the source - copy in reverse order
- for( i = count - 1; i >= 0; --i )
- {
- v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2));
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
- script_removetop(st, -1, 0);
- }
- }
- else
- {// normal copy
- for( i = 0; i < count; ++i )
- {
- if( idx2 + i < 128 )
- {
- v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2));
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
- script_removetop(st, -1, 0);
- }
- else// out of range - assume ""/0
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1));
- }
- }
- return 0;
- }
- /// Returns the size of the array.
- /// Assumes that everything before the starting index exists.
- /// ex: getarraysize(arr[3])
- ///
- /// getarraysize(<array variable>) -> <int>
- BUILDIN_FUNC(getarraysize)
- {
- struct script_data* data;
- const char* name;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:getarraysize: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not a variable
- }
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:getarraysize: illegal scope\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not supported
- }
- script_pushint(st, getarraysize(st, reference_getid(data), reference_getindex(data), is_string_variable(name), reference_getref(data)));
- return 0;
- }
- /// Deletes count or all the elements in an array, from the starting index.
- /// ex: deletearray arr[4],2;
- ///
- /// deletearray <array variable>;
- /// deletearray <array variable>,<count>;
- BUILDIN_FUNC(deletearray)
- {
- struct script_data* data;
- const char* name;
- int start;
- int end;
- int id;
- TBL_PC *sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:deletearray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:deletearray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- end = getarraysize(st, id, start, is_string_variable(name), reference_getref(data));
- if( start >= end )
- return 0;// nothing to free
- if( script_hasdata(st,3) )
- {
- int count = script_getnum(st, 3);
- if( count > end - start )
- count = end - start;
- if( count <= 0 )
- return 0;// nothing to free
- // move rest of the elements backward
- for( ; start + count < end; ++start )
- {
- void* v = get_val2(st, reference_uid(id, start + count), reference_getref(data));
- set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
- script_removetop(st, -1, 0);
- }
- }
- // clear the rest of the array
- if( is_string_variable(name) )
- {
- for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void *)"", reference_getref(data));
- }
- else
- {
- for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void*)0, reference_getref(data));
- }
- return 0;
- }
- /// Returns a reference to the target index of the array variable.
- /// Equivalent to var[index].
- ///
- /// getelementofarray(<array variable>,<index>) -> <variable reference>
- BUILDIN_FUNC(getelementofarray)
- {
- struct script_data* data;
- const char* name;
- int32 id;
- int i;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:getelementofarray: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:getelementofarray: illegal scope\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not supported
- }
- i = script_getnum(st, 3);
- if( i < 0 || i >= 128 )
- {
- ShowWarning("script:getelementofarray: index out of range (%d)\n", i);
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// out of range
- }
- push_val2(st->stack, C_NAME, reference_uid(id, i), reference_getref(data));
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- /// ...
- ///
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(setlook)
- {
- int type,val;
- TBL_PC* sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_changelook(sd,type,val);
- return 0;
- }
- BUILDIN_FUNC(changelook)
- { // As setlook but only client side
- int type,val;
- TBL_PC* sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_changelook(&sd->bl,type,val);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(cutin)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_cutin(sd,script_getstr(st,2),script_getnum(st,3));
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(viewpoint)
- {
- int type,x,y,id,color;
- TBL_PC* sd;
- type=script_getnum(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- id=script_getnum(st,5);
- color=script_getnum(st,6);
-
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_viewpoint(sd,st->oid,type,x,y,id,color);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(countitem)
- {
- int nameid, i;
- int count = 0;
- struct script_data* data;
- TBL_PC* sd = script_rid2sd(st);
- if (!sd) {
- script_pushint(st,0);
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) {
- const char* name = conv_str(st,data);
- struct item_data* item_data;
- if((item_data = itemdb_searchname(name)) != NULL)
- nameid = item_data->nameid;
- else
- nameid = 0;
- } else
- nameid = conv_num(st,data);
- if (nameid < 500) {
- ShowError("wrong item ID : countitem(%i)\n", nameid);
- script_reportsrc(st);
- script_pushint(st,0);
- return 1;
- }
- for(i = 0; i < MAX_INVENTORY; i++)
- if(sd->status.inventory[i].nameid == nameid)
- count += sd->status.inventory[i].amount;
- script_pushint(st,count);
- return 0;
- }
- /*==========================================
- * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
- * returns number of items that meet the conditions
- *------------------------------------------*/
- BUILDIN_FUNC(countitem2)
- {
- int nameid, iden, ref, attr, c1, c2, c3, c4;
- int count = 0;
- int i;
- struct script_data* data;
-
- TBL_PC* sd = script_rid2sd(st);
- if (!sd) {
- script_pushint(st,0);
- return 0;
- }
-
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) {
- const char* name = conv_str(st,data);
- struct item_data* item_data;
- if((item_data = itemdb_searchname(name)) != NULL)
- nameid = item_data->nameid;
- else
- nameid = 0;
- } else
- nameid = conv_num(st,data);
-
- iden = script_getnum(st,3);
- ref = script_getnum(st,4);
- attr = script_getnum(st,5);
- c1 = (short)script_getnum(st,6);
- c2 = (short)script_getnum(st,7);
- c3 = (short)script_getnum(st,8);
- c4 = (short)script_getnum(st,9);
-
- if (nameid < 500) {
- ShowError("wrong item ID : countitem2(%i)\n", nameid);
- script_pushint(st,0);
- return 1;
- }
-
- for(i = 0; i < MAX_INVENTORY; i++)
- if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] != NULL &&
- sd->status.inventory[i].amount > 0 && sd->status.inventory[i].nameid == nameid &&
- sd->status.inventory[i].identify == iden && sd->status.inventory[i].refine == ref &&
- sd->status.inventory[i].attribute == attr && sd->status.inventory[i].card[0] == c1 &&
- sd->status.inventory[i].card[1] == c2 && sd->status.inventory[i].card[2] == c3 &&
- sd->status.inventory[i].card[3] == c4
- )
- count += sd->status.inventory[i].amount;
- script_pushint(st,count);
- return 0;
- }
- /*==========================================
- * 重量チェック
- *------------------------------------------*/
- BUILDIN_FUNC(checkweight)
- {
- int nameid=0,amount,i;
- unsigned long weight;
- TBL_PC *sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- nameid=item_data->nameid;
- }else
- nameid=conv_num(st,data);
- amount=script_getnum(st,3);
- if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
- script_pushint(st,0);
- ShowError("buildin_checkweight: Wrong item ID or amount.\n");
- return 1;
- }
- weight = itemdb_weight(nameid)*amount;
- if( amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight )
- script_pushint(st,0);
- else if( itemdb_isstackable(nameid) )
- {
- if( (i = pc_search_inventory(sd,nameid)) >= 0 )
- script_pushint(st,amount + sd->status.inventory[i].amount > MAX_AMOUNT ? 0 : 1);
- else
- script_pushint(st,pc_search_inventory(sd,0) >= 0 ? 1 : 0);
- }
- else
- {
- for( i = 0; i < MAX_INVENTORY && amount; ++i )
- if( sd->status.inventory[i].nameid == 0 )
- amount--;
- script_pushint(st,amount ? 0 : 1);
- }
- return 0;
- }
- /*==========================================
- * getitem <item id>,<amount>{,<character ID>};
- * getitem "<item name>",<amount>{,<character ID>};
- *------------------------------------------*/
- BUILDIN_FUNC(getitem)
- {
- int nameid,amount,get_count,i,flag = 0;
- struct item it;
- TBL_PC *sd;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) )
- {// "<item name>"
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data == NULL ){
- ShowError("buildin_getitem: Nonexistant item %s requested.\n", name);
- return 1; //No item created.
- }
- nameid=item_data->nameid;
- } else if( data_isint(data) )
- {// <item id>
- nameid=conv_num(st,data);
- //Violet Box, Blue Box, etc - random item pick
- if( nameid < 0 ) {
- nameid=itemdb_searchrandomid(-nameid);
- flag = 1;
- }
- if( nameid <= 0 || !itemdb_exists(nameid) ){
- ShowError("buildin_getitem: Nonexistant item %d requested.\n", nameid);
- return 1; //No item created.
- }
- } else {
- ShowError("buildin_getitem: invalid data type for argument #1 (%d).", data->type);
- return 1;
- }
- // <amount>
- if( (amount=script_getnum(st,3)) <= 0)
- return 0; //return if amount <=0, skip the useles iteration
- memset(&it,0,sizeof(it));
- it.nameid=nameid;
- if(!flag)
- it.identify=1;
- else
- it.identify=itemdb_isidentified(nameid);
- if( script_hasdata(st,4) )
- sd=map_id2sd(script_getnum(st,4)); // <Account ID>
- else
- sd=script_rid2sd(st); // Attached player
- if( sd == NULL ) // no target
- return 0;
- //Check if it's stackable.
- if (!itemdb_isstackable(nameid))
- get_count = 1;
- else
- get_count = amount;
- for (i = 0; i < amount; i += get_count)
- {
- // if not pet egg
- if (!pet_create_egg(sd, nameid))
- {
- if ((flag = pc_additem(sd, &it, get_count)))
- {
- clif_additem(sd, 0, 0, flag);
- if( pc_candrop(sd,&it) )
- map_addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&LOG_SCRIPT_TRANSACTIONS)
- log_pick_pc(sd, "N", nameid, amount, NULL);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(getitem2)
- {
- int nameid,amount,get_count,i,flag = 0;
- int iden,ref,attr,c1,c2,c3,c4;
- struct item_data *item_data;
- struct item item_tmp;
- TBL_PC *sd;
- struct script_data *data;
- if( script_hasdata(st,11) )
- sd=map_id2sd(script_getnum(st,11)); // <Account ID>
- else
- sd=script_rid2sd(st); // Attached player
- if( sd == NULL ) // no target
- return 0;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- nameid=item_data->nameid;
- else
- nameid=UNKNOWN_ITEM_ID;
- }else
- nameid=conv_num(st,data);
- amount=script_getnum(st,3);
- iden=script_getnum(st,4);
- ref=script_getnum(st,5);
- attr=script_getnum(st,6);
- c1=(short)script_getnum(st,7);
- c2=(short)script_getnum(st,8);
- c3=(short)script_getnum(st,9);
- c4=(short)script_getnum(st,10);
- if(nameid<0) { // ランダム
- nameid=itemdb_searchrandomid(-nameid);
- flag = 1;
- }
- if(nameid > 0) {
- memset(&item_tmp,0,sizeof(item_tmp));
- item_data=itemdb_exists(nameid);
- if (item_data == NULL)
- return -1;
- if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR){
- if(ref > 10) ref = 10;
- }
- else if(item_data->type==IT_PETEGG) {
- iden = 1;
- ref = 0;
- }
- else {
- iden = 1;
- ref = attr = 0;
- }
- item_tmp.nameid=nameid;
- if(!flag)
- item_tmp.identify=iden;
- else if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR)
- item_tmp.identify=0;
- item_tmp.refine=ref;
- item_tmp.attribute=attr;
- item_tmp.card[0]=(short)c1;
- item_tmp.card[1]=(short)c2;
- item_tmp.card[2]=(short)c3;
- item_tmp.card[3]=(short)c4;
- //Check if it's stackable.
- if (!itemdb_isstackable(nameid))
- get_count = 1;
- else
- get_count = amount;
- for (i = 0; i < amount; i += get_count)
- {
- // if not pet egg
- if (!pet_create_egg(sd, nameid))
- {
- if ((flag = pc_additem(sd, &item_tmp, get_count)))
- {
- clif_additem(sd, 0, 0, flag);
- if( pc_candrop(sd,&item_tmp) )
- map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", nameid, amount, &item_tmp);
- }
- return 0;
- }
- /*==========================================
- * rentitem <item id>
- * rentitem "<item name>"
- *------------------------------------------*/
- BUILDIN_FUNC(rentitem)
- {
- struct map_session_data *sd;
- struct script_data *data;
- struct item it;
- int seconds;
- int nameid = 0, flag;
- data = script_getdata(st,2);
- get_val(st,data);
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( data_isstring(data) )
- {
- const char *name = conv_str(st,data);
- struct item_data *itd = itemdb_searchname(name);
- if( itd == NULL )
- {
- ShowError("buildin_rentitem: Nonexistant item %s requested.\n", name);
- return 1;
- }
- nameid = itd->nameid;
- }
- else if( data_isint(data) )
- {
- nameid = conv_num(st,data);
- if( nameid <= 0 || !itemdb_exists(nameid) )
- {
- ShowError("buildin_rentitem: Nonexistant item %d requested.\n", nameid);
- return 1;
- }
- }
- else
- {
- ShowError("buildin_rentitem: invalid data type for argument #1 (%d).\n", data->type);
- return 1;
- }
- seconds = script_getnum(st,3);
- memset(&it, 0, sizeof(it));
- it.nameid = nameid;
- it.identify = 1;
- it.expire_time = (unsigned int)(time(NULL) + seconds);
- if( (flag = pc_additem(sd, &it, 1)) )
- {
- clif_additem(sd, 0, 0, flag);
- return 1;
- }
- clif_rental_time(sd->fd, nameid, seconds);
- pc_inventory_rental_add(sd, seconds);
- if( log_config.enable_logs&LOG_SCRIPT_TRANSACTIONS )
- log_pick_pc(sd, "N", nameid, 1, NULL);
-
- return 0;
- }
- /*==========================================
- * gets an item with someone's name inscribed [Skotlex]
- * getinscribeditem item_num, character_name
- * Returned Qty is always 1, only works on equip-able
- * equipment
- *------------------------------------------*/
- BUILDIN_FUNC(getnameditem)
- {
- int nameid;
- struct item item_tmp;
- TBL_PC *sd, *tsd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if (sd == NULL)
- { //Player not attached!
- script_pushint(st,0);
- return 0;
- }
-
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data == NULL)
- { //Failed
- script_pushint(st,0);
- return 0;
- }
- nameid = item_data->nameid;
- }else
- nameid = conv_num(st,data);
- if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/)
- { //Even though named stackable items "could" be risky, they are required for certain quests.
- script_pushint(st,0);
- return 0;
- }
- data=script_getdata(st,3);
- get_val(st,data);
- if( data_isstring(data) ) //Char Name
- tsd=map_nick2sd(conv_str(st,data));
- else //Char Id was given
- tsd=map_charid2sd(conv_num(st,data));
-
- if( tsd == NULL )
- { //Failed
- script_pushint(st,0);
- return 0;
- }
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid=nameid;
- item_tmp.amount=1;
- item_tmp.identify=1;
- item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
- item_tmp.card[2]=tsd->status.char_id;
- item_tmp.card[3]=tsd->status.char_id >> 16;
- if(pc_additem(sd,&item_tmp,1)) {
- script_pushint(st,0);
- return 0; //Failed to add item, we will not drop if they don't fit
- }
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", item_tmp.nameid, item_tmp.amount, &item_tmp);
- script_pushint(st,1);
- return 0;
- }
- /*==========================================
- * gets a random item ID from an item group [Skotlex]
- * groupranditem group_num
- *------------------------------------------*/
- BUILDIN_FUNC(grouprandomitem)
- {
- int group;
- group = script_getnum(st,2);
- script_pushint(st,itemdb_searchrandomid(group));
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(makeitem)
- {
- int nameid,amount,flag = 0;
- int x,y,m;
- const char *mapname;
- struct item item_tmp;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- nameid=item_data->nameid;
- else
- nameid=UNKNOWN_ITEM_ID;
- }else
- nameid=conv_num(st,data);
- amount=script_getnum(st,3);
- mapname =script_getstr(st,4);
- x =script_getnum(st,5);
- y =script_getnum(st,6);
- if(strcmp(mapname,"this")==0)
- {
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if (!sd) return 0; //Failed...
- m=sd->bl.m;
- } else
- m=map_mapname2mapid(mapname);
- if(nameid<0) { // ランダム
- nameid=itemdb_searchrandomid(-nameid);
- flag = 1;
- }
- if(nameid > 0) {
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid=nameid;
- if(!flag)
- item_tmp.identify=1;
- else
- item_tmp.identify=itemdb_isidentified(nameid);
- map_addflooritem(&item_tmp,amount,m,x,y,0,0,0,0);
- }
- return 0;
- }
- /// Deletes items from the target/attached player.
- /// Prioritizes ordinary items.
- ///
- /// delitem <item id>,<amount>{,<account id>}
- /// delitem "<item name>",<amount>{,<account id>}
- BUILDIN_FUNC(delitem)
- {
- int nameid=0,amount,i,important_item=0;
- TBL_PC *sd;
- struct script_data *data;
- if( script_hasdata(st,4) )
- {
- int account_id = script_getnum(st,4);
- sd = map_id2sd(account_id); // <account id>
- if( sd == NULL )
- {
- ShowError("script:delitem: player not found (AID=%d).\n", account_id);
- st->state = END;
- return 1;
- }
- }
- else
- {
- sd = script_rid2sd(st);// attached player
- if( sd == NULL )
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) )
- {
- const char* item_name = conv_str(st,data);
- struct item_data* id = itemdb_searchname(item_name);
- if( id == NULL )
- {
- ShowError("script:delitem: unknown item \"%s\".\n", item_name);
- st->state = END;
- return 1;
- }
- nameid = id->nameid;// "<item name>"
- }
- else
- nameid = conv_num(st,data);// <item id>
- amount=script_getnum(st,3);
- if( amount <= 0 )
- return 0;// nothing to do
- //1st pass
- //here we won't delete items with CARDS, named items but we count them
- for(i=0;i<MAX_INVENTORY;i++){
- //we don't delete wrong item or equipped item
- if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
- sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
- continue;
- //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
- if(sd->inventory_data[i]->type==IT_PETEGG &&
- sd->status.inventory[i].card[0] == CARD0_PET)
- {
- if (!intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
- continue; //pet couldn't be sent for deletion.
- } else
- //is this item important? does it have cards? or Player's name? or Refined/Upgraded
- if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
- sd->status.inventory[i].card[0] ||
- sd->status.inventory[i].refine) {
- //this is important item, count it (except for pet eggs)
- if(sd->status.inventory[i].card[0] != CARD0_PET)
- important_item++;
- continue;
- }
- if(sd->status.inventory[i].amount>=amount){
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
- pc_delitem(sd,i,amount,0,0);
- return 0; //we deleted exact amount of items. now exit
- } else {
- amount-=sd->status.inventory[i].amount;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40) {
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
- }
- //Logs
- pc_delitem(sd,i,sd->status.inventory[i].amount,0,0);
- }
- }
- //2nd pass
- //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
- if (important_item>0 && amount>0)
- for(i=0;i<MAX_INVENTORY;i++){
- //we don't delete wrong item
- if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
- sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
- continue;
- if(sd->status.inventory[i].amount>=amount){
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
- pc_delitem(sd,i,amount,0,0);
- return 0; //we deleted exact amount of items. now exit
- } else {
- amount-=sd->status.inventory[i].amount;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
- pc_delitem(sd,i,sd->status.inventory[i].amount,0,0);
- }
- }
- ShowError("script:delitem: failed to delete %d items (AID=%d item_id=%d).\n", amount, sd->status.account_id, nameid);
- st->state = END;
- clif_scriptclose(sd, st->oid);
- return 1;
- }
- /// Deletes items from the target/attached player.
- ///
- /// delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>}
- /// delitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>}
- BUILDIN_FUNC(delitem2)
- {
- int nameid=0,amount,i=0;
- int iden,ref,attr,c1,c2,c3,c4;
- TBL_PC *sd;
- struct script_data *data;
- if( script_hasdata(st,11) )
- {
- int account_id = script_getnum(st,11);
- sd = map_id2sd(account_id); // <account id>
- if( sd == NULL )
- {
- ShowError("script:delitem2: player not found (AID=%d).\n", account_id);
- st->state = END;
- return 1;
- }
- }
- else
- {
- sd = script_rid2sd(st);// attached player
- if( sd == NULL )
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) )
- {
- const char* item_name = conv_str(st,data);
- struct item_data* id = itemdb_searchname(item_name);
- if( id == NULL )
- {
- ShowError("script:delitem2: unknown item \"%s\".\n", item_name);
- st->state = END;
- return 1;
- }
- nameid = id->nameid;// "<item name>"
- }
- else
- nameid = conv_num(st,data);// <item id>
- amount=script_getnum(st,3);
- iden=script_getnum(st,4);
- ref=script_getnum(st,5);
- attr=script_getnum(st,6);
- c1=(short)script_getnum(st,7);
- c2=(short)script_getnum(st,8);
- c3=(short)script_getnum(st,9);
- c4=(short)script_getnum(st,10);
- if( amount <= 0 )
- return 0;// nothing to do
- for(i=0;i<MAX_INVENTORY;i++){
- //we don't delete wrong item or equipped item
- if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
- sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
- sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
- sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
- sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
- sd->status.inventory[i].card[3]!=c4)
- continue;
- //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
- if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
- {
- if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
- continue; //Failed to send delete the pet.
- }
- if(sd->status.inventory[i].amount>=amount){
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
- pc_delitem(sd,i,amount,0,0);
- return 0; //we deleted exact amount of items. now exit
- } else {
- amount-=sd->status.inventory[i].amount;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
- pc_delitem(sd,i,sd->status.inventory[i].amount,0,0);
- }
- }
- ShowError("script:delitem2: failed to delete %d items (AID=%d item_id=%d).\n", amount, sd->status.account_id, nameid);
- st->state = END;
- clif_scriptclose(sd, st->oid);
- return 1;
- }
- /*==========================================
- * Enables/Disables use of items while in an NPC [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(enableitemuse)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (sd)
- sd->npc_item_flag = st->oid;
- return 0;
- }
- BUILDIN_FUNC(disableitemuse)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (sd)
- sd->npc_item_flag = 0;
- return 0;
- }
- /*==========================================
- *キャラ関係のパラメータ取得
- *------------------------------------------*/
- BUILDIN_FUNC(readparam)
- {
- int type;
- TBL_PC *sd;
- type=script_getnum(st,2);
- if( script_hasdata(st,3) )
- sd=map_nick2sd(script_getstr(st,3));
- else
- sd=script_rid2sd(st);
- if(sd==NULL){
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,pc_readparam(sd,type));
- return 0;
- }
- /*==========================================
- *キャラ関係のID取得
- *------------------------------------------*/
- BUILDIN_FUNC(getcharid)
- {
- int num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- if( script_hasdata(st,3) )
- sd=map_nick2sd(script_getstr(st,3));
- else
- sd=script_rid2sd(st);
- if(sd==NULL){
- script_pushint(st,0); //return 0, according docs
- return 0;
- }
- switch( num ) {
- case 0: script_pushint(st,sd->status.char_id); break;
- case 1: script_pushint(st,sd->status.party_id); break;
- case 2: script_pushint(st,sd->status.guild_id); break;
- case 3: script_pushint(st,sd->status.account_id); break;
- case 4: script_pushint(st,sd->state.bg_id); break;
- default:
- ShowError("buildin_getcharid: invalid parameter (%d).\n", num);
- script_pushint(st,0);
- break;
- }
-
- return 0;
- }
- /*==========================================
- *指定IDのPT名取得
- *------------------------------------------*/
- char *buildin_getpartyname_sub(int party_id)
- {
- struct party_data *p;
- p=party_search(party_id);
- if(p!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, p->party.name, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
- }
- return 0;
- }
- BUILDIN_FUNC(getpartyname)
- {
- char *name;
- int party_id;
- party_id=script_getnum(st,2);
- name=buildin_getpartyname_sub(party_id);
- if(name != NULL)
- script_pushstr(st,name);
- else
- script_pushconststr(st,"null");
- return 0;
- }
- /*==========================================
- *指定IDのPT人数とメンバーID取得
- *------------------------------------------*/
- BUILDIN_FUNC(getpartymember)
- {
- struct party_data *p;
- int i,j=0,type=0;
- p=party_search(script_getnum(st,2));
- if( script_hasdata(st,3) )
- type=script_getnum(st,3);
-
- if(p!=NULL){
- for(i=0;i<MAX_PARTY;i++){
- if(p->party.member[i].account_id){
- switch (type) {
- case 2:
- mapreg_setreg(add_str("$@partymemberaid")+(j<<24),p->party.member[i].account_id);
- break;
- case 1:
- mapreg_setreg(add_str("$@partymembercid")+(j<<24),p->party.member[i].char_id);
- break;
- default:
- mapreg_setregstr(add_str("$@partymembername$")+(j<<24),p->party.member[i].name);
- }
- j++;
- }
- }
- }
- mapreg_setreg(add_str("$@partymembercount"),j);
- return 0;
- }
- /*==========================================
- * Retrieves party leader. if flag is specified,
- * return some of the leader data. Otherwise, return name.
- *------------------------------------------*/
- BUILDIN_FUNC(getpartyleader)
- {
- int party_id, type = 0, i=0;
- struct party_data *p;
- party_id=script_getnum(st,2);
- if( script_hasdata(st,3) )
- type=script_getnum(st,3);
- p=party_search(party_id);
- if (p) //Search leader
- for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
- if (!p || i == MAX_PARTY) { //leader not found
- if (type)
- script_pushint(st,-1);
- else
- script_pushconststr(st,"null");
- return 0;
- }
- switch (type) {
- case 1: script_pushint(st,p->party.member[i].account_id); break;
- case 2: script_pushint(st,p->party.member[i].char_id); break;
- case 3: script_pushint(st,p->party.member[i].class_); break;
- case 4: script_pushstrcopy(st,mapindex_id2name(p->party.member[i].map)); break;
- case 5: script_pushint(st,p->party.member[i].lv); break;
- default: script_pushstrcopy(st,p->party.member[i].name); break;
- }
- return 0;
- }
- /*==========================================
- *指定IDのギルド名取得
- *------------------------------------------*/
- char *buildin_getguildname_sub(int guild_id)
- {
- struct guild *g=NULL;
- g=guild_search(guild_id);
- if(g!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, g->name, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
- }
- return NULL;
- }
- BUILDIN_FUNC(getguildname)
- {
- char *name;
- int guild_id=script_getnum(st,2);
- name=buildin_getguildname_sub(guild_id);
- if(name != NULL)
- script_pushstr(st,name);
- else
- script_pushconststr(st,"null");
- return 0;
- }
- /*==========================================
- *指定IDのGuildMaster名取得
- *------------------------------------------*/
- char *buildin_getguildmaster_sub(int guild_id)
- {
- struct guild *g=NULL;
- g=guild_search(guild_id);
- if(g!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, g->master, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
- }
- return 0;
- }
- BUILDIN_FUNC(getguildmaster)
- {
- char *master;
- int guild_id=script_getnum(st,2);
- master=buildin_getguildmaster_sub(guild_id);
- if(master!=0)
- script_pushstr(st,master);
- else
- script_pushconststr(st,"null");
- return 0;
- }
- BUILDIN_FUNC(getguildmasterid)
- {
- char *master;
- TBL_PC *sd=NULL;
- int guild_id=script_getnum(st,2);
- master=buildin_getguildmaster_sub(guild_id);
- if(master!=0){
- if((sd=map_nick2sd(master)) == NULL){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.char_id);
- }else{
- script_pushint(st,0);
- }
- return 0;
- }
- /*==========================================
- * キャラクタの名前
- *------------------------------------------*/
- BUILDIN_FUNC(strcharinfo)
- {
- TBL_PC *sd;
- int num;
- char *buf;
- sd=script_rid2sd(st);
- if (!sd) { //Avoid crashing....
- script_pushconststr(st,"");
- return 0;
- }
- num=script_getnum(st,2);
- switch(num){
- case 0:
- script_pushstrcopy(st,sd->status.name);
- break;
- case 1:
- buf=buildin_getpartyname_sub(sd->status.party_id);
- if(buf!=0)
- script_pushstr(st,buf);
- else
- script_pushconststr(st,"");
- break;
- case 2:
- buf=buildin_getguildname_sub(sd->status.guild_id);
- if(buf != NULL)
- script_pushstr(st,buf);
- else
- script_pushconststr(st,"");
- break;
- case 3:
- script_pushconststr(st,map[sd->bl.m].name);
- break;
- default:
- ShowWarning("buildin_strcharinfo: unknown parameter.\n");
- script_pushconststr(st,"");
- break;
- }
- return 0;
- }
- /*==========================================
- * 呼び出し元のNPC情報を取得する
- *------------------------------------------*/
- BUILDIN_FUNC(strnpcinfo)
- {
- TBL_NPC* nd;
- int num;
- char *buf,*name=NULL;
- nd = map_id2nd(st->oid);
- if (!nd) {
- script_pushconststr(st, "");
- return 0;
- }
- num = script_getnum(st,2);
- switch(num){
- case 0: // display name
- name = aStrdup(nd->name);
- break;
- case 1: // visible part of display name
- if((buf = strchr(nd->name,'#')) != NULL)
- {
- name = aStrdup(nd->name);
- name[buf - nd->name] = 0;
- } else // Return the name, there is no '#' present
- name = aStrdup(nd->name);
- break;
- case 2: // # fragment
- if((buf = strchr(nd->name,'#')) != NULL)
- name = aStrdup(buf+1);
- break;
- case 3: // unique name
- name = aStrdup(nd->exname);
- break;
- }
- if(name)
- script_pushstr(st, name);
- else
- script_pushconststr(st, "");
- return 0;
- }
- // aegis->athena slot position conversion table
- static unsigned int equip[] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW};
- /*==========================================
- * GetEquipID(Pos); Pos: 1-10
- *------------------------------------------*/
- BUILDIN_FUNC(getequipid)
- {
- int i, num;
- TBL_PC* sd;
- struct item_data* item;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
- {
- script_pushint(st,-1);
- return 0;
- }
- // get inventory position of item
- i = pc_checkequip(sd,equip[num]);
- if( i < 0 )
- {
- script_pushint(st,-1);
- return 0;
- }
-
- item = sd->inventory_data[i];
- if( item != 0 )
- script_pushint(st,item->nameid);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備名文字列(精錬メニュー用)
- *------------------------------------------*/
- BUILDIN_FUNC(getequipname)
- {
- int i, num;
- TBL_PC* sd;
- struct item_data* item;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
- {
- script_pushconststr(st,"");
- return 0;
- }
- // get inventory position of item
- i = pc_checkequip(sd,equip[num]);
- if( i < 0 )
- {
- script_pushint(st,-1);
- return 0;
- }
- item = sd->inventory_data[i];
- if( item != 0 )
- script_pushstrcopy(st,item->jname);
- else
- script_pushconststr(st,"");
- return 0;
- }
- /*==========================================
- * getbrokenid [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(getbrokenid)
- {
- int i,num,id=0,brokencounter=0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num=script_getnum(st,2);
- for(i=0; i<MAX_INVENTORY; i++) {
- if(sd->status.inventory[i].attribute){
- brokencounter++;
- if(num==brokencounter){
- id=sd->status.inventory[i].nameid;
- break;
- }
- }
- }
- script_pushint(st,id);
- return 0;
- }
- /*==========================================
- * repair [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(repair)
- {
- int i,num;
- int repaircounter=0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num=script_getnum(st,2);
- for(i=0; i<MAX_INVENTORY; i++) {
- if(sd->status.inventory[i].attribute){
- repaircounter++;
- if(num==repaircounter){
- sd->status.inventory[i].attribute=0;
- clif_equiplist(sd);
- clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
- clif_misceffect(&sd->bl, 3);
- break;
- }
- }
- }
- return 0;
- }
- /*==========================================
- * 装備チェック
- *------------------------------------------*/
- BUILDIN_FUNC(getequipisequiped)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0)
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備品精錬可能チェック
- *------------------------------------------*/
- BUILDIN_FUNC(getequipisenableref)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( num > 0 && num <= ARRAYLENGTH(equip) )
- i = pc_checkequip(sd,equip[num-1]);
- if( i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine && !sd->status.inventory[i].expire_time )
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備品鑑定チェック
- *------------------------------------------*/
- BUILDIN_FUNC(getequipisidentify)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0)
- script_pushint(st,sd->status.inventory[i].identify);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備品精錬度
- *------------------------------------------*/
- BUILDIN_FUNC(getequiprefinerycnt)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0)
- script_pushint(st,sd->status.inventory[i].refine);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備品武器LV
- *------------------------------------------*/
- BUILDIN_FUNC(getequipweaponlv)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && sd->inventory_data[i])
- script_pushint(st,sd->inventory_data[i]->wlv);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 装備品精錬成功率
- *------------------------------------------*/
- BUILDIN_FUNC(getequippercentrefinery)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
- script_pushint(st,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * 精錬成功
- *------------------------------------------*/
- BUILDIN_FUNC(successrefitem)
- {
- int i=-1,num,ep;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- ep=sd->status.inventory[i].equip;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
- sd->status.inventory[i].refine++;
- pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below
- clif_refine(sd->fd,0,i,sd->status.inventory[i].refine);
- clif_delitem(sd,i,1,3);
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
- clif_additem(sd,i,1,0);
- pc_equipitem(sd,i,ep);
- clif_misceffect(&sd->bl,3);
- if(sd->status.inventory[i].refine == MAX_REFINE &&
- sd->status.inventory[i].card[0] == CARD0_FORGE &&
- sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
- ){ // Fame point system [DracoRPG]
- switch (sd->inventory_data[i]->wlv){
- case 1:
- pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
- break;
- case 2:
- pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
- break;
- case 3:
- pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
- break;
- }
- }
- }
- return 0;
- }
- /*==========================================
- * 精錬失敗
- *------------------------------------------*/
- BUILDIN_FUNC(failedrefitem)
- {
- int i=-1,num;
- TBL_PC *sd;
- num=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
- sd->status.inventory[i].refine = 0;
- pc_unequipitem(sd,i,3);
- // 精錬失敗エフェクトのパケット
- clif_refine(sd->fd,1,i,sd->status.inventory[i].refine);
- pc_delitem(sd,i,1,0,2);
- // 他の人にも失敗を通知
- clif_misceffect(&sd->bl,2);
- }
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(statusup)
- {
- int type;
- TBL_PC *sd;
- type=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_statusup(sd,type);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(statusup2)
- {
- int type,val;
- TBL_PC *sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_statusup2(sd,type,val);
- return 0;
- }
- /// See 'doc/item_bonus.txt'
- ///
- /// bonus <bonus type>,<val1>;
- /// bonus2 <bonus type>,<val1>,<val2>;
- /// bonus3 <bonus type>,<val1>,<val2>,<val3>;
- /// bonus4 <bonus type>,<val1>,<val2>,<val3>,<val4>;
- /// bonus5 <bonus type>,<val1>,<val2>,<val3>,<val4>,<val5>;
- BUILDIN_FUNC(bonus)
- {
- int type;
- int val1;
- int val2 = 0;
- int val3 = 0;
- int val4 = 0;
- int val5 = 0;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- type = script_getnum(st,2);
- switch( type )
- {
- case SP_AUTOSPELL:
- case SP_AUTOSPELL_WHENHIT:
- case SP_AUTOSPELL_ONSKILL:
- case SP_SKILL_ATK:
- case SP_SKILL_HEAL:
- case SP_SKILL_HEAL2:
- case SP_ADD_SKILL_BLOW:
- case SP_CASTRATE:
- case SP_ADDEFF_ONSKILL:
- // these bonuses support skill names
- val1 = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- break;
- default:
- val1 = script_getnum(st,3);
- break;
- }
- switch( script_lastdata(st)-2 )
- {
- case 1:
- pc_bonus(sd, type, val1);
- break;
- case 2:
- val2 = script_getnum(st,4);
- pc_bonus2(sd, type, val1, val2);
- break;
- case 3:
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- pc_bonus3(sd, type, val1, val2, val3);
- break;
- case 4:
- if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) )
- val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name
- else
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- val4 = script_getnum(st,6);
- pc_bonus4(sd, type, val1, val2, val3, val4);
- break;
- case 5:
- if( type == SP_AUTOSPELL_ONSKILL && script_isstring(st,4) )
- val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name
- else
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- val4 = script_getnum(st,6);
- val5 = script_getnum(st,7);
- pc_bonus5(sd, type, val1, val2, val3, val4, val5);
- break;
- default:
- ShowDebug("buildin_bonus: unexpected number of arguments (%d)\n", (script_lastdata(st) - 1));
- break;
- }
- return 0;
- }
- BUILDIN_FUNC(autobonus)
- {
- unsigned int dur;
- short rate;
- short atk_type = 0;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !bonus_script )
- return 0;
- if( script_hasdata(st,5) )
- atk_type = script_getnum(st,5);
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return 0;
- }
- BUILDIN_FUNC(autobonus2)
- {
- unsigned int dur;
- short rate;
- short atk_type = 0;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !bonus_script )
- return 0;
- if( script_hasdata(st,5) )
- atk_type = script_getnum(st,5);
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return 0;
- }
- BUILDIN_FUNC(autobonus3)
- {
- unsigned int dur;
- short rate,atk_type;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- atk_type = ( script_isstring(st,5) ? skill_name2id(script_getstr(st,5)) : script_getnum(st,5) );
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !atk_type || !bonus_script )
- return 0;
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,true) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return 0;
- }
- /// Changes the level of a player skill.
- /// <flag> defaults to 1
- /// <flag>=0 : set the level of the skill
- /// <flag>=1 : set the temporary level of the skill
- /// <flag>=2 : add to the level of the skill
- ///
- /// skill <skill id>,<level>,<flag>
- /// skill <skill id>,<level>
- /// skill "<skill name>",<level>,<flag>
- /// skill "<skill name>",<level>
- BUILDIN_FUNC(skill)
- {
- int id;
- int level;
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- if( script_hasdata(st,4) )
- flag = script_getnum(st,4);
- pc_skill(sd, id, level, flag);
- return 0;
- }
- /// Changes the level of a player skill.
- /// like skill, but <flag> defaults to 2
- ///
- /// addtoskill <skill id>,<amount>,<flag>
- /// addtoskill <skill id>,<amount>
- /// addtoskill "<skill name>",<amount>,<flag>
- /// addtoskill "<skill name>",<amount>
- ///
- /// @see skill
- BUILDIN_FUNC(addtoskill)
- {
- int id;
- int level;
- int flag = 2;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- if( script_hasdata(st,4) )
- flag = script_getnum(st,4);
- pc_skill(sd, id, level, flag);
- return 0;
- }
- /// Increases the level of a guild skill.
- ///
- /// guildskill <skill id>,<amount>;
- /// guildskill "<skill name>",<amount>;
- BUILDIN_FUNC(guildskill)
- {
- int id;
- int level;
- TBL_PC* sd;
- int i;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- for( i=0; i < level; i++ )
- guild_skillup(sd, id);
- return 0;
- }
- /// Returns the level of the player skill.
- ///
- /// getskilllv(<skill id>) -> <level>
- /// getskilllv("<skill name>") -> <level>
- BUILDIN_FUNC(getskilllv)
- {
- int id;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- script_pushint(st, pc_checkskill(sd,id));
- return 0;
- }
- /// Returns the level of the guild skill.
- ///
- /// getgdskilllv(<guild id>,<skill id>) -> <level>
- /// getgdskilllv(<guild id>,"<skill name>") -> <level>
- BUILDIN_FUNC(getgdskilllv)
- {
- int guild_id;
- int skill_id;
- struct guild* g;
- guild_id = script_getnum(st,2);
- skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- g = guild_search(guild_id);
- if( g == NULL )
- script_pushint(st, -1);
- else
- script_pushint(st, guild_checkskill(g,skill_id));
- return 0;
- }
- /// Returns the 'basic_skill_check' setting.
- /// This config determines if the server checks the skill level of NV_BASIC
- /// before allowing the basic actions.
- ///
- /// basicskillcheck() -> <bool>
- BUILDIN_FUNC(basicskillcheck)
- {
- script_pushint(st, battle_config.basic_skill_check);
- return 0;
- }
- /// Returns the GM level of the player.
- ///
- /// getgmlevel() -> <level>
- BUILDIN_FUNC(getgmlevel)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- script_pushint(st, pc_isGM(sd));
- return 0;
- }
- /// Terminates the execution of this script instance.
- ///
- /// end
- BUILDIN_FUNC(end)
- {
- st->state = END;
- return 0;
- }
- /// Checks if the player has that effect state (option).
- ///
- /// checkoption(<option>) -> <bool>
- BUILDIN_FUNC(checkoption)
- {
- int option;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- option = script_getnum(st,2);
- if( sd->sc.option&option )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Checks if the player is in that body state (opt1).
- ///
- /// checkoption1(<opt1>) -> <bool>
- BUILDIN_FUNC(checkoption1)
- {
- int opt1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- opt1 = script_getnum(st,2);
- if( sd->sc.opt1 == opt1 )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Checks if the player has that health state (opt2).
- ///
- /// checkoption2(<opt2>) -> <bool>
- BUILDIN_FUNC(checkoption2)
- {
- int opt2;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- opt2 = script_getnum(st,2);
- if( sd->sc.opt2&opt2 )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Changes the effect state (option) of the player.
- /// <flag> defaults to 1
- /// <flag>=0 : removes the option
- /// <flag>=other : adds the option
- ///
- /// setoption <option>,<flag>;
- /// setoption <option>;
- BUILDIN_FUNC(setoption)
- {
- int option;
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- option = script_getnum(st,2);
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- else if( !option ){// Request to remove everything.
- flag = 0;
- option = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
- }
- if( flag ){// Add option
- if( option&OPTION_WEDDING && !battle_config.wedding_modifydisplay )
- option &= ~OPTION_WEDDING;// Do not show the wedding sprites
- pc_setoption(sd, sd->sc.option|option);
- } else// Remove option
- pc_setoption(sd, sd->sc.option&~option);
- return 0;
- }
- /// Returns if the player has a cart.
- ///
- /// checkcart() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkcart)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_iscarton(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Sets the cart of the player.
- /// <type> defaults to 1
- /// <type>=0 : removes the cart
- /// <type>=1 : Normal cart
- /// <type>=2 : Wooden cart
- /// <type>=3 : Covered cart with flowers and ferns
- /// <type>=4 : Wooden cart with a Panda doll on the back
- /// <type>=5 : Normal cart with bigger wheels, a roof and a banner on the back
- ///
- /// setcart <type>;
- /// setcart;
- BUILDIN_FUNC(setcart)
- {
- int type = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- type = script_getnum(st,2);
- pc_setcart(sd, type);
- return 0;
- }
- /// Returns if the player has a falcon.
- ///
- /// checkfalcon() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkfalcon)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_isfalcon(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Sets if the player has a falcon or not.
- /// <flag> defaults to 1
- ///
- /// setfalcon <flag>;
- /// setfalcon;
- BUILDIN_FUNC(setfalcon)
- {
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- flag = script_getnum(st,2);
- pc_setfalcon(sd, flag);
- return 0;
- }
- /// Returns if the player is riding.
- ///
- /// checkriding() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkriding)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_isriding(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Sets if the player is riding.
- /// <flag> defaults to 1
- ///
- /// setriding <flag>;
- /// setriding;
- BUILDIN_FUNC(setriding)
- {
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- flag = script_getnum(st,2);
- pc_setriding(sd, flag);
- return 0;
- }
- /// Sets the save point of the player.
- ///
- /// save "<map name>",<x>,<y>
- /// savepoint "<map name>",<x>,<y>
- BUILDIN_FUNC(savepoint)
- {
- int x;
- int y;
- short map;
- const char* str;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- str = script_getstr(st, 2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- map = mapindex_name2id(str);
- if( map )
- pc_setsavepoint(sd, map, x, y);
- return 0;
- }
- /*==========================================
- * GetTimeTick(0: System Tick, 1: Time Second Tick)
- *------------------------------------------*/
- BUILDIN_FUNC(gettimetick) /* Asgard Version */
- {
- int type;
- time_t timer;
- struct tm *t;
- type=script_getnum(st,2);
- switch(type){
- case 2:
- //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
- // from the system clock.)
- script_pushint(st,(int)time(NULL));
- break;
- case 1:
- //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
- time(&timer);
- t=localtime(&timer);
- script_pushint(st,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
- break;
- case 0:
- default:
- //type 0:(System Ticks)
- script_pushint(st,gettick());
- break;
- }
- return 0;
- }
- /*==========================================
- * GetTime(Type);
- * 1: Sec 2: Min 3: Hour
- * 4: WeekDay 5: MonthDay 6: Month
- * 7: Year
- *------------------------------------------*/
- BUILDIN_FUNC(gettime) /* Asgard Version */
- {
- int type;
- time_t timer;
- struct tm *t;
- type=script_getnum(st,2);
- time(&timer);
- t=localtime(&timer);
- switch(type){
- case 1://Sec(0~59)
- script_pushint(st,t->tm_sec);
- break;
- case 2://Min(0~59)
- script_pushint(st,t->tm_min);
- break;
- case 3://Hour(0~23)
- script_pushint(st,t->tm_hour);
- break;
- case 4://WeekDay(0~6)
- script_pushint(st,t->tm_wday);
- break;
- case 5://MonthDay(01~31)
- script_pushint(st,t->tm_mday);
- break;
- case 6://Month(01~12)
- script_pushint(st,t->tm_mon+1);
- break;
- case 7://Year(20xx)
- script_pushint(st,t->tm_year+1900);
- break;
- case 8://Year Day(01~366)
- script_pushint(st,t->tm_yday+1);
- break;
- default://(format error)
- script_pushint(st,-1);
- break;
- }
- return 0;
- }
- /*==========================================
- * GetTimeStr("TimeFMT", Length);
- *------------------------------------------*/
- BUILDIN_FUNC(gettimestr)
- {
- char *tmpstr;
- const char *fmtstr;
- int maxlen;
- time_t now = time(NULL);
- fmtstr=script_getstr(st,2);
- maxlen=script_getnum(st,3);
- tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
- strftime(tmpstr,maxlen,fmtstr,localtime(&now));
- tmpstr[maxlen]='\0';
- script_pushstr(st,tmpstr);
- return 0;
- }
- /*==========================================
- * カプラ倉庫を開く
- *------------------------------------------*/
- BUILDIN_FUNC(openstorage)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- storage_storageopen(sd);
- return 0;
- }
- BUILDIN_FUNC(guildopenstorage)
- {
- TBL_PC* sd;
- int ret;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- ret = storage_guild_storageopen(sd);
- script_pushint(st,ret);
- return 0;
- }
- /*==========================================
- * アイテムによるスキル発動
- *------------------------------------------*/
- /// itemskill <skill id>,<level>
- /// itemskill "<skill name>",<level>
- BUILDIN_FUNC(itemskill)
- {
- int id;
- int lv;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL || sd->ud.skilltimer != INVALID_TIMER )
- return 0;
- id = ( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- lv = script_getnum(st,3);
- sd->skillitem=id;
- sd->skillitemlv=lv;
- clif_item_skill(sd,id,lv);
- return 0;
- }
- /*==========================================
- * アイテム作成
- *------------------------------------------*/
- BUILDIN_FUNC(produce)
- {
- int trigger;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- trigger=script_getnum(st,2);
- clif_skill_produce_mix_list(sd, trigger);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(cooking)
- {
- int trigger;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- trigger=script_getnum(st,2);
- clif_cooking_list(sd, trigger);
- return 0;
- }
- /*==========================================
- * NPCでペット作る
- *------------------------------------------*/
- BUILDIN_FUNC(makepet)
- {
- TBL_PC* sd;
- int id,pet_id;
- id=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pet_id = search_petDB_index(id, PET_CLASS);
- if (pet_id < 0)
- pet_id = search_petDB_index(id, PET_EGG);
- if (pet_id >= 0 && sd) {
- sd->catch_target_class = pet_db[pet_id].class_;
- intif_create_pet(
- sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
- }
- return 0;
- }
- /*==========================================
- * NPCで経験値上げる
- *------------------------------------------*/
- BUILDIN_FUNC(getexp)
- {
- TBL_PC* sd;
- int base=0,job=0;
- double bonus;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- base=script_getnum(st,2);
- job =script_getnum(st,3);
- if(base<0 || job<0)
- return 0;
- // bonus for npc-given exp
- bonus = battle_config.quest_exp_rate / 100.;
- base = (int) cap_value(base * bonus, 0, INT_MAX);
- job = (int) cap_value(job * bonus, 0, INT_MAX);
- pc_gainexp(sd, NULL, base, job, true);
- return 0;
- }
- /*==========================================
- * Gain guild exp [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(guildgetexp)
- {
- TBL_PC* sd;
- int exp;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- exp = script_getnum(st,2);
- if(exp < 0)
- return 0;
- if(sd && sd->status.guild_id > 0)
- guild_getexp (sd, exp);
- return 0;
- }
- /*==========================================
- * Changes the guild master of a guild [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(guildchangegm)
- {
- TBL_PC *sd;
- int guild_id;
- const char *name;
- guild_id = script_getnum(st,2);
- name = script_getstr(st,3);
- sd=map_nick2sd(name);
- if (!sd)
- script_pushint(st,0);
- else
- script_pushint(st,guild_gm_change(guild_id, sd));
- return 0;
- }
- /*==========================================
- * モンスター発生
- *------------------------------------------*/
- BUILDIN_FUNC(monster)
- {
- const char* mapn = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- const char* str = script_getstr(st,5);
- int class_ = script_getnum(st,6);
- int amount = script_getnum(st,7);
- const char* event = "";
- struct map_session_data* sd;
- int m;
- if( script_hasdata(st,8) )
- {
- event = script_getstr(st,8);
- check_event(st, event);
- }
- if (class_ >= 0 && !mobdb_checkid(class_)) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
- return 1;
- }
- sd = map_id2sd(st->rid);
- if( sd && strcmp(mapn,"this") == 0 )
- m = sd->bl.m;
- else
- {
- m = map_mapname2mapid(mapn);
- if( map[m].flag.src4instance && st->instance_id )
- { // Try to redirect to the instance map, not the src map
- if( (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- {
- ShowError("buildin_monster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn);
- return 1;
- }
- }
- }
- mob_once_spawn(sd,m,x,y,str,class_,amount,event);
- return 0;
- }
- /*==========================================
- * Request List of Monster Drops
- *------------------------------------------*/
- BUILDIN_FUNC(getmobdrops)
- {
- int class_ = script_getnum(st,2);
- int i, j = 0;
- struct mob_db *mob;
- if( !mobdb_checkid(class_) )
- {
- script_pushint(st, 0);
- return 0;
- }
- mob = mob_db(class_);
- for( i = 0; i < MAX_MOB_DROP; i++ )
- {
- if( mob->dropitem[i].nameid < 1 )
- continue;
- if( itemdb_exists(mob->dropitem[i].nameid) == NULL )
- continue;
- mapreg_setreg(add_str("$@MobDrop_item") + (j<<24), mob->dropitem[i].nameid);
- mapreg_setreg(add_str("$@MobDrop_rate") + (j<<24), mob->dropitem[i].p);
- j++;
- }
- mapreg_setreg(add_str("$@MobDrop_count"), j);
- script_pushint(st, 1);
- return 0;
- }
- /*==========================================
- * モンスター発生
- *------------------------------------------*/
- BUILDIN_FUNC(areamonster)
- {
- const char* mapn = script_getstr(st,2);
- int x0 = script_getnum(st,3);
- int y0 = script_getnum(st,4);
- int x1 = script_getnum(st,5);
- int y1 = script_getnum(st,6);
- const char* str = script_getstr(st,7);
- int class_ = script_getnum(st,8);
- int amount = script_getnum(st,9);
- const char* event = "";
- struct map_session_data* sd;
- int m;
- if( script_hasdata(st,10) )
- {
- event = script_getstr(st,10);
- check_event(st, event);
- }
- sd = map_id2sd(st->rid);
- if( sd && strcmp(mapn,"this") == 0 )
- m = sd->bl.m;
- else
- {
- m = map_mapname2mapid(mapn);
- if( map[m].flag.src4instance && st->instance_id )
- { // Try to redirect to the instance map, not the src map
- if( (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- {
- ShowError("buildin_areamonster: Trying to spawn monster (%d) on instance map (%s) without instance attached.\n", class_, mapn);
- return 1;
- }
- }
- }
-
- mob_once_spawn_area(sd,m,x0,y0,x1,y1,str,class_,amount,event);
- return 0;
- }
- /*==========================================
- * モンスター削除
- *------------------------------------------*/
- static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
- { //same fix but with killmonster instead - stripping events from mobs.
- TBL_MOB* md = (TBL_MOB*)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
- md->state.npc_killmonster = 1;
-
- if(!allflag){
- if(strcmp(event,md->npc_event)==0)
- status_kill(bl);
- }else{
- if(!md->spawn)
- status_kill(bl);
- }
- md->state.npc_killmonster = 0;
- return 0;
- }
- static int buildin_killmonster_sub(struct block_list *bl,va_list ap)
- {
- TBL_MOB* md = (TBL_MOB*)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
- if(!allflag){
- if(strcmp(event,md->npc_event)==0)
- status_kill(bl);
- }else{
- if(!md->spawn)
- status_kill(bl);
- }
- return 0;
- }
- BUILDIN_FUNC(killmonster)
- {
- const char *mapname,*event;
- int m,allflag=0;
- mapname=script_getstr(st,2);
- event=script_getstr(st,3);
- if(strcmp(event,"All")==0)
- allflag = 1;
- else
- check_event(st, event);
- if( (m=map_mapname2mapid(mapname))<0 )
- return 0;
-
- if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- return 0;
- if( script_hasdata(st,4) ) {
- if ( script_getnum(st,4) == 1 ) {
- map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
- return 0;
- }
- }
-
- map_freeblock_lock();
- map_foreachinmap(buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag);
- map_freeblock_unlock();
- return 0;
- }
- static int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap)
- { //Strips the event from the mob if it's killed the old method.
- struct mob_data *md;
-
- md = BL_CAST(BL_MOB, bl);
- if (md->npc_event[0])
- md->npc_event[0] = 0;
-
- status_kill(bl);
- return 0;
- }
- static int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
- {
- status_kill(bl);
- return 0;
- }
- BUILDIN_FUNC(killmonsterall)
- {
- const char *mapname;
- int m;
- mapname=script_getstr(st,2);
-
- if( (m = map_mapname2mapid(mapname))<0 )
- return 0;
- if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- return 0;
- if( script_hasdata(st,3) ) {
- if ( script_getnum(st,3) == 1 ) {
- map_foreachinmap(buildin_killmonsterall_sub,m,BL_MOB);
- return 0;
- }
- }
-
- map_foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB);
- return 0;
- }
- /*==========================================
- * Creates a clone of a player.
- * clone map, x, y, event, char_id, master_id, mode, flag, duration
- *------------------------------------------*/
- BUILDIN_FUNC(clone)
- {
- TBL_PC *sd, *msd=NULL;
- int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
- unsigned int duration = 0;
- const char *map,*event="";
- map=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- event=script_getstr(st,5);
- char_id=script_getnum(st,6);
- if( script_hasdata(st,7) )
- master_id=script_getnum(st,7);
- if( script_hasdata(st,8) )
- mode=script_getnum(st,8);
- if( script_hasdata(st,9) )
- flag=script_getnum(st,9);
-
- if( script_hasdata(st,10) )
- duration=script_getnum(st,10);
- check_event(st, event);
- m = map_mapname2mapid(map);
- if (m < 0) return 0;
- sd = map_charid2sd(char_id);
- if (master_id) {
- msd = map_charid2sd(master_id);
- if (msd)
- master_id = msd->bl.id;
- else
- master_id = 0;
- }
- if (sd) //Return ID of newly crafted clone.
- script_pushint(st,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
- else //Failed to create clone.
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * イベント実行
- *------------------------------------------*/
- BUILDIN_FUNC(doevent)
- {
- const char* event = script_getstr(st,2);
- check_event(st, event);
- npc_event(map_id2sd(st->rid),event,0);
- return 0;
- }
- /*==========================================
- * NPC主体イベント実行
- *------------------------------------------*/
- BUILDIN_FUNC(donpcevent)
- {
- const char* event = script_getstr(st,2);
- check_event(st, event);
- npc_event_do(event);
- return 0;
- }
- /// for Aegis compatibility
- /// basically a specialized 'donpcevent', with the event specified as two arguments instead of one
- BUILDIN_FUNC(cmdothernpc) // Added by RoVeRT
- {
- const char* npc = script_getstr(st,2);
- const char* command = script_getstr(st,3);
- char event[51];
- snprintf(event, 51, "%s::OnCommand%s", npc, command);
- check_event(st, event);
- npc_event_do(event);
- return 0;
- }
- /*==========================================
- * イベントタイマー追加
- *------------------------------------------*/
- BUILDIN_FUNC(addtimer)
- {
- int tick = script_getnum(st,2);
- const char* event = script_getstr(st, 3);
- TBL_PC* sd;
- check_event(st, event);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_addeventtimer(sd,tick,event);
- return 0;
- }
- /*==========================================
- * イベントタイマー削除
- *------------------------------------------*/
- BUILDIN_FUNC(deltimer)
- {
- const char *event;
- TBL_PC* sd;
- event=script_getstr(st, 2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- check_event(st, event);
- pc_deleventtimer(sd,event);
- return 0;
- }
- /*==========================================
- * イベントタイマーのカウント値追加
- *------------------------------------------*/
- BUILDIN_FUNC(addtimercount)
- {
- const char *event;
- int tick;
- TBL_PC* sd;
- event=script_getstr(st, 2);
- tick=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- check_event(st, event);
- pc_addeventtimercount(sd,event,tick);
- return 0;
- }
- /*==========================================
- * NPCタイマー初期化
- *------------------------------------------*/
- BUILDIN_FUNC(initnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Attach
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- nd->u.scr.rid = sd->bl.id;
- }
- npc_settimerevent_tick(nd,0);
- npc_timerevent_start(nd, st->rid);
- return 0;
- }
- /*==========================================
- * NPCタイマー開始
- *------------------------------------------*/
- BUILDIN_FUNC(startnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd=(struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Attach
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- nd->u.scr.rid = sd->bl.id;
- }
- npc_timerevent_start(nd, st->rid);
- return 0;
- }
- /*==========================================
- * NPCタイマー停止
- *------------------------------------------*/
- BUILDIN_FUNC(stopnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd=(struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Detach
- nd->u.scr.rid = 0;
- npc_timerevent_stop(nd);
- return 0;
- }
- /*==========================================
- * NPCタイマー情報所得
- *------------------------------------------*/
- BUILDIN_FUNC(getnpctimer)
- {
- struct npc_data *nd;
- TBL_PC *sd;
- int type = script_getnum(st,2);
- int val = 0;
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
-
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,0);
- ShowError("getnpctimer: Invalid NPC.\n");
- return 1;
- }
- switch( type )
- {
- case 0: val = npc_gettimerevent_tick(nd); break;
- case 1:
- if( nd->u.scr.rid )
- {
- sd = map_id2sd(nd->u.scr.rid);
- if( !sd )
- {
- ShowError("buildin_getnpctimer: Attached player not found!\n");
- break;
- }
- val = (sd->npc_timer_id != -1);
- }
- else
- val = (nd->u.scr.timerid !=-1);
- break;
- case 2: val = nd->u.scr.timeramount; break;
- }
- script_pushint(st,val);
- return 0;
- }
- /*==========================================
- * NPCタイマー値設定
- *------------------------------------------*/
- BUILDIN_FUNC(setnpctimer)
- {
- int tick;
- struct npc_data *nd;
- tick = script_getnum(st,2);
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("setnpctimer: Invalid NPC.\n");
- return 1;
- }
- npc_settimerevent_tick(nd,tick);
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * attaches the player rid to the timer [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(attachnpctimer)
- {
- TBL_PC *sd;
- struct npc_data *nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("setnpctimer: Invalid NPC.\n");
- return 1;
- }
- if( script_hasdata(st,2) )
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if( !sd )
- {
- script_pushint(st,1);
- ShowWarning("attachnpctimer: Invalid player.\n");
- return 1;
- }
- nd->u.scr.rid = sd->bl.id;
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * detaches a player rid from the timer [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(detachnpctimer)
- {
- struct npc_data *nd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("detachnpctimer: Invalid NPC.\n");
- return 1;
- }
- nd->u.scr.rid = 0;
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * To avoid "player not attached" script errors, this function is provided,
- * it checks if there is a player attached to the current script. [Skotlex]
- * If no, returns 0, if yes, returns the account_id of the attached player.
- *------------------------------------------*/
- BUILDIN_FUNC(playerattached)
- {
- if(st->rid == 0 || map_id2sd(st->rid) == NULL)
- script_pushint(st,0);
- else
- script_pushint(st,st->rid);
- return 0;
- }
- /*==========================================
- * 天の声アナウンス
- *------------------------------------------*/
- BUILDIN_FUNC(announce)
- {
- const char *mes = script_getstr(st,2);
- int flag = script_getnum(st,3);
- const char *fontColor = script_hasdata(st,4) ? script_getstr(st,4) : NULL;
- int fontType = script_hasdata(st,5) ? script_getnum(st,5) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,6) ? script_getnum(st,6) : 12; // default fontSize
- int fontAlign = script_hasdata(st,7) ? script_getnum(st,7) : 0; // default fontAlign
- int fontY = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontY
-
- if (flag&0x0f) // Broadcast source or broadcast region defined
- {
- send_target target;
- struct block_list *bl = (flag&0x08) ? map_id2bl(st->oid) : (struct block_list *)script_rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source
- if (bl == NULL)
- return 0;
-
- flag &= 0x07;
- target = (flag == 1) ? ALL_SAMEMAP :
- (flag == 2) ? AREA :
- (flag == 3) ? SELF :
- ALL_CLIENT;
- if (fontColor)
- clif_broadcast2(bl, mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target);
- else
- clif_broadcast(bl, mes, (int)strlen(mes)+1, flag&0xf0, target);
- }
- else
- {
- if (fontColor)
- intif_broadcast2(mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY);
- else
- intif_broadcast(mes, (int)strlen(mes)+1, flag&0xf0);
- }
- return 0;
- }
- /*==========================================
- * 天の声アナウンス(特定マップ)
- *------------------------------------------*/
- static int buildin_announce_sub(struct block_list *bl, va_list ap)
- {
- char *mes = va_arg(ap, char *);
- int len = va_arg(ap, int);
- int type = va_arg(ap, int);
- char *fontColor = va_arg(ap, char *);
- short fontType = (short)va_arg(ap, int);
- short fontSize = (short)va_arg(ap, int);
- short fontAlign = (short)va_arg(ap, int);
- short fontY = (short)va_arg(ap, int);
- if (fontColor)
- clif_broadcast2(bl, mes, len, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF);
- else
- clif_broadcast(bl, mes, len, type, SELF);
- return 0;
- }
- BUILDIN_FUNC(mapannounce)
- {
- const char *mapname = script_getstr(st,2);
- const char *mes = script_getstr(st,3);
- int flag = script_getnum(st,4);
- const char *fontColor = script_hasdata(st,5) ? script_getstr(st,5) : NULL;
- int fontType = script_hasdata(st,6) ? script_getnum(st,6) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,7) ? script_getnum(st,7) : 12; // default fontSize
- int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign
- int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY
- int m;
- if ((m = map_mapname2mapid(mapname)) < 0)
- return 0;
- map_foreachinmap(buildin_announce_sub, m, BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return 0;
- }
- /*==========================================
- * 天の声アナウンス(特定エリア)
- *------------------------------------------*/
- BUILDIN_FUNC(areaannounce)
- {
- const char *mapname = script_getstr(st,2);
- int x0 = script_getnum(st,3);
- int y0 = script_getnum(st,4);
- int x1 = script_getnum(st,5);
- int y1 = script_getnum(st,6);
- const char *mes = script_getstr(st,7);
- int flag = script_getnum(st,8);
- const char *fontColor = script_hasdata(st,9) ? script_getstr(st,9) : NULL;
- int fontType = script_hasdata(st,10) ? script_getnum(st,10) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,11) ? script_getnum(st,11) : 12; // default fontSize
- int fontAlign = script_hasdata(st,12) ? script_getnum(st,12) : 0; // default fontAlign
- int fontY = script_hasdata(st,13) ? script_getnum(st,13) : 0; // default fontY
- int m;
- if ((m = map_mapname2mapid(mapname)) < 0)
- return 0;
- map_foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return 0;
- }
- /*==========================================
- * ユーザー数所得
- *------------------------------------------*/
- BUILDIN_FUNC(getusers)
- {
- int flag, val = 0;
- struct map_session_data* sd;
- struct block_list* bl = NULL;
- flag = script_getnum(st,2);
- if(flag&0x8)
- {// npc
- bl = map_id2bl(st->oid);
- }
- else if((sd = script_rid2sd(st))!=NULL)
- {// pc
- bl = &sd->bl;
- }
- switch(flag&0x07)
- {
- case 0:
- if(bl)
- {
- val = map[bl->m].users;
- }
- break;
- case 1:
- val = map_getusers();
- break;
- default:
- ShowWarning("buildin_getusers: Unknown type %d.\n", flag);
- script_pushint(st,0);
- return 1;
- }
- script_pushint(st,val);
- return 0;
- }
- /*==========================================
- * Works like @WHO - displays all online users names in window
- *------------------------------------------*/
- BUILDIN_FUNC(getusersname)
- {
- TBL_PC *sd, *pl_sd;
- int disp_num=1;
- struct s_mapiterator* iter;
- sd = script_rid2sd(st);
- if (!sd) return 0;
- iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
- {
- if( battle_config.hide_GM_session && pc_isGM(pl_sd) )
- continue; // skip hidden GMs
- if((disp_num++)%10==0)
- clif_scriptnext(sd,st->oid);
- clif_scriptmes(sd,st->oid,pl_sd->status.name);
- }
- mapit_free(iter);
-
- return 0;
- }
- /*==========================================
- * getmapguildusers("mapname",guild ID) Returns the number guild members present on a map [Reddozen]
- *------------------------------------------*/
- BUILDIN_FUNC(getmapguildusers)
- {
- const char *str;
- int m, gid;
- int i=0,c=0;
- struct guild *g = NULL;
- str=script_getstr(st,2);
- gid=script_getnum(st,3);
- if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server)
- script_pushint(st,-1);
- return 0;
- }
- g = guild_search(gid);
- if (g){
- for(i = 0; i < g->max_member; i++)
- {
- if (g->member[i].sd && g->member[i].sd->bl.m == m)
- c++;
- }
- }
- script_pushint(st,c);
- return 0;
- }
- /*==========================================
- * マップ指定ユーザー数所得
- *------------------------------------------*/
- BUILDIN_FUNC(getmapusers)
- {
- const char *str;
- int m;
- str=script_getstr(st,2);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,map[m].users);
- return 0;
- }
- /*==========================================
- * エリア指定ユーザー数所得
- *------------------------------------------*/
- static int buildin_getareausers_sub(struct block_list *bl,va_list ap)
- {
- int *users=va_arg(ap,int *);
- (*users)++;
- return 0;
- }
- BUILDIN_FUNC(getareausers)
- {
- const char *str;
- int m,x0,y0,x1,y1,users=0;
- str=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- map_foreachinarea(buildin_getareausers_sub,
- m,x0,y0,x1,y1,BL_PC,&users);
- script_pushint(st,users);
- return 0;
- }
- /*==========================================
- * エリア指定ドロップアイテム数所得
- *------------------------------------------*/
- static int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
- {
- int item=va_arg(ap,int);
- int *amount=va_arg(ap,int *);
- struct flooritem_data *drop=(struct flooritem_data *)bl;
- if(drop->item_data.nameid==item)
- (*amount)+=drop->item_data.amount;
- return 0;
- }
- BUILDIN_FUNC(getareadropitem)
- {
- const char *str;
- int m,x0,y0,x1,y1,item,amount=0;
- struct script_data *data;
- str=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- data=script_getdata(st,7);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- item=UNKNOWN_ITEM_ID;
- if( item_data )
- item=item_data->nameid;
- }else
- item=conv_num(st,data);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- map_foreachinarea(buildin_getareadropitem_sub,
- m,x0,y0,x1,y1,BL_ITEM,item,&amount);
- script_pushint(st,amount);
- return 0;
- }
- /*==========================================
- * NPCの有効化
- *------------------------------------------*/
- BUILDIN_FUNC(enablenpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,1);
- return 0;
- }
- /*==========================================
- * NPCの無効化
- *------------------------------------------*/
- BUILDIN_FUNC(disablenpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,0);
- return 0;
- }
- /*==========================================
- * 隠れているNPCの表示
- *------------------------------------------*/
- BUILDIN_FUNC(hideoffnpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,2);
- return 0;
- }
- /*==========================================
- * NPCをハイディング
- *------------------------------------------*/
- BUILDIN_FUNC(hideonnpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,4);
- return 0;
- }
- /// Starts a status effect on the target unit or on the attached player.
- ///
- /// sc_start <effect_id>,<duration>,<val1>{,<unit_id>};
- BUILDIN_FUNC(sc_start)
- {
- struct block_list* bl;
- enum sc_type type;
- int tick;
- int val1;
- int val4 = 0;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- if( script_hasdata(st,5) )
- bl = map_id2bl(script_getnum(st,5));
- else
- bl = map_id2bl(st->rid);
- if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 )
- {// When there isn't a duration specified, try to get it from the skill_db
- tick = skill_get_time(status_sc2skill(type), val1);
- }
- if( potion_flag == 1 && potion_target )
- { //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = map_id2bl(potion_target);
- tick /= 2;// Thrown potions only last half.
- val4 = 1;// Mark that this was a thrown sc_effect
- }
- if( bl )
- status_change_start(bl, type, 10000, val1, 0, 0, val4, tick, 2);
- return 0;
- }
- /// Starts a status effect on the target unit or on the attached player.
- ///
- /// sc_start2 <effect_id>,<duration>,<val1>,<percent chance>{,<unit_id>};
- BUILDIN_FUNC(sc_start2)
- {
- struct block_list* bl;
- enum sc_type type;
- int tick;
- int val1;
- int val4 = 0;
- int rate;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- rate = script_getnum(st,5);
- if( script_hasdata(st,6) )
- bl = map_id2bl(script_getnum(st,6));
- else
- bl = map_id2bl(st->rid);
- if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 )
- {// When there isn't a duration specified, try to get it from the skill_db
- tick = skill_get_time(status_sc2skill(type), val1);
- }
- if( potion_flag == 1 && potion_target )
- { //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = map_id2bl(potion_target);
- tick /= 2;// Thrown potions only last half.
- val4 = 1;// Mark that this was a thrown sc_effect
- }
- if( bl )
- status_change_start(bl, type, rate, val1, 0, 0, val4, tick, 2);
- return 0;
- }
- /// Starts a status effect on the target unit or on the attached player.
- ///
- /// sc_start4 <effect_id>,<duration>,<val1>,<val2>,<val3>,<val4>{,<unit_id>};
- BUILDIN_FUNC(sc_start4)
- {
- struct block_list* bl;
- enum sc_type type;
- int tick;
- int val1;
- int val2;
- int val3;
- int val4;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- val2 = script_getnum(st,5);
- val3 = script_getnum(st,6);
- val4 = script_getnum(st,7);
- if( script_hasdata(st,8) )
- bl = map_id2bl(script_getnum(st,8));
- else
- bl = map_id2bl(st->rid);
- if( tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0 )
- {// When there isn't a duration specified, try to get it from the skill_db
- tick = skill_get_time(status_sc2skill(type), val1);
- }
- if( potion_flag == 1 && potion_target )
- { //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = map_id2bl(potion_target);
- tick /= 2;// Thrown potions only last half.
- }
- if( bl )
- status_change_start(bl, type, 10000, val1, val2, val3, val4, tick, 2);
- return 0;
- }
- /// Ends one or all status effects on the target unit or on the attached player.
- ///
- /// sc_end <effect_id>{,<unit_id>};
- BUILDIN_FUNC(sc_end)
- {
- struct block_list* bl;
- int type;
- type = script_getnum(st,2);
- if( script_hasdata(st,3) )
- bl = map_id2bl(script_getnum(st,3));
- else
- bl = map_id2bl(st->rid);
-
- if( potion_flag==1 && potion_target )
- {//##TODO how does this work [FlavioJS]
- bl = map_id2bl(potion_target);
- }
- if( !bl ) return 0;
- if( type >= 0 && type < SC_MAX )
- {
- struct status_change *sc = status_get_sc(bl);
- struct status_change_entry *sce = sc?sc->data[type]:NULL;
- if (!sce) return 0;
- //This should help status_change_end force disabling the SC in case it has no limit.
- sce->val1 = sce->val2 = sce->val3 = sce->val4 = 0;
- status_change_end(bl, (sc_type)type, INVALID_TIMER);
- } else
- status_change_clear(bl, 2);// remove all effects
- return 0;
- }
- /*==========================================
- * 状態異常耐性を計算した確率を返す
- *------------------------------------------*/
- BUILDIN_FUNC(getscrate)
- {
- struct block_list *bl;
- int type,rate;
- type=script_getnum(st,2);
- rate=script_getnum(st,3);
- if( script_hasdata(st,4) ) //指定したキャラの耐性を計算する
- bl = map_id2bl(script_getnum(st,4));
- else
- bl = map_id2bl(st->rid);
- if (bl)
- rate = status_get_sc_def(bl, (sc_type)type, 10000, 10000, 0);
- script_pushint(st,rate);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(debugmes)
- {
- const char *str;
- str=script_getstr(st,2);
- ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,str);
- return 0;
- }
- /*==========================================
- *捕獲アイテム使用
- *------------------------------------------*/
- BUILDIN_FUNC(catchpet)
- {
- int pet_id;
- TBL_PC *sd;
- pet_id= script_getnum(st,2);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pet_catch_process1(sd,pet_id);
- return 0;
- }
- /*==========================================
- * [orn]
- *------------------------------------------*/
- BUILDIN_FUNC(homunculus_evolution)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if(merc_is_hom_active(sd->hd))
- {
- if (sd->hd->homunculus.intimacy > 91000)
- merc_hom_evolution(sd->hd);
- else
- clif_emotion(&sd->hd->bl, 4) ; //swt
- }
- return 0;
- }
- // [Zephyrus]
- BUILDIN_FUNC(homunculus_shuffle)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if(merc_is_hom_active(sd->hd))
- merc_hom_shuffle(sd->hd);
- return 0;
- }
- //These two functions bring the eA MAPID_* class functionality to scripts.
- BUILDIN_FUNC(eaclass)
- {
- int class_;
- if( script_hasdata(st,2) )
- class_ = script_getnum(st,2);
- else {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (!sd) {
- script_pushint(st,-1);
- return 0;
- }
- class_ = sd->status.class_;
- }
- script_pushint(st,pc_jobid2mapid(class_));
- return 0;
- }
- BUILDIN_FUNC(roclass)
- {
- int class_ =script_getnum(st,2);
- int sex;
- if( script_hasdata(st,3) )
- sex = script_getnum(st,3);
- else {
- TBL_PC *sd;
- if (st->rid && (sd=script_rid2sd(st)))
- sex = sd->status.sex;
- else
- sex = 1; //Just use male when not found.
- }
- script_pushint(st,pc_mapid2jobid(class_, sex));
- return 0;
- }
- /*==========================================
- *携帯卵孵化機使用
- *------------------------------------------*/
- BUILDIN_FUNC(birthpet)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_sendegg(sd);
- return 0;
- }
- /*==========================================
- * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
- *------------------------------------------*/
- BUILDIN_FUNC(resetlvl)
- {
- TBL_PC *sd;
- int type=script_getnum(st,2);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_resetlvl(sd,type);
- return 0;
- }
- /*==========================================
- * ステータスリセット
- *------------------------------------------*/
- BUILDIN_FUNC(resetstatus)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- pc_resetstate(sd);
- return 0;
- }
- /*==========================================
- * script command resetskill
- *------------------------------------------*/
- BUILDIN_FUNC(resetskill)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- pc_resetskill(sd,1);
- return 0;
- }
- /*==========================================
- * Counts total amount of skill points.
- *------------------------------------------*/
- BUILDIN_FUNC(skillpointcount)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- script_pushint(st,sd->status.skill_point + pc_resetskill(sd,2));
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(changebase)
- {
- TBL_PC *sd=NULL;
- int vclass;
- if( script_hasdata(st,3) )
- sd=map_id2sd(script_getnum(st,3));
- else
- sd=script_rid2sd(st);
- if(sd == NULL)
- return 0;
- vclass = script_getnum(st,2);
- if(vclass == JOB_WEDDING)
- {
- if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
- sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
- )
- return 0;
- }
- if(!sd->disguise && vclass != sd->vd.class_) {
- status_set_viewdata(&sd->bl, vclass);
- //Updated client view. Base, Weapon and Cloth Colors.
- clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
- clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
- if (sd->vd.cloth_color)
- clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
- clif_skillinfoblock(sd);
- }
- return 0;
- }
- /*==========================================
- * 性別変換
- *------------------------------------------*/
- BUILDIN_FUNC(changesex)
- {
- TBL_PC *sd = NULL;
- sd = script_rid2sd(st);
- chrif_changesex(sd);
- return 0;
- }
- /*==========================================
- * Works like 'announce' but outputs in the common chat window
- *------------------------------------------*/
- BUILDIN_FUNC(globalmes)
- {
- struct block_list *bl = map_id2bl(st->oid);
- struct npc_data *nd = (struct npc_data *)bl;
- const char *name=NULL,*mes;
- mes=script_getstr(st,2); // メッセージの取得
- if(mes==NULL) return 0;
-
- if(script_hasdata(st,3)){ // NPC名の取得(123#456)
- name=script_getstr(st,3);
- } else {
- name=nd->name;
- }
- npc_globalmessage(name,mes); // グローバルメッセージ送信
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- // NPC waiting room (chat room)
- //
- /// Creates a waiting room (chat room) for this npc.
- ///
- /// waitingroom "<title>",<limit>,<trigger>,"<event>";
- /// waitingroom "<title>",<limit>,"<event>",<trigger>;
- /// waitingroom "<title>",<limit>,"<event>";
- /// waitingroom "<title>",<limit>;
- BUILDIN_FUNC(waitingroom)
- {
- struct npc_data* nd;
- const char* title;
- const char* ev = "";
- int limit;
- int trigger = 0;
- int pub = 1;
- title = script_getstr(st, 2);
- limit = script_getnum(st, 3);
- if( script_hasdata(st,5) )
- {
- struct script_data* last = script_getdata(st, 5);
- get_val(st, last);
- if( data_isstring(last) )
- {// ,<trigger>,"<event>"
- trigger = script_getnum(st, 4);
- ev = script_getstr(st, 5);
- }
- else
- {// ,"<event>",<trigger>
- ev = script_getstr(st, 4);
- trigger = script_getnum(st,5);
- }
- }
- else if( script_hasdata(st,4) )
- {// ,"<event>"
- ev = script_getstr(st, 4);
- trigger = limit;
- }
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL )
- chat_createnpcchat(nd, title, limit, pub, trigger, ev);
- return 0;
- }
- /// Removes the waiting room of the current or target npc.
- ///
- /// delwaitingroom "<npc_name>";
- /// delwaitingroom;
- BUILDIN_FUNC(delwaitingroom)
- {
- struct npc_data* nd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL )
- chat_deletenpcchat(nd);
- return 0;
- }
- /// Kicks all the players from the waiting room of the current or target npc.
- ///
- /// kickwaitingroomall "<npc_name>";
- /// kickwaitingroomall;
- BUILDIN_FUNC(waitingroomkickall)
- {
- struct npc_data* nd;
- struct chat_data* cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_npckickall(cd);
- return 0;
- }
- /// Enables the waiting room event of the current or target npc.
- ///
- /// enablewaitingroomevent "<npc_name>";
- /// enablewaitingroomevent;
- BUILDIN_FUNC(enablewaitingroomevent)
- {
- struct npc_data* nd;
- struct chat_data* cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_enableevent(cd);
- return 0;
- }
- /// Disables the waiting room event of the current or target npc.
- ///
- /// disablewaitingroomevent "<npc_name>";
- /// disablewaitingroomevent;
- BUILDIN_FUNC(disablewaitingroomevent)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_disableevent(cd);
- return 0;
- }
- /// Returns info on the waiting room of the current or target npc.
- /// Returns -1 if the type unknown
- /// <type>=0 : current number of users
- /// <type>=1 : maximum number of users allowed
- /// <type>=2 : the number of users that trigger the event
- /// <type>=3 : if the trigger is disabled
- /// <type>=4 : the title of the waiting room
- /// <type>=5 : the password of the waiting room
- /// <type>=16 : the name of the waiting room event
- /// <type>=32 : if the waiting room is full
- /// <type>=33 : if there are enough users to trigger the event
- ///
- /// getwaitingroomstate(<type>,"<npc_name>") -> <info>
- /// getwaitingroomstate(<type>) -> <info>
- BUILDIN_FUNC(getwaitingroomstate)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- int type;
- type = script_getnum(st,2);
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st, 3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- {
- script_pushint(st, -1);
- return 0;
- }
- switch(type)
- {
- case 0: script_pushint(st, cd->users); break;
- case 1: script_pushint(st, cd->limit); break;
- case 2: script_pushint(st, cd->trigger&0x7f); break;
- case 3: script_pushint(st, ((cd->trigger&0x80)!=0)); break;
- case 4: script_pushstrcopy(st, cd->title); break;
- case 5: script_pushstrcopy(st, cd->pass); break;
- case 16: script_pushstrcopy(st, cd->npc_event);break;
- case 32: script_pushint(st, (cd->users >= cd->limit)); break;
- case 33: script_pushint(st, (cd->users >= cd->trigger)); break;
- default: script_pushint(st, -1); break;
- }
- return 0;
- }
- /// Warps the trigger or target amount of players to the target map and position.
- /// Players are automatically removed from the waiting room.
- /// Those waiting the longest will get warped first.
- /// The target map can be "Random" for a random position in the current map,
- /// and "SavePoint" for the savepoint map+position.
- /// The map flag noteleport of the current map is only considered when teleporting to the savepoint.
- ///
- /// The id's of the teleported players are put into the array $@warpwaitingpc[]
- /// The total number of teleported players is put into $@warpwaitingpcnum
- ///
- /// warpwaitingpc "<map name>",<x>,<y>,<number of players>;
- /// warpwaitingpc "<map name>",<x>,<y>;
- BUILDIN_FUNC(warpwaitingpc)
- {
- int x;
- int y;
- int i;
- int n;
- const char* map_name;
- struct npc_data* nd;
- struct chat_data* cd;
- TBL_PC* sd;
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- return 0;
- map_name = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- n = cd->trigger&0x7f;
- if( script_hasdata(st,5) )
- n = script_getnum(st,5);
- for( i = 0; i < n && cd->users > 0; i++ )
- {
- sd = cd->usersd[0];
- if( sd == NULL )
- {
- ShowDebug("script:warpwaitingpc: no user in chat room position 0 (cd->users=%d,%d/%d)\n", cd->users, i, n);
- mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24), 0);
- continue;// Broken npc chat room?
- }
- mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24), sd->bl.id);
- if( strcmp(map_name,"Random") == 0 )
- pc_randomwarp(sd,3);
- else if( strcmp(map_name,"SavePoint") == 0 )
- {
- if( map[sd->bl.m].flag.noteleport )
- return 0;// can't teleport on this map
- pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 3);
- }
- else
- pc_setpos(sd, mapindex_name2id(map_name), x, y, 0);
- }
- mapreg_setreg(add_str("$@warpwaitingpcnum"), i);
- return 0;
- }
- /////////////////////////////////////////////////////////////////////
- // ...
- //
- /// Detaches a character from a script.
- ///
- /// @param st Script state to detach the character from.
- static void script_detach_rid(struct script_state* st)
- {
- if(st->rid)
- {
- script_detach_state(st, false);
- st->rid = 0;
- }
- }
- /*==========================================
- * RIDのアタッチ
- *------------------------------------------*/
- BUILDIN_FUNC(attachrid)
- {
- int rid = script_getnum(st,2);
- struct map_session_data* sd;
- if ((sd = map_id2sd(rid))!=NULL) {
- script_detach_rid(st);
- st->rid = rid;
- script_attach_state(st);
- script_pushint(st,1);
- } else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * RIDのデタッチ
- *------------------------------------------*/
- BUILDIN_FUNC(detachrid)
- {
- script_detach_rid(st);
- return 0;
- }
- /*==========================================
- * 存在チェック
- *------------------------------------------*/
- BUILDIN_FUNC(isloggedin)
- {
- TBL_PC* sd = map_id2sd(script_getnum(st,2));
- if (script_hasdata(st,3) && sd &&
- sd->status.char_id != script_getnum(st,3))
- sd = NULL;
- push_val(st->stack,C_INT,sd!=NULL);
- return 0;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(setmapflagnosave)
- {
- int m,x,y;
- unsigned short mapindex;
- const char *str,*str2;
- str=script_getstr(st,2);
- str2=script_getstr(st,3);
- x=script_getnum(st,4);
- y=script_getnum(st,5);
- m = map_mapname2mapid(str);
- mapindex = mapindex_name2id(str2);
-
- if(m >= 0 && mapindex) {
- map[m].flag.nosave=1;
- map[m].save.map=mapindex;
- map[m].save.x=x;
- map[m].save.y=y;
- }
- return 0;
- }
- BUILDIN_FUNC(getmapflag)
- {
- int m,i;
- const char *str;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: script_pushint(st,map[m].flag.nomemo); break;
- case MF_NOTELEPORT: script_pushint(st,map[m].flag.noteleport); break;
- case MF_NOBRANCH: script_pushint(st,map[m].flag.nobranch); break;
- case MF_NOPENALTY: script_pushint(st,map[m].flag.noexppenalty); break;
- case MF_NOZENYPENALTY: script_pushint(st,map[m].flag.nozenypenalty); break;
- case MF_PVP: script_pushint(st,map[m].flag.pvp); break;
- case MF_PVP_NOPARTY: script_pushint(st,map[m].flag.pvp_noparty); break;
- case MF_PVP_NOGUILD: script_pushint(st,map[m].flag.pvp_noguild); break;
- case MF_GVG: script_pushint(st,map[m].flag.gvg); break;
- case MF_GVG_NOPARTY: script_pushint(st,map[m].flag.gvg_noparty); break;
- case MF_GVG_DUNGEON: script_pushint(st,map[m].flag.gvg_dungeon); break;
- case MF_GVG_CASTLE: script_pushint(st,map[m].flag.gvg_castle); break;
- case MF_NOTRADE: script_pushint(st,map[m].flag.notrade); break;
- case MF_NODROP: script_pushint(st,map[m].flag.nodrop); break;
- case MF_NOSKILL: script_pushint(st,map[m].flag.noskill); break;
- case MF_NOWARP: script_pushint(st,map[m].flag.nowarp); break;
- case MF_NOICEWALL: script_pushint(st,map[m].flag.noicewall); break;
- case MF_SNOW: script_pushint(st,map[m].flag.snow); break;
- case MF_CLOUDS: script_pushint(st,map[m].flag.clouds); break;
- case MF_CLOUDS2: script_pushint(st,map[m].flag.clouds2); break;
- case MF_FOG: script_pushint(st,map[m].flag.fog); break;
- case MF_FIREWORKS: script_pushint(st,map[m].flag.fireworks); break;
- case MF_SAKURA: script_pushint(st,map[m].flag.sakura); break;
- case MF_LEAVES: script_pushint(st,map[m].flag.leaves); break;
- case MF_RAIN: script_pushint(st,map[m].flag.rain); break;
- case MF_NIGHTENABLED: script_pushint(st,map[m].flag.nightenabled); break;
- case MF_NOGO: script_pushint(st,map[m].flag.nogo); break;
- case MF_NOBASEEXP: script_pushint(st,map[m].flag.nobaseexp); break;
- case MF_NOJOBEXP: script_pushint(st,map[m].flag.nojobexp); break;
- case MF_NOMOBLOOT: script_pushint(st,map[m].flag.nomobloot); break;
- case MF_NOMVPLOOT: script_pushint(st,map[m].flag.nomvploot); break;
- case MF_NORETURN: script_pushint(st,map[m].flag.noreturn); break;
- case MF_NOWARPTO: script_pushint(st,map[m].flag.nowarpto); break;
- case MF_NIGHTMAREDROP: script_pushint(st,map[m].flag.pvp_nightmaredrop); break;
- case MF_RESTRICTED: script_pushint(st,map[m].flag.restricted); break;
- case MF_NOCOMMAND: script_pushint(st,map[m].nocommand); break;
- case MF_JEXP: script_pushint(st,map[m].jexp); break;
- case MF_BEXP: script_pushint(st,map[m].bexp); break;
- case MF_NOVENDING: script_pushint(st,map[m].flag.novending); break;
- case MF_LOADEVENT: script_pushint(st,map[m].flag.loadevent); break;
- case MF_NOCHAT: script_pushint(st,map[m].flag.nochat); break;
- case MF_PARTYLOCK: script_pushint(st,map[m].flag.partylock); break;
- case MF_GUILDLOCK: script_pushint(st,map[m].flag.guildlock); break;
- case MF_TOWN: script_pushint(st,map[m].flag.town); break;
- case MF_AUTOTRADE: script_pushint(st,map[m].flag.autotrade); break;
- case MF_ALLOWKS: script_pushint(st,map[m].flag.allowks); break;
- case MF_MONSTER_NOTELEPORT: script_pushint(st,map[m].flag.monster_noteleport); break;
- case MF_PVP_NOCALCRANK: script_pushint(st,map[m].flag.pvp_nocalcrank); break;
- case MF_BATTLEGROUND: script_pushint(st,map[m].flag.battleground); break;
- }
- }
- return 0;
- }
- BUILDIN_FUNC(setmapflag)
- {
- int m,i;
- const char *str;
- const char *val=NULL;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- if(script_hasdata(st,4)){
- val=script_getstr(st,4);
- }
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: map[m].flag.nomemo=1; break;
- case MF_NOTELEPORT: map[m].flag.noteleport=1; break;
- case MF_NOBRANCH: map[m].flag.nobranch=1; break;
- case MF_NOPENALTY: map[m].flag.noexppenalty=1; map[m].flag.nozenypenalty=1; break;
- case MF_NOZENYPENALTY: map[m].flag.nozenypenalty=1; break;
- case MF_PVP: map[m].flag.pvp=1; break;
- case MF_PVP_NOPARTY: map[m].flag.pvp_noparty=1; break;
- case MF_PVP_NOGUILD: map[m].flag.pvp_noguild=1; break;
- case MF_GVG: map[m].flag.gvg=1; break;
- case MF_GVG_NOPARTY: map[m].flag.gvg_noparty=1; break;
- case MF_GVG_DUNGEON: map[m].flag.gvg_dungeon=1; break;
- case MF_GVG_CASTLE: map[m].flag.gvg_castle=1; break;
- case MF_NOTRADE: map[m].flag.notrade=1; break;
- case MF_NODROP: map[m].flag.nodrop=1; break;
- case MF_NOSKILL: map[m].flag.noskill=1; break;
- case MF_NOWARP: map[m].flag.nowarp=1; break;
- case MF_NOICEWALL: map[m].flag.noicewall=1; break;
- case MF_SNOW: map[m].flag.snow=1; break;
- case MF_CLOUDS: map[m].flag.clouds=1; break;
- case MF_CLOUDS2: map[m].flag.clouds2=1; break;
- case MF_FOG: map[m].flag.fog=1; break;
- case MF_FIREWORKS: map[m].flag.fireworks=1; break;
- case MF_SAKURA: map[m].flag.sakura=1; break;
- case MF_LEAVES: map[m].flag.leaves=1; break;
- case MF_RAIN: map[m].flag.rain=1; break;
- case MF_NIGHTENABLED: map[m].flag.nightenabled=1; break;
- case MF_NOGO: map[m].flag.nogo=1; break;
- case MF_NOBASEEXP: map[m].flag.nobaseexp=1; break;
- case MF_NOJOBEXP: map[m].flag.nojobexp=1; break;
- case MF_NOMOBLOOT: map[m].flag.nomobloot=1; break;
- case MF_NOMVPLOOT: map[m].flag.nomvploot=1; break;
- case MF_NORETURN: map[m].flag.noreturn=1; break;
- case MF_NOWARPTO: map[m].flag.nowarpto=1; break;
- case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop=1; break;
- case MF_RESTRICTED: map[m].flag.restricted=1; break;
- case MF_NOCOMMAND: map[m].nocommand = (!val || atoi(val) <= 0) ? 100 : atoi(val); break;
- case MF_JEXP: map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val); break;
- case MF_BEXP: map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val); break;
- case MF_NOVENDING: map[m].flag.novending=1; break;
- case MF_LOADEVENT: map[m].flag.loadevent=1; break;
- case MF_NOCHAT: map[m].flag.nochat=1; break;
- case MF_PARTYLOCK: map[m].flag.partylock=1; break;
- case MF_GUILDLOCK: map[m].flag.guildlock=1; break;
- case MF_TOWN: map[m].flag.town=1; break;
- case MF_AUTOTRADE: map[m].flag.autotrade=1; break;
- case MF_ALLOWKS: map[m].flag.allowks=1; break;
- case MF_MONSTER_NOTELEPORT: map[m].flag.monster_noteleport=1; break;
- case MF_PVP_NOCALCRANK: map[m].flag.pvp_nocalcrank=1; break;
- case MF_BATTLEGROUND: map[m].flag.battleground = (!val || atoi(val) < 0 || atoi(val) > 2) ? 1 : atoi(val); break;
- }
- }
- return 0;
- }
- BUILDIN_FUNC(removemapflag)
- {
- int m,i;
- const char *str;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: map[m].flag.nomemo=0; break;
- case MF_NOTELEPORT: map[m].flag.noteleport=0; break;
- case MF_NOSAVE: map[m].flag.nosave=0; break;
- case MF_NOBRANCH: map[m].flag.nobranch=0; break;
- case MF_NOPENALTY: map[m].flag.noexppenalty=0; map[m].flag.nozenypenalty=0; break;
- case MF_PVP: map[m].flag.pvp=0; break;
- case MF_PVP_NOPARTY: map[m].flag.pvp_noparty=0; break;
- case MF_PVP_NOGUILD: map[m].flag.pvp_noguild=0; break;
- case MF_GVG: map[m].flag.gvg=0; break;
- case MF_GVG_NOPARTY: map[m].flag.gvg_noparty=0; break;
- case MF_GVG_DUNGEON: map[m].flag.gvg_dungeon=0; break;
- case MF_GVG_CASTLE: map[m].flag.gvg_castle=0; break;
- case MF_NOZENYPENALTY: map[m].flag.nozenypenalty=0; break;
- case MF_NOTRADE: map[m].flag.notrade=0; break;
- case MF_NODROP: map[m].flag.nodrop=0; break;
- case MF_NOSKILL: map[m].flag.noskill=0; break;
- case MF_NOWARP: map[m].flag.nowarp=0; break;
- case MF_NOICEWALL: map[m].flag.noicewall=0; break;
- case MF_SNOW: map[m].flag.snow=0; break;
- case MF_CLOUDS: map[m].flag.clouds=0; break;
- case MF_CLOUDS2: map[m].flag.clouds2=0; break;
- case MF_FOG: map[m].flag.fog=0; break;
- case MF_FIREWORKS: map[m].flag.fireworks=0; break;
- case MF_SAKURA: map[m].flag.sakura=0; break;
- case MF_LEAVES: map[m].flag.leaves=0; break;
- case MF_RAIN: map[m].flag.rain=0; break;
- case MF_NIGHTENABLED: map[m].flag.nightenabled=0; break;
- case MF_NOGO: map[m].flag.nogo=0; break;
- case MF_NOBASEEXP: map[m].flag.nobaseexp=0; break;
- case MF_NOJOBEXP: map[m].flag.nojobexp=0; break;
- case MF_NOMOBLOOT: map[m].flag.nomobloot=0; break;
- case MF_NOMVPLOOT: map[m].flag.nomvploot=0; break;
- case MF_NORETURN: map[m].flag.noreturn=0; break;
- case MF_NOWARPTO: map[m].flag.nowarpto=0; break;
- case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop=0; break;
- case MF_RESTRICTED: map[m].flag.restricted=0; break;
- case MF_NOCOMMAND: map[m].nocommand=0; break;
- case MF_JEXP: map[m].jexp=100; break;
- case MF_BEXP: map[m].bexp=100; break;
- case MF_NOVENDING: map[m].flag.novending=0; break;
- case MF_LOADEVENT: map[m].flag.loadevent=0; break;
- case MF_NOCHAT: map[m].flag.nochat=0; break;
- case MF_PARTYLOCK: map[m].flag.partylock=0; break;
- case MF_GUILDLOCK: map[m].flag.guildlock=0; break;
- case MF_TOWN: map[m].flag.town=0; break;
- case MF_AUTOTRADE: map[m].flag.autotrade=0; break;
- case MF_ALLOWKS: map[m].flag.allowks=0; break;
- case MF_MONSTER_NOTELEPORT: map[m].flag.monster_noteleport=0; break;
- case MF_PVP_NOCALCRANK: map[m].flag.pvp_nocalcrank=0; break;
- case MF_BATTLEGROUND: map[m].flag.battleground=0; break;
- }
- }
- return 0;
- }
- BUILDIN_FUNC(pvpon)
- {
- int m;
- const char *str;
- TBL_PC* sd = NULL;
- struct s_mapiterator* iter;
- str = script_getstr(st,2);
- m = map_mapname2mapid(str);
- if( m < 0 || map[m].flag.pvp )
- return 0; // nothing to do
- map[m].flag.pvp = 1;
- clif_send0199(m,1);
- if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
- return 0;
- iter = mapit_getallusers();
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
- {
- if( sd->bl.m != m || sd->pvp_timer != -1 )
- continue; // not applicable
- sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
- sd->pvp_rank = 0;
- sd->pvp_lastusers = 0;
- sd->pvp_point = 5;
- sd->pvp_won = 0;
- sd->pvp_lost = 0;
- }
- mapit_free(iter);
- return 0;
- }
- static int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
- {
- TBL_PC* sd = (TBL_PC*)bl;
- clif_pvpset(sd, 0, 0, 2);
- if (sd->pvp_timer != -1) {
- delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
- sd->pvp_timer = INVALID_TIMER;
- }
- return 0;
- }
- BUILDIN_FUNC(pvpoff)
- {
- int m;
- const char *str;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m < 0 || !map[m].flag.pvp)
- return 0; //fixed Lupus
- map[m].flag.pvp = 0;
- clif_send0199(m,0);
- if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
- return 0;
-
- map_foreachinmap(buildin_pvpoff_sub, m, BL_PC);
- return 0;
- }
- BUILDIN_FUNC(gvgon)
- {
- int m;
- const char *str;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m >= 0 && !map[m].flag.gvg) {
- map[m].flag.gvg = 1;
- clif_send0199(m,3);
- }
- return 0;
- }
- BUILDIN_FUNC(gvgoff)
- {
- int m;
- const char *str;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m >= 0 && map[m].flag.gvg) {
- map[m].flag.gvg = 0;
- clif_send0199(m,0);
- }
- return 0;
- }
- /*==========================================
- * Shows an emoticon on top of the player/npc
- * emotion emotion#, <target: 0 - NPC, 1 - PC>, <NPC/PC name>
- *------------------------------------------*/
- //Optional second parameter added by [Skotlex]
- BUILDIN_FUNC(emotion)
- {
- int type;
- int player=0;
-
- type=script_getnum(st,2);
- if(type < 0 || type > 100)
- return 0;
- if( script_hasdata(st,3) )
- player=script_getnum(st,3);
-
- if (player) {
- TBL_PC *sd = NULL;
- if( script_hasdata(st,4) )
- sd = map_nick2sd(script_getstr(st,4));
- else
- sd = script_rid2sd(st);
- if (sd)
- clif_emotion(&sd->bl,type);
- } else
- if( script_hasdata(st,4) )
- {
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
- if(nd)
- clif_emotion(&nd->bl,type);
- }
- else
- clif_emotion(map_id2bl(st->oid),type);
- return 0;
- }
- static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
- {
- int m=va_arg(ap,int);
- int g_id=va_arg(ap,int);
- int flag=va_arg(ap,int);
- if(!sd || sd->bl.m != m)
- return 0;
- if(
- (sd->status.guild_id == g_id && flag&1) || //Warp out owners
- (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders
- (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
- )
- pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
- return 1;
- }
- static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
- {
- struct mob_data *md=(struct mob_data *)bl;
- if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
- status_kill(bl);
- return 0;
- }
- BUILDIN_FUNC(maprespawnguildid)
- {
- const char *mapname=script_getstr(st,2);
- int g_id=script_getnum(st,3);
- int flag=script_getnum(st,4);
- int m=map_mapname2mapid(mapname);
- if(m == -1)
- return 0;
- //Catch ALL players (in case some are 'between maps' on execution time)
- map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag);
- if (flag&4) //Remove script mobs.
- map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB);
- return 0;
- }
- BUILDIN_FUNC(agitstart)
- {
- if(agit_flag==1) return 0; // Agit already Start.
- agit_flag=1;
- guild_agit_start();
- return 0;
- }
- BUILDIN_FUNC(agitend)
- {
- if(agit_flag==0) return 0; // Agit already End.
- agit_flag=0;
- guild_agit_end();
- return 0;
- }
- BUILDIN_FUNC(agitstart2)
- {
- if(agit2_flag==1) return 0; // Agit2 already Start.
- agit2_flag=1;
- guild_agit2_start();
- return 0;
- }
- BUILDIN_FUNC(agitend2)
- {
- if(agit2_flag==0) return 0; // Agit2 already End.
- agit2_flag=0;
- guild_agit2_end();
- return 0;
- }
- /*==========================================
- * Returns whether woe is on or off. // choice script
- *------------------------------------------*/
- BUILDIN_FUNC(agitcheck)
- {
- script_pushint(st,agit_flag);
- return 0;
- }
- /*==========================================
- * Returns whether woese is on or off. // choice script
- *------------------------------------------*/
- BUILDIN_FUNC(agitcheck2)
- {
- script_pushint(st,agit2_flag);
- return 0;
- }
- /// Sets the guild_id of this npc.
- ///
- /// flagemblem <guild_id>;
- BUILDIN_FUNC(flagemblem)
- {
- TBL_NPC* nd;
- int g_id=script_getnum(st,2);
- if(g_id < 0) return 0;
- nd = (TBL_NPC*)map_id2nd(st->oid);
- if( nd == NULL )
- {
- ShowError("script:flagemblem: npc %d not found\n", st->oid);
- }
- else if( nd->subtype != SCRIPT )
- {
- ShowError("script:flagemblem: unexpected subtype %d for npc %d '%s'\n", nd->subtype, st->oid, nd->exname);
- }
- else
- {
- nd->u.scr.guild_id = g_id;
- clif_guild_emblem_area(&nd->bl);
- }
- return 0;
- }
- BUILDIN_FUNC(getcastlename)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- const char* name = (gc) ? gc->castle_name : "";
- script_pushstrcopy(st,name);
- return 0;
- }
- BUILDIN_FUNC(getcastledata)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int index = script_getnum(st,3);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- if(script_hasdata(st,4) && index==0 && gc) {
- const char* event = script_getstr(st,4);
- check_event(st, event);
- guild_addcastleinfoevent(gc->castle_id,17,event);
- }
- if(gc){
- switch(index){
- case 0: {
- int i;
- for(i=1;i<18;i++) // Initialize[AgitInit]
- guild_castledataload(gc->castle_id,i);
- } break;
- case 1:
- script_pushint(st,gc->guild_id); break;
- case 2:
- script_pushint(st,gc->economy); break;
- case 3:
- script_pushint(st,gc->defense); break;
- case 4:
- script_pushint(st,gc->triggerE); break;
- case 5:
- script_pushint(st,gc->triggerD); break;
- case 6:
- script_pushint(st,gc->nextTime); break;
- case 7:
- script_pushint(st,gc->payTime); break;
- case 8:
- script_pushint(st,gc->createTime); break;
- case 9:
- script_pushint(st,gc->visibleC); break;
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- script_pushint(st,gc->guardian[index-10].visible); break;
- default:
- script_pushint(st,0); break;
- }
- return 0;
- }
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(setcastledata)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int index = script_getnum(st,3);
- int value = script_getnum(st,4);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- if(gc) {
- // Save Data byself First
- switch(index){
- case 1:
- gc->guild_id = value; break;
- case 2:
- gc->economy = value; break;
- case 3:
- gc->defense = value; break;
- case 4:
- gc->triggerE = value; break;
- case 5:
- gc->triggerD = value; break;
- case 6:
- gc->nextTime = value; break;
- case 7:
- gc->payTime = value; break;
- case 8:
- gc->createTime = value; break;
- case 9:
- gc->visibleC = value; break;
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- gc->guardian[index-10].visible = value; break;
- default:
- return 0;
- }
- guild_castledatasave(gc->castle_id,index,value);
- }
- return 0;
- }
- /* =====================================================================
- * ギルド情報を要求する
- * ---------------------------------------------------------------------*/
- BUILDIN_FUNC(requestguildinfo)
- {
- int guild_id=script_getnum(st,2);
- const char *event=NULL;
- if( script_hasdata(st,3) ){
- event=script_getstr(st,3);
- check_event(st, event);
- }
- if(guild_id>0)
- guild_npc_request_info(guild_id,event);
- return 0;
- }
- /// Returns the number of cards that have been compounded onto the specified equipped item.
- /// getequipcardcnt(<equipment slot>);
- BUILDIN_FUNC(getequipcardcnt)
- {
- int i=-1,j,num;
- TBL_PC *sd;
- int count;
- num=script_getnum(st,2);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i]) {
- script_pushint(st,0);
- return 0;
- }
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- {
- script_pushint(st,0);
- return 0;
- }
- count = 0;
- for( j = 0; j < sd->inventory_data[i]->slot; j++ )
- if( sd->status.inventory[i].card[j] && itemdb_type(sd->status.inventory[i].card[j]) == IT_CARD )
- count++;
- script_pushint(st,count);
- return 0;
- }
- /// Removes all cards from the item found in the specified equipment slot of the invoking character,
- /// and give them to the character. If any cards were removed in this manner, it will also show a success effect.
- /// successremovecards <slot>;
- BUILDIN_FUNC(successremovecards)
- {
- int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
- int num = script_getnum(st,2);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i]) {
- return 0;
- }
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- return 0;
- for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c )
- {
- if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD )
- {// extract this card from the item
- int flag;
- struct item item_tmp;
- cardflag = 1;
- item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c];
- item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
- item_tmp.attribute=0,item_tmp.expire_time=0;
- for (j = 0; j < MAX_SLOTS; j++)
- item_tmp.card[j]=0;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
- if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- if(cardflag == 1)
- { // カードを取り除いたアイテム所得
- int flag;
- struct item item_tmp;
- item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
- item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
- item_tmp.attribute=sd->status.inventory[i].attribute,item_tmp.expire_time=sd->status.inventory[i].expire_time;
- for (j = 0; j < sd->inventory_data[i]->slot; j++)
- item_tmp.card[j]=0;
- for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++)
- item_tmp.card[j]=sd->status.inventory[i].card[j];
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
- pc_delitem(sd,i,1,0,3);
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
- if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- clif_misceffect(&sd->bl,3);
- }
- return 0;
- }
- /// Removes all cards from the item found in the specified equipment slot of the invoking character.
- /// failedremovecards <slot>, <type>;
- /// <type>=0 : will destroy both the item and the cards.
- /// <type>=1 : will keep the item, but destroy the cards.
- /// <type>=2 : will keep the cards, but destroy the item.
- /// <type>=? : will just display the failure effect.
- BUILDIN_FUNC(failedremovecards)
- {
- int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
- int num = script_getnum(st,2);
- int typefail = script_getnum(st,3);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i])
- return 0;
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- return 0;
- for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c )
- {
- if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD )
- {
- cardflag = 1;
- if(typefail == 2)
- {// add cards to inventory, clear
- int flag;
- struct item item_tmp;
- item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c];
- item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
- item_tmp.attribute=0,item_tmp.expire_time=0;
- for (j = 0; j < MAX_SLOTS; j++)
- item_tmp.card[j]=0;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
- if((flag=pc_additem(sd,&item_tmp,1))){
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- }
- if(cardflag == 1)
- {
- if(typefail == 0 || typefail == 2){ // 武具損失
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
- pc_delitem(sd,i,1,0,2);
- }
- if(typefail == 1){ // カードのみ損失(武具を返す)
- int flag;
- struct item item_tmp;
- item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
- item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
- item_tmp.attribute=sd->status.inventory[i].attribute,item_tmp.expire_time=sd->status.inventory[i].expire_time;
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
- for (j = 0; j < sd->inventory_data[i]->slot; j++)
- item_tmp.card[j]=0;
- for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++)
- item_tmp.card[j]=sd->status.inventory[i].card[j];
- pc_delitem(sd,i,1,0,2);
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
- if((flag=pc_additem(sd,&item_tmp,1))){
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- clif_misceffect(&sd->bl,2);
- }
- return 0;
- }
- /* ================================================================
- * mapwarp "<from map>","<to map>",<x>,<y>,<type>,<ID for Type>;
- * type: 0=everyone, 1=guild, 2=party; [Reddozen]
- * improved by [Lance]
- * ================================================================*/
- BUILDIN_FUNC(mapwarp) // Added by RoVeRT
- {
- int x,y,m,check_val=0,check_ID=0,i=0;
- struct guild *g = NULL;
- struct party_data *p = NULL;
- const char *str;
- const char *mapname;
- unsigned int index;
- mapname=script_getstr(st,2);
- str=script_getstr(st,3);
- x=script_getnum(st,4);
- y=script_getnum(st,5);
- if(script_hasdata(st,7)){
- check_val=script_getnum(st,6);
- check_ID=script_getnum(st,7);
- }
- if((m=map_mapname2mapid(mapname))< 0)
- return 0;
- if(!(index=mapindex_name2id(str)))
- return 0;
- switch(check_val){
- case 1:
- g = guild_search(check_ID);
- if (g){
- for( i=0; i < g->max_member; i++)
- {
- if(g->member[i].sd && g->member[i].sd->bl.m==m){
- pc_setpos(g->member[i].sd,index,x,y,3);
- }
- }
- }
- break;
- case 2:
- p = party_search(check_ID);
- if(p){
- for(i=0;i<MAX_PARTY; i++){
- if(p->data[i].sd && p->data[i].sd->bl.m == m){
- pc_setpos(p->data[i].sd,index,x,y,3);
- }
- }
- }
- break;
- default:
- map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y);
- break;
- }
- return 0;
- }
- static int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
- {
- char *event=va_arg(ap,char *);
- struct mob_data *md = ((struct mob_data *)bl);
- if(strcmp(event,md->npc_event)==0 && md->status.hp > 0)
- return 1;
- return 0;
- }
- BUILDIN_FUNC(mobcount) // Added by RoVeRT
- {
- const char *mapname,*event;
- int m;
- mapname=script_getstr(st,2);
- event=script_getstr(st,3);
- check_event(st, event);
- if( (m = map_mapname2mapid(mapname)) < 0 ) {
- script_pushint(st,-1);
- return 0;
- }
-
- if( map[m].flag.src4instance && map[m].instance_id == 0 && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- {
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event));
- return 0;
- }
- BUILDIN_FUNC(marriage)
- {
- const char *partner=script_getstr(st,2);
- TBL_PC *sd=script_rid2sd(st);
- TBL_PC *p_sd=map_nick2sd(partner);
- if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(wedding_effect)
- {
- TBL_PC *sd=script_rid2sd(st);
- struct block_list *bl;
- if(sd==NULL) {
- bl=map_id2bl(st->oid);
- } else
- bl=&sd->bl;
- clif_wedding_effect(bl);
- return 0;
- }
- BUILDIN_FUNC(divorce)
- {
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || pc_divorce(sd) < 0){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(ispartneron)
- {
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || !pc_ismarried(sd) ||
- map_charid2sd(sd->status.partner_id) == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(getpartnerid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.partner_id);
- return 0;
- }
- BUILDIN_FUNC(getchildid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.child);
- return 0;
- }
- BUILDIN_FUNC(getmotherid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.mother);
- return 0;
- }
- BUILDIN_FUNC(getfatherid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.father);
- return 0;
- }
- BUILDIN_FUNC(warppartner)
- {
- int x,y;
- unsigned short mapindex;
- const char *str;
- TBL_PC *sd=script_rid2sd(st);
- TBL_PC *p_sd=NULL;
- if(sd==NULL || !pc_ismarried(sd) ||
- (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
- script_pushint(st,0);
- return 0;
- }
- str=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- mapindex = mapindex_name2id(str);
- if (mapindex) {
- pc_setpos(p_sd,mapindex,x,y,0);
- script_pushint(st,1);
- } else
- script_pushint(st,0);
- return 0;
- }
- /*================================================
- * Script for Displaying MOB Information [Valaris]
- *------------------------------------------------*/
- BUILDIN_FUNC(strmobinfo)
- {
- int num=script_getnum(st,2);
- int class_=script_getnum(st,3);
- if(!mobdb_checkid(class_))
- {
- script_pushint(st,0);
- return 0;
- }
- switch (num) {
- case 1: script_pushstrcopy(st,mob_db(class_)->name); break;
- case 2: script_pushstrcopy(st,mob_db(class_)->jname); break;
- case 3: script_pushint(st,mob_db(class_)->lv); break;
- case 4: script_pushint(st,mob_db(class_)->status.max_hp); break;
- case 5: script_pushint(st,mob_db(class_)->status.max_sp); break;
- case 6: script_pushint(st,mob_db(class_)->base_exp); break;
- case 7: script_pushint(st,mob_db(class_)->job_exp); break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- /*==========================================
- * Summon guardians [Valaris]
- * guardian("<map name>",<x>,<y>,"<name to show>",<mob id>{,"<event label>"}{,<guardian index>}) -> <id>
- *------------------------------------------*/
- BUILDIN_FUNC(guardian)
- {
- int class_=0,x=0,y=0,guardian=0;
- const char *str,*map,*evt="";
- struct script_data *data;
- bool has_index = false;
- map =script_getstr(st,2);
- x =script_getnum(st,3);
- y =script_getnum(st,4);
- str =script_getstr(st,5);
- class_=script_getnum(st,6);
- if( script_hasdata(st,8) )
- {// "<event label>",<guardian index>
- evt=script_getstr(st,7);
- guardian=script_getnum(st,8);
- has_index = true;
- } else if( script_hasdata(st,7) ){
- data=script_getdata(st,7);
- get_val(st,data);
- if( data_isstring(data) )
- {// "<event label>"
- evt=script_getstr(st,7);
- } else if( data_isint(data) )
- {// <guardian index>
- guardian=script_getnum(st,7);
- has_index = true;
- } else {
- ShowError("script:guardian: invalid data type for argument #6 (from 1)\n");
- script_reportdata(data);
- return 1;
- }
- }
- check_event(st, evt);
- script_pushint(st, mob_spawn_guardian(map,x,y,str,class_,evt,guardian,has_index));
- return 0;
- }
- /*==========================================
- * Invisible Walls [Zephyrus]
- *------------------------------------------*/
- BUILDIN_FUNC(setwall)
- {
- const char *map, *name;
- int x, y, m, size, dir;
- bool shootable;
-
- map = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- size = script_getnum(st,5);
- dir = script_getnum(st,6);
- shootable = script_getnum(st,7);
- name = script_getstr(st,8);
- if( (m = map_mapname2mapid(map)) < 0 )
- return 0; // Invalid Map
- map_iwall_set(m, x, y, size, dir, shootable, name);
- return 0;
- }
- BUILDIN_FUNC(delwall)
- {
- const char *name = script_getstr(st,2);
- map_iwall_remove(name);
- return 0;
- }
- /// Retrieves various information about the specified guardian.
- ///
- /// guardianinfo("<map_name>", <index>, <type>) -> <value>
- /// type: 0 - whether it is deployed or not
- /// 1 - maximum hp
- /// 2 - current hp
- ///
- BUILDIN_FUNC(guardianinfo)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int id = script_getnum(st,3);
- int type = script_getnum(st,4);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- struct mob_data* gd;
- if( gc == NULL || id < 0 || id >= MAX_GUARDIANS )
- {
- script_pushint(st,-1);
- return 0;
- }
- if( type == 0 )
- script_pushint(st, gc->guardian[id].visible);
- else
- if( !gc->guardian[id].visible )
- script_pushint(st,-1);
- else
- if( (gd = map_id2md(gc->guardian[id].id)) == NULL )
- script_pushint(st,-1);
- else
- {
- if ( type == 1 ) script_pushint(st,gd->status.max_hp);
- else if( type == 2 ) script_pushint(st,gd->status.hp);
- else
- script_pushint(st,-1);
- }
- return 0;
- }
- /*==========================================
- * IDからItem名
- *------------------------------------------*/
- BUILDIN_FUNC(getitemname)
- {
- int item_id=0;
- struct item_data *i_data;
- char *item_name;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- item_id=item_data->nameid;
- }else
- item_id=conv_num(st,data);
- i_data = itemdb_exists(item_id);
- if (i_data == NULL)
- {
- script_pushconststr(st,"null");
- return 0;
- }
- item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
- memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
- script_pushstr(st,item_name);
- return 0;
- }
- /*==========================================
- * Returns number of slots an item has. [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(getitemslots)
- {
- int item_id;
- struct item_data *i_data;
- item_id=script_getnum(st,2);
- i_data = itemdb_exists(item_id);
- if (i_data)
- script_pushint(st,i_data->slot);
- else
- script_pushint(st,-1);
- return 0;
- }
- /*==========================================
- * Returns some values of an item [Lupus]
- * Price, Weight, etc...
- getiteminfo(itemID,n), where n
- 0 value_buy;
- 1 value_sell;
- 2 type;
- 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
- if = 0, then monsters don't drop it at all (rare or a quest item)
- if = 10000, then this item is sold in NPC shops only
- 4 sex;
- 5 equip;
- 6 weight;
- 7 atk;
- 8 def;
- 9 range;
- 10 slot;
- 11 look;
- 12 elv;
- 13 wlv;
- 14 view id
- *------------------------------------------*/
- BUILDIN_FUNC(getiteminfo)
- {
- int item_id,n;
- int *item_arr;
- struct item_data *i_data;
- item_id = script_getnum(st,2);
- n = script_getnum(st,3);
- i_data = itemdb_exists(item_id);
- if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
- script_pushint(st,item_arr[n]);
- } else
- script_pushint(st,-1);
- return 0;
- }
- /*==========================================
- * Set some values of an item [Lupus]
- * Price, Weight, etc...
- setiteminfo(itemID,n,Value), where n
- 0 value_buy;
- 1 value_sell;
- 2 type;
- 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
- if = 0, then monsters don't drop it at all (rare or a quest item)
- if = 10000, then this item is sold in NPC shops only
- 4 sex;
- 5 equip;
- 6 weight;
- 7 atk;
- 8 def;
- 9 range;
- 10 slot;
- 11 look;
- 12 elv;
- 13 wlv;
- 14 view id
- * Returns Value or -1 if the wrong field's been set
- *------------------------------------------*/
- BUILDIN_FUNC(setiteminfo)
- {
- int item_id,n,value;
- int *item_arr;
- struct item_data *i_data;
- item_id = script_getnum(st,2);
- n = script_getnum(st,3);
- value = script_getnum(st,4);
- i_data = itemdb_exists(item_id);
- if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
- item_arr[n] = value;
- script_pushint(st,value);
- } else
- script_pushint(st,-1);
- return 0;
- }
- /*==========================================
- * Returns value from equipped item slot n [Lupus]
- getequipcardid(num,slot)
- where
- num = eqip position slot
- slot = 0,1,2,3 (Card Slot N)
- This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
- it's useful when you want to check item cards or if it's signed
- Useful for such quests as "Sign this refined item with players name" etc
- Hat[0] +4 -> Player's Hat[0] +4
- *------------------------------------------*/
- BUILDIN_FUNC(getequipcardid)
- {
- int i=-1,num,slot;
- TBL_PC *sd;
- num=script_getnum(st,2);
- slot=script_getnum(st,3);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && slot>=0 && slot<4)
- script_pushint(st,sd->status.inventory[i].card[slot]);
- else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * petskillbonus [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petskillbonus)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->bonus)
- { //Clear previous bonus
- if (pd->bonus->timer != -1)
- delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
- } else //init
- pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
- pd->bonus->type=script_getnum(st,2);
- pd->bonus->val=script_getnum(st,3);
- pd->bonus->duration=script_getnum(st,4);
- pd->bonus->delay=script_getnum(st,5);
- if (pd->state.skillbonus == 1)
- pd->state.skillbonus=0; // waiting state
- // wait for timer to start
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->bonus->timer = INVALID_TIMER;
- else
- pd->bonus->timer = add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
- return 0;
- }
- /*==========================================
- * pet looting [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petloot)
- {
- int max;
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
-
- if(sd==NULL || sd->pd==NULL)
- return 0;
- max=script_getnum(st,2);
- if(max < 1)
- max = 1; //Let'em loot at least 1 item.
- else if (max > MAX_PETLOOT_SIZE)
- max = MAX_PETLOOT_SIZE;
-
- pd = sd->pd;
- if (pd->loot != NULL)
- { //Release whatever was there already and reallocate memory
- pet_lootitem_drop(pd, pd->msd);
- aFree(pd->loot->item);
- }
- else
- pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
- pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
-
- pd->loot->max=max;
- pd->loot->count = 0;
- pd->loot->weight = 0;
- return 0;
- }
- /*==========================================
- * PCの所持品情報読み取り
- *------------------------------------------*/
- BUILDIN_FUNC(getinventorylist)
- {
- TBL_PC *sd=script_rid2sd(st);
- char card_var[NAME_LENGTH];
-
- int i,j=0,k;
- if(!sd) return 0;
- for(i=0;i<MAX_INVENTORY;i++){
- if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
- pc_setreg(sd,add_str("@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
- pc_setreg(sd,add_str("@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
- pc_setreg(sd,add_str("@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
- pc_setreg(sd,add_str("@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
- pc_setreg(sd,add_str("@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
- pc_setreg(sd,add_str("@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
- for (k = 0; k < MAX_SLOTS; k++)
- {
- sprintf(card_var, "@inventorylist_card%d",k+1);
- pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
- }
- pc_setreg(sd,add_str("@inventorylist_expire")+(j<<24),sd->status.inventory[i].expire_time);
- j++;
- }
- }
- pc_setreg(sd,add_str("@inventorylist_count"),j);
- return 0;
- }
- BUILDIN_FUNC(getskilllist)
- {
- TBL_PC *sd=script_rid2sd(st);
- int i,j=0;
- if(!sd) return 0;
- for(i=0;i<MAX_SKILL;i++){
- if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
- pc_setreg(sd,add_str("@skilllist_id")+(j<<24),sd->status.skill[i].id);
- pc_setreg(sd,add_str("@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
- pc_setreg(sd,add_str("@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
- j++;
- }
- }
- pc_setreg(sd,add_str("@skilllist_count"),j);
- return 0;
- }
- BUILDIN_FUNC(clearitem)
- {
- TBL_PC *sd=script_rid2sd(st);
- int i;
- if(sd==NULL) return 0;
- for (i=0; i<MAX_INVENTORY; i++) {
- if (sd->status.inventory[i].amount) {
- //Logs items, got from (N)PC scripts [Lupus]
- if(log_config.enable_logs&0x40)
- log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
- pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0);
- }
- }
- return 0;
- }
- /*==========================================
- * Disguise Player (returns Mob/NPC ID if success, 0 on fail)
- *------------------------------------------*/
- BUILDIN_FUNC(disguise)
- {
- int id;
- TBL_PC* sd = script_rid2sd(st);
- if (sd == NULL) return 0;
- id = script_getnum(st,2);
- if (mobdb_checkid(id) || npcdb_checkid(id)) {
- pc_disguise(sd, id);
- script_pushint(st,id);
- } else
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * Undisguise Player (returns 1 if success, 0 on fail)
- *------------------------------------------*/
- BUILDIN_FUNC(undisguise)
- {
- TBL_PC* sd = script_rid2sd(st);
- if (sd == NULL) return 0;
- if (sd->disguise) {
- pc_disguise(sd, 0);
- script_pushint(st,0);
- } else {
- script_pushint(st,1);
- }
- return 0;
- }
- /*==========================================
- * NPCクラスチェンジ
- * classは変わりたいclass
- * typeは通常0なのかな?
- *------------------------------------------*/
- BUILDIN_FUNC(classchange)
- {
- int _class,type;
- struct block_list *bl=map_id2bl(st->oid);
- if(bl==NULL) return 0;
- _class=script_getnum(st,2);
- type=script_getnum(st,3);
- clif_class_change(bl,_class,type);
- return 0;
- }
- /*==========================================
- * NPCから発生するエフェクト
- *------------------------------------------*/
- BUILDIN_FUNC(misceffect)
- {
- int type;
- type=script_getnum(st,2);
- if(st->oid && st->oid != fake_nd->bl.id) {
- struct block_list *bl = map_id2bl(st->oid);
- if (bl)
- clif_misceffect2(bl,type);
- } else{
- TBL_PC *sd=script_rid2sd(st);
- if(sd)
- clif_misceffect2(&sd->bl,type);
- }
- return 0;
- }
- /*==========================================
- * Play a BGM on a single client [Rikter/Yommy]
- *------------------------------------------*/
- BUILDIN_FUNC(playBGM)
- {
- TBL_PC* sd = script_rid2sd(st);
- const char* name = script_getstr(st,2);
- if(sd)
- {
- if(!st->rid)
- clif_playBGM(sd,map_id2bl(st->oid),name);
- else
- clif_playBGM(sd,&sd->bl,name);
- }
- return 0;
- }
- int playBGM_sub(struct block_list* bl,va_list ap)
- {
- char* name = va_arg(ap,char*);
- clif_playBGM((TBL_PC *)bl, bl, name);
- return 0;
- }
- /*==========================================
- * Play a BGM on multiple client [Rikter/Yommy]
- *------------------------------------------*/
- BUILDIN_FUNC(playBGMall)
- {
- struct block_list* bl;
- const char* name;
- bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid);
- if (!bl)
- return 0;
- name = script_getstr(st,2);
- if(script_hasdata(st,7))
- { // specified part of map
- const char* map = script_getstr(st,3);
- int x0 = script_getnum(st,4);
- int y0 = script_getnum(st,5);
- int x1 = script_getnum(st,6);
- int y1 = script_getnum(st,7);
- map_foreachinarea(playBGM_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name);
- }
- else
- if(!script_hasdata(st,7))
- { // entire map
- const char* map = script_getstr(st,3);
- map_foreachinmap(playBGM_sub, map_mapname2mapid(map), BL_PC, name);
- }
- else
- {
- ShowError("buildin_playBGMall: insufficient arguments for specific area broadcast.\n");
- }
- return 0;
- }
- /*==========================================
- * サウンドエフェクト
- *------------------------------------------*/
- BUILDIN_FUNC(soundeffect)
- {
- TBL_PC* sd = script_rid2sd(st);
- const char* name = script_getstr(st,2);
- int type = script_getnum(st,3);
- if(sd)
- {
- if(!st->rid)
- clif_soundeffect(sd,map_id2bl(st->oid),name,type);
- else
- clif_soundeffect(sd,&sd->bl,name,type);
- }
- return 0;
- }
- int soundeffect_sub(struct block_list* bl,va_list ap)
- {
- char* name = va_arg(ap,char*);
- int type = va_arg(ap,int);
- clif_soundeffect((TBL_PC *)bl, bl, name, type);
- return 0;
- }
- /*==========================================
- * Play a sound effect (.wav) on multiple clients
- * soundeffectall "<filepath>",<type>{,"<map name>"}{,<x0>,<y0>,<x1>,<y1>};
- *------------------------------------------*/
- BUILDIN_FUNC(soundeffectall)
- {
- struct block_list* bl;
- const char* name;
- int type;
- bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid);
- if (!bl)
- return 0;
- name = script_getstr(st,2);
- type = script_getnum(st,3);
- //FIXME: enumerating map squares (map_foreach) is slower than enumerating the list of online players (map_foreachpc?) [ultramage]
- if(!script_hasdata(st,4))
- { // area around
- clif_soundeffectall(bl, name, type, AREA);
- }
- else
- if(!script_hasdata(st,5))
- { // entire map
- const char* map = script_getstr(st,4);
- map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type);
- }
- else
- if(script_hasdata(st,8))
- { // specified part of map
- const char* map = script_getstr(st,4);
- int x0 = script_getnum(st,5);
- int y0 = script_getnum(st,6);
- int x1 = script_getnum(st,7);
- int y1 = script_getnum(st,8);
- map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type);
- }
- else
- {
- ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
- }
- return 0;
- }
- /*==========================================
- * pet status recovery [Valaris] / Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petrecovery)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
-
- if (pd->recovery)
- { //Halt previous bonus
- if (pd->recovery->timer != -1)
- delete_timer(pd->recovery->timer, pet_recovery_timer);
- } else //Init
- pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
-
- pd->recovery->type = (sc_type)script_getnum(st,2);
- pd->recovery->delay = script_getnum(st,3);
- pd->recovery->timer = INVALID_TIMER;
- return 0;
- }
- /*==========================================
- * pet healing [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petheal)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->s_skill)
- { //Clear previous skill
- if (pd->s_skill->timer != -1)
- {
- if (pd->s_skill->id)
- delete_timer(pd->s_skill->timer, pet_skill_support_timer);
- else
- delete_timer(pd->s_skill->timer, pet_heal_timer);
- }
- } else //init memory
- pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
-
- pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
- //Use the lv as the amount to heal
- pd->s_skill->lv=script_getnum(st,2);
- pd->s_skill->delay=script_getnum(st,3);
- pd->s_skill->hp=script_getnum(st,4);
- pd->s_skill->sp=script_getnum(st,5);
- //Use delay as initial offset to avoid skill/heal exploits
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->s_skill->timer = INVALID_TIMER;
- else
- pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
- return 0;
- }
- /*==========================================
- * pet attack skills [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- /// petskillattack <skill id>,<level>,<rate>,<bonusrate>
- /// petskillattack "<skill name>",<level>,<rate>,<bonusrate>
- BUILDIN_FUNC(petskillattack)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->a_skill == NULL)
- pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
-
- pd->a_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->a_skill->lv=script_getnum(st,3);
- pd->a_skill->div_ = 0;
- pd->a_skill->rate=script_getnum(st,4);
- pd->a_skill->bonusrate=script_getnum(st,5);
- return 0;
- }
- /*==========================================
- * pet attack skills [Valaris]
- *------------------------------------------*/
- /// petskillattack2 <skill id>,<level>,<div>,<rate>,<bonusrate>
- /// petskillattack2 "<skill name>",<level>,<div>,<rate>,<bonusrate>
- BUILDIN_FUNC(petskillattack2)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->a_skill == NULL)
- pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
-
- pd->a_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->a_skill->lv=script_getnum(st,3);
- pd->a_skill->div_ = script_getnum(st,4);
- pd->a_skill->rate=script_getnum(st,5);
- pd->a_skill->bonusrate=script_getnum(st,6);
- return 0;
- }
- /*==========================================
- * pet support skills [Skotlex]
- *------------------------------------------*/
- /// petskillsupport <skill id>,<level>,<delay>,<hp>,<sp>
- /// petskillsupport "<skill name>",<level>,<delay>,<hp>,<sp>
- BUILDIN_FUNC(petskillsupport)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->s_skill)
- { //Clear previous skill
- if (pd->s_skill->timer != -1)
- {
- if (pd->s_skill->id)
- delete_timer(pd->s_skill->timer, pet_skill_support_timer);
- else
- delete_timer(pd->s_skill->timer, pet_heal_timer);
- }
- } else //init memory
- pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
-
- pd->s_skill->id=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->s_skill->lv=script_getnum(st,3);
- pd->s_skill->delay=script_getnum(st,4);
- pd->s_skill->hp=script_getnum(st,5);
- pd->s_skill->sp=script_getnum(st,6);
- //Use delay as initial offset to avoid skill/heal exploits
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->s_skill->timer = INVALID_TIMER;
- else
- pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
- return 0;
- }
- /*==========================================
- * Scripted skill effects [Celest]
- *------------------------------------------*/
- /// skilleffect <skill id>,<level>
- /// skilleffect "<skill name>",<level>
- BUILDIN_FUNC(skilleffect)
- {
- TBL_PC *sd;
- int skillid=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- int skilllv=script_getnum(st,3);
- sd=script_rid2sd(st);
- clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
- return 0;
- }
- /*==========================================
- * NPC skill effects [Valaris]
- *------------------------------------------*/
- /// npcskilleffect <skill id>,<level>,<x>,<y>
- /// npcskilleffect "<skill name>",<level>,<x>,<y>
- BUILDIN_FUNC(npcskilleffect)
- {
- struct block_list *bl= map_id2bl(st->oid);
- int skillid=( script_isstring(st,2) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- int skilllv=script_getnum(st,3);
- int x=script_getnum(st,4);
- int y=script_getnum(st,5);
- if (bl)
- clif_skill_poseffect(bl,skillid,skilllv,x,y,gettick());
- return 0;
- }
- /*==========================================
- * Special effects [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(specialeffect)
- {
- struct block_list *bl=map_id2bl(st->oid);
- int type = script_getnum(st,2);
- enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
- if(bl==NULL)
- return 0;
- if( script_hasdata(st,4) )
- {
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
- if(nd)
- clif_specialeffect(&nd->bl, type, target);
- }
- else
- clif_specialeffect(bl, type, target);
- return 0;
- }
- BUILDIN_FUNC(specialeffect2)
- {
- TBL_PC *sd=script_rid2sd(st);
- int type = script_getnum(st,2);
- enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
- if( script_hasdata(st,4) )
- sd = map_nick2sd(script_getstr(st,4));
- if (sd)
- clif_specialeffect(&sd->bl, type, target);
- return 0;
- }
- /*==========================================
- * Nude [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(nude)
- {
- TBL_PC *sd=script_rid2sd(st);
- int i,calcflag=0;
- if(sd==NULL)
- return 0;
- for(i=0;i<11;i++)
- if(sd->equip_index[i] >= 0) {
- if(!calcflag)
- calcflag=1;
- pc_unequipitem(sd,sd->equip_index[i],2);
- }
- if(calcflag)
- status_calc_pc(sd,0);
- return 0;
- }
- /*==========================================
- * gmcommand [MouseJstr]
- *
- * suggested on the forums...
- * splitted into atcommand & charcommand by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(atcommand)
- {
- TBL_PC dummy_sd;
- TBL_PC* sd;
- int fd;
- const char* cmd;
- cmd = script_getstr(st,2);
- if (st->rid) {
- sd = script_rid2sd(st);
- fd = sd->fd;
- } else { //Use a dummy character.
- sd = &dummy_sd;
- fd = 0;
- memset(&dummy_sd, 0, sizeof(TBL_PC));
- if (st->oid)
- {
- struct block_list* bl = map_id2bl(st->oid);
- memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
- if (bl->type == BL_NPC)
- safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
- }
- }
- // compatibility with previous implementation (deprecated!)
- if(cmd[0] != atcommand_symbol)
- {
- cmd += strlen(sd->status.name);
- while(*cmd != atcommand_symbol && *cmd != 0)
- cmd++;
- }
- is_atcommand(fd, sd, cmd, 0);
- return 0;
- }
- BUILDIN_FUNC(charcommand)
- {
- TBL_PC dummy_sd;
- TBL_PC* sd;
- int fd;
- const char* cmd;
- cmd = script_getstr(st,2);
- if (st->rid) {
- sd = script_rid2sd(st);
- fd = sd->fd;
- } else { //Use a dummy character.
- sd = &dummy_sd;
- fd = 0;
- memset(&dummy_sd, 0, sizeof(TBL_PC));
- if (st->oid)
- {
- struct block_list* bl = map_id2bl(st->oid);
- memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
- if (bl->type == BL_NPC)
- safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
- }
- }
- if (*cmd != charcommand_symbol) {
- ShowWarning("script: buildin_charcommand: No '#' symbol!\n");
- script_reportsrc(st);
- return 1;
- }
-
- is_atcommand(fd, sd, cmd, 0);
- return 0;
- }
- /*==========================================
- * Displays a message for the player only (like system messages like "you got an apple" )
- *------------------------------------------*/
- BUILDIN_FUNC(dispbottom)
- {
- TBL_PC *sd=script_rid2sd(st);
- const char *message;
- message=script_getstr(st,2);
- if(sd)
- clif_disp_onlyself(sd,message,(int)strlen(message));
- return 0;
- }
- /*==========================================
- * All The Players Full Recovery
- * (HP/SP full restore and resurrect if need)
- *------------------------------------------*/
- BUILDIN_FUNC(recovery)
- {
- TBL_PC* sd;
- struct s_mapiterator* iter;
- iter = mapit_getallusers();
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
- {
- if(pc_isdead(sd))
- status_revive(&sd->bl, 100, 100);
- else
- status_percent_heal(&sd->bl, 100, 100);
- clif_displaymessage(sd->fd,"You have been recovered!");
- }
- mapit_free(iter);
- return 0;
- }
- /*==========================================
- * Get your pet info: getpetinfo(n)
- * n -> 0:pet_id 1:pet_class 2:pet_name
- * 3:friendly 4:hungry, 5: rename flag.
- *------------------------------------------*/
- BUILDIN_FUNC(getpetinfo)
- {
- TBL_PC *sd=script_rid2sd(st);
- TBL_PET *pd;
- int type=script_getnum(st,2);
-
- if(!sd || !sd->pd) {
- if (type == 2)
- script_pushconststr(st,"null");
- else
- script_pushint(st,0);
- return 0;
- }
- pd = sd->pd;
- switch(type){
- case 0: script_pushint(st,pd->pet.pet_id); break;
- case 1: script_pushint(st,pd->pet.class_); break;
- case 2: script_pushstrcopy(st,pd->pet.name); break;
- case 3: script_pushint(st,pd->pet.intimate); break;
- case 4: script_pushint(st,pd->pet.hungry); break;
- case 5: script_pushint(st,pd->pet.rename_flag); break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- /*==========================================
- * Get your homunculus info: gethominfo(n)
- * n -> 0:hom_id 1:class 2:name
- * 3:friendly 4:hungry, 5: rename flag.
- * 6: level
- *------------------------------------------*/
- BUILDIN_FUNC(gethominfo)
- {
- TBL_PC *sd=script_rid2sd(st);
- TBL_HOM *hd;
- int type=script_getnum(st,2);
- hd = sd?sd->hd:NULL;
- if(!merc_is_hom_active(hd))
- {
- if (type == 2)
- script_pushconststr(st,"null");
- else
- script_pushint(st,0);
- return 0;
- }
- switch(type){
- case 0: script_pushint(st,hd->homunculus.hom_id); break;
- case 1: script_pushint(st,hd->homunculus.class_); break;
- case 2: script_pushstrcopy(st,hd->homunculus.name); break;
- case 3: script_pushint(st,hd->homunculus.intimacy); break;
- case 4: script_pushint(st,hd->homunculus.hunger); break;
- case 5: script_pushint(st,hd->homunculus.rename_flag); break;
- case 6: script_pushint(st,hd->homunculus.level); break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- /*==========================================
- * Shows wether your inventory(and equips) contain
- selected card or not.
- checkequipedcard(4001);
- *------------------------------------------*/
- BUILDIN_FUNC(checkequipedcard)
- {
- TBL_PC *sd=script_rid2sd(st);
- int n,i,c=0;
- c=script_getnum(st,2);
- if(sd){
- for(i=0;i<MAX_INVENTORY;i++){
- if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount && sd->inventory_data[i]){
- if (itemdb_isspecial(sd->status.inventory[i].card[0]))
- continue;
- for(n=0;n<sd->inventory_data[i]->slot;n++){
- if(sd->status.inventory[i].card[n]==c){
- script_pushint(st,1);
- return 0;
- }
- }
- }
- }
- }
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(jump_zero)
- {
- int sel;
- sel=script_getnum(st,2);
- if(!sel) {
- int pos;
- if( !data_islabel(script_getdata(st,3)) ){
- ShowError("script: jump_zero: not label !\n");
- st->state=END;
- return 1;
- }
- pos=script_getnum(st,3);
- st->pos=pos;
- st->state=GOTO;
- // printf("script: jump_zero: jumpto : %d\n",pos);
- } else {
- // printf("script: jump_zero: fail\n");
- }
- return 0;
- }
- /*==========================================
- * GetMapMobs
- returns mob counts on a set map:
- e.g. GetMapMobs("prontera")
- use "this" - for player's map
- *------------------------------------------*/
- BUILDIN_FUNC(getmapmobs)
- {
- const char *str=NULL;
- int m=-1,bx,by;
- int count=0;
- struct block_list *bl;
- str=script_getstr(st,2);
- if(strcmp(str,"this")==0){
- TBL_PC *sd=script_rid2sd(st);
- if(sd)
- m=sd->bl.m;
- else{
- script_pushint(st,-1);
- return 0;
- }
- }else
- m=map_mapname2mapid(str);
- if(m < 0){
- script_pushint(st,-1);
- return 0;
- }
- for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++)
- for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++)
- for( bl = map[m].block_mob[bx+by*map[m].bxs] ; bl != NULL ; bl = bl->next )
- if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
- count++;
- script_pushint(st,count);
- return 0;
- }
- /*==========================================
- * movenpc [MouseJstr]
- *------------------------------------------*/
- BUILDIN_FUNC(movenpc)
- {
- TBL_NPC *nd = NULL;
- const char *npc;
- int x,y;
- npc = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if ((nd = npc_name2id(npc)) == NULL)
- return -1;
- npc_movenpc(nd, x, y);
- return 0;
- }
- /*==========================================
- * message [MouseJstr]
- *------------------------------------------*/
- BUILDIN_FUNC(message)
- {
- const char *msg,*player;
- TBL_PC *pl_sd = NULL;
- player = script_getstr(st,2);
- msg = script_getstr(st,3);
- if((pl_sd=map_nick2sd((char *) player)) == NULL)
- return 0;
- clif_displaymessage(pl_sd->fd, msg);
- return 0;
- }
- /*==========================================
- * npctalk (sends message to surrounding area)
- *------------------------------------------*/
- BUILDIN_FUNC(npctalk)
- {
- const char* str;
- char message[255];
- struct npc_data* nd = (struct npc_data *)map_id2bl(st->oid);
- str = script_getstr(st,2);
- if(nd) {
- memcpy(message, nd->name, NAME_LENGTH);
- strtok(message, "#"); // discard extra name identifier if present
- strcat(message, " : ");
- strncat(message, str, 254); //Prevent overflow possibility. [Skotlex]
- clif_message(&(nd->bl), message);
- }
- return 0;
- }
- // change npc walkspeed [Valaris]
- BUILDIN_FUNC(npcspeed)
- {
- struct npc_data* nd;
- int speed;
- speed = script_getnum(st,2);
- nd =(struct npc_data *)map_id2bl(st->oid);
- if( nd )
- {
- nd->speed = speed;
- nd->ud.state.speed_changed = 1;
- }
- return 0;
- }
- // make an npc walk to a position [Valaris]
- BUILDIN_FUNC(npcwalkto)
- {
- struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
- int x=0,y=0;
- x=script_getnum(st,2);
- y=script_getnum(st,3);
- if(nd) {
- unit_walktoxy(&nd->bl,x,y,0);
- }
- return 0;
- }
- // stop an npc's movement [Valaris]
- BUILDIN_FUNC(npcstop)
- {
- struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
- if(nd) {
- unit_stop_walking(&nd->bl,1|4);
- }
- return 0;
- }
- /*==========================================
- * getlook char info. getlook(arg)
- *------------------------------------------*/
- BUILDIN_FUNC(getlook)
- {
- int type,val;
- TBL_PC *sd;
- sd=script_rid2sd(st);
- type=script_getnum(st,2);
- val=-1;
- switch(type) {
- case LOOK_HAIR: val=sd->status.hair; break; //1
- case LOOK_WEAPON: val=sd->status.weapon; break; //2
- case LOOK_HEAD_BOTTOM: val=sd->status.head_bottom; break; //3
- case LOOK_HEAD_TOP: val=sd->status.head_top; break; //4
- case LOOK_HEAD_MID: val=sd->status.head_mid; break; //5
- case LOOK_HAIR_COLOR: val=sd->status.hair_color; break; //6
- case LOOK_CLOTHES_COLOR: val=sd->status.clothes_color; break; //7
- case LOOK_SHIELD: val=sd->status.shield; break; //8
- case LOOK_SHOES: break; //9
- }
- script_pushint(st,val);
- return 0;
- }
- /*==========================================
- * get char save point. argument: 0- map name, 1- x, 2- y
- *------------------------------------------*/
- BUILDIN_FUNC(getsavepoint)
- {
- TBL_PC* sd;
- int type;
- sd = script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- type = script_getnum(st,2);
- switch(type) {
- case 0: script_pushstrcopy(st,mapindex_id2name(sd->status.save_point.map)); break;
- case 1: script_pushint(st,sd->status.save_point.x); break;
- case 2: script_pushint(st,sd->status.save_point.y); break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- /*==========================================
- * Get position for char/npc/pet/mob objects. Added by Lorky
- *
- * int getMapXY(MapName$,MapX,MapY,type,[CharName$]);
- * where type:
- * MapName$ - String variable for output map name
- * MapX - Integer variable for output coord X
- * MapY - Integer variable for output coord Y
- * type - type of object
- * 0 - Character coord
- * 1 - NPC coord
- * 2 - Pet coord
- * 3 - Mob coord (not released)
- * 4 - Homun coord
- * CharName$ - Name object. If miss or "this" the current object
- *
- * Return:
- * 0 - success
- * -1 - some error, MapName$,MapX,MapY contains unknown value.
- *------------------------------------------*/
- BUILDIN_FUNC(getmapxy)
- {
- struct block_list *bl = NULL;
- TBL_PC *sd=NULL;
- int num;
- const char *name;
- char prefix;
- int x,y,type;
- char mapname[MAP_NAME_LENGTH];
- if( !data_isreference(script_getdata(st,2)) ){
- ShowWarning("script: buildin_getmapxy: not mapname variable\n");
- script_pushint(st,-1);
- return 1;
- }
- if( !data_isreference(script_getdata(st,3)) ){
- ShowWarning("script: buildin_getmapxy: not mapx variable\n");
- script_pushint(st,-1);
- return 1;
- }
- if( !data_isreference(script_getdata(st,4)) ){
- ShowWarning("script: buildin_getmapxy: not mapy variable\n");
- script_pushint(st,-1);
- return 1;
- }
- // Possible needly check function parameters on C_STR,C_INT,C_INT
- type=script_getnum(st,5);
- switch (type){
- case 0: //Get Character Position
- if( script_hasdata(st,6) )
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd)
- bl = &sd->bl;
- break;
- case 1: //Get NPC Position
- if( script_hasdata(st,6) )
- {
- struct npc_data *nd;
- nd=npc_name2id(script_getstr(st,6));
- if (nd)
- bl = &nd->bl;
- } else //In case the origin is not an npc?
- bl=map_id2bl(st->oid);
- break;
- case 2: //Get Pet Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->pd)
- bl = &sd->pd->bl;
- break;
- case 3: //Get Mob Position
- break; //Not supported?
- case 4: //Get Homun Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->hd)
- bl = &sd->hd->bl;
- break;
- default:
- ShowWarning("script: buildin_getmapxy: Invalid type %d\n", type);
- script_pushint(st,-1);
- return 1;
- }
- if (!bl) { //No object found.
- script_pushint(st,-1);
- return 0;
- }
- x= bl->x;
- y= bl->y;
- safestrncpy(mapname, map[bl->m].name, MAP_NAME_LENGTH);
-
- //Set MapName$
- num=st->stack->stack_data[st->start+2].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2));
- //Set MapX
- num=st->stack->stack_data[st->start+3].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)x,script_getref(st,3));
- //Set MapY
- num=st->stack->stack_data[st->start+4].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)y,script_getref(st,4));
- //Return Success value
- script_pushint(st,0);
- return 0;
- }
- /*==========================================
- * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
- *------------------------------------------*/
- BUILDIN_FUNC(logmes)
- {
- const char *str;
- TBL_PC* sd;
- if( log_config.npc <= 0 )
- return 0;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 1;
- str = script_getstr(st,2);
- log_npc(sd,str);
- return 0;
- }
- BUILDIN_FUNC(summon)
- {
- int _class, timeout=0;
- const char *str,*event="";
- TBL_PC *sd;
- struct mob_data *md;
- int tick = gettick();
- sd=script_rid2sd(st);
- if (!sd) return 0;
-
- str =script_getstr(st,2);
- _class=script_getnum(st,3);
- if( script_hasdata(st,4) )
- timeout=script_getnum(st,4);
- if( script_hasdata(st,5) ){
- event=script_getstr(st,5);
- check_event(st, event);
- }
- clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
- md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event);
- if (md) {
- md->master_id=sd->bl.id;
- md->special_state.ai=1;
- if( md->deletetimer != INVALID_TIMER )
- delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0);
- mob_spawn (md); //Now it is ready for spawning.
- clif_misceffect2(&md->bl,344);
- sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
- }
- return 0;
- }
- /*==========================================
- * Checks whether it is daytime/nighttime
- *------------------------------------------*/
- BUILDIN_FUNC(isnight)
- {
- script_pushint(st,(night_flag == 1));
- return 0;
- }
- BUILDIN_FUNC(isday)
- {
- script_pushint(st,(night_flag == 0));
- return 0;
- }
- /*================================================
- * Check whether another item/card has been
- * equipped - used for 2/15's cards patch [celest]
- *------------------------------------------------*/
- // leave this here, just in case
- #if 0
- BUILDIN_FUNC(isequipped)
- {
- TBL_PC *sd;
- int i, j, k, id = 1;
- int ret = -1;
- sd = script_rid2sd(st);
-
- for (i=0; id!=0; i++) {
- int flag = 0;
-
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
-
- for (j=0; j<EQI_MAX; j++) {
- int index;
- index = sd->equip_index[j];
- if(index < 0) continue;
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
-
- if(!sd->inventory_data[index])
- continue;
- if(itemdb_type(id) != IT_CARD) { //Non card
- if (sd->inventory_data[index]->nameid != id)
- continue;
- flag = 1;
- break;
- } else { //Card
- if (itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue;
- for(k=0; k<sd->inventory_data[index]->slot; k++) {
- if (sd->status.inventory[index].card[k] == id)
- {
- flag = 1;
- break;
- }
- }
- }
- if (flag) break;
- }
- if (ret == -1)
- ret = flag;
- else
- ret &= flag;
- if (!ret) break;
- }
-
- script_pushint(st,ret);
- return 0;
- }
- #endif
- /*================================================
- * Check how many items/cards in the list are
- * equipped - used for 2/15's cards patch [celest]
- *------------------------------------------------*/
- BUILDIN_FUNC(isequippedcnt)
- {
- TBL_PC *sd;
- int i, j, k, id = 1;
- int ret = 0;
- sd = script_rid2sd(st);
- if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
- script_pushint(st,0);
- return 0;
- }
-
- for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
-
- for (j=0; j<EQI_MAX; j++) {
- int index;
- index = sd->equip_index[j];
- if(index < 0) continue;
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
-
- if(!sd->inventory_data[index])
- continue;
- if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
- if (sd->inventory_data[index]->nameid == id)
- ret+= sd->status.inventory[index].amount;
- } else { //Count cards.
- if (itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue; //No cards
- for(k=0; k<sd->inventory_data[index]->slot; k++) {
- if (sd->status.inventory[index].card[k] == id)
- ret++; //[Lupus]
- }
- }
- }
- }
-
- script_pushint(st,ret);
- return 0;
- }
- /*================================================
- * Check whether another card has been
- * equipped - used for 2/15's cards patch [celest]
- * -- Items checked cannot be reused in another
- * card set to prevent exploits
- *------------------------------------------------*/
- BUILDIN_FUNC(isequipped)
- {
- TBL_PC *sd;
- int i, j, k, id = 1;
- int index, flag;
- int ret = -1;
- //Original hash to reverse it when full check fails.
- unsigned int setitem_hash = 0, setitem_hash2 = 0;
- sd = script_rid2sd(st);
-
- if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
- script_pushint(st,0);
- return 0;
- }
- setitem_hash = sd->setitem_hash;
- setitem_hash2 = sd->setitem_hash2;
- for (i=0; id!=0; i++)
- {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
- flag = 0;
- for (j=0; j<EQI_MAX; j++)
- {
- index = sd->equip_index[j];
- if(index < 0) continue;
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
-
- if(!sd->inventory_data[index])
- continue;
-
- if (itemdb_type(id) != IT_CARD) {
- if (sd->inventory_data[index]->nameid != id)
- continue;
- flag = 1;
- break;
- } else { //Cards
- if (sd->inventory_data[index]->slot == 0 ||
- itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue;
- for (k = 0; k < sd->inventory_data[index]->slot; k++)
- { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
- unsigned int hash = 0;
- if (sd->status.inventory[index].card[k] != id)
- continue;
- hash = 1<<((j<5?j:j-5)*4 + k);
- // check if card is already used by another set
- if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
- continue;
- // We have found a match
- flag = 1;
- // Set hash so this card cannot be used by another
- if (j<5)
- sd->setitem_hash |= hash;
- else
- sd->setitem_hash2 |= hash;
- break;
- }
- }
- if (flag) break; //Card found
- }
- if (ret == -1)
- ret = flag;
- else
- ret &= flag;
- if (!ret) break;
- }
- if (!ret)
- { //When check fails, restore original hash values. [Skotlex]
- sd->setitem_hash = setitem_hash;
- sd->setitem_hash2 = setitem_hash2;
- }
- script_pushint(st,ret);
- return 0;
- }
- /*================================================
- * Check how many given inserted cards in the CURRENT
- * weapon - used for 2/15's cards patch [Lupus]
- *------------------------------------------------*/
- BUILDIN_FUNC(cardscnt)
- {
- TBL_PC *sd;
- int i, k, id = 1;
- int ret = 0;
- int index;
- sd = script_rid2sd(st);
-
- for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
-
- index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
- if(index < 0) continue;
-
- if(!sd->inventory_data[index])
- continue;
- if(itemdb_type(id) != IT_CARD) {
- if (sd->inventory_data[index]->nameid == id)
- ret+= sd->status.inventory[index].amount;
- } else {
- if (itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue;
- for(k=0; k<sd->inventory_data[index]->slot; k++) {
- if (sd->status.inventory[index].card[k] == id)
- ret++;
- }
- }
- }
- script_pushint(st,ret);
- // script_pushint(st,current_equip_item_index);
- return 0;
- }
- /*=======================================================
- * Returns the refined number of the current item, or an
- * item with inventory index specified
- *-------------------------------------------------------*/
- BUILDIN_FUNC(getrefine)
- {
- TBL_PC *sd;
- if ((sd = script_rid2sd(st))!= NULL)
- script_pushint(st,sd->status.inventory[current_equip_item_index].refine);
- else
- script_pushint(st,0);
- return 0;
- }
- /*=======================================================
- * Day/Night controls
- *-------------------------------------------------------*/
- BUILDIN_FUNC(night)
- {
- if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
- return 0;
- }
- BUILDIN_FUNC(day)
- {
- if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
- return 0;
- }
- //=======================================================
- // Unequip [Spectre]
- //-------------------------------------------------------
- BUILDIN_FUNC(unequip)
- {
- int i;
- size_t num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(equip) )
- {
- i = pc_checkequip(sd,equip[num-1]);
- if (i >= 0)
- pc_unequipitem(sd,i,1|2);
- }
- return 0;
- }
- BUILDIN_FUNC(equip)
- {
- int nameid=0,i;
- TBL_PC *sd;
- struct item_data *item_data;
- sd = script_rid2sd(st);
- nameid=script_getnum(st,2);
- if((item_data = itemdb_exists(nameid)) == NULL)
- {
- ShowError("wrong item ID : equipitem(%i)\n",nameid);
- return 1;
- }
- ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid );
- if( i < MAX_INVENTORY )
- pc_equipitem(sd,i,item_data->equip);
- return 0;
- }
- BUILDIN_FUNC(autoequip)
- {
- int nameid, flag;
- struct item_data *item_data;
- nameid=script_getnum(st,2);
- flag=script_getnum(st,3);
- if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
- item_data->flag.autoequip = flag>0?1:0;
- }
- return 0;
- }
- BUILDIN_FUNC(setbattleflag)
- {
- const char *flag, *value;
- flag = script_getstr(st,2);
- value = script_getstr(st,3);
-
- if (battle_set_value(flag, value) == 0)
- ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag);
- else
- ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value);
- return 0;
- }
- BUILDIN_FUNC(getbattleflag)
- {
- const char *flag;
- flag = script_getstr(st,2);
- script_pushint(st,battle_get_value(flag));
- return 0;
- }
- //=======================================================
- // strlen [Valaris]
- //-------------------------------------------------------
- BUILDIN_FUNC(getstrlen)
- {
- const char *str = script_getstr(st,2);
- int len = (str) ? (int)strlen(str) : 0;
- script_pushint(st,len);
- return 0;
- }
- //=======================================================
- // isalpha [Valaris]
- //-------------------------------------------------------
- BUILDIN_FUNC(charisalpha)
- {
- const char *str=script_getstr(st,2);
- int pos=script_getnum(st,3);
- int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISALPHA( str[pos] ) : 0;
- script_pushint(st,val);
- return 0;
- }
- /// Changes the display name and/or display class of the npc.
- /// Returns 0 is successful, 1 if the npc does not exist.
- ///
- /// setnpcdisplay("<npc name>", "<new display name>", <new class id>, <new size>) -> <int>
- /// setnpcdisplay("<npc name>", "<new display name>", <new class id>) -> <int>
- /// setnpcdisplay("<npc name>", "<new display name>") -> <int>
- /// setnpcdisplay("<npc name>", <new class id>) -> <int>
- BUILDIN_FUNC(setnpcdisplay)
- {
- const char* name;
- const char* newname = NULL;
- int class_ = -1, size = -1;
- struct script_data* data;
- struct npc_data* nd;
- name = script_getstr(st,2);
- data = script_getdata(st,3);
- if( script_hasdata(st,4) )
- class_ = script_getnum(st,4);
- if( script_hasdata(st,5) )
- size = script_getnum(st,5);
- get_val(st, data);
- if( data_isstring(data) )
- newname = conv_str(st,data);
- else if( data_isint(data) )
- class_ = conv_num(st,data);
- else
- {
- ShowError("script:setnpcdisplay: expected a string or number\n");
- script_reportdata(data);
- return 1;
- }
- nd = npc_name2id(name);
- if( nd == NULL )
- {// not found
- script_pushint(st,1);
- return 0;
- }
- // update npc
- if( newname )
- npc_setdisplayname(nd, newname);
- if( size != -1 && size != nd->size )
- nd->size = size;
- else
- size = -1;
- if( class_ != -1 && nd->class_ != class_ )
- npc_setclass(nd, class_);
- else if( size != -1 )
- { // Required to update the visual size
- clif_clearunit_area(&nd->bl, 0);
- clif_spawn(&nd->bl);
- }
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(atoi)
- {
- const char *value;
- value = script_getstr(st,2);
- script_pushint(st,atoi(value));
- return 0;
- }
- // case-insensitive substring search [lordalfa]
- BUILDIN_FUNC(compare)
- {
- const char *message;
- const char *cmpstring;
- message = script_getstr(st,2);
- cmpstring = script_getstr(st,3);
- script_pushint(st,(stristr(message,cmpstring) != NULL));
- return 0;
- }
- // [zBuffer] List of mathematics commands --->
- BUILDIN_FUNC(sqrt)
- {
- double i, a;
- i = script_getnum(st,2);
- a = sqrt(i);
- script_pushint(st,(int)a);
- return 0;
- }
- BUILDIN_FUNC(pow)
- {
- double i, a, b;
- a = script_getnum(st,2);
- b = script_getnum(st,3);
- i = pow(a,b);
- script_pushint(st,(int)i);
- return 0;
- }
- BUILDIN_FUNC(distance)
- {
- int x0, y0, x1, y1;
- x0 = script_getnum(st,2);
- y0 = script_getnum(st,3);
- x1 = script_getnum(st,4);
- y1 = script_getnum(st,5);
- script_pushint(st,distance_xy(x0,y0,x1,y1));
- return 0;
- }
- // <--- [zBuffer] List of mathematics commands
- BUILDIN_FUNC(md5)
- {
- const char *tmpstr;
- char *md5str;
- tmpstr = script_getstr(st,2);
- md5str = (char *)aMallocA((32+1)*sizeof(char));
- MD5_String(tmpstr, md5str);
- script_pushstr(st, md5str);
- return 0;
- }
- // [zBuffer] List of dynamic var commands --->
- BUILDIN_FUNC(setd)
- {
- TBL_PC *sd=NULL;
- char varname[100];
- const char *value, *buffer;
- int elem;
- buffer = script_getstr(st, 2);
- value = script_getstr(st, 3);
- if(sscanf(buffer, "%99[^[][%d]", varname, &elem) < 2)
- elem = 0;
- if( not_server_variable(*varname) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {
- ShowError("script:setd: no player attached for player variable '%s'\n", buffer);
- return 0;
- }
- }
- if(varname[strlen(varname)-1] != '$') {
- setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
- } else {
- setd_sub(st,sd, varname, elem, (void *)value,NULL);
- }
-
- return 0;
- }
- #ifndef TXT_ONLY
- int buildin_query_sql_sub(struct script_state* st, Sql* handle)
- {
- int i, j;
- TBL_PC* sd = NULL;
- const char* query;
- struct script_data* data;
- const char* name;
- int max_rows = 128;// maximum number of rows
- int num_vars;
- int num_cols;
- // check target variables
- for( i = 3; script_hasdata(st,i); ++i )
- {
- data = script_getdata(st, i);
- if( data_isreference(data) && reference_tovariable(data) )
- {// it's a variable
- name = reference_getname(data);
- if( not_server_variable(*name) && sd == NULL )
- {// requires a player
- sd = script_rid2sd(st);
- if( sd == NULL )
- {// no player attached
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- }
- if( not_array_variable(*name) )
- max_rows = 1;// not an array, limit to one row
- }
- else
- {
- ShowError("script:query_sql: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- }
- num_vars = i - 3;
- // Execute the query
- query = script_getstr(st,2);
- if( SQL_ERROR == Sql_QueryStr(handle, query) )
- {
- Sql_ShowDebug(handle);
- script_pushint(st, 0);
- return 1;
- }
- if( Sql_NumRows(handle) == 0 )
- {// No data received
- Sql_FreeResult(handle);
- script_pushint(st, 0);
- return 0;
- }
- // Count the number of columns to store
- num_cols = Sql_NumColumns(handle);
- if( num_vars < num_cols )
- {
- ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars));
- script_reportsrc(st);
- }
- else if( num_vars > num_cols )
- {
- ShowWarning("script:query_sql: Too many variables (%u extra).\n", (unsigned int)(num_vars-num_cols));
- script_reportsrc(st);
- }
- // Store data
- for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i )
- {
- for( j = 0; j < num_vars; ++j )
- {
- char* str = NULL;
- if( j < num_cols )
- Sql_GetData(handle, j, &str, NULL);
- data = script_getdata(st, j+3);
- name = reference_getname(data);
- if( is_string_variable(name) )
- setd_sub(st, sd, name, i, (void *)(str?str:""), reference_getref(data));
- else
- setd_sub(st, sd, name, i, (void *)(str?atoi(str):0), reference_getref(data));
- }
- }
- if( i == max_rows && max_rows < Sql_NumRows(handle) )
- {
- ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle));
- script_reportsrc(st);
- }
- // Free data
- Sql_FreeResult(handle);
- script_pushint(st, i);
- return 0;
- }
- #endif
- BUILDIN_FUNC(query_sql)
- {
- #ifndef TXT_ONLY
- return buildin_query_sql_sub(st, mmysql_handle);
- #else
- //for TXT version, we always return -1
- script_pushint(st,-1);
- return 0;
- #endif
- }
- BUILDIN_FUNC(query_logsql)
- {
- #ifndef TXT_ONLY
- return buildin_query_sql_sub(st, logmysql_handle);
- #else
- //for TXT version, we always return -1
- script_pushint(st,-1);
- return 0;
- #endif
- }
- //Allows escaping of a given string.
- BUILDIN_FUNC(escape_sql)
- {
- const char *str;
- char *esc_str;
- size_t len;
- str = script_getstr(st,2);
- len = strlen(str);
- esc_str = (char*)aMallocA(len*2+1);
- #if defined(TXT_ONLY)
- jstrescapecpy(esc_str, str);
- #else
- Sql_EscapeStringLen(mmysql_handle, esc_str, str, len);
- #endif
- script_pushstr(st, esc_str);
- return 0;
- }
- BUILDIN_FUNC(getd)
- {
- char varname[100];
- const char *buffer;
- int elem;
- buffer = script_getstr(st, 2);
- if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
- elem = 0;
- // Push the 'pointer' so it's more flexible [Lance]
- push_val(st->stack, C_NAME, (elem<<24) | add_str(varname));
- return 0;
- }
- // <--- [zBuffer] List of dynamic var commands
- // Pet stat [Lance]
- BUILDIN_FUNC(petstat)
- {
- TBL_PC *sd = NULL;
- struct pet_data *pd;
- int flag = script_getnum(st,2);
- sd = script_rid2sd(st);
- if(!sd || !sd->status.pet_id || !sd->pd){
- if(flag == 2)
- script_pushconststr(st, "");
- else
- script_pushint(st,0);
- return 0;
- }
- pd = sd->pd;
- switch(flag){
- case 1: script_pushint(st,(int)pd->pet.class_); break;
- case 2: script_pushstrcopy(st, pd->pet.name); break;
- case 3: script_pushint(st,(int)pd->pet.level); break;
- case 4: script_pushint(st,(int)pd->pet.hungry); break;
- case 5: script_pushint(st,(int)pd->pet.intimate); break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- BUILDIN_FUNC(callshop)
- {
- TBL_PC *sd = NULL;
- struct npc_data *nd;
- const char *shopname;
- int flag = 0;
- sd = script_rid2sd(st);
- if (!sd) {
- script_pushint(st,0);
- return 0;
- }
- shopname = script_getstr(st, 2);
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- nd = npc_name2id(shopname);
- if( !nd || nd->bl.type != BL_NPC || (nd->subtype != SHOP && nd->subtype != CASHSHOP) )
- {
- ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)\n", shopname);
- script_pushint(st,0);
- return 1;
- }
-
- if( nd->subtype == SHOP )
- {
- switch( flag )
- {
- case 1: npc_buysellsel(sd,nd->bl.id,0); break; //Buy window
- case 2: npc_buysellsel(sd,nd->bl.id,1); break; //Sell window
- default: clif_npcbuysell(sd,nd->bl.id); break; //Show menu
- }
- }
- else
- clif_cashshop_show(sd, nd);
- sd->npc_shopid = nd->bl.id;
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(npcshopitem)
- {
- const char* npcname = script_getstr(st, 2);
- struct npc_data* nd = npc_name2id(npcname);
- int n, i;
- int amount;
- if( !nd || nd->subtype != SHOP )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- // get the count of new entries
- amount = (script_lastdata(st)-2)/2;
- // generate new shop item list
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, amount);
- for( n = 0, i = 3; n < amount; n++, i+=2 )
- {
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
- nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
- }
- nd->u.shop.count = n;
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(npcshopadditem)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- int n, i;
- int amount;
- if( !nd || nd->subtype != SHOP )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- // get the count of new entries
- amount = (script_lastdata(st)-2)/2;
- // append new items to existing shop item list
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count+amount);
- for( n = nd->u.shop.count, i = 3; n < nd->u.shop.count+amount; n++, i+=2 )
- {
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
- nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
- }
- nd->u.shop.count = n;
- script_pushint(st,1);
- return 0;
- }
- BUILDIN_FUNC(npcshopdelitem)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- int n, i;
- int amount;
- int size;
- if( !nd || nd->subtype != SHOP )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- amount = script_lastdata(st)-2;
- size = nd->u.shop.count;
- // remove specified items from the shop item list
- for( i = 3; i < 3 + amount; i++ )
- {
- ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == script_getnum(st,i) );
- if( n < size )
- {
- memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n));
- size--;
- }
- }
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, size);
- nd->u.shop.count = size;
- script_pushint(st,1);
- return 0;
- }
- //Sets a script to attach to a shop npc.
- BUILDIN_FUNC(npcshopattach)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- int flag = 1;
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- if( !nd || nd->subtype != SHOP )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- if (flag)
- nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
- else
- nd->master_nd = NULL;
- script_pushint(st,1);
- return 0;
- }
- /*==========================================
- * Returns some values of an item [Lupus]
- * Price, Weight, etc...
- setitemscript(itemID,"{new item bonus script}",[n]);
- Where n:
- 0 - script
- 1 - Equip script
- 2 - Unequip script
- *------------------------------------------*/
- BUILDIN_FUNC(setitemscript)
- {
- int item_id,n=0;
- const char *script;
- struct item_data *i_data;
- struct script_code **dstscript;
- item_id = script_getnum(st,2);
- script = script_getstr(st,3);
- if( script_hasdata(st,4) )
- n=script_getnum(st,4);
- i_data = itemdb_exists(item_id);
- if (!i_data || script==NULL || script[0]!='{') {
- script_pushint(st,0);
- return 0;
- }
- switch (n) {
- case 2:
- dstscript = &i_data->unequip_script;
- break;
- case 1:
- dstscript = &i_data->equip_script;
- break;
- default:
- dstscript = &i_data->script;
- break;
- }
- if(*dstscript)
- script_free_code(*dstscript);
- *dstscript = parse_script(script, "script_setitemscript", 0, 0);
- script_pushint(st,1);
- return 0;
- }
- /* Work In Progress [Lupus]
- BUILDIN_FUNC(addmonsterdrop)
- {
- int class_,item_id,chance;
- class_=script_getnum(st,2);
- item_id=script_getnum(st,3);
- chance=script_getnum(st,4);
- if(class_>1000 && item_id>500 && chance>0) {
- script_pushint(st,1);
- } else {
- script_pushint(st,0);
- }
- }
- BUILDIN_FUNC(delmonsterdrop)
- {
- int class_,item_id;
- class_=script_getnum(st,2);
- item_id=script_getnum(st,3);
- if(class_>1000 && item_id>500) {
- script_pushint(st,1);
- } else {
- script_pushint(st,0);
- }
- }
- */
- /*==========================================
- * Returns some values of a monster [Lupus]
- * Name, Level, race, size, etc...
- getmonsterinfo(monsterID,queryIndex);
- *------------------------------------------*/
- BUILDIN_FUNC(getmonsterinfo)
- {
- struct mob_db *mob;
- int mob_id;
- mob_id = script_getnum(st,2);
- if (!mobdb_checkid(mob_id)) {
- ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i\n", mob_id);
- if ( !script_getnum(st,3) ) //requested a string
- script_pushconststr(st,"null");
- else
- script_pushint(st,-1);
- return -1;
- }
- mob = mob_db(mob_id);
- switch ( script_getnum(st,3) ) {
- case 0: script_pushstrcopy(st,mob->jname); break;
- case 1: script_pushint(st,mob->lv); break;
- case 2: script_pushint(st,mob->status.max_hp); break;
- case 3: script_pushint(st,mob->base_exp); break;
- case 4: script_pushint(st,mob->job_exp); break;
- case 5: script_pushint(st,mob->status.rhw.atk); break;
- case 6: script_pushint(st,mob->status.rhw.atk2); break;
- case 7: script_pushint(st,mob->status.def); break;
- case 8: script_pushint(st,mob->status.mdef); break;
- case 9: script_pushint(st,mob->status.str); break;
- case 10: script_pushint(st,mob->status.agi); break;
- case 11: script_pushint(st,mob->status.vit); break;
- case 12: script_pushint(st,mob->status.int_); break;
- case 13: script_pushint(st,mob->status.dex); break;
- case 14: script_pushint(st,mob->status.luk); break;
- case 15: script_pushint(st,mob->status.rhw.range); break;
- case 16: script_pushint(st,mob->range2); break;
- case 17: script_pushint(st,mob->range3); break;
- case 18: script_pushint(st,mob->status.size); break;
- case 19: script_pushint(st,mob->status.race); break;
- case 20: script_pushint(st,mob->status.def_ele); break;
- case 21: script_pushint(st,mob->status.mode); break;
- default: script_pushint(st,-1); //wrong Index
- }
- return 0;
- }
- BUILDIN_FUNC(checkvending) // check vending [Nab4]
- {
- TBL_PC *sd = NULL;
- if(script_hasdata(st,2))
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if(sd)
- script_pushint(st,(sd->vender_id != 0));
- else
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(checkchatting) // check chatting [Marka]
- {
- TBL_PC *sd = NULL;
- if(script_hasdata(st,2))
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if(sd)
- script_pushint(st,(sd->chatID != 0));
- else
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(searchitem)
- {
- struct script_data* data = script_getdata(st, 2);
- const char *itemname = script_getstr(st,3);
- struct item_data *items[MAX_SEARCH];
- int count;
- char* name;
- int32 start;
- int32 id;
- int32 i;
- TBL_PC* sd = NULL;
- if ((items[0] = itemdb_exists(atoi(itemname))))
- count = 1;
- else {
- count = itemdb_searchname_array(items, ARRAYLENGTH(items), itemname);
- if (count > MAX_SEARCH) count = MAX_SEARCH;
- }
- if (!count) {
- script_pushint(st, 0);
- return 0;
- }
- if( !data_isreference(data) )
- {
- ShowError("script:searchitem: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:searchitem: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- if( is_string_variable(name) )
- {// string array
- ShowError("script:searchitem: not an integer array reference\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- for( i = 0; i < count; ++start, ++i )
- {// Set array
- void* v = (void*)items[i]->nameid;
- set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
- }
- script_pushint(st, count);
- return 0;
- }
- int axtoi(const char *hexStg)
- {
- int n = 0; // position in string
- int m = 0; // position in digit[] to shift
- int count; // loop index
- int intValue = 0; // integer value of hex string
- int digit[11]; // hold values to convert
- while (n < 10) {
- if (hexStg[n]=='\0')
- break;
- if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
- digit[n] = hexStg[n] & 0x0f; //convert to int
- else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else break;
- n++;
- }
- count = n;
- m = n - 1;
- n = 0;
- while(n < count) {
- // digit[n] is value of hex digit at position n
- // (m << 2) is the number of positions to shift
- // OR the bits into return value
- intValue = intValue | (digit[n] << (m << 2));
- m--; // adjust the position to set
- n++; // next digit to process
- }
- return (intValue);
- }
- // [Lance] Hex string to integer converter
- BUILDIN_FUNC(axtoi)
- {
- const char *hex = script_getstr(st,2);
- script_pushint(st,axtoi(hex));
- return 0;
- }
- // [zBuffer] List of player cont commands --->
- BUILDIN_FUNC(rid2name)
- {
- struct block_list *bl = NULL;
- int rid = script_getnum(st,2);
- if((bl = map_id2bl(rid)))
- {
- switch(bl->type) {
- case BL_MOB: script_pushstrcopy(st,((TBL_MOB*)bl)->name); break;
- case BL_PC: script_pushstrcopy(st,((TBL_PC*)bl)->status.name); break;
- case BL_NPC: script_pushstrcopy(st,((TBL_NPC*)bl)->exname); break;
- case BL_PET: script_pushstrcopy(st,((TBL_PET*)bl)->pet.name); break;
- case BL_HOM: script_pushstrcopy(st,((TBL_HOM*)bl)->homunculus.name); break;
- case BL_MER: script_pushstrcopy(st,((TBL_MER*)bl)->db->name); break;
- default:
- ShowError("buildin_rid2name: BL type unknown.\n");
- script_pushconststr(st,"");
- break;
- }
- } else {
- ShowError("buildin_rid2name: invalid RID\n");
- script_pushconststr(st,"(null)");
- }
- return 0;
- }
- BUILDIN_FUNC(pcblockmove)
- {
- int id, flag;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- flag = script_getnum(st,3);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- sd->state.blockedmove = flag > 0;
- return 0;
- }
- BUILDIN_FUNC(pcfollow)
- {
- int id, targetid;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- targetid = script_getnum(st,3);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- pc_follow(sd, targetid);
- return 0;
- }
- BUILDIN_FUNC(pcstopfollow)
- {
- int id;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- pc_stop_following(sd);
- return 0;
- }
- // <--- [zBuffer] List of player cont commands
- // [zBuffer] List of mob control commands --->
- //## TODO always return if the request/whatever was successfull [FlavioJS]
- /// Makes the unit walk to target position or map
- /// Returns if it was successfull
- ///
- /// unitwalk(<unit_id>,<x>,<y>) -> <bool>
- /// unitwalk(<unit_id>,<map_id>) -> <bool>
- BUILDIN_FUNC(unitwalk)
- {
- struct block_list* bl;
- bl = map_id2bl(script_getnum(st,2));
- if( bl == NULL )
- {
- script_pushint(st, 0);
- }
- else if( script_hasdata(st,4) )
- {
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- script_pushint(st, unit_walktoxy(bl,x,y,0));// We'll use harder calculations.
- }
- else
- {
- int map_id = script_getnum(st,3);
- script_pushint(st, unit_walktobl(bl,map_id2bl(map_id),65025,1));
- }
- return 0;
- }
- /// Kills the unit
- ///
- /// unitkill <unit_id>;
- BUILDIN_FUNC(unitkill)
- {
- struct block_list* bl = map_id2bl(script_getnum(st,2));
- if( bl != NULL )
- status_kill(bl);
- return 0;
- }
- /// Warps the unit to the target position in the target map
- /// Returns if it was successfull
- ///
- /// unitwarp(<unit_id>,"<map name>",<x>,<y>) -> <bool>
- BUILDIN_FUNC(unitwarp)
- {
- int unit_id;
- int map;
- short x;
- short y;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- map = map_mapname2mapid(script_getstr(st, 3));
- x = (short)script_getnum(st,4);
- y = (short)script_getnum(st,5);
- bl = map_id2bl(unit_id);
- if( map >= 0 && bl != NULL )
- script_pushint(st, unit_warp(bl,map,x,y,0));
- else
- script_pushint(st, 0);
- return 0;
- }
- /// Makes the unit attack the target.
- /// If the unit is a player and <action type> is not 0, it does a continuous
- /// attack instead of a single attack.
- /// Returns if the request was successfull.
- ///
- /// unitattack(<unit_id>,"<target name>"{,<action type>}) -> <bool>
- /// unitattack(<unit_id>,<target_id>{,<action type>}) -> <bool>
- BUILDIN_FUNC(unitattack)
- {
- struct block_list* unit_bl;
- struct block_list* target_bl = NULL;
- struct script_data* data;
- int actiontype = 0;
- // get unit
- unit_bl = map_id2bl(script_getnum(st,2));
- if( unit_bl == NULL ) {
- script_pushint(st, 0);
- return 0;
- }
-
- data = script_getdata(st, 3);
- get_val(st, data);
- if( data_isstring(data) )
- {
- TBL_PC* sd = map_nick2sd(conv_str(st, data));
- if( sd != NULL )
- target_bl = &sd->bl;
- } else
- target_bl = map_id2bl(conv_num(st, data));
- // request the attack
- if( target_bl == NULL )
- {
- script_pushint(st, 0);
- return 0;
- }
-
- // get actiontype
- if( script_hasdata(st,4) )
- actiontype = script_getnum(st,4);
- switch( unit_bl->type )
- {
- case BL_PC:
- clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick());
- script_pushint(st, 1);
- return 0;
- case BL_MOB:
- ((TBL_MOB *)unit_bl)->target_id = target_bl->id;
- break;
- case BL_PET:
- ((TBL_PET *)unit_bl)->target_id = target_bl->id;
- break;
- default:
- ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
- script_pushint(st, 0);
- return 1;
- }
- script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
- return 0;
- }
- /// Makes the unit stop attacking and moving
- ///
- /// unitstop <unit_id>;
- BUILDIN_FUNC(unitstop)
- {
- int unit_id;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- {
- unit_stop_attack(bl);
- unit_stop_walking(bl,4);
- if( bl->type == BL_MOB )
- ((TBL_MOB*)bl)->target_id = 0;
- }
- return 0;
- }
- /// Makes the unit say the message
- ///
- /// unittalk <unit_id>,"<message>";
- BUILDIN_FUNC(unittalk)
- {
- int unit_id;
- const char* message;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- message = script_getstr(st, 3);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- {
- struct StringBuf sbuf;
- StringBuf_Init(&sbuf);
- StringBuf_Printf(&sbuf, "%s : %s", status_get_name(bl), message);
- clif_message(bl, StringBuf_Value(&sbuf));
- if( bl->type == BL_PC )
- clif_displaymessage(((TBL_PC*)bl)->fd, StringBuf_Value(&sbuf));
- StringBuf_Destroy(&sbuf);
- }
- return 0;
- }
- /// Makes the unit do an emotion
- ///
- /// unitemote <unit_id>,<emotion>;
- ///
- /// @see e_* in const.txt
- BUILDIN_FUNC(unitemote)
- {
- int unit_id;
- int emotion;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- emotion = script_getnum(st,3);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- clif_emotion(bl, emotion);
- return 0;
- }
- /// Makes the unit cast the skill on the target or self if no target is specified
- ///
- /// unitskilluseid <unit_id>,<skill_id>,<skill_lv>{,<target_id>};
- /// unitskilluseid <unit_id>,"<skill name>",<skill_lv>{,<target_id>};
- BUILDIN_FUNC(unitskilluseid)
- {
- int unit_id;
- int skill_id;
- int skill_lv;
- int target_id;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- skill_lv = script_getnum(st,4);
- target_id = ( script_hasdata(st,5) ? script_getnum(st,5) : unit_id );
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- unit_skilluse_id(bl, target_id, skill_id, skill_lv);
- return 0;
- }
- /// Makes the unit cast the skill on the target position.
- ///
- /// unitskillusepos <unit_id>,<skill_id>,<skill_lv>,<target_x>,<target_y>;
- /// unitskillusepos <unit_id>,"<skill name>",<skill_lv>,<target_x>,<target_y>;
- BUILDIN_FUNC(unitskillusepos)
- {
- int unit_id;
- int skill_id;
- int skill_lv;
- int skill_x;
- int skill_y;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- skill_id = ( script_isstring(st,3) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- skill_lv = script_getnum(st,4);
- skill_x = script_getnum(st,5);
- skill_y = script_getnum(st,6);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- unit_skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv);
- return 0;
- }
- // <--- [zBuffer] List of mob control commands
- /// Pauses the execution of the script, detaching the player
- ///
- /// sleep <mili seconds>;
- BUILDIN_FUNC(sleep)
- {
- int ticks;
-
- ticks = script_getnum(st,2);
- // detach the player
- script_detach_rid(st);
- if( ticks <= 0 )
- {// do nothing
- }
- else if( st->sleep.tick == 0 )
- {// sleep for the target amount of time
- st->state = RERUNLINE;
- st->sleep.tick = ticks;
- }
- else
- {// sleep time is over
- st->state = RUN;
- st->sleep.tick = 0;
- }
- return 0;
- }
- /// Pauses the execution of the script, keeping the player attached
- /// Returns if a player is still attached
- ///
- /// sleep2(<mili secconds>) -> <bool>
- BUILDIN_FUNC(sleep2)
- {
- int ticks;
-
- ticks = script_getnum(st,2);
- if( ticks <= 0 )
- {// do nothing
- script_pushint(st, (map_id2sd(st->rid)!=NULL));
- }
- else if( !st->sleep.tick )
- {// sleep for the target amount of time
- st->state = RERUNLINE;
- st->sleep.tick = ticks;
- }
- else
- {// sleep time is over
- st->state = RUN;
- st->sleep.tick = 0;
- script_pushint(st, (map_id2sd(st->rid)!=NULL));
- }
- return 0;
- }
- /// Awakes all the sleep timers of the target npc
- ///
- /// awake "<npc name>";
- BUILDIN_FUNC(awake)
- {
- struct npc_data* nd;
- struct linkdb_node *node = (struct linkdb_node *)sleep_db;
- nd = npc_name2id(script_getstr(st, 2));
- if( nd == NULL ) {
- ShowError("awake: NPC \"%s\" not found\n", script_getstr(st, 2));
- return 1;
- }
- while( node )
- {
- if( (int)node->key == nd->bl.id )
- {// sleep timer for the npc
- struct script_state* tst = (struct script_state*)node->data;
- TBL_PC* sd = map_id2sd(tst->rid);
- if( tst->sleep.timer == -1 )
- {// already awake ???
- node = node->next;
- continue;
- }
- if( (sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd))
- {// char not online anymore / another char of the same account is online - Cancel execution
- tst->state = END;
- tst->rid = 0;
- }
- delete_timer(tst->sleep.timer, run_script_timer);
- node = script_erase_sleepdb(node);
- tst->sleep.timer = INVALID_TIMER;
- if(tst->state != RERUNLINE)
- tst->sleep.tick = 0;
- run_script_main(tst);
- }
- else
- {
- node = node->next;
- }
- }
- return 0;
- }
- /// Returns a reference to a variable of the target NPC.
- /// Returns 0 if an error occurs.
- ///
- /// getvariableofnpc(<variable>, "<npc name>") -> <reference>
- BUILDIN_FUNC(getvariableofnpc)
- {
- struct script_data* data;
- const char* name;
- struct npc_data* nd;
- data = script_getdata(st,2);
- if( !data_isreference(data) )
- {// Not a reference (aka varaible name)
- ShowError("script:getvariableofnpc: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- name = reference_getname(data);
- if( *name != '.' || name[1] == '@' )
- {// not a npc variable
- ShowError("script:getvariableofnpc: invalid scope (not npc variable)\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- nd = npc_name2id(script_getstr(st,3));
- if( nd == NULL || nd->subtype != SCRIPT || nd->u.scr.script == NULL )
- {// NPC not found or has no script
- ShowError("script:getvariableofnpc: can't find npc %s\n", script_getstr(st,3));
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- push_val2(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars );
- return 0;
- }
- /// Opens a warp portal.
- /// Has no "portal opening" effect/sound, it opens the portal immediately.
- ///
- /// warpportal <source x>,<source y>,"<target map>",<target x>,<target y>;
- ///
- /// @author blackhole89
- BUILDIN_FUNC(warpportal)
- {
- int spx;
- int spy;
- unsigned short mapindex;
- int tpx;
- int tpy;
- struct skill_unit_group* group;
- struct block_list* bl;
- bl = map_id2bl(st->oid);
- if( bl == NULL )
- {
- ShowError("script:warpportal: npc is needed\n");
- return 1;
- }
- spx = script_getnum(st,2);
- spy = script_getnum(st,3);
- mapindex = mapindex_name2id(script_getstr(st, 4));
- tpx = script_getnum(st,5);
- tpy = script_getnum(st,6);
- if( mapindex == 0 )
- return 0;// map not found
- group = skill_unitsetting(bl, AL_WARP, 4, spx, spy, 0);
- if( group == NULL )
- return 0;// failed
- group->val2 = (tpx<<16) | tpy;
- group->val3 = mapindex;
- return 0;
- }
- BUILDIN_FUNC(openmail)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifndef TXT_ONLY
- mail_openmail(sd);
- #endif
- return 0;
- }
- BUILDIN_FUNC(openauction)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifndef TXT_ONLY
- clif_Auction_openwindow(sd);
- #endif
- return 0;
- }
- /// Retrieves the value of the specified flag of the specified cell.
- ///
- /// checkcell("<map name>",<x>,<y>,<type>) -> <bool>
- ///
- /// @see cell_chk* constants in const.txt for the types
- BUILDIN_FUNC(checkcell)
- {
- int m = map_mapname2mapid(script_getstr(st,2));
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- cell_chk type = (cell_chk)script_getnum(st,5);
- script_pushint(st, map_getcell(m, x, y, type));
- return 0;
- }
- /// Modifies flags of cells in the specified area.
- ///
- /// setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>;
- ///
- /// @see cell_* constants in const.txt for the types
- BUILDIN_FUNC(setcell)
- {
- int m = map_mapname2mapid(script_getstr(st,2));
- int x1 = script_getnum(st,3);
- int y1 = script_getnum(st,4);
- int x2 = script_getnum(st,5);
- int y2 = script_getnum(st,6);
- cell_t type = (cell_t)script_getnum(st,7);
- bool flag = (bool)script_getnum(st,8);
- int x,y;
- if( x1 > x2 ) swap(x1,x2);
- if( y1 > y2 ) swap(y1,y2);
- for( y = y1; y <= y2; ++y )
- for( x = x1; x <= x2; ++x )
- map_setcell(m, x, y, type, flag);
- return 0;
- }
- /*==========================================
- * Mercenary Commands
- *------------------------------------------*/
- BUILDIN_FUNC(mercenary_create)
- {
- struct map_session_data *sd;
- int class_, contract_time;
- if( (sd = script_rid2sd(st)) == NULL || sd->md || sd->status.mer_id != 0 )
- return 0;
-
- class_ = script_getnum(st,2);
- if( !merc_class(class_) )
- return 0;
- contract_time = script_getnum(st,3);
- merc_create(sd, class_, contract_time);
- return 0;
- }
- BUILDIN_FUNC(mercenary_heal)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int hp, sp;
- if( sd == NULL || sd->md == NULL )
- return 0;
- hp = script_getnum(st,2);
- sp = script_getnum(st,3);
- status_heal(&sd->md->bl, hp, sp, 0);
- return 0;
- }
- BUILDIN_FUNC(mercenary_sc_start)
- {
- struct map_session_data *sd = script_rid2sd(st);
- enum sc_type type;
- int tick, val1;
- if( sd == NULL || sd->md == NULL )
- return 0;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- status_change_start(&sd->md->bl, type, 10000, val1, 0, 0, 0, tick, 2);
- return 0;
- }
- BUILDIN_FUNC(mercenary_get_calls)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- script_pushint(st,sd->status.arch_calls);
- break;
- case SPEAR_MERC_GUILD:
- script_pushint(st,sd->status.spear_calls);
- break;
- case SWORD_MERC_GUILD:
- script_pushint(st,sd->status.sword_calls);
- break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- BUILDIN_FUNC(mercenary_set_calls)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild, value, *calls;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- value = script_getnum(st,3);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- calls = &sd->status.arch_calls;
- break;
- case SPEAR_MERC_GUILD:
- calls = &sd->status.spear_calls;
- break;
- case SWORD_MERC_GUILD:
- calls = &sd->status.sword_calls;
- break;
- default:
- return 0; // Invalid Guild
- }
- *calls += value;
- *calls = cap_value(*calls, 0, INT_MAX);
- return 0;
- }
- BUILDIN_FUNC(mercenary_get_faith)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- script_pushint(st,sd->status.arch_faith);
- break;
- case SPEAR_MERC_GUILD:
- script_pushint(st,sd->status.spear_faith);
- break;
- case SWORD_MERC_GUILD:
- script_pushint(st,sd->status.sword_faith);
- break;
- default:
- script_pushint(st,0);
- break;
- }
- return 0;
- }
- BUILDIN_FUNC(mercenary_set_faith)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild, value, *calls;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- value = script_getnum(st,3);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- calls = &sd->status.arch_faith;
- break;
- case SPEAR_MERC_GUILD:
- calls = &sd->status.spear_faith;
- break;
- case SWORD_MERC_GUILD:
- calls = &sd->status.sword_faith;
- break;
- default:
- return 0; // Invalid Guild
- }
- *calls += value;
- *calls = cap_value(*calls, 0, INT_MAX);
- if( mercenary_get_guild(sd->md) == guild )
- clif_mercenary_updatestatus(sd,SP_MERCFAITH);
- return 0;
- }
- /*------------------------------------------
- * Book Reading
- *------------------------------------------*/
- BUILDIN_FUNC(readbook)
- {
- struct map_session_data *sd;
- int book_id, page;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- book_id = script_getnum(st,2);
- page = script_getnum(st,3);
- clif_readbook(sd->fd, book_id, page);
- return 0;
- }
- /******************
- Questlog script commands
- *******************/
- BUILDIN_FUNC(setquest)
- {
- TBL_PC * sd = script_rid2sd(st);
- quest_add(sd, script_getnum(st, 2));
- return 0;
- }
- BUILDIN_FUNC(erasequest)
- {
- TBL_PC * sd = script_rid2sd(st);
- quest_delete(sd, script_getnum(st, 2));
- return 0;
- }
- BUILDIN_FUNC(completequest)
- {
- TBL_PC * sd = script_rid2sd(st);
- quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE);
- return 0;
- }
- BUILDIN_FUNC(changequest)
- {
- TBL_PC * sd = script_rid2sd(st);
- quest_change(sd, script_getnum(st, 2),script_getnum(st, 3));
- return 0;
- }
- BUILDIN_FUNC(checkquest)
- {
- TBL_PC * sd = script_rid2sd(st);
- quest_check_type type = HAVEQUEST;
- if( script_hasdata(st, 3) )
- type = (quest_check_type)script_getnum(st, 3);
- script_pushint(st, quest_check(sd, script_getnum(st, 2), type));
- return 0;
- }
- BUILDIN_FUNC(showevent)
- {
- TBL_PC *sd = script_rid2sd(st);
- struct npc_data *nd = map_id2nd(st->oid);
- int state, color;
- if( sd == NULL || nd == NULL )
- return 0;
- state = script_getnum(st, 2);
- color = script_getnum(st, 3);
- if( color < 0 || color > 4 )
- color = 0; // set default color
- clif_quest_show_event(sd, &nd->bl, state, color);
- return 0;
- }
- /*==========================================
- * BattleGround System
- *------------------------------------------*/
- BUILDIN_FUNC(waitingroom2bg)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- const char *map_name, *ev = "", *dev = "";
- int x, y, i, mapindex = 0, bg_id, n;
- struct map_session_data *sd;
- if( script_hasdata(st,7) )
- nd = npc_name2id(script_getstr(st,7));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- {
- script_pushint(st,0);
- return 0;
- }
- map_name = script_getstr(st,2);
- if( strcmp(map_name,"-") != 0 )
- {
- mapindex = mapindex_name2id(map_name);
- if( mapindex == 0 )
- { // Invalid Map
- script_pushint(st,0);
- return 0;
- }
- }
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- ev = script_getstr(st,5); // Logout Event
- dev = script_getstr(st,6); // Die Event
- if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 )
- { // Creation failed
- script_pushint(st,0);
- return 0;
- }
- n = cd->users;
- for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) )
- mapreg_setreg(add_str("$@arenamembers") + (i<<24), sd->bl.id);
- else
- mapreg_setreg(add_str("$@arenamembers") + (i<<24), 0);
- }
- mapreg_setreg(add_str("$@arenamembersnum"), i);
- script_pushint(st,bg_id);
- return 0;
- }
- BUILDIN_FUNC(waitingroom2bg_single)
- {
- const char* map_name;
- struct npc_data *nd;
- struct chat_data *cd;
- struct map_session_data *sd;
- int x, y, mapindex, bg_id;
- bg_id = script_getnum(st,2);
- map_name = script_getstr(st,3);
- if( (mapindex = mapindex_name2id(map_name)) == 0 )
- return 0; // Invalid Map
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- nd = npc_name2id(script_getstr(st,6));
- if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL || cd->users <= 0 )
- return 0;
- if( (sd = cd->usersd[0]) == NULL )
- return 0;
- if( bg_team_join(bg_id, sd) )
- {
- pc_setpos(sd, mapindex, x, y, 3);
- script_pushint(st,1);
- }
- else
- script_pushint(st,0);
- return 0;
- }
- BUILDIN_FUNC(bg_team_setxy)
- {
- struct battleground_data *bg;
- int bg_id;
- bg_id = script_getnum(st,2);
- if( (bg = bg_team_search(bg_id)) == NULL )
- return 0;
- bg->x = script_getnum(st,3);
- bg->y = script_getnum(st,4);
- return 0;
- }
- BUILDIN_FUNC(bg_warp)
- {
- int x, y, mapindex, bg_id;
- const char* map_name;
- bg_id = script_getnum(st,2);
- map_name = script_getstr(st,3);
- if( (mapindex = mapindex_name2id(map_name)) == 0 )
- return 0; // Invalid Map
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- bg_team_warp(bg_id, mapindex, x, y);
- return 0;
- }
- BUILDIN_FUNC(bg_monster)
- {
- int class_ = 0, x = 0, y = 0, bg_id = 0;
- const char *str,*map, *evt="";
- bg_id = script_getnum(st,2);
- map = script_getstr(st,3);
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- str = script_getstr(st,6);
- class_ = script_getnum(st,7);
- if( script_hasdata(st,8) ) evt = script_getstr(st,8);
- check_event(st, evt);
- script_pushint(st, mob_spawn_bg(map,x,y,str,class_,evt,bg_id));
- return 0;
- }
- BUILDIN_FUNC(bg_monster_set_team)
- {
- struct mob_data *md;
- struct block_list *mbl;
- int id = script_getnum(st,2),
- bg_id = script_getnum(st,3);
-
- if( (mbl = map_id2bl(id)) == NULL || mbl->type != BL_MOB )
- return 0;
- md = (TBL_MOB *)mbl;
- md->state.bg_id = bg_id;
- mob_stop_attack(md);
- mob_stop_walking(md, 0);
- md->target_id = md->attacked_id = 0;
- clif_charnameack(0, &md->bl);
- return 0;
- }
- BUILDIN_FUNC(bg_leave)
- {
- struct map_session_data *sd = script_rid2sd(st);
- if( sd == NULL || !sd->state.bg_id )
- return 0;
-
- bg_team_leave(sd,0);
- return 0;
- }
- BUILDIN_FUNC(bg_destroy)
- {
- int bg_id = script_getnum(st,2);
- bg_team_delete(bg_id);
- return 0;
- }
- BUILDIN_FUNC(bg_getareausers)
- {
- const char *str;
- int m, x0, y0, x1, y1, bg_id;
- int i = 0, c = 0;
- struct battleground_data *bg = NULL;
- struct map_session_data *sd;
- bg_id = script_getnum(st,2);
- str = script_getstr(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL || (m = map_mapname2mapid(str)) < 0 )
- {
- script_pushint(st,0);
- return 0;
- }
- x0 = script_getnum(st,4);
- y0 = script_getnum(st,5);
- x1 = script_getnum(st,6);
- y1 = script_getnum(st,7);
- for( i = 0; i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = bg->members[i].sd) == NULL )
- continue;
- if( sd->bl.m != m || sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1 )
- continue;
- c++;
- }
- script_pushint(st,c);
- return 0;
- }
- BUILDIN_FUNC(bg_updatescore)
- {
- const char *str;
- int m;
- str = script_getstr(st,2);
- if( (m = map_mapname2mapid(str)) < 0 )
- return 0;
- map[m].bgscore_lion = script_getnum(st,3);
- map[m].bgscore_eagle = script_getnum(st,4);
- clif_bg_updatescore(m);
- return 0;
- }
- BUILDIN_FUNC(bg_get_data)
- {
- struct battleground_data *bg;
- int bg_id = script_getnum(st,2),
- type = script_getnum(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL )
- {
- script_pushint(st,0);
- return 0;
- }
- switch( type )
- {
- case 0: script_pushint(st, bg->count); break;
- default:
- ShowError("script:bg_get_data: unknown data identifier %d\n", type);
- break;
- }
- return 0;
- }
- /*==========================================
- * Instancing Script Commands
- *------------------------------------------*/
- BUILDIN_FUNC(instance_create)
- {
- const char *name;
- int party_id, res;
- name = script_getstr(st, 2);
- party_id = script_getnum(st, 3);
- res = instance_create(party_id, name);
- if( res == -4 ) // Already exists
- {
- script_pushint(st, -1);
- return 0;
- }
- else if( res < 0 )
- {
- char *err;
- switch(res)
- {
- case -3: err = "No free instances"; break;
- case -2: err = "Missing parameter"; break;
- case -1: err = "Invalid type"; break;
- default: err = "Unknown"; break;
- }
- ShowError("buildin_instance_create: %s [%d].\n", err, res);
- script_pushint(st, -2);
- return 0;
- }
-
- script_pushint(st, res);
- return 0;
- }
- BUILDIN_FUNC(instance_destroy)
- {
- int instance_id;
- struct map_session_data *sd;
- struct party_data *p;
- if( script_hasdata(st, 2) )
- instance_id = script_getnum(st, 2);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- else return 0;
- if( instance_id <= 0 || instance_id >= MAX_INSTANCE )
- {
- ShowError("buildin_instance_destroy: Trying to destroy invalid instance %d.\n", instance_id);
- return 0;
- }
- instance_destroy(instance_id);
- return 0;
- }
- BUILDIN_FUNC(instance_attachmap)
- {
- const char *name;
- int m;
- int instance_id;
- bool usebasename = false;
-
- name = script_getstr(st,2);
- instance_id = script_getnum(st,3);
- if( script_hasdata(st,4) && script_getnum(st,4) > 0)
- usebasename = true;
- if( (m = instance_add_map(name, instance_id, usebasename)) < 0 ) // [Saithis]
- {
- ShowError("buildin_instance_attachmap: instance creation failed (%s): %d\n", name, m);
- script_pushconststr(st, "");
- return 0;
- }
- script_pushconststr(st, map[m].name);
-
- return 0;
- }
- BUILDIN_FUNC(instance_detachmap)
- {
- struct map_session_data *sd;
- struct party_data *p;
- const char *str;
- int m, instance_id;
-
- str = script_getstr(st, 2);
- if( script_hasdata(st, 3) )
- instance_id = script_getnum(st, 3);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- else return 0;
-
- if( (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m,instance_id)) < 0 )
- {
- ShowError("buildin_instance_detachmap: Trying to detach invalid map %s\n", str);
- return 0;
- }
- instance_del_map(m);
- return 0;
- }
- BUILDIN_FUNC(instance_attach)
- {
- int instance_id;
-
- instance_id = script_getnum(st, 2);
- if( instance_id <= 0 || instance_id >= MAX_INSTANCE )
- return 0;
-
- st->instance_id = instance_id;
- return 0;
- }
- BUILDIN_FUNC(instance_id)
- {
- int type, instance_id;
- struct map_session_data *sd;
- struct party_data *p;
-
- if( script_hasdata(st, 2) )
- {
- type = script_getnum(st, 2);
- if( type == 0 )
- instance_id = st->instance_id;
- else if( type == 1 && (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL )
- instance_id = p->instance_id;
- else
- instance_id = 0;
- }
- else
- instance_id = st->instance_id;
- script_pushint(st, instance_id);
- return 0;
- }
- BUILDIN_FUNC(instance_set_timeout)
- {
- int progress_timeout, idle_timeout;
- int instance_id;
- struct map_session_data *sd;
- struct party_data *p;
-
- progress_timeout = script_getnum(st, 2);
- idle_timeout = script_getnum(st, 3);
- if( script_hasdata(st, 4) )
- instance_id = script_getnum(st, 4);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- else return 0;
- if( instance_id > 0 )
- instance_set_timeout(instance_id, progress_timeout, idle_timeout);
-
- return 0;
- }
- BUILDIN_FUNC(instance_init)
- {
- int instance_id = script_getnum(st, 2);
- if( instance[instance_id].state != INSTANCE_IDLE )
- {
- ShowError("instance_init: instance already initialized.\n");
- return 0;
- }
- instance_init(instance_id);
- return 0;
- }
- BUILDIN_FUNC(instance_announce)
- {
- int instance_id = script_getnum(st,2);
- const char *mes = script_getstr(st,3);
- int flag = script_getnum(st,4);
- const char *fontColor = script_hasdata(st,5) ? script_getstr(st,5) : NULL;
- int fontType = script_hasdata(st,6) ? script_getnum(st,6) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,7) ? script_getnum(st,7) : 12; // default fontSize
- int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign
- int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY
- int i;
- struct map_session_data *sd;
- struct party_data *p;
- if( instance_id == 0 )
- {
- if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- else return 0;
- }
- if( instance_id <= 0 || instance_id >= MAX_INSTANCE )
- return 0;
-
- for( i = 0; i < instance[instance_id].num_map; i++ )
- map_foreachinmap(buildin_announce_sub, instance[instance_id].map[i], BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return 0;
- }
- BUILDIN_FUNC(instance_npcname)
- {
- const char *str;
- int instance_id = 0;
- struct map_session_data *sd;
- struct party_data *p;
- struct npc_data *nd;
-
- str = script_getstr(st, 2);
- if( script_hasdata(st, 3) )
- instance_id = script_getnum(st, 3);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- if( instance_id && (nd = npc_name2id(str)) != NULL )
- {
- static char npcname[NAME_LENGTH];
- snprintf(npcname, sizeof(npcname), "dup_%d_%d", instance_id, nd->bl.id);
- script_pushconststr(st,npcname);
- }
- else
- {
- ShowError("script:instance_npcname: invalid instance NPC (instance_id: %d, NPC name: \"%s\".)\n", instance_id, str);
- st->state = END;
- return 1;
- }
- return 0;
- }
- BUILDIN_FUNC(has_instance)
- {
- struct map_session_data *sd;
- struct party_data *p;
- const char *str;
- int m, instance_id = 0;
-
- str = script_getstr(st, 2);
- if( script_hasdata(st, 3) )
- instance_id = script_getnum(st, 3);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- if( !instance_id || (m = map_mapname2mapid(str)) < 0 || (m = instance_map2imap(m, instance_id)) < 0 )
- {
- script_pushconststr(st, "");
- return 0;
- }
- script_pushconststr(st, map[m].name);
- return 0;
- }
- BUILDIN_FUNC(instance_warpall)
- {
- struct map_session_data *pl_sd;
- int m, i, instance_id;
- const char *mapn;
- int x, y;
- unsigned short mapindex;
- struct party_data *p = NULL;
- mapn = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if( script_hasdata(st,5) )
- instance_id = script_getnum(st,5);
- else if( st->instance_id )
- instance_id = st->instance_id;
- else if( (pl_sd = script_rid2sd(st)) != NULL && pl_sd->status.party_id && (p = party_search(pl_sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- else return 0;
- if( (m = map_mapname2mapid(mapn)) < 0 || (map[m].flag.src4instance && (m = instance_mapid2imapid(m, instance_id)) < 0) )
- return 0;
- if( !(p = party_search(instance[instance_id].party_id)) )
- return 0;
- mapindex = map_id2index(m);
- for( i = 0; i < MAX_PARTY; i++ )
- if( (pl_sd = p->data[i].sd) && map[pl_sd->bl.m].instance_id == st->instance_id ) pc_setpos(pl_sd,mapindex,x,y,3);
- return 0;
- }
- /*==========================================
- * Custom Fonts
- *------------------------------------------*/
- BUILDIN_FUNC(setfont)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int font = script_getnum(st,2);
- if( sd == NULL )
- return 0;
- if( sd->state.user_font != font )
- sd->state.user_font = font;
- else
- sd->state.user_font = 0;
-
- clif_font(sd);
- return 0;
- }
- static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
- {
- TBL_MOB* md = (TBL_MOB*)bl;
- struct block_list *tbl;
- int mobid = va_arg(ap,int);
- int skillid = va_arg(ap,int);
- int skilllv = va_arg(ap,int);
- int casttime = va_arg(ap,int);
- int cancel = va_arg(ap,int);
- int emotion = va_arg(ap,int);
- int target = va_arg(ap,int);
- if( md->class_ != mobid )
- return 0;
- if( md->ud.skilltimer != -1 ) // Cancel the casting skill.
- unit_skillcastcancel(bl,0);
- // 0:self, 1:target, 2:master, default:random
- switch( target )
- {
- case 0: tbl = map_id2bl(md->bl.id); break;
- case 1: tbl = map_id2bl(md->target_id); break;
- case 2: tbl = map_id2bl(md->master_id); break;
- default:tbl = battle_getenemy(&md->bl, DEFAULT_ENEMY_TYPE(md),skill_get_range2(&md->bl, skillid, skilllv)); break;
- }
- if( !tbl )
- return 0;
- if( skill_get_casttype(skillid) == CAST_GROUND )
- unit_skilluse_pos2(&md->bl, tbl->x, tbl->y, skillid, skilllv, casttime, cancel);
- else
- unit_skilluse_id2(&md->bl, tbl->id, skillid, skilllv, casttime, cancel);
- clif_emotion(&md->bl, emotion);
- return 0;
- }
- /*==========================================
- * areamobuseskill "Map Name",<x>,<y>,<range>,<Mob ID>,"Skill Name"/<Skill ID>,<Skill Lv>,<Cast Time>,<Cancelable>,<Emotion>,<Target Type>;
- *------------------------------------------*/
- BUILDIN_FUNC(areamobuseskill)
- {
- struct block_list center;
- int m,range,mobid,skillid,skilllv,casttime,emotion,target,cancel;
- if( (m = map_mapname2mapid(script_getstr(st,2))) < 0 )
- {
- ShowError("areamobuseskill: invalid map name.\n");
- return 0;
- }
- if( map[m].flag.src4instance && st->instance_id && (m = instance_mapid2imapid(m, st->instance_id)) < 0 )
- return 0;
- center.m = m;
- center.x = script_getnum(st,3);
- center.y = script_getnum(st,4);
- range = script_getnum(st,5);
- mobid = script_getnum(st,6);
- skillid = ( script_isstring(st,7) ? skill_name2id(script_getstr(st,7)) : script_getnum(st,7) );
- if( (skilllv = script_getnum(st,8)) > battle_config.mob_max_skilllvl )
- skilllv = battle_config.mob_max_skilllvl;
- casttime = script_getnum(st,9);
- cancel = script_getnum(st,10);
- emotion = script_getnum(st,11);
- target = script_getnum(st,12);
-
- map_foreachinrange(buildin_mobuseskill_sub, ¢er, range, BL_MOB, mobid, skillid, skilllv, casttime, cancel, emotion, target);
- return 0;
- }
- BUILDIN_FUNC(progressbar)
- {
- #if PACKETVER >= 20080318
- struct map_session_data * sd = script_rid2sd(st);
- const char * color;
- unsigned int second;
- if( !st || !sd )
- return 0;
- st->state = STOP;
- color = script_getstr(st,2);
- second = script_getnum(st,3);
- sd->progressbar.npc_id = st->oid;
- sd->progressbar.timeout = gettick() + second*1000;
- clif_progressbar(sd, strtol(color, (char **)NULL, 0), second);
- #endif
- return 0;
- }
- BUILDIN_FUNC(pushpc)
- {
- int direction, cells, dx, dy;
- struct map_session_data* sd;
- if((sd = script_rid2sd(st))==NULL)
- {
- return 0;
- }
- direction = script_getnum(st,2);
- cells = script_getnum(st,3);
- if(direction<0 || direction>7)
- {
- ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", direction);
- script_reportsrc(st);
- direction%= 8; // trim spin-over
- }
- if(!cells)
- {// zero distance
- return 0;
- }
- else if(cells<0)
- {// pushing backwards
- direction = (direction+4)%8; // turn around
- cells = -cells;
- }
- dx = dirx[direction];
- dy = diry[direction];
- unit_blown(&sd->bl, dx, dy, cells, 0);
- return 0;
- }
- // declarations that were supposed to be exported from npc_chat.c
- #ifdef PCRE_SUPPORT
- BUILDIN_FUNC(defpattern);
- BUILDIN_FUNC(activatepset);
- BUILDIN_FUNC(deactivatepset);
- BUILDIN_FUNC(deletepset);
- #endif
- struct script_function buildin_func[] = {
- // NPC interaction
- BUILDIN_DEF(mes,"s"),
- BUILDIN_DEF(next,""),
- BUILDIN_DEF(close,""),
- BUILDIN_DEF(close2,""),
- BUILDIN_DEF(menu,"sl*"),
- BUILDIN_DEF(select,"s*"), //for future jA script compatibility
- BUILDIN_DEF(prompt,"s*"),
- //
- BUILDIN_DEF(goto,"l"),
- BUILDIN_DEF(callsub,"i*"),
- BUILDIN_DEF(callfunc,"s*"),
- BUILDIN_DEF(return,"?"),
- BUILDIN_DEF(getarg,"i?"),
- BUILDIN_DEF(jobchange,"i*"),
- BUILDIN_DEF(jobname,"i"),
- BUILDIN_DEF(input,"v??"),
- BUILDIN_DEF(warp,"sii"),
- BUILDIN_DEF(areawarp,"siiiisii"),
- BUILDIN_DEF(warpchar,"siii"), // [LuzZza]
- BUILDIN_DEF(warpparty,"siii*"), // [Fredzilla] [Paradox924X]
- BUILDIN_DEF(warpguild,"siii"), // [Fredzilla]
- BUILDIN_DEF(setlook,"ii"),
- BUILDIN_DEF(changelook,"ii"), // Simulates but don't Store it
- BUILDIN_DEF(set,"ii"),
- BUILDIN_DEF(setarray,"rv*"),
- BUILDIN_DEF(cleararray,"rvi"),
- BUILDIN_DEF(copyarray,"rri"),
- BUILDIN_DEF(getarraysize,"r"),
- BUILDIN_DEF(deletearray,"r?"),
- BUILDIN_DEF(getelementofarray,"ri"),
- BUILDIN_DEF(getitem,"vi?"),
- BUILDIN_DEF(rentitem,"vi"),
- BUILDIN_DEF(getitem2,"iiiiiiiii*"),
- BUILDIN_DEF(getnameditem,"is"),
- BUILDIN_DEF2(grouprandomitem,"groupranditem","i"),
- BUILDIN_DEF(makeitem,"iisii"),
- BUILDIN_DEF(delitem,"ii?"),
- BUILDIN_DEF(delitem2,"iiiiiiiii?"),
- BUILDIN_DEF2(enableitemuse,"enable_items",""),
- BUILDIN_DEF2(disableitemuse,"disable_items",""),
- BUILDIN_DEF(cutin,"si"),
- BUILDIN_DEF(viewpoint,"iiiii"),
- BUILDIN_DEF(heal,"ii"),
- BUILDIN_DEF(itemheal,"ii"),
- BUILDIN_DEF(percentheal,"ii"),
- BUILDIN_DEF(rand,"i?"),
- BUILDIN_DEF(countitem,"i"),
- BUILDIN_DEF(countitem2,"iiiiiiii"),
- BUILDIN_DEF(checkweight,"ii"),
- BUILDIN_DEF(readparam,"i*"),
- BUILDIN_DEF(getcharid,"i*"),
- BUILDIN_DEF(getpartyname,"i"),
- BUILDIN_DEF(getpartymember,"i*"),
- BUILDIN_DEF(getpartyleader,"i?"),
- BUILDIN_DEF(getguildname,"i"),
- BUILDIN_DEF(getguildmaster,"i"),
- BUILDIN_DEF(getguildmasterid,"i"),
- BUILDIN_DEF(strcharinfo,"i"),
- BUILDIN_DEF(strnpcinfo,"i"),
- BUILDIN_DEF(getequipid,"i"),
- BUILDIN_DEF(getequipname,"i"),
- BUILDIN_DEF(getbrokenid,"i"), // [Valaris]
- BUILDIN_DEF(repair,"i"), // [Valaris]
- BUILDIN_DEF(getequipisequiped,"i"),
- BUILDIN_DEF(getequipisenableref,"i"),
- BUILDIN_DEF(getequipisidentify,"i"),
- BUILDIN_DEF(getequiprefinerycnt,"i"),
- BUILDIN_DEF(getequipweaponlv,"i"),
- BUILDIN_DEF(getequippercentrefinery,"i"),
- BUILDIN_DEF(successrefitem,"i"),
- BUILDIN_DEF(failedrefitem,"i"),
- BUILDIN_DEF(statusup,"i"),
- BUILDIN_DEF(statusup2,"ii"),
- BUILDIN_DEF(bonus,"iv"),
- BUILDIN_DEF2(bonus,"bonus2","ivi"),
- BUILDIN_DEF2(bonus,"bonus3","ivii"),
- BUILDIN_DEF2(bonus,"bonus4","ivvii"),
- BUILDIN_DEF2(bonus,"bonus5","ivviii"),
- BUILDIN_DEF(autobonus,"sii??"),
- BUILDIN_DEF(autobonus2,"sii??"),
- BUILDIN_DEF(autobonus3,"siiv?"),
- BUILDIN_DEF(skill,"vi?"),
- BUILDIN_DEF(addtoskill,"vi?"), // [Valaris]
- BUILDIN_DEF(guildskill,"vi"),
- BUILDIN_DEF(getskilllv,"v"),
- BUILDIN_DEF(getgdskilllv,"iv"),
- BUILDIN_DEF(basicskillcheck,""),
- BUILDIN_DEF(getgmlevel,""),
- BUILDIN_DEF(end,""),
- BUILDIN_DEF(checkoption,"i"),
- BUILDIN_DEF(setoption,"i?"),
- BUILDIN_DEF(setcart,"?"),
- BUILDIN_DEF(checkcart,""),
- BUILDIN_DEF(setfalcon,"?"),
- BUILDIN_DEF(checkfalcon,""),
- BUILDIN_DEF(setriding,"?"),
- BUILDIN_DEF(checkriding,""),
- BUILDIN_DEF2(savepoint,"save","sii"),
- BUILDIN_DEF(savepoint,"sii"),
- BUILDIN_DEF(gettimetick,"i"),
- BUILDIN_DEF(gettime,"i"),
- BUILDIN_DEF(gettimestr,"si"),
- BUILDIN_DEF(openstorage,""),
- BUILDIN_DEF(guildopenstorage,"*"),
- BUILDIN_DEF(itemskill,"vi"),
- BUILDIN_DEF(produce,"i"),
- BUILDIN_DEF(cooking,"i"),
- BUILDIN_DEF(monster,"siisii*"),
- BUILDIN_DEF(getmobdrops,"i"),
- BUILDIN_DEF(areamonster,"siiiisii*"),
- BUILDIN_DEF(killmonster,"ss?"),
- BUILDIN_DEF(killmonsterall,"s?"),
- BUILDIN_DEF(clone,"siisi*"),
- BUILDIN_DEF(doevent,"s"),
- BUILDIN_DEF(donpcevent,"s"),
- BUILDIN_DEF(cmdothernpc,"ss"),
- BUILDIN_DEF(addtimer,"is"),
- BUILDIN_DEF(deltimer,"s"),
- BUILDIN_DEF(addtimercount,"si"),
- BUILDIN_DEF(initnpctimer,"??"),
- BUILDIN_DEF(stopnpctimer,"??"),
- BUILDIN_DEF(startnpctimer,"??"),
- BUILDIN_DEF(setnpctimer,"i?"),
- BUILDIN_DEF(getnpctimer,"i?"),
- BUILDIN_DEF(attachnpctimer,"?"), // attached the player id to the npc timer [Celest]
- BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest]
- BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex]
- BUILDIN_DEF(announce,"si*"),
- BUILDIN_DEF(mapannounce,"ssi*"),
- BUILDIN_DEF(areaannounce,"siiiisi*"),
- BUILDIN_DEF(getusers,"i"),
- BUILDIN_DEF(getmapguildusers,"si"),
- BUILDIN_DEF(getmapusers,"s"),
- BUILDIN_DEF(getareausers,"siiii"),
- BUILDIN_DEF(getareadropitem,"siiiii"),
- BUILDIN_DEF(enablenpc,"s"),
- BUILDIN_DEF(disablenpc,"s"),
- BUILDIN_DEF(hideoffnpc,"s"),
- BUILDIN_DEF(hideonnpc,"s"),
- BUILDIN_DEF(sc_start,"iii?"),
- BUILDIN_DEF(sc_start2,"iiii?"),
- BUILDIN_DEF(sc_start4,"iiiiii?"),
- BUILDIN_DEF(sc_end,"i?"),
- BUILDIN_DEF(getscrate,"ii*"),
- BUILDIN_DEF(debugmes,"s"),
- BUILDIN_DEF2(catchpet,"pet","i"),
- BUILDIN_DEF2(birthpet,"bpet",""),
- BUILDIN_DEF(resetlvl,"i"),
- BUILDIN_DEF(resetstatus,""),
- BUILDIN_DEF(resetskill,""),
- BUILDIN_DEF(skillpointcount,""),
- BUILDIN_DEF(changebase,"i"),
- BUILDIN_DEF(changesex,""),
- BUILDIN_DEF(waitingroom,"si??"),
- BUILDIN_DEF(delwaitingroom,"?"),
- BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"),
- BUILDIN_DEF(enablewaitingroomevent,"?"),
- BUILDIN_DEF(disablewaitingroomevent,"?"),
- BUILDIN_DEF2(enablewaitingroomevent,"enablearena",""), // Added by RoVeRT
- BUILDIN_DEF2(disablewaitingroomevent,"disablearena",""), // Added by RoVeRT
- BUILDIN_DEF(getwaitingroomstate,"i?"),
- BUILDIN_DEF(warpwaitingpc,"sii?"),
- BUILDIN_DEF(attachrid,"i"),
- BUILDIN_DEF(detachrid,""),
- BUILDIN_DEF(isloggedin,"i?"),
- BUILDIN_DEF(setmapflagnosave,"ssii"),
- BUILDIN_DEF(getmapflag,"si"),
- BUILDIN_DEF(setmapflag,"si*"),
- BUILDIN_DEF(removemapflag,"si"),
- BUILDIN_DEF(pvpon,"s"),
- BUILDIN_DEF(pvpoff,"s"),
- BUILDIN_DEF(gvgon,"s"),
- BUILDIN_DEF(gvgoff,"s"),
- BUILDIN_DEF(emotion,"i*"),
- BUILDIN_DEF(maprespawnguildid,"sii"),
- BUILDIN_DEF(agitstart,""), // <Agit>
- BUILDIN_DEF(agitend,""),
- BUILDIN_DEF(agitcheck,""), // <Agitcheck>
- BUILDIN_DEF(flagemblem,"i"), // Flag Emblem
- BUILDIN_DEF(getcastlename,"s"),
- BUILDIN_DEF(getcastledata,"si*"),
- BUILDIN_DEF(setcastledata,"sii"),
- BUILDIN_DEF(requestguildinfo,"i*"),
- BUILDIN_DEF(getequipcardcnt,"i"),
- BUILDIN_DEF(successremovecards,"i"),
- BUILDIN_DEF(failedremovecards,"ii"),
- BUILDIN_DEF(marriage,"s"),
- BUILDIN_DEF2(wedding_effect,"wedding",""),
- BUILDIN_DEF(divorce,""),
- BUILDIN_DEF(ispartneron,""),
- BUILDIN_DEF(getpartnerid,""),
- BUILDIN_DEF(getchildid,""),
- BUILDIN_DEF(getmotherid,""),
- BUILDIN_DEF(getfatherid,""),
- BUILDIN_DEF(warppartner,"sii"),
- BUILDIN_DEF(getitemname,"i"),
- BUILDIN_DEF(getitemslots,"i"),
- BUILDIN_DEF(makepet,"i"),
- BUILDIN_DEF(getexp,"ii"),
- BUILDIN_DEF(getinventorylist,""),
- BUILDIN_DEF(getskilllist,""),
- BUILDIN_DEF(clearitem,""),
- BUILDIN_DEF(classchange,"ii"),
- BUILDIN_DEF(misceffect,"i"),
- BUILDIN_DEF(playBGM,"s"),
- BUILDIN_DEF(playBGMall,"s*"),
- BUILDIN_DEF(soundeffect,"si"),
- BUILDIN_DEF(soundeffectall,"si*"), // SoundEffectAll [Codemaster]
- BUILDIN_DEF(strmobinfo,"ii"), // display mob data [Valaris]
- BUILDIN_DEF(guardian,"siisi??"), // summon guardians
- BUILDIN_DEF(guardianinfo,"sii"), // display guardian data [Valaris]
- BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris]
- BUILDIN_DEF(petrecovery,"ii"), // [Valaris]
- BUILDIN_DEF(petloot,"i"), // [Valaris]
- BUILDIN_DEF(petheal,"iiii"), // [Valaris]
- BUILDIN_DEF(petskillattack,"viii"), // [Skotlex]
- BUILDIN_DEF(petskillattack2,"viiii"), // [Valaris]
- BUILDIN_DEF(petskillsupport,"viiii"), // [Skotlex]
- BUILDIN_DEF(skilleffect,"vi"), // skill effect [Celest]
- BUILDIN_DEF(npcskilleffect,"viii"), // npc skill effect [Valaris]
- BUILDIN_DEF(specialeffect,"i*"), // npc skill effect [Valaris]
- BUILDIN_DEF(specialeffect2,"i*"), // skill effect on players[Valaris]
- BUILDIN_DEF(nude,""), // nude command [Valaris]
- BUILDIN_DEF(mapwarp,"ssii*"), // Added by RoVeRT
- BUILDIN_DEF(atcommand,"*"), // [MouseJstr]
- BUILDIN_DEF(charcommand,"*"), // [MouseJstr]
- BUILDIN_DEF(movenpc,"sii"), // [MouseJstr]
- BUILDIN_DEF(message,"s*"), // [MouseJstr]
- BUILDIN_DEF(npctalk,"*"), // [Valaris]
- BUILDIN_DEF(mobcount,"ss"),
- BUILDIN_DEF(getlook,"i"),
- BUILDIN_DEF(getsavepoint,"i"),
- BUILDIN_DEF(npcspeed,"i"), // [Valaris]
- BUILDIN_DEF(npcwalkto,"ii"), // [Valaris]
- BUILDIN_DEF(npcstop,""), // [Valaris]
- BUILDIN_DEF(getmapxy,"siii*"), //by Lorky [Lupus]
- BUILDIN_DEF(checkoption1,"i"),
- BUILDIN_DEF(checkoption2,"i"),
- BUILDIN_DEF(guildgetexp,"i"),
- BUILDIN_DEF(guildchangegm,"is"),
- BUILDIN_DEF(logmes,"s"), //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
- BUILDIN_DEF(summon,"si*"), // summons a slave monster [Celest]
- BUILDIN_DEF(isnight,""), // check whether it is night time [Celest]
- BUILDIN_DEF(isday,""), // check whether it is day time [Celest]
- BUILDIN_DEF(isequipped,"i*"), // check whether another item/card has been equipped [Celest]
- BUILDIN_DEF(isequippedcnt,"i*"), // check how many items/cards are being equipped [Celest]
- BUILDIN_DEF(cardscnt,"i*"), // check how many items/cards are being equipped in the same arm [Lupus]
- BUILDIN_DEF(getrefine,"*"), // returns the refined number of the current item, or an item with index specified [celest]
- BUILDIN_DEF(night,""), // sets the server to night time
- BUILDIN_DEF(day,""), // sets the server to day time
- #ifdef PCRE_SUPPORT
- BUILDIN_DEF(defpattern,"iss"), // Define pattern to listen for [MouseJstr]
- BUILDIN_DEF(activatepset,"i"), // Activate a pattern set [MouseJstr]
- BUILDIN_DEF(deactivatepset,"i"), // Deactive a pattern set [MouseJstr]
- BUILDIN_DEF(deletepset,"i"), // Delete a pattern set [MouseJstr]
- #endif
- BUILDIN_DEF(dispbottom,"s"), //added from jA [Lupus]
- BUILDIN_DEF(getusersname,"*"),
- BUILDIN_DEF(recovery,""),
- BUILDIN_DEF(getpetinfo,"i"),
- BUILDIN_DEF(gethominfo,"i"),
- BUILDIN_DEF(checkequipedcard,"i"),
- BUILDIN_DEF(jump_zero,"ii"), //for future jA script compatibility
- BUILDIN_DEF(globalmes,"s*"),
- BUILDIN_DEF(getmapmobs,"s"), //end jA addition
- BUILDIN_DEF(unequip,"i"), // unequip command [Spectre]
- BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris]
- BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris]
- BUILDIN_DEF(setnpcdisplay,"sv??"),
- BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine.
- BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info
- BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info
- BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
- // [zBuffer] List of mathematics commands --->
- BUILDIN_DEF(sqrt,"i"),
- BUILDIN_DEF(pow,"ii"),
- BUILDIN_DEF(distance,"iiii"),
- // <--- [zBuffer] List of mathematics commands
- BUILDIN_DEF(md5,"s"),
- // [zBuffer] List of dynamic var commands --->
- BUILDIN_DEF(getd,"*"),
- BUILDIN_DEF(setd,"*"),
- // <--- [zBuffer] List of dynamic var commands
- BUILDIN_DEF(petstat,"i"),
- BUILDIN_DEF(callshop,"si"), // [Skotlex]
- BUILDIN_DEF(npcshopitem,"sii*"), // [Lance]
- BUILDIN_DEF(npcshopadditem,"sii*"),
- BUILDIN_DEF(npcshopdelitem,"si*"),
- BUILDIN_DEF(npcshopattach,"s?"),
- BUILDIN_DEF(equip,"i"),
- BUILDIN_DEF(autoequip,"ii"),
- BUILDIN_DEF(setbattleflag,"ss"),
- BUILDIN_DEF(getbattleflag,"s"),
- BUILDIN_DEF(setitemscript,"is*"), //Set NEW item bonus script. Lupus
- BUILDIN_DEF(disguise,"i"), //disguise player. Lupus
- BUILDIN_DEF(undisguise,"*"), //undisguise player. Lupus
- BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus
- BUILDIN_DEF(axtoi,"s"),
- BUILDIN_DEF(query_sql,"s*"),
- BUILDIN_DEF(query_logsql,"s*"),
- BUILDIN_DEF(escape_sql,"s"),
- BUILDIN_DEF(atoi,"s"),
- // [zBuffer] List of player cont commands --->
- BUILDIN_DEF(rid2name,"i"),
- BUILDIN_DEF(pcfollow,"ii"),
- BUILDIN_DEF(pcstopfollow,"i"),
- BUILDIN_DEF(pcblockmove,"ii"),
- // <--- [zBuffer] List of player cont commands
- // [zBuffer] List of mob control commands --->
- BUILDIN_DEF(unitwalk,"ii?"),
- BUILDIN_DEF(unitkill,"i"),
- BUILDIN_DEF(unitwarp,"isii"),
- BUILDIN_DEF(unitattack,"iv?"),
- BUILDIN_DEF(unitstop,"i"),
- BUILDIN_DEF(unittalk,"is"),
- BUILDIN_DEF(unitemote,"ii"),
- BUILDIN_DEF(unitskilluseid,"ivi?"), // originally by Qamera [Celest]
- BUILDIN_DEF(unitskillusepos,"iviii"), // [Celest]
- // <--- [zBuffer] List of mob control commands
- BUILDIN_DEF(sleep,"i"),
- BUILDIN_DEF(sleep2,"i"),
- BUILDIN_DEF(awake,"s"),
- BUILDIN_DEF(getvariableofnpc,"rs"),
- BUILDIN_DEF(warpportal,"iisii"),
- BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn]
- BUILDIN_DEF2(homunculus_shuffle,"homshuffle",""), //[Zephyrus]
- BUILDIN_DEF(eaclass,"*"), //[Skotlex]
- BUILDIN_DEF(roclass,"i*"), //[Skotlex]
- BUILDIN_DEF(checkvending,"*"),
- BUILDIN_DEF(checkchatting,"*"),
- BUILDIN_DEF(openmail,""),
- BUILDIN_DEF(openauction,""),
- BUILDIN_DEF(checkcell,"siii"),
- BUILDIN_DEF(setcell,"siiiiii"),
- BUILDIN_DEF(setwall,"siiiiis"),
- BUILDIN_DEF(delwall,"s"),
- BUILDIN_DEF(searchitem,"rs"),
- BUILDIN_DEF(mercenary_create,"ii"),
- BUILDIN_DEF(mercenary_heal,"ii"),
- BUILDIN_DEF(mercenary_sc_start,"iii"),
- BUILDIN_DEF(mercenary_get_calls,"i"),
- BUILDIN_DEF(mercenary_get_faith,"i"),
- BUILDIN_DEF(mercenary_set_calls,"ii"),
- BUILDIN_DEF(mercenary_set_faith,"ii"),
- BUILDIN_DEF(readbook,"ii"),
- BUILDIN_DEF(setfont,"i"),
- BUILDIN_DEF(areamobuseskill,"siiiiviiiii"),
- BUILDIN_DEF(progressbar, "si"),
- BUILDIN_DEF(pushpc,"ii"),
- // WoE SE
- BUILDIN_DEF(agitstart2,""),
- BUILDIN_DEF(agitend2,""),
- BUILDIN_DEF(agitcheck2,""),
- // BattleGround
- BUILDIN_DEF(waitingroom2bg,"siiss?"),
- BUILDIN_DEF(waitingroom2bg_single,"isiis"),
- BUILDIN_DEF(bg_team_setxy,"iii"),
- BUILDIN_DEF(bg_warp,"isii"),
- BUILDIN_DEF(bg_monster,"isiisi*"),
- BUILDIN_DEF(bg_monster_set_team,"ii"),
- BUILDIN_DEF(bg_leave,""),
- BUILDIN_DEF(bg_destroy,"i"),
- BUILDIN_DEF(areapercentheal,"siiiiii"),
- BUILDIN_DEF(bg_get_data,"ii"),
- BUILDIN_DEF(bg_getareausers,"isiiii"),
- BUILDIN_DEF(bg_updatescore,"sii"),
- // Instancing
- BUILDIN_DEF(instance_create,"si"),
- BUILDIN_DEF(instance_destroy,"?"),
- BUILDIN_DEF(instance_attachmap,"si?"),
- BUILDIN_DEF(instance_detachmap,"s?"),
- BUILDIN_DEF(instance_attach,"i"),
- BUILDIN_DEF(instance_id,"?"),
- BUILDIN_DEF(instance_set_timeout,"ii?"),
- BUILDIN_DEF(instance_init,"i"),
- BUILDIN_DEF(instance_announce,"isi*"),
- BUILDIN_DEF(instance_npcname,"s?"),
- BUILDIN_DEF(has_instance,"s?"),
- BUILDIN_DEF(instance_warpall,"sii?"),
- //Quest Log System [Inkfish]
- BUILDIN_DEF(setquest, "i"),
- BUILDIN_DEF(erasequest, "i"),
- BUILDIN_DEF(completequest, "i"),
- BUILDIN_DEF(checkquest, "i*"),
- BUILDIN_DEF(changequest, "ii"),
- BUILDIN_DEF(showevent, "ii"),
- {NULL,NULL,NULL},
- };
|