script.c 322 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524
  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. #ifndef _WIN32
  12. #include <sys/time.h>
  13. #endif
  14. #include <time.h>
  15. #include "../common/socket.h"
  16. #include "../common/timer.h"
  17. #include "../common/malloc.h"
  18. #include "../common/lock.h"
  19. #include "../common/nullpo.h"
  20. #include "../common/showmsg.h"
  21. #include "map.h"
  22. #include "clif.h"
  23. #include "chrif.h"
  24. #include "itemdb.h"
  25. #include "pc.h"
  26. #include "status.h"
  27. #include "script.h"
  28. #include "storage.h"
  29. #include "mob.h"
  30. #include "npc.h"
  31. #include "pet.h"
  32. #include "intif.h"
  33. #include "skill.h"
  34. #include "chat.h"
  35. #include "battle.h"
  36. #include "party.h"
  37. #include "guild.h"
  38. #include "atcommand.h"
  39. #include "charcommand.h"
  40. #include "log.h"
  41. #include "unit.h"
  42. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  43. #include "strlib.h"
  44. #endif
  45. #include "irc.h"
  46. #define SCRIPT_BLOCK_SIZE 256
  47. #define FETCH(n, t) \
  48. if(st->end>st->start+(n)) \
  49. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  50. enum { LABEL_NEXTLINE=1,LABEL_START };
  51. static unsigned char * script_buf = NULL;
  52. static int script_pos,script_size;
  53. char *str_buf;
  54. int str_pos,str_size;
  55. static struct str_data_struct {
  56. int type;
  57. int str;
  58. int backpatch;
  59. int label;
  60. int (*func)(struct script_state *);
  61. int val;
  62. int next;
  63. } *str_data = NULL;
  64. int str_num=LABEL_START,str_data_size;
  65. int str_hash[16];
  66. static struct dbt *mapreg_db=NULL;
  67. static struct dbt *mapregstr_db=NULL;
  68. static int mapreg_dirty=-1;
  69. char mapreg_txt[256]="save/mapreg.txt";
  70. #define MAPREG_AUTOSAVE_INTERVAL (10*1000)
  71. static struct dbt *scriptlabel_db=NULL;
  72. static struct dbt *userfunc_db=NULL;
  73. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  74. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  75. static char pos[11][100] = {"頭","体","左手","右手","ローブ","靴","アクセサリー1","アクセサリー2","頭2","頭3","装着していない"};
  76. struct Script_Config script_config;
  77. static int parse_cmd;
  78. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  79. // [Eoe / jA 1080, 1081, 1094, 1164]
  80. enum { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  81. static struct {
  82. struct {
  83. int type;
  84. int index;
  85. int count;
  86. int flag;
  87. } curly[256]; // 右カッコの情報
  88. int curly_count; // 右カッコの数
  89. int index; // スクリプト内で使用した構文の数
  90. } syntax;
  91. unsigned char* parse_curly_close(unsigned char *p);
  92. unsigned char* parse_syntax_close(unsigned char *p);
  93. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag);
  94. unsigned char* parse_syntax(unsigned char *p);
  95. static int parse_syntax_for_flag = 0;
  96. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  97. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  98. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  99. int potion_target=0;
  100. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  101. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  102. char mapregsql_db[32] = "mapreg";
  103. char mapregsql_db_varname[32] = "varname";
  104. char mapregsql_db_index[32] = "index";
  105. char mapregsql_db_value[32] = "value";
  106. char tmp_sql[65535];
  107. // --------------------------------------------------------
  108. #endif
  109. /*==========================================
  110. * ローカルプロトタイプ宣言 (必要な物のみ)
  111. *------------------------------------------
  112. */
  113. unsigned char* parse_subexpr(unsigned char *,int);
  114. #ifndef TXT_ONLY
  115. int buildin_query_sql(struct script_state *st);
  116. #endif
  117. int buildin_atoi(struct script_state *st);
  118. int buildin_axtoi(struct script_state *st);
  119. int buildin_mes(struct script_state *st);
  120. int buildin_goto(struct script_state *st);
  121. int buildin_callsub(struct script_state *st);
  122. int buildin_callfunc(struct script_state *st);
  123. int buildin_return(struct script_state *st);
  124. int buildin_getarg(struct script_state *st);
  125. int buildin_next(struct script_state *st);
  126. int buildin_close(struct script_state *st);
  127. int buildin_close2(struct script_state *st);
  128. int buildin_menu(struct script_state *st);
  129. int buildin_rand(struct script_state *st);
  130. int buildin_warp(struct script_state *st);
  131. int buildin_areawarp(struct script_state *st);
  132. int buildin_warpchar(struct script_state *st); // [LuzZza]
  133. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  134. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  135. int buildin_heal(struct script_state *st);
  136. int buildin_itemheal(struct script_state *st);
  137. int buildin_percentheal(struct script_state *st);
  138. int buildin_jobchange(struct script_state *st);
  139. int buildin_input(struct script_state *st);
  140. int buildin_setlook(struct script_state *st);
  141. int buildin_set(struct script_state *st);
  142. int buildin_setarray(struct script_state *st);
  143. int buildin_cleararray(struct script_state *st);
  144. int buildin_copyarray(struct script_state *st);
  145. int buildin_getarraysize(struct script_state *st);
  146. int buildin_deletearray(struct script_state *st);
  147. int buildin_getelementofarray(struct script_state *st);
  148. int buildin_getitem(struct script_state *st);
  149. int buildin_getitem2(struct script_state *st);
  150. int buildin_getnameditem(struct script_state *st);
  151. int buildin_grouprandomitem(struct script_state *st);
  152. int buildin_makeitem(struct script_state *st);
  153. int buildin_delitem(struct script_state *st);
  154. int buildin_delitem2(struct script_state *st);
  155. int buildin_enableitemuse(struct script_state *st);
  156. int buildin_disableitemuse(struct script_state *st);
  157. int buildin_viewpoint(struct script_state *st);
  158. int buildin_countitem(struct script_state *st);
  159. int buildin_countitem2(struct script_state *st);
  160. int buildin_checkweight(struct script_state *st);
  161. int buildin_readparam(struct script_state *st);
  162. int buildin_getcharid(struct script_state *st);
  163. int buildin_getpartyname(struct script_state *st);
  164. int buildin_getpartymember(struct script_state *st);
  165. int buildin_getguildname(struct script_state *st);
  166. int buildin_getguildmaster(struct script_state *st);
  167. int buildin_getguildmasterid(struct script_state *st);
  168. int buildin_strcharinfo(struct script_state *st);
  169. int buildin_getequipid(struct script_state *st);
  170. int buildin_getequipname(struct script_state *st);
  171. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  172. int buildin_repair(struct script_state *st); // [Valaris]
  173. int buildin_getequipisequiped(struct script_state *st);
  174. int buildin_getequipisenableref(struct script_state *st);
  175. int buildin_getequipisidentify(struct script_state *st);
  176. int buildin_getequiprefinerycnt(struct script_state *st);
  177. int buildin_getequipweaponlv(struct script_state *st);
  178. int buildin_getequippercentrefinery(struct script_state *st);
  179. int buildin_successrefitem(struct script_state *st);
  180. int buildin_failedrefitem(struct script_state *st);
  181. int buildin_cutin(struct script_state *st);
  182. int buildin_cutincard(struct script_state *st);
  183. int buildin_statusup(struct script_state *st);
  184. int buildin_statusup2(struct script_state *st);
  185. int buildin_bonus(struct script_state *st);
  186. int buildin_bonus2(struct script_state *st);
  187. int buildin_bonus3(struct script_state *st);
  188. int buildin_bonus4(struct script_state *st);
  189. int buildin_skill(struct script_state *st);
  190. int buildin_addtoskill(struct script_state *st); // [Valaris]
  191. int buildin_guildskill(struct script_state *st);
  192. int buildin_getskilllv(struct script_state *st);
  193. int buildin_getgdskilllv(struct script_state *st);
  194. int buildin_basicskillcheck(struct script_state *st);
  195. int buildin_getgmlevel(struct script_state *st);
  196. int buildin_end(struct script_state *st);
  197. int buildin_checkoption(struct script_state *st);
  198. int buildin_setoption(struct script_state *st);
  199. int buildin_setcart(struct script_state *st);
  200. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  201. int buildin_setfalcon(struct script_state *st);
  202. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  203. int buildin_setriding(struct script_state *st);
  204. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  205. int buildin_savepoint(struct script_state *st);
  206. int buildin_gettimetick(struct script_state *st);
  207. int buildin_gettime(struct script_state *st);
  208. int buildin_gettimestr(struct script_state *st);
  209. int buildin_openstorage(struct script_state *st);
  210. int buildin_guildopenstorage(struct script_state *st);
  211. int buildin_itemskill(struct script_state *st);
  212. int buildin_produce(struct script_state *st);
  213. int buildin_monster(struct script_state *st);
  214. int buildin_areamonster(struct script_state *st);
  215. int buildin_killmonster(struct script_state *st);
  216. int buildin_killmonsterall(struct script_state *st);
  217. int buildin_clone(struct script_state *st);
  218. int buildin_doevent(struct script_state *st);
  219. int buildin_donpcevent(struct script_state *st);
  220. int buildin_addtimer(struct script_state *st);
  221. int buildin_deltimer(struct script_state *st);
  222. int buildin_addtimercount(struct script_state *st);
  223. int buildin_initnpctimer(struct script_state *st);
  224. int buildin_stopnpctimer(struct script_state *st);
  225. int buildin_startnpctimer(struct script_state *st);
  226. int buildin_setnpctimer(struct script_state *st);
  227. int buildin_getnpctimer(struct script_state *st);
  228. int buildin_attachnpctimer(struct script_state *st); // [celest]
  229. int buildin_detachnpctimer(struct script_state *st); // [celest]
  230. int buildin_playerattached(struct script_state *st); // [Skotlex]
  231. int buildin_announce(struct script_state *st);
  232. int buildin_mapannounce(struct script_state *st);
  233. int buildin_areaannounce(struct script_state *st);
  234. int buildin_getusers(struct script_state *st);
  235. int buildin_getmapusers(struct script_state *st);
  236. int buildin_getareausers(struct script_state *st);
  237. int buildin_getareadropitem(struct script_state *st);
  238. int buildin_enablenpc(struct script_state *st);
  239. int buildin_disablenpc(struct script_state *st);
  240. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  241. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  242. int buildin_hideoffnpc(struct script_state *st);
  243. int buildin_hideonnpc(struct script_state *st);
  244. int buildin_sc_start(struct script_state *st);
  245. int buildin_sc_start2(struct script_state *st);
  246. int buildin_sc_start4(struct script_state *st);
  247. int buildin_sc_end(struct script_state *st);
  248. int buildin_getscrate(struct script_state *st);
  249. int buildin_debugmes(struct script_state *st);
  250. int buildin_catchpet(struct script_state *st);
  251. int buildin_birthpet(struct script_state *st);
  252. int buildin_resetlvl(struct script_state *st);
  253. int buildin_resetstatus(struct script_state *st);
  254. int buildin_resetskill(struct script_state *st);
  255. int buildin_changebase(struct script_state *st);
  256. int buildin_changesex(struct script_state *st);
  257. int buildin_waitingroom(struct script_state *st);
  258. int buildin_delwaitingroom(struct script_state *st);
  259. int buildin_enablewaitingroomevent(struct script_state *st);
  260. int buildin_disablewaitingroomevent(struct script_state *st);
  261. int buildin_getwaitingroomstate(struct script_state *st);
  262. int buildin_warpwaitingpc(struct script_state *st);
  263. int buildin_attachrid(struct script_state *st);
  264. int buildin_detachrid(struct script_state *st);
  265. int buildin_isloggedin(struct script_state *st);
  266. int buildin_setmapflagnosave(struct script_state *st);
  267. int buildin_setmapflag(struct script_state *st);
  268. int buildin_removemapflag(struct script_state *st);
  269. int buildin_pvpon(struct script_state *st);
  270. int buildin_pvpoff(struct script_state *st);
  271. int buildin_gvgon(struct script_state *st);
  272. int buildin_gvgoff(struct script_state *st);
  273. int buildin_emotion(struct script_state *st);
  274. int buildin_maprespawnguildid(struct script_state *st);
  275. int buildin_agitstart(struct script_state *st); // <Agit>
  276. int buildin_agitend(struct script_state *st);
  277. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  278. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  279. int buildin_getcastlename(struct script_state *st);
  280. int buildin_getcastledata(struct script_state *st);
  281. int buildin_setcastledata(struct script_state *st);
  282. int buildin_requestguildinfo(struct script_state *st);
  283. int buildin_getequipcardcnt(struct script_state *st);
  284. int buildin_successremovecards(struct script_state *st);
  285. int buildin_failedremovecards(struct script_state *st);
  286. int buildin_marriage(struct script_state *st);
  287. int buildin_wedding_effect(struct script_state *st);
  288. int buildin_divorce(struct script_state *st);
  289. int buildin_ispartneron(struct script_state *st); // MouseJstr
  290. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  291. int buildin_getchildid(struct script_state *st); // Skotlex
  292. int buildin_getmotherid(struct script_state *st); // Lupus
  293. int buildin_getfatherid(struct script_state *st); // Lupus
  294. int buildin_warppartner(struct script_state *st); // MouseJstr
  295. int buildin_getitemname(struct script_state *st);
  296. int buildin_getitemslots(struct script_state *st);
  297. int buildin_makepet(struct script_state *st);
  298. int buildin_getexp(struct script_state *st);
  299. int buildin_getinventorylist(struct script_state *st);
  300. int buildin_getskilllist(struct script_state *st);
  301. int buildin_clearitem(struct script_state *st);
  302. int buildin_classchange(struct script_state *st);
  303. int buildin_misceffect(struct script_state *st);
  304. int buildin_soundeffect(struct script_state *st);
  305. int buildin_soundeffectall(struct script_state *st);
  306. int buildin_setcastledata(struct script_state *st);
  307. int buildin_mapwarp(struct script_state *st);
  308. int buildin_inittimer(struct script_state *st);
  309. int buildin_stoptimer(struct script_state *st);
  310. int buildin_cmdothernpc(struct script_state *st);
  311. int buildin_mobcount(struct script_state *st);
  312. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  313. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  314. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  315. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  316. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  317. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  318. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  319. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  320. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  321. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  322. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  323. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  324. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  325. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  326. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  327. int buildin_nude(struct script_state *st); // nude [Valaris]
  328. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  329. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  330. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  331. int buildin_message(struct script_state *st); // [MouseJstr]
  332. int buildin_npctalk(struct script_state *st); // [Valaris]
  333. int buildin_hasitems(struct script_state *st); // [Valaris]
  334. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  335. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  336. int buildin_npcspeed(struct script_state *st); // [Valaris]
  337. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  338. int buildin_npcstop(struct script_state *st); // [Valaris]
  339. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  340. int buildin_checkoption1(struct script_state *st); // [celest]
  341. int buildin_checkoption2(struct script_state *st); // [celest]
  342. int buildin_guildgetexp(struct script_state *st); // [celest]
  343. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  344. int buildin_skilluseid(struct script_state *st); // originally by Qamera [celest]
  345. int buildin_skillusepos(struct script_state *st); // originally by Qamera [celest]
  346. int buildin_logmes(struct script_state *st); // [Lupus]
  347. int buildin_summon(struct script_state *st); // [celest]
  348. int buildin_isnight(struct script_state *st); // [celest]
  349. int buildin_isday(struct script_state *st); // [celest]
  350. int buildin_isequipped(struct script_state *st); // [celest]
  351. int buildin_isequippedcnt(struct script_state *st); // [celest]
  352. int buildin_cardscnt(struct script_state *st); // [Lupus]
  353. int buildin_getrefine(struct script_state *st); // [celest]
  354. int buildin_adopt(struct script_state *st);
  355. int buildin_night(struct script_state *st);
  356. int buildin_day(struct script_state *st);
  357. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  358. int buildin_dispbottom(struct script_state *st);
  359. int buildin_recovery(struct script_state *st);
  360. int buildin_getpetinfo(struct script_state *st);
  361. int buildin_checkequipedcard(struct script_state *st);
  362. int buildin_globalmes(struct script_state *st);
  363. int buildin_jump_zero(struct script_state *st);
  364. int buildin_select(struct script_state *st);
  365. int buildin_getmapmobs(struct script_state *st); //jA addition end
  366. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  367. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  368. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  369. int buildin_fakenpcname(struct script_state *st); // [Lance]
  370. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  371. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  372. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  373. // [zBuffer] List of mathematics commands --->
  374. int buildin_sqrt(struct script_state *st);
  375. int buildin_pow(struct script_state *st);
  376. int buildin_distance(struct script_state *st);
  377. // <--- [zBuffer] List of mathematics commands
  378. // [zBuffer] List of dynamic var commands --->
  379. int buildin_getd(struct script_state *st);
  380. int buildin_setd(struct script_state *st);
  381. // <--- [zBuffer] List of dynamic var commands
  382. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  383. int buildin_callshop(struct script_state *st); // [Skotlex]
  384. int buildin_npcshopitem(struct script_state *st); // [Lance]
  385. int buildin_equip(struct script_state *st);
  386. int buildin_autoequip(struct script_state *st);
  387. int buildin_setbattleflag(struct script_state *st);
  388. // [zBuffer] List of player cont commands --->
  389. int buildin_rid2name(struct script_state *st);
  390. int buildin_pcwalkxy(struct script_state *st);
  391. int buildin_pctalk(struct script_state *st);
  392. int buildin_pcemote(struct script_state *st);
  393. int buildin_pcfollow(struct script_state *st);
  394. int buildin_pcstopfollow(struct script_state *st);
  395. int buildin_pcblockmove(struct script_state *st);
  396. // <--- [zBuffer] List of player cont commands
  397. // [zBuffer] List of mob control commands --->
  398. int buildin_spawnmob(struct script_state *st);
  399. int buildin_removemob(struct script_state *st);
  400. int buildin_mobwalk(struct script_state *st);
  401. int buildin_getmobdata(struct script_state *st);
  402. int buildin_setmobdata(struct script_state *st);
  403. int buildin_mobattack(struct script_state *st);
  404. int buildin_mobstop(struct script_state *st);
  405. int buildin_mobassist(struct script_state *st);
  406. int buildin_mobtalk(struct script_state *st);
  407. int buildin_mobemote(struct script_state *st);
  408. int buildin_mobattach(struct script_state *st);
  409. // <--- [zBuffer] List of mob control commands
  410. void push_val(struct script_stack *stack,int type,int val);
  411. int run_func(struct script_state *st);
  412. int mapreg_setreg(int num,int val);
  413. int mapreg_setregstr(int num,const char *str);
  414. int buildin_setitemscript(struct script_state *st);
  415. int buildin_disguise(struct script_state *st);
  416. int buildin_undisguise(struct script_state *st);
  417. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  418. #ifdef PCRE_SUPPORT
  419. int buildin_defpattern(struct script_state *st); // MouseJstr
  420. int buildin_activatepset(struct script_state *st); // MouseJstr
  421. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  422. int buildin_deletepset(struct script_state *st); // MouseJstr
  423. #endif
  424. struct {
  425. int (*func)(struct script_state *);
  426. char *name;
  427. char *arg;
  428. } buildin_func[]={
  429. {buildin_axtoi,"axtoi","s"},
  430. #ifndef TXT_ONLY
  431. {buildin_query_sql, "query_sql", "s*"},
  432. #endif
  433. {buildin_atoi,"atoi","s"},
  434. {buildin_mes,"mes","s"},
  435. {buildin_next,"next",""},
  436. {buildin_close,"close",""},
  437. {buildin_close2,"close2",""},
  438. {buildin_menu,"menu","*"},
  439. {buildin_goto,"goto","l"},
  440. {buildin_callsub,"callsub","i*"},
  441. {buildin_callfunc,"callfunc","s*"},
  442. {buildin_return,"return","*"},
  443. {buildin_getarg,"getarg","i"},
  444. {buildin_jobchange,"jobchange","i*"},
  445. {buildin_input,"input","*"},
  446. {buildin_warp,"warp","sii"},
  447. {buildin_areawarp,"areawarp","siiiisii"},
  448. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  449. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  450. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  451. {buildin_setlook,"setlook","ii"},
  452. {buildin_set,"set","ii"},
  453. {buildin_setarray,"setarray","ii*"},
  454. {buildin_cleararray,"cleararray","iii"},
  455. {buildin_copyarray,"copyarray","iii"},
  456. {buildin_getarraysize,"getarraysize","i"},
  457. {buildin_deletearray,"deletearray","ii"},
  458. {buildin_getelementofarray,"getelementofarray","ii"},
  459. {buildin_getitem,"getitem","ii**"},
  460. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  461. {buildin_getnameditem,"getnameditem","is"},
  462. {buildin_grouprandomitem,"groupranditem","i"},
  463. {buildin_makeitem,"makeitem","iisii"},
  464. {buildin_delitem,"delitem","ii"},
  465. {buildin_delitem2,"delitem2","iiiiiiiii"},
  466. {buildin_enableitemuse,"enable_items",""},
  467. {buildin_disableitemuse,"disable_items",""},
  468. {buildin_cutin,"cutin","si"},
  469. {buildin_cutincard,"cutincard","i"},
  470. {buildin_viewpoint,"viewpoint","iiiii"},
  471. {buildin_heal,"heal","ii"},
  472. {buildin_itemheal,"itemheal","ii"},
  473. {buildin_percentheal,"percentheal","ii"},
  474. {buildin_rand,"rand","i*"},
  475. {buildin_countitem,"countitem","i"},
  476. {buildin_countitem2,"countitem2","iiiiiiii"},
  477. {buildin_checkweight,"checkweight","ii"},
  478. {buildin_readparam,"readparam","i*"},
  479. {buildin_getcharid,"getcharid","i*"},
  480. {buildin_getpartyname,"getpartyname","i"},
  481. {buildin_getpartymember,"getpartymember","i"},
  482. {buildin_getguildname,"getguildname","i"},
  483. {buildin_getguildmaster,"getguildmaster","i"},
  484. {buildin_getguildmasterid,"getguildmasterid","i"},
  485. {buildin_strcharinfo,"strcharinfo","i"},
  486. {buildin_getequipid,"getequipid","i"},
  487. {buildin_getequipname,"getequipname","i"},
  488. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  489. {buildin_repair,"repair","i"}, // [Valaris]
  490. {buildin_getequipisequiped,"getequipisequiped","i"},
  491. {buildin_getequipisenableref,"getequipisenableref","i"},
  492. {buildin_getequipisidentify,"getequipisidentify","i"},
  493. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  494. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  495. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  496. {buildin_successrefitem,"successrefitem","i"},
  497. {buildin_failedrefitem,"failedrefitem","i"},
  498. {buildin_statusup,"statusup","i"},
  499. {buildin_statusup2,"statusup2","ii"},
  500. {buildin_bonus,"bonus","ii"},
  501. {buildin_bonus2,"bonus2","iii"},
  502. {buildin_bonus3,"bonus3","iiii"},
  503. {buildin_bonus4,"bonus4","iiiii"},
  504. {buildin_skill,"skill","ii*"},
  505. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  506. {buildin_guildskill,"guildskill","ii"},
  507. {buildin_getskilllv,"getskilllv","i"},
  508. {buildin_getgdskilllv,"getgdskilllv","ii"},
  509. {buildin_basicskillcheck,"basicskillcheck","*"},
  510. {buildin_getgmlevel,"getgmlevel","*"},
  511. {buildin_end,"end",""},
  512. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  513. {buildin_checkoption,"checkoption","i"},
  514. {buildin_setoption,"setoption","i"},
  515. {buildin_setcart,"setcart",""},
  516. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  517. {buildin_setfalcon,"setfalcon",""},
  518. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  519. {buildin_setriding,"setriding",""},
  520. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  521. {buildin_savepoint,"save","sii"},
  522. {buildin_savepoint,"savepoint","sii"},
  523. {buildin_gettimetick,"gettimetick","i"},
  524. {buildin_gettime,"gettime","i"},
  525. {buildin_gettimestr,"gettimestr","si"},
  526. {buildin_openstorage,"openstorage",""},
  527. {buildin_guildopenstorage,"guildopenstorage","*"},
  528. {buildin_itemskill,"itemskill","iis"},
  529. {buildin_produce,"produce","i"},
  530. {buildin_monster,"monster","siisii*"},
  531. {buildin_areamonster,"areamonster","siiiisii*"},
  532. {buildin_killmonster,"killmonster","ss"},
  533. {buildin_killmonsterall,"killmonsterall","s"},
  534. {buildin_clone,"clone","siisi*"},
  535. {buildin_doevent,"doevent","s"},
  536. {buildin_donpcevent,"donpcevent","s"},
  537. {buildin_addtimer,"addtimer","is"},
  538. {buildin_deltimer,"deltimer","s"},
  539. {buildin_addtimercount,"addtimercount","si"},
  540. {buildin_initnpctimer,"initnpctimer","*"},
  541. {buildin_stopnpctimer,"stopnpctimer","*"},
  542. {buildin_startnpctimer,"startnpctimer","*"},
  543. {buildin_setnpctimer,"setnpctimer","*"},
  544. {buildin_getnpctimer,"getnpctimer","i*"},
  545. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  546. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  547. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  548. {buildin_announce,"announce","si*"},
  549. {buildin_mapannounce,"mapannounce","ssi*"},
  550. {buildin_areaannounce,"areaannounce","siiiisi*"},
  551. {buildin_getusers,"getusers","i"},
  552. {buildin_getmapusers,"getmapusers","s"},
  553. {buildin_getareausers,"getareausers","siiii"},
  554. {buildin_getareadropitem,"getareadropitem","siiiii"},
  555. {buildin_enablenpc,"enablenpc","s"},
  556. {buildin_disablenpc,"disablenpc","s"},
  557. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  558. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  559. {buildin_hideoffnpc,"hideoffnpc","s"},
  560. {buildin_hideonnpc,"hideonnpc","s"},
  561. {buildin_sc_start,"sc_start","iii*"},
  562. {buildin_sc_start2,"sc_start2","iiii*"},
  563. {buildin_sc_start4,"sc_start4","iiiiii*"},
  564. {buildin_sc_end,"sc_end","i"},
  565. {buildin_getscrate,"getscrate","ii*"},
  566. {buildin_debugmes,"debugmes","s"},
  567. {buildin_catchpet,"pet","i"},
  568. {buildin_birthpet,"bpet",""},
  569. {buildin_resetlvl,"resetlvl","i"},
  570. {buildin_resetstatus,"resetstatus",""},
  571. {buildin_resetskill,"resetskill",""},
  572. {buildin_changebase,"changebase","i"},
  573. {buildin_changesex,"changesex",""},
  574. {buildin_waitingroom,"waitingroom","si*"},
  575. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  576. {buildin_delwaitingroom,"delwaitingroom","*"},
  577. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  578. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  579. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  580. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  581. {buildin_attachrid,"attachrid","i"},
  582. {buildin_detachrid,"detachrid",""},
  583. {buildin_isloggedin,"isloggedin","i"},
  584. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  585. {buildin_setmapflag,"setmapflag","si"},
  586. {buildin_removemapflag,"removemapflag","si"},
  587. {buildin_pvpon,"pvpon","s"},
  588. {buildin_pvpoff,"pvpoff","s"},
  589. {buildin_gvgon,"gvgon","s"},
  590. {buildin_gvgoff,"gvgoff","s"},
  591. {buildin_emotion,"emotion","i*"},
  592. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  593. {buildin_agitstart,"agitstart",""}, // <Agit>
  594. {buildin_agitend,"agitend",""},
  595. {buildin_agitcheck,"agitcheck","i"}, // <Agitcheck>
  596. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  597. {buildin_getcastlename,"getcastlename","s"},
  598. {buildin_getcastledata,"getcastledata","si*"},
  599. {buildin_setcastledata,"setcastledata","sii"},
  600. {buildin_requestguildinfo,"requestguildinfo","i*"},
  601. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  602. {buildin_successremovecards,"successremovecards","i"},
  603. {buildin_failedremovecards,"failedremovecards","ii"},
  604. {buildin_marriage,"marriage","s"},
  605. {buildin_wedding_effect,"wedding",""},
  606. {buildin_divorce,"divorce",""},
  607. {buildin_ispartneron,"ispartneron",""},
  608. {buildin_getpartnerid,"getpartnerid",""},
  609. {buildin_getchildid,"getchildid",""},
  610. {buildin_getmotherid,"getmotherid",""},
  611. {buildin_getfatherid,"getfatherid",""},
  612. {buildin_warppartner,"warppartner","sii"},
  613. {buildin_getitemname,"getitemname","i"},
  614. {buildin_getitemslots,"getitemslots","i"},
  615. {buildin_makepet,"makepet","i"},
  616. {buildin_getexp,"getexp","ii"},
  617. {buildin_getinventorylist,"getinventorylist",""},
  618. {buildin_getskilllist,"getskilllist",""},
  619. {buildin_clearitem,"clearitem",""},
  620. {buildin_classchange,"classchange","ii"},
  621. {buildin_misceffect,"misceffect","i"},
  622. {buildin_soundeffect,"soundeffect","si"},
  623. {buildin_soundeffectall,"soundeffectall","*"}, // SoundEffectAll [Codemaster]
  624. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  625. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  626. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  627. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  628. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  629. {buildin_petloot,"petloot","i"}, // [Valaris]
  630. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  631. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  632. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  633. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  634. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  635. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  636. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  637. {buildin_specialeffect,"specialeffect","i"}, // npc skill effect [Valaris]
  638. {buildin_specialeffect2,"specialeffect2","i"}, // skill effect on players[Valaris]
  639. {buildin_nude,"nude",""}, // nude command [Valaris]
  640. {buildin_mapwarp,"mapwarp","ssii"}, // Added by RoVeRT
  641. {buildin_inittimer,"inittimer",""},
  642. {buildin_stoptimer,"stoptimer",""},
  643. {buildin_cmdothernpc,"cmdothernpc","ss"},
  644. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  645. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  646. // {buildin_movenpc,"movenpc","siis"}, // [MouseJstr]
  647. {buildin_message,"message","s*"}, // [MouseJstr]
  648. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  649. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  650. {buildin_mobcount,"mobcount","ss"},
  651. {buildin_getlook,"getlook","i"},
  652. {buildin_getsavepoint,"getsavepoint","i"},
  653. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  654. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  655. {buildin_npcstop,"npcstop",""}, // [Valaris]
  656. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  657. {buildin_checkoption1,"checkoption1","i"},
  658. {buildin_checkoption2,"checkoption2","i"},
  659. {buildin_guildgetexp,"guildgetexp","i"},
  660. {buildin_guildchangegm,"guildchangegm","is"},
  661. {buildin_skilluseid,"skilluseid","ii"}, // originally by Qamera [Celest]
  662. {buildin_skilluseid,"doskill","ii"}, // since a lot of scripts would already use 'doskill'...
  663. {buildin_skillusepos,"skillusepos","iiii"}, // [Celest]
  664. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  665. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  666. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  667. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  668. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  669. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  670. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  671. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  672. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  673. {buildin_night,"night",""}, // sets the server to night time
  674. {buildin_day,"day",""}, // sets the server to day time
  675. #ifdef PCRE_SUPPORT
  676. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  677. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  678. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  679. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  680. #endif
  681. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  682. {buildin_getusersname,"getusersname","*"},
  683. {buildin_recovery,"recovery",""},
  684. {buildin_getpetinfo,"getpetinfo","i"},
  685. {buildin_checkequipedcard,"checkequipedcard","i"},
  686. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  687. {buildin_select,"select","*"}, //for future jA script compatibility
  688. {buildin_globalmes,"globalmes","s*"},
  689. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  690. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  691. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  692. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  693. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  694. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  695. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  696. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  697. // [zBuffer] List of mathematics commands --->
  698. {buildin_sqrt,"sqrt","i"},
  699. {buildin_pow,"pow","ii"},
  700. {buildin_distance,"distance","iiii"},
  701. // <--- [zBuffer] List of mathematics commands
  702. // [zBuffer] List of dynamic var commands --->
  703. {buildin_getd,"getd","*"},
  704. {buildin_setd,"setd","*"},
  705. // <--- [zBuffer] List of dynamic var commands
  706. {buildin_petstat,"petstat","i"},
  707. {buildin_callshop,"callshop","si"}, // [Skotlex]
  708. {buildin_npcshopitem,"npcshopitem","*"}, // [Lance]
  709. {buildin_equip,"equip","i"},
  710. {buildin_autoequip,"autoequip","ii"},
  711. {buildin_setbattleflag,"setbattleflag","ss"},
  712. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  713. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  714. {buildin_undisguise,"undisguise","i"}, //undisguise player. Lupus
  715. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  716. // [zBuffer] List of player cont commands --->
  717. {buildin_rid2name,"rid2name","i"},
  718. {buildin_pcwalkxy,"pcwalkxy","iii"},
  719. {buildin_pctalk,"pctalk","is"},
  720. {buildin_pcemote,"pcemote","ii"},
  721. {buildin_pcfollow,"pcfollow","ii"},
  722. {buildin_pcstopfollow,"pcstopfollow","i"},
  723. {buildin_pcblockmove,"pcblockmove","ii"},
  724. // <--- [zBuffer] List of player cont commands
  725. // [zBuffer] List of mob control commands --->
  726. {buildin_spawnmob,"spawnmob","*"},
  727. {buildin_removemob,"removemob","*"},
  728. {buildin_mobwalk,"mobwalk","*"},
  729. {buildin_getmobdata,"getmobdata","*"},
  730. {buildin_setmobdata,"setmobdata","*"},
  731. {buildin_mobattack,"mobattack","*"},
  732. {buildin_mobstop,"mobstop","*"},
  733. {buildin_mobassist,"mobassist","*"},
  734. {buildin_mobtalk,"mobtalk","*"},
  735. {buildin_mobemote,"mobemote","*"},
  736. {buildin_mobattach,"mobattach","*"},
  737. // <--- [zBuffer] List of mob control commands
  738. {NULL,NULL,NULL},
  739. };
  740. enum {
  741. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  742. C_NAME,C_EOL, C_RETINFO,
  743. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  744. C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  745. 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
  746. };
  747. //Reports on the console the src of an script error.
  748. static void report_src(struct script_state *st) {
  749. struct block_list *bl;
  750. if (!st->oid) return; //Can't report source.
  751. bl = map_id2bl(st->oid);
  752. if (!bl) return;
  753. switch (bl->type) {
  754. case BL_NPC:
  755. if (bl->m >=0)
  756. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  757. else
  758. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  759. break;
  760. default:
  761. if (bl->m >=0)
  762. ShowDebug("Source (Non-NPC): type %d at %s (%d,%d)\n", bl->type, map[bl->m].name, bl->x, bl->y);
  763. else
  764. ShowDebug("Source (Non-NPC): type %d (invisible/not on a map)\n", bl->type);
  765. break;
  766. }
  767. }
  768. /*==========================================
  769. * 文字列のハッシュを計算
  770. *------------------------------------------
  771. */
  772. static int calc_hash(const unsigned char *p)
  773. {
  774. int h=0;
  775. while(*p){
  776. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  777. h+=*p++;
  778. }
  779. return h&15;
  780. }
  781. /*==========================================
  782. * str_dataの中に名前があるか検索する
  783. *------------------------------------------
  784. */
  785. // 既存のであれば番号、無ければ-1
  786. static int search_str(const unsigned char *p)
  787. {
  788. int i;
  789. i=str_hash[calc_hash(p)];
  790. while(i){
  791. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  792. return i;
  793. }
  794. i=str_data[i].next;
  795. }
  796. return -1;
  797. }
  798. /*==========================================
  799. * str_dataに名前を登録
  800. *------------------------------------------
  801. */
  802. // 既存のであれば番号、無ければ登録して新規番号
  803. static int add_str(const unsigned char *p)
  804. {
  805. int i;
  806. char *lowcase;
  807. lowcase=aStrdup((char *) p);
  808. for(i=0;lowcase[i];i++)
  809. lowcase[i]=tolower(lowcase[i]);
  810. if((i=search_str((unsigned char *) lowcase))>=0){
  811. aFree(lowcase);
  812. return i;
  813. }
  814. aFree(lowcase);
  815. i=calc_hash(p);
  816. if(str_hash[i]==0){
  817. str_hash[i]=str_num;
  818. } else {
  819. i=str_hash[i];
  820. for(;;){
  821. if(strcmp(str_buf+str_data[i].str,(char *) p)==0){
  822. return i;
  823. }
  824. if(str_data[i].next==0)
  825. break;
  826. i=str_data[i].next;
  827. }
  828. str_data[i].next=str_num;
  829. }
  830. if(str_num>=str_data_size){
  831. str_data_size+=128;
  832. str_data=(struct str_data_struct *) aRealloc(str_data,sizeof(str_data[0])*str_data_size);
  833. memset(str_data + (str_data_size - 128), '\0', 128);
  834. }
  835. while(str_pos+(int)strlen((char *) p)+1>=str_size){
  836. str_size+=256;
  837. str_buf=(char *)aRealloc(str_buf,str_size);
  838. memset(str_buf + (str_size - 256), '\0', 256);
  839. }
  840. strcpy(str_buf+str_pos, (char *) p);
  841. str_data[str_num].type=C_NOP;
  842. str_data[str_num].str=str_pos;
  843. str_data[str_num].next=0;
  844. str_data[str_num].func=NULL;
  845. str_data[str_num].backpatch=-1;
  846. str_data[str_num].label=-1;
  847. str_pos+=(int)strlen( (char *) p)+1;
  848. return str_num++;
  849. }
  850. /*==========================================
  851. * スクリプトバッファサイズの確認と拡張
  852. *------------------------------------------
  853. */
  854. static void check_script_buf(int size)
  855. {
  856. if(script_pos+size>=script_size){
  857. script_size+=SCRIPT_BLOCK_SIZE;
  858. script_buf=(unsigned char *)aRealloc(script_buf,script_size);
  859. memset(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  860. SCRIPT_BLOCK_SIZE);
  861. }
  862. }
  863. /*==========================================
  864. * スクリプトバッファに1バイト書き込む
  865. *------------------------------------------
  866. */
  867. static void add_scriptb(int a)
  868. {
  869. check_script_buf(1);
  870. script_buf[script_pos++]=a;
  871. }
  872. /*==========================================
  873. * スクリプトバッファにデータタイプを書き込む
  874. *------------------------------------------
  875. */
  876. static void add_scriptc(int a)
  877. {
  878. while(a>=0x40){
  879. add_scriptb((a&0x3f)|0x40);
  880. a=(a-0x40)>>6;
  881. }
  882. add_scriptb(a&0x3f);
  883. }
  884. /*==========================================
  885. * スクリプトバッファに整数を書き込む
  886. *------------------------------------------
  887. */
  888. static void add_scripti(int a)
  889. {
  890. while(a>=0x40){
  891. add_scriptb(a|0xc0);
  892. a=(a-0x40)>>6;
  893. }
  894. add_scriptb(a|0x80);
  895. }
  896. /*==========================================
  897. * スクリプトバッファにラベル/変数/関数を書き込む
  898. *------------------------------------------
  899. */
  900. // 最大16Mまで
  901. static void add_scriptl(int l)
  902. {
  903. int backpatch = str_data[l].backpatch;
  904. switch(str_data[l].type){
  905. case C_POS:
  906. case C_USERFUNC_POS:
  907. add_scriptc(C_POS);
  908. add_scriptb(str_data[l].label);
  909. add_scriptb(str_data[l].label>>8);
  910. add_scriptb(str_data[l].label>>16);
  911. break;
  912. case C_NOP:
  913. case C_USERFUNC:
  914. // ラベルの可能性があるのでbackpatch用データ埋め込み
  915. add_scriptc(C_NAME);
  916. str_data[l].backpatch=script_pos;
  917. add_scriptb(backpatch);
  918. add_scriptb(backpatch>>8);
  919. add_scriptb(backpatch>>16);
  920. break;
  921. case C_INT:
  922. add_scripti(str_data[l].val);
  923. break;
  924. default:
  925. // もう他の用途と確定してるので数字をそのまま
  926. add_scriptc(C_NAME);
  927. add_scriptb(l);
  928. add_scriptb(l>>8);
  929. add_scriptb(l>>16);
  930. break;
  931. }
  932. }
  933. /*==========================================
  934. * ラベルを解決する
  935. *------------------------------------------
  936. */
  937. void set_label(int l,int pos)
  938. {
  939. int i,next;
  940. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  941. str_data[l].label=pos;
  942. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  943. next=(*(int*)(script_buf+i)) & 0x00ffffff;
  944. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  945. script_buf[i]=pos;
  946. script_buf[i+1]=pos>>8;
  947. script_buf[i+2]=pos>>16;
  948. i=next;
  949. }
  950. }
  951. /*==========================================
  952. * スペース/コメント読み飛ばし
  953. *------------------------------------------
  954. */
  955. static unsigned char *skip_space(unsigned char *p)
  956. {
  957. while(1){
  958. while(isspace(*p))
  959. p++;
  960. if(p[0]=='/' && p[1]=='/'){
  961. while(*p && *p!='\n')
  962. p++;
  963. } else if(p[0]=='/' && p[1]=='*'){
  964. p++;
  965. while(*p && (p[-1]!='*' || p[0]!='/'))
  966. p++;
  967. if(*p) p++;
  968. } else
  969. break;
  970. }
  971. return p;
  972. }
  973. /*==========================================
  974. * 1単語スキップ
  975. *------------------------------------------
  976. */
  977. static unsigned char *skip_word(unsigned char *p)
  978. {
  979. // prefix
  980. if(*p=='$') p++; // MAP鯖内共有変数用
  981. if(*p=='@') p++; // 一時的変数用(like weiss)
  982. if(*p=='#') p++; // account変数用
  983. if(*p=='#') p++; // ワールドaccount変数用
  984. while(isalnum(*p)||*p=='_'|| *p>=0x81)
  985. if(*p>=0x81 && p[1]){
  986. p+=2;
  987. } else
  988. p++;
  989. // postfix
  990. if(*p=='$') p++; // 文字列変数
  991. return p;
  992. }
  993. static unsigned char *startptr;
  994. static int startline;
  995. /*==========================================
  996. * エラーメッセージ出力
  997. *------------------------------------------
  998. */
  999. static void disp_error_message(const char *mes,const unsigned char *pos)
  1000. {
  1001. int line,c=0,i;
  1002. unsigned char *p,*linestart,*lineend;
  1003. for(line=startline,p=startptr;p && *p;line++){
  1004. linestart=p;
  1005. lineend=(unsigned char *) strchr((char *) p,'\n');
  1006. if(lineend){
  1007. c=*lineend;
  1008. *lineend=0;
  1009. }
  1010. if(lineend==NULL || pos<lineend){
  1011. fprintf(stderr, "\r"); //To not printout the error next to the spinner...
  1012. ShowError(" "); //Better error display [Skotlex]
  1013. if (current_file) {
  1014. printf("%s in "CL_WHITE"\'%s\'"CL_RESET" line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, current_file, line);
  1015. } else {
  1016. printf("%s line "CL_WHITE"\'%d\'"CL_RESET" : ", mes, line);
  1017. }
  1018. for(i=0;(linestart[i]!='\r') && (linestart[i]!='\n') && linestart[i];i++){
  1019. if(linestart+i!=pos)
  1020. printf("%c",linestart[i]);
  1021. else
  1022. printf("\'%c\'",linestart[i]);
  1023. }
  1024. printf("\a\n");
  1025. if(lineend)
  1026. *lineend=c;
  1027. return;
  1028. }
  1029. *lineend=c;
  1030. p=lineend+1;
  1031. }
  1032. }
  1033. /*==========================================
  1034. * 項の解析
  1035. *------------------------------------------
  1036. */
  1037. unsigned char* parse_simpleexpr(unsigned char *p)
  1038. {
  1039. int i;
  1040. p=skip_space(p);
  1041. #ifdef DEBUG_FUNCIN
  1042. if(battle_config.etc_log)
  1043. ShowDebug("parse_simpleexpr %s\n",p);
  1044. #endif
  1045. if(*p==';' || *p==','){
  1046. disp_error_message("unexpected expr end",p);
  1047. exit(1);
  1048. }
  1049. if(*p=='('){
  1050. p=parse_subexpr(p+1,-1);
  1051. p=skip_space(p);
  1052. if((*p++)!=')'){
  1053. disp_error_message("unmatch ')'",p);
  1054. exit(1);
  1055. }
  1056. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  1057. char *np;
  1058. i=strtoul((char *) p,&np,0);
  1059. add_scripti(i);
  1060. p=(unsigned char *) np;
  1061. } else if(*p=='"'){
  1062. add_scriptc(C_STR);
  1063. p++;
  1064. while(*p && *p!='"'){
  1065. if(p[-1]<=0x7e && *p=='\\')
  1066. p++;
  1067. else if(*p=='\n'){
  1068. disp_error_message("unexpected newline @ string",p);
  1069. exit(1);
  1070. }
  1071. add_scriptb(*p++);
  1072. }
  1073. if(!*p){
  1074. disp_error_message("unexpected eof @ string",p);
  1075. exit(1);
  1076. }
  1077. add_scriptb(0);
  1078. p++; //'"'
  1079. } else {
  1080. int c,l;
  1081. char *p2;
  1082. // label , register , function etc
  1083. if(skip_word(p)==p && !(*p==')' && p[-1]=='(')){
  1084. disp_error_message("unexpected character",p);
  1085. exit(1);
  1086. }
  1087. p2=(char *) skip_word(p);
  1088. c=*p2; *p2=0; // 名前をadd_strする
  1089. l=add_str(p);
  1090. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  1091. *p2=c;
  1092. p=(unsigned char *) p2;
  1093. if(str_data[l].type!=C_FUNC && c=='['){
  1094. // array(name[i] => getelementofarray(name,i) )
  1095. add_scriptl(search_str((unsigned char *) "getelementofarray"));
  1096. add_scriptc(C_ARG);
  1097. add_scriptl(l);
  1098. p=parse_subexpr(p+1,-1);
  1099. p=skip_space(p);
  1100. if((*p++)!=']'){
  1101. disp_error_message("unmatch ']'",p);
  1102. exit(1);
  1103. }
  1104. add_scriptc(C_FUNC);
  1105. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  1106. add_scriptl(search_str((unsigned char*)"callsub"));
  1107. add_scriptc(C_ARG);
  1108. add_scriptl(l);
  1109. }else
  1110. add_scriptl(l);
  1111. }
  1112. #ifdef DEBUG_FUNCIN
  1113. if(battle_config.etc_log)
  1114. ShowDebug("parse_simpleexpr end %s\n",p);
  1115. #endif
  1116. return p;
  1117. }
  1118. /*==========================================
  1119. * 式の解析
  1120. *------------------------------------------
  1121. */
  1122. unsigned char* parse_subexpr(unsigned char *p,int limit)
  1123. {
  1124. int op,opl,len;
  1125. char *tmpp;
  1126. #ifdef DEBUG_FUNCIN
  1127. if(battle_config.etc_log)
  1128. ShowDebug("parse_subexpr %s\n",p);
  1129. #endif
  1130. p=skip_space(p);
  1131. if(*p=='-'){
  1132. tmpp=(char *) skip_space((unsigned char *) (p+1));
  1133. if(*tmpp==';' || *tmpp==','){
  1134. add_scriptl(LABEL_NEXTLINE);
  1135. p++;
  1136. return p;
  1137. }
  1138. }
  1139. tmpp=(char *) p;
  1140. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  1141. p=parse_subexpr(p+1,100);
  1142. add_scriptc(op);
  1143. } else
  1144. p=parse_simpleexpr(p);
  1145. p=skip_space(p);
  1146. while(((op=C_ADD,opl=6,len=1,*p=='+') ||
  1147. (op=C_SUB,opl=6,len=1,*p=='-') ||
  1148. (op=C_MUL,opl=7,len=1,*p=='*') ||
  1149. (op=C_DIV,opl=7,len=1,*p=='/') ||
  1150. (op=C_MOD,opl=7,len=1,*p=='%') ||
  1151. (op=C_FUNC,opl=8,len=1,*p=='(') ||
  1152. (op=C_LAND,opl=1,len=2,*p=='&' && p[1]=='&') ||
  1153. (op=C_AND,opl=5,len=1,*p=='&') ||
  1154. (op=C_LOR,opl=0,len=2,*p=='|' && p[1]=='|') ||
  1155. (op=C_OR,opl=4,len=1,*p=='|') ||
  1156. (op=C_XOR,opl=3,len=1,*p=='^') ||
  1157. (op=C_EQ,opl=2,len=2,*p=='=' && p[1]=='=') ||
  1158. (op=C_NE,opl=2,len=2,*p=='!' && p[1]=='=') ||
  1159. (op=C_R_SHIFT,opl=5,len=2,*p=='>' && p[1]=='>') ||
  1160. (op=C_GE,opl=2,len=2,*p=='>' && p[1]=='=') ||
  1161. (op=C_GT,opl=2,len=1,*p=='>') ||
  1162. (op=C_L_SHIFT,opl=5,len=2,*p=='<' && p[1]=='<') ||
  1163. (op=C_LE,opl=2,len=2,*p=='<' && p[1]=='=') ||
  1164. (op=C_LT,opl=2,len=1,*p=='<')) && opl>limit){
  1165. p+=len;
  1166. if(op==C_FUNC){
  1167. int i=0,func=parse_cmd;
  1168. const char *plist[128];
  1169. if(str_data[parse_cmd].type == C_FUNC){
  1170. // 通常の関数
  1171. add_scriptc(C_ARG);
  1172. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  1173. // ユーザー定義関数呼び出し
  1174. parse_cmd = search_str((unsigned char*)"callsub");
  1175. i++;
  1176. } else {
  1177. disp_error_message(
  1178. "expect command, missing function name or calling undeclared function",(unsigned char *) tmpp
  1179. );
  1180. exit(0);
  1181. }
  1182. func=parse_cmd;
  1183. do {
  1184. plist[i]=(char *) p;
  1185. p=parse_subexpr(p,-1);
  1186. p=skip_space(p);
  1187. if(*p==',') p++;
  1188. else if(*p!=')' && script_config.warn_func_no_comma){
  1189. disp_error_message("expect ',' or ')' at func params",p);
  1190. }
  1191. p=skip_space(p);
  1192. i++;
  1193. } while(*p && *p!=')' && i<128);
  1194. plist[i]=(char *) p;
  1195. if(*(p++)!=')'){
  1196. disp_error_message("func request '(' ')'",p);
  1197. exit(1);
  1198. }
  1199. if (str_data[func].type == C_FUNC && script_config.warn_func_mismatch_paramnum) {
  1200. const char *arg = buildin_func[str_data[func].val].arg;
  1201. int j = 0;
  1202. for (; arg[j]; j++) if (arg[j] == '*') break;
  1203. if (!(i <= 1 && j == 0) && ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j))) {
  1204. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  1205. }
  1206. }
  1207. } else {
  1208. p=parse_subexpr(p,opl);
  1209. }
  1210. add_scriptc(op);
  1211. p=skip_space(p);
  1212. }
  1213. #ifdef DEBUG_FUNCIN
  1214. if(battle_config.etc_log)
  1215. ShowDebug("parse_subexpr end %s\n",p);
  1216. #endif
  1217. return p; /* return first untreated operator */
  1218. }
  1219. /*==========================================
  1220. * 式の評価
  1221. *------------------------------------------
  1222. */
  1223. unsigned char* parse_expr(unsigned char *p)
  1224. {
  1225. #ifdef DEBUG_FUNCIN
  1226. if(battle_config.etc_log)
  1227. ShowDebug("parse_expr %s\n",p);
  1228. #endif
  1229. switch(*p){
  1230. case ')': case ';': case ':': case '[': case ']':
  1231. case '}':
  1232. disp_error_message("unexpected char",p);
  1233. exit(1);
  1234. }
  1235. p=parse_subexpr(p,-1);
  1236. #ifdef DEBUG_FUNCIN
  1237. if(battle_config.etc_log)
  1238. ShowDebug("parse_expr end %s\n",p);
  1239. #endif
  1240. return p;
  1241. }
  1242. /*==========================================
  1243. * 行の解析
  1244. *------------------------------------------
  1245. */
  1246. unsigned char* parse_line(unsigned char *p)
  1247. {
  1248. int i=0,cmd;
  1249. const char *plist[128];
  1250. unsigned char *p2;
  1251. char end;
  1252. p=skip_space(p);
  1253. if(*p==';')
  1254. return p + 1;
  1255. p = skip_space(p);
  1256. if(p[0] == '{') {
  1257. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  1258. syntax.curly[syntax.curly_count].count = -1;
  1259. syntax.curly[syntax.curly_count].index = -1;
  1260. syntax.curly_count++;
  1261. return p + 1;
  1262. } else if(p[0] == '}') {
  1263. return parse_curly_close(p);
  1264. }
  1265. // 構文関連の処理
  1266. p2 = parse_syntax(p);
  1267. if(p2 != NULL) { return p2; }
  1268. // 最初は関数名
  1269. p2=(char *) p;
  1270. p=parse_simpleexpr(p);
  1271. p=skip_space(p);
  1272. if(str_data[parse_cmd].type == C_FUNC){
  1273. // 通常の関数
  1274. add_scriptc(C_ARG);
  1275. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  1276. // ユーザー定義関数呼び出し
  1277. parse_cmd = search_str((unsigned char*)"callsub");
  1278. i++;
  1279. } else {
  1280. disp_error_message(
  1281. "expect command, missing function name or calling undeclared function", (unsigned char *)p2
  1282. );
  1283. // exit(0);
  1284. }
  1285. cmd=parse_cmd;
  1286. if(parse_syntax_for_flag) {
  1287. end = ')';
  1288. } else {
  1289. end = ';';
  1290. }
  1291. while(p && *p && *p!=end && i<128){
  1292. plist[i]=(char *) p;
  1293. p=parse_expr(p);
  1294. p=skip_space(p);
  1295. // 引数区切りの,処理
  1296. if(*p==',') p++;
  1297. else if(*p!=end && script_config.warn_cmd_no_comma && 0 <= i ){
  1298. if(parse_syntax_for_flag) {
  1299. disp_error_message("expect ',' or ')' at cmd params",p);
  1300. } else {
  1301. disp_error_message("expect ',' or ';' at cmd params",p);
  1302. }
  1303. }
  1304. p=skip_space(p);
  1305. i++;
  1306. }
  1307. plist[i]=(char *) p;
  1308. if(!p || *(p++)!=end){
  1309. if(parse_syntax_for_flag) {
  1310. disp_error_message("need ')'",p);
  1311. } else {
  1312. disp_error_message("need ';'",p);
  1313. }
  1314. exit(1);
  1315. }
  1316. add_scriptc(C_FUNC);
  1317. // if, for , while の閉じ判定
  1318. p = parse_syntax_close(p);
  1319. if( str_data[cmd].type==C_FUNC && script_config.warn_cmd_mismatch_paramnum){
  1320. const char *arg=buildin_func[str_data[cmd].val].arg;
  1321. int j=0;
  1322. for(j=0;arg[j];j++) if(arg[j]=='*')break;
  1323. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) ){
  1324. disp_error_message("illegal number of parameters",(unsigned char *) (plist[(i<j)?i:j]));
  1325. }
  1326. }
  1327. return p;
  1328. }
  1329. // { ... } の閉じ処理
  1330. unsigned char* parse_curly_close(unsigned char *p) {
  1331. if(syntax.curly_count <= 0) {
  1332. disp_error_message("unexpected string",p);
  1333. return p + 1;
  1334. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  1335. syntax.curly_count--;
  1336. // if, for , while の閉じ判定
  1337. p = parse_syntax_close(p + 1);
  1338. return p;
  1339. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  1340. // switch() 閉じ判定
  1341. int pos = syntax.curly_count-1;
  1342. unsigned char label[256];
  1343. int l;
  1344. // 一時変数を消す
  1345. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  1346. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1347. parse_line(label);
  1348. syntax.curly_count--;
  1349. // 無条件で終了ポインタに移動
  1350. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  1351. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1352. parse_line(label);
  1353. syntax.curly_count--;
  1354. // 現在地のラベルを付ける
  1355. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1356. l=add_str(label);
  1357. if(str_data[l].label!=-1){
  1358. disp_error_message("dup label ",p);
  1359. exit(1);
  1360. }
  1361. set_label(l,script_pos);
  1362. if(syntax.curly[pos].flag) {
  1363. // default が存在する
  1364. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  1365. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1366. parse_line(label);
  1367. syntax.curly_count--;
  1368. }
  1369. // 終了ラベルを付ける
  1370. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  1371. l=add_str(label);
  1372. if(str_data[l].label!=-1){
  1373. disp_error_message("dup label ",p);
  1374. exit(1);
  1375. }
  1376. set_label(l,script_pos);
  1377. syntax.curly_count--;
  1378. return p+1;
  1379. } else {
  1380. disp_error_message("unexpected string",p);
  1381. return p + 1;
  1382. }
  1383. }
  1384. // 構文関連の処理
  1385. // break, case, continue, default, do, for, function,
  1386. // if, switch, while をこの内部で処理します。
  1387. unsigned char* parse_syntax(unsigned char *p) {
  1388. switch(p[0]) {
  1389. case 'b':
  1390. if(!strncmp(p,"break",5) && !isalpha(*(p + 5))) {
  1391. // break の処理
  1392. char label[256];
  1393. int pos = syntax.curly_count - 1;
  1394. while(pos >= 0) {
  1395. if(syntax.curly[pos].type == TYPE_DO) {
  1396. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  1397. break;
  1398. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1399. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  1400. break;
  1401. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1402. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  1403. break;
  1404. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  1405. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  1406. break;
  1407. }
  1408. pos--;
  1409. }
  1410. if(pos < 0) {
  1411. disp_error_message("unexpected 'break'",p);
  1412. } else {
  1413. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1414. parse_line(label);
  1415. syntax.curly_count--;
  1416. }
  1417. p = skip_word(p);
  1418. p++;
  1419. // if, for , while の閉じ判定
  1420. p = parse_syntax_close(p + 1);
  1421. return p;
  1422. }
  1423. break;
  1424. case 'c':
  1425. if(!strncmp(p,"case",4) && !isalpha(*(p + 4))) {
  1426. // case の処理
  1427. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  1428. disp_error_message("unexpected 'case' ",p);
  1429. return p+1;
  1430. } else {
  1431. char *p2;
  1432. char label[256];
  1433. int l;
  1434. int pos = syntax.curly_count-1;
  1435. if(syntax.curly[pos].count != 1) {
  1436. // FALLTHRU 用のジャンプ
  1437. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  1438. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1439. parse_line(label);
  1440. syntax.curly_count--;
  1441. // 現在地のラベルを付ける
  1442. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1443. l=add_str(label);
  1444. if(str_data[l].label!=-1){
  1445. disp_error_message("dup label ",p);
  1446. exit(1);
  1447. }
  1448. set_label(l,script_pos);
  1449. }
  1450. // switch 判定文
  1451. p = skip_word(p);
  1452. p = skip_space(p);
  1453. p2 = p;
  1454. p = skip_word(p);
  1455. p = skip_space(p);
  1456. if(*p != ':') {
  1457. disp_error_message("expect ':'",p);
  1458. exit(1);
  1459. }
  1460. *p = 0;
  1461. sprintf(label,"if(%s != $@__SW%x_VAL) goto __SW%x_%x;",
  1462. p2,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  1463. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1464. *p = ':';
  1465. // 2回parse しないとダメ
  1466. p2 = parse_line(label);
  1467. parse_line(p2);
  1468. syntax.curly_count--;
  1469. if(syntax.curly[pos].count != 1) {
  1470. // FALLTHRU 終了後のラベル
  1471. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  1472. l=add_str(label);
  1473. if(str_data[l].label!=-1){
  1474. disp_error_message("dup label ",p);
  1475. exit(1);
  1476. }
  1477. set_label(l,script_pos);
  1478. }
  1479. // 一時変数を消す
  1480. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  1481. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1482. parse_line(label);
  1483. syntax.curly_count--;
  1484. syntax.curly[pos].count++;
  1485. }
  1486. return p + 1;
  1487. } else if(!strncmp(p,"continue",8) && !isalpha(*(p + 8))) {
  1488. // continue の処理
  1489. char label[256];
  1490. int pos = syntax.curly_count - 1;
  1491. while(pos >= 0) {
  1492. if(syntax.curly[pos].type == TYPE_DO) {
  1493. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  1494. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  1495. break;
  1496. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1497. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1498. break;
  1499. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1500. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1501. break;
  1502. }
  1503. pos--;
  1504. }
  1505. if(pos < 0) {
  1506. disp_error_message("unexpected 'continue'",p);
  1507. } else {
  1508. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1509. parse_line(label);
  1510. syntax.curly_count--;
  1511. }
  1512. p = skip_word(p);
  1513. p++;
  1514. // if, for , while の閉じ判定
  1515. p = parse_syntax_close(p + 1);
  1516. return p;
  1517. }
  1518. break;
  1519. case 'd':
  1520. if(!strncmp(p,"default",7) && !isalpha(*(p + 7))) {
  1521. // switch - default の処理
  1522. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  1523. disp_error_message("unexpected 'delault'",p);
  1524. return p+1;
  1525. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  1526. disp_error_message("dup 'delault'",p);
  1527. return p+1;
  1528. } else {
  1529. char label[256];
  1530. int l;
  1531. int pos = syntax.curly_count-1;
  1532. // 現在地のラベルを付ける
  1533. p = skip_word(p);
  1534. p = skip_space(p);
  1535. if(*p != ':') {
  1536. disp_error_message("need ':'",p);
  1537. }
  1538. p++;
  1539. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1540. l=add_str(label);
  1541. if(str_data[l].label!=-1){
  1542. disp_error_message("dup label ",p);
  1543. exit(1);
  1544. }
  1545. set_label(l,script_pos);
  1546. // 無条件で次のリンクに飛ばす
  1547. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  1548. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1549. parse_line(label);
  1550. syntax.curly_count--;
  1551. // default のラベルを付ける
  1552. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  1553. l=add_str(label);
  1554. if(str_data[l].label!=-1){
  1555. disp_error_message("dup label ",p);
  1556. exit(1);
  1557. }
  1558. set_label(l,script_pos);
  1559. syntax.curly[syntax.curly_count - 1].flag = 1;
  1560. syntax.curly[pos].count++;
  1561. p = skip_word(p);
  1562. return p + 1;
  1563. }
  1564. } else if(!strncmp(p,"do",2) && !isalpha(*(p + 2))) {
  1565. int l;
  1566. char label[256];
  1567. p=skip_word(p);
  1568. p=skip_space(p);
  1569. syntax.curly[syntax.curly_count].type = TYPE_DO;
  1570. syntax.curly[syntax.curly_count].count = 1;
  1571. syntax.curly[syntax.curly_count].index = syntax.index++;
  1572. syntax.curly[syntax.curly_count].flag = 0;
  1573. // 現在地のラベル形成する
  1574. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  1575. l=add_str(label);
  1576. if(str_data[l].label!=-1){
  1577. disp_error_message("dup label ",p);
  1578. exit(1);
  1579. }
  1580. set_label(l,script_pos);
  1581. syntax.curly_count++;
  1582. return p;
  1583. }
  1584. break;
  1585. case 'f':
  1586. if(!strncmp(p,"for",3) && !isalpha(*(p + 3))) {
  1587. int l;
  1588. unsigned char label[256];
  1589. int pos = syntax.curly_count;
  1590. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1591. syntax.curly[syntax.curly_count].count = 1;
  1592. syntax.curly[syntax.curly_count].index = syntax.index++;
  1593. syntax.curly[syntax.curly_count].flag = 0;
  1594. syntax.curly_count++;
  1595. p=skip_word(p);
  1596. p=skip_space(p);
  1597. if(*p != '(') {
  1598. disp_error_message("need '('",p);
  1599. return p+1;
  1600. }
  1601. p++;
  1602. // 初期化文を実行する
  1603. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1604. p=parse_line(p);
  1605. syntax.curly_count--;
  1606. // 条件判断開始のラベル形成する
  1607. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1608. l=add_str(label);
  1609. if(str_data[l].label!=-1){
  1610. disp_error_message("dup label ",p);
  1611. exit(1);
  1612. }
  1613. set_label(l,script_pos);
  1614. if(*p == ';') {
  1615. // for(;;) のパターンなので必ず真
  1616. ;
  1617. } else {
  1618. // 条件が偽なら終了地点に飛ばす
  1619. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1620. add_scriptl(add_str("jump_zero"));
  1621. add_scriptc(C_ARG);
  1622. p=parse_expr(p);
  1623. p=skip_space(p);
  1624. add_scriptl(add_str(label));
  1625. add_scriptc(C_FUNC);
  1626. }
  1627. if(*p != ';') {
  1628. disp_error_message("need ';'",p);
  1629. return p+1;
  1630. }
  1631. p++;
  1632. // ループ開始に飛ばす
  1633. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1634. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1635. parse_line(label);
  1636. syntax.curly_count--;
  1637. // 次のループへのラベル形成する
  1638. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1639. l=add_str(label);
  1640. if(str_data[l].label!=-1){
  1641. disp_error_message("dup label ",p);
  1642. exit(1);
  1643. }
  1644. set_label(l,script_pos);
  1645. // 次のループに入る時の処理
  1646. // for 最後の '(' を ';' として扱うフラグ
  1647. parse_syntax_for_flag = 1;
  1648. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1649. p=parse_line(p);
  1650. syntax.curly_count--;
  1651. parse_syntax_for_flag = 0;
  1652. // 条件判定処理に飛ばす
  1653. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1654. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1655. parse_line(label);
  1656. syntax.curly_count--;
  1657. // ループ開始のラベル付け
  1658. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1659. l=add_str(label);
  1660. if(str_data[l].label!=-1){
  1661. disp_error_message("dup label ",p);
  1662. exit(1);
  1663. }
  1664. set_label(l,script_pos);
  1665. return p;
  1666. } else if(!strncmp(p,"function",8) && !isalpha(*(p + 8))) {
  1667. unsigned char *func_name;
  1668. // function
  1669. p=skip_word(p);
  1670. p=skip_space(p);
  1671. // function - name
  1672. func_name = p;
  1673. p=skip_word(p);
  1674. if(*skip_space(p) == ';') {
  1675. // 関数の宣言 - 名前を登録して終わり
  1676. unsigned char c = *p;
  1677. int l;
  1678. *p = 0;
  1679. l=add_str(func_name);
  1680. *p = c;
  1681. if(str_data[l].type == C_NOP) {
  1682. str_data[l].type = C_USERFUNC;
  1683. }
  1684. return skip_space(p) + 1;
  1685. } else {
  1686. // 関数の中身
  1687. char label[256];
  1688. unsigned char c = *p;
  1689. int l;
  1690. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1691. syntax.curly[syntax.curly_count].count = 1;
  1692. syntax.curly[syntax.curly_count].index = syntax.index++;
  1693. syntax.curly[syntax.curly_count].flag = 0;
  1694. syntax.curly_count++;
  1695. // 関数終了まで飛ばす
  1696. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1697. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1698. parse_line(label);
  1699. syntax.curly_count--;
  1700. // 関数名のラベルを付ける
  1701. *p = 0;
  1702. l=add_str(func_name);
  1703. if(str_data[l].type == C_NOP) {
  1704. str_data[l].type = C_USERFUNC;
  1705. }
  1706. if(str_data[l].label!=-1){
  1707. *p=c;
  1708. disp_error_message("dup label ",p);
  1709. exit(1);
  1710. }
  1711. set_label(l,script_pos);
  1712. strdb_put(scriptlabel_db,func_name,(void*)script_pos); // 外部用label db登録
  1713. *p = c;
  1714. return skip_space(p);
  1715. }
  1716. }
  1717. break;
  1718. case 'i':
  1719. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1720. // if() の処理
  1721. char label[256];
  1722. p=skip_word(p);
  1723. p=skip_space(p);
  1724. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1725. syntax.curly[syntax.curly_count].count = 1;
  1726. syntax.curly[syntax.curly_count].index = syntax.index++;
  1727. syntax.curly[syntax.curly_count].flag = 0;
  1728. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1729. syntax.curly_count++;
  1730. add_scriptl(add_str("jump_zero"));
  1731. add_scriptc(C_ARG);
  1732. p=parse_expr(p);
  1733. p=skip_space(p);
  1734. add_scriptl(add_str(label));
  1735. add_scriptc(C_FUNC);
  1736. return p;
  1737. }
  1738. break;
  1739. case 's':
  1740. if(!strncmp(p,"switch",6) && !isalpha(*(p + 6))) {
  1741. // switch() の処理
  1742. char label[256];
  1743. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1744. syntax.curly[syntax.curly_count].count = 1;
  1745. syntax.curly[syntax.curly_count].index = syntax.index++;
  1746. syntax.curly[syntax.curly_count].flag = 0;
  1747. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1748. syntax.curly_count++;
  1749. add_scriptl(add_str((unsigned char*)"set"));
  1750. add_scriptc(C_ARG);
  1751. add_scriptl(add_str(label));
  1752. p=skip_word(p);
  1753. p=skip_space(p);
  1754. p=parse_expr(p);
  1755. p=skip_space(p);
  1756. if(*p != '{') {
  1757. disp_error_message("need '{'",p);
  1758. }
  1759. add_scriptc(C_FUNC);
  1760. return p + 1;
  1761. }
  1762. break;
  1763. case 'w':
  1764. if(!strncmp(p,"while",5) && !isalpha(*(p + 5))) {
  1765. int l;
  1766. char label[256];
  1767. p=skip_word(p);
  1768. p=skip_space(p);
  1769. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1770. syntax.curly[syntax.curly_count].count = 1;
  1771. syntax.curly[syntax.curly_count].index = syntax.index++;
  1772. syntax.curly[syntax.curly_count].flag = 0;
  1773. // 条件判断開始のラベル形成する
  1774. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1775. l=add_str(label);
  1776. if(str_data[l].label!=-1){
  1777. disp_error_message("dup label ",p);
  1778. exit(1);
  1779. }
  1780. set_label(l,script_pos);
  1781. // 条件が偽なら終了地点に飛ばす
  1782. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1783. add_scriptl(add_str("jump_zero"));
  1784. add_scriptc(C_ARG);
  1785. p=parse_expr(p);
  1786. p=skip_space(p);
  1787. add_scriptl(add_str(label));
  1788. add_scriptc(C_FUNC);
  1789. syntax.curly_count++;
  1790. return p;
  1791. }
  1792. break;
  1793. }
  1794. return NULL;
  1795. }
  1796. unsigned char* parse_syntax_close(unsigned char *p) {
  1797. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1798. int flag;
  1799. do {
  1800. p = parse_syntax_close_sub(p,&flag);
  1801. } while(flag);
  1802. return p;
  1803. }
  1804. // if, for , while , do の閉じ判定
  1805. // flag == 1 : 閉じられた
  1806. // flag == 0 : 閉じられない
  1807. unsigned char* parse_syntax_close_sub(unsigned char *p,int *flag) {
  1808. unsigned char label[256];
  1809. int pos = syntax.curly_count - 1;
  1810. int l;
  1811. *flag = 1;
  1812. if(syntax.curly_count <= 0) {
  1813. *flag = 0;
  1814. return p;
  1815. } else if(syntax.curly[pos].type == TYPE_IF) {
  1816. char *p2 = p;
  1817. // if 最終場所へ飛ばす
  1818. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1819. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1820. parse_line(label);
  1821. syntax.curly_count--;
  1822. // 現在地のラベルを付ける
  1823. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1824. l=add_str(label);
  1825. if(str_data[l].label!=-1){
  1826. disp_error_message("dup label ",p);
  1827. exit(1);
  1828. }
  1829. set_label(l,script_pos);
  1830. syntax.curly[pos].count++;
  1831. p = skip_space(p);
  1832. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !isalpha(*(p + 4))) {
  1833. // else or else - if
  1834. p = skip_word(p);
  1835. p = skip_space(p);
  1836. if(!strncmp(p,"if",2) && !isalpha(*(p + 2))) {
  1837. // else - if
  1838. p=skip_word(p);
  1839. p=skip_space(p);
  1840. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1841. add_scriptl(add_str("jump_zero"));
  1842. add_scriptc(C_ARG);
  1843. p=parse_expr(p);
  1844. p=skip_space(p);
  1845. add_scriptl(add_str(label));
  1846. add_scriptc(C_FUNC);
  1847. *flag = 0;
  1848. return p;
  1849. } else {
  1850. // else
  1851. if(!syntax.curly[pos].flag) {
  1852. syntax.curly[pos].flag = 1;
  1853. *flag = 0;
  1854. return p;
  1855. }
  1856. }
  1857. }
  1858. // if 閉じ
  1859. syntax.curly_count--;
  1860. // 最終地のラベルを付ける
  1861. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1862. l=add_str(label);
  1863. if(str_data[l].label!=-1){
  1864. disp_error_message("dup label ",p);
  1865. exit(1);
  1866. }
  1867. set_label(l,script_pos);
  1868. if(syntax.curly[pos].flag == 1) {
  1869. // このifに対するelseじゃないのでポインタの位置は同じ
  1870. return p2;
  1871. }
  1872. return p;
  1873. } else if(syntax.curly[pos].type == TYPE_DO) {
  1874. int l;
  1875. char label[256];
  1876. unsigned char *p2;
  1877. if(syntax.curly[pos].flag) {
  1878. // 現在地のラベル形成する(continue でここに来る)
  1879. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1880. l=add_str(label);
  1881. if(str_data[l].label!=-1){
  1882. disp_error_message("dup label ",p);
  1883. exit(1);
  1884. }
  1885. set_label(l,script_pos);
  1886. }
  1887. // 条件が偽なら終了地点に飛ばす
  1888. p = skip_space(p);
  1889. p2 = skip_word(p);
  1890. if(p2 - p != 5 || strncmp("while",p,5)) {
  1891. disp_error_message("need 'while'",p);
  1892. }
  1893. p = p2;
  1894. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1895. add_scriptl(add_str("jump_zero"));
  1896. add_scriptc(C_ARG);
  1897. p=parse_expr(p);
  1898. p=skip_space(p);
  1899. add_scriptl(add_str(label));
  1900. add_scriptc(C_FUNC);
  1901. // 開始地点に飛ばす
  1902. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1903. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1904. parse_line(label);
  1905. syntax.curly_count--;
  1906. // 条件終了地点のラベル形成する
  1907. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1908. l=add_str(label);
  1909. if(str_data[l].label!=-1){
  1910. disp_error_message("dup label ",p);
  1911. exit(1);
  1912. }
  1913. set_label(l,script_pos);
  1914. p = skip_space(p);
  1915. if(*p != ';') {
  1916. disp_error_message("need ';'",p);
  1917. return p+1;
  1918. }
  1919. p++;
  1920. syntax.curly_count--;
  1921. return p;
  1922. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1923. // 次のループに飛ばす
  1924. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1925. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1926. parse_line(label);
  1927. syntax.curly_count--;
  1928. // for 終了のラベル付け
  1929. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1930. l=add_str(label);
  1931. if(str_data[l].label!=-1){
  1932. disp_error_message("dup label ",p);
  1933. exit(1);
  1934. }
  1935. set_label(l,script_pos);
  1936. syntax.curly_count--;
  1937. return p;
  1938. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1939. // while 条件判断へ飛ばす
  1940. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1941. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1942. parse_line(label);
  1943. syntax.curly_count--;
  1944. // while 終了のラベル付け
  1945. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1946. l=add_str(label);
  1947. if(str_data[l].label!=-1){
  1948. disp_error_message("dup label ",p);
  1949. exit(1);
  1950. }
  1951. set_label(l,script_pos);
  1952. syntax.curly_count--;
  1953. return p;
  1954. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1955. int pos = syntax.curly_count-1;
  1956. char label[256];
  1957. int l;
  1958. // 戻す
  1959. sprintf(label,"return;");
  1960. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1961. parse_line(label);
  1962. syntax.curly_count--;
  1963. // 現在地のラベルを付ける
  1964. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1965. l=add_str(label);
  1966. if(str_data[l].label!=-1){
  1967. disp_error_message("dup label ",p);
  1968. exit(1);
  1969. }
  1970. set_label(l,script_pos);
  1971. syntax.curly_count--;
  1972. return p + 1;
  1973. } else {
  1974. *flag = 0;
  1975. return p;
  1976. }
  1977. }
  1978. /*==========================================
  1979. * 組み込み関数の追加
  1980. *------------------------------------------
  1981. */
  1982. static void add_buildin_func(void)
  1983. {
  1984. int i,n;
  1985. for(i=0;buildin_func[i].func;i++){
  1986. n=add_str((unsigned char *) buildin_func[i].name);
  1987. str_data[n].type=C_FUNC;
  1988. str_data[n].val=i;
  1989. str_data[n].func=buildin_func[i].func;
  1990. }
  1991. }
  1992. /*==========================================
  1993. * 定数データベースの読み込み
  1994. *------------------------------------------
  1995. */
  1996. static void read_constdb(void)
  1997. {
  1998. FILE *fp;
  1999. char line[1024],name[1024];
  2000. int val,n,i,type;
  2001. sprintf(line, "%s/const.txt", db_path);
  2002. fp=fopen(line, "r");
  2003. if(fp==NULL){
  2004. ShowError("can't read %s\n", line);
  2005. return ;
  2006. }
  2007. while(fgets(line,1020,fp)){
  2008. if(line[0]=='/' && line[1]=='/')
  2009. continue;
  2010. type=0;
  2011. if(sscanf(line,"%[A-Za-z0-9_],%d,%d",name,&val,&type)>=2 ||
  2012. sscanf(line,"%[A-Za-z0-9_] %d %d",name,&val,&type)>=2){
  2013. for(i=0;name[i];i++)
  2014. name[i]=tolower(name[i]);
  2015. n=add_str((const unsigned char *) name);
  2016. if(type==0)
  2017. str_data[n].type=C_INT;
  2018. else
  2019. str_data[n].type=C_PARAM;
  2020. str_data[n].val=val;
  2021. }
  2022. }
  2023. fclose(fp);
  2024. }
  2025. /*==========================================
  2026. * スクリプトの解析
  2027. *------------------------------------------
  2028. */
  2029. unsigned char* parse_script(unsigned char *src,int line)
  2030. {
  2031. unsigned char *p, *tmpp;
  2032. int i;
  2033. static int first = 1;
  2034. if (first) {
  2035. add_buildin_func();
  2036. read_constdb();
  2037. }
  2038. first = 0;
  2039. //////////////////////////////////////////////
  2040. // additional check on the input to filter empty scripts ("{}" and "{ }")
  2041. p = src;
  2042. p = skip_space(p);
  2043. if (*p != '{') {
  2044. disp_error_message("not found '{'", p);
  2045. return NULL;
  2046. }
  2047. p++;
  2048. p = skip_space(p);
  2049. if (*p == '}') {
  2050. // an empty function, just return
  2051. return NULL;
  2052. }
  2053. script_buf = (unsigned char *) aCallocA(SCRIPT_BLOCK_SIZE, sizeof(unsigned char));
  2054. script_pos = 0;
  2055. script_size = SCRIPT_BLOCK_SIZE;
  2056. str_data[LABEL_NEXTLINE].type = C_NOP;
  2057. str_data[LABEL_NEXTLINE].backpatch = -1;
  2058. str_data[LABEL_NEXTLINE].label = -1;
  2059. for (i = LABEL_START; i < str_num; i++) {
  2060. if (
  2061. str_data[i].type == C_POS || str_data[i].type == C_NAME ||
  2062. str_data[i].type == C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  2063. ) {
  2064. str_data[i].type = C_NOP;
  2065. str_data[i].backpatch = -1;
  2066. str_data[i].label = -1;
  2067. }
  2068. }
  2069. //Labels must be reparsed for the script....
  2070. scriptlabel_db->clear(scriptlabel_db, NULL);
  2071. // for error message
  2072. startptr = src;
  2073. startline = line;
  2074. while (p && *p && (*p != '}' || syntax.curly_count != 0)) {
  2075. p = skip_space(p);
  2076. // labelだけ特殊処理
  2077. tmpp = skip_space(skip_word(p));
  2078. if (*tmpp == ':' && !(!strncmp(p,"default",7) && !isalpha(*(p + 7)))) {
  2079. int l, c;
  2080. c = *skip_word(p);
  2081. *skip_word(p) = 0;
  2082. l = add_str(p);
  2083. if (str_data[l].label != -1) {
  2084. *skip_word(p) = c;
  2085. disp_error_message("dup label ", p);
  2086. exit(1);
  2087. }
  2088. set_label(l, script_pos);
  2089. strdb_put(scriptlabel_db, p, (void*)script_pos); // 外部用label db登録
  2090. *skip_word(p) = c;
  2091. p = tmpp + 1;
  2092. continue;
  2093. }
  2094. // 他は全部一緒くた
  2095. p = parse_line(p);
  2096. p = skip_space(p);
  2097. add_scriptc(C_EOL);
  2098. set_label(LABEL_NEXTLINE, script_pos);
  2099. str_data[LABEL_NEXTLINE].type = C_NOP;
  2100. str_data[LABEL_NEXTLINE].backpatch = -1;
  2101. str_data[LABEL_NEXTLINE].label = -1;
  2102. }
  2103. add_scriptc(C_NOP);
  2104. script_size = script_pos;
  2105. script_buf = (unsigned char *)aRealloc(script_buf, script_pos + 1);
  2106. // 未解決のラベルを解決
  2107. for (i = LABEL_START; i < str_num; i++) {
  2108. if (str_data[i].type == C_NOP) {
  2109. int j, next;
  2110. str_data[i].type = C_NAME;
  2111. str_data[i].label = i;
  2112. for (j = str_data[i].backpatch; j >= 0 && j != 0x00ffffff; ) {
  2113. next = (*(int*)(script_buf+j)) & 0x00ffffff;
  2114. script_buf[j] = i;
  2115. script_buf[j+1] = i>>8;
  2116. script_buf[j+2] = i>>16;
  2117. j = next;
  2118. }
  2119. }
  2120. }
  2121. #ifdef DEBUG_DISP
  2122. for (i = 0; i < script_pos; i++) {
  2123. if ((i & 15) == 0) printf("%04x : ", i);
  2124. printf("%02x ", script_buf[i]);
  2125. if((i&15) == 15) printf("\n");
  2126. }
  2127. printf("\n");
  2128. #endif
  2129. startptr = NULL; //Clear pointer to prevent future references to a src that may be free'd. [Skotlex]
  2130. return (unsigned char *) script_buf;
  2131. }
  2132. //
  2133. // 実行系
  2134. //
  2135. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  2136. /*==========================================
  2137. * ridからsdへの解決
  2138. *------------------------------------------
  2139. */
  2140. struct map_session_data *script_rid2sd(struct script_state *st)
  2141. {
  2142. struct map_session_data *sd=map_id2sd(st->rid);
  2143. if(!sd){
  2144. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  2145. report_src(st);
  2146. }
  2147. return sd;
  2148. }
  2149. /*==========================================
  2150. * 変数の読み取り
  2151. *------------------------------------------
  2152. */
  2153. int get_val(struct script_state*st,struct script_data* data)
  2154. {
  2155. struct map_session_data *sd=NULL;
  2156. if(data->type==C_NAME){
  2157. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  2158. char prefix=*name;
  2159. char postfix=name[strlen(name)-1];
  2160. if(prefix!='$'){
  2161. if((sd=script_rid2sd(st))==NULL)
  2162. ShowError("get_val error name?:%s\n",name);
  2163. }
  2164. if(postfix=='$'){
  2165. data->type=C_CONSTSTR;
  2166. if( prefix=='@'){
  2167. if(sd)
  2168. data->u.str = pc_readregstr(sd,data->u.num);
  2169. }else if(prefix=='$'){
  2170. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  2171. }else if(prefix=='#'){
  2172. if( name[1]=='#'){
  2173. if(sd)
  2174. data->u.str = pc_readaccountreg2str(sd,name);
  2175. }else{
  2176. if(sd)
  2177. data->u.str = pc_readaccountregstr(sd,name);
  2178. }
  2179. }else{
  2180. if(sd)
  2181. data->u.str = pc_readglobalreg_str(sd,name);
  2182. } // [zBuffer]
  2183. /*else{
  2184. ShowWarning("script: get_val: illegal scope string variable.\n");
  2185. data->u.str = "!!ERROR!!";
  2186. }*/
  2187. if( data->u.str == NULL )
  2188. data->u.str ="";
  2189. }else{
  2190. data->type=C_INT;
  2191. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  2192. data->u.num = str_data[data->u.num&0x00ffffff].val;
  2193. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  2194. if(sd)
  2195. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  2196. }else if(prefix=='@'){
  2197. if(sd)
  2198. data->u.num = pc_readreg(sd,data->u.num);
  2199. }else if(prefix=='$'){
  2200. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  2201. }else if(prefix=='#'){
  2202. if( name[1]=='#'){
  2203. if(sd)
  2204. data->u.num = pc_readaccountreg2(sd,name);
  2205. }else{
  2206. if(sd)
  2207. data->u.num = pc_readaccountreg(sd,name);
  2208. }
  2209. }else{
  2210. if(sd)
  2211. data->u.num = pc_readglobalreg(sd,name);
  2212. }
  2213. }
  2214. }
  2215. return 0;
  2216. }
  2217. /*==========================================
  2218. * 変数の読み取り2
  2219. *------------------------------------------
  2220. */
  2221. void* get_val2(struct script_state*st,int num)
  2222. {
  2223. struct script_data dat;
  2224. dat.type=C_NAME;
  2225. dat.u.num=num;
  2226. get_val(st,&dat);
  2227. if( dat.type==C_INT ) return (void*)dat.u.num;
  2228. else return (void*)dat.u.str;
  2229. }
  2230. /*==========================================
  2231. * 変数設定用
  2232. *------------------------------------------
  2233. */
  2234. static int set_reg(struct map_session_data *sd,int num,char *name,void *v)
  2235. {
  2236. char prefix=*name;
  2237. char postfix=name[strlen(name)-1];
  2238. if( postfix=='$' ){
  2239. char *str=(char*)v;
  2240. if( prefix=='@'){
  2241. pc_setregstr(sd,num,str);
  2242. }else if(prefix=='$') {
  2243. mapreg_setregstr(num,str);
  2244. }else if(prefix=='#') {
  2245. if( name[1]=='#' )
  2246. pc_setaccountreg2str(sd,name,str);
  2247. else
  2248. pc_setaccountregstr(sd,name,str);
  2249. }else{
  2250. pc_setglobalreg_str(sd,name,str);
  2251. } // [zBuffer]
  2252. /*else{
  2253. ShowWarning("script: set_reg: illegal scope string variable !");
  2254. }*/
  2255. }else{
  2256. // 数値
  2257. int val = (int)v;
  2258. if(str_data[num&0x00ffffff].type==C_PARAM){
  2259. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  2260. }else if(prefix=='@') {
  2261. pc_setreg(sd,num,val);
  2262. }else if(prefix=='$') {
  2263. mapreg_setreg(num,val);
  2264. }else if(prefix=='#') {
  2265. if( name[1]=='#' )
  2266. pc_setaccountreg2(sd,name,val);
  2267. else
  2268. pc_setaccountreg(sd,name,val);
  2269. }else{
  2270. pc_setglobalreg(sd,name,val);
  2271. }
  2272. }
  2273. return 0;
  2274. }
  2275. int set_var(struct map_session_data *sd, char *name, void *val)
  2276. {
  2277. return set_reg(sd, add_str((unsigned char *) name), name, val);
  2278. }
  2279. /*==========================================
  2280. * 文字列への変換
  2281. *------------------------------------------
  2282. */
  2283. char* conv_str(struct script_state *st,struct script_data *data)
  2284. {
  2285. get_val(st,data);
  2286. if(data->type==C_INT){
  2287. char *buf;
  2288. buf=(char *)aCallocA(ITEM_NAME_LENGTH,sizeof(char));
  2289. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  2290. data->type=C_STR;
  2291. data->u.str=buf;
  2292. #if 1
  2293. } else if(data->type==C_NAME){
  2294. // テンポラリ。本来無いはず
  2295. data->type=C_CONSTSTR;
  2296. data->u.str=str_buf+str_data[data->u.num].str;
  2297. #endif
  2298. }
  2299. return data->u.str;
  2300. }
  2301. /*==========================================
  2302. * 数値へ変換
  2303. *------------------------------------------
  2304. */
  2305. int conv_num(struct script_state *st,struct script_data *data)
  2306. {
  2307. char *p;
  2308. get_val(st,data);
  2309. if(data->type==C_STR || data->type==C_CONSTSTR){
  2310. p=data->u.str;
  2311. data->u.num = atoi(p);
  2312. if(data->type==C_STR)
  2313. aFree(p);
  2314. data->type=C_INT;
  2315. }
  2316. return data->u.num;
  2317. }
  2318. /*==========================================
  2319. * スタックへ数値をプッシュ
  2320. *------------------------------------------
  2321. */
  2322. void push_val(struct script_stack *stack,int type,int val)
  2323. {
  2324. if(stack->sp >= stack->sp_max){
  2325. stack->sp_max += 64;
  2326. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  2327. sizeof(stack->stack_data[0]) * stack->sp_max);
  2328. memset(stack->stack_data + (stack->sp_max - 64), 0,
  2329. 64 * sizeof(*(stack->stack_data)));
  2330. }
  2331. // if(battle_config.etc_log)
  2332. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  2333. stack->stack_data[stack->sp].type=type;
  2334. stack->stack_data[stack->sp].u.num=val;
  2335. stack->sp++;
  2336. }
  2337. /*==========================================
  2338. * スタックへ文字列をプッシュ
  2339. *------------------------------------------
  2340. */
  2341. void push_str(struct script_stack *stack,int type,unsigned char *str)
  2342. {
  2343. if(stack->sp>=stack->sp_max){
  2344. stack->sp_max += 64;
  2345. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  2346. sizeof(stack->stack_data[0]) * stack->sp_max);
  2347. memset(stack->stack_data + (stack->sp_max - 64), '\0',
  2348. 64 * sizeof(*(stack->stack_data)));
  2349. }
  2350. // if(battle_config.etc_log)
  2351. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  2352. stack->stack_data[stack->sp].type=type;
  2353. stack->stack_data[stack->sp].u.str=(char *) str;
  2354. stack->sp++;
  2355. }
  2356. /*==========================================
  2357. * スタックへ複製をプッシュ
  2358. *------------------------------------------
  2359. */
  2360. void push_copy(struct script_stack *stack,int pos)
  2361. {
  2362. switch(stack->stack_data[pos].type){
  2363. case C_CONSTSTR:
  2364. push_str(stack,C_CONSTSTR,(unsigned char *) stack->stack_data[pos].u.str);
  2365. break;
  2366. case C_STR:
  2367. push_str(stack,C_STR,(unsigned char *) aStrdup(stack->stack_data[pos].u.str));
  2368. break;
  2369. default:
  2370. push_val(stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num);
  2371. break;
  2372. }
  2373. }
  2374. /*==========================================
  2375. * スタックからポップ
  2376. *------------------------------------------
  2377. */
  2378. void pop_stack(struct script_stack* stack,int start,int end)
  2379. {
  2380. int i;
  2381. for(i=start;i<end;i++){
  2382. if(stack->stack_data[i].type==C_STR){
  2383. aFree(stack->stack_data[i].u.str);
  2384. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  2385. }
  2386. }
  2387. if(stack->sp>end){
  2388. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  2389. }
  2390. stack->sp-=end-start;
  2391. }
  2392. /*==========================================
  2393. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  2394. *------------------------------------------
  2395. */
  2396. void script_free_stack(struct script_stack* stack)
  2397. {
  2398. int i;
  2399. for (i = 0; i < stack->sp; i++)
  2400. {
  2401. if(stack->stack_data[i].type==C_STR)
  2402. {
  2403. //ShowDebug ("script_free_stack: freeing %p at sp=%d.\n", stack->stack_data[i].u.str, i);
  2404. aFree(stack->stack_data[i].u.str);
  2405. stack->stack_data[i].type = C_INT;
  2406. }
  2407. }
  2408. aFree (stack->stack_data);
  2409. aFree (stack);
  2410. }
  2411. int axtoi(char *hexStg) {
  2412. int n = 0; // position in string
  2413. int m = 0; // position in digit[] to shift
  2414. int count; // loop index
  2415. int intValue = 0; // integer value of hex string
  2416. int digit[11]; // hold values to convert
  2417. while (n < 10) {
  2418. if (hexStg[n]=='\0')
  2419. break;
  2420. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  2421. digit[n] = hexStg[n] & 0x0f; //convert to int
  2422. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  2423. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  2424. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  2425. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  2426. else break;
  2427. n++;
  2428. }
  2429. count = n;
  2430. m = n - 1;
  2431. n = 0;
  2432. while(n < count) {
  2433. // digit[n] is value of hex digit at position n
  2434. // (m << 2) is the number of positions to shift
  2435. // OR the bits into return value
  2436. intValue = intValue | (digit[n] << (m << 2));
  2437. m--; // adjust the position to set
  2438. n++; // next digit to process
  2439. }
  2440. return (intValue);
  2441. }
  2442. // [Lance] Hex string to integer converter
  2443. int buildin_axtoi(struct script_state *st)
  2444. {
  2445. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  2446. push_val(st->stack, C_INT, axtoi(hex));
  2447. return 0;
  2448. }
  2449. //
  2450. // 埋め込み関数
  2451. //
  2452. /*==========================================
  2453. *
  2454. *------------------------------------------
  2455. */
  2456. int buildin_mes(struct script_state *st)
  2457. {
  2458. conv_str(st,& (st->stack->stack_data[st->start+2]));
  2459. clif_scriptmes(script_rid2sd(st),st->oid,st->stack->stack_data[st->start+2].u.str);
  2460. return 0;
  2461. }
  2462. /*==========================================
  2463. *
  2464. *------------------------------------------
  2465. */
  2466. int buildin_goto(struct script_state *st)
  2467. {
  2468. int pos;
  2469. if (st->stack->stack_data[st->start+2].type != C_POS){
  2470. int func = st->stack->stack_data[st->start+2].u.num;
  2471. ShowMessage("script: goto '"CL_WHITE"%s"CL_RESET"': not label!\n", str_buf + str_data[func].str);
  2472. st->state = END;
  2473. return 1;
  2474. }
  2475. pos = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2476. st->pos = pos;
  2477. st->state = GOTO;
  2478. return 0;
  2479. }
  2480. /*==========================================
  2481. * ユーザー定義関数の呼び出し
  2482. *------------------------------------------
  2483. */
  2484. int buildin_callfunc(struct script_state *st)
  2485. {
  2486. char *scr;
  2487. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2488. if( (scr=(char *) strdb_get(userfunc_db,(unsigned char*)str)) ){
  2489. int i,j;
  2490. for(i=st->start+3,j=0;i<st->end;i++,j++)
  2491. push_copy(st->stack,i);
  2492. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  2493. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  2494. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  2495. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  2496. st->pos=0;
  2497. st->script=scr;
  2498. st->stack->defsp=st->start+4+j;
  2499. st->state=GOTO;
  2500. }else{
  2501. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  2502. st->state=END;
  2503. return 1;
  2504. }
  2505. return 0;
  2506. }
  2507. /*==========================================
  2508. * サブルーティンの呼び出し
  2509. *------------------------------------------
  2510. */
  2511. int buildin_callsub(struct script_state *st)
  2512. {
  2513. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2514. int i,j;
  2515. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  2516. ShowError("script: callsub: not label !\n");
  2517. st->state=END;
  2518. return 1;
  2519. } else {
  2520. for(i=st->start+3,j=0;i<st->end;i++,j++)
  2521. push_copy(st->stack,i);
  2522. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  2523. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  2524. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  2525. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  2526. st->pos=pos;
  2527. st->stack->defsp=st->start+4+j;
  2528. st->state=GOTO;
  2529. }
  2530. return 0;
  2531. }
  2532. /*==========================================
  2533. * 引数の所得
  2534. *------------------------------------------
  2535. */
  2536. int buildin_getarg(struct script_state *st)
  2537. {
  2538. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2539. int max,stsp;
  2540. if( st->stack->defsp<4 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  2541. ShowWarning("script:getarg without callfunc or callsub!\n");
  2542. st->state=END;
  2543. return 1;
  2544. }
  2545. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4]));
  2546. stsp=st->stack->defsp - max -4;
  2547. if( num >= max ){
  2548. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  2549. st->state=END;
  2550. return 1;
  2551. }
  2552. push_copy(st->stack,stsp+num);
  2553. return 0;
  2554. }
  2555. /*==========================================
  2556. * サブルーチン/ユーザー定義関数の終了
  2557. *------------------------------------------
  2558. */
  2559. int buildin_return(struct script_state *st)
  2560. {
  2561. if(st->end>st->start+2){ // 戻り値有り
  2562. push_copy(st->stack,st->start+2);
  2563. }
  2564. st->state=RETFUNC;
  2565. return 0;
  2566. }
  2567. /*==========================================
  2568. *
  2569. *------------------------------------------
  2570. */
  2571. int buildin_next(struct script_state *st)
  2572. {
  2573. st->state=STOP;
  2574. clif_scriptnext(script_rid2sd(st),st->oid);
  2575. return 0;
  2576. }
  2577. /*==========================================
  2578. *
  2579. *------------------------------------------
  2580. */
  2581. int buildin_close(struct script_state *st)
  2582. {
  2583. st->state=END;
  2584. clif_scriptclose(script_rid2sd(st),st->oid);
  2585. return 0;
  2586. }
  2587. int buildin_close2(struct script_state *st)
  2588. {
  2589. st->state=STOP;
  2590. clif_scriptclose(script_rid2sd(st),st->oid);
  2591. return 0;
  2592. }
  2593. /*==========================================
  2594. *
  2595. *------------------------------------------
  2596. */
  2597. int buildin_menu(struct script_state *st)
  2598. {
  2599. char *buf;
  2600. int len,i;
  2601. struct map_session_data *sd;
  2602. sd=script_rid2sd(st);
  2603. if(sd->state.menu_or_input==0){
  2604. st->state=RERUNLINE;
  2605. sd->state.menu_or_input=1;
  2606. for(i=st->start+2,len=16;i<st->end;i+=2){
  2607. conv_str(st,& (st->stack->stack_data[i]));
  2608. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  2609. }
  2610. buf=(char *)aCallocA(len+1,sizeof(char));
  2611. buf[0]=0;
  2612. for(i=st->start+2,len=0;i<st->end;i+=2){
  2613. strcat(buf,st->stack->stack_data[i].u.str);
  2614. strcat(buf,":");
  2615. }
  2616. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  2617. aFree(buf);
  2618. } else if(sd->npc_menu==0xff){ // cansel
  2619. sd->state.menu_or_input=0;
  2620. st->state=END;
  2621. } else { // goto動作
  2622. sd->state.menu_or_input=0;
  2623. if(sd->npc_menu>0){
  2624. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  2625. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2)
  2626. {
  2627. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  2628. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  2629. }
  2630. if(sd->npc_menu >= (st->end-st->start)/2) {
  2631. //Invalid selection.
  2632. st->state=END;
  2633. return 0;
  2634. }
  2635. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  2636. ShowError("script: menu: not label !\n");
  2637. st->state=END;
  2638. return 1;
  2639. }
  2640. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  2641. st->pos= conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  2642. st->state=GOTO;
  2643. }
  2644. }
  2645. return 0;
  2646. }
  2647. /*==========================================
  2648. *
  2649. *------------------------------------------
  2650. */
  2651. int buildin_rand(struct script_state *st)
  2652. {
  2653. int range;
  2654. if (st->end > st->start+3){
  2655. int min, max;
  2656. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2657. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  2658. if (max == min){ //Why would someone do this?
  2659. push_val(st->stack,C_INT,min);
  2660. return 0;
  2661. }
  2662. if (max < min){
  2663. int tmp = min;
  2664. min = max;
  2665. max = tmp;
  2666. }
  2667. range = max - min + 1;
  2668. if (range == 0) range = 1;
  2669. push_val(st->stack,C_INT,rand()%range+min);
  2670. } else {
  2671. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  2672. if (range == 0) range = 1;
  2673. push_val(st->stack,C_INT,rand()%range);
  2674. }
  2675. return 0;
  2676. }
  2677. /*==========================================
  2678. *
  2679. *------------------------------------------
  2680. */
  2681. int buildin_warp(struct script_state *st)
  2682. {
  2683. int x,y;
  2684. char *str;
  2685. struct map_session_data *sd=script_rid2sd(st);
  2686. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2687. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2688. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2689. if(strcmp(str,"Random")==0)
  2690. pc_randomwarp(sd,3);
  2691. else if(strcmp(str,"SavePoint")==0){
  2692. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  2693. return 0;
  2694. pc_setpos(sd,sd->status.save_point.map,
  2695. sd->status.save_point.x,sd->status.save_point.y,3);
  2696. }else if(strcmp(str,"Save")==0){
  2697. if(map[sd->bl.m].flag.noreturn) // 蝶禁止
  2698. return 0;
  2699. pc_setpos(sd,sd->status.save_point.map,
  2700. sd->status.save_point.x,sd->status.save_point.y,3);
  2701. }else
  2702. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  2703. return 0;
  2704. }
  2705. /*==========================================
  2706. * エリア指定ワープ
  2707. *------------------------------------------
  2708. */
  2709. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  2710. {
  2711. int x,y;
  2712. unsigned int map;
  2713. map=va_arg(ap, unsigned int);
  2714. x=va_arg(ap,int);
  2715. y=va_arg(ap,int);
  2716. if(map == 0)
  2717. pc_randomwarp((struct map_session_data *)bl,3);
  2718. else
  2719. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  2720. return 0;
  2721. }
  2722. int buildin_areawarp(struct script_state *st)
  2723. {
  2724. int x,y,m;
  2725. unsigned int index;
  2726. char *str;
  2727. char *mapname;
  2728. int x0,y0,x1,y1;
  2729. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2730. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2731. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2732. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2733. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  2734. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  2735. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  2736. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  2737. if( (m=map_mapname2mapid(mapname))< 0)
  2738. return 0;
  2739. if(strcmp(str,"Random")==0)
  2740. index = 0;
  2741. else if(!(index=mapindex_name2id(str)))
  2742. return 0;
  2743. map_foreachinarea(buildin_areawarp_sub,
  2744. m,x0,y0,x1,y1,BL_PC, index,x,y );
  2745. return 0;
  2746. }
  2747. /*==========================================
  2748. * warpchar [LuzZza]
  2749. * Useful for warp one player from
  2750. * another player npc-session.
  2751. * Using: warpchar "mapname.gat",x,y,Char_ID;
  2752. *------------------------------------------
  2753. */
  2754. int buildin_warpchar(struct script_state *st)
  2755. {
  2756. int x,y,a,i;
  2757. char *str;
  2758. struct map_session_data *sd, **pl_allsd;
  2759. int users;
  2760. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2761. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2762. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2763. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2764. pl_allsd = map_getallusers(&users);
  2765. for(i=0; i<users; i++) {
  2766. sd = pl_allsd[i];
  2767. if(sd->status.char_id == a) {
  2768. if(strcmp(str, "Random") == 0)
  2769. pc_randomwarp(sd, 3);
  2770. else if(strcmp(str, "SavePoint") == 0)
  2771. pc_setpos(sd, sd->status.save_point.map,
  2772. sd->status.save_point.x, sd->status.save_point.y, 3);
  2773. else
  2774. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  2775. }
  2776. }
  2777. return 0;
  2778. }
  2779. /*==========================================
  2780. * Warpparty - [Fredzilla]
  2781. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  2782. *------------------------------------------
  2783. */
  2784. int buildin_warpparty(struct script_state *st)
  2785. {
  2786. int x,y;
  2787. char *str;
  2788. int p_id;
  2789. int i;
  2790. unsigned short mapindex;
  2791. struct map_session_data *pl_sd;
  2792. struct party *p=NULL;
  2793. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2794. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2795. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2796. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2797. if(p_id < 1)
  2798. return 0;
  2799. p = party_search(p_id);
  2800. if (!p)
  2801. return 0;
  2802. if(strcmp(str,"Random")==0)
  2803. {
  2804. for (i = 0; i < MAX_PARTY; i++)
  2805. {
  2806. if ((pl_sd = p->member[i].sd))
  2807. {
  2808. if(map[pl_sd->bl.m].flag.nowarp)
  2809. continue;
  2810. pc_randomwarp(pl_sd,3);
  2811. }
  2812. }
  2813. }
  2814. else if(strcmp(str,"SavePointAll")==0)
  2815. {
  2816. for (i = 0; i < MAX_PARTY; i++)
  2817. {
  2818. if ((pl_sd = p->member[i].sd))
  2819. {
  2820. if(map[pl_sd->bl.m].flag.noreturn)
  2821. continue;
  2822. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  2823. }
  2824. }
  2825. }
  2826. else if(strcmp(str,"SavePoint")==0)
  2827. {
  2828. pl_sd=script_rid2sd(st);
  2829. if (!pl_sd) return 0;
  2830. mapindex=pl_sd->status.save_point.map;
  2831. x=pl_sd->status.save_point.x;
  2832. y=pl_sd->status.save_point.y;
  2833. for (i = 0; i < MAX_PARTY; i++)
  2834. {
  2835. if ((pl_sd = p->member[i].sd))
  2836. {
  2837. if(map[pl_sd->bl.m].flag.noreturn)
  2838. continue;
  2839. pc_setpos(pl_sd,mapindex,x,y,3);
  2840. }
  2841. }
  2842. }
  2843. else
  2844. {
  2845. mapindex = mapindex_name2id(str);
  2846. if (!mapindex) //Show source of npc error.
  2847. return 1;
  2848. for (i = 0; i < MAX_PARTY; i++)
  2849. {
  2850. if ((pl_sd = p->member[i].sd))
  2851. {
  2852. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  2853. continue;
  2854. pc_setpos(pl_sd,mapindex,x,y,3);
  2855. }
  2856. }
  2857. }
  2858. return 0;
  2859. }
  2860. /*==========================================
  2861. * Warpguild - [Fredzilla]
  2862. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  2863. *------------------------------------------
  2864. */
  2865. int buildin_warpguild(struct script_state *st)
  2866. {
  2867. int x,y;
  2868. unsigned short mapindex;
  2869. char *str;
  2870. int g;
  2871. int i;
  2872. struct map_session_data *pl_sd, **pl_allsd;
  2873. int users;
  2874. struct map_session_data *sd;
  2875. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  2876. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2877. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  2878. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  2879. sd=script_rid2sd(st);
  2880. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  2881. return 0;
  2882. if(g < 1)
  2883. return 0;
  2884. pl_allsd = map_getallusers(&users);
  2885. if(strcmp(str,"Random")==0)
  2886. {
  2887. for (i = 0; i < users; i++)
  2888. {
  2889. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  2890. {
  2891. if(map[pl_sd->bl.m].flag.nowarp)
  2892. continue;
  2893. pc_randomwarp(pl_sd,3);
  2894. }
  2895. }
  2896. }
  2897. else if(strcmp(str,"SavePointAll")==0)
  2898. {
  2899. if(map[sd->bl.m].flag.noreturn)
  2900. return 0;
  2901. for (i = 0; i < users; i++)
  2902. {
  2903. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  2904. {
  2905. if(map[pl_sd->bl.m].flag.noreturn)
  2906. continue;
  2907. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  2908. }
  2909. }
  2910. }
  2911. else if(strcmp(str,"SavePoint")==0)
  2912. {
  2913. if(map[sd->bl.m].flag.noreturn)
  2914. return 0;
  2915. mapindex=sd->status.save_point.map;
  2916. x=sd->status.save_point.x;
  2917. y=sd->status.save_point.y;
  2918. for (i = 0; i < users; i++)
  2919. {
  2920. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  2921. {
  2922. if(map[pl_sd->bl.m].flag.noreturn)
  2923. continue;
  2924. pc_setpos(pl_sd,mapindex,x,y,3);
  2925. }
  2926. }
  2927. }
  2928. else
  2929. {
  2930. mapindex = mapindex_name2id(str);
  2931. for (i = 0; i < users; i++)
  2932. {
  2933. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  2934. {
  2935. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  2936. continue;
  2937. pc_setpos(pl_sd,mapindex,x,y,3);
  2938. }
  2939. }
  2940. }
  2941. return 0;
  2942. }
  2943. /*==========================================
  2944. *
  2945. *------------------------------------------
  2946. */
  2947. int buildin_heal(struct script_state *st)
  2948. {
  2949. int hp,sp;
  2950. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2951. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2952. pc_heal(script_rid2sd(st),hp,sp);
  2953. return 0;
  2954. }
  2955. /*==========================================
  2956. *
  2957. *------------------------------------------
  2958. */
  2959. int buildin_itemheal(struct script_state *st)
  2960. {
  2961. int hp,sp;
  2962. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2963. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2964. if(potion_flag==1) {
  2965. potion_hp = hp;
  2966. potion_sp = sp;
  2967. return 0;
  2968. }
  2969. pc_itemheal(script_rid2sd(st),hp,sp);
  2970. return 0;
  2971. }
  2972. /*==========================================
  2973. *
  2974. *------------------------------------------
  2975. */
  2976. int buildin_percentheal(struct script_state *st)
  2977. {
  2978. int hp,sp;
  2979. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2980. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2981. if(potion_flag==1) {
  2982. potion_per_hp = hp;
  2983. potion_per_sp = sp;
  2984. return 0;
  2985. }
  2986. pc_percentheal(script_rid2sd(st),hp,sp);
  2987. return 0;
  2988. }
  2989. /*==========================================
  2990. *
  2991. *------------------------------------------
  2992. */
  2993. int buildin_jobchange(struct script_state *st)
  2994. {
  2995. int job, upper=-1;
  2996. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  2997. if( st->end>st->start+3 )
  2998. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  2999. if ((job >= 0 && job < MAX_PC_CLASS)){
  3000. pc_jobchange(script_rid2sd(st),job, upper);
  3001. if(use_irc && irc_announce_jobchange_flag)
  3002. irc_announce_jobchange(script_rid2sd(st));
  3003. }
  3004. return 0;
  3005. }
  3006. /*==========================================
  3007. *
  3008. *------------------------------------------
  3009. */
  3010. int buildin_input(struct script_state *st)
  3011. {
  3012. struct map_session_data *sd=NULL;
  3013. int num=(st->end>st->start+2)?st->stack->stack_data[st->start+2].u.num:0;
  3014. char *name=(char *) ((st->end>st->start+2)?str_buf+str_data[num&0x00ffffff].str:"");
  3015. // char prefix=*name;
  3016. char postfix=name[strlen(name)-1];
  3017. sd=script_rid2sd(st);
  3018. if(sd->state.menu_or_input){
  3019. sd->state.menu_or_input=0;
  3020. if( postfix=='$' ){
  3021. // 文字列
  3022. if(st->end>st->start+2){ // 引数1個
  3023. set_reg(sd,num,name,(void*)sd->npc_str);
  3024. }else{
  3025. ShowError("buildin_input: string discarded !!\n");
  3026. return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. // commented by Lupus (check Value Number Input fix in clif.c)
  3031. // readded by Yor: set ammount to 0 instead of cancel trade.
  3032. // ** Fix by fritz :X keeps people from abusing old input bugs
  3033. if (sd->npc_amount < 0) { //** If input amount is less then 0
  3034. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  3035. // buildin_close(st); // ** close
  3036. sd->npc_amount = 0;
  3037. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  3038. sd->npc_amount = battle_config.vending_max_value;
  3039. // 数値
  3040. if(st->end>st->start+2){ // 引数1個
  3041. set_reg(sd,num,name,(void*)sd->npc_amount);
  3042. } else {
  3043. // ragemu互換のため
  3044. pc_setreg(sd,add_str((unsigned char *) "l14"),sd->npc_amount);
  3045. }
  3046. return 0;
  3047. }
  3048. //state.menu_or_input = 0
  3049. st->state=RERUNLINE;
  3050. if(postfix=='$')
  3051. clif_scriptinputstr(sd,st->oid);
  3052. else
  3053. clif_scriptinput(sd,st->oid);
  3054. sd->state.menu_or_input=1;
  3055. return 0;
  3056. }
  3057. /*==========================================
  3058. * 変数設定
  3059. *------------------------------------------
  3060. */
  3061. int buildin_set(struct script_state *st)
  3062. {
  3063. struct map_session_data *sd=NULL;
  3064. int num=st->stack->stack_data[st->start+2].u.num;
  3065. char *name=str_buf+str_data[num&0x00ffffff].str;
  3066. char prefix=*name;
  3067. char postfix=name[strlen(name)-1];
  3068. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  3069. ShowError("script: buildin_set: not name\n");
  3070. return 1;
  3071. }
  3072. if( prefix!='$' )
  3073. sd=script_rid2sd(st);
  3074. if( postfix=='$' ){
  3075. // 文字列
  3076. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  3077. set_reg(sd,num,name,(void*)str);
  3078. }else{
  3079. // 数値
  3080. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3081. set_reg(sd,num,name,(void*)val);
  3082. }
  3083. return 0;
  3084. }
  3085. /*==========================================
  3086. * 配列変数設定
  3087. *------------------------------------------
  3088. */
  3089. int buildin_setarray(struct script_state *st)
  3090. {
  3091. struct map_session_data *sd=NULL;
  3092. int num=st->stack->stack_data[st->start+2].u.num;
  3093. char *name=str_buf+str_data[num&0x00ffffff].str;
  3094. char prefix=*name;
  3095. char postfix=name[strlen(name)-1];
  3096. int i,j;
  3097. if( prefix!='$' && prefix!='@' ){
  3098. ShowWarning("buildin_setarray: illegal scope !\n");
  3099. return 1;
  3100. }
  3101. if( prefix!='$' )
  3102. sd=script_rid2sd(st);
  3103. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  3104. void *v;
  3105. if( postfix=='$' )
  3106. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  3107. else
  3108. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  3109. set_reg( sd, num+(j<<24), name, v);
  3110. }
  3111. return 0;
  3112. }
  3113. /*==========================================
  3114. * 配列変数クリア
  3115. *------------------------------------------
  3116. */
  3117. int buildin_cleararray(struct script_state *st)
  3118. {
  3119. struct map_session_data *sd=NULL;
  3120. int num=st->stack->stack_data[st->start+2].u.num;
  3121. char *name=str_buf+str_data[num&0x00ffffff].str;
  3122. char prefix=*name;
  3123. char postfix=name[strlen(name)-1];
  3124. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3125. int i;
  3126. void *v;
  3127. if( prefix!='$' && prefix!='@' ){
  3128. ShowWarning("buildin_cleararray: illegal scope !\n");
  3129. return 1;
  3130. }
  3131. if( prefix!='$' )
  3132. sd=script_rid2sd(st);
  3133. if( postfix=='$' )
  3134. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  3135. else
  3136. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  3137. for(i=0;i<sz;i++)
  3138. set_reg(sd,num+(i<<24),name,v);
  3139. return 0;
  3140. }
  3141. /*==========================================
  3142. * 配列変数コピー
  3143. *------------------------------------------
  3144. */
  3145. int buildin_copyarray(struct script_state *st)
  3146. {
  3147. struct map_session_data *sd=NULL;
  3148. int num=st->stack->stack_data[st->start+2].u.num;
  3149. char *name=str_buf+str_data[num&0x00ffffff].str;
  3150. char prefix=*name;
  3151. char postfix=name[strlen(name)-1];
  3152. int num2=st->stack->stack_data[st->start+3].u.num;
  3153. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  3154. char prefix2=*name2;
  3155. char postfix2=name2[strlen(name2)-1];
  3156. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3157. int i;
  3158. if( prefix!='$' && prefix!='@' && prefix2!='$' && prefix2!='@' ){
  3159. ShowWarning("buildin_copyarray: illegal scope !\n");
  3160. return 1;
  3161. }
  3162. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  3163. ShowError("buildin_copyarray: type mismatch !\n");
  3164. return 1;
  3165. }
  3166. if( prefix!='$' || prefix2!='$' )
  3167. sd=script_rid2sd(st);
  3168. // if two array is the same and (num > num2), bottom-up copy is required [Eoe / jA 1116]
  3169. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  3170. for(i=sz-1;i>=0;i--)
  3171. set_reg(sd,num+(i<<24),name, get_val2(st,num2+(i<<24)) );
  3172. } else {
  3173. for(i=0;i<sz;i++)
  3174. set_reg(sd,num+(i<<24),name, get_val2(st,num2+(i<<24)) );
  3175. }
  3176. return 0;
  3177. }
  3178. /*==========================================
  3179. * 配列変数のサイズ所得
  3180. *------------------------------------------
  3181. */
  3182. static int getarraysize(struct script_state *st,int num,int postfix)
  3183. {
  3184. int i=(num>>24),c=-1; // Moded to -1 because even if the first element is 0, it will still report as 1 [Lance]
  3185. for(;i<128;i++){
  3186. // num must be the first elements of array [Eoe / jA 1127]
  3187. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24));
  3188. if(postfix=='$' && *((char*)v) ) c=i;
  3189. if(postfix!='$' && (int)v )c=i;
  3190. }
  3191. return c+1;
  3192. }
  3193. int buildin_getarraysize(struct script_state *st)
  3194. {
  3195. int num=st->stack->stack_data[st->start+2].u.num;
  3196. char *name=str_buf+str_data[num&0x00ffffff].str;
  3197. char prefix=*name;
  3198. char postfix=name[strlen(name)-1];
  3199. if( prefix!='$' && prefix!='@' ){
  3200. ShowWarning("buildin_copyarray: illegal scope !\n");
  3201. return 1;
  3202. }
  3203. push_val(st->stack,C_INT,getarraysize(st,num,postfix) );
  3204. return 0;
  3205. }
  3206. /*==========================================
  3207. * 配列変数から要素削除
  3208. *------------------------------------------
  3209. */
  3210. int buildin_deletearray(struct script_state *st)
  3211. {
  3212. struct map_session_data *sd=NULL;
  3213. int num=st->stack->stack_data[st->start+2].u.num;
  3214. char *name=str_buf+str_data[num&0x00ffffff].str;
  3215. char prefix=*name;
  3216. char postfix=name[strlen(name)-1];
  3217. int count=1;
  3218. int i,sz=getarraysize(st,num,postfix)-(num>>24)-count+1;
  3219. if( (st->end > st->start+3) )
  3220. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3221. if( prefix!='$' && prefix!='@' ){
  3222. ShowWarning("buildin_deletearray: illegal scope !\n");
  3223. return 1;
  3224. }
  3225. if( prefix!='$' )
  3226. sd=script_rid2sd(st);
  3227. for(i=0;i<sz;i++){
  3228. set_reg(sd,num+(i<<24),name, get_val2(st,num+((i+count)<<24) ) );
  3229. }
  3230. for(;i<(128-(num>>24));i++){
  3231. if( postfix!='$' ) set_reg(sd,num+(i<<24),name, 0);
  3232. if( postfix=='$' ) set_reg(sd,num+(i<<24),name, (void *) "");
  3233. }
  3234. return 0;
  3235. }
  3236. /*==========================================
  3237. * 指定要素を表す値(キー)を所得する
  3238. *------------------------------------------
  3239. */
  3240. int buildin_getelementofarray(struct script_state *st)
  3241. {
  3242. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  3243. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3244. if(i>127 || i<0){
  3245. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  3246. push_val(st->stack,C_INT,0);
  3247. return 1;
  3248. }else{
  3249. push_val(st->stack,C_NAME,
  3250. (i<<24) | st->stack->stack_data[st->start+2].u.num );
  3251. }
  3252. }else{
  3253. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  3254. push_val(st->stack,C_INT,0);
  3255. }
  3256. return 0;
  3257. }
  3258. /*==========================================
  3259. *
  3260. *------------------------------------------
  3261. */
  3262. int buildin_setlook(struct script_state *st)
  3263. {
  3264. int type,val;
  3265. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3266. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3267. pc_changelook(script_rid2sd(st),type,val);
  3268. return 0;
  3269. }
  3270. /*==========================================
  3271. *
  3272. *------------------------------------------
  3273. */
  3274. int buildin_cutin(struct script_state *st)
  3275. {
  3276. int type;
  3277. conv_str(st,& (st->stack->stack_data[st->start+2]));
  3278. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3279. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  3280. return 0;
  3281. }
  3282. /*==========================================
  3283. * カードのイラストを表示する
  3284. *------------------------------------------
  3285. */
  3286. int buildin_cutincard(struct script_state *st)
  3287. {
  3288. int itemid;
  3289. struct item_data *i_data;
  3290. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3291. i_data = itemdb_exists(itemid);
  3292. if (i_data)
  3293. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  3294. return 0;
  3295. }
  3296. /*==========================================
  3297. *
  3298. *------------------------------------------
  3299. */
  3300. int buildin_viewpoint(struct script_state *st)
  3301. {
  3302. int type,x,y,id,color;
  3303. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3304. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3305. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3306. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3307. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3308. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  3309. return 0;
  3310. }
  3311. /*==========================================
  3312. *
  3313. *------------------------------------------
  3314. */
  3315. int buildin_countitem(struct script_state *st)
  3316. {
  3317. int nameid=0,count=0,i;
  3318. struct map_session_data *sd;
  3319. struct script_data *data;
  3320. sd = script_rid2sd(st);
  3321. data=&(st->stack->stack_data[st->start+2]);
  3322. get_val(st,data);
  3323. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3324. const char *name=conv_str(st,data);
  3325. struct item_data *item_data;
  3326. if( (item_data = itemdb_searchname(name)) != NULL)
  3327. nameid=item_data->nameid;
  3328. }else
  3329. nameid=conv_num(st,data);
  3330. if (nameid>=500) //if no such ID then skip this iteration
  3331. for(i=0;i<MAX_INVENTORY;i++){
  3332. if(sd->status.inventory[i].nameid==nameid)
  3333. count+=sd->status.inventory[i].amount;
  3334. }
  3335. else{
  3336. if(battle_config.error_log)
  3337. ShowError("wrong item ID : countitem(%i)\n",nameid);
  3338. push_val(st->stack,C_INT,0);
  3339. return 1;
  3340. }
  3341. push_val(st->stack,C_INT,count);
  3342. return 0;
  3343. }
  3344. /*==========================================
  3345. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  3346. * returns number of items that met the conditions
  3347. *------------------------------------------
  3348. */
  3349. int buildin_countitem2(struct script_state *st)
  3350. {
  3351. int nameid=0,count=0,i;
  3352. int iden,ref,attr,c1,c2,c3,c4;
  3353. struct map_session_data *sd;
  3354. struct script_data *data;
  3355. sd = script_rid2sd(st);
  3356. data=&(st->stack->stack_data[st->start+2]);
  3357. get_val(st,data);
  3358. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3359. const char *name=conv_str(st,data);
  3360. struct item_data *item_data;
  3361. if( (item_data = itemdb_searchname(name)) != NULL)
  3362. nameid=item_data->nameid;
  3363. }else
  3364. nameid=conv_num(st,data);
  3365. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3366. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3367. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3368. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3369. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3370. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3371. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3372. if (nameid>=500) //if no such ID then skip this iteration
  3373. for(i=0;i<MAX_INVENTORY;i++){
  3374. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3375. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  3376. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  3377. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  3378. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  3379. sd->status.inventory[i].card[3]!=c4)
  3380. continue;
  3381. count+=sd->status.inventory[i].amount;
  3382. }
  3383. else{
  3384. if(battle_config.error_log)
  3385. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  3386. push_val(st->stack,C_INT,0);
  3387. return 1;
  3388. }
  3389. push_val(st->stack,C_INT,count);
  3390. return 0;
  3391. }
  3392. /*==========================================
  3393. * 重量チェック
  3394. *------------------------------------------
  3395. */
  3396. int buildin_checkweight(struct script_state *st)
  3397. {
  3398. int nameid=0,amount,i;
  3399. unsigned long weight;
  3400. struct map_session_data *sd;
  3401. struct script_data *data;
  3402. sd = script_rid2sd(st);
  3403. data=&(st->stack->stack_data[st->start+2]);
  3404. get_val(st,data);
  3405. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3406. const char *name=conv_str(st,data);
  3407. struct item_data *item_data = itemdb_searchname(name);
  3408. if( item_data )
  3409. nameid=item_data->nameid;
  3410. }else
  3411. nameid=conv_num(st,data);
  3412. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3413. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  3414. push_val(st->stack,C_INT,0);
  3415. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  3416. return 1;
  3417. }
  3418. weight = itemdb_weight(nameid)*amount;
  3419. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  3420. push_val(st->stack,C_INT,0);
  3421. } else {
  3422. //Check if the inventory ain't full.
  3423. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  3424. i = pc_search_inventory(sd,0);
  3425. if (i >= 0) //Empty slot available.
  3426. push_val(st->stack,C_INT,1);
  3427. else //Inventory full
  3428. push_val(st->stack,C_INT,0);
  3429. }
  3430. return 0;
  3431. }
  3432. /*==========================================
  3433. *
  3434. *------------------------------------------
  3435. */
  3436. int buildin_getitem(struct script_state *st)
  3437. {
  3438. int nameid,nameidsrc,amount,flag = 0;
  3439. struct item item_tmp;
  3440. struct map_session_data *sd;
  3441. struct script_data *data;
  3442. sd = script_rid2sd(st);
  3443. data=&(st->stack->stack_data[st->start+2]);
  3444. get_val(st,data);
  3445. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3446. const char *name=conv_str(st,data);
  3447. struct item_data *item_data = itemdb_searchname(name);
  3448. nameid=512; //Apple item ID
  3449. if( item_data != NULL)
  3450. nameid=item_data->nameid;
  3451. }else
  3452. nameid=conv_num(st,data);
  3453. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0) {
  3454. return 0; //return if amount <=0, skip the useles iteration
  3455. }
  3456. //Violet Box, Blue Box, etc - random item pick
  3457. if((nameidsrc = nameid)<0) { // Save real ID of the source Box [Lupus]
  3458. nameid=itemdb_searchrandomid(-nameid);
  3459. if(log_config.present > 0)
  3460. log_present(sd, -nameidsrc, nameid); //fixed missing ID by Lupus
  3461. flag = 1;
  3462. }
  3463. if(nameid > 0) {
  3464. memset(&item_tmp,0,sizeof(item_tmp));
  3465. item_tmp.nameid=nameid;
  3466. if(!flag)
  3467. item_tmp.identify=1;
  3468. else
  3469. item_tmp.identify=!itemdb_isequip3(nameid);
  3470. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  3471. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  3472. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  3473. return 0;
  3474. if((flag = pc_additem(sd,&item_tmp,amount))) {
  3475. clif_additem(sd,0,0,flag);
  3476. if(pc_candrop(sd,nameid))
  3477. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  3478. }
  3479. //Logs items, got from (N)PC scripts [Lupus]
  3480. if(log_config.pick > 0 ) {
  3481. log_pick(sd, "N", 0, nameid, amount, NULL);
  3482. }
  3483. //Logs
  3484. }
  3485. return 0;
  3486. }
  3487. /*==========================================
  3488. *
  3489. *------------------------------------------
  3490. */
  3491. int buildin_getitem2(struct script_state *st)
  3492. {
  3493. int nameid,amount,flag = 0;
  3494. int iden,ref,attr,c1,c2,c3,c4;
  3495. struct item_data *item_data;
  3496. struct item item_tmp;
  3497. struct map_session_data *sd;
  3498. struct script_data *data;
  3499. sd = script_rid2sd(st);
  3500. data=&(st->stack->stack_data[st->start+2]);
  3501. get_val(st,data);
  3502. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3503. const char *name=conv_str(st,data);
  3504. struct item_data *item_data = itemdb_searchname(name);
  3505. nameid=512; //Apple item ID
  3506. if( item_data )
  3507. nameid=item_data->nameid;
  3508. }else
  3509. nameid=conv_num(st,data);
  3510. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3511. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3512. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3513. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3514. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3515. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3516. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3517. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  3518. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  3519. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  3520. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  3521. return 0;
  3522. if(nameid<0) { // ランダム
  3523. nameid=itemdb_searchrandomid(-nameid);
  3524. flag = 1;
  3525. }
  3526. if(nameid > 0) {
  3527. memset(&item_tmp,0,sizeof(item_tmp));
  3528. item_data=itemdb_exists(nameid);
  3529. if (item_data == NULL)
  3530. return -1;
  3531. if(item_data->type==4 || item_data->type==5){
  3532. if(ref > 10) ref = 10;
  3533. }
  3534. else if(item_data->type==7) {
  3535. iden = 1;
  3536. ref = 0;
  3537. }
  3538. else {
  3539. iden = 1;
  3540. ref = attr = 0;
  3541. }
  3542. item_tmp.nameid=nameid;
  3543. if(!flag)
  3544. item_tmp.identify=iden;
  3545. else if(item_data->type==4 || item_data->type==5)
  3546. item_tmp.identify=0;
  3547. item_tmp.refine=ref;
  3548. item_tmp.attribute=attr;
  3549. item_tmp.card[0]=c1;
  3550. item_tmp.card[1]=c2;
  3551. item_tmp.card[2]=c3;
  3552. item_tmp.card[3]=c4;
  3553. if((flag = pc_additem(sd,&item_tmp,amount))) {
  3554. clif_additem(sd,0,0,flag);
  3555. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  3556. }
  3557. //Logs items, got from (N)PC scripts [Lupus]
  3558. if(log_config.pick > 0 ) {
  3559. log_pick(sd, "N", 0, nameid, amount, &item_tmp);
  3560. }
  3561. //Logs
  3562. }
  3563. return 0;
  3564. }
  3565. /*==========================================
  3566. * gets an item with someone's name inscribed [Skotlex]
  3567. * getinscribeditem item_num, character_name
  3568. * Returned Qty is always 1, only works on equip-able
  3569. * equipment
  3570. *------------------------------------------
  3571. */
  3572. int buildin_getnameditem(struct script_state *st)
  3573. {
  3574. int nameid;
  3575. struct item item_tmp;
  3576. struct map_session_data *sd, *tsd;
  3577. struct script_data *data;
  3578. sd = script_rid2sd(st);
  3579. if (sd == NULL)
  3580. { //Player not attached!
  3581. push_val(st->stack,C_INT,0);
  3582. return 0;
  3583. }
  3584. data=&(st->stack->stack_data[st->start+2]);
  3585. get_val(st,data);
  3586. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3587. const char *name=conv_str(st,data);
  3588. struct item_data *item_data = itemdb_searchname(name);
  3589. if( item_data == NULL)
  3590. { //Failed
  3591. push_val(st->stack,C_INT,0);
  3592. return 0;
  3593. }
  3594. nameid = item_data->nameid;
  3595. }else
  3596. nameid = conv_num(st,data);
  3597. if(!itemdb_exists(nameid) || !itemdb_isequip3(nameid))
  3598. { //We don't allow non-equipable/stackable items to be named
  3599. //to avoid any qty exploits that could happen because of it.
  3600. push_val(st->stack,C_INT,0);
  3601. return 0;
  3602. }
  3603. data=&(st->stack->stack_data[st->start+3]);
  3604. get_val(st,data);
  3605. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  3606. tsd=map_nick2sd(conv_str(st,data));
  3607. else //Char Id was given
  3608. tsd=map_charid2sd(conv_num(st,data));
  3609. if( tsd == NULL )
  3610. { //Failed
  3611. push_val(st->stack,C_INT,0);
  3612. return 0;
  3613. }
  3614. memset(&item_tmp,0,sizeof(item_tmp));
  3615. item_tmp.nameid=nameid;
  3616. item_tmp.amount=1;
  3617. item_tmp.identify=1;
  3618. item_tmp.card[0]=254; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  3619. item_tmp.card[2]=tsd->status.char_id;
  3620. item_tmp.card[3]=tsd->status.char_id >> 16;
  3621. if(pc_additem(sd,&item_tmp,1)) {
  3622. push_val(st->stack,C_INT,0);
  3623. return 0; //Failed to add item, we will not drop if they don't fit
  3624. }
  3625. //Logs items, got from (N)PC scripts [Lupus]
  3626. if(log_config.pick > 0 ) {
  3627. log_pick(sd, "N", 0, item_tmp.nameid, item_tmp.amount, &item_tmp);
  3628. }
  3629. //Logs
  3630. push_val(st->stack,C_INT,1);
  3631. return 0;
  3632. }
  3633. /*==========================================
  3634. * gets a random item ID from an item group [Skotlex]
  3635. * groupranditem group_num
  3636. *------------------------------------------
  3637. */
  3638. int buildin_grouprandomitem(struct script_state *st)
  3639. {
  3640. int group;
  3641. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3642. push_val(st->stack, C_INT, itemdb_searchrandomgroup(group));
  3643. return 0;
  3644. }
  3645. /*==========================================
  3646. *
  3647. *------------------------------------------
  3648. */
  3649. int buildin_makeitem(struct script_state *st)
  3650. {
  3651. int nameid,amount,flag = 0;
  3652. int x,y,m;
  3653. char *mapname;
  3654. struct item item_tmp;
  3655. struct script_data *data;
  3656. data=&(st->stack->stack_data[st->start+2]);
  3657. get_val(st,data);
  3658. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3659. const char *name=conv_str(st,data);
  3660. struct item_data *item_data = itemdb_searchname(name);
  3661. nameid=512; //Apple Item ID
  3662. if( item_data )
  3663. nameid=item_data->nameid;
  3664. }else
  3665. nameid=conv_num(st,data);
  3666. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3667. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  3668. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  3669. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  3670. if(strcmp(mapname,"this")==0)
  3671. {
  3672. struct map_session_data *sd;
  3673. sd = script_rid2sd(st);
  3674. if (!sd) return 0; //Failed...
  3675. m=sd->bl.m;
  3676. } else
  3677. m=map_mapname2mapid(mapname);
  3678. if(nameid<0) { // ランダム
  3679. nameid=itemdb_searchrandomid(-nameid);
  3680. flag = 1;
  3681. }
  3682. if(nameid > 0) {
  3683. memset(&item_tmp,0,sizeof(item_tmp));
  3684. item_tmp.nameid=nameid;
  3685. if(!flag)
  3686. item_tmp.identify=1;
  3687. else
  3688. item_tmp.identify=!itemdb_isequip3(nameid);
  3689. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  3690. }
  3691. return 0;
  3692. }
  3693. /*==========================================
  3694. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  3695. *------------------------------------------
  3696. */
  3697. int buildin_delitem(struct script_state *st)
  3698. {
  3699. int nameid=0,amount,i,important_item=0;
  3700. struct map_session_data *sd;
  3701. struct script_data *data;
  3702. sd = script_rid2sd(st);
  3703. data=&(st->stack->stack_data[st->start+2]);
  3704. get_val(st,data);
  3705. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3706. const char *name=conv_str(st,data);
  3707. struct item_data *item_data = itemdb_searchname(name);
  3708. //nameid=512;
  3709. if( item_data )
  3710. nameid=item_data->nameid;
  3711. }else
  3712. nameid=conv_num(st,data);
  3713. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3714. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  3715. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  3716. return 0;
  3717. }
  3718. //1st pass
  3719. //here we won't delete items with CARDS, named items but we count them
  3720. for(i=0;i<MAX_INVENTORY;i++){
  3721. //we don't delete wrong item or equipped item
  3722. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3723. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  3724. continue;
  3725. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  3726. if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
  3727. intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2]) );
  3728. //clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
  3729. sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
  3730. //now this egg'll be deleted as a common unimportant item
  3731. }
  3732. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  3733. if( sd->status.inventory[i].card[0] || sd->status.inventory[i].card[1] ||
  3734. sd->status.inventory[i].card[2] || sd->status.inventory[i].card[3] || sd->status.inventory[i].refine) {
  3735. //this is important item, count it
  3736. important_item++;
  3737. continue;
  3738. }
  3739. if(sd->status.inventory[i].amount>=amount){
  3740. //Logs items, got from (N)PC scripts [Lupus]
  3741. if(log_config.pick > 0 ) {
  3742. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  3743. }
  3744. //Logs
  3745. pc_delitem(sd,i,amount,0);
  3746. return 0; //we deleted exact amount of items. now exit
  3747. } else {
  3748. amount-=sd->status.inventory[i].amount;
  3749. //Logs items, got from (N)PC scripts [Lupus]
  3750. if(log_config.pick > 0 ) {
  3751. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  3752. }
  3753. //Logs
  3754. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  3755. }
  3756. }
  3757. //2nd pass
  3758. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  3759. if (important_item>0 && amount>0)
  3760. for(i=0;i<MAX_INVENTORY;i++){
  3761. //we don't delete wrong item
  3762. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3763. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  3764. continue;
  3765. if(sd->status.inventory[i].amount>=amount){
  3766. //Logs items, got from (N)PC scripts [Lupus]
  3767. if(log_config.pick > 0 ) {
  3768. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  3769. }
  3770. //Logs
  3771. pc_delitem(sd,i,amount,0);
  3772. return 0; //we deleted exact amount of items. now exit
  3773. } else {
  3774. amount-=sd->status.inventory[i].amount;
  3775. //Logs items, got from (N)PC scripts [Lupus]
  3776. if(log_config.pick > 0 ) {
  3777. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  3778. }
  3779. //Logs
  3780. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  3781. }
  3782. }
  3783. return 0;
  3784. }
  3785. /*==========================================
  3786. * advanced version of delitem [modified by Mihilion]
  3787. *------------------------------------------
  3788. */
  3789. int buildin_delitem2(struct script_state *st)
  3790. {
  3791. int nameid=0,amount,i=0;
  3792. int iden,ref,attr,c1,c2,c3,c4;
  3793. struct map_session_data *sd;
  3794. struct script_data *data;
  3795. sd = script_rid2sd(st);
  3796. data=&(st->stack->stack_data[st->start+2]);
  3797. get_val(st,data);
  3798. if( data->type==C_STR || data->type==C_CONSTSTR ){
  3799. const char *name=conv_str(st,data);
  3800. struct item_data *item_data = itemdb_searchname(name);
  3801. //nameid=512;
  3802. if( item_data )
  3803. nameid=item_data->nameid;
  3804. }else
  3805. nameid=conv_num(st,data);
  3806. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  3807. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  3808. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  3809. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  3810. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  3811. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  3812. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  3813. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  3814. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  3815. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  3816. return 0;
  3817. }
  3818. for(i=0;i<MAX_INVENTORY;i++){
  3819. //we don't delete wrong item or equipped item
  3820. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  3821. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  3822. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  3823. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  3824. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  3825. sd->status.inventory[i].card[3]!=c4)
  3826. continue;
  3827. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  3828. if(sd->inventory_data[i]->type==7 && sd->status.inventory[i].card[0] == (short)0xff00 && search_petDB_index(nameid, PET_EGG) >= 0 ){
  3829. intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2]) );
  3830. //clear egg flag. so it won't be put in IMPORTANT items (eggs look like item with 2 cards ^_^)
  3831. sd->status.inventory[i].card[1] = sd->status.inventory[i].card[0] = 0;
  3832. //now this egg'll be deleted as a common unimportant item
  3833. }
  3834. if(sd->status.inventory[i].amount>=amount){
  3835. //Logs items, got from (N)PC scripts [Lupus]
  3836. if(log_config.pick > 0 ) {
  3837. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  3838. }
  3839. //Logs
  3840. pc_delitem(sd,i,amount,0);
  3841. return 0; //we deleted exact amount of items. now exit
  3842. } else {
  3843. amount-=sd->status.inventory[i].amount;
  3844. //Logs items, got from (N)PC scripts [Lupus]
  3845. if(log_config.pick > 0 ) {
  3846. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  3847. }
  3848. //Logs
  3849. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  3850. }
  3851. }
  3852. return 0;
  3853. }
  3854. /*==========================================
  3855. * Enables/Disables use of items while in an NPC [Skotlex]
  3856. *------------------------------------------
  3857. */
  3858. int buildin_enableitemuse(struct script_state *st) {
  3859. struct map_session_data *sd;
  3860. sd=script_rid2sd(st);
  3861. if (sd)
  3862. sd->npc_item_flag = st->oid;
  3863. return 0;
  3864. }
  3865. int buildin_disableitemuse(struct script_state *st) {
  3866. struct map_session_data *sd;
  3867. sd=script_rid2sd(st);
  3868. if (sd)
  3869. sd->npc_item_flag = 0;
  3870. return 0;
  3871. }
  3872. /*==========================================
  3873. *キャラ関係のパラメータ取得
  3874. *------------------------------------------
  3875. */
  3876. int buildin_readparam(struct script_state *st)
  3877. {
  3878. int type;
  3879. struct map_session_data *sd;
  3880. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3881. if( st->end>st->start+3 )
  3882. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3883. else
  3884. sd=script_rid2sd(st);
  3885. if(sd==NULL){
  3886. push_val(st->stack,C_INT,-1);
  3887. return 0;
  3888. }
  3889. push_val(st->stack,C_INT,pc_readparam(sd,type));
  3890. return 0;
  3891. }
  3892. /*==========================================
  3893. *キャラ関係のID取得
  3894. *------------------------------------------
  3895. */
  3896. int buildin_getcharid(struct script_state *st)
  3897. {
  3898. int num;
  3899. struct map_session_data *sd;
  3900. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3901. if( st->end>st->start+3 )
  3902. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  3903. else
  3904. sd=script_rid2sd(st);
  3905. if(sd==NULL){
  3906. push_val(st->stack,C_INT,-1);
  3907. return 0;
  3908. }
  3909. if(num==0)
  3910. push_val(st->stack,C_INT,sd->status.char_id);
  3911. if(num==1)
  3912. push_val(st->stack,C_INT,sd->status.party_id);
  3913. if(num==2)
  3914. push_val(st->stack,C_INT,sd->status.guild_id);
  3915. if(num==3)
  3916. push_val(st->stack,C_INT,sd->status.account_id);
  3917. return 0;
  3918. }
  3919. /*==========================================
  3920. *指定IDのPT名取得
  3921. *------------------------------------------
  3922. */
  3923. char *buildin_getpartyname_sub(int party_id)
  3924. {
  3925. struct party *p;
  3926. p=NULL;
  3927. p=party_search(party_id);
  3928. if(p!=NULL){
  3929. char *buf;
  3930. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  3931. memcpy(buf, p->name, NAME_LENGTH-1);
  3932. return buf;
  3933. }
  3934. return 0;
  3935. }
  3936. int buildin_getpartyname(struct script_state *st)
  3937. {
  3938. char *name;
  3939. int party_id;
  3940. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3941. name=buildin_getpartyname_sub(party_id);
  3942. if(name != NULL)
  3943. push_str(st->stack,C_STR,(unsigned char *)name);
  3944. else
  3945. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  3946. return 0;
  3947. }
  3948. /*==========================================
  3949. *指定IDのPT人数とメンバーID取得
  3950. *------------------------------------------
  3951. */
  3952. int buildin_getpartymember(struct script_state *st)
  3953. {
  3954. struct party *p;
  3955. int i,j=0;
  3956. p=NULL;
  3957. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  3958. if(p!=NULL){
  3959. for(i=0;i<MAX_PARTY;i++){
  3960. if(p->member[i].account_id){
  3961. // printf("name:%s %d\n",p->member[i].name,i);
  3962. mapreg_setregstr(add_str((unsigned char *) "$@partymembername$")+(i<<24),p->member[i].name);
  3963. j++;
  3964. }
  3965. }
  3966. }
  3967. mapreg_setreg(add_str((unsigned char *) "$@partymembercount"),j);
  3968. return 0;
  3969. }
  3970. /*==========================================
  3971. *指定IDのギルド名取得
  3972. *------------------------------------------
  3973. */
  3974. char *buildin_getguildname_sub(int guild_id)
  3975. {
  3976. struct guild *g=NULL;
  3977. g=guild_search(guild_id);
  3978. if(g!=NULL){
  3979. char *buf;
  3980. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  3981. memcpy(buf, g->name, NAME_LENGTH-1);
  3982. return buf;
  3983. }
  3984. return NULL;
  3985. }
  3986. int buildin_getguildname(struct script_state *st)
  3987. {
  3988. char *name;
  3989. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3990. name=buildin_getguildname_sub(guild_id);
  3991. if(name != NULL)
  3992. push_str(st->stack,C_STR,(unsigned char *) name);
  3993. else
  3994. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  3995. return 0;
  3996. }
  3997. /*==========================================
  3998. *指定IDのGuildMaster名取得
  3999. *------------------------------------------
  4000. */
  4001. char *buildin_getguildmaster_sub(int guild_id)
  4002. {
  4003. struct guild *g=NULL;
  4004. g=guild_search(guild_id);
  4005. if(g!=NULL){
  4006. char *buf;
  4007. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  4008. memcpy(buf, g->master, NAME_LENGTH-1);
  4009. return buf;
  4010. }
  4011. return 0;
  4012. }
  4013. int buildin_getguildmaster(struct script_state *st)
  4014. {
  4015. char *master;
  4016. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4017. master=buildin_getguildmaster_sub(guild_id);
  4018. if(master!=0)
  4019. push_str(st->stack,C_STR,(unsigned char *) master);
  4020. else
  4021. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  4022. return 0;
  4023. }
  4024. int buildin_getguildmasterid(struct script_state *st)
  4025. {
  4026. char *master;
  4027. struct map_session_data *sd=NULL;
  4028. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4029. master=buildin_getguildmaster_sub(guild_id);
  4030. if(master!=0){
  4031. if((sd=map_nick2sd(master)) == NULL){
  4032. push_val(st->stack,C_INT,0);
  4033. return 0;
  4034. }
  4035. push_val(st->stack,C_INT,sd->status.char_id);
  4036. }else{
  4037. push_val(st->stack,C_INT,0);
  4038. }
  4039. return 0;
  4040. }
  4041. /*==========================================
  4042. * キャラクタの名前
  4043. *------------------------------------------
  4044. */
  4045. int buildin_strcharinfo(struct script_state *st)
  4046. {
  4047. struct map_session_data *sd;
  4048. char *buf;
  4049. int num;
  4050. sd=script_rid2sd(st);
  4051. if (!sd) { //Avoid crashing....
  4052. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4053. return 0;
  4054. }
  4055. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4056. switch(num){
  4057. case 0:
  4058. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  4059. memcpy(buf, sd->status.name, NAME_LENGTH-1);
  4060. push_str(st->stack,C_STR,(unsigned char *) buf);
  4061. break;
  4062. case 1:
  4063. buf=buildin_getpartyname_sub(sd->status.party_id);
  4064. if(buf!=0)
  4065. push_str(st->stack,C_STR,(unsigned char *) buf);
  4066. else
  4067. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4068. break;
  4069. case 2:
  4070. buf=buildin_getguildname_sub(sd->status.guild_id);
  4071. if(buf != NULL)
  4072. push_str(st->stack,C_STR,(unsigned char *) buf);
  4073. else
  4074. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4075. break;
  4076. default:
  4077. ShowWarning("buildin_strcharinfo: unknown parameter.");
  4078. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  4079. break;
  4080. }
  4081. return 0;
  4082. }
  4083. unsigned int equip[10]={0x0100,0x0010,0x0020,0x0002,0x0004,0x0040,0x0008,0x0080,0x0200,0x0001};
  4084. /*==========================================
  4085. * GetEquipID(Pos); Pos: 1-10
  4086. *------------------------------------------
  4087. */
  4088. int buildin_getequipid(struct script_state *st)
  4089. {
  4090. int i,num;
  4091. struct map_session_data *sd;
  4092. struct item_data* item;
  4093. sd=script_rid2sd(st);
  4094. if(sd == NULL)
  4095. {
  4096. ShowError("getequipid: sd == NULL\n");
  4097. return 0;
  4098. }
  4099. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4100. i=pc_checkequip(sd,equip[num-1]);
  4101. if(i >= 0){
  4102. item=sd->inventory_data[i];
  4103. if(item)
  4104. push_val(st->stack,C_INT,item->nameid);
  4105. else
  4106. push_val(st->stack,C_INT,0);
  4107. }else{
  4108. push_val(st->stack,C_INT,-1);
  4109. }
  4110. return 0;
  4111. }
  4112. /*==========================================
  4113. * 装備名文字列(精錬メニュー用)
  4114. *------------------------------------------
  4115. */
  4116. int buildin_getequipname(struct script_state *st)
  4117. {
  4118. int i,num;
  4119. struct map_session_data *sd;
  4120. struct item_data* item;
  4121. char *buf;
  4122. buf=(char *)aCallocA(64,sizeof(char));
  4123. sd=script_rid2sd(st);
  4124. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4125. i=pc_checkequip(sd,equip[num-1]);
  4126. if(i >= 0){
  4127. item=sd->inventory_data[i];
  4128. if(item)
  4129. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  4130. else
  4131. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  4132. }else{
  4133. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  4134. }
  4135. push_str(st->stack,C_STR,(unsigned char *) buf);
  4136. return 0;
  4137. }
  4138. /*==========================================
  4139. * getbrokenid [Valaris]
  4140. *------------------------------------------
  4141. */
  4142. int buildin_getbrokenid(struct script_state *st)
  4143. {
  4144. int i,num,id=0,brokencounter=0;
  4145. struct map_session_data *sd;
  4146. sd=script_rid2sd(st);
  4147. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4148. for(i=0; i<MAX_INVENTORY; i++) {
  4149. if(sd->status.inventory[i].attribute==1){
  4150. brokencounter++;
  4151. if(num==brokencounter){
  4152. id=sd->status.inventory[i].nameid;
  4153. break;
  4154. }
  4155. }
  4156. }
  4157. push_val(st->stack,C_INT,id);
  4158. return 0;
  4159. }
  4160. /*==========================================
  4161. * repair [Valaris]
  4162. *------------------------------------------
  4163. */
  4164. int buildin_repair(struct script_state *st)
  4165. {
  4166. int i,num;
  4167. int repaircounter=0;
  4168. struct map_session_data *sd;
  4169. sd=script_rid2sd(st);
  4170. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4171. for(i=0; i<MAX_INVENTORY; i++) {
  4172. if(sd->status.inventory[i].attribute==1){
  4173. repaircounter++;
  4174. if(num==repaircounter){
  4175. sd->status.inventory[i].attribute=0;
  4176. clif_equiplist(sd);
  4177. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  4178. clif_misceffect(&sd->bl, 3);
  4179. clif_displaymessage(sd->fd,"Item has been repaired.");
  4180. break;
  4181. }
  4182. }
  4183. }
  4184. return 0;
  4185. }
  4186. /*==========================================
  4187. * 装備チェック
  4188. *------------------------------------------
  4189. */
  4190. int buildin_getequipisequiped(struct script_state *st)
  4191. {
  4192. int i,num;
  4193. struct map_session_data *sd;
  4194. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4195. sd=script_rid2sd(st);
  4196. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  4197. i = -1;
  4198. else
  4199. i=pc_checkequip(sd,equip[num-1]);
  4200. if(i >= 0)
  4201. push_val(st->stack,C_INT,1);
  4202. else
  4203. push_val(st->stack,C_INT,0);
  4204. return 0;
  4205. }
  4206. /*==========================================
  4207. * 装備品精錬可能チェック
  4208. *------------------------------------------
  4209. */
  4210. int buildin_getequipisenableref(struct script_state *st)
  4211. {
  4212. int i,num;
  4213. struct map_session_data *sd;
  4214. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4215. sd=script_rid2sd(st);
  4216. i=pc_checkequip(sd,equip[num-1]);
  4217. if(i >= 0 && num<7 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  4218. {
  4219. push_val(st->stack,C_INT,1);
  4220. } else {
  4221. push_val(st->stack,C_INT,0);
  4222. }
  4223. return 0;
  4224. }
  4225. /*==========================================
  4226. * 装備品鑑定チェック
  4227. *------------------------------------------
  4228. */
  4229. int buildin_getequipisidentify(struct script_state *st)
  4230. {
  4231. int i,num;
  4232. struct map_session_data *sd;
  4233. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4234. sd=script_rid2sd(st);
  4235. i=pc_checkequip(sd,equip[num-1]);
  4236. if(i >= 0)
  4237. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  4238. else
  4239. push_val(st->stack,C_INT,0);
  4240. return 0;
  4241. }
  4242. /*==========================================
  4243. * 装備品精錬度
  4244. *------------------------------------------
  4245. */
  4246. int buildin_getequiprefinerycnt(struct script_state *st)
  4247. {
  4248. int i,num;
  4249. struct map_session_data *sd;
  4250. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4251. sd=script_rid2sd(st);
  4252. i=pc_checkequip(sd,equip[num-1]);
  4253. if(i >= 0)
  4254. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  4255. else
  4256. push_val(st->stack,C_INT,0);
  4257. return 0;
  4258. }
  4259. /*==========================================
  4260. * 装備品武器LV
  4261. *------------------------------------------
  4262. */
  4263. int buildin_getequipweaponlv(struct script_state *st)
  4264. {
  4265. int i,num;
  4266. struct map_session_data *sd;
  4267. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4268. sd=script_rid2sd(st);
  4269. i=pc_checkequip(sd,equip[num-1]);
  4270. if(i >= 0 && sd->inventory_data[i])
  4271. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  4272. else
  4273. push_val(st->stack,C_INT,0);
  4274. return 0;
  4275. }
  4276. /*==========================================
  4277. * 装備品精錬成功率
  4278. *------------------------------------------
  4279. */
  4280. int buildin_getequippercentrefinery(struct script_state *st)
  4281. {
  4282. int i,num;
  4283. struct map_session_data *sd;
  4284. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4285. sd=script_rid2sd(st);
  4286. i=pc_checkequip(sd,equip[num-1]);
  4287. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  4288. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  4289. else
  4290. push_val(st->stack,C_INT,0);
  4291. return 0;
  4292. }
  4293. /*==========================================
  4294. * 精錬成功
  4295. *------------------------------------------
  4296. */
  4297. int buildin_successrefitem(struct script_state *st)
  4298. {
  4299. int i,num,ep;
  4300. struct map_session_data *sd;
  4301. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4302. sd=script_rid2sd(st);
  4303. i=pc_checkequip(sd,equip[num-1]);
  4304. if(i >= 0) {
  4305. ep=sd->status.inventory[i].equip;
  4306. if(log_config.refine > 0)
  4307. log_refine(sd, i, 1);
  4308. //Logs items, got from (N)PC scripts [Lupus]
  4309. if(log_config.pick > 0 ) {
  4310. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  4311. }
  4312. //Logs
  4313. sd->status.inventory[i].refine++;
  4314. pc_unequipitem(sd,i,2);
  4315. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  4316. clif_delitem(sd,i,1);
  4317. //Logs items, got from (N)PC scripts [Lupus]
  4318. if(log_config.pick > 0 ) {
  4319. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  4320. }
  4321. //Logs
  4322. clif_additem(sd,i,1,0);
  4323. pc_equipitem(sd,i,ep);
  4324. clif_misceffect(&sd->bl,3);
  4325. if(sd->status.inventory[i].refine == 10 && sd->status.inventory[i].card[0] == 0x00ff && sd->char_id == MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])){ // Fame point system [DracoRPG]
  4326. switch (sd->inventory_data[i]->wlv){
  4327. case 1:
  4328. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  4329. break;
  4330. case 2:
  4331. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  4332. break;
  4333. case 3:
  4334. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  4335. break;
  4336. }
  4337. }
  4338. }
  4339. return 0;
  4340. }
  4341. /*==========================================
  4342. * 精錬失敗
  4343. *------------------------------------------
  4344. */
  4345. int buildin_failedrefitem(struct script_state *st)
  4346. {
  4347. int i,num;
  4348. struct map_session_data *sd;
  4349. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4350. sd=script_rid2sd(st);
  4351. i=pc_checkequip(sd,equip[num-1]);
  4352. if(i >= 0) {
  4353. if(log_config.refine > 0)
  4354. log_refine(sd, i, 0);
  4355. //Logs items, got from (N)PC scripts [Lupus]
  4356. if(log_config.pick > 0 ) {
  4357. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  4358. }
  4359. //Logs
  4360. sd->status.inventory[i].refine = 0;
  4361. pc_unequipitem(sd,i,3);
  4362. // 精錬失敗エフェクトのパケット
  4363. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  4364. pc_delitem(sd,i,1,0);
  4365. // 他の人にも失敗を通知
  4366. clif_misceffect(&sd->bl,2);
  4367. }
  4368. return 0;
  4369. }
  4370. /*==========================================
  4371. *
  4372. *------------------------------------------
  4373. */
  4374. int buildin_statusup(struct script_state *st)
  4375. {
  4376. int type;
  4377. struct map_session_data *sd;
  4378. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4379. sd=script_rid2sd(st);
  4380. pc_statusup(sd,type);
  4381. return 0;
  4382. }
  4383. /*==========================================
  4384. *
  4385. *------------------------------------------
  4386. */
  4387. int buildin_statusup2(struct script_state *st)
  4388. {
  4389. int type,val;
  4390. struct map_session_data *sd;
  4391. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4392. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4393. sd=script_rid2sd(st);
  4394. pc_statusup2(sd,type,val);
  4395. return 0;
  4396. }
  4397. /*==========================================
  4398. * 装備品による能力値ボーナス
  4399. *------------------------------------------
  4400. */
  4401. int buildin_bonus(struct script_state *st)
  4402. {
  4403. int type,val;
  4404. struct map_session_data *sd;
  4405. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4406. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4407. sd=script_rid2sd(st);
  4408. pc_bonus(sd,type,val);
  4409. return 0;
  4410. }
  4411. /*==========================================
  4412. * 装備品による能力値ボーナス
  4413. *------------------------------------------
  4414. */
  4415. int buildin_bonus2(struct script_state *st)
  4416. {
  4417. int type,type2,val;
  4418. struct map_session_data *sd;
  4419. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4420. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4421. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4422. sd=script_rid2sd(st);
  4423. pc_bonus2(sd,type,type2,val);
  4424. return 0;
  4425. }
  4426. /*==========================================
  4427. * 装備品による能力値ボーナス
  4428. *------------------------------------------
  4429. */
  4430. int buildin_bonus3(struct script_state *st)
  4431. {
  4432. int type,type2,type3,val;
  4433. struct map_session_data *sd;
  4434. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4435. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4436. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4437. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4438. sd=script_rid2sd(st);
  4439. pc_bonus3(sd,type,type2,type3,val);
  4440. return 0;
  4441. }
  4442. int buildin_bonus4(struct script_state *st)
  4443. {
  4444. int type,type2,type3,type4,val;
  4445. struct map_session_data *sd;
  4446. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4447. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4448. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4449. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4450. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4451. sd=script_rid2sd(st);
  4452. pc_bonus4(sd,type,type2,type3,type4,val);
  4453. return 0;
  4454. }
  4455. /*==========================================
  4456. * スキル所得
  4457. *------------------------------------------
  4458. */
  4459. int buildin_skill(struct script_state *st)
  4460. {
  4461. int id,level,flag=1;
  4462. struct map_session_data *sd;
  4463. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4464. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4465. if( st->end>st->start+4 )
  4466. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4467. sd=script_rid2sd(st);
  4468. pc_skill(sd,id,level,flag);
  4469. return 0;
  4470. }
  4471. // add x levels of skill (stackable) [Valaris]
  4472. int buildin_addtoskill(struct script_state *st)
  4473. {
  4474. int id,level,flag=2;
  4475. struct map_session_data *sd;
  4476. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4477. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4478. if( st->end>st->start+4 )
  4479. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4480. sd=script_rid2sd(st);
  4481. pc_skill(sd,id,level,flag);
  4482. return 0;
  4483. }
  4484. /*==========================================
  4485. * ギルドスキル取得
  4486. *------------------------------------------
  4487. */
  4488. int buildin_guildskill(struct script_state *st)
  4489. {
  4490. int id,level,flag=0;
  4491. struct map_session_data *sd;
  4492. int i=0;
  4493. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4494. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4495. if( st->end>st->start+4 )
  4496. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  4497. sd=script_rid2sd(st);
  4498. for(i=0;i<level;i++)
  4499. guild_skillup(sd,id,flag);
  4500. return 0;
  4501. }
  4502. /*==========================================
  4503. * スキルレベル所得
  4504. *------------------------------------------
  4505. */
  4506. int buildin_getskilllv(struct script_state *st)
  4507. {
  4508. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4509. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  4510. return 0;
  4511. }
  4512. /*==========================================
  4513. * getgdskilllv(Guild_ID, Skill_ID);
  4514. * skill_id = 10000 : GD_APPROVAL
  4515. * 10001 : GD_KAFRACONTRACT
  4516. * 10002 : GD_GUARDIANRESEARCH
  4517. * 10003 : GD_GUARDUP
  4518. * 10004 : GD_EXTENSION
  4519. *------------------------------------------
  4520. */
  4521. int buildin_getgdskilllv(struct script_state *st)
  4522. {
  4523. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4524. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4525. struct guild *g=guild_search(guild_id);
  4526. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  4527. return 0;
  4528. /*
  4529. struct map_session_data *sd=NULL;
  4530. struct guild *g=NULL;
  4531. int skill_id;
  4532. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4533. sd=script_rid2sd(st);
  4534. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  4535. if(sd && g) {
  4536. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  4537. } else {
  4538. push_val(st->stack,C_INT,-1);
  4539. }
  4540. return 0;
  4541. */
  4542. }
  4543. /*==========================================
  4544. *
  4545. *------------------------------------------
  4546. */
  4547. int buildin_basicskillcheck(struct script_state *st)
  4548. {
  4549. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  4550. return 0;
  4551. }
  4552. /*==========================================
  4553. *
  4554. *------------------------------------------
  4555. */
  4556. int buildin_getgmlevel(struct script_state *st)
  4557. {
  4558. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  4559. return 0;
  4560. }
  4561. /*==========================================
  4562. *
  4563. *------------------------------------------
  4564. */
  4565. int buildin_end(struct script_state *st)
  4566. {
  4567. st->state = END;
  4568. return 0;
  4569. }
  4570. /*==========================================
  4571. *
  4572. *------------------------------------------
  4573. */
  4574. int buildin_checkoption(struct script_state *st)
  4575. {
  4576. int type;
  4577. struct map_session_data *sd;
  4578. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4579. sd=script_rid2sd(st);
  4580. if(sd->sc.option & type){
  4581. push_val(st->stack,C_INT,1);
  4582. } else {
  4583. push_val(st->stack,C_INT,0);
  4584. }
  4585. return 0;
  4586. }
  4587. /*==========================================
  4588. *
  4589. *------------------------------------------
  4590. */
  4591. int buildin_checkoption1(struct script_state *st)
  4592. {
  4593. int type;
  4594. struct map_session_data *sd;
  4595. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4596. sd=script_rid2sd(st);
  4597. if(sd->sc.opt1 & type){
  4598. push_val(st->stack,C_INT,1);
  4599. } else {
  4600. push_val(st->stack,C_INT,0);
  4601. }
  4602. return 0;
  4603. }
  4604. /*==========================================
  4605. *
  4606. *------------------------------------------
  4607. */
  4608. int buildin_checkoption2(struct script_state *st)
  4609. {
  4610. int type;
  4611. struct map_session_data *sd;
  4612. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4613. sd=script_rid2sd(st);
  4614. if(sd->sc.opt2 & type){
  4615. push_val(st->stack,C_INT,1);
  4616. } else {
  4617. push_val(st->stack,C_INT,0);
  4618. }
  4619. return 0;
  4620. }
  4621. /*==========================================
  4622. *
  4623. *------------------------------------------
  4624. */
  4625. int buildin_setoption(struct script_state *st)
  4626. {
  4627. int type;
  4628. struct map_session_data *sd;
  4629. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4630. sd=script_rid2sd(st);
  4631. pc_setoption(sd,type);
  4632. return 0;
  4633. }
  4634. /*==========================================
  4635. * Checkcart [Valaris]
  4636. *------------------------------------------
  4637. */
  4638. int buildin_checkcart(struct script_state *st)
  4639. {
  4640. struct map_session_data *sd;
  4641. sd=script_rid2sd(st);
  4642. if(pc_iscarton(sd)){
  4643. push_val(st->stack,C_INT,1);
  4644. } else {
  4645. push_val(st->stack,C_INT,0);
  4646. }
  4647. return 0;
  4648. }
  4649. /*==========================================
  4650. * カートを付ける
  4651. *------------------------------------------
  4652. */
  4653. int buildin_setcart(struct script_state *st)
  4654. {
  4655. struct map_session_data *sd;
  4656. sd=script_rid2sd(st);
  4657. pc_setcart(sd,1);
  4658. return 0;
  4659. }
  4660. /*==========================================
  4661. * checkfalcon [Valaris]
  4662. *------------------------------------------
  4663. */
  4664. int buildin_checkfalcon(struct script_state *st)
  4665. {
  4666. struct map_session_data *sd;
  4667. sd=script_rid2sd(st);
  4668. if(pc_isfalcon(sd)){
  4669. push_val(st->stack,C_INT,1);
  4670. } else {
  4671. push_val(st->stack,C_INT,0);
  4672. }
  4673. return 0;
  4674. }
  4675. /*==========================================
  4676. * 鷹を付ける
  4677. *------------------------------------------
  4678. */
  4679. int buildin_setfalcon(struct script_state *st)
  4680. {
  4681. struct map_session_data *sd;
  4682. sd=script_rid2sd(st);
  4683. pc_setfalcon(sd);
  4684. return 0;
  4685. }
  4686. /*==========================================
  4687. * Checkcart [Valaris]
  4688. *------------------------------------------
  4689. */
  4690. int buildin_checkriding(struct script_state *st)
  4691. {
  4692. struct map_session_data *sd;
  4693. sd=script_rid2sd(st);
  4694. if(pc_isriding(sd)){
  4695. push_val(st->stack,C_INT,1);
  4696. } else {
  4697. push_val(st->stack,C_INT,0);
  4698. }
  4699. return 0;
  4700. }
  4701. /*==========================================
  4702. * ペコペコ乗り
  4703. *------------------------------------------
  4704. */
  4705. int buildin_setriding(struct script_state *st)
  4706. {
  4707. struct map_session_data *sd;
  4708. sd=script_rid2sd(st);
  4709. pc_setriding(sd);
  4710. return 0;
  4711. }
  4712. /*==========================================
  4713. * セーブポイントの保存
  4714. *------------------------------------------
  4715. */
  4716. int buildin_savepoint(struct script_state *st)
  4717. {
  4718. int x,y;
  4719. short map;
  4720. char *str;
  4721. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4722. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4723. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4724. map = mapindex_name2id(str);
  4725. if (map)
  4726. pc_setsavepoint(script_rid2sd(st),map,x,y);
  4727. return 0;
  4728. }
  4729. /*==========================================
  4730. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  4731. *------------------------------------------
  4732. */
  4733. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  4734. {
  4735. int type;
  4736. time_t timer;
  4737. struct tm *t;
  4738. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4739. switch(type){
  4740. case 2:
  4741. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  4742. // from the system clock.)
  4743. push_val(st->stack,C_INT,(int)time(NULL));
  4744. break;
  4745. case 1:
  4746. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  4747. time(&timer);
  4748. t=localtime(&timer);
  4749. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  4750. break;
  4751. case 0:
  4752. default:
  4753. //type 0:(System Ticks)
  4754. push_val(st->stack,C_INT,gettick());
  4755. break;
  4756. }
  4757. return 0;
  4758. }
  4759. /*==========================================
  4760. * GetTime(Type);
  4761. * 1: Sec 2: Min 3: Hour
  4762. * 4: WeekDay 5: MonthDay 6: Month
  4763. * 7: Year
  4764. *------------------------------------------
  4765. */
  4766. int buildin_gettime(struct script_state *st) /* Asgard Version */
  4767. {
  4768. int type;
  4769. time_t timer;
  4770. struct tm *t;
  4771. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4772. time(&timer);
  4773. t=localtime(&timer);
  4774. switch(type){
  4775. case 1://Sec(0~59)
  4776. push_val(st->stack,C_INT,t->tm_sec);
  4777. break;
  4778. case 2://Min(0~59)
  4779. push_val(st->stack,C_INT,t->tm_min);
  4780. break;
  4781. case 3://Hour(0~23)
  4782. push_val(st->stack,C_INT,t->tm_hour);
  4783. break;
  4784. case 4://WeekDay(0~6)
  4785. push_val(st->stack,C_INT,t->tm_wday);
  4786. break;
  4787. case 5://MonthDay(01~31)
  4788. push_val(st->stack,C_INT,t->tm_mday);
  4789. break;
  4790. case 6://Month(01~12)
  4791. push_val(st->stack,C_INT,t->tm_mon+1);
  4792. break;
  4793. case 7://Year(20xx)
  4794. push_val(st->stack,C_INT,t->tm_year+1900);
  4795. break;
  4796. case 8://Year Day(01~366)
  4797. push_val(st->stack,C_INT,t->tm_yday+1);
  4798. break;
  4799. default://(format error)
  4800. push_val(st->stack,C_INT,-1);
  4801. break;
  4802. }
  4803. return 0;
  4804. }
  4805. /*==========================================
  4806. * GetTimeStr("TimeFMT", Length);
  4807. *------------------------------------------
  4808. */
  4809. int buildin_gettimestr(struct script_state *st)
  4810. {
  4811. char *tmpstr;
  4812. char *fmtstr;
  4813. int maxlen;
  4814. time_t now = time(NULL);
  4815. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4816. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4817. tmpstr=(char *)aCallocA(maxlen+1,sizeof(char));
  4818. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  4819. tmpstr[maxlen]='\0';
  4820. push_str(st->stack,C_STR,(unsigned char *) tmpstr);
  4821. return 0;
  4822. }
  4823. /*==========================================
  4824. * カプラ倉庫を開く
  4825. *------------------------------------------
  4826. */
  4827. int buildin_openstorage(struct script_state *st)
  4828. {
  4829. storage_storageopen(script_rid2sd(st));
  4830. return 0;
  4831. }
  4832. int buildin_guildopenstorage(struct script_state *st)
  4833. {
  4834. struct map_session_data *sd=script_rid2sd(st);
  4835. int ret;
  4836. ret = storage_guild_storageopen(sd);
  4837. push_val(st->stack,C_INT,ret);
  4838. return 0;
  4839. }
  4840. /*==========================================
  4841. * アイテムによるスキル発動
  4842. *------------------------------------------
  4843. */
  4844. int buildin_itemskill(struct script_state *st)
  4845. {
  4846. int id,lv;
  4847. char *str;
  4848. struct map_session_data *sd=script_rid2sd(st);
  4849. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4850. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4851. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  4852. // 詠唱中にスキルアイテムは使用できない
  4853. if(sd->ud.skilltimer != -1)
  4854. return 0;
  4855. sd->skillitem=id;
  4856. sd->skillitemlv=lv;
  4857. clif_item_skill(sd,id,lv,str);
  4858. return 0;
  4859. }
  4860. /*==========================================
  4861. * アイテム作成
  4862. *------------------------------------------
  4863. */
  4864. int buildin_produce(struct script_state *st)
  4865. {
  4866. int trigger;
  4867. struct map_session_data *sd=script_rid2sd(st);
  4868. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4869. clif_skill_produce_mix_list(sd, trigger);
  4870. return 0;
  4871. }
  4872. /*==========================================
  4873. * NPCでペット作る
  4874. *------------------------------------------
  4875. */
  4876. int buildin_makepet(struct script_state *st)
  4877. {
  4878. struct map_session_data *sd = script_rid2sd(st);
  4879. struct script_data *data;
  4880. int id,pet_id;
  4881. data=&(st->stack->stack_data[st->start+2]);
  4882. get_val(st,data);
  4883. id=conv_num(st,data);
  4884. pet_id = search_petDB_index(id, PET_CLASS);
  4885. if (pet_id < 0)
  4886. pet_id = search_petDB_index(id, PET_EGG);
  4887. if (pet_id >= 0 && sd) {
  4888. sd->catch_target_class = pet_db[pet_id].class_;
  4889. intif_create_pet(
  4890. sd->status.account_id, sd->status.char_id,
  4891. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  4892. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  4893. 100, 0, 1, pet_db[pet_id].jname);
  4894. }
  4895. return 0;
  4896. }
  4897. /*==========================================
  4898. * NPCで経験値上げる
  4899. *------------------------------------------
  4900. */
  4901. int buildin_getexp(struct script_state *st)
  4902. {
  4903. struct map_session_data *sd = script_rid2sd(st);
  4904. int base=0,job=0;
  4905. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4906. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  4907. if(base<0 || job<0)
  4908. return 0;
  4909. if(sd)
  4910. pc_gainexp(sd,base,job);
  4911. return 0;
  4912. }
  4913. /*==========================================
  4914. * Gain guild exp [Celest]
  4915. *------------------------------------------
  4916. */
  4917. int buildin_guildgetexp(struct script_state *st)
  4918. {
  4919. struct map_session_data *sd = script_rid2sd(st);
  4920. int exp;
  4921. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4922. if(exp < 0)
  4923. return 0;
  4924. if(sd && sd->status.guild_id > 0)
  4925. guild_getexp (sd, exp);
  4926. return 0;
  4927. }
  4928. /*==========================================
  4929. * Changes the guild master of a guild [Skotlex]
  4930. *------------------------------------------
  4931. */
  4932. int buildin_guildchangegm(struct script_state *st)
  4933. {
  4934. struct map_session_data *sd;
  4935. int guild_id;
  4936. char *name;
  4937. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4938. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4939. sd=map_nick2sd(name);
  4940. if (!sd)
  4941. push_val(st->stack,C_INT,0);
  4942. else
  4943. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * モンスター発生
  4948. *------------------------------------------
  4949. */
  4950. int buildin_monster(struct script_state *st)
  4951. {
  4952. int class_,amount,x,y;
  4953. char *str,*map,*event="";
  4954. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  4955. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  4956. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  4957. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  4958. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4959. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4960. if( st->end>st->start+8 )
  4961. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  4962. if (class_ >= 0 && !mobdb_checkid(class_)) {
  4963. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  4964. return 1;
  4965. }
  4966. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  4967. return 0;
  4968. }
  4969. /*==========================================
  4970. * モンスター発生
  4971. *------------------------------------------
  4972. */
  4973. int buildin_areamonster(struct script_state *st)
  4974. {
  4975. int class_,amount,x0,y0,x1,y1;
  4976. char *str,*map,*event="";
  4977. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  4978. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  4979. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  4980. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  4981. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  4982. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  4983. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4984. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4985. if( st->end>st->start+10 )
  4986. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  4987. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  4988. return 0;
  4989. }
  4990. /*==========================================
  4991. * モンスター削除
  4992. *------------------------------------------
  4993. */
  4994. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  4995. {
  4996. TBL_MOB* md = (TBL_MOB*)bl;
  4997. char *event=va_arg(ap,char *);
  4998. int allflag=va_arg(ap,int);
  4999. if(!allflag){
  5000. if(strcmp(event,md->npc_event)==0)
  5001. unit_remove_map(bl,1);
  5002. return 0;
  5003. }else{
  5004. if(!md->spawn)
  5005. unit_remove_map(bl,1);
  5006. return 0;
  5007. }
  5008. return 0;
  5009. }
  5010. int buildin_killmonster(struct script_state *st)
  5011. {
  5012. char *mapname,*event;
  5013. int m,allflag=0;
  5014. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5015. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5016. if(strcmp(event,"All")==0)
  5017. allflag = 1;
  5018. if( (m=map_mapname2mapid(mapname))<0 )
  5019. return 0;
  5020. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  5021. return 0;
  5022. }
  5023. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  5024. {
  5025. unit_remove_map(bl,1);
  5026. return 0;
  5027. }
  5028. int buildin_killmonsterall(struct script_state *st)
  5029. {
  5030. char *mapname;
  5031. int m;
  5032. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5033. if( (m=map_mapname2mapid(mapname))<0 )
  5034. return 0;
  5035. map_foreachinmap(buildin_killmonsterall_sub,
  5036. m,BL_MOB);
  5037. return 0;
  5038. }
  5039. /*==========================================
  5040. * Creates a clone of a player.
  5041. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  5042. *------------------------------------------
  5043. */
  5044. int buildin_clone(struct script_state *st) {
  5045. struct map_session_data *sd, *msd=NULL;
  5046. int char_id,master_id=0,x,y, mode = 0, flag = 0;
  5047. unsigned int duration = 0;
  5048. char *map,*event="";
  5049. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5050. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5051. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5052. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  5053. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5054. if( st->end>st->start+7 )
  5055. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5056. if( st->end>st->start+8 )
  5057. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5058. if( st->end>st->start+9 )
  5059. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5060. if( st->end>st->start+10 )
  5061. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5062. sd = map_charid2sd(char_id);
  5063. if (master_id) {
  5064. msd = map_charid2sd(master_id);
  5065. if (msd)
  5066. master_id = msd->bl.id;
  5067. else
  5068. master_id = 0;
  5069. }
  5070. if (sd) //Return ID of newly crafted clone.
  5071. push_val(st->stack,C_INT,mob_clone_spawn(sd, map, x, y, event, master_id, mode, flag, 1000*duration));
  5072. else //Failed to create clone.
  5073. push_val(st->stack,C_INT,0);
  5074. return 0;
  5075. }
  5076. /*==========================================
  5077. * イベント実行
  5078. *------------------------------------------
  5079. */
  5080. int buildin_doevent(struct script_state *st)
  5081. {
  5082. char *event;
  5083. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5084. npc_event(map_id2sd(st->rid),event,0);
  5085. return 0;
  5086. }
  5087. /*==========================================
  5088. * NPC主体イベント実行
  5089. *------------------------------------------
  5090. */
  5091. int buildin_donpcevent(struct script_state *st)
  5092. {
  5093. char *event;
  5094. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5095. npc_event_do(event);
  5096. return 0;
  5097. }
  5098. /*==========================================
  5099. * イベントタイマー追加
  5100. *------------------------------------------
  5101. */
  5102. int buildin_addtimer(struct script_state *st)
  5103. {
  5104. char *event;
  5105. int tick;
  5106. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5107. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5108. pc_addeventtimer(script_rid2sd(st),tick,event);
  5109. return 0;
  5110. }
  5111. /*==========================================
  5112. * イベントタイマー削除
  5113. *------------------------------------------
  5114. */
  5115. int buildin_deltimer(struct script_state *st)
  5116. {
  5117. char *event;
  5118. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5119. pc_deleventtimer(script_rid2sd(st),event);
  5120. return 0;
  5121. }
  5122. /*==========================================
  5123. * イベントタイマーのカウント値追加
  5124. *------------------------------------------
  5125. */
  5126. int buildin_addtimercount(struct script_state *st)
  5127. {
  5128. char *event;
  5129. int tick;
  5130. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5131. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5132. pc_addeventtimercount(script_rid2sd(st),event,tick);
  5133. return 0;
  5134. }
  5135. /*==========================================
  5136. * NPCタイマー初期化
  5137. *------------------------------------------
  5138. */
  5139. int buildin_initnpctimer(struct script_state *st)
  5140. {
  5141. struct npc_data *nd;
  5142. if( st->end > st->start+2 )
  5143. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5144. else
  5145. nd=(struct npc_data *)map_id2bl(st->oid);
  5146. //nd->u.scr.rid = st->rid; //NO, use npcattachtimer if you want a player-attached timer! [Skotlex]
  5147. npc_settimerevent_tick(nd,0);
  5148. npc_timerevent_start(nd, st->rid);
  5149. return 0;
  5150. }
  5151. /*==========================================
  5152. * NPCタイマー開始
  5153. *------------------------------------------
  5154. */
  5155. int buildin_startnpctimer(struct script_state *st)
  5156. {
  5157. struct npc_data *nd;
  5158. if( st->end > st->start+2 )
  5159. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5160. else
  5161. nd=(struct npc_data *)map_id2bl(st->oid);
  5162. npc_timerevent_start(nd, st->rid);
  5163. return 0;
  5164. }
  5165. /*==========================================
  5166. * NPCタイマー停止
  5167. *------------------------------------------
  5168. */
  5169. int buildin_stopnpctimer(struct script_state *st)
  5170. {
  5171. struct npc_data *nd;
  5172. if( st->end > st->start+2 )
  5173. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5174. else
  5175. nd=(struct npc_data *)map_id2bl(st->oid);
  5176. npc_timerevent_stop(nd);
  5177. return 0;
  5178. }
  5179. /*==========================================
  5180. * NPCタイマー情報所得
  5181. *------------------------------------------
  5182. */
  5183. int buildin_getnpctimer(struct script_state *st)
  5184. {
  5185. struct npc_data *nd;
  5186. struct map_session_data *sd;
  5187. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5188. int val=0;
  5189. if( st->end > st->start+3 )
  5190. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5191. else
  5192. nd=(struct npc_data *)map_id2bl(st->oid);
  5193. switch(type){
  5194. case 0: val=npc_gettimerevent_tick(nd); break;
  5195. case 1:
  5196. if (nd->u.scr.rid) {
  5197. sd = map_id2sd(nd->u.scr.rid);
  5198. if (!sd) {
  5199. if(battle_config.error_log)
  5200. ShowError("buildin_getnpctimer: Attached player not found!\n");
  5201. break;
  5202. }
  5203. val = (sd->npc_timer_id != -1);
  5204. } else
  5205. val= (nd->u.scr.timerid !=-1);
  5206. break;
  5207. case 2: val= nd->u.scr.timeramount; break;
  5208. }
  5209. push_val(st->stack,C_INT,val);
  5210. return 0;
  5211. }
  5212. /*==========================================
  5213. * NPCタイマー値設定
  5214. *------------------------------------------
  5215. */
  5216. int buildin_setnpctimer(struct script_state *st)
  5217. {
  5218. int tick;
  5219. struct npc_data *nd;
  5220. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5221. if( st->end > st->start+3 )
  5222. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5223. else
  5224. nd=(struct npc_data *)map_id2bl(st->oid);
  5225. npc_settimerevent_tick(nd,tick);
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * attaches the player rid to the timer [Celest]
  5230. *------------------------------------------
  5231. */
  5232. int buildin_attachnpctimer(struct script_state *st)
  5233. {
  5234. struct map_session_data *sd;
  5235. struct npc_data *nd;
  5236. nd=(struct npc_data *)map_id2bl(st->oid);
  5237. if( st->end > st->start+2 ) {
  5238. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  5239. sd=map_nick2sd(name);
  5240. } else {
  5241. sd = script_rid2sd(st);
  5242. }
  5243. if (sd==NULL)
  5244. return 0;
  5245. nd->u.scr.rid = sd->bl.id;
  5246. return 0;
  5247. }
  5248. /*==========================================
  5249. * detaches a player rid from the timer [Celest]
  5250. *------------------------------------------
  5251. */
  5252. int buildin_detachnpctimer(struct script_state *st)
  5253. {
  5254. struct npc_data *nd;
  5255. if( st->end > st->start+2 )
  5256. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5257. else
  5258. nd=(struct npc_data *)map_id2bl(st->oid);
  5259. nd->u.scr.rid = 0;
  5260. return 0;
  5261. }
  5262. /*==========================================
  5263. * To avoid "player not attached" script errors, this function is provided,
  5264. * it checks if there is a player attached to the current script. [Skotlex]
  5265. * If no, returns 0, if yes, returns the char_id of the attached player.
  5266. *------------------------------------------
  5267. */
  5268. int buildin_playerattached(struct script_state *st)
  5269. {
  5270. struct map_session_data *sd;
  5271. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  5272. push_val(st->stack,C_INT,0);
  5273. else
  5274. push_val(st->stack,C_INT,st->rid);
  5275. return 0;
  5276. }
  5277. /*==========================================
  5278. * 天の声アナウンス
  5279. *------------------------------------------
  5280. */
  5281. int buildin_announce(struct script_state *st)
  5282. {
  5283. char *str, *color=NULL;
  5284. int flag;
  5285. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5286. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5287. if (st->end>st->start+4)
  5288. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  5289. if(flag&0x0f){
  5290. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  5291. (struct block_list *)script_rid2sd(st);
  5292. if (color)
  5293. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  5294. else
  5295. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  5296. }else {
  5297. if (color)
  5298. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  5299. else
  5300. intif_GMmessage(str,(int)strlen(str)+1,flag);
  5301. }
  5302. return 0;
  5303. }
  5304. /*==========================================
  5305. * 天の声アナウンス(特定マップ)
  5306. *------------------------------------------
  5307. */
  5308. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  5309. {
  5310. char *str, *color;
  5311. int len,flag;
  5312. str=va_arg(ap,char *);
  5313. len=va_arg(ap,int);
  5314. flag=va_arg(ap,int);
  5315. color=va_arg(ap,char *);
  5316. if (color)
  5317. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  5318. else
  5319. clif_GMmessage(bl,str,len,flag|3);
  5320. return 0;
  5321. }
  5322. int buildin_mapannounce(struct script_state *st)
  5323. {
  5324. char *mapname,*str, *color=NULL;
  5325. int flag,m;
  5326. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5327. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5328. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5329. if (st->end>st->start+5)
  5330. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  5331. if( (m=map_mapname2mapid(mapname))<0 )
  5332. return 0;
  5333. map_foreachinmap(buildin_mapannounce_sub,
  5334. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  5335. return 0;
  5336. }
  5337. /*==========================================
  5338. * 天の声アナウンス(特定エリア)
  5339. *------------------------------------------
  5340. */
  5341. int buildin_areaannounce(struct script_state *st)
  5342. {
  5343. char *map,*str,*color=NULL;
  5344. int flag,m;
  5345. int x0,y0,x1,y1;
  5346. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5347. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5348. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5349. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5350. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5351. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  5352. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5353. if (st->end>st->start+9)
  5354. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  5355. if( (m=map_mapname2mapid(map))<0 )
  5356. return 0;
  5357. map_foreachinarea(buildin_mapannounce_sub,
  5358. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  5359. return 0;
  5360. }
  5361. /*==========================================
  5362. * ユーザー数所得
  5363. *------------------------------------------
  5364. */
  5365. int buildin_getusers(struct script_state *st)
  5366. {
  5367. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5368. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  5369. int val=0;
  5370. switch(flag&0x07){
  5371. case 0: val=map[bl->m].users; break;
  5372. case 1: val=map_getusers(); break;
  5373. }
  5374. push_val(st->stack,C_INT,val);
  5375. return 0;
  5376. }
  5377. /*==========================================
  5378. * Works like @WHO - displays all online users names in window
  5379. *------------------------------------------
  5380. */
  5381. int buildin_getusersname(struct script_state *st)
  5382. {
  5383. struct map_session_data *pl_sd = NULL, **pl_allsd;
  5384. int i=0,disp_num=1, users;
  5385. pl_allsd = map_getallusers(&users);
  5386. for (i=0;i<users;i++)
  5387. {
  5388. pl_sd = pl_allsd[i];
  5389. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  5390. {
  5391. if((disp_num++)%10==0)
  5392. clif_scriptnext(script_rid2sd(st),st->oid);
  5393. clif_scriptmes(script_rid2sd(st),st->oid,pl_sd->status.name);
  5394. }
  5395. }
  5396. return 0;
  5397. }
  5398. /*==========================================
  5399. * マップ指定ユーザー数所得
  5400. *------------------------------------------
  5401. */
  5402. int buildin_getmapusers(struct script_state *st)
  5403. {
  5404. char *str;
  5405. int m;
  5406. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5407. if( (m=map_mapname2mapid(str))< 0){
  5408. push_val(st->stack,C_INT,-1);
  5409. return 0;
  5410. }
  5411. push_val(st->stack,C_INT,map[m].users);
  5412. return 0;
  5413. }
  5414. /*==========================================
  5415. * エリア指定ユーザー数所得
  5416. *------------------------------------------
  5417. */
  5418. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  5419. {
  5420. int *users=va_arg(ap,int *);
  5421. (*users)++;
  5422. return 0;
  5423. }
  5424. int buildin_getareausers(struct script_state *st)
  5425. {
  5426. char *str;
  5427. int m,x0,y0,x1,y1,users=0;
  5428. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5429. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5430. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5431. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5432. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5433. if( (m=map_mapname2mapid(str))< 0){
  5434. push_val(st->stack,C_INT,-1);
  5435. return 0;
  5436. }
  5437. map_foreachinarea(buildin_getareausers_sub,
  5438. m,x0,y0,x1,y1,BL_PC,&users);
  5439. push_val(st->stack,C_INT,users);
  5440. return 0;
  5441. }
  5442. /*==========================================
  5443. * エリア指定ドロップアイテム数所得
  5444. *------------------------------------------
  5445. */
  5446. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  5447. {
  5448. int item=va_arg(ap,int);
  5449. int *amount=va_arg(ap,int *);
  5450. struct flooritem_data *drop=(struct flooritem_data *)bl;
  5451. if(drop->item_data.nameid==item)
  5452. (*amount)+=drop->item_data.amount;
  5453. return 0;
  5454. }
  5455. int buildin_getareadropitem(struct script_state *st)
  5456. {
  5457. char *str;
  5458. int m,x0,y0,x1,y1,item,amount=0;
  5459. struct script_data *data;
  5460. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5461. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5462. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5463. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5464. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5465. data=&(st->stack->stack_data[st->start+7]);
  5466. get_val(st,data);
  5467. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5468. const char *name=conv_str(st,data);
  5469. struct item_data *item_data = itemdb_searchname(name);
  5470. item=512;
  5471. if( item_data )
  5472. item=item_data->nameid;
  5473. }else
  5474. item=conv_num(st,data);
  5475. if( (m=map_mapname2mapid(str))< 0){
  5476. push_val(st->stack,C_INT,-1);
  5477. return 0;
  5478. }
  5479. map_foreachinarea(buildin_getareadropitem_sub,
  5480. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  5481. push_val(st->stack,C_INT,amount);
  5482. return 0;
  5483. }
  5484. /*==========================================
  5485. * NPCの有効化
  5486. *------------------------------------------
  5487. */
  5488. int buildin_enablenpc(struct script_state *st)
  5489. {
  5490. char *str;
  5491. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5492. npc_enable(str,1);
  5493. return 0;
  5494. }
  5495. /*==========================================
  5496. * NPCの無効化
  5497. *------------------------------------------
  5498. */
  5499. int buildin_disablenpc(struct script_state *st)
  5500. {
  5501. char *str;
  5502. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5503. npc_enable(str,0);
  5504. return 0;
  5505. }
  5506. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  5507. {
  5508. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5509. struct chat_data *cd;
  5510. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  5511. return 0;
  5512. npc_enable(nd->name,1);
  5513. nd->arenaflag=1;
  5514. if(cd->users>=cd->trigger && cd->npc_event[0])
  5515. npc_timer_event(cd->npc_event);
  5516. return 0;
  5517. }
  5518. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  5519. {
  5520. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5521. nd->arenaflag=0;
  5522. return 0;
  5523. }
  5524. /*==========================================
  5525. * 隠れているNPCの表示
  5526. *------------------------------------------
  5527. */
  5528. int buildin_hideoffnpc(struct script_state *st)
  5529. {
  5530. char *str;
  5531. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5532. npc_enable(str,2);
  5533. return 0;
  5534. }
  5535. /*==========================================
  5536. * NPCをハイディング
  5537. *------------------------------------------
  5538. */
  5539. int buildin_hideonnpc(struct script_state *st)
  5540. {
  5541. char *str;
  5542. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5543. npc_enable(str,4);
  5544. return 0;
  5545. }
  5546. /*==========================================
  5547. * 状態異常にかかる
  5548. *------------------------------------------
  5549. */
  5550. int buildin_sc_start(struct script_state *st)
  5551. {
  5552. struct block_list *bl;
  5553. int type,tick,val1,val4=0;
  5554. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5555. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5556. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5557. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  5558. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  5559. else
  5560. bl = map_id2bl(st->rid);
  5561. if (potion_flag==1 && potion_target) {
  5562. bl = map_id2bl(potion_target);
  5563. tick/=2; //Thrown potions only last half.
  5564. val4 = 1; //Mark that this was a thrown sc_effect
  5565. }
  5566. if (bl)
  5567. sc_start4(bl,type,100,val1,0,0,val4,tick);
  5568. return 0;
  5569. }
  5570. /*==========================================
  5571. * 状態異常にかかる(確率指定)
  5572. *------------------------------------------
  5573. */
  5574. int buildin_sc_start2(struct script_state *st)
  5575. {
  5576. struct block_list *bl;
  5577. int type,tick,val1,val4=0,per;
  5578. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5579. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5580. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5581. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5582. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  5583. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  5584. else
  5585. bl = map_id2bl(st->rid);
  5586. if (potion_flag==1 && potion_target) {
  5587. bl = map_id2bl(potion_target);
  5588. tick/=2;
  5589. val4 = 1;
  5590. }
  5591. if(bl)
  5592. status_change_start(bl,type,per,val1,0,0,val4,tick,0);
  5593. return 0;
  5594. }
  5595. /*==========================================
  5596. * Starts a SC_ change with the four values passed. [Skotlex]
  5597. * Final optional argument is the ID of player to affect.
  5598. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  5599. *------------------------------------------
  5600. */
  5601. int buildin_sc_start4(struct script_state *st)
  5602. {
  5603. struct block_list *bl;
  5604. int type,tick,val1,val2,val3,val4;
  5605. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5606. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5607. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5608. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5609. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5610. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5611. if( st->end>st->start+8 )
  5612. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  5613. else
  5614. bl = map_id2bl(st->rid);
  5615. if (potion_flag==1 && potion_target) {
  5616. bl = map_id2bl(potion_target);
  5617. tick/=2;
  5618. }
  5619. if (bl)
  5620. sc_start4(bl,type,100,val1,val2,val3,val4,tick);
  5621. return 0;
  5622. }
  5623. /*==========================================
  5624. * 状態異常が直る
  5625. *------------------------------------------
  5626. */
  5627. int buildin_sc_end(struct script_state *st)
  5628. {
  5629. struct block_list *bl;
  5630. int type;
  5631. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5632. bl = map_id2bl(st->rid);
  5633. if (potion_flag==1 && potion_target)
  5634. bl = map_id2bl(potion_target);
  5635. if (bl)
  5636. status_change_end(bl,type,-1);
  5637. return 0;
  5638. }
  5639. /*==========================================
  5640. * 状態異常耐性を計算した確率を返す
  5641. *------------------------------------------
  5642. */
  5643. int buildin_getscrate(struct script_state *st)
  5644. {
  5645. struct block_list *bl;
  5646. int sc_def=0,type,rate;
  5647. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5648. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5649. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  5650. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  5651. else
  5652. bl = map_id2bl(st->rid);
  5653. if (bl)
  5654. sc_def = status_get_sc_def(bl,type);
  5655. rate = rate*(10000-sc_def)/10000;
  5656. push_val(st->stack,C_INT,rate<0?0:rate);
  5657. return 0;
  5658. }
  5659. /*==========================================
  5660. *
  5661. *------------------------------------------
  5662. */
  5663. int buildin_debugmes(struct script_state *st)
  5664. {
  5665. conv_str(st,& (st->stack->stack_data[st->start+2]));
  5666. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  5667. return 0;
  5668. }
  5669. /*==========================================
  5670. *捕獲アイテム使用
  5671. *------------------------------------------
  5672. */
  5673. int buildin_catchpet(struct script_state *st)
  5674. {
  5675. int pet_id;
  5676. struct map_session_data *sd;
  5677. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  5678. sd=script_rid2sd(st);
  5679. pet_catch_process1(sd,pet_id);
  5680. return 0;
  5681. }
  5682. /*==========================================
  5683. *携帯卵孵化機使用
  5684. *------------------------------------------
  5685. */
  5686. int buildin_birthpet(struct script_state *st)
  5687. {
  5688. struct map_session_data *sd;
  5689. sd=script_rid2sd(st);
  5690. clif_sendegg(sd);
  5691. return 0;
  5692. }
  5693. /*==========================================
  5694. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  5695. *------------------------------------------
  5696. */
  5697. int buildin_resetlvl(struct script_state *st)
  5698. {
  5699. struct map_session_data *sd;
  5700. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5701. sd=script_rid2sd(st);
  5702. pc_resetlvl(sd,type);
  5703. return 0;
  5704. }
  5705. /*==========================================
  5706. * ステータスリセット
  5707. *------------------------------------------
  5708. */
  5709. int buildin_resetstatus(struct script_state *st)
  5710. {
  5711. struct map_session_data *sd;
  5712. sd=script_rid2sd(st);
  5713. pc_resetstate(sd);
  5714. return 0;
  5715. }
  5716. /*==========================================
  5717. * script command resetskill
  5718. *------------------------------------------
  5719. */
  5720. int buildin_resetskill(struct script_state *st)
  5721. {
  5722. struct map_session_data *sd;
  5723. sd=script_rid2sd(st);
  5724. pc_resetskill(sd,1);
  5725. return 0;
  5726. }
  5727. /*==========================================
  5728. *
  5729. *------------------------------------------
  5730. */
  5731. int buildin_changebase(struct script_state *st)
  5732. {
  5733. struct map_session_data *sd=NULL;
  5734. int vclass;
  5735. if( st->end>st->start+3 )
  5736. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  5737. else
  5738. sd=script_rid2sd(st);
  5739. if(sd == NULL)
  5740. return 0;
  5741. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  5742. if(vclass == JOB_WEDDING)
  5743. {
  5744. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  5745. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex]
  5746. )
  5747. return 0;
  5748. }
  5749. //If you are already using a special view (disguises?) prevent overriding it. [Skotlex]
  5750. if (sd->vd.class_ == sd->status.class_)
  5751. status_set_viewdata(&sd->bl, vclass);
  5752. return 0;
  5753. }
  5754. /*==========================================
  5755. * 性別変換
  5756. *------------------------------------------
  5757. */
  5758. int buildin_changesex(struct script_state *st) {
  5759. struct map_session_data *sd = NULL;
  5760. sd = script_rid2sd(st);
  5761. if (sd->status.sex == 0) {
  5762. sd->status.sex = 1;
  5763. sd->sex = 1;
  5764. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  5765. sd->status.class_ -= 1;
  5766. } else if (sd->status.sex == 1) {
  5767. sd->status.sex = 0;
  5768. sd->sex = 0;
  5769. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  5770. sd->status.class_ += 1;
  5771. }
  5772. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  5773. chrif_save(sd,0);
  5774. return 0;
  5775. }
  5776. /*==========================================
  5777. * npcチャット作成
  5778. *------------------------------------------
  5779. */
  5780. int buildin_waitingroom(struct script_state *st)
  5781. {
  5782. char *name,*ev="";
  5783. int limit, trigger = 0,pub=1;
  5784. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5785. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  5786. if(limit==0)
  5787. pub=3;
  5788. if( (st->end > st->start+5) ){
  5789. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  5790. get_val(st,data);
  5791. if(data->type==C_INT){
  5792. // 新Athena仕様(旧Athena仕様と互換性あり)
  5793. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  5794. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5795. }else{
  5796. // eathena仕様
  5797. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5798. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  5799. }
  5800. }else{
  5801. // 旧Athena仕様
  5802. if( st->end > st->start+4 )
  5803. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  5804. }
  5805. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  5806. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  5807. return 0;
  5808. }
  5809. /*==========================================
  5810. * Works like 'announce' but outputs in the common chat window
  5811. *------------------------------------------
  5812. */
  5813. int buildin_globalmes(struct script_state *st)
  5814. {
  5815. struct block_list *bl = map_id2bl(st->oid);
  5816. struct npc_data *nd = (struct npc_data *)bl;
  5817. char *name=NULL,*mes;
  5818. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  5819. if(mes==NULL) return 0;
  5820. if(st->end>st->start+3){ // NPC名の取得(123#456)
  5821. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  5822. } else {
  5823. name=nd->name;
  5824. }
  5825. npc_globalmessage(name,mes); // グローバルメッセージ送信
  5826. return 0;
  5827. }
  5828. /*==========================================
  5829. * npcチャット削除
  5830. *------------------------------------------
  5831. */
  5832. int buildin_delwaitingroom(struct script_state *st)
  5833. {
  5834. struct npc_data *nd;
  5835. if( st->end > st->start+2 )
  5836. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5837. else
  5838. nd=(struct npc_data *)map_id2bl(st->oid);
  5839. chat_deletenpcchat(nd);
  5840. return 0;
  5841. }
  5842. /*==========================================
  5843. * npcチャット全員蹴り出す
  5844. *------------------------------------------
  5845. */
  5846. int buildin_waitingroomkickall(struct script_state *st)
  5847. {
  5848. struct npc_data *nd;
  5849. struct chat_data *cd;
  5850. if( st->end > st->start+2 )
  5851. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5852. else
  5853. nd=(struct npc_data *)map_id2bl(st->oid);
  5854. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  5855. return 0;
  5856. chat_npckickall(cd);
  5857. return 0;
  5858. }
  5859. /*==========================================
  5860. * npcチャットイベント有効化
  5861. *------------------------------------------
  5862. */
  5863. int buildin_enablewaitingroomevent(struct script_state *st)
  5864. {
  5865. struct npc_data *nd;
  5866. struct chat_data *cd;
  5867. if( st->end > st->start+2 )
  5868. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5869. else
  5870. nd=(struct npc_data *)map_id2bl(st->oid);
  5871. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  5872. return 0;
  5873. chat_enableevent(cd);
  5874. return 0;
  5875. }
  5876. /*==========================================
  5877. * npcチャットイベント無効化
  5878. *------------------------------------------
  5879. */
  5880. int buildin_disablewaitingroomevent(struct script_state *st)
  5881. {
  5882. struct npc_data *nd;
  5883. struct chat_data *cd;
  5884. if( st->end > st->start+2 )
  5885. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  5886. else
  5887. nd=(struct npc_data *)map_id2bl(st->oid);
  5888. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  5889. return 0;
  5890. chat_disableevent(cd);
  5891. return 0;
  5892. }
  5893. /*==========================================
  5894. * npcチャット状態所得
  5895. *------------------------------------------
  5896. */
  5897. int buildin_getwaitingroomstate(struct script_state *st)
  5898. {
  5899. struct npc_data *nd;
  5900. struct chat_data *cd;
  5901. int val=0,type;
  5902. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5903. if( st->end > st->start+3 )
  5904. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5905. else
  5906. nd=(struct npc_data *)map_id2bl(st->oid);
  5907. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  5908. push_val(st->stack,C_INT,-1);
  5909. return 0;
  5910. }
  5911. switch(type){
  5912. case 0: val=cd->users; break;
  5913. case 1: val=cd->limit; break;
  5914. case 2: val=cd->trigger&0x7f; break;
  5915. case 3: val=((cd->trigger&0x80)>0); break;
  5916. case 32: val=(cd->users >= cd->limit); break;
  5917. case 33: val=(cd->users >= cd->trigger); break;
  5918. case 4:
  5919. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->title);
  5920. return 0;
  5921. case 5:
  5922. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->pass);
  5923. return 0;
  5924. case 16:
  5925. push_str(st->stack,C_CONSTSTR,(unsigned char *) cd->npc_event);
  5926. return 0;
  5927. }
  5928. push_val(st->stack,C_INT,val);
  5929. return 0;
  5930. }
  5931. /*==========================================
  5932. * チャットメンバー(規定人数)ワープ
  5933. *------------------------------------------
  5934. */
  5935. int buildin_warpwaitingpc(struct script_state *st)
  5936. {
  5937. int x,y,i,n;
  5938. char *str;
  5939. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  5940. struct chat_data *cd;
  5941. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  5942. return 0;
  5943. n=cd->trigger&0x7f;
  5944. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  5945. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5946. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5947. if( st->end > st->start+5 )
  5948. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5949. for(i=0;i<n;i++){
  5950. struct map_session_data *sd=cd->usersd[0]; // リスト先頭のPCを次々に。
  5951. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpc")+(i<<24),sd->bl.id);
  5952. if(strcmp(str,"Random")==0)
  5953. pc_randomwarp(sd,3);
  5954. else if(strcmp(str,"SavePoint")==0){
  5955. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  5956. return 0;
  5957. pc_setpos(sd,sd->status.save_point.map,
  5958. sd->status.save_point.x,sd->status.save_point.y,3);
  5959. }else
  5960. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  5961. }
  5962. mapreg_setreg(add_str((unsigned char *) "$@warpwaitingpcnum"),n);
  5963. return 0;
  5964. }
  5965. /*==========================================
  5966. * RIDのアタッチ
  5967. *------------------------------------------
  5968. */
  5969. int buildin_attachrid(struct script_state *st)
  5970. {
  5971. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5972. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  5973. return 0;
  5974. }
  5975. /*==========================================
  5976. * RIDのデタッチ
  5977. *------------------------------------------
  5978. */
  5979. int buildin_detachrid(struct script_state *st)
  5980. {
  5981. st->rid=0;
  5982. return 0;
  5983. }
  5984. /*==========================================
  5985. * 存在チェック
  5986. *------------------------------------------
  5987. */
  5988. int buildin_isloggedin(struct script_state *st)
  5989. {
  5990. push_val(st->stack,C_INT, map_id2sd(
  5991. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  5992. return 0;
  5993. }
  5994. /*==========================================
  5995. *
  5996. *------------------------------------------
  5997. */
  5998. enum { MF_NOMEMO,MF_NOTELEPORT,MF_NOSAVE,MF_NOBRANCH,MF_NOPENALTY,MF_NOZENYPENALTY,
  5999. MF_PVP,MF_PVP_NOPARTY,MF_PVP_NOGUILD,MF_GVG,MF_GVG_NOPARTY,MF_NOTRADE,MF_NOSKILL,
  6000. MF_NOWARP,MF_NOPVP,MF_NOICEWALL,MF_SNOW,MF_FOG,MF_SAKURA,MF_LEAVES,MF_RAIN,
  6001. MF_INDOORS,MF_NOGO,MF_CLOUDS,MF_CLOUDS2,MF_FIREWORKS,MF_GVG_CASTLE,MF_GVG_DUNGEON,MF_NIGHTENABLED,
  6002. MF_NOBASEEXP, MF_NOJOBEXP, MF_NOMOBLOOT, MF_NOMVPLOOT, MF_NORETURN, MF_NOWARPTO, MF_NIGHTMAREDROP,
  6003. MF_RESTRICTED, MF_NOCOMMAND, MF_NODROP };
  6004. int buildin_setmapflagnosave(struct script_state *st)
  6005. {
  6006. int m,x,y;
  6007. unsigned short mapindex;
  6008. char *str,*str2;
  6009. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6010. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6011. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6012. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6013. m = map_mapname2mapid(str);
  6014. mapindex = mapindex_name2id(str2);
  6015. if(m >= 0 && mapindex) {
  6016. map[m].flag.nosave=1;
  6017. map[m].save.map=mapindex;
  6018. map[m].save.x=x;
  6019. map[m].save.y=y;
  6020. }
  6021. return 0;
  6022. }
  6023. int buildin_setmapflag(struct script_state *st)
  6024. {
  6025. int m,i;
  6026. char *str;
  6027. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6028. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6029. m = map_mapname2mapid(str);
  6030. if(m >= 0) {
  6031. switch(i) {
  6032. case MF_NOMEMO:
  6033. map[m].flag.nomemo=1;
  6034. break;
  6035. case MF_NOTELEPORT:
  6036. map[m].flag.noteleport=1;
  6037. break;
  6038. case MF_NOBRANCH:
  6039. map[m].flag.nobranch=1;
  6040. break;
  6041. case MF_NOPENALTY:
  6042. map[m].flag.nopenalty=1;
  6043. break;
  6044. case MF_NOZENYPENALTY:
  6045. map[m].flag.nozenypenalty=1;
  6046. break;
  6047. case MF_PVP:
  6048. map[m].flag.pvp=1;
  6049. break;
  6050. case MF_PVP_NOPARTY:
  6051. map[m].flag.pvp_noparty=1;
  6052. break;
  6053. case MF_PVP_NOGUILD:
  6054. map[m].flag.pvp_noguild=1;
  6055. break;
  6056. case MF_GVG:
  6057. map[m].flag.gvg=1;
  6058. break;
  6059. case MF_GVG_NOPARTY:
  6060. map[m].flag.gvg_noparty=1;
  6061. break;
  6062. case MF_GVG_DUNGEON:
  6063. map[m].flag.gvg_dungeon=1;
  6064. break;
  6065. case MF_GVG_CASTLE:
  6066. map[m].flag.gvg_castle=1;
  6067. break;
  6068. case MF_NOTRADE:
  6069. map[m].flag.notrade=1;
  6070. break;
  6071. case MF_NODROP:
  6072. map[m].flag.nodrop=1;
  6073. break;
  6074. case MF_NOSKILL:
  6075. map[m].flag.noskill=1;
  6076. break;
  6077. case MF_NOWARP:
  6078. map[m].flag.nowarp=1;
  6079. break;
  6080. case MF_NOPVP:
  6081. map[m].flag.nopvp=1;
  6082. break;
  6083. case MF_NOICEWALL: // [Valaris]
  6084. map[m].flag.noicewall=1;
  6085. break;
  6086. case MF_SNOW: // [Valaris]
  6087. map[m].flag.snow=1;
  6088. break;
  6089. case MF_CLOUDS:
  6090. map[m].flag.clouds=1;
  6091. break;
  6092. case MF_CLOUDS2: // [Valaris]
  6093. map[m].flag.clouds2=1;
  6094. break;
  6095. case MF_FOG: // [Valaris]
  6096. map[m].flag.fog=1;
  6097. break;
  6098. case MF_FIREWORKS:
  6099. map[m].flag.fireworks=1;
  6100. break;
  6101. case MF_SAKURA: // [Valaris]
  6102. map[m].flag.sakura=1;
  6103. break;
  6104. case MF_LEAVES: // [Valaris]
  6105. map[m].flag.leaves=1;
  6106. break;
  6107. case MF_RAIN: // [Valaris]
  6108. map[m].flag.rain=1;
  6109. break;
  6110. case MF_INDOORS: // celest
  6111. map[m].flag.indoors=1;
  6112. break;
  6113. case MF_NIGHTENABLED:
  6114. map[m].flag.nightenabled=1;
  6115. break;
  6116. case MF_NOGO: // celest
  6117. map[m].flag.nogo=1;
  6118. break;
  6119. case MF_NOBASEEXP:
  6120. map[m].flag.nobaseexp=1;
  6121. break;
  6122. case MF_NOJOBEXP:
  6123. map[m].flag.nojobexp=1;
  6124. break;
  6125. case MF_NOMOBLOOT:
  6126. map[m].flag.nomobloot=1;
  6127. break;
  6128. case MF_NOMVPLOOT:
  6129. map[m].flag.nomvploot=1;
  6130. break;
  6131. case MF_NORETURN:
  6132. map[m].flag.noreturn=1;
  6133. break;
  6134. case MF_NOWARPTO:
  6135. map[m].flag.nowarpto=1;
  6136. break;
  6137. case MF_NIGHTMAREDROP:
  6138. map[m].flag.pvp_nightmaredrop=1;
  6139. break;
  6140. case MF_RESTRICTED:
  6141. map[m].flag.restricted=1;
  6142. break;
  6143. case MF_NOCOMMAND:
  6144. map[m].flag.nocommand=1;
  6145. break;
  6146. }
  6147. }
  6148. return 0;
  6149. }
  6150. int buildin_removemapflag(struct script_state *st)
  6151. {
  6152. int m,i;
  6153. char *str;
  6154. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6155. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6156. m = map_mapname2mapid(str);
  6157. if(m >= 0) {
  6158. switch(i) {
  6159. case MF_NOMEMO:
  6160. map[m].flag.nomemo=0;
  6161. break;
  6162. case MF_NOTELEPORT:
  6163. map[m].flag.noteleport=0;
  6164. break;
  6165. case MF_NOSAVE:
  6166. map[m].flag.nosave=0;
  6167. break;
  6168. case MF_NOBRANCH:
  6169. map[m].flag.nobranch=0;
  6170. break;
  6171. case MF_NOPENALTY:
  6172. map[m].flag.nopenalty=0;
  6173. break;
  6174. case MF_PVP:
  6175. map[m].flag.pvp=0;
  6176. break;
  6177. case MF_PVP_NOPARTY:
  6178. map[m].flag.pvp_noparty=0;
  6179. break;
  6180. case MF_PVP_NOGUILD:
  6181. map[m].flag.pvp_noguild=0;
  6182. break;
  6183. case MF_GVG:
  6184. map[m].flag.gvg=0;
  6185. break;
  6186. case MF_GVG_NOPARTY:
  6187. map[m].flag.gvg_noparty=0;
  6188. break;
  6189. case MF_GVG_DUNGEON:
  6190. map[m].flag.gvg_dungeon=0;
  6191. break;
  6192. case MF_GVG_CASTLE:
  6193. map[m].flag.gvg_castle=0;
  6194. break;
  6195. case MF_NOZENYPENALTY:
  6196. map[m].flag.nozenypenalty=0;
  6197. break;
  6198. case MF_NOTRADE:
  6199. map[m].flag.notrade=0;
  6200. break;
  6201. case MF_NODROP:
  6202. map[m].flag.nodrop=0;
  6203. break;
  6204. case MF_NOSKILL:
  6205. map[m].flag.noskill=0;
  6206. break;
  6207. case MF_NOWARP:
  6208. map[m].flag.nowarp=0;
  6209. break;
  6210. case MF_NOPVP:
  6211. map[m].flag.nopvp=0;
  6212. break;
  6213. case MF_NOICEWALL: // [Valaris]
  6214. map[m].flag.noicewall=0;
  6215. break;
  6216. case MF_SNOW: // [Valaris]
  6217. map[m].flag.snow=0;
  6218. break;
  6219. case MF_CLOUDS:
  6220. map[m].flag.clouds=0;
  6221. break;
  6222. case MF_CLOUDS2: // [Valaris]
  6223. map[m].flag.clouds2=0;
  6224. break;
  6225. case MF_FOG: // [Valaris]
  6226. map[m].flag.fog=0;
  6227. break;
  6228. case MF_FIREWORKS:
  6229. map[m].flag.fireworks=0;
  6230. break;
  6231. case MF_SAKURA: // [Valaris]
  6232. map[m].flag.sakura=0;
  6233. break;
  6234. case MF_LEAVES: // [Valaris]
  6235. map[m].flag.leaves=0;
  6236. break;
  6237. case MF_RAIN: // [Valaris]
  6238. map[m].flag.rain=0;
  6239. break;
  6240. case MF_INDOORS: // celest
  6241. map[m].flag.indoors=0;
  6242. break;
  6243. case MF_NIGHTENABLED:
  6244. map[m].flag.nightenabled=0;
  6245. break;
  6246. case MF_NOGO: // celest
  6247. map[m].flag.nogo=0;
  6248. break;
  6249. case MF_NOBASEEXP:
  6250. map[m].flag.nobaseexp=0;
  6251. break;
  6252. case MF_NOJOBEXP:
  6253. map[m].flag.nojobexp=0;
  6254. break;
  6255. case MF_NOMOBLOOT:
  6256. map[m].flag.nomobloot=0;
  6257. break;
  6258. case MF_NOMVPLOOT:
  6259. map[m].flag.nomvploot=0;
  6260. break;
  6261. case MF_NORETURN:
  6262. map[m].flag.noreturn=0;
  6263. break;
  6264. case MF_NOWARPTO:
  6265. map[m].flag.nowarpto=0;
  6266. break;
  6267. case MF_NIGHTMAREDROP:
  6268. map[m].flag.pvp_nightmaredrop=0;
  6269. break;
  6270. case MF_RESTRICTED:
  6271. map[m].flag.restricted=0;
  6272. break;
  6273. case MF_NOCOMMAND:
  6274. map[m].flag.nocommand=0;
  6275. break;
  6276. }
  6277. }
  6278. return 0;
  6279. }
  6280. int buildin_pvpon(struct script_state *st)
  6281. {
  6282. int m,i,users;
  6283. char *str;
  6284. struct map_session_data *pl_sd=NULL, **pl_allsd;
  6285. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6286. m = map_mapname2mapid(str);
  6287. if(m >= 0 && !map[m].flag.pvp && !map[m].flag.nopvp) {
  6288. map[m].flag.pvp = 1;
  6289. clif_send0199(m,1);
  6290. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  6291. return 0;
  6292. pl_allsd = map_getallusers(&users);
  6293. for(i=0;i<users;i++)
  6294. {
  6295. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  6296. {
  6297. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  6298. pl_sd->pvp_rank=0;
  6299. pl_sd->pvp_lastusers=0;
  6300. pl_sd->pvp_point=5;
  6301. pl_sd->pvp_won = 0;
  6302. pl_sd->pvp_lost = 0;
  6303. }
  6304. }
  6305. }
  6306. return 0;
  6307. }
  6308. int buildin_pvpoff(struct script_state *st)
  6309. {
  6310. int m,i,users;
  6311. char *str;
  6312. struct map_session_data *pl_sd=NULL, **pl_allsd;
  6313. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6314. m = map_mapname2mapid(str);
  6315. if(m >= 0 && map[m].flag.pvp && !map[m].flag.nopvp) { //fixed Lupus
  6316. map[m].flag.pvp = 0;
  6317. clif_send0199(m,0);
  6318. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  6319. return 0;
  6320. pl_allsd = map_getallusers(&users);
  6321. for(i=0;i<users;i++)
  6322. {
  6323. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  6324. {
  6325. clif_pvpset(pl_sd,0,0,2);
  6326. if(pl_sd->pvp_timer != -1) {
  6327. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  6328. pl_sd->pvp_timer = -1;
  6329. }
  6330. }
  6331. }
  6332. }
  6333. return 0;
  6334. }
  6335. int buildin_gvgon(struct script_state *st)
  6336. {
  6337. int m;
  6338. char *str;
  6339. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6340. m = map_mapname2mapid(str);
  6341. if(m >= 0 && !map[m].flag.gvg) {
  6342. map[m].flag.gvg = 1;
  6343. clif_send0199(m,3);
  6344. }
  6345. return 0;
  6346. }
  6347. int buildin_gvgoff(struct script_state *st)
  6348. {
  6349. int m;
  6350. char *str;
  6351. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6352. m = map_mapname2mapid(str);
  6353. if(m >= 0 && map[m].flag.gvg) {
  6354. map[m].flag.gvg = 0;
  6355. clif_send0199(m,0);
  6356. }
  6357. return 0;
  6358. }
  6359. /*==========================================
  6360. * Shows an emoticon on top of the player/npc
  6361. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  6362. *------------------------------------------
  6363. */
  6364. //Optional second parameter added by [Skotlex]
  6365. int buildin_emotion(struct script_state *st)
  6366. {
  6367. int type;
  6368. int player=0;
  6369. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6370. if(type < 0 || type > 100)
  6371. return 0;
  6372. if( st->end>st->start+3 )
  6373. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6374. if (player) {
  6375. struct map_session_data *sd = script_rid2sd(st);
  6376. if (sd)
  6377. clif_emotion(&sd->bl,type);
  6378. } else
  6379. clif_emotion(map_id2bl(st->oid),type);
  6380. return 0;
  6381. }
  6382. int buildin_maprespawnguildid_sub(struct block_list *bl,va_list ap)
  6383. {
  6384. int g_id=va_arg(ap,int);
  6385. int flag=va_arg(ap,int);
  6386. struct map_session_data *sd=NULL;
  6387. struct mob_data *md=NULL;
  6388. if(bl->type == BL_PC)
  6389. sd=(struct map_session_data*)bl;
  6390. if(bl->type == BL_MOB)
  6391. md=(struct mob_data *)bl;
  6392. if(sd){
  6393. if((sd->status.guild_id == g_id) && (flag&1))
  6394. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  6395. else if((sd->status.guild_id != g_id) && (flag&2))
  6396. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  6397. else if (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  6398. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3); // end addition [Valaris]
  6399. }
  6400. if(md && flag&4){
  6401. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  6402. unit_remove_map(bl,1);
  6403. }
  6404. return 0;
  6405. }
  6406. int buildin_maprespawnguildid(struct script_state *st)
  6407. {
  6408. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6409. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6410. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6411. int m=map_mapname2mapid(mapname);
  6412. if(m) map_foreachinmap(buildin_maprespawnguildid_sub,m,BL_CHAR,g_id,flag);
  6413. return 0;
  6414. }
  6415. int buildin_agitstart(struct script_state *st)
  6416. {
  6417. if(agit_flag==1) return 0; // Agit already Start.
  6418. agit_flag=1;
  6419. guild_agit_start();
  6420. return 0;
  6421. }
  6422. int buildin_agitend(struct script_state *st)
  6423. {
  6424. if(agit_flag==0) return 0; // Agit already End.
  6425. agit_flag=0;
  6426. guild_agit_end();
  6427. return 0;
  6428. }
  6429. /*==========================================
  6430. * agitcheck 1; // choice script
  6431. * if(@agit_flag == 1) goto agit;
  6432. * if(agitcheck(0) == 1) goto agit;
  6433. *------------------------------------------
  6434. */
  6435. int buildin_agitcheck(struct script_state *st)
  6436. {
  6437. struct map_session_data *sd;
  6438. int cond;
  6439. cond=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6440. if(cond == 0) {
  6441. if (agit_flag==1) push_val(st->stack,C_INT,1);
  6442. if (agit_flag==0) push_val(st->stack,C_INT,0);
  6443. } else {
  6444. sd=script_rid2sd(st);
  6445. if (agit_flag==1) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),1);
  6446. if (agit_flag==0) pc_setreg(sd,add_str((unsigned char *) "@agit_flag"),0);
  6447. }
  6448. return 0;
  6449. }
  6450. int buildin_flagemblem(struct script_state *st)
  6451. {
  6452. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6453. if(g_id < 0) return 0;
  6454. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  6455. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  6456. return 0;
  6457. }
  6458. int buildin_getcastlename(struct script_state *st)
  6459. {
  6460. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6461. struct guild_castle *gc;
  6462. int i;
  6463. char *buf=NULL;
  6464. for(i=0;i<MAX_GUILDCASTLE;i++){
  6465. if( (gc=guild_castle_search(i)) != NULL ){
  6466. if(strcmp(mapname,gc->map_name)==0){
  6467. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  6468. memcpy(buf, gc->castle_name, NAME_LENGTH-1);
  6469. break;
  6470. }
  6471. }
  6472. }
  6473. if(buf)
  6474. push_str(st->stack,C_STR,(unsigned char *) buf);
  6475. else
  6476. push_str(st->stack,C_CONSTSTR,(unsigned char *) "");
  6477. return 0;
  6478. }
  6479. int buildin_getcastledata(struct script_state *st)
  6480. {
  6481. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6482. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6483. char *event=NULL;
  6484. struct guild_castle *gc;
  6485. int i,j;
  6486. if( st->end>st->start+4 && index==0){
  6487. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  6488. if( (gc=guild_castle_search(i)) != NULL &&
  6489. strcmp(mapname,gc->map_name)==0 )
  6490. j=i;
  6491. if(j>=0){
  6492. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6493. guild_addcastleinfoevent(j,17,event);
  6494. }
  6495. }
  6496. for(i=0;i<MAX_GUILDCASTLE;i++){
  6497. if( (gc=guild_castle_search(i)) != NULL ){
  6498. if(strcmp(mapname,gc->map_name)==0){
  6499. switch(index){
  6500. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  6501. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  6502. case 2: push_val(st->stack,C_INT,gc->economy); break;
  6503. case 3: push_val(st->stack,C_INT,gc->defense); break;
  6504. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  6505. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  6506. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  6507. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  6508. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  6509. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  6510. case 10:
  6511. case 11:
  6512. case 12:
  6513. case 13:
  6514. case 14:
  6515. case 15:
  6516. case 16:
  6517. case 17:
  6518. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  6519. case 18:
  6520. case 19:
  6521. case 20:
  6522. case 21:
  6523. case 22:
  6524. case 23:
  6525. case 24:
  6526. case 25:
  6527. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  6528. default:
  6529. push_val(st->stack,C_INT,0); break;
  6530. }
  6531. return 0;
  6532. }
  6533. }
  6534. }
  6535. push_val(st->stack,C_INT,0);
  6536. return 0;
  6537. }
  6538. int buildin_setcastledata(struct script_state *st)
  6539. {
  6540. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6541. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6542. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6543. struct guild_castle *gc;
  6544. int i;
  6545. for(i=0;i<MAX_GUILDCASTLE;i++){
  6546. if( (gc=guild_castle_search(i)) != NULL ){
  6547. if(strcmp(mapname,gc->map_name)==0){
  6548. // Save Data byself First
  6549. switch(index){
  6550. case 1: gc->guild_id = value; break;
  6551. case 2: gc->economy = value; break;
  6552. case 3: gc->defense = value; break;
  6553. case 4: gc->triggerE = value; break;
  6554. case 5: gc->triggerD = value; break;
  6555. case 6: gc->nextTime = value; break;
  6556. case 7: gc->payTime = value; break;
  6557. case 8: gc->createTime = value; break;
  6558. case 9: gc->visibleC = value; break;
  6559. case 10:
  6560. case 11:
  6561. case 12:
  6562. case 13:
  6563. case 14:
  6564. case 15:
  6565. case 16:
  6566. case 17:
  6567. gc->guardian[index-10].visible = value; break;
  6568. case 18:
  6569. case 19:
  6570. case 20:
  6571. case 21:
  6572. case 22:
  6573. case 23:
  6574. case 24:
  6575. case 25:
  6576. gc->guardian[index-18].hp = value; break;
  6577. default: return 0;
  6578. }
  6579. guild_castledatasave(gc->castle_id,index,value);
  6580. return 0;
  6581. }
  6582. }
  6583. }
  6584. return 0;
  6585. }
  6586. /* =====================================================================
  6587. * ギルド情報を要求する
  6588. * ---------------------------------------------------------------------
  6589. */
  6590. int buildin_requestguildinfo(struct script_state *st)
  6591. {
  6592. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6593. char *event=NULL;
  6594. if( st->end>st->start+3 )
  6595. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6596. if(guild_id>0)
  6597. guild_npc_request_info(guild_id,event);
  6598. return 0;
  6599. }
  6600. /* =====================================================================
  6601. * カードの数を得る
  6602. * ---------------------------------------------------------------------
  6603. */
  6604. int buildin_getequipcardcnt(struct script_state *st)
  6605. {
  6606. int i,num;
  6607. struct map_session_data *sd;
  6608. int c=MAX_SLOTS;
  6609. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6610. sd=script_rid2sd(st);
  6611. i=pc_checkequip(sd,equip[num-1]);
  6612. if(sd->status.inventory[i].card[0] == 0x00ff){ // 製造武器はカードなし
  6613. push_val(st->stack,C_INT,0);
  6614. return 0;
  6615. }
  6616. do{
  6617. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  6618. sd->status.inventory[i].card[c-1] < 5000) ||
  6619. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  6620. push_val(st->stack,C_INT,(c));
  6621. return 0;
  6622. }
  6623. }while(c--);
  6624. push_val(st->stack,C_INT,0);
  6625. return 0;
  6626. }
  6627. /* ================================================================
  6628. * カード取り外し成功
  6629. * ----------------------------------------------------------------
  6630. */
  6631. int buildin_successremovecards(struct script_state *st)
  6632. {
  6633. int i,j,num,cardflag=0,flag;
  6634. struct map_session_data *sd;
  6635. struct item item_tmp;
  6636. int c=MAX_SLOTS;
  6637. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6638. sd=script_rid2sd(st);
  6639. i=pc_checkequip(sd,equip[num-1]);
  6640. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  6641. return 0;
  6642. }
  6643. do{
  6644. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  6645. sd->status.inventory[i].card[c-1] < 5000) ||
  6646. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  6647. cardflag = 1;
  6648. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  6649. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  6650. item_tmp.attribute=0;
  6651. for (j = 0; j < MAX_SLOTS; j++)
  6652. item_tmp.card[j]=0;
  6653. //Logs items, got from (N)PC scripts [Lupus]
  6654. if(log_config.pick > 0 ) {
  6655. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  6656. }
  6657. //Logs
  6658. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  6659. clif_additem(sd,0,0,flag);
  6660. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6661. }
  6662. }
  6663. }while(c--);
  6664. if(cardflag == 1){ // カードを取り除いたアイテム所得
  6665. flag=0;
  6666. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  6667. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  6668. item_tmp.attribute=sd->status.inventory[i].attribute;
  6669. //Logs items, got from (N)PC scripts [Lupus]
  6670. if(log_config.pick > 0 ) {
  6671. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  6672. }
  6673. //Logs
  6674. for (j = 0; j < MAX_SLOTS; j++)
  6675. item_tmp.card[j]=0;
  6676. pc_delitem(sd,i,1,0);
  6677. //Logs items, got from (N)PC scripts [Lupus]
  6678. if(log_config.pick > 0 ) {
  6679. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  6680. }
  6681. //Logs
  6682. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  6683. clif_additem(sd,0,0,flag);
  6684. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6685. }
  6686. clif_misceffect(&sd->bl,3);
  6687. return 0;
  6688. }
  6689. return 0;
  6690. }
  6691. /* ================================================================
  6692. * カード取り外し失敗 slot,type
  6693. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  6694. * ----------------------------------------------------------------
  6695. */
  6696. int buildin_failedremovecards(struct script_state *st)
  6697. {
  6698. int i,j,num,cardflag=0,flag,typefail;
  6699. struct map_session_data *sd;
  6700. struct item item_tmp;
  6701. int c=MAX_SLOTS;
  6702. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6703. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6704. sd=script_rid2sd(st);
  6705. i=pc_checkequip(sd,equip[num-1]);
  6706. if(sd->status.inventory[i].card[0]==0x00ff){ // 製造武器は処理しない
  6707. return 0;
  6708. }
  6709. do{
  6710. if( (sd->status.inventory[i].card[c-1] > 4000 &&
  6711. sd->status.inventory[i].card[c-1] < 5000) ||
  6712. itemdb_type(sd->status.inventory[i].card[c-1]) == 6){ // [Celest]
  6713. cardflag = 1;
  6714. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  6715. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  6716. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  6717. item_tmp.attribute=0;
  6718. for (j = 0; j < MAX_SLOTS; j++)
  6719. item_tmp.card[j]=0;
  6720. //Logs items, got from (N)PC scripts [Lupus]
  6721. if(log_config.pick > 0 ) {
  6722. log_pick(sd, "N", 0, item_tmp.nameid, 1, NULL);
  6723. }
  6724. //Logs
  6725. if((flag=pc_additem(sd,&item_tmp,1))){
  6726. clif_additem(sd,0,0,flag);
  6727. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6728. }
  6729. }
  6730. }
  6731. }while(c--);
  6732. if(cardflag == 1){
  6733. if(typefail == 0 || typefail == 2){ // 武具損失
  6734. //Logs items, got from (N)PC scripts [Lupus]
  6735. if(log_config.pick > 0 ) {
  6736. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  6737. }
  6738. //Logs
  6739. pc_delitem(sd,i,1,0);
  6740. clif_misceffect(&sd->bl,2);
  6741. return 0;
  6742. }
  6743. if(typefail == 1){ // カードのみ損失(武具を返す)
  6744. flag=0;
  6745. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  6746. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  6747. item_tmp.attribute=sd->status.inventory[i].attribute;
  6748. //Logs items, got from (N)PC scripts [Lupus]
  6749. if(log_config.pick > 0 ) {
  6750. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  6751. }
  6752. //Logs
  6753. for (j = 0; j < MAX_SLOTS; j++)
  6754. item_tmp.card[j]=0;
  6755. pc_delitem(sd,i,1,0);
  6756. //Logs items, got from (N)PC scripts [Lupus]
  6757. if(log_config.pick > 0 ) {
  6758. log_pick(sd, "N", 0, item_tmp.nameid, 1, &item_tmp);
  6759. }
  6760. //Logs
  6761. if((flag=pc_additem(sd,&item_tmp,1))){
  6762. clif_additem(sd,0,0,flag);
  6763. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  6764. }
  6765. }
  6766. clif_misceffect(&sd->bl,2);
  6767. return 0;
  6768. }
  6769. return 0;
  6770. }
  6771. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  6772. {
  6773. int x,y,m;
  6774. char *str;
  6775. char *mapname;
  6776. int x0,y0,x1,y1;
  6777. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6778. x0=0;
  6779. y0=0;
  6780. x1=map[map_mapname2mapid(mapname)].xs;
  6781. y1=map[map_mapname2mapid(mapname)].ys;
  6782. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6783. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6784. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6785. if( (m=map_mapname2mapid(mapname))< 0)
  6786. return 0;
  6787. map_foreachinarea(buildin_areawarp_sub,
  6788. m,x0,y0,x1,y1,BL_PC, map_mapname2mapid(str),x,y );
  6789. return 0;
  6790. }
  6791. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  6792. {
  6793. char *npc,*command;
  6794. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6795. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6796. npc_command(map_id2sd(st->rid),npc,command);
  6797. return 0;
  6798. }
  6799. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  6800. {
  6801. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  6802. // nd->lastaction=nd->timer=gettick();
  6803. npc_do_ontimer(st->oid, 1);
  6804. return 0;
  6805. }
  6806. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  6807. {
  6808. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  6809. // nd->lastaction=nd->timer=-1;
  6810. npc_do_ontimer(st->oid, 0);
  6811. return 0;
  6812. }
  6813. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  6814. {
  6815. char *event=va_arg(ap,char *);
  6816. int *c=va_arg(ap,int *);
  6817. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  6818. (*c)++;
  6819. return 0;
  6820. }
  6821. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  6822. {
  6823. char *mapname,*event;
  6824. int m,c=0;
  6825. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6826. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6827. if( (m=map_mapname2mapid(mapname))<0 ) {
  6828. push_val(st->stack,C_INT,-1);
  6829. return 0;
  6830. }
  6831. map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event,&c );
  6832. push_val(st->stack,C_INT, (c));
  6833. return 0;
  6834. }
  6835. int buildin_marriage(struct script_state *st)
  6836. {
  6837. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6838. struct map_session_data *sd=script_rid2sd(st);
  6839. struct map_session_data *p_sd=map_nick2sd(partner);
  6840. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  6841. push_val(st->stack,C_INT,0);
  6842. return 0;
  6843. }
  6844. push_val(st->stack,C_INT,1);
  6845. return 0;
  6846. }
  6847. int buildin_wedding_effect(struct script_state *st)
  6848. {
  6849. struct map_session_data *sd=script_rid2sd(st);
  6850. struct block_list *bl;
  6851. if(sd==NULL) {
  6852. bl=map_id2bl(st->oid);
  6853. } else
  6854. bl=&sd->bl;
  6855. clif_wedding_effect(bl);
  6856. return 0;
  6857. }
  6858. int buildin_divorce(struct script_state *st)
  6859. {
  6860. struct map_session_data *sd=script_rid2sd(st);
  6861. if(sd==NULL || pc_divorce(sd) < 0){
  6862. push_val(st->stack,C_INT,0);
  6863. return 0;
  6864. }
  6865. push_val(st->stack,C_INT,1);
  6866. return 0;
  6867. }
  6868. int buildin_ispartneron(struct script_state *st)
  6869. {
  6870. struct map_session_data *sd=script_rid2sd(st);
  6871. struct map_session_data *p_sd=NULL;
  6872. if(sd==NULL || !pc_ismarried(sd) ||
  6873. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  6874. push_val(st->stack,C_INT,0);
  6875. return 0;
  6876. }
  6877. push_val(st->stack,C_INT,1);
  6878. return 0;
  6879. }
  6880. int buildin_getpartnerid(struct script_state *st)
  6881. {
  6882. struct map_session_data *sd=script_rid2sd(st);
  6883. if (sd == NULL) {
  6884. push_val(st->stack,C_INT,0);
  6885. return 0;
  6886. }
  6887. push_val(st->stack,C_INT,sd->status.partner_id);
  6888. return 0;
  6889. }
  6890. int buildin_getchildid(struct script_state *st)
  6891. {
  6892. struct map_session_data *sd=script_rid2sd(st);
  6893. if (sd == NULL) {
  6894. push_val(st->stack,C_INT,0);
  6895. return 0;
  6896. }
  6897. push_val(st->stack,C_INT,sd->status.child);
  6898. return 0;
  6899. }
  6900. int buildin_getmotherid(struct script_state *st)
  6901. {
  6902. struct map_session_data *sd=script_rid2sd(st);
  6903. if (sd == NULL) {
  6904. push_val(st->stack,C_INT,0);
  6905. return 0;
  6906. }
  6907. push_val(st->stack,C_INT,sd->status.mother);
  6908. return 0;
  6909. }
  6910. int buildin_getfatherid(struct script_state *st)
  6911. {
  6912. struct map_session_data *sd=script_rid2sd(st);
  6913. if (sd == NULL) {
  6914. push_val(st->stack,C_INT,0);
  6915. return 0;
  6916. }
  6917. push_val(st->stack,C_INT,sd->status.father);
  6918. return 0;
  6919. }
  6920. int buildin_warppartner(struct script_state *st)
  6921. {
  6922. int x,y;
  6923. unsigned short mapindex;
  6924. char *str;
  6925. struct map_session_data *sd=script_rid2sd(st);
  6926. struct map_session_data *p_sd=NULL;
  6927. if(sd==NULL || !pc_ismarried(sd) ||
  6928. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  6929. push_val(st->stack,C_INT,0);
  6930. return 0;
  6931. }
  6932. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6933. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6934. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6935. mapindex = mapindex_name2id(str);
  6936. if (mapindex) {
  6937. pc_setpos(p_sd,mapindex,x,y,0);
  6938. push_val(st->stack,C_INT,1);
  6939. } else
  6940. push_val(st->stack,C_INT,0);
  6941. return 0;
  6942. }
  6943. /*================================================
  6944. * Script for Displaying MOB Information [Valaris]
  6945. *------------------------------------------------
  6946. */
  6947. int buildin_strmobinfo(struct script_state *st)
  6948. {
  6949. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6950. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6951. if((class_>=0 && class_<=1000) || class_ >2000)
  6952. return 0;
  6953. switch (num) {
  6954. case 1:
  6955. {
  6956. char *buf;
  6957. buf=(char *) aCallocA(NAME_LENGTH, sizeof(char));
  6958. // buf=mob_db(class_)->name;
  6959. // for string assignments you would need to go for c++ [Shinomori]
  6960. memcpy(buf, mob_db(class_)->name, NAME_LENGTH-1);
  6961. push_str(st->stack,C_STR,(unsigned char *) buf);
  6962. break;
  6963. }
  6964. case 2:
  6965. {
  6966. char *buf;
  6967. buf=(char *) aCallocA(NAME_LENGTH, sizeof(char));
  6968. // buf=mob_db(class_).jname;
  6969. // for string assignments you would need to go for c++ [Shinomori]
  6970. memcpy(buf,mob_db(class_)->jname, NAME_LENGTH-1);
  6971. push_str(st->stack,C_STR,(unsigned char *) buf);
  6972. break;
  6973. }
  6974. case 3:
  6975. push_val(st->stack,C_INT,mob_db(class_)->lv);
  6976. break;
  6977. case 4:
  6978. push_val(st->stack,C_INT,mob_db(class_)->max_hp);
  6979. break;
  6980. case 5:
  6981. push_val(st->stack,C_INT,mob_db(class_)->max_sp);
  6982. break;
  6983. case 6:
  6984. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  6985. break;
  6986. case 7:
  6987. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  6988. break;
  6989. }
  6990. return 0;
  6991. }
  6992. /*==========================================
  6993. * Summon guardians [Valaris]
  6994. *------------------------------------------
  6995. */
  6996. int buildin_guardian(struct script_state *st)
  6997. {
  6998. int class_=0,amount=1,x=0,y=0,guardian=0;
  6999. char *str,*map,*event="";
  7000. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  7001. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  7002. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  7003. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  7004. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7005. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  7006. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  7007. if( st->end>st->start+9 )
  7008. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  7009. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  7010. return 0;
  7011. }
  7012. /*================================================
  7013. * Script for Displaying Guardian Info [Valaris]
  7014. *------------------------------------------------
  7015. */
  7016. int buildin_guardianinfo(struct script_state *st)
  7017. {
  7018. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7019. struct map_session_data *sd=script_rid2sd(st);
  7020. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  7021. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  7022. {
  7023. push_val(st->stack,C_INT,-1);
  7024. return 0;
  7025. }
  7026. if(gc->guardian[guardian].visible)
  7027. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  7028. else push_val(st->stack,C_INT,-1);
  7029. return 0;
  7030. }
  7031. /*==========================================
  7032. * IDからItem名
  7033. *------------------------------------------
  7034. */
  7035. int buildin_getitemname(struct script_state *st)
  7036. {
  7037. int item_id=0;
  7038. struct item_data *i_data;
  7039. char *item_name;
  7040. struct script_data *data;
  7041. data=&(st->stack->stack_data[st->start+2]);
  7042. get_val(st,data);
  7043. if( data->type==C_STR || data->type==C_CONSTSTR ){
  7044. const char *name=conv_str(st,data);
  7045. struct item_data *item_data = itemdb_searchname(name);
  7046. if( item_data )
  7047. item_id=item_data->nameid;
  7048. }else
  7049. item_id=conv_num(st,data);
  7050. i_data = itemdb_exists(item_id);
  7051. if (i_data == NULL)
  7052. {
  7053. push_str(st->stack,C_CONSTSTR,(unsigned char *) "null");
  7054. return 0;
  7055. }
  7056. item_name=(char *)aCallocA(ITEM_NAME_LENGTH,sizeof(char));
  7057. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH-1);
  7058. push_str(st->stack,C_STR,(unsigned char *) item_name);
  7059. return 0;
  7060. }
  7061. /*==========================================
  7062. * Returns number of slots an item has. [Skotlex]
  7063. *------------------------------------------
  7064. */
  7065. int buildin_getitemslots(struct script_state *st)
  7066. {
  7067. int item_id;
  7068. struct item_data *i_data;
  7069. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7070. i_data = itemdb_exists(item_id);
  7071. if (i_data)
  7072. push_val(st->stack,C_INT,i_data->slot);
  7073. else
  7074. push_val(st->stack,C_INT,-1);
  7075. return 0;
  7076. }
  7077. /*==========================================
  7078. * Returns some values of an item [Lupus]
  7079. * Price, Weight, etc...
  7080. getiteminfo(itemID,n), where n
  7081. 0 value_buy;
  7082. 1 value_sell;
  7083. 2 type;
  7084. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  7085. if = 0, then monsters don't drop it at all (rare or a quest item)
  7086. if = 10000, then this item is sold in NPC shops only
  7087. 4 sex;
  7088. 5 equip;
  7089. 6 weight;
  7090. 7 atk;
  7091. 8 def;
  7092. 9 range;
  7093. 10 slot;
  7094. 11 look;
  7095. 12 elv;
  7096. 13 wlv;
  7097. *------------------------------------------
  7098. */
  7099. int buildin_getiteminfo(struct script_state *st)
  7100. {
  7101. int item_id,n;
  7102. int *item_arr;
  7103. struct item_data *i_data;
  7104. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7105. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  7106. i_data = itemdb_exists(item_id);
  7107. if (i_data && n>=0 && n<14) {
  7108. item_arr = (int*)&i_data->value_buy;
  7109. push_val(st->stack,C_INT,item_arr[n]);
  7110. } else
  7111. push_val(st->stack,C_INT,-1);
  7112. return 0;
  7113. }
  7114. /*==========================================
  7115. * Returns value from equipped item slot n [Lupus]
  7116. getequipcardid(num,slot)
  7117. where
  7118. num = eqip position slot
  7119. slot = 0,1,2,3 (Card Slot N)
  7120. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  7121. it's useful when you want to check item cards or if it's signed
  7122. Useful for such quests as "Sign this refined item with players name" etc
  7123. Hat[0] +4 -> Player's Hat[0] +4
  7124. *------------------------------------------
  7125. */
  7126. int buildin_getequipcardid(struct script_state *st)
  7127. {
  7128. int i,num,slot;
  7129. struct map_session_data *sd;
  7130. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7131. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7132. sd=script_rid2sd(st);
  7133. i=pc_checkequip(sd,equip[num-1]);
  7134. if(i >= 0 && slot>=0 && slot<4)
  7135. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  7136. else
  7137. push_val(st->stack,C_INT,0);
  7138. return 0;
  7139. }
  7140. /*==========================================
  7141. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  7142. *------------------------------------------
  7143. */
  7144. int buildin_petskillbonus(struct script_state *st)
  7145. {
  7146. struct pet_data *pd;
  7147. struct map_session_data *sd=script_rid2sd(st);
  7148. if(sd==NULL || sd->pd==NULL)
  7149. return 0;
  7150. pd=sd->pd;
  7151. if (pd->bonus)
  7152. { //Clear previous bonus
  7153. if (pd->bonus->timer != -1)
  7154. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  7155. } else //init
  7156. pd->bonus = (struct pet_bonus *) aCalloc(1, sizeof(struct pet_bonus));
  7157. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7158. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7159. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7160. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7161. if (pd->state.skillbonus == -1)
  7162. pd->state.skillbonus=0; // waiting state
  7163. // wait for timer to start
  7164. if (battle_config.pet_equip_required && pd->equip == 0)
  7165. pd->bonus->timer=-1;
  7166. else
  7167. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  7168. return 0;
  7169. }
  7170. /*==========================================
  7171. * pet looting [Valaris] //Rewritten by [Skotlex]
  7172. *------------------------------------------
  7173. */
  7174. int buildin_petloot(struct script_state *st)
  7175. {
  7176. int max;
  7177. struct pet_data *pd;
  7178. struct map_session_data *sd=script_rid2sd(st);
  7179. if(sd==NULL || sd->pd==NULL)
  7180. return 0;
  7181. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7182. if(max < 1)
  7183. max = 1; //Let'em loot at least 1 item.
  7184. else if (max > MAX_PETLOOT_SIZE)
  7185. max = MAX_PETLOOT_SIZE;
  7186. pd = sd->pd;
  7187. if (pd->loot != NULL)
  7188. { //Release whatever was there already and reallocate memory
  7189. pet_lootitem_drop(pd, pd->msd);
  7190. aFree(pd->loot->item);
  7191. }
  7192. else
  7193. pd->loot = (struct pet_loot *)aCalloc(1, sizeof(struct pet_loot));
  7194. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  7195. memset(pd->loot->item,0,max * sizeof(struct item));
  7196. pd->loot->max=max;
  7197. pd->loot->count = 0;
  7198. pd->loot->weight = 0;
  7199. return 0;
  7200. }
  7201. /*==========================================
  7202. * PCの所持品情報読み取り
  7203. *------------------------------------------
  7204. */
  7205. int buildin_getinventorylist(struct script_state *st)
  7206. {
  7207. struct map_session_data *sd=script_rid2sd(st);
  7208. unsigned char card_var[NAME_LENGTH];
  7209. int i,j=0,k;
  7210. if(!sd) return 0;
  7211. for(i=0;i<MAX_INVENTORY;i++){
  7212. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  7213. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  7214. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  7215. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  7216. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  7217. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  7218. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  7219. for (k = 0; k < MAX_SLOTS; k++)
  7220. {
  7221. sprintf(card_var, "@inventorylist_card%d",k+1);
  7222. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  7223. }
  7224. j++;
  7225. }
  7226. }
  7227. pc_setreg(sd,add_str((unsigned char *) "@inventorylist_count"),j);
  7228. return 0;
  7229. }
  7230. int buildin_getskilllist(struct script_state *st)
  7231. {
  7232. struct map_session_data *sd=script_rid2sd(st);
  7233. int i,j=0;
  7234. if(!sd) return 0;
  7235. for(i=0;i<MAX_SKILL;i++){
  7236. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  7237. pc_setreg(sd,add_str((unsigned char *) "@skilllist_id")+(j<<24),sd->status.skill[i].id);
  7238. pc_setreg(sd,add_str((unsigned char *)"@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  7239. pc_setreg(sd,add_str((unsigned char *)"@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  7240. j++;
  7241. }
  7242. }
  7243. pc_setreg(sd,add_str((unsigned char *) "@skilllist_count"),j);
  7244. return 0;
  7245. }
  7246. int buildin_clearitem(struct script_state *st)
  7247. {
  7248. struct map_session_data *sd=script_rid2sd(st);
  7249. int i;
  7250. if(sd==NULL) return 0;
  7251. for (i=0; i<MAX_INVENTORY; i++) {
  7252. if (sd->status.inventory[i].amount) {
  7253. //Logs items, got from (N)PC scripts [Lupus]
  7254. if(log_config.pick > 0 ) {
  7255. log_pick(sd, "N", 0, sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  7256. }
  7257. //Logs
  7258. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  7259. }
  7260. }
  7261. return 0;
  7262. }
  7263. /*==========================================
  7264. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  7265. *------------------------------------------
  7266. */
  7267. int buildin_disguise(struct script_state *st)
  7268. {
  7269. struct map_session_data *sd=script_rid2sd(st);
  7270. int id;
  7271. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7272. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  7273. push_val(st->stack,C_INT,0);
  7274. return 0;
  7275. }
  7276. pc_disguise(sd, id);
  7277. push_val(st->stack,C_INT,id);
  7278. return 0;
  7279. }
  7280. /*==========================================
  7281. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  7282. *------------------------------------------
  7283. */
  7284. int buildin_undisguise(struct script_state *st)
  7285. {
  7286. struct map_session_data *sd=script_rid2sd(st);
  7287. if (sd->disguise) {
  7288. pc_disguise(sd, 0);
  7289. push_val(st->stack,C_INT,0);
  7290. } else {
  7291. push_val(st->stack,C_INT,1);
  7292. }
  7293. return 0;
  7294. }
  7295. /*==========================================
  7296. * NPCクラスチェンジ
  7297. * classは変わりたいclass
  7298. * typeは通常0なのかな?
  7299. *------------------------------------------
  7300. */
  7301. int buildin_classchange(struct script_state *st)
  7302. {
  7303. int _class,type;
  7304. struct block_list *bl=map_id2bl(st->oid);
  7305. if(bl==NULL) return 0;
  7306. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7307. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7308. clif_class_change(bl,_class,type);
  7309. return 0;
  7310. }
  7311. /*==========================================
  7312. * NPCから発生するエフェクト
  7313. *------------------------------------------
  7314. */
  7315. int buildin_misceffect(struct script_state *st)
  7316. {
  7317. int type;
  7318. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7319. if(st->oid)
  7320. clif_misceffect2(map_id2bl(st->oid),type);
  7321. else{
  7322. struct map_session_data *sd=script_rid2sd(st);
  7323. if(sd)
  7324. clif_misceffect2(&sd->bl,type);
  7325. }
  7326. return 0;
  7327. }
  7328. /*==========================================
  7329. * サウンドエフェクト
  7330. *------------------------------------------
  7331. */
  7332. int buildin_soundeffect(struct script_state *st)
  7333. {
  7334. // Redundn
  7335. struct map_session_data *sd=script_rid2sd(st);
  7336. char *name;
  7337. int type=0;
  7338. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7339. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7340. if(sd){
  7341. if(!st->rid)
  7342. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  7343. else{
  7344. clif_soundeffect(sd,&sd->bl,name,type);
  7345. }
  7346. }
  7347. return 0;
  7348. }
  7349. int soundeffect_sub(struct block_list* bl,va_list ap)
  7350. {
  7351. char *name;
  7352. int type;
  7353. nullpo_retr(0, bl);
  7354. nullpo_retr(0, ap);
  7355. name = va_arg(ap,char *);
  7356. type = va_arg(ap,int);
  7357. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  7358. return 0;
  7359. }
  7360. int buildin_soundeffectall(struct script_state *st)
  7361. {
  7362. // [Lance] - Improved.
  7363. char *name, *map = NULL;
  7364. struct block_list *bl;
  7365. int type, coverage, x0, y0, x1, y1;
  7366. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7367. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7368. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7369. if(!st->rid)
  7370. bl = map_id2bl(st->oid);
  7371. else
  7372. bl = &(script_rid2sd(st)->bl);
  7373. if(bl){
  7374. if(coverage < 23){
  7375. clif_soundeffectall(bl,name,type,coverage);
  7376. }else {
  7377. if(st->end > st->start+9){
  7378. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7379. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  7380. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  7381. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  7382. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  7383. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  7384. } else {
  7385. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  7386. }
  7387. }
  7388. }
  7389. return 0;
  7390. }
  7391. /*==========================================
  7392. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  7393. *------------------------------------------
  7394. */
  7395. int buildin_petrecovery(struct script_state *st)
  7396. {
  7397. struct pet_data *pd;
  7398. struct map_session_data *sd=script_rid2sd(st);
  7399. if(sd==NULL || sd->pd==NULL)
  7400. return 0;
  7401. pd=sd->pd;
  7402. if (pd->recovery)
  7403. { //Halt previous bonus
  7404. if (pd->recovery->timer != -1)
  7405. delete_timer(pd->recovery->timer, pet_recovery_timer);
  7406. } else //Init
  7407. pd->recovery = (struct pet_recovery *)aCalloc(1, sizeof(struct pet_recovery));
  7408. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7409. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7410. pd->recovery->timer=-1;
  7411. return 0;
  7412. }
  7413. /*==========================================
  7414. * pet healing [Valaris] //Rewritten by [Skotlex]
  7415. *------------------------------------------
  7416. */
  7417. int buildin_petheal(struct script_state *st)
  7418. {
  7419. struct pet_data *pd;
  7420. struct map_session_data *sd=script_rid2sd(st);
  7421. if(sd==NULL || sd->pd==NULL)
  7422. return 0;
  7423. pd=sd->pd;
  7424. if (pd->s_skill)
  7425. { //Clear previous skill
  7426. if (pd->s_skill->timer != -1)
  7427. {
  7428. if (pd->s_skill->id)
  7429. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  7430. else
  7431. delete_timer(pd->s_skill->timer, pet_heal_timer);
  7432. }
  7433. } else //init memory
  7434. pd->s_skill = (struct pet_skill_support *) aCalloc(1, sizeof(struct pet_skill_support));
  7435. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  7436. //Use the lv as the amount to heal
  7437. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7438. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7439. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7440. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7441. //Use delay as initial offset to avoid skill/heal exploits
  7442. if (battle_config.pet_equip_required && pd->equip == 0)
  7443. pd->s_skill->timer=-1;
  7444. else
  7445. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  7446. return 0;
  7447. }
  7448. /*==========================================
  7449. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  7450. *------------------------------------------
  7451. */
  7452. int buildin_petskillattack(struct script_state *st)
  7453. {
  7454. struct pet_data *pd;
  7455. struct map_session_data *sd=script_rid2sd(st);
  7456. if(sd==NULL || sd->pd==NULL)
  7457. return 0;
  7458. pd=sd->pd;
  7459. if (pd->a_skill == NULL)
  7460. pd->a_skill = (struct pet_skill_attack *)aCalloc(1, sizeof(struct pet_skill_attack));
  7461. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7462. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7463. pd->a_skill->div_ = 0;
  7464. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7465. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7466. return 0;
  7467. }
  7468. /*==========================================
  7469. * pet attack skills [Valaris]
  7470. *------------------------------------------
  7471. */
  7472. int buildin_petskillattack2(struct script_state *st)
  7473. {
  7474. struct pet_data *pd;
  7475. struct map_session_data *sd=script_rid2sd(st);
  7476. if(sd==NULL || sd->pd==NULL)
  7477. return 0;
  7478. pd=sd->pd;
  7479. if (pd->a_skill == NULL)
  7480. pd->a_skill = (struct pet_skill_attack *)aCalloc(1, sizeof(struct pet_skill_attack));
  7481. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7482. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7483. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  7484. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7485. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7486. return 0;
  7487. }
  7488. /*==========================================
  7489. * pet support skills [Skotlex]
  7490. *------------------------------------------
  7491. */
  7492. int buildin_petskillsupport(struct script_state *st)
  7493. {
  7494. struct pet_data *pd;
  7495. struct map_session_data *sd=script_rid2sd(st);
  7496. if(sd==NULL || sd->pd==NULL)
  7497. return 0;
  7498. pd=sd->pd;
  7499. if (pd->s_skill)
  7500. { //Clear previous skill
  7501. if (pd->s_skill->timer != -1)
  7502. {
  7503. if (pd->s_skill->id)
  7504. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  7505. else
  7506. delete_timer(pd->s_skill->timer, pet_heal_timer);
  7507. }
  7508. } else //init memory
  7509. pd->s_skill = (struct pet_skill_support *) aCalloc(1, sizeof(struct pet_skill_support));
  7510. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7511. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7512. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7513. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7514. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7515. //Use delay as initial offset to avoid skill/heal exploits
  7516. if (battle_config.pet_equip_required && pd->equip == 0)
  7517. pd->s_skill->timer=-1;
  7518. else
  7519. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  7520. return 0;
  7521. }
  7522. /*==========================================
  7523. * Scripted skill effects [Celest]
  7524. *------------------------------------------
  7525. */
  7526. int buildin_skilleffect(struct script_state *st)
  7527. {
  7528. struct map_session_data *sd;
  7529. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7530. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7531. sd=script_rid2sd(st);
  7532. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  7533. return 0;
  7534. }
  7535. /*==========================================
  7536. * NPC skill effects [Valaris]
  7537. *------------------------------------------
  7538. */
  7539. int buildin_npcskilleffect(struct script_state *st)
  7540. {
  7541. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7542. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7543. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7544. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7545. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7546. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  7547. return 0;
  7548. }
  7549. /*==========================================
  7550. * Special effects [Valaris]
  7551. *------------------------------------------
  7552. */
  7553. int buildin_specialeffect(struct script_state *st)
  7554. {
  7555. struct block_list *bl=map_id2bl(st->oid);
  7556. if(bl==NULL)
  7557. return 0;
  7558. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  7559. return 0;
  7560. }
  7561. int buildin_specialeffect2(struct script_state *st)
  7562. {
  7563. struct map_session_data *sd=script_rid2sd(st);
  7564. if(sd==NULL)
  7565. return 0;
  7566. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), 0);
  7567. return 0;
  7568. }
  7569. /*==========================================
  7570. * Nude [Valaris]
  7571. *------------------------------------------
  7572. */
  7573. int buildin_nude(struct script_state *st)
  7574. {
  7575. struct map_session_data *sd=script_rid2sd(st);
  7576. int i,calcflag=0;
  7577. if(sd==NULL)
  7578. return 0;
  7579. for(i=0;i<11;i++)
  7580. if(sd->equip_index[i] >= 0) {
  7581. if(!calcflag)
  7582. calcflag=1;
  7583. pc_unequipitem(sd,sd->equip_index[i],2);
  7584. }
  7585. if(calcflag)
  7586. status_calc_pc(sd,1);
  7587. return 0;
  7588. }
  7589. /*==========================================
  7590. * gmcommand [MouseJstr]
  7591. *
  7592. * suggested on the forums...
  7593. * splitted into atcommand & charcommand by [Skotlex]
  7594. *------------------------------------------
  7595. */
  7596. int buildin_atcommand(struct script_state *st)
  7597. {
  7598. struct map_session_data *sd=NULL;
  7599. char *cmd;
  7600. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7601. if (st->rid)
  7602. sd = script_rid2sd(st);
  7603. if (sd) is_atcommand(sd->fd, sd, cmd, 99);
  7604. else { //Use a dummy character.
  7605. struct map_session_data dummy_sd;
  7606. struct block_list *bl = NULL;
  7607. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  7608. if (st->oid) bl = map_id2bl(st->oid);
  7609. if (bl) {
  7610. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  7611. if (bl->type == BL_NPC)
  7612. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7613. }
  7614. is_atcommand(0, &dummy_sd, cmd, 99);
  7615. }
  7616. return 0;
  7617. }
  7618. int buildin_charcommand(struct script_state *st)
  7619. {
  7620. struct map_session_data *sd=NULL;
  7621. char *cmd;
  7622. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7623. if (st->rid)
  7624. sd = script_rid2sd(st);
  7625. if (sd) is_charcommand(sd->fd, sd, cmd, 99);
  7626. else { //Use a dummy character.
  7627. struct map_session_data dummy_sd;
  7628. struct block_list *bl = NULL;
  7629. memset(&dummy_sd, 0, sizeof(struct map_session_data));
  7630. if (st->oid) bl = map_id2bl(st->oid);
  7631. if (bl) {
  7632. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  7633. if (bl->type == BL_NPC)
  7634. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7635. }
  7636. is_charcommand(0, &dummy_sd, cmd, 99);
  7637. }
  7638. return 0;
  7639. }
  7640. /*==========================================
  7641. * Displays a message for the player only (like system messages like "you got an apple" )
  7642. *------------------------------------------
  7643. */
  7644. int buildin_dispbottom(struct script_state *st)
  7645. {
  7646. struct map_session_data *sd=script_rid2sd(st);
  7647. char *message;
  7648. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7649. if(sd)
  7650. clif_disp_onlyself(sd,message,(int)strlen(message));
  7651. return 0;
  7652. }
  7653. /*==========================================
  7654. * All The Players Full Recovery
  7655. (HP/SP full restore and resurrect if need)
  7656. *------------------------------------------
  7657. */
  7658. int buildin_recovery(struct script_state *st)
  7659. {
  7660. struct map_session_data *sd, **all_sd;
  7661. int i = 0, users;
  7662. all_sd = map_getallusers(&users);
  7663. for (i = 0; i < users; i++)
  7664. {
  7665. sd = all_sd[i];
  7666. sd->status.hp = sd->status.max_hp;
  7667. sd->status.sp = sd->status.max_sp;
  7668. clif_updatestatus(sd, SP_HP);
  7669. clif_updatestatus(sd, SP_SP);
  7670. if(pc_isdead(sd)){
  7671. pc_setstand(sd);
  7672. clif_resurrection(&sd->bl, 1);
  7673. }
  7674. clif_displaymessage(sd->fd,"You have been recovered!");
  7675. }
  7676. return 0;
  7677. }
  7678. /*==========================================
  7679. * Get your pet info: getpetinfo(n)
  7680. * n -> 0:pet_id 1:pet_class 2:pet_name
  7681. 3:friendly 4:hungry
  7682. *------------------------------------------
  7683. */
  7684. int buildin_getpetinfo(struct script_state *st)
  7685. {
  7686. struct map_session_data *sd=script_rid2sd(st);
  7687. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7688. if(sd && sd->status.pet_id){
  7689. switch(type){
  7690. case 0:
  7691. push_val(st->stack,C_INT,sd->status.pet_id);
  7692. break;
  7693. case 1:
  7694. push_val(st->stack,C_INT,sd->pet.class_);
  7695. break;
  7696. case 2:
  7697. if(sd->pet.name)
  7698. { //Shamelessly copied from strcharinfo() [Skotlex]
  7699. char *buf;
  7700. buf=(char *)aCallocA(NAME_LENGTH,sizeof(char));
  7701. memcpy(buf, sd->pet.name, NAME_LENGTH-1);
  7702. push_str(st->stack,C_STR,(unsigned char *) buf);
  7703. }
  7704. else
  7705. push_str(st->stack,C_CONSTSTR, (unsigned char *) "null");
  7706. break;
  7707. case 3:
  7708. //if(sd->pet.intimate)
  7709. push_val(st->stack,C_INT,sd->pet.intimate);
  7710. break;
  7711. case 4:
  7712. //if(sd->pet.hungry)
  7713. push_val(st->stack,C_INT,sd->pet.hungry);
  7714. break;
  7715. default:
  7716. push_val(st->stack,C_INT,0);
  7717. break;
  7718. }
  7719. }else{
  7720. push_val(st->stack,C_INT,0);
  7721. }
  7722. return 0;
  7723. }
  7724. /*==========================================
  7725. * Shows wether your inventory(and equips) contain
  7726. selected card or not.
  7727. checkequipedcard(4001);
  7728. *------------------------------------------
  7729. */
  7730. int buildin_checkequipedcard(struct script_state *st)
  7731. {
  7732. struct map_session_data *sd=script_rid2sd(st);
  7733. int n,i,c=0;
  7734. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7735. if(sd){
  7736. for(i=0;i<MAX_INVENTORY;i++){
  7737. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  7738. for(n=0;n<MAX_SLOTS;n++){
  7739. if(sd->status.inventory[i].card[n]==c){
  7740. push_val(st->stack,C_INT,1);
  7741. return 0;
  7742. }
  7743. }
  7744. }
  7745. }
  7746. }
  7747. push_val(st->stack,C_INT,0);
  7748. return 0;
  7749. }
  7750. int buildin_jump_zero(struct script_state *st) {
  7751. int sel;
  7752. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7753. if(!sel) {
  7754. int pos;
  7755. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  7756. ShowError("script: jump_zero: not label !\n");
  7757. st->state=END;
  7758. return 0;
  7759. }
  7760. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7761. st->pos=pos;
  7762. st->state=GOTO;
  7763. // printf("script: jump_zero: jumpto : %d\n",pos);
  7764. } else {
  7765. // printf("script: jump_zero: fail\n");
  7766. }
  7767. return 0;
  7768. }
  7769. int buildin_select(struct script_state *st)
  7770. {
  7771. char *buf;
  7772. int len,i;
  7773. struct map_session_data *sd;
  7774. sd=script_rid2sd(st);
  7775. if(sd->state.menu_or_input==0){
  7776. st->state=RERUNLINE;
  7777. sd->state.menu_or_input=1;
  7778. for(i=st->start+2,len=16;i<st->end;i++){
  7779. conv_str(st,& (st->stack->stack_data[i]));
  7780. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  7781. }
  7782. buf=(char *)aCalloc(len+1,sizeof(char));
  7783. buf[0]=0;
  7784. for(i=st->start+2,len=0;i<st->end;i++){
  7785. strcat(buf,st->stack->stack_data[i].u.str);
  7786. strcat(buf,":");
  7787. }
  7788. clif_scriptmenu(script_rid2sd(st),st->oid,buf);
  7789. aFree(buf);
  7790. } else if(sd->npc_menu==0xff){ // cansel
  7791. sd->state.menu_or_input=0;
  7792. st->state=END;
  7793. } else {
  7794. // pc_setreg(sd,add_str((unsigned char *) "l15"),sd->npc_menu);
  7795. pc_setreg(sd,add_str((unsigned char *) "@menu"),sd->npc_menu);
  7796. sd->state.menu_or_input=0;
  7797. push_val(st->stack,C_INT,sd->npc_menu);
  7798. }
  7799. return 0;
  7800. }
  7801. /*==========================================
  7802. * GetMapMobs
  7803. returns mob counts on a set map:
  7804. e.g. GetMapMobs("prontera.gat")
  7805. use "this" - for player's map
  7806. *------------------------------------------
  7807. */
  7808. int buildin_getmapmobs(struct script_state *st)
  7809. {
  7810. char *str=NULL;
  7811. int m=-1,bx,by,i;
  7812. int count=0,c;
  7813. struct block_list *bl;
  7814. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7815. if(strcmp(str,"this")==0){
  7816. struct map_session_data *sd=script_rid2sd(st);
  7817. if(sd)
  7818. m=sd->bl.m;
  7819. else{
  7820. push_val(st->stack,C_INT,-1);
  7821. return 0;
  7822. }
  7823. }else
  7824. m=map_mapname2mapid(str);
  7825. if(m < 0){
  7826. push_val(st->stack,C_INT,-1);
  7827. return 0;
  7828. }
  7829. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  7830. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  7831. bl = map[m].block_mob[bx+by*map[m].bxs];
  7832. c = map[m].block_mob_count[bx+by*map[m].bxs];
  7833. for(i=0;i<c && bl;i++,bl=bl->next){
  7834. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  7835. count++;
  7836. }
  7837. }
  7838. }
  7839. push_val(st->stack,C_INT,count);
  7840. return 0;
  7841. }
  7842. /*==========================================
  7843. * movenpc [MouseJstr]
  7844. *------------------------------------------
  7845. */
  7846. int buildin_movenpc(struct script_state *st)
  7847. {
  7848. struct map_session_data *sd;
  7849. char *map,*npc;
  7850. int x,y;
  7851. sd = script_rid2sd(st);
  7852. map = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7853. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  7854. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  7855. npc = conv_str(st,& (st->stack->stack_data[st->start+5]));
  7856. return 0;
  7857. }
  7858. /*==========================================
  7859. * message [MouseJstr]
  7860. *------------------------------------------
  7861. */
  7862. int buildin_message(struct script_state *st)
  7863. {
  7864. struct map_session_data *sd;
  7865. char *msg,*player;
  7866. struct map_session_data *pl_sd = NULL;
  7867. sd = script_rid2sd(st);
  7868. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  7869. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  7870. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  7871. return 0;
  7872. clif_displaymessage(pl_sd->fd, msg);
  7873. return 0;
  7874. }
  7875. /*==========================================
  7876. * npctalk (sends message to surrounding
  7877. * area) [Valaris]
  7878. *------------------------------------------
  7879. */
  7880. int buildin_npctalk(struct script_state *st)
  7881. {
  7882. char *str;
  7883. char message[255];
  7884. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7885. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7886. if(nd) {
  7887. memcpy(message, nd->name, NAME_LENGTH);
  7888. strcat(message," : ");
  7889. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  7890. clif_message(&(nd->bl), message);
  7891. }
  7892. return 0;
  7893. }
  7894. /*==========================================
  7895. * hasitems (checks to see if player has any
  7896. * items on them, if so will return a 1)
  7897. * [Valaris]
  7898. *------------------------------------------
  7899. */
  7900. int buildin_hasitems(struct script_state *st)
  7901. {
  7902. int i;
  7903. struct map_session_data *sd;
  7904. sd=script_rid2sd(st);
  7905. for(i=0; i<MAX_INVENTORY; i++) {
  7906. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  7907. push_val(st->stack,C_INT,1);
  7908. return 0;
  7909. }
  7910. }
  7911. push_val(st->stack,C_INT,0);
  7912. return 0;
  7913. }
  7914. // change npc walkspeed [Valaris]
  7915. int buildin_npcspeed(struct script_state *st)
  7916. {
  7917. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7918. int x=0;
  7919. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7920. if(nd) {
  7921. nd->speed=x;
  7922. }
  7923. return 0;
  7924. }
  7925. // make an npc walk to a position [Valaris]
  7926. int buildin_npcwalkto(struct script_state *st)
  7927. {
  7928. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7929. int x=0,y=0;
  7930. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7931. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7932. if(nd) {
  7933. unit_walktoxy(&nd->bl,x,y,0);
  7934. }
  7935. return 0;
  7936. }
  7937. // stop an npc's movement [Valaris]
  7938. int buildin_npcstop(struct script_state *st)
  7939. {
  7940. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7941. if(nd) {
  7942. unit_stop_walking(&nd->bl,1);
  7943. }
  7944. return 0;
  7945. }
  7946. /*==========================================
  7947. * getlook char info. getlook(arg)
  7948. *------------------------------------------
  7949. */
  7950. int buildin_getlook(struct script_state *st){
  7951. int type,val;
  7952. struct map_session_data *sd;
  7953. sd=script_rid2sd(st);
  7954. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7955. val=-1;
  7956. switch(type){
  7957. case LOOK_HAIR: //1
  7958. val=sd->status.hair;
  7959. break;
  7960. case LOOK_WEAPON: //2
  7961. val=sd->status.weapon;
  7962. break;
  7963. case LOOK_HEAD_BOTTOM: //3
  7964. val=sd->status.head_bottom;
  7965. break;
  7966. case LOOK_HEAD_TOP: //4
  7967. val=sd->status.head_top;
  7968. break;
  7969. case LOOK_HEAD_MID: //5
  7970. val=sd->status.head_mid;
  7971. break;
  7972. case LOOK_HAIR_COLOR: //6
  7973. val=sd->status.hair_color;
  7974. break;
  7975. case LOOK_CLOTHES_COLOR: //7
  7976. val=sd->status.clothes_color;
  7977. break;
  7978. case LOOK_SHIELD: //8
  7979. val=sd->status.shield;
  7980. break;
  7981. case LOOK_SHOES: //9
  7982. break;
  7983. }
  7984. push_val(st->stack,C_INT,val);
  7985. return 0;
  7986. }
  7987. /*==========================================
  7988. * get char save point. argument: 0- map name, 1- x, 2- y
  7989. *------------------------------------------
  7990. */
  7991. int buildin_getsavepoint(struct script_state *st)
  7992. {
  7993. int x,y,type;
  7994. char *mapname;
  7995. struct map_session_data *sd;
  7996. sd=script_rid2sd(st);
  7997. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7998. x=sd->status.save_point.x;
  7999. y=sd->status.save_point.y;
  8000. switch(type){
  8001. case 0:
  8002. mapname=(char *) aCallocA(MAP_NAME_LENGTH+1, sizeof(char));
  8003. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  8004. mapname[MAP_NAME_LENGTH]='\0';
  8005. push_str(st->stack,C_STR,(unsigned char *) mapname);
  8006. break;
  8007. case 1:
  8008. push_val(st->stack,C_INT,x);
  8009. break;
  8010. case 2:
  8011. push_val(st->stack,C_INT,y);
  8012. break;
  8013. }
  8014. return 0;
  8015. }
  8016. /*==========================================
  8017. * Get position for char/npc/pet/mob objects. Added by Lorky
  8018. *
  8019. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  8020. * where type:
  8021. * MapName$ - String variable for output map name
  8022. * MapX - Integer variable for output coord X
  8023. * MapY - Integer variable for output coord Y
  8024. * type - type of object
  8025. * 0 - Character coord
  8026. * 1 - NPC coord
  8027. * 2 - Pet coord
  8028. * 3 - Mob coord (not released)
  8029. * CharName$ - Name object. If miss or "this" the current object
  8030. *
  8031. * Return:
  8032. * 0 - success
  8033. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  8034. *------------------------------------------
  8035. */
  8036. int buildin_getmapxy(struct script_state *st){
  8037. struct map_session_data *sd=NULL;
  8038. struct npc_data *nd;
  8039. struct pet_data *pd;
  8040. int num;
  8041. char *name;
  8042. char prefix;
  8043. int x,y,type;
  8044. char mapname[MAP_NAME_LENGTH+1];
  8045. memset(mapname, 0, sizeof(mapname));
  8046. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  8047. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  8048. push_val(st->stack,C_INT,-1);
  8049. return 0;
  8050. }
  8051. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  8052. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  8053. push_val(st->stack,C_INT,-1);
  8054. return 0;
  8055. }
  8056. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  8057. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  8058. push_val(st->stack,C_INT,-1);
  8059. return 0;
  8060. }
  8061. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  8062. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8063. switch (type){
  8064. case 0: //Get Character Position
  8065. if( st->end>st->start+6 )
  8066. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8067. else
  8068. sd=script_rid2sd(st);
  8069. if ( sd==NULL ) { //wrong char name or char offline
  8070. push_val(st->stack,C_INT,-1);
  8071. return 0;
  8072. }
  8073. x=sd->bl.x;
  8074. y=sd->bl.y;
  8075. memcpy(mapname,mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  8076. break;
  8077. case 1: //Get NPC Position
  8078. if( st->end > st->start+6 )
  8079. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8080. else
  8081. nd=(struct npc_data *)map_id2bl(st->oid);
  8082. if ( nd==NULL ) { //wrong npc name or char offline
  8083. push_val(st->stack,C_INT,-1);
  8084. return 0;
  8085. }
  8086. x=nd->bl.x;
  8087. y=nd->bl.y;
  8088. memcpy(mapname, map[nd->bl.m].name, MAP_NAME_LENGTH);
  8089. break;
  8090. case 2: //Get Pet Position
  8091. if( st->end>st->start+6 )
  8092. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  8093. else
  8094. sd=script_rid2sd(st);
  8095. if ( sd==NULL ) { //wrong char name or char offline
  8096. push_val(st->stack,C_INT,-1);
  8097. return 0;
  8098. }
  8099. pd=sd->pd;
  8100. if(pd==NULL){ //pet data not found
  8101. push_val(st->stack,C_INT,-1);
  8102. return 0;
  8103. }
  8104. x=pd->bl.x;
  8105. y=pd->bl.y;
  8106. memcpy(mapname, map[pd->bl.m].name, MAP_NAME_LENGTH);
  8107. break;
  8108. case 3: //Get Mob Position
  8109. push_val(st->stack,C_INT,-1);
  8110. return 0;
  8111. default: //Wrong type parameter
  8112. push_val(st->stack,C_INT,-1);
  8113. return 0;
  8114. }
  8115. //Set MapName$
  8116. num=st->stack->stack_data[st->start+2].u.num;
  8117. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8118. prefix=*name;
  8119. if( prefix!='$' )
  8120. sd=script_rid2sd(st);
  8121. else
  8122. sd=NULL;
  8123. set_reg(sd,num,name,(void*)mapname);
  8124. //Set MapX
  8125. num=st->stack->stack_data[st->start+3].u.num;
  8126. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8127. prefix=*name;
  8128. if( prefix!='$' )
  8129. sd=script_rid2sd(st);
  8130. else
  8131. sd=NULL;
  8132. set_reg(sd,num,name,(void*)x);
  8133. //Set MapY
  8134. num=st->stack->stack_data[st->start+4].u.num;
  8135. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8136. prefix=*name;
  8137. if( prefix!='$' )
  8138. sd=script_rid2sd(st);
  8139. else
  8140. sd=NULL;
  8141. set_reg(sd,num,name,(void*)y);
  8142. //Return Success value
  8143. push_val(st->stack,C_INT,0);
  8144. return 0;
  8145. }
  8146. /*=====================================================
  8147. * Allows players to use a skill - by Qamera
  8148. *-----------------------------------------------------
  8149. */
  8150. int buildin_skilluseid (struct script_state *st)
  8151. {
  8152. int skid,sklv;
  8153. struct map_session_data *sd;
  8154. skid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8155. sklv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8156. sd=script_rid2sd(st);
  8157. if (sd)
  8158. unit_skilluse_id(&sd->bl,sd->bl.id,skid,sklv);
  8159. return 0;
  8160. }
  8161. /*=====================================================
  8162. * Allows players to use a skill on a position [Celest]
  8163. *-----------------------------------------------------
  8164. */
  8165. int buildin_skillusepos(struct script_state *st)
  8166. {
  8167. int skid,sklv,x,y;
  8168. struct map_session_data *sd;
  8169. skid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8170. sklv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8171. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8172. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8173. sd=script_rid2sd(st);
  8174. if (sd)
  8175. unit_skilluse_pos(&sd->bl,x,y,skid,sklv);
  8176. return 0;
  8177. }
  8178. /*==========================================
  8179. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  8180. *------------------------------------------
  8181. */
  8182. int buildin_logmes(struct script_state *st)
  8183. {
  8184. if (log_config.npc <= 0 ) return 0;
  8185. conv_str(st,& (st->stack->stack_data[st->start+2]));
  8186. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  8187. return 0;
  8188. }
  8189. int buildin_summon(struct script_state *st)
  8190. {
  8191. int _class, id, timeout=0;
  8192. char *str,*event="";
  8193. struct map_session_data *sd;
  8194. struct mob_data *md;
  8195. sd=script_rid2sd(st);
  8196. if (sd) {
  8197. int tick = gettick();
  8198. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8199. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8200. if( st->end>st->start+4 )
  8201. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8202. if( st->end>st->start+5 )
  8203. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8204. id=mob_once_spawn(sd, "this", 0, 0, str,_class,1,event);
  8205. if((md=(struct mob_data *)map_id2bl(id))){
  8206. md->master_id=sd->bl.id;
  8207. md->special_state.ai=1;
  8208. md->mode=mob_db(md->class_)->mode|0x04;
  8209. md->deletetimer=add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,id,0);
  8210. clif_misceffect2(&md->bl,344);
  8211. }
  8212. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  8213. }
  8214. return 0;
  8215. }
  8216. /*==========================================
  8217. * Checks whether it is daytime/nighttime
  8218. *------------------------------------------
  8219. */
  8220. int buildin_isnight(struct script_state *st)
  8221. {
  8222. push_val(st->stack,C_INT, (night_flag == 1));
  8223. return 0;
  8224. }
  8225. int buildin_isday(struct script_state *st)
  8226. {
  8227. push_val(st->stack,C_INT, (night_flag == 0));
  8228. return 0;
  8229. }
  8230. /*================================================
  8231. * Check whether another item/card has been
  8232. * equipped - used for 2/15's cards patch [celest]
  8233. *------------------------------------------------
  8234. */
  8235. // leave this here, just in case
  8236. #if 0
  8237. int buildin_isequipped(struct script_state *st)
  8238. {
  8239. struct map_session_data *sd;
  8240. int i, j, k, id = 1;
  8241. int ret = -1;
  8242. sd = script_rid2sd(st);
  8243. for (i=0; id!=0; i++) {
  8244. int flag = 0;
  8245. FETCH (i+2, id) else id = 0;
  8246. if (id <= 0)
  8247. continue;
  8248. for (j=0; j<10; j++) {
  8249. int index, type;
  8250. index = sd->equip_index[j];
  8251. if(index < 0) continue;
  8252. if(j == 9 && sd->equip_index[8] == index) continue;
  8253. if(j == 5 && sd->equip_index[4] == index) continue;
  8254. if(j == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index)) continue;
  8255. type = itemdb_type(id);
  8256. if(sd->inventory_data[index]) {
  8257. if (type == 4 || type == 5) {
  8258. if (sd->inventory_data[index]->nameid == id)
  8259. flag = 1;
  8260. } else if (type == 6) {
  8261. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8262. if (sd->status.inventory[index].card[0]!=0x00ff &&
  8263. sd->status.inventory[index].card[0]!=0x00fe &&
  8264. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  8265. sd->status.inventory[index].card[k] == id) {
  8266. flag = 1;
  8267. break;
  8268. }
  8269. }
  8270. }
  8271. if (flag) break;
  8272. }
  8273. }
  8274. if (ret == -1)
  8275. ret = flag;
  8276. else
  8277. ret &= flag;
  8278. if (!ret) break;
  8279. }
  8280. push_val(st->stack,C_INT,ret);
  8281. return 0;
  8282. }
  8283. #endif
  8284. /*================================================
  8285. * Check how many items/cards in the list are
  8286. * equipped - used for 2/15's cards patch [celest]
  8287. *------------------------------------------------
  8288. */
  8289. int buildin_isequippedcnt(struct script_state *st)
  8290. {
  8291. struct map_session_data *sd;
  8292. int i, j, k, id = 1;
  8293. int ret = 0;
  8294. sd = script_rid2sd(st);
  8295. for (i=0; id!=0; i++) {
  8296. FETCH (i+2, id) else id = 0;
  8297. if (id <= 0)
  8298. continue;
  8299. for (j=0; j<10; j++) {
  8300. int index, type;
  8301. index = sd->equip_index[j];
  8302. if(index < 0) continue;
  8303. if(j == 9 && sd->equip_index[8] == index) continue;
  8304. if(j == 5 && sd->equip_index[4] == index) continue;
  8305. if(j == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index)) continue;
  8306. type = itemdb_type(id);
  8307. if(sd->inventory_data[index]) {
  8308. if (type == 4 || type == 5) {
  8309. if (sd->inventory_data[index]->nameid == id)
  8310. ret++; //[Lupus]
  8311. } else if (type == 6) {
  8312. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8313. if (sd->status.inventory[index].card[0]!=0x00ff &&
  8314. sd->status.inventory[index].card[0]!=0x00fe &&
  8315. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  8316. sd->status.inventory[index].card[k] == id) {
  8317. ret++; //[Lupus]
  8318. }
  8319. }
  8320. }
  8321. }
  8322. }
  8323. }
  8324. push_val(st->stack,C_INT,ret);
  8325. return 0;
  8326. }
  8327. /*================================================
  8328. * Check whether another card has been
  8329. * equipped - used for 2/15's cards patch [celest]
  8330. * -- Items checked cannot be reused in another
  8331. * card set to prevent exploits
  8332. *------------------------------------------------
  8333. */
  8334. int buildin_isequipped(struct script_state *st)
  8335. {
  8336. struct map_session_data *sd;
  8337. int i, j, k, id = 1;
  8338. int index, type, flag;
  8339. int ret = -1;
  8340. sd = script_rid2sd(st);
  8341. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  8342. push_val(st->stack,C_INT,0);
  8343. return 0;
  8344. }
  8345. for (i=0; id!=0; i++)
  8346. {
  8347. FETCH (i+2, id) else id = 0;
  8348. if (id <= 0)
  8349. continue;
  8350. type = itemdb_type(id);
  8351. flag = 0;
  8352. for (j=0; j<10; j++)
  8353. {
  8354. index = sd->equip_index[j];
  8355. if(index < 0) continue;
  8356. if(j == 9 && sd->equip_index[8] == index) continue;
  8357. if(j == 5 && sd->equip_index[4] == index) continue;
  8358. if(j == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index)) continue;
  8359. if(!sd->inventory_data[index])
  8360. continue;
  8361. switch (type)
  8362. {
  8363. case 4:
  8364. case 5:
  8365. if (sd->inventory_data[index]->nameid == id)
  8366. flag = 1;
  8367. break;
  8368. case 6:
  8369. if (
  8370. sd->inventory_data[index]->slot == 0 ||
  8371. sd->status.inventory[index].card[0] == 0x00ff ||
  8372. sd->status.inventory[index].card[0] == 0x00fe ||
  8373. sd->status.inventory[index].card[0] == (short)0xff00)
  8374. continue;
  8375. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  8376. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  8377. unsigned int hash = 0;
  8378. if (sd->status.inventory[index].card[k] != id)
  8379. continue;
  8380. hash = 1<<((j<5?j:j-5)*4 + k);
  8381. // check if card is already used by another set
  8382. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  8383. continue;
  8384. // We have found a match
  8385. flag = 1;
  8386. // Set hash so this card cannot be used by another
  8387. if (j<5)
  8388. sd->setitem_hash |= hash;
  8389. else
  8390. sd->setitem_hash2 |= hash;
  8391. break;
  8392. }
  8393. //Case 6 end
  8394. break;
  8395. }
  8396. if (flag) break;
  8397. }
  8398. if (ret == -1)
  8399. ret = flag;
  8400. else
  8401. ret &= flag;
  8402. if (!ret) break;
  8403. }
  8404. push_val(st->stack,C_INT,ret);
  8405. return 0;
  8406. }
  8407. /*================================================
  8408. * Check how many given inserted cards in the CURRENT
  8409. * weapon - used for 2/15's cards patch [Lupus]
  8410. *------------------------------------------------
  8411. */
  8412. int buildin_cardscnt(struct script_state *st)
  8413. {
  8414. struct map_session_data *sd;
  8415. int i, k, id = 1;
  8416. int ret = 0;
  8417. int index, type;
  8418. sd = script_rid2sd(st);
  8419. for (i=0; id!=0; i++) {
  8420. FETCH (i+2, id) else id = 0;
  8421. if (id <= 0)
  8422. continue;
  8423. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  8424. if(index < 0) continue;
  8425. type = itemdb_type(id);
  8426. if(sd->inventory_data[index]) {
  8427. if (type == 4 || type == 5) {
  8428. if (sd->inventory_data[index]->nameid == id)
  8429. ret++;
  8430. } else if (type == 6) {
  8431. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  8432. if (sd->status.inventory[index].card[0]!=0x00ff &&
  8433. sd->status.inventory[index].card[0]!=0x00fe &&
  8434. sd->status.inventory[index].card[0]!=(short)0xff00 &&
  8435. sd->status.inventory[index].card[k] == id) {
  8436. ret++;
  8437. }
  8438. }
  8439. }
  8440. }
  8441. }
  8442. push_val(st->stack,C_INT,ret);
  8443. // push_val(st->stack,C_INT,current_equip_item_index);
  8444. return 0;
  8445. }
  8446. /*=======================================================
  8447. * Returns the refined number of the current item, or an
  8448. * item with inventory index specified
  8449. *-------------------------------------------------------
  8450. */
  8451. int buildin_getrefine(struct script_state *st)
  8452. {
  8453. struct map_session_data *sd;
  8454. if ((sd = script_rid2sd(st))!= NULL)
  8455. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  8456. return 0;
  8457. }
  8458. /*=======================================================
  8459. * Allows 2 Parents to adopt a character as a Baby
  8460. *-------------------------------------------------------
  8461. */
  8462. int buildin_adopt(struct script_state *st)
  8463. {
  8464. int ret;
  8465. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8466. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8467. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  8468. struct map_session_data *p1_sd = map_nick2sd(parent1);
  8469. struct map_session_data *p2_sd = map_nick2sd(parent2);
  8470. struct map_session_data *c_sd = map_nick2sd(child);
  8471. if (!p1_sd || !p2_sd || !c_sd ||
  8472. p1_sd->status.base_level < 70 ||
  8473. p2_sd->status.base_level < 70)
  8474. return 0;
  8475. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  8476. push_val(st->stack, C_INT, ret);
  8477. return 0;
  8478. }
  8479. /*=======================================================
  8480. * Day/Night controls
  8481. *-------------------------------------------------------
  8482. */
  8483. int buildin_night(struct script_state *st)
  8484. {
  8485. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  8486. return 0;
  8487. }
  8488. int buildin_day(struct script_state *st)
  8489. {
  8490. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  8491. return 0;
  8492. }
  8493. //=======================================================
  8494. // Unequip [Spectre]
  8495. //-------------------------------------------------------
  8496. int buildin_unequip(struct script_state *st)
  8497. {
  8498. int i;
  8499. size_t num;
  8500. struct map_session_data *sd;
  8501. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  8502. sd=script_rid2sd(st);
  8503. if(sd!=NULL && num<10)
  8504. {
  8505. i=pc_checkequip(sd,equip[num]);
  8506. pc_unequipitem(sd,i,2);
  8507. return 0;
  8508. }
  8509. return 0;
  8510. }
  8511. int buildin_equip(struct script_state *st)
  8512. {
  8513. int nameid=0,count=0,i;
  8514. struct map_session_data *sd;
  8515. struct item_data *item_data;
  8516. sd = script_rid2sd(st);
  8517. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8518. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL)
  8519. for(i=0;i<MAX_INVENTORY;i++){
  8520. if(sd->status.inventory[i].nameid==nameid)
  8521. count+=sd->status.inventory[i].amount;
  8522. }
  8523. else{
  8524. if(battle_config.error_log)
  8525. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  8526. return 1;
  8527. }
  8528. if(count){
  8529. pc_equipitem(sd,nameid,item_data->equip);
  8530. }
  8531. return 0;
  8532. }
  8533. int buildin_autoequip(struct script_state *st){
  8534. int nameid, flag;
  8535. struct item_data *item_data;
  8536. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8537. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8538. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  8539. item_data->flag.autoequip = flag>0?1:0;
  8540. }
  8541. return 0;
  8542. }
  8543. int buildin_setbattleflag(struct script_state *st){
  8544. char *flag, *value;
  8545. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8546. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8547. if (battle_set_value(flag, value) == 0)
  8548. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'",flag);
  8549. else
  8550. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.",flag,value);
  8551. return 0;
  8552. }
  8553. //=======================================================
  8554. // strlen [Valaris]
  8555. //-------------------------------------------------------
  8556. int buildin_getstrlen(struct script_state *st) {
  8557. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8558. int len = (str) ? (int)strlen(str) : 0;
  8559. push_val(st->stack,C_INT,len);
  8560. return 0;
  8561. }
  8562. //=======================================================
  8563. // isalpha [Valaris]
  8564. //-------------------------------------------------------
  8565. int buildin_charisalpha(struct script_state *st) {
  8566. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8567. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8568. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? isalpha( str[pos] ) : 0;
  8569. push_val(st->stack,C_INT,val);
  8570. return 0;
  8571. }
  8572. // [Lance]
  8573. int buildin_fakenpcname(struct script_state *st)
  8574. {
  8575. char *name;
  8576. char *newname;
  8577. int look;
  8578. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8579. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8580. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  8581. if(look > 32767 || look < -32768) {
  8582. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  8583. return 1; // Safety measure to prevent runtime errors
  8584. }
  8585. npc_changename(name,newname,(short)look);
  8586. return 0;
  8587. }
  8588. int buildin_atoi(struct script_state *st) {
  8589. char *value;
  8590. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8591. push_val(st->stack, C_INT, atoi(value));
  8592. return 0;
  8593. }
  8594. //-----------------------------------------------------------------------//
  8595. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  8596. //-----------------------------------------------------------------------//
  8597. int buildin_compare(struct script_state *st) {
  8598. char *message;
  8599. char *cmpstring;
  8600. int j;
  8601. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8602. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8603. for (j = 0; message[j]; j++)
  8604. message[j] = tolower(message[j]);
  8605. for (j = 0; cmpstring[j]; j++)
  8606. cmpstring[j] = tolower(cmpstring[j]);
  8607. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  8608. return 0;
  8609. }
  8610. //-----------------------------------------------------------------------//
  8611. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  8612. //-----------------------------------------------------------------------//
  8613. // [zBuffer] List of mathematics commands --->
  8614. int buildin_sqrt(struct script_state *st){
  8615. double i, a;
  8616. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8617. a = sqrt(i);
  8618. push_val(st->stack, C_INT, (int)a);
  8619. return 0;
  8620. }
  8621. int buildin_pow(struct script_state *st){
  8622. double i, a, b;
  8623. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8624. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  8625. i = pow(a,b);
  8626. push_val(st->stack, C_INT, (int)i);
  8627. return 0;
  8628. }
  8629. int buildin_distance(struct script_state *st){
  8630. int x0, y0, x1, y1;
  8631. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  8632. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  8633. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  8634. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  8635. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  8636. return 0;
  8637. }
  8638. // <--- [zBuffer] List of mathematics commands
  8639. // [zBuffer] List of dynamic var commands --->
  8640. void setd_sub(struct map_session_data *sd, char *varname, int elem, void *value)
  8641. {
  8642. set_reg(sd, add_str((unsigned char *) varname)+(elem<<24), varname, value);
  8643. return;
  8644. }
  8645. int buildin_setd(struct script_state *st)
  8646. {
  8647. struct map_session_data *sd=NULL;
  8648. char varname[100], *buffer;
  8649. char *value;
  8650. int elem;
  8651. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  8652. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  8653. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  8654. elem = 0;
  8655. if(st->rid)
  8656. sd = script_rid2sd(st);
  8657. if(varname[strlen(varname)-1] != '$') {
  8658. setd_sub(sd, varname, elem, (void *)atoi(value));
  8659. } else {
  8660. setd_sub(sd, varname, elem, (void *)value);
  8661. }
  8662. return 0;
  8663. }
  8664. #ifndef TXT_ONLY
  8665. int buildin_query_sql(struct script_state *st) {
  8666. char *name, *query;
  8667. int num, i = 0;
  8668. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  8669. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  8670. strcpy(tmp_sql, query);
  8671. if(mysql_query(&mmysql_handle,tmp_sql)){
  8672. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  8673. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  8674. return 1;
  8675. }
  8676. if(st->end > st->start+3) {
  8677. if(st->stack->stack_data[st->start+3].type != C_NAME){
  8678. ShowWarning("buildin_query_sql: 2nd parameter is not a variable!\n");
  8679. } else {
  8680. num=st->stack->stack_data[st->start+3].u.num;
  8681. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  8682. if((sql_res = mysql_store_result(&mmysql_handle))){
  8683. if(name[strlen(name)-1] != '$') {
  8684. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  8685. setd_sub(sd, name, i, (void *)atoi(sql_row[0]));
  8686. i++;
  8687. }
  8688. } else {
  8689. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  8690. setd_sub(sd, name, i, (void *)sql_row[0]);
  8691. i++;
  8692. }
  8693. }
  8694. mysql_free_result(sql_res);
  8695. }
  8696. }
  8697. }
  8698. return 0;
  8699. }
  8700. #endif
  8701. int buildin_getd (struct script_state *st)
  8702. {
  8703. char varname[100], *buffer;
  8704. //struct script_data dat;
  8705. int elem;
  8706. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  8707. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  8708. elem = 0;
  8709. /*dat.type=C_NAME;
  8710. dat.u.num=add_str((unsigned char *) varname)+(elem<<24);
  8711. get_val(st,&dat);
  8712. if(dat.type == C_INT)
  8713. push_val(st->stack, C_INT, dat.u.num);
  8714. else if(dat.type == C_CONSTSTR){
  8715. buffer = aStrdup((char *)dat.u.str);
  8716. // dat.u.str holds the actual pointer to the data, must be duplicated.
  8717. // It will be freed later. Tested.
  8718. push_str(st->stack, C_STR, buffer);
  8719. }*/
  8720. // Push the 'pointer' so it's more flexible [Lance]
  8721. push_val(st->stack,C_NAME,
  8722. (elem<<24) | add_str((unsigned char *) varname));
  8723. return 0;
  8724. }
  8725. // <--- [zBuffer] List of dynamic var commands
  8726. // Pet stat [Lance]
  8727. int buildin_petstat(struct script_state *st){
  8728. struct map_session_data *sd = NULL;
  8729. char *tmp;
  8730. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  8731. sd = script_rid2sd(st);
  8732. if(!sd || !sd->pet.pet_id){
  8733. if(flag == 2)
  8734. push_str(st->stack, C_CONSTSTR, "");
  8735. else
  8736. push_val(st->stack, C_INT, 0);
  8737. }
  8738. else {
  8739. switch(flag){
  8740. case 1:
  8741. push_val(st->stack, C_INT, (int)sd->pet.class_);
  8742. break;
  8743. case 2:
  8744. tmp = aStrdup(sd->pet.name);
  8745. push_str(st->stack, C_STR, tmp);
  8746. break;
  8747. case 3:
  8748. push_val(st->stack, C_INT, (int)sd->pet.level);
  8749. break;
  8750. case 4:
  8751. push_val(st->stack, C_INT, (int)sd->pet.hungry);
  8752. break;
  8753. case 5:
  8754. push_val(st->stack, C_INT, (int)sd->pet.intimate);
  8755. break;
  8756. default:
  8757. push_val(st->stack, C_INT, 0);
  8758. break;
  8759. }
  8760. }
  8761. return 0;
  8762. }
  8763. int buildin_callshop(struct script_state *st)
  8764. {
  8765. struct map_session_data *sd = NULL;
  8766. struct npc_data *nd;
  8767. char *shopname;
  8768. int flag = 0;
  8769. sd = script_rid2sd(st);
  8770. if (!sd) {
  8771. push_val(st->stack,C_INT,0);
  8772. return 0;
  8773. }
  8774. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  8775. if( st->end>st->start+3 )
  8776. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  8777. nd = npc_name2id(shopname);
  8778. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  8779. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  8780. push_val(st->stack,C_INT,0);
  8781. return 1;
  8782. }
  8783. switch (flag) {
  8784. case 1: //Buy window
  8785. npc_buysellsel(sd,nd->bl.id,0);
  8786. break;
  8787. case 2: //Sell window
  8788. npc_buysellsel(sd,nd->bl.id,1);
  8789. break;
  8790. default: //Show menu
  8791. clif_npcbuysell(sd,nd->bl.id);
  8792. break;
  8793. }
  8794. sd->npc_shopid = nd->bl.id;
  8795. push_val(st->stack,C_INT,1);
  8796. return 0;
  8797. }
  8798. int buildin_npcshopitem(struct script_state *st)
  8799. {
  8800. struct npc_data *nd= NULL;
  8801. int n = 0;
  8802. int i = 3;
  8803. int itemid, value;
  8804. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  8805. nd = npc_name2id(npcname);
  8806. #ifndef MAX_SHOPITEM
  8807. #define MAX_SHOPITEM 100
  8808. #endif
  8809. if(nd){
  8810. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  8811. sizeof(nd->u.shop_item[0]) * (MAX_SHOPITEM + 1));
  8812. // Reset sell list.
  8813. for(;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM; n++){
  8814. nd->u.shop_item[n].nameid = 0;
  8815. nd->u.shop_item[n].value = 0;
  8816. }
  8817. n = 0;
  8818. while (st->end > st->start + i) {
  8819. itemid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  8820. nd->u.shop_item[n].nameid = itemid;
  8821. i++;
  8822. value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  8823. nd->u.shop_item[n].value = value;
  8824. i++;
  8825. n++;
  8826. }
  8827. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  8828. sizeof(nd->u.shop_item[0]) * (n+1));
  8829. map_addiddb(&nd->bl);
  8830. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  8831. } else {
  8832. ShowError("buildin_npcshopitem: shop not found.\n");
  8833. }
  8834. return 0;
  8835. }
  8836. /*==========================================
  8837. * Returns some values of an item [Lupus]
  8838. * Price, Weight, etc...
  8839. setiteminfo(itemID,"{new item bonus script}");
  8840. *------------------------------------------
  8841. */
  8842. int buildin_setitemscript(struct script_state *st)
  8843. {
  8844. int item_id;
  8845. char *script;
  8846. struct item_data *i_data;
  8847. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8848. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  8849. i_data = itemdb_exists(item_id);
  8850. if (i_data && script!=NULL && script[0]=='{') {
  8851. if(i_data->script!=NULL)
  8852. aFree(i_data->script);
  8853. i_data->script = parse_script((unsigned char *) script, 0);
  8854. push_val(st->stack,C_INT,1);
  8855. } else
  8856. push_val(st->stack,C_INT,0);
  8857. return 0;
  8858. }
  8859. /* Work In Progress [Lupus]
  8860. int buildin_addmonsterdrop(struct script_state *st)
  8861. {
  8862. int class_,item_id,chance;
  8863. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8864. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8865. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8866. if(class_>1000 && item_id>500 && chance>0) {
  8867. push_val(st->stack,C_INT,1);
  8868. } else {
  8869. push_val(st->stack,C_INT,0);
  8870. }
  8871. }
  8872. int buildin_delmonsterdrop(struct script_state *st)
  8873. {
  8874. int class_,item_id;
  8875. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8876. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8877. if(class_>1000 && item_id>500) {
  8878. push_val(st->stack,C_INT,1);
  8879. } else {
  8880. push_val(st->stack,C_INT,0);
  8881. }
  8882. }
  8883. */
  8884. /*==========================================
  8885. * Returns some values of a monster [Lupus]
  8886. * Name, Level, race, size, etc...
  8887. getmonsterinfo(monsterID,queryIndex);
  8888. *------------------------------------------
  8889. */
  8890. int buildin_getmonsterinfo(struct script_state *st)
  8891. {
  8892. struct mob_db *mob;
  8893. int mob_id;
  8894. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8895. if (mob_id <= 1000 || (mob = mob_db(mob_id))==NULL) {
  8896. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  8897. push_val(st->stack, C_INT, -1);
  8898. return -1;
  8899. }
  8900. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  8901. case 0: //Name
  8902. push_str(st->stack,C_CONSTSTR, (unsigned char *) mob->jname);
  8903. break;
  8904. case 1: //Lvl
  8905. push_val(st->stack,C_INT, mob->lv);
  8906. break;
  8907. case 2: //MaxHP
  8908. push_val(st->stack,C_INT, mob->max_hp);
  8909. break;
  8910. case 3: //Base EXP
  8911. push_val(st->stack,C_INT, mob->base_exp);
  8912. break;
  8913. case 4: //Job EXP
  8914. push_val(st->stack,C_INT, mob->job_exp);
  8915. break;
  8916. case 5: //Atk1
  8917. push_val(st->stack,C_INT, mob->atk1);
  8918. break;
  8919. case 6: //Atk2
  8920. push_val(st->stack,C_INT, mob->atk2);
  8921. break;
  8922. case 7: //Def
  8923. push_val(st->stack,C_INT, mob->def);
  8924. break;
  8925. case 8: //Mdef
  8926. push_val(st->stack,C_INT, mob->mdef);
  8927. break;
  8928. case 9: //Str
  8929. push_val(st->stack,C_INT, mob->str);
  8930. break;
  8931. case 10: //Agi
  8932. push_val(st->stack,C_INT, mob->agi);
  8933. break;
  8934. case 11: //Vit
  8935. push_val(st->stack,C_INT, mob->vit);
  8936. break;
  8937. case 12: //Int
  8938. push_val(st->stack,C_INT, mob->int_);
  8939. break;
  8940. case 13: //Dex
  8941. push_val(st->stack,C_INT, mob->dex);
  8942. break;
  8943. case 14: //Luk
  8944. push_val(st->stack,C_INT, mob->luk);
  8945. break;
  8946. case 15: //Range
  8947. push_val(st->stack,C_INT, mob->range);
  8948. break;
  8949. case 16: //Range2
  8950. push_val(st->stack,C_INT, mob->range2);
  8951. break;
  8952. case 17: //Range3
  8953. push_val(st->stack,C_INT, mob->range3);
  8954. break;
  8955. case 18: //Size
  8956. push_val(st->stack,C_INT, mob->size);
  8957. break;
  8958. case 19: //Race
  8959. push_val(st->stack,C_INT, mob->race);
  8960. break;
  8961. case 20: //Element
  8962. push_val(st->stack,C_INT, mob->element);
  8963. break;
  8964. case 21: //Mode
  8965. push_val(st->stack,C_INT, mob->mode);
  8966. break;
  8967. default: //wrong Index
  8968. push_val(st->stack,C_INT,-1);
  8969. }
  8970. return 0;
  8971. }
  8972. // [zBuffer] List of player cont commands --->
  8973. int buildin_rid2name(struct script_state *st){
  8974. struct block_list *bl = NULL;
  8975. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  8976. if((bl = map_id2bl(rid))){
  8977. switch(bl->type){
  8978. case BL_MOB:
  8979. push_str(st->stack,C_STR,((struct mob_data *)bl)->name);
  8980. break;
  8981. case BL_PC:
  8982. push_str(st->stack,C_STR,((struct map_session_data *)bl)->status.name);
  8983. break;
  8984. case BL_NPC:
  8985. push_str(st->stack,C_STR,((struct npc_data *)bl)->exname);
  8986. break;
  8987. default:
  8988. ShowError("buildin_rid2name: BL type unknown.\n");
  8989. break;
  8990. }
  8991. }
  8992. return 0;
  8993. }
  8994. int buildin_pcwalkxy(struct script_state *st){
  8995. int id, x, y;
  8996. struct map_session_data *sd = NULL;
  8997. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  8998. x = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  8999. y = conv_num(st, & (st->stack->stack_data[st->start + 4]));
  9000. if(id)
  9001. sd = map_id2sd(id);
  9002. else
  9003. sd = script_rid2sd(st);
  9004. if(sd)
  9005. unit_walktoxy(&sd->bl, x, y, 0);
  9006. return 0;
  9007. }
  9008. int buildin_pcblockmove(struct script_state *st){
  9009. int id, flag;
  9010. struct map_session_data *sd = NULL;
  9011. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9012. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  9013. if(id)
  9014. sd = map_id2sd(id);
  9015. else
  9016. sd = script_rid2sd(st);
  9017. if(sd)
  9018. sd->state.blockedmove = flag > 0;
  9019. return 0;
  9020. }
  9021. int buildin_pctalk(struct script_state *st){
  9022. int id;
  9023. char *str;
  9024. char message[255];
  9025. struct map_session_data *sd = NULL;
  9026. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9027. str = conv_str(st, & (st->stack->stack_data[st->start + 3]));
  9028. if(id)
  9029. sd = map_id2sd(id);
  9030. else
  9031. sd = script_rid2sd(st);
  9032. if(sd){
  9033. memcpy(message, sd->status.name, NAME_LENGTH);
  9034. strcat(message," : ");
  9035. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9036. clif_message(&(sd->bl), message);
  9037. clif_displaymessage(sd->fd, message);
  9038. }
  9039. return 0;
  9040. }
  9041. int buildin_pcemote(struct script_state *st) {
  9042. int id, emo;
  9043. struct map_session_data *sd = NULL;
  9044. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9045. emo = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  9046. if(id)
  9047. sd = map_id2sd(id);
  9048. else
  9049. sd = script_rid2sd(st);
  9050. if(sd)
  9051. clif_emotion(&sd->bl,emo);
  9052. return 0;
  9053. }
  9054. int buildin_pcfollow(struct script_state *st) {
  9055. int id, targetid;
  9056. struct map_session_data *sd = NULL;
  9057. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9058. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  9059. if(id)
  9060. sd = map_id2sd(id);
  9061. else
  9062. sd = script_rid2sd(st);
  9063. if(sd)
  9064. pc_follow(sd, targetid);
  9065. return 0;
  9066. }
  9067. int buildin_pcstopfollow(struct script_state *st) {
  9068. int id;
  9069. struct map_session_data *sd = NULL;
  9070. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  9071. if(id)
  9072. sd = map_id2sd(id);
  9073. else
  9074. sd = script_rid2sd(st);
  9075. if(sd)
  9076. pc_stop_following(sd);
  9077. return 0;
  9078. }
  9079. // <--- [zBuffer] List of player cont commands
  9080. // [zBuffer] List of mob control commands --->
  9081. int buildin_spawnmob(struct script_state *st){
  9082. int class_,x,y,id;
  9083. char *str,*map,*event="";
  9084. struct mob_data *md = NULL;
  9085. // Who?
  9086. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9087. // What?
  9088. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  9089. // Where?
  9090. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  9091. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  9092. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  9093. // When?
  9094. if( st->end > st->start+8 )
  9095. event=conv_str(st,& (st->stack->stack_data[st->start+7]));
  9096. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,event);
  9097. if(id){
  9098. md = (struct mob_data *)map_id2bl(id);
  9099. if(md){
  9100. md->mode = md->db->mode;
  9101. }
  9102. push_val(st->stack,C_INT,id);
  9103. }
  9104. return 0;
  9105. }
  9106. int buildin_removemob(struct script_state *st) {
  9107. int id;
  9108. struct block_list *bl = NULL;
  9109. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9110. bl = map_id2bl(id);
  9111. if (bl && bl->type == BL_MOB)
  9112. unit_free(bl);
  9113. return 0;
  9114. }
  9115. int buildin_mobwalk(struct script_state *st){
  9116. int id,x,y;
  9117. struct block_list *bl = NULL;
  9118. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9119. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9120. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  9121. bl = map_id2bl(id);
  9122. if(bl && bl->type == BL_MOB)
  9123. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  9124. else
  9125. push_val(st->stack,C_INT,0);
  9126. return 0;
  9127. }
  9128. int buildin_getmobdata(struct script_state *st) {
  9129. int num, id;
  9130. char *name;
  9131. struct mob_data *md = NULL;
  9132. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9133. if(!(md = (struct mob_data *)map_id2bl(id)) || st->stack->stack_data[st->start+3].type!=C_NAME ){
  9134. ShowWarning("buildin_getmobdata: Error in argiment!\n");
  9135. } else {
  9136. num=st->stack->stack_data[st->start+2].u.num;
  9137. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9138. setd_sub(map_id2sd(st->rid),name,0,(void *)(int)md->class_);
  9139. setd_sub(map_id2sd(st->rid),name,1,(void *)(int)md->level);
  9140. setd_sub(map_id2sd(st->rid),name,2,(void *)(int)md->hp);
  9141. setd_sub(map_id2sd(st->rid),name,3,(void *)(int)md->max_hp);
  9142. setd_sub(map_id2sd(st->rid),name,4,(void *)(int)md->master_id);
  9143. setd_sub(map_id2sd(st->rid),name,5,(void *)(int)md->bl.m);
  9144. setd_sub(map_id2sd(st->rid),name,6,(void *)(int)md->bl.x);
  9145. setd_sub(map_id2sd(st->rid),name,7,(void *)(int)md->bl.y);
  9146. setd_sub(map_id2sd(st->rid),name,8,(void *)(int)md->speed);
  9147. setd_sub(map_id2sd(st->rid),name,9,(void *)(int)md->mode);
  9148. setd_sub(map_id2sd(st->rid),name,10,(void *)(int)md->special_state.ai);
  9149. setd_sub(map_id2sd(st->rid),name,11,(void *)(int)md->db->option);
  9150. setd_sub(map_id2sd(st->rid),name,12,(void *)(int)md->vd->sex);
  9151. setd_sub(map_id2sd(st->rid),name,13,(void *)(int)md->vd->class_);
  9152. setd_sub(map_id2sd(st->rid),name,14,(void *)(int)md->vd->hair_style);
  9153. setd_sub(map_id2sd(st->rid),name,15,(void *)(int)md->vd->hair_color);
  9154. setd_sub(map_id2sd(st->rid),name,16,(void *)(int)md->vd->head_bottom);
  9155. setd_sub(map_id2sd(st->rid),name,17,(void *)(int)md->vd->head_mid);
  9156. setd_sub(map_id2sd(st->rid),name,18,(void *)(int)md->vd->head_top);
  9157. setd_sub(map_id2sd(st->rid),name,19,(void *)(int)md->vd->cloth_color);
  9158. setd_sub(map_id2sd(st->rid),name,20,(void *)(int)md->vd->shield);
  9159. setd_sub(map_id2sd(st->rid),name,21,(void *)(int)md->vd->weapon);
  9160. setd_sub(map_id2sd(st->rid),name,22,(void *)(int)md->vd->shield);
  9161. setd_sub(map_id2sd(st->rid),name,23,(void *)(int)md->ud.dir);
  9162. }
  9163. return 0;
  9164. }
  9165. int buildin_setmobdata(struct script_state *st){
  9166. int id, value;
  9167. struct mob_data *md = NULL;
  9168. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9169. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9170. if(!(md = (struct mob_data *)map_id2bl(id)) || st->stack->stack_data[st->start+3].type!=C_NAME ){
  9171. ShowWarning("buildin_setmobdata: Error in argument!\n");
  9172. } else {
  9173. switch(id){
  9174. case 0:
  9175. md->class_ = (short)value;
  9176. break;
  9177. case 1:
  9178. md->level = (unsigned short)value;
  9179. break;
  9180. case 2:
  9181. md->hp = value;
  9182. break;
  9183. case 3:
  9184. md->max_hp = value;
  9185. break;
  9186. case 4:
  9187. md->master_id = value;
  9188. break;
  9189. case 5:
  9190. md->bl.m = (short)value;
  9191. break;
  9192. case 6:
  9193. md->bl.x = (short)value;
  9194. break;
  9195. case 7:
  9196. md->bl.y = (short)value;
  9197. break;
  9198. case 8:
  9199. md->speed = (short)value;
  9200. break;
  9201. case 9:
  9202. md->mode = (short)value;
  9203. break;
  9204. case 10:
  9205. md->special_state.ai = (unsigned int)value;
  9206. break;
  9207. case 11:
  9208. md->db->option = (short)value;
  9209. break;
  9210. case 12:
  9211. md->vd->sex = value;
  9212. break;
  9213. case 13:
  9214. md->vd->class_ = value;
  9215. break;
  9216. case 14:
  9217. md->vd->hair_style = (short)value;
  9218. break;
  9219. case 15:
  9220. md->vd->hair_color = (short)value;
  9221. break;
  9222. case 16:
  9223. md->vd->head_bottom = (short)value;
  9224. break;
  9225. case 17:
  9226. md->vd->head_mid = (short)value;
  9227. break;
  9228. case 18:
  9229. md->vd->head_top = (short)value;
  9230. break;
  9231. case 19:
  9232. md->vd->cloth_color = (short)value;
  9233. break;
  9234. case 20:
  9235. md->vd->shield = value;
  9236. break;
  9237. case 21:
  9238. md->vd->weapon = (short)value;
  9239. break;
  9240. case 22:
  9241. md->vd->shield = (short)value;
  9242. break;
  9243. case 23:
  9244. md->ud.dir = (unsigned char)value;
  9245. break;
  9246. default:
  9247. ShowError("buildin_setmobdata: argument id is not identified.");
  9248. break;
  9249. }
  9250. }
  9251. return 0;
  9252. }
  9253. int buildin_mobattack(struct script_state *st) {
  9254. int id;
  9255. char *target;
  9256. struct mob_data *md = NULL;
  9257. struct map_session_data *sd = NULL;
  9258. struct block_list *bl = NULL;
  9259. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9260. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9261. if((sd = map_nick2sd(target)) != NULL || (bl = map_id2bl(atoi(target))) != NULL) {
  9262. if (sd) bl = &sd->bl;
  9263. md = (struct mob_data *)map_id2bl(id);
  9264. if (md && md->bl.type == BL_MOB) {
  9265. md->target_id = sd->bl.id;
  9266. md->special_state.ai = 1;
  9267. md->min_chase = distance_bl(bl,&md->bl) + md->db->range2;
  9268. }
  9269. }
  9270. return 0;
  9271. }
  9272. int buildin_mobstop(struct script_state *st) {
  9273. int id;
  9274. struct block_list *bl = NULL;
  9275. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9276. bl = map_id2bl(id);
  9277. if(bl && bl->type == BL_MOB){
  9278. unit_stop_attack(bl);
  9279. unit_stop_walking(bl,0);
  9280. ((TBL_MOB*)bl)->master_id = bl->id; // Quick hack to stop random walking.
  9281. }
  9282. return 0;
  9283. }
  9284. int buildin_mobassist(struct script_state *st) {
  9285. int id;
  9286. char *target;
  9287. struct mob_data *md = NULL;
  9288. struct block_list *bl = NULL;
  9289. struct unit_data *ud;
  9290. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9291. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  9292. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  9293. md = (struct mob_data *)map_id2bl(id);
  9294. if(md && md->bl.type == BL_MOB) {
  9295. ud = unit_bl2ud(bl);
  9296. md->master_id = bl->id;
  9297. if (ud) {
  9298. if (ud->attacktarget)
  9299. md->target_id = ud->attacktarget;
  9300. else if (ud->skilltarget)
  9301. md->target_id = ud->skilltarget;
  9302. md->min_chase = distance_bl(&md->bl,map_id2bl(md->target_id)) + md->db->range2;
  9303. }
  9304. }
  9305. }
  9306. return 0;
  9307. }
  9308. int buildin_mobtalk(struct script_state *st)
  9309. {
  9310. char *str;
  9311. int id;
  9312. char message[255];
  9313. struct mob_data *md = NULL;
  9314. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9315. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  9316. md = (struct mob_data *)map_id2bl(id);
  9317. if(md && md->bl.type == BL_MOB) {
  9318. memcpy(message, md->name, NAME_LENGTH);
  9319. strcat(message," : ");
  9320. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9321. clif_message(&(md->bl), message);
  9322. }
  9323. return 0;
  9324. }
  9325. int buildin_mobemote(struct script_state *st) {
  9326. int id, emo;
  9327. struct mob_data *md = NULL;
  9328. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9329. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  9330. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  9331. clif_emotion(&md->bl,emo);
  9332. return 0;
  9333. }
  9334. int buildin_mobattach(struct script_state *st){
  9335. int id;
  9336. struct mob_data *md = NULL;
  9337. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  9338. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  9339. md->nd = (struct npc_data *)map_id2bl(st->oid);
  9340. return 0;
  9341. }
  9342. // <--- [zBuffer] List of mob control commands
  9343. //
  9344. // 実行部main
  9345. //
  9346. /*==========================================
  9347. * コマンドの読み取り
  9348. *------------------------------------------
  9349. */
  9350. static int unget_com_data=-1;
  9351. int get_com(unsigned char *script,int *pos)
  9352. {
  9353. int i,j;
  9354. if(unget_com_data>=0){
  9355. i=unget_com_data;
  9356. unget_com_data=-1;
  9357. return i;
  9358. }
  9359. if(script[*pos]>=0x80){
  9360. return C_INT;
  9361. }
  9362. i=0; j=0;
  9363. while(script[*pos]>=0x40){
  9364. i=script[(*pos)++]<<j;
  9365. j+=6;
  9366. }
  9367. return i+(script[(*pos)++]<<j);
  9368. }
  9369. /*==========================================
  9370. * コマンドのプッシュバック
  9371. *------------------------------------------
  9372. */
  9373. void unget_com(int c)
  9374. {
  9375. if(unget_com_data!=-1){
  9376. if(battle_config.error_log)
  9377. ShowError("unget_com can back only 1 data\n");
  9378. }
  9379. unget_com_data=c;
  9380. }
  9381. /*==========================================
  9382. * 数値の所得
  9383. *------------------------------------------
  9384. */
  9385. int get_num(unsigned char *script,int *pos)
  9386. {
  9387. int i,j;
  9388. i=0; j=0;
  9389. while(script[*pos]>=0xc0){
  9390. i+=(script[(*pos)++]&0x7f)<<j;
  9391. j+=6;
  9392. }
  9393. return i+((script[(*pos)++]&0x7f)<<j);
  9394. }
  9395. /*==========================================
  9396. * スタックから値を取り出す
  9397. *------------------------------------------
  9398. */
  9399. int pop_val(struct script_state* st)
  9400. {
  9401. if(st->stack->sp<=0)
  9402. return 0;
  9403. st->stack->sp--;
  9404. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  9405. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  9406. return st->stack->stack_data[st->stack->sp].u.num;
  9407. return 0;
  9408. }
  9409. #define isstr(c) ((c).type==C_STR || (c).type==C_CONSTSTR)
  9410. /*==========================================
  9411. * 加算演算子
  9412. *------------------------------------------
  9413. */
  9414. void op_add(struct script_state* st)
  9415. {
  9416. st->stack->sp--;
  9417. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  9418. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  9419. if(isstr(st->stack->stack_data[st->stack->sp]) || isstr(st->stack->stack_data[st->stack->sp-1])){
  9420. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  9421. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  9422. }
  9423. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  9424. st->stack->stack_data[st->stack->sp-1].u.num += st->stack->stack_data[st->stack->sp].u.num;
  9425. } else { // ssの予定
  9426. char *buf;
  9427. buf=(char *)aCallocA(strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  9428. strlen(st->stack->stack_data[st->stack->sp].u.str)+1,sizeof(char));
  9429. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  9430. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  9431. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  9432. {
  9433. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  9434. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  9435. }
  9436. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  9437. {
  9438. aFree(st->stack->stack_data[st->stack->sp].u.str);
  9439. st->stack->stack_data[st->stack->sp].type=C_INT;
  9440. }
  9441. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  9442. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  9443. }
  9444. }
  9445. /*==========================================
  9446. * 二項演算子(文字列)
  9447. *------------------------------------------
  9448. */
  9449. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  9450. {
  9451. char *s1=st->stack->stack_data[sp1].u.str,
  9452. *s2=st->stack->stack_data[sp2].u.str;
  9453. int a=0;
  9454. switch(op){
  9455. case C_EQ:
  9456. a= (strcmp(s1,s2)==0);
  9457. break;
  9458. case C_NE:
  9459. a= (strcmp(s1,s2)!=0);
  9460. break;
  9461. case C_GT:
  9462. a= (strcmp(s1,s2)> 0);
  9463. break;
  9464. case C_GE:
  9465. a= (strcmp(s1,s2)>=0);
  9466. break;
  9467. case C_LT:
  9468. a= (strcmp(s1,s2)< 0);
  9469. break;
  9470. case C_LE:
  9471. a= (strcmp(s1,s2)<=0);
  9472. break;
  9473. default:
  9474. ShowWarning("script: illegal string operator\n");
  9475. break;
  9476. }
  9477. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  9478. // So, call push_val() after freeing strings. [jA1783]
  9479. // push_val(st->stack,C_INT,a);
  9480. if(st->stack->stack_data[sp1].type==C_STR)
  9481. {
  9482. aFree(s1);
  9483. st->stack->stack_data[sp1].type=C_INT;
  9484. }
  9485. if(st->stack->stack_data[sp2].type==C_STR)
  9486. {
  9487. aFree(s2);
  9488. st->stack->stack_data[sp2].type=C_INT;
  9489. }
  9490. push_val(st->stack,C_INT,a);
  9491. }
  9492. /*==========================================
  9493. * 二項演算子(数値)
  9494. *------------------------------------------
  9495. */
  9496. void op_2num(struct script_state *st,int op,int i1,int i2)
  9497. {
  9498. switch(op){
  9499. case C_SUB:
  9500. i1-=i2;
  9501. break;
  9502. case C_MUL:
  9503. {
  9504. #ifndef _MSC_VER
  9505. long long res = i1 * i2;
  9506. #else
  9507. __int64 res = i1 * i2;
  9508. #endif
  9509. if (res > 2147483647 )
  9510. i1 = 2147483647;
  9511. else
  9512. i1*=i2;
  9513. }
  9514. break;
  9515. case C_DIV:
  9516. if (i2 != 0)
  9517. i1/=i2;
  9518. else
  9519. ShowWarning("op_2num: Attempted to divide by 0 in a script (operation C_DIV)!\n");
  9520. break;
  9521. case C_MOD:
  9522. if (i2 != 0)
  9523. i1%=i2;
  9524. else
  9525. ShowWarning("op_2num: Attempted to divide by 0 in a script (operation C_MOD)!\n");
  9526. break;
  9527. case C_AND:
  9528. i1&=i2;
  9529. break;
  9530. case C_OR:
  9531. i1|=i2;
  9532. break;
  9533. case C_XOR:
  9534. i1^=i2;
  9535. break;
  9536. case C_LAND:
  9537. i1=i1&&i2;
  9538. break;
  9539. case C_LOR:
  9540. i1=i1||i2;
  9541. break;
  9542. case C_EQ:
  9543. i1=i1==i2;
  9544. break;
  9545. case C_NE:
  9546. i1=i1!=i2;
  9547. break;
  9548. case C_GT:
  9549. i1=i1>i2;
  9550. break;
  9551. case C_GE:
  9552. i1=i1>=i2;
  9553. break;
  9554. case C_LT:
  9555. i1=i1<i2;
  9556. break;
  9557. case C_LE:
  9558. i1=i1<=i2;
  9559. break;
  9560. case C_R_SHIFT:
  9561. i1=i1>>i2;
  9562. break;
  9563. case C_L_SHIFT:
  9564. i1=i1<<i2;
  9565. break;
  9566. }
  9567. push_val(st->stack,C_INT,i1);
  9568. }
  9569. /*==========================================
  9570. * 二項演算子
  9571. *------------------------------------------
  9572. */
  9573. void op_2(struct script_state *st,int op)
  9574. {
  9575. int i1,i2;
  9576. char *s1=NULL,*s2=NULL;
  9577. i2=pop_val(st);
  9578. if( isstr(st->stack->stack_data[st->stack->sp]) )
  9579. s2=st->stack->stack_data[st->stack->sp].u.str;
  9580. i1=pop_val(st);
  9581. if( isstr(st->stack->stack_data[st->stack->sp]) )
  9582. s1=st->stack->stack_data[st->stack->sp].u.str;
  9583. if( s1!=NULL && s2!=NULL ){
  9584. // ss => op_2str
  9585. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  9586. }else if( s1==NULL && s2==NULL ){
  9587. // ii => op_2num
  9588. op_2num(st,op,i1,i2);
  9589. }else{
  9590. // si,is => error
  9591. ShowWarning("script: op_2: int&str, str&int not allow.");
  9592. push_val(st->stack,C_INT,0);
  9593. }
  9594. }
  9595. /*==========================================
  9596. * 単項演算子
  9597. *------------------------------------------
  9598. */
  9599. void op_1num(struct script_state *st,int op)
  9600. {
  9601. int i1;
  9602. i1=pop_val(st);
  9603. switch(op){
  9604. case C_NEG:
  9605. i1=-i1;
  9606. break;
  9607. case C_NOT:
  9608. i1=~i1;
  9609. break;
  9610. case C_LNOT:
  9611. i1=!i1;
  9612. break;
  9613. }
  9614. push_val(st->stack,C_INT,i1);
  9615. }
  9616. /*==========================================
  9617. * 関数の実行
  9618. *------------------------------------------
  9619. */
  9620. int run_func(struct script_state *st)
  9621. {
  9622. int i,start_sp,end_sp,func;
  9623. end_sp=st->stack->sp;
  9624. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  9625. if(i==0){
  9626. if(battle_config.error_log)
  9627. ShowError("function not found\n");
  9628. // st->stack->sp=0;
  9629. st->state=END;
  9630. report_src(st);
  9631. return 1;
  9632. }
  9633. start_sp=i-1;
  9634. st->start=i-1;
  9635. st->end=end_sp;
  9636. func=st->stack->stack_data[st->start].u.num;
  9637. if( st->stack->stack_data[st->start].type!=C_NAME || str_data[func].type!=C_FUNC ){
  9638. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n",
  9639. str_buf + str_data[func].str, str_data[func].type);
  9640. // st->stack->sp=0;
  9641. st->state=END;
  9642. report_src(st);
  9643. return 1;
  9644. }
  9645. #ifdef DEBUG_RUN
  9646. if(battle_config.etc_log) {
  9647. 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);
  9648. ShowDebug("stack dump :");
  9649. for(i=0;i<end_sp;i++){
  9650. switch(st->stack->stack_data[i].type){
  9651. case C_INT:
  9652. printf(" int(%d)",st->stack->stack_data[i].u.num);
  9653. break;
  9654. case C_NAME:
  9655. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num].str);
  9656. break;
  9657. case C_ARG:
  9658. printf(" arg");
  9659. break;
  9660. case C_POS:
  9661. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  9662. break;
  9663. case C_STR:
  9664. printf(" str(%s)",st->stack->stack_data[i].u.str);
  9665. break;
  9666. case C_CONSTSTR:
  9667. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  9668. break;
  9669. default:
  9670. printf(" %d,%d",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  9671. }
  9672. }
  9673. printf("\n");
  9674. }
  9675. #endif
  9676. if(str_data[func].func){
  9677. if (str_data[func].func(st)) //Report error
  9678. report_src(st);
  9679. } else {
  9680. if(battle_config.error_log)
  9681. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  9682. push_val(st->stack,C_INT,0);
  9683. report_src(st);
  9684. }
  9685. // Stack's datum are used when re-run functions [Eoe]
  9686. if(st->state != RERUNLINE) {
  9687. pop_stack(st->stack,start_sp,end_sp);
  9688. }
  9689. if(st->state==RETFUNC){
  9690. // ユーザー定義関数からの復帰
  9691. int olddefsp=st->stack->defsp;
  9692. int i;
  9693. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  9694. if(st->stack->defsp<4 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  9695. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  9696. st->state=END;
  9697. report_src(st);
  9698. return 1;
  9699. }
  9700. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 引数の数所得
  9701. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  9702. st->script=(char*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-2])); // スクリプトを復元
  9703. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // 基準スタックポインタを復元
  9704. pop_stack(st->stack,olddefsp-4-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  9705. st->state=GOTO;
  9706. }
  9707. return 0;
  9708. }
  9709. /*==========================================
  9710. * スクリプトの実行メイン部分
  9711. *------------------------------------------
  9712. */
  9713. int run_script_main(struct script_state *st)
  9714. {
  9715. int c/*,rerun_pos*/;
  9716. int cmdcount=script_config.check_cmdcount;
  9717. int gotocount=script_config.check_gotocount;
  9718. struct script_stack *stack=st->stack;
  9719. if(st->state == RERUNLINE) {
  9720. st->state = RUN;
  9721. run_func(st);
  9722. if(st->state == GOTO){
  9723. st->state = RUN;
  9724. }
  9725. } else {
  9726. st->state = RUN;
  9727. }
  9728. while( st->state == RUN) {
  9729. c= get_com((unsigned char *) st->script,&st->pos);
  9730. switch(c){
  9731. case C_EOL:
  9732. if(stack->sp!=stack->defsp){
  9733. if(stack->sp > stack->defsp)
  9734. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  9735. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  9736. if (battle_config.etc_log)
  9737. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  9738. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  9739. } else if(battle_config.error_log)
  9740. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  9741. stack->sp=stack->defsp;
  9742. }
  9743. // rerun_pos=st->pos;
  9744. break;
  9745. case C_INT:
  9746. push_val(stack,C_INT,get_num((unsigned char *) st->script,&st->pos));
  9747. break;
  9748. case C_POS:
  9749. case C_NAME:
  9750. push_val(stack,c,(*(int*)(st->script+st->pos))&0xffffff);
  9751. st->pos+=3;
  9752. break;
  9753. case C_ARG:
  9754. push_val(stack,c,0);
  9755. break;
  9756. case C_STR:
  9757. push_str(stack,C_CONSTSTR,(unsigned char *) (st->script+st->pos));
  9758. while(st->script[st->pos++]);
  9759. break;
  9760. case C_FUNC:
  9761. run_func(st);
  9762. if(st->state==GOTO){
  9763. // rerun_pos=st->pos;
  9764. st->state=0;
  9765. if( gotocount>0 && (--gotocount)<=0 ){
  9766. ShowError("run_script: infinity loop !\n");
  9767. st->state=END;
  9768. }
  9769. }
  9770. break;
  9771. case C_ADD:
  9772. op_add(st);
  9773. break;
  9774. case C_SUB:
  9775. case C_MUL:
  9776. case C_DIV:
  9777. case C_MOD:
  9778. case C_EQ:
  9779. case C_NE:
  9780. case C_GT:
  9781. case C_GE:
  9782. case C_LT:
  9783. case C_LE:
  9784. case C_AND:
  9785. case C_OR:
  9786. case C_XOR:
  9787. case C_LAND:
  9788. case C_LOR:
  9789. case C_R_SHIFT:
  9790. case C_L_SHIFT:
  9791. op_2(st,c);
  9792. break;
  9793. case C_NEG:
  9794. case C_NOT:
  9795. case C_LNOT:
  9796. op_1num(st,c);
  9797. break;
  9798. case C_NOP:
  9799. st->state=END;
  9800. break;
  9801. default:
  9802. if(battle_config.error_log)
  9803. ShowError("unknown command : %d @ %d\n",c,pos);
  9804. st->state=END;
  9805. break;
  9806. }
  9807. if( cmdcount>0 && (--cmdcount)<=0 ){
  9808. ShowError("run_script: infinity loop !\n");
  9809. st->state=END;
  9810. }
  9811. }
  9812. switch(st->state){
  9813. case STOP:
  9814. break;
  9815. case END:
  9816. {
  9817. struct map_session_data *sd=map_id2sd(st->rid);
  9818. st->pos=-1;
  9819. if(sd && sd->npc_id==st->oid)
  9820. npc_event_dequeue(sd);
  9821. }
  9822. break;
  9823. case RERUNLINE:
  9824. // Do not call function of commands two time! [ Eoe / jA 1094 ]
  9825. // For example: select "1", "2", callsub(...);
  9826. // If current script position is changed, callsub will be called two time.
  9827. //
  9828. // {
  9829. // st->pos=rerun_pos;
  9830. // }
  9831. break;
  9832. }
  9833. return 0;
  9834. }
  9835. /*==========================================
  9836. * スクリプトの実行
  9837. *------------------------------------------
  9838. */
  9839. int run_script(unsigned char *script,int pos,int rid,int oid)
  9840. {
  9841. struct script_state st;
  9842. struct map_session_data *sd;
  9843. unsigned char *rootscript = script;
  9844. //Variables for backing up the previous script and restore it if needed. [Skotlex]
  9845. unsigned char *bck_script = NULL;
  9846. unsigned char *bck_scriptroot = NULL;
  9847. int bck_scriptstate = 0;
  9848. struct script_stack *bck_stack = NULL;
  9849. if (script == NULL || pos < 0)
  9850. return -1;
  9851. memset(&st, 0, sizeof(struct script_state));
  9852. if ((sd = map_id2sd(rid)) && sd->stack && sd->npc_scriptroot == rootscript){
  9853. // we have a stack for the same script, should continue exec.
  9854. st.script = sd->npc_script;
  9855. st.stack = sd->stack;
  9856. st.state = sd->npc_scriptstate;
  9857. // and clear vars
  9858. sd->stack = NULL;
  9859. sd->npc_script = NULL;
  9860. sd->npc_scriptroot = NULL;
  9861. sd->npc_scriptstate = 0;
  9862. } else {
  9863. // the script is different, make new script_state and stack
  9864. st.stack = aCalloc (1, sizeof(struct script_stack));
  9865. st.stack->sp = 0;
  9866. st.stack->sp_max = 64;
  9867. st.stack->stack_data = (struct script_data *) aCalloc (st.stack->sp_max,sizeof(st.stack->stack_data[0]));
  9868. st.stack->defsp = st.stack->sp;
  9869. st.state = RUN;
  9870. st.script = rootscript;
  9871. if (sd && sd->stack) { // if there's a sd and a stack - back it up and restore it if possible.
  9872. bck_script = sd->npc_script;
  9873. bck_scriptroot = sd->npc_scriptroot;
  9874. bck_scriptstate = sd->npc_scriptstate;
  9875. bck_stack = sd->stack;
  9876. sd->stack = NULL;
  9877. }
  9878. }
  9879. st.pos = pos;
  9880. st.rid = rid;
  9881. st.oid = oid;
  9882. // let's run that stuff
  9883. run_script_main(&st);
  9884. sd = map_id2sd(st.rid);
  9885. if (st.state != END && sd) {
  9886. // script is not finished, store data in sd.
  9887. sd->npc_script = st.script;
  9888. sd->npc_scriptroot = rootscript;
  9889. sd->npc_scriptstate = st.state;
  9890. sd->stack = st.stack;
  9891. if (bck_stack) //Get rid of the backup as it can't be restored.
  9892. script_free_stack (bck_stack);
  9893. } else {
  9894. // we are done with stuff, free the stack
  9895. script_free_stack (st.stack);
  9896. // and if there was a sd associated - zero vars.
  9897. if (sd) {
  9898. //Clear or restore previous script.
  9899. sd->npc_script = bck_script;
  9900. sd->npc_scriptroot = bck_scriptroot;
  9901. sd->npc_scriptstate = bck_scriptstate;
  9902. sd->stack = bck_stack;
  9903. //Since the script is done, save any changed account variables [Skotlex]
  9904. if (sd->state.reg_dirty&2)
  9905. intif_saveregistry(sd,2);
  9906. if (sd->state.reg_dirty&1)
  9907. intif_saveregistry(sd,1);
  9908. }
  9909. }
  9910. return st.pos;
  9911. }
  9912. /*==========================================
  9913. * マップ変数の変更
  9914. *------------------------------------------
  9915. */
  9916. int mapreg_setreg(int num,int val)
  9917. {
  9918. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9919. int i=num>>24;
  9920. char *name=str_buf+str_data[num&0x00ffffff].str;
  9921. char tmp_str[64];
  9922. #endif
  9923. if(val!=0) {
  9924. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9925. if(name[1] != '@' && idb_get(mapreg_db,num) == NULL) {
  9926. 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);
  9927. if(mysql_query(&mmysql_handle,tmp_sql)){
  9928. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  9929. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  9930. }
  9931. }
  9932. #endif
  9933. idb_put(mapreg_db,num,(void*)val);
  9934. // else
  9935. } else { // [zBuffer]
  9936. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9937. if(name[1] != '@') { // Remove from database because it is unused.
  9938. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  9939. if(mysql_query(&mmysql_handle,tmp_sql)){
  9940. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  9941. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  9942. }
  9943. }
  9944. #endif
  9945. idb_remove(mapreg_db,num);
  9946. }
  9947. mapreg_dirty=1;
  9948. return 0;
  9949. }
  9950. /*==========================================
  9951. * 文字列型マップ変数の変更
  9952. *------------------------------------------
  9953. */
  9954. int mapreg_setregstr(int num,const char *str)
  9955. {
  9956. char *p;
  9957. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9958. char tmp_str[64];
  9959. char tmp_str2[512];
  9960. int i=num>>24; // [zBuffer]
  9961. char *name=str_buf+str_data[num&0x00ffffff].str;
  9962. #endif
  9963. if( str==NULL || *str==0 ){
  9964. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9965. if(name[1] != '@') {
  9966. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  9967. if(mysql_query(&mmysql_handle,tmp_sql)){
  9968. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  9969. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  9970. }
  9971. }
  9972. #endif
  9973. idb_remove(mapregstr_db,num);
  9974. mapreg_dirty=1;
  9975. return 0;
  9976. }
  9977. p=(char *)aCallocA(strlen(str)+1, sizeof(char));
  9978. strcpy(p,str);
  9979. if (idb_put(mapregstr_db,num,p))
  9980. ;
  9981. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  9982. else { //put returned null, so we must insert.
  9983. 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));
  9984. if(mysql_query(&mmysql_handle,tmp_sql)){
  9985. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  9986. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  9987. }
  9988. }
  9989. #endif
  9990. mapreg_dirty=1;
  9991. return 0;
  9992. }
  9993. /*==========================================
  9994. * 永続的マップ変数の読み込み
  9995. *------------------------------------------
  9996. */
  9997. static int script_load_mapreg(void)
  9998. {
  9999. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10000. FILE *fp;
  10001. char line[1024];
  10002. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  10003. return -1;
  10004. while(fgets(line,sizeof(line),fp)){
  10005. char buf1[256],buf2[1024],*p;
  10006. int n,v,s,i;
  10007. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  10008. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  10009. continue;
  10010. if( buf1[strlen(buf1)-1]=='$' ){
  10011. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  10012. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  10013. continue;
  10014. }
  10015. p=(char *)aCallocA(strlen(buf2) + 1,sizeof(char));
  10016. strcpy(p,buf2);
  10017. s= add_str((unsigned char *) buf1);
  10018. idb_put(mapregstr_db,(i<<24)|s,p);
  10019. }else{
  10020. if( sscanf(line+n,"%d",&v)!=1 ){
  10021. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  10022. continue;
  10023. }
  10024. s= add_str((unsigned char *) buf1);
  10025. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  10026. }
  10027. }
  10028. fclose(fp);
  10029. mapreg_dirty=0;
  10030. return 0;
  10031. #else
  10032. // SQL mapreg code start [zBuffer]
  10033. /*
  10034. 0 1 2
  10035. +-------------------------+
  10036. | varname | index | value |
  10037. +-------------------------+
  10038. */
  10039. int perfomance = gettick_nocache();
  10040. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  10041. ShowInfo("Querying script_load_mapreg ...\n");
  10042. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10043. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10044. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10045. return -1;
  10046. }
  10047. ShowInfo("Success! Returning results ...\n");
  10048. sql_res = mysql_store_result(&mmysql_handle);
  10049. if (sql_res) {
  10050. while ((sql_row = mysql_fetch_row(sql_res))) {
  10051. char buf1[33], *p = NULL;
  10052. int i,v,s;
  10053. strcpy(buf1,sql_row[0]);
  10054. if( buf1[strlen(buf1)-1]=='$' ){
  10055. i = atoi(sql_row[1]);
  10056. p=(char *)aCallocA(strlen(sql_row[2]) + 1,sizeof(char));
  10057. strcpy(p,sql_row[2]);
  10058. s= add_str((unsigned char *) buf1);
  10059. idb_put(mapregstr_db,(i<<24)|s,p);
  10060. }else{
  10061. s= add_str((unsigned char *) buf1);
  10062. v= atoi(sql_row[2]);
  10063. i = atoi(sql_row[1]);
  10064. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  10065. }
  10066. }
  10067. }
  10068. ShowInfo("Freeing results...\n");
  10069. mysql_free_result(sql_res);
  10070. mapreg_dirty=0;
  10071. perfomance = (gettick_nocache() - perfomance) / 1000;
  10072. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  10073. return 0;
  10074. #endif /* TXT_ONLY */
  10075. }
  10076. /*==========================================
  10077. * 永続的マップ変数の書き込み
  10078. *------------------------------------------
  10079. */
  10080. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  10081. {
  10082. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10083. FILE *fp=va_arg(ap,FILE*);
  10084. int num=key.i&0x00ffffff, i=key.i>>24;
  10085. char *name=str_buf+str_data[num].str;
  10086. if( name[1]!='@' ){
  10087. if(i==0)
  10088. fprintf(fp,"%s\t%d\n", name, (int)data);
  10089. else
  10090. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  10091. }
  10092. return 0;
  10093. #else
  10094. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  10095. char *name=str_buf+str_data[num].str;
  10096. if ( name[1] != '@') {
  10097. 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);
  10098. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10099. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10100. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10101. }
  10102. }
  10103. return 0;
  10104. #endif
  10105. }
  10106. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  10107. {
  10108. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10109. FILE *fp=va_arg(ap,FILE*);
  10110. int num=key.i&0x00ffffff, i=key.i>>24;
  10111. char *name=str_buf+str_data[num].str;
  10112. if( name[1]!='@' ){
  10113. if(i==0)
  10114. fprintf(fp,"%s\t%s\n", name, (char *)data);
  10115. else
  10116. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  10117. }
  10118. return 0;
  10119. #else
  10120. char tmp_str2[512];
  10121. int num=key.i&0x00ffffff, i=key.i>>24;
  10122. char *name=str_buf+str_data[num].str;
  10123. if ( name[1] != '@') {
  10124. 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);
  10125. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  10126. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10127. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10128. }
  10129. }
  10130. return 0;
  10131. #endif
  10132. }
  10133. static int script_save_mapreg(void)
  10134. {
  10135. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  10136. FILE *fp;
  10137. int lock;
  10138. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  10139. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  10140. return -1;
  10141. }
  10142. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  10143. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  10144. lock_fclose(fp,mapreg_txt,&lock);
  10145. #else
  10146. int perfomance = gettick_nocache();
  10147. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  10148. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  10149. perfomance = (gettick_nocache() - perfomance) / 1000;
  10150. ShowInfo("Mapreg saved in %d seconds.\n", perfomance);
  10151. #endif
  10152. mapreg_dirty=0;
  10153. return 0;
  10154. }
  10155. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  10156. {
  10157. if(mapreg_dirty)
  10158. if (script_save_mapreg() == -1)
  10159. ShowError("Failed to save the mapreg data!\n");
  10160. return 0;
  10161. }
  10162. /*==========================================
  10163. *
  10164. *------------------------------------------
  10165. */
  10166. static int set_posword(char *p)
  10167. {
  10168. char* np,* str[15];
  10169. int i=0;
  10170. for(i=0;i<11;i++) {
  10171. if((np=strchr(p,','))!=NULL) {
  10172. str[i]=p;
  10173. *np=0;
  10174. p=np+1;
  10175. } else {
  10176. str[i]=p;
  10177. p+=strlen(p);
  10178. }
  10179. if(str[i])
  10180. strcpy(pos[i],str[i]);
  10181. }
  10182. return 0;
  10183. }
  10184. int script_config_read_sub(char *cfgName)
  10185. {
  10186. int i;
  10187. char line[1024],w1[1024],w2[1024];
  10188. FILE *fp;
  10189. fp = fopen(cfgName, "r");
  10190. if (fp == NULL) {
  10191. ShowError("file not found: [%s]\n", cfgName);
  10192. return 1;
  10193. }
  10194. while (fgets(line, sizeof(line) - 1, fp)) {
  10195. if (line[0] == '/' && line[1] == '/')
  10196. continue;
  10197. i = sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  10198. if (i != 2)
  10199. continue;
  10200. if(strcmpi(w1,"refine_posword")==0) {
  10201. set_posword(w2);
  10202. }
  10203. else if(strcmpi(w1,"verbose_mode")==0) {
  10204. script_config.verbose_mode = battle_config_switch(w2);
  10205. }
  10206. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  10207. script_config.warn_func_no_comma = battle_config_switch(w2);
  10208. }
  10209. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  10210. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  10211. }
  10212. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  10213. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  10214. }
  10215. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  10216. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  10217. }
  10218. else if(strcmpi(w1,"check_cmdcount")==0) {
  10219. script_config.check_cmdcount = battle_config_switch(w2);
  10220. }
  10221. else if(strcmpi(w1,"check_gotocount")==0) {
  10222. script_config.check_gotocount = battle_config_switch(w2);
  10223. }
  10224. else if(strcmpi(w1,"event_script_type")==0) {
  10225. script_config.event_script_type = battle_config_switch(w2);
  10226. }
  10227. else if(strcmpi(w1,"event_requires_trigger")==0) {
  10228. script_config.event_requires_trigger = battle_config_switch(w2);
  10229. }
  10230. else if(strcmpi(w1,"die_event_name")==0) {
  10231. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  10232. if (strlen(script_config.die_event_name) != strlen(w2))
  10233. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  10234. }
  10235. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  10236. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  10237. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  10238. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  10239. }
  10240. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  10241. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  10242. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  10243. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  10244. }
  10245. else if(strcmpi(w1,"login_event_name")==0) {
  10246. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  10247. if (strlen(script_config.login_event_name) != strlen(w2))
  10248. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  10249. }
  10250. else if(strcmpi(w1,"logout_event_name")==0) {
  10251. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  10252. if (strlen(script_config.logout_event_name) != strlen(w2))
  10253. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  10254. }
  10255. else if(strcmpi(w1,"loadmap_event_name")==0) {
  10256. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  10257. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  10258. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  10259. }
  10260. else if(strcmpi(w1,"baselvup_event_name")==0) {
  10261. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  10262. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  10263. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  10264. }
  10265. else if(strcmpi(w1,"joblvup_event_name")==0) {
  10266. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  10267. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  10268. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  10269. }
  10270. else if(strcmpi(w1,"import")==0){
  10271. script_config_read_sub(w2);
  10272. }
  10273. }
  10274. fclose(fp);
  10275. return 0;
  10276. }
  10277. int script_config_read(char *cfgName)
  10278. { //Script related variables should be initialized once! [Skotlex]
  10279. memset (&script_config, 0, sizeof(script_config));
  10280. script_config.verbose_mode = 0;
  10281. script_config.warn_func_no_comma = 1;
  10282. script_config.warn_cmd_no_comma = 1;
  10283. script_config.warn_func_mismatch_paramnum = 1;
  10284. script_config.warn_cmd_mismatch_paramnum = 1;
  10285. script_config.check_cmdcount = 65535;
  10286. script_config.check_gotocount = 2048;
  10287. script_config.event_script_type = 0;
  10288. script_config.event_requires_trigger = 1;
  10289. return script_config_read_sub(cfgName);
  10290. }
  10291. /*==========================================
  10292. * 終了
  10293. *------------------------------------------
  10294. */
  10295. int do_final_script()
  10296. {
  10297. if(mapreg_dirty>=0)
  10298. script_save_mapreg();
  10299. mapreg_db->destroy(mapreg_db,NULL);
  10300. mapregstr_db->destroy(mapregstr_db,NULL);
  10301. scriptlabel_db->destroy(scriptlabel_db,NULL);
  10302. userfunc_db->destroy(userfunc_db,NULL);
  10303. if (str_data)
  10304. aFree(str_data);
  10305. if (str_buf)
  10306. aFree(str_buf);
  10307. return 0;
  10308. }
  10309. /*==========================================
  10310. * 初期化
  10311. *------------------------------------------
  10312. */
  10313. int do_init_script()
  10314. {
  10315. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  10316. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  10317. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  10318. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_ALLOW_NULL_DATA,50);
  10319. script_load_mapreg();
  10320. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  10321. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  10322. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  10323. return 0;
  10324. }
  10325. int script_reload()
  10326. {
  10327. if(mapreg_dirty>=0)
  10328. script_save_mapreg();
  10329. mapreg_db->clear(mapreg_db, NULL);
  10330. mapregstr_db->clear(mapreg_db, NULL);
  10331. userfunc_db->clear(mapreg_db, NULL);
  10332. scriptlabel_db->clear(mapreg_db, NULL);
  10333. script_load_mapreg();
  10334. return 0;
  10335. }