script.c 342 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. //#define DEBUG_FUNCIN
  4. //#define DEBUG_DISP
  5. //#define DEBUG_RUN
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #ifndef _WIN32
  13. #include <sys/time.h>
  14. #endif
  15. #include <time.h>
  16. #include <setjmp.h>
  17. #include "../common/cbasetypes.h"
  18. #include "../common/socket.h"
  19. #include "../common/timer.h"
  20. #include "../common/malloc.h"
  21. #include "../common/lock.h"
  22. #include "../common/nullpo.h"
  23. #include "../common/showmsg.h"
  24. #include "../common/strlib.h"
  25. #include "../common/utils.h"
  26. #include "map.h"
  27. #include "clif.h"
  28. #include "chrif.h"
  29. #include "itemdb.h"
  30. #include "pc.h"
  31. #include "status.h"
  32. #include "script.h"
  33. #include "storage.h"
  34. #include "mob.h"
  35. #include "npc.h"
  36. #include "pet.h"
  37. #include "mercenary.h" //[orn]
  38. #include "intif.h"
  39. #include "skill.h"
  40. #include "chat.h"
  41. #include "battle.h"
  42. #include "party.h"
  43. #include "guild.h"
  44. #include "atcommand.h"
  45. #include "charcommand.h"
  46. #include "log.h"
  47. #include "unit.h"
  48. #include "irc.h"
  49. #include "pet.h"
  50. #define FETCH(n, t) \
  51. if(st->end>st->start+(n)) \
  52. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  53. #define SCRIPT_BLOCK_SIZE 512
  54. enum { LABEL_NEXTLINE=1,LABEL_START };
  55. static unsigned char * script_buf = NULL;
  56. static int script_pos,script_size;
  57. #define GETVALUE(buf,i) ((int)MakeDWord(MakeWord((buf)[i],(buf)[i+1]),MakeWord((buf)[i+2],0)))
  58. #define SETVALUE(buf,i,n) ((buf)[i]=GetByte(n,0),(buf)[i+1]=GetByte(n,1),(buf)[i+2]=GetByte(n,2))
  59. #define GETSTRING(off) (str_buf+(off))
  60. static char *str_buf;
  61. static int str_pos,str_size;
  62. static struct str_data_struct {
  63. int type;
  64. int str;
  65. int backpatch;
  66. int label;
  67. int (*func)(struct script_state *st);
  68. int val;
  69. int next;
  70. } *str_data = NULL;
  71. int str_num=LABEL_START,str_data_size;
  72. int str_hash[16];
  73. static struct dbt *mapreg_db=NULL;
  74. static struct dbt *mapregstr_db=NULL;
  75. static int mapreg_dirty=-1;
  76. char mapreg_txt[256]="save/mapreg.txt";
  77. #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
  78. static struct dbt *scriptlabel_db=NULL;
  79. static struct dbt *userfunc_db=NULL;
  80. static int parse_options=0;
  81. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  82. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  83. static char pos[11][100] = {"Head","Body","Left hand","Right hand","Robe","Shoes","Accessory 1","Accessory 2","Head 2","Head 3","Not Equipped"};
  84. struct Script_Config script_config;
  85. static int parse_cmd;
  86. static jmp_buf error_jump;
  87. static char* error_msg;
  88. static const char* error_pos;
  89. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  90. // [Eoe / jA 1080, 1081, 1094, 1164]
  91. enum curly_type { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  92. static struct {
  93. struct {
  94. int type;
  95. int index;
  96. int count;
  97. int flag;
  98. } curly[256]; // 右カッコの情報
  99. int curly_count; // 右カッコの数
  100. int index; // スクリプト内で使用した構文の数
  101. } syntax;
  102. const char* parse_curly_close(const char* p);
  103. const char* parse_syntax_close(const char* p);
  104. const char* parse_syntax_close_sub(const char* p,int* flag);
  105. const char* parse_syntax(const char* p);
  106. static int parse_syntax_for_flag = 0;
  107. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  108. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  109. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  110. int potion_target=0;
  111. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  112. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  113. char mapregsql_db[32] = "mapreg";
  114. char mapregsql_db_varname[32] = "varname";
  115. char mapregsql_db_index[32] = "index";
  116. char mapregsql_db_value[32] = "value";
  117. char tmp_sql[65535];
  118. // --------------------------------------------------------
  119. #endif
  120. int get_com(unsigned char *script,int *pos);
  121. int get_num(unsigned char *script,int *pos);
  122. extern struct script_function {
  123. int (*func)(struct script_state *st);
  124. char *name;
  125. char *arg;
  126. } buildin_func[];
  127. static struct linkdb_node *sleep_db;
  128. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  129. /*==========================================
  130. * ローカルプロトタイプ宣言 (必要な物のみ)
  131. *------------------------------------------
  132. */
  133. const char* parse_subexpr(const char* p,int limit);
  134. void push_val(struct script_stack *stack,int type,int val);
  135. int run_func(struct script_state *st);
  136. int mapreg_setreg(int num,int val);
  137. int mapreg_setregstr(int num,const char *str);
  138. static void disp_error_message(const char *mes,const char *pos);
  139. enum c_op {
  140. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  141. C_NAME,C_EOL, C_RETINFO,
  142. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  143. C_OP3,C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  144. C_XOR,C_OR,C_AND,C_ADD,C_SUB,C_MUL,C_DIV,C_MOD,C_NEG,C_LNOT,C_NOT,C_R_SHIFT,C_L_SHIFT
  145. };
  146. enum {
  147. MF_NOMEMO, //0
  148. MF_NOTELEPORT,
  149. MF_NOSAVE,
  150. MF_NOBRANCH,
  151. MF_NOPENALTY,
  152. MF_NOZENYPENALTY,
  153. MF_PVP,
  154. MF_PVP_NOPARTY,
  155. MF_PVP_NOGUILD,
  156. MF_GVG,
  157. MF_GVG_NOPARTY, //10
  158. MF_NOTRADE,
  159. MF_NOSKILL,
  160. MF_NOWARP,
  161. MF_PARTYLOCK,
  162. MF_NOICEWALL,
  163. MF_SNOW,
  164. MF_FOG,
  165. MF_SAKURA,
  166. MF_LEAVES,
  167. MF_RAIN, //20
  168. MF_INDOORS,
  169. MF_NOGO,
  170. MF_CLOUDS,
  171. MF_CLOUDS2,
  172. MF_FIREWORKS,
  173. MF_GVG_CASTLE,
  174. MF_GVG_DUNGEON,
  175. MF_NIGHTENABLED,
  176. MF_NOBASEEXP,
  177. MF_NOJOBEXP, //30
  178. MF_NOMOBLOOT,
  179. MF_NOMVPLOOT,
  180. MF_NORETURN,
  181. MF_NOWARPTO,
  182. MF_NIGHTMAREDROP,
  183. MF_RESTRICTED,
  184. MF_NOCOMMAND,
  185. MF_NODROP,
  186. MF_JEXP,
  187. MF_BEXP, //40
  188. MF_NOVENDING,
  189. MF_LOADEVENT,
  190. MF_NOCHAT,
  191. MF_NOEXPPENALTY,
  192. MF_GUILDLOCK
  193. };
  194. //Reports on the console the src of an script error.
  195. static void report_src(struct script_state *st) {
  196. struct block_list *bl;
  197. if (!st->oid) return; //Can't report source.
  198. bl = map_id2bl(st->oid);
  199. if (!bl) return;
  200. switch (bl->type) {
  201. case BL_NPC:
  202. if (bl->m >=0)
  203. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  204. else
  205. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  206. break;
  207. default:
  208. if (bl->m >=0)
  209. 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);
  210. else
  211. ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl));
  212. break;
  213. }
  214. }
  215. static void check_event(struct script_state *st, const char *event){
  216. if(event != NULL && event[0] != '\0' && !stristr(event,"::On")){
  217. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  218. report_src(st);
  219. }
  220. return;
  221. }
  222. /*==========================================
  223. * 文字列のハッシュを計算
  224. *------------------------------------------
  225. */
  226. static int calc_hash(const unsigned char *p)
  227. {
  228. int h=0;
  229. while(*p){
  230. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  231. h+=*p++;
  232. }
  233. return h&15;
  234. }
  235. /*==========================================
  236. * str_dataの中に名前があるか検索する
  237. *------------------------------------------
  238. */
  239. // 既存のであれば番号、無ければ-1
  240. static int search_str(const char *p)
  241. {
  242. int i;
  243. i=str_hash[calc_hash(p)];
  244. while(i){
  245. if(strcmp(str_buf+str_data[i].str,p)==0){
  246. return i;
  247. }
  248. i=str_data[i].next;
  249. }
  250. return -1;
  251. }
  252. /*==========================================
  253. * str_dataに名前を登録
  254. *------------------------------------------
  255. */
  256. // 既存のであれば番号、無ければ登録して新規番号
  257. int add_str(const char* p)
  258. {
  259. int i;
  260. int len;
  261. char* lowcase;
  262. lowcase=aStrdup(p);
  263. for(i=0;lowcase[i];i++)
  264. lowcase[i]=TOLOWER(lowcase[i]);
  265. if((i=search_str(lowcase))>=0){
  266. aFree(lowcase);
  267. return i;
  268. }
  269. aFree(lowcase);
  270. i=calc_hash(p);
  271. if(str_hash[i]==0){
  272. str_hash[i]=str_num;
  273. } else {
  274. i=str_hash[i];
  275. for(;;){
  276. if(strcmp(str_buf+str_data[i].str,p)==0){
  277. return i;
  278. }
  279. if(str_data[i].next==0)
  280. break;
  281. i=str_data[i].next;
  282. }
  283. str_data[i].next=str_num;
  284. }
  285. if(str_num>=str_data_size){
  286. str_data_size+=128;
  287. RECREATE(str_data,struct str_data_struct,str_data_size);
  288. malloc_tsetdword(str_data + (str_data_size - 128), '\0', 128);
  289. }
  290. len=(int)strlen(p);
  291. while(str_pos+len+1>=str_size){
  292. str_size+=256;
  293. RECREATE(str_buf,char,str_size);
  294. malloc_tsetdword(str_buf + (str_size - 256), '\0', 256);
  295. }
  296. memcpy(str_buf+str_pos,p,len+1);
  297. str_data[str_num].type=C_NOP;
  298. str_data[str_num].str=str_pos;
  299. str_data[str_num].next=0;
  300. str_data[str_num].func=NULL;
  301. str_data[str_num].backpatch=-1;
  302. str_data[str_num].label=-1;
  303. str_pos+=len+1;
  304. return str_num++;
  305. }
  306. /*==========================================
  307. * スクリプトバッファサイズの確認と拡張
  308. *------------------------------------------
  309. */
  310. static void check_script_buf(int size)
  311. {
  312. if(script_pos+size>=script_size){
  313. script_size+=SCRIPT_BLOCK_SIZE;
  314. RECREATE(script_buf,unsigned char,script_size);
  315. malloc_tsetdword(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  316. SCRIPT_BLOCK_SIZE);
  317. }
  318. }
  319. /*==========================================
  320. * スクリプトバッファに1バイト書き込む
  321. *------------------------------------------
  322. */
  323. #define add_scriptb(a) if( script_pos+1>=script_size ) check_script_buf(1); script_buf[script_pos++]=(uint8)(a)
  324. #if 0
  325. static void add_scriptb(int a)
  326. {
  327. check_script_buf(1);
  328. script_buf[script_pos++]=a;
  329. }
  330. #endif
  331. /*==========================================
  332. * スクリプトバッファにデータタイプを書き込む
  333. *------------------------------------------
  334. */
  335. static void add_scriptc(int a)
  336. {
  337. while(a>=0x40){
  338. add_scriptb((a&0x3f)|0x40);
  339. a=(a-0x40)>>6;
  340. }
  341. add_scriptb(a&0x3f);
  342. }
  343. /*==========================================
  344. * スクリプトバッファに整数を書き込む
  345. *------------------------------------------
  346. */
  347. static void add_scripti(int a)
  348. {
  349. while(a>=0x40){
  350. add_scriptb(a|0xc0);
  351. a=(a-0x40)>>6;
  352. }
  353. add_scriptb(a|0x80);
  354. }
  355. /*==========================================
  356. * スクリプトバッファにラベル/変数/関数を書き込む
  357. *------------------------------------------
  358. */
  359. // 最大16Mまで
  360. static void add_scriptl(int l)
  361. {
  362. int backpatch = str_data[l].backpatch;
  363. switch(str_data[l].type){
  364. case C_POS:
  365. case C_USERFUNC_POS:
  366. add_scriptc(C_POS);
  367. add_scriptb(str_data[l].label);
  368. add_scriptb(str_data[l].label>>8);
  369. add_scriptb(str_data[l].label>>16);
  370. break;
  371. case C_NOP:
  372. case C_USERFUNC:
  373. // ラベルの可能性があるのでbackpatch用データ埋め込み
  374. add_scriptc(C_NAME);
  375. str_data[l].backpatch=script_pos;
  376. add_scriptb(backpatch);
  377. add_scriptb(backpatch>>8);
  378. add_scriptb(backpatch>>16);
  379. break;
  380. case C_INT:
  381. add_scripti(abs(str_data[l].val));
  382. if(str_data[l].val < 0) //Notice that this is negative, from jA (Rayce)
  383. add_scriptc(C_NEG);
  384. break;
  385. default:
  386. // もう他の用途と確定してるので数字をそのまま
  387. add_scriptc(C_NAME);
  388. add_scriptb(l);
  389. add_scriptb(l>>8);
  390. add_scriptb(l>>16);
  391. break;
  392. }
  393. }
  394. /*==========================================
  395. * ラベルを解決する
  396. *------------------------------------------
  397. */
  398. void set_label(int l,int pos, const char* script_pos)
  399. {
  400. int i,next;
  401. if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
  402. { //Prevent overwriting constants values and parameters [Skotlex]
  403. disp_error_message("set_label: invalid label name",script_pos);
  404. return;
  405. }
  406. if(str_data[l].label!=-1){
  407. disp_error_message("set_label: dup label ",script_pos);
  408. return;
  409. }
  410. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  411. str_data[l].label=pos;
  412. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  413. next=GETVALUE(script_buf,i);
  414. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  415. SETVALUE(script_buf,i,pos);
  416. i=next;
  417. }
  418. }
  419. /*==========================================
  420. * スペース/コメント読み飛ばし
  421. *------------------------------------------
  422. */
  423. static const char *skip_space(const char *p)
  424. {
  425. for(;;){
  426. while(ISSPACE(*p))
  427. ++p;
  428. if( *p=='/' && p[1]=='/' ){
  429. while(*p && *p!='\n')
  430. ++p;
  431. } else if( *p=='/' && p[1]=='*' ){
  432. p+=2;
  433. if(*p) ++p;
  434. while( *p && (p[-1]!='*' || *p!='/') )
  435. p++;
  436. if(*p)
  437. ++p;
  438. else
  439. disp_error_message("skip_space: unexpected eof @ block comment",p);
  440. } else
  441. break;
  442. }
  443. return p;
  444. }
  445. /*==========================================
  446. * 1単語スキップ
  447. *------------------------------------------
  448. */
  449. static const char *skip_word(const char *p)
  450. {
  451. // prefix
  452. if(*p=='.') p++;
  453. if(*p=='$') p++; // MAP鯖内共有変数用
  454. if(*p=='@') p++; // 一時的変数用(like weiss)
  455. if(*p=='#') p++; // account変数用
  456. if(*p=='#') p++; // ワールドaccount変数用
  457. //# Changing from unsigned char to signed char makes p never be able to go above 0x81, but what IS 0x81 for? [Skotlex]
  458. //# It's for multibyte encodings like Shift-JIS. Unfortunately this can be problematic for singlebyte encodings.
  459. // Using (*p)>>7 would yield the appropriate result but it's better to restrict words to ASCII characters only. [FlavioJS]
  460. while( ISALNUM(*p) || *p == '_' )
  461. ++p;
  462. // postfix
  463. if(*p=='$') p++; // 文字列変数
  464. return p;
  465. }
  466. /// Adds a word to str_data
  467. int add_word(const char *p)
  468. {
  469. char *word;
  470. int len;
  471. int i;
  472. // Check for a word
  473. len = skip_word(p)-p;
  474. if( len == 0 )
  475. disp_error_message("add_word: not a word",p);
  476. // Copy the word
  477. CREATE(word,char,len+1);
  478. memcpy(word,p,len);
  479. word[len]=0;
  480. // add the word
  481. i=add_str(word);
  482. aFree(word);
  483. return i;
  484. }
  485. /*==========================================
  486. * エラーメッセージ出力
  487. *------------------------------------------
  488. */
  489. static void disp_error_message(const char *mes,const char *pos)
  490. {
  491. error_msg = aStrdup(mes);
  492. error_pos = pos;
  493. longjmp( error_jump, 1 );
  494. }
  495. /*==========================================
  496. * 項の解析
  497. *------------------------------------------
  498. */
  499. const char* parse_simpleexpr(const char *p)
  500. {
  501. int i;
  502. p=skip_space(p);
  503. #ifdef DEBUG_FUNCIN
  504. if(battle_config.etc_log)
  505. ShowDebug("parse_simpleexpr %s\n",p);
  506. #endif
  507. if(*p==';' || *p==',')
  508. disp_error_message("parse_simpleexpr: unexpected expr end",p);
  509. if(*p=='('){
  510. p=parse_subexpr(p+1,-1);
  511. p=skip_space(p);
  512. if((*p++)!=')')
  513. disp_error_message("parse_simpleexpr: unmatch ')'",p-1);
  514. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  515. char *np;
  516. i=strtoul(p,&np,0);
  517. add_scripti(i);
  518. p=np;
  519. } else if(*p=='"'){
  520. add_scriptc(C_STR);
  521. p++;
  522. while(*p && *p!='"'){
  523. if(p[-1]<=0x7e && *p=='\\')
  524. p++;
  525. else if(*p=='\n')
  526. disp_error_message("parse_simpleexpr: unexpected newline @ string",p);
  527. add_scriptb(*p++);
  528. }
  529. if(!*p)
  530. disp_error_message("parse_simpleexpr: unexpected eof @ string",p);
  531. add_scriptb(0);
  532. p++; //'"'
  533. } else {
  534. int l;
  535. // label , register , function etc
  536. if(skip_word(p)==p)
  537. disp_error_message("parse_simpleexpr: unexpected character",p);
  538. l=add_word(p);
  539. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  540. p=skip_word(p);
  541. if(str_data[l].type!=C_FUNC && *p=='['){
  542. // array(name[i] => getelementofarray(name,i) )
  543. add_scriptl(search_str("getelementofarray"));
  544. add_scriptc(C_ARG);
  545. add_scriptl(l);
  546. p=parse_subexpr(p+1,-1);
  547. p=skip_space(p);
  548. if((*p++)!=']')
  549. disp_error_message("parse_simpleexpr: unmatch ']'",p-1);
  550. add_scriptc(C_FUNC);
  551. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  552. add_scriptl(search_str("callsub"));
  553. add_scriptc(C_ARG);
  554. add_scriptl(l);
  555. }else
  556. add_scriptl(l);
  557. }
  558. #ifdef DEBUG_FUNCIN
  559. if(battle_config.etc_log)
  560. ShowDebug("parse_simpleexpr end %s\n",p);
  561. #endif
  562. return p;
  563. }
  564. /*==========================================
  565. * 式の解析
  566. *------------------------------------------
  567. */
  568. const char* parse_subexpr(const char* p,int limit)
  569. {
  570. int op,opl,len;
  571. const char* tmpp;
  572. #ifdef DEBUG_FUNCIN
  573. if(battle_config.etc_log)
  574. ShowDebug("parse_subexpr %s\n",p);
  575. #endif
  576. p=skip_space(p);
  577. if(*p=='-'){
  578. tmpp=skip_space(p+1);
  579. if(*tmpp==';' || *tmpp==','){
  580. add_scriptl(LABEL_NEXTLINE);
  581. p++;
  582. return p;
  583. }
  584. }
  585. tmpp=p;
  586. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  587. p=parse_subexpr(p+1,10);
  588. add_scriptc(op);
  589. } else
  590. p=parse_simpleexpr(p);
  591. p=skip_space(p);
  592. while((
  593. (op=C_OP3,opl=0,len=1,*p=='?') ||
  594. (op=C_ADD,opl=8,len=1,*p=='+') ||
  595. (op=C_SUB,opl=8,len=1,*p=='-') ||
  596. (op=C_MUL,opl=9,len=1,*p=='*') ||
  597. (op=C_DIV,opl=9,len=1,*p=='/') ||
  598. (op=C_MOD,opl=9,len=1,*p=='%') ||
  599. (op=C_FUNC,opl=11,len=1,*p=='(') ||
  600. (op=C_LAND,opl=2,len=2,*p=='&' && p[1]=='&') ||
  601. (op=C_AND,opl=6,len=1,*p=='&') ||
  602. (op=C_LOR,opl=1,len=2,*p=='|' && p[1]=='|') ||
  603. (op=C_OR,opl=5,len=1,*p=='|') ||
  604. (op=C_XOR,opl=4,len=1,*p=='^') ||
  605. (op=C_EQ,opl=3,len=2,*p=='=' && p[1]=='=') ||
  606. (op=C_NE,opl=3,len=2,*p=='!' && p[1]=='=') ||
  607. (op=C_R_SHIFT,opl=7,len=2,*p=='>' && p[1]=='>') ||
  608. (op=C_GE,opl=3,len=2,*p=='>' && p[1]=='=') ||
  609. (op=C_GT,opl=3,len=1,*p=='>') ||
  610. (op=C_L_SHIFT,opl=7,len=2,*p=='<' && p[1]=='<') ||
  611. (op=C_LE,opl=3,len=2,*p=='<' && p[1]=='=') ||
  612. (op=C_LT,opl=3,len=1,*p=='<')) && opl>limit){
  613. p+=len;
  614. if(op==C_FUNC){
  615. int i=0;
  616. int j=0;
  617. int func=parse_cmd;
  618. const char *plist[128];
  619. const char *arg = NULL;
  620. if(str_data[parse_cmd].type == C_FUNC){
  621. // 通常の関数
  622. add_scriptc(C_ARG);
  623. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  624. // ユーザー定義関数呼び出し
  625. parse_cmd = search_str("callsub");
  626. i++;
  627. } else
  628. disp_error_message("parse_subexpr: expect command, missing function name or calling undeclared function",tmpp);
  629. func=parse_cmd;
  630. p=skip_space(p);
  631. // check number of arguments of the function
  632. if( str_data[func].type == C_FUNC && script_config.warn_cmd_mismatch_paramnum) {
  633. arg = buildin_func[str_data[func].val].arg;
  634. for(j=0; arg[j]; j++) {
  635. if(arg[j] == '*')
  636. break;
  637. }
  638. }
  639. while(*p && *p!=')' && i<128) {
  640. plist[i]=p;
  641. p=parse_subexpr(p,-1);
  642. p=skip_space(p);
  643. if(*p==',') {
  644. if(arg == NULL || arg[j] == '*' || i+1 < j)
  645. p++; // the next argument is valid, skip the comma
  646. }
  647. else if(*p!=')' && script_config.warn_func_no_comma){
  648. disp_error_message("parse_subexpr: expect ',' or ')' at func params",p);
  649. }
  650. p=skip_space(p);
  651. i++;
  652. }
  653. plist[i]=p;
  654. if(*(p++)!=')')
  655. disp_error_message("parse_subexpr: func request '(' ')'",p-1);
  656. if(arg) {
  657. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) )
  658. disp_error_message("parse_subexpr: illegal number of parameters",plist[min(i,j)]);
  659. }
  660. } else if(op == C_OP3) {
  661. p=parse_subexpr(p,-1);
  662. p=skip_space(p);
  663. if( *(p++) != ':')
  664. disp_error_message("parse_subexpr: need ':'", p-1);
  665. p=parse_subexpr(p,-1);
  666. } else {
  667. p=parse_subexpr(p,opl);
  668. }
  669. add_scriptc(op);
  670. p=skip_space(p);
  671. }
  672. #ifdef DEBUG_FUNCIN
  673. if(battle_config.etc_log)
  674. ShowDebug("parse_subexpr end %s\n",p);
  675. #endif
  676. return p; /* return first untreated operator */
  677. }
  678. /*==========================================
  679. * 式の評価
  680. *------------------------------------------
  681. */
  682. const char* parse_expr(const char *p)
  683. {
  684. #ifdef DEBUG_FUNCIN
  685. if(battle_config.etc_log)
  686. ShowDebug("parse_expr %s\n",p);
  687. #endif
  688. switch(*p){
  689. case ')': case ';': case ':': case '[': case ']':
  690. case '}':
  691. disp_error_message("parse_expr: unexpected char",p);
  692. exit(1);
  693. }
  694. p=parse_subexpr(p,-1);
  695. #ifdef DEBUG_FUNCIN
  696. if(battle_config.etc_log)
  697. ShowDebug("parse_expr end %s\n",p);
  698. #endif
  699. return p;
  700. }
  701. /*==========================================
  702. * 行の解析
  703. *------------------------------------------
  704. */
  705. const char* parse_line(const char* p)
  706. {
  707. int i=0;
  708. int j=0;
  709. int cmd;
  710. const char* plist[128];
  711. const char* p2;
  712. const char *arg=NULL;
  713. char end;
  714. char end2=0;
  715. int old_flag=0;
  716. p=skip_space(p);
  717. if(*p==';') {
  718. // if(); for(); while(); のために閉じ判定
  719. p = parse_syntax_close(p);
  720. return p+1;
  721. }
  722. if(*p==')' && parse_syntax_for_flag)
  723. return p+1;
  724. p = skip_space(p);
  725. if(p[0] == '{') {
  726. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  727. syntax.curly[syntax.curly_count].count = -1;
  728. syntax.curly[syntax.curly_count].index = -1;
  729. syntax.curly_count++;
  730. return p + 1;
  731. } else if(p[0] == '}') {
  732. return parse_curly_close(p);
  733. }
  734. // 構文関連の処理
  735. p2 = parse_syntax(p);
  736. if(p2 != NULL)
  737. return p2;
  738. // 最初は関数名
  739. p2=p;
  740. p=parse_simpleexpr(p);
  741. p=skip_space(p);
  742. if(str_data[parse_cmd].type == C_FUNC){
  743. // 通常の関数
  744. add_scriptc(C_ARG);
  745. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  746. // ユーザー定義関数呼び出し
  747. parse_cmd = search_str("callsub");
  748. i++;
  749. } else
  750. disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p2);
  751. cmd=parse_cmd;
  752. if(parse_syntax_for_flag) {
  753. end = ')';
  754. } else {
  755. end = ';';
  756. }
  757. // Check number of arguments of the function
  758. if( str_data[cmd].type == C_FUNC && script_config.warn_cmd_mismatch_paramnum) {
  759. arg = buildin_func[str_data[cmd].val].arg;
  760. for(j=0; arg[j]; j++) {
  761. if(arg[j] == '*')
  762. break;
  763. }
  764. }
  765. // Check for parenthesis argument list
  766. if( *p == '(' ){
  767. ++p;
  768. end2 = end;
  769. end = ')';
  770. old_flag = parse_syntax_for_flag;
  771. parse_syntax_for_flag = 1;
  772. }
  773. while(p && *p && *p != end && i<128){
  774. plist[i]=p;
  775. p=parse_expr(p);
  776. p=skip_space(p);
  777. // 引数区切りの,処理
  778. if(*p==',') {
  779. if(arg == NULL || arg[j] == '*' || i+1 < j)
  780. p++; // the next argument is valid, skip the comma
  781. }
  782. else if(*p!=end && script_config.warn_cmd_no_comma){
  783. if(parse_syntax_for_flag) {
  784. disp_error_message("parse_line: expect ',' or ')' at cmd params",p);
  785. } else {
  786. disp_error_message("parse_line: expect ',' or ';' at cmd params",p);
  787. }
  788. }
  789. p=skip_space(p);
  790. i++;
  791. }
  792. plist[i]=p;
  793. if( end2 ){ // restore previous ending and recheck
  794. if( *p != ')' )
  795. disp_error_message("parse_line: need ')' to end param list",p);
  796. p=skip_space(p+1);
  797. end = end2;
  798. parse_syntax_for_flag = old_flag;
  799. }
  800. if(!p || *p!=end){
  801. if(parse_syntax_for_flag) {
  802. disp_error_message("parse_line: need ')'",p);
  803. } else {
  804. disp_error_message("parse_line: need ';'",p);
  805. }
  806. }
  807. add_scriptc(C_FUNC);
  808. // if, for , while の閉じ判定
  809. p = parse_syntax_close(p+1);
  810. if(arg) {
  811. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) )
  812. disp_error_message("parse_line: illegal number of parameters",plist[min(i,j)]);
  813. }
  814. return p;
  815. }
  816. // { ... } の閉じ処理
  817. const char* parse_curly_close(const char* p) {
  818. if(syntax.curly_count <= 0) {
  819. disp_error_message("parse_curly_close: unexpected string",p);
  820. return p + 1;
  821. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  822. syntax.curly_count--;
  823. // if, for , while の閉じ判定
  824. p = parse_syntax_close(p + 1);
  825. return p;
  826. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  827. // switch() 閉じ判定
  828. int pos = syntax.curly_count-1;
  829. char label[256];
  830. int l;
  831. // 一時変数を消す
  832. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  833. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  834. parse_line(label);
  835. syntax.curly_count--;
  836. // 無条件で終了ポインタに移動
  837. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  838. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  839. parse_line(label);
  840. syntax.curly_count--;
  841. // 現在地のラベルを付ける
  842. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  843. l=add_str(label);
  844. set_label(l,script_pos, p);
  845. if(syntax.curly[pos].flag) {
  846. // default が存在する
  847. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  848. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  849. parse_line(label);
  850. syntax.curly_count--;
  851. }
  852. // 終了ラベルを付ける
  853. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  854. l=add_str(label);
  855. set_label(l,script_pos, p);
  856. syntax.curly_count--;
  857. return p+1;
  858. } else {
  859. disp_error_message("parse_curly_close: unexpected string",p);
  860. return p + 1;
  861. }
  862. }
  863. // 構文関連の処理
  864. // break, case, continue, default, do, for, function,
  865. // if, switch, while をこの内部で処理します。
  866. const char* parse_syntax(const char* p) {
  867. switch(*p) {
  868. case 'b':
  869. if(!strncmp(p,"break",5) && !ISALPHA(p[5])) {
  870. // break の処理
  871. char label[256];
  872. int pos = syntax.curly_count - 1;
  873. while(pos >= 0) {
  874. if(syntax.curly[pos].type == TYPE_DO) {
  875. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  876. break;
  877. } else if(syntax.curly[pos].type == TYPE_FOR) {
  878. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  879. break;
  880. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  881. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  882. break;
  883. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  884. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  885. break;
  886. }
  887. pos--;
  888. }
  889. if(pos < 0) {
  890. disp_error_message("parse_syntax: unexpected 'break'",p);
  891. } else {
  892. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  893. parse_line(label);
  894. syntax.curly_count--;
  895. }
  896. p = skip_word(p);
  897. p++;
  898. // if, for , while の閉じ判定
  899. p = parse_syntax_close(p + 1);
  900. return p;
  901. }
  902. break;
  903. case 'c':
  904. if(!strncmp(p,"case",4) && !ISALPHA(p[4])) {
  905. // case の処理
  906. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  907. disp_error_message("parse_syntax: unexpected 'case' ",p);
  908. return p+1;
  909. } else {
  910. const char *p2;
  911. char label[256];
  912. int l;
  913. int len;
  914. int pos = syntax.curly_count-1;
  915. if(syntax.curly[pos].count != 1) {
  916. // FALLTHRU 用のジャンプ
  917. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  918. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  919. parse_line(label);
  920. syntax.curly_count--;
  921. // 現在地のラベルを付ける
  922. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  923. l=add_str(label);
  924. set_label(l,script_pos, p);
  925. }
  926. // switch 判定文
  927. p = skip_word(p);
  928. p = skip_space(p);
  929. p2 = p;
  930. p = skip_word(p);
  931. len = p-p2; // length of word at p2
  932. p = skip_space(p);
  933. if(*p != ':')
  934. disp_error_message("parse_syntax: expect ':'",p);
  935. memcpy(label,"if(",3);
  936. memcpy(label+3,p2,len);
  937. sprintf(label+3+len," != $@__SW%x_VAL) goto __SW%x_%x;",
  938. syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  939. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  940. // 2回parse しないとダメ
  941. p2 = parse_line(label);
  942. parse_line(p2);
  943. syntax.curly_count--;
  944. if(syntax.curly[pos].count != 1) {
  945. // FALLTHRU 終了後のラベル
  946. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  947. l=add_str(label);
  948. set_label(l,script_pos,p);
  949. }
  950. // 一時変数を消す
  951. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  952. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  953. parse_line(label);
  954. syntax.curly_count--;
  955. syntax.curly[pos].count++;
  956. }
  957. return p + 1;
  958. } else if(!strncmp(p,"continue",8) && !ISALPHA(p[8])) {
  959. // continue の処理
  960. char label[256];
  961. int pos = syntax.curly_count - 1;
  962. while(pos >= 0) {
  963. if(syntax.curly[pos].type == TYPE_DO) {
  964. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  965. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  966. break;
  967. } else if(syntax.curly[pos].type == TYPE_FOR) {
  968. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  969. break;
  970. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  971. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  972. break;
  973. }
  974. pos--;
  975. }
  976. if(pos < 0) {
  977. disp_error_message("parse_syntax: unexpected 'continue'",p);
  978. } else {
  979. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  980. parse_line(label);
  981. syntax.curly_count--;
  982. }
  983. p = skip_word(p);
  984. p++;
  985. // if, for , while の閉じ判定
  986. p = parse_syntax_close(p + 1);
  987. return p;
  988. }
  989. break;
  990. case 'd':
  991. if(!strncmp(p,"default",7) && !ISALPHA(p[7])) {
  992. // switch - default の処理
  993. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  994. disp_error_message("parse_syntax: unexpected 'default'",p);
  995. return p+1;
  996. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  997. disp_error_message("parse_syntax: dup 'default'",p);
  998. return p+1;
  999. } else {
  1000. char label[256];
  1001. int l;
  1002. int pos = syntax.curly_count-1;
  1003. // 現在地のラベルを付ける
  1004. p = skip_word(p);
  1005. p = skip_space(p);
  1006. if(*p != ':') {
  1007. disp_error_message("parse_syntax: need ':'",p);
  1008. }
  1009. p++;
  1010. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1011. l=add_str(label);
  1012. set_label(l,script_pos,p);
  1013. // 無条件で次のリンクに飛ばす
  1014. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  1015. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1016. parse_line(label);
  1017. syntax.curly_count--;
  1018. // default のラベルを付ける
  1019. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  1020. l=add_str(label);
  1021. set_label(l,script_pos,p);
  1022. syntax.curly[syntax.curly_count - 1].flag = 1;
  1023. syntax.curly[pos].count++;
  1024. p = skip_word(p);
  1025. return p + 1;
  1026. }
  1027. } else if(!strncmp(p,"do",2) && !ISALPHA(p[2])) {
  1028. int l;
  1029. char label[256];
  1030. p=skip_word(p);
  1031. p=skip_space(p);
  1032. syntax.curly[syntax.curly_count].type = TYPE_DO;
  1033. syntax.curly[syntax.curly_count].count = 1;
  1034. syntax.curly[syntax.curly_count].index = syntax.index++;
  1035. syntax.curly[syntax.curly_count].flag = 0;
  1036. // 現在地のラベル形成する
  1037. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  1038. l=add_str(label);
  1039. set_label(l,script_pos,p);
  1040. syntax.curly_count++;
  1041. return p;
  1042. }
  1043. break;
  1044. case 'f':
  1045. if(!strncmp(p,"for",3) && !ISALPHA(p[3])) {
  1046. int l;
  1047. char label[256];
  1048. int pos = syntax.curly_count;
  1049. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1050. syntax.curly[syntax.curly_count].count = 1;
  1051. syntax.curly[syntax.curly_count].index = syntax.index++;
  1052. syntax.curly[syntax.curly_count].flag = 0;
  1053. syntax.curly_count++;
  1054. p=skip_word(p);
  1055. p=skip_space(p);
  1056. if(*p != '(') {
  1057. disp_error_message("parse_syntax: need '('",p);
  1058. return p+1;
  1059. }
  1060. p++;
  1061. // 初期化文を実行する
  1062. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1063. p=parse_line(p);
  1064. syntax.curly_count--;
  1065. // 条件判断開始のラベル形成する
  1066. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1067. l=add_str(label);
  1068. set_label(l,script_pos,p);
  1069. p=skip_space(p);
  1070. if(*p == ';') {
  1071. // for(;;) のパターンなので必ず真
  1072. ;
  1073. } else {
  1074. // 条件が偽なら終了地点に飛ばす
  1075. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1076. add_scriptl(add_str("jump_zero"));
  1077. add_scriptc(C_ARG);
  1078. p=parse_expr(p);
  1079. p=skip_space(p);
  1080. add_scriptl(add_str(label));
  1081. add_scriptc(C_FUNC);
  1082. }
  1083. if(*p != ';') {
  1084. disp_error_message("parse_syntax: need ';'",p);
  1085. return p+1;
  1086. }
  1087. p++;
  1088. // ループ開始に飛ばす
  1089. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1090. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1091. parse_line(label);
  1092. syntax.curly_count--;
  1093. // 次のループへのラベル形成する
  1094. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1095. l=add_str(label);
  1096. set_label(l,script_pos,p);
  1097. // 次のループに入る時の処理
  1098. // for 最後の ')' を ';' として扱うフラグ
  1099. parse_syntax_for_flag = 1;
  1100. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1101. p=parse_line(p);
  1102. syntax.curly_count--;
  1103. parse_syntax_for_flag = 0;
  1104. // 条件判定処理に飛ばす
  1105. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1106. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1107. parse_line(label);
  1108. syntax.curly_count--;
  1109. // ループ開始のラベル付け
  1110. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1111. l=add_str(label);
  1112. set_label(l,script_pos,p);
  1113. return p;
  1114. } else if(!strncmp(p,"function",8) && !ISALPHA(p[8])) {
  1115. const char *func_name;
  1116. // function
  1117. p=skip_word(p);
  1118. p=skip_space(p);
  1119. // function - name
  1120. func_name = p;
  1121. p=skip_word(p);
  1122. if(*skip_space(p) == ';') {
  1123. // 関数の宣言 - 名前を登録して終わり
  1124. int l;
  1125. l=add_word(func_name);
  1126. if(str_data[l].type == C_NOP)
  1127. str_data[l].type = C_USERFUNC;
  1128. return skip_space(p) + 1;
  1129. } else {
  1130. // 関数の中身
  1131. char label[256];
  1132. int l;
  1133. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1134. syntax.curly[syntax.curly_count].count = 1;
  1135. syntax.curly[syntax.curly_count].index = syntax.index++;
  1136. syntax.curly[syntax.curly_count].flag = 0;
  1137. syntax.curly_count++;
  1138. // 関数終了まで飛ばす
  1139. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1140. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1141. parse_line(label);
  1142. syntax.curly_count--;
  1143. // 関数名のラベルを付ける
  1144. l=add_word(func_name);
  1145. if(str_data[l].type == C_NOP)
  1146. str_data[l].type = C_USERFUNC;
  1147. set_label(l,script_pos,p);
  1148. if( parse_options&SCRIPT_USE_LABEL_DB )
  1149. strdb_put(scriptlabel_db, GETSTRING(str_data[l].str), (void*)script_pos);
  1150. return skip_space(p);
  1151. }
  1152. }
  1153. break;
  1154. case 'i':
  1155. if(!strncmp(p,"if",2) && !ISALPHA(p[2])) {
  1156. // if() の処理
  1157. char label[256];
  1158. p=skip_word(p);
  1159. p=skip_space(p);
  1160. if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
  1161. disp_error_message("need '('",p);
  1162. }
  1163. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1164. syntax.curly[syntax.curly_count].count = 1;
  1165. syntax.curly[syntax.curly_count].index = syntax.index++;
  1166. syntax.curly[syntax.curly_count].flag = 0;
  1167. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1168. syntax.curly_count++;
  1169. add_scriptl(add_str("jump_zero"));
  1170. add_scriptc(C_ARG);
  1171. p=parse_expr(p);
  1172. p=skip_space(p);
  1173. add_scriptl(add_str(label));
  1174. add_scriptc(C_FUNC);
  1175. return p;
  1176. }
  1177. break;
  1178. case 's':
  1179. if(!strncmp(p,"switch",6) && !ISALPHA(p[6])) {
  1180. // switch() の処理
  1181. char label[256];
  1182. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1183. syntax.curly[syntax.curly_count].count = 1;
  1184. syntax.curly[syntax.curly_count].index = syntax.index++;
  1185. syntax.curly[syntax.curly_count].flag = 0;
  1186. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1187. syntax.curly_count++;
  1188. add_scriptl(add_str("set"));
  1189. add_scriptc(C_ARG);
  1190. add_scriptl(add_str(label));
  1191. p=skip_word(p);
  1192. p=skip_space(p);
  1193. p=parse_expr(p);
  1194. p=skip_space(p);
  1195. if(*p != '{') {
  1196. disp_error_message("parse_syntax: need '{'",p);
  1197. }
  1198. add_scriptc(C_FUNC);
  1199. return p + 1;
  1200. }
  1201. break;
  1202. case 'w':
  1203. if(!strncmp(p,"while",5) && !ISALPHA(p[5])) {
  1204. int l;
  1205. char label[256];
  1206. p=skip_word(p);
  1207. p=skip_space(p);
  1208. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1209. syntax.curly[syntax.curly_count].count = 1;
  1210. syntax.curly[syntax.curly_count].index = syntax.index++;
  1211. syntax.curly[syntax.curly_count].flag = 0;
  1212. // 条件判断開始のラベル形成する
  1213. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1214. l=add_str(label);
  1215. set_label(l,script_pos,p);
  1216. // 条件が偽なら終了地点に飛ばす
  1217. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1218. add_scriptl(add_str("jump_zero"));
  1219. add_scriptc(C_ARG);
  1220. p=parse_expr(p);
  1221. p=skip_space(p);
  1222. add_scriptl(add_str(label));
  1223. add_scriptc(C_FUNC);
  1224. syntax.curly_count++;
  1225. return p;
  1226. }
  1227. break;
  1228. }
  1229. return NULL;
  1230. }
  1231. const char* parse_syntax_close(const char *p) {
  1232. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1233. int flag;
  1234. do {
  1235. p = parse_syntax_close_sub(p,&flag);
  1236. } while(flag);
  1237. return p;
  1238. }
  1239. // if, for , while , do の閉じ判定
  1240. // flag == 1 : 閉じられた
  1241. // flag == 0 : 閉じられない
  1242. const char* parse_syntax_close_sub(const char* p,int* flag) {
  1243. char label[256];
  1244. int pos = syntax.curly_count - 1;
  1245. int l;
  1246. *flag = 1;
  1247. if(syntax.curly_count <= 0) {
  1248. *flag = 0;
  1249. return p;
  1250. } else if(syntax.curly[pos].type == TYPE_IF) {
  1251. const char *p2 = p;
  1252. // if 最終場所へ飛ばす
  1253. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1254. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1255. parse_line(label);
  1256. syntax.curly_count--;
  1257. // 現在地のラベルを付ける
  1258. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1259. l=add_str(label);
  1260. set_label(l,script_pos,p);
  1261. syntax.curly[pos].count++;
  1262. p = skip_space(p);
  1263. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !ISALPHA(p[4])) {
  1264. // else or else - if
  1265. p = skip_word(p);
  1266. p = skip_space(p);
  1267. if(!strncmp(p,"if",2) && !ISALPHA(p[2])) {
  1268. // else - if
  1269. p=skip_word(p);
  1270. p=skip_space(p);
  1271. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1272. add_scriptl(add_str("jump_zero"));
  1273. add_scriptc(C_ARG);
  1274. p=parse_expr(p);
  1275. p=skip_space(p);
  1276. add_scriptl(add_str(label));
  1277. add_scriptc(C_FUNC);
  1278. *flag = 0;
  1279. return p;
  1280. } else {
  1281. // else
  1282. if(!syntax.curly[pos].flag) {
  1283. syntax.curly[pos].flag = 1;
  1284. *flag = 0;
  1285. return p;
  1286. }
  1287. }
  1288. }
  1289. // if 閉じ
  1290. syntax.curly_count--;
  1291. // 最終地のラベルを付ける
  1292. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1293. l=add_str(label);
  1294. set_label(l,script_pos,p);
  1295. if(syntax.curly[pos].flag == 1) {
  1296. // このifに対するelseじゃないのでポインタの位置は同じ
  1297. return p2;
  1298. }
  1299. return p;
  1300. } else if(syntax.curly[pos].type == TYPE_DO) {
  1301. int l;
  1302. char label[256];
  1303. const char *p2;
  1304. if(syntax.curly[pos].flag) {
  1305. // 現在地のラベル形成する(continue でここに来る)
  1306. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1307. l=add_str(label);
  1308. set_label(l,script_pos,p);
  1309. }
  1310. // 条件が偽なら終了地点に飛ばす
  1311. p = skip_space(p);
  1312. p2 = skip_word(p);
  1313. if(p2 - p != 5 || strncmp("while",p,5)) {
  1314. disp_error_message("parse_syntax: need 'while'",p);
  1315. }
  1316. p = p2;
  1317. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1318. add_scriptl(add_str("jump_zero"));
  1319. add_scriptc(C_ARG);
  1320. p=parse_expr(p);
  1321. p=skip_space(p);
  1322. add_scriptl(add_str(label));
  1323. add_scriptc(C_FUNC);
  1324. // 開始地点に飛ばす
  1325. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1326. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1327. parse_line(label);
  1328. syntax.curly_count--;
  1329. // 条件終了地点のラベル形成する
  1330. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1331. l=add_str(label);
  1332. set_label(l,script_pos,p);
  1333. p = skip_space(p);
  1334. if(*p != ';') {
  1335. disp_error_message("parse_syntax: need ';'",p);
  1336. return p+1;
  1337. }
  1338. p++;
  1339. syntax.curly_count--;
  1340. return p;
  1341. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1342. // 次のループに飛ばす
  1343. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1344. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1345. parse_line(label);
  1346. syntax.curly_count--;
  1347. // for 終了のラベル付け
  1348. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1349. l=add_str(label);
  1350. set_label(l,script_pos,p);
  1351. syntax.curly_count--;
  1352. return p;
  1353. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1354. // while 条件判断へ飛ばす
  1355. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1356. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1357. parse_line(label);
  1358. syntax.curly_count--;
  1359. // while 終了のラベル付け
  1360. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1361. l=add_str(label);
  1362. set_label(l,script_pos,p);
  1363. syntax.curly_count--;
  1364. return p;
  1365. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1366. int pos = syntax.curly_count-1;
  1367. char label[256];
  1368. int l;
  1369. // 戻す
  1370. sprintf(label,"return;");
  1371. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1372. parse_line(label);
  1373. syntax.curly_count--;
  1374. // 現在地のラベルを付ける
  1375. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1376. l=add_str(label);
  1377. set_label(l,script_pos,p);
  1378. syntax.curly_count--;
  1379. return p + 1;
  1380. } else {
  1381. *flag = 0;
  1382. return p;
  1383. }
  1384. }
  1385. /*==========================================
  1386. * 組み込み関数の追加
  1387. *------------------------------------------
  1388. */
  1389. static void add_buildin_func(void)
  1390. {
  1391. int i,n;
  1392. for(i=0;buildin_func[i].func;i++){
  1393. n=add_str(buildin_func[i].name);
  1394. str_data[n].type=C_FUNC;
  1395. str_data[n].val=i;
  1396. str_data[n].func=buildin_func[i].func;
  1397. }
  1398. }
  1399. /*==========================================
  1400. * 定数データベースの読み込み
  1401. *------------------------------------------
  1402. */
  1403. static void read_constdb(void)
  1404. {
  1405. FILE *fp;
  1406. char line[1024],name[1024],val[1024];
  1407. int n,i,type;
  1408. sprintf(line, "%s/const.txt", db_path);
  1409. fp=fopen(line, "r");
  1410. if(fp==NULL){
  1411. ShowError("can't read %s\n", line);
  1412. return ;
  1413. }
  1414. while(fgets(line,1020,fp)){
  1415. if(line[0]=='/' && line[1]=='/')
  1416. continue;
  1417. type=0;
  1418. if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
  1419. sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
  1420. for(i=0;name[i];i++)
  1421. name[i]=TOLOWER(name[i]);
  1422. n=add_str(name);
  1423. if(type==0)
  1424. str_data[n].type=C_INT;
  1425. else
  1426. str_data[n].type=C_PARAM;
  1427. str_data[n].val= (int)strtol(val,NULL,0);
  1428. }
  1429. }
  1430. fclose(fp);
  1431. }
  1432. /*==========================================
  1433. * エラー表示
  1434. *------------------------------------------
  1435. */
  1436. const char* script_print_line( const char *p, const char *mark, int line ) {
  1437. int i;
  1438. if( p == NULL || !p[0] ) return NULL;
  1439. if( line < 0 )
  1440. printf("*% 5d : ", -line);
  1441. else
  1442. printf(" % 5d : ", line);
  1443. for(i=0;p[i] && p[i] != '\n';i++){
  1444. if(p + i != mark)
  1445. printf("%c",p[i]);
  1446. else
  1447. printf("\'%c\'",p[i]);
  1448. }
  1449. printf("\n");
  1450. return p+i+(p[i] == '\n' ? 1 : 0);
  1451. }
  1452. void script_error(const char *src,const char *file,int start_line, const char *error_msg, const char *error_pos) {
  1453. // エラーが発生した行を求める
  1454. int j;
  1455. int line = start_line;
  1456. const char *p;
  1457. const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
  1458. for(p=src;p && *p;line++){
  1459. char *lineend=strchr(p,'\n');
  1460. if(lineend==NULL || error_pos<lineend){
  1461. break;
  1462. }
  1463. for( j = 0; j < 4; j++ ) {
  1464. linestart[j] = linestart[j+1];
  1465. }
  1466. linestart[4] = p;
  1467. p=lineend+1;
  1468. }
  1469. printf("\a\n");
  1470. printf("script error on %s line %d\n", file, line);
  1471. printf(" %s\n", error_msg);
  1472. for(j = 0; j < 5; j++ ) {
  1473. script_print_line( linestart[j], NULL, line + j - 5);
  1474. }
  1475. p = script_print_line( p, error_pos, -line);
  1476. for(j = 0; j < 5; j++) {
  1477. p = script_print_line( p, NULL, line + j + 1 );
  1478. }
  1479. }
  1480. /*==========================================
  1481. * スクリプトの解析
  1482. *------------------------------------------
  1483. */
  1484. struct script_code* parse_script(const char *src,const char *file,int line,int options)
  1485. {
  1486. const char *p,*tmpp;
  1487. int i;
  1488. struct script_code *code;
  1489. static int first=1;
  1490. malloc_set(&syntax,0,sizeof(syntax));
  1491. if(first){
  1492. add_buildin_func();
  1493. read_constdb();
  1494. }
  1495. first=0;
  1496. CREATE(script_buf,unsigned char,SCRIPT_BLOCK_SIZE);
  1497. script_pos=0;
  1498. script_size=SCRIPT_BLOCK_SIZE;
  1499. str_data[LABEL_NEXTLINE].type=C_NOP;
  1500. str_data[LABEL_NEXTLINE].backpatch=-1;
  1501. str_data[LABEL_NEXTLINE].label=-1;
  1502. for(i=LABEL_START;i<str_num;i++){
  1503. if(
  1504. str_data[i].type==C_POS || str_data[i].type==C_NAME ||
  1505. str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  1506. ){
  1507. str_data[i].type=C_NOP;
  1508. str_data[i].backpatch=-1;
  1509. str_data[i].label=-1;
  1510. }
  1511. }
  1512. // who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
  1513. if( options&SCRIPT_USE_LABEL_DB )
  1514. scriptlabel_db->clear(scriptlabel_db, NULL);
  1515. parse_options = options;
  1516. if( setjmp( error_jump ) != 0 ) {
  1517. //Restore program state when script has problems. [from jA]
  1518. script_error(src,file,line,error_msg,error_pos);
  1519. aFree( error_msg );
  1520. aFree( script_buf );
  1521. script_pos = 0;
  1522. script_size = 0;
  1523. script_buf = NULL;
  1524. for(i=LABEL_START;i<str_num;i++){
  1525. if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
  1526. }
  1527. return NULL;
  1528. }
  1529. parse_syntax_for_flag=0;
  1530. p=src;
  1531. p=skip_space(p);
  1532. if(*p!='{'){
  1533. disp_error_message("not found '{'",p);
  1534. }
  1535. p++;
  1536. p = skip_space(p);
  1537. if (p && *p == '}') {
  1538. // an empty function, just return
  1539. aFree( script_buf );
  1540. script_pos = 0;
  1541. script_size = 0;
  1542. script_buf = NULL;
  1543. return NULL;
  1544. }
  1545. while (p && *p && (*p!='}' || syntax.curly_count != 0)) {
  1546. p=skip_space(p);
  1547. // labelだけ特殊処理
  1548. tmpp=skip_space(skip_word(p));
  1549. if(*tmpp==':' && !(!strncmp(p,"default:",8) && p + 7 == tmpp)){
  1550. i=add_word(p);
  1551. set_label(i,script_pos,p);
  1552. if( parse_options&SCRIPT_USE_LABEL_DB )
  1553. strdb_put(scriptlabel_db, GETSTRING(str_data[i].str), (void*)script_pos);
  1554. p=tmpp+1;
  1555. continue;
  1556. }
  1557. // 他は全部一緒くた
  1558. p=parse_line(p);
  1559. p=skip_space(p);
  1560. add_scriptc(C_EOL);
  1561. set_label(LABEL_NEXTLINE,script_pos,p);
  1562. str_data[LABEL_NEXTLINE].type=C_NOP;
  1563. str_data[LABEL_NEXTLINE].backpatch=-1;
  1564. str_data[LABEL_NEXTLINE].label=-1;
  1565. }
  1566. add_scriptc(C_NOP);
  1567. script_size = script_pos;
  1568. RECREATE(script_buf,unsigned char,script_pos);
  1569. // 未解決のラベルを解決
  1570. for(i=LABEL_START;i<str_num;i++){
  1571. if(str_data[i].type==C_NOP){
  1572. int j,next;
  1573. str_data[i].type=C_NAME;
  1574. str_data[i].label=i;
  1575. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1576. next=GETVALUE(script_buf,j);
  1577. SETVALUE(script_buf,j,i);
  1578. j=next;
  1579. }
  1580. }
  1581. }
  1582. #ifdef DEBUG_DISP
  1583. for(i=0;i<script_pos;i++){
  1584. if((i&15)==0) printf("%04x : ",i);
  1585. printf("%02x ",script_buf[i]);
  1586. if((i&15)==15) printf("\n");
  1587. }
  1588. printf("\n");
  1589. #endif
  1590. CREATE(code,struct script_code,1);
  1591. code->script_buf = script_buf;
  1592. code->script_size = script_size;
  1593. code->script_vars = NULL;
  1594. return code;
  1595. }
  1596. //
  1597. // 実行系
  1598. //
  1599. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  1600. /*==========================================
  1601. * ridからsdへの解決
  1602. *------------------------------------------
  1603. */
  1604. struct map_session_data *script_rid2sd(struct script_state *st)
  1605. {
  1606. struct map_session_data *sd=map_id2sd(st->rid);
  1607. if(!sd){
  1608. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  1609. report_src(st);
  1610. }
  1611. return sd;
  1612. }
  1613. /*==========================================
  1614. * 変数の読み取り
  1615. *------------------------------------------
  1616. */
  1617. int get_val(struct script_state*st,struct script_data* data)
  1618. {
  1619. struct map_session_data *sd=NULL;
  1620. if(data->type==C_NAME){
  1621. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1622. char prefix=*name;
  1623. char postfix=name[strlen(name)-1];
  1624. if(not_server_variable(prefix)){
  1625. if((sd=script_rid2sd(st))==NULL)
  1626. ShowError("get_val error name?:%s\n",name);
  1627. }
  1628. if(postfix=='$'){
  1629. data->type=C_CONSTSTR;
  1630. if( prefix=='@'){
  1631. if(sd)
  1632. data->u.str = pc_readregstr(sd,data->u.num);
  1633. }else if(prefix=='$'){
  1634. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  1635. }else if(prefix=='#'){
  1636. if( name[1]=='#'){
  1637. if(sd)
  1638. data->u.str = pc_readaccountreg2str(sd,name);
  1639. }else{
  1640. if(sd)
  1641. data->u.str = pc_readaccountregstr(sd,name);
  1642. }
  1643. }else if(prefix=='.') {
  1644. struct linkdb_node **n;
  1645. if( data->ref ) {
  1646. n = data->ref;
  1647. } else if( name[1] == '@' ) {
  1648. n = st->stack->var_function;
  1649. } else {
  1650. n = &st->script->script_vars;
  1651. }
  1652. data->u.str = linkdb_search(n, (void*)data->u.num );
  1653. }else{
  1654. if(sd)
  1655. data->u.str = pc_readglobalreg_str(sd,name);
  1656. } // [zBuffer]
  1657. /*else{
  1658. ShowWarning("script: get_val: illegal scope string variable.\n");
  1659. data->u.str = "!!ERROR!!";
  1660. }*/
  1661. if( data->u.str == NULL )
  1662. data->u.str ="";
  1663. }else{
  1664. data->type=C_INT;
  1665. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1666. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1667. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1668. if(sd)
  1669. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1670. }else if(prefix=='@'){
  1671. if(sd)
  1672. data->u.num = pc_readreg(sd,data->u.num);
  1673. }else if(prefix=='$'){
  1674. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  1675. }else if(prefix=='#'){
  1676. if( name[1]=='#'){
  1677. if(sd)
  1678. data->u.num = pc_readaccountreg2(sd,name);
  1679. }else{
  1680. if(sd)
  1681. data->u.num = pc_readaccountreg(sd,name);
  1682. }
  1683. }else if(prefix=='.'){
  1684. struct linkdb_node **n;
  1685. if( data->ref ) {
  1686. n = data->ref;
  1687. } else if( name[1] == '@' ) {
  1688. n = st->stack->var_function;
  1689. } else {
  1690. n = &st->script->script_vars;
  1691. }
  1692. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  1693. }else{
  1694. if(sd)
  1695. data->u.num = pc_readglobalreg(sd,name);
  1696. }
  1697. }
  1698. }
  1699. return 0;
  1700. }
  1701. /*==========================================
  1702. * 変数の読み取り2
  1703. *------------------------------------------
  1704. */
  1705. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  1706. {
  1707. struct script_data dat;
  1708. dat.type=C_NAME;
  1709. dat.u.num=num;
  1710. dat.ref=ref;
  1711. get_val(st,&dat);
  1712. if( dat.type==C_INT ) return (void*)dat.u.num;
  1713. else return (void*)dat.u.str;
  1714. }
  1715. /*==========================================
  1716. * 変数設定用
  1717. *------------------------------------------
  1718. */
  1719. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  1720. {
  1721. char prefix=*name;
  1722. char postfix=name[strlen(name)-1];
  1723. if( postfix=='$' ){
  1724. char *str=(char*)v;
  1725. if( prefix=='@'){
  1726. pc_setregstr(sd,num,str);
  1727. }else if(prefix=='$') {
  1728. mapreg_setregstr(num,str);
  1729. }else if(prefix=='#') {
  1730. if( name[1]=='#' )
  1731. pc_setaccountreg2str(sd,name,str);
  1732. else
  1733. pc_setaccountregstr(sd,name,str);
  1734. }else if(prefix=='.') {
  1735. char *p;
  1736. struct linkdb_node **n;
  1737. if( ref ) {
  1738. n = ref;
  1739. } else if( name[1] == '@' ) {
  1740. n = st->stack->var_function;
  1741. } else {
  1742. n = &st->script->script_vars;
  1743. }
  1744. p = linkdb_search(n, (void*)num);
  1745. if(p) {
  1746. linkdb_erase(n, (void*)num);
  1747. aFree(p);
  1748. }
  1749. if( ((char*)v)[0] )
  1750. linkdb_insert(n, (void*)num, aStrdup(v));
  1751. }else{
  1752. pc_setglobalreg_str(sd,name,str);
  1753. } // [zBuffer]
  1754. }else{
  1755. // 数値
  1756. int val = (int)v;
  1757. if(str_data[num&0x00ffffff].type==C_PARAM){
  1758. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1759. }else if(prefix=='@') {
  1760. pc_setreg(sd,num,val);
  1761. }else if(prefix=='$') {
  1762. mapreg_setreg(num,val);
  1763. }else if(prefix=='#') {
  1764. if( name[1]=='#' )
  1765. pc_setaccountreg2(sd,name,val);
  1766. else
  1767. pc_setaccountreg(sd,name,val);
  1768. }else if(prefix == '.') {
  1769. struct linkdb_node **n;
  1770. if( ref ) {
  1771. n = ref;
  1772. } else if( name[1] == '@' ) {
  1773. n = st->stack->var_function;
  1774. } else {
  1775. n = &st->script->script_vars;
  1776. }
  1777. if( val == 0 ) {
  1778. linkdb_erase(n, (void*)num);
  1779. } else {
  1780. linkdb_replace(n, (void*)num, (void*)val);
  1781. }
  1782. }else{
  1783. pc_setglobalreg(sd,name,val);
  1784. }
  1785. }
  1786. return 0;
  1787. }
  1788. int set_var(struct map_session_data *sd, char *name, void *val)
  1789. {
  1790. return set_reg(NULL, sd, add_str(name), name, val, NULL);
  1791. }
  1792. /*==========================================
  1793. * 文字列への変換
  1794. *------------------------------------------
  1795. */
  1796. char* conv_str(struct script_state *st,struct script_data *data)
  1797. {
  1798. get_val(st,data);
  1799. if(data->type==C_INT){
  1800. char *buf;
  1801. CREATE(buf,char,ITEM_NAME_LENGTH);
  1802. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  1803. buf[ITEM_NAME_LENGTH-1]=0;
  1804. data->type=C_STR;
  1805. data->u.str=buf;
  1806. } else if(data->type==C_POS) {
  1807. // Protect form crashes by passing labels to string-expected args [jA2200]
  1808. data->type = C_CONSTSTR;
  1809. data->u.str = "** SCRIPT ERROR **";
  1810. } else if(data->type==C_NAME){
  1811. data->type=C_CONSTSTR;
  1812. data->u.str=str_buf+str_data[data->u.num].str;
  1813. }
  1814. return data->u.str;
  1815. }
  1816. /*==========================================
  1817. * 数値へ変換
  1818. *------------------------------------------
  1819. */
  1820. int conv_num(struct script_state *st,struct script_data *data)
  1821. {
  1822. char *p;
  1823. get_val(st,data);
  1824. if(data->type==C_STR || data->type==C_CONSTSTR){
  1825. p=data->u.str;
  1826. data->u.num = atoi(p);
  1827. if(data->type==C_STR)
  1828. aFree(p);
  1829. data->type=C_INT;
  1830. }
  1831. return data->u.num;
  1832. }
  1833. /*==========================================
  1834. * スタックへ数値をプッシュ
  1835. *------------------------------------------
  1836. */
  1837. void push_val(struct script_stack *stack,int type,int val)
  1838. {
  1839. if(stack->sp >= stack->sp_max){
  1840. stack->sp_max += 64;
  1841. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1842. sizeof(stack->stack_data[0]) * stack->sp_max);
  1843. malloc_tsetdword(stack->stack_data + (stack->sp_max - 64), 0,
  1844. 64 * sizeof(*(stack->stack_data)));
  1845. }
  1846. // if(battle_config.etc_log)
  1847. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1848. stack->stack_data[stack->sp].type=type;
  1849. stack->stack_data[stack->sp].u.num=val;
  1850. stack->stack_data[stack->sp].ref = NULL;
  1851. stack->sp++;
  1852. }
  1853. /*==========================================
  1854. * スタックへ数値+リファレンスをプッシュ
  1855. *------------------------------------------
  1856. */
  1857. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  1858. push_val(stack,type,val);
  1859. stack->stack_data[stack->sp-1].ref = ref;
  1860. }
  1861. /*==========================================
  1862. * スタックへ文字列をプッシュ
  1863. *------------------------------------------
  1864. */
  1865. void push_str(struct script_stack *stack,int type,char *str)
  1866. {
  1867. if(stack->sp>=stack->sp_max){
  1868. stack->sp_max += 64;
  1869. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1870. sizeof(stack->stack_data[0]) * stack->sp_max);
  1871. malloc_tsetdword(stack->stack_data + (stack->sp_max - 64), '\0',
  1872. 64 * sizeof(*(stack->stack_data)));
  1873. }
  1874. // if(battle_config.etc_log)
  1875. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1876. stack->stack_data[stack->sp].type =type;
  1877. stack->stack_data[stack->sp].u.str=str;
  1878. stack->stack_data[stack->sp].ref =NULL;
  1879. stack->sp++;
  1880. }
  1881. /*==========================================
  1882. * スタックへ複製をプッシュ
  1883. *------------------------------------------
  1884. */
  1885. void push_copy(struct script_stack *stack,int pos)
  1886. {
  1887. switch(stack->stack_data[pos].type){
  1888. case C_CONSTSTR:
  1889. push_str(stack,C_CONSTSTR,stack->stack_data[pos].u.str);
  1890. break;
  1891. case C_STR:
  1892. push_str(stack,C_STR,aStrdup(stack->stack_data[pos].u.str));
  1893. break;
  1894. default:
  1895. push_val2(
  1896. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  1897. stack->stack_data[pos].ref
  1898. );
  1899. break;
  1900. }
  1901. }
  1902. /*==========================================
  1903. * スタックからポップ
  1904. *------------------------------------------
  1905. */
  1906. void pop_stack(struct script_stack* stack,int start,int end)
  1907. {
  1908. int i;
  1909. for(i=start;i<end;i++){
  1910. if(stack->stack_data[i].type==C_STR){
  1911. aFree(stack->stack_data[i].u.str);
  1912. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  1913. }
  1914. }
  1915. if(stack->sp>end){
  1916. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1917. }
  1918. stack->sp-=end-start;
  1919. }
  1920. /*==========================================
  1921. * スクリプト依存変数、関数依存変数の解放
  1922. *------------------------------------------
  1923. */
  1924. void script_free_vars(struct linkdb_node **node) {
  1925. struct linkdb_node *n = *node;
  1926. while(n) {
  1927. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  1928. char postfix = name[strlen(name)-1];
  1929. if( postfix == '$' ) {
  1930. // 文字型変数なので、データ削除
  1931. aFree(n->data);
  1932. }
  1933. n = n->next;
  1934. }
  1935. linkdb_final( node );
  1936. }
  1937. /*==========================================
  1938. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  1939. *------------------------------------------
  1940. */
  1941. void script_free_stack(struct script_stack *stack) {
  1942. int i;
  1943. for(i = 0; i < stack->sp; i++) {
  1944. if( stack->stack_data[i].type == C_STR ) {
  1945. aFree(stack->stack_data[i].u.str);
  1946. stack->stack_data[i].type = C_INT;
  1947. } else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  1948. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  1949. script_free_vars( n );
  1950. aFree( n );
  1951. }
  1952. }
  1953. script_free_vars( stack->var_function );
  1954. aFree(stack->var_function);
  1955. aFree(stack->stack_data);
  1956. aFree(stack);
  1957. }
  1958. void script_free_code(struct script_code* code) {
  1959. script_free_vars( &code->script_vars );
  1960. aFree( code->script_buf );
  1961. aFree( code );
  1962. }
  1963. //
  1964. // 実行部main
  1965. //
  1966. /*==========================================
  1967. * コマンドの読み取り
  1968. *------------------------------------------
  1969. */
  1970. static int unget_com_data=-1;
  1971. int get_com(unsigned char *script,int *pos)
  1972. {
  1973. int i,j;
  1974. if(unget_com_data>=0){
  1975. i=unget_com_data;
  1976. unget_com_data=-1;
  1977. return i;
  1978. }
  1979. if(script[*pos]>=0x80){
  1980. return C_INT;
  1981. }
  1982. i=0; j=0;
  1983. while(script[*pos]>=0x40){
  1984. i=script[(*pos)++]<<j;
  1985. j+=6;
  1986. }
  1987. return i+(script[(*pos)++]<<j);
  1988. }
  1989. /*==========================================
  1990. * コマンドのプッシュバック
  1991. *------------------------------------------
  1992. */
  1993. void unget_com(int c)
  1994. {
  1995. if(unget_com_data!=-1){
  1996. if(battle_config.error_log)
  1997. ShowError("unget_com can back only 1 data\n");
  1998. }
  1999. unget_com_data=c;
  2000. }
  2001. /*==========================================
  2002. * 数値の所得
  2003. *------------------------------------------
  2004. */
  2005. int get_num(unsigned char *script,int *pos)
  2006. {
  2007. int i,j;
  2008. i=0; j=0;
  2009. while(script[*pos]>=0xc0){
  2010. i+=(script[(*pos)++]&0x7f)<<j;
  2011. j+=6;
  2012. }
  2013. return i+((script[(*pos)++]&0x7f)<<j);
  2014. }
  2015. /*==========================================
  2016. * スタックから値を取り出す
  2017. *------------------------------------------
  2018. */
  2019. int pop_val(struct script_state* st)
  2020. {
  2021. if(st->stack->sp<=0)
  2022. return 0;
  2023. st->stack->sp--;
  2024. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2025. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  2026. return st->stack->stack_data[st->stack->sp].u.num;
  2027. return 0;
  2028. }
  2029. int isstr(struct script_data *c) {
  2030. if( c->type == C_STR || c->type == C_CONSTSTR )
  2031. return 1;
  2032. else if( c->type == C_NAME ) {
  2033. char *p = str_buf + str_data[c->u.num & 0xffffff].str;
  2034. char postfix = p[strlen(p)-1];
  2035. return (postfix == '$');
  2036. }
  2037. return 0;
  2038. }
  2039. /*==========================================
  2040. * Three-section operator
  2041. * test ? if_true : if_false
  2042. *------------------------------------------
  2043. */
  2044. void op_3(struct script_state *st) {
  2045. int flag = 0;
  2046. if( isstr(&st->stack->stack_data[st->stack->sp-3])) {
  2047. char *str = conv_str(st,& (st->stack->stack_data[st->stack->sp-3]));
  2048. flag = str[0];
  2049. } else {
  2050. flag = conv_num(st,& (st->stack->stack_data[st->stack->sp-3]));
  2051. }
  2052. if( flag ) {
  2053. push_copy(st->stack, st->stack->sp-2 );
  2054. } else {
  2055. push_copy(st->stack, st->stack->sp-1 );
  2056. }
  2057. pop_stack(st->stack,st->stack->sp-4,st->stack->sp-1);
  2058. }
  2059. /*==========================================
  2060. * 加算演算子
  2061. *------------------------------------------
  2062. */
  2063. void op_add(struct script_state* st)
  2064. {
  2065. st->stack->sp--;
  2066. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2067. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  2068. if(isstr(&st->stack->stack_data[st->stack->sp]) || isstr(&st->stack->stack_data[st->stack->sp-1])){
  2069. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  2070. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  2071. }
  2072. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  2073. int *i1 = &st->stack->stack_data[st->stack->sp-1].u.num;
  2074. int *i2 = &st->stack->stack_data[st->stack->sp].u.num;
  2075. int ret = *i1 + *i2;
  2076. double ret_double = (double)*i1 + (double)*i2;
  2077. if(ret_double > INT_MAX|| ret_double < INT_MIN) {
  2078. ShowWarning("script::op_add overflow detected op:%d\n",C_ADD);
  2079. report_src(st);
  2080. ret = cap_value(ret, INT_MIN, INT_MAX);
  2081. }
  2082. *i1 = ret;
  2083. } else { // ssの予定
  2084. char *buf;
  2085. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  2086. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  2087. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  2088. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  2089. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  2090. {
  2091. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  2092. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  2093. }
  2094. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  2095. {
  2096. aFree(st->stack->stack_data[st->stack->sp].u.str);
  2097. st->stack->stack_data[st->stack->sp].type=C_INT;
  2098. }
  2099. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  2100. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  2101. }
  2102. st->stack->stack_data[st->stack->sp-1].ref = NULL;
  2103. }
  2104. /*==========================================
  2105. * 二項演算子(文字列)
  2106. *------------------------------------------
  2107. */
  2108. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  2109. {
  2110. char *s1=st->stack->stack_data[sp1].u.str,
  2111. *s2=st->stack->stack_data[sp2].u.str;
  2112. int a=0;
  2113. switch(op){
  2114. case C_EQ:
  2115. a= (strcmp(s1,s2)==0);
  2116. break;
  2117. case C_NE:
  2118. a= (strcmp(s1,s2)!=0);
  2119. break;
  2120. case C_GT:
  2121. a= (strcmp(s1,s2)> 0);
  2122. break;
  2123. case C_GE:
  2124. a= (strcmp(s1,s2)>=0);
  2125. break;
  2126. case C_LT:
  2127. a= (strcmp(s1,s2)< 0);
  2128. break;
  2129. case C_LE:
  2130. a= (strcmp(s1,s2)<=0);
  2131. break;
  2132. default:
  2133. ShowWarning("script: illegal string operator\n");
  2134. break;
  2135. }
  2136. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  2137. // So, call push_val() after freeing strings. [jA1783]
  2138. // push_val(st->stack,C_INT,a);
  2139. if(st->stack->stack_data[sp1].type==C_STR)
  2140. {
  2141. aFree(s1);
  2142. st->stack->stack_data[sp1].type=C_INT;
  2143. }
  2144. if(st->stack->stack_data[sp2].type==C_STR)
  2145. {
  2146. aFree(s2);
  2147. st->stack->stack_data[sp2].type=C_INT;
  2148. }
  2149. push_val(st->stack,C_INT,a);
  2150. }
  2151. /*==========================================
  2152. * 二項演算子(数値)
  2153. *------------------------------------------
  2154. */
  2155. void op_2num(struct script_state *st,int op,int i1,int i2)
  2156. {
  2157. int ret = 0;
  2158. double ret_double = 0;
  2159. switch(op){
  2160. case C_MOD: ret = i1 % i2; break;
  2161. case C_AND: ret = i1 & i2; break;
  2162. case C_OR: ret = i1 | i2; break;
  2163. case C_XOR: ret = i1 ^ i2; break;
  2164. case C_LAND: ret = (i1 && i2); break;
  2165. case C_LOR: ret = (i1 || i2); break;
  2166. case C_EQ: ret = (i1 == i2); break;
  2167. case C_NE: ret = (i1 != i2); break;
  2168. case C_GT: ret = (i1 > i2); break;
  2169. case C_GE: ret = (i1 >= i2); break;
  2170. case C_LT: ret = (i1 < i2); break;
  2171. case C_LE: ret = (i1 <= i2); break;
  2172. case C_R_SHIFT: ret = i1>>i2; break;
  2173. case C_L_SHIFT: ret = i1<<i2; break;
  2174. default:
  2175. switch(op) {
  2176. case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
  2177. case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
  2178. case C_DIV:
  2179. if(i2 == 0) {
  2180. printf("script::op_2num division by zero.\n");
  2181. ret = INT_MAX;
  2182. ret_double = 0; // doubleの精度が怪しいのでオーバーフロー対策を飛ばす
  2183. } else {
  2184. ret = i1 / i2; ret_double = (double)i1 / (double)i2;
  2185. }
  2186. break;
  2187. }
  2188. if(ret_double > INT_MAX || ret_double < INT_MIN) {
  2189. printf("script::op_2num overflow detected op:%d\n",op);
  2190. report_src(st);
  2191. ret = (int)cap_value(ret_double,INT_MAX,INT_MIN);
  2192. }
  2193. }
  2194. push_val(st->stack,C_INT,ret);
  2195. }
  2196. /*==========================================
  2197. * 二項演算子
  2198. *------------------------------------------
  2199. */
  2200. void op_2(struct script_state *st,int op)
  2201. {
  2202. int i1,i2;
  2203. char *s1=NULL,*s2=NULL;
  2204. i2=pop_val(st);
  2205. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2206. s2=st->stack->stack_data[st->stack->sp].u.str;
  2207. i1=pop_val(st);
  2208. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2209. s1=st->stack->stack_data[st->stack->sp].u.str;
  2210. if( s1!=NULL && s2!=NULL ){
  2211. // ss => op_2str
  2212. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  2213. }else if( s1==NULL && s2==NULL ){
  2214. // ii => op_2num
  2215. op_2num(st,op,i1,i2);
  2216. }else{
  2217. // si,is => error
  2218. ShowWarning("script: op_2: int&str, str&int not allow.\n");
  2219. report_src(st);
  2220. if(s1 && st->stack->stack_data[st->stack->sp].type == C_STR)
  2221. {
  2222. aFree(s1);
  2223. st->stack->stack_data[st->stack->sp].type = C_INT;
  2224. }
  2225. if(s2 && st->stack->stack_data[st->stack->sp+1].type == C_STR)
  2226. {
  2227. aFree(s2);
  2228. st->stack->stack_data[st->stack->sp+1].type = C_INT;
  2229. }
  2230. push_val(st->stack,C_INT,0);
  2231. }
  2232. }
  2233. /*==========================================
  2234. * 単項演算子
  2235. *------------------------------------------
  2236. */
  2237. void op_1num(struct script_state *st,int op)
  2238. {
  2239. int i1;
  2240. i1=pop_val(st);
  2241. switch(op){
  2242. case C_NEG:
  2243. i1=-i1;
  2244. break;
  2245. case C_NOT:
  2246. i1=~i1;
  2247. break;
  2248. case C_LNOT:
  2249. i1=!i1;
  2250. break;
  2251. }
  2252. push_val(st->stack,C_INT,i1);
  2253. }
  2254. /*==========================================
  2255. * 関数の実行
  2256. *------------------------------------------
  2257. */
  2258. int run_func(struct script_state *st)
  2259. {
  2260. int i,start_sp,end_sp,func;
  2261. end_sp=st->stack->sp;
  2262. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  2263. if(i<=0){ //Crash fix when missing "push_val" causes current pointer to become -1. from Rayce (jA)
  2264. if(battle_config.error_log)
  2265. ShowError("function not found\n");
  2266. // st->stack->sp=0;
  2267. st->state=END;
  2268. report_src(st);
  2269. return 1;
  2270. }
  2271. start_sp=i-1;
  2272. st->start=i-1;
  2273. st->end=end_sp;
  2274. func=st->stack->stack_data[st->start].u.num;
  2275. #ifdef DEBUG_RUN
  2276. if(battle_config.etc_log) {
  2277. ShowDebug("run_func : %s? (%d(%d)) sp=%d (%d...%d)\n",str_buf+str_data[func].str, func, str_data[func].type, st->stack->sp, st->start, st->end);
  2278. ShowDebug("stack dump :");
  2279. for(i=0;i<end_sp;i++){
  2280. switch(st->stack->stack_data[i].type){
  2281. case C_INT:
  2282. printf(" int(%d)",st->stack->stack_data[i].u.num);
  2283. break;
  2284. case C_NAME:
  2285. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num & 0xffffff].str);
  2286. break;
  2287. case C_ARG:
  2288. printf(" arg");
  2289. break;
  2290. case C_POS:
  2291. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  2292. break;
  2293. case C_STR:
  2294. printf(" str(%s)",st->stack->stack_data[i].u.str);
  2295. break;
  2296. case C_CONSTSTR:
  2297. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  2298. break;
  2299. default:
  2300. printf(" etc(%d,%d)",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  2301. }
  2302. }
  2303. printf("\n");
  2304. }
  2305. #endif
  2306. if(str_data[func].type!=C_FUNC ){
  2307. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n", str_buf+str_data[func].str, str_data[func].type);
  2308. // st->stack->sp=0;
  2309. st->state=END;
  2310. report_src(st);
  2311. return 1;
  2312. }
  2313. #ifdef DEBUG_RUN
  2314. ShowDebug("run_func : %s (func_no : %d , func_type : %d pos : 0x%x)\n",
  2315. str_buf+str_data[func].str,func,str_data[func].type,st->pos
  2316. );
  2317. #endif
  2318. if(str_data[func].func){
  2319. if (str_data[func].func(st)) //Report error
  2320. report_src(st);
  2321. } else {
  2322. if(battle_config.error_log)
  2323. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  2324. push_val(st->stack,C_INT,0);
  2325. report_src(st);
  2326. }
  2327. // Stack's datum are used when re-run functions [Eoe]
  2328. if(st->state != RERUNLINE) {
  2329. pop_stack(st->stack,start_sp,end_sp);
  2330. }
  2331. if(st->state==RETFUNC){
  2332. // ユーザー定義関数からの復帰
  2333. int olddefsp=st->stack->defsp;
  2334. int i;
  2335. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  2336. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  2337. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  2338. st->state=END;
  2339. report_src(st);
  2340. return 1;
  2341. }
  2342. script_free_vars( st->stack->var_function );
  2343. aFree(st->stack->var_function);
  2344. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  2345. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  2346. st->script=(struct script_code*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  2347. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  2348. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  2349. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  2350. st->state=GOTO;
  2351. }
  2352. return 0;
  2353. }
  2354. /*==========================================
  2355. * スクリプトの実行
  2356. *------------------------------------------
  2357. */
  2358. void run_script_main(struct script_state *st);
  2359. void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  2360. {
  2361. struct script_state *st;
  2362. struct map_session_data *sd=NULL;
  2363. if(rootscript==NULL || pos<0)
  2364. return;
  2365. if (rid) sd = map_id2sd(rid);
  2366. if (sd && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  2367. //Resume script.
  2368. st = sd->st;
  2369. } else {
  2370. st = aCalloc(sizeof(struct script_state), 1);
  2371. // the script is different, make new script_state and stack
  2372. st->stack = aMalloc (sizeof(struct script_stack));
  2373. st->stack->sp=0;
  2374. st->stack->sp_max=64;
  2375. st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  2376. st->stack->defsp = st->stack->sp;
  2377. st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  2378. st->state = RUN;
  2379. st->script = rootscript;
  2380. }
  2381. st->pos = pos;
  2382. st->rid = rid;
  2383. st->oid = oid;
  2384. st->sleep.timer = -1;
  2385. run_script_main(st);
  2386. }
  2387. /*==========================================
  2388. * 指定ノードをsleep_dbから削除
  2389. *------------------------------------------
  2390. */
  2391. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  2392. {
  2393. struct linkdb_node *retnode;
  2394. if( n == NULL)
  2395. return NULL;
  2396. if( n->prev == NULL )
  2397. sleep_db = n->next;
  2398. else
  2399. n->prev->next = n->next;
  2400. if( n->next )
  2401. n->next->prev = n->prev;
  2402. retnode = n->next;
  2403. aFree( n );
  2404. return retnode; // 次のノードを返す
  2405. }
  2406. /*==========================================
  2407. * sleep用タイマー関数
  2408. *------------------------------------------
  2409. */
  2410. int run_script_timer(int tid, unsigned int tick, int id, int data)
  2411. {
  2412. struct script_state *st = (struct script_state *)data;
  2413. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  2414. struct map_session_data *sd = map_id2sd(st->rid);
  2415. if((sd && sd->status.char_id != id) || (st->rid && !sd))
  2416. { //Character mismatch. Cancel execution.
  2417. st->rid = 0;
  2418. st->state = END;
  2419. }
  2420. while( node && st->sleep.timer != -1 ) {
  2421. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  2422. script_erase_sleepdb(node);
  2423. st->sleep.timer = -1;
  2424. break;
  2425. }
  2426. node = node->next;
  2427. }
  2428. if(st->state != RERUNLINE)
  2429. st->sleep.tick = 0;
  2430. run_script_main(st);
  2431. return 0;
  2432. }
  2433. /*==========================================
  2434. * スクリプトの実行メイン部分
  2435. *------------------------------------------
  2436. */
  2437. void run_script_main(struct script_state *st)
  2438. {
  2439. int c;
  2440. int cmdcount=script_config.check_cmdcount;
  2441. int gotocount=script_config.check_gotocount;
  2442. struct map_session_data *sd;
  2443. //For backing up purposes
  2444. struct script_state *bk_st = NULL;
  2445. int bk_npcid = 0;
  2446. struct script_stack *stack=st->stack;
  2447. sd = st->rid?map_id2sd(st->rid):NULL;
  2448. if(sd){
  2449. if(sd->st != st){
  2450. bk_st = sd->st;
  2451. bk_npcid = sd->npc_id;
  2452. }
  2453. sd->st = st;
  2454. sd->npc_id = st->oid;
  2455. }
  2456. if(st->state == RERUNLINE) {
  2457. st->state = RUN;
  2458. run_func(st);
  2459. if(st->state == GOTO)
  2460. st->state = RUN;
  2461. } else if(st->state != END)
  2462. st->state = RUN;
  2463. while(st->state == RUN){
  2464. c= get_com(st->script->script_buf,&st->pos);
  2465. switch(c){
  2466. case C_EOL:
  2467. if(stack->sp!=stack->defsp){
  2468. if(stack->sp > stack->defsp)
  2469. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  2470. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  2471. if (battle_config.etc_log)
  2472. {
  2473. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  2474. report_src(st);
  2475. }
  2476. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  2477. } else if(battle_config.error_log)
  2478. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  2479. stack->sp=stack->defsp;
  2480. }
  2481. break;
  2482. case C_INT:
  2483. push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos));
  2484. break;
  2485. case C_POS:
  2486. case C_NAME:
  2487. push_val(stack,c,GETVALUE(st->script->script_buf,st->pos));
  2488. st->pos+=3;
  2489. break;
  2490. case C_ARG:
  2491. push_val(stack,c,0);
  2492. break;
  2493. case C_STR:
  2494. push_str(stack,C_CONSTSTR,(st->script->script_buf+st->pos));
  2495. while(st->script->script_buf[st->pos++]);
  2496. break;
  2497. case C_FUNC:
  2498. run_func(st);
  2499. if(st->state==GOTO){
  2500. st->state = RUN;
  2501. if( gotocount>0 && (--gotocount)<=0 ){
  2502. ShowError("run_script: infinity loop !\n");
  2503. report_src(st);
  2504. st->state=END;
  2505. }
  2506. }
  2507. break;
  2508. case C_ADD:
  2509. op_add(st);
  2510. break;
  2511. case C_SUB:
  2512. case C_MUL:
  2513. case C_DIV:
  2514. case C_MOD:
  2515. case C_EQ:
  2516. case C_NE:
  2517. case C_GT:
  2518. case C_GE:
  2519. case C_LT:
  2520. case C_LE:
  2521. case C_AND:
  2522. case C_OR:
  2523. case C_XOR:
  2524. case C_LAND:
  2525. case C_LOR:
  2526. case C_R_SHIFT:
  2527. case C_L_SHIFT:
  2528. op_2(st,c);
  2529. break;
  2530. case C_NEG:
  2531. case C_NOT:
  2532. case C_LNOT:
  2533. op_1num(st,c);
  2534. break;
  2535. case C_OP3:
  2536. op_3(st);
  2537. break;
  2538. case C_NOP:
  2539. st->state=END;
  2540. break;
  2541. default:
  2542. if(battle_config.error_log)
  2543. ShowError("unknown command : %d @ %d\n",c,pos);
  2544. st->state=END;
  2545. break;
  2546. }
  2547. if( cmdcount>0 && (--cmdcount)<=0 ){
  2548. ShowError("run_script: infinity loop !\n");
  2549. report_src(st);
  2550. st->state=END;
  2551. }
  2552. }
  2553. if(st->sleep.tick > 0) {
  2554. //Delay execution
  2555. st->sleep.charid = sd?sd->status.char_id:0;
  2556. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  2557. run_script_timer, st->sleep.charid, (int)st);
  2558. linkdb_insert(&sleep_db, (void*)st->oid, st);
  2559. //Restore previous script
  2560. if (sd) {
  2561. sd->st = bk_st;
  2562. sd->npc_id = bk_npcid;
  2563. bk_st = NULL; //Remove tag for removal.
  2564. }
  2565. }
  2566. else if(st->state != END && sd){
  2567. //Resume later (st is already attached to player).
  2568. if(bk_st) {
  2569. ShowWarning("Unable to restore stack! Double continuation!\n");
  2570. //Report BOTH scripts to see if that can help somehow.
  2571. ShowDebug("Previous script (lost):\n");
  2572. report_src(bk_st);
  2573. ShowDebug("Current script:\n");
  2574. report_src(st);
  2575. }
  2576. } else {
  2577. //Dispose of script.
  2578. if (sd)
  2579. { //Restore previous stack and save char.
  2580. if(sd->state.using_fake_npc){
  2581. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  2582. sd->state.using_fake_npc = 0;
  2583. }
  2584. //Restore previous script if any.
  2585. sd->st = bk_st;
  2586. sd->npc_id = bk_npcid;
  2587. if (!bk_st)
  2588. npc_event_dequeue(sd);
  2589. else
  2590. bk_st = NULL; //Remove tag for removal.
  2591. if (sd->state.reg_dirty&2)
  2592. intif_saveregistry(sd,2);
  2593. if (sd->state.reg_dirty&1)
  2594. intif_saveregistry(sd,1);
  2595. }
  2596. st->pos = -1;
  2597. script_free_stack (st->stack);
  2598. aFree(st);
  2599. }
  2600. if (bk_st)
  2601. { //Remove previous script
  2602. bk_st->pos = -1;
  2603. script_free_stack(bk_st->stack);
  2604. aFree(bk_st);
  2605. bk_st = NULL;
  2606. }
  2607. }
  2608. /*==========================================
  2609. * マップ変数の変更
  2610. *------------------------------------------
  2611. */
  2612. int mapreg_setreg(int num,int val)
  2613. {
  2614. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2615. int i=num>>24;
  2616. char *name=str_buf+str_data[num&0x00ffffff].str;
  2617. char tmp_str[64];
  2618. #endif
  2619. if(val!=0) {
  2620. if(idb_put(mapreg_db,num,(void*)val))
  2621. ;
  2622. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2623. else if(name[1] != '@') {
  2624. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%d')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,val);
  2625. if(mysql_query(&mmysql_handle,tmp_sql)){
  2626. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2627. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2628. }
  2629. }
  2630. #endif
  2631. } else { // [zBuffer]
  2632. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2633. if(name[1] != '@') { // Remove from database because it is unused.
  2634. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2635. if(mysql_query(&mmysql_handle,tmp_sql)){
  2636. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2637. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2638. }
  2639. }
  2640. #endif
  2641. idb_remove(mapreg_db,num);
  2642. }
  2643. mapreg_dirty=1;
  2644. return 0;
  2645. }
  2646. /*==========================================
  2647. * 文字列型マップ変数の変更
  2648. *------------------------------------------
  2649. */
  2650. int mapreg_setregstr(int num,const char *str)
  2651. {
  2652. char *p;
  2653. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2654. char tmp_str[64];
  2655. char tmp_str2[512];
  2656. int i=num>>24; // [zBuffer]
  2657. char *name=str_buf+str_data[num&0x00ffffff].str;
  2658. #endif
  2659. if( str==NULL || *str==0 ){
  2660. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2661. if(name[1] != '@') {
  2662. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2663. if(mysql_query(&mmysql_handle,tmp_sql)){
  2664. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2665. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2666. }
  2667. }
  2668. #endif
  2669. idb_remove(mapregstr_db,num);
  2670. mapreg_dirty=1;
  2671. return 0;
  2672. }
  2673. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  2674. strcpy(p,str);
  2675. if (idb_put(mapregstr_db,num,p))
  2676. ;
  2677. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2678. else if(name[1] != '@'){ //put returned null, so we must insert.
  2679. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  2680. sprintf(tmp_sql,"INSERT INTO `%s`(`%s`,`%s`,`%s`) VALUES ('%s','%d','%s')",mapregsql_db,mapregsql_db_varname,mapregsql_db_index,mapregsql_db_value,jstrescapecpy(tmp_str,name),i,jstrescapecpy(tmp_str2,p));
  2681. if(mysql_query(&mmysql_handle,tmp_sql)){
  2682. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2683. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2684. }
  2685. }
  2686. #endif
  2687. mapreg_dirty=1;
  2688. return 0;
  2689. }
  2690. /*==========================================
  2691. * 永続的マップ変数の読み込み
  2692. *------------------------------------------
  2693. */
  2694. static int script_load_mapreg(void)
  2695. {
  2696. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2697. FILE *fp;
  2698. char line[1024];
  2699. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  2700. return -1;
  2701. while(fgets(line,sizeof(line),fp)){
  2702. char buf1[256],buf2[1024],*p;
  2703. int n,v,s,i;
  2704. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  2705. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  2706. continue;
  2707. if( buf1[strlen(buf1)-1]=='$' ){
  2708. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  2709. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2710. continue;
  2711. }
  2712. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  2713. strcpy(p,buf2);
  2714. s= add_str(buf1);
  2715. idb_put(mapregstr_db,(i<<24)|s,p);
  2716. }else{
  2717. if( sscanf(line+n,"%d",&v)!=1 ){
  2718. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2719. continue;
  2720. }
  2721. s= add_str(buf1);
  2722. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  2723. }
  2724. }
  2725. fclose(fp);
  2726. mapreg_dirty=0;
  2727. return 0;
  2728. #else
  2729. // SQL mapreg code start [zBuffer]
  2730. /*
  2731. 0 1 2
  2732. +-------------------------+
  2733. | varname | index | value |
  2734. +-------------------------+
  2735. */
  2736. unsigned int perfomance = (unsigned int)time(NULL);
  2737. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  2738. ShowInfo("Querying script_load_mapreg ...\n");
  2739. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2740. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2741. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2742. return -1;
  2743. }
  2744. ShowInfo("Success! Returning results ...\n");
  2745. sql_res = mysql_store_result(&mmysql_handle);
  2746. if (sql_res) {
  2747. while ((sql_row = mysql_fetch_row(sql_res))) {
  2748. char buf1[33], *p = NULL;
  2749. int i,v,s;
  2750. strcpy(buf1,sql_row[0]);
  2751. if( buf1[strlen(buf1)-1]=='$' ){
  2752. i = atoi(sql_row[1]);
  2753. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  2754. strcpy(p,sql_row[2]);
  2755. s= add_str(buf1);
  2756. idb_put(mapregstr_db,(i<<24)|s,p);
  2757. }else{
  2758. s= add_str(buf1);
  2759. v= atoi(sql_row[2]);
  2760. i = atoi(sql_row[1]);
  2761. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  2762. }
  2763. }
  2764. }
  2765. ShowInfo("Freeing results...\n");
  2766. mysql_free_result(sql_res);
  2767. mapreg_dirty=0;
  2768. perfomance = (time(NULL) - perfomance);
  2769. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  2770. return 0;
  2771. #endif /* TXT_ONLY */
  2772. }
  2773. /*==========================================
  2774. * 永続的マップ変数の書き込み
  2775. *------------------------------------------
  2776. */
  2777. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  2778. {
  2779. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2780. FILE *fp=va_arg(ap,FILE*);
  2781. int num=key.i&0x00ffffff, i=key.i>>24;
  2782. char *name=str_buf+str_data[num].str;
  2783. if( name[1]!='@' ){
  2784. if(i==0)
  2785. fprintf(fp,"%s\t%d\n", name, (int)data);
  2786. else
  2787. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  2788. }
  2789. return 0;
  2790. #else
  2791. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  2792. char *name=str_buf+str_data[num].str;
  2793. if ( name[1] != '@') {
  2794. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%d' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,(int)data,mapregsql_db_varname,name,mapregsql_db_index,i);
  2795. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2796. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2797. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2798. }
  2799. }
  2800. return 0;
  2801. #endif
  2802. }
  2803. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  2804. {
  2805. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2806. FILE *fp=va_arg(ap,FILE*);
  2807. int num=key.i&0x00ffffff, i=key.i>>24;
  2808. char *name=str_buf+str_data[num].str;
  2809. if( name[1]!='@' ){
  2810. if(i==0)
  2811. fprintf(fp,"%s\t%s\n", name, (char *)data);
  2812. else
  2813. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  2814. }
  2815. return 0;
  2816. #else
  2817. char tmp_str2[512];
  2818. int num=key.i&0x00ffffff, i=key.i>>24;
  2819. char *name=str_buf+str_data[num].str;
  2820. if ( name[1] != '@') {
  2821. sprintf(tmp_sql,"UPDATE `%s` SET `%s`='%s' WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_value,jstrescapecpy(tmp_str2,(char *)data),mapregsql_db_varname,name,mapregsql_db_index,i);
  2822. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2823. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2824. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2825. }
  2826. }
  2827. return 0;
  2828. #endif
  2829. }
  2830. static int script_save_mapreg(void)
  2831. {
  2832. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2833. FILE *fp;
  2834. int lock;
  2835. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  2836. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  2837. return -1;
  2838. }
  2839. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  2840. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  2841. lock_fclose(fp,mapreg_txt,&lock);
  2842. #else
  2843. unsigned int perfomance = (unsigned int)time(NULL);
  2844. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  2845. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  2846. perfomance = ((unsigned int)time(NULL) - perfomance);
  2847. if(perfomance > 2)
  2848. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  2849. #endif
  2850. mapreg_dirty=0;
  2851. return 0;
  2852. }
  2853. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  2854. {
  2855. if(mapreg_dirty)
  2856. if (script_save_mapreg() == -1)
  2857. ShowError("Failed to save the mapreg data!\n");
  2858. return 0;
  2859. }
  2860. /*==========================================
  2861. *
  2862. *------------------------------------------
  2863. */
  2864. static int set_posword(char *p)
  2865. {
  2866. char* np,* str[15];
  2867. int i=0;
  2868. for(i=0;i<11;i++) {
  2869. if((np=strchr(p,','))!=NULL) {
  2870. str[i]=p;
  2871. *np=0;
  2872. p=np+1;
  2873. } else {
  2874. str[i]=p;
  2875. p+=strlen(p);
  2876. }
  2877. if(str[i])
  2878. strcpy(pos[i],str[i]);
  2879. }
  2880. return 0;
  2881. }
  2882. int script_config_read_sub(char *cfgName)
  2883. {
  2884. int i;
  2885. char line[1024],w1[1024],w2[1024];
  2886. FILE *fp;
  2887. fp=fopen(cfgName,"r");
  2888. if(fp==NULL){
  2889. ShowError("file not found: [%s]\n", cfgName);
  2890. return 1;
  2891. }
  2892. while(fgets(line,sizeof(line)-1,fp)){
  2893. if(line[0] == '/' && line[1] == '/')
  2894. continue;
  2895. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  2896. if(i!=2)
  2897. continue;
  2898. if(strcmpi(w1,"refine_posword")==0) {
  2899. set_posword(w2);
  2900. }
  2901. else if(strcmpi(w1,"verbose_mode")==0) {
  2902. script_config.verbose_mode = battle_config_switch(w2);
  2903. }
  2904. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  2905. script_config.warn_func_no_comma = battle_config_switch(w2);
  2906. }
  2907. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  2908. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  2909. }
  2910. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  2911. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  2912. }
  2913. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  2914. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  2915. }
  2916. else if(strcmpi(w1,"check_cmdcount")==0) {
  2917. script_config.check_cmdcount = battle_config_switch(w2);
  2918. }
  2919. else if(strcmpi(w1,"check_gotocount")==0) {
  2920. script_config.check_gotocount = battle_config_switch(w2);
  2921. }
  2922. else if(strcmpi(w1,"event_script_type")==0) {
  2923. script_config.event_script_type = battle_config_switch(w2);
  2924. }
  2925. else if(strcmpi(w1,"event_requires_trigger")==0) {
  2926. script_config.event_requires_trigger = battle_config_switch(w2);
  2927. }
  2928. else if(strcmpi(w1,"die_event_name")==0) {
  2929. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  2930. if (strlen(script_config.die_event_name) != strlen(w2))
  2931. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  2932. }
  2933. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  2934. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  2935. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  2936. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  2937. }
  2938. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  2939. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  2940. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  2941. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  2942. }
  2943. else if(strcmpi(w1,"login_event_name")==0) {
  2944. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  2945. if (strlen(script_config.login_event_name) != strlen(w2))
  2946. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  2947. }
  2948. else if(strcmpi(w1,"logout_event_name")==0) {
  2949. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  2950. if (strlen(script_config.logout_event_name) != strlen(w2))
  2951. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  2952. }
  2953. else if(strcmpi(w1,"loadmap_event_name")==0) {
  2954. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  2955. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  2956. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  2957. }
  2958. else if(strcmpi(w1,"baselvup_event_name")==0) {
  2959. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  2960. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  2961. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  2962. }
  2963. else if(strcmpi(w1,"joblvup_event_name")==0) {
  2964. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  2965. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  2966. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  2967. }
  2968. else if(strcmpi(w1,"import")==0){
  2969. script_config_read_sub(w2);
  2970. }
  2971. }
  2972. fclose(fp);
  2973. return 0;
  2974. }
  2975. int script_config_read(char *cfgName)
  2976. { //Script related variables should be initialized once! [Skotlex]
  2977. malloc_set (&script_config, 0, sizeof(script_config));
  2978. script_config.verbose_mode = 0;
  2979. script_config.warn_func_no_comma = 1;
  2980. script_config.warn_cmd_no_comma = 1;
  2981. script_config.warn_func_mismatch_paramnum = 1;
  2982. script_config.warn_cmd_mismatch_paramnum = 1;
  2983. script_config.check_cmdcount = 65535;
  2984. script_config.check_gotocount = 2048;
  2985. script_config.event_script_type = 0;
  2986. script_config.event_requires_trigger = 1;
  2987. return script_config_read_sub(cfgName);
  2988. }
  2989. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap)
  2990. {
  2991. struct script_code *code = (struct script_code *)data;
  2992. if(code){
  2993. script_free_vars( &code->script_vars );
  2994. aFree( code->script_buf );
  2995. }
  2996. return 0;
  2997. }
  2998. /*==========================================
  2999. * 終了
  3000. *------------------------------------------
  3001. */
  3002. int do_final_script()
  3003. {
  3004. if(mapreg_dirty>=0)
  3005. script_save_mapreg();
  3006. mapreg_db->destroy(mapreg_db,NULL);
  3007. mapregstr_db->destroy(mapregstr_db,NULL);
  3008. scriptlabel_db->destroy(scriptlabel_db,NULL);
  3009. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  3010. if(sleep_db) {
  3011. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3012. while(n) {
  3013. struct script_state *st = (struct script_state *)n->data;
  3014. script_free_stack(st->stack);
  3015. aFree(st);
  3016. n = n->next;
  3017. }
  3018. linkdb_final(&sleep_db);
  3019. }
  3020. if (str_data)
  3021. aFree(str_data);
  3022. if (str_buf)
  3023. aFree(str_buf);
  3024. return 0;
  3025. }
  3026. /*==========================================
  3027. * 初期化
  3028. *------------------------------------------
  3029. */
  3030. int do_init_script()
  3031. {
  3032. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  3033. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  3034. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  3035. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA,50);
  3036. script_load_mapreg();
  3037. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  3038. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  3039. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  3040. return 0;
  3041. }
  3042. int script_reload()
  3043. {
  3044. if(mapreg_dirty>=0)
  3045. script_save_mapreg();
  3046. mapreg_db->clear(mapreg_db, NULL);
  3047. mapregstr_db->clear(mapregstr_db, NULL);
  3048. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  3049. scriptlabel_db->clear(scriptlabel_db, NULL);
  3050. if(sleep_db) {
  3051. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3052. while(n) {
  3053. struct script_state *st = (struct script_state *)n->data;
  3054. script_free_stack(st->stack);
  3055. aFree(st);
  3056. n = n->next;
  3057. }
  3058. linkdb_final(&sleep_db);
  3059. }
  3060. script_load_mapreg();
  3061. return 0;
  3062. }
  3063. int buildin_mes(struct script_state *st);
  3064. int buildin_goto(struct script_state *st);
  3065. int buildin_callsub(struct script_state *st);
  3066. int buildin_callfunc(struct script_state *st);
  3067. int buildin_return(struct script_state *st);
  3068. int buildin_getarg(struct script_state *st);
  3069. int buildin_next(struct script_state *st);
  3070. int buildin_close(struct script_state *st);
  3071. int buildin_close2(struct script_state *st);
  3072. int buildin_menu(struct script_state *st);
  3073. int buildin_rand(struct script_state *st);
  3074. int buildin_warp(struct script_state *st);
  3075. int buildin_areawarp(struct script_state *st);
  3076. int buildin_warpchar(struct script_state *st); // [LuzZza]
  3077. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  3078. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  3079. int buildin_heal(struct script_state *st);
  3080. int buildin_itemheal(struct script_state *st);
  3081. int buildin_percentheal(struct script_state *st);
  3082. int buildin_jobchange(struct script_state *st);
  3083. int buildin_jobname(struct script_state *st);
  3084. int buildin_input(struct script_state *st);
  3085. int buildin_setlook(struct script_state *st);
  3086. int buildin_set(struct script_state *st);
  3087. int buildin_setarray(struct script_state *st);
  3088. int buildin_cleararray(struct script_state *st);
  3089. int buildin_copyarray(struct script_state *st);
  3090. int buildin_getarraysize(struct script_state *st);
  3091. int buildin_deletearray(struct script_state *st);
  3092. int buildin_getelementofarray(struct script_state *st);
  3093. int buildin_getitem(struct script_state *st);
  3094. int buildin_getitem2(struct script_state *st);
  3095. int buildin_getnameditem(struct script_state *st);
  3096. int buildin_grouprandomitem(struct script_state *st);
  3097. int buildin_makeitem(struct script_state *st);
  3098. int buildin_delitem(struct script_state *st);
  3099. int buildin_delitem2(struct script_state *st);
  3100. int buildin_enableitemuse(struct script_state *st);
  3101. int buildin_disableitemuse(struct script_state *st);
  3102. int buildin_viewpoint(struct script_state *st);
  3103. int buildin_countitem(struct script_state *st);
  3104. int buildin_countitem2(struct script_state *st);
  3105. int buildin_checkweight(struct script_state *st);
  3106. int buildin_readparam(struct script_state *st);
  3107. int buildin_getcharid(struct script_state *st);
  3108. int buildin_getpartyname(struct script_state *st);
  3109. int buildin_getpartymember(struct script_state *st);
  3110. int buildin_getpartyleader(struct script_state *st);
  3111. int buildin_getguildname(struct script_state *st);
  3112. int buildin_getguildmaster(struct script_state *st);
  3113. int buildin_getguildmasterid(struct script_state *st);
  3114. int buildin_strcharinfo(struct script_state *st);
  3115. int buildin_getequipid(struct script_state *st);
  3116. int buildin_getequipname(struct script_state *st);
  3117. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  3118. int buildin_repair(struct script_state *st); // [Valaris]
  3119. int buildin_getequipisequiped(struct script_state *st);
  3120. int buildin_getequipisenableref(struct script_state *st);
  3121. int buildin_getequipisidentify(struct script_state *st);
  3122. int buildin_getequiprefinerycnt(struct script_state *st);
  3123. int buildin_getequipweaponlv(struct script_state *st);
  3124. int buildin_getequippercentrefinery(struct script_state *st);
  3125. int buildin_successrefitem(struct script_state *st);
  3126. int buildin_failedrefitem(struct script_state *st);
  3127. int buildin_cutin(struct script_state *st);
  3128. int buildin_cutincard(struct script_state *st);
  3129. int buildin_statusup(struct script_state *st);
  3130. int buildin_statusup2(struct script_state *st);
  3131. int buildin_bonus(struct script_state *st);
  3132. int buildin_bonus2(struct script_state *st);
  3133. int buildin_bonus3(struct script_state *st);
  3134. int buildin_bonus4(struct script_state *st);
  3135. int buildin_skill(struct script_state *st);
  3136. int buildin_addtoskill(struct script_state *st); // [Valaris]
  3137. int buildin_guildskill(struct script_state *st);
  3138. int buildin_getskilllv(struct script_state *st);
  3139. int buildin_getgdskilllv(struct script_state *st);
  3140. int buildin_basicskillcheck(struct script_state *st);
  3141. int buildin_getgmlevel(struct script_state *st);
  3142. int buildin_end(struct script_state *st);
  3143. int buildin_checkoption(struct script_state *st);
  3144. int buildin_setoption(struct script_state *st);
  3145. int buildin_setcart(struct script_state *st);
  3146. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  3147. int buildin_setfalcon(struct script_state *st);
  3148. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  3149. int buildin_setriding(struct script_state *st);
  3150. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  3151. int buildin_savepoint(struct script_state *st);
  3152. int buildin_gettimetick(struct script_state *st);
  3153. int buildin_gettime(struct script_state *st);
  3154. int buildin_gettimestr(struct script_state *st);
  3155. int buildin_openstorage(struct script_state *st);
  3156. int buildin_guildopenstorage(struct script_state *st);
  3157. int buildin_itemskill(struct script_state *st);
  3158. int buildin_produce(struct script_state *st);
  3159. int buildin_monster(struct script_state *st);
  3160. int buildin_areamonster(struct script_state *st);
  3161. int buildin_killmonster(struct script_state *st);
  3162. int buildin_killmonsterall(struct script_state *st);
  3163. int buildin_clone(struct script_state *st);
  3164. int buildin_doevent(struct script_state *st);
  3165. int buildin_donpcevent(struct script_state *st);
  3166. int buildin_addtimer(struct script_state *st);
  3167. int buildin_deltimer(struct script_state *st);
  3168. int buildin_addtimercount(struct script_state *st);
  3169. int buildin_initnpctimer(struct script_state *st);
  3170. int buildin_stopnpctimer(struct script_state *st);
  3171. int buildin_startnpctimer(struct script_state *st);
  3172. int buildin_setnpctimer(struct script_state *st);
  3173. int buildin_getnpctimer(struct script_state *st);
  3174. int buildin_attachnpctimer(struct script_state *st); // [celest]
  3175. int buildin_detachnpctimer(struct script_state *st); // [celest]
  3176. int buildin_playerattached(struct script_state *st); // [Skotlex]
  3177. int buildin_announce(struct script_state *st);
  3178. int buildin_mapannounce(struct script_state *st);
  3179. int buildin_areaannounce(struct script_state *st);
  3180. int buildin_getusers(struct script_state *st);
  3181. int buildin_getmapguildusers(struct script_state *st);
  3182. int buildin_getmapusers(struct script_state *st);
  3183. int buildin_getareausers(struct script_state *st);
  3184. int buildin_getareadropitem(struct script_state *st);
  3185. int buildin_enablenpc(struct script_state *st);
  3186. int buildin_disablenpc(struct script_state *st);
  3187. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  3188. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  3189. int buildin_hideoffnpc(struct script_state *st);
  3190. int buildin_hideonnpc(struct script_state *st);
  3191. int buildin_sc_start(struct script_state *st);
  3192. int buildin_sc_start2(struct script_state *st);
  3193. int buildin_sc_start4(struct script_state *st);
  3194. int buildin_sc_end(struct script_state *st);
  3195. int buildin_getscrate(struct script_state *st);
  3196. int buildin_debugmes(struct script_state *st);
  3197. int buildin_catchpet(struct script_state *st);
  3198. int buildin_birthpet(struct script_state *st);
  3199. int buildin_resetlvl(struct script_state *st);
  3200. int buildin_resetstatus(struct script_state *st);
  3201. int buildin_resetskill(struct script_state *st);
  3202. int buildin_skillpointcount(struct script_state *st);
  3203. int buildin_changebase(struct script_state *st);
  3204. int buildin_changesex(struct script_state *st);
  3205. int buildin_waitingroom(struct script_state *st);
  3206. int buildin_delwaitingroom(struct script_state *st);
  3207. int buildin_waitingroomkickall(struct script_state *st);
  3208. int buildin_enablewaitingroomevent(struct script_state *st);
  3209. int buildin_disablewaitingroomevent(struct script_state *st);
  3210. int buildin_getwaitingroomstate(struct script_state *st);
  3211. int buildin_warpwaitingpc(struct script_state *st);
  3212. int buildin_attachrid(struct script_state *st);
  3213. int buildin_detachrid(struct script_state *st);
  3214. int buildin_isloggedin(struct script_state *st);
  3215. int buildin_setmapflagnosave(struct script_state *st);
  3216. int buildin_setmapflag(struct script_state *st);
  3217. int buildin_removemapflag(struct script_state *st);
  3218. int buildin_pvpon(struct script_state *st);
  3219. int buildin_pvpoff(struct script_state *st);
  3220. int buildin_gvgon(struct script_state *st);
  3221. int buildin_gvgoff(struct script_state *st);
  3222. int buildin_emotion(struct script_state *st);
  3223. int buildin_maprespawnguildid(struct script_state *st);
  3224. int buildin_agitstart(struct script_state *st); // <Agit>
  3225. int buildin_agitend(struct script_state *st);
  3226. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  3227. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  3228. int buildin_getcastlename(struct script_state *st);
  3229. int buildin_getcastledata(struct script_state *st);
  3230. int buildin_setcastledata(struct script_state *st);
  3231. int buildin_requestguildinfo(struct script_state *st);
  3232. int buildin_getequipcardcnt(struct script_state *st);
  3233. int buildin_successremovecards(struct script_state *st);
  3234. int buildin_failedremovecards(struct script_state *st);
  3235. int buildin_marriage(struct script_state *st);
  3236. int buildin_wedding_effect(struct script_state *st);
  3237. int buildin_divorce(struct script_state *st);
  3238. int buildin_ispartneron(struct script_state *st); // MouseJstr
  3239. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  3240. int buildin_getchildid(struct script_state *st); // Skotlex
  3241. int buildin_getmotherid(struct script_state *st); // Lupus
  3242. int buildin_getfatherid(struct script_state *st); // Lupus
  3243. int buildin_warppartner(struct script_state *st); // MouseJstr
  3244. int buildin_getitemname(struct script_state *st);
  3245. int buildin_getitemslots(struct script_state *st);
  3246. int buildin_makepet(struct script_state *st);
  3247. int buildin_getexp(struct script_state *st);
  3248. int buildin_getinventorylist(struct script_state *st);
  3249. int buildin_getskilllist(struct script_state *st);
  3250. int buildin_clearitem(struct script_state *st);
  3251. int buildin_classchange(struct script_state *st);
  3252. int buildin_misceffect(struct script_state *st);
  3253. int buildin_soundeffect(struct script_state *st);
  3254. int buildin_soundeffectall(struct script_state *st);
  3255. int buildin_setcastledata(struct script_state *st);
  3256. int buildin_mapwarp(struct script_state *st);
  3257. int buildin_inittimer(struct script_state *st);
  3258. int buildin_stoptimer(struct script_state *st);
  3259. int buildin_cmdothernpc(struct script_state *st);
  3260. int buildin_mobcount(struct script_state *st);
  3261. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3262. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  3263. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3264. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  3265. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  3266. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  3267. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  3268. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  3269. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  3270. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  3271. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  3272. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  3273. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  3274. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  3275. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  3276. int buildin_nude(struct script_state *st); // nude [Valaris]
  3277. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  3278. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  3279. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  3280. int buildin_message(struct script_state *st); // [MouseJstr]
  3281. int buildin_npctalk(struct script_state *st); // [Valaris]
  3282. int buildin_hasitems(struct script_state *st); // [Valaris]
  3283. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  3284. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  3285. int buildin_npcspeed(struct script_state *st); // [Valaris]
  3286. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  3287. int buildin_npcstop(struct script_state *st); // [Valaris]
  3288. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  3289. int buildin_checkoption1(struct script_state *st); // [celest]
  3290. int buildin_checkoption2(struct script_state *st); // [celest]
  3291. int buildin_guildgetexp(struct script_state *st); // [celest]
  3292. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  3293. int buildin_logmes(struct script_state *st); // [Lupus]
  3294. int buildin_summon(struct script_state *st); // [celest]
  3295. int buildin_isnight(struct script_state *st); // [celest]
  3296. int buildin_isday(struct script_state *st); // [celest]
  3297. int buildin_isequipped(struct script_state *st); // [celest]
  3298. int buildin_isequippedcnt(struct script_state *st); // [celest]
  3299. int buildin_cardscnt(struct script_state *st); // [Lupus]
  3300. int buildin_getrefine(struct script_state *st); // [celest]
  3301. int buildin_adopt(struct script_state *st);
  3302. int buildin_night(struct script_state *st);
  3303. int buildin_day(struct script_state *st);
  3304. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  3305. int buildin_dispbottom(struct script_state *st);
  3306. int buildin_recovery(struct script_state *st);
  3307. int buildin_getpetinfo(struct script_state *st);
  3308. int buildin_checkequipedcard(struct script_state *st);
  3309. int buildin_globalmes(struct script_state *st);
  3310. int buildin_jump_zero(struct script_state *st);
  3311. int buildin_select(struct script_state *st);
  3312. int buildin_prompt(struct script_state *st);
  3313. int buildin_getmapmobs(struct script_state *st); //jA addition end
  3314. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  3315. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  3316. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  3317. int buildin_fakenpcname(struct script_state *st); // [Lance]
  3318. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  3319. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  3320. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  3321. // [zBuffer] List of mathematics commands --->
  3322. int buildin_sqrt(struct script_state *st);
  3323. int buildin_pow(struct script_state *st);
  3324. int buildin_distance(struct script_state *st);
  3325. int buildin_checkcell(struct script_state *st);
  3326. // <--- [zBuffer] List of mathematics commands
  3327. // [zBuffer] List of dynamic var commands --->
  3328. int buildin_getd(struct script_state *st);
  3329. int buildin_setd(struct script_state *st);
  3330. // <--- [zBuffer] List of dynamic var commands
  3331. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  3332. int buildin_callshop(struct script_state *st); // [Skotlex]
  3333. int buildin_npcshopitem(struct script_state *st); // [Lance]
  3334. int buildin_npcshopadditem(struct script_state *st);
  3335. int buildin_npcshopdelitem(struct script_state *st);
  3336. int buildin_equip(struct script_state *st);
  3337. int buildin_autoequip(struct script_state *st);
  3338. int buildin_setbattleflag(struct script_state *st);
  3339. int buildin_getbattleflag(struct script_state *st);
  3340. int buildin_query_sql(struct script_state *st);
  3341. int buildin_escape_sql(struct script_state *st);
  3342. int buildin_atoi(struct script_state *st);
  3343. int buildin_axtoi(struct script_state *st);
  3344. // [zBuffer] List of player cont commands --->
  3345. int buildin_rid2name(struct script_state *st);
  3346. int buildin_pcfollow(struct script_state *st);
  3347. int buildin_pcstopfollow(struct script_state *st);
  3348. int buildin_pcblockmove(struct script_state *st);
  3349. // <--- [zBuffer] List of player cont commands
  3350. // [zBuffer] List of mob control commands --->
  3351. int buildin_mobspawn(struct script_state *st);
  3352. int buildin_mobremove(struct script_state *st);
  3353. int buildin_getmobdata(struct script_state *st);
  3354. int buildin_setmobdata(struct script_state *st);
  3355. int buildin_mobassist(struct script_state *st);
  3356. int buildin_mobattach(struct script_state *st);
  3357. int buildin_unitwalk(struct script_state *st);
  3358. int buildin_unitkill(struct script_state *st);
  3359. int buildin_unitwarp(struct script_state *st);
  3360. int buildin_unitattack(struct script_state *st);
  3361. int buildin_unitstop(struct script_state *st);
  3362. int buildin_unittalk(struct script_state *st);
  3363. int buildin_unitemote(struct script_state *st);
  3364. int buildin_unitdeadsit(struct script_state *st);
  3365. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  3366. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  3367. // <--- [zBuffer] List of mob control commands
  3368. int buildin_sleep(struct script_state *st);
  3369. int buildin_sleep2(struct script_state *st);
  3370. int buildin_awake(struct script_state *st);
  3371. int buildin_getvariableofnpc(struct script_state *st);
  3372. // [blackhole89] -->
  3373. int buildin_warpportal(struct script_state *st);
  3374. // <-- [blackhole89]
  3375. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  3376. int buildin_eaclass(struct script_state *st);
  3377. int buildin_roclass(struct script_state *st);
  3378. int buildin_setitemscript(struct script_state *st);
  3379. int buildin_disguise(struct script_state *st);
  3380. int buildin_undisguise(struct script_state *st);
  3381. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  3382. int buildin_checkvending(struct script_state *st); // check vending [Nab4]
  3383. int buildin_checkchatting(struct script_state *st); // check chatting [Marka]
  3384. #ifdef PCRE_SUPPORT
  3385. int buildin_defpattern(struct script_state *st); // MouseJstr
  3386. int buildin_activatepset(struct script_state *st); // MouseJstr
  3387. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  3388. int buildin_deletepset(struct script_state *st); // MouseJstr
  3389. #endif
  3390. struct script_function buildin_func[] = {
  3391. {buildin_mes,"mes","s"},
  3392. {buildin_next,"next",""},
  3393. {buildin_close,"close",""},
  3394. {buildin_close2,"close2",""},
  3395. {buildin_menu,"menu","*"},
  3396. {buildin_goto,"goto","l"},
  3397. {buildin_callsub,"callsub","i*"},
  3398. {buildin_callfunc,"callfunc","s*"},
  3399. {buildin_return,"return","*"},
  3400. {buildin_getarg,"getarg","i"},
  3401. {buildin_jobchange,"jobchange","i*"},
  3402. {buildin_jobname,"jobname","i"},
  3403. {buildin_input,"input","*"},
  3404. {buildin_warp,"warp","sii"},
  3405. {buildin_areawarp,"areawarp","siiiisii"},
  3406. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  3407. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  3408. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  3409. {buildin_setlook,"setlook","ii"},
  3410. {buildin_set,"set","ii"},
  3411. {buildin_setarray,"setarray","ii*"},
  3412. {buildin_cleararray,"cleararray","iii"},
  3413. {buildin_copyarray,"copyarray","iii"},
  3414. {buildin_getarraysize,"getarraysize","i"},
  3415. {buildin_deletearray,"deletearray","ii"},
  3416. {buildin_getelementofarray,"getelementofarray","ii"},
  3417. {buildin_getitem,"getitem","ii**"},
  3418. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  3419. {buildin_getnameditem,"getnameditem","is"},
  3420. {buildin_grouprandomitem,"groupranditem","i"},
  3421. {buildin_makeitem,"makeitem","iisii"},
  3422. {buildin_delitem,"delitem","ii"},
  3423. {buildin_delitem2,"delitem2","iiiiiiiii"},
  3424. {buildin_enableitemuse,"enable_items",""},
  3425. {buildin_disableitemuse,"disable_items",""},
  3426. {buildin_cutin,"cutin","si"},
  3427. {buildin_cutincard,"cutincard","i"},
  3428. {buildin_viewpoint,"viewpoint","iiiii"},
  3429. {buildin_heal,"heal","ii"},
  3430. {buildin_itemheal,"itemheal","ii"},
  3431. {buildin_percentheal,"percentheal","ii"},
  3432. {buildin_rand,"rand","i*"},
  3433. {buildin_countitem,"countitem","i"},
  3434. {buildin_countitem2,"countitem2","iiiiiiii"},
  3435. {buildin_checkweight,"checkweight","ii"},
  3436. {buildin_readparam,"readparam","i*"},
  3437. {buildin_getcharid,"getcharid","i*"},
  3438. {buildin_getpartyname,"getpartyname","i"},
  3439. {buildin_getpartymember,"getpartymember","i*"},
  3440. {buildin_getpartyleader,"getpartyleader","i*"},
  3441. {buildin_getguildname,"getguildname","i"},
  3442. {buildin_getguildmaster,"getguildmaster","i"},
  3443. {buildin_getguildmasterid,"getguildmasterid","i"},
  3444. {buildin_strcharinfo,"strcharinfo","i"},
  3445. {buildin_getequipid,"getequipid","i"},
  3446. {buildin_getequipname,"getequipname","i"},
  3447. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  3448. {buildin_repair,"repair","i"}, // [Valaris]
  3449. {buildin_getequipisequiped,"getequipisequiped","i"},
  3450. {buildin_getequipisenableref,"getequipisenableref","i"},
  3451. {buildin_getequipisidentify,"getequipisidentify","i"},
  3452. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  3453. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  3454. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  3455. {buildin_successrefitem,"successrefitem","i"},
  3456. {buildin_failedrefitem,"failedrefitem","i"},
  3457. {buildin_statusup,"statusup","i"},
  3458. {buildin_statusup2,"statusup2","ii"},
  3459. {buildin_bonus,"bonus","ii"},
  3460. {buildin_bonus2,"bonus2","iii"},
  3461. {buildin_bonus3,"bonus3","iiii"},
  3462. {buildin_bonus4,"bonus4","iiiii"},
  3463. {buildin_skill,"skill","ii*"},
  3464. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  3465. {buildin_guildskill,"guildskill","ii"},
  3466. {buildin_getskilllv,"getskilllv","i"},
  3467. {buildin_getgdskilllv,"getgdskilllv","ii"},
  3468. {buildin_basicskillcheck,"basicskillcheck","*"},
  3469. {buildin_getgmlevel,"getgmlevel","*"},
  3470. {buildin_end,"end",""},
  3471. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  3472. {buildin_checkoption,"checkoption","i"},
  3473. {buildin_setoption,"setoption","i*"},
  3474. {buildin_setcart,"setcart",""},
  3475. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  3476. {buildin_setfalcon,"setfalcon",""},
  3477. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3478. {buildin_setriding,"setriding",""},
  3479. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3480. {buildin_savepoint,"save","sii"},
  3481. {buildin_savepoint,"savepoint","sii"},
  3482. {buildin_gettimetick,"gettimetick","i"},
  3483. {buildin_gettime,"gettime","i"},
  3484. {buildin_gettimestr,"gettimestr","si"},
  3485. {buildin_openstorage,"openstorage",""},
  3486. {buildin_guildopenstorage,"guildopenstorage","*"},
  3487. {buildin_itemskill,"itemskill","iis"},
  3488. {buildin_produce,"produce","i"},
  3489. {buildin_monster,"monster","siisii*"},
  3490. {buildin_areamonster,"areamonster","siiiisii*"},
  3491. {buildin_killmonster,"killmonster","ss"},
  3492. {buildin_killmonsterall,"killmonsterall","s"},
  3493. {buildin_clone,"clone","siisi*"},
  3494. {buildin_doevent,"doevent","s"},
  3495. {buildin_donpcevent,"donpcevent","s"},
  3496. {buildin_addtimer,"addtimer","is"},
  3497. {buildin_deltimer,"deltimer","s"},
  3498. {buildin_addtimercount,"addtimercount","si"},
  3499. {buildin_initnpctimer,"initnpctimer","*"},
  3500. {buildin_stopnpctimer,"stopnpctimer","*"},
  3501. {buildin_startnpctimer,"startnpctimer","*"},
  3502. {buildin_setnpctimer,"setnpctimer","*"},
  3503. {buildin_getnpctimer,"getnpctimer","i*"},
  3504. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  3505. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  3506. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  3507. {buildin_announce,"announce","si*"},
  3508. {buildin_mapannounce,"mapannounce","ssi*"},
  3509. {buildin_areaannounce,"areaannounce","siiiisi*"},
  3510. {buildin_getusers,"getusers","i"},
  3511. {buildin_getmapguildusers,"getmapguildusers","si"},
  3512. {buildin_getmapusers,"getmapusers","s"},
  3513. {buildin_getareausers,"getareausers","siiii"},
  3514. {buildin_getareadropitem,"getareadropitem","siiiii"},
  3515. {buildin_enablenpc,"enablenpc","s"},
  3516. {buildin_disablenpc,"disablenpc","s"},
  3517. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  3518. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  3519. {buildin_hideoffnpc,"hideoffnpc","s"},
  3520. {buildin_hideonnpc,"hideonnpc","s"},
  3521. {buildin_sc_start,"sc_start","iii*"},
  3522. {buildin_sc_start2,"sc_start2","iiii*"},
  3523. {buildin_sc_start4,"sc_start4","iiiiii*"},
  3524. {buildin_sc_end,"sc_end","i"},
  3525. {buildin_getscrate,"getscrate","ii*"},
  3526. {buildin_debugmes,"debugmes","s"},
  3527. {buildin_catchpet,"pet","i"},
  3528. {buildin_birthpet,"bpet",""},
  3529. {buildin_resetlvl,"resetlvl","i"},
  3530. {buildin_resetstatus,"resetstatus",""},
  3531. {buildin_resetskill,"resetskill",""},
  3532. {buildin_skillpointcount,"skillpointcount",""},
  3533. {buildin_changebase,"changebase","i"},
  3534. {buildin_changesex,"changesex",""},
  3535. {buildin_waitingroom,"waitingroom","si*"},
  3536. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  3537. {buildin_delwaitingroom,"delwaitingroom","*"},
  3538. {buildin_waitingroomkickall,"kickwaitingroomall","*"},
  3539. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  3540. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  3541. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  3542. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  3543. {buildin_attachrid,"attachrid","i"},
  3544. {buildin_detachrid,"detachrid",""},
  3545. {buildin_isloggedin,"isloggedin","i"},
  3546. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  3547. {buildin_setmapflag,"setmapflag","si*"},
  3548. {buildin_removemapflag,"removemapflag","si"},
  3549. {buildin_pvpon,"pvpon","s"},
  3550. {buildin_pvpoff,"pvpoff","s"},
  3551. {buildin_gvgon,"gvgon","s"},
  3552. {buildin_gvgoff,"gvgoff","s"},
  3553. {buildin_emotion,"emotion","i*"},
  3554. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  3555. {buildin_agitstart,"agitstart",""}, // <Agit>
  3556. {buildin_agitend,"agitend",""},
  3557. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  3558. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  3559. {buildin_getcastlename,"getcastlename","s"},
  3560. {buildin_getcastledata,"getcastledata","si*"},
  3561. {buildin_setcastledata,"setcastledata","sii"},
  3562. {buildin_requestguildinfo,"requestguildinfo","i*"},
  3563. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  3564. {buildin_successremovecards,"successremovecards","i"},
  3565. {buildin_failedremovecards,"failedremovecards","ii"},
  3566. {buildin_marriage,"marriage","s"},
  3567. {buildin_wedding_effect,"wedding",""},
  3568. {buildin_divorce,"divorce",""},
  3569. {buildin_ispartneron,"ispartneron",""},
  3570. {buildin_getpartnerid,"getpartnerid",""},
  3571. {buildin_getchildid,"getchildid",""},
  3572. {buildin_getmotherid,"getmotherid",""},
  3573. {buildin_getfatherid,"getfatherid",""},
  3574. {buildin_warppartner,"warppartner","sii"},
  3575. {buildin_getitemname,"getitemname","i"},
  3576. {buildin_getitemslots,"getitemslots","i"},
  3577. {buildin_makepet,"makepet","i"},
  3578. {buildin_getexp,"getexp","ii"},
  3579. {buildin_getinventorylist,"getinventorylist",""},
  3580. {buildin_getskilllist,"getskilllist",""},
  3581. {buildin_clearitem,"clearitem",""},
  3582. {buildin_classchange,"classchange","ii"},
  3583. {buildin_misceffect,"misceffect","i"},
  3584. {buildin_soundeffect,"soundeffect","si"},
  3585. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  3586. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  3587. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  3588. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  3589. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  3590. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  3591. {buildin_petloot,"petloot","i"}, // [Valaris]
  3592. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  3593. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  3594. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  3595. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  3596. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  3597. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  3598. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  3599. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  3600. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  3601. {buildin_nude,"nude",""}, // nude command [Valaris]
  3602. {buildin_mapwarp,"mapwarp","ssii*"}, // Added by RoVeRT
  3603. {buildin_inittimer,"inittimer",""},
  3604. {buildin_stoptimer,"stoptimer",""},
  3605. {buildin_cmdothernpc,"cmdothernpc","ss"},
  3606. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  3607. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  3608. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  3609. {buildin_message,"message","s*"}, // [MouseJstr]
  3610. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  3611. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  3612. {buildin_mobcount,"mobcount","ss"},
  3613. {buildin_getlook,"getlook","i"},
  3614. {buildin_getsavepoint,"getsavepoint","i"},
  3615. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  3616. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  3617. {buildin_npcstop,"npcstop",""}, // [Valaris]
  3618. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  3619. {buildin_checkoption1,"checkoption1","i"},
  3620. {buildin_checkoption2,"checkoption2","i"},
  3621. {buildin_guildgetexp,"guildgetexp","i"},
  3622. {buildin_guildchangegm,"guildchangegm","is"},
  3623. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  3624. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  3625. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  3626. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  3627. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  3628. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  3629. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  3630. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  3631. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  3632. {buildin_night,"night",""}, // sets the server to night time
  3633. {buildin_day,"day",""}, // sets the server to day time
  3634. #ifdef PCRE_SUPPORT
  3635. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  3636. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  3637. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  3638. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  3639. #endif
  3640. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  3641. {buildin_getusersname,"getusersname","*"},
  3642. {buildin_recovery,"recovery",""},
  3643. {buildin_getpetinfo,"getpetinfo","i"},
  3644. {buildin_checkequipedcard,"checkequipedcard","i"},
  3645. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  3646. {buildin_select,"select","*"}, //for future jA script compatibility
  3647. {buildin_prompt,"prompt","*"},
  3648. {buildin_globalmes,"globalmes","s*"},
  3649. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  3650. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  3651. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  3652. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  3653. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  3654. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  3655. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  3656. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  3657. // [zBuffer] List of mathematics commands --->
  3658. {buildin_sqrt,"sqrt","i"},
  3659. {buildin_pow,"pow","ii"},
  3660. {buildin_distance,"distance","iiii"},
  3661. {buildin_checkcell,"checkcell","siii"},
  3662. // <--- [zBuffer] List of mathematics commands
  3663. // [zBuffer] List of dynamic var commands --->
  3664. {buildin_getd,"getd","*"},
  3665. {buildin_setd,"setd","*"},
  3666. // <--- [zBuffer] List of dynamic var commands
  3667. {buildin_petstat,"petstat","i"},
  3668. {buildin_callshop,"callshop","si"}, // [Skotlex]
  3669. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  3670. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  3671. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  3672. {buildin_equip,"equip","i"},
  3673. {buildin_autoequip,"autoequip","ii"},
  3674. {buildin_setbattleflag,"setbattleflag","ss"},
  3675. {buildin_getbattleflag,"getbattleflag","s"},
  3676. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  3677. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  3678. {buildin_undisguise,"undisguise","*"}, //undisguise player. Lupus
  3679. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  3680. {buildin_axtoi,"axtoi","s"},
  3681. {buildin_query_sql, "query_sql", "s*"},
  3682. {buildin_escape_sql, "escape_sql", "s"},
  3683. {buildin_atoi,"atoi","s"},
  3684. // [zBuffer] List of player cont commands --->
  3685. {buildin_rid2name,"rid2name","i"},
  3686. {buildin_pcfollow,"pcfollow","ii"},
  3687. {buildin_pcstopfollow,"pcstopfollow","i"},
  3688. {buildin_pcblockmove,"pcblockmove","ii"},
  3689. // <--- [zBuffer] List of player cont commands
  3690. // [zBuffer] List of mob control commands --->
  3691. {buildin_mobspawn,"mobspawn","*"},
  3692. {buildin_mobremove,"mobremove","i"},
  3693. {buildin_getmobdata,"getmobdata","i*"},
  3694. {buildin_setmobdata,"setmobdata","iii"},
  3695. {buildin_mobassist,"mobassist","i*"},
  3696. {buildin_mobattach,"mobattach","i*"},
  3697. {buildin_unitwalk,"unitwalk","i*"},
  3698. {buildin_unitkill,"unitkill","i"},
  3699. {buildin_unitwarp,"unitwarp","isii"},
  3700. {buildin_unitattack,"unitattack","i*"},
  3701. {buildin_unitstop,"unitstop","i"},
  3702. {buildin_unittalk,"unittalk","is"},
  3703. {buildin_unitemote,"unitemote","ii"},
  3704. {buildin_unitdeadsit,"unitdeadsit","ii"},
  3705. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  3706. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  3707. // <--- [zBuffer] List of mob control commands
  3708. {buildin_sleep,"sleep","i"},
  3709. {buildin_sleep2,"sleep2","i"},
  3710. {buildin_awake,"awake","s"},
  3711. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  3712. // [blackhole89] -->
  3713. {buildin_warpportal,"warpportal","iisii"},
  3714. // <--- [blackhole89]
  3715. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  3716. {buildin_eaclass,"eaclass","*"}, //[Skotlex]
  3717. {buildin_roclass,"roclass","i*"}, //[Skotlex]
  3718. {buildin_checkvending,"checkvending","*"},
  3719. {buildin_checkchatting,"checkchatting","*"},
  3720. {NULL,NULL,NULL},
  3721. };
  3722. /*==========================================
  3723. *
  3724. *------------------------------------------
  3725. */
  3726. int buildin_mes(struct script_state *st)
  3727. {
  3728. struct map_session_data *sd = script_rid2sd(st);
  3729. char *mes = conv_str(st, &(st->stack->stack_data[st->start+2]));
  3730. if (sd)
  3731. clif_scriptmes(sd, st->oid, mes);
  3732. return 0;
  3733. }
  3734. /*==========================================
  3735. *
  3736. *------------------------------------------
  3737. */
  3738. int buildin_goto(struct script_state *st)
  3739. {
  3740. int pos;
  3741. if( st->stack->stack_data[st->start+2].type!=C_POS){
  3742. ShowMessage("script: goto: not label!\n");
  3743. st->state=END;
  3744. return 1;
  3745. }
  3746. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3747. st->pos=pos;
  3748. st->state=GOTO;
  3749. return 0;
  3750. }
  3751. /*==========================================
  3752. * ユーザー定義関数の呼び出し
  3753. *------------------------------------------
  3754. */
  3755. int buildin_callfunc(struct script_state *st)
  3756. {
  3757. struct script_code *scr, *oldscr;
  3758. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3759. if( (scr=strdb_get(userfunc_db,str)) ){
  3760. int i,j;
  3761. struct linkdb_node **oldval = st->stack->var_function;
  3762. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3763. push_copy(st->stack,i);
  3764. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3765. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3766. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3767. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3768. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3769. oldscr = st->script;
  3770. st->pos=0;
  3771. st->script=scr;
  3772. st->stack->defsp=st->start+5+j;
  3773. st->state=GOTO;
  3774. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3775. // ' 変数の引き継ぎ
  3776. for(i = 0; i < j; i++) {
  3777. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3778. if( s->type == C_NAME && !s->ref ) {
  3779. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3780. // '@ 変数の引き継ぎ
  3781. if( name[0] == '.' && name[1] == '@' ) {
  3782. s->ref = oldval;
  3783. } else if( name[0] == '.' ) {
  3784. s->ref = &oldscr->script_vars;
  3785. }
  3786. }
  3787. }
  3788. }else{
  3789. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  3790. st->state=END;
  3791. return 1;
  3792. }
  3793. return 0;
  3794. }
  3795. /*==========================================
  3796. * サブルーティンの呼び出し
  3797. *------------------------------------------
  3798. */
  3799. int buildin_callsub(struct script_state *st)
  3800. {
  3801. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3802. int i,j;
  3803. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  3804. ShowError("script: callsub: not label !\n");
  3805. st->state=END;
  3806. return 1;
  3807. } else {
  3808. struct linkdb_node **oldval = st->stack->var_function;
  3809. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3810. push_copy(st->stack,i);
  3811. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3812. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3813. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3814. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3815. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3816. st->pos=pos;
  3817. st->stack->defsp=st->start+5+j;
  3818. st->state=GOTO;
  3819. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3820. // ' 変数の引き継ぎ
  3821. for(i = 0; i < j; i++) {
  3822. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3823. if( s->type == C_NAME && !s->ref ) {
  3824. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3825. // '@ 変数の引き継ぎ
  3826. if( name[0] == '.' && name[1] == '@' ) {
  3827. s->ref = oldval;
  3828. }
  3829. }
  3830. }
  3831. }
  3832. return 0;
  3833. }
  3834. /*==========================================
  3835. * 引数の所得
  3836. *------------------------------------------
  3837. */
  3838. int buildin_getarg(struct script_state *st)
  3839. {
  3840. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3841. int max,stsp;
  3842. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  3843. ShowWarning("script:getarg without callfunc or callsub!\n");
  3844. st->state=END;
  3845. return 1;
  3846. }
  3847. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  3848. stsp=st->stack->defsp - max -5;
  3849. if( num >= max ){
  3850. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  3851. st->state=END;
  3852. return 1;
  3853. }
  3854. push_copy(st->stack,stsp+num);
  3855. return 0;
  3856. }
  3857. /*==========================================
  3858. * サブルーチン/ユーザー定義関数の終了
  3859. *------------------------------------------
  3860. */
  3861. int buildin_return(struct script_state *st)
  3862. {
  3863. if(st->end>st->start+2){ // 戻り値有り
  3864. struct script_data *sd;
  3865. push_copy(st->stack,st->start+2);
  3866. sd = &st->stack->stack_data[st->stack->sp-1];
  3867. if(sd->type == C_NAME) {
  3868. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  3869. if( name[0] == '.' && name[1] == '@') {
  3870. // '@ 変数を参照渡しにすると危険なので値渡しにする
  3871. get_val(st,sd);
  3872. } else if( name[0] == '.' && !sd->ref) {
  3873. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  3874. // 元のスクリプトの値を差してしまうので補正する。
  3875. sd->ref = &st->script->script_vars;
  3876. }
  3877. }
  3878. }
  3879. st->state=RETFUNC;
  3880. return 0;
  3881. }
  3882. /*==========================================
  3883. *
  3884. *------------------------------------------
  3885. */
  3886. int buildin_next(struct script_state *st)
  3887. {
  3888. st->state=STOP;
  3889. clif_scriptnext(script_rid2sd(st),st->oid);
  3890. return 0;
  3891. }
  3892. /*==========================================
  3893. *
  3894. *------------------------------------------
  3895. */
  3896. int buildin_close(struct script_state *st)
  3897. {
  3898. st->state=END;
  3899. clif_scriptclose(script_rid2sd(st),st->oid);
  3900. return 0;
  3901. }
  3902. int buildin_close2(struct script_state *st)
  3903. {
  3904. st->state=STOP;
  3905. clif_scriptclose(script_rid2sd(st),st->oid);
  3906. return 0;
  3907. }
  3908. /*==========================================
  3909. *
  3910. *------------------------------------------
  3911. */
  3912. int buildin_menu(struct script_state *st)
  3913. {
  3914. char *buf;
  3915. int len,i, max = 1;
  3916. struct map_session_data *sd = script_rid2sd(st);
  3917. nullpo_retr(0, sd);
  3918. if(sd->state.menu_or_input==0){
  3919. st->state=RERUNLINE;
  3920. sd->state.menu_or_input=1;
  3921. if( (st->end - st->start - 2) % 2 == 1 ) {
  3922. // 引数の数が奇数なのでエラー扱い
  3923. ShowError("buildin_menu: illegal argument count(%d).\n", st->end - st->start - 2);
  3924. sd->state.menu_or_input=0;
  3925. st->state=END;
  3926. return 1;
  3927. }
  3928. for(i=st->start+2,len=0;i<st->end;i+=2){
  3929. conv_str(st,& (st->stack->stack_data[i]));
  3930. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  3931. }
  3932. buf=(char *)aMallocA((len+1)*sizeof(char));
  3933. buf[0]=0;
  3934. for(i=st->start+2,len=0;i<st->end;i+=2){
  3935. if( st->stack->stack_data[i].u.str[0] ) {
  3936. strcat(buf,st->stack->stack_data[i].u.str);
  3937. strcat(buf,":");
  3938. }
  3939. }
  3940. for(i=0; (unsigned int)i < strlen(buf); i++){
  3941. if(buf[i] == ':')
  3942. max++;
  3943. }
  3944. sd->max_menu = max;
  3945. clif_scriptmenu(sd,st->oid,buf);
  3946. aFree(buf);
  3947. } else if(sd->npc_menu==0xff){ // cancel
  3948. sd->state.menu_or_input=0;
  3949. st->state=END;
  3950. } else { // goto動作
  3951. sd->state.menu_or_input=0;
  3952. if(sd->npc_menu>0){
  3953. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  3954. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2) {
  3955. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  3956. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  3957. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  3958. }
  3959. if(sd->npc_menu >= (st->end-st->start)/2) {
  3960. //Invalid selection.
  3961. st->state=END;
  3962. return 0;
  3963. }
  3964. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  3965. ShowError("script: menu: not label !\n");
  3966. st->state=END;
  3967. return 1;
  3968. }
  3969. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  3970. st->pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  3971. st->state=GOTO;
  3972. }
  3973. }
  3974. return 0;
  3975. }
  3976. /*==========================================
  3977. *
  3978. *------------------------------------------
  3979. */
  3980. int buildin_rand(struct script_state *st)
  3981. {
  3982. int range,min,max;
  3983. if (st->end > st->start+3){
  3984. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3985. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3986. if (max == min){ //Why would someone do this?
  3987. push_val(st->stack,C_INT,min);
  3988. return 0;
  3989. }
  3990. if(max<min){
  3991. int tmp = min;
  3992. min = max;
  3993. max = tmp;
  3994. }
  3995. range = max - min + 1;
  3996. if (range == 0) range = 1;
  3997. push_val(st->stack,C_INT,rand()%range+min);
  3998. } else {
  3999. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4000. if (range == 0) range = 1;
  4001. push_val(st->stack,C_INT,rand()%range);
  4002. }
  4003. return 0;
  4004. }
  4005. /*==========================================
  4006. *
  4007. *------------------------------------------
  4008. */
  4009. int buildin_warp(struct script_state *st)
  4010. {
  4011. int x,y;
  4012. char *str;
  4013. struct map_session_data *sd=script_rid2sd(st);
  4014. nullpo_retr(0, sd);
  4015. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4016. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4017. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4018. if(strcmp(str,"Random")==0)
  4019. pc_randomwarp(sd,3);
  4020. else if(strcmp(str,"SavePoint")==0){
  4021. pc_setpos(sd,sd->status.save_point.map,
  4022. sd->status.save_point.x,sd->status.save_point.y,3);
  4023. }else if(strcmp(str,"Save")==0){
  4024. pc_setpos(sd,sd->status.save_point.map,
  4025. sd->status.save_point.x,sd->status.save_point.y,3);
  4026. }else
  4027. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  4028. return 0;
  4029. }
  4030. /*==========================================
  4031. * エリア指定ワープ
  4032. *------------------------------------------
  4033. */
  4034. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  4035. {
  4036. int x,y;
  4037. unsigned int map;
  4038. map=va_arg(ap, unsigned int);
  4039. x=va_arg(ap,int);
  4040. y=va_arg(ap,int);
  4041. if(map == 0)
  4042. pc_randomwarp((struct map_session_data *)bl,3);
  4043. else
  4044. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  4045. return 0;
  4046. }
  4047. int buildin_areawarp(struct script_state *st)
  4048. {
  4049. int x,y,m;
  4050. unsigned int index;
  4051. char *str;
  4052. char *mapname;
  4053. int x0,y0,x1,y1;
  4054. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4055. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4056. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4057. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4058. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4059. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  4060. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4061. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4062. if( (m=map_mapname2mapid(mapname))< 0)
  4063. return 0;
  4064. if(strcmp(str,"Random")==0)
  4065. index = 0;
  4066. else if(!(index=mapindex_name2id(str)))
  4067. return 0;
  4068. map_foreachinarea(buildin_areawarp_sub,
  4069. m,x0,y0,x1,y1,BL_PC, index,x,y );
  4070. return 0;
  4071. }
  4072. /*==========================================
  4073. * warpchar [LuzZza]
  4074. * Useful for warp one player from
  4075. * another player npc-session.
  4076. * Using: warpchar "mapname.gat",x,y,Char_ID;
  4077. *------------------------------------------
  4078. */
  4079. int buildin_warpchar(struct script_state *st)
  4080. {
  4081. int x,y,a,i;
  4082. char *str;
  4083. struct map_session_data *sd, **pl_allsd;
  4084. int users;
  4085. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4086. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4087. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4088. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4089. pl_allsd = map_getallusers(&users);
  4090. for(i=0; i<users; i++) {
  4091. sd = pl_allsd[i];
  4092. if(sd->status.char_id == a) {
  4093. if(strcmp(str, "Random") == 0)
  4094. pc_randomwarp(sd, 3);
  4095. else if(strcmp(str, "SavePoint") == 0)
  4096. pc_setpos(sd, sd->status.save_point.map,
  4097. sd->status.save_point.x, sd->status.save_point.y, 3);
  4098. else
  4099. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  4100. }
  4101. }
  4102. return 0;
  4103. }
  4104. /*==========================================
  4105. * Warpparty - [Fredzilla]
  4106. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  4107. *------------------------------------------
  4108. */
  4109. int buildin_warpparty(struct script_state *st)
  4110. {
  4111. int x,y;
  4112. char *str;
  4113. int p_id;
  4114. int i;
  4115. unsigned short mapindex;
  4116. struct map_session_data *pl_sd;
  4117. struct party_data *p=NULL;
  4118. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4119. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4120. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4121. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4122. if(p_id < 1)
  4123. return 0;
  4124. p = party_search(p_id);
  4125. if (!p)
  4126. return 0;
  4127. if(strcmp(str,"Random")==0)
  4128. {
  4129. for (i = 0; i < MAX_PARTY; i++)
  4130. {
  4131. if ((pl_sd = p->data[i].sd))
  4132. {
  4133. if(map[pl_sd->bl.m].flag.nowarp)
  4134. continue;
  4135. pc_randomwarp(pl_sd,3);
  4136. }
  4137. }
  4138. }
  4139. else if(strcmp(str,"SavePointAll")==0)
  4140. {
  4141. for (i = 0; i < MAX_PARTY; i++)
  4142. {
  4143. if ((pl_sd = p->data[i].sd))
  4144. {
  4145. if(map[pl_sd->bl.m].flag.noreturn)
  4146. continue;
  4147. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4148. }
  4149. }
  4150. }
  4151. else if(strcmp(str,"SavePoint")==0)
  4152. {
  4153. pl_sd=script_rid2sd(st);
  4154. if (!pl_sd) return 0;
  4155. mapindex=pl_sd->status.save_point.map;
  4156. x=pl_sd->status.save_point.x;
  4157. y=pl_sd->status.save_point.y;
  4158. for (i = 0; i < MAX_PARTY; i++)
  4159. {
  4160. if ((pl_sd = p->data[i].sd))
  4161. {
  4162. if(map[pl_sd->bl.m].flag.noreturn)
  4163. continue;
  4164. pc_setpos(pl_sd,mapindex,x,y,3);
  4165. }
  4166. }
  4167. }
  4168. else
  4169. {
  4170. mapindex = mapindex_name2id(str);
  4171. if (!mapindex) //Show source of npc error.
  4172. return 1;
  4173. for (i = 0; i < MAX_PARTY; i++)
  4174. {
  4175. if ((pl_sd = p->data[i].sd))
  4176. {
  4177. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4178. continue;
  4179. pc_setpos(pl_sd,mapindex,x,y,3);
  4180. }
  4181. }
  4182. }
  4183. return 0;
  4184. }
  4185. /*==========================================
  4186. * Warpguild - [Fredzilla]
  4187. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  4188. *------------------------------------------
  4189. */
  4190. int buildin_warpguild(struct script_state *st)
  4191. {
  4192. int x,y;
  4193. unsigned short mapindex;
  4194. char *str;
  4195. int g;
  4196. int i;
  4197. struct map_session_data *pl_sd, **pl_allsd;
  4198. int users;
  4199. struct map_session_data *sd;
  4200. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4201. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4202. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4203. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4204. sd=script_rid2sd(st);
  4205. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  4206. return 0;
  4207. if(g < 1)
  4208. return 0;
  4209. pl_allsd = map_getallusers(&users);
  4210. if(strcmp(str,"Random")==0)
  4211. {
  4212. for (i = 0; i < users; i++)
  4213. {
  4214. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4215. {
  4216. if(map[pl_sd->bl.m].flag.nowarp)
  4217. continue;
  4218. pc_randomwarp(pl_sd,3);
  4219. }
  4220. }
  4221. }
  4222. else if(strcmp(str,"SavePointAll")==0)
  4223. {
  4224. if(map[sd->bl.m].flag.noreturn)
  4225. return 0;
  4226. for (i = 0; i < users; i++)
  4227. {
  4228. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4229. {
  4230. if(map[pl_sd->bl.m].flag.noreturn)
  4231. continue;
  4232. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4233. }
  4234. }
  4235. }
  4236. else if(strcmp(str,"SavePoint")==0)
  4237. {
  4238. if(map[sd->bl.m].flag.noreturn)
  4239. return 0;
  4240. mapindex=sd->status.save_point.map;
  4241. x=sd->status.save_point.x;
  4242. y=sd->status.save_point.y;
  4243. for (i = 0; i < users; i++)
  4244. {
  4245. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4246. {
  4247. if(map[pl_sd->bl.m].flag.noreturn)
  4248. continue;
  4249. pc_setpos(pl_sd,mapindex,x,y,3);
  4250. }
  4251. }
  4252. }
  4253. else
  4254. {
  4255. mapindex = mapindex_name2id(str);
  4256. for (i = 0; i < users; i++)
  4257. {
  4258. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4259. {
  4260. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4261. continue;
  4262. pc_setpos(pl_sd,mapindex,x,y,3);
  4263. }
  4264. }
  4265. }
  4266. return 0;
  4267. }
  4268. /*==========================================
  4269. *
  4270. *------------------------------------------
  4271. */
  4272. int buildin_heal(struct script_state *st)
  4273. {
  4274. struct map_session_data *sd;
  4275. int hp,sp;
  4276. sd = script_rid2sd(st);
  4277. if (!sd) return 0;
  4278. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4279. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4280. status_heal(&sd->bl, hp, sp, 1);
  4281. return 0;
  4282. }
  4283. /*==========================================
  4284. *
  4285. *------------------------------------------
  4286. */
  4287. int buildin_itemheal(struct script_state *st)
  4288. {
  4289. struct map_session_data *sd;
  4290. int hp,sp;
  4291. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4292. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4293. if(potion_flag==1) {
  4294. potion_hp = hp;
  4295. potion_sp = sp;
  4296. return 0;
  4297. }
  4298. sd = script_rid2sd(st);
  4299. if (!sd) return 0;
  4300. pc_itemheal(sd,sd->itemid,hp,sp);
  4301. return 0;
  4302. }
  4303. /*==========================================
  4304. *
  4305. *------------------------------------------
  4306. */
  4307. int buildin_percentheal(struct script_state *st)
  4308. {
  4309. int hp,sp;
  4310. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4311. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4312. if(potion_flag==1) {
  4313. potion_per_hp = hp;
  4314. potion_per_sp = sp;
  4315. return 0;
  4316. }
  4317. pc_percentheal(script_rid2sd(st),hp,sp);
  4318. return 0;
  4319. }
  4320. /*==========================================
  4321. *
  4322. *------------------------------------------
  4323. */
  4324. int buildin_jobchange(struct script_state *st)
  4325. {
  4326. int job, upper=-1;
  4327. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4328. if( st->end>st->start+3 )
  4329. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4330. if ((job >= 0 && job < MAX_PC_CLASS))
  4331. {
  4332. pc_jobchange(script_rid2sd(st),job, upper);
  4333. if(use_irc && irc_announce_jobchange_flag)
  4334. irc_announce_jobchange(script_rid2sd(st));
  4335. }
  4336. return 0;
  4337. }
  4338. /*==========================================
  4339. *
  4340. *------------------------------------------
  4341. */
  4342. int buildin_jobname(struct script_state *st)
  4343. {
  4344. int class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4345. push_str(st->stack,C_CONSTSTR,job_name(class_));
  4346. return 0;
  4347. }
  4348. /*==========================================
  4349. *
  4350. *------------------------------------------
  4351. */
  4352. int buildin_input(struct script_state *st)
  4353. {
  4354. struct map_session_data *sd = script_rid2sd(st);
  4355. int num = (st->end>st->start+2)? st->stack->stack_data[st->start+2].u.num: 0;
  4356. char *name = (st->end>st->start+2)? str_buf+str_data[num&0x00ffffff].str: "";
  4357. char postfix=name[strlen(name)-1];
  4358. nullpo_retr(0, sd);
  4359. if(sd->state.menu_or_input){
  4360. sd->state.menu_or_input=0;
  4361. if( postfix=='$' ){
  4362. // 文字列
  4363. if(st->end>st->start+2){ // 引数1個
  4364. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  4365. }else{
  4366. ShowError("buildin_input: string discarded !!\n");
  4367. return 1;
  4368. }
  4369. return 0;
  4370. }
  4371. // commented by Lupus (check Value Number Input fix in clif.c)
  4372. // readded by Yor: set ammount to 0 instead of cancel trade.
  4373. // ** Fix by fritz :X keeps people from abusing old input bugs
  4374. if (sd->npc_amount < 0) { //** If input amount is less then 0
  4375. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  4376. // buildin_close(st); // ** close
  4377. sd->npc_amount = 0;
  4378. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  4379. sd->npc_amount = battle_config.vending_max_value;
  4380. // 数値
  4381. if(st->end>st->start+2){ // 引数1個
  4382. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  4383. } else {
  4384. // ragemu互換のため
  4385. //pc_setreg(sd,add_str("l14"),sd->npc_amount);
  4386. }
  4387. return 0;
  4388. }
  4389. //state.menu_or_input = 0
  4390. st->state=RERUNLINE;
  4391. if(postfix=='$')
  4392. clif_scriptinputstr(sd,st->oid);
  4393. else
  4394. clif_scriptinput(sd,st->oid);
  4395. sd->state.menu_or_input=1;
  4396. return 0;
  4397. }
  4398. /*==========================================
  4399. * 変数設定
  4400. *------------------------------------------
  4401. */
  4402. int buildin_set(struct script_state *st)
  4403. {
  4404. struct map_session_data *sd=NULL;
  4405. int num=st->stack->stack_data[st->start+2].u.num;
  4406. char *name=str_buf+str_data[num&0x00ffffff].str;
  4407. char prefix=*name;
  4408. char postfix=name[strlen(name)-1];
  4409. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  4410. ShowError("script: buildin_set: not name\n");
  4411. return 1;
  4412. }
  4413. if(not_server_variable(prefix))
  4414. sd=script_rid2sd(st);
  4415. if( postfix=='$' ){
  4416. // 文字列
  4417. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4418. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  4419. }else{
  4420. // 数値
  4421. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  4422. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  4423. }
  4424. return 0;
  4425. }
  4426. /*==========================================
  4427. * 配列変数設定
  4428. *------------------------------------------
  4429. */
  4430. int buildin_setarray(struct script_state *st)
  4431. {
  4432. struct map_session_data *sd=NULL;
  4433. int num=st->stack->stack_data[st->start+2].u.num;
  4434. char *name=str_buf+str_data[num&0x00ffffff].str;
  4435. char prefix=*name;
  4436. char postfix=name[strlen(name)-1];
  4437. int i,j;
  4438. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4439. ShowWarning("buildin_setarray: illegal scope !\n");
  4440. return 1;
  4441. }
  4442. if(not_server_variable(prefix))
  4443. sd=script_rid2sd(st);
  4444. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  4445. void *v;
  4446. if( postfix=='$' )
  4447. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  4448. else
  4449. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  4450. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  4451. }
  4452. return 0;
  4453. }
  4454. /*==========================================
  4455. * 配列変数クリア
  4456. *------------------------------------------
  4457. */
  4458. int buildin_cleararray(struct script_state *st)
  4459. {
  4460. struct map_session_data *sd=NULL;
  4461. int num=st->stack->stack_data[st->start+2].u.num;
  4462. char *name=str_buf+str_data[num&0x00ffffff].str;
  4463. char prefix=*name;
  4464. char postfix=name[strlen(name)-1];
  4465. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4466. int i;
  4467. void *v;
  4468. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4469. ShowWarning("buildin_cleararray: illegal scope !\n");
  4470. return 1;
  4471. }
  4472. if( not_server_variable(prefix) )
  4473. sd=script_rid2sd(st);
  4474. if( postfix=='$' )
  4475. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  4476. else
  4477. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  4478. for(i=0;i<sz;i++)
  4479. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  4480. return 0;
  4481. }
  4482. /*==========================================
  4483. * 配列変数コピー
  4484. *------------------------------------------
  4485. */
  4486. int buildin_copyarray(struct script_state *st)
  4487. {
  4488. struct map_session_data *sd=NULL;
  4489. int num=st->stack->stack_data[st->start+2].u.num;
  4490. char *name=str_buf+str_data[num&0x00ffffff].str;
  4491. char prefix=*name;
  4492. char postfix=name[strlen(name)-1];
  4493. int num2=st->stack->stack_data[st->start+3].u.num;
  4494. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  4495. char prefix2=*name2;
  4496. char postfix2=name2[strlen(name2)-1];
  4497. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4498. int i;
  4499. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4500. printf("buildin_copyarray: illeagal scope !\n");
  4501. return 0;
  4502. }
  4503. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  4504. printf("buildin_copyarray: illeagal scope !\n");
  4505. return 0;
  4506. }
  4507. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  4508. printf("buildin_copyarray: type mismatch !\n");
  4509. return 0;
  4510. }
  4511. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  4512. sd=script_rid2sd(st);
  4513. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  4514. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  4515. for(i=sz-1;i>=0;i--)
  4516. set_reg(
  4517. st,sd,num+(i<<24),name,
  4518. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4519. st->stack->stack_data[st->start+2].ref
  4520. );
  4521. } else {
  4522. for(i=0;i<sz;i++)
  4523. set_reg(
  4524. st,sd,num+(i<<24),name,
  4525. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4526. st->stack->stack_data[st->start+2].ref
  4527. );
  4528. }
  4529. return 0;
  4530. }
  4531. /*==========================================
  4532. * 配列変数のサイズ所得
  4533. *------------------------------------------
  4534. */
  4535. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  4536. {
  4537. int i=(num>>24),c=(i==0? -1:i); // Moded to -1 because even if the first element is 0, it will still report as 1 [Lance]
  4538. if(postfix == '$'){
  4539. for(;i<128;i++){
  4540. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4541. if(*((char*)v)) c=i;
  4542. }
  4543. }else{
  4544. for(;i<128;i++){
  4545. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4546. if((int)v) c=i;
  4547. }
  4548. }
  4549. return c+1;
  4550. }
  4551. int buildin_getarraysize(struct script_state *st)
  4552. {
  4553. int num=st->stack->stack_data[st->start+2].u.num;
  4554. char *name=str_buf+str_data[num&0x00ffffff].str;
  4555. char prefix=*name;
  4556. char postfix=name[strlen(name)-1];
  4557. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4558. ShowWarning("buildin_copyarray: illegal scope !\n");
  4559. push_val(st->stack,C_INT,0);
  4560. return 1;
  4561. }
  4562. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  4563. return 0;
  4564. }
  4565. /*==========================================
  4566. * 配列変数から要素削除
  4567. *------------------------------------------
  4568. */
  4569. int buildin_deletearray(struct script_state *st)
  4570. {
  4571. struct map_session_data *sd=NULL;
  4572. int num=st->stack->stack_data[st->start+2].u.num;
  4573. char *name=str_buf+str_data[num&0x00ffffff].str;
  4574. char prefix=*name;
  4575. char postfix=name[strlen(name)-1];
  4576. int count=1;
  4577. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  4578. if( (st->end > st->start+3) )
  4579. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4580. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4581. ShowWarning("buildin_deletearray: illegal scope !\n");
  4582. return 1;
  4583. }
  4584. if( not_server_variable(prefix) )
  4585. sd=script_rid2sd(st);
  4586. for(i=0;i<sz;i++){
  4587. set_reg(
  4588. st,sd,num+(i<<24),name,
  4589. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  4590. st->stack->stack_data[st->start+2].ref
  4591. );
  4592. }
  4593. if(postfix != '$'){
  4594. for(;i<(128-(num>>24));i++)
  4595. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  4596. } else {
  4597. for(;i<(128-(num>>24));i++)
  4598. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  4599. }
  4600. return 0;
  4601. }
  4602. /*==========================================
  4603. * 指定要素を表す値(キー)を所得する
  4604. *------------------------------------------
  4605. */
  4606. int buildin_getelementofarray(struct script_state *st)
  4607. {
  4608. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  4609. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4610. if(i>127 || i<0){
  4611. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  4612. push_val(st->stack,C_INT,0);
  4613. return 1;
  4614. }else{
  4615. push_val2(st->stack,C_NAME,
  4616. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  4617. }
  4618. }else{
  4619. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  4620. push_val(st->stack,C_INT,0);
  4621. }
  4622. return 0;
  4623. }
  4624. /*==========================================
  4625. *
  4626. *------------------------------------------
  4627. */
  4628. int buildin_setlook(struct script_state *st)
  4629. {
  4630. int type,val;
  4631. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4632. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4633. pc_changelook(script_rid2sd(st),type,val);
  4634. return 0;
  4635. }
  4636. /*==========================================
  4637. *
  4638. *------------------------------------------
  4639. */
  4640. int buildin_cutin(struct script_state *st)
  4641. {
  4642. int type;
  4643. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4644. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4645. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  4646. return 0;
  4647. }
  4648. /*==========================================
  4649. * カードのイラストを表示する
  4650. *------------------------------------------
  4651. */
  4652. int buildin_cutincard(struct script_state *st)
  4653. {
  4654. int itemid;
  4655. struct item_data *i_data;
  4656. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4657. i_data = itemdb_exists(itemid);
  4658. if (i_data)
  4659. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  4660. return 0;
  4661. }
  4662. /*==========================================
  4663. *
  4664. *------------------------------------------
  4665. */
  4666. int buildin_viewpoint(struct script_state *st)
  4667. {
  4668. int type,x,y,id,color;
  4669. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4670. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4671. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4672. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4673. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4674. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  4675. return 0;
  4676. }
  4677. /*==========================================
  4678. *
  4679. *------------------------------------------
  4680. */
  4681. int buildin_countitem(struct script_state *st)
  4682. {
  4683. int nameid=0,count=0,i;
  4684. struct map_session_data *sd;
  4685. struct script_data *data;
  4686. sd = script_rid2sd(st);
  4687. data=&(st->stack->stack_data[st->start+2]);
  4688. get_val(st,data);
  4689. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4690. const char *name=conv_str(st,data);
  4691. struct item_data *item_data;
  4692. if( (item_data = itemdb_searchname(name)) != NULL)
  4693. nameid=item_data->nameid;
  4694. }else
  4695. nameid=conv_num(st,data);
  4696. if (nameid>=500) //if no such ID then skip this iteration
  4697. for(i=0;i<MAX_INVENTORY;i++){
  4698. if(sd->status.inventory[i].nameid==nameid)
  4699. count+=sd->status.inventory[i].amount;
  4700. }
  4701. else{
  4702. if(battle_config.error_log)
  4703. ShowError("wrong item ID : countitem(%i)\n",nameid);
  4704. push_val(st->stack,C_INT,0);
  4705. return 1;
  4706. }
  4707. push_val(st->stack,C_INT,count);
  4708. return 0;
  4709. }
  4710. /*==========================================
  4711. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  4712. * returns number of items that met the conditions
  4713. *------------------------------------------
  4714. */
  4715. int buildin_countitem2(struct script_state *st)
  4716. {
  4717. int nameid=0,count=0,i;
  4718. int iden,ref,attr,c1,c2,c3,c4;
  4719. struct map_session_data *sd;
  4720. struct script_data *data;
  4721. sd = script_rid2sd(st);
  4722. data=&(st->stack->stack_data[st->start+2]);
  4723. get_val(st,data);
  4724. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4725. const char *name=conv_str(st,data);
  4726. struct item_data *item_data;
  4727. if( (item_data = itemdb_searchname(name)) != NULL)
  4728. nameid=item_data->nameid;
  4729. }else
  4730. nameid=conv_num(st,data);
  4731. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4732. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4733. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4734. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4735. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4736. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4737. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4738. if (nameid>=500) //if no such ID then skip this iteration
  4739. for(i=0;i<MAX_INVENTORY;i++){
  4740. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4741. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4742. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4743. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4744. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4745. sd->status.inventory[i].card[3]!=c4)
  4746. continue;
  4747. count+=sd->status.inventory[i].amount;
  4748. }
  4749. else{
  4750. if(battle_config.error_log)
  4751. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  4752. push_val(st->stack,C_INT,0);
  4753. return 1;
  4754. }
  4755. push_val(st->stack,C_INT,count);
  4756. return 0;
  4757. }
  4758. /*==========================================
  4759. * 重量チェック
  4760. *------------------------------------------
  4761. */
  4762. int buildin_checkweight(struct script_state *st)
  4763. {
  4764. int nameid=0,amount,i;
  4765. unsigned long weight;
  4766. struct map_session_data *sd;
  4767. struct script_data *data;
  4768. sd = script_rid2sd(st);
  4769. data=&(st->stack->stack_data[st->start+2]);
  4770. get_val(st,data);
  4771. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4772. const char *name=conv_str(st,data);
  4773. struct item_data *item_data = itemdb_searchname(name);
  4774. if( item_data )
  4775. nameid=item_data->nameid;
  4776. }else
  4777. nameid=conv_num(st,data);
  4778. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4779. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  4780. push_val(st->stack,C_INT,0);
  4781. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  4782. return 1;
  4783. }
  4784. weight = itemdb_weight(nameid)*amount;
  4785. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  4786. push_val(st->stack,C_INT,0);
  4787. } else {
  4788. //Check if the inventory ain't full.
  4789. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  4790. i = pc_search_inventory(sd,0);
  4791. if (i >= 0) //Empty slot available.
  4792. push_val(st->stack,C_INT,1);
  4793. else //Inventory full
  4794. push_val(st->stack,C_INT,0);
  4795. }
  4796. return 0;
  4797. }
  4798. /*==========================================
  4799. *
  4800. *------------------------------------------
  4801. */
  4802. int buildin_getitem(struct script_state *st)
  4803. {
  4804. int nameid,amount,flag = 0;
  4805. struct item item_tmp;
  4806. struct map_session_data *sd;
  4807. struct script_data *data;
  4808. sd = script_rid2sd(st);
  4809. data=&(st->stack->stack_data[st->start+2]);
  4810. get_val(st,data);
  4811. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4812. const char *name=conv_str(st,data);
  4813. struct item_data *item_data = itemdb_searchname(name);
  4814. if( item_data == NULL) {
  4815. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  4816. return 1; //No item created.
  4817. }
  4818. nameid=item_data->nameid;
  4819. }else
  4820. nameid=conv_num(st,data);
  4821. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  4822. return 0; //return if amount <=0, skip the useles iteration
  4823. //Violet Box, Blue Box, etc - random item pick
  4824. if(nameid <0) {
  4825. nameid=itemdb_searchrandomid(-nameid);
  4826. flag = 1;
  4827. }
  4828. if(nameid <= 0 || !itemdb_exists(nameid)) {
  4829. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  4830. return 1; //No item created.
  4831. }
  4832. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4833. item_tmp.nameid=nameid;
  4834. if(!flag)
  4835. item_tmp.identify=1;
  4836. else
  4837. item_tmp.identify=itemdb_isidentified(nameid);
  4838. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  4839. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  4840. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4841. return 0;
  4842. if(pet_create_egg(sd, nameid))
  4843. amount = 1; //This is a pet!
  4844. else
  4845. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4846. clif_additem(sd,0,0,flag);
  4847. if (pc_candrop(sd, &item_tmp))
  4848. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4849. }
  4850. //Logs items, got from (N)PC scripts [Lupus]
  4851. if(log_config.enable_logs&0x40)
  4852. log_pick_pc(sd, "N", nameid, amount, NULL);
  4853. return 0;
  4854. }
  4855. /*==========================================
  4856. *
  4857. *------------------------------------------
  4858. */
  4859. int buildin_getitem2(struct script_state *st)
  4860. {
  4861. int nameid,amount,flag = 0;
  4862. int iden,ref,attr,c1,c2,c3,c4;
  4863. struct item_data *item_data;
  4864. struct item item_tmp;
  4865. struct map_session_data *sd;
  4866. struct script_data *data;
  4867. sd = script_rid2sd(st);
  4868. data=&(st->stack->stack_data[st->start+2]);
  4869. get_val(st,data);
  4870. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4871. const char *name=conv_str(st,data);
  4872. struct item_data *item_data = itemdb_searchname(name);
  4873. nameid=UNKNOWN_ITEM_ID;
  4874. if( item_data )
  4875. nameid=item_data->nameid;
  4876. }else
  4877. nameid=conv_num(st,data);
  4878. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4879. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4880. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4881. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4882. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4883. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4884. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4885. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4886. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  4887. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  4888. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4889. return 0;
  4890. if(nameid<0) { // ランダム
  4891. nameid=itemdb_searchrandomid(-nameid);
  4892. flag = 1;
  4893. }
  4894. if(nameid > 0) {
  4895. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4896. item_data=itemdb_exists(nameid);
  4897. if (item_data == NULL)
  4898. return -1;
  4899. if(item_data->type==4 || item_data->type==5){
  4900. if(ref > 10) ref = 10;
  4901. }
  4902. else if(item_data->type==7) {
  4903. iden = 1;
  4904. ref = 0;
  4905. }
  4906. else {
  4907. iden = 1;
  4908. ref = attr = 0;
  4909. }
  4910. item_tmp.nameid=nameid;
  4911. if(!flag)
  4912. item_tmp.identify=iden;
  4913. else if(item_data->type==4 || item_data->type==5)
  4914. item_tmp.identify=0;
  4915. item_tmp.refine=ref;
  4916. item_tmp.attribute=attr;
  4917. item_tmp.card[0]=c1;
  4918. item_tmp.card[1]=c2;
  4919. item_tmp.card[2]=c3;
  4920. item_tmp.card[3]=c4;
  4921. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4922. clif_additem(sd,0,0,flag);
  4923. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4924. }
  4925. //Logs items, got from (N)PC scripts [Lupus]
  4926. if(log_config.enable_logs&0x40)
  4927. log_pick_pc(sd, "N", nameid, amount, &item_tmp);
  4928. }
  4929. return 0;
  4930. }
  4931. /*==========================================
  4932. * gets an item with someone's name inscribed [Skotlex]
  4933. * getinscribeditem item_num, character_name
  4934. * Returned Qty is always 1, only works on equip-able
  4935. * equipment
  4936. *------------------------------------------
  4937. */
  4938. int buildin_getnameditem(struct script_state *st)
  4939. {
  4940. int nameid;
  4941. struct item item_tmp;
  4942. struct map_session_data *sd, *tsd;
  4943. struct script_data *data;
  4944. sd = script_rid2sd(st);
  4945. if (sd == NULL)
  4946. { //Player not attached!
  4947. push_val(st->stack,C_INT,0);
  4948. return 0;
  4949. }
  4950. data=&(st->stack->stack_data[st->start+2]);
  4951. get_val(st,data);
  4952. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4953. const char *name=conv_str(st,data);
  4954. struct item_data *item_data = itemdb_searchname(name);
  4955. if( item_data == NULL)
  4956. { //Failed
  4957. push_val(st->stack,C_INT,0);
  4958. return 0;
  4959. }
  4960. nameid = item_data->nameid;
  4961. }else
  4962. nameid = conv_num(st,data);
  4963. if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/)
  4964. { //Even though named stackable items "could" be risky, they are required for certain quests.
  4965. push_val(st->stack,C_INT,0);
  4966. return 0;
  4967. }
  4968. data=&(st->stack->stack_data[st->start+3]);
  4969. get_val(st,data);
  4970. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  4971. tsd=map_nick2sd(conv_str(st,data));
  4972. else //Char Id was given
  4973. tsd=map_charid2sd(conv_num(st,data));
  4974. if( tsd == NULL )
  4975. { //Failed
  4976. push_val(st->stack,C_INT,0);
  4977. return 0;
  4978. }
  4979. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4980. item_tmp.nameid=nameid;
  4981. item_tmp.amount=1;
  4982. item_tmp.identify=1;
  4983. item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  4984. item_tmp.card[2]=tsd->status.char_id;
  4985. item_tmp.card[3]=tsd->status.char_id >> 16;
  4986. if(pc_additem(sd,&item_tmp,1)) {
  4987. push_val(st->stack,C_INT,0);
  4988. return 0; //Failed to add item, we will not drop if they don't fit
  4989. }
  4990. //Logs items, got from (N)PC scripts [Lupus]
  4991. if(log_config.enable_logs&0x40)
  4992. log_pick_pc(sd, "N", item_tmp.nameid, item_tmp.amount, &item_tmp);
  4993. push_val(st->stack,C_INT,1);
  4994. return 0;
  4995. }
  4996. /*==========================================
  4997. * gets a random item ID from an item group [Skotlex]
  4998. * groupranditem group_num
  4999. *------------------------------------------
  5000. */
  5001. int buildin_grouprandomitem(struct script_state *st)
  5002. {
  5003. int group;
  5004. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  5005. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  5006. return 0;
  5007. }
  5008. /*==========================================
  5009. *
  5010. *------------------------------------------
  5011. */
  5012. int buildin_makeitem(struct script_state *st)
  5013. {
  5014. int nameid,amount,flag = 0;
  5015. int x,y,m;
  5016. char *mapname;
  5017. struct item item_tmp;
  5018. struct script_data *data;
  5019. data=&(st->stack->stack_data[st->start+2]);
  5020. get_val(st,data);
  5021. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5022. const char *name=conv_str(st,data);
  5023. struct item_data *item_data = itemdb_searchname(name);
  5024. nameid=UNKNOWN_ITEM_ID;
  5025. if( item_data )
  5026. nameid=item_data->nameid;
  5027. }else
  5028. nameid=conv_num(st,data);
  5029. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5030. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  5031. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  5032. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  5033. if(strcmp(mapname,"this")==0)
  5034. {
  5035. struct map_session_data *sd;
  5036. sd = script_rid2sd(st);
  5037. if (!sd) return 0; //Failed...
  5038. m=sd->bl.m;
  5039. } else
  5040. m=map_mapname2mapid(mapname);
  5041. if(nameid<0) { // ランダム
  5042. nameid=itemdb_searchrandomid(-nameid);
  5043. flag = 1;
  5044. }
  5045. if(nameid > 0) {
  5046. malloc_set(&item_tmp,0,sizeof(item_tmp));
  5047. item_tmp.nameid=nameid;
  5048. if(!flag)
  5049. item_tmp.identify=1;
  5050. else
  5051. item_tmp.identify=itemdb_isidentified(nameid);
  5052. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  5053. }
  5054. return 0;
  5055. }
  5056. /*==========================================
  5057. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  5058. *------------------------------------------
  5059. */
  5060. int buildin_delitem(struct script_state *st)
  5061. {
  5062. int nameid=0,amount,i,important_item=0;
  5063. struct map_session_data *sd;
  5064. struct script_data *data;
  5065. sd = script_rid2sd(st);
  5066. data=&(st->stack->stack_data[st->start+2]);
  5067. get_val(st,data);
  5068. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5069. const char *name=conv_str(st,data);
  5070. struct item_data *item_data = itemdb_searchname(name);
  5071. //nameid=UNKNOWN_ITEM_ID;
  5072. if( item_data )
  5073. nameid=item_data->nameid;
  5074. }else
  5075. nameid=conv_num(st,data);
  5076. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5077. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5078. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5079. return 0;
  5080. }
  5081. //1st pass
  5082. //here we won't delete items with CARDS, named items but we count them
  5083. for(i=0;i<MAX_INVENTORY;i++){
  5084. //we don't delete wrong item or equipped item
  5085. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5086. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  5087. continue;
  5088. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5089. if(sd->inventory_data[i]->type==IT_PETEGG &&
  5090. sd->status.inventory[i].card[0] == CARD0_PET)
  5091. {
  5092. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5093. continue; //pet couldn't be sent for deletion.
  5094. }
  5095. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  5096. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  5097. sd->status.inventory[i].card[0] ||
  5098. sd->status.inventory[i].refine) {
  5099. //this is important item, count it (except for pet eggs)
  5100. if(sd->status.inventory[i].card[0] != CARD0_PET)
  5101. important_item++;
  5102. continue;
  5103. }
  5104. if(sd->status.inventory[i].amount>=amount){
  5105. //Logs items, got from (N)PC scripts [Lupus]
  5106. if(log_config.enable_logs&0x40)
  5107. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5108. pc_delitem(sd,i,amount,0);
  5109. return 0; //we deleted exact amount of items. now exit
  5110. } else {
  5111. amount-=sd->status.inventory[i].amount;
  5112. //Logs items, got from (N)PC scripts [Lupus]
  5113. if(log_config.enable_logs&0x40) {
  5114. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5115. }
  5116. //Logs
  5117. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5118. }
  5119. }
  5120. //2nd pass
  5121. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  5122. if (important_item>0 && amount>0)
  5123. for(i=0;i<MAX_INVENTORY;i++){
  5124. //we don't delete wrong item
  5125. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5126. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  5127. continue;
  5128. if(sd->status.inventory[i].amount>=amount){
  5129. //Logs items, got from (N)PC scripts [Lupus]
  5130. if(log_config.enable_logs&0x40)
  5131. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5132. pc_delitem(sd,i,amount,0);
  5133. return 0; //we deleted exact amount of items. now exit
  5134. } else {
  5135. amount-=sd->status.inventory[i].amount;
  5136. //Logs items, got from (N)PC scripts [Lupus]
  5137. if(log_config.enable_logs&0x40)
  5138. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5139. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5140. }
  5141. }
  5142. return 0;
  5143. }
  5144. /*==========================================
  5145. * advanced version of delitem [modified by Mihilion]
  5146. *------------------------------------------
  5147. */
  5148. int buildin_delitem2(struct script_state *st)
  5149. {
  5150. int nameid=0,amount,i=0;
  5151. int iden,ref,attr,c1,c2,c3,c4;
  5152. struct map_session_data *sd;
  5153. struct script_data *data;
  5154. sd = script_rid2sd(st);
  5155. data=&(st->stack->stack_data[st->start+2]);
  5156. get_val(st,data);
  5157. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5158. const char *name=conv_str(st,data);
  5159. struct item_data *item_data = itemdb_searchname(name);
  5160. //nameid=UNKNOWN_ITEM_ID;
  5161. if( item_data )
  5162. nameid=item_data->nameid;
  5163. }else
  5164. nameid=conv_num(st,data);
  5165. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5166. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5167. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5168. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5169. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5170. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5171. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5172. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5173. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5174. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5175. return 0;
  5176. }
  5177. for(i=0;i<MAX_INVENTORY;i++){
  5178. //we don't delete wrong item or equipped item
  5179. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5180. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  5181. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  5182. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  5183. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  5184. sd->status.inventory[i].card[3]!=c4)
  5185. continue;
  5186. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5187. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  5188. {
  5189. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5190. continue; //Failed to send delete the pet.
  5191. }
  5192. if(sd->status.inventory[i].amount>=amount){
  5193. //Logs items, got from (N)PC scripts [Lupus]
  5194. if(log_config.enable_logs&0x40)
  5195. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5196. pc_delitem(sd,i,amount,0);
  5197. return 0; //we deleted exact amount of items. now exit
  5198. } else {
  5199. amount-=sd->status.inventory[i].amount;
  5200. //Logs items, got from (N)PC scripts [Lupus]
  5201. if(log_config.enable_logs&0x40)
  5202. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5203. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5204. }
  5205. }
  5206. return 0;
  5207. }
  5208. /*==========================================
  5209. * Enables/Disables use of items while in an NPC [Skotlex]
  5210. *------------------------------------------
  5211. */
  5212. int buildin_enableitemuse(struct script_state *st) {
  5213. struct map_session_data *sd;
  5214. sd=script_rid2sd(st);
  5215. if (sd)
  5216. sd->npc_item_flag = st->oid;
  5217. return 0;
  5218. }
  5219. int buildin_disableitemuse(struct script_state *st) {
  5220. struct map_session_data *sd;
  5221. sd=script_rid2sd(st);
  5222. if (sd)
  5223. sd->npc_item_flag = 0;
  5224. return 0;
  5225. }
  5226. /*==========================================
  5227. *キャラ関係のパラメータ取得
  5228. *------------------------------------------
  5229. */
  5230. int buildin_readparam(struct script_state *st)
  5231. {
  5232. int type;
  5233. struct map_session_data *sd;
  5234. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5235. if( st->end>st->start+3 )
  5236. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5237. else
  5238. sd=script_rid2sd(st);
  5239. if(sd==NULL){
  5240. push_val(st->stack,C_INT,-1);
  5241. return 0;
  5242. }
  5243. push_val(st->stack,C_INT,pc_readparam(sd,type));
  5244. return 0;
  5245. }
  5246. /*==========================================
  5247. *キャラ関係のID取得
  5248. *------------------------------------------
  5249. */
  5250. int buildin_getcharid(struct script_state *st)
  5251. {
  5252. int num;
  5253. struct map_session_data *sd;
  5254. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5255. if( st->end>st->start+3 )
  5256. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5257. else
  5258. sd=script_rid2sd(st);
  5259. if(sd==NULL || num<0 || num>3){
  5260. push_val(st->stack,C_INT,0); //return 0, according docs
  5261. return 0;
  5262. }
  5263. if(num==0)
  5264. push_val(st->stack,C_INT,sd->status.char_id);
  5265. if(num==1)
  5266. push_val(st->stack,C_INT,sd->status.party_id);
  5267. if(num==2)
  5268. push_val(st->stack,C_INT,sd->status.guild_id);
  5269. if(num==3)
  5270. push_val(st->stack,C_INT,sd->status.account_id);
  5271. return 0;
  5272. }
  5273. /*==========================================
  5274. *指定IDのPT名取得
  5275. *------------------------------------------
  5276. */
  5277. char *buildin_getpartyname_sub(int party_id)
  5278. {
  5279. struct party_data *p;
  5280. p=party_search(party_id);
  5281. if(p!=NULL){
  5282. char *buf;
  5283. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5284. memcpy(buf, p->party.name, NAME_LENGTH-1);
  5285. buf[NAME_LENGTH-1] = '\0';
  5286. return buf;
  5287. }
  5288. return 0;
  5289. }
  5290. int buildin_getpartyname(struct script_state *st)
  5291. {
  5292. char *name;
  5293. int party_id;
  5294. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5295. name=buildin_getpartyname_sub(party_id);
  5296. if(name != NULL)
  5297. push_str(st->stack,C_STR,name);
  5298. else
  5299. push_str(st->stack,C_CONSTSTR,"null");
  5300. return 0;
  5301. }
  5302. /*==========================================
  5303. *指定IDのPT人数とメンバーID取得
  5304. *------------------------------------------
  5305. */
  5306. int buildin_getpartymember(struct script_state *st)
  5307. {
  5308. struct party_data *p;
  5309. int i,j=0,type=0;
  5310. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  5311. if( st->end>st->start+3 )
  5312. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5313. if(p!=NULL){
  5314. for(i=0;i<MAX_PARTY;i++){
  5315. if(p->party.member[i].account_id){
  5316. switch (type) {
  5317. case 2:
  5318. mapreg_setreg(add_str("$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  5319. break;
  5320. case 1:
  5321. mapreg_setreg(add_str("$@partymembercid")+(j<<24),p->party.member[i].char_id);
  5322. break;
  5323. default:
  5324. mapreg_setregstr(add_str("$@partymembername$")+(j<<24),p->party.member[i].name);
  5325. }
  5326. j++;
  5327. }
  5328. }
  5329. }
  5330. mapreg_setreg(add_str("$@partymembercount"),j);
  5331. return 0;
  5332. }
  5333. /*==========================================
  5334. * Retrieves party leader. if flag is specified,
  5335. * return some of the leader data. Otherwise, return name.
  5336. *------------------------------------------
  5337. */
  5338. int buildin_getpartyleader(struct script_state *st)
  5339. {
  5340. int party_id, type = 0, i=0;
  5341. struct party_data *p;
  5342. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5343. if( st->end>st->start+3 )
  5344. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5345. p=party_search(party_id);
  5346. if (p) //Search leader
  5347. for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
  5348. if (!p || i == MAX_PARTY) { //leader not found
  5349. if (type)
  5350. push_val(st->stack,C_INT,-1);
  5351. else
  5352. push_str(st->stack,C_CONSTSTR,"null");
  5353. return 0;
  5354. }
  5355. switch (type) {
  5356. case 1:
  5357. push_val(st->stack,C_INT,p->party.member[i].account_id);
  5358. break;
  5359. case 2:
  5360. push_val(st->stack,C_INT,p->party.member[i].char_id);
  5361. break;
  5362. case 3:
  5363. push_val(st->stack,C_INT,p->party.member[i].class_);
  5364. break;
  5365. case 4:
  5366. push_val(st->stack,C_INT,p->party.member[i].map);
  5367. break;
  5368. case 5:
  5369. push_val(st->stack,C_INT,p->party.member[i].lv);
  5370. break;
  5371. default:
  5372. push_str(st->stack,C_STR,p->party.member[i].name);
  5373. break;
  5374. }
  5375. return 0;
  5376. }
  5377. /*==========================================
  5378. *指定IDのギルド名取得
  5379. *------------------------------------------
  5380. */
  5381. char *buildin_getguildname_sub(int guild_id)
  5382. {
  5383. struct guild *g=NULL;
  5384. g=guild_search(guild_id);
  5385. if(g!=NULL){
  5386. char *buf;
  5387. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5388. memcpy(buf, g->name, NAME_LENGTH-1);
  5389. buf[NAME_LENGTH-1] = '\0';
  5390. return buf;
  5391. }
  5392. return NULL;
  5393. }
  5394. int buildin_getguildname(struct script_state *st)
  5395. {
  5396. char *name;
  5397. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5398. name=buildin_getguildname_sub(guild_id);
  5399. if(name != NULL)
  5400. push_str(st->stack,C_STR,name);
  5401. else
  5402. push_str(st->stack,C_CONSTSTR,"null");
  5403. return 0;
  5404. }
  5405. /*==========================================
  5406. *指定IDのGuildMaster名取得
  5407. *------------------------------------------
  5408. */
  5409. char *buildin_getguildmaster_sub(int guild_id)
  5410. {
  5411. struct guild *g=NULL;
  5412. g=guild_search(guild_id);
  5413. if(g!=NULL){
  5414. char *buf;
  5415. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5416. memcpy(buf, g->master, NAME_LENGTH-1);
  5417. buf[NAME_LENGTH-1] = '\0';
  5418. return buf;
  5419. }
  5420. return 0;
  5421. }
  5422. int buildin_getguildmaster(struct script_state *st)
  5423. {
  5424. char *master;
  5425. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5426. master=buildin_getguildmaster_sub(guild_id);
  5427. if(master!=0)
  5428. push_str(st->stack,C_STR,master);
  5429. else
  5430. push_str(st->stack,C_CONSTSTR,"null");
  5431. return 0;
  5432. }
  5433. int buildin_getguildmasterid(struct script_state *st)
  5434. {
  5435. char *master;
  5436. struct map_session_data *sd=NULL;
  5437. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5438. master=buildin_getguildmaster_sub(guild_id);
  5439. if(master!=0){
  5440. if((sd=map_nick2sd(master)) == NULL){
  5441. push_val(st->stack,C_INT,0);
  5442. return 0;
  5443. }
  5444. push_val(st->stack,C_INT,sd->status.char_id);
  5445. }else{
  5446. push_val(st->stack,C_INT,0);
  5447. }
  5448. return 0;
  5449. }
  5450. /*==========================================
  5451. * キャラクタの名前
  5452. *------------------------------------------
  5453. */
  5454. int buildin_strcharinfo(struct script_state *st)
  5455. {
  5456. struct map_session_data *sd;
  5457. int num;
  5458. char *buf;
  5459. sd=script_rid2sd(st);
  5460. if (!sd) { //Avoid crashing....
  5461. push_str(st->stack,C_CONSTSTR,"");
  5462. return 0;
  5463. }
  5464. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5465. switch(num){
  5466. case 0:
  5467. push_str(st->stack,C_CONSTSTR,sd->status.name);
  5468. break;
  5469. case 1:
  5470. buf=buildin_getpartyname_sub(sd->status.party_id);
  5471. if(buf!=0)
  5472. push_str(st->stack,C_STR,buf);
  5473. else
  5474. push_str(st->stack,C_CONSTSTR,"");
  5475. break;
  5476. case 2:
  5477. buf=buildin_getguildname_sub(sd->status.guild_id);
  5478. if(buf != NULL)
  5479. push_str(st->stack,C_STR,buf);
  5480. else
  5481. push_str(st->stack,C_CONSTSTR,"");
  5482. break;
  5483. default:
  5484. ShowWarning("buildin_strcharinfo: unknown parameter.");
  5485. push_str(st->stack,C_CONSTSTR,"");
  5486. break;
  5487. }
  5488. return 0;
  5489. }
  5490. unsigned int equip[10]={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};
  5491. /*==========================================
  5492. * GetEquipID(Pos); Pos: 1-10
  5493. *------------------------------------------
  5494. */
  5495. int buildin_getequipid(struct script_state *st)
  5496. {
  5497. int i,num;
  5498. struct map_session_data *sd;
  5499. struct item_data* item;
  5500. sd=script_rid2sd(st);
  5501. if(sd == NULL)
  5502. {
  5503. ShowError("getequipid: sd == NULL\n");
  5504. return 0;
  5505. }
  5506. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5507. i=pc_checkequip(sd,equip[num-1]);
  5508. if(i >= 0){
  5509. item=sd->inventory_data[i];
  5510. if(item)
  5511. push_val(st->stack,C_INT,item->nameid);
  5512. else
  5513. push_val(st->stack,C_INT,0);
  5514. }else{
  5515. push_val(st->stack,C_INT,-1);
  5516. }
  5517. return 0;
  5518. }
  5519. /*==========================================
  5520. * 装備名文字列(精錬メニュー用)
  5521. *------------------------------------------
  5522. */
  5523. int buildin_getequipname(struct script_state *st)
  5524. {
  5525. int i,num;
  5526. struct map_session_data *sd;
  5527. struct item_data* item;
  5528. char *buf;
  5529. buf=(char *)aMallocA(64*sizeof(char));
  5530. sd=script_rid2sd(st);
  5531. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5532. i=pc_checkequip(sd,equip[num-1]);
  5533. if(i >= 0){
  5534. item=sd->inventory_data[i];
  5535. if(item)
  5536. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  5537. else
  5538. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5539. }else{
  5540. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5541. }
  5542. push_str(st->stack,C_STR,buf);
  5543. return 0;
  5544. }
  5545. /*==========================================
  5546. * getbrokenid [Valaris]
  5547. *------------------------------------------
  5548. */
  5549. int buildin_getbrokenid(struct script_state *st)
  5550. {
  5551. int i,num,id=0,brokencounter=0;
  5552. struct map_session_data *sd;
  5553. sd=script_rid2sd(st);
  5554. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5555. for(i=0; i<MAX_INVENTORY; i++) {
  5556. if(sd->status.inventory[i].attribute==1){
  5557. brokencounter++;
  5558. if(num==brokencounter){
  5559. id=sd->status.inventory[i].nameid;
  5560. break;
  5561. }
  5562. }
  5563. }
  5564. push_val(st->stack,C_INT,id);
  5565. return 0;
  5566. }
  5567. /*==========================================
  5568. * repair [Valaris]
  5569. *------------------------------------------
  5570. */
  5571. int buildin_repair(struct script_state *st)
  5572. {
  5573. int i,num;
  5574. int repaircounter=0;
  5575. struct map_session_data *sd;
  5576. sd=script_rid2sd(st);
  5577. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5578. for(i=0; i<MAX_INVENTORY; i++) {
  5579. if(sd->status.inventory[i].attribute==1){
  5580. repaircounter++;
  5581. if(num==repaircounter){
  5582. sd->status.inventory[i].attribute=0;
  5583. clif_equiplist(sd);
  5584. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  5585. clif_misceffect(&sd->bl, 3);
  5586. break;
  5587. }
  5588. }
  5589. }
  5590. return 0;
  5591. }
  5592. /*==========================================
  5593. * 装備チェック
  5594. *------------------------------------------
  5595. */
  5596. int buildin_getequipisequiped(struct script_state *st)
  5597. {
  5598. int i,num;
  5599. struct map_session_data *sd;
  5600. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5601. sd=script_rid2sd(st);
  5602. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  5603. i = -1;
  5604. else
  5605. i=pc_checkequip(sd,equip[num-1]);
  5606. if(i >= 0)
  5607. push_val(st->stack,C_INT,1);
  5608. else
  5609. push_val(st->stack,C_INT,0);
  5610. return 0;
  5611. }
  5612. /*==========================================
  5613. * 装備品精錬可能チェック
  5614. *------------------------------------------
  5615. */
  5616. int buildin_getequipisenableref(struct script_state *st)
  5617. {
  5618. int i,num;
  5619. struct map_session_data *sd;
  5620. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5621. sd=script_rid2sd(st);
  5622. i=pc_checkequip(sd,equip[num-1]);
  5623. if(i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  5624. {
  5625. push_val(st->stack,C_INT,1);
  5626. } else {
  5627. push_val(st->stack,C_INT,0);
  5628. }
  5629. return 0;
  5630. }
  5631. /*==========================================
  5632. * 装備品鑑定チェック
  5633. *------------------------------------------
  5634. */
  5635. int buildin_getequipisidentify(struct script_state *st)
  5636. {
  5637. int i,num;
  5638. struct map_session_data *sd;
  5639. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5640. sd=script_rid2sd(st);
  5641. i=pc_checkequip(sd,equip[num-1]);
  5642. if(i >= 0)
  5643. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  5644. else
  5645. push_val(st->stack,C_INT,0);
  5646. return 0;
  5647. }
  5648. /*==========================================
  5649. * 装備品精錬度
  5650. *------------------------------------------
  5651. */
  5652. int buildin_getequiprefinerycnt(struct script_state *st)
  5653. {
  5654. int i,num;
  5655. struct map_session_data *sd;
  5656. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5657. sd=script_rid2sd(st);
  5658. i=pc_checkequip(sd,equip[num-1]);
  5659. if(i >= 0)
  5660. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  5661. else
  5662. push_val(st->stack,C_INT,0);
  5663. return 0;
  5664. }
  5665. /*==========================================
  5666. * 装備品武器LV
  5667. *------------------------------------------
  5668. */
  5669. int buildin_getequipweaponlv(struct script_state *st)
  5670. {
  5671. int i,num;
  5672. struct map_session_data *sd;
  5673. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5674. sd=script_rid2sd(st);
  5675. i=pc_checkequip(sd,equip[num-1]);
  5676. if(i >= 0 && sd->inventory_data[i])
  5677. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  5678. else
  5679. push_val(st->stack,C_INT,0);
  5680. return 0;
  5681. }
  5682. /*==========================================
  5683. * 装備品精錬成功率
  5684. *------------------------------------------
  5685. */
  5686. int buildin_getequippercentrefinery(struct script_state *st)
  5687. {
  5688. int i,num;
  5689. struct map_session_data *sd;
  5690. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5691. sd=script_rid2sd(st);
  5692. i=pc_checkequip(sd,equip[num-1]);
  5693. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  5694. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  5695. else
  5696. push_val(st->stack,C_INT,0);
  5697. return 0;
  5698. }
  5699. /*==========================================
  5700. * 精錬成功
  5701. *------------------------------------------
  5702. */
  5703. int buildin_successrefitem(struct script_state *st)
  5704. {
  5705. int i,num,ep;
  5706. struct map_session_data *sd;
  5707. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5708. sd=script_rid2sd(st);
  5709. i=pc_checkequip(sd,equip[num-1]);
  5710. if(i >= 0) {
  5711. ep=sd->status.inventory[i].equip;
  5712. //Logs items, got from (N)PC scripts [Lupus]
  5713. if(log_config.enable_logs&0x40)
  5714. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5715. sd->status.inventory[i].refine++;
  5716. pc_unequipitem(sd,i,2);
  5717. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  5718. clif_delitem(sd,i,1);
  5719. //Logs items, got from (N)PC scripts [Lupus]
  5720. if(log_config.enable_logs&0x40)
  5721. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  5722. clif_additem(sd,i,1,0);
  5723. pc_equipitem(sd,i,ep);
  5724. clif_misceffect(&sd->bl,3);
  5725. if(sd->status.inventory[i].refine == MAX_REFINE &&
  5726. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  5727. sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  5728. ){ // Fame point system [DracoRPG]
  5729. switch (sd->inventory_data[i]->wlv){
  5730. case 1:
  5731. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  5732. break;
  5733. case 2:
  5734. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  5735. break;
  5736. case 3:
  5737. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  5738. break;
  5739. }
  5740. }
  5741. }
  5742. return 0;
  5743. }
  5744. /*==========================================
  5745. * 精錬失敗
  5746. *------------------------------------------
  5747. */
  5748. int buildin_failedrefitem(struct script_state *st)
  5749. {
  5750. int i,num;
  5751. struct map_session_data *sd;
  5752. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5753. sd=script_rid2sd(st);
  5754. i=pc_checkequip(sd,equip[num-1]);
  5755. if(i >= 0) {
  5756. //Logs items, got from (N)PC scripts [Lupus]
  5757. if(log_config.enable_logs&0x40)
  5758. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5759. sd->status.inventory[i].refine = 0;
  5760. pc_unequipitem(sd,i,3);
  5761. // 精錬失敗エフェクトのパケット
  5762. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  5763. pc_delitem(sd,i,1,0);
  5764. // 他の人にも失敗を通知
  5765. clif_misceffect(&sd->bl,2);
  5766. }
  5767. return 0;
  5768. }
  5769. /*==========================================
  5770. *
  5771. *------------------------------------------
  5772. */
  5773. int buildin_statusup(struct script_state *st)
  5774. {
  5775. int type;
  5776. struct map_session_data *sd;
  5777. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5778. sd=script_rid2sd(st);
  5779. pc_statusup(sd,type);
  5780. return 0;
  5781. }
  5782. /*==========================================
  5783. *
  5784. *------------------------------------------
  5785. */
  5786. int buildin_statusup2(struct script_state *st)
  5787. {
  5788. int type,val;
  5789. struct map_session_data *sd;
  5790. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5791. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5792. sd=script_rid2sd(st);
  5793. pc_statusup2(sd,type,val);
  5794. return 0;
  5795. }
  5796. /*==========================================
  5797. * 装備品による能力値ボーナス
  5798. *------------------------------------------
  5799. */
  5800. int buildin_bonus(struct script_state *st)
  5801. {
  5802. int type,val;
  5803. struct map_session_data *sd;
  5804. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5805. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5806. sd=script_rid2sd(st);
  5807. pc_bonus(sd,type,val);
  5808. return 0;
  5809. }
  5810. /*==========================================
  5811. * 装備品による能力値ボーナス
  5812. *------------------------------------------
  5813. */
  5814. int buildin_bonus2(struct script_state *st)
  5815. {
  5816. int type,type2,val;
  5817. struct map_session_data *sd;
  5818. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5819. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5820. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5821. sd=script_rid2sd(st);
  5822. pc_bonus2(sd,type,type2,val);
  5823. return 0;
  5824. }
  5825. /*==========================================
  5826. * 装備品による能力値ボーナス
  5827. *------------------------------------------
  5828. */
  5829. int buildin_bonus3(struct script_state *st)
  5830. {
  5831. int type,type2,type3,val;
  5832. struct map_session_data *sd;
  5833. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5834. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5835. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5836. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5837. sd=script_rid2sd(st);
  5838. pc_bonus3(sd,type,type2,type3,val);
  5839. return 0;
  5840. }
  5841. int buildin_bonus4(struct script_state *st)
  5842. {
  5843. int type,type2,type3,type4,val;
  5844. struct map_session_data *sd;
  5845. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5846. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5847. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5848. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5849. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5850. sd=script_rid2sd(st);
  5851. pc_bonus4(sd,type,type2,type3,type4,val);
  5852. return 0;
  5853. }
  5854. /*==========================================
  5855. * スキル所得
  5856. *------------------------------------------
  5857. */
  5858. int buildin_skill(struct script_state *st)
  5859. {
  5860. int id,level,flag=1;
  5861. struct map_session_data *sd;
  5862. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5863. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5864. if( st->end>st->start+4 )
  5865. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5866. sd=script_rid2sd(st);
  5867. pc_skill(sd,id,level,flag);
  5868. return 0;
  5869. }
  5870. // add x levels of skill (stackable) [Valaris]
  5871. int buildin_addtoskill(struct script_state *st)
  5872. {
  5873. int id,level,flag=2;
  5874. struct map_session_data *sd;
  5875. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5876. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5877. if( st->end>st->start+4 )
  5878. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5879. sd=script_rid2sd(st);
  5880. pc_skill(sd,id,level,flag);
  5881. return 0;
  5882. }
  5883. /*==========================================
  5884. * ギルドスキル取得
  5885. *------------------------------------------
  5886. */
  5887. int buildin_guildskill(struct script_state *st)
  5888. {
  5889. int id,level,flag=0;
  5890. struct map_session_data *sd;
  5891. int i=0;
  5892. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5893. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5894. if( st->end>st->start+4 )
  5895. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5896. sd=script_rid2sd(st);
  5897. for(i=0;i<level;i++)
  5898. guild_skillup(sd,id,flag);
  5899. return 0;
  5900. }
  5901. /*==========================================
  5902. * スキルレベル所得
  5903. *------------------------------------------
  5904. */
  5905. int buildin_getskilllv(struct script_state *st)
  5906. {
  5907. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5908. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  5909. return 0;
  5910. }
  5911. /*==========================================
  5912. * getgdskilllv(Guild_ID, Skill_ID);
  5913. * skill_id = 10000 : GD_APPROVAL
  5914. * 10001 : GD_KAFRACONTRACT
  5915. * 10002 : GD_GUARDIANRESEARCH
  5916. * 10003 : GD_GUARDUP
  5917. * 10004 : GD_EXTENSION
  5918. *------------------------------------------
  5919. */
  5920. int buildin_getgdskilllv(struct script_state *st)
  5921. {
  5922. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5923. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5924. struct guild *g=guild_search(guild_id);
  5925. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  5926. return 0;
  5927. /*
  5928. struct map_session_data *sd=NULL;
  5929. struct guild *g=NULL;
  5930. int skill_id;
  5931. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5932. sd=script_rid2sd(st);
  5933. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  5934. if(sd && g) {
  5935. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  5936. } else {
  5937. push_val(st->stack,C_INT,-1);
  5938. }
  5939. return 0;
  5940. */
  5941. }
  5942. /*==========================================
  5943. *
  5944. *------------------------------------------
  5945. */
  5946. int buildin_basicskillcheck(struct script_state *st)
  5947. {
  5948. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  5949. return 0;
  5950. }
  5951. /*==========================================
  5952. *
  5953. *------------------------------------------
  5954. */
  5955. int buildin_getgmlevel(struct script_state *st)
  5956. {
  5957. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  5958. return 0;
  5959. }
  5960. /*==========================================
  5961. *
  5962. *------------------------------------------
  5963. */
  5964. int buildin_end(struct script_state *st)
  5965. {
  5966. st->state = END;
  5967. return 0;
  5968. }
  5969. /*==========================================
  5970. *
  5971. *------------------------------------------
  5972. */
  5973. int buildin_checkoption(struct script_state *st)
  5974. {
  5975. int type;
  5976. struct map_session_data *sd;
  5977. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5978. sd=script_rid2sd(st);
  5979. if(sd->sc.option & type){
  5980. push_val(st->stack,C_INT,1);
  5981. } else {
  5982. push_val(st->stack,C_INT,0);
  5983. }
  5984. return 0;
  5985. }
  5986. /*==========================================
  5987. *
  5988. *------------------------------------------
  5989. */
  5990. int buildin_checkoption1(struct script_state *st)
  5991. {
  5992. int type;
  5993. struct map_session_data *sd;
  5994. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5995. sd=script_rid2sd(st);
  5996. if(sd->sc.opt1 & type){
  5997. push_val(st->stack,C_INT,1);
  5998. } else {
  5999. push_val(st->stack,C_INT,0);
  6000. }
  6001. return 0;
  6002. }
  6003. /*==========================================
  6004. *
  6005. *------------------------------------------
  6006. */
  6007. int buildin_checkoption2(struct script_state *st)
  6008. {
  6009. int type;
  6010. struct map_session_data *sd;
  6011. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6012. sd=script_rid2sd(st);
  6013. if(sd->sc.opt2 & type){
  6014. push_val(st->stack,C_INT,1);
  6015. } else {
  6016. push_val(st->stack,C_INT,0);
  6017. }
  6018. return 0;
  6019. }
  6020. /*==========================================
  6021. *
  6022. *------------------------------------------
  6023. */
  6024. int buildin_setoption(struct script_state *st)
  6025. {
  6026. int type;
  6027. struct map_session_data *sd;
  6028. int flag=1;
  6029. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6030. if(st->end>st->start+3 )
  6031. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  6032. else if (!type) { //Request to remove everything.
  6033. flag = 0;
  6034. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  6035. }
  6036. sd=script_rid2sd(st);
  6037. if (!sd) return 0;
  6038. if (flag) {//Add option
  6039. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  6040. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  6041. pc_setoption(sd,sd->sc.option|type);
  6042. } else//Remove option
  6043. pc_setoption(sd,sd->sc.option&~type);
  6044. return 0;
  6045. }
  6046. /*==========================================
  6047. * Checkcart [Valaris]
  6048. *------------------------------------------
  6049. */
  6050. int buildin_checkcart(struct script_state *st)
  6051. {
  6052. struct map_session_data *sd;
  6053. sd=script_rid2sd(st);
  6054. if(pc_iscarton(sd)){
  6055. push_val(st->stack,C_INT,1);
  6056. } else {
  6057. push_val(st->stack,C_INT,0);
  6058. }
  6059. return 0;
  6060. }
  6061. /*==========================================
  6062. * カートを付ける
  6063. *------------------------------------------
  6064. */
  6065. int buildin_setcart(struct script_state *st)
  6066. {
  6067. struct map_session_data *sd;
  6068. sd=script_rid2sd(st);
  6069. pc_setcart(sd,1);
  6070. return 0;
  6071. }
  6072. /*==========================================
  6073. * checkfalcon [Valaris]
  6074. *------------------------------------------
  6075. */
  6076. int buildin_checkfalcon(struct script_state *st)
  6077. {
  6078. struct map_session_data *sd;
  6079. sd=script_rid2sd(st);
  6080. if(pc_isfalcon(sd)){
  6081. push_val(st->stack,C_INT,1);
  6082. } else {
  6083. push_val(st->stack,C_INT,0);
  6084. }
  6085. return 0;
  6086. }
  6087. /*==========================================
  6088. * 鷹を付ける
  6089. *------------------------------------------
  6090. */
  6091. int buildin_setfalcon(struct script_state *st)
  6092. {
  6093. struct map_session_data *sd;
  6094. sd=script_rid2sd(st);
  6095. pc_setfalcon(sd);
  6096. return 0;
  6097. }
  6098. /*==========================================
  6099. * Checkcart [Valaris]
  6100. *------------------------------------------
  6101. */
  6102. int buildin_checkriding(struct script_state *st)
  6103. {
  6104. struct map_session_data *sd;
  6105. sd=script_rid2sd(st);
  6106. if(pc_isriding(sd)){
  6107. push_val(st->stack,C_INT,1);
  6108. } else {
  6109. push_val(st->stack,C_INT,0);
  6110. }
  6111. return 0;
  6112. }
  6113. /*==========================================
  6114. * ペコペコ乗り
  6115. *------------------------------------------
  6116. */
  6117. int buildin_setriding(struct script_state *st)
  6118. {
  6119. struct map_session_data *sd;
  6120. sd=script_rid2sd(st);
  6121. pc_setriding(sd);
  6122. return 0;
  6123. }
  6124. /*==========================================
  6125. * セーブポイントの保存
  6126. *------------------------------------------
  6127. */
  6128. int buildin_savepoint(struct script_state *st)
  6129. {
  6130. int x,y;
  6131. short map;
  6132. char *str;
  6133. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6134. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6135. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6136. map = mapindex_name2id(str);
  6137. if (map)
  6138. pc_setsavepoint(script_rid2sd(st),map,x,y);
  6139. return 0;
  6140. }
  6141. /*==========================================
  6142. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  6143. *------------------------------------------
  6144. */
  6145. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  6146. {
  6147. int type;
  6148. time_t timer;
  6149. struct tm *t;
  6150. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6151. switch(type){
  6152. case 2:
  6153. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  6154. // from the system clock.)
  6155. push_val(st->stack,C_INT,(int)time(NULL));
  6156. break;
  6157. case 1:
  6158. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  6159. time(&timer);
  6160. t=localtime(&timer);
  6161. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  6162. break;
  6163. case 0:
  6164. default:
  6165. //type 0:(System Ticks)
  6166. push_val(st->stack,C_INT,gettick());
  6167. break;
  6168. }
  6169. return 0;
  6170. }
  6171. /*==========================================
  6172. * GetTime(Type);
  6173. * 1: Sec 2: Min 3: Hour
  6174. * 4: WeekDay 5: MonthDay 6: Month
  6175. * 7: Year
  6176. *------------------------------------------
  6177. */
  6178. int buildin_gettime(struct script_state *st) /* Asgard Version */
  6179. {
  6180. int type;
  6181. time_t timer;
  6182. struct tm *t;
  6183. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6184. time(&timer);
  6185. t=localtime(&timer);
  6186. switch(type){
  6187. case 1://Sec(0~59)
  6188. push_val(st->stack,C_INT,t->tm_sec);
  6189. break;
  6190. case 2://Min(0~59)
  6191. push_val(st->stack,C_INT,t->tm_min);
  6192. break;
  6193. case 3://Hour(0~23)
  6194. push_val(st->stack,C_INT,t->tm_hour);
  6195. break;
  6196. case 4://WeekDay(0~6)
  6197. push_val(st->stack,C_INT,t->tm_wday);
  6198. break;
  6199. case 5://MonthDay(01~31)
  6200. push_val(st->stack,C_INT,t->tm_mday);
  6201. break;
  6202. case 6://Month(01~12)
  6203. push_val(st->stack,C_INT,t->tm_mon+1);
  6204. break;
  6205. case 7://Year(20xx)
  6206. push_val(st->stack,C_INT,t->tm_year+1900);
  6207. break;
  6208. case 8://Year Day(01~366)
  6209. push_val(st->stack,C_INT,t->tm_yday+1);
  6210. break;
  6211. default://(format error)
  6212. push_val(st->stack,C_INT,-1);
  6213. break;
  6214. }
  6215. return 0;
  6216. }
  6217. /*==========================================
  6218. * GetTimeStr("TimeFMT", Length);
  6219. *------------------------------------------
  6220. */
  6221. int buildin_gettimestr(struct script_state *st)
  6222. {
  6223. char *tmpstr;
  6224. char *fmtstr;
  6225. int maxlen;
  6226. time_t now = time(NULL);
  6227. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6228. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6229. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  6230. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  6231. tmpstr[maxlen]='\0';
  6232. push_str(st->stack,C_STR,tmpstr);
  6233. return 0;
  6234. }
  6235. /*==========================================
  6236. * カプラ倉庫を開く
  6237. *------------------------------------------
  6238. */
  6239. int buildin_openstorage(struct script_state *st)
  6240. {
  6241. storage_storageopen(script_rid2sd(st));
  6242. return 0;
  6243. }
  6244. int buildin_guildopenstorage(struct script_state *st)
  6245. {
  6246. struct map_session_data *sd=script_rid2sd(st);
  6247. int ret;
  6248. ret = storage_guild_storageopen(sd);
  6249. push_val(st->stack,C_INT,ret);
  6250. return 0;
  6251. }
  6252. /*==========================================
  6253. * アイテムによるスキル発動
  6254. *------------------------------------------
  6255. */
  6256. int buildin_itemskill(struct script_state *st)
  6257. {
  6258. int id,lv;
  6259. char *str;
  6260. struct map_session_data *sd=script_rid2sd(st);
  6261. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6262. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6263. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6264. // 詠唱中にスキルアイテムは使用できない
  6265. if(sd->ud.skilltimer != -1)
  6266. return 0;
  6267. sd->skillitem=id;
  6268. sd->skillitemlv=lv;
  6269. clif_item_skill(sd,id,lv,str);
  6270. return 0;
  6271. }
  6272. /*==========================================
  6273. * アイテム作成
  6274. *------------------------------------------
  6275. */
  6276. int buildin_produce(struct script_state *st)
  6277. {
  6278. int trigger;
  6279. struct map_session_data *sd=script_rid2sd(st);
  6280. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6281. clif_skill_produce_mix_list(sd, trigger);
  6282. return 0;
  6283. }
  6284. /*==========================================
  6285. * NPCでペット作る
  6286. *------------------------------------------
  6287. */
  6288. int buildin_makepet(struct script_state *st)
  6289. {
  6290. struct map_session_data *sd = script_rid2sd(st);
  6291. struct script_data *data;
  6292. int id,pet_id;
  6293. data=&(st->stack->stack_data[st->start+2]);
  6294. get_val(st,data);
  6295. id=conv_num(st,data);
  6296. pet_id = search_petDB_index(id, PET_CLASS);
  6297. if (pet_id < 0)
  6298. pet_id = search_petDB_index(id, PET_EGG);
  6299. if (pet_id >= 0 && sd) {
  6300. sd->catch_target_class = pet_db[pet_id].class_;
  6301. intif_create_pet(
  6302. sd->status.account_id, sd->status.char_id,
  6303. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  6304. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  6305. 100, 0, 1, pet_db[pet_id].jname);
  6306. }
  6307. return 0;
  6308. }
  6309. /*==========================================
  6310. * NPCで経験値上げる
  6311. *------------------------------------------
  6312. */
  6313. int buildin_getexp(struct script_state *st)
  6314. {
  6315. struct map_session_data *sd = script_rid2sd(st);
  6316. int base=0,job=0;
  6317. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6318. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6319. if(base<0 || job<0)
  6320. return 0;
  6321. if(sd)
  6322. pc_gainexp(sd,NULL,base,job);
  6323. return 0;
  6324. }
  6325. /*==========================================
  6326. * Gain guild exp [Celest]
  6327. *------------------------------------------
  6328. */
  6329. int buildin_guildgetexp(struct script_state *st)
  6330. {
  6331. struct map_session_data *sd = script_rid2sd(st);
  6332. int exp;
  6333. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6334. if(exp < 0)
  6335. return 0;
  6336. if(sd && sd->status.guild_id > 0)
  6337. guild_getexp (sd, exp);
  6338. return 0;
  6339. }
  6340. /*==========================================
  6341. * Changes the guild master of a guild [Skotlex]
  6342. *------------------------------------------
  6343. */
  6344. int buildin_guildchangegm(struct script_state *st)
  6345. {
  6346. struct map_session_data *sd;
  6347. int guild_id;
  6348. char *name;
  6349. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6350. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  6351. sd=map_nick2sd(name);
  6352. if (!sd)
  6353. push_val(st->stack,C_INT,0);
  6354. else
  6355. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  6356. return 0;
  6357. }
  6358. /*==========================================
  6359. * モンスター発生
  6360. *------------------------------------------
  6361. */
  6362. int buildin_monster(struct script_state *st)
  6363. {
  6364. int class_,amount,x,y;
  6365. char *str,*map,*event="";
  6366. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6367. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6368. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6369. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  6370. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6371. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6372. if( st->end>st->start+8 ){
  6373. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  6374. check_event(st, event);
  6375. }
  6376. if (class_ >= 0 && !mobdb_checkid(class_)) {
  6377. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  6378. return 1;
  6379. }
  6380. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  6381. return 0;
  6382. }
  6383. /*==========================================
  6384. * モンスター発生
  6385. *------------------------------------------
  6386. */
  6387. int buildin_areamonster(struct script_state *st)
  6388. {
  6389. int class_,amount,x0,y0,x1,y1;
  6390. char *str,*map,*event="";
  6391. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6392. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6393. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6394. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  6395. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  6396. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  6397. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6398. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6399. if( st->end>st->start+10 ){
  6400. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  6401. check_event(st, event);
  6402. }
  6403. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  6404. return 0;
  6405. }
  6406. /*==========================================
  6407. * モンスター削除
  6408. *------------------------------------------
  6409. */
  6410. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  6411. {
  6412. TBL_MOB* md = (TBL_MOB*)bl;
  6413. char *event=va_arg(ap,char *);
  6414. int allflag=va_arg(ap,int);
  6415. if(!allflag){
  6416. if(strcmp(event,md->npc_event)==0)
  6417. status_kill(bl);
  6418. }else{
  6419. if(!md->spawn)
  6420. status_kill(bl);
  6421. }
  6422. return 0;
  6423. }
  6424. int buildin_killmonster(struct script_state *st)
  6425. {
  6426. char *mapname,*event;
  6427. int m,allflag=0;
  6428. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6429. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6430. if(strcmp(event,"All")==0)
  6431. allflag = 1;
  6432. else
  6433. check_event(st, event);
  6434. if( (m=map_mapname2mapid(mapname))<0 )
  6435. return 0;
  6436. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  6437. return 0;
  6438. }
  6439. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  6440. {
  6441. status_kill(bl);
  6442. return 0;
  6443. }
  6444. int buildin_killmonsterall(struct script_state *st)
  6445. {
  6446. char *mapname;
  6447. int m;
  6448. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6449. if( (m=map_mapname2mapid(mapname))<0 )
  6450. return 0;
  6451. map_foreachinmap(buildin_killmonsterall_sub,
  6452. m,BL_MOB);
  6453. return 0;
  6454. }
  6455. /*==========================================
  6456. * Creates a clone of a player.
  6457. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  6458. *------------------------------------------
  6459. */
  6460. int buildin_clone(struct script_state *st) {
  6461. struct map_session_data *sd, *msd=NULL;
  6462. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  6463. unsigned int duration = 0;
  6464. char *map,*event="";
  6465. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6466. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6467. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6468. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6469. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6470. if( st->end>st->start+7 )
  6471. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6472. if( st->end>st->start+8 )
  6473. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6474. if( st->end>st->start+9 )
  6475. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6476. if( st->end>st->start+10 )
  6477. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  6478. check_event(st, event);
  6479. m = map_mapname2mapid(map);
  6480. if (m < 0) return 0;
  6481. sd = map_charid2sd(char_id);
  6482. if (master_id) {
  6483. msd = map_charid2sd(master_id);
  6484. if (msd)
  6485. master_id = msd->bl.id;
  6486. else
  6487. master_id = 0;
  6488. }
  6489. if (sd) //Return ID of newly crafted clone.
  6490. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  6491. else //Failed to create clone.
  6492. push_val(st->stack,C_INT,0);
  6493. return 0;
  6494. }
  6495. /*==========================================
  6496. * イベント実行
  6497. *------------------------------------------
  6498. */
  6499. int buildin_doevent(struct script_state *st)
  6500. {
  6501. char *event;
  6502. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6503. check_event(st, event);
  6504. npc_event(map_id2sd(st->rid),event,0);
  6505. return 0;
  6506. }
  6507. /*==========================================
  6508. * NPC主体イベント実行
  6509. *------------------------------------------
  6510. */
  6511. int buildin_donpcevent(struct script_state *st)
  6512. {
  6513. char *event;
  6514. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6515. check_event(st, event);
  6516. npc_event_do(event);
  6517. return 0;
  6518. }
  6519. /*==========================================
  6520. * イベントタイマー追加
  6521. *------------------------------------------
  6522. */
  6523. int buildin_addtimer(struct script_state *st)
  6524. {
  6525. char *event;
  6526. int tick;
  6527. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6528. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6529. check_event(st, event);
  6530. pc_addeventtimer(script_rid2sd(st),tick,event);
  6531. return 0;
  6532. }
  6533. /*==========================================
  6534. * イベントタイマー削除
  6535. *------------------------------------------
  6536. */
  6537. int buildin_deltimer(struct script_state *st)
  6538. {
  6539. char *event;
  6540. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6541. check_event(st, event);
  6542. pc_deleventtimer(script_rid2sd(st),event);
  6543. return 0;
  6544. }
  6545. /*==========================================
  6546. * イベントタイマーのカウント値追加
  6547. *------------------------------------------
  6548. */
  6549. int buildin_addtimercount(struct script_state *st)
  6550. {
  6551. char *event;
  6552. int tick;
  6553. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6554. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6555. check_event(st, event);
  6556. pc_addeventtimercount(script_rid2sd(st),event,tick);
  6557. return 0;
  6558. }
  6559. /*==========================================
  6560. * NPCタイマー初期化
  6561. *------------------------------------------
  6562. */
  6563. int buildin_initnpctimer(struct script_state *st)
  6564. {
  6565. struct npc_data *nd;
  6566. if( st->end > st->start+2 )
  6567. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6568. else
  6569. nd=(struct npc_data *)map_id2bl(st->oid);
  6570. npc_settimerevent_tick(nd,0);
  6571. npc_timerevent_start(nd, st->rid);
  6572. return 0;
  6573. }
  6574. /*==========================================
  6575. * NPCタイマー開始
  6576. *------------------------------------------
  6577. */
  6578. int buildin_startnpctimer(struct script_state *st)
  6579. {
  6580. struct npc_data *nd;
  6581. if( st->end > st->start+2 )
  6582. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6583. else
  6584. nd=(struct npc_data *)map_id2bl(st->oid);
  6585. npc_timerevent_start(nd, st->rid);
  6586. return 0;
  6587. }
  6588. /*==========================================
  6589. * NPCタイマー停止
  6590. *------------------------------------------
  6591. */
  6592. int buildin_stopnpctimer(struct script_state *st)
  6593. {
  6594. struct npc_data *nd;
  6595. if( st->end > st->start+2 )
  6596. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6597. else
  6598. nd=(struct npc_data *)map_id2bl(st->oid);
  6599. npc_timerevent_stop(nd);
  6600. return 0;
  6601. }
  6602. /*==========================================
  6603. * NPCタイマー情報所得
  6604. *------------------------------------------
  6605. */
  6606. int buildin_getnpctimer(struct script_state *st)
  6607. {
  6608. struct npc_data *nd;
  6609. struct map_session_data *sd;
  6610. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6611. int val=0;
  6612. if( st->end > st->start+3 )
  6613. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6614. else
  6615. nd=(struct npc_data *)map_id2bl(st->oid);
  6616. if (!nd || nd->bl.type != BL_NPC)
  6617. {
  6618. push_val(st->stack,C_INT,0);
  6619. if (battle_config.error_log)
  6620. ShowError("getnpctimer: Invalid NPC\n");
  6621. return 1;
  6622. }
  6623. switch(type){
  6624. case 0: val=npc_gettimerevent_tick(nd); break;
  6625. case 1:
  6626. if (nd->u.scr.rid) {
  6627. sd = map_id2sd(nd->u.scr.rid);
  6628. if (!sd) {
  6629. if(battle_config.error_log)
  6630. ShowError("buildin_getnpctimer: Attached player not found!\n");
  6631. break;
  6632. }
  6633. val = (sd->npc_timer_id != -1);
  6634. } else
  6635. val= (nd->u.scr.timerid !=-1);
  6636. break;
  6637. case 2: val= nd->u.scr.timeramount; break;
  6638. }
  6639. push_val(st->stack,C_INT,val);
  6640. return 0;
  6641. }
  6642. /*==========================================
  6643. * NPCタイマー値設定
  6644. *------------------------------------------
  6645. */
  6646. int buildin_setnpctimer(struct script_state *st)
  6647. {
  6648. int tick;
  6649. struct npc_data *nd;
  6650. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6651. if( st->end > st->start+3 )
  6652. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6653. else
  6654. nd=(struct npc_data *)map_id2bl(st->oid);
  6655. npc_settimerevent_tick(nd,tick);
  6656. return 0;
  6657. }
  6658. /*==========================================
  6659. * attaches the player rid to the timer [Celest]
  6660. *------------------------------------------
  6661. */
  6662. int buildin_attachnpctimer(struct script_state *st)
  6663. {
  6664. struct map_session_data *sd;
  6665. struct npc_data *nd;
  6666. nd=(struct npc_data *)map_id2bl(st->oid);
  6667. if( st->end > st->start+2 ) {
  6668. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  6669. sd=map_nick2sd(name);
  6670. } else {
  6671. sd = script_rid2sd(st);
  6672. }
  6673. if (sd==NULL)
  6674. return 0;
  6675. nd->u.scr.rid = sd->bl.id;
  6676. return 0;
  6677. }
  6678. /*==========================================
  6679. * detaches a player rid from the timer [Celest]
  6680. *------------------------------------------
  6681. */
  6682. int buildin_detachnpctimer(struct script_state *st)
  6683. {
  6684. struct npc_data *nd;
  6685. if( st->end > st->start+2 )
  6686. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6687. else
  6688. nd=(struct npc_data *)map_id2bl(st->oid);
  6689. nd->u.scr.rid = 0;
  6690. return 0;
  6691. }
  6692. /*==========================================
  6693. * To avoid "player not attached" script errors, this function is provided,
  6694. * it checks if there is a player attached to the current script. [Skotlex]
  6695. * If no, returns 0, if yes, returns the char_id of the attached player.
  6696. *------------------------------------------
  6697. */
  6698. int buildin_playerattached(struct script_state *st)
  6699. {
  6700. struct map_session_data *sd;
  6701. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  6702. push_val(st->stack,C_INT,0);
  6703. else
  6704. push_val(st->stack,C_INT,st->rid);
  6705. return 0;
  6706. }
  6707. /*==========================================
  6708. * 天の声アナウンス
  6709. *------------------------------------------
  6710. */
  6711. int buildin_announce(struct script_state *st)
  6712. {
  6713. char *str, *color=NULL;
  6714. int flag;
  6715. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6716. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6717. if (st->end>st->start+4)
  6718. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6719. if(flag&0x0f){
  6720. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  6721. (struct block_list *)script_rid2sd(st);
  6722. if (color)
  6723. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  6724. else
  6725. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  6726. }else {
  6727. if (color)
  6728. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  6729. else
  6730. intif_GMmessage(str,(int)strlen(str)+1,flag);
  6731. }
  6732. return 0;
  6733. }
  6734. /*==========================================
  6735. * 天の声アナウンス(特定マップ)
  6736. *------------------------------------------
  6737. */
  6738. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  6739. {
  6740. char *str, *color;
  6741. int len,flag;
  6742. str=va_arg(ap,char *);
  6743. len=va_arg(ap,int);
  6744. flag=va_arg(ap,int);
  6745. color=va_arg(ap,char *);
  6746. if (color)
  6747. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  6748. else
  6749. clif_GMmessage(bl,str,len,flag|3);
  6750. return 0;
  6751. }
  6752. int buildin_mapannounce(struct script_state *st)
  6753. {
  6754. char *mapname,*str, *color=NULL;
  6755. int flag,m;
  6756. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6757. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6758. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6759. if (st->end>st->start+5)
  6760. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6761. if( (m=map_mapname2mapid(mapname))<0 )
  6762. return 0;
  6763. map_foreachinmap(buildin_mapannounce_sub,
  6764. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  6765. return 0;
  6766. }
  6767. /*==========================================
  6768. * 天の声アナウンス(特定エリア)
  6769. *------------------------------------------
  6770. */
  6771. int buildin_areaannounce(struct script_state *st)
  6772. {
  6773. char *map,*str,*color=NULL;
  6774. int flag,m;
  6775. int x0,y0,x1,y1;
  6776. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6777. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6778. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6779. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6780. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6781. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  6782. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6783. if (st->end>st->start+9)
  6784. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  6785. if( (m=map_mapname2mapid(map))<0 )
  6786. return 0;
  6787. map_foreachinarea(buildin_mapannounce_sub,
  6788. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  6789. return 0;
  6790. }
  6791. /*==========================================
  6792. * ユーザー数所得
  6793. *------------------------------------------
  6794. */
  6795. int buildin_getusers(struct script_state *st)
  6796. {
  6797. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6798. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  6799. int val=0;
  6800. switch(flag&0x07){
  6801. case 0: val=map[bl->m].users; break;
  6802. case 1: val=map_getusers(); break;
  6803. }
  6804. push_val(st->stack,C_INT,val);
  6805. return 0;
  6806. }
  6807. /*==========================================
  6808. * Works like @WHO - displays all online users names in window
  6809. *------------------------------------------
  6810. */
  6811. int buildin_getusersname(struct script_state *st)
  6812. {
  6813. struct map_session_data *sd, *pl_sd = NULL, **pl_allsd;
  6814. int i=0,disp_num=1, users;
  6815. sd = script_rid2sd(st);
  6816. if (!sd) return 0;
  6817. pl_allsd = map_getallusers(&users);
  6818. for (i=0;i<users;i++)
  6819. {
  6820. pl_sd = pl_allsd[i];
  6821. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  6822. {
  6823. if((disp_num++)%10==0)
  6824. clif_scriptnext(sd,st->oid);
  6825. clif_scriptmes(sd,st->oid,pl_sd->status.name);
  6826. }
  6827. }
  6828. return 0;
  6829. }
  6830. /*==========================================
  6831. * getmapguildusers("mapname.gat",guild ID) Returns the number guild members present on a map [Reddozen]
  6832. *------------------------------------------
  6833. */
  6834. int buildin_getmapguildusers(struct script_state *st) {
  6835. char *str;
  6836. int m, gid;
  6837. int i=0,c=0;
  6838. struct guild *g = NULL;
  6839. str=conv_str(st, &(st->stack->stack_data[st->start+2]));
  6840. gid=conv_num(st, &(st->stack->stack_data[st->start+3]));
  6841. if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server)
  6842. push_val(st->stack, C_INT, -1);
  6843. return 0;
  6844. }
  6845. g = guild_search(gid);
  6846. if (g){
  6847. for(i = 0; i < g->max_member; i++)
  6848. {
  6849. if (g->member[i].sd && g->member[i].sd->bl.m == m)
  6850. c++;
  6851. }
  6852. }
  6853. push_val(st->stack, C_INT, c);
  6854. return 0;
  6855. }
  6856. /*==========================================
  6857. * マップ指定ユーザー数所得
  6858. *------------------------------------------
  6859. */
  6860. int buildin_getmapusers(struct script_state *st)
  6861. {
  6862. char *str;
  6863. int m;
  6864. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6865. if( (m=map_mapname2mapid(str))< 0){
  6866. push_val(st->stack,C_INT,-1);
  6867. return 0;
  6868. }
  6869. push_val(st->stack,C_INT,map[m].users);
  6870. return 0;
  6871. }
  6872. /*==========================================
  6873. * エリア指定ユーザー数所得
  6874. *------------------------------------------
  6875. */
  6876. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  6877. {
  6878. int *users=va_arg(ap,int *);
  6879. (*users)++;
  6880. return 0;
  6881. }
  6882. int buildin_getareausers(struct script_state *st)
  6883. {
  6884. char *str;
  6885. int m,x0,y0,x1,y1,users=0;
  6886. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6887. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6888. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6889. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6890. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6891. if( (m=map_mapname2mapid(str))< 0){
  6892. push_val(st->stack,C_INT,-1);
  6893. return 0;
  6894. }
  6895. map_foreachinarea(buildin_getareausers_sub,
  6896. m,x0,y0,x1,y1,BL_PC,&users);
  6897. push_val(st->stack,C_INT,users);
  6898. return 0;
  6899. }
  6900. /*==========================================
  6901. * エリア指定ドロップアイテム数所得
  6902. *------------------------------------------
  6903. */
  6904. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  6905. {
  6906. int item=va_arg(ap,int);
  6907. int *amount=va_arg(ap,int *);
  6908. struct flooritem_data *drop=(struct flooritem_data *)bl;
  6909. if(drop->item_data.nameid==item)
  6910. (*amount)+=drop->item_data.amount;
  6911. return 0;
  6912. }
  6913. int buildin_getareadropitem(struct script_state *st)
  6914. {
  6915. char *str;
  6916. int m,x0,y0,x1,y1,item,amount=0;
  6917. struct script_data *data;
  6918. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6919. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6920. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6921. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6922. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6923. data=&(st->stack->stack_data[st->start+7]);
  6924. get_val(st,data);
  6925. if( data->type==C_STR || data->type==C_CONSTSTR ){
  6926. const char *name=conv_str(st,data);
  6927. struct item_data *item_data = itemdb_searchname(name);
  6928. item=UNKNOWN_ITEM_ID;
  6929. if( item_data )
  6930. item=item_data->nameid;
  6931. }else
  6932. item=conv_num(st,data);
  6933. if( (m=map_mapname2mapid(str))< 0){
  6934. push_val(st->stack,C_INT,-1);
  6935. return 0;
  6936. }
  6937. map_foreachinarea(buildin_getareadropitem_sub,
  6938. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  6939. push_val(st->stack,C_INT,amount);
  6940. return 0;
  6941. }
  6942. /*==========================================
  6943. * NPCの有効化
  6944. *------------------------------------------
  6945. */
  6946. int buildin_enablenpc(struct script_state *st)
  6947. {
  6948. char *str;
  6949. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6950. npc_enable(str,1);
  6951. return 0;
  6952. }
  6953. /*==========================================
  6954. * NPCの無効化
  6955. *------------------------------------------
  6956. */
  6957. int buildin_disablenpc(struct script_state *st)
  6958. {
  6959. char *str;
  6960. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6961. npc_enable(str,0);
  6962. return 0;
  6963. }
  6964. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  6965. {
  6966. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6967. struct chat_data *cd;
  6968. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  6969. return 0;
  6970. npc_enable(nd->name,1);
  6971. nd->arenaflag=1;
  6972. if(cd->users>=cd->trigger && cd->npc_event[0])
  6973. npc_timer_event(cd->npc_event);
  6974. return 0;
  6975. }
  6976. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  6977. {
  6978. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6979. nd->arenaflag=0;
  6980. return 0;
  6981. }
  6982. /*==========================================
  6983. * 隠れているNPCの表示
  6984. *------------------------------------------
  6985. */
  6986. int buildin_hideoffnpc(struct script_state *st)
  6987. {
  6988. char *str;
  6989. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6990. npc_enable(str,2);
  6991. return 0;
  6992. }
  6993. /*==========================================
  6994. * NPCをハイディング
  6995. *------------------------------------------
  6996. */
  6997. int buildin_hideonnpc(struct script_state *st)
  6998. {
  6999. char *str;
  7000. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7001. npc_enable(str,4);
  7002. return 0;
  7003. }
  7004. /*==========================================
  7005. * 状態異常にかかる
  7006. *------------------------------------------
  7007. */
  7008. int buildin_sc_start(struct script_state *st)
  7009. {
  7010. struct block_list *bl;
  7011. int type,tick,val1,val4=0;
  7012. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7013. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7014. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7015. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  7016. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  7017. else
  7018. bl = map_id2bl(st->rid);
  7019. if (potion_flag==1 && potion_target) {
  7020. bl = map_id2bl(potion_target);
  7021. tick/=2; //Thrown potions only last half.
  7022. val4 = 1; //Mark that this was a thrown sc_effect
  7023. }
  7024. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7025. { //When there isn't a duration specified, try to get it from the skill_db
  7026. tick = StatusSkillChangeTable[type];
  7027. if (tick)
  7028. tick = skill_get_time(tick,val1);
  7029. else //Failed to retrieve duration, reset to what it was.
  7030. tick = 0;
  7031. }
  7032. if (bl)
  7033. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  7034. return 0;
  7035. }
  7036. /*==========================================
  7037. * 状態異常にかかる(確率指定)
  7038. *------------------------------------------
  7039. */
  7040. int buildin_sc_start2(struct script_state *st)
  7041. {
  7042. struct block_list *bl;
  7043. int type,tick,val1,val4=0,per;
  7044. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7045. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7046. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7047. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7048. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  7049. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7050. else
  7051. bl = map_id2bl(st->rid);
  7052. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7053. { //When there isn't a duration specified, try to get it from the skill_db
  7054. tick = StatusSkillChangeTable[type];
  7055. if (tick)
  7056. tick = skill_get_time(tick,val1);
  7057. else //Failed to retrieve duration, reset to what it was.
  7058. tick = 0;
  7059. }
  7060. if (potion_flag==1 && potion_target) {
  7061. bl = map_id2bl(potion_target);
  7062. tick/=2;
  7063. val4 = 1;
  7064. }
  7065. if(bl)
  7066. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  7067. return 0;
  7068. }
  7069. /*==========================================
  7070. * Starts a SC_ change with the four values passed. [Skotlex]
  7071. * Final optional argument is the ID of player to affect.
  7072. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  7073. *------------------------------------------
  7074. */
  7075. int buildin_sc_start4(struct script_state *st)
  7076. {
  7077. struct block_list *bl;
  7078. int type,tick,val1,val2,val3,val4;
  7079. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7080. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7081. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7082. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7083. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7084. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  7085. if( st->end>st->start+8 )
  7086. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  7087. else
  7088. bl = map_id2bl(st->rid);
  7089. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7090. { //When there isn't a duration specified, try to get it from the skill_db
  7091. tick = StatusSkillChangeTable[type];
  7092. if (tick)
  7093. tick = skill_get_time(tick,val1);
  7094. else //Failed to retrieve duration, reset to what it was.
  7095. tick = 0;
  7096. }
  7097. if (potion_flag==1 && potion_target) {
  7098. bl = map_id2bl(potion_target);
  7099. tick/=2;
  7100. }
  7101. if (bl)
  7102. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  7103. return 0;
  7104. }
  7105. /*==========================================
  7106. * 状態異常が直る
  7107. *------------------------------------------
  7108. */
  7109. int buildin_sc_end(struct script_state *st)
  7110. {
  7111. struct block_list *bl;
  7112. int type;
  7113. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7114. bl = map_id2bl(st->rid);
  7115. if (potion_flag==1 && potion_target)
  7116. bl = map_id2bl(potion_target);
  7117. if (!bl) return 0;
  7118. if (type >= 0)
  7119. status_change_end(bl,type,-1);
  7120. else
  7121. status_change_clear(bl, 2);
  7122. return 0;
  7123. }
  7124. /*==========================================
  7125. * 状態異常耐性を計算した確率を返す
  7126. *------------------------------------------
  7127. */
  7128. int buildin_getscrate(struct script_state *st)
  7129. {
  7130. struct block_list *bl;
  7131. int sc_def=0,type,rate;
  7132. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7133. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7134. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  7135. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7136. else
  7137. bl = map_id2bl(st->rid);
  7138. if (bl)
  7139. sc_def = status_get_sc_def(bl,type);
  7140. rate = rate*(10000-sc_def)/10000;
  7141. push_val(st->stack,C_INT,rate<0?0:rate);
  7142. return 0;
  7143. }
  7144. /*==========================================
  7145. *
  7146. *------------------------------------------
  7147. */
  7148. int buildin_debugmes(struct script_state *st)
  7149. {
  7150. conv_str(st,& (st->stack->stack_data[st->start+2]));
  7151. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  7152. return 0;
  7153. }
  7154. /*==========================================
  7155. *捕獲アイテム使用
  7156. *------------------------------------------
  7157. */
  7158. int buildin_catchpet(struct script_state *st)
  7159. {
  7160. int pet_id;
  7161. struct map_session_data *sd;
  7162. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  7163. sd=script_rid2sd(st);
  7164. pet_catch_process1(sd,pet_id);
  7165. return 0;
  7166. }
  7167. /*==========================================
  7168. * [orn]
  7169. *------------------------------------------
  7170. */
  7171. int buildin_homunculus_evolution(struct script_state *st)
  7172. {
  7173. struct map_session_data *sd;
  7174. sd=script_rid2sd(st);
  7175. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->hd->homunculus.intimacy > 91000 ) {
  7176. return !merc_hom_evolution(sd->hd) ;
  7177. }
  7178. clif_emotion(&sd->hd->bl, 4) ; //swt
  7179. return 0;
  7180. }
  7181. //These two functions bring the eA MAPID_* class functionality to scripts.
  7182. int buildin_eaclass(struct script_state *st)
  7183. {
  7184. int class_;
  7185. if( st->end>st->start+2 )
  7186. class_ = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7187. else {
  7188. struct map_session_data *sd;
  7189. sd=script_rid2sd(st);
  7190. if (!sd) {
  7191. push_val(st->stack,C_INT, -1);
  7192. return 0;
  7193. }
  7194. class_ = sd->status.class_;
  7195. }
  7196. push_val(st->stack,C_INT, pc_jobid2mapid(class_));
  7197. return 0;
  7198. }
  7199. int buildin_roclass(struct script_state *st)
  7200. {
  7201. int class_ =conv_num(st,& (st->stack->stack_data[st->start+2]));
  7202. int sex;
  7203. if( st->end>st->start+3 )
  7204. sex = conv_num(st,& (st->stack->stack_data[st->start+3]));
  7205. else {
  7206. struct map_session_data *sd;
  7207. if (st->rid && (sd=script_rid2sd(st)))
  7208. sex = sd->status.sex;
  7209. else
  7210. sex = 1; //Just use male when not found.
  7211. }
  7212. push_val(st->stack,C_INT,pc_mapid2jobid(class_, sex));
  7213. return 0;
  7214. }
  7215. /*==========================================
  7216. *携帯卵孵化機使用
  7217. *------------------------------------------
  7218. */
  7219. int buildin_birthpet(struct script_state *st)
  7220. {
  7221. struct map_session_data *sd;
  7222. sd=script_rid2sd(st);
  7223. clif_sendegg(sd);
  7224. return 0;
  7225. }
  7226. /*==========================================
  7227. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  7228. *------------------------------------------
  7229. */
  7230. int buildin_resetlvl(struct script_state *st)
  7231. {
  7232. struct map_session_data *sd;
  7233. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7234. sd=script_rid2sd(st);
  7235. pc_resetlvl(sd,type);
  7236. return 0;
  7237. }
  7238. /*==========================================
  7239. * ステータスリセット
  7240. *------------------------------------------
  7241. */
  7242. int buildin_resetstatus(struct script_state *st)
  7243. {
  7244. struct map_session_data *sd;
  7245. sd=script_rid2sd(st);
  7246. pc_resetstate(sd);
  7247. return 0;
  7248. }
  7249. /*==========================================
  7250. * script command resetskill
  7251. *------------------------------------------
  7252. */
  7253. int buildin_resetskill(struct script_state *st)
  7254. {
  7255. struct map_session_data *sd;
  7256. sd=script_rid2sd(st);
  7257. pc_resetskill(sd,1);
  7258. return 0;
  7259. }
  7260. /*==========================================
  7261. * Counts total amount of skill points.
  7262. *------------------------------------------
  7263. */
  7264. int buildin_skillpointcount(struct script_state *st)
  7265. {
  7266. struct map_session_data *sd;
  7267. sd=script_rid2sd(st);
  7268. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  7269. return 0;
  7270. }
  7271. /*==========================================
  7272. *
  7273. *------------------------------------------
  7274. */
  7275. int buildin_changebase(struct script_state *st)
  7276. {
  7277. struct map_session_data *sd=NULL;
  7278. int vclass;
  7279. if( st->end>st->start+3 )
  7280. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  7281. else
  7282. sd=script_rid2sd(st);
  7283. if(sd == NULL)
  7284. return 0;
  7285. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7286. if(vclass == JOB_WEDDING)
  7287. {
  7288. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  7289. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  7290. )
  7291. return 0;
  7292. }
  7293. if(!sd->disguise && vclass != sd->vd.class_) {
  7294. status_set_viewdata(&sd->bl, vclass);
  7295. //Updated client view. Base, Weapon and Cloth Colors.
  7296. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  7297. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7298. if (sd->vd.cloth_color)
  7299. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7300. }
  7301. return 0;
  7302. }
  7303. /*==========================================
  7304. * 性別変換
  7305. *------------------------------------------
  7306. */
  7307. int buildin_changesex(struct script_state *st) {
  7308. struct map_session_data *sd = NULL;
  7309. sd = script_rid2sd(st);
  7310. if (sd->status.sex == 0) {
  7311. sd->status.sex = 1;
  7312. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7313. sd->status.class_ -= 1;
  7314. } else if (sd->status.sex == 1) {
  7315. sd->status.sex = 0;
  7316. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7317. sd->status.class_ += 1;
  7318. }
  7319. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  7320. chrif_save(sd,0);
  7321. return 0;
  7322. }
  7323. /*==========================================
  7324. * npcチャット作成
  7325. *------------------------------------------
  7326. */
  7327. int buildin_waitingroom(struct script_state *st)
  7328. {
  7329. char *name,*ev="";
  7330. int limit, trigger = 0,pub=1;
  7331. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7332. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  7333. if(limit==0)
  7334. pub=3;
  7335. if( (st->end > st->start+5) ){
  7336. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  7337. get_val(st,data);
  7338. if(data->type==C_INT){
  7339. // 新Athena仕様(旧Athena仕様と互換性あり)
  7340. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7341. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7342. }else{
  7343. // eathena仕様
  7344. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7345. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7346. }
  7347. }else{
  7348. // 旧Athena仕様
  7349. if( st->end > st->start+4 )
  7350. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7351. }
  7352. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  7353. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  7354. return 0;
  7355. }
  7356. /*==========================================
  7357. * Works like 'announce' but outputs in the common chat window
  7358. *------------------------------------------
  7359. */
  7360. int buildin_globalmes(struct script_state *st)
  7361. {
  7362. struct block_list *bl = map_id2bl(st->oid);
  7363. struct npc_data *nd = (struct npc_data *)bl;
  7364. char *name=NULL,*mes;
  7365. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  7366. if(mes==NULL) return 0;
  7367. if(st->end>st->start+3){ // NPC名の取得(123#456)
  7368. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7369. } else {
  7370. name=nd->name;
  7371. }
  7372. npc_globalmessage(name,mes); // グローバルメッセージ送信
  7373. return 0;
  7374. }
  7375. /*==========================================
  7376. * npcチャット削除
  7377. *------------------------------------------
  7378. */
  7379. int buildin_delwaitingroom(struct script_state *st)
  7380. {
  7381. struct npc_data *nd;
  7382. if( st->end > st->start+2 )
  7383. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7384. else
  7385. nd=(struct npc_data *)map_id2bl(st->oid);
  7386. chat_deletenpcchat(nd);
  7387. return 0;
  7388. }
  7389. /*==========================================
  7390. * npcチャット全員蹴り出す
  7391. *------------------------------------------
  7392. */
  7393. int buildin_waitingroomkickall(struct script_state *st)
  7394. {
  7395. struct npc_data *nd;
  7396. struct chat_data *cd;
  7397. if( st->end > st->start+2 )
  7398. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7399. else
  7400. nd=(struct npc_data *)map_id2bl(st->oid);
  7401. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7402. return 0;
  7403. chat_npckickall(cd);
  7404. return 0;
  7405. }
  7406. /*==========================================
  7407. * npcチャットイベント有効化
  7408. *------------------------------------------
  7409. */
  7410. int buildin_enablewaitingroomevent(struct script_state *st)
  7411. {
  7412. struct npc_data *nd;
  7413. struct chat_data *cd;
  7414. if( st->end > st->start+2 )
  7415. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7416. else
  7417. nd=(struct npc_data *)map_id2bl(st->oid);
  7418. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7419. return 0;
  7420. chat_enableevent(cd);
  7421. return 0;
  7422. }
  7423. /*==========================================
  7424. * npcチャットイベント無効化
  7425. *------------------------------------------
  7426. */
  7427. int buildin_disablewaitingroomevent(struct script_state *st)
  7428. {
  7429. struct npc_data *nd;
  7430. struct chat_data *cd;
  7431. if( st->end > st->start+2 )
  7432. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7433. else
  7434. nd=(struct npc_data *)map_id2bl(st->oid);
  7435. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7436. return 0;
  7437. chat_disableevent(cd);
  7438. return 0;
  7439. }
  7440. /*==========================================
  7441. * npcチャット状態所得
  7442. *------------------------------------------
  7443. */
  7444. int buildin_getwaitingroomstate(struct script_state *st)
  7445. {
  7446. struct npc_data *nd;
  7447. struct chat_data *cd;
  7448. int val=0,type;
  7449. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7450. if( st->end > st->start+3 )
  7451. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  7452. else
  7453. nd=(struct npc_data *)map_id2bl(st->oid);
  7454. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  7455. push_val(st->stack,C_INT,-1);
  7456. return 0;
  7457. }
  7458. switch(type){
  7459. case 0: val=cd->users; break;
  7460. case 1: val=cd->limit; break;
  7461. case 2: val=cd->trigger&0x7f; break;
  7462. case 3: val=((cd->trigger&0x80)>0); break;
  7463. case 32: val=(cd->users >= cd->limit); break;
  7464. case 33: val=(cd->users >= cd->trigger); break;
  7465. case 4:
  7466. push_str(st->stack,C_CONSTSTR,cd->title);
  7467. return 0;
  7468. case 5:
  7469. push_str(st->stack,C_CONSTSTR,cd->pass);
  7470. return 0;
  7471. case 16:
  7472. push_str(st->stack,C_CONSTSTR,cd->npc_event);
  7473. return 0;
  7474. }
  7475. push_val(st->stack,C_INT,val);
  7476. return 0;
  7477. }
  7478. /*==========================================
  7479. * チャットメンバー(規定人数)ワープ
  7480. *------------------------------------------
  7481. */
  7482. int buildin_warpwaitingpc(struct script_state *st)
  7483. {
  7484. int x,y,i,n;
  7485. char *str;
  7486. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7487. struct chat_data *cd;
  7488. struct map_session_data *sd;
  7489. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7490. return 0;
  7491. n=cd->trigger&0x7f;
  7492. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7493. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7494. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7495. if( st->end > st->start+5 )
  7496. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7497. for(i=0;i<n;i++){
  7498. sd=cd->usersd[0];
  7499. if (!sd) continue; //Broken npc chat room?
  7500. mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24),sd->bl.id);
  7501. if(strcmp(str,"Random")==0)
  7502. pc_randomwarp(sd,3);
  7503. else if(strcmp(str,"SavePoint")==0){
  7504. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  7505. return 0;
  7506. pc_setpos(sd,sd->status.save_point.map,
  7507. sd->status.save_point.x,sd->status.save_point.y,3);
  7508. }else
  7509. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  7510. }
  7511. mapreg_setreg(add_str("$@warpwaitingpcnum"),n);
  7512. return 0;
  7513. }
  7514. /*==========================================
  7515. * RIDのアタッチ
  7516. *------------------------------------------
  7517. */
  7518. int buildin_attachrid(struct script_state *st)
  7519. {
  7520. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7521. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  7522. return 0;
  7523. }
  7524. /*==========================================
  7525. * RIDのデタッチ
  7526. *------------------------------------------
  7527. */
  7528. int buildin_detachrid(struct script_state *st)
  7529. {
  7530. st->rid=0;
  7531. return 0;
  7532. }
  7533. /*==========================================
  7534. * 存在チェック
  7535. *------------------------------------------
  7536. */
  7537. int buildin_isloggedin(struct script_state *st)
  7538. {
  7539. push_val(st->stack,C_INT, map_id2sd(
  7540. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  7541. return 0;
  7542. }
  7543. /*==========================================
  7544. *
  7545. *------------------------------------------
  7546. */
  7547. int buildin_setmapflagnosave(struct script_state *st)
  7548. {
  7549. int m,x,y;
  7550. unsigned short mapindex;
  7551. char *str,*str2;
  7552. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7553. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7554. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7555. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7556. m = map_mapname2mapid(str);
  7557. mapindex = mapindex_name2id(str2);
  7558. if(m >= 0 && mapindex) {
  7559. map[m].flag.nosave=1;
  7560. map[m].save.map=mapindex;
  7561. map[m].save.x=x;
  7562. map[m].save.y=y;
  7563. }
  7564. return 0;
  7565. }
  7566. int buildin_setmapflag(struct script_state *st)
  7567. {
  7568. int m,i;
  7569. char *str;
  7570. char *val=NULL;
  7571. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7572. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7573. if(st->end>st->start+4){
  7574. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7575. }
  7576. m = map_mapname2mapid(str);
  7577. if(m >= 0) {
  7578. switch(i) {
  7579. case MF_NOMEMO:
  7580. map[m].flag.nomemo=1;
  7581. break;
  7582. case MF_NOTELEPORT:
  7583. map[m].flag.noteleport=1;
  7584. break;
  7585. case MF_NOBRANCH:
  7586. map[m].flag.nobranch=1;
  7587. break;
  7588. case MF_NOPENALTY:
  7589. map[m].flag.noexppenalty=1;
  7590. map[m].flag.nozenypenalty=1;
  7591. break;
  7592. case MF_NOZENYPENALTY:
  7593. map[m].flag.nozenypenalty=1;
  7594. break;
  7595. case MF_PVP:
  7596. map[m].flag.pvp=1;
  7597. break;
  7598. case MF_PVP_NOPARTY:
  7599. map[m].flag.pvp_noparty=1;
  7600. break;
  7601. case MF_PVP_NOGUILD:
  7602. map[m].flag.pvp_noguild=1;
  7603. break;
  7604. case MF_GVG:
  7605. map[m].flag.gvg=1;
  7606. break;
  7607. case MF_GVG_NOPARTY:
  7608. map[m].flag.gvg_noparty=1;
  7609. break;
  7610. case MF_GVG_DUNGEON:
  7611. map[m].flag.gvg_dungeon=1;
  7612. break;
  7613. case MF_GVG_CASTLE:
  7614. map[m].flag.gvg_castle=1;
  7615. break;
  7616. case MF_NOTRADE:
  7617. map[m].flag.notrade=1;
  7618. break;
  7619. case MF_NODROP:
  7620. map[m].flag.nodrop=1;
  7621. break;
  7622. case MF_NOSKILL:
  7623. map[m].flag.noskill=1;
  7624. break;
  7625. case MF_NOWARP:
  7626. map[m].flag.nowarp=1;
  7627. break;
  7628. case MF_NOICEWALL: // [Valaris]
  7629. map[m].flag.noicewall=1;
  7630. break;
  7631. case MF_SNOW: // [Valaris]
  7632. map[m].flag.snow=1;
  7633. break;
  7634. case MF_CLOUDS:
  7635. map[m].flag.clouds=1;
  7636. break;
  7637. case MF_CLOUDS2: // [Valaris]
  7638. map[m].flag.clouds2=1;
  7639. break;
  7640. case MF_FOG: // [Valaris]
  7641. map[m].flag.fog=1;
  7642. break;
  7643. case MF_FIREWORKS:
  7644. map[m].flag.fireworks=1;
  7645. break;
  7646. case MF_SAKURA: // [Valaris]
  7647. map[m].flag.sakura=1;
  7648. break;
  7649. case MF_LEAVES: // [Valaris]
  7650. map[m].flag.leaves=1;
  7651. break;
  7652. case MF_RAIN: // [Valaris]
  7653. map[m].flag.rain=1;
  7654. break;
  7655. case MF_INDOORS: // celest
  7656. map[m].flag.indoors=1;
  7657. break;
  7658. case MF_NIGHTENABLED:
  7659. map[m].flag.nightenabled=1;
  7660. break;
  7661. case MF_NOGO: // celest
  7662. map[m].flag.nogo=1;
  7663. break;
  7664. case MF_NOBASEEXP:
  7665. map[m].flag.nobaseexp=1;
  7666. break;
  7667. case MF_NOJOBEXP:
  7668. map[m].flag.nojobexp=1;
  7669. break;
  7670. case MF_NOMOBLOOT:
  7671. map[m].flag.nomobloot=1;
  7672. break;
  7673. case MF_NOMVPLOOT:
  7674. map[m].flag.nomvploot=1;
  7675. break;
  7676. case MF_NORETURN:
  7677. map[m].flag.noreturn=1;
  7678. break;
  7679. case MF_NOWARPTO:
  7680. map[m].flag.nowarpto=1;
  7681. break;
  7682. case MF_NIGHTMAREDROP:
  7683. map[m].flag.pvp_nightmaredrop=1;
  7684. break;
  7685. case MF_RESTRICTED:
  7686. map[m].flag.restricted=1;
  7687. break;
  7688. case MF_NOCOMMAND:
  7689. map[m].nocommand = (!val || atoi(val) <= 0) ? 100 : atoi(val);
  7690. break;
  7691. case MF_JEXP:
  7692. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7693. break;
  7694. case MF_BEXP:
  7695. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7696. break;
  7697. case MF_NOVENDING:
  7698. map[m].flag.novending=1;
  7699. break;
  7700. case MF_LOADEVENT:
  7701. map[m].flag.loadevent=1;
  7702. break;
  7703. case MF_NOCHAT:
  7704. map[m].flag.nochat=1;
  7705. break;
  7706. case MF_PARTYLOCK:
  7707. map[m].flag.partylock=1;
  7708. break;
  7709. case MF_GUILDLOCK:
  7710. map[m].flag.guildlock=1;
  7711. break;
  7712. }
  7713. }
  7714. return 0;
  7715. }
  7716. int buildin_removemapflag(struct script_state *st)
  7717. {
  7718. int m,i;
  7719. char *str;
  7720. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7721. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7722. m = map_mapname2mapid(str);
  7723. if(m >= 0) {
  7724. switch(i) {
  7725. case MF_NOMEMO:
  7726. map[m].flag.nomemo=0;
  7727. break;
  7728. case MF_NOTELEPORT:
  7729. map[m].flag.noteleport=0;
  7730. break;
  7731. case MF_NOSAVE:
  7732. map[m].flag.nosave=0;
  7733. break;
  7734. case MF_NOBRANCH:
  7735. map[m].flag.nobranch=0;
  7736. break;
  7737. case MF_NOPENALTY:
  7738. map[m].flag.noexppenalty=0;
  7739. map[m].flag.nozenypenalty=0;
  7740. break;
  7741. case MF_PVP:
  7742. map[m].flag.pvp=0;
  7743. break;
  7744. case MF_PVP_NOPARTY:
  7745. map[m].flag.pvp_noparty=0;
  7746. break;
  7747. case MF_PVP_NOGUILD:
  7748. map[m].flag.pvp_noguild=0;
  7749. break;
  7750. case MF_GVG:
  7751. map[m].flag.gvg=0;
  7752. break;
  7753. case MF_GVG_NOPARTY:
  7754. map[m].flag.gvg_noparty=0;
  7755. break;
  7756. case MF_GVG_DUNGEON:
  7757. map[m].flag.gvg_dungeon=0;
  7758. break;
  7759. case MF_GVG_CASTLE:
  7760. map[m].flag.gvg_castle=0;
  7761. break;
  7762. case MF_NOZENYPENALTY:
  7763. map[m].flag.nozenypenalty=0;
  7764. break;
  7765. case MF_NOTRADE:
  7766. map[m].flag.notrade=0;
  7767. break;
  7768. case MF_NODROP:
  7769. map[m].flag.nodrop=0;
  7770. break;
  7771. case MF_NOSKILL:
  7772. map[m].flag.noskill=0;
  7773. break;
  7774. case MF_NOWARP:
  7775. map[m].flag.nowarp=0;
  7776. break;
  7777. case MF_NOICEWALL: // [Valaris]
  7778. map[m].flag.noicewall=0;
  7779. break;
  7780. case MF_SNOW: // [Valaris]
  7781. map[m].flag.snow=0;
  7782. break;
  7783. case MF_CLOUDS:
  7784. map[m].flag.clouds=0;
  7785. break;
  7786. case MF_CLOUDS2: // [Valaris]
  7787. map[m].flag.clouds2=0;
  7788. break;
  7789. case MF_FOG: // [Valaris]
  7790. map[m].flag.fog=0;
  7791. break;
  7792. case MF_FIREWORKS:
  7793. map[m].flag.fireworks=0;
  7794. break;
  7795. case MF_SAKURA: // [Valaris]
  7796. map[m].flag.sakura=0;
  7797. break;
  7798. case MF_LEAVES: // [Valaris]
  7799. map[m].flag.leaves=0;
  7800. break;
  7801. case MF_RAIN: // [Valaris]
  7802. map[m].flag.rain=0;
  7803. break;
  7804. case MF_INDOORS: // celest
  7805. map[m].flag.indoors=0;
  7806. break;
  7807. case MF_NIGHTENABLED:
  7808. map[m].flag.nightenabled=0;
  7809. break;
  7810. case MF_NOGO: // celest
  7811. map[m].flag.nogo=0;
  7812. break;
  7813. case MF_NOBASEEXP:
  7814. map[m].flag.nobaseexp=0;
  7815. break;
  7816. case MF_NOJOBEXP:
  7817. map[m].flag.nojobexp=0;
  7818. break;
  7819. case MF_NOMOBLOOT:
  7820. map[m].flag.nomobloot=0;
  7821. break;
  7822. case MF_NOMVPLOOT:
  7823. map[m].flag.nomvploot=0;
  7824. break;
  7825. case MF_NORETURN:
  7826. map[m].flag.noreturn=0;
  7827. break;
  7828. case MF_NOWARPTO:
  7829. map[m].flag.nowarpto=0;
  7830. break;
  7831. case MF_NIGHTMAREDROP:
  7832. map[m].flag.pvp_nightmaredrop=0;
  7833. break;
  7834. case MF_RESTRICTED:
  7835. map[m].flag.restricted=0;
  7836. break;
  7837. case MF_NOCOMMAND:
  7838. map[m].nocommand=0;
  7839. break;
  7840. case MF_JEXP:
  7841. map[m].jexp=100;
  7842. break;
  7843. case MF_BEXP:
  7844. map[m].bexp=100;
  7845. break;
  7846. case MF_NOVENDING:
  7847. map[m].flag.novending=0;
  7848. break;
  7849. case MF_LOADEVENT:
  7850. map[m].flag.loadevent=0;
  7851. break;
  7852. case MF_NOCHAT:
  7853. map[m].flag.nochat=0;
  7854. break;
  7855. case MF_PARTYLOCK:
  7856. map[m].flag.partylock=0;
  7857. break;
  7858. case MF_GUILDLOCK:
  7859. map[m].flag.guildlock=0;
  7860. break;
  7861. }
  7862. }
  7863. return 0;
  7864. }
  7865. int buildin_pvpon(struct script_state *st)
  7866. {
  7867. int m,i,users;
  7868. char *str;
  7869. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7870. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7871. m = map_mapname2mapid(str);
  7872. if(m >= 0 && !map[m].flag.pvp) {
  7873. map[m].flag.pvp = 1;
  7874. clif_send0199(m,1);
  7875. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  7876. return 0;
  7877. pl_allsd = map_getallusers(&users);
  7878. for(i=0;i<users;i++)
  7879. {
  7880. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  7881. {
  7882. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  7883. pl_sd->pvp_rank=0;
  7884. pl_sd->pvp_lastusers=0;
  7885. pl_sd->pvp_point=5;
  7886. pl_sd->pvp_won = 0;
  7887. pl_sd->pvp_lost = 0;
  7888. }
  7889. }
  7890. }
  7891. return 0;
  7892. }
  7893. int buildin_pvpoff(struct script_state *st)
  7894. {
  7895. int m,i,users;
  7896. char *str;
  7897. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7898. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7899. m = map_mapname2mapid(str);
  7900. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  7901. map[m].flag.pvp = 0;
  7902. clif_send0199(m,0);
  7903. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  7904. return 0;
  7905. pl_allsd = map_getallusers(&users);
  7906. for(i=0;i<users;i++)
  7907. {
  7908. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  7909. {
  7910. clif_pvpset(pl_sd,0,0,2);
  7911. if(pl_sd->pvp_timer != UINT_MAX) {
  7912. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  7913. pl_sd->pvp_timer = -1;
  7914. }
  7915. }
  7916. }
  7917. }
  7918. return 0;
  7919. }
  7920. int buildin_gvgon(struct script_state *st)
  7921. {
  7922. int m;
  7923. char *str;
  7924. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7925. m = map_mapname2mapid(str);
  7926. if(m >= 0 && !map[m].flag.gvg) {
  7927. map[m].flag.gvg = 1;
  7928. clif_send0199(m,3);
  7929. }
  7930. return 0;
  7931. }
  7932. int buildin_gvgoff(struct script_state *st)
  7933. {
  7934. int m;
  7935. char *str;
  7936. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7937. m = map_mapname2mapid(str);
  7938. if(m >= 0 && map[m].flag.gvg) {
  7939. map[m].flag.gvg = 0;
  7940. clif_send0199(m,0);
  7941. }
  7942. return 0;
  7943. }
  7944. /*==========================================
  7945. * Shows an emoticon on top of the player/npc
  7946. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  7947. *------------------------------------------
  7948. */
  7949. //Optional second parameter added by [Skotlex]
  7950. int buildin_emotion(struct script_state *st)
  7951. {
  7952. int type;
  7953. int player=0;
  7954. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7955. if(type < 0 || type > 100)
  7956. return 0;
  7957. if( st->end>st->start+3 )
  7958. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7959. if (player) {
  7960. struct map_session_data *sd = script_rid2sd(st);
  7961. if (sd)
  7962. clif_emotion(&sd->bl,type);
  7963. } else
  7964. clif_emotion(map_id2bl(st->oid),type);
  7965. return 0;
  7966. }
  7967. static int buildin_maprespawnguildid_sub_pc(DBKey key, void *data, va_list ap)
  7968. {
  7969. int m=va_arg(ap,int);
  7970. int g_id=va_arg(ap,int);
  7971. int flag=va_arg(ap,int);
  7972. struct map_session_data *sd = (TBL_PC*)data;
  7973. if(!sd || sd->bl.m != m)
  7974. return 0;
  7975. if(
  7976. (sd->status.guild_id == g_id && flag&1) || //Warp out owners
  7977. (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders
  7978. (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  7979. )
  7980. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7981. return 1;
  7982. }
  7983. static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
  7984. {
  7985. struct mob_data *md=(struct mob_data *)bl;
  7986. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  7987. status_kill(bl);
  7988. return 0;
  7989. }
  7990. int buildin_maprespawnguildid(struct script_state *st)
  7991. {
  7992. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7993. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7994. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7995. int m=map_mapname2mapid(mapname);
  7996. if(m == -1)
  7997. return 0;
  7998. //Catch ALL players (in case some are 'between maps' on execution time)
  7999. map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag);
  8000. if (flag&4) //Remove script mobs.
  8001. map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB);
  8002. return 0;
  8003. }
  8004. int buildin_agitstart(struct script_state *st)
  8005. {
  8006. if(agit_flag==1) return 0; // Agit already Start.
  8007. agit_flag=1;
  8008. guild_agit_start();
  8009. return 0;
  8010. }
  8011. int buildin_agitend(struct script_state *st)
  8012. {
  8013. if(agit_flag==0) return 0; // Agit already End.
  8014. agit_flag=0;
  8015. guild_agit_end();
  8016. return 0;
  8017. }
  8018. /*==========================================
  8019. * agitcheck 1; // choice script
  8020. * if(@agit_flag == 1) goto agit;
  8021. * if(agitcheck(0) == 1) goto agit;
  8022. *------------------------------------------
  8023. */
  8024. int buildin_agitcheck(struct script_state *st)
  8025. {
  8026. struct map_session_data *sd;
  8027. int cond;
  8028. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8029. if(cond == 0) {
  8030. if (agit_flag==1) push_val(st->stack,C_INT,1);
  8031. if (agit_flag==0) push_val(st->stack,C_INT,0);
  8032. } else {
  8033. sd=script_rid2sd(st);
  8034. if (agit_flag==1) pc_setreg(sd,add_str("@agit_flag"),1);
  8035. if (agit_flag==0) pc_setreg(sd,add_str("@agit_flag"),0);
  8036. }
  8037. return 0;
  8038. }
  8039. int buildin_flagemblem(struct script_state *st)
  8040. {
  8041. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8042. if(g_id < 0) return 0;
  8043. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  8044. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  8045. return 0;
  8046. }
  8047. int buildin_getcastlename(struct script_state *st)
  8048. {
  8049. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8050. struct guild_castle *gc=NULL;
  8051. int i;
  8052. for(i=0;i<MAX_GUILDCASTLE;i++){
  8053. if( (gc=guild_castle_search(i)) != NULL ){
  8054. if(strcmp(mapname,gc->map_name)==0){
  8055. break;
  8056. }
  8057. }
  8058. }
  8059. if(gc)
  8060. push_str(st->stack,C_CONSTSTR,gc->castle_name);
  8061. else
  8062. push_str(st->stack,C_CONSTSTR,"");
  8063. return 0;
  8064. }
  8065. int buildin_getcastledata(struct script_state *st)
  8066. {
  8067. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8068. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8069. char *event=NULL;
  8070. struct guild_castle *gc;
  8071. int i,j;
  8072. if( st->end>st->start+4 && index==0){
  8073. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  8074. if( (gc=guild_castle_search(i)) != NULL &&
  8075. strcmp(mapname,gc->map_name)==0 )
  8076. j=i;
  8077. if(j>=0){
  8078. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  8079. check_event(st, event);
  8080. guild_addcastleinfoevent(j,17,event);
  8081. }
  8082. }
  8083. for(i=0;i<MAX_GUILDCASTLE;i++){
  8084. if( (gc=guild_castle_search(i)) != NULL ){
  8085. if(strcmp(mapname,gc->map_name)==0){
  8086. switch(index){
  8087. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  8088. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  8089. case 2: push_val(st->stack,C_INT,gc->economy); break;
  8090. case 3: push_val(st->stack,C_INT,gc->defense); break;
  8091. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  8092. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  8093. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  8094. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  8095. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  8096. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  8097. case 10:
  8098. case 11:
  8099. case 12:
  8100. case 13:
  8101. case 14:
  8102. case 15:
  8103. case 16:
  8104. case 17:
  8105. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  8106. case 18:
  8107. case 19:
  8108. case 20:
  8109. case 21:
  8110. case 22:
  8111. case 23:
  8112. case 24:
  8113. case 25:
  8114. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  8115. default:
  8116. push_val(st->stack,C_INT,0); break;
  8117. }
  8118. return 0;
  8119. }
  8120. }
  8121. }
  8122. push_val(st->stack,C_INT,0);
  8123. return 0;
  8124. }
  8125. int buildin_setcastledata(struct script_state *st)
  8126. {
  8127. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8128. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8129. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8130. struct guild_castle *gc;
  8131. int i;
  8132. for(i=0;i<MAX_GUILDCASTLE;i++){
  8133. if( (gc=guild_castle_search(i)) != NULL ){
  8134. if(strcmp(mapname,gc->map_name)==0){
  8135. // Save Data byself First
  8136. switch(index){
  8137. case 1: gc->guild_id = value; break;
  8138. case 2: gc->economy = value; break;
  8139. case 3: gc->defense = value; break;
  8140. case 4: gc->triggerE = value; break;
  8141. case 5: gc->triggerD = value; break;
  8142. case 6: gc->nextTime = value; break;
  8143. case 7: gc->payTime = value; break;
  8144. case 8: gc->createTime = value; break;
  8145. case 9: gc->visibleC = value; break;
  8146. case 10:
  8147. case 11:
  8148. case 12:
  8149. case 13:
  8150. case 14:
  8151. case 15:
  8152. case 16:
  8153. case 17:
  8154. gc->guardian[index-10].visible = value; break;
  8155. case 18:
  8156. case 19:
  8157. case 20:
  8158. case 21:
  8159. case 22:
  8160. case 23:
  8161. case 24:
  8162. case 25:
  8163. gc->guardian[index-18].hp = value;
  8164. if (gc->guardian[index-18].id)
  8165. { //Update this mob's HP.
  8166. struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
  8167. if (!bl)
  8168. { //Wrong target?
  8169. gc->guardian[index-18].id = 0;
  8170. break;
  8171. }
  8172. if (value < 1) {
  8173. status_kill(bl);
  8174. break;
  8175. }
  8176. status_set_hp(bl, value, 0);
  8177. }
  8178. break;
  8179. default: return 0;
  8180. }
  8181. guild_castledatasave(gc->castle_id,index,value);
  8182. return 0;
  8183. }
  8184. }
  8185. }
  8186. return 0;
  8187. }
  8188. /* =====================================================================
  8189. * ギルド情報を要求する
  8190. * ---------------------------------------------------------------------
  8191. */
  8192. int buildin_requestguildinfo(struct script_state *st)
  8193. {
  8194. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8195. char *event=NULL;
  8196. if( st->end>st->start+3 ){
  8197. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8198. check_event(st, event);
  8199. }
  8200. if(guild_id>0)
  8201. guild_npc_request_info(guild_id,event);
  8202. return 0;
  8203. }
  8204. /* =====================================================================
  8205. * カードの数を得る
  8206. * ---------------------------------------------------------------------
  8207. */
  8208. int buildin_getequipcardcnt(struct script_state *st)
  8209. {
  8210. int i,num;
  8211. struct map_session_data *sd;
  8212. int c=MAX_SLOTS;
  8213. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8214. sd=script_rid2sd(st);
  8215. i=pc_checkequip(sd,equip[num-1]);
  8216. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8217. {
  8218. push_val(st->stack,C_INT,0);
  8219. return 0;
  8220. }
  8221. do{
  8222. if(sd->status.inventory[i].card[c-1] &&
  8223. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8224. push_val(st->stack,C_INT,(c));
  8225. return 0;
  8226. }
  8227. }while(c--);
  8228. push_val(st->stack,C_INT,0);
  8229. return 0;
  8230. }
  8231. /* ================================================================
  8232. * カード取り外し成功
  8233. * ----------------------------------------------------------------
  8234. */
  8235. int buildin_successremovecards(struct script_state *st)
  8236. {
  8237. int i,j,num,cardflag=0,flag;
  8238. struct map_session_data *sd;
  8239. struct item item_tmp;
  8240. int c=MAX_SLOTS;
  8241. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8242. sd=script_rid2sd(st);
  8243. i=pc_checkequip(sd,equip[num-1]);
  8244. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8245. return 0;
  8246. do{
  8247. if(sd->status.inventory[i].card[c-1] &&
  8248. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8249. cardflag = 1;
  8250. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8251. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8252. item_tmp.attribute=0;
  8253. for (j = 0; j < MAX_SLOTS; j++)
  8254. item_tmp.card[j]=0;
  8255. //Logs items, got from (N)PC scripts [Lupus]
  8256. if(log_config.enable_logs&0x40)
  8257. log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
  8258. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  8259. clif_additem(sd,0,0,flag);
  8260. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8261. }
  8262. }
  8263. }while(c--);
  8264. if(cardflag == 1){ // カードを取り除いたアイテム所得
  8265. flag=0;
  8266. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8267. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8268. item_tmp.attribute=sd->status.inventory[i].attribute;
  8269. //Logs items, got from (N)PC scripts [Lupus]
  8270. if(log_config.enable_logs&0x40)
  8271. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8272. for (j = 0; j < MAX_SLOTS; j++)
  8273. item_tmp.card[j]=0;
  8274. pc_delitem(sd,i,1,0);
  8275. //Logs items, got from (N)PC scripts [Lupus]
  8276. if(log_config.enable_logs&0x40)
  8277. log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
  8278. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  8279. clif_additem(sd,0,0,flag);
  8280. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8281. }
  8282. clif_misceffect(&sd->bl,3);
  8283. return 0;
  8284. }
  8285. return 0;
  8286. }
  8287. /* ================================================================
  8288. * カード取り外し失敗 slot,type
  8289. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  8290. * ----------------------------------------------------------------
  8291. */
  8292. int buildin_failedremovecards(struct script_state *st)
  8293. {
  8294. int i,j,num,cardflag=0,flag,typefail;
  8295. struct map_session_data *sd;
  8296. struct item item_tmp;
  8297. int c=MAX_SLOTS;
  8298. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8299. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8300. sd=script_rid2sd(st);
  8301. i=pc_checkequip(sd,equip[num-1]);
  8302. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8303. return 0;
  8304. do{
  8305. if(sd->status.inventory[i].card[c-1] &&
  8306. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8307. cardflag = 1;
  8308. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  8309. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8310. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8311. item_tmp.attribute=0;
  8312. for (j = 0; j < MAX_SLOTS; j++)
  8313. item_tmp.card[j]=0;
  8314. //Logs items, got from (N)PC scripts [Lupus]
  8315. if(log_config.enable_logs&0x40)
  8316. log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
  8317. if((flag=pc_additem(sd,&item_tmp,1))){
  8318. clif_additem(sd,0,0,flag);
  8319. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8320. }
  8321. }
  8322. }
  8323. }while(c--);
  8324. if(cardflag == 1){
  8325. if(typefail == 0 || typefail == 2){ // 武具損失
  8326. //Logs items, got from (N)PC scripts [Lupus]
  8327. if(log_config.enable_logs&0x40)
  8328. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8329. pc_delitem(sd,i,1,0);
  8330. clif_misceffect(&sd->bl,2);
  8331. return 0;
  8332. }
  8333. if(typefail == 1){ // カードのみ損失(武具を返す)
  8334. flag=0;
  8335. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8336. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8337. item_tmp.attribute=sd->status.inventory[i].attribute;
  8338. //Logs items, got from (N)PC scripts [Lupus]
  8339. if(log_config.enable_logs&0x40)
  8340. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8341. for (j = 0; j < MAX_SLOTS; j++)
  8342. item_tmp.card[j]=0;
  8343. pc_delitem(sd,i,1,0);
  8344. //Logs items, got from (N)PC scripts [Lupus]
  8345. if(log_config.enable_logs&0x40)
  8346. log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
  8347. if((flag=pc_additem(sd,&item_tmp,1))){
  8348. clif_additem(sd,0,0,flag);
  8349. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8350. }
  8351. }
  8352. clif_misceffect(&sd->bl,2);
  8353. return 0;
  8354. }
  8355. return 0;
  8356. }
  8357. /* ================================================================
  8358. * mapwarp "<from map>","<to map>",<x>,<y>,<type>,<ID for Type>;
  8359. * type: 0=everyone, 1=guild, 2=party; [Reddozen]
  8360. * improved by [Lance]
  8361. * ================================================================
  8362. */
  8363. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  8364. {
  8365. int x,y,m,check_val=0,check_ID=0,i=0;
  8366. struct guild *g = NULL;
  8367. struct party_data *p = NULL;
  8368. char *str;
  8369. char *mapname;
  8370. unsigned int index;
  8371. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8372. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8373. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8374. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8375. if(st->end > st->start+7){
  8376. check_val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8377. check_ID=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8378. }
  8379. if( (m=map_mapname2mapid(mapname))< 0)
  8380. return 0;
  8381. if(!(index=mapindex_name2id(str)))
  8382. return 0;
  8383. switch(check_val){
  8384. case 1:
  8385. g = guild_search(check_ID);
  8386. if (g){
  8387. for( i=0; i < g->max_member; i++)
  8388. {
  8389. if(g->member[i].sd && g->member[i].sd->bl.m==m){
  8390. pc_setpos(g->member[i].sd,index,x,y,3);
  8391. }
  8392. }
  8393. }
  8394. break;
  8395. case 2:
  8396. p = party_search(check_ID);
  8397. if(p){
  8398. for(i=0;i<MAX_PARTY; i++){
  8399. if(p->data[i].sd && p->data[i].sd->bl.m == m){
  8400. pc_setpos(p->data[i].sd,index,x,y,3);
  8401. }
  8402. }
  8403. }
  8404. break;
  8405. default:
  8406. map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y);
  8407. break;
  8408. }
  8409. return 0;
  8410. }
  8411. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  8412. {
  8413. char *npc,*command;
  8414. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8415. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8416. npc_command(map_id2sd(st->rid),npc,command);
  8417. return 0;
  8418. }
  8419. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  8420. {
  8421. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8422. // nd->lastaction=nd->timer=gettick();
  8423. npc_do_ontimer(st->oid, 1);
  8424. return 0;
  8425. }
  8426. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  8427. {
  8428. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8429. // nd->lastaction=nd->timer=-1;
  8430. npc_do_ontimer(st->oid, 0);
  8431. return 0;
  8432. }
  8433. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  8434. {
  8435. char *event=va_arg(ap,char *);
  8436. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  8437. return 1;
  8438. return 0;
  8439. }
  8440. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  8441. {
  8442. char *mapname,*event;
  8443. int m;
  8444. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8445. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8446. check_event(st, event);
  8447. if( (m=map_mapname2mapid(mapname))<0 ) {
  8448. push_val(st->stack,C_INT,-1);
  8449. return 0;
  8450. }
  8451. push_val(st->stack,C_INT,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event));
  8452. return 0;
  8453. }
  8454. int buildin_marriage(struct script_state *st)
  8455. {
  8456. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8457. struct map_session_data *sd=script_rid2sd(st);
  8458. struct map_session_data *p_sd=map_nick2sd(partner);
  8459. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  8460. push_val(st->stack,C_INT,0);
  8461. return 0;
  8462. }
  8463. push_val(st->stack,C_INT,1);
  8464. return 0;
  8465. }
  8466. int buildin_wedding_effect(struct script_state *st)
  8467. {
  8468. struct map_session_data *sd=script_rid2sd(st);
  8469. struct block_list *bl;
  8470. if(sd==NULL) {
  8471. bl=map_id2bl(st->oid);
  8472. } else
  8473. bl=&sd->bl;
  8474. clif_wedding_effect(bl);
  8475. return 0;
  8476. }
  8477. int buildin_divorce(struct script_state *st)
  8478. {
  8479. struct map_session_data *sd=script_rid2sd(st);
  8480. if(sd==NULL || pc_divorce(sd) < 0){
  8481. push_val(st->stack,C_INT,0);
  8482. return 0;
  8483. }
  8484. push_val(st->stack,C_INT,1);
  8485. return 0;
  8486. }
  8487. int buildin_ispartneron(struct script_state *st)
  8488. {
  8489. struct map_session_data *sd=script_rid2sd(st);
  8490. struct map_session_data *p_sd=NULL;
  8491. if(sd==NULL || !pc_ismarried(sd) ||
  8492. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8493. push_val(st->stack,C_INT,0);
  8494. return 0;
  8495. }
  8496. push_val(st->stack,C_INT,1);
  8497. return 0;
  8498. }
  8499. int buildin_getpartnerid(struct script_state *st)
  8500. {
  8501. struct map_session_data *sd=script_rid2sd(st);
  8502. if (sd == NULL) {
  8503. push_val(st->stack,C_INT,0);
  8504. return 0;
  8505. }
  8506. push_val(st->stack,C_INT,sd->status.partner_id);
  8507. return 0;
  8508. }
  8509. int buildin_getchildid(struct script_state *st)
  8510. {
  8511. struct map_session_data *sd=script_rid2sd(st);
  8512. if (sd == NULL) {
  8513. push_val(st->stack,C_INT,0);
  8514. return 0;
  8515. }
  8516. push_val(st->stack,C_INT,sd->status.child);
  8517. return 0;
  8518. }
  8519. int buildin_getmotherid(struct script_state *st)
  8520. {
  8521. struct map_session_data *sd=script_rid2sd(st);
  8522. if (sd == NULL) {
  8523. push_val(st->stack,C_INT,0);
  8524. return 0;
  8525. }
  8526. push_val(st->stack,C_INT,sd->status.mother);
  8527. return 0;
  8528. }
  8529. int buildin_getfatherid(struct script_state *st)
  8530. {
  8531. struct map_session_data *sd=script_rid2sd(st);
  8532. if (sd == NULL) {
  8533. push_val(st->stack,C_INT,0);
  8534. return 0;
  8535. }
  8536. push_val(st->stack,C_INT,sd->status.father);
  8537. return 0;
  8538. }
  8539. int buildin_warppartner(struct script_state *st)
  8540. {
  8541. int x,y;
  8542. unsigned short mapindex;
  8543. char *str;
  8544. struct map_session_data *sd=script_rid2sd(st);
  8545. struct map_session_data *p_sd=NULL;
  8546. if(sd==NULL || !pc_ismarried(sd) ||
  8547. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8548. push_val(st->stack,C_INT,0);
  8549. return 0;
  8550. }
  8551. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8552. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8553. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8554. mapindex = mapindex_name2id(str);
  8555. if (mapindex) {
  8556. pc_setpos(p_sd,mapindex,x,y,0);
  8557. push_val(st->stack,C_INT,1);
  8558. } else
  8559. push_val(st->stack,C_INT,0);
  8560. return 0;
  8561. }
  8562. /*================================================
  8563. * Script for Displaying MOB Information [Valaris]
  8564. *------------------------------------------------
  8565. */
  8566. int buildin_strmobinfo(struct script_state *st)
  8567. {
  8568. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8569. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8570. if((class_>=0 && class_<=1000) || class_ >2000)
  8571. return 0;
  8572. switch (num) {
  8573. case 1:
  8574. push_str(st->stack,C_CONSTSTR,mob_db(class_)->name);
  8575. break;
  8576. case 2:
  8577. push_str(st->stack,C_CONSTSTR,mob_db(class_)->jname);
  8578. break;
  8579. case 3:
  8580. push_val(st->stack,C_INT,mob_db(class_)->lv);
  8581. break;
  8582. case 4:
  8583. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  8584. break;
  8585. case 5:
  8586. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  8587. break;
  8588. case 6:
  8589. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  8590. break;
  8591. case 7:
  8592. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  8593. break;
  8594. default:
  8595. push_val(st->stack,C_INT,0);
  8596. break;
  8597. }
  8598. return 0;
  8599. }
  8600. /*==========================================
  8601. * Summon guardians [Valaris]
  8602. *------------------------------------------
  8603. */
  8604. int buildin_guardian(struct script_state *st)
  8605. {
  8606. int class_=0,amount=1,x=0,y=0,guardian=0;
  8607. char *str,*map,*event="";
  8608. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8609. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  8610. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  8611. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  8612. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8613. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8614. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  8615. if( st->end>st->start+9 )
  8616. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  8617. check_event(st, event);
  8618. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  8619. return 0;
  8620. }
  8621. /*================================================
  8622. * Script for Displaying Guardian Info [Valaris]
  8623. *------------------------------------------------
  8624. */
  8625. int buildin_guardianinfo(struct script_state *st)
  8626. {
  8627. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8628. struct map_session_data *sd=script_rid2sd(st);
  8629. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  8630. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  8631. {
  8632. push_val(st->stack,C_INT,-1);
  8633. return 0;
  8634. }
  8635. if(gc->guardian[guardian].visible)
  8636. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  8637. else push_val(st->stack,C_INT,-1);
  8638. return 0;
  8639. }
  8640. /*==========================================
  8641. * IDからItem名
  8642. *------------------------------------------
  8643. */
  8644. int buildin_getitemname(struct script_state *st)
  8645. {
  8646. int item_id=0;
  8647. struct item_data *i_data;
  8648. char *item_name;
  8649. struct script_data *data;
  8650. data=&(st->stack->stack_data[st->start+2]);
  8651. get_val(st,data);
  8652. if( data->type==C_STR || data->type==C_CONSTSTR ){
  8653. const char *name=conv_str(st,data);
  8654. struct item_data *item_data = itemdb_searchname(name);
  8655. if( item_data )
  8656. item_id=item_data->nameid;
  8657. }else
  8658. item_id=conv_num(st,data);
  8659. i_data = itemdb_exists(item_id);
  8660. if (i_data == NULL)
  8661. {
  8662. push_str(st->stack,C_CONSTSTR,"null");
  8663. return 0;
  8664. }
  8665. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  8666. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  8667. push_str(st->stack,C_STR,item_name);
  8668. return 0;
  8669. }
  8670. /*==========================================
  8671. * Returns number of slots an item has. [Skotlex]
  8672. *------------------------------------------
  8673. */
  8674. int buildin_getitemslots(struct script_state *st)
  8675. {
  8676. int item_id;
  8677. struct item_data *i_data;
  8678. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8679. i_data = itemdb_exists(item_id);
  8680. if (i_data)
  8681. push_val(st->stack,C_INT,i_data->slot);
  8682. else
  8683. push_val(st->stack,C_INT,-1);
  8684. return 0;
  8685. }
  8686. /*==========================================
  8687. * Returns some values of an item [Lupus]
  8688. * Price, Weight, etc...
  8689. getiteminfo(itemID,n), where n
  8690. 0 value_buy;
  8691. 1 value_sell;
  8692. 2 type;
  8693. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  8694. if = 0, then monsters don't drop it at all (rare or a quest item)
  8695. if = 10000, then this item is sold in NPC shops only
  8696. 4 sex;
  8697. 5 equip;
  8698. 6 weight;
  8699. 7 atk;
  8700. 8 def;
  8701. 9 range;
  8702. 10 slot;
  8703. 11 look;
  8704. 12 elv;
  8705. 13 wlv;
  8706. *------------------------------------------
  8707. */
  8708. int buildin_getiteminfo(struct script_state *st)
  8709. {
  8710. int item_id,n;
  8711. int *item_arr;
  8712. struct item_data *i_data;
  8713. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8714. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8715. i_data = itemdb_exists(item_id);
  8716. if (i_data && n>=0 && n<14) {
  8717. item_arr = (int*)&i_data->value_buy;
  8718. push_val(st->stack,C_INT,item_arr[n]);
  8719. } else
  8720. push_val(st->stack,C_INT,-1);
  8721. return 0;
  8722. }
  8723. /*==========================================
  8724. * Returns value from equipped item slot n [Lupus]
  8725. getequipcardid(num,slot)
  8726. where
  8727. num = eqip position slot
  8728. slot = 0,1,2,3 (Card Slot N)
  8729. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  8730. it's useful when you want to check item cards or if it's signed
  8731. Useful for such quests as "Sign this refined item with players name" etc
  8732. Hat[0] +4 -> Player's Hat[0] +4
  8733. *------------------------------------------
  8734. */
  8735. int buildin_getequipcardid(struct script_state *st)
  8736. {
  8737. int i,num,slot;
  8738. struct map_session_data *sd;
  8739. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8740. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8741. sd=script_rid2sd(st);
  8742. i=pc_checkequip(sd,equip[num-1]);
  8743. if(i >= 0 && slot>=0 && slot<4)
  8744. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  8745. else
  8746. push_val(st->stack,C_INT,0);
  8747. return 0;
  8748. }
  8749. /*==========================================
  8750. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  8751. *------------------------------------------
  8752. */
  8753. int buildin_petskillbonus(struct script_state *st)
  8754. {
  8755. struct pet_data *pd;
  8756. struct map_session_data *sd=script_rid2sd(st);
  8757. if(sd==NULL || sd->pd==NULL)
  8758. return 0;
  8759. pd=sd->pd;
  8760. if (pd->bonus)
  8761. { //Clear previous bonus
  8762. if (pd->bonus->timer != -1)
  8763. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  8764. } else //init
  8765. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  8766. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8767. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8768. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8769. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8770. if (pd->state.skillbonus == 1)
  8771. pd->state.skillbonus=0; // waiting state
  8772. // wait for timer to start
  8773. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  8774. pd->bonus->timer=-1;
  8775. else
  8776. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  8777. return 0;
  8778. }
  8779. /*==========================================
  8780. * pet looting [Valaris] //Rewritten by [Skotlex]
  8781. *------------------------------------------
  8782. */
  8783. int buildin_petloot(struct script_state *st)
  8784. {
  8785. int max;
  8786. struct pet_data *pd;
  8787. struct map_session_data *sd=script_rid2sd(st);
  8788. if(sd==NULL || sd->pd==NULL)
  8789. return 0;
  8790. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8791. if(max < 1)
  8792. max = 1; //Let'em loot at least 1 item.
  8793. else if (max > MAX_PETLOOT_SIZE)
  8794. max = MAX_PETLOOT_SIZE;
  8795. pd = sd->pd;
  8796. if (pd->loot != NULL)
  8797. { //Release whatever was there already and reallocate memory
  8798. pet_lootitem_drop(pd, pd->msd);
  8799. aFree(pd->loot->item);
  8800. }
  8801. else
  8802. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  8803. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  8804. pd->loot->max=max;
  8805. pd->loot->count = 0;
  8806. pd->loot->weight = 0;
  8807. return 0;
  8808. }
  8809. /*==========================================
  8810. * PCの所持品情報読み取り
  8811. *------------------------------------------
  8812. */
  8813. int buildin_getinventorylist(struct script_state *st)
  8814. {
  8815. struct map_session_data *sd=script_rid2sd(st);
  8816. unsigned char card_var[NAME_LENGTH];
  8817. int i,j=0,k;
  8818. if(!sd) return 0;
  8819. for(i=0;i<MAX_INVENTORY;i++){
  8820. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  8821. pc_setreg(sd,add_str("@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  8822. pc_setreg(sd,add_str("@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  8823. pc_setreg(sd,add_str("@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  8824. pc_setreg(sd,add_str("@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  8825. pc_setreg(sd,add_str("@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  8826. pc_setreg(sd,add_str("@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  8827. for (k = 0; k < MAX_SLOTS; k++)
  8828. {
  8829. sprintf(card_var, "@inventorylist_card%d",k+1);
  8830. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  8831. }
  8832. j++;
  8833. }
  8834. }
  8835. pc_setreg(sd,add_str("@inventorylist_count"),j);
  8836. return 0;
  8837. }
  8838. int buildin_getskilllist(struct script_state *st)
  8839. {
  8840. struct map_session_data *sd=script_rid2sd(st);
  8841. int i,j=0;
  8842. if(!sd) return 0;
  8843. for(i=0;i<MAX_SKILL;i++){
  8844. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  8845. pc_setreg(sd,add_str("@skilllist_id")+(j<<24),sd->status.skill[i].id);
  8846. pc_setreg(sd,add_str("@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  8847. pc_setreg(sd,add_str("@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  8848. j++;
  8849. }
  8850. }
  8851. pc_setreg(sd,add_str("@skilllist_count"),j);
  8852. return 0;
  8853. }
  8854. int buildin_clearitem(struct script_state *st)
  8855. {
  8856. struct map_session_data *sd=script_rid2sd(st);
  8857. int i;
  8858. if(sd==NULL) return 0;
  8859. for (i=0; i<MAX_INVENTORY; i++) {
  8860. if (sd->status.inventory[i].amount) {
  8861. //Logs items, got from (N)PC scripts [Lupus]
  8862. if(log_config.enable_logs&0x40)
  8863. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  8864. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  8865. }
  8866. }
  8867. return 0;
  8868. }
  8869. /*==========================================
  8870. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  8871. *------------------------------------------
  8872. */
  8873. int buildin_disguise(struct script_state *st)
  8874. {
  8875. struct map_session_data *sd=script_rid2sd(st);
  8876. int id;
  8877. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8878. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  8879. push_val(st->stack,C_INT,0);
  8880. return 0;
  8881. }
  8882. pc_disguise(sd, id);
  8883. push_val(st->stack,C_INT,id);
  8884. return 0;
  8885. }
  8886. /*==========================================
  8887. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  8888. *------------------------------------------
  8889. */
  8890. int buildin_undisguise(struct script_state *st)
  8891. {
  8892. struct map_session_data *sd=script_rid2sd(st);
  8893. if (sd->disguise) {
  8894. pc_disguise(sd, 0);
  8895. push_val(st->stack,C_INT,0);
  8896. } else {
  8897. push_val(st->stack,C_INT,1);
  8898. }
  8899. return 0;
  8900. }
  8901. /*==========================================
  8902. * NPCクラスチェンジ
  8903. * classは変わりたいclass
  8904. * typeは通常0なのかな?
  8905. *------------------------------------------
  8906. */
  8907. int buildin_classchange(struct script_state *st)
  8908. {
  8909. int _class,type;
  8910. struct block_list *bl=map_id2bl(st->oid);
  8911. if(bl==NULL) return 0;
  8912. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8913. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8914. clif_class_change(bl,_class,type);
  8915. return 0;
  8916. }
  8917. /*==========================================
  8918. * NPCから発生するエフェクト
  8919. *------------------------------------------
  8920. */
  8921. int buildin_misceffect(struct script_state *st)
  8922. {
  8923. int type;
  8924. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8925. if(st->oid && st->oid != fake_nd->bl.id) {
  8926. struct block_list *bl = map_id2bl(st->oid);
  8927. if (bl)
  8928. clif_misceffect2(bl,type);
  8929. } else{
  8930. struct map_session_data *sd=script_rid2sd(st);
  8931. if(sd)
  8932. clif_misceffect2(&sd->bl,type);
  8933. }
  8934. return 0;
  8935. }
  8936. /*==========================================
  8937. * サウンドエフェクト
  8938. *------------------------------------------
  8939. */
  8940. int buildin_soundeffect(struct script_state *st)
  8941. {
  8942. // Redundn
  8943. struct map_session_data *sd=script_rid2sd(st);
  8944. char *name;
  8945. int type=0;
  8946. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8947. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8948. if(sd){
  8949. if(!st->rid)
  8950. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  8951. else{
  8952. clif_soundeffect(sd,&sd->bl,name,type);
  8953. }
  8954. }
  8955. return 0;
  8956. }
  8957. int soundeffect_sub(struct block_list* bl,va_list ap)
  8958. {
  8959. char *name;
  8960. int type;
  8961. nullpo_retr(0, bl);
  8962. nullpo_retr(0, ap);
  8963. name = va_arg(ap,char *);
  8964. type = va_arg(ap,int);
  8965. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  8966. return 0;
  8967. }
  8968. int buildin_soundeffectall(struct script_state *st)
  8969. {
  8970. // [Lance] - Improved.
  8971. char *name, *map = NULL;
  8972. struct block_list *bl;
  8973. int type, coverage, x0, y0, x1, y1;
  8974. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8975. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8976. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8977. if(!st->rid)
  8978. bl = map_id2bl(st->oid);
  8979. else
  8980. bl = &(script_rid2sd(st)->bl);
  8981. if(bl){
  8982. if(coverage < 23){
  8983. clif_soundeffectall(bl,name,type,coverage);
  8984. }else {
  8985. if(st->end > st->start+9){
  8986. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8987. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  8988. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  8989. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  8990. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  8991. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  8992. } else {
  8993. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  8994. }
  8995. }
  8996. }
  8997. return 0;
  8998. }
  8999. /*==========================================
  9000. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  9001. *------------------------------------------
  9002. */
  9003. int buildin_petrecovery(struct script_state *st)
  9004. {
  9005. struct pet_data *pd;
  9006. struct map_session_data *sd=script_rid2sd(st);
  9007. if(sd==NULL || sd->pd==NULL)
  9008. return 0;
  9009. pd=sd->pd;
  9010. if (pd->recovery)
  9011. { //Halt previous bonus
  9012. if (pd->recovery->timer != -1)
  9013. delete_timer(pd->recovery->timer, pet_recovery_timer);
  9014. } else //Init
  9015. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  9016. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9017. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9018. pd->recovery->timer=-1;
  9019. return 0;
  9020. }
  9021. /*==========================================
  9022. * pet healing [Valaris] //Rewritten by [Skotlex]
  9023. *------------------------------------------
  9024. */
  9025. int buildin_petheal(struct script_state *st)
  9026. {
  9027. struct pet_data *pd;
  9028. struct map_session_data *sd=script_rid2sd(st);
  9029. if(sd==NULL || sd->pd==NULL)
  9030. return 0;
  9031. pd=sd->pd;
  9032. if (pd->s_skill)
  9033. { //Clear previous skill
  9034. if (pd->s_skill->timer != -1)
  9035. {
  9036. if (pd->s_skill->id)
  9037. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  9038. else
  9039. delete_timer(pd->s_skill->timer, pet_heal_timer);
  9040. }
  9041. } else //init memory
  9042. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  9043. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  9044. //Use the lv as the amount to heal
  9045. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9046. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9047. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9048. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9049. //Use delay as initial offset to avoid skill/heal exploits
  9050. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  9051. pd->s_skill->timer=-1;
  9052. else
  9053. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  9054. return 0;
  9055. }
  9056. /*==========================================
  9057. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  9058. *------------------------------------------
  9059. */
  9060. int buildin_petskillattack(struct script_state *st)
  9061. {
  9062. struct pet_data *pd;
  9063. struct map_session_data *sd=script_rid2sd(st);
  9064. if(sd==NULL || sd->pd==NULL)
  9065. return 0;
  9066. pd=sd->pd;
  9067. if (pd->a_skill == NULL)
  9068. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  9069. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9070. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9071. pd->a_skill->div_ = 0;
  9072. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9073. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9074. return 0;
  9075. }
  9076. /*==========================================
  9077. * pet attack skills [Valaris]
  9078. *------------------------------------------
  9079. */
  9080. int buildin_petskillattack2(struct script_state *st)
  9081. {
  9082. struct pet_data *pd;
  9083. struct map_session_data *sd=script_rid2sd(st);
  9084. if(sd==NULL || sd->pd==NULL)
  9085. return 0;
  9086. pd=sd->pd;
  9087. if (pd->a_skill == NULL)
  9088. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  9089. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9090. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9091. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9092. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9093. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  9094. return 0;
  9095. }
  9096. /*==========================================
  9097. * pet support skills [Skotlex]
  9098. *------------------------------------------
  9099. */
  9100. int buildin_petskillsupport(struct script_state *st)
  9101. {
  9102. struct pet_data *pd;
  9103. struct map_session_data *sd=script_rid2sd(st);
  9104. if(sd==NULL || sd->pd==NULL)
  9105. return 0;
  9106. pd=sd->pd;
  9107. if (pd->s_skill)
  9108. { //Clear previous skill
  9109. if (pd->s_skill->timer != -1)
  9110. {
  9111. if (pd->s_skill->id)
  9112. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  9113. else
  9114. delete_timer(pd->s_skill->timer, pet_heal_timer);
  9115. }
  9116. } else //init memory
  9117. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  9118. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9119. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9120. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9121. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9122. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  9123. //Use delay as initial offset to avoid skill/heal exploits
  9124. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  9125. pd->s_skill->timer=-1;
  9126. else
  9127. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  9128. return 0;
  9129. }
  9130. /*==========================================
  9131. * Scripted skill effects [Celest]
  9132. *------------------------------------------
  9133. */
  9134. int buildin_skilleffect(struct script_state *st)
  9135. {
  9136. struct map_session_data *sd;
  9137. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9138. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9139. sd=script_rid2sd(st);
  9140. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  9141. return 0;
  9142. }
  9143. /*==========================================
  9144. * NPC skill effects [Valaris]
  9145. *------------------------------------------
  9146. */
  9147. int buildin_npcskilleffect(struct script_state *st)
  9148. {
  9149. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9150. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9151. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9152. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9153. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9154. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  9155. return 0;
  9156. }
  9157. /*==========================================
  9158. * Special effects [Valaris]
  9159. *------------------------------------------
  9160. */
  9161. int buildin_specialeffect(struct script_state *st)
  9162. {
  9163. struct block_list *bl=map_id2bl(st->oid);
  9164. if(bl==NULL)
  9165. return 0;
  9166. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  9167. return 0;
  9168. }
  9169. int buildin_specialeffect2(struct script_state *st)
  9170. {
  9171. struct map_session_data *sd=script_rid2sd(st);
  9172. if(sd==NULL)
  9173. return 0;
  9174. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  9175. return 0;
  9176. }
  9177. /*==========================================
  9178. * Nude [Valaris]
  9179. *------------------------------------------
  9180. */
  9181. int buildin_nude(struct script_state *st)
  9182. {
  9183. struct map_session_data *sd=script_rid2sd(st);
  9184. int i,calcflag=0;
  9185. if(sd==NULL)
  9186. return 0;
  9187. for(i=0;i<11;i++)
  9188. if(sd->equip_index[i] >= 0) {
  9189. if(!calcflag)
  9190. calcflag=1;
  9191. pc_unequipitem(sd,sd->equip_index[i],2);
  9192. }
  9193. if(calcflag)
  9194. status_calc_pc(sd,0);
  9195. return 0;
  9196. }
  9197. /*==========================================
  9198. * gmcommand [MouseJstr]
  9199. *
  9200. * suggested on the forums...
  9201. * splitted into atcommand & charcommand by [Skotlex]
  9202. *------------------------------------------
  9203. */
  9204. int buildin_atcommand(struct script_state *st)
  9205. {
  9206. struct map_session_data *sd=NULL;
  9207. char *cmd;
  9208. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9209. if (st->rid)
  9210. sd = script_rid2sd(st);
  9211. if (sd){
  9212. if(cmd[0] != atcommand_symbol){
  9213. cmd += strlen(sd->status.name);
  9214. while(*cmd != atcommand_symbol && *cmd != 0)
  9215. cmd++;
  9216. }
  9217. atcommand_sub(sd->fd, sd, cmd, 99);
  9218. } else { //Use a dummy character.
  9219. struct map_session_data dummy_sd;
  9220. struct block_list *bl = NULL;
  9221. malloc_set(&dummy_sd, 0, sizeof(struct map_session_data));
  9222. if (st->oid) bl = map_id2bl(st->oid);
  9223. if (bl) {
  9224. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9225. if (bl->type == BL_NPC)
  9226. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9227. }
  9228. if(cmd[0] != atcommand_symbol){
  9229. cmd += strlen(dummy_sd.status.name);
  9230. while(*cmd != atcommand_symbol && *cmd != 0)
  9231. cmd++;
  9232. }
  9233. atcommand_sub(0, &dummy_sd, cmd, 99);
  9234. }
  9235. return 0;
  9236. }
  9237. int buildin_charcommand(struct script_state *st)
  9238. {
  9239. struct map_session_data *sd=NULL;
  9240. char *cmd;
  9241. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9242. if (st->rid)
  9243. sd = script_rid2sd(st);
  9244. if (sd){
  9245. if(cmd[0] != charcommand_symbol){
  9246. cmd += strlen(sd->status.name);
  9247. while(*cmd != charcommand_symbol && *cmd != 0)
  9248. cmd++;
  9249. }
  9250. charcommand_sub(sd->fd, sd, cmd,99);
  9251. } else { //Use a dummy character.
  9252. struct map_session_data dummy_sd;
  9253. struct block_list *bl = NULL;
  9254. malloc_set(&dummy_sd, 0, sizeof(struct map_session_data));
  9255. if (st->oid) bl = map_id2bl(st->oid);
  9256. if (bl) {
  9257. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9258. if (bl->type == BL_NPC)
  9259. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9260. }
  9261. if(cmd[0] != charcommand_symbol){
  9262. cmd += strlen(dummy_sd.status.name);
  9263. while(*cmd != charcommand_symbol && *cmd != 0)
  9264. cmd++;
  9265. }
  9266. charcommand_sub(0, &dummy_sd, cmd, 99);
  9267. }
  9268. return 0;
  9269. }
  9270. /*==========================================
  9271. * Displays a message for the player only (like system messages like "you got an apple" )
  9272. *------------------------------------------
  9273. */
  9274. int buildin_dispbottom(struct script_state *st)
  9275. {
  9276. struct map_session_data *sd=script_rid2sd(st);
  9277. char *message;
  9278. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9279. if(sd)
  9280. clif_disp_onlyself(sd,message,(int)strlen(message));
  9281. return 0;
  9282. }
  9283. /*==========================================
  9284. * All The Players Full Recovery
  9285. (HP/SP full restore and resurrect if need)
  9286. *------------------------------------------
  9287. */
  9288. int buildin_recovery(struct script_state *st)
  9289. {
  9290. struct map_session_data *sd, **all_sd;
  9291. int i = 0, users;
  9292. all_sd = map_getallusers(&users);
  9293. for (i = 0; i < users; i++)
  9294. {
  9295. sd = all_sd[i];
  9296. if(pc_isdead(sd))
  9297. status_revive(&sd->bl, 100, 100);
  9298. else
  9299. status_percent_heal(&sd->bl, 100, 100);
  9300. clif_displaymessage(sd->fd,"You have been recovered!");
  9301. }
  9302. return 0;
  9303. }
  9304. /*==========================================
  9305. * Get your pet info: getpetinfo(n)
  9306. * n -> 0:pet_id 1:pet_class 2:pet_name
  9307. 3:friendly 4:hungry
  9308. *------------------------------------------
  9309. */
  9310. int buildin_getpetinfo(struct script_state *st)
  9311. {
  9312. struct map_session_data *sd=script_rid2sd(st);
  9313. struct pet_data *pd;
  9314. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9315. if(sd && sd->status.pet_id && sd->pd){
  9316. pd = sd->pd;
  9317. switch(type){
  9318. case 0:
  9319. push_val(st->stack,C_INT,sd->status.pet_id);
  9320. break;
  9321. case 1:
  9322. push_val(st->stack,C_INT,pd->pet.class_);
  9323. break;
  9324. case 2:
  9325. if(pd->pet.name)
  9326. push_str(st->stack,C_CONSTSTR,pd->pet.name);
  9327. else
  9328. push_str(st->stack,C_CONSTSTR,"null");
  9329. break;
  9330. case 3:
  9331. push_val(st->stack,C_INT,pd->pet.intimate);
  9332. break;
  9333. case 4:
  9334. push_val(st->stack,C_INT,pd->pet.hungry);
  9335. break;
  9336. default:
  9337. push_val(st->stack,C_INT,0);
  9338. break;
  9339. }
  9340. }else{
  9341. push_val(st->stack,C_INT,0);
  9342. }
  9343. return 0;
  9344. }
  9345. /*==========================================
  9346. * Shows wether your inventory(and equips) contain
  9347. selected card or not.
  9348. checkequipedcard(4001);
  9349. *------------------------------------------
  9350. */
  9351. int buildin_checkequipedcard(struct script_state *st)
  9352. {
  9353. struct map_session_data *sd=script_rid2sd(st);
  9354. int n,i,c=0;
  9355. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9356. if(sd){
  9357. for(i=0;i<MAX_INVENTORY;i++){
  9358. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  9359. for(n=0;n<MAX_SLOTS;n++){
  9360. if(sd->status.inventory[i].card[n]==c){
  9361. push_val(st->stack,C_INT,1);
  9362. return 0;
  9363. }
  9364. }
  9365. }
  9366. }
  9367. }
  9368. push_val(st->stack,C_INT,0);
  9369. return 0;
  9370. }
  9371. int buildin_jump_zero(struct script_state *st) {
  9372. int sel;
  9373. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9374. if(!sel) {
  9375. int pos;
  9376. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  9377. ShowError("script: jump_zero: not label !\n");
  9378. st->state=END;
  9379. return 0;
  9380. }
  9381. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9382. st->pos=pos;
  9383. st->state=GOTO;
  9384. // printf("script: jump_zero: jumpto : %d\n",pos);
  9385. } else {
  9386. // printf("script: jump_zero: fail\n");
  9387. }
  9388. return 0;
  9389. }
  9390. int buildin_select(struct script_state *st)
  9391. {
  9392. char *buf;
  9393. int len,i,max = 1;
  9394. struct map_session_data *sd;
  9395. sd=script_rid2sd(st);
  9396. nullpo_retr(0, sd);
  9397. if(sd->state.menu_or_input==0){
  9398. st->state=RERUNLINE;
  9399. sd->state.menu_or_input=1;
  9400. for(i=st->start+2,len=16;i<st->end;i++){
  9401. conv_str(st,& (st->stack->stack_data[i]));
  9402. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9403. }
  9404. buf=(char *)aMalloc((len+1)*sizeof(char));
  9405. buf[0]=0;
  9406. for(i=st->start+2,len=0;i<st->end;i++){
  9407. strcat(buf,st->stack->stack_data[i].u.str);
  9408. strcat(buf,":");
  9409. }
  9410. for(i=0; (unsigned int)i < strlen(buf); i++){
  9411. if(buf[i] == ':')
  9412. max++;
  9413. }
  9414. sd->max_menu = max;
  9415. clif_scriptmenu(sd,st->oid,buf);
  9416. aFree(buf);
  9417. } else if(sd->npc_menu==0xff){
  9418. sd->state.menu_or_input=0;
  9419. st->state=END;
  9420. } else {
  9421. //Skip empty menu entries which weren't displayed on the client (Skotlex)
  9422. for(i=st->start+2;i< (st->start+2+sd->npc_menu) && sd->npc_menu < (st->end-st->start-2);i++) {
  9423. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  9424. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  9425. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  9426. }
  9427. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  9428. sd->state.menu_or_input=0;
  9429. push_val(st->stack,C_INT,sd->npc_menu);
  9430. }
  9431. return 0;
  9432. }
  9433. int buildin_prompt(struct script_state *st)
  9434. {
  9435. char *buf;
  9436. int len,i,max = 1;
  9437. struct map_session_data *sd;
  9438. sd=script_rid2sd(st);
  9439. nullpo_retr(0, sd);
  9440. if(sd->state.menu_or_input==0){
  9441. st->state=RERUNLINE;
  9442. sd->state.menu_or_input=1;
  9443. for(i=st->start+2,len=16;i<st->end;i++){
  9444. conv_str(st,& (st->stack->stack_data[i]));
  9445. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9446. }
  9447. buf=(char *)aMalloc((len+1)*sizeof(char));
  9448. buf[0]=0;
  9449. for(i=st->start+2,len=0;i<st->end;i++){
  9450. strcat(buf,st->stack->stack_data[i].u.str);
  9451. strcat(buf,":");
  9452. }
  9453. for(i=0; (unsigned int)i < strlen(buf); i++){
  9454. if(buf[i] == ':')
  9455. max++;
  9456. }
  9457. sd->max_menu = max;
  9458. clif_scriptmenu(sd,st->oid,buf);
  9459. aFree(buf);
  9460. } else {
  9461. if(sd->npc_menu != 0xff){
  9462. //Skip empty menu entries which weren't displayed on the client (Skotlex)
  9463. for(i=st->start+2;i< (st->start+2+sd->npc_menu) && sd->npc_menu < (st->end-st->start-2);i++) {
  9464. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  9465. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  9466. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  9467. }
  9468. }
  9469. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  9470. sd->state.menu_or_input=0;
  9471. push_val(st->stack,C_INT,sd->npc_menu);
  9472. }
  9473. return 0;
  9474. }
  9475. /*==========================================
  9476. * GetMapMobs
  9477. returns mob counts on a set map:
  9478. e.g. GetMapMobs("prontera.gat")
  9479. use "this" - for player's map
  9480. *------------------------------------------
  9481. */
  9482. int buildin_getmapmobs(struct script_state *st)
  9483. {
  9484. char *str=NULL;
  9485. int m=-1,bx,by,i;
  9486. int count=0,c;
  9487. struct block_list *bl;
  9488. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9489. if(strcmp(str,"this")==0){
  9490. struct map_session_data *sd=script_rid2sd(st);
  9491. if(sd)
  9492. m=sd->bl.m;
  9493. else{
  9494. push_val(st->stack,C_INT,-1);
  9495. return 0;
  9496. }
  9497. }else
  9498. m=map_mapname2mapid(str);
  9499. if(m < 0){
  9500. push_val(st->stack,C_INT,-1);
  9501. return 0;
  9502. }
  9503. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  9504. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  9505. bl = map[m].block_mob[bx+by*map[m].bxs];
  9506. c = map[m].block_mob_count[bx+by*map[m].bxs];
  9507. for(i=0;i<c && bl;i++,bl=bl->next){
  9508. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  9509. count++;
  9510. }
  9511. }
  9512. }
  9513. push_val(st->stack,C_INT,count);
  9514. return 0;
  9515. }
  9516. /*==========================================
  9517. * movenpc [MouseJstr]
  9518. *------------------------------------------
  9519. */
  9520. int buildin_movenpc(struct script_state *st)
  9521. {
  9522. TBL_NPC *nd = NULL;
  9523. char *npc;
  9524. int x,y;
  9525. short m;
  9526. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9527. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  9528. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9529. if ((nd = npc_name2id(npc)) == NULL)
  9530. return -1;
  9531. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  9532. return -1; //Not on a map.
  9533. if (x < 0) x = 0;
  9534. else if (x >= map[m].xs) x = map[m].xs-1;
  9535. if (y < 0) y = 0;
  9536. else if (y >= map[m].ys) y = map[m].ys-1;
  9537. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9538. map_moveblock(&nd->bl, x, y, gettick());
  9539. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9540. return 0;
  9541. }
  9542. /*==========================================
  9543. * message [MouseJstr]
  9544. *------------------------------------------
  9545. */
  9546. int buildin_message(struct script_state *st)
  9547. {
  9548. struct map_session_data *sd;
  9549. char *msg,*player;
  9550. struct map_session_data *pl_sd = NULL;
  9551. sd = script_rid2sd(st);
  9552. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9553. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9554. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  9555. return 0;
  9556. clif_displaymessage(pl_sd->fd, msg);
  9557. return 0;
  9558. }
  9559. /*==========================================
  9560. * npctalk (sends message to surrounding
  9561. * area) [Valaris]
  9562. *------------------------------------------
  9563. */
  9564. int buildin_npctalk(struct script_state *st)
  9565. {
  9566. char *str;
  9567. char message[255];
  9568. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9569. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9570. if(nd) {
  9571. memcpy(message, nd->name, NAME_LENGTH);
  9572. strcat(message," : ");
  9573. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9574. clif_message(&(nd->bl), message);
  9575. }
  9576. return 0;
  9577. }
  9578. /*==========================================
  9579. * hasitems (checks to see if player has any
  9580. * items on them, if so will return a 1)
  9581. * [Valaris]
  9582. *------------------------------------------
  9583. */
  9584. int buildin_hasitems(struct script_state *st)
  9585. {
  9586. int i;
  9587. struct map_session_data *sd;
  9588. sd=script_rid2sd(st);
  9589. for(i=0; i<MAX_INVENTORY; i++) {
  9590. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  9591. push_val(st->stack,C_INT,1);
  9592. return 0;
  9593. }
  9594. }
  9595. push_val(st->stack,C_INT,0);
  9596. return 0;
  9597. }
  9598. // change npc walkspeed [Valaris]
  9599. int buildin_npcspeed(struct script_state *st)
  9600. {
  9601. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9602. int x=0;
  9603. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9604. if(nd) {
  9605. nd->speed=x;
  9606. }
  9607. return 0;
  9608. }
  9609. // make an npc walk to a position [Valaris]
  9610. int buildin_npcwalkto(struct script_state *st)
  9611. {
  9612. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9613. int x=0,y=0;
  9614. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9615. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9616. if(nd) {
  9617. unit_walktoxy(&nd->bl,x,y,0);
  9618. }
  9619. return 0;
  9620. }
  9621. // stop an npc's movement [Valaris]
  9622. int buildin_npcstop(struct script_state *st)
  9623. {
  9624. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9625. if(nd) {
  9626. unit_stop_walking(&nd->bl,1);
  9627. }
  9628. return 0;
  9629. }
  9630. /*==========================================
  9631. * getlook char info. getlook(arg)
  9632. *------------------------------------------
  9633. */
  9634. int buildin_getlook(struct script_state *st){
  9635. int type,val;
  9636. struct map_session_data *sd;
  9637. sd=script_rid2sd(st);
  9638. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9639. val=-1;
  9640. switch(type){
  9641. case LOOK_HAIR: //1
  9642. val=sd->status.hair;
  9643. break;
  9644. case LOOK_WEAPON: //2
  9645. val=sd->status.weapon;
  9646. break;
  9647. case LOOK_HEAD_BOTTOM: //3
  9648. val=sd->status.head_bottom;
  9649. break;
  9650. case LOOK_HEAD_TOP: //4
  9651. val=sd->status.head_top;
  9652. break;
  9653. case LOOK_HEAD_MID: //5
  9654. val=sd->status.head_mid;
  9655. break;
  9656. case LOOK_HAIR_COLOR: //6
  9657. val=sd->status.hair_color;
  9658. break;
  9659. case LOOK_CLOTHES_COLOR: //7
  9660. val=sd->status.clothes_color;
  9661. break;
  9662. case LOOK_SHIELD: //8
  9663. val=sd->status.shield;
  9664. break;
  9665. case LOOK_SHOES: //9
  9666. break;
  9667. }
  9668. push_val(st->stack,C_INT,val);
  9669. return 0;
  9670. }
  9671. /*==========================================
  9672. * get char save point. argument: 0- map name, 1- x, 2- y
  9673. *------------------------------------------
  9674. */
  9675. int buildin_getsavepoint(struct script_state *st)
  9676. {
  9677. int x,y,type;
  9678. char *mapname;
  9679. struct map_session_data *sd;
  9680. sd=script_rid2sd(st);
  9681. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9682. x=sd->status.save_point.x;
  9683. y=sd->status.save_point.y;
  9684. switch(type){
  9685. case 0:
  9686. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  9687. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  9688. mapname[MAP_NAME_LENGTH]='\0';
  9689. push_str(st->stack,C_STR,mapname);
  9690. break;
  9691. case 1:
  9692. push_val(st->stack,C_INT,x);
  9693. break;
  9694. case 2:
  9695. push_val(st->stack,C_INT,y);
  9696. break;
  9697. default:
  9698. push_val(st->stack,C_INT,0);
  9699. break;
  9700. }
  9701. return 0;
  9702. }
  9703. /*==========================================
  9704. * Get position for char/npc/pet/mob objects. Added by Lorky
  9705. *
  9706. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  9707. * where type:
  9708. * MapName$ - String variable for output map name
  9709. * MapX - Integer variable for output coord X
  9710. * MapY - Integer variable for output coord Y
  9711. * type - type of object
  9712. * 0 - Character coord
  9713. * 1 - NPC coord
  9714. * 2 - Pet coord
  9715. * 3 - Mob coord (not released)
  9716. * 4 - Homun coord
  9717. * CharName$ - Name object. If miss or "this" the current object
  9718. *
  9719. * Return:
  9720. * 0 - success
  9721. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  9722. *------------------------------------------
  9723. */
  9724. int buildin_getmapxy(struct script_state *st){
  9725. struct block_list *bl = NULL;
  9726. struct map_session_data *sd=NULL;
  9727. int num;
  9728. char *name;
  9729. char prefix;
  9730. int x,y,type;
  9731. char mapname[MAP_NAME_LENGTH+1];
  9732. malloc_set(mapname, 0, sizeof(mapname));
  9733. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  9734. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  9735. push_val(st->stack,C_INT,-1);
  9736. return 1;
  9737. }
  9738. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  9739. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  9740. push_val(st->stack,C_INT,-1);
  9741. return 1;
  9742. }
  9743. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  9744. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  9745. push_val(st->stack,C_INT,-1);
  9746. return 1;
  9747. }
  9748. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  9749. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9750. switch (type){
  9751. case 0: //Get Character Position
  9752. if( st->end>st->start+6 )
  9753. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9754. else
  9755. sd=script_rid2sd(st);
  9756. if (sd)
  9757. bl = &sd->bl;
  9758. break;
  9759. case 1: //Get NPC Position
  9760. if( st->end > st->start+6 )
  9761. {
  9762. struct npc_data *nd;
  9763. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9764. if (nd)
  9765. bl = &nd->bl;
  9766. } else //In case the origin is not an npc?
  9767. bl=map_id2bl(st->oid);
  9768. break;
  9769. case 2: //Get Pet Position
  9770. if(st->end>st->start+6)
  9771. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9772. else
  9773. sd=script_rid2sd(st);
  9774. if (sd && sd->pd)
  9775. bl = &sd->pd->bl;
  9776. break;
  9777. case 3: //Get Mob Position
  9778. break; //Not supported?
  9779. case 4: //Get Homun Position
  9780. if(st->end>st->start+6)
  9781. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9782. else
  9783. sd=script_rid2sd(st);
  9784. if (sd && sd->hd)
  9785. bl = &sd->hd->bl;
  9786. break;
  9787. }
  9788. if (!bl) { //No object found.
  9789. push_val(st->stack,C_INT,-1);
  9790. return 0;
  9791. }
  9792. x= bl->x;
  9793. y= bl->y;
  9794. memcpy(mapname, map[bl->m].name, MAP_NAME_LENGTH);
  9795. //Set MapName$
  9796. num=st->stack->stack_data[st->start+2].u.num;
  9797. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9798. prefix=*name;
  9799. if(not_server_variable(prefix))
  9800. sd=script_rid2sd(st);
  9801. else
  9802. sd=NULL;
  9803. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  9804. //Set MapX
  9805. num=st->stack->stack_data[st->start+3].u.num;
  9806. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9807. prefix=*name;
  9808. if(not_server_variable(prefix))
  9809. sd=script_rid2sd(st);
  9810. else
  9811. sd=NULL;
  9812. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  9813. //Set MapY
  9814. num=st->stack->stack_data[st->start+4].u.num;
  9815. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9816. prefix=*name;
  9817. if(not_server_variable(prefix))
  9818. sd=script_rid2sd(st);
  9819. else
  9820. sd=NULL;
  9821. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  9822. //Return Success value
  9823. push_val(st->stack,C_INT,0);
  9824. return 0;
  9825. }
  9826. /*==========================================
  9827. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  9828. *------------------------------------------
  9829. */
  9830. int buildin_logmes(struct script_state *st)
  9831. {
  9832. if (log_config.npc <= 0 ) return 0;
  9833. conv_str(st,& (st->stack->stack_data[st->start+2]));
  9834. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  9835. return 0;
  9836. }
  9837. int buildin_summon(struct script_state *st)
  9838. {
  9839. int _class, timeout=0;
  9840. char *str,*event="";
  9841. struct map_session_data *sd;
  9842. struct mob_data *md;
  9843. int tick = gettick();
  9844. sd=script_rid2sd(st);
  9845. if (!sd) return 0;
  9846. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9847. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9848. if( st->end>st->start+4 )
  9849. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9850. if( st->end>st->start+5 ){
  9851. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  9852. check_event(st, event);
  9853. }
  9854. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  9855. md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event);
  9856. if (md) {
  9857. md->master_id=sd->bl.id;
  9858. md->special_state.ai=1;
  9859. md->deletetimer = add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0);
  9860. mob_spawn (md); //Now it is ready for spawning.
  9861. clif_misceffect2(&md->bl,344);
  9862. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  9863. }
  9864. return 0;
  9865. }
  9866. /*==========================================
  9867. * Checks whether it is daytime/nighttime
  9868. *------------------------------------------
  9869. */
  9870. int buildin_isnight(struct script_state *st)
  9871. {
  9872. push_val(st->stack,C_INT, (night_flag == 1));
  9873. return 0;
  9874. }
  9875. int buildin_isday(struct script_state *st)
  9876. {
  9877. push_val(st->stack,C_INT, (night_flag == 0));
  9878. return 0;
  9879. }
  9880. /*================================================
  9881. * Check whether another item/card has been
  9882. * equipped - used for 2/15's cards patch [celest]
  9883. *------------------------------------------------
  9884. */
  9885. // leave this here, just in case
  9886. #if 0
  9887. int buildin_isequipped(struct script_state *st)
  9888. {
  9889. struct map_session_data *sd;
  9890. int i, j, k, id = 1;
  9891. int ret = -1;
  9892. sd = script_rid2sd(st);
  9893. for (i=0; id!=0; i++) {
  9894. int flag = 0;
  9895. FETCH (i+2, id) else id = 0;
  9896. if (id <= 0)
  9897. continue;
  9898. for (j=0; j<EQI_MAX; j++) {
  9899. int index;
  9900. index = sd->equip_index[j];
  9901. if(index < 0) continue;
  9902. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9903. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9904. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9905. if(!sd->inventory_data[index])
  9906. continue;
  9907. if(itemdb_type(id) != IT_CARD) { //Non card
  9908. if (sd->inventory_data[index]->nameid != id)
  9909. continue;
  9910. flag = 1;
  9911. break;
  9912. } else { //Card
  9913. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9914. continue;
  9915. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9916. if (sd->status.inventory[index].card[k] == id)
  9917. {
  9918. flag = 1;
  9919. break;
  9920. }
  9921. }
  9922. }
  9923. if (flag) break;
  9924. }
  9925. if (ret == -1)
  9926. ret = flag;
  9927. else
  9928. ret &= flag;
  9929. if (!ret) break;
  9930. }
  9931. push_val(st->stack,C_INT,ret);
  9932. return 0;
  9933. }
  9934. #endif
  9935. /*================================================
  9936. * Check how many items/cards in the list are
  9937. * equipped - used for 2/15's cards patch [celest]
  9938. *------------------------------------------------
  9939. */
  9940. int buildin_isequippedcnt(struct script_state *st)
  9941. {
  9942. struct map_session_data *sd;
  9943. int i, j, k, id = 1;
  9944. int ret = 0;
  9945. sd = script_rid2sd(st);
  9946. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9947. push_val(st->stack,C_INT,0);
  9948. return 0;
  9949. }
  9950. for (i=0; id!=0; i++) {
  9951. FETCH (i+2, id) else id = 0;
  9952. if (id <= 0)
  9953. continue;
  9954. for (j=0; j<EQI_MAX; j++) {
  9955. int index;
  9956. index = sd->equip_index[j];
  9957. if(index < 0) continue;
  9958. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9959. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9960. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9961. if(!sd->inventory_data[index])
  9962. continue;
  9963. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  9964. if (sd->inventory_data[index]->nameid == id)
  9965. ret+= sd->status.inventory[index].amount;
  9966. } else { //Count cards.
  9967. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9968. continue; //No cards
  9969. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9970. if (sd->status.inventory[index].card[k] == id)
  9971. ret++; //[Lupus]
  9972. }
  9973. }
  9974. }
  9975. }
  9976. push_val(st->stack,C_INT,ret);
  9977. return 0;
  9978. }
  9979. /*================================================
  9980. * Check whether another card has been
  9981. * equipped - used for 2/15's cards patch [celest]
  9982. * -- Items checked cannot be reused in another
  9983. * card set to prevent exploits
  9984. *------------------------------------------------
  9985. */
  9986. int buildin_isequipped(struct script_state *st)
  9987. {
  9988. struct map_session_data *sd;
  9989. int i, j, k, id = 1;
  9990. int index, flag;
  9991. int ret = -1;
  9992. //Original hash to reverse it when full check fails.
  9993. unsigned int setitem_hash = 0, setitem_hash2 = 0;
  9994. sd = script_rid2sd(st);
  9995. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9996. push_val(st->stack,C_INT,0);
  9997. return 0;
  9998. }
  9999. setitem_hash = sd->setitem_hash;
  10000. setitem_hash2 = sd->setitem_hash2;
  10001. for (i=0; id!=0; i++)
  10002. {
  10003. FETCH (i+2, id) else id = 0;
  10004. if (id <= 0)
  10005. continue;
  10006. flag = 0;
  10007. for (j=0; j<EQI_MAX; j++)
  10008. {
  10009. index = sd->equip_index[j];
  10010. if(index < 0) continue;
  10011. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  10012. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  10013. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  10014. if(!sd->inventory_data[index])
  10015. continue;
  10016. if (itemdb_type(id) != IT_CARD) {
  10017. if (sd->inventory_data[index]->nameid != id)
  10018. continue;
  10019. flag = 1;
  10020. break;
  10021. } else { //Cards
  10022. if (sd->inventory_data[index]->slot == 0 ||
  10023. itemdb_isspecial(sd->status.inventory[index].card[0]))
  10024. continue;
  10025. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  10026. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  10027. unsigned int hash = 0;
  10028. if (sd->status.inventory[index].card[k] != id)
  10029. continue;
  10030. hash = 1<<((j<5?j:j-5)*4 + k);
  10031. // check if card is already used by another set
  10032. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  10033. continue;
  10034. // We have found a match
  10035. flag = 1;
  10036. // Set hash so this card cannot be used by another
  10037. if (j<5)
  10038. sd->setitem_hash |= hash;
  10039. else
  10040. sd->setitem_hash2 |= hash;
  10041. break;
  10042. }
  10043. }
  10044. if (flag) break; //Card found
  10045. }
  10046. if (ret == -1)
  10047. ret = flag;
  10048. else
  10049. ret &= flag;
  10050. if (!ret) break;
  10051. }
  10052. if (!ret)
  10053. { //When check fails, restore original hash values. [Skotlex]
  10054. sd->setitem_hash = setitem_hash;
  10055. sd->setitem_hash2 = setitem_hash2;
  10056. }
  10057. push_val(st->stack,C_INT,ret);
  10058. return 0;
  10059. }
  10060. /*================================================
  10061. * Check how many given inserted cards in the CURRENT
  10062. * weapon - used for 2/15's cards patch [Lupus]
  10063. *------------------------------------------------
  10064. */
  10065. int buildin_cardscnt(struct script_state *st)
  10066. {
  10067. struct map_session_data *sd;
  10068. int i, k, id = 1;
  10069. int ret = 0;
  10070. int index;
  10071. sd = script_rid2sd(st);
  10072. for (i=0; id!=0; i++) {
  10073. FETCH (i+2, id) else id = 0;
  10074. if (id <= 0)
  10075. continue;
  10076. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  10077. if(index < 0) continue;
  10078. if(!sd->inventory_data[index])
  10079. continue;
  10080. if(itemdb_type(id) != IT_CARD) {
  10081. if (sd->inventory_data[index]->nameid == id)
  10082. ret+= sd->status.inventory[index].amount;
  10083. } else {
  10084. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  10085. continue;
  10086. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  10087. if (sd->status.inventory[index].card[k] == id)
  10088. ret++;
  10089. }
  10090. }
  10091. }
  10092. push_val(st->stack,C_INT,ret);
  10093. // push_val(st->stack,C_INT,current_equip_item_index);
  10094. return 0;
  10095. }
  10096. /*=======================================================
  10097. * Returns the refined number of the current item, or an
  10098. * item with inventory index specified
  10099. *-------------------------------------------------------
  10100. */
  10101. int buildin_getrefine(struct script_state *st)
  10102. {
  10103. struct map_session_data *sd;
  10104. if ((sd = script_rid2sd(st))!= NULL)
  10105. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  10106. else
  10107. push_val(st->stack,C_INT,0);
  10108. return 0;
  10109. }
  10110. /*=======================================================
  10111. * Allows 2 Parents to adopt a character as a Baby
  10112. *-------------------------------------------------------
  10113. */
  10114. int buildin_adopt(struct script_state *st)
  10115. {
  10116. int ret;
  10117. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10118. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10119. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  10120. struct map_session_data *p1_sd = map_nick2sd(parent1);
  10121. struct map_session_data *p2_sd = map_nick2sd(parent2);
  10122. struct map_session_data *c_sd = map_nick2sd(child);
  10123. if (!p1_sd || !p2_sd || !c_sd ||
  10124. p1_sd->status.base_level < 70 ||
  10125. p2_sd->status.base_level < 70)
  10126. return 0;
  10127. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  10128. push_val(st->stack, C_INT, ret);
  10129. return 0;
  10130. }
  10131. /*=======================================================
  10132. * Day/Night controls
  10133. *-------------------------------------------------------
  10134. */
  10135. int buildin_night(struct script_state *st)
  10136. {
  10137. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  10138. return 0;
  10139. }
  10140. int buildin_day(struct script_state *st)
  10141. {
  10142. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  10143. return 0;
  10144. }
  10145. //=======================================================
  10146. // Unequip [Spectre]
  10147. //-------------------------------------------------------
  10148. int buildin_unequip(struct script_state *st)
  10149. {
  10150. int i;
  10151. size_t num;
  10152. struct map_session_data *sd;
  10153. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  10154. sd=script_rid2sd(st);
  10155. if(sd!=NULL && num<10)
  10156. {
  10157. i=pc_checkequip(sd,equip[num]);
  10158. pc_unequipitem(sd,i,2);
  10159. return 0;
  10160. }
  10161. return 0;
  10162. }
  10163. int buildin_equip(struct script_state *st)
  10164. {
  10165. int nameid=0,i;
  10166. struct map_session_data *sd;
  10167. struct item_data *item_data;
  10168. sd = script_rid2sd(st);
  10169. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10170. if((item_data = itemdb_exists(nameid)) == NULL)
  10171. {
  10172. if(battle_config.error_log)
  10173. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  10174. return 1;
  10175. }
  10176. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  10177. if(i==MAX_INVENTORY) return 0;
  10178. pc_equipitem(sd,i,item_data->equip);
  10179. return 0;
  10180. }
  10181. int buildin_autoequip(struct script_state *st){
  10182. int nameid, flag;
  10183. struct item_data *item_data;
  10184. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10185. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10186. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  10187. item_data->flag.autoequip = flag>0?1:0;
  10188. }
  10189. return 0;
  10190. }
  10191. int buildin_setbattleflag(struct script_state *st){
  10192. char *flag, *value;
  10193. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10194. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10195. if (battle_set_value(flag, value) == 0)
  10196. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag);
  10197. else
  10198. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value);
  10199. return 0;
  10200. }
  10201. int buildin_getbattleflag(struct script_state *st){
  10202. char *flag;
  10203. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10204. push_val(st->stack,C_INT,battle_get_value(flag));
  10205. return 0;
  10206. }
  10207. //=======================================================
  10208. // strlen [Valaris]
  10209. //-------------------------------------------------------
  10210. int buildin_getstrlen(struct script_state *st) {
  10211. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10212. int len = (str) ? (int)strlen(str) : 0;
  10213. push_val(st->stack,C_INT,len);
  10214. return 0;
  10215. }
  10216. //=======================================================
  10217. // isalpha [Valaris]
  10218. //-------------------------------------------------------
  10219. int buildin_charisalpha(struct script_state *st) {
  10220. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  10221. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10222. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? ISALPHA( str[pos] ) : 0;
  10223. push_val(st->stack,C_INT,val);
  10224. return 0;
  10225. }
  10226. // [Lance]
  10227. int buildin_fakenpcname(struct script_state *st)
  10228. {
  10229. char *name;
  10230. char *newname;
  10231. int look;
  10232. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10233. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10234. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  10235. if(look > 32767 || look < -32768) {
  10236. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  10237. return 1; // Safety measure to prevent runtime errors
  10238. }
  10239. npc_changename(name,newname,(short)look);
  10240. return 0;
  10241. }
  10242. int buildin_atoi(struct script_state *st) {
  10243. char *value;
  10244. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10245. push_val(st->stack, C_INT, atoi(value));
  10246. return 0;
  10247. }
  10248. //-----------------------------------------------------------------------//
  10249. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  10250. //-----------------------------------------------------------------------//
  10251. int buildin_compare(struct script_state *st) {
  10252. char *message;
  10253. char *cmpstring;
  10254. int j;
  10255. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10256. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10257. for (j = 0; message[j]; j++)
  10258. message[j] = TOLOWER(message[j]);
  10259. for (j = 0; cmpstring[j]; j++)
  10260. cmpstring[j] = TOLOWER(cmpstring[j]);
  10261. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  10262. return 0;
  10263. }
  10264. //-----------------------------------------------------------------------//
  10265. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  10266. //-----------------------------------------------------------------------//
  10267. // [zBuffer] List of mathematics commands --->
  10268. int buildin_sqrt(struct script_state *st){
  10269. double i, a;
  10270. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10271. a = sqrt(i);
  10272. push_val(st->stack, C_INT, (int)a);
  10273. return 0;
  10274. }
  10275. int buildin_pow(struct script_state *st){
  10276. double i, a, b;
  10277. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10278. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10279. i = pow(a,b);
  10280. push_val(st->stack, C_INT, (int)i);
  10281. return 0;
  10282. }
  10283. int buildin_distance(struct script_state *st){
  10284. int x0, y0, x1, y1;
  10285. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10286. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10287. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  10288. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  10289. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  10290. return 0;
  10291. }
  10292. int buildin_checkcell(struct script_state *st){
  10293. int m;
  10294. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  10295. m = mapindex_name2id(map);
  10296. if(m){
  10297. push_val(st->stack, C_INT, map_getcell(m, conv_num(st, &(st->stack->stack_data[st->start+3])), conv_num(st, &(st->stack->stack_data[st->start+4])),conv_num(st, &(st->stack->stack_data[st->start+5]))));
  10298. } else {
  10299. push_val(st->stack, C_INT, 0);
  10300. }
  10301. return 0;
  10302. }
  10303. // <--- [zBuffer] List of mathematics commands
  10304. // [zBuffer] List of dynamic var commands --->
  10305. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  10306. {
  10307. set_reg(st, sd, add_str(varname)+(elem<<24), varname, value, ref);
  10308. return;
  10309. }
  10310. int buildin_setd(struct script_state *st)
  10311. {
  10312. struct map_session_data *sd=NULL;
  10313. char varname[100], *buffer;
  10314. char *value;
  10315. int elem;
  10316. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10317. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10318. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10319. elem = 0;
  10320. if(st->rid)
  10321. sd = script_rid2sd(st);
  10322. if(varname[strlen(varname)-1] != '$') {
  10323. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  10324. } else {
  10325. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  10326. }
  10327. return 0;
  10328. }
  10329. int buildin_query_sql(struct script_state *st) {
  10330. #ifndef TXT_ONLY
  10331. char *name = NULL, *query;
  10332. int num, i = 0,j, nb_rows;
  10333. struct { char * dst_var_name; char type; } row[32];
  10334. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  10335. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10336. strcpy(tmp_sql, query);
  10337. if(mysql_query(&mmysql_handle,tmp_sql)){
  10338. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10339. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10340. push_val(st->stack,C_INT,0);
  10341. return 1;
  10342. }
  10343. // If some data was returned
  10344. if((sql_res = mysql_store_result(&mmysql_handle))){
  10345. // Count the number of rows to store
  10346. nb_rows = mysql_num_fields(sql_res);
  10347. // Can't store more row than variable
  10348. if (nb_rows > st->end - (st->start+3))
  10349. nb_rows = st->end - (st->start+3);
  10350. if (!nb_rows)
  10351. {
  10352. push_val(st->stack,C_INT,0);
  10353. return 0; // Nothing to store
  10354. }
  10355. if (nb_rows > 32)
  10356. {
  10357. ShowWarning("buildin_query_sql: too many rows!\n");
  10358. push_val(st->stack,C_INT,0);
  10359. return 1;
  10360. }
  10361. malloc_set(row, 0, sizeof(row));
  10362. // Verify argument types
  10363. for(j=0; j < nb_rows; j++)
  10364. {
  10365. if(st->stack->stack_data[st->start+3+j].type != C_NAME){
  10366. ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
  10367. push_val(st->stack,C_INT,0);
  10368. return 0;
  10369. } else {
  10370. // Store type of variable (string = 0/int = 1)
  10371. num=st->stack->stack_data[st->start+3+j].u.num;
  10372. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10373. if(name[strlen(name)-1] != '$') {
  10374. row[j].type = 1;
  10375. }
  10376. row[j].dst_var_name = name;
  10377. }
  10378. }
  10379. // Store data
  10380. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10381. for(j=0; j < nb_rows; j++)
  10382. {
  10383. if (row[j].type == 1)
  10384. setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(sql_row[j]),st->stack->stack_data[st->start+3+j].ref);
  10385. else
  10386. setd_sub(st,sd, row[j].dst_var_name, i, (void *)sql_row[j],st->stack->stack_data[st->start+3+j].ref);
  10387. }
  10388. i++;
  10389. }
  10390. // Free data
  10391. mysql_free_result(sql_res);
  10392. }
  10393. push_val(st->stack, C_INT, i);
  10394. #else
  10395. //for TXT version, we always return -1
  10396. push_val(st->stack, C_INT, -1);
  10397. #endif
  10398. return 0;
  10399. }
  10400. //Allows escaping of a given string.
  10401. int buildin_escape_sql(struct script_state *st) {
  10402. char *t_query, *query;
  10403. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10404. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  10405. jstrescapecpy(t_query,query);
  10406. push_str(st->stack,C_STR,t_query);
  10407. return 0;
  10408. }
  10409. int buildin_getd (struct script_state *st)
  10410. {
  10411. char varname[100], *buffer;
  10412. //struct script_data dat;
  10413. int elem;
  10414. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10415. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10416. elem = 0;
  10417. /*dat.type=C_NAME;
  10418. dat.u.num=add_str(varname)+(elem<<24);
  10419. get_val(st,&dat);
  10420. if(dat.type == C_INT)
  10421. push_val(st->stack, C_INT, dat.u.num);
  10422. else if(dat.type == C_CONSTSTR){
  10423. buffer = aStrdup((char *)dat.u.str);
  10424. // dat.u.str holds the actual pointer to the data, must be duplicated.
  10425. // It will be freed later. Tested.
  10426. push_str(st->stack, C_STR, buffer);
  10427. }*/
  10428. // Push the 'pointer' so it's more flexible [Lance]
  10429. push_val(st->stack,C_NAME,
  10430. (elem<<24) | add_str(varname));
  10431. return 0;
  10432. }
  10433. // <--- [zBuffer] List of dynamic var commands
  10434. // Pet stat [Lance]
  10435. int buildin_petstat(struct script_state *st){
  10436. struct map_session_data *sd = NULL;
  10437. struct pet_data *pd;
  10438. char *tmp;
  10439. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10440. sd = script_rid2sd(st);
  10441. if(!sd || !sd->status.pet_id || !sd->pd){
  10442. if(flag == 2)
  10443. push_str(st->stack, C_CONSTSTR, "");
  10444. else
  10445. push_val(st->stack, C_INT, 0);
  10446. return 0;
  10447. }
  10448. pd = sd->pd;
  10449. switch(flag){
  10450. case 1:
  10451. push_val(st->stack, C_INT, (int)pd->pet.class_);
  10452. break;
  10453. case 2:
  10454. tmp = aStrdup(pd->pet.name);
  10455. push_str(st->stack, C_STR, tmp);
  10456. break;
  10457. case 3:
  10458. push_val(st->stack, C_INT, (int)pd->pet.level);
  10459. break;
  10460. case 4:
  10461. push_val(st->stack, C_INT, (int)pd->pet.hungry);
  10462. break;
  10463. case 5:
  10464. push_val(st->stack, C_INT, (int)pd->pet.intimate);
  10465. break;
  10466. default:
  10467. push_val(st->stack, C_INT, 0);
  10468. break;
  10469. }
  10470. return 0;
  10471. }
  10472. int buildin_callshop(struct script_state *st)
  10473. {
  10474. struct map_session_data *sd = NULL;
  10475. struct npc_data *nd;
  10476. char *shopname;
  10477. int flag = 0;
  10478. sd = script_rid2sd(st);
  10479. if (!sd) {
  10480. push_val(st->stack,C_INT,0);
  10481. return 0;
  10482. }
  10483. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10484. if( st->end>st->start+3 )
  10485. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10486. nd = npc_name2id(shopname);
  10487. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  10488. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  10489. push_val(st->stack,C_INT,0);
  10490. return 1;
  10491. }
  10492. switch (flag) {
  10493. case 1: //Buy window
  10494. npc_buysellsel(sd,nd->bl.id,0);
  10495. break;
  10496. case 2: //Sell window
  10497. npc_buysellsel(sd,nd->bl.id,1);
  10498. break;
  10499. default: //Show menu
  10500. clif_npcbuysell(sd,nd->bl.id);
  10501. break;
  10502. }
  10503. sd->npc_shopid = nd->bl.id;
  10504. push_val(st->stack,C_INT,1);
  10505. return 0;
  10506. }
  10507. #ifndef MAX_SHOPITEM
  10508. #define MAX_SHOPITEM 100
  10509. #endif
  10510. int buildin_npcshopitem(struct script_state *st)
  10511. {
  10512. struct npc_data *nd= NULL;
  10513. int n = 0;
  10514. int i = 3;
  10515. int amount;
  10516. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  10517. nd = npc_name2id(npcname);
  10518. if(nd && nd->bl.subtype==SHOP){
  10519. amount = ((st->end-2)/2)+1;
  10520. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  10521. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10522. sizeof(nd->u.shop_item[0]) * amount);
  10523. // Reset sell list.
  10524. malloc_set(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  10525. n = 0;
  10526. while (st->end > st->start + i) {
  10527. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10528. i++;
  10529. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10530. i++;
  10531. n++;
  10532. }
  10533. map_addiddb(&nd->bl);
  10534. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10535. } else {
  10536. ShowError("buildin_npcshopitem: shop not found.\n");
  10537. }
  10538. return 0;
  10539. }
  10540. int buildin_npcshopadditem(struct script_state *st) {
  10541. struct npc_data *nd=NULL;
  10542. int n = 0;
  10543. int i = 3;
  10544. int amount;
  10545. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10546. nd = npc_name2id(npcname);
  10547. if (nd && nd->bl.subtype==SHOP){
  10548. amount = ((st->end-2)/2)+1;
  10549. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  10550. n++;
  10551. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10552. sizeof(nd->u.shop_item[0]) * (amount+n));
  10553. while(st->end > st->start + i){
  10554. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10555. i++;
  10556. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10557. i++;
  10558. n++;
  10559. }
  10560. // Marks the last of our stuff..
  10561. nd->u.shop_item[n].value = 0;
  10562. nd->u.shop_item[n].nameid = 0;
  10563. map_addiddb(&nd->bl);
  10564. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10565. } else {
  10566. ShowError("buildin_npcshopadditem: shop not found.\n");
  10567. }
  10568. return 0;
  10569. }
  10570. int buildin_npcshopdelitem(struct script_state *st)
  10571. {
  10572. struct npc_data *nd=NULL;
  10573. int n=0;
  10574. int i=3;
  10575. int size = 0;
  10576. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10577. nd = npc_name2id(npcname);
  10578. if (nd && nd->bl.subtype==SHOP) {
  10579. while (nd->u.shop_item[size].nameid)
  10580. size++;
  10581. while (st->end > st->start+i) {
  10582. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  10583. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  10584. // We're moving 1 extra empty block. Junk data is eliminated later.
  10585. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  10586. }
  10587. }
  10588. i++;
  10589. }
  10590. size = 0;
  10591. while (nd->u.shop_item[size].nameid)
  10592. size++;
  10593. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10594. sizeof(nd->u.shop_item[0]) * (size+1));
  10595. map_addiddb(&nd->bl);
  10596. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10597. } else {
  10598. ShowError("buildin_npcshopdelitem: shop not found.\n");
  10599. }
  10600. return 0;
  10601. }
  10602. /*==========================================
  10603. * Returns some values of an item [Lupus]
  10604. * Price, Weight, etc...
  10605. setiteminfo(itemID,"{new item bonus script}");
  10606. *------------------------------------------
  10607. */
  10608. int buildin_setitemscript(struct script_state *st)
  10609. {
  10610. int item_id;
  10611. char *script;
  10612. struct item_data *i_data;
  10613. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10614. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10615. i_data = itemdb_exists(item_id);
  10616. if (i_data && script!=NULL && script[0]=='{') {
  10617. if(i_data->script!=NULL)
  10618. script_free_code(i_data->script);
  10619. i_data->script = parse_script(script, "script_setitemscript", 0, 0);
  10620. push_val(st->stack,C_INT,1);
  10621. } else
  10622. push_val(st->stack,C_INT,0);
  10623. return 0;
  10624. }
  10625. /* Work In Progress [Lupus]
  10626. int buildin_addmonsterdrop(struct script_state *st)
  10627. {
  10628. int class_,item_id,chance;
  10629. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10630. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10631. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10632. if(class_>1000 && item_id>500 && chance>0) {
  10633. push_val(st->stack,C_INT,1);
  10634. } else {
  10635. push_val(st->stack,C_INT,0);
  10636. }
  10637. }
  10638. int buildin_delmonsterdrop(struct script_state *st)
  10639. {
  10640. int class_,item_id;
  10641. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10642. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10643. if(class_>1000 && item_id>500) {
  10644. push_val(st->stack,C_INT,1);
  10645. } else {
  10646. push_val(st->stack,C_INT,0);
  10647. }
  10648. }
  10649. */
  10650. /*==========================================
  10651. * Returns some values of a monster [Lupus]
  10652. * Name, Level, race, size, etc...
  10653. getmonsterinfo(monsterID,queryIndex);
  10654. *------------------------------------------
  10655. */
  10656. int buildin_getmonsterinfo(struct script_state *st)
  10657. {
  10658. struct mob_db *mob;
  10659. int mob_id;
  10660. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10661. if (!mobdb_checkid(mob_id)) {
  10662. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  10663. push_val(st->stack, C_INT, -1);
  10664. return -1;
  10665. }
  10666. mob = mob_db(mob_id);
  10667. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  10668. case 0: //Name
  10669. push_str(st->stack,C_CONSTSTR,mob->jname);
  10670. break;
  10671. case 1: //Lvl
  10672. push_val(st->stack,C_INT, mob->lv);
  10673. break;
  10674. case 2: //MaxHP
  10675. push_val(st->stack,C_INT, mob->status.max_hp);
  10676. break;
  10677. case 3: //Base EXP
  10678. push_val(st->stack,C_INT, mob->base_exp);
  10679. break;
  10680. case 4: //Job EXP
  10681. push_val(st->stack,C_INT, mob->job_exp);
  10682. break;
  10683. case 5: //Atk1
  10684. push_val(st->stack,C_INT, mob->status.rhw.atk);
  10685. break;
  10686. case 6: //Atk2
  10687. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  10688. break;
  10689. case 7: //Def
  10690. push_val(st->stack,C_INT, mob->status.def);
  10691. break;
  10692. case 8: //Mdef
  10693. push_val(st->stack,C_INT, mob->status.mdef);
  10694. break;
  10695. case 9: //Str
  10696. push_val(st->stack,C_INT, mob->status.str);
  10697. break;
  10698. case 10: //Agi
  10699. push_val(st->stack,C_INT, mob->status.agi);
  10700. break;
  10701. case 11: //Vit
  10702. push_val(st->stack,C_INT, mob->status.vit);
  10703. break;
  10704. case 12: //Int
  10705. push_val(st->stack,C_INT, mob->status.int_);
  10706. break;
  10707. case 13: //Dex
  10708. push_val(st->stack,C_INT, mob->status.dex);
  10709. break;
  10710. case 14: //Luk
  10711. push_val(st->stack,C_INT, mob->status.luk);
  10712. break;
  10713. case 15: //Range
  10714. push_val(st->stack,C_INT, mob->status.rhw.range);
  10715. break;
  10716. case 16: //Range2
  10717. push_val(st->stack,C_INT, mob->range2);
  10718. break;
  10719. case 17: //Range3
  10720. push_val(st->stack,C_INT, mob->range3);
  10721. break;
  10722. case 18: //Size
  10723. push_val(st->stack,C_INT, mob->status.size);
  10724. break;
  10725. case 19: //Race
  10726. push_val(st->stack,C_INT, mob->status.race);
  10727. break;
  10728. case 20: //Element
  10729. push_val(st->stack,C_INT, mob->status.def_ele);
  10730. break;
  10731. case 21: //Mode
  10732. push_val(st->stack,C_INT, mob->status.mode);
  10733. break;
  10734. default: //wrong Index
  10735. push_val(st->stack,C_INT,-1);
  10736. }
  10737. return 0;
  10738. }
  10739. int buildin_checkvending(struct script_state *st){ // check vending [Nab4]
  10740. struct map_session_data *sd = NULL;
  10741. if(st->end > st->start + 2)
  10742. sd = map_nick2sd(conv_str(st,&st->stack->stack_data[st->start+2]));
  10743. else
  10744. sd = script_rid2sd(st);
  10745. if(sd)
  10746. push_val(st->stack, C_INT, (sd->vender_id != 0));
  10747. else
  10748. push_val(st->stack, C_INT, 0);
  10749. return 0;
  10750. }
  10751. int buildin_checkchatting(struct script_state *st){ // check chatting [Marka]
  10752. struct map_session_data *sd = NULL;
  10753. if(st->end > st->start + 2)
  10754. sd = map_nick2sd(conv_str(st,&st->stack->stack_data[st->start+2]));
  10755. else
  10756. sd = script_rid2sd(st);
  10757. if(sd)
  10758. push_val(st->stack, C_INT, (sd->chatID != 0));
  10759. else
  10760. push_val(st->stack, C_INT, 0);
  10761. return 0;
  10762. }
  10763. int axtoi(char *hexStg) {
  10764. int n = 0; // position in string
  10765. int m = 0; // position in digit[] to shift
  10766. int count; // loop index
  10767. int intValue = 0; // integer value of hex string
  10768. int digit[11]; // hold values to convert
  10769. while (n < 10) {
  10770. if (hexStg[n]=='\0')
  10771. break;
  10772. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  10773. digit[n] = hexStg[n] & 0x0f; //convert to int
  10774. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  10775. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10776. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  10777. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10778. else break;
  10779. n++;
  10780. }
  10781. count = n;
  10782. m = n - 1;
  10783. n = 0;
  10784. while(n < count) {
  10785. // digit[n] is value of hex digit at position n
  10786. // (m << 2) is the number of positions to shift
  10787. // OR the bits into return value
  10788. intValue = intValue | (digit[n] << (m << 2));
  10789. m--; // adjust the position to set
  10790. n++; // next digit to process
  10791. }
  10792. return (intValue);
  10793. }
  10794. // [Lance] Hex string to integer converter
  10795. int buildin_axtoi(struct script_state *st)
  10796. {
  10797. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10798. push_val(st->stack, C_INT, axtoi(hex));
  10799. return 0;
  10800. }
  10801. // [zBuffer] List of player cont commands --->
  10802. int buildin_rid2name(struct script_state *st){
  10803. struct block_list *bl = NULL;
  10804. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10805. if((bl = map_id2bl(rid))){
  10806. switch(bl->type){
  10807. case BL_MOB:
  10808. push_str(st->stack,C_CONSTSTR,((TBL_MOB*)bl)->name);
  10809. break;
  10810. case BL_PC:
  10811. push_str(st->stack,C_CONSTSTR,((TBL_PC*)bl)->status.name);
  10812. break;
  10813. case BL_NPC:
  10814. push_str(st->stack,C_CONSTSTR,((TBL_NPC*)bl)->exname);
  10815. break;
  10816. case BL_PET:
  10817. push_str(st->stack,C_CONSTSTR,((TBL_PET*)bl)->pet.name);
  10818. break;
  10819. case BL_HOM:
  10820. push_str(st->stack,C_CONSTSTR,((TBL_HOM*)bl)->homunculus.name);
  10821. break;
  10822. default:
  10823. ShowError("buildin_rid2name: BL type unknown.\n");
  10824. push_str(st->stack,C_CONSTSTR,"");
  10825. break;
  10826. }
  10827. } else {
  10828. ShowError("buildin_rid2name: invalid RID\n");
  10829. push_str(st->stack,C_CONSTSTR,"(null)");
  10830. }
  10831. return 0;
  10832. }
  10833. int buildin_pcblockmove(struct script_state *st){
  10834. int id, flag;
  10835. struct map_session_data *sd = NULL;
  10836. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10837. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10838. if(id)
  10839. sd = map_id2sd(id);
  10840. else
  10841. sd = script_rid2sd(st);
  10842. if(sd)
  10843. sd->state.blockedmove = flag > 0;
  10844. return 0;
  10845. }
  10846. int buildin_pcfollow(struct script_state *st) {
  10847. int id, targetid;
  10848. struct map_session_data *sd = NULL;
  10849. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10850. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10851. if(id)
  10852. sd = map_id2sd(id);
  10853. else
  10854. sd = script_rid2sd(st);
  10855. if(sd)
  10856. pc_follow(sd, targetid);
  10857. return 0;
  10858. }
  10859. int buildin_pcstopfollow(struct script_state *st) {
  10860. int id;
  10861. struct map_session_data *sd = NULL;
  10862. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10863. if(id)
  10864. sd = map_id2sd(id);
  10865. else
  10866. sd = script_rid2sd(st);
  10867. if(sd)
  10868. pc_stop_following(sd);
  10869. return 0;
  10870. }
  10871. // <--- [zBuffer] List of player cont commands
  10872. // [zBuffer] List of mob control commands --->
  10873. int buildin_mobspawn(struct script_state *st){
  10874. int class_,x,y,id;
  10875. char *str,*map;
  10876. // Who?
  10877. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  10878. // What?
  10879. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  10880. // Where?
  10881. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  10882. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  10883. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  10884. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,"");
  10885. push_val(st->stack,C_INT,id);
  10886. return 0;
  10887. }
  10888. int buildin_mobremove(struct script_state *st) {
  10889. int id;
  10890. struct block_list *bl = NULL;
  10891. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10892. bl = map_id2bl(id);
  10893. if (bl && bl->type == BL_MOB)
  10894. unit_free(bl,0);
  10895. return 0;
  10896. }
  10897. int buildin_getmobdata(struct script_state *st) {
  10898. int num, id;
  10899. char *name;
  10900. struct mob_data *md = NULL;
  10901. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  10902. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10903. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  10904. ShowWarning("buildin_getmobdata: Error in argument!\n");
  10905. return -1;
  10906. }
  10907. num=st->stack->stack_data[st->start+3].u.num;
  10908. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10909. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  10910. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  10911. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  10912. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  10913. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  10914. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  10915. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  10916. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  10917. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  10918. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  10919. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  10920. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  10921. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  10922. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  10923. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  10924. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  10925. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  10926. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  10927. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  10928. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  10929. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10930. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  10931. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10932. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  10933. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  10934. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  10935. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  10936. return 0;
  10937. }
  10938. int buildin_setmobdata(struct script_state *st){
  10939. int id, value, value2;
  10940. struct mob_data *md = NULL;
  10941. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10942. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10943. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10944. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  10945. ShowWarning("buildin_setmobdata: Error in argument!\n");
  10946. return -1;
  10947. }
  10948. switch(value){
  10949. case 0:
  10950. md->class_ = (short)value2;
  10951. break;
  10952. case 1:
  10953. md->level = (unsigned short)value2;
  10954. break;
  10955. case 2:
  10956. md->status.hp = (unsigned int)value2;
  10957. break;
  10958. case 3:
  10959. md->status.max_hp = (unsigned int)value2;
  10960. break;
  10961. case 4:
  10962. md->master_id = value2;
  10963. break;
  10964. case 5:
  10965. md->bl.m = (short)value2;
  10966. break;
  10967. case 6:
  10968. md->bl.x = (short)value2;
  10969. break;
  10970. case 7:
  10971. md->bl.y = (short)value2;
  10972. break;
  10973. case 8:
  10974. md->status.speed = (unsigned short)value2;
  10975. break;
  10976. case 9:
  10977. md->status.mode = (unsigned short)value2;
  10978. break;
  10979. case 10:
  10980. md->special_state.ai = (unsigned int)value2;
  10981. break;
  10982. case 11:
  10983. md->sc.option = (unsigned short)value2;
  10984. break;
  10985. case 12:
  10986. md->vd->sex = (char)value2;
  10987. break;
  10988. case 13:
  10989. md->vd->class_ = (unsigned short)value2;
  10990. break;
  10991. case 14:
  10992. md->vd->hair_style = (unsigned short)value2;
  10993. break;
  10994. case 15:
  10995. md->vd->hair_color = (unsigned short)value2;
  10996. break;
  10997. case 16:
  10998. md->vd->head_bottom = (unsigned short)value2;
  10999. break;
  11000. case 17:
  11001. md->vd->head_mid = (unsigned short)value2;
  11002. break;
  11003. case 18:
  11004. md->vd->head_top = (unsigned short)value2;
  11005. break;
  11006. case 19:
  11007. md->vd->cloth_color = (unsigned short)value2;
  11008. break;
  11009. case 20:
  11010. md->vd->shield = (unsigned short)value2;
  11011. break;
  11012. case 21:
  11013. md->vd->weapon = (unsigned short)value2;
  11014. break;
  11015. case 22:
  11016. md->vd->shield = (unsigned short)value2;
  11017. break;
  11018. case 23:
  11019. md->ud.dir = (unsigned char)value2;
  11020. break;
  11021. case 24:
  11022. md->state.killer = value2>0?1:0;
  11023. break;
  11024. case 25:
  11025. md->callback_flag = (short)value2;
  11026. break;
  11027. case 26:
  11028. md->state.no_random_walk = value2>0?1:0;
  11029. break;
  11030. default:
  11031. ShowError("buildin_setmobdata: argument id is not identified.");
  11032. return -1;
  11033. }
  11034. return 0;
  11035. }
  11036. int buildin_mobassist(struct script_state *st) {
  11037. int id;
  11038. char *target;
  11039. struct mob_data *md = NULL;
  11040. struct block_list *bl = NULL;
  11041. struct unit_data *ud;
  11042. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11043. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11044. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  11045. md = (struct mob_data *)map_id2bl(id);
  11046. if(md && md->bl.type == BL_MOB) {
  11047. ud = unit_bl2ud(bl);
  11048. md->master_id = bl->id;
  11049. md->state.killer = 1;
  11050. mob_convertslave(md);
  11051. if (ud) {
  11052. if (ud->target)
  11053. md->target_id = ud->target;
  11054. else if (ud->skilltarget)
  11055. md->target_id = ud->skilltarget;
  11056. if(md->target_id)
  11057. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  11058. }
  11059. }
  11060. }
  11061. return 0;
  11062. }
  11063. int buildin_mobattach(struct script_state *st){
  11064. int id;
  11065. struct mob_data *md = NULL;
  11066. struct npc_data *nd = NULL;
  11067. char *npcname = NULL;
  11068. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11069. if(st->end > st->start + 3){
  11070. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11071. }
  11072. if(npcname)
  11073. nd = npc_name2id(npcname);
  11074. else
  11075. nd = (struct npc_data *)map_id2bl(st->oid);
  11076. if(nd)
  11077. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  11078. md->nd = nd;
  11079. return 0;
  11080. }
  11081. int buildin_unitwalk(struct script_state *st){
  11082. int id,x,y = 0;
  11083. struct block_list *bl = NULL;
  11084. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11085. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11086. if(st->end > st->start+4)
  11087. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11088. bl = map_id2bl(id);
  11089. if(bl){
  11090. if(y)
  11091. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  11092. else
  11093. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  11094. } else {
  11095. push_val(st->stack,C_INT,0);
  11096. }
  11097. return 0;
  11098. }
  11099. int buildin_unitkill(struct script_state *st){
  11100. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  11101. if(bl)
  11102. status_kill(bl);
  11103. return 0;
  11104. }
  11105. int buildin_unitwarp(struct script_state *st){
  11106. int id,x,y,m = 0;
  11107. char *map;
  11108. struct block_list *bl = NULL;
  11109. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11110. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11111. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11112. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  11113. bl = map_id2bl(id);
  11114. m = map_mapname2mapid(map);
  11115. if(m && bl){
  11116. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  11117. } else {
  11118. push_val(st->stack,C_INT,0);
  11119. }
  11120. return 0;
  11121. }
  11122. int buildin_unitattack(struct script_state *st) {
  11123. int id = 0, actiontype = 0;
  11124. char *target = NULL;
  11125. struct map_session_data *sd = NULL;
  11126. struct block_list *bl = NULL, *tbl = NULL;
  11127. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11128. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11129. if(st->end > st->start + 4)
  11130. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11131. sd = map_nick2sd(target);
  11132. if(!sd)
  11133. tbl = map_id2bl(atoi(target));
  11134. else
  11135. tbl = &sd->bl;
  11136. if((bl = map_id2bl(id))){
  11137. switch (bl->type) {
  11138. case BL_PC:
  11139. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  11140. push_val(st->stack,C_INT,1);
  11141. return 0;
  11142. case BL_MOB:
  11143. ((TBL_MOB *)bl)->state.killer = 1;
  11144. ((TBL_MOB *)bl)->target_id = tbl->id;
  11145. break;
  11146. case BL_PET:
  11147. ((TBL_PET *)bl)->target_id = tbl->id;
  11148. break;
  11149. }
  11150. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  11151. } else {
  11152. push_val(st->stack,C_INT,0);
  11153. }
  11154. return 0;
  11155. }
  11156. int buildin_unitstop(struct script_state *st) {
  11157. int id;
  11158. struct block_list *bl = NULL;
  11159. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11160. bl = map_id2bl(id);
  11161. if(bl){
  11162. unit_stop_attack(bl);
  11163. unit_stop_walking(bl,0);
  11164. if(bl->type == BL_MOB)
  11165. ((TBL_MOB *)bl)->target_id = 0;
  11166. }
  11167. return 0;
  11168. }
  11169. int buildin_unittalk(struct script_state *st)
  11170. {
  11171. char *str;
  11172. int id;
  11173. char message[255];
  11174. struct block_list *bl = NULL;
  11175. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11176. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  11177. bl = map_id2bl(id);
  11178. if(bl) {
  11179. memcpy(message, status_get_name(bl), NAME_LENGTH);
  11180. strcat(message," : ");
  11181. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  11182. clif_message(bl, message);
  11183. if(bl->type == BL_PC)
  11184. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  11185. }
  11186. return 0;
  11187. }
  11188. int buildin_unitemote(struct script_state *st) {
  11189. int id, emo;
  11190. struct block_list *bl= NULL;
  11191. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11192. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11193. if((bl = map_id2bl(id)))
  11194. clif_emotion(bl,emo);
  11195. return 0;
  11196. }
  11197. int buildin_unitdeadsit(struct script_state *st){
  11198. int id, action;
  11199. struct block_list *bl = NULL;
  11200. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11201. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11202. if((bl = map_id2bl(id))){
  11203. if(action > -1 && action < 4){
  11204. unsigned char buf[61] = "";
  11205. struct view_data *vd = status_get_viewdata(bl);
  11206. if (vd) vd->dead_sit = action;
  11207. WBUFW(buf, 0) = 0x8a;
  11208. WBUFL(buf, 2) = bl->id;
  11209. WBUFB(buf,26) = (unsigned char)action;
  11210. clif_send(buf, 61, bl, AREA);
  11211. }else {
  11212. ShowError("buildin_unitdeadsit: Invalid action.\n");
  11213. report_src(st);
  11214. }
  11215. }else{
  11216. ShowError("buildin_unitdeadsit: Target is not found.\n");
  11217. report_src(st);
  11218. }
  11219. return 0;
  11220. }
  11221. int buildin_unitskilluseid (struct script_state *st)
  11222. {
  11223. int id,skid,sklv;
  11224. struct block_list *bl = NULL;
  11225. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11226. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  11227. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  11228. if ((bl = map_id2bl(id)))
  11229. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  11230. return 0;
  11231. }
  11232. int buildin_unitskillusepos(struct script_state *st)
  11233. {
  11234. int skid,sklv,x,y,id;
  11235. struct block_list *bl = NULL;
  11236. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11237. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  11238. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  11239. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  11240. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  11241. if ((bl=map_id2bl(id)))
  11242. unit_skilluse_pos(bl,x,y,skid,sklv);
  11243. return 0;
  11244. }
  11245. // <--- [zBuffer] List of mob control commands
  11246. // sleep <mili sec>
  11247. int buildin_sleep(struct script_state *st) {
  11248. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11249. struct map_session_data *sd = map_id2sd(st->rid);
  11250. if(sd && sd->npc_id == st->oid) {
  11251. sd->npc_id = 0;
  11252. }
  11253. st->rid = 0;
  11254. if(tick <= 0) {
  11255. // 何もしない
  11256. } else if( !st->sleep.tick ) {
  11257. // 初回実行
  11258. st->state = RERUNLINE;
  11259. st->sleep.tick = tick;
  11260. } else {
  11261. // 続行
  11262. st->sleep.tick = 0;
  11263. }
  11264. return 0;
  11265. }
  11266. // sleep2 <mili sec>
  11267. int buildin_sleep2(struct script_state *st) {
  11268. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11269. if( tick <= 0 ) {
  11270. // 0ms の待機時間を指定された
  11271. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11272. } else if( !st->sleep.tick ) {
  11273. // 初回実行時
  11274. st->state = RERUNLINE;
  11275. st->sleep.tick = tick;
  11276. } else {
  11277. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11278. st->sleep.tick = 0;
  11279. }
  11280. return 0;
  11281. }
  11282. /*==========================================
  11283. * 指定NPCの全てのsleepを再開する
  11284. *------------------------------------------
  11285. */
  11286. int buildin_awake(struct script_state *st)
  11287. {
  11288. struct npc_data *nd;
  11289. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  11290. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  11291. if(nd == NULL)
  11292. return 0;
  11293. while( node ) {
  11294. if( (int)node->key == nd->bl.id) {
  11295. struct script_state *tst = node->data;
  11296. struct map_session_data *sd = map_id2sd(tst->rid);
  11297. if( tst->sleep.timer == -1 ) {
  11298. node = node->next;
  11299. continue;
  11300. }
  11301. if((sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd))
  11302. { //Cancel Execution
  11303. tst->state=END;
  11304. tst->rid = 0;
  11305. }
  11306. delete_timer(tst->sleep.timer, run_script_timer);
  11307. node = script_erase_sleepdb(node);
  11308. tst->sleep.timer = -1;
  11309. tst->sleep.tick = 0;
  11310. run_script_main(tst);
  11311. } else {
  11312. node = node->next;
  11313. }
  11314. }
  11315. return 0;
  11316. }
  11317. // getvariableofnpc(<param>, <npc name>);
  11318. int buildin_getvariableofnpc(struct script_state *st)
  11319. {
  11320. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  11321. // 第一引数が変数名じゃない
  11322. printf("getvariableofnpc: param not name\n");
  11323. push_val(st->stack,C_INT,0);
  11324. } else {
  11325. int num = st->stack->stack_data[st->start+2].u.num;
  11326. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  11327. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  11328. struct npc_data *nd = npc_name2id(npc_name);
  11329. if( var_name[0] != '.' || var_name[1] == '@' ) {
  11330. // ' 変数以外はダメ
  11331. printf("getvariableofnpc: invalid scope %s\n", var_name);
  11332. push_val(st->stack,C_INT,0);
  11333. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  11334. // NPC が見つからない or SCRIPT以外のNPC
  11335. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  11336. push_val(st->stack,C_INT,0);
  11337. } else {
  11338. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  11339. }
  11340. }
  11341. return 0;
  11342. }
  11343. // [blackhole89] --->
  11344. // Set a warp portal.
  11345. int buildin_warpportal(struct script_state *st){
  11346. struct skill_unit_group *group;
  11347. unsigned short mapindex;
  11348. long spx,spy,tpx,tpy;
  11349. struct block_list *bl=map_id2bl(st->oid);
  11350. nullpo_retr(0,bl);
  11351. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  11352. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  11353. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  11354. printf("mapindex: %d\n",mapindex);
  11355. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  11356. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  11357. if(!mapindex) return 0;
  11358. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  11359. return 0;
  11360. }
  11361. group->val2=(tpx<<16)|tpy;
  11362. group->val3 = mapindex;
  11363. return 0;
  11364. }
  11365. // <-- [blackhole89]