script.c 342 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647
  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 <setjmp.h>
  16. #include "../common/cbasetypes.h"
  17. #include "../common/socket.h"
  18. #include "../common/timer.h"
  19. #include "../common/malloc.h"
  20. #include "../common/lock.h"
  21. #include "../common/nullpo.h"
  22. #include "../common/showmsg.h"
  23. #include "../common/strlib.h"
  24. #include "../common/utils.h"
  25. #include "map.h"
  26. #include "clif.h"
  27. #include "chrif.h"
  28. #include "itemdb.h"
  29. #include "pc.h"
  30. #include "status.h"
  31. #include "script.h"
  32. #include "storage.h"
  33. #include "mob.h"
  34. #include "npc.h"
  35. #include "pet.h"
  36. #include "mercenary.h" //[orn]
  37. #include "intif.h"
  38. #include "skill.h"
  39. #include "chat.h"
  40. #include "battle.h"
  41. #include "party.h"
  42. #include "guild.h"
  43. #include "atcommand.h"
  44. #include "charcommand.h"
  45. #include "log.h"
  46. #include "unit.h"
  47. #include "irc.h"
  48. #include "pet.h"
  49. #define FETCH(n, t) \
  50. if(st->end>st->start+(n)) \
  51. (t)=conv_num(st,&(st->stack->stack_data[st->start+(n)]));
  52. #define SCRIPT_BLOCK_SIZE 512
  53. enum { LABEL_NEXTLINE=1,LABEL_START };
  54. static unsigned char * script_buf = NULL;
  55. static int script_pos,script_size;
  56. #define GETVALUE(buf,i) ((int)MakeDWord(MakeWord((buf)[i],(buf)[i+1]),MakeWord((buf)[i+2],0)))
  57. #define SETVALUE(buf,i,n) ((buf)[i]=GetByte(n,0),(buf)[i+1]=GetByte(n,1),(buf)[i+2]=GetByte(n,2))
  58. #define GETSTRING(off) (str_buf+(off))
  59. static char *str_buf;
  60. static int str_pos,str_size;
  61. static struct str_data_struct {
  62. int type;
  63. int str;
  64. int backpatch;
  65. int label;
  66. int (*func)(struct script_state *st);
  67. int val;
  68. int next;
  69. } *str_data = NULL;
  70. int str_num=LABEL_START,str_data_size;
  71. int str_hash[16];
  72. static struct dbt *mapreg_db=NULL;
  73. static struct dbt *mapregstr_db=NULL;
  74. static int mapreg_dirty=-1;
  75. char mapreg_txt[256]="save/mapreg.txt";
  76. #define MAPREG_AUTOSAVE_INTERVAL (300*1000)
  77. static struct dbt *scriptlabel_db=NULL;
  78. static struct dbt *userfunc_db=NULL;
  79. static int parse_options=0;
  80. struct dbt* script_get_label_db(){ return scriptlabel_db; }
  81. struct dbt* script_get_userfunc_db(){ return userfunc_db; }
  82. static char pos[11][100] = {"Head","Body","Left hand","Right hand","Robe","Shoes","Accessory 1","Accessory 2","Head 2","Head 3","Not Equipped"};
  83. struct Script_Config script_config;
  84. static int parse_cmd;
  85. static jmp_buf error_jump;
  86. static char* error_msg;
  87. static const char* error_pos;
  88. // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
  89. // [Eoe / jA 1080, 1081, 1094, 1164]
  90. enum curly_type { TYPE_NULL = 0 , TYPE_IF , TYPE_SWITCH , TYPE_WHILE , TYPE_FOR , TYPE_DO , TYPE_USERFUNC};
  91. static struct {
  92. struct {
  93. int type;
  94. int index;
  95. int count;
  96. int flag;
  97. } curly[256]; // 右カッコの情報
  98. int curly_count; // 右カッコの数
  99. int index; // スクリプト内で使用した構文の数
  100. } syntax;
  101. const char* parse_curly_close(const char* p);
  102. const char* parse_syntax_close(const char* p);
  103. const char* parse_syntax_close_sub(const char* p,int* flag);
  104. const char* parse_syntax(const char* p);
  105. static int parse_syntax_for_flag = 0;
  106. extern int current_equip_item_index; //for New CARS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
  107. int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
  108. int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
  109. int potion_target=0;
  110. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  111. // [zBuffer] SQL Mapreg Saving/Loading Database Declaration
  112. char mapregsql_db[32] = "mapreg";
  113. char mapregsql_db_varname[32] = "varname";
  114. char mapregsql_db_index[32] = "index";
  115. char mapregsql_db_value[32] = "value";
  116. char tmp_sql[65535];
  117. // --------------------------------------------------------
  118. #endif
  119. int get_com(unsigned char *script,int *pos);
  120. int get_num(unsigned char *script,int *pos);
  121. extern struct script_function {
  122. int (*func)(struct script_state *st);
  123. char *name;
  124. char *arg;
  125. } buildin_func[];
  126. static struct linkdb_node *sleep_db;
  127. #define not_server_variable(prefix) (prefix != '$' && prefix != '.')
  128. /*==========================================
  129. * ローカルプロトタイプ宣言 (必要な物のみ)
  130. *------------------------------------------
  131. */
  132. const char* parse_subexpr(const char* p,int limit);
  133. void push_val(struct script_stack *stack,int type,int val);
  134. int run_func(struct script_state *st);
  135. int mapreg_setreg(int num,int val);
  136. int mapreg_setregstr(int num,const char *str);
  137. static void disp_error_message(const char *mes,const char *pos);
  138. enum c_op {
  139. C_NOP,C_POS,C_INT,C_PARAM,C_FUNC,C_STR,C_CONSTSTR,C_ARG,
  140. C_NAME,C_EOL, C_RETINFO,
  141. C_USERFUNC, C_USERFUNC_POS, // user defined functions
  142. C_OP3,C_LOR,C_LAND,C_LE,C_LT,C_GE,C_GT,C_EQ,C_NE, //operator
  143. 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
  144. };
  145. enum {
  146. MF_NOMEMO, //0
  147. MF_NOTELEPORT,
  148. MF_NOSAVE,
  149. MF_NOBRANCH,
  150. MF_NOPENALTY,
  151. MF_NOZENYPENALTY,
  152. MF_PVP,
  153. MF_PVP_NOPARTY,
  154. MF_PVP_NOGUILD,
  155. MF_GVG,
  156. MF_GVG_NOPARTY, //10
  157. MF_NOTRADE,
  158. MF_NOSKILL,
  159. MF_NOWARP,
  160. MF_PARTYLOCK,
  161. MF_NOICEWALL,
  162. MF_SNOW,
  163. MF_FOG,
  164. MF_SAKURA,
  165. MF_LEAVES,
  166. MF_RAIN, //20
  167. MF_INDOORS,
  168. MF_NOGO,
  169. MF_CLOUDS,
  170. MF_CLOUDS2,
  171. MF_FIREWORKS,
  172. MF_GVG_CASTLE,
  173. MF_GVG_DUNGEON,
  174. MF_NIGHTENABLED,
  175. MF_NOBASEEXP,
  176. MF_NOJOBEXP, //30
  177. MF_NOMOBLOOT,
  178. MF_NOMVPLOOT,
  179. MF_NORETURN,
  180. MF_NOWARPTO,
  181. MF_NIGHTMAREDROP,
  182. MF_RESTRICTED,
  183. MF_NOCOMMAND,
  184. MF_NODROP,
  185. MF_JEXP,
  186. MF_BEXP, //40
  187. MF_NOVENDING,
  188. MF_LOADEVENT,
  189. MF_NOCHAT,
  190. MF_NOEXPPENALTY,
  191. MF_GUILDLOCK
  192. };
  193. //Reports on the console the src of an script error.
  194. static void report_src(struct script_state *st) {
  195. struct block_list *bl;
  196. if (!st->oid) return; //Can't report source.
  197. bl = map_id2bl(st->oid);
  198. if (!bl) return;
  199. switch (bl->type) {
  200. case BL_NPC:
  201. if (bl->m >=0)
  202. ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
  203. else
  204. ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
  205. break;
  206. default:
  207. if (bl->m >=0)
  208. ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map[bl->m].name, bl->x, bl->y);
  209. else
  210. ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl));
  211. break;
  212. }
  213. }
  214. static void check_event(struct script_state *st, const char *event){
  215. if(event != NULL && event[0] != '\0' && !stristr(event,"::On")){
  216. ShowError("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n",event);
  217. report_src(st);
  218. }
  219. return;
  220. }
  221. /*==========================================
  222. * 文字列のハッシュを計算
  223. *------------------------------------------
  224. */
  225. static int calc_hash(const unsigned char *p)
  226. {
  227. int h=0;
  228. while(*p){
  229. h=(h<<1)+(h>>3)+(h>>5)+(h>>8);
  230. h+=*p++;
  231. }
  232. return h&15;
  233. }
  234. /*==========================================
  235. * str_dataの中に名前があるか検索する
  236. *------------------------------------------
  237. */
  238. // 既存のであれば番号、無ければ-1
  239. static int search_str(const char *p)
  240. {
  241. int i;
  242. i=str_hash[calc_hash(p)];
  243. while(i){
  244. if(strcmp(str_buf+str_data[i].str,p)==0){
  245. return i;
  246. }
  247. i=str_data[i].next;
  248. }
  249. return -1;
  250. }
  251. /*==========================================
  252. * str_dataに名前を登録
  253. *------------------------------------------
  254. */
  255. // 既存のであれば番号、無ければ登録して新規番号
  256. int add_str(const char* p)
  257. {
  258. int i;
  259. int len;
  260. char* lowcase;
  261. lowcase=aStrdup(p);
  262. for(i=0;lowcase[i];i++)
  263. lowcase[i]=TOLOWER(lowcase[i]);
  264. if((i=search_str(lowcase))>=0){
  265. aFree(lowcase);
  266. return i;
  267. }
  268. aFree(lowcase);
  269. i=calc_hash(p);
  270. if(str_hash[i]==0){
  271. str_hash[i]=str_num;
  272. } else {
  273. i=str_hash[i];
  274. for(;;){
  275. if(strcmp(str_buf+str_data[i].str,p)==0){
  276. return i;
  277. }
  278. if(str_data[i].next==0)
  279. break;
  280. i=str_data[i].next;
  281. }
  282. str_data[i].next=str_num;
  283. }
  284. if(str_num>=str_data_size){
  285. str_data_size+=128;
  286. RECREATE(str_data,struct str_data_struct,str_data_size);
  287. malloc_tsetdword(str_data + (str_data_size - 128), '\0', 128);
  288. }
  289. len=(int)strlen(p);
  290. while(str_pos+len+1>=str_size){
  291. str_size+=256;
  292. RECREATE(str_buf,char,str_size);
  293. malloc_tsetdword(str_buf + (str_size - 256), '\0', 256);
  294. }
  295. memcpy(str_buf+str_pos,p,len+1);
  296. str_data[str_num].type=C_NOP;
  297. str_data[str_num].str=str_pos;
  298. str_data[str_num].next=0;
  299. str_data[str_num].func=NULL;
  300. str_data[str_num].backpatch=-1;
  301. str_data[str_num].label=-1;
  302. str_pos+=len+1;
  303. return str_num++;
  304. }
  305. /*==========================================
  306. * スクリプトバッファサイズの確認と拡張
  307. *------------------------------------------
  308. */
  309. static void check_script_buf(int size)
  310. {
  311. if(script_pos+size>=script_size){
  312. script_size+=SCRIPT_BLOCK_SIZE;
  313. RECREATE(script_buf,unsigned char,script_size);
  314. malloc_tsetdword(script_buf + script_size - SCRIPT_BLOCK_SIZE, '\0',
  315. SCRIPT_BLOCK_SIZE);
  316. }
  317. }
  318. /*==========================================
  319. * スクリプトバッファに1バイト書き込む
  320. *------------------------------------------
  321. */
  322. #define add_scriptb(a) if( script_pos+1>=script_size ) check_script_buf(1); script_buf[script_pos++]=(uint8)(a)
  323. #if 0
  324. static void add_scriptb(int a)
  325. {
  326. check_script_buf(1);
  327. script_buf[script_pos++]=a;
  328. }
  329. #endif
  330. /*==========================================
  331. * スクリプトバッファにデータタイプを書き込む
  332. *------------------------------------------
  333. */
  334. static void add_scriptc(int a)
  335. {
  336. while(a>=0x40){
  337. add_scriptb((a&0x3f)|0x40);
  338. a=(a-0x40)>>6;
  339. }
  340. add_scriptb(a&0x3f);
  341. }
  342. /*==========================================
  343. * スクリプトバッファに整数を書き込む
  344. *------------------------------------------
  345. */
  346. static void add_scripti(int a)
  347. {
  348. while(a>=0x40){
  349. add_scriptb(a|0xc0);
  350. a=(a-0x40)>>6;
  351. }
  352. add_scriptb(a|0x80);
  353. }
  354. /*==========================================
  355. * スクリプトバッファにラベル/変数/関数を書き込む
  356. *------------------------------------------
  357. */
  358. // 最大16Mまで
  359. static void add_scriptl(int l)
  360. {
  361. int backpatch = str_data[l].backpatch;
  362. switch(str_data[l].type){
  363. case C_POS:
  364. case C_USERFUNC_POS:
  365. add_scriptc(C_POS);
  366. add_scriptb(str_data[l].label);
  367. add_scriptb(str_data[l].label>>8);
  368. add_scriptb(str_data[l].label>>16);
  369. break;
  370. case C_NOP:
  371. case C_USERFUNC:
  372. // ラベルの可能性があるのでbackpatch用データ埋め込み
  373. add_scriptc(C_NAME);
  374. str_data[l].backpatch=script_pos;
  375. add_scriptb(backpatch);
  376. add_scriptb(backpatch>>8);
  377. add_scriptb(backpatch>>16);
  378. break;
  379. case C_INT:
  380. add_scripti(abs(str_data[l].val));
  381. if(str_data[l].val < 0) //Notice that this is negative, from jA (Rayce)
  382. add_scriptc(C_NEG);
  383. break;
  384. default:
  385. // もう他の用途と確定してるので数字をそのまま
  386. add_scriptc(C_NAME);
  387. add_scriptb(l);
  388. add_scriptb(l>>8);
  389. add_scriptb(l>>16);
  390. break;
  391. }
  392. }
  393. /*==========================================
  394. * ラベルを解決する
  395. *------------------------------------------
  396. */
  397. void set_label(int l,int pos, const char* script_pos)
  398. {
  399. int i,next;
  400. if(str_data[l].type==C_INT || str_data[l].type==C_PARAM)
  401. { //Prevent overwriting constants values and parameters [Skotlex]
  402. disp_error_message("set_label: invalid label name",script_pos);
  403. return;
  404. }
  405. if(str_data[l].label!=-1){
  406. disp_error_message("set_label: dup label ",script_pos);
  407. return;
  408. }
  409. str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  410. str_data[l].label=pos;
  411. for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
  412. next=GETVALUE(script_buf,i);
  413. script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
  414. SETVALUE(script_buf,i,pos);
  415. i=next;
  416. }
  417. }
  418. /*==========================================
  419. * スペース/コメント読み飛ばし
  420. *------------------------------------------
  421. */
  422. static const char *skip_space(const char *p)
  423. {
  424. for(;;){
  425. while(ISSPACE(*p))
  426. ++p;
  427. if( *p=='/' && p[1]=='/' ){
  428. while(*p && *p!='\n')
  429. ++p;
  430. } else if( *p=='/' && p[1]=='*' ){
  431. p+=2;
  432. if(*p) ++p;
  433. while( *p && (p[-1]!='*' || *p!='/') )
  434. p++;
  435. if(*p)
  436. ++p;
  437. else
  438. disp_error_message("skip_space: unexpected eof @ block comment",p);
  439. } else
  440. break;
  441. }
  442. return p;
  443. }
  444. /*==========================================
  445. * 1単語スキップ
  446. *------------------------------------------
  447. */
  448. static const char *skip_word(const char *p)
  449. {
  450. // prefix
  451. if(*p=='.') p++;
  452. if(*p=='$') p++; // MAP鯖内共有変数用
  453. if(*p=='@') p++; // 一時的変数用(like weiss)
  454. if(*p=='#') p++; // account変数用
  455. if(*p=='#') p++; // ワールドaccount変数用
  456. //# Changing from unsigned char to signed char makes p never be able to go above 0x81, but what IS 0x81 for? [Skotlex]
  457. //# It's for multibyte encodings like Shift-JIS. Unfortunately this can be problematic for singlebyte encodings.
  458. // Using (*p)>>7 would yield the appropriate result but it's better to restrict words to ASCII characters only. [FlavioJS]
  459. while( ISALNUM(*p) || *p == '_' )
  460. ++p;
  461. // postfix
  462. if(*p=='$') p++; // 文字列変数
  463. return p;
  464. }
  465. /// Adds a word to str_data
  466. int add_word(const char *p)
  467. {
  468. char *word;
  469. int len;
  470. int i;
  471. // Check for a word
  472. len = skip_word(p)-p;
  473. if( len == 0 )
  474. disp_error_message("add_word: not a word",p);
  475. // Copy the word
  476. CREATE(word,char,len+1);
  477. memcpy(word,p,len);
  478. word[len]=0;
  479. // add the word
  480. i=add_str(word);
  481. aFree(word);
  482. return i;
  483. }
  484. /*==========================================
  485. * エラーメッセージ出力
  486. *------------------------------------------
  487. */
  488. static void disp_error_message(const char *mes,const char *pos)
  489. {
  490. error_msg = aStrdup(mes);
  491. error_pos = pos;
  492. longjmp( error_jump, 1 );
  493. }
  494. /*==========================================
  495. * 項の解析
  496. *------------------------------------------
  497. */
  498. const char* parse_simpleexpr(const char *p)
  499. {
  500. int i;
  501. p=skip_space(p);
  502. #ifdef DEBUG_FUNCIN
  503. if(battle_config.etc_log)
  504. ShowDebug("parse_simpleexpr %s\n",p);
  505. #endif
  506. if(*p==';' || *p==',')
  507. disp_error_message("parse_simpleexpr: unexpected expr end",p);
  508. if(*p=='('){
  509. p=parse_subexpr(p+1,-1);
  510. p=skip_space(p);
  511. if((*p++)!=')')
  512. disp_error_message("parse_simpleexpr: unmatch ')'",p-1);
  513. } else if(isdigit(*p) || ((*p=='-' || *p=='+') && isdigit(p[1]))){
  514. char *np;
  515. i=strtoul(p,&np,0);
  516. add_scripti(i);
  517. p=np;
  518. } else if(*p=='"'){
  519. add_scriptc(C_STR);
  520. p++;
  521. while(*p && *p!='"'){
  522. if(p[-1]<=0x7e && *p=='\\')
  523. p++;
  524. else if(*p=='\n')
  525. disp_error_message("parse_simpleexpr: unexpected newline @ string",p);
  526. add_scriptb(*p++);
  527. }
  528. if(!*p)
  529. disp_error_message("parse_simpleexpr: unexpected eof @ string",p);
  530. add_scriptb(0);
  531. p++; //'"'
  532. } else {
  533. int l;
  534. // label , register , function etc
  535. if(skip_word(p)==p)
  536. disp_error_message("parse_simpleexpr: unexpected character",p);
  537. l=add_word(p);
  538. parse_cmd=l; // warn_*_mismatch_paramnumのために必要
  539. p=skip_word(p);
  540. if(str_data[l].type!=C_FUNC && *p=='['){
  541. // array(name[i] => getelementofarray(name,i) )
  542. add_scriptl(search_str("getelementofarray"));
  543. add_scriptc(C_ARG);
  544. add_scriptl(l);
  545. p=parse_subexpr(p+1,-1);
  546. p=skip_space(p);
  547. if((*p++)!=']')
  548. disp_error_message("parse_simpleexpr: unmatch ']'",p-1);
  549. add_scriptc(C_FUNC);
  550. } else if(str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS) {
  551. add_scriptl(search_str("callsub"));
  552. add_scriptc(C_ARG);
  553. add_scriptl(l);
  554. }else
  555. add_scriptl(l);
  556. }
  557. #ifdef DEBUG_FUNCIN
  558. if(battle_config.etc_log)
  559. ShowDebug("parse_simpleexpr end %s\n",p);
  560. #endif
  561. return p;
  562. }
  563. /*==========================================
  564. * 式の解析
  565. *------------------------------------------
  566. */
  567. const char* parse_subexpr(const char* p,int limit)
  568. {
  569. int op,opl,len;
  570. const char* tmpp;
  571. #ifdef DEBUG_FUNCIN
  572. if(battle_config.etc_log)
  573. ShowDebug("parse_subexpr %s\n",p);
  574. #endif
  575. p=skip_space(p);
  576. if(*p=='-'){
  577. tmpp=skip_space(p+1);
  578. if(*tmpp==';' || *tmpp==','){
  579. add_scriptl(LABEL_NEXTLINE);
  580. p++;
  581. return p;
  582. }
  583. }
  584. tmpp=p;
  585. if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
  586. p=parse_subexpr(p+1,10);
  587. add_scriptc(op);
  588. } else
  589. p=parse_simpleexpr(p);
  590. p=skip_space(p);
  591. while((
  592. (op=C_OP3,opl=0,len=1,*p=='?') ||
  593. (op=C_ADD,opl=8,len=1,*p=='+') ||
  594. (op=C_SUB,opl=8,len=1,*p=='-') ||
  595. (op=C_MUL,opl=9,len=1,*p=='*') ||
  596. (op=C_DIV,opl=9,len=1,*p=='/') ||
  597. (op=C_MOD,opl=9,len=1,*p=='%') ||
  598. (op=C_FUNC,opl=11,len=1,*p=='(') ||
  599. (op=C_LAND,opl=2,len=2,*p=='&' && p[1]=='&') ||
  600. (op=C_AND,opl=6,len=1,*p=='&') ||
  601. (op=C_LOR,opl=1,len=2,*p=='|' && p[1]=='|') ||
  602. (op=C_OR,opl=5,len=1,*p=='|') ||
  603. (op=C_XOR,opl=4,len=1,*p=='^') ||
  604. (op=C_EQ,opl=3,len=2,*p=='=' && p[1]=='=') ||
  605. (op=C_NE,opl=3,len=2,*p=='!' && p[1]=='=') ||
  606. (op=C_R_SHIFT,opl=7,len=2,*p=='>' && p[1]=='>') ||
  607. (op=C_GE,opl=3,len=2,*p=='>' && p[1]=='=') ||
  608. (op=C_GT,opl=3,len=1,*p=='>') ||
  609. (op=C_L_SHIFT,opl=7,len=2,*p=='<' && p[1]=='<') ||
  610. (op=C_LE,opl=3,len=2,*p=='<' && p[1]=='=') ||
  611. (op=C_LT,opl=3,len=1,*p=='<')) && opl>limit){
  612. p+=len;
  613. if(op==C_FUNC){
  614. int i=0;
  615. int j=0;
  616. int func=parse_cmd;
  617. const char *plist[128];
  618. const char *arg = NULL;
  619. if(str_data[parse_cmd].type == C_FUNC){
  620. // 通常の関数
  621. add_scriptc(C_ARG);
  622. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  623. // ユーザー定義関数呼び出し
  624. parse_cmd = search_str("callsub");
  625. i++;
  626. } else
  627. disp_error_message("parse_subexpr: expect command, missing function name or calling undeclared function",tmpp);
  628. func=parse_cmd;
  629. p=skip_space(p);
  630. // check number of arguments of the function
  631. if( str_data[func].type == C_FUNC && script_config.warn_cmd_mismatch_paramnum) {
  632. arg = buildin_func[str_data[func].val].arg;
  633. for(j=0; arg[j]; j++) {
  634. if(arg[j] == '*')
  635. break;
  636. }
  637. }
  638. while(*p && *p!=')' && i<128) {
  639. plist[i]=p;
  640. p=parse_subexpr(p,-1);
  641. p=skip_space(p);
  642. if(*p==',') {
  643. if(arg == NULL || arg[j] == '*' || i+1 < j)
  644. p++; // the next argument is valid, skip the comma
  645. }
  646. else if(*p!=')' && script_config.warn_func_no_comma){
  647. disp_error_message("parse_subexpr: expect ',' or ')' at func params",p);
  648. }
  649. p=skip_space(p);
  650. i++;
  651. }
  652. plist[i]=p;
  653. if(*(p++)!=')')
  654. disp_error_message("parse_subexpr: func request '(' ')'",p-1);
  655. if(arg) {
  656. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) )
  657. disp_error_message("parse_subexpr: illegal number of parameters",plist[min(i,j)]);
  658. }
  659. } else if(op == C_OP3) {
  660. p=parse_subexpr(p,-1);
  661. p=skip_space(p);
  662. if( *(p++) != ':')
  663. disp_error_message("parse_subexpr: need ':'", p-1);
  664. p=parse_subexpr(p,-1);
  665. } else {
  666. p=parse_subexpr(p,opl);
  667. }
  668. add_scriptc(op);
  669. p=skip_space(p);
  670. }
  671. #ifdef DEBUG_FUNCIN
  672. if(battle_config.etc_log)
  673. ShowDebug("parse_subexpr end %s\n",p);
  674. #endif
  675. return p; /* return first untreated operator */
  676. }
  677. /*==========================================
  678. * 式の評価
  679. *------------------------------------------
  680. */
  681. const char* parse_expr(const char *p)
  682. {
  683. #ifdef DEBUG_FUNCIN
  684. if(battle_config.etc_log)
  685. ShowDebug("parse_expr %s\n",p);
  686. #endif
  687. switch(*p){
  688. case ')': case ';': case ':': case '[': case ']':
  689. case '}':
  690. disp_error_message("parse_expr: unexpected char",p);
  691. exit(1);
  692. }
  693. p=parse_subexpr(p,-1);
  694. #ifdef DEBUG_FUNCIN
  695. if(battle_config.etc_log)
  696. ShowDebug("parse_expr end %s\n",p);
  697. #endif
  698. return p;
  699. }
  700. /*==========================================
  701. * 行の解析
  702. *------------------------------------------
  703. */
  704. const char* parse_line(const char* p)
  705. {
  706. int i=0;
  707. int j=0;
  708. int cmd;
  709. const char* plist[128];
  710. const char* p2;
  711. const char *arg=NULL;
  712. char end;
  713. char end2=0;
  714. int old_flag=0;
  715. p=skip_space(p);
  716. if(*p==';') {
  717. // if(); for(); while(); のために閉じ判定
  718. p = parse_syntax_close(p);
  719. return p+1;
  720. }
  721. if(*p==')' && parse_syntax_for_flag)
  722. return p+1;
  723. p = skip_space(p);
  724. if(p[0] == '{') {
  725. syntax.curly[syntax.curly_count].type = TYPE_NULL;
  726. syntax.curly[syntax.curly_count].count = -1;
  727. syntax.curly[syntax.curly_count].index = -1;
  728. syntax.curly_count++;
  729. return p + 1;
  730. } else if(p[0] == '}') {
  731. return parse_curly_close(p);
  732. }
  733. // 構文関連の処理
  734. p2 = parse_syntax(p);
  735. if(p2 != NULL)
  736. return p2;
  737. // 最初は関数名
  738. p2=p;
  739. p=parse_simpleexpr(p);
  740. p=skip_space(p);
  741. if(str_data[parse_cmd].type == C_FUNC){
  742. // 通常の関数
  743. add_scriptc(C_ARG);
  744. } else if(str_data[parse_cmd].type == C_USERFUNC || str_data[parse_cmd].type == C_USERFUNC_POS) {
  745. // ユーザー定義関数呼び出し
  746. parse_cmd = search_str("callsub");
  747. i++;
  748. } else
  749. disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p2);
  750. cmd=parse_cmd;
  751. if(parse_syntax_for_flag) {
  752. end = ')';
  753. } else {
  754. end = ';';
  755. }
  756. // Check number of arguments of the function
  757. if( str_data[cmd].type == C_FUNC && script_config.warn_cmd_mismatch_paramnum) {
  758. arg = buildin_func[str_data[cmd].val].arg;
  759. for(j=0; arg[j]; j++) {
  760. if(arg[j] == '*')
  761. break;
  762. }
  763. }
  764. // Check for parenthesis argument list
  765. if( *p == '(' ){
  766. ++p;
  767. end2 = end;
  768. end = ')';
  769. old_flag = parse_syntax_for_flag;
  770. parse_syntax_for_flag = 1;
  771. }
  772. while(p && *p && *p != end && i<128){
  773. plist[i]=p;
  774. p=parse_expr(p);
  775. p=skip_space(p);
  776. // 引数区切りの,処理
  777. if( *p==',' ) {
  778. if( arg == NULL || arg[j] == '*' || i+1 < j )
  779. p++; // the next argument is valid, skip the comma
  780. }
  781. else if( end2 && i == 0 && *p == ')' && *skip_space(p+1) == ',' )
  782. {// parenthesis argument list fallback for "func (exp) , ..."
  783. end = end2;
  784. parse_syntax_for_flag = old_flag;
  785. end2 = 0;
  786. p=skip_space(p+1);
  787. if( arg == NULL || arg[j] == '*' || i+1 < j )
  788. p++; // the next argument is valid, skip the comma
  789. }
  790. else if(*p!=end && script_config.warn_cmd_no_comma){
  791. if(parse_syntax_for_flag) {
  792. disp_error_message("parse_line: expect ',' or ')' at cmd params",p);
  793. } else {
  794. disp_error_message("parse_line: expect ',' or ';' at cmd params",p);
  795. }
  796. }
  797. p=skip_space(p);
  798. i++;
  799. }
  800. plist[i]=p;
  801. if( end2 ){ // restore previous ending and recheck
  802. if( *p != ')' )
  803. disp_error_message("parse_line: need ')' to end param list",p);
  804. p=skip_space(p+1);
  805. end = end2;
  806. parse_syntax_for_flag = old_flag;
  807. }
  808. if(!p || *p!=end){
  809. if(parse_syntax_for_flag) {
  810. disp_error_message("parse_line: need ')'",p);
  811. } else {
  812. disp_error_message("parse_line: need ';'",p);
  813. }
  814. }
  815. add_scriptc(C_FUNC);
  816. // if, for , while の閉じ判定
  817. p = parse_syntax_close(p+1);
  818. if(arg) {
  819. if( (arg[j]==0 && i!=j) || (arg[j]=='*' && i<j) )
  820. disp_error_message("parse_line: illegal number of parameters",plist[min(i,j)]);
  821. }
  822. return p;
  823. }
  824. // { ... } の閉じ処理
  825. const char* parse_curly_close(const char* p) {
  826. if(syntax.curly_count <= 0) {
  827. disp_error_message("parse_curly_close: unexpected string",p);
  828. return p + 1;
  829. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
  830. syntax.curly_count--;
  831. // if, for , while の閉じ判定
  832. p = parse_syntax_close(p + 1);
  833. return p;
  834. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
  835. // switch() 閉じ判定
  836. int pos = syntax.curly_count-1;
  837. char label[256];
  838. int l;
  839. // 一時変数を消す
  840. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  841. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  842. parse_line(label);
  843. syntax.curly_count--;
  844. // 無条件で終了ポインタに移動
  845. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  846. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  847. parse_line(label);
  848. syntax.curly_count--;
  849. // 現在地のラベルを付ける
  850. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  851. l=add_str(label);
  852. set_label(l,script_pos, p);
  853. if(syntax.curly[pos].flag) {
  854. // default が存在する
  855. sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
  856. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  857. parse_line(label);
  858. syntax.curly_count--;
  859. }
  860. // 終了ラベルを付ける
  861. sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
  862. l=add_str(label);
  863. set_label(l,script_pos, p);
  864. syntax.curly_count--;
  865. return p+1;
  866. } else {
  867. disp_error_message("parse_curly_close: unexpected string",p);
  868. return p + 1;
  869. }
  870. }
  871. // 構文関連の処理
  872. // break, case, continue, default, do, for, function,
  873. // if, switch, while をこの内部で処理します。
  874. const char* parse_syntax(const char* p) {
  875. switch(*p) {
  876. case 'b':
  877. if(!strncmp(p,"break",5) && !ISALPHA(p[5])) {
  878. // break の処理
  879. char label[256];
  880. int pos = syntax.curly_count - 1;
  881. while(pos >= 0) {
  882. if(syntax.curly[pos].type == TYPE_DO) {
  883. sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
  884. break;
  885. } else if(syntax.curly[pos].type == TYPE_FOR) {
  886. sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
  887. break;
  888. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  889. sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
  890. break;
  891. } else if(syntax.curly[pos].type == TYPE_SWITCH) {
  892. sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
  893. break;
  894. }
  895. pos--;
  896. }
  897. if(pos < 0) {
  898. disp_error_message("parse_syntax: unexpected 'break'",p);
  899. } else {
  900. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  901. parse_line(label);
  902. syntax.curly_count--;
  903. }
  904. p = skip_word(p);
  905. p++;
  906. // if, for , while の閉じ判定
  907. p = parse_syntax_close(p + 1);
  908. return p;
  909. }
  910. break;
  911. case 'c':
  912. if(!strncmp(p,"case",4) && !ISALPHA(p[4])) {
  913. // case の処理
  914. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  915. disp_error_message("parse_syntax: unexpected 'case' ",p);
  916. return p+1;
  917. } else {
  918. const char *p2;
  919. char label[256];
  920. int l;
  921. int len;
  922. int pos = syntax.curly_count-1;
  923. if(syntax.curly[pos].count != 1) {
  924. // FALLTHRU 用のジャンプ
  925. sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
  926. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  927. parse_line(label);
  928. syntax.curly_count--;
  929. // 現在地のラベルを付ける
  930. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  931. l=add_str(label);
  932. set_label(l,script_pos, p);
  933. }
  934. // switch 判定文
  935. p = skip_word(p);
  936. p = skip_space(p);
  937. p2 = p;
  938. p = skip_word(p);
  939. len = p-p2; // length of word at p2
  940. p = skip_space(p);
  941. if(*p != ':')
  942. disp_error_message("parse_syntax: expect ':'",p);
  943. memcpy(label,"if(",3);
  944. memcpy(label+3,p2,len);
  945. sprintf(label+3+len," != $@__SW%x_VAL) goto __SW%x_%x;",
  946. syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
  947. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  948. // 2回parse しないとダメ
  949. p2 = parse_line(label);
  950. parse_line(p2);
  951. syntax.curly_count--;
  952. if(syntax.curly[pos].count != 1) {
  953. // FALLTHRU 終了後のラベル
  954. sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
  955. l=add_str(label);
  956. set_label(l,script_pos,p);
  957. }
  958. // 一時変数を消す
  959. sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
  960. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  961. parse_line(label);
  962. syntax.curly_count--;
  963. syntax.curly[pos].count++;
  964. }
  965. return p + 1;
  966. } else if(!strncmp(p,"continue",8) && !ISALPHA(p[8])) {
  967. // continue の処理
  968. char label[256];
  969. int pos = syntax.curly_count - 1;
  970. while(pos >= 0) {
  971. if(syntax.curly[pos].type == TYPE_DO) {
  972. sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
  973. syntax.curly[pos].flag = 1; // continue 用のリンク張るフラグ
  974. break;
  975. } else if(syntax.curly[pos].type == TYPE_FOR) {
  976. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  977. break;
  978. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  979. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  980. break;
  981. }
  982. pos--;
  983. }
  984. if(pos < 0) {
  985. disp_error_message("parse_syntax: unexpected 'continue'",p);
  986. } else {
  987. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  988. parse_line(label);
  989. syntax.curly_count--;
  990. }
  991. p = skip_word(p);
  992. p++;
  993. // if, for , while の閉じ判定
  994. p = parse_syntax_close(p + 1);
  995. return p;
  996. }
  997. break;
  998. case 'd':
  999. if(!strncmp(p,"default",7) && !ISALPHA(p[7])) {
  1000. // switch - default の処理
  1001. if(syntax.curly_count <= 0 || syntax.curly[syntax.curly_count - 1].type != TYPE_SWITCH) {
  1002. disp_error_message("parse_syntax: unexpected 'default'",p);
  1003. return p+1;
  1004. } else if(syntax.curly[syntax.curly_count - 1].flag) {
  1005. disp_error_message("parse_syntax: dup 'default'",p);
  1006. return p+1;
  1007. } else {
  1008. char label[256];
  1009. int l;
  1010. int pos = syntax.curly_count-1;
  1011. // 現在地のラベルを付ける
  1012. p = skip_word(p);
  1013. p = skip_space(p);
  1014. if(*p != ':') {
  1015. disp_error_message("parse_syntax: need ':'",p);
  1016. }
  1017. p++;
  1018. sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1019. l=add_str(label);
  1020. set_label(l,script_pos,p);
  1021. // 無条件で次のリンクに飛ばす
  1022. sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
  1023. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1024. parse_line(label);
  1025. syntax.curly_count--;
  1026. // default のラベルを付ける
  1027. sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
  1028. l=add_str(label);
  1029. set_label(l,script_pos,p);
  1030. syntax.curly[syntax.curly_count - 1].flag = 1;
  1031. syntax.curly[pos].count++;
  1032. p = skip_word(p);
  1033. return p + 1;
  1034. }
  1035. } else if(!strncmp(p,"do",2) && !ISALPHA(p[2])) {
  1036. int l;
  1037. char label[256];
  1038. p=skip_word(p);
  1039. p=skip_space(p);
  1040. syntax.curly[syntax.curly_count].type = TYPE_DO;
  1041. syntax.curly[syntax.curly_count].count = 1;
  1042. syntax.curly[syntax.curly_count].index = syntax.index++;
  1043. syntax.curly[syntax.curly_count].flag = 0;
  1044. // 現在地のラベル形成する
  1045. sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
  1046. l=add_str(label);
  1047. set_label(l,script_pos,p);
  1048. syntax.curly_count++;
  1049. return p;
  1050. }
  1051. break;
  1052. case 'f':
  1053. if(!strncmp(p,"for",3) && !ISALPHA(p[3])) {
  1054. int l;
  1055. char label[256];
  1056. int pos = syntax.curly_count;
  1057. syntax.curly[syntax.curly_count].type = TYPE_FOR;
  1058. syntax.curly[syntax.curly_count].count = 1;
  1059. syntax.curly[syntax.curly_count].index = syntax.index++;
  1060. syntax.curly[syntax.curly_count].flag = 0;
  1061. syntax.curly_count++;
  1062. p=skip_word(p);
  1063. p=skip_space(p);
  1064. if(*p != '(') {
  1065. disp_error_message("parse_syntax: need '('",p);
  1066. return p+1;
  1067. }
  1068. p++;
  1069. // 初期化文を実行する
  1070. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1071. p=parse_line(p);
  1072. syntax.curly_count--;
  1073. // 条件判断開始のラベル形成する
  1074. sprintf(label,"__FR%x_J",syntax.curly[pos].index);
  1075. l=add_str(label);
  1076. set_label(l,script_pos,p);
  1077. p=skip_space(p);
  1078. if(*p == ';') {
  1079. // for(;;) のパターンなので必ず真
  1080. ;
  1081. } else {
  1082. // 条件が偽なら終了地点に飛ばす
  1083. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1084. add_scriptl(add_str("jump_zero"));
  1085. add_scriptc(C_ARG);
  1086. p=parse_expr(p);
  1087. p=skip_space(p);
  1088. add_scriptl(add_str(label));
  1089. add_scriptc(C_FUNC);
  1090. }
  1091. if(*p != ';') {
  1092. disp_error_message("parse_syntax: need ';'",p);
  1093. return p+1;
  1094. }
  1095. p++;
  1096. // ループ開始に飛ばす
  1097. sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
  1098. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1099. parse_line(label);
  1100. syntax.curly_count--;
  1101. // 次のループへのラベル形成する
  1102. sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
  1103. l=add_str(label);
  1104. set_label(l,script_pos,p);
  1105. // 次のループに入る時の処理
  1106. // for 最後の ')' を ';' として扱うフラグ
  1107. parse_syntax_for_flag = 1;
  1108. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1109. p=parse_line(p);
  1110. syntax.curly_count--;
  1111. parse_syntax_for_flag = 0;
  1112. // 条件判定処理に飛ばす
  1113. sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
  1114. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1115. parse_line(label);
  1116. syntax.curly_count--;
  1117. // ループ開始のラベル付け
  1118. sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
  1119. l=add_str(label);
  1120. set_label(l,script_pos,p);
  1121. return p;
  1122. } else if(!strncmp(p,"function",8) && !ISALPHA(p[8])) {
  1123. const char *func_name;
  1124. // function
  1125. p=skip_word(p);
  1126. p=skip_space(p);
  1127. // function - name
  1128. func_name = p;
  1129. p=skip_word(p);
  1130. if(*skip_space(p) == ';') {
  1131. // 関数の宣言 - 名前を登録して終わり
  1132. int l;
  1133. l=add_word(func_name);
  1134. if(str_data[l].type == C_NOP)
  1135. str_data[l].type = C_USERFUNC;
  1136. return skip_space(p) + 1;
  1137. } else {
  1138. // 関数の中身
  1139. char label[256];
  1140. int l;
  1141. syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
  1142. syntax.curly[syntax.curly_count].count = 1;
  1143. syntax.curly[syntax.curly_count].index = syntax.index++;
  1144. syntax.curly[syntax.curly_count].flag = 0;
  1145. syntax.curly_count++;
  1146. // 関数終了まで飛ばす
  1147. sprintf(label,"goto __FN%x_FIN;",syntax.curly[syntax.curly_count-1].index);
  1148. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1149. parse_line(label);
  1150. syntax.curly_count--;
  1151. // 関数名のラベルを付ける
  1152. l=add_word(func_name);
  1153. if(str_data[l].type == C_NOP)
  1154. str_data[l].type = C_USERFUNC;
  1155. set_label(l,script_pos,p);
  1156. if( parse_options&SCRIPT_USE_LABEL_DB )
  1157. strdb_put(scriptlabel_db, GETSTRING(str_data[l].str), (void*)script_pos);
  1158. return skip_space(p);
  1159. }
  1160. }
  1161. break;
  1162. case 'i':
  1163. if(!strncmp(p,"if",2) && !ISALPHA(p[2])) {
  1164. // if() の処理
  1165. char label[256];
  1166. p=skip_word(p);
  1167. p=skip_space(p);
  1168. if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
  1169. disp_error_message("need '('",p);
  1170. }
  1171. syntax.curly[syntax.curly_count].type = TYPE_IF;
  1172. syntax.curly[syntax.curly_count].count = 1;
  1173. syntax.curly[syntax.curly_count].index = syntax.index++;
  1174. syntax.curly[syntax.curly_count].flag = 0;
  1175. sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
  1176. syntax.curly_count++;
  1177. add_scriptl(add_str("jump_zero"));
  1178. add_scriptc(C_ARG);
  1179. p=parse_expr(p);
  1180. p=skip_space(p);
  1181. add_scriptl(add_str(label));
  1182. add_scriptc(C_FUNC);
  1183. return p;
  1184. }
  1185. break;
  1186. case 's':
  1187. if(!strncmp(p,"switch",6) && !ISALPHA(p[6])) {
  1188. // switch() の処理
  1189. char label[256];
  1190. syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
  1191. syntax.curly[syntax.curly_count].count = 1;
  1192. syntax.curly[syntax.curly_count].index = syntax.index++;
  1193. syntax.curly[syntax.curly_count].flag = 0;
  1194. sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
  1195. syntax.curly_count++;
  1196. add_scriptl(add_str("set"));
  1197. add_scriptc(C_ARG);
  1198. add_scriptl(add_str(label));
  1199. p=skip_word(p);
  1200. p=skip_space(p);
  1201. p=parse_expr(p);
  1202. p=skip_space(p);
  1203. if(*p != '{') {
  1204. disp_error_message("parse_syntax: need '{'",p);
  1205. }
  1206. add_scriptc(C_FUNC);
  1207. return p + 1;
  1208. }
  1209. break;
  1210. case 'w':
  1211. if(!strncmp(p,"while",5) && !ISALPHA(p[5])) {
  1212. int l;
  1213. char label[256];
  1214. p=skip_word(p);
  1215. p=skip_space(p);
  1216. syntax.curly[syntax.curly_count].type = TYPE_WHILE;
  1217. syntax.curly[syntax.curly_count].count = 1;
  1218. syntax.curly[syntax.curly_count].index = syntax.index++;
  1219. syntax.curly[syntax.curly_count].flag = 0;
  1220. // 条件判断開始のラベル形成する
  1221. sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
  1222. l=add_str(label);
  1223. set_label(l,script_pos,p);
  1224. // 条件が偽なら終了地点に飛ばす
  1225. sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
  1226. add_scriptl(add_str("jump_zero"));
  1227. add_scriptc(C_ARG);
  1228. p=parse_expr(p);
  1229. p=skip_space(p);
  1230. add_scriptl(add_str(label));
  1231. add_scriptc(C_FUNC);
  1232. syntax.curly_count++;
  1233. return p;
  1234. }
  1235. break;
  1236. }
  1237. return NULL;
  1238. }
  1239. const char* parse_syntax_close(const char *p) {
  1240. // if(...) for(...) hoge(); のように、1度閉じられたら再度閉じられるか確認する
  1241. int flag;
  1242. do {
  1243. p = parse_syntax_close_sub(p,&flag);
  1244. } while(flag);
  1245. return p;
  1246. }
  1247. // if, for , while , do の閉じ判定
  1248. // flag == 1 : 閉じられた
  1249. // flag == 0 : 閉じられない
  1250. const char* parse_syntax_close_sub(const char* p,int* flag) {
  1251. char label[256];
  1252. int pos = syntax.curly_count - 1;
  1253. int l;
  1254. *flag = 1;
  1255. if(syntax.curly_count <= 0) {
  1256. *flag = 0;
  1257. return p;
  1258. } else if(syntax.curly[pos].type == TYPE_IF) {
  1259. const char *p2 = p;
  1260. // if 最終場所へ飛ばす
  1261. sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
  1262. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1263. parse_line(label);
  1264. syntax.curly_count--;
  1265. // 現在地のラベルを付ける
  1266. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1267. l=add_str(label);
  1268. set_label(l,script_pos,p);
  1269. syntax.curly[pos].count++;
  1270. p = skip_space(p);
  1271. if(!syntax.curly[pos].flag && !strncmp(p,"else",4) && !ISALPHA(p[4])) {
  1272. // else or else - if
  1273. p = skip_word(p);
  1274. p = skip_space(p);
  1275. if(!strncmp(p,"if",2) && !ISALPHA(p[2])) {
  1276. // else - if
  1277. p=skip_word(p);
  1278. p=skip_space(p);
  1279. sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
  1280. add_scriptl(add_str("jump_zero"));
  1281. add_scriptc(C_ARG);
  1282. p=parse_expr(p);
  1283. p=skip_space(p);
  1284. add_scriptl(add_str(label));
  1285. add_scriptc(C_FUNC);
  1286. *flag = 0;
  1287. return p;
  1288. } else {
  1289. // else
  1290. if(!syntax.curly[pos].flag) {
  1291. syntax.curly[pos].flag = 1;
  1292. *flag = 0;
  1293. return p;
  1294. }
  1295. }
  1296. }
  1297. // if 閉じ
  1298. syntax.curly_count--;
  1299. // 最終地のラベルを付ける
  1300. sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
  1301. l=add_str(label);
  1302. set_label(l,script_pos,p);
  1303. if(syntax.curly[pos].flag == 1) {
  1304. // このifに対するelseじゃないのでポインタの位置は同じ
  1305. return p2;
  1306. }
  1307. return p;
  1308. } else if(syntax.curly[pos].type == TYPE_DO) {
  1309. int l;
  1310. char label[256];
  1311. const char *p2;
  1312. if(syntax.curly[pos].flag) {
  1313. // 現在地のラベル形成する(continue でここに来る)
  1314. sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
  1315. l=add_str(label);
  1316. set_label(l,script_pos,p);
  1317. }
  1318. // 条件が偽なら終了地点に飛ばす
  1319. p = skip_space(p);
  1320. p2 = skip_word(p);
  1321. if(p2 - p != 5 || strncmp("while",p,5)) {
  1322. disp_error_message("parse_syntax: need 'while'",p);
  1323. }
  1324. p = p2;
  1325. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1326. add_scriptl(add_str("jump_zero"));
  1327. add_scriptc(C_ARG);
  1328. p=parse_expr(p);
  1329. p=skip_space(p);
  1330. add_scriptl(add_str(label));
  1331. add_scriptc(C_FUNC);
  1332. // 開始地点に飛ばす
  1333. sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
  1334. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1335. parse_line(label);
  1336. syntax.curly_count--;
  1337. // 条件終了地点のラベル形成する
  1338. sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
  1339. l=add_str(label);
  1340. set_label(l,script_pos,p);
  1341. p = skip_space(p);
  1342. if(*p != ';') {
  1343. disp_error_message("parse_syntax: need ';'",p);
  1344. return p+1;
  1345. }
  1346. p++;
  1347. syntax.curly_count--;
  1348. return p;
  1349. } else if(syntax.curly[pos].type == TYPE_FOR) {
  1350. // 次のループに飛ばす
  1351. sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
  1352. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1353. parse_line(label);
  1354. syntax.curly_count--;
  1355. // for 終了のラベル付け
  1356. sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
  1357. l=add_str(label);
  1358. set_label(l,script_pos,p);
  1359. syntax.curly_count--;
  1360. return p;
  1361. } else if(syntax.curly[pos].type == TYPE_WHILE) {
  1362. // while 条件判断へ飛ばす
  1363. sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
  1364. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1365. parse_line(label);
  1366. syntax.curly_count--;
  1367. // while 終了のラベル付け
  1368. sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
  1369. l=add_str(label);
  1370. set_label(l,script_pos,p);
  1371. syntax.curly_count--;
  1372. return p;
  1373. } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
  1374. int pos = syntax.curly_count-1;
  1375. char label[256];
  1376. int l;
  1377. // 戻す
  1378. sprintf(label,"return;");
  1379. syntax.curly[syntax.curly_count++].type = TYPE_NULL;
  1380. parse_line(label);
  1381. syntax.curly_count--;
  1382. // 現在地のラベルを付ける
  1383. sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
  1384. l=add_str(label);
  1385. set_label(l,script_pos,p);
  1386. syntax.curly_count--;
  1387. return p + 1;
  1388. } else {
  1389. *flag = 0;
  1390. return p;
  1391. }
  1392. }
  1393. /*==========================================
  1394. * 組み込み関数の追加
  1395. *------------------------------------------
  1396. */
  1397. static void add_buildin_func(void)
  1398. {
  1399. int i,n;
  1400. for(i=0;buildin_func[i].func;i++){
  1401. n=add_str(buildin_func[i].name);
  1402. str_data[n].type=C_FUNC;
  1403. str_data[n].val=i;
  1404. str_data[n].func=buildin_func[i].func;
  1405. }
  1406. }
  1407. /*==========================================
  1408. * 定数データベースの読み込み
  1409. *------------------------------------------
  1410. */
  1411. static void read_constdb(void)
  1412. {
  1413. FILE *fp;
  1414. char line[1024],name[1024],val[1024];
  1415. int n,i,type;
  1416. sprintf(line, "%s/const.txt", db_path);
  1417. fp=fopen(line, "r");
  1418. if(fp==NULL){
  1419. ShowError("can't read %s\n", line);
  1420. return ;
  1421. }
  1422. while(fgets(line,1020,fp)){
  1423. if(line[0]=='/' && line[1]=='/')
  1424. continue;
  1425. type=0;
  1426. if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
  1427. sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
  1428. for(i=0;name[i];i++)
  1429. name[i]=TOLOWER(name[i]);
  1430. n=add_str(name);
  1431. if(type==0)
  1432. str_data[n].type=C_INT;
  1433. else
  1434. str_data[n].type=C_PARAM;
  1435. str_data[n].val= (int)strtol(val,NULL,0);
  1436. }
  1437. }
  1438. fclose(fp);
  1439. }
  1440. /*==========================================
  1441. * エラー表示
  1442. *------------------------------------------
  1443. */
  1444. const char* script_print_line( const char *p, const char *mark, int line ) {
  1445. int i;
  1446. if( p == NULL || !p[0] ) return NULL;
  1447. if( line < 0 )
  1448. printf("*% 5d : ", -line);
  1449. else
  1450. printf(" % 5d : ", line);
  1451. for(i=0;p[i] && p[i] != '\n';i++){
  1452. if(p + i != mark)
  1453. printf("%c",p[i]);
  1454. else
  1455. printf("\'%c\'",p[i]);
  1456. }
  1457. printf("\n");
  1458. return p+i+(p[i] == '\n' ? 1 : 0);
  1459. }
  1460. void script_error(const char *src,const char *file,int start_line, const char *error_msg, const char *error_pos) {
  1461. // エラーが発生した行を求める
  1462. int j;
  1463. int line = start_line;
  1464. const char *p;
  1465. const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
  1466. for(p=src;p && *p;line++){
  1467. char *lineend=strchr(p,'\n');
  1468. if(lineend==NULL || error_pos<lineend){
  1469. break;
  1470. }
  1471. for( j = 0; j < 4; j++ ) {
  1472. linestart[j] = linestart[j+1];
  1473. }
  1474. linestart[4] = p;
  1475. p=lineend+1;
  1476. }
  1477. printf("\a\n");
  1478. printf("script error on %s line %d\n", file, line);
  1479. printf(" %s\n", error_msg);
  1480. for(j = 0; j < 5; j++ ) {
  1481. script_print_line( linestart[j], NULL, line + j - 5);
  1482. }
  1483. p = script_print_line( p, error_pos, -line);
  1484. for(j = 0; j < 5; j++) {
  1485. p = script_print_line( p, NULL, line + j + 1 );
  1486. }
  1487. }
  1488. /*==========================================
  1489. * スクリプトの解析
  1490. *------------------------------------------
  1491. */
  1492. struct script_code* parse_script(const char *src,const char *file,int line,int options)
  1493. {
  1494. const char *p,*tmpp;
  1495. int i;
  1496. struct script_code *code;
  1497. static int first=1;
  1498. malloc_set(&syntax,0,sizeof(syntax));
  1499. if(first){
  1500. add_buildin_func();
  1501. read_constdb();
  1502. }
  1503. first=0;
  1504. CREATE(script_buf,unsigned char,SCRIPT_BLOCK_SIZE);
  1505. script_pos=0;
  1506. script_size=SCRIPT_BLOCK_SIZE;
  1507. str_data[LABEL_NEXTLINE].type=C_NOP;
  1508. str_data[LABEL_NEXTLINE].backpatch=-1;
  1509. str_data[LABEL_NEXTLINE].label=-1;
  1510. for(i=LABEL_START;i<str_num;i++){
  1511. if(
  1512. str_data[i].type==C_POS || str_data[i].type==C_NAME ||
  1513. str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
  1514. ){
  1515. str_data[i].type=C_NOP;
  1516. str_data[i].backpatch=-1;
  1517. str_data[i].label=-1;
  1518. }
  1519. }
  1520. // who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
  1521. if( options&SCRIPT_USE_LABEL_DB )
  1522. scriptlabel_db->clear(scriptlabel_db, NULL);
  1523. parse_options = options;
  1524. if( setjmp( error_jump ) != 0 ) {
  1525. //Restore program state when script has problems. [from jA]
  1526. script_error(src,file,line,error_msg,error_pos);
  1527. aFree( error_msg );
  1528. aFree( script_buf );
  1529. script_pos = 0;
  1530. script_size = 0;
  1531. script_buf = NULL;
  1532. for(i=LABEL_START;i<str_num;i++){
  1533. if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
  1534. }
  1535. return NULL;
  1536. }
  1537. parse_syntax_for_flag=0;
  1538. p=src;
  1539. p=skip_space(p);
  1540. if(*p!='{'){
  1541. disp_error_message("not found '{'",p);
  1542. }
  1543. p++;
  1544. p = skip_space(p);
  1545. if (p && *p == '}') {
  1546. // an empty function, just return
  1547. aFree( script_buf );
  1548. script_pos = 0;
  1549. script_size = 0;
  1550. script_buf = NULL;
  1551. return NULL;
  1552. }
  1553. while (p && *p && (*p!='}' || syntax.curly_count != 0)) {
  1554. p=skip_space(p);
  1555. // labelだけ特殊処理
  1556. tmpp=skip_space(skip_word(p));
  1557. if(*tmpp==':' && !(!strncmp(p,"default:",8) && p + 7 == tmpp)){
  1558. i=add_word(p);
  1559. set_label(i,script_pos,p);
  1560. if( parse_options&SCRIPT_USE_LABEL_DB )
  1561. strdb_put(scriptlabel_db, GETSTRING(str_data[i].str), (void*)script_pos);
  1562. p=tmpp+1;
  1563. continue;
  1564. }
  1565. // 他は全部一緒くた
  1566. p=parse_line(p);
  1567. p=skip_space(p);
  1568. add_scriptc(C_EOL);
  1569. set_label(LABEL_NEXTLINE,script_pos,p);
  1570. str_data[LABEL_NEXTLINE].type=C_NOP;
  1571. str_data[LABEL_NEXTLINE].backpatch=-1;
  1572. str_data[LABEL_NEXTLINE].label=-1;
  1573. }
  1574. add_scriptc(C_NOP);
  1575. script_size = script_pos;
  1576. RECREATE(script_buf,unsigned char,script_pos);
  1577. // 未解決のラベルを解決
  1578. for(i=LABEL_START;i<str_num;i++){
  1579. if(str_data[i].type==C_NOP){
  1580. int j,next;
  1581. str_data[i].type=C_NAME;
  1582. str_data[i].label=i;
  1583. for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
  1584. next=GETVALUE(script_buf,j);
  1585. SETVALUE(script_buf,j,i);
  1586. j=next;
  1587. }
  1588. }
  1589. }
  1590. #ifdef DEBUG_DISP
  1591. for(i=0;i<script_pos;i++){
  1592. if((i&15)==0) printf("%04x : ",i);
  1593. printf("%02x ",script_buf[i]);
  1594. if((i&15)==15) printf("\n");
  1595. }
  1596. printf("\n");
  1597. #endif
  1598. CREATE(code,struct script_code,1);
  1599. code->script_buf = script_buf;
  1600. code->script_size = script_size;
  1601. code->script_vars = NULL;
  1602. return code;
  1603. }
  1604. //
  1605. // 実行系
  1606. //
  1607. enum {RUN = 0,STOP,END,RERUNLINE,GOTO,RETFUNC};
  1608. /*==========================================
  1609. * ridからsdへの解決
  1610. *------------------------------------------
  1611. */
  1612. struct map_session_data *script_rid2sd(struct script_state *st)
  1613. {
  1614. struct map_session_data *sd=map_id2sd(st->rid);
  1615. if(!sd){
  1616. ShowError("script_rid2sd: fatal error ! player not attached!\n");
  1617. report_src(st);
  1618. }
  1619. return sd;
  1620. }
  1621. /*==========================================
  1622. * 変数の読み取り
  1623. *------------------------------------------
  1624. */
  1625. int get_val(struct script_state*st,struct script_data* data)
  1626. {
  1627. struct map_session_data *sd=NULL;
  1628. if(data->type==C_NAME){
  1629. char *name=str_buf+str_data[data->u.num&0x00ffffff].str;
  1630. char prefix=*name;
  1631. char postfix=name[strlen(name)-1];
  1632. if(not_server_variable(prefix)){
  1633. if((sd=script_rid2sd(st))==NULL)
  1634. ShowError("get_val error name?:%s\n",name);
  1635. }
  1636. if(postfix=='$'){
  1637. data->type=C_CONSTSTR;
  1638. if( prefix=='@'){
  1639. if(sd)
  1640. data->u.str = pc_readregstr(sd,data->u.num);
  1641. }else if(prefix=='$'){
  1642. data->u.str = (char *)idb_get(mapregstr_db,data->u.num);
  1643. }else if(prefix=='#'){
  1644. if( name[1]=='#'){
  1645. if(sd)
  1646. data->u.str = pc_readaccountreg2str(sd,name);
  1647. }else{
  1648. if(sd)
  1649. data->u.str = pc_readaccountregstr(sd,name);
  1650. }
  1651. }else if(prefix=='.') {
  1652. struct linkdb_node **n;
  1653. if( data->ref ) {
  1654. n = data->ref;
  1655. } else if( name[1] == '@' ) {
  1656. n = st->stack->var_function;
  1657. } else {
  1658. n = &st->script->script_vars;
  1659. }
  1660. data->u.str = linkdb_search(n, (void*)data->u.num );
  1661. }else{
  1662. if(sd)
  1663. data->u.str = pc_readglobalreg_str(sd,name);
  1664. } // [zBuffer]
  1665. /*else{
  1666. ShowWarning("script: get_val: illegal scope string variable.\n");
  1667. data->u.str = "!!ERROR!!";
  1668. }*/
  1669. if( data->u.str == NULL )
  1670. data->u.str ="";
  1671. }else{
  1672. data->type=C_INT;
  1673. if(str_data[data->u.num&0x00ffffff].type==C_INT){
  1674. data->u.num = str_data[data->u.num&0x00ffffff].val;
  1675. }else if(str_data[data->u.num&0x00ffffff].type==C_PARAM){
  1676. if(sd)
  1677. data->u.num = pc_readparam(sd,str_data[data->u.num&0x00ffffff].val);
  1678. }else if(prefix=='@'){
  1679. if(sd)
  1680. data->u.num = pc_readreg(sd,data->u.num);
  1681. }else if(prefix=='$'){
  1682. data->u.num = (int)idb_get(mapreg_db,data->u.num);
  1683. }else if(prefix=='#'){
  1684. if( name[1]=='#'){
  1685. if(sd)
  1686. data->u.num = pc_readaccountreg2(sd,name);
  1687. }else{
  1688. if(sd)
  1689. data->u.num = pc_readaccountreg(sd,name);
  1690. }
  1691. }else if(prefix=='.'){
  1692. struct linkdb_node **n;
  1693. if( data->ref ) {
  1694. n = data->ref;
  1695. } else if( name[1] == '@' ) {
  1696. n = st->stack->var_function;
  1697. } else {
  1698. n = &st->script->script_vars;
  1699. }
  1700. data->u.num = (int)linkdb_search(n, (void*)data->u.num);
  1701. }else{
  1702. if(sd)
  1703. data->u.num = pc_readglobalreg(sd,name);
  1704. }
  1705. }
  1706. }
  1707. return 0;
  1708. }
  1709. /*==========================================
  1710. * 変数の読み取り2
  1711. *------------------------------------------
  1712. */
  1713. void* get_val2(struct script_state*st,int num,struct linkdb_node **ref)
  1714. {
  1715. struct script_data dat;
  1716. dat.type=C_NAME;
  1717. dat.u.num=num;
  1718. dat.ref=ref;
  1719. get_val(st,&dat);
  1720. if( dat.type==C_INT ) return (void*)dat.u.num;
  1721. else return (void*)dat.u.str;
  1722. }
  1723. /*==========================================
  1724. * 変数設定用
  1725. *------------------------------------------
  1726. */
  1727. static int set_reg(struct script_state*st,struct map_session_data *sd,int num,char *name,void *v,struct linkdb_node** ref)
  1728. {
  1729. char prefix=*name;
  1730. char postfix=name[strlen(name)-1];
  1731. if( postfix=='$' ){
  1732. char *str=(char*)v;
  1733. if( prefix=='@'){
  1734. pc_setregstr(sd,num,str);
  1735. }else if(prefix=='$') {
  1736. mapreg_setregstr(num,str);
  1737. }else if(prefix=='#') {
  1738. if( name[1]=='#' )
  1739. pc_setaccountreg2str(sd,name,str);
  1740. else
  1741. pc_setaccountregstr(sd,name,str);
  1742. }else if(prefix=='.') {
  1743. char *p;
  1744. struct linkdb_node **n;
  1745. if( ref ) {
  1746. n = ref;
  1747. } else if( name[1] == '@' ) {
  1748. n = st->stack->var_function;
  1749. } else {
  1750. n = &st->script->script_vars;
  1751. }
  1752. p = linkdb_search(n, (void*)num);
  1753. if(p) {
  1754. linkdb_erase(n, (void*)num);
  1755. aFree(p);
  1756. }
  1757. if( ((char*)v)[0] )
  1758. linkdb_insert(n, (void*)num, aStrdup(v));
  1759. }else{
  1760. pc_setglobalreg_str(sd,name,str);
  1761. } // [zBuffer]
  1762. }else{
  1763. // 数値
  1764. int val = (int)v;
  1765. if(str_data[num&0x00ffffff].type==C_PARAM){
  1766. pc_setparam(sd,str_data[num&0x00ffffff].val,val);
  1767. }else if(prefix=='@') {
  1768. pc_setreg(sd,num,val);
  1769. }else if(prefix=='$') {
  1770. mapreg_setreg(num,val);
  1771. }else if(prefix=='#') {
  1772. if( name[1]=='#' )
  1773. pc_setaccountreg2(sd,name,val);
  1774. else
  1775. pc_setaccountreg(sd,name,val);
  1776. }else if(prefix == '.') {
  1777. struct linkdb_node **n;
  1778. if( ref ) {
  1779. n = ref;
  1780. } else if( name[1] == '@' ) {
  1781. n = st->stack->var_function;
  1782. } else {
  1783. n = &st->script->script_vars;
  1784. }
  1785. if( val == 0 ) {
  1786. linkdb_erase(n, (void*)num);
  1787. } else {
  1788. linkdb_replace(n, (void*)num, (void*)val);
  1789. }
  1790. }else{
  1791. pc_setglobalreg(sd,name,val);
  1792. }
  1793. }
  1794. return 0;
  1795. }
  1796. int set_var(struct map_session_data *sd, char *name, void *val)
  1797. {
  1798. return set_reg(NULL, sd, add_str(name), name, val, NULL);
  1799. }
  1800. /*==========================================
  1801. * 文字列への変換
  1802. *------------------------------------------
  1803. */
  1804. char* conv_str(struct script_state *st,struct script_data *data)
  1805. {
  1806. get_val(st,data);
  1807. if(data->type==C_INT){
  1808. char *buf;
  1809. CREATE(buf,char,ITEM_NAME_LENGTH);
  1810. snprintf(buf,ITEM_NAME_LENGTH, "%d",data->u.num);
  1811. buf[ITEM_NAME_LENGTH-1]=0;
  1812. data->type=C_STR;
  1813. data->u.str=buf;
  1814. } else if(data->type==C_POS) {
  1815. // Protect form crashes by passing labels to string-expected args [jA2200]
  1816. data->type = C_CONSTSTR;
  1817. data->u.str = "** SCRIPT ERROR **";
  1818. } else if(data->type==C_NAME){
  1819. data->type=C_CONSTSTR;
  1820. data->u.str=str_buf+str_data[data->u.num].str;
  1821. }
  1822. return data->u.str;
  1823. }
  1824. /*==========================================
  1825. * 数値へ変換
  1826. *------------------------------------------
  1827. */
  1828. int conv_num(struct script_state *st,struct script_data *data)
  1829. {
  1830. char *p;
  1831. get_val(st,data);
  1832. if(data->type==C_STR || data->type==C_CONSTSTR){
  1833. p=data->u.str;
  1834. data->u.num = atoi(p);
  1835. if(data->type==C_STR)
  1836. aFree(p);
  1837. data->type=C_INT;
  1838. }
  1839. return data->u.num;
  1840. }
  1841. /*==========================================
  1842. * スタックへ数値をプッシュ
  1843. *------------------------------------------
  1844. */
  1845. void push_val(struct script_stack *stack,int type,int val)
  1846. {
  1847. if(stack->sp >= stack->sp_max){
  1848. stack->sp_max += 64;
  1849. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1850. sizeof(stack->stack_data[0]) * stack->sp_max);
  1851. malloc_tsetdword(stack->stack_data + (stack->sp_max - 64), 0,
  1852. 64 * sizeof(*(stack->stack_data)));
  1853. }
  1854. // if(battle_config.etc_log)
  1855. // printf("push (%d,%d)-> %d\n",type,val,stack->sp);
  1856. stack->stack_data[stack->sp].type=type;
  1857. stack->stack_data[stack->sp].u.num=val;
  1858. stack->stack_data[stack->sp].ref = NULL;
  1859. stack->sp++;
  1860. }
  1861. /*==========================================
  1862. * スタックへ数値+リファレンスをプッシュ
  1863. *------------------------------------------
  1864. */
  1865. void push_val2(struct script_stack *stack,int type,int val,struct linkdb_node** ref) {
  1866. push_val(stack,type,val);
  1867. stack->stack_data[stack->sp-1].ref = ref;
  1868. }
  1869. /*==========================================
  1870. * スタックへ文字列をプッシュ
  1871. *------------------------------------------
  1872. */
  1873. void push_str(struct script_stack *stack,int type,char *str)
  1874. {
  1875. if(stack->sp>=stack->sp_max){
  1876. stack->sp_max += 64;
  1877. stack->stack_data = (struct script_data *)aRealloc(stack->stack_data,
  1878. sizeof(stack->stack_data[0]) * stack->sp_max);
  1879. malloc_tsetdword(stack->stack_data + (stack->sp_max - 64), '\0',
  1880. 64 * sizeof(*(stack->stack_data)));
  1881. }
  1882. // if(battle_config.etc_log)
  1883. // printf("push (%d,%x)-> %d\n",type,str,stack->sp);
  1884. stack->stack_data[stack->sp].type =type;
  1885. stack->stack_data[stack->sp].u.str=str;
  1886. stack->stack_data[stack->sp].ref =NULL;
  1887. stack->sp++;
  1888. }
  1889. /*==========================================
  1890. * スタックへ複製をプッシュ
  1891. *------------------------------------------
  1892. */
  1893. void push_copy(struct script_stack *stack,int pos)
  1894. {
  1895. switch(stack->stack_data[pos].type){
  1896. case C_CONSTSTR:
  1897. push_str(stack,C_CONSTSTR,stack->stack_data[pos].u.str);
  1898. break;
  1899. case C_STR:
  1900. push_str(stack,C_STR,aStrdup(stack->stack_data[pos].u.str));
  1901. break;
  1902. default:
  1903. push_val2(
  1904. stack,stack->stack_data[pos].type,stack->stack_data[pos].u.num,
  1905. stack->stack_data[pos].ref
  1906. );
  1907. break;
  1908. }
  1909. }
  1910. /*==========================================
  1911. * スタックからポップ
  1912. *------------------------------------------
  1913. */
  1914. void pop_stack(struct script_stack* stack,int start,int end)
  1915. {
  1916. int i;
  1917. for(i=start;i<end;i++){
  1918. if(stack->stack_data[i].type==C_STR){
  1919. aFree(stack->stack_data[i].u.str);
  1920. stack->stack_data[i].type=C_INT; //Might not be correct, but it's done in case to prevent pointer errors later on. [Skotlex]
  1921. }
  1922. }
  1923. if(stack->sp>end){
  1924. memmove(&stack->stack_data[start],&stack->stack_data[end],sizeof(stack->stack_data[0])*(stack->sp-end));
  1925. }
  1926. stack->sp-=end-start;
  1927. }
  1928. /*==========================================
  1929. * スクリプト依存変数、関数依存変数の解放
  1930. *------------------------------------------
  1931. */
  1932. void script_free_vars(struct linkdb_node **node) {
  1933. struct linkdb_node *n = *node;
  1934. while(n) {
  1935. char *name = str_buf + str_data[(int)(n->key)&0x00ffffff].str;
  1936. char postfix = name[strlen(name)-1];
  1937. if( postfix == '$' ) {
  1938. // 文字型変数なので、データ削除
  1939. aFree(n->data);
  1940. }
  1941. n = n->next;
  1942. }
  1943. linkdb_final( node );
  1944. }
  1945. /*==========================================
  1946. * Free's the whole stack. Invoked when clearing a character. [Skotlex]
  1947. *------------------------------------------
  1948. */
  1949. void script_free_stack(struct script_stack *stack) {
  1950. int i;
  1951. for(i = 0; i < stack->sp; i++) {
  1952. if( stack->stack_data[i].type == C_STR ) {
  1953. aFree(stack->stack_data[i].u.str);
  1954. stack->stack_data[i].type = C_INT;
  1955. } else if( i > 0 && stack->stack_data[i].type == C_RETINFO ) {
  1956. struct linkdb_node** n = (struct linkdb_node**)stack->stack_data[i-1].u.num;
  1957. script_free_vars( n );
  1958. aFree( n );
  1959. }
  1960. }
  1961. script_free_vars( stack->var_function );
  1962. aFree(stack->var_function);
  1963. aFree(stack->stack_data);
  1964. aFree(stack);
  1965. }
  1966. void script_free_code(struct script_code* code) {
  1967. script_free_vars( &code->script_vars );
  1968. aFree( code->script_buf );
  1969. aFree( code );
  1970. }
  1971. //
  1972. // 実行部main
  1973. //
  1974. /*==========================================
  1975. * コマンドの読み取り
  1976. *------------------------------------------
  1977. */
  1978. static int unget_com_data=-1;
  1979. int get_com(unsigned char *script,int *pos)
  1980. {
  1981. int i,j;
  1982. if(unget_com_data>=0){
  1983. i=unget_com_data;
  1984. unget_com_data=-1;
  1985. return i;
  1986. }
  1987. if(script[*pos]>=0x80){
  1988. return C_INT;
  1989. }
  1990. i=0; j=0;
  1991. while(script[*pos]>=0x40){
  1992. i=script[(*pos)++]<<j;
  1993. j+=6;
  1994. }
  1995. return i+(script[(*pos)++]<<j);
  1996. }
  1997. /*==========================================
  1998. * コマンドのプッシュバック
  1999. *------------------------------------------
  2000. */
  2001. void unget_com(int c)
  2002. {
  2003. if(unget_com_data!=-1){
  2004. if(battle_config.error_log)
  2005. ShowError("unget_com can back only 1 data\n");
  2006. }
  2007. unget_com_data=c;
  2008. }
  2009. /*==========================================
  2010. * 数値の所得
  2011. *------------------------------------------
  2012. */
  2013. int get_num(unsigned char *script,int *pos)
  2014. {
  2015. int i,j;
  2016. i=0; j=0;
  2017. while(script[*pos]>=0xc0){
  2018. i+=(script[(*pos)++]&0x7f)<<j;
  2019. j+=6;
  2020. }
  2021. return i+((script[(*pos)++]&0x7f)<<j);
  2022. }
  2023. /*==========================================
  2024. * スタックから値を取り出す
  2025. *------------------------------------------
  2026. */
  2027. int pop_val(struct script_state* st)
  2028. {
  2029. if(st->stack->sp<=0)
  2030. return 0;
  2031. st->stack->sp--;
  2032. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2033. if(st->stack->stack_data[st->stack->sp].type==C_INT)
  2034. return st->stack->stack_data[st->stack->sp].u.num;
  2035. return 0;
  2036. }
  2037. int isstr(struct script_data *c) {
  2038. if( c->type == C_STR || c->type == C_CONSTSTR )
  2039. return 1;
  2040. else if( c->type == C_NAME ) {
  2041. char *p = str_buf + str_data[c->u.num & 0xffffff].str;
  2042. char postfix = p[strlen(p)-1];
  2043. return (postfix == '$');
  2044. }
  2045. return 0;
  2046. }
  2047. /*==========================================
  2048. * Three-section operator
  2049. * test ? if_true : if_false
  2050. *------------------------------------------
  2051. */
  2052. void op_3(struct script_state *st) {
  2053. int flag = 0;
  2054. if( isstr(&st->stack->stack_data[st->stack->sp-3])) {
  2055. char *str = conv_str(st,& (st->stack->stack_data[st->stack->sp-3]));
  2056. flag = str[0];
  2057. } else {
  2058. flag = conv_num(st,& (st->stack->stack_data[st->stack->sp-3]));
  2059. }
  2060. if( flag ) {
  2061. push_copy(st->stack, st->stack->sp-2 );
  2062. } else {
  2063. push_copy(st->stack, st->stack->sp-1 );
  2064. }
  2065. pop_stack(st->stack,st->stack->sp-4,st->stack->sp-1);
  2066. }
  2067. /*==========================================
  2068. * 加算演算子
  2069. *------------------------------------------
  2070. */
  2071. void op_add(struct script_state* st)
  2072. {
  2073. st->stack->sp--;
  2074. get_val(st,&(st->stack->stack_data[st->stack->sp]));
  2075. get_val(st,&(st->stack->stack_data[st->stack->sp-1]));
  2076. if(isstr(&st->stack->stack_data[st->stack->sp]) || isstr(&st->stack->stack_data[st->stack->sp-1])){
  2077. conv_str(st,&(st->stack->stack_data[st->stack->sp]));
  2078. conv_str(st,&(st->stack->stack_data[st->stack->sp-1]));
  2079. }
  2080. if(st->stack->stack_data[st->stack->sp].type==C_INT){ // ii
  2081. int *i1 = &st->stack->stack_data[st->stack->sp-1].u.num;
  2082. int *i2 = &st->stack->stack_data[st->stack->sp].u.num;
  2083. int ret = *i1 + *i2;
  2084. double ret_double = (double)*i1 + (double)*i2;
  2085. if(ret_double > INT_MAX|| ret_double < INT_MIN) {
  2086. ShowWarning("script::op_add overflow detected op:%d\n",C_ADD);
  2087. report_src(st);
  2088. ret = cap_value(ret, INT_MIN, INT_MAX);
  2089. }
  2090. *i1 = ret;
  2091. } else { // ssの予定
  2092. char *buf;
  2093. buf=(char *)aMallocA((strlen(st->stack->stack_data[st->stack->sp-1].u.str)+
  2094. strlen(st->stack->stack_data[st->stack->sp].u.str)+1)*sizeof(char));
  2095. strcpy(buf,st->stack->stack_data[st->stack->sp-1].u.str);
  2096. strcat(buf,st->stack->stack_data[st->stack->sp].u.str);
  2097. if(st->stack->stack_data[st->stack->sp-1].type==C_STR)
  2098. {
  2099. aFree(st->stack->stack_data[st->stack->sp-1].u.str);
  2100. st->stack->stack_data[st->stack->sp-1].type=C_INT;
  2101. }
  2102. if(st->stack->stack_data[st->stack->sp].type==C_STR)
  2103. {
  2104. aFree(st->stack->stack_data[st->stack->sp].u.str);
  2105. st->stack->stack_data[st->stack->sp].type=C_INT;
  2106. }
  2107. st->stack->stack_data[st->stack->sp-1].type=C_STR;
  2108. st->stack->stack_data[st->stack->sp-1].u.str=buf;
  2109. }
  2110. st->stack->stack_data[st->stack->sp-1].ref = NULL;
  2111. }
  2112. /*==========================================
  2113. * 二項演算子(文字列)
  2114. *------------------------------------------
  2115. */
  2116. void op_2str(struct script_state *st,int op,int sp1,int sp2)
  2117. {
  2118. char *s1=st->stack->stack_data[sp1].u.str,
  2119. *s2=st->stack->stack_data[sp2].u.str;
  2120. int a=0;
  2121. switch(op){
  2122. case C_EQ:
  2123. a= (strcmp(s1,s2)==0);
  2124. break;
  2125. case C_NE:
  2126. a= (strcmp(s1,s2)!=0);
  2127. break;
  2128. case C_GT:
  2129. a= (strcmp(s1,s2)> 0);
  2130. break;
  2131. case C_GE:
  2132. a= (strcmp(s1,s2)>=0);
  2133. break;
  2134. case C_LT:
  2135. a= (strcmp(s1,s2)< 0);
  2136. break;
  2137. case C_LE:
  2138. a= (strcmp(s1,s2)<=0);
  2139. break;
  2140. default:
  2141. ShowWarning("script: illegal string operator\n");
  2142. break;
  2143. }
  2144. // Because push_val() overwrite stack_data[sp1], C_STR on stack_data[sp1] won't be freed.
  2145. // So, call push_val() after freeing strings. [jA1783]
  2146. // push_val(st->stack,C_INT,a);
  2147. if(st->stack->stack_data[sp1].type==C_STR)
  2148. {
  2149. aFree(s1);
  2150. st->stack->stack_data[sp1].type=C_INT;
  2151. }
  2152. if(st->stack->stack_data[sp2].type==C_STR)
  2153. {
  2154. aFree(s2);
  2155. st->stack->stack_data[sp2].type=C_INT;
  2156. }
  2157. push_val(st->stack,C_INT,a);
  2158. }
  2159. /*==========================================
  2160. * 二項演算子(数値)
  2161. *------------------------------------------
  2162. */
  2163. void op_2num(struct script_state *st,int op,int i1,int i2)
  2164. {
  2165. int ret = 0;
  2166. double ret_double = 0;
  2167. switch(op){
  2168. case C_MOD: ret = i1 % i2; break;
  2169. case C_AND: ret = i1 & i2; break;
  2170. case C_OR: ret = i1 | i2; break;
  2171. case C_XOR: ret = i1 ^ i2; break;
  2172. case C_LAND: ret = (i1 && i2); break;
  2173. case C_LOR: ret = (i1 || i2); break;
  2174. case C_EQ: ret = (i1 == i2); break;
  2175. case C_NE: ret = (i1 != i2); break;
  2176. case C_GT: ret = (i1 > i2); break;
  2177. case C_GE: ret = (i1 >= i2); break;
  2178. case C_LT: ret = (i1 < i2); break;
  2179. case C_LE: ret = (i1 <= i2); break;
  2180. case C_R_SHIFT: ret = i1>>i2; break;
  2181. case C_L_SHIFT: ret = i1<<i2; break;
  2182. default:
  2183. switch(op) {
  2184. case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
  2185. case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
  2186. case C_DIV:
  2187. if(i2 == 0) {
  2188. printf("script::op_2num division by zero.\n");
  2189. ret = INT_MAX;
  2190. ret_double = 0; // doubleの精度が怪しいのでオーバーフロー対策を飛ばす
  2191. } else {
  2192. ret = i1 / i2; ret_double = (double)i1 / (double)i2;
  2193. }
  2194. break;
  2195. }
  2196. if(ret_double > INT_MAX || ret_double < INT_MIN) {
  2197. printf("script::op_2num overflow detected op:%d\n",op);
  2198. report_src(st);
  2199. ret = (int)cap_value(ret_double,INT_MAX,INT_MIN);
  2200. }
  2201. }
  2202. push_val(st->stack,C_INT,ret);
  2203. }
  2204. /*==========================================
  2205. * 二項演算子
  2206. *------------------------------------------
  2207. */
  2208. void op_2(struct script_state *st,int op)
  2209. {
  2210. int i1,i2;
  2211. char *s1=NULL,*s2=NULL;
  2212. i2=pop_val(st);
  2213. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2214. s2=st->stack->stack_data[st->stack->sp].u.str;
  2215. i1=pop_val(st);
  2216. if( isstr(&st->stack->stack_data[st->stack->sp]) )
  2217. s1=st->stack->stack_data[st->stack->sp].u.str;
  2218. if( s1!=NULL && s2!=NULL ){
  2219. // ss => op_2str
  2220. op_2str(st,op,st->stack->sp,st->stack->sp+1);
  2221. }else if( s1==NULL && s2==NULL ){
  2222. // ii => op_2num
  2223. op_2num(st,op,i1,i2);
  2224. }else{
  2225. // si,is => error
  2226. ShowWarning("script: op_2: int&str, str&int not allow.\n");
  2227. report_src(st);
  2228. if(s1 && st->stack->stack_data[st->stack->sp].type == C_STR)
  2229. {
  2230. aFree(s1);
  2231. st->stack->stack_data[st->stack->sp].type = C_INT;
  2232. }
  2233. if(s2 && st->stack->stack_data[st->stack->sp+1].type == C_STR)
  2234. {
  2235. aFree(s2);
  2236. st->stack->stack_data[st->stack->sp+1].type = C_INT;
  2237. }
  2238. push_val(st->stack,C_INT,0);
  2239. }
  2240. }
  2241. /*==========================================
  2242. * 単項演算子
  2243. *------------------------------------------
  2244. */
  2245. void op_1num(struct script_state *st,int op)
  2246. {
  2247. int i1;
  2248. i1=pop_val(st);
  2249. switch(op){
  2250. case C_NEG:
  2251. i1=-i1;
  2252. break;
  2253. case C_NOT:
  2254. i1=~i1;
  2255. break;
  2256. case C_LNOT:
  2257. i1=!i1;
  2258. break;
  2259. }
  2260. push_val(st->stack,C_INT,i1);
  2261. }
  2262. /*==========================================
  2263. * 関数の実行
  2264. *------------------------------------------
  2265. */
  2266. int run_func(struct script_state *st)
  2267. {
  2268. int i,start_sp,end_sp,func;
  2269. end_sp=st->stack->sp;
  2270. for(i=end_sp-1;i>=0 && st->stack->stack_data[i].type!=C_ARG;i--);
  2271. if(i<=0){ //Crash fix when missing "push_val" causes current pointer to become -1. from Rayce (jA)
  2272. if(battle_config.error_log)
  2273. ShowError("function not found\n");
  2274. // st->stack->sp=0;
  2275. st->state=END;
  2276. report_src(st);
  2277. return 1;
  2278. }
  2279. start_sp=i-1;
  2280. st->start=i-1;
  2281. st->end=end_sp;
  2282. func=st->stack->stack_data[st->start].u.num;
  2283. #ifdef DEBUG_RUN
  2284. if(battle_config.etc_log) {
  2285. 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);
  2286. ShowDebug("stack dump :");
  2287. for(i=0;i<end_sp;i++){
  2288. switch(st->stack->stack_data[i].type){
  2289. case C_INT:
  2290. printf(" int(%d)",st->stack->stack_data[i].u.num);
  2291. break;
  2292. case C_NAME:
  2293. printf(" name(%s)",str_buf+str_data[st->stack->stack_data[i].u.num & 0xffffff].str);
  2294. break;
  2295. case C_ARG:
  2296. printf(" arg");
  2297. break;
  2298. case C_POS:
  2299. printf(" pos(%d)",st->stack->stack_data[i].u.num);
  2300. break;
  2301. case C_STR:
  2302. printf(" str(%s)",st->stack->stack_data[i].u.str);
  2303. break;
  2304. case C_CONSTSTR:
  2305. printf(" cstr(%s)",st->stack->stack_data[i].u.str);
  2306. break;
  2307. default:
  2308. printf(" etc(%d,%d)",st->stack->stack_data[i].type,st->stack->stack_data[i].u.num);
  2309. }
  2310. }
  2311. printf("\n");
  2312. }
  2313. #endif
  2314. if(str_data[func].type!=C_FUNC ){
  2315. ShowMessage ("run_func: '"CL_WHITE"%s"CL_RESET"' (type %d) is not function and command!\n", str_buf+str_data[func].str, str_data[func].type);
  2316. // st->stack->sp=0;
  2317. st->state=END;
  2318. report_src(st);
  2319. return 1;
  2320. }
  2321. #ifdef DEBUG_RUN
  2322. ShowDebug("run_func : %s (func_no : %d , func_type : %d pos : 0x%x)\n",
  2323. str_buf+str_data[func].str,func,str_data[func].type,st->pos
  2324. );
  2325. #endif
  2326. if(str_data[func].func){
  2327. if (str_data[func].func(st)) //Report error
  2328. report_src(st);
  2329. } else {
  2330. if(battle_config.error_log)
  2331. ShowError("run_func : %s? (%d(%d))\n",str_buf+str_data[func].str,func,str_data[func].type);
  2332. push_val(st->stack,C_INT,0);
  2333. report_src(st);
  2334. }
  2335. // Stack's datum are used when re-run functions [Eoe]
  2336. if(st->state != RERUNLINE) {
  2337. pop_stack(st->stack,start_sp,end_sp);
  2338. }
  2339. if(st->state==RETFUNC){
  2340. // ユーザー定義関数からの復帰
  2341. int olddefsp=st->stack->defsp;
  2342. int i;
  2343. pop_stack(st->stack,st->stack->defsp,start_sp); // 復帰に邪魔なスタック削除
  2344. if(st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO){
  2345. ShowWarning("script:run_func(return) return without callfunc or callsub!\n");
  2346. st->state=END;
  2347. report_src(st);
  2348. return 1;
  2349. }
  2350. script_free_vars( st->stack->var_function );
  2351. aFree(st->stack->var_function);
  2352. i = conv_num(st,& (st->stack->stack_data[st->stack->defsp-5])); // 引数の数所得
  2353. st->pos=conv_num(st,& (st->stack->stack_data[st->stack->defsp-1])); // スクリプト位置の復元
  2354. st->script=(struct script_code*)conv_num(st,& (st->stack->stack_data[st->stack->defsp-3])); // スクリプトを復元
  2355. st->stack->var_function = (struct linkdb_node**)st->stack->stack_data[st->stack->defsp-2].u.num; // 関数依存変数
  2356. st->stack->defsp=conv_num(st,& (st->stack->stack_data[st->stack->defsp-4])); // 基準スタックポインタを復元
  2357. pop_stack(st->stack,olddefsp-5-i,olddefsp); // 要らなくなったスタック(引数と復帰用データ)削除
  2358. st->state=GOTO;
  2359. }
  2360. return 0;
  2361. }
  2362. /*==========================================
  2363. * スクリプトの実行
  2364. *------------------------------------------
  2365. */
  2366. void run_script_main(struct script_state *st);
  2367. void run_script(struct script_code *rootscript,int pos,int rid,int oid)
  2368. {
  2369. struct script_state *st;
  2370. struct map_session_data *sd=NULL;
  2371. if(rootscript==NULL || pos<0)
  2372. return;
  2373. if (rid) sd = map_id2sd(rid);
  2374. if (sd && sd->st && sd->st->scriptroot == rootscript && sd->st->pos == pos){
  2375. //Resume script.
  2376. st = sd->st;
  2377. } else {
  2378. st = aCalloc(sizeof(struct script_state), 1);
  2379. // the script is different, make new script_state and stack
  2380. st->stack = aMalloc (sizeof(struct script_stack));
  2381. st->stack->sp=0;
  2382. st->stack->sp_max=64;
  2383. st->stack->stack_data = (struct script_data *)aCalloc(st->stack->sp_max,sizeof(st->stack->stack_data[0]));
  2384. st->stack->defsp = st->stack->sp;
  2385. st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
  2386. st->state = RUN;
  2387. st->script = rootscript;
  2388. }
  2389. st->pos = pos;
  2390. st->rid = rid;
  2391. st->oid = oid;
  2392. st->sleep.timer = -1;
  2393. run_script_main(st);
  2394. }
  2395. /*==========================================
  2396. * 指定ノードをsleep_dbから削除
  2397. *------------------------------------------
  2398. */
  2399. struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
  2400. {
  2401. struct linkdb_node *retnode;
  2402. if( n == NULL)
  2403. return NULL;
  2404. if( n->prev == NULL )
  2405. sleep_db = n->next;
  2406. else
  2407. n->prev->next = n->next;
  2408. if( n->next )
  2409. n->next->prev = n->prev;
  2410. retnode = n->next;
  2411. aFree( n );
  2412. return retnode; // 次のノードを返す
  2413. }
  2414. /*==========================================
  2415. * sleep用タイマー関数
  2416. *------------------------------------------
  2417. */
  2418. int run_script_timer(int tid, unsigned int tick, int id, int data)
  2419. {
  2420. struct script_state *st = (struct script_state *)data;
  2421. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  2422. struct map_session_data *sd = map_id2sd(st->rid);
  2423. if((sd && sd->status.char_id != id) || (st->rid && !sd))
  2424. { //Character mismatch. Cancel execution.
  2425. st->rid = 0;
  2426. st->state = END;
  2427. }
  2428. while( node && st->sleep.timer != -1 ) {
  2429. if( (int)node->key == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
  2430. script_erase_sleepdb(node);
  2431. st->sleep.timer = -1;
  2432. break;
  2433. }
  2434. node = node->next;
  2435. }
  2436. if(st->state != RERUNLINE)
  2437. st->sleep.tick = 0;
  2438. run_script_main(st);
  2439. return 0;
  2440. }
  2441. /*==========================================
  2442. * スクリプトの実行メイン部分
  2443. *------------------------------------------
  2444. */
  2445. void run_script_main(struct script_state *st)
  2446. {
  2447. int c;
  2448. int cmdcount=script_config.check_cmdcount;
  2449. int gotocount=script_config.check_gotocount;
  2450. struct map_session_data *sd;
  2451. //For backing up purposes
  2452. struct script_state *bk_st = NULL;
  2453. int bk_npcid = 0;
  2454. struct script_stack *stack=st->stack;
  2455. sd = st->rid?map_id2sd(st->rid):NULL;
  2456. if(sd){
  2457. if(sd->st != st){
  2458. bk_st = sd->st;
  2459. bk_npcid = sd->npc_id;
  2460. }
  2461. sd->st = st;
  2462. sd->npc_id = st->oid;
  2463. }
  2464. if(st->state == RERUNLINE) {
  2465. st->state = RUN;
  2466. run_func(st);
  2467. if(st->state == GOTO)
  2468. st->state = RUN;
  2469. } else if(st->state != END)
  2470. st->state = RUN;
  2471. while(st->state == RUN){
  2472. c= get_com(st->script->script_buf,&st->pos);
  2473. switch(c){
  2474. case C_EOL:
  2475. if(stack->sp!=stack->defsp){
  2476. if(stack->sp > stack->defsp)
  2477. { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
  2478. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
  2479. if (battle_config.etc_log)
  2480. {
  2481. ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
  2482. report_src(st);
  2483. }
  2484. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
  2485. } else if(battle_config.error_log)
  2486. ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp);
  2487. stack->sp=stack->defsp;
  2488. }
  2489. break;
  2490. case C_INT:
  2491. push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos));
  2492. break;
  2493. case C_POS:
  2494. case C_NAME:
  2495. push_val(stack,c,GETVALUE(st->script->script_buf,st->pos));
  2496. st->pos+=3;
  2497. break;
  2498. case C_ARG:
  2499. push_val(stack,c,0);
  2500. break;
  2501. case C_STR:
  2502. push_str(stack,C_CONSTSTR,(st->script->script_buf+st->pos));
  2503. while(st->script->script_buf[st->pos++]);
  2504. break;
  2505. case C_FUNC:
  2506. run_func(st);
  2507. if(st->state==GOTO){
  2508. st->state = RUN;
  2509. if( gotocount>0 && (--gotocount)<=0 ){
  2510. ShowError("run_script: infinity loop !\n");
  2511. report_src(st);
  2512. st->state=END;
  2513. }
  2514. }
  2515. break;
  2516. case C_ADD:
  2517. op_add(st);
  2518. break;
  2519. case C_SUB:
  2520. case C_MUL:
  2521. case C_DIV:
  2522. case C_MOD:
  2523. case C_EQ:
  2524. case C_NE:
  2525. case C_GT:
  2526. case C_GE:
  2527. case C_LT:
  2528. case C_LE:
  2529. case C_AND:
  2530. case C_OR:
  2531. case C_XOR:
  2532. case C_LAND:
  2533. case C_LOR:
  2534. case C_R_SHIFT:
  2535. case C_L_SHIFT:
  2536. op_2(st,c);
  2537. break;
  2538. case C_NEG:
  2539. case C_NOT:
  2540. case C_LNOT:
  2541. op_1num(st,c);
  2542. break;
  2543. case C_OP3:
  2544. op_3(st);
  2545. break;
  2546. case C_NOP:
  2547. st->state=END;
  2548. break;
  2549. default:
  2550. if(battle_config.error_log)
  2551. ShowError("unknown command : %d @ %d\n",c,pos);
  2552. st->state=END;
  2553. break;
  2554. }
  2555. if( cmdcount>0 && (--cmdcount)<=0 ){
  2556. ShowError("run_script: infinity loop !\n");
  2557. report_src(st);
  2558. st->state=END;
  2559. }
  2560. }
  2561. if(st->sleep.tick > 0) {
  2562. //Delay execution
  2563. st->sleep.charid = sd?sd->status.char_id:0;
  2564. st->sleep.timer = add_timer(gettick()+st->sleep.tick,
  2565. run_script_timer, st->sleep.charid, (int)st);
  2566. linkdb_insert(&sleep_db, (void*)st->oid, st);
  2567. //Restore previous script
  2568. if (sd) {
  2569. sd->st = bk_st;
  2570. sd->npc_id = bk_npcid;
  2571. bk_st = NULL; //Remove tag for removal.
  2572. }
  2573. }
  2574. else if(st->state != END && sd){
  2575. //Resume later (st is already attached to player).
  2576. if(bk_st) {
  2577. ShowWarning("Unable to restore stack! Double continuation!\n");
  2578. //Report BOTH scripts to see if that can help somehow.
  2579. ShowDebug("Previous script (lost):\n");
  2580. report_src(bk_st);
  2581. ShowDebug("Current script:\n");
  2582. report_src(st);
  2583. }
  2584. } else {
  2585. //Dispose of script.
  2586. if (sd)
  2587. { //Restore previous stack and save char.
  2588. if(sd->state.using_fake_npc){
  2589. clif_clearchar_id(sd->npc_id, 0, sd->fd);
  2590. sd->state.using_fake_npc = 0;
  2591. }
  2592. //Restore previous script if any.
  2593. sd->st = bk_st;
  2594. sd->npc_id = bk_npcid;
  2595. if (!bk_st)
  2596. npc_event_dequeue(sd);
  2597. else
  2598. bk_st = NULL; //Remove tag for removal.
  2599. if (sd->state.reg_dirty&2)
  2600. intif_saveregistry(sd,2);
  2601. if (sd->state.reg_dirty&1)
  2602. intif_saveregistry(sd,1);
  2603. }
  2604. st->pos = -1;
  2605. script_free_stack (st->stack);
  2606. aFree(st);
  2607. }
  2608. if (bk_st)
  2609. { //Remove previous script
  2610. bk_st->pos = -1;
  2611. script_free_stack(bk_st->stack);
  2612. aFree(bk_st);
  2613. bk_st = NULL;
  2614. }
  2615. }
  2616. /*==========================================
  2617. * マップ変数の変更
  2618. *------------------------------------------
  2619. */
  2620. int mapreg_setreg(int num,int val)
  2621. {
  2622. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2623. int i=num>>24;
  2624. char *name=str_buf+str_data[num&0x00ffffff].str;
  2625. char tmp_str[64];
  2626. #endif
  2627. if(val!=0) {
  2628. if(idb_put(mapreg_db,num,(void*)val))
  2629. ;
  2630. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2631. else if(name[1] != '@') {
  2632. 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);
  2633. if(mysql_query(&mmysql_handle,tmp_sql)){
  2634. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2635. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2636. }
  2637. }
  2638. #endif
  2639. } else { // [zBuffer]
  2640. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2641. if(name[1] != '@') { // Remove from database because it is unused.
  2642. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2643. if(mysql_query(&mmysql_handle,tmp_sql)){
  2644. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2645. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2646. }
  2647. }
  2648. #endif
  2649. idb_remove(mapreg_db,num);
  2650. }
  2651. mapreg_dirty=1;
  2652. return 0;
  2653. }
  2654. /*==========================================
  2655. * 文字列型マップ変数の変更
  2656. *------------------------------------------
  2657. */
  2658. int mapreg_setregstr(int num,const char *str)
  2659. {
  2660. char *p;
  2661. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2662. char tmp_str[64];
  2663. char tmp_str2[512];
  2664. int i=num>>24; // [zBuffer]
  2665. char *name=str_buf+str_data[num&0x00ffffff].str;
  2666. #endif
  2667. if( str==NULL || *str==0 ){
  2668. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2669. if(name[1] != '@') {
  2670. sprintf(tmp_sql,"DELETE FROM `%s` WHERE `%s`='%s' AND `%s`='%d'",mapregsql_db,mapregsql_db_varname,name,mapregsql_db_index,i);
  2671. if(mysql_query(&mmysql_handle,tmp_sql)){
  2672. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2673. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2674. }
  2675. }
  2676. #endif
  2677. idb_remove(mapregstr_db,num);
  2678. mapreg_dirty=1;
  2679. return 0;
  2680. }
  2681. p=(char *)aMallocA((strlen(str)+1)*sizeof(char));
  2682. strcpy(p,str);
  2683. if (idb_put(mapregstr_db,num,p))
  2684. ;
  2685. #if !defined(TXT_ONLY) && defined(MAPREGSQL)
  2686. else if(name[1] != '@'){ //put returned null, so we must insert.
  2687. // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
  2688. 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));
  2689. if(mysql_query(&mmysql_handle,tmp_sql)){
  2690. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2691. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2692. }
  2693. }
  2694. #endif
  2695. mapreg_dirty=1;
  2696. return 0;
  2697. }
  2698. /*==========================================
  2699. * 永続的マップ変数の読み込み
  2700. *------------------------------------------
  2701. */
  2702. static int script_load_mapreg(void)
  2703. {
  2704. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2705. FILE *fp;
  2706. char line[1024];
  2707. if( (fp=fopen(mapreg_txt,"rt"))==NULL )
  2708. return -1;
  2709. while(fgets(line,sizeof(line),fp)){
  2710. char buf1[256],buf2[1024],*p;
  2711. int n,v,s,i;
  2712. if( sscanf(line,"%255[^,],%d\t%n",buf1,&i,&n)!=2 &&
  2713. (i=0,sscanf(line,"%[^\t]\t%n",buf1,&n)!=1) )
  2714. continue;
  2715. if( buf1[strlen(buf1)-1]=='$' ){
  2716. if( sscanf(line+n,"%[^\n\r]",buf2)!=1 ){
  2717. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2718. continue;
  2719. }
  2720. p=(char *)aMallocA((strlen(buf2) + 1)*sizeof(char));
  2721. strcpy(p,buf2);
  2722. s= add_str(buf1);
  2723. idb_put(mapregstr_db,(i<<24)|s,p);
  2724. }else{
  2725. if( sscanf(line+n,"%d",&v)!=1 ){
  2726. ShowError("%s: %s broken data !\n",mapreg_txt,buf1);
  2727. continue;
  2728. }
  2729. s= add_str(buf1);
  2730. idb_put(mapreg_db,(i<<24)|s,(void*)v);
  2731. }
  2732. }
  2733. fclose(fp);
  2734. mapreg_dirty=0;
  2735. return 0;
  2736. #else
  2737. // SQL mapreg code start [zBuffer]
  2738. /*
  2739. 0 1 2
  2740. +-------------------------+
  2741. | varname | index | value |
  2742. +-------------------------+
  2743. */
  2744. unsigned int perfomance = (unsigned int)time(NULL);
  2745. sprintf(tmp_sql,"SELECT * FROM `%s`",mapregsql_db);
  2746. ShowInfo("Querying script_load_mapreg ...\n");
  2747. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2748. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2749. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2750. return -1;
  2751. }
  2752. ShowInfo("Success! Returning results ...\n");
  2753. sql_res = mysql_store_result(&mmysql_handle);
  2754. if (sql_res) {
  2755. while ((sql_row = mysql_fetch_row(sql_res))) {
  2756. char buf1[33], *p = NULL;
  2757. int i,v,s;
  2758. strcpy(buf1,sql_row[0]);
  2759. if( buf1[strlen(buf1)-1]=='$' ){
  2760. i = atoi(sql_row[1]);
  2761. p=(char *)aMallocA((strlen(sql_row[2]) + 1)*sizeof(char));
  2762. strcpy(p,sql_row[2]);
  2763. s= add_str(buf1);
  2764. idb_put(mapregstr_db,(i<<24)|s,p);
  2765. }else{
  2766. s= add_str(buf1);
  2767. v= atoi(sql_row[2]);
  2768. i = atoi(sql_row[1]);
  2769. idb_put(mapreg_db,(i<<24)|s,(void *)v);
  2770. }
  2771. }
  2772. }
  2773. ShowInfo("Freeing results...\n");
  2774. mysql_free_result(sql_res);
  2775. mapreg_dirty=0;
  2776. perfomance = (((unsigned int)time(NULL)) - perfomance);
  2777. ShowInfo("SQL Mapreg Loading Completed Under %d Seconds.\n",perfomance);
  2778. return 0;
  2779. #endif /* TXT_ONLY */
  2780. }
  2781. /*==========================================
  2782. * 永続的マップ変数の書き込み
  2783. *------------------------------------------
  2784. */
  2785. static int script_save_mapreg_intsub(DBKey key,void *data,va_list ap)
  2786. {
  2787. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2788. FILE *fp=va_arg(ap,FILE*);
  2789. int num=key.i&0x00ffffff, i=key.i>>24;
  2790. char *name=str_buf+str_data[num].str;
  2791. if( name[1]!='@' ){
  2792. if(i==0)
  2793. fprintf(fp,"%s\t%d\n", name, (int)data);
  2794. else
  2795. fprintf(fp,"%s,%d\t%d\n", name, i, (int)data);
  2796. }
  2797. return 0;
  2798. #else
  2799. int num=key.i&0x00ffffff, i=key.i>>24; // [zBuffer]
  2800. char *name=str_buf+str_data[num].str;
  2801. if ( name[1] != '@') {
  2802. 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);
  2803. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2804. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2805. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2806. }
  2807. }
  2808. return 0;
  2809. #endif
  2810. }
  2811. static int script_save_mapreg_strsub(DBKey key,void *data,va_list ap)
  2812. {
  2813. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2814. FILE *fp=va_arg(ap,FILE*);
  2815. int num=key.i&0x00ffffff, i=key.i>>24;
  2816. char *name=str_buf+str_data[num].str;
  2817. if( name[1]!='@' ){
  2818. if(i==0)
  2819. fprintf(fp,"%s\t%s\n", name, (char *)data);
  2820. else
  2821. fprintf(fp,"%s,%d\t%s\n", name, i, (char *)data);
  2822. }
  2823. return 0;
  2824. #else
  2825. char tmp_str2[512];
  2826. int num=key.i&0x00ffffff, i=key.i>>24;
  2827. char *name=str_buf+str_data[num].str;
  2828. if ( name[1] != '@') {
  2829. 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);
  2830. if(mysql_query(&mmysql_handle, tmp_sql) ) {
  2831. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  2832. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  2833. }
  2834. }
  2835. return 0;
  2836. #endif
  2837. }
  2838. static int script_save_mapreg(void)
  2839. {
  2840. #if defined(TXT_ONLY) || !defined(MAPREGSQL)
  2841. FILE *fp;
  2842. int lock;
  2843. if( (fp=lock_fopen(mapreg_txt,&lock))==NULL ) {
  2844. ShowError("script_save_mapreg: Unable to lock-open file [%s]\n",mapreg_txt);
  2845. return -1;
  2846. }
  2847. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub,fp);
  2848. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub,fp);
  2849. lock_fclose(fp,mapreg_txt,&lock);
  2850. #else
  2851. unsigned int perfomance = (unsigned int)time(NULL);
  2852. mapreg_db->foreach(mapreg_db,script_save_mapreg_intsub); // [zBuffer]
  2853. mapregstr_db->foreach(mapregstr_db,script_save_mapreg_strsub);
  2854. perfomance = ((unsigned int)time(NULL) - perfomance);
  2855. if(perfomance > 2)
  2856. ShowWarning("Slow Query: MapregSQL Saving @ %d second(s).\n", perfomance);
  2857. #endif
  2858. mapreg_dirty=0;
  2859. return 0;
  2860. }
  2861. static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
  2862. {
  2863. if(mapreg_dirty)
  2864. if (script_save_mapreg() == -1)
  2865. ShowError("Failed to save the mapreg data!\n");
  2866. return 0;
  2867. }
  2868. /*==========================================
  2869. *
  2870. *------------------------------------------
  2871. */
  2872. static int set_posword(char *p)
  2873. {
  2874. char* np,* str[15];
  2875. int i=0;
  2876. for(i=0;i<11;i++) {
  2877. if((np=strchr(p,','))!=NULL) {
  2878. str[i]=p;
  2879. *np=0;
  2880. p=np+1;
  2881. } else {
  2882. str[i]=p;
  2883. p+=strlen(p);
  2884. }
  2885. if(str[i])
  2886. strcpy(pos[i],str[i]);
  2887. }
  2888. return 0;
  2889. }
  2890. int script_config_read_sub(char *cfgName)
  2891. {
  2892. int i;
  2893. char line[1024],w1[1024],w2[1024];
  2894. FILE *fp;
  2895. fp=fopen(cfgName,"r");
  2896. if(fp==NULL){
  2897. ShowError("file not found: [%s]\n", cfgName);
  2898. return 1;
  2899. }
  2900. while(fgets(line,sizeof(line)-1,fp)){
  2901. if(line[0] == '/' && line[1] == '/')
  2902. continue;
  2903. i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
  2904. if(i!=2)
  2905. continue;
  2906. if(strcmpi(w1,"refine_posword")==0) {
  2907. set_posword(w2);
  2908. }
  2909. else if(strcmpi(w1,"verbose_mode")==0) {
  2910. script_config.verbose_mode = battle_config_switch(w2);
  2911. }
  2912. else if(strcmpi(w1,"warn_func_no_comma")==0) {
  2913. script_config.warn_func_no_comma = battle_config_switch(w2);
  2914. }
  2915. else if(strcmpi(w1,"warn_cmd_no_comma")==0) {
  2916. script_config.warn_cmd_no_comma = battle_config_switch(w2);
  2917. }
  2918. else if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
  2919. script_config.warn_func_mismatch_paramnum = battle_config_switch(w2);
  2920. }
  2921. else if(strcmpi(w1,"warn_cmd_mismatch_paramnum")==0) {
  2922. script_config.warn_cmd_mismatch_paramnum = battle_config_switch(w2);
  2923. }
  2924. else if(strcmpi(w1,"check_cmdcount")==0) {
  2925. script_config.check_cmdcount = battle_config_switch(w2);
  2926. }
  2927. else if(strcmpi(w1,"check_gotocount")==0) {
  2928. script_config.check_gotocount = battle_config_switch(w2);
  2929. }
  2930. else if(strcmpi(w1,"event_script_type")==0) {
  2931. script_config.event_script_type = battle_config_switch(w2);
  2932. }
  2933. else if(strcmpi(w1,"event_requires_trigger")==0) {
  2934. script_config.event_requires_trigger = battle_config_switch(w2);
  2935. }
  2936. else if(strcmpi(w1,"die_event_name")==0) {
  2937. strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
  2938. if (strlen(script_config.die_event_name) != strlen(w2))
  2939. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
  2940. }
  2941. else if(strcmpi(w1,"kill_pc_event_name")==0) {
  2942. strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
  2943. if (strlen(script_config.kill_pc_event_name) != strlen(w2))
  2944. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
  2945. }
  2946. else if(strcmpi(w1,"kill_mob_event_name")==0) {
  2947. strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
  2948. if (strlen(script_config.kill_mob_event_name) != strlen(w2))
  2949. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
  2950. }
  2951. else if(strcmpi(w1,"login_event_name")==0) {
  2952. strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
  2953. if (strlen(script_config.login_event_name) != strlen(w2))
  2954. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
  2955. }
  2956. else if(strcmpi(w1,"logout_event_name")==0) {
  2957. strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
  2958. if (strlen(script_config.logout_event_name) != strlen(w2))
  2959. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
  2960. }
  2961. else if(strcmpi(w1,"loadmap_event_name")==0) {
  2962. strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
  2963. if (strlen(script_config.loadmap_event_name) != strlen(w2))
  2964. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
  2965. }
  2966. else if(strcmpi(w1,"baselvup_event_name")==0) {
  2967. strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
  2968. if (strlen(script_config.baselvup_event_name) != strlen(w2))
  2969. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
  2970. }
  2971. else if(strcmpi(w1,"joblvup_event_name")==0) {
  2972. strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
  2973. if (strlen(script_config.joblvup_event_name) != strlen(w2))
  2974. ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
  2975. }
  2976. else if(strcmpi(w1,"import")==0){
  2977. script_config_read_sub(w2);
  2978. }
  2979. }
  2980. fclose(fp);
  2981. return 0;
  2982. }
  2983. int script_config_read(char *cfgName)
  2984. { //Script related variables should be initialized once! [Skotlex]
  2985. malloc_set (&script_config, 0, sizeof(script_config));
  2986. script_config.verbose_mode = 0;
  2987. script_config.warn_func_no_comma = 1;
  2988. script_config.warn_cmd_no_comma = 1;
  2989. script_config.warn_func_mismatch_paramnum = 1;
  2990. script_config.warn_cmd_mismatch_paramnum = 1;
  2991. script_config.check_cmdcount = 65535;
  2992. script_config.check_gotocount = 2048;
  2993. script_config.event_script_type = 0;
  2994. script_config.event_requires_trigger = 1;
  2995. return script_config_read_sub(cfgName);
  2996. }
  2997. static int do_final_userfunc_sub (DBKey key,void *data,va_list ap)
  2998. {
  2999. struct script_code *code = (struct script_code *)data;
  3000. if(code){
  3001. script_free_vars( &code->script_vars );
  3002. aFree( code->script_buf );
  3003. }
  3004. return 0;
  3005. }
  3006. /*==========================================
  3007. * 終了
  3008. *------------------------------------------
  3009. */
  3010. int do_final_script()
  3011. {
  3012. if(mapreg_dirty>=0)
  3013. script_save_mapreg();
  3014. mapreg_db->destroy(mapreg_db,NULL);
  3015. mapregstr_db->destroy(mapregstr_db,NULL);
  3016. scriptlabel_db->destroy(scriptlabel_db,NULL);
  3017. userfunc_db->destroy(userfunc_db,do_final_userfunc_sub);
  3018. if(sleep_db) {
  3019. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3020. while(n) {
  3021. struct script_state *st = (struct script_state *)n->data;
  3022. script_free_stack(st->stack);
  3023. aFree(st);
  3024. n = n->next;
  3025. }
  3026. linkdb_final(&sleep_db);
  3027. }
  3028. if (str_data)
  3029. aFree(str_data);
  3030. if (str_buf)
  3031. aFree(str_buf);
  3032. return 0;
  3033. }
  3034. /*==========================================
  3035. * 初期化
  3036. *------------------------------------------
  3037. */
  3038. int do_init_script()
  3039. {
  3040. mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
  3041. mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
  3042. userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
  3043. scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA,50);
  3044. script_load_mapreg();
  3045. add_timer_func_list(script_autosave_mapreg,"script_autosave_mapreg");
  3046. add_timer_interval(gettick()+MAPREG_AUTOSAVE_INTERVAL,
  3047. script_autosave_mapreg,0,0,MAPREG_AUTOSAVE_INTERVAL);
  3048. return 0;
  3049. }
  3050. int script_reload()
  3051. {
  3052. if(mapreg_dirty>=0)
  3053. script_save_mapreg();
  3054. mapreg_db->clear(mapreg_db, NULL);
  3055. mapregstr_db->clear(mapregstr_db, NULL);
  3056. userfunc_db->clear(userfunc_db,do_final_userfunc_sub);
  3057. scriptlabel_db->clear(scriptlabel_db, NULL);
  3058. if(sleep_db) {
  3059. struct linkdb_node *n = (struct linkdb_node *)sleep_db;
  3060. while(n) {
  3061. struct script_state *st = (struct script_state *)n->data;
  3062. script_free_stack(st->stack);
  3063. aFree(st);
  3064. n = n->next;
  3065. }
  3066. linkdb_final(&sleep_db);
  3067. }
  3068. script_load_mapreg();
  3069. return 0;
  3070. }
  3071. int buildin_mes(struct script_state *st);
  3072. int buildin_goto(struct script_state *st);
  3073. int buildin_callsub(struct script_state *st);
  3074. int buildin_callfunc(struct script_state *st);
  3075. int buildin_return(struct script_state *st);
  3076. int buildin_getarg(struct script_state *st);
  3077. int buildin_next(struct script_state *st);
  3078. int buildin_close(struct script_state *st);
  3079. int buildin_close2(struct script_state *st);
  3080. int buildin_menu(struct script_state *st);
  3081. int buildin_rand(struct script_state *st);
  3082. int buildin_warp(struct script_state *st);
  3083. int buildin_areawarp(struct script_state *st);
  3084. int buildin_warpchar(struct script_state *st); // [LuzZza]
  3085. int buildin_warpparty(struct script_state *st); //[Fredzilla]
  3086. int buildin_warpguild(struct script_state *st); //[Fredzilla]
  3087. int buildin_heal(struct script_state *st);
  3088. int buildin_itemheal(struct script_state *st);
  3089. int buildin_percentheal(struct script_state *st);
  3090. int buildin_jobchange(struct script_state *st);
  3091. int buildin_jobname(struct script_state *st);
  3092. int buildin_input(struct script_state *st);
  3093. int buildin_setlook(struct script_state *st);
  3094. int buildin_set(struct script_state *st);
  3095. int buildin_setarray(struct script_state *st);
  3096. int buildin_cleararray(struct script_state *st);
  3097. int buildin_copyarray(struct script_state *st);
  3098. int buildin_getarraysize(struct script_state *st);
  3099. int buildin_deletearray(struct script_state *st);
  3100. int buildin_getelementofarray(struct script_state *st);
  3101. int buildin_getitem(struct script_state *st);
  3102. int buildin_getitem2(struct script_state *st);
  3103. int buildin_getnameditem(struct script_state *st);
  3104. int buildin_grouprandomitem(struct script_state *st);
  3105. int buildin_makeitem(struct script_state *st);
  3106. int buildin_delitem(struct script_state *st);
  3107. int buildin_delitem2(struct script_state *st);
  3108. int buildin_enableitemuse(struct script_state *st);
  3109. int buildin_disableitemuse(struct script_state *st);
  3110. int buildin_viewpoint(struct script_state *st);
  3111. int buildin_countitem(struct script_state *st);
  3112. int buildin_countitem2(struct script_state *st);
  3113. int buildin_checkweight(struct script_state *st);
  3114. int buildin_readparam(struct script_state *st);
  3115. int buildin_getcharid(struct script_state *st);
  3116. int buildin_getpartyname(struct script_state *st);
  3117. int buildin_getpartymember(struct script_state *st);
  3118. int buildin_getpartyleader(struct script_state *st);
  3119. int buildin_getguildname(struct script_state *st);
  3120. int buildin_getguildmaster(struct script_state *st);
  3121. int buildin_getguildmasterid(struct script_state *st);
  3122. int buildin_strcharinfo(struct script_state *st);
  3123. int buildin_getequipid(struct script_state *st);
  3124. int buildin_getequipname(struct script_state *st);
  3125. int buildin_getbrokenid(struct script_state *st); // [Valaris]
  3126. int buildin_repair(struct script_state *st); // [Valaris]
  3127. int buildin_getequipisequiped(struct script_state *st);
  3128. int buildin_getequipisenableref(struct script_state *st);
  3129. int buildin_getequipisidentify(struct script_state *st);
  3130. int buildin_getequiprefinerycnt(struct script_state *st);
  3131. int buildin_getequipweaponlv(struct script_state *st);
  3132. int buildin_getequippercentrefinery(struct script_state *st);
  3133. int buildin_successrefitem(struct script_state *st);
  3134. int buildin_failedrefitem(struct script_state *st);
  3135. int buildin_cutin(struct script_state *st);
  3136. int buildin_cutincard(struct script_state *st);
  3137. int buildin_statusup(struct script_state *st);
  3138. int buildin_statusup2(struct script_state *st);
  3139. int buildin_bonus(struct script_state *st);
  3140. int buildin_bonus2(struct script_state *st);
  3141. int buildin_bonus3(struct script_state *st);
  3142. int buildin_bonus4(struct script_state *st);
  3143. int buildin_skill(struct script_state *st);
  3144. int buildin_addtoskill(struct script_state *st); // [Valaris]
  3145. int buildin_guildskill(struct script_state *st);
  3146. int buildin_getskilllv(struct script_state *st);
  3147. int buildin_getgdskilllv(struct script_state *st);
  3148. int buildin_basicskillcheck(struct script_state *st);
  3149. int buildin_getgmlevel(struct script_state *st);
  3150. int buildin_end(struct script_state *st);
  3151. int buildin_checkoption(struct script_state *st);
  3152. int buildin_setoption(struct script_state *st);
  3153. int buildin_setcart(struct script_state *st);
  3154. int buildin_checkcart(struct script_state *st); // check cart [Valaris]
  3155. int buildin_setfalcon(struct script_state *st);
  3156. int buildin_checkfalcon(struct script_state *st); // check falcon [Valaris]
  3157. int buildin_setriding(struct script_state *st);
  3158. int buildin_checkriding(struct script_state *st); // check for pecopeco [Valaris]
  3159. int buildin_savepoint(struct script_state *st);
  3160. int buildin_gettimetick(struct script_state *st);
  3161. int buildin_gettime(struct script_state *st);
  3162. int buildin_gettimestr(struct script_state *st);
  3163. int buildin_openstorage(struct script_state *st);
  3164. int buildin_guildopenstorage(struct script_state *st);
  3165. int buildin_itemskill(struct script_state *st);
  3166. int buildin_produce(struct script_state *st);
  3167. int buildin_monster(struct script_state *st);
  3168. int buildin_areamonster(struct script_state *st);
  3169. int buildin_killmonster(struct script_state *st);
  3170. int buildin_killmonsterall(struct script_state *st);
  3171. int buildin_clone(struct script_state *st);
  3172. int buildin_doevent(struct script_state *st);
  3173. int buildin_donpcevent(struct script_state *st);
  3174. int buildin_addtimer(struct script_state *st);
  3175. int buildin_deltimer(struct script_state *st);
  3176. int buildin_addtimercount(struct script_state *st);
  3177. int buildin_initnpctimer(struct script_state *st);
  3178. int buildin_stopnpctimer(struct script_state *st);
  3179. int buildin_startnpctimer(struct script_state *st);
  3180. int buildin_setnpctimer(struct script_state *st);
  3181. int buildin_getnpctimer(struct script_state *st);
  3182. int buildin_attachnpctimer(struct script_state *st); // [celest]
  3183. int buildin_detachnpctimer(struct script_state *st); // [celest]
  3184. int buildin_playerattached(struct script_state *st); // [Skotlex]
  3185. int buildin_announce(struct script_state *st);
  3186. int buildin_mapannounce(struct script_state *st);
  3187. int buildin_areaannounce(struct script_state *st);
  3188. int buildin_getusers(struct script_state *st);
  3189. int buildin_getmapguildusers(struct script_state *st);
  3190. int buildin_getmapusers(struct script_state *st);
  3191. int buildin_getareausers(struct script_state *st);
  3192. int buildin_getareadropitem(struct script_state *st);
  3193. int buildin_enablenpc(struct script_state *st);
  3194. int buildin_disablenpc(struct script_state *st);
  3195. int buildin_enablearena(struct script_state *st); // Added by RoVeRT
  3196. int buildin_disablearena(struct script_state *st); // Added by RoVeRT
  3197. int buildin_hideoffnpc(struct script_state *st);
  3198. int buildin_hideonnpc(struct script_state *st);
  3199. int buildin_sc_start(struct script_state *st);
  3200. int buildin_sc_start2(struct script_state *st);
  3201. int buildin_sc_start4(struct script_state *st);
  3202. int buildin_sc_end(struct script_state *st);
  3203. int buildin_getscrate(struct script_state *st);
  3204. int buildin_debugmes(struct script_state *st);
  3205. int buildin_catchpet(struct script_state *st);
  3206. int buildin_birthpet(struct script_state *st);
  3207. int buildin_resetlvl(struct script_state *st);
  3208. int buildin_resetstatus(struct script_state *st);
  3209. int buildin_resetskill(struct script_state *st);
  3210. int buildin_skillpointcount(struct script_state *st);
  3211. int buildin_changebase(struct script_state *st);
  3212. int buildin_changesex(struct script_state *st);
  3213. int buildin_waitingroom(struct script_state *st);
  3214. int buildin_delwaitingroom(struct script_state *st);
  3215. int buildin_waitingroomkickall(struct script_state *st);
  3216. int buildin_enablewaitingroomevent(struct script_state *st);
  3217. int buildin_disablewaitingroomevent(struct script_state *st);
  3218. int buildin_getwaitingroomstate(struct script_state *st);
  3219. int buildin_warpwaitingpc(struct script_state *st);
  3220. int buildin_attachrid(struct script_state *st);
  3221. int buildin_detachrid(struct script_state *st);
  3222. int buildin_isloggedin(struct script_state *st);
  3223. int buildin_setmapflagnosave(struct script_state *st);
  3224. int buildin_setmapflag(struct script_state *st);
  3225. int buildin_removemapflag(struct script_state *st);
  3226. int buildin_pvpon(struct script_state *st);
  3227. int buildin_pvpoff(struct script_state *st);
  3228. int buildin_gvgon(struct script_state *st);
  3229. int buildin_gvgoff(struct script_state *st);
  3230. int buildin_emotion(struct script_state *st);
  3231. int buildin_maprespawnguildid(struct script_state *st);
  3232. int buildin_agitstart(struct script_state *st); // <Agit>
  3233. int buildin_agitend(struct script_state *st);
  3234. int buildin_agitcheck(struct script_state *st); // <Agitcheck>
  3235. int buildin_flagemblem(struct script_state *st); // Flag Emblem
  3236. int buildin_getcastlename(struct script_state *st);
  3237. int buildin_getcastledata(struct script_state *st);
  3238. int buildin_setcastledata(struct script_state *st);
  3239. int buildin_requestguildinfo(struct script_state *st);
  3240. int buildin_getequipcardcnt(struct script_state *st);
  3241. int buildin_successremovecards(struct script_state *st);
  3242. int buildin_failedremovecards(struct script_state *st);
  3243. int buildin_marriage(struct script_state *st);
  3244. int buildin_wedding_effect(struct script_state *st);
  3245. int buildin_divorce(struct script_state *st);
  3246. int buildin_ispartneron(struct script_state *st); // MouseJstr
  3247. int buildin_getpartnerid(struct script_state *st); // MouseJstr
  3248. int buildin_getchildid(struct script_state *st); // Skotlex
  3249. int buildin_getmotherid(struct script_state *st); // Lupus
  3250. int buildin_getfatherid(struct script_state *st); // Lupus
  3251. int buildin_warppartner(struct script_state *st); // MouseJstr
  3252. int buildin_getitemname(struct script_state *st);
  3253. int buildin_getitemslots(struct script_state *st);
  3254. int buildin_makepet(struct script_state *st);
  3255. int buildin_getexp(struct script_state *st);
  3256. int buildin_getinventorylist(struct script_state *st);
  3257. int buildin_getskilllist(struct script_state *st);
  3258. int buildin_clearitem(struct script_state *st);
  3259. int buildin_classchange(struct script_state *st);
  3260. int buildin_misceffect(struct script_state *st);
  3261. int buildin_soundeffect(struct script_state *st);
  3262. int buildin_soundeffectall(struct script_state *st);
  3263. int buildin_setcastledata(struct script_state *st);
  3264. int buildin_mapwarp(struct script_state *st);
  3265. int buildin_inittimer(struct script_state *st);
  3266. int buildin_stoptimer(struct script_state *st);
  3267. int buildin_cmdothernpc(struct script_state *st);
  3268. int buildin_mobcount(struct script_state *st);
  3269. int buildin_strmobinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3270. int buildin_guardian(struct script_state *st); // Script for displaying mob info [Valaris]
  3271. int buildin_guardianinfo(struct script_state *st); // Script for displaying mob info [Valaris]
  3272. int buildin_petskillbonus(struct script_state *st); // petskillbonus [Valaris]
  3273. int buildin_petrecovery(struct script_state *st); // pet skill for curing status [Valaris]
  3274. int buildin_petloot(struct script_state *st); // pet looting [Valaris]
  3275. int buildin_petheal(struct script_state *st); // pet healing [Valaris]
  3276. //int buildin_petmag(struct script_state *st); // pet magnificat [Valaris]
  3277. int buildin_petskillattack(struct script_state *st); // pet skill attacks [Skotlex]
  3278. int buildin_petskillattack2(struct script_state *st); // pet skill attacks [Skotlex]
  3279. int buildin_petskillsupport(struct script_state *st); // pet support skill [Valaris]
  3280. int buildin_skilleffect(struct script_state *st); // skill effects [Celest]
  3281. int buildin_npcskilleffect(struct script_state *st); // skill effects for npcs [Valaris]
  3282. int buildin_specialeffect(struct script_state *st); // special effect script [Valaris]
  3283. int buildin_specialeffect2(struct script_state *st); // special effect script [Valaris]
  3284. int buildin_nude(struct script_state *st); // nude [Valaris]
  3285. int buildin_atcommand(struct script_state *st); // [MouseJstr]
  3286. int buildin_charcommand(struct script_state *st); // [MouseJstr]
  3287. int buildin_movenpc(struct script_state *st); // [MouseJstr]
  3288. int buildin_message(struct script_state *st); // [MouseJstr]
  3289. int buildin_npctalk(struct script_state *st); // [Valaris]
  3290. int buildin_hasitems(struct script_state *st); // [Valaris]
  3291. int buildin_getlook(struct script_state *st); //Lorky [Lupus]
  3292. int buildin_getsavepoint(struct script_state *st); //Lorky [Lupus]
  3293. int buildin_npcspeed(struct script_state *st); // [Valaris]
  3294. int buildin_npcwalkto(struct script_state *st); // [Valaris]
  3295. int buildin_npcstop(struct script_state *st); // [Valaris]
  3296. int buildin_getmapxy(struct script_state *st); //get map position for player/npc/pet/mob by Lorky [Lupus]
  3297. int buildin_checkoption1(struct script_state *st); // [celest]
  3298. int buildin_checkoption2(struct script_state *st); // [celest]
  3299. int buildin_guildgetexp(struct script_state *st); // [celest]
  3300. int buildin_guildchangegm(struct script_state *st); // [Skotlex]
  3301. int buildin_logmes(struct script_state *st); // [Lupus]
  3302. int buildin_summon(struct script_state *st); // [celest]
  3303. int buildin_isnight(struct script_state *st); // [celest]
  3304. int buildin_isday(struct script_state *st); // [celest]
  3305. int buildin_isequipped(struct script_state *st); // [celest]
  3306. int buildin_isequippedcnt(struct script_state *st); // [celest]
  3307. int buildin_cardscnt(struct script_state *st); // [Lupus]
  3308. int buildin_getrefine(struct script_state *st); // [celest]
  3309. int buildin_adopt(struct script_state *st);
  3310. int buildin_night(struct script_state *st);
  3311. int buildin_day(struct script_state *st);
  3312. int buildin_getusersname(struct script_state *st); //jA commands added [Lupus]
  3313. int buildin_dispbottom(struct script_state *st);
  3314. int buildin_recovery(struct script_state *st);
  3315. int buildin_getpetinfo(struct script_state *st);
  3316. int buildin_checkequipedcard(struct script_state *st);
  3317. int buildin_globalmes(struct script_state *st);
  3318. int buildin_jump_zero(struct script_state *st);
  3319. int buildin_select(struct script_state *st);
  3320. int buildin_prompt(struct script_state *st);
  3321. int buildin_getmapmobs(struct script_state *st); //jA addition end
  3322. int buildin_unequip(struct script_state *st); // unequip [Spectre]
  3323. int buildin_getstrlen(struct script_state *st); //strlen [valaris]
  3324. int buildin_charisalpha(struct script_state *st);//isalpha [valaris]
  3325. int buildin_fakenpcname(struct script_state *st); // [Lance]
  3326. int buildin_compare(struct script_state *st); // Lordalfa, to bring strstr to Scripting Engine
  3327. int buildin_getiteminfo(struct script_state *st); //[Lupus] returns Items Buy / sell Price, etc info
  3328. int buildin_getequipcardid(struct script_state *st); //[Lupus] returns card id from quipped item card slot N
  3329. // [zBuffer] List of mathematics commands --->
  3330. int buildin_sqrt(struct script_state *st);
  3331. int buildin_pow(struct script_state *st);
  3332. int buildin_distance(struct script_state *st);
  3333. int buildin_checkcell(struct script_state *st);
  3334. // <--- [zBuffer] List of mathematics commands
  3335. // [zBuffer] List of dynamic var commands --->
  3336. int buildin_getd(struct script_state *st);
  3337. int buildin_setd(struct script_state *st);
  3338. // <--- [zBuffer] List of dynamic var commands
  3339. int buildin_petstat(struct script_state *st); // [Lance] Pet Stat Rq: Dubby
  3340. int buildin_callshop(struct script_state *st); // [Skotlex]
  3341. int buildin_npcshopitem(struct script_state *st); // [Lance]
  3342. int buildin_npcshopadditem(struct script_state *st);
  3343. int buildin_npcshopdelitem(struct script_state *st);
  3344. int buildin_equip(struct script_state *st);
  3345. int buildin_autoequip(struct script_state *st);
  3346. int buildin_setbattleflag(struct script_state *st);
  3347. int buildin_getbattleflag(struct script_state *st);
  3348. int buildin_query_sql(struct script_state *st);
  3349. int buildin_escape_sql(struct script_state *st);
  3350. int buildin_atoi(struct script_state *st);
  3351. int buildin_axtoi(struct script_state *st);
  3352. // [zBuffer] List of player cont commands --->
  3353. int buildin_rid2name(struct script_state *st);
  3354. int buildin_pcfollow(struct script_state *st);
  3355. int buildin_pcstopfollow(struct script_state *st);
  3356. int buildin_pcblockmove(struct script_state *st);
  3357. // <--- [zBuffer] List of player cont commands
  3358. // [zBuffer] List of mob control commands --->
  3359. int buildin_mobspawn(struct script_state *st);
  3360. int buildin_mobremove(struct script_state *st);
  3361. int buildin_getmobdata(struct script_state *st);
  3362. int buildin_setmobdata(struct script_state *st);
  3363. int buildin_mobassist(struct script_state *st);
  3364. int buildin_mobattach(struct script_state *st);
  3365. int buildin_unitwalk(struct script_state *st);
  3366. int buildin_unitkill(struct script_state *st);
  3367. int buildin_unitwarp(struct script_state *st);
  3368. int buildin_unitattack(struct script_state *st);
  3369. int buildin_unitstop(struct script_state *st);
  3370. int buildin_unittalk(struct script_state *st);
  3371. int buildin_unitemote(struct script_state *st);
  3372. int buildin_unitdeadsit(struct script_state *st);
  3373. int buildin_unitskilluseid(struct script_state *st); // originally by Qamera [celest]
  3374. int buildin_unitskillusepos(struct script_state *st); // originally by Qamera [celest]
  3375. // <--- [zBuffer] List of mob control commands
  3376. int buildin_sleep(struct script_state *st);
  3377. int buildin_sleep2(struct script_state *st);
  3378. int buildin_awake(struct script_state *st);
  3379. int buildin_getvariableofnpc(struct script_state *st);
  3380. // [blackhole89] -->
  3381. int buildin_warpportal(struct script_state *st);
  3382. // <-- [blackhole89]
  3383. int buildin_homunculus_evolution(struct script_state *st) ; //[orn]
  3384. int buildin_eaclass(struct script_state *st);
  3385. int buildin_roclass(struct script_state *st);
  3386. int buildin_setitemscript(struct script_state *st);
  3387. int buildin_disguise(struct script_state *st);
  3388. int buildin_undisguise(struct script_state *st);
  3389. int buildin_getmonsterinfo(struct script_state *st); // [Lupus]
  3390. int buildin_checkvending(struct script_state *st); // check vending [Nab4]
  3391. int buildin_checkchatting(struct script_state *st); // check chatting [Marka]
  3392. #ifdef PCRE_SUPPORT
  3393. int buildin_defpattern(struct script_state *st); // MouseJstr
  3394. int buildin_activatepset(struct script_state *st); // MouseJstr
  3395. int buildin_deactivatepset(struct script_state *st); // MouseJstr
  3396. int buildin_deletepset(struct script_state *st); // MouseJstr
  3397. #endif
  3398. struct script_function buildin_func[] = {
  3399. {buildin_mes,"mes","s"},
  3400. {buildin_next,"next",""},
  3401. {buildin_close,"close",""},
  3402. {buildin_close2,"close2",""},
  3403. {buildin_menu,"menu","*"},
  3404. {buildin_goto,"goto","l"},
  3405. {buildin_callsub,"callsub","i*"},
  3406. {buildin_callfunc,"callfunc","s*"},
  3407. {buildin_return,"return","*"},
  3408. {buildin_getarg,"getarg","i"},
  3409. {buildin_jobchange,"jobchange","i*"},
  3410. {buildin_jobname,"jobname","i"},
  3411. {buildin_input,"input","*"},
  3412. {buildin_warp,"warp","sii"},
  3413. {buildin_areawarp,"areawarp","siiiisii"},
  3414. {buildin_warpchar,"warpchar","siii"}, // [LuzZza]
  3415. {buildin_warpparty,"warpparty","siii"}, // [Fredzilla]
  3416. {buildin_warpguild,"warpguild","siii"}, // [Fredzilla]
  3417. {buildin_setlook,"setlook","ii"},
  3418. {buildin_set,"set","ii"},
  3419. {buildin_setarray,"setarray","ii*"},
  3420. {buildin_cleararray,"cleararray","iii"},
  3421. {buildin_copyarray,"copyarray","iii"},
  3422. {buildin_getarraysize,"getarraysize","i"},
  3423. {buildin_deletearray,"deletearray","ii"},
  3424. {buildin_getelementofarray,"getelementofarray","ii"},
  3425. {buildin_getitem,"getitem","ii**"},
  3426. {buildin_getitem2,"getitem2","iiiiiiiii*"},
  3427. {buildin_getnameditem,"getnameditem","is"},
  3428. {buildin_grouprandomitem,"groupranditem","i"},
  3429. {buildin_makeitem,"makeitem","iisii"},
  3430. {buildin_delitem,"delitem","ii"},
  3431. {buildin_delitem2,"delitem2","iiiiiiiii"},
  3432. {buildin_enableitemuse,"enable_items",""},
  3433. {buildin_disableitemuse,"disable_items",""},
  3434. {buildin_cutin,"cutin","si"},
  3435. {buildin_cutincard,"cutincard","i"},
  3436. {buildin_viewpoint,"viewpoint","iiiii"},
  3437. {buildin_heal,"heal","ii"},
  3438. {buildin_itemheal,"itemheal","ii"},
  3439. {buildin_percentheal,"percentheal","ii"},
  3440. {buildin_rand,"rand","i*"},
  3441. {buildin_countitem,"countitem","i"},
  3442. {buildin_countitem2,"countitem2","iiiiiiii"},
  3443. {buildin_checkweight,"checkweight","ii"},
  3444. {buildin_readparam,"readparam","i*"},
  3445. {buildin_getcharid,"getcharid","i*"},
  3446. {buildin_getpartyname,"getpartyname","i"},
  3447. {buildin_getpartymember,"getpartymember","i*"},
  3448. {buildin_getpartyleader,"getpartyleader","i*"},
  3449. {buildin_getguildname,"getguildname","i"},
  3450. {buildin_getguildmaster,"getguildmaster","i"},
  3451. {buildin_getguildmasterid,"getguildmasterid","i"},
  3452. {buildin_strcharinfo,"strcharinfo","i"},
  3453. {buildin_getequipid,"getequipid","i"},
  3454. {buildin_getequipname,"getequipname","i"},
  3455. {buildin_getbrokenid,"getbrokenid","i"}, // [Valaris]
  3456. {buildin_repair,"repair","i"}, // [Valaris]
  3457. {buildin_getequipisequiped,"getequipisequiped","i"},
  3458. {buildin_getequipisenableref,"getequipisenableref","i"},
  3459. {buildin_getequipisidentify,"getequipisidentify","i"},
  3460. {buildin_getequiprefinerycnt,"getequiprefinerycnt","i"},
  3461. {buildin_getequipweaponlv,"getequipweaponlv","i"},
  3462. {buildin_getequippercentrefinery,"getequippercentrefinery","i"},
  3463. {buildin_successrefitem,"successrefitem","i"},
  3464. {buildin_failedrefitem,"failedrefitem","i"},
  3465. {buildin_statusup,"statusup","i"},
  3466. {buildin_statusup2,"statusup2","ii"},
  3467. {buildin_bonus,"bonus","ii"},
  3468. {buildin_bonus2,"bonus2","iii"},
  3469. {buildin_bonus3,"bonus3","iiii"},
  3470. {buildin_bonus4,"bonus4","iiiii"},
  3471. {buildin_skill,"skill","ii*"},
  3472. {buildin_addtoskill,"addtoskill","ii*"}, // [Valaris]
  3473. {buildin_guildskill,"guildskill","ii"},
  3474. {buildin_getskilllv,"getskilllv","i"},
  3475. {buildin_getgdskilllv,"getgdskilllv","ii"},
  3476. {buildin_basicskillcheck,"basicskillcheck","*"},
  3477. {buildin_getgmlevel,"getgmlevel","*"},
  3478. {buildin_end,"end",""},
  3479. // {buildin_end,"break",""}, this might confuse advanced scripting support [Eoe]
  3480. {buildin_checkoption,"checkoption","i"},
  3481. {buildin_setoption,"setoption","i*"},
  3482. {buildin_setcart,"setcart",""},
  3483. {buildin_checkcart,"checkcart","*"}, //fixed by Lupus (added '*')
  3484. {buildin_setfalcon,"setfalcon",""},
  3485. {buildin_checkfalcon,"checkfalcon","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3486. {buildin_setriding,"setriding",""},
  3487. {buildin_checkriding,"checkriding","*"}, //fixed by Lupus (fixed wrong pointer, added '*')
  3488. {buildin_savepoint,"save","sii"},
  3489. {buildin_savepoint,"savepoint","sii"},
  3490. {buildin_gettimetick,"gettimetick","i"},
  3491. {buildin_gettime,"gettime","i"},
  3492. {buildin_gettimestr,"gettimestr","si"},
  3493. {buildin_openstorage,"openstorage",""},
  3494. {buildin_guildopenstorage,"guildopenstorage","*"},
  3495. {buildin_itemskill,"itemskill","iis"},
  3496. {buildin_produce,"produce","i"},
  3497. {buildin_monster,"monster","siisii*"},
  3498. {buildin_areamonster,"areamonster","siiiisii*"},
  3499. {buildin_killmonster,"killmonster","ss"},
  3500. {buildin_killmonsterall,"killmonsterall","s"},
  3501. {buildin_clone,"clone","siisi*"},
  3502. {buildin_doevent,"doevent","s"},
  3503. {buildin_donpcevent,"donpcevent","s"},
  3504. {buildin_addtimer,"addtimer","is"},
  3505. {buildin_deltimer,"deltimer","s"},
  3506. {buildin_addtimercount,"addtimercount","si"},
  3507. {buildin_initnpctimer,"initnpctimer","*"},
  3508. {buildin_stopnpctimer,"stopnpctimer","*"},
  3509. {buildin_startnpctimer,"startnpctimer","*"},
  3510. {buildin_setnpctimer,"setnpctimer","*"},
  3511. {buildin_getnpctimer,"getnpctimer","i*"},
  3512. {buildin_attachnpctimer,"attachnpctimer","*"}, // attached the player id to the npc timer [Celest]
  3513. {buildin_detachnpctimer,"detachnpctimer","*"}, // detached the player id from the npc timer [Celest]
  3514. {buildin_playerattached,"playerattached",""}, // returns id of the current attached player. [Skotlex]
  3515. {buildin_announce,"announce","si*"},
  3516. {buildin_mapannounce,"mapannounce","ssi*"},
  3517. {buildin_areaannounce,"areaannounce","siiiisi*"},
  3518. {buildin_getusers,"getusers","i"},
  3519. {buildin_getmapguildusers,"getmapguildusers","si"},
  3520. {buildin_getmapusers,"getmapusers","s"},
  3521. {buildin_getareausers,"getareausers","siiii"},
  3522. {buildin_getareadropitem,"getareadropitem","siiiii"},
  3523. {buildin_enablenpc,"enablenpc","s"},
  3524. {buildin_disablenpc,"disablenpc","s"},
  3525. {buildin_enablearena,"enablearena",""}, // Added by RoVeRT
  3526. {buildin_disablearena,"disablearena",""}, // Added by RoVeRT
  3527. {buildin_hideoffnpc,"hideoffnpc","s"},
  3528. {buildin_hideonnpc,"hideonnpc","s"},
  3529. {buildin_sc_start,"sc_start","iii*"},
  3530. {buildin_sc_start2,"sc_start2","iiii*"},
  3531. {buildin_sc_start4,"sc_start4","iiiiii*"},
  3532. {buildin_sc_end,"sc_end","i"},
  3533. {buildin_getscrate,"getscrate","ii*"},
  3534. {buildin_debugmes,"debugmes","s"},
  3535. {buildin_catchpet,"pet","i"},
  3536. {buildin_birthpet,"bpet",""},
  3537. {buildin_resetlvl,"resetlvl","i"},
  3538. {buildin_resetstatus,"resetstatus",""},
  3539. {buildin_resetskill,"resetskill",""},
  3540. {buildin_skillpointcount,"skillpointcount",""},
  3541. {buildin_changebase,"changebase","i"},
  3542. {buildin_changesex,"changesex",""},
  3543. {buildin_waitingroom,"waitingroom","si*"},
  3544. {buildin_warpwaitingpc,"warpwaitingpc","sii"},
  3545. {buildin_delwaitingroom,"delwaitingroom","*"},
  3546. {buildin_waitingroomkickall,"kickwaitingroomall","*"},
  3547. {buildin_enablewaitingroomevent,"enablewaitingroomevent","*"},
  3548. {buildin_disablewaitingroomevent,"disablewaitingroomevent","*"},
  3549. {buildin_getwaitingroomstate,"getwaitingroomstate","i*"},
  3550. {buildin_warpwaitingpc,"warpwaitingpc","sii*"},
  3551. {buildin_attachrid,"attachrid","i"},
  3552. {buildin_detachrid,"detachrid",""},
  3553. {buildin_isloggedin,"isloggedin","i"},
  3554. {buildin_setmapflagnosave,"setmapflagnosave","ssii"},
  3555. {buildin_setmapflag,"setmapflag","si*"},
  3556. {buildin_removemapflag,"removemapflag","si"},
  3557. {buildin_pvpon,"pvpon","s"},
  3558. {buildin_pvpoff,"pvpoff","s"},
  3559. {buildin_gvgon,"gvgon","s"},
  3560. {buildin_gvgoff,"gvgoff","s"},
  3561. {buildin_emotion,"emotion","i*"},
  3562. {buildin_maprespawnguildid,"maprespawnguildid","sii"},
  3563. {buildin_agitstart,"agitstart",""}, // <Agit>
  3564. {buildin_agitend,"agitend",""},
  3565. {buildin_agitcheck,"agitcheck",""}, // <Agitcheck>
  3566. {buildin_flagemblem,"flagemblem","i"}, // Flag Emblem
  3567. {buildin_getcastlename,"getcastlename","s"},
  3568. {buildin_getcastledata,"getcastledata","si*"},
  3569. {buildin_setcastledata,"setcastledata","sii"},
  3570. {buildin_requestguildinfo,"requestguildinfo","i*"},
  3571. {buildin_getequipcardcnt,"getequipcardcnt","i"},
  3572. {buildin_successremovecards,"successremovecards","i"},
  3573. {buildin_failedremovecards,"failedremovecards","ii"},
  3574. {buildin_marriage,"marriage","s"},
  3575. {buildin_wedding_effect,"wedding",""},
  3576. {buildin_divorce,"divorce",""},
  3577. {buildin_ispartneron,"ispartneron",""},
  3578. {buildin_getpartnerid,"getpartnerid",""},
  3579. {buildin_getchildid,"getchildid",""},
  3580. {buildin_getmotherid,"getmotherid",""},
  3581. {buildin_getfatherid,"getfatherid",""},
  3582. {buildin_warppartner,"warppartner","sii"},
  3583. {buildin_getitemname,"getitemname","i"},
  3584. {buildin_getitemslots,"getitemslots","i"},
  3585. {buildin_makepet,"makepet","i"},
  3586. {buildin_getexp,"getexp","ii"},
  3587. {buildin_getinventorylist,"getinventorylist",""},
  3588. {buildin_getskilllist,"getskilllist",""},
  3589. {buildin_clearitem,"clearitem",""},
  3590. {buildin_classchange,"classchange","ii"},
  3591. {buildin_misceffect,"misceffect","i"},
  3592. {buildin_soundeffect,"soundeffect","si"},
  3593. {buildin_soundeffectall,"soundeffectall","si*"}, // SoundEffectAll [Codemaster]
  3594. {buildin_strmobinfo,"strmobinfo","ii"}, // display mob data [Valaris]
  3595. {buildin_guardian,"guardian","siisii*i"}, // summon guardians
  3596. {buildin_guardianinfo,"guardianinfo","i"}, // display guardian data [Valaris]
  3597. {buildin_petskillbonus,"petskillbonus","iiii"}, // [Valaris]
  3598. {buildin_petrecovery,"petrecovery","ii"}, // [Valaris]
  3599. {buildin_petloot,"petloot","i"}, // [Valaris]
  3600. {buildin_petheal,"petheal","iiii"}, // [Valaris]
  3601. // {buildin_petmag,"petmag","iiii"}, // [Valaris]
  3602. {buildin_petskillattack,"petskillattack","iiii"}, // [Skotlex]
  3603. {buildin_petskillattack2,"petskillattack2","iiiii"}, // [Valaris]
  3604. {buildin_petskillsupport,"petskillsupport","iiiii"}, // [Skotlex]
  3605. {buildin_skilleffect,"skilleffect","ii"}, // skill effect [Celest]
  3606. {buildin_npcskilleffect,"npcskilleffect","iiii"}, // npc skill effect [Valaris]
  3607. {buildin_specialeffect,"specialeffect","i*"}, // npc skill effect [Valaris]
  3608. {buildin_specialeffect2,"specialeffect2","i*"}, // skill effect on players[Valaris]
  3609. {buildin_nude,"nude",""}, // nude command [Valaris]
  3610. {buildin_mapwarp,"mapwarp","ssii*"}, // Added by RoVeRT
  3611. {buildin_inittimer,"inittimer",""},
  3612. {buildin_stoptimer,"stoptimer",""},
  3613. {buildin_cmdothernpc,"cmdothernpc","ss"},
  3614. {buildin_atcommand,"atcommand","*"}, // [MouseJstr]
  3615. {buildin_charcommand,"charcommand","*"}, // [MouseJstr]
  3616. {buildin_movenpc,"movenpc","sii"}, // [MouseJstr]
  3617. {buildin_message,"message","s*"}, // [MouseJstr]
  3618. {buildin_npctalk,"npctalk","*"}, // [Valaris]
  3619. {buildin_hasitems,"hasitems","*"}, // [Valaris]
  3620. {buildin_mobcount,"mobcount","ss"},
  3621. {buildin_getlook,"getlook","i"},
  3622. {buildin_getsavepoint,"getsavepoint","i"},
  3623. {buildin_npcspeed,"npcspeed","i"}, // [Valaris]
  3624. {buildin_npcwalkto,"npcwalkto","ii"}, // [Valaris]
  3625. {buildin_npcstop,"npcstop",""}, // [Valaris]
  3626. {buildin_getmapxy,"getmapxy","siii*"}, //by Lorky [Lupus]
  3627. {buildin_checkoption1,"checkoption1","i"},
  3628. {buildin_checkoption2,"checkoption2","i"},
  3629. {buildin_guildgetexp,"guildgetexp","i"},
  3630. {buildin_guildchangegm,"guildchangegm","is"},
  3631. {buildin_logmes,"logmes","s"}, //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
  3632. {buildin_summon,"summon","si*"}, // summons a slave monster [Celest]
  3633. {buildin_isnight,"isnight",""}, // check whether it is night time [Celest]
  3634. {buildin_isday,"isday",""}, // check whether it is day time [Celest]
  3635. {buildin_isequipped,"isequipped","i*"}, // check whether another item/card has been equipped [Celest]
  3636. {buildin_isequippedcnt,"isequippedcnt","i*"}, // check how many items/cards are being equipped [Celest]
  3637. {buildin_cardscnt,"cardscnt","i*"}, // check how many items/cards are being equipped in the same arm [Lupus]
  3638. {buildin_getrefine,"getrefine","*"}, // returns the refined number of the current item, or an item with index specified [celest]
  3639. {buildin_adopt,"adopt","sss"}, // allows 2 parents to adopt a child
  3640. {buildin_night,"night",""}, // sets the server to night time
  3641. {buildin_day,"day",""}, // sets the server to day time
  3642. #ifdef PCRE_SUPPORT
  3643. {buildin_defpattern, "defpattern", "iss"}, // Define pattern to listen for [MouseJstr]
  3644. {buildin_activatepset, "activatepset", "i"}, // Activate a pattern set [MouseJstr]
  3645. {buildin_deactivatepset, "deactivatepset", "i"}, // Deactive a pattern set [MouseJstr]
  3646. {buildin_deletepset, "deletepset", "i"}, // Delete a pattern set [MouseJstr]
  3647. #endif
  3648. {buildin_dispbottom,"dispbottom","s"}, //added from jA [Lupus]
  3649. {buildin_getusersname,"getusersname","*"},
  3650. {buildin_recovery,"recovery",""},
  3651. {buildin_getpetinfo,"getpetinfo","i"},
  3652. {buildin_checkequipedcard,"checkequipedcard","i"},
  3653. {buildin_jump_zero,"jump_zero","ii"}, //for future jA script compatibility
  3654. {buildin_select,"select","*"}, //for future jA script compatibility
  3655. {buildin_prompt,"prompt","*"},
  3656. {buildin_globalmes,"globalmes","s*"},
  3657. {buildin_getmapmobs,"getmapmobs","s"}, //end jA addition
  3658. {buildin_unequip,"unequip","i"}, // unequip command [Spectre]
  3659. {buildin_getstrlen,"getstrlen","s"}, //strlen [Valaris]
  3660. {buildin_charisalpha,"charisalpha","si"}, //isalpha [Valaris]
  3661. {buildin_fakenpcname,"fakenpcname","ssi"}, // [Lance]
  3662. {buildin_compare,"compare","ss"}, // Lordalfa - To bring strstr to scripting Engine.
  3663. {buildin_getiteminfo,"getiteminfo","ii"}, //[Lupus] returns Items Buy / sell Price, etc info
  3664. {buildin_getequipcardid,"getequipcardid","ii"}, //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
  3665. // [zBuffer] List of mathematics commands --->
  3666. {buildin_sqrt,"sqrt","i"},
  3667. {buildin_pow,"pow","ii"},
  3668. {buildin_distance,"distance","iiii"},
  3669. {buildin_checkcell,"checkcell","siii"},
  3670. // <--- [zBuffer] List of mathematics commands
  3671. // [zBuffer] List of dynamic var commands --->
  3672. {buildin_getd,"getd","*"},
  3673. {buildin_setd,"setd","*"},
  3674. // <--- [zBuffer] List of dynamic var commands
  3675. {buildin_petstat,"petstat","i"},
  3676. {buildin_callshop,"callshop","si"}, // [Skotlex]
  3677. {buildin_npcshopitem,"npcshopitem","sii*"}, // [Lance]
  3678. {buildin_npcshopadditem,"npcshopadditem","sii*"},
  3679. {buildin_npcshopdelitem,"npcshopdelitem","si*"},
  3680. {buildin_equip,"equip","i"},
  3681. {buildin_autoequip,"autoequip","ii"},
  3682. {buildin_setbattleflag,"setbattleflag","ss"},
  3683. {buildin_getbattleflag,"getbattleflag","s"},
  3684. {buildin_setitemscript,"setitemscript","is"}, //Set NEW item bonus script. Lupus
  3685. {buildin_disguise,"disguise","i"}, //disguise player. Lupus
  3686. {buildin_undisguise,"undisguise","*"}, //undisguise player. Lupus
  3687. {buildin_getmonsterinfo,"getmonsterinfo","ii"}, //Lupus
  3688. {buildin_axtoi,"axtoi","s"},
  3689. {buildin_query_sql, "query_sql", "s*"},
  3690. {buildin_escape_sql, "escape_sql", "s"},
  3691. {buildin_atoi,"atoi","s"},
  3692. // [zBuffer] List of player cont commands --->
  3693. {buildin_rid2name,"rid2name","i"},
  3694. {buildin_pcfollow,"pcfollow","ii"},
  3695. {buildin_pcstopfollow,"pcstopfollow","i"},
  3696. {buildin_pcblockmove,"pcblockmove","ii"},
  3697. // <--- [zBuffer] List of player cont commands
  3698. // [zBuffer] List of mob control commands --->
  3699. {buildin_mobspawn,"mobspawn","*"},
  3700. {buildin_mobremove,"mobremove","i"},
  3701. {buildin_getmobdata,"getmobdata","i*"},
  3702. {buildin_setmobdata,"setmobdata","iii"},
  3703. {buildin_mobassist,"mobassist","i*"},
  3704. {buildin_mobattach,"mobattach","i*"},
  3705. {buildin_unitwalk,"unitwalk","i*"},
  3706. {buildin_unitkill,"unitkill","i"},
  3707. {buildin_unitwarp,"unitwarp","isii"},
  3708. {buildin_unitattack,"unitattack","i*"},
  3709. {buildin_unitstop,"unitstop","i"},
  3710. {buildin_unittalk,"unittalk","is"},
  3711. {buildin_unitemote,"unitemote","ii"},
  3712. {buildin_unitdeadsit,"unitdeadsit","ii"},
  3713. {buildin_unitskilluseid,"unitskilluseid","iii*"}, // originally by Qamera [Celest]
  3714. {buildin_unitskillusepos,"unitskillusepos","iiiii"}, // [Celest]
  3715. // <--- [zBuffer] List of mob control commands
  3716. {buildin_sleep,"sleep","i"},
  3717. {buildin_sleep2,"sleep2","i"},
  3718. {buildin_awake,"awake","s"},
  3719. {buildin_getvariableofnpc,"getvariableofnpc","is"},
  3720. // [blackhole89] -->
  3721. {buildin_warpportal,"warpportal","iisii"},
  3722. // <--- [blackhole89]
  3723. {buildin_homunculus_evolution,"homevolution",""}, //[orn]
  3724. {buildin_eaclass,"eaclass","*"}, //[Skotlex]
  3725. {buildin_roclass,"roclass","i*"}, //[Skotlex]
  3726. {buildin_checkvending,"checkvending","*"},
  3727. {buildin_checkchatting,"checkchatting","*"},
  3728. {NULL,NULL,NULL},
  3729. };
  3730. /*==========================================
  3731. *
  3732. *------------------------------------------
  3733. */
  3734. int buildin_mes(struct script_state *st)
  3735. {
  3736. struct map_session_data *sd = script_rid2sd(st);
  3737. char *mes = conv_str(st, &(st->stack->stack_data[st->start+2]));
  3738. if (sd)
  3739. clif_scriptmes(sd, st->oid, mes);
  3740. return 0;
  3741. }
  3742. /*==========================================
  3743. *
  3744. *------------------------------------------
  3745. */
  3746. int buildin_goto(struct script_state *st)
  3747. {
  3748. int pos;
  3749. if( st->stack->stack_data[st->start+2].type!=C_POS){
  3750. ShowMessage("script: goto: not label!\n");
  3751. st->state=END;
  3752. return 1;
  3753. }
  3754. pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3755. st->pos=pos;
  3756. st->state=GOTO;
  3757. return 0;
  3758. }
  3759. /*==========================================
  3760. * ユーザー定義関数の呼び出し
  3761. *------------------------------------------
  3762. */
  3763. int buildin_callfunc(struct script_state *st)
  3764. {
  3765. struct script_code *scr, *oldscr;
  3766. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  3767. if( (scr=strdb_get(userfunc_db,str)) ){
  3768. int i,j;
  3769. struct linkdb_node **oldval = st->stack->var_function;
  3770. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3771. push_copy(st->stack,i);
  3772. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3773. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3774. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3775. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3776. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3777. oldscr = st->script;
  3778. st->pos=0;
  3779. st->script=scr;
  3780. st->stack->defsp=st->start+5+j;
  3781. st->state=GOTO;
  3782. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3783. // ' 変数の引き継ぎ
  3784. for(i = 0; i < j; i++) {
  3785. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3786. if( s->type == C_NAME && !s->ref ) {
  3787. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3788. // '@ 変数の引き継ぎ
  3789. if( name[0] == '.' && name[1] == '@' ) {
  3790. s->ref = oldval;
  3791. } else if( name[0] == '.' ) {
  3792. s->ref = &oldscr->script_vars;
  3793. }
  3794. }
  3795. }
  3796. }else{
  3797. ShowWarning("script:callfunc: function not found! [%s]\n",str);
  3798. st->state=END;
  3799. return 1;
  3800. }
  3801. return 0;
  3802. }
  3803. /*==========================================
  3804. * サブルーティンの呼び出し
  3805. *------------------------------------------
  3806. */
  3807. int buildin_callsub(struct script_state *st)
  3808. {
  3809. int pos=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3810. int i,j;
  3811. if(st->stack->stack_data[st->start+2].type != C_POS && st->stack->stack_data[st->start+2].type != C_USERFUNC_POS) {
  3812. ShowError("script: callsub: not label !\n");
  3813. st->state=END;
  3814. return 1;
  3815. } else {
  3816. struct linkdb_node **oldval = st->stack->var_function;
  3817. for(i=st->start+3,j=0;i<st->end;i++,j++)
  3818. push_copy(st->stack,i);
  3819. push_val(st->stack,C_INT,j); // 引数の数をプッシュ
  3820. push_val(st->stack,C_INT,st->stack->defsp); // 現在の基準スタックポインタをプッシュ
  3821. push_val(st->stack,C_INT,(int)st->script); // 現在のスクリプトをプッシュ
  3822. push_val(st->stack,C_INT,(int)st->stack->var_function); // 現在の関数依存変数をプッシュ
  3823. push_val(st->stack,C_RETINFO,st->pos); // 現在のスクリプト位置をプッシュ
  3824. st->pos=pos;
  3825. st->stack->defsp=st->start+5+j;
  3826. st->state=GOTO;
  3827. st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
  3828. // ' 変数の引き継ぎ
  3829. for(i = 0; i < j; i++) {
  3830. struct script_data *s = &st->stack->stack_data[st->stack->sp-6-i];
  3831. if( s->type == C_NAME && !s->ref ) {
  3832. char *name = str_buf+str_data[s->u.num&0x00ffffff].str;
  3833. // '@ 変数の引き継ぎ
  3834. if( name[0] == '.' && name[1] == '@' ) {
  3835. s->ref = oldval;
  3836. }
  3837. }
  3838. }
  3839. }
  3840. return 0;
  3841. }
  3842. /*==========================================
  3843. * 引数の所得
  3844. *------------------------------------------
  3845. */
  3846. int buildin_getarg(struct script_state *st)
  3847. {
  3848. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  3849. int max,stsp;
  3850. if( st->stack->defsp<5 || st->stack->stack_data[st->stack->defsp-1].type!=C_RETINFO ){
  3851. ShowWarning("script:getarg without callfunc or callsub!\n");
  3852. st->state=END;
  3853. return 1;
  3854. }
  3855. max=conv_num(st,& (st->stack->stack_data[st->stack->defsp-5]));
  3856. stsp=st->stack->defsp - max -5;
  3857. if( num >= max ){
  3858. ShowWarning("script:getarg arg1(%d) out of range(%d) !\n",num,max);
  3859. st->state=END;
  3860. return 1;
  3861. }
  3862. push_copy(st->stack,stsp+num);
  3863. return 0;
  3864. }
  3865. /*==========================================
  3866. * サブルーチン/ユーザー定義関数の終了
  3867. *------------------------------------------
  3868. */
  3869. int buildin_return(struct script_state *st)
  3870. {
  3871. if(st->end>st->start+2){ // 戻り値有り
  3872. struct script_data *sd;
  3873. push_copy(st->stack,st->start+2);
  3874. sd = &st->stack->stack_data[st->stack->sp-1];
  3875. if(sd->type == C_NAME) {
  3876. char *name = str_buf + str_data[sd->u.num&0x00ffffff].str;
  3877. if( name[0] == '.' && name[1] == '@') {
  3878. // '@ 変数を参照渡しにすると危険なので値渡しにする
  3879. get_val(st,sd);
  3880. } else if( name[0] == '.' && !sd->ref) {
  3881. // ' 変数は参照渡しでも良いが、参照元が設定されていないと
  3882. // 元のスクリプトの値を差してしまうので補正する。
  3883. sd->ref = &st->script->script_vars;
  3884. }
  3885. }
  3886. }
  3887. st->state=RETFUNC;
  3888. return 0;
  3889. }
  3890. /*==========================================
  3891. *
  3892. *------------------------------------------
  3893. */
  3894. int buildin_next(struct script_state *st)
  3895. {
  3896. st->state=STOP;
  3897. clif_scriptnext(script_rid2sd(st),st->oid);
  3898. return 0;
  3899. }
  3900. /*==========================================
  3901. *
  3902. *------------------------------------------
  3903. */
  3904. int buildin_close(struct script_state *st)
  3905. {
  3906. st->state=END;
  3907. clif_scriptclose(script_rid2sd(st),st->oid);
  3908. return 0;
  3909. }
  3910. int buildin_close2(struct script_state *st)
  3911. {
  3912. st->state=STOP;
  3913. clif_scriptclose(script_rid2sd(st),st->oid);
  3914. return 0;
  3915. }
  3916. /*==========================================
  3917. *
  3918. *------------------------------------------
  3919. */
  3920. int buildin_menu(struct script_state *st)
  3921. {
  3922. char *buf;
  3923. int len,i, max = 1;
  3924. struct map_session_data *sd = script_rid2sd(st);
  3925. nullpo_retr(0, sd);
  3926. if(sd->state.menu_or_input==0){
  3927. st->state=RERUNLINE;
  3928. sd->state.menu_or_input=1;
  3929. if( (st->end - st->start - 2) % 2 == 1 ) {
  3930. // 引数の数が奇数なのでエラー扱い
  3931. ShowError("buildin_menu: illegal argument count(%d).\n", st->end - st->start - 2);
  3932. sd->state.menu_or_input=0;
  3933. st->state=END;
  3934. return 1;
  3935. }
  3936. for(i=st->start+2,len=0;i<st->end;i+=2){
  3937. conv_str(st,& (st->stack->stack_data[i]));
  3938. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  3939. }
  3940. buf=(char *)aMallocA((len+1)*sizeof(char));
  3941. buf[0]=0;
  3942. for(i=st->start+2,len=0;i<st->end;i+=2){
  3943. if( st->stack->stack_data[i].u.str[0] ) {
  3944. strcat(buf,st->stack->stack_data[i].u.str);
  3945. strcat(buf,":");
  3946. }
  3947. }
  3948. for(i=0; (unsigned int)i < strlen(buf); i++){
  3949. if(buf[i] == ':')
  3950. max++;
  3951. }
  3952. sd->max_menu = max;
  3953. clif_scriptmenu(sd,st->oid,buf);
  3954. aFree(buf);
  3955. } else if(sd->npc_menu==0xff){ // cancel
  3956. sd->state.menu_or_input=0;
  3957. st->state=END;
  3958. } else { // goto動作
  3959. sd->state.menu_or_input=0;
  3960. if(sd->npc_menu>0){
  3961. //Skip empty menu entries which weren't displayed on the client (blackhole89)
  3962. for(i=st->start+2;i<=(st->start+sd->npc_menu*2) && sd->npc_menu<(st->end-st->start)/2;i+=2) {
  3963. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  3964. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  3965. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  3966. }
  3967. if(sd->npc_menu >= (st->end-st->start)/2) {
  3968. //Invalid selection.
  3969. st->state=END;
  3970. return 0;
  3971. }
  3972. if( st->stack->stack_data[st->start+sd->npc_menu*2+1].type!=C_POS ){
  3973. ShowError("script: menu: not label !\n");
  3974. st->state=END;
  3975. return 1;
  3976. }
  3977. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  3978. st->pos=conv_num(st,& (st->stack->stack_data[st->start+sd->npc_menu*2+1]));
  3979. st->state=GOTO;
  3980. }
  3981. }
  3982. return 0;
  3983. }
  3984. /*==========================================
  3985. *
  3986. *------------------------------------------
  3987. */
  3988. int buildin_rand(struct script_state *st)
  3989. {
  3990. int range,min,max;
  3991. if (st->end > st->start+3){
  3992. min = conv_num(st,& (st->stack->stack_data[st->start+2]));
  3993. max = conv_num(st,& (st->stack->stack_data[st->start+3]));
  3994. if (max == min){ //Why would someone do this?
  3995. push_val(st->stack,C_INT,min);
  3996. return 0;
  3997. }
  3998. if(max<min){
  3999. int tmp = min;
  4000. min = max;
  4001. max = tmp;
  4002. }
  4003. range = max - min + 1;
  4004. if (range == 0) range = 1;
  4005. push_val(st->stack,C_INT,rand()%range+min);
  4006. } else {
  4007. range = conv_num(st,& (st->stack->stack_data[st->start+2]));
  4008. if (range == 0) range = 1;
  4009. push_val(st->stack,C_INT,rand()%range);
  4010. }
  4011. return 0;
  4012. }
  4013. /*==========================================
  4014. *
  4015. *------------------------------------------
  4016. */
  4017. int buildin_warp(struct script_state *st)
  4018. {
  4019. int x,y;
  4020. char *str;
  4021. struct map_session_data *sd=script_rid2sd(st);
  4022. nullpo_retr(0, sd);
  4023. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4024. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4025. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4026. if(strcmp(str,"Random")==0)
  4027. pc_randomwarp(sd,3);
  4028. else if(strcmp(str,"SavePoint")==0){
  4029. pc_setpos(sd,sd->status.save_point.map,
  4030. sd->status.save_point.x,sd->status.save_point.y,3);
  4031. }else if(strcmp(str,"Save")==0){
  4032. pc_setpos(sd,sd->status.save_point.map,
  4033. sd->status.save_point.x,sd->status.save_point.y,3);
  4034. }else
  4035. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  4036. return 0;
  4037. }
  4038. /*==========================================
  4039. * エリア指定ワープ
  4040. *------------------------------------------
  4041. */
  4042. int buildin_areawarp_sub(struct block_list *bl,va_list ap)
  4043. {
  4044. int x,y;
  4045. unsigned int map;
  4046. map=va_arg(ap, unsigned int);
  4047. x=va_arg(ap,int);
  4048. y=va_arg(ap,int);
  4049. if(map == 0)
  4050. pc_randomwarp((struct map_session_data *)bl,3);
  4051. else
  4052. pc_setpos((struct map_session_data *)bl,map,x,y,0);
  4053. return 0;
  4054. }
  4055. int buildin_areawarp(struct script_state *st)
  4056. {
  4057. int x,y,m;
  4058. unsigned int index;
  4059. char *str;
  4060. char *mapname;
  4061. int x0,y0,x1,y1;
  4062. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4063. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4064. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4065. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4066. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4067. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  4068. x=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4069. y=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4070. if( (m=map_mapname2mapid(mapname))< 0)
  4071. return 0;
  4072. if(strcmp(str,"Random")==0)
  4073. index = 0;
  4074. else if(!(index=mapindex_name2id(str)))
  4075. return 0;
  4076. map_foreachinarea(buildin_areawarp_sub,
  4077. m,x0,y0,x1,y1,BL_PC, index,x,y );
  4078. return 0;
  4079. }
  4080. /*==========================================
  4081. * warpchar [LuzZza]
  4082. * Useful for warp one player from
  4083. * another player npc-session.
  4084. * Using: warpchar "mapname.gat",x,y,Char_ID;
  4085. *------------------------------------------
  4086. */
  4087. int buildin_warpchar(struct script_state *st)
  4088. {
  4089. int x,y,a,i;
  4090. char *str;
  4091. struct map_session_data *sd, **pl_allsd;
  4092. int users;
  4093. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4094. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4095. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4096. a=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4097. pl_allsd = map_getallusers(&users);
  4098. for(i=0; i<users; i++) {
  4099. sd = pl_allsd[i];
  4100. if(sd->status.char_id == a) {
  4101. if(strcmp(str, "Random") == 0)
  4102. pc_randomwarp(sd, 3);
  4103. else if(strcmp(str, "SavePoint") == 0)
  4104. pc_setpos(sd, sd->status.save_point.map,
  4105. sd->status.save_point.x, sd->status.save_point.y, 3);
  4106. else
  4107. pc_setpos(sd, mapindex_name2id(str), x, y, 3);
  4108. }
  4109. }
  4110. return 0;
  4111. }
  4112. /*==========================================
  4113. * Warpparty - [Fredzilla]
  4114. * Syntax: warpparty "mapname.gat",x,y,Party_ID;
  4115. *------------------------------------------
  4116. */
  4117. int buildin_warpparty(struct script_state *st)
  4118. {
  4119. int x,y;
  4120. char *str;
  4121. int p_id;
  4122. int i;
  4123. unsigned short mapindex;
  4124. struct map_session_data *pl_sd;
  4125. struct party_data *p=NULL;
  4126. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4127. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4128. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4129. p_id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4130. if(p_id < 1)
  4131. return 0;
  4132. p = party_search(p_id);
  4133. if (!p)
  4134. return 0;
  4135. if(strcmp(str,"Random")==0)
  4136. {
  4137. for (i = 0; i < MAX_PARTY; i++)
  4138. {
  4139. if ((pl_sd = p->data[i].sd))
  4140. {
  4141. if(map[pl_sd->bl.m].flag.nowarp)
  4142. continue;
  4143. pc_randomwarp(pl_sd,3);
  4144. }
  4145. }
  4146. }
  4147. else if(strcmp(str,"SavePointAll")==0)
  4148. {
  4149. for (i = 0; i < MAX_PARTY; i++)
  4150. {
  4151. if ((pl_sd = p->data[i].sd))
  4152. {
  4153. if(map[pl_sd->bl.m].flag.noreturn)
  4154. continue;
  4155. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4156. }
  4157. }
  4158. }
  4159. else if(strcmp(str,"SavePoint")==0)
  4160. {
  4161. pl_sd=script_rid2sd(st);
  4162. if (!pl_sd) return 0;
  4163. mapindex=pl_sd->status.save_point.map;
  4164. x=pl_sd->status.save_point.x;
  4165. y=pl_sd->status.save_point.y;
  4166. for (i = 0; i < MAX_PARTY; i++)
  4167. {
  4168. if ((pl_sd = p->data[i].sd))
  4169. {
  4170. if(map[pl_sd->bl.m].flag.noreturn)
  4171. continue;
  4172. pc_setpos(pl_sd,mapindex,x,y,3);
  4173. }
  4174. }
  4175. }
  4176. else
  4177. {
  4178. mapindex = mapindex_name2id(str);
  4179. if (!mapindex) //Show source of npc error.
  4180. return 1;
  4181. for (i = 0; i < MAX_PARTY; i++)
  4182. {
  4183. if ((pl_sd = p->data[i].sd))
  4184. {
  4185. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4186. continue;
  4187. pc_setpos(pl_sd,mapindex,x,y,3);
  4188. }
  4189. }
  4190. }
  4191. return 0;
  4192. }
  4193. /*==========================================
  4194. * Warpguild - [Fredzilla]
  4195. * Syntax: warpguild "mapname.gat",x,y,Guild_ID;
  4196. *------------------------------------------
  4197. */
  4198. int buildin_warpguild(struct script_state *st)
  4199. {
  4200. int x,y;
  4201. unsigned short mapindex;
  4202. char *str;
  4203. int g;
  4204. int i;
  4205. struct map_session_data *pl_sd, **pl_allsd;
  4206. int users;
  4207. struct map_session_data *sd;
  4208. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  4209. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4210. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4211. g=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4212. sd=script_rid2sd(st);
  4213. if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
  4214. return 0;
  4215. if(g < 1)
  4216. return 0;
  4217. pl_allsd = map_getallusers(&users);
  4218. if(strcmp(str,"Random")==0)
  4219. {
  4220. for (i = 0; i < users; i++)
  4221. {
  4222. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4223. {
  4224. if(map[pl_sd->bl.m].flag.nowarp)
  4225. continue;
  4226. pc_randomwarp(pl_sd,3);
  4227. }
  4228. }
  4229. }
  4230. else if(strcmp(str,"SavePointAll")==0)
  4231. {
  4232. if(map[sd->bl.m].flag.noreturn)
  4233. return 0;
  4234. for (i = 0; i < users; i++)
  4235. {
  4236. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4237. {
  4238. if(map[pl_sd->bl.m].flag.noreturn)
  4239. continue;
  4240. pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
  4241. }
  4242. }
  4243. }
  4244. else if(strcmp(str,"SavePoint")==0)
  4245. {
  4246. if(map[sd->bl.m].flag.noreturn)
  4247. return 0;
  4248. mapindex=sd->status.save_point.map;
  4249. x=sd->status.save_point.x;
  4250. y=sd->status.save_point.y;
  4251. for (i = 0; i < users; i++)
  4252. {
  4253. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4254. {
  4255. if(map[pl_sd->bl.m].flag.noreturn)
  4256. continue;
  4257. pc_setpos(pl_sd,mapindex,x,y,3);
  4258. }
  4259. }
  4260. }
  4261. else
  4262. {
  4263. mapindex = mapindex_name2id(str);
  4264. for (i = 0; i < users; i++)
  4265. {
  4266. if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
  4267. {
  4268. if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
  4269. continue;
  4270. pc_setpos(pl_sd,mapindex,x,y,3);
  4271. }
  4272. }
  4273. }
  4274. return 0;
  4275. }
  4276. /*==========================================
  4277. *
  4278. *------------------------------------------
  4279. */
  4280. int buildin_heal(struct script_state *st)
  4281. {
  4282. struct map_session_data *sd;
  4283. int hp,sp;
  4284. sd = script_rid2sd(st);
  4285. if (!sd) return 0;
  4286. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4287. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4288. status_heal(&sd->bl, hp, sp, 1);
  4289. return 0;
  4290. }
  4291. /*==========================================
  4292. *
  4293. *------------------------------------------
  4294. */
  4295. int buildin_itemheal(struct script_state *st)
  4296. {
  4297. struct map_session_data *sd;
  4298. int hp,sp;
  4299. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4300. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4301. if(potion_flag==1) {
  4302. potion_hp = hp;
  4303. potion_sp = sp;
  4304. return 0;
  4305. }
  4306. sd = script_rid2sd(st);
  4307. if (!sd) return 0;
  4308. pc_itemheal(sd,sd->itemid,hp,sp);
  4309. return 0;
  4310. }
  4311. /*==========================================
  4312. *
  4313. *------------------------------------------
  4314. */
  4315. int buildin_percentheal(struct script_state *st)
  4316. {
  4317. int hp,sp;
  4318. hp=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4319. sp=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4320. if(potion_flag==1) {
  4321. potion_per_hp = hp;
  4322. potion_per_sp = sp;
  4323. return 0;
  4324. }
  4325. pc_percentheal(script_rid2sd(st),hp,sp);
  4326. return 0;
  4327. }
  4328. /*==========================================
  4329. *
  4330. *------------------------------------------
  4331. */
  4332. int buildin_jobchange(struct script_state *st)
  4333. {
  4334. int job, upper=-1;
  4335. job=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4336. if( st->end>st->start+3 )
  4337. upper=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4338. if ((job >= 0 && job < MAX_PC_CLASS))
  4339. {
  4340. pc_jobchange(script_rid2sd(st),job, upper);
  4341. if(use_irc && irc_announce_jobchange_flag)
  4342. irc_announce_jobchange(script_rid2sd(st));
  4343. }
  4344. return 0;
  4345. }
  4346. /*==========================================
  4347. *
  4348. *------------------------------------------
  4349. */
  4350. int buildin_jobname(struct script_state *st)
  4351. {
  4352. int class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4353. push_str(st->stack,C_CONSTSTR,job_name(class_));
  4354. return 0;
  4355. }
  4356. /*==========================================
  4357. *
  4358. *------------------------------------------
  4359. */
  4360. int buildin_input(struct script_state *st)
  4361. {
  4362. struct map_session_data *sd = script_rid2sd(st);
  4363. int num = (st->end>st->start+2)? st->stack->stack_data[st->start+2].u.num: 0;
  4364. char *name = (st->end>st->start+2)? str_buf+str_data[num&0x00ffffff].str: "";
  4365. char postfix=name[strlen(name)-1];
  4366. nullpo_retr(0, sd);
  4367. if(sd->state.menu_or_input){
  4368. sd->state.menu_or_input=0;
  4369. if( postfix=='$' ){
  4370. // 文字列
  4371. if(st->end>st->start+2){ // 引数1個
  4372. set_reg(st,sd,num,name,(void*)sd->npc_str,st->stack->stack_data[st->start+2].ref);
  4373. }else{
  4374. ShowError("buildin_input: string discarded !!\n");
  4375. return 1;
  4376. }
  4377. return 0;
  4378. }
  4379. // commented by Lupus (check Value Number Input fix in clif.c)
  4380. // readded by Yor: set ammount to 0 instead of cancel trade.
  4381. // ** Fix by fritz :X keeps people from abusing old input bugs
  4382. if (sd->npc_amount < 0) { //** If input amount is less then 0
  4383. // clif_tradecancelled(sd); // added "Deal has been cancelled" message by Valaris
  4384. // buildin_close(st); // ** close
  4385. sd->npc_amount = 0;
  4386. } else if ((unsigned int)sd->npc_amount > battle_config.vending_max_value) // new fix by Yor
  4387. sd->npc_amount = battle_config.vending_max_value;
  4388. // 数値
  4389. if(st->end>st->start+2){ // 引数1個
  4390. set_reg(st,sd,num,name,(void*)sd->npc_amount,st->stack->stack_data[st->start+2].ref);
  4391. } else {
  4392. // ragemu互換のため
  4393. //pc_setreg(sd,add_str("l14"),sd->npc_amount);
  4394. }
  4395. return 0;
  4396. }
  4397. //state.menu_or_input = 0
  4398. st->state=RERUNLINE;
  4399. if(postfix=='$')
  4400. clif_scriptinputstr(sd,st->oid);
  4401. else
  4402. clif_scriptinput(sd,st->oid);
  4403. sd->state.menu_or_input=1;
  4404. return 0;
  4405. }
  4406. /*==========================================
  4407. * 変数設定
  4408. *------------------------------------------
  4409. */
  4410. int buildin_set(struct script_state *st)
  4411. {
  4412. struct map_session_data *sd=NULL;
  4413. int num=st->stack->stack_data[st->start+2].u.num;
  4414. char *name=str_buf+str_data[num&0x00ffffff].str;
  4415. char prefix=*name;
  4416. char postfix=name[strlen(name)-1];
  4417. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  4418. ShowError("script: buildin_set: not name\n");
  4419. return 1;
  4420. }
  4421. if(not_server_variable(prefix))
  4422. sd=script_rid2sd(st);
  4423. if( postfix=='$' ){
  4424. // 文字列
  4425. char *str = conv_str(st,& (st->stack->stack_data[st->start+3]));
  4426. set_reg(st,sd,num,name,(void*)str,st->stack->stack_data[st->start+2].ref);
  4427. }else{
  4428. // 数値
  4429. int val = conv_num(st,& (st->stack->stack_data[st->start+3]));
  4430. set_reg(st,sd,num,name,(void*)val,st->stack->stack_data[st->start+2].ref);
  4431. }
  4432. return 0;
  4433. }
  4434. /*==========================================
  4435. * 配列変数設定
  4436. *------------------------------------------
  4437. */
  4438. int buildin_setarray(struct script_state *st)
  4439. {
  4440. struct map_session_data *sd=NULL;
  4441. int num=st->stack->stack_data[st->start+2].u.num;
  4442. char *name=str_buf+str_data[num&0x00ffffff].str;
  4443. char prefix=*name;
  4444. char postfix=name[strlen(name)-1];
  4445. int i,j;
  4446. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4447. ShowWarning("buildin_setarray: illegal scope !\n");
  4448. return 1;
  4449. }
  4450. if(not_server_variable(prefix))
  4451. sd=script_rid2sd(st);
  4452. for(j=0,i=st->start+3; i<st->end && j<128;i++,j++){
  4453. void *v;
  4454. if( postfix=='$' )
  4455. v=(void*)conv_str(st,& (st->stack->stack_data[i]));
  4456. else
  4457. v=(void*)conv_num(st,& (st->stack->stack_data[i]));
  4458. set_reg(st, sd, num+(j<<24), name, v, st->stack->stack_data[st->start+2].ref);
  4459. }
  4460. return 0;
  4461. }
  4462. /*==========================================
  4463. * 配列変数クリア
  4464. *------------------------------------------
  4465. */
  4466. int buildin_cleararray(struct script_state *st)
  4467. {
  4468. struct map_session_data *sd=NULL;
  4469. int num=st->stack->stack_data[st->start+2].u.num;
  4470. char *name=str_buf+str_data[num&0x00ffffff].str;
  4471. char prefix=*name;
  4472. char postfix=name[strlen(name)-1];
  4473. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4474. int i;
  4475. void *v;
  4476. if( prefix!='$' && prefix!='@' && prefix!='.'){
  4477. ShowWarning("buildin_cleararray: illegal scope !\n");
  4478. return 1;
  4479. }
  4480. if( not_server_variable(prefix) )
  4481. sd=script_rid2sd(st);
  4482. if( postfix=='$' )
  4483. v=(void*)conv_str(st,& (st->stack->stack_data[st->start+3]));
  4484. else
  4485. v=(void*)conv_num(st,& (st->stack->stack_data[st->start+3]));
  4486. for(i=0;i<sz;i++)
  4487. set_reg(st,sd,num+(i<<24),name,v,st->stack->stack_data[st->start+2].ref);
  4488. return 0;
  4489. }
  4490. /*==========================================
  4491. * 配列変数コピー
  4492. *------------------------------------------
  4493. */
  4494. int buildin_copyarray(struct script_state *st)
  4495. {
  4496. struct map_session_data *sd=NULL;
  4497. int num=st->stack->stack_data[st->start+2].u.num;
  4498. char *name=str_buf+str_data[num&0x00ffffff].str;
  4499. char prefix=*name;
  4500. char postfix=name[strlen(name)-1];
  4501. int num2=st->stack->stack_data[st->start+3].u.num;
  4502. char *name2=str_buf+str_data[num2&0x00ffffff].str;
  4503. char prefix2=*name2;
  4504. char postfix2=name2[strlen(name2)-1];
  4505. int sz=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4506. int i;
  4507. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4508. printf("buildin_copyarray: illeagal scope !\n");
  4509. return 0;
  4510. }
  4511. if( prefix2!='$' && prefix2!='@' && prefix2!='.' ) {
  4512. printf("buildin_copyarray: illeagal scope !\n");
  4513. return 0;
  4514. }
  4515. if( (postfix=='$' || postfix2=='$') && postfix!=postfix2 ){
  4516. printf("buildin_copyarray: type mismatch !\n");
  4517. return 0;
  4518. }
  4519. if( not_server_variable(prefix) || not_server_variable(prefix2) )
  4520. sd=script_rid2sd(st);
  4521. if((num & 0x00FFFFFF) == (num2 & 0x00FFFFFF) && (num & 0xFF000000) > (num2 & 0xFF000000)) {
  4522. // 同じ配列で、num > num2 の場合大きい方からコピーしないといけない
  4523. for(i=sz-1;i>=0;i--)
  4524. set_reg(
  4525. st,sd,num+(i<<24),name,
  4526. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4527. st->stack->stack_data[st->start+2].ref
  4528. );
  4529. } else {
  4530. for(i=0;i<sz;i++)
  4531. set_reg(
  4532. st,sd,num+(i<<24),name,
  4533. get_val2(st,num2+(i<<24),st->stack->stack_data[st->start+3].ref),
  4534. st->stack->stack_data[st->start+2].ref
  4535. );
  4536. }
  4537. return 0;
  4538. }
  4539. /*==========================================
  4540. * 配列変数のサイズ所得
  4541. *------------------------------------------
  4542. */
  4543. static int getarraysize(struct script_state *st,int num,int postfix,struct linkdb_node** ref)
  4544. {
  4545. int i=(num>>24),c=(i==0? -1:i); // Moded to -1 because even if the first element is 0, it will still report as 1 [Lance]
  4546. if(postfix == '$'){
  4547. for(;i<128;i++){
  4548. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4549. if(*((char*)v)) c=i;
  4550. }
  4551. }else{
  4552. for(;i<128;i++){
  4553. void *v=get_val2(st,(num & 0x00FFFFFF)+(i<<24),ref);
  4554. if((int)v) c=i;
  4555. }
  4556. }
  4557. return c+1;
  4558. }
  4559. int buildin_getarraysize(struct script_state *st)
  4560. {
  4561. int num=st->stack->stack_data[st->start+2].u.num;
  4562. char *name=str_buf+str_data[num&0x00ffffff].str;
  4563. char prefix=*name;
  4564. char postfix=name[strlen(name)-1];
  4565. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4566. ShowWarning("buildin_copyarray: illegal scope !\n");
  4567. push_val(st->stack,C_INT,0);
  4568. return 1;
  4569. }
  4570. push_val(st->stack,C_INT,getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref));
  4571. return 0;
  4572. }
  4573. /*==========================================
  4574. * 配列変数から要素削除
  4575. *------------------------------------------
  4576. */
  4577. int buildin_deletearray(struct script_state *st)
  4578. {
  4579. struct map_session_data *sd=NULL;
  4580. int num=st->stack->stack_data[st->start+2].u.num;
  4581. char *name=str_buf+str_data[num&0x00ffffff].str;
  4582. char prefix=*name;
  4583. char postfix=name[strlen(name)-1];
  4584. int count=1;
  4585. int i,sz=getarraysize(st,num,postfix,st->stack->stack_data[st->start+2].ref)-(num>>24)-count+1;
  4586. if( (st->end > st->start+3) )
  4587. count=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4588. if( prefix!='$' && prefix!='@' && prefix!='.' ){
  4589. ShowWarning("buildin_deletearray: illegal scope !\n");
  4590. return 1;
  4591. }
  4592. if( not_server_variable(prefix) )
  4593. sd=script_rid2sd(st);
  4594. for(i=0;i<sz;i++){
  4595. set_reg(
  4596. st,sd,num+(i<<24),name,
  4597. get_val2(st,num+((i+count)<<24),st->stack->stack_data[st->start+2].ref),
  4598. st->stack->stack_data[st->start+2].ref
  4599. );
  4600. }
  4601. if(postfix != '$'){
  4602. for(;i<(128-(num>>24));i++)
  4603. set_reg(st,sd,num+(i<<24),name, 0,st->stack->stack_data[st->start+2].ref);
  4604. } else {
  4605. for(;i<(128-(num>>24));i++)
  4606. set_reg(st,sd,num+(i<<24),name, (void *) "",st->stack->stack_data[st->start+2].ref);
  4607. }
  4608. return 0;
  4609. }
  4610. /*==========================================
  4611. * 指定要素を表す値(キー)を所得する
  4612. *------------------------------------------
  4613. */
  4614. int buildin_getelementofarray(struct script_state *st)
  4615. {
  4616. if( st->stack->stack_data[st->start+2].type==C_NAME ){
  4617. int i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4618. if(i>127 || i<0){
  4619. ShowWarning("script: getelementofarray (operator[]): param2 illegal number %d\n",i);
  4620. push_val(st->stack,C_INT,0);
  4621. return 1;
  4622. }else{
  4623. push_val2(st->stack,C_NAME,
  4624. (i<<24) | st->stack->stack_data[st->start+2].u.num, st->stack->stack_data[st->start+2].ref );
  4625. }
  4626. }else{
  4627. ShowError("script: getelementofarray (operator[]): param1 not name !\n");
  4628. push_val(st->stack,C_INT,0);
  4629. }
  4630. return 0;
  4631. }
  4632. /*==========================================
  4633. *
  4634. *------------------------------------------
  4635. */
  4636. int buildin_setlook(struct script_state *st)
  4637. {
  4638. int type,val;
  4639. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4640. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4641. pc_changelook(script_rid2sd(st),type,val);
  4642. return 0;
  4643. }
  4644. /*==========================================
  4645. *
  4646. *------------------------------------------
  4647. */
  4648. int buildin_cutin(struct script_state *st)
  4649. {
  4650. int type;
  4651. conv_str(st,& (st->stack->stack_data[st->start+2]));
  4652. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4653. clif_cutin(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str,type);
  4654. return 0;
  4655. }
  4656. /*==========================================
  4657. * カードのイラストを表示する
  4658. *------------------------------------------
  4659. */
  4660. int buildin_cutincard(struct script_state *st)
  4661. {
  4662. int itemid;
  4663. struct item_data *i_data;
  4664. itemid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4665. i_data = itemdb_exists(itemid);
  4666. if (i_data)
  4667. clif_cutin(script_rid2sd(st),i_data->cardillustname,4);
  4668. return 0;
  4669. }
  4670. /*==========================================
  4671. *
  4672. *------------------------------------------
  4673. */
  4674. int buildin_viewpoint(struct script_state *st)
  4675. {
  4676. int type,x,y,id,color;
  4677. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  4678. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4679. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4680. id=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4681. color=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4682. clif_viewpoint(script_rid2sd(st),st->oid,type,x,y,id,color);
  4683. return 0;
  4684. }
  4685. /*==========================================
  4686. *
  4687. *------------------------------------------
  4688. */
  4689. int buildin_countitem(struct script_state *st)
  4690. {
  4691. int nameid=0,count=0,i;
  4692. struct map_session_data *sd;
  4693. struct script_data *data;
  4694. sd = script_rid2sd(st);
  4695. data=&(st->stack->stack_data[st->start+2]);
  4696. get_val(st,data);
  4697. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4698. const char *name=conv_str(st,data);
  4699. struct item_data *item_data;
  4700. if( (item_data = itemdb_searchname(name)) != NULL)
  4701. nameid=item_data->nameid;
  4702. }else
  4703. nameid=conv_num(st,data);
  4704. if (nameid>=500) //if no such ID then skip this iteration
  4705. for(i=0;i<MAX_INVENTORY;i++){
  4706. if(sd->status.inventory[i].nameid==nameid)
  4707. count+=sd->status.inventory[i].amount;
  4708. }
  4709. else{
  4710. if(battle_config.error_log)
  4711. ShowError("wrong item ID : countitem(%i)\n",nameid);
  4712. push_val(st->stack,C_INT,0);
  4713. return 1;
  4714. }
  4715. push_val(st->stack,C_INT,count);
  4716. return 0;
  4717. }
  4718. /*==========================================
  4719. * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
  4720. * returns number of items that met the conditions
  4721. *------------------------------------------
  4722. */
  4723. int buildin_countitem2(struct script_state *st)
  4724. {
  4725. int nameid=0,count=0,i;
  4726. int iden,ref,attr,c1,c2,c3,c4;
  4727. struct map_session_data *sd;
  4728. struct script_data *data;
  4729. sd = script_rid2sd(st);
  4730. data=&(st->stack->stack_data[st->start+2]);
  4731. get_val(st,data);
  4732. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4733. const char *name=conv_str(st,data);
  4734. struct item_data *item_data;
  4735. if( (item_data = itemdb_searchname(name)) != NULL)
  4736. nameid=item_data->nameid;
  4737. }else
  4738. nameid=conv_num(st,data);
  4739. iden=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4740. ref=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4741. attr=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4742. c1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4743. c2=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4744. c3=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4745. c4=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4746. if (nameid>=500) //if no such ID then skip this iteration
  4747. for(i=0;i<MAX_INVENTORY;i++){
  4748. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  4749. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  4750. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  4751. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  4752. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  4753. sd->status.inventory[i].card[3]!=c4)
  4754. continue;
  4755. count+=sd->status.inventory[i].amount;
  4756. }
  4757. else{
  4758. if(battle_config.error_log)
  4759. ShowError("wrong item ID : countitem2(%i)\n",nameid);
  4760. push_val(st->stack,C_INT,0);
  4761. return 1;
  4762. }
  4763. push_val(st->stack,C_INT,count);
  4764. return 0;
  4765. }
  4766. /*==========================================
  4767. * 重量チェック
  4768. *------------------------------------------
  4769. */
  4770. int buildin_checkweight(struct script_state *st)
  4771. {
  4772. int nameid=0,amount,i;
  4773. unsigned long weight;
  4774. struct map_session_data *sd;
  4775. struct script_data *data;
  4776. sd = script_rid2sd(st);
  4777. data=&(st->stack->stack_data[st->start+2]);
  4778. get_val(st,data);
  4779. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4780. const char *name=conv_str(st,data);
  4781. struct item_data *item_data = itemdb_searchname(name);
  4782. if( item_data )
  4783. nameid=item_data->nameid;
  4784. }else
  4785. nameid=conv_num(st,data);
  4786. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4787. if ( amount<=0 || nameid<500 ) { //if get wrong item ID or amount<=0, don't count weight of non existing items
  4788. push_val(st->stack,C_INT,0);
  4789. ShowError("buildin_checkweight: Wrong item ID or amount.\n");
  4790. return 1;
  4791. }
  4792. weight = itemdb_weight(nameid)*amount;
  4793. if(amount > MAX_AMOUNT || weight + sd->weight > sd->max_weight){
  4794. push_val(st->stack,C_INT,0);
  4795. } else {
  4796. //Check if the inventory ain't full.
  4797. //TODO: Currently does not checks if you can just stack it on top of another item you already have....
  4798. i = pc_search_inventory(sd,0);
  4799. if (i >= 0) //Empty slot available.
  4800. push_val(st->stack,C_INT,1);
  4801. else //Inventory full
  4802. push_val(st->stack,C_INT,0);
  4803. }
  4804. return 0;
  4805. }
  4806. /*==========================================
  4807. *
  4808. *------------------------------------------
  4809. */
  4810. int buildin_getitem(struct script_state *st)
  4811. {
  4812. int nameid,amount,flag = 0;
  4813. struct item item_tmp;
  4814. struct map_session_data *sd;
  4815. struct script_data *data;
  4816. sd = script_rid2sd(st);
  4817. data=&(st->stack->stack_data[st->start+2]);
  4818. get_val(st,data);
  4819. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4820. const char *name=conv_str(st,data);
  4821. struct item_data *item_data = itemdb_searchname(name);
  4822. if( item_data == NULL) {
  4823. ShowWarning("buildin_getitem: Nonexistant item %s requested.\n", name);
  4824. return 1; //No item created.
  4825. }
  4826. nameid=item_data->nameid;
  4827. }else
  4828. nameid=conv_num(st,data);
  4829. if ( ( amount=conv_num(st,& (st->stack->stack_data[st->start+3])) ) <= 0)
  4830. return 0; //return if amount <=0, skip the useles iteration
  4831. //Violet Box, Blue Box, etc - random item pick
  4832. if(nameid <0) {
  4833. nameid=itemdb_searchrandomid(-nameid);
  4834. flag = 1;
  4835. }
  4836. if(nameid <= 0 || !itemdb_exists(nameid)) {
  4837. ShowWarning("buildin_getitem: Nonexistant item %d requested.\n", nameid);
  4838. return 1; //No item created.
  4839. }
  4840. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4841. item_tmp.nameid=nameid;
  4842. if(!flag)
  4843. item_tmp.identify=1;
  4844. else
  4845. item_tmp.identify=itemdb_isidentified(nameid);
  4846. if( st->end>st->start+5 ) //アイテムを指定したIDに渡す
  4847. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+5])));
  4848. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4849. return 0;
  4850. if(pet_create_egg(sd, nameid))
  4851. amount = 1; //This is a pet!
  4852. else
  4853. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4854. clif_additem(sd,0,0,flag);
  4855. if (pc_candrop(sd, &item_tmp))
  4856. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4857. }
  4858. //Logs items, got from (N)PC scripts [Lupus]
  4859. if(log_config.enable_logs&0x40)
  4860. log_pick_pc(sd, "N", nameid, amount, NULL);
  4861. return 0;
  4862. }
  4863. /*==========================================
  4864. *
  4865. *------------------------------------------
  4866. */
  4867. int buildin_getitem2(struct script_state *st)
  4868. {
  4869. int nameid,amount,flag = 0;
  4870. int iden,ref,attr,c1,c2,c3,c4;
  4871. struct item_data *item_data;
  4872. struct item item_tmp;
  4873. struct map_session_data *sd;
  4874. struct script_data *data;
  4875. sd = script_rid2sd(st);
  4876. data=&(st->stack->stack_data[st->start+2]);
  4877. get_val(st,data);
  4878. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4879. const char *name=conv_str(st,data);
  4880. struct item_data *item_data = itemdb_searchname(name);
  4881. nameid=UNKNOWN_ITEM_ID;
  4882. if( item_data )
  4883. nameid=item_data->nameid;
  4884. }else
  4885. nameid=conv_num(st,data);
  4886. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  4887. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  4888. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  4889. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  4890. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  4891. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  4892. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  4893. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  4894. if( st->end>st->start+11 ) //アイテムを指定したIDに渡す
  4895. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+11])));
  4896. if(sd == NULL) //アイテムを渡す相手がいなかったらお帰り
  4897. return 0;
  4898. if(nameid<0) { // ランダム
  4899. nameid=itemdb_searchrandomid(-nameid);
  4900. flag = 1;
  4901. }
  4902. if(nameid > 0) {
  4903. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4904. item_data=itemdb_exists(nameid);
  4905. if (item_data == NULL)
  4906. return -1;
  4907. if(item_data->type==4 || item_data->type==5){
  4908. if(ref > 10) ref = 10;
  4909. }
  4910. else if(item_data->type==7) {
  4911. iden = 1;
  4912. ref = 0;
  4913. }
  4914. else {
  4915. iden = 1;
  4916. ref = attr = 0;
  4917. }
  4918. item_tmp.nameid=nameid;
  4919. if(!flag)
  4920. item_tmp.identify=iden;
  4921. else if(item_data->type==4 || item_data->type==5)
  4922. item_tmp.identify=0;
  4923. item_tmp.refine=ref;
  4924. item_tmp.attribute=attr;
  4925. item_tmp.card[0]=c1;
  4926. item_tmp.card[1]=c2;
  4927. item_tmp.card[2]=c3;
  4928. item_tmp.card[3]=c4;
  4929. if((flag = pc_additem(sd,&item_tmp,amount))) {
  4930. clif_additem(sd,0,0,flag);
  4931. map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  4932. }
  4933. //Logs items, got from (N)PC scripts [Lupus]
  4934. if(log_config.enable_logs&0x40)
  4935. log_pick_pc(sd, "N", nameid, amount, &item_tmp);
  4936. }
  4937. return 0;
  4938. }
  4939. /*==========================================
  4940. * gets an item with someone's name inscribed [Skotlex]
  4941. * getinscribeditem item_num, character_name
  4942. * Returned Qty is always 1, only works on equip-able
  4943. * equipment
  4944. *------------------------------------------
  4945. */
  4946. int buildin_getnameditem(struct script_state *st)
  4947. {
  4948. int nameid;
  4949. struct item item_tmp;
  4950. struct map_session_data *sd, *tsd;
  4951. struct script_data *data;
  4952. sd = script_rid2sd(st);
  4953. if (sd == NULL)
  4954. { //Player not attached!
  4955. push_val(st->stack,C_INT,0);
  4956. return 0;
  4957. }
  4958. data=&(st->stack->stack_data[st->start+2]);
  4959. get_val(st,data);
  4960. if( data->type==C_STR || data->type==C_CONSTSTR ){
  4961. const char *name=conv_str(st,data);
  4962. struct item_data *item_data = itemdb_searchname(name);
  4963. if( item_data == NULL)
  4964. { //Failed
  4965. push_val(st->stack,C_INT,0);
  4966. return 0;
  4967. }
  4968. nameid = item_data->nameid;
  4969. }else
  4970. nameid = conv_num(st,data);
  4971. if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/)
  4972. { //Even though named stackable items "could" be risky, they are required for certain quests.
  4973. push_val(st->stack,C_INT,0);
  4974. return 0;
  4975. }
  4976. data=&(st->stack->stack_data[st->start+3]);
  4977. get_val(st,data);
  4978. if( data->type==C_STR || data->type==C_CONSTSTR ) //Char Name
  4979. tsd=map_nick2sd(conv_str(st,data));
  4980. else //Char Id was given
  4981. tsd=map_charid2sd(conv_num(st,data));
  4982. if( tsd == NULL )
  4983. { //Failed
  4984. push_val(st->stack,C_INT,0);
  4985. return 0;
  4986. }
  4987. malloc_set(&item_tmp,0,sizeof(item_tmp));
  4988. item_tmp.nameid=nameid;
  4989. item_tmp.amount=1;
  4990. item_tmp.identify=1;
  4991. item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
  4992. item_tmp.card[2]=tsd->status.char_id;
  4993. item_tmp.card[3]=tsd->status.char_id >> 16;
  4994. if(pc_additem(sd,&item_tmp,1)) {
  4995. push_val(st->stack,C_INT,0);
  4996. return 0; //Failed to add item, we will not drop if they don't fit
  4997. }
  4998. //Logs items, got from (N)PC scripts [Lupus]
  4999. if(log_config.enable_logs&0x40)
  5000. log_pick_pc(sd, "N", item_tmp.nameid, item_tmp.amount, &item_tmp);
  5001. push_val(st->stack,C_INT,1);
  5002. return 0;
  5003. }
  5004. /*==========================================
  5005. * gets a random item ID from an item group [Skotlex]
  5006. * groupranditem group_num
  5007. *------------------------------------------
  5008. */
  5009. int buildin_grouprandomitem(struct script_state *st)
  5010. {
  5011. int group;
  5012. group = conv_num(st,& (st->stack->stack_data[st->start+2]));
  5013. push_val(st->stack, C_INT, itemdb_searchrandomid(group));
  5014. return 0;
  5015. }
  5016. /*==========================================
  5017. *
  5018. *------------------------------------------
  5019. */
  5020. int buildin_makeitem(struct script_state *st)
  5021. {
  5022. int nameid,amount,flag = 0;
  5023. int x,y,m;
  5024. char *mapname;
  5025. struct item item_tmp;
  5026. struct script_data *data;
  5027. data=&(st->stack->stack_data[st->start+2]);
  5028. get_val(st,data);
  5029. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5030. const char *name=conv_str(st,data);
  5031. struct item_data *item_data = itemdb_searchname(name);
  5032. nameid=UNKNOWN_ITEM_ID;
  5033. if( item_data )
  5034. nameid=item_data->nameid;
  5035. }else
  5036. nameid=conv_num(st,data);
  5037. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5038. mapname =conv_str(st,& (st->stack->stack_data[st->start+4]));
  5039. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  5040. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  5041. if(strcmp(mapname,"this")==0)
  5042. {
  5043. struct map_session_data *sd;
  5044. sd = script_rid2sd(st);
  5045. if (!sd) return 0; //Failed...
  5046. m=sd->bl.m;
  5047. } else
  5048. m=map_mapname2mapid(mapname);
  5049. if(nameid<0) { // ランダム
  5050. nameid=itemdb_searchrandomid(-nameid);
  5051. flag = 1;
  5052. }
  5053. if(nameid > 0) {
  5054. malloc_set(&item_tmp,0,sizeof(item_tmp));
  5055. item_tmp.nameid=nameid;
  5056. if(!flag)
  5057. item_tmp.identify=1;
  5058. else
  5059. item_tmp.identify=itemdb_isidentified(nameid);
  5060. map_addflooritem(&item_tmp,amount,m,x,y,NULL,NULL,NULL,0);
  5061. }
  5062. return 0;
  5063. }
  5064. /*==========================================
  5065. * script DELITEM command (fixed 2 bugs by Lupus, added deletion priority by Lupus)
  5066. *------------------------------------------
  5067. */
  5068. int buildin_delitem(struct script_state *st)
  5069. {
  5070. int nameid=0,amount,i,important_item=0;
  5071. struct map_session_data *sd;
  5072. struct script_data *data;
  5073. sd = script_rid2sd(st);
  5074. data=&(st->stack->stack_data[st->start+2]);
  5075. get_val(st,data);
  5076. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5077. const char *name=conv_str(st,data);
  5078. struct item_data *item_data = itemdb_searchname(name);
  5079. //nameid=UNKNOWN_ITEM_ID;
  5080. if( item_data )
  5081. nameid=item_data->nameid;
  5082. }else
  5083. nameid=conv_num(st,data);
  5084. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5085. if (nameid<500 || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5086. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5087. return 0;
  5088. }
  5089. //1st pass
  5090. //here we won't delete items with CARDS, named items but we count them
  5091. for(i=0;i<MAX_INVENTORY;i++){
  5092. //we don't delete wrong item or equipped item
  5093. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5094. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid)
  5095. continue;
  5096. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5097. if(sd->inventory_data[i]->type==IT_PETEGG &&
  5098. sd->status.inventory[i].card[0] == CARD0_PET)
  5099. {
  5100. if (intif_delete_petdata(MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5101. continue; //pet couldn't be sent for deletion.
  5102. }
  5103. //is this item important? does it have cards? or Player's name? or Refined/Upgraded
  5104. if(itemdb_isspecial(sd->status.inventory[i].card[0]) ||
  5105. sd->status.inventory[i].card[0] ||
  5106. sd->status.inventory[i].refine) {
  5107. //this is important item, count it (except for pet eggs)
  5108. if(sd->status.inventory[i].card[0] != CARD0_PET)
  5109. important_item++;
  5110. continue;
  5111. }
  5112. if(sd->status.inventory[i].amount>=amount){
  5113. //Logs items, got from (N)PC scripts [Lupus]
  5114. if(log_config.enable_logs&0x40)
  5115. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5116. pc_delitem(sd,i,amount,0);
  5117. return 0; //we deleted exact amount of items. now exit
  5118. } else {
  5119. amount-=sd->status.inventory[i].amount;
  5120. //Logs items, got from (N)PC scripts [Lupus]
  5121. if(log_config.enable_logs&0x40) {
  5122. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5123. }
  5124. //Logs
  5125. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5126. }
  5127. }
  5128. //2nd pass
  5129. //now if there WERE items with CARDs/REFINED/NAMED... and if we still have to delete some items. we'll delete them finally
  5130. if (important_item>0 && amount>0)
  5131. for(i=0;i<MAX_INVENTORY;i++){
  5132. //we don't delete wrong item
  5133. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5134. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid )
  5135. continue;
  5136. if(sd->status.inventory[i].amount>=amount){
  5137. //Logs items, got from (N)PC scripts [Lupus]
  5138. if(log_config.enable_logs&0x40)
  5139. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5140. pc_delitem(sd,i,amount,0);
  5141. return 0; //we deleted exact amount of items. now exit
  5142. } else {
  5143. amount-=sd->status.inventory[i].amount;
  5144. //Logs items, got from (N)PC scripts [Lupus]
  5145. if(log_config.enable_logs&0x40)
  5146. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5147. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5148. }
  5149. }
  5150. return 0;
  5151. }
  5152. /*==========================================
  5153. * advanced version of delitem [modified by Mihilion]
  5154. *------------------------------------------
  5155. */
  5156. int buildin_delitem2(struct script_state *st)
  5157. {
  5158. int nameid=0,amount,i=0;
  5159. int iden,ref,attr,c1,c2,c3,c4;
  5160. struct map_session_data *sd;
  5161. struct script_data *data;
  5162. sd = script_rid2sd(st);
  5163. data=&(st->stack->stack_data[st->start+2]);
  5164. get_val(st,data);
  5165. if( data->type==C_STR || data->type==C_CONSTSTR ){
  5166. const char *name=conv_str(st,data);
  5167. struct item_data *item_data = itemdb_searchname(name);
  5168. //nameid=UNKNOWN_ITEM_ID;
  5169. if( item_data )
  5170. nameid=item_data->nameid;
  5171. }else
  5172. nameid=conv_num(st,data);
  5173. amount=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5174. iden=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5175. ref=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5176. attr=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5177. c1=conv_num(st,& (st->stack->stack_data[st->start+7]));
  5178. c2=conv_num(st,& (st->stack->stack_data[st->start+8]));
  5179. c3=conv_num(st,& (st->stack->stack_data[st->start+9]));
  5180. c4=conv_num(st,& (st->stack->stack_data[st->start+10]));
  5181. if (!itemdb_exists(nameid) || amount<=0 ) {//by Lupus. Don't run FOR if u got wrong item ID or amount<=0
  5182. //eprintf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
  5183. return 0;
  5184. }
  5185. for(i=0;i<MAX_INVENTORY;i++){
  5186. //we don't delete wrong item or equipped item
  5187. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5188. sd->status.inventory[i].amount<=0 || sd->status.inventory[i].nameid!=nameid ||
  5189. sd->status.inventory[i].identify!=iden || sd->status.inventory[i].refine!=ref ||
  5190. sd->status.inventory[i].attribute!=attr || sd->status.inventory[i].card[0]!=c1 ||
  5191. sd->status.inventory[i].card[1]!=c2 || sd->status.inventory[i].card[2]!=c3 ||
  5192. sd->status.inventory[i].card[3]!=c4)
  5193. continue;
  5194. //1 egg uses 1 cell in the inventory. so it's ok to delete 1 pet / per cycle
  5195. if(sd->inventory_data[i]->type==IT_PETEGG && sd->status.inventory[i].card[0] == CARD0_PET)
  5196. {
  5197. if (!intif_delete_petdata( MakeDWord(sd->status.inventory[i].card[1], sd->status.inventory[i].card[2])))
  5198. continue; //Failed to send delete the pet.
  5199. }
  5200. if(sd->status.inventory[i].amount>=amount){
  5201. //Logs items, got from (N)PC scripts [Lupus]
  5202. if(log_config.enable_logs&0x40)
  5203. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -amount, &sd->status.inventory[i]);
  5204. pc_delitem(sd,i,amount,0);
  5205. return 0; //we deleted exact amount of items. now exit
  5206. } else {
  5207. amount-=sd->status.inventory[i].amount;
  5208. //Logs items, got from (N)PC scripts [Lupus]
  5209. if(log_config.enable_logs&0x40)
  5210. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  5211. pc_delitem(sd,i,sd->status.inventory[i].amount,0);
  5212. }
  5213. }
  5214. return 0;
  5215. }
  5216. /*==========================================
  5217. * Enables/Disables use of items while in an NPC [Skotlex]
  5218. *------------------------------------------
  5219. */
  5220. int buildin_enableitemuse(struct script_state *st) {
  5221. struct map_session_data *sd;
  5222. sd=script_rid2sd(st);
  5223. if (sd)
  5224. sd->npc_item_flag = st->oid;
  5225. return 0;
  5226. }
  5227. int buildin_disableitemuse(struct script_state *st) {
  5228. struct map_session_data *sd;
  5229. sd=script_rid2sd(st);
  5230. if (sd)
  5231. sd->npc_item_flag = 0;
  5232. return 0;
  5233. }
  5234. /*==========================================
  5235. *キャラ関係のパラメータ取得
  5236. *------------------------------------------
  5237. */
  5238. int buildin_readparam(struct script_state *st)
  5239. {
  5240. int type;
  5241. struct map_session_data *sd;
  5242. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5243. if( st->end>st->start+3 )
  5244. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5245. else
  5246. sd=script_rid2sd(st);
  5247. if(sd==NULL){
  5248. push_val(st->stack,C_INT,-1);
  5249. return 0;
  5250. }
  5251. push_val(st->stack,C_INT,pc_readparam(sd,type));
  5252. return 0;
  5253. }
  5254. /*==========================================
  5255. *キャラ関係のID取得
  5256. *------------------------------------------
  5257. */
  5258. int buildin_getcharid(struct script_state *st)
  5259. {
  5260. int num;
  5261. struct map_session_data *sd;
  5262. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5263. if( st->end>st->start+3 )
  5264. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+3])));
  5265. else
  5266. sd=script_rid2sd(st);
  5267. if(sd==NULL || num<0 || num>3){
  5268. push_val(st->stack,C_INT,0); //return 0, according docs
  5269. return 0;
  5270. }
  5271. if(num==0)
  5272. push_val(st->stack,C_INT,sd->status.char_id);
  5273. if(num==1)
  5274. push_val(st->stack,C_INT,sd->status.party_id);
  5275. if(num==2)
  5276. push_val(st->stack,C_INT,sd->status.guild_id);
  5277. if(num==3)
  5278. push_val(st->stack,C_INT,sd->status.account_id);
  5279. return 0;
  5280. }
  5281. /*==========================================
  5282. *指定IDのPT名取得
  5283. *------------------------------------------
  5284. */
  5285. char *buildin_getpartyname_sub(int party_id)
  5286. {
  5287. struct party_data *p;
  5288. p=party_search(party_id);
  5289. if(p!=NULL){
  5290. char *buf;
  5291. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5292. memcpy(buf, p->party.name, NAME_LENGTH-1);
  5293. buf[NAME_LENGTH-1] = '\0';
  5294. return buf;
  5295. }
  5296. return 0;
  5297. }
  5298. int buildin_getpartyname(struct script_state *st)
  5299. {
  5300. char *name;
  5301. int party_id;
  5302. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5303. name=buildin_getpartyname_sub(party_id);
  5304. if(name != NULL)
  5305. push_str(st->stack,C_STR,name);
  5306. else
  5307. push_str(st->stack,C_CONSTSTR,"null");
  5308. return 0;
  5309. }
  5310. /*==========================================
  5311. *指定IDのPT人数とメンバーID取得
  5312. *------------------------------------------
  5313. */
  5314. int buildin_getpartymember(struct script_state *st)
  5315. {
  5316. struct party_data *p;
  5317. int i,j=0,type=0;
  5318. p=party_search(conv_num(st,& (st->stack->stack_data[st->start+2])));
  5319. if( st->end>st->start+3 )
  5320. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5321. if(p!=NULL){
  5322. for(i=0;i<MAX_PARTY;i++){
  5323. if(p->party.member[i].account_id){
  5324. switch (type) {
  5325. case 2:
  5326. mapreg_setreg(add_str("$@partymemberaid")+(j<<24),p->party.member[i].account_id);
  5327. break;
  5328. case 1:
  5329. mapreg_setreg(add_str("$@partymembercid")+(j<<24),p->party.member[i].char_id);
  5330. break;
  5331. default:
  5332. mapreg_setregstr(add_str("$@partymembername$")+(j<<24),p->party.member[i].name);
  5333. }
  5334. j++;
  5335. }
  5336. }
  5337. }
  5338. mapreg_setreg(add_str("$@partymembercount"),j);
  5339. return 0;
  5340. }
  5341. /*==========================================
  5342. * Retrieves party leader. if flag is specified,
  5343. * return some of the leader data. Otherwise, return name.
  5344. *------------------------------------------
  5345. */
  5346. int buildin_getpartyleader(struct script_state *st)
  5347. {
  5348. int party_id, type = 0, i=0;
  5349. struct party_data *p;
  5350. party_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5351. if( st->end>st->start+3 )
  5352. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5353. p=party_search(party_id);
  5354. if (p) //Search leader
  5355. for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
  5356. if (!p || i == MAX_PARTY) { //leader not found
  5357. if (type)
  5358. push_val(st->stack,C_INT,-1);
  5359. else
  5360. push_str(st->stack,C_CONSTSTR,"null");
  5361. return 0;
  5362. }
  5363. switch (type) {
  5364. case 1:
  5365. push_val(st->stack,C_INT,p->party.member[i].account_id);
  5366. break;
  5367. case 2:
  5368. push_val(st->stack,C_INT,p->party.member[i].char_id);
  5369. break;
  5370. case 3:
  5371. push_val(st->stack,C_INT,p->party.member[i].class_);
  5372. break;
  5373. case 4:
  5374. push_val(st->stack,C_INT,p->party.member[i].map);
  5375. break;
  5376. case 5:
  5377. push_val(st->stack,C_INT,p->party.member[i].lv);
  5378. break;
  5379. default:
  5380. push_str(st->stack,C_STR,p->party.member[i].name);
  5381. break;
  5382. }
  5383. return 0;
  5384. }
  5385. /*==========================================
  5386. *指定IDのギルド名取得
  5387. *------------------------------------------
  5388. */
  5389. char *buildin_getguildname_sub(int guild_id)
  5390. {
  5391. struct guild *g=NULL;
  5392. g=guild_search(guild_id);
  5393. if(g!=NULL){
  5394. char *buf;
  5395. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5396. memcpy(buf, g->name, NAME_LENGTH-1);
  5397. buf[NAME_LENGTH-1] = '\0';
  5398. return buf;
  5399. }
  5400. return NULL;
  5401. }
  5402. int buildin_getguildname(struct script_state *st)
  5403. {
  5404. char *name;
  5405. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5406. name=buildin_getguildname_sub(guild_id);
  5407. if(name != NULL)
  5408. push_str(st->stack,C_STR,name);
  5409. else
  5410. push_str(st->stack,C_CONSTSTR,"null");
  5411. return 0;
  5412. }
  5413. /*==========================================
  5414. *指定IDのGuildMaster名取得
  5415. *------------------------------------------
  5416. */
  5417. char *buildin_getguildmaster_sub(int guild_id)
  5418. {
  5419. struct guild *g=NULL;
  5420. g=guild_search(guild_id);
  5421. if(g!=NULL){
  5422. char *buf;
  5423. buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
  5424. memcpy(buf, g->master, NAME_LENGTH-1);
  5425. buf[NAME_LENGTH-1] = '\0';
  5426. return buf;
  5427. }
  5428. return 0;
  5429. }
  5430. int buildin_getguildmaster(struct script_state *st)
  5431. {
  5432. char *master;
  5433. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5434. master=buildin_getguildmaster_sub(guild_id);
  5435. if(master!=0)
  5436. push_str(st->stack,C_STR,master);
  5437. else
  5438. push_str(st->stack,C_CONSTSTR,"null");
  5439. return 0;
  5440. }
  5441. int buildin_getguildmasterid(struct script_state *st)
  5442. {
  5443. char *master;
  5444. struct map_session_data *sd=NULL;
  5445. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5446. master=buildin_getguildmaster_sub(guild_id);
  5447. if(master!=0){
  5448. if((sd=map_nick2sd(master)) == NULL){
  5449. push_val(st->stack,C_INT,0);
  5450. return 0;
  5451. }
  5452. push_val(st->stack,C_INT,sd->status.char_id);
  5453. }else{
  5454. push_val(st->stack,C_INT,0);
  5455. }
  5456. return 0;
  5457. }
  5458. /*==========================================
  5459. * キャラクタの名前
  5460. *------------------------------------------
  5461. */
  5462. int buildin_strcharinfo(struct script_state *st)
  5463. {
  5464. struct map_session_data *sd;
  5465. int num;
  5466. char *buf;
  5467. sd=script_rid2sd(st);
  5468. if (!sd) { //Avoid crashing....
  5469. push_str(st->stack,C_CONSTSTR,"");
  5470. return 0;
  5471. }
  5472. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5473. switch(num){
  5474. case 0:
  5475. push_str(st->stack,C_CONSTSTR,sd->status.name);
  5476. break;
  5477. case 1:
  5478. buf=buildin_getpartyname_sub(sd->status.party_id);
  5479. if(buf!=0)
  5480. push_str(st->stack,C_STR,buf);
  5481. else
  5482. push_str(st->stack,C_CONSTSTR,"");
  5483. break;
  5484. case 2:
  5485. buf=buildin_getguildname_sub(sd->status.guild_id);
  5486. if(buf != NULL)
  5487. push_str(st->stack,C_STR,buf);
  5488. else
  5489. push_str(st->stack,C_CONSTSTR,"");
  5490. break;
  5491. default:
  5492. ShowWarning("buildin_strcharinfo: unknown parameter.");
  5493. push_str(st->stack,C_CONSTSTR,"");
  5494. break;
  5495. }
  5496. return 0;
  5497. }
  5498. unsigned int equip[10]={EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW};
  5499. /*==========================================
  5500. * GetEquipID(Pos); Pos: 1-10
  5501. *------------------------------------------
  5502. */
  5503. int buildin_getequipid(struct script_state *st)
  5504. {
  5505. int i,num;
  5506. struct map_session_data *sd;
  5507. struct item_data* item;
  5508. sd=script_rid2sd(st);
  5509. if(sd == NULL)
  5510. {
  5511. ShowError("getequipid: sd == NULL\n");
  5512. return 0;
  5513. }
  5514. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5515. i=pc_checkequip(sd,equip[num-1]);
  5516. if(i >= 0){
  5517. item=sd->inventory_data[i];
  5518. if(item)
  5519. push_val(st->stack,C_INT,item->nameid);
  5520. else
  5521. push_val(st->stack,C_INT,0);
  5522. }else{
  5523. push_val(st->stack,C_INT,-1);
  5524. }
  5525. return 0;
  5526. }
  5527. /*==========================================
  5528. * 装備名文字列(精錬メニュー用)
  5529. *------------------------------------------
  5530. */
  5531. int buildin_getequipname(struct script_state *st)
  5532. {
  5533. int i,num;
  5534. struct map_session_data *sd;
  5535. struct item_data* item;
  5536. char *buf;
  5537. buf=(char *)aMallocA(64*sizeof(char));
  5538. sd=script_rid2sd(st);
  5539. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5540. i=pc_checkequip(sd,equip[num-1]);
  5541. if(i >= 0){
  5542. item=sd->inventory_data[i];
  5543. if(item)
  5544. sprintf(buf,"%s-[%s]",pos[num-1],item->jname);
  5545. else
  5546. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5547. }else{
  5548. sprintf(buf,"%s-[%s]",pos[num-1],pos[10]);
  5549. }
  5550. push_str(st->stack,C_STR,buf);
  5551. return 0;
  5552. }
  5553. /*==========================================
  5554. * getbrokenid [Valaris]
  5555. *------------------------------------------
  5556. */
  5557. int buildin_getbrokenid(struct script_state *st)
  5558. {
  5559. int i,num,id=0,brokencounter=0;
  5560. struct map_session_data *sd;
  5561. sd=script_rid2sd(st);
  5562. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5563. for(i=0; i<MAX_INVENTORY; i++) {
  5564. if(sd->status.inventory[i].attribute==1){
  5565. brokencounter++;
  5566. if(num==brokencounter){
  5567. id=sd->status.inventory[i].nameid;
  5568. break;
  5569. }
  5570. }
  5571. }
  5572. push_val(st->stack,C_INT,id);
  5573. return 0;
  5574. }
  5575. /*==========================================
  5576. * repair [Valaris]
  5577. *------------------------------------------
  5578. */
  5579. int buildin_repair(struct script_state *st)
  5580. {
  5581. int i,num;
  5582. int repaircounter=0;
  5583. struct map_session_data *sd;
  5584. sd=script_rid2sd(st);
  5585. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5586. for(i=0; i<MAX_INVENTORY; i++) {
  5587. if(sd->status.inventory[i].attribute==1){
  5588. repaircounter++;
  5589. if(num==repaircounter){
  5590. sd->status.inventory[i].attribute=0;
  5591. clif_equiplist(sd);
  5592. clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
  5593. clif_misceffect(&sd->bl, 3);
  5594. break;
  5595. }
  5596. }
  5597. }
  5598. return 0;
  5599. }
  5600. /*==========================================
  5601. * 装備チェック
  5602. *------------------------------------------
  5603. */
  5604. int buildin_getequipisequiped(struct script_state *st)
  5605. {
  5606. int i,num;
  5607. struct map_session_data *sd;
  5608. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5609. sd=script_rid2sd(st);
  5610. if ((num - 1) >= (sizeof(equip) / sizeof(equip[0])))
  5611. i = -1;
  5612. else
  5613. i=pc_checkequip(sd,equip[num-1]);
  5614. if(i >= 0)
  5615. push_val(st->stack,C_INT,1);
  5616. else
  5617. push_val(st->stack,C_INT,0);
  5618. return 0;
  5619. }
  5620. /*==========================================
  5621. * 装備品精錬可能チェック
  5622. *------------------------------------------
  5623. */
  5624. int buildin_getequipisenableref(struct script_state *st)
  5625. {
  5626. int i,num;
  5627. struct map_session_data *sd;
  5628. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5629. sd=script_rid2sd(st);
  5630. i=pc_checkequip(sd,equip[num-1]);
  5631. if(i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine)
  5632. {
  5633. push_val(st->stack,C_INT,1);
  5634. } else {
  5635. push_val(st->stack,C_INT,0);
  5636. }
  5637. return 0;
  5638. }
  5639. /*==========================================
  5640. * 装備品鑑定チェック
  5641. *------------------------------------------
  5642. */
  5643. int buildin_getequipisidentify(struct script_state *st)
  5644. {
  5645. int i,num;
  5646. struct map_session_data *sd;
  5647. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5648. sd=script_rid2sd(st);
  5649. i=pc_checkequip(sd,equip[num-1]);
  5650. if(i >= 0)
  5651. push_val(st->stack,C_INT,sd->status.inventory[i].identify);
  5652. else
  5653. push_val(st->stack,C_INT,0);
  5654. return 0;
  5655. }
  5656. /*==========================================
  5657. * 装備品精錬度
  5658. *------------------------------------------
  5659. */
  5660. int buildin_getequiprefinerycnt(struct script_state *st)
  5661. {
  5662. int i,num;
  5663. struct map_session_data *sd;
  5664. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5665. sd=script_rid2sd(st);
  5666. i=pc_checkequip(sd,equip[num-1]);
  5667. if(i >= 0)
  5668. push_val(st->stack,C_INT,sd->status.inventory[i].refine);
  5669. else
  5670. push_val(st->stack,C_INT,0);
  5671. return 0;
  5672. }
  5673. /*==========================================
  5674. * 装備品武器LV
  5675. *------------------------------------------
  5676. */
  5677. int buildin_getequipweaponlv(struct script_state *st)
  5678. {
  5679. int i,num;
  5680. struct map_session_data *sd;
  5681. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5682. sd=script_rid2sd(st);
  5683. i=pc_checkequip(sd,equip[num-1]);
  5684. if(i >= 0 && sd->inventory_data[i])
  5685. push_val(st->stack,C_INT,sd->inventory_data[i]->wlv);
  5686. else
  5687. push_val(st->stack,C_INT,0);
  5688. return 0;
  5689. }
  5690. /*==========================================
  5691. * 装備品精錬成功率
  5692. *------------------------------------------
  5693. */
  5694. int buildin_getequippercentrefinery(struct script_state *st)
  5695. {
  5696. int i,num;
  5697. struct map_session_data *sd;
  5698. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5699. sd=script_rid2sd(st);
  5700. i=pc_checkequip(sd,equip[num-1]);
  5701. if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
  5702. push_val(st->stack,C_INT,percentrefinery[itemdb_wlv(sd->status.inventory[i].nameid)][(int)sd->status.inventory[i].refine]);
  5703. else
  5704. push_val(st->stack,C_INT,0);
  5705. return 0;
  5706. }
  5707. /*==========================================
  5708. * 精錬成功
  5709. *------------------------------------------
  5710. */
  5711. int buildin_successrefitem(struct script_state *st)
  5712. {
  5713. int i,num,ep;
  5714. struct map_session_data *sd;
  5715. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5716. sd=script_rid2sd(st);
  5717. i=pc_checkequip(sd,equip[num-1]);
  5718. if(i >= 0) {
  5719. ep=sd->status.inventory[i].equip;
  5720. //Logs items, got from (N)PC scripts [Lupus]
  5721. if(log_config.enable_logs&0x40)
  5722. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5723. sd->status.inventory[i].refine++;
  5724. pc_unequipitem(sd,i,2);
  5725. clif_refine(sd->fd,sd,0,i,sd->status.inventory[i].refine);
  5726. clif_delitem(sd,i,1);
  5727. //Logs items, got from (N)PC scripts [Lupus]
  5728. if(log_config.enable_logs&0x40)
  5729. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, 1, &sd->status.inventory[i]);
  5730. clif_additem(sd,i,1,0);
  5731. pc_equipitem(sd,i,ep);
  5732. clif_misceffect(&sd->bl,3);
  5733. if(sd->status.inventory[i].refine == MAX_REFINE &&
  5734. sd->status.inventory[i].card[0] == CARD0_FORGE &&
  5735. sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
  5736. ){ // Fame point system [DracoRPG]
  5737. switch (sd->inventory_data[i]->wlv){
  5738. case 1:
  5739. pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
  5740. break;
  5741. case 2:
  5742. pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
  5743. break;
  5744. case 3:
  5745. pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
  5746. break;
  5747. }
  5748. }
  5749. }
  5750. return 0;
  5751. }
  5752. /*==========================================
  5753. * 精錬失敗
  5754. *------------------------------------------
  5755. */
  5756. int buildin_failedrefitem(struct script_state *st)
  5757. {
  5758. int i,num;
  5759. struct map_session_data *sd;
  5760. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5761. sd=script_rid2sd(st);
  5762. i=pc_checkequip(sd,equip[num-1]);
  5763. if(i >= 0) {
  5764. //Logs items, got from (N)PC scripts [Lupus]
  5765. if(log_config.enable_logs&0x40)
  5766. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  5767. sd->status.inventory[i].refine = 0;
  5768. pc_unequipitem(sd,i,3);
  5769. // 精錬失敗エフェクトのパケット
  5770. clif_refine(sd->fd,sd,1,i,sd->status.inventory[i].refine);
  5771. pc_delitem(sd,i,1,0);
  5772. // 他の人にも失敗を通知
  5773. clif_misceffect(&sd->bl,2);
  5774. }
  5775. return 0;
  5776. }
  5777. /*==========================================
  5778. *
  5779. *------------------------------------------
  5780. */
  5781. int buildin_statusup(struct script_state *st)
  5782. {
  5783. int type;
  5784. struct map_session_data *sd;
  5785. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5786. sd=script_rid2sd(st);
  5787. pc_statusup(sd,type);
  5788. return 0;
  5789. }
  5790. /*==========================================
  5791. *
  5792. *------------------------------------------
  5793. */
  5794. int buildin_statusup2(struct script_state *st)
  5795. {
  5796. int type,val;
  5797. struct map_session_data *sd;
  5798. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5799. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5800. sd=script_rid2sd(st);
  5801. pc_statusup2(sd,type,val);
  5802. return 0;
  5803. }
  5804. /*==========================================
  5805. * 装備品による能力値ボーナス
  5806. *------------------------------------------
  5807. */
  5808. int buildin_bonus(struct script_state *st)
  5809. {
  5810. int type,val;
  5811. struct map_session_data *sd;
  5812. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5813. val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5814. sd=script_rid2sd(st);
  5815. pc_bonus(sd,type,val);
  5816. return 0;
  5817. }
  5818. /*==========================================
  5819. * 装備品による能力値ボーナス
  5820. *------------------------------------------
  5821. */
  5822. int buildin_bonus2(struct script_state *st)
  5823. {
  5824. int type,type2,val;
  5825. struct map_session_data *sd;
  5826. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5827. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5828. val=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5829. sd=script_rid2sd(st);
  5830. pc_bonus2(sd,type,type2,val);
  5831. return 0;
  5832. }
  5833. /*==========================================
  5834. * 装備品による能力値ボーナス
  5835. *------------------------------------------
  5836. */
  5837. int buildin_bonus3(struct script_state *st)
  5838. {
  5839. int type,type2,type3,val;
  5840. struct map_session_data *sd;
  5841. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5842. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5843. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5844. val=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5845. sd=script_rid2sd(st);
  5846. pc_bonus3(sd,type,type2,type3,val);
  5847. return 0;
  5848. }
  5849. int buildin_bonus4(struct script_state *st)
  5850. {
  5851. int type,type2,type3,type4,val;
  5852. struct map_session_data *sd;
  5853. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5854. type2=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5855. type3=conv_num(st,& (st->stack->stack_data[st->start+4]));
  5856. type4=conv_num(st,& (st->stack->stack_data[st->start+5]));
  5857. val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  5858. sd=script_rid2sd(st);
  5859. pc_bonus4(sd,type,type2,type3,type4,val);
  5860. return 0;
  5861. }
  5862. /*==========================================
  5863. * スキル所得
  5864. *------------------------------------------
  5865. */
  5866. int buildin_skill(struct script_state *st)
  5867. {
  5868. int id,level,flag=1;
  5869. struct map_session_data *sd;
  5870. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5871. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5872. if( st->end>st->start+4 )
  5873. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5874. sd=script_rid2sd(st);
  5875. pc_skill(sd,id,level,flag);
  5876. return 0;
  5877. }
  5878. // add x levels of skill (stackable) [Valaris]
  5879. int buildin_addtoskill(struct script_state *st)
  5880. {
  5881. int id,level,flag=2;
  5882. struct map_session_data *sd;
  5883. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5884. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5885. if( st->end>st->start+4 )
  5886. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5887. sd=script_rid2sd(st);
  5888. pc_skill(sd,id,level,flag);
  5889. return 0;
  5890. }
  5891. /*==========================================
  5892. * ギルドスキル取得
  5893. *------------------------------------------
  5894. */
  5895. int buildin_guildskill(struct script_state *st)
  5896. {
  5897. int id,level,flag=0;
  5898. struct map_session_data *sd;
  5899. int i=0;
  5900. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5901. level=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5902. if( st->end>st->start+4 )
  5903. flag=conv_num(st,&(st->stack->stack_data[st->start+4]) );
  5904. sd=script_rid2sd(st);
  5905. for(i=0;i<level;i++)
  5906. guild_skillup(sd,id,flag);
  5907. return 0;
  5908. }
  5909. /*==========================================
  5910. * スキルレベル所得
  5911. *------------------------------------------
  5912. */
  5913. int buildin_getskilllv(struct script_state *st)
  5914. {
  5915. int id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5916. push_val(st->stack,C_INT, pc_checkskill( script_rid2sd(st) ,id) );
  5917. return 0;
  5918. }
  5919. /*==========================================
  5920. * getgdskilllv(Guild_ID, Skill_ID);
  5921. * skill_id = 10000 : GD_APPROVAL
  5922. * 10001 : GD_KAFRACONTRACT
  5923. * 10002 : GD_GUARDIANRESEARCH
  5924. * 10003 : GD_GUARDUP
  5925. * 10004 : GD_EXTENSION
  5926. *------------------------------------------
  5927. */
  5928. int buildin_getgdskilllv(struct script_state *st)
  5929. {
  5930. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5931. int skill_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  5932. struct guild *g=guild_search(guild_id);
  5933. push_val(st->stack,C_INT, (g==NULL)?-1:guild_checkskill(g,skill_id) );
  5934. return 0;
  5935. /*
  5936. struct map_session_data *sd=NULL;
  5937. struct guild *g=NULL;
  5938. int skill_id;
  5939. skill_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5940. sd=script_rid2sd(st);
  5941. if(sd && sd->status.guild_id > 0) g=guild_search(sd->status.guild_id);
  5942. if(sd && g) {
  5943. push_val(st->stack,C_INT, guild_checkskill(g,skill_id+9999) );
  5944. } else {
  5945. push_val(st->stack,C_INT,-1);
  5946. }
  5947. return 0;
  5948. */
  5949. }
  5950. /*==========================================
  5951. *
  5952. *------------------------------------------
  5953. */
  5954. int buildin_basicskillcheck(struct script_state *st)
  5955. {
  5956. push_val(st->stack,C_INT, battle_config.basic_skill_check);
  5957. return 0;
  5958. }
  5959. /*==========================================
  5960. *
  5961. *------------------------------------------
  5962. */
  5963. int buildin_getgmlevel(struct script_state *st)
  5964. {
  5965. push_val(st->stack,C_INT, pc_isGM(script_rid2sd(st)));
  5966. return 0;
  5967. }
  5968. /*==========================================
  5969. *
  5970. *------------------------------------------
  5971. */
  5972. int buildin_end(struct script_state *st)
  5973. {
  5974. st->state = END;
  5975. return 0;
  5976. }
  5977. /*==========================================
  5978. *
  5979. *------------------------------------------
  5980. */
  5981. int buildin_checkoption(struct script_state *st)
  5982. {
  5983. int type;
  5984. struct map_session_data *sd;
  5985. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  5986. sd=script_rid2sd(st);
  5987. if(sd->sc.option & type){
  5988. push_val(st->stack,C_INT,1);
  5989. } else {
  5990. push_val(st->stack,C_INT,0);
  5991. }
  5992. return 0;
  5993. }
  5994. /*==========================================
  5995. *
  5996. *------------------------------------------
  5997. */
  5998. int buildin_checkoption1(struct script_state *st)
  5999. {
  6000. int type;
  6001. struct map_session_data *sd;
  6002. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6003. sd=script_rid2sd(st);
  6004. if(sd->sc.opt1 & type){
  6005. push_val(st->stack,C_INT,1);
  6006. } else {
  6007. push_val(st->stack,C_INT,0);
  6008. }
  6009. return 0;
  6010. }
  6011. /*==========================================
  6012. *
  6013. *------------------------------------------
  6014. */
  6015. int buildin_checkoption2(struct script_state *st)
  6016. {
  6017. int type;
  6018. struct map_session_data *sd;
  6019. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6020. sd=script_rid2sd(st);
  6021. if(sd->sc.opt2 & type){
  6022. push_val(st->stack,C_INT,1);
  6023. } else {
  6024. push_val(st->stack,C_INT,0);
  6025. }
  6026. return 0;
  6027. }
  6028. /*==========================================
  6029. *
  6030. *------------------------------------------
  6031. */
  6032. int buildin_setoption(struct script_state *st)
  6033. {
  6034. int type;
  6035. struct map_session_data *sd;
  6036. int flag=1;
  6037. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6038. if(st->end>st->start+3 )
  6039. flag=conv_num(st,&(st->stack->stack_data[st->start+3]) );
  6040. else if (!type) { //Request to remove everything.
  6041. flag = 0;
  6042. type = OPTION_CART|OPTION_FALCON|OPTION_RIDING;
  6043. }
  6044. sd=script_rid2sd(st);
  6045. if (!sd) return 0;
  6046. if (flag) {//Add option
  6047. if (type&OPTION_WEDDING && !battle_config.wedding_modifydisplay)
  6048. type&=~OPTION_WEDDING; //Do not show the wedding sprites
  6049. pc_setoption(sd,sd->sc.option|type);
  6050. } else//Remove option
  6051. pc_setoption(sd,sd->sc.option&~type);
  6052. return 0;
  6053. }
  6054. /*==========================================
  6055. * Checkcart [Valaris]
  6056. *------------------------------------------
  6057. */
  6058. int buildin_checkcart(struct script_state *st)
  6059. {
  6060. struct map_session_data *sd;
  6061. sd=script_rid2sd(st);
  6062. if(pc_iscarton(sd)){
  6063. push_val(st->stack,C_INT,1);
  6064. } else {
  6065. push_val(st->stack,C_INT,0);
  6066. }
  6067. return 0;
  6068. }
  6069. /*==========================================
  6070. * カートを付ける
  6071. *------------------------------------------
  6072. */
  6073. int buildin_setcart(struct script_state *st)
  6074. {
  6075. struct map_session_data *sd;
  6076. sd=script_rid2sd(st);
  6077. pc_setcart(sd,1);
  6078. return 0;
  6079. }
  6080. /*==========================================
  6081. * checkfalcon [Valaris]
  6082. *------------------------------------------
  6083. */
  6084. int buildin_checkfalcon(struct script_state *st)
  6085. {
  6086. struct map_session_data *sd;
  6087. sd=script_rid2sd(st);
  6088. if(pc_isfalcon(sd)){
  6089. push_val(st->stack,C_INT,1);
  6090. } else {
  6091. push_val(st->stack,C_INT,0);
  6092. }
  6093. return 0;
  6094. }
  6095. /*==========================================
  6096. * 鷹を付ける
  6097. *------------------------------------------
  6098. */
  6099. int buildin_setfalcon(struct script_state *st)
  6100. {
  6101. struct map_session_data *sd;
  6102. sd=script_rid2sd(st);
  6103. pc_setfalcon(sd);
  6104. return 0;
  6105. }
  6106. /*==========================================
  6107. * Checkcart [Valaris]
  6108. *------------------------------------------
  6109. */
  6110. int buildin_checkriding(struct script_state *st)
  6111. {
  6112. struct map_session_data *sd;
  6113. sd=script_rid2sd(st);
  6114. if(pc_isriding(sd)){
  6115. push_val(st->stack,C_INT,1);
  6116. } else {
  6117. push_val(st->stack,C_INT,0);
  6118. }
  6119. return 0;
  6120. }
  6121. /*==========================================
  6122. * ペコペコ乗り
  6123. *------------------------------------------
  6124. */
  6125. int buildin_setriding(struct script_state *st)
  6126. {
  6127. struct map_session_data *sd;
  6128. sd=script_rid2sd(st);
  6129. pc_setriding(sd);
  6130. return 0;
  6131. }
  6132. /*==========================================
  6133. * セーブポイントの保存
  6134. *------------------------------------------
  6135. */
  6136. int buildin_savepoint(struct script_state *st)
  6137. {
  6138. int x,y;
  6139. short map;
  6140. char *str;
  6141. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6142. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6143. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6144. map = mapindex_name2id(str);
  6145. if (map)
  6146. pc_setsavepoint(script_rid2sd(st),map,x,y);
  6147. return 0;
  6148. }
  6149. /*==========================================
  6150. * GetTimeTick(0: System Tick, 1: Time Second Tick)
  6151. *------------------------------------------
  6152. */
  6153. int buildin_gettimetick(struct script_state *st) /* Asgard Version */
  6154. {
  6155. int type;
  6156. time_t timer;
  6157. struct tm *t;
  6158. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6159. switch(type){
  6160. case 2:
  6161. //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
  6162. // from the system clock.)
  6163. push_val(st->stack,C_INT,(int)time(NULL));
  6164. break;
  6165. case 1:
  6166. //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
  6167. time(&timer);
  6168. t=localtime(&timer);
  6169. push_val(st->stack,C_INT,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
  6170. break;
  6171. case 0:
  6172. default:
  6173. //type 0:(System Ticks)
  6174. push_val(st->stack,C_INT,gettick());
  6175. break;
  6176. }
  6177. return 0;
  6178. }
  6179. /*==========================================
  6180. * GetTime(Type);
  6181. * 1: Sec 2: Min 3: Hour
  6182. * 4: WeekDay 5: MonthDay 6: Month
  6183. * 7: Year
  6184. *------------------------------------------
  6185. */
  6186. int buildin_gettime(struct script_state *st) /* Asgard Version */
  6187. {
  6188. int type;
  6189. time_t timer;
  6190. struct tm *t;
  6191. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6192. time(&timer);
  6193. t=localtime(&timer);
  6194. switch(type){
  6195. case 1://Sec(0~59)
  6196. push_val(st->stack,C_INT,t->tm_sec);
  6197. break;
  6198. case 2://Min(0~59)
  6199. push_val(st->stack,C_INT,t->tm_min);
  6200. break;
  6201. case 3://Hour(0~23)
  6202. push_val(st->stack,C_INT,t->tm_hour);
  6203. break;
  6204. case 4://WeekDay(0~6)
  6205. push_val(st->stack,C_INT,t->tm_wday);
  6206. break;
  6207. case 5://MonthDay(01~31)
  6208. push_val(st->stack,C_INT,t->tm_mday);
  6209. break;
  6210. case 6://Month(01~12)
  6211. push_val(st->stack,C_INT,t->tm_mon+1);
  6212. break;
  6213. case 7://Year(20xx)
  6214. push_val(st->stack,C_INT,t->tm_year+1900);
  6215. break;
  6216. case 8://Year Day(01~366)
  6217. push_val(st->stack,C_INT,t->tm_yday+1);
  6218. break;
  6219. default://(format error)
  6220. push_val(st->stack,C_INT,-1);
  6221. break;
  6222. }
  6223. return 0;
  6224. }
  6225. /*==========================================
  6226. * GetTimeStr("TimeFMT", Length);
  6227. *------------------------------------------
  6228. */
  6229. int buildin_gettimestr(struct script_state *st)
  6230. {
  6231. char *tmpstr;
  6232. char *fmtstr;
  6233. int maxlen;
  6234. time_t now = time(NULL);
  6235. fmtstr=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6236. maxlen=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6237. tmpstr=(char *)aMallocA((maxlen+1)*sizeof(char));
  6238. strftime(tmpstr,maxlen,fmtstr,localtime(&now));
  6239. tmpstr[maxlen]='\0';
  6240. push_str(st->stack,C_STR,tmpstr);
  6241. return 0;
  6242. }
  6243. /*==========================================
  6244. * カプラ倉庫を開く
  6245. *------------------------------------------
  6246. */
  6247. int buildin_openstorage(struct script_state *st)
  6248. {
  6249. storage_storageopen(script_rid2sd(st));
  6250. return 0;
  6251. }
  6252. int buildin_guildopenstorage(struct script_state *st)
  6253. {
  6254. struct map_session_data *sd=script_rid2sd(st);
  6255. int ret;
  6256. ret = storage_guild_storageopen(sd);
  6257. push_val(st->stack,C_INT,ret);
  6258. return 0;
  6259. }
  6260. /*==========================================
  6261. * アイテムによるスキル発動
  6262. *------------------------------------------
  6263. */
  6264. int buildin_itemskill(struct script_state *st)
  6265. {
  6266. int id,lv;
  6267. char *str;
  6268. struct map_session_data *sd=script_rid2sd(st);
  6269. id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6270. lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6271. str=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6272. // 詠唱中にスキルアイテムは使用できない
  6273. if(sd->ud.skilltimer != -1)
  6274. return 0;
  6275. sd->skillitem=id;
  6276. sd->skillitemlv=lv;
  6277. clif_item_skill(sd,id,lv,str);
  6278. return 0;
  6279. }
  6280. /*==========================================
  6281. * アイテム作成
  6282. *------------------------------------------
  6283. */
  6284. int buildin_produce(struct script_state *st)
  6285. {
  6286. int trigger;
  6287. struct map_session_data *sd=script_rid2sd(st);
  6288. trigger=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6289. clif_skill_produce_mix_list(sd, trigger);
  6290. return 0;
  6291. }
  6292. /*==========================================
  6293. * NPCでペット作る
  6294. *------------------------------------------
  6295. */
  6296. int buildin_makepet(struct script_state *st)
  6297. {
  6298. struct map_session_data *sd = script_rid2sd(st);
  6299. struct script_data *data;
  6300. int id,pet_id;
  6301. data=&(st->stack->stack_data[st->start+2]);
  6302. get_val(st,data);
  6303. id=conv_num(st,data);
  6304. pet_id = search_petDB_index(id, PET_CLASS);
  6305. if (pet_id < 0)
  6306. pet_id = search_petDB_index(id, PET_EGG);
  6307. if (pet_id >= 0 && sd) {
  6308. sd->catch_target_class = pet_db[pet_id].class_;
  6309. intif_create_pet(
  6310. sd->status.account_id, sd->status.char_id,
  6311. (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
  6312. (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
  6313. 100, 0, 1, pet_db[pet_id].jname);
  6314. }
  6315. return 0;
  6316. }
  6317. /*==========================================
  6318. * NPCで経験値上げる
  6319. *------------------------------------------
  6320. */
  6321. int buildin_getexp(struct script_state *st)
  6322. {
  6323. struct map_session_data *sd = script_rid2sd(st);
  6324. int base=0,job=0;
  6325. base=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6326. job =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6327. if(base<0 || job<0)
  6328. return 0;
  6329. if(sd)
  6330. pc_gainexp(sd,NULL,base,job);
  6331. return 0;
  6332. }
  6333. /*==========================================
  6334. * Gain guild exp [Celest]
  6335. *------------------------------------------
  6336. */
  6337. int buildin_guildgetexp(struct script_state *st)
  6338. {
  6339. struct map_session_data *sd = script_rid2sd(st);
  6340. int exp;
  6341. exp = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6342. if(exp < 0)
  6343. return 0;
  6344. if(sd && sd->status.guild_id > 0)
  6345. guild_getexp (sd, exp);
  6346. return 0;
  6347. }
  6348. /*==========================================
  6349. * Changes the guild master of a guild [Skotlex]
  6350. *------------------------------------------
  6351. */
  6352. int buildin_guildchangegm(struct script_state *st)
  6353. {
  6354. struct map_session_data *sd;
  6355. int guild_id;
  6356. char *name;
  6357. guild_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  6358. name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  6359. sd=map_nick2sd(name);
  6360. if (!sd)
  6361. push_val(st->stack,C_INT,0);
  6362. else
  6363. push_val(st->stack,C_INT,guild_gm_change(guild_id, sd));
  6364. return 0;
  6365. }
  6366. /*==========================================
  6367. * モンスター発生
  6368. *------------------------------------------
  6369. */
  6370. int buildin_monster(struct script_state *st)
  6371. {
  6372. int class_,amount,x,y;
  6373. char *str,*map,*event="";
  6374. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6375. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6376. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6377. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  6378. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6379. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6380. if( st->end>st->start+8 ){
  6381. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  6382. check_event(st, event);
  6383. }
  6384. if (class_ >= 0 && !mobdb_checkid(class_)) {
  6385. ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
  6386. return 1;
  6387. }
  6388. mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,amount,event);
  6389. return 0;
  6390. }
  6391. /*==========================================
  6392. * モンスター発生
  6393. *------------------------------------------
  6394. */
  6395. int buildin_areamonster(struct script_state *st)
  6396. {
  6397. int class_,amount,x0,y0,x1,y1;
  6398. char *str,*map,*event="";
  6399. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  6400. x0 =conv_num(st,& (st->stack->stack_data[st->start+3]));
  6401. y0 =conv_num(st,& (st->stack->stack_data[st->start+4]));
  6402. x1 =conv_num(st,& (st->stack->stack_data[st->start+5]));
  6403. y1 =conv_num(st,& (st->stack->stack_data[st->start+6]));
  6404. str =conv_str(st,& (st->stack->stack_data[st->start+7]));
  6405. class_=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6406. amount=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6407. if( st->end>st->start+10 ){
  6408. event=conv_str(st,& (st->stack->stack_data[st->start+10]));
  6409. check_event(st, event);
  6410. }
  6411. mob_once_spawn_area(map_id2sd(st->rid),map,x0,y0,x1,y1,str,class_,amount,event);
  6412. return 0;
  6413. }
  6414. /*==========================================
  6415. * モンスター削除
  6416. *------------------------------------------
  6417. */
  6418. int buildin_killmonster_sub(struct block_list *bl,va_list ap)
  6419. {
  6420. TBL_MOB* md = (TBL_MOB*)bl;
  6421. char *event=va_arg(ap,char *);
  6422. int allflag=va_arg(ap,int);
  6423. if(!allflag){
  6424. if(strcmp(event,md->npc_event)==0)
  6425. status_kill(bl);
  6426. }else{
  6427. if(!md->spawn)
  6428. status_kill(bl);
  6429. }
  6430. return 0;
  6431. }
  6432. int buildin_killmonster(struct script_state *st)
  6433. {
  6434. char *mapname,*event;
  6435. int m,allflag=0;
  6436. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6437. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6438. if(strcmp(event,"All")==0)
  6439. allflag = 1;
  6440. else
  6441. check_event(st, event);
  6442. if( (m=map_mapname2mapid(mapname))<0 )
  6443. return 0;
  6444. map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
  6445. return 0;
  6446. }
  6447. int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
  6448. {
  6449. status_kill(bl);
  6450. return 0;
  6451. }
  6452. int buildin_killmonsterall(struct script_state *st)
  6453. {
  6454. char *mapname;
  6455. int m;
  6456. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6457. if( (m=map_mapname2mapid(mapname))<0 )
  6458. return 0;
  6459. map_foreachinmap(buildin_killmonsterall_sub,
  6460. m,BL_MOB);
  6461. return 0;
  6462. }
  6463. /*==========================================
  6464. * Creates a clone of a player.
  6465. * clone map, x, y, event, char_id, master_id, mode, flag, duration
  6466. *------------------------------------------
  6467. */
  6468. int buildin_clone(struct script_state *st) {
  6469. struct map_session_data *sd, *msd=NULL;
  6470. int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
  6471. unsigned int duration = 0;
  6472. char *map,*event="";
  6473. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6474. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6475. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6476. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6477. char_id=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6478. if( st->end>st->start+7 )
  6479. master_id=conv_num(st,& (st->stack->stack_data[st->start+7]));
  6480. if( st->end>st->start+8 )
  6481. mode=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6482. if( st->end>st->start+9 )
  6483. flag=conv_num(st,& (st->stack->stack_data[st->start+9]));
  6484. if( st->end>st->start+10 )
  6485. duration=conv_num(st,& (st->stack->stack_data[st->start+10]));
  6486. check_event(st, event);
  6487. m = map_mapname2mapid(map);
  6488. if (m < 0) return 0;
  6489. sd = map_charid2sd(char_id);
  6490. if (master_id) {
  6491. msd = map_charid2sd(master_id);
  6492. if (msd)
  6493. master_id = msd->bl.id;
  6494. else
  6495. master_id = 0;
  6496. }
  6497. if (sd) //Return ID of newly crafted clone.
  6498. push_val(st->stack,C_INT,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
  6499. else //Failed to create clone.
  6500. push_val(st->stack,C_INT,0);
  6501. return 0;
  6502. }
  6503. /*==========================================
  6504. * イベント実行
  6505. *------------------------------------------
  6506. */
  6507. int buildin_doevent(struct script_state *st)
  6508. {
  6509. char *event;
  6510. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6511. check_event(st, event);
  6512. npc_event(map_id2sd(st->rid),event,0);
  6513. return 0;
  6514. }
  6515. /*==========================================
  6516. * NPC主体イベント実行
  6517. *------------------------------------------
  6518. */
  6519. int buildin_donpcevent(struct script_state *st)
  6520. {
  6521. char *event;
  6522. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6523. check_event(st, event);
  6524. npc_event_do(event);
  6525. return 0;
  6526. }
  6527. /*==========================================
  6528. * イベントタイマー追加
  6529. *------------------------------------------
  6530. */
  6531. int buildin_addtimer(struct script_state *st)
  6532. {
  6533. char *event;
  6534. int tick;
  6535. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6536. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6537. check_event(st, event);
  6538. pc_addeventtimer(script_rid2sd(st),tick,event);
  6539. return 0;
  6540. }
  6541. /*==========================================
  6542. * イベントタイマー削除
  6543. *------------------------------------------
  6544. */
  6545. int buildin_deltimer(struct script_state *st)
  6546. {
  6547. char *event;
  6548. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6549. check_event(st, event);
  6550. pc_deleventtimer(script_rid2sd(st),event);
  6551. return 0;
  6552. }
  6553. /*==========================================
  6554. * イベントタイマーのカウント値追加
  6555. *------------------------------------------
  6556. */
  6557. int buildin_addtimercount(struct script_state *st)
  6558. {
  6559. char *event;
  6560. int tick;
  6561. event=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6562. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6563. check_event(st, event);
  6564. pc_addeventtimercount(script_rid2sd(st),event,tick);
  6565. return 0;
  6566. }
  6567. /*==========================================
  6568. * NPCタイマー初期化
  6569. *------------------------------------------
  6570. */
  6571. int buildin_initnpctimer(struct script_state *st)
  6572. {
  6573. struct npc_data *nd;
  6574. if( st->end > st->start+2 )
  6575. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6576. else
  6577. nd=(struct npc_data *)map_id2bl(st->oid);
  6578. npc_settimerevent_tick(nd,0);
  6579. npc_timerevent_start(nd, st->rid);
  6580. return 0;
  6581. }
  6582. /*==========================================
  6583. * NPCタイマー開始
  6584. *------------------------------------------
  6585. */
  6586. int buildin_startnpctimer(struct script_state *st)
  6587. {
  6588. struct npc_data *nd;
  6589. if( st->end > st->start+2 )
  6590. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6591. else
  6592. nd=(struct npc_data *)map_id2bl(st->oid);
  6593. npc_timerevent_start(nd, st->rid);
  6594. return 0;
  6595. }
  6596. /*==========================================
  6597. * NPCタイマー停止
  6598. *------------------------------------------
  6599. */
  6600. int buildin_stopnpctimer(struct script_state *st)
  6601. {
  6602. struct npc_data *nd;
  6603. if( st->end > st->start+2 )
  6604. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6605. else
  6606. nd=(struct npc_data *)map_id2bl(st->oid);
  6607. npc_timerevent_stop(nd);
  6608. return 0;
  6609. }
  6610. /*==========================================
  6611. * NPCタイマー情報所得
  6612. *------------------------------------------
  6613. */
  6614. int buildin_getnpctimer(struct script_state *st)
  6615. {
  6616. struct npc_data *nd;
  6617. struct map_session_data *sd;
  6618. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6619. int val=0;
  6620. if( st->end > st->start+3 )
  6621. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6622. else
  6623. nd=(struct npc_data *)map_id2bl(st->oid);
  6624. if (!nd || nd->bl.type != BL_NPC)
  6625. {
  6626. push_val(st->stack,C_INT,0);
  6627. if (battle_config.error_log)
  6628. ShowError("getnpctimer: Invalid NPC\n");
  6629. return 1;
  6630. }
  6631. switch(type){
  6632. case 0: val=npc_gettimerevent_tick(nd); break;
  6633. case 1:
  6634. if (nd->u.scr.rid) {
  6635. sd = map_id2sd(nd->u.scr.rid);
  6636. if (!sd) {
  6637. if(battle_config.error_log)
  6638. ShowError("buildin_getnpctimer: Attached player not found!\n");
  6639. break;
  6640. }
  6641. val = (sd->npc_timer_id != -1);
  6642. } else
  6643. val= (nd->u.scr.timerid !=-1);
  6644. break;
  6645. case 2: val= nd->u.scr.timeramount; break;
  6646. }
  6647. push_val(st->stack,C_INT,val);
  6648. return 0;
  6649. }
  6650. /*==========================================
  6651. * NPCタイマー値設定
  6652. *------------------------------------------
  6653. */
  6654. int buildin_setnpctimer(struct script_state *st)
  6655. {
  6656. int tick;
  6657. struct npc_data *nd;
  6658. tick=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6659. if( st->end > st->start+3 )
  6660. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  6661. else
  6662. nd=(struct npc_data *)map_id2bl(st->oid);
  6663. npc_settimerevent_tick(nd,tick);
  6664. return 0;
  6665. }
  6666. /*==========================================
  6667. * attaches the player rid to the timer [Celest]
  6668. *------------------------------------------
  6669. */
  6670. int buildin_attachnpctimer(struct script_state *st)
  6671. {
  6672. struct map_session_data *sd;
  6673. struct npc_data *nd;
  6674. nd=(struct npc_data *)map_id2bl(st->oid);
  6675. if( st->end > st->start+2 ) {
  6676. char *name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  6677. sd=map_nick2sd(name);
  6678. } else {
  6679. sd = script_rid2sd(st);
  6680. }
  6681. if (sd==NULL)
  6682. return 0;
  6683. nd->u.scr.rid = sd->bl.id;
  6684. return 0;
  6685. }
  6686. /*==========================================
  6687. * detaches a player rid from the timer [Celest]
  6688. *------------------------------------------
  6689. */
  6690. int buildin_detachnpctimer(struct script_state *st)
  6691. {
  6692. struct npc_data *nd;
  6693. if( st->end > st->start+2 )
  6694. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  6695. else
  6696. nd=(struct npc_data *)map_id2bl(st->oid);
  6697. nd->u.scr.rid = 0;
  6698. return 0;
  6699. }
  6700. /*==========================================
  6701. * To avoid "player not attached" script errors, this function is provided,
  6702. * it checks if there is a player attached to the current script. [Skotlex]
  6703. * If no, returns 0, if yes, returns the char_id of the attached player.
  6704. *------------------------------------------
  6705. */
  6706. int buildin_playerattached(struct script_state *st)
  6707. {
  6708. struct map_session_data *sd;
  6709. if (st->rid == 0 || (sd = map_id2sd(st->rid)) == NULL)
  6710. push_val(st->stack,C_INT,0);
  6711. else
  6712. push_val(st->stack,C_INT,st->rid);
  6713. return 0;
  6714. }
  6715. /*==========================================
  6716. * 天の声アナウンス
  6717. *------------------------------------------
  6718. */
  6719. int buildin_announce(struct script_state *st)
  6720. {
  6721. char *str, *color=NULL;
  6722. int flag;
  6723. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6724. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6725. if (st->end>st->start+4)
  6726. color=conv_str(st,& (st->stack->stack_data[st->start+4]));
  6727. if(flag&0x0f){
  6728. struct block_list *bl=(flag&0x08)? map_id2bl(st->oid) :
  6729. (struct block_list *)script_rid2sd(st);
  6730. if (color)
  6731. clif_announce(bl,str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0),flag);
  6732. else
  6733. clif_GMmessage(bl,str,(int)strlen(str)+1,flag);
  6734. }else {
  6735. if (color)
  6736. intif_announce(str,(int)strlen(str)+1, strtol(color, (char **)NULL, 0), flag);
  6737. else
  6738. intif_GMmessage(str,(int)strlen(str)+1,flag);
  6739. }
  6740. return 0;
  6741. }
  6742. /*==========================================
  6743. * 天の声アナウンス(特定マップ)
  6744. *------------------------------------------
  6745. */
  6746. int buildin_mapannounce_sub(struct block_list *bl,va_list ap)
  6747. {
  6748. char *str, *color;
  6749. int len,flag;
  6750. str=va_arg(ap,char *);
  6751. len=va_arg(ap,int);
  6752. flag=va_arg(ap,int);
  6753. color=va_arg(ap,char *);
  6754. if (color)
  6755. clif_announce(bl,str,len, strtol(color, (char **)NULL, 0), flag|3);
  6756. else
  6757. clif_GMmessage(bl,str,len,flag|3);
  6758. return 0;
  6759. }
  6760. int buildin_mapannounce(struct script_state *st)
  6761. {
  6762. char *mapname,*str, *color=NULL;
  6763. int flag,m;
  6764. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6765. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  6766. flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6767. if (st->end>st->start+5)
  6768. color=conv_str(st,& (st->stack->stack_data[st->start+5]));
  6769. if( (m=map_mapname2mapid(mapname))<0 )
  6770. return 0;
  6771. map_foreachinmap(buildin_mapannounce_sub,
  6772. m, BL_PC, str,strlen(str)+1,flag&0x10, color);
  6773. return 0;
  6774. }
  6775. /*==========================================
  6776. * 天の声アナウンス(特定エリア)
  6777. *------------------------------------------
  6778. */
  6779. int buildin_areaannounce(struct script_state *st)
  6780. {
  6781. char *map,*str,*color=NULL;
  6782. int flag,m;
  6783. int x0,y0,x1,y1;
  6784. map=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6785. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6786. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6787. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6788. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6789. str=conv_str(st,& (st->stack->stack_data[st->start+7]));
  6790. flag=conv_num(st,& (st->stack->stack_data[st->start+8]));
  6791. if (st->end>st->start+9)
  6792. color=conv_str(st,& (st->stack->stack_data[st->start+9]));
  6793. if( (m=map_mapname2mapid(map))<0 )
  6794. return 0;
  6795. map_foreachinarea(buildin_mapannounce_sub,
  6796. m,x0,y0,x1,y1,BL_PC, str,strlen(str)+1,flag&0x10, color);
  6797. return 0;
  6798. }
  6799. /*==========================================
  6800. * ユーザー数所得
  6801. *------------------------------------------
  6802. */
  6803. int buildin_getusers(struct script_state *st)
  6804. {
  6805. int flag=conv_num(st,& (st->stack->stack_data[st->start+2]));
  6806. struct block_list *bl=map_id2bl((flag&0x08)?st->oid:st->rid);
  6807. int val=0;
  6808. switch(flag&0x07){
  6809. case 0: val=map[bl->m].users; break;
  6810. case 1: val=map_getusers(); break;
  6811. }
  6812. push_val(st->stack,C_INT,val);
  6813. return 0;
  6814. }
  6815. /*==========================================
  6816. * Works like @WHO - displays all online users names in window
  6817. *------------------------------------------
  6818. */
  6819. int buildin_getusersname(struct script_state *st)
  6820. {
  6821. struct map_session_data *sd, *pl_sd = NULL, **pl_allsd;
  6822. int i=0,disp_num=1, users;
  6823. sd = script_rid2sd(st);
  6824. if (!sd) return 0;
  6825. pl_allsd = map_getallusers(&users);
  6826. for (i=0;i<users;i++)
  6827. {
  6828. pl_sd = pl_allsd[i];
  6829. if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
  6830. {
  6831. if((disp_num++)%10==0)
  6832. clif_scriptnext(sd,st->oid);
  6833. clif_scriptmes(sd,st->oid,pl_sd->status.name);
  6834. }
  6835. }
  6836. return 0;
  6837. }
  6838. /*==========================================
  6839. * getmapguildusers("mapname.gat",guild ID) Returns the number guild members present on a map [Reddozen]
  6840. *------------------------------------------
  6841. */
  6842. int buildin_getmapguildusers(struct script_state *st) {
  6843. char *str;
  6844. int m, gid;
  6845. int i=0,c=0;
  6846. struct guild *g = NULL;
  6847. str=conv_str(st, &(st->stack->stack_data[st->start+2]));
  6848. gid=conv_num(st, &(st->stack->stack_data[st->start+3]));
  6849. if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server)
  6850. push_val(st->stack, C_INT, -1);
  6851. return 0;
  6852. }
  6853. g = guild_search(gid);
  6854. if (g){
  6855. for(i = 0; i < g->max_member; i++)
  6856. {
  6857. if (g->member[i].sd && g->member[i].sd->bl.m == m)
  6858. c++;
  6859. }
  6860. }
  6861. push_val(st->stack, C_INT, c);
  6862. return 0;
  6863. }
  6864. /*==========================================
  6865. * マップ指定ユーザー数所得
  6866. *------------------------------------------
  6867. */
  6868. int buildin_getmapusers(struct script_state *st)
  6869. {
  6870. char *str;
  6871. int m;
  6872. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6873. if( (m=map_mapname2mapid(str))< 0){
  6874. push_val(st->stack,C_INT,-1);
  6875. return 0;
  6876. }
  6877. push_val(st->stack,C_INT,map[m].users);
  6878. return 0;
  6879. }
  6880. /*==========================================
  6881. * エリア指定ユーザー数所得
  6882. *------------------------------------------
  6883. */
  6884. int buildin_getareausers_sub(struct block_list *bl,va_list ap)
  6885. {
  6886. int *users=va_arg(ap,int *);
  6887. (*users)++;
  6888. return 0;
  6889. }
  6890. int buildin_getareausers(struct script_state *st)
  6891. {
  6892. char *str;
  6893. int m,x0,y0,x1,y1,users=0;
  6894. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6895. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6896. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6897. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6898. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6899. if( (m=map_mapname2mapid(str))< 0){
  6900. push_val(st->stack,C_INT,-1);
  6901. return 0;
  6902. }
  6903. map_foreachinarea(buildin_getareausers_sub,
  6904. m,x0,y0,x1,y1,BL_PC,&users);
  6905. push_val(st->stack,C_INT,users);
  6906. return 0;
  6907. }
  6908. /*==========================================
  6909. * エリア指定ドロップアイテム数所得
  6910. *------------------------------------------
  6911. */
  6912. int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
  6913. {
  6914. int item=va_arg(ap,int);
  6915. int *amount=va_arg(ap,int *);
  6916. struct flooritem_data *drop=(struct flooritem_data *)bl;
  6917. if(drop->item_data.nameid==item)
  6918. (*amount)+=drop->item_data.amount;
  6919. return 0;
  6920. }
  6921. int buildin_getareadropitem(struct script_state *st)
  6922. {
  6923. char *str;
  6924. int m,x0,y0,x1,y1,item,amount=0;
  6925. struct script_data *data;
  6926. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6927. x0=conv_num(st,& (st->stack->stack_data[st->start+3]));
  6928. y0=conv_num(st,& (st->stack->stack_data[st->start+4]));
  6929. x1=conv_num(st,& (st->stack->stack_data[st->start+5]));
  6930. y1=conv_num(st,& (st->stack->stack_data[st->start+6]));
  6931. data=&(st->stack->stack_data[st->start+7]);
  6932. get_val(st,data);
  6933. if( data->type==C_STR || data->type==C_CONSTSTR ){
  6934. const char *name=conv_str(st,data);
  6935. struct item_data *item_data = itemdb_searchname(name);
  6936. item=UNKNOWN_ITEM_ID;
  6937. if( item_data )
  6938. item=item_data->nameid;
  6939. }else
  6940. item=conv_num(st,data);
  6941. if( (m=map_mapname2mapid(str))< 0){
  6942. push_val(st->stack,C_INT,-1);
  6943. return 0;
  6944. }
  6945. map_foreachinarea(buildin_getareadropitem_sub,
  6946. m,x0,y0,x1,y1,BL_ITEM,item,&amount);
  6947. push_val(st->stack,C_INT,amount);
  6948. return 0;
  6949. }
  6950. /*==========================================
  6951. * NPCの有効化
  6952. *------------------------------------------
  6953. */
  6954. int buildin_enablenpc(struct script_state *st)
  6955. {
  6956. char *str;
  6957. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6958. npc_enable(str,1);
  6959. return 0;
  6960. }
  6961. /*==========================================
  6962. * NPCの無効化
  6963. *------------------------------------------
  6964. */
  6965. int buildin_disablenpc(struct script_state *st)
  6966. {
  6967. char *str;
  6968. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6969. npc_enable(str,0);
  6970. return 0;
  6971. }
  6972. int buildin_enablearena(struct script_state *st) // Added by RoVeRT
  6973. {
  6974. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6975. struct chat_data *cd;
  6976. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL)
  6977. return 0;
  6978. npc_enable(nd->name,1);
  6979. nd->arenaflag=1;
  6980. if(cd->users>=cd->trigger && cd->npc_event[0])
  6981. npc_timer_event(cd->npc_event);
  6982. return 0;
  6983. }
  6984. int buildin_disablearena(struct script_state *st) // Added by RoVeRT
  6985. {
  6986. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  6987. nd->arenaflag=0;
  6988. return 0;
  6989. }
  6990. /*==========================================
  6991. * 隠れているNPCの表示
  6992. *------------------------------------------
  6993. */
  6994. int buildin_hideoffnpc(struct script_state *st)
  6995. {
  6996. char *str;
  6997. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  6998. npc_enable(str,2);
  6999. return 0;
  7000. }
  7001. /*==========================================
  7002. * NPCをハイディング
  7003. *------------------------------------------
  7004. */
  7005. int buildin_hideonnpc(struct script_state *st)
  7006. {
  7007. char *str;
  7008. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7009. npc_enable(str,4);
  7010. return 0;
  7011. }
  7012. /*==========================================
  7013. * 状態異常にかかる
  7014. *------------------------------------------
  7015. */
  7016. int buildin_sc_start(struct script_state *st)
  7017. {
  7018. struct block_list *bl;
  7019. int type,tick,val1,val4=0;
  7020. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7021. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7022. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7023. if( st->end>st->start+5 ) //指定したキャラを状態異常にする
  7024. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+5])));
  7025. else
  7026. bl = map_id2bl(st->rid);
  7027. if (potion_flag==1 && potion_target) {
  7028. bl = map_id2bl(potion_target);
  7029. tick/=2; //Thrown potions only last half.
  7030. val4 = 1; //Mark that this was a thrown sc_effect
  7031. }
  7032. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7033. { //When there isn't a duration specified, try to get it from the skill_db
  7034. tick = StatusSkillChangeTable[type];
  7035. if (tick)
  7036. tick = skill_get_time(tick,val1);
  7037. else //Failed to retrieve duration, reset to what it was.
  7038. tick = 0;
  7039. }
  7040. if (bl)
  7041. status_change_start(bl,type,10000,val1,0,0,val4,tick,11);
  7042. return 0;
  7043. }
  7044. /*==========================================
  7045. * 状態異常にかかる(確率指定)
  7046. *------------------------------------------
  7047. */
  7048. int buildin_sc_start2(struct script_state *st)
  7049. {
  7050. struct block_list *bl;
  7051. int type,tick,val1,val4=0,per;
  7052. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7053. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7054. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7055. per=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7056. if( st->end>st->start+6 ) //指定したキャラを状態異常にする
  7057. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7058. else
  7059. bl = map_id2bl(st->rid);
  7060. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7061. { //When there isn't a duration specified, try to get it from the skill_db
  7062. tick = StatusSkillChangeTable[type];
  7063. if (tick)
  7064. tick = skill_get_time(tick,val1);
  7065. else //Failed to retrieve duration, reset to what it was.
  7066. tick = 0;
  7067. }
  7068. if (potion_flag==1 && potion_target) {
  7069. bl = map_id2bl(potion_target);
  7070. tick/=2;
  7071. val4 = 1;
  7072. }
  7073. if(bl)
  7074. status_change_start(bl,type,per,val1,0,0,val4,tick,11);
  7075. return 0;
  7076. }
  7077. /*==========================================
  7078. * Starts a SC_ change with the four values passed. [Skotlex]
  7079. * Final optional argument is the ID of player to affect.
  7080. * sc_start4 type, duration, val1, val2, val3, val4, <id>;
  7081. *------------------------------------------
  7082. */
  7083. int buildin_sc_start4(struct script_state *st)
  7084. {
  7085. struct block_list *bl;
  7086. int type,tick,val1,val2,val3,val4;
  7087. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7088. tick=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7089. val1=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7090. val2=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7091. val3=conv_num(st,& (st->stack->stack_data[st->start+6]));
  7092. val4=conv_num(st,& (st->stack->stack_data[st->start+7]));
  7093. if( st->end>st->start+8 )
  7094. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+8])));
  7095. else
  7096. bl = map_id2bl(st->rid);
  7097. if (type >= 0 && type < SC_MAX && val1 && !tick)
  7098. { //When there isn't a duration specified, try to get it from the skill_db
  7099. tick = StatusSkillChangeTable[type];
  7100. if (tick)
  7101. tick = skill_get_time(tick,val1);
  7102. else //Failed to retrieve duration, reset to what it was.
  7103. tick = 0;
  7104. }
  7105. if (potion_flag==1 && potion_target) {
  7106. bl = map_id2bl(potion_target);
  7107. tick/=2;
  7108. }
  7109. if (bl)
  7110. status_change_start(bl,type,10000,val1,val2,val3,val4,tick,11);
  7111. return 0;
  7112. }
  7113. /*==========================================
  7114. * 状態異常が直る
  7115. *------------------------------------------
  7116. */
  7117. int buildin_sc_end(struct script_state *st)
  7118. {
  7119. struct block_list *bl;
  7120. int type;
  7121. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7122. bl = map_id2bl(st->rid);
  7123. if (potion_flag==1 && potion_target)
  7124. bl = map_id2bl(potion_target);
  7125. if (!bl) return 0;
  7126. if (type >= 0)
  7127. status_change_end(bl,type,-1);
  7128. else
  7129. status_change_clear(bl, 2);
  7130. return 0;
  7131. }
  7132. /*==========================================
  7133. * 状態異常耐性を計算した確率を返す
  7134. *------------------------------------------
  7135. */
  7136. int buildin_getscrate(struct script_state *st)
  7137. {
  7138. struct block_list *bl;
  7139. int sc_def=0,type,rate;
  7140. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7141. rate=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7142. if( st->end>st->start+4 ) //指定したキャラの耐性を計算する
  7143. bl = map_id2bl(conv_num(st,& (st->stack->stack_data[st->start+6])));
  7144. else
  7145. bl = map_id2bl(st->rid);
  7146. if (bl)
  7147. sc_def = status_get_sc_def(bl,type);
  7148. rate = rate*(10000-sc_def)/10000;
  7149. push_val(st->stack,C_INT,rate<0?0:rate);
  7150. return 0;
  7151. }
  7152. /*==========================================
  7153. *
  7154. *------------------------------------------
  7155. */
  7156. int buildin_debugmes(struct script_state *st)
  7157. {
  7158. conv_str(st,& (st->stack->stack_data[st->start+2]));
  7159. ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,st->stack->stack_data[st->start+2].u.str);
  7160. return 0;
  7161. }
  7162. /*==========================================
  7163. *捕獲アイテム使用
  7164. *------------------------------------------
  7165. */
  7166. int buildin_catchpet(struct script_state *st)
  7167. {
  7168. int pet_id;
  7169. struct map_session_data *sd;
  7170. pet_id= conv_num(st,& (st->stack->stack_data[st->start+2]));
  7171. sd=script_rid2sd(st);
  7172. pet_catch_process1(sd,pet_id);
  7173. return 0;
  7174. }
  7175. /*==========================================
  7176. * [orn]
  7177. *------------------------------------------
  7178. */
  7179. int buildin_homunculus_evolution(struct script_state *st)
  7180. {
  7181. struct map_session_data *sd;
  7182. sd=script_rid2sd(st);
  7183. if ( sd->hd && sd->hd->homunculusDB->evo_class && sd->hd->homunculus.intimacy > 91000 ) {
  7184. return !merc_hom_evolution(sd->hd) ;
  7185. }
  7186. clif_emotion(&sd->hd->bl, 4) ; //swt
  7187. return 0;
  7188. }
  7189. //These two functions bring the eA MAPID_* class functionality to scripts.
  7190. int buildin_eaclass(struct script_state *st)
  7191. {
  7192. int class_;
  7193. if( st->end>st->start+2 )
  7194. class_ = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7195. else {
  7196. struct map_session_data *sd;
  7197. sd=script_rid2sd(st);
  7198. if (!sd) {
  7199. push_val(st->stack,C_INT, -1);
  7200. return 0;
  7201. }
  7202. class_ = sd->status.class_;
  7203. }
  7204. push_val(st->stack,C_INT, pc_jobid2mapid(class_));
  7205. return 0;
  7206. }
  7207. int buildin_roclass(struct script_state *st)
  7208. {
  7209. int class_ =conv_num(st,& (st->stack->stack_data[st->start+2]));
  7210. int sex;
  7211. if( st->end>st->start+3 )
  7212. sex = conv_num(st,& (st->stack->stack_data[st->start+3]));
  7213. else {
  7214. struct map_session_data *sd;
  7215. if (st->rid && (sd=script_rid2sd(st)))
  7216. sex = sd->status.sex;
  7217. else
  7218. sex = 1; //Just use male when not found.
  7219. }
  7220. push_val(st->stack,C_INT,pc_mapid2jobid(class_, sex));
  7221. return 0;
  7222. }
  7223. /*==========================================
  7224. *携帯卵孵化機使用
  7225. *------------------------------------------
  7226. */
  7227. int buildin_birthpet(struct script_state *st)
  7228. {
  7229. struct map_session_data *sd;
  7230. sd=script_rid2sd(st);
  7231. clif_sendegg(sd);
  7232. return 0;
  7233. }
  7234. /*==========================================
  7235. * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
  7236. *------------------------------------------
  7237. */
  7238. int buildin_resetlvl(struct script_state *st)
  7239. {
  7240. struct map_session_data *sd;
  7241. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7242. sd=script_rid2sd(st);
  7243. pc_resetlvl(sd,type);
  7244. return 0;
  7245. }
  7246. /*==========================================
  7247. * ステータスリセット
  7248. *------------------------------------------
  7249. */
  7250. int buildin_resetstatus(struct script_state *st)
  7251. {
  7252. struct map_session_data *sd;
  7253. sd=script_rid2sd(st);
  7254. pc_resetstate(sd);
  7255. return 0;
  7256. }
  7257. /*==========================================
  7258. * script command resetskill
  7259. *------------------------------------------
  7260. */
  7261. int buildin_resetskill(struct script_state *st)
  7262. {
  7263. struct map_session_data *sd;
  7264. sd=script_rid2sd(st);
  7265. pc_resetskill(sd,1);
  7266. return 0;
  7267. }
  7268. /*==========================================
  7269. * Counts total amount of skill points.
  7270. *------------------------------------------
  7271. */
  7272. int buildin_skillpointcount(struct script_state *st)
  7273. {
  7274. struct map_session_data *sd;
  7275. sd=script_rid2sd(st);
  7276. push_val(st->stack,C_INT,sd->status.skill_point + pc_resetskill(sd,2));
  7277. return 0;
  7278. }
  7279. /*==========================================
  7280. *
  7281. *------------------------------------------
  7282. */
  7283. int buildin_changebase(struct script_state *st)
  7284. {
  7285. struct map_session_data *sd=NULL;
  7286. int vclass;
  7287. if( st->end>st->start+3 )
  7288. sd=map_id2sd(conv_num(st,& (st->stack->stack_data[st->start+3])));
  7289. else
  7290. sd=script_rid2sd(st);
  7291. if(sd == NULL)
  7292. return 0;
  7293. vclass = conv_num(st,& (st->stack->stack_data[st->start+2]));
  7294. if(vclass == JOB_WEDDING)
  7295. {
  7296. if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
  7297. sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
  7298. )
  7299. return 0;
  7300. }
  7301. if(!sd->disguise && vclass != sd->vd.class_) {
  7302. status_set_viewdata(&sd->bl, vclass);
  7303. //Updated client view. Base, Weapon and Cloth Colors.
  7304. clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
  7305. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7306. if (sd->vd.cloth_color)
  7307. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
  7308. }
  7309. return 0;
  7310. }
  7311. /*==========================================
  7312. * 性別変換
  7313. *------------------------------------------
  7314. */
  7315. int buildin_changesex(struct script_state *st) {
  7316. struct map_session_data *sd = NULL;
  7317. sd = script_rid2sd(st);
  7318. if (sd->status.sex == 0) {
  7319. sd->status.sex = 1;
  7320. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7321. sd->status.class_ -= 1;
  7322. } else if (sd->status.sex == 1) {
  7323. sd->status.sex = 0;
  7324. if ((sd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER)
  7325. sd->status.class_ += 1;
  7326. }
  7327. chrif_char_ask_name(-1, sd->status.name, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex
  7328. chrif_save(sd,0);
  7329. return 0;
  7330. }
  7331. /*==========================================
  7332. * npcチャット作成
  7333. *------------------------------------------
  7334. */
  7335. int buildin_waitingroom(struct script_state *st)
  7336. {
  7337. char *name,*ev="";
  7338. int limit, trigger = 0,pub=1;
  7339. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7340. limit= conv_num(st,& (st->stack->stack_data[st->start+3]));
  7341. if(limit==0)
  7342. pub=3;
  7343. if( (st->end > st->start+5) ){
  7344. struct script_data* data=&(st->stack->stack_data[st->start+5]);
  7345. get_val(st,data);
  7346. if(data->type==C_INT){
  7347. // 新Athena仕様(旧Athena仕様と互換性あり)
  7348. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7349. trigger=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7350. }else{
  7351. // eathena仕様
  7352. trigger=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7353. ev=conv_str(st,& (st->stack->stack_data[st->start+5]));
  7354. }
  7355. }else{
  7356. // 旧Athena仕様
  7357. if( st->end > st->start+4 )
  7358. ev=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7359. }
  7360. chat_createnpcchat( (struct npc_data *)map_id2bl(st->oid),
  7361. limit,pub,trigger,name,(int)strlen(name)+1,ev);
  7362. return 0;
  7363. }
  7364. /*==========================================
  7365. * Works like 'announce' but outputs in the common chat window
  7366. *------------------------------------------
  7367. */
  7368. int buildin_globalmes(struct script_state *st)
  7369. {
  7370. struct block_list *bl = map_id2bl(st->oid);
  7371. struct npc_data *nd = (struct npc_data *)bl;
  7372. char *name=NULL,*mes;
  7373. mes=conv_str(st,& (st->stack->stack_data[st->start+2])); // メッセージの取得
  7374. if(mes==NULL) return 0;
  7375. if(st->end>st->start+3){ // NPC名の取得(123#456)
  7376. name=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7377. } else {
  7378. name=nd->name;
  7379. }
  7380. npc_globalmessage(name,mes); // グローバルメッセージ送信
  7381. return 0;
  7382. }
  7383. /*==========================================
  7384. * npcチャット削除
  7385. *------------------------------------------
  7386. */
  7387. int buildin_delwaitingroom(struct script_state *st)
  7388. {
  7389. struct npc_data *nd;
  7390. if( st->end > st->start+2 )
  7391. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7392. else
  7393. nd=(struct npc_data *)map_id2bl(st->oid);
  7394. chat_deletenpcchat(nd);
  7395. return 0;
  7396. }
  7397. /*==========================================
  7398. * npcチャット全員蹴り出す
  7399. *------------------------------------------
  7400. */
  7401. int buildin_waitingroomkickall(struct script_state *st)
  7402. {
  7403. struct npc_data *nd;
  7404. struct chat_data *cd;
  7405. if( st->end > st->start+2 )
  7406. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7407. else
  7408. nd=(struct npc_data *)map_id2bl(st->oid);
  7409. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7410. return 0;
  7411. chat_npckickall(cd);
  7412. return 0;
  7413. }
  7414. /*==========================================
  7415. * npcチャットイベント有効化
  7416. *------------------------------------------
  7417. */
  7418. int buildin_enablewaitingroomevent(struct script_state *st)
  7419. {
  7420. struct npc_data *nd;
  7421. struct chat_data *cd;
  7422. if( st->end > st->start+2 )
  7423. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7424. else
  7425. nd=(struct npc_data *)map_id2bl(st->oid);
  7426. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7427. return 0;
  7428. chat_enableevent(cd);
  7429. return 0;
  7430. }
  7431. /*==========================================
  7432. * npcチャットイベント無効化
  7433. *------------------------------------------
  7434. */
  7435. int buildin_disablewaitingroomevent(struct script_state *st)
  7436. {
  7437. struct npc_data *nd;
  7438. struct chat_data *cd;
  7439. if( st->end > st->start+2 )
  7440. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  7441. else
  7442. nd=(struct npc_data *)map_id2bl(st->oid);
  7443. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7444. return 0;
  7445. chat_disableevent(cd);
  7446. return 0;
  7447. }
  7448. /*==========================================
  7449. * npcチャット状態所得
  7450. *------------------------------------------
  7451. */
  7452. int buildin_getwaitingroomstate(struct script_state *st)
  7453. {
  7454. struct npc_data *nd;
  7455. struct chat_data *cd;
  7456. int val=0,type;
  7457. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7458. if( st->end > st->start+3 )
  7459. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+3])));
  7460. else
  7461. nd=(struct npc_data *)map_id2bl(st->oid);
  7462. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL ){
  7463. push_val(st->stack,C_INT,-1);
  7464. return 0;
  7465. }
  7466. switch(type){
  7467. case 0: val=cd->users; break;
  7468. case 1: val=cd->limit; break;
  7469. case 2: val=cd->trigger&0x7f; break;
  7470. case 3: val=((cd->trigger&0x80)>0); break;
  7471. case 32: val=(cd->users >= cd->limit); break;
  7472. case 33: val=(cd->users >= cd->trigger); break;
  7473. case 4:
  7474. push_str(st->stack,C_CONSTSTR,cd->title);
  7475. return 0;
  7476. case 5:
  7477. push_str(st->stack,C_CONSTSTR,cd->pass);
  7478. return 0;
  7479. case 16:
  7480. push_str(st->stack,C_CONSTSTR,cd->npc_event);
  7481. return 0;
  7482. }
  7483. push_val(st->stack,C_INT,val);
  7484. return 0;
  7485. }
  7486. /*==========================================
  7487. * チャットメンバー(規定人数)ワープ
  7488. *------------------------------------------
  7489. */
  7490. int buildin_warpwaitingpc(struct script_state *st)
  7491. {
  7492. int x,y,i,n;
  7493. char *str;
  7494. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  7495. struct chat_data *cd;
  7496. struct map_session_data *sd;
  7497. if(nd==NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id))==NULL )
  7498. return 0;
  7499. n=cd->trigger&0x7f;
  7500. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7501. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7502. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7503. if( st->end > st->start+5 )
  7504. n=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7505. for(i=0;i<n;i++){
  7506. sd=cd->usersd[0];
  7507. if (!sd) continue; //Broken npc chat room?
  7508. mapreg_setreg(add_str("$@warpwaitingpc")+(i<<24),sd->bl.id);
  7509. if(strcmp(str,"Random")==0)
  7510. pc_randomwarp(sd,3);
  7511. else if(strcmp(str,"SavePoint")==0){
  7512. if(map[sd->bl.m].flag.noteleport) // テレポ禁止
  7513. return 0;
  7514. pc_setpos(sd,sd->status.save_point.map,
  7515. sd->status.save_point.x,sd->status.save_point.y,3);
  7516. }else
  7517. pc_setpos(sd,mapindex_name2id(str),x,y,0);
  7518. }
  7519. mapreg_setreg(add_str("$@warpwaitingpcnum"),n);
  7520. return 0;
  7521. }
  7522. /*==========================================
  7523. * RIDのアタッチ
  7524. *------------------------------------------
  7525. */
  7526. int buildin_attachrid(struct script_state *st)
  7527. {
  7528. st->rid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7529. push_val(st->stack,C_INT, (map_id2sd(st->rid)!=NULL));
  7530. return 0;
  7531. }
  7532. /*==========================================
  7533. * RIDのデタッチ
  7534. *------------------------------------------
  7535. */
  7536. int buildin_detachrid(struct script_state *st)
  7537. {
  7538. st->rid=0;
  7539. return 0;
  7540. }
  7541. /*==========================================
  7542. * 存在チェック
  7543. *------------------------------------------
  7544. */
  7545. int buildin_isloggedin(struct script_state *st)
  7546. {
  7547. push_val(st->stack,C_INT, map_id2sd(
  7548. conv_num(st,& (st->stack->stack_data[st->start+2])) )!=NULL );
  7549. return 0;
  7550. }
  7551. /*==========================================
  7552. *
  7553. *------------------------------------------
  7554. */
  7555. int buildin_setmapflagnosave(struct script_state *st)
  7556. {
  7557. int m,x,y;
  7558. unsigned short mapindex;
  7559. char *str,*str2;
  7560. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7561. str2=conv_str(st,& (st->stack->stack_data[st->start+3]));
  7562. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  7563. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  7564. m = map_mapname2mapid(str);
  7565. mapindex = mapindex_name2id(str2);
  7566. if(m >= 0 && mapindex) {
  7567. map[m].flag.nosave=1;
  7568. map[m].save.map=mapindex;
  7569. map[m].save.x=x;
  7570. map[m].save.y=y;
  7571. }
  7572. return 0;
  7573. }
  7574. int buildin_setmapflag(struct script_state *st)
  7575. {
  7576. int m,i;
  7577. char *str;
  7578. char *val=NULL;
  7579. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7580. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7581. if(st->end>st->start+4){
  7582. val=conv_str(st,& (st->stack->stack_data[st->start+4]));
  7583. }
  7584. m = map_mapname2mapid(str);
  7585. if(m >= 0) {
  7586. switch(i) {
  7587. case MF_NOMEMO:
  7588. map[m].flag.nomemo=1;
  7589. break;
  7590. case MF_NOTELEPORT:
  7591. map[m].flag.noteleport=1;
  7592. break;
  7593. case MF_NOBRANCH:
  7594. map[m].flag.nobranch=1;
  7595. break;
  7596. case MF_NOPENALTY:
  7597. map[m].flag.noexppenalty=1;
  7598. map[m].flag.nozenypenalty=1;
  7599. break;
  7600. case MF_NOZENYPENALTY:
  7601. map[m].flag.nozenypenalty=1;
  7602. break;
  7603. case MF_PVP:
  7604. map[m].flag.pvp=1;
  7605. break;
  7606. case MF_PVP_NOPARTY:
  7607. map[m].flag.pvp_noparty=1;
  7608. break;
  7609. case MF_PVP_NOGUILD:
  7610. map[m].flag.pvp_noguild=1;
  7611. break;
  7612. case MF_GVG:
  7613. map[m].flag.gvg=1;
  7614. break;
  7615. case MF_GVG_NOPARTY:
  7616. map[m].flag.gvg_noparty=1;
  7617. break;
  7618. case MF_GVG_DUNGEON:
  7619. map[m].flag.gvg_dungeon=1;
  7620. break;
  7621. case MF_GVG_CASTLE:
  7622. map[m].flag.gvg_castle=1;
  7623. break;
  7624. case MF_NOTRADE:
  7625. map[m].flag.notrade=1;
  7626. break;
  7627. case MF_NODROP:
  7628. map[m].flag.nodrop=1;
  7629. break;
  7630. case MF_NOSKILL:
  7631. map[m].flag.noskill=1;
  7632. break;
  7633. case MF_NOWARP:
  7634. map[m].flag.nowarp=1;
  7635. break;
  7636. case MF_NOICEWALL: // [Valaris]
  7637. map[m].flag.noicewall=1;
  7638. break;
  7639. case MF_SNOW: // [Valaris]
  7640. map[m].flag.snow=1;
  7641. break;
  7642. case MF_CLOUDS:
  7643. map[m].flag.clouds=1;
  7644. break;
  7645. case MF_CLOUDS2: // [Valaris]
  7646. map[m].flag.clouds2=1;
  7647. break;
  7648. case MF_FOG: // [Valaris]
  7649. map[m].flag.fog=1;
  7650. break;
  7651. case MF_FIREWORKS:
  7652. map[m].flag.fireworks=1;
  7653. break;
  7654. case MF_SAKURA: // [Valaris]
  7655. map[m].flag.sakura=1;
  7656. break;
  7657. case MF_LEAVES: // [Valaris]
  7658. map[m].flag.leaves=1;
  7659. break;
  7660. case MF_RAIN: // [Valaris]
  7661. map[m].flag.rain=1;
  7662. break;
  7663. case MF_INDOORS: // celest
  7664. map[m].flag.indoors=1;
  7665. break;
  7666. case MF_NIGHTENABLED:
  7667. map[m].flag.nightenabled=1;
  7668. break;
  7669. case MF_NOGO: // celest
  7670. map[m].flag.nogo=1;
  7671. break;
  7672. case MF_NOBASEEXP:
  7673. map[m].flag.nobaseexp=1;
  7674. break;
  7675. case MF_NOJOBEXP:
  7676. map[m].flag.nojobexp=1;
  7677. break;
  7678. case MF_NOMOBLOOT:
  7679. map[m].flag.nomobloot=1;
  7680. break;
  7681. case MF_NOMVPLOOT:
  7682. map[m].flag.nomvploot=1;
  7683. break;
  7684. case MF_NORETURN:
  7685. map[m].flag.noreturn=1;
  7686. break;
  7687. case MF_NOWARPTO:
  7688. map[m].flag.nowarpto=1;
  7689. break;
  7690. case MF_NIGHTMAREDROP:
  7691. map[m].flag.pvp_nightmaredrop=1;
  7692. break;
  7693. case MF_RESTRICTED:
  7694. map[m].flag.restricted=1;
  7695. break;
  7696. case MF_NOCOMMAND:
  7697. map[m].nocommand = (!val || atoi(val) <= 0) ? 100 : atoi(val);
  7698. break;
  7699. case MF_JEXP:
  7700. map[m].jexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7701. break;
  7702. case MF_BEXP:
  7703. map[m].bexp = (!val || atoi(val) < 0) ? 100 : atoi(val);
  7704. break;
  7705. case MF_NOVENDING:
  7706. map[m].flag.novending=1;
  7707. break;
  7708. case MF_LOADEVENT:
  7709. map[m].flag.loadevent=1;
  7710. break;
  7711. case MF_NOCHAT:
  7712. map[m].flag.nochat=1;
  7713. break;
  7714. case MF_PARTYLOCK:
  7715. map[m].flag.partylock=1;
  7716. break;
  7717. case MF_GUILDLOCK:
  7718. map[m].flag.guildlock=1;
  7719. break;
  7720. }
  7721. }
  7722. return 0;
  7723. }
  7724. int buildin_removemapflag(struct script_state *st)
  7725. {
  7726. int m,i;
  7727. char *str;
  7728. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7729. i=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7730. m = map_mapname2mapid(str);
  7731. if(m >= 0) {
  7732. switch(i) {
  7733. case MF_NOMEMO:
  7734. map[m].flag.nomemo=0;
  7735. break;
  7736. case MF_NOTELEPORT:
  7737. map[m].flag.noteleport=0;
  7738. break;
  7739. case MF_NOSAVE:
  7740. map[m].flag.nosave=0;
  7741. break;
  7742. case MF_NOBRANCH:
  7743. map[m].flag.nobranch=0;
  7744. break;
  7745. case MF_NOPENALTY:
  7746. map[m].flag.noexppenalty=0;
  7747. map[m].flag.nozenypenalty=0;
  7748. break;
  7749. case MF_PVP:
  7750. map[m].flag.pvp=0;
  7751. break;
  7752. case MF_PVP_NOPARTY:
  7753. map[m].flag.pvp_noparty=0;
  7754. break;
  7755. case MF_PVP_NOGUILD:
  7756. map[m].flag.pvp_noguild=0;
  7757. break;
  7758. case MF_GVG:
  7759. map[m].flag.gvg=0;
  7760. break;
  7761. case MF_GVG_NOPARTY:
  7762. map[m].flag.gvg_noparty=0;
  7763. break;
  7764. case MF_GVG_DUNGEON:
  7765. map[m].flag.gvg_dungeon=0;
  7766. break;
  7767. case MF_GVG_CASTLE:
  7768. map[m].flag.gvg_castle=0;
  7769. break;
  7770. case MF_NOZENYPENALTY:
  7771. map[m].flag.nozenypenalty=0;
  7772. break;
  7773. case MF_NOTRADE:
  7774. map[m].flag.notrade=0;
  7775. break;
  7776. case MF_NODROP:
  7777. map[m].flag.nodrop=0;
  7778. break;
  7779. case MF_NOSKILL:
  7780. map[m].flag.noskill=0;
  7781. break;
  7782. case MF_NOWARP:
  7783. map[m].flag.nowarp=0;
  7784. break;
  7785. case MF_NOICEWALL: // [Valaris]
  7786. map[m].flag.noicewall=0;
  7787. break;
  7788. case MF_SNOW: // [Valaris]
  7789. map[m].flag.snow=0;
  7790. break;
  7791. case MF_CLOUDS:
  7792. map[m].flag.clouds=0;
  7793. break;
  7794. case MF_CLOUDS2: // [Valaris]
  7795. map[m].flag.clouds2=0;
  7796. break;
  7797. case MF_FOG: // [Valaris]
  7798. map[m].flag.fog=0;
  7799. break;
  7800. case MF_FIREWORKS:
  7801. map[m].flag.fireworks=0;
  7802. break;
  7803. case MF_SAKURA: // [Valaris]
  7804. map[m].flag.sakura=0;
  7805. break;
  7806. case MF_LEAVES: // [Valaris]
  7807. map[m].flag.leaves=0;
  7808. break;
  7809. case MF_RAIN: // [Valaris]
  7810. map[m].flag.rain=0;
  7811. break;
  7812. case MF_INDOORS: // celest
  7813. map[m].flag.indoors=0;
  7814. break;
  7815. case MF_NIGHTENABLED:
  7816. map[m].flag.nightenabled=0;
  7817. break;
  7818. case MF_NOGO: // celest
  7819. map[m].flag.nogo=0;
  7820. break;
  7821. case MF_NOBASEEXP:
  7822. map[m].flag.nobaseexp=0;
  7823. break;
  7824. case MF_NOJOBEXP:
  7825. map[m].flag.nojobexp=0;
  7826. break;
  7827. case MF_NOMOBLOOT:
  7828. map[m].flag.nomobloot=0;
  7829. break;
  7830. case MF_NOMVPLOOT:
  7831. map[m].flag.nomvploot=0;
  7832. break;
  7833. case MF_NORETURN:
  7834. map[m].flag.noreturn=0;
  7835. break;
  7836. case MF_NOWARPTO:
  7837. map[m].flag.nowarpto=0;
  7838. break;
  7839. case MF_NIGHTMAREDROP:
  7840. map[m].flag.pvp_nightmaredrop=0;
  7841. break;
  7842. case MF_RESTRICTED:
  7843. map[m].flag.restricted=0;
  7844. break;
  7845. case MF_NOCOMMAND:
  7846. map[m].nocommand=0;
  7847. break;
  7848. case MF_JEXP:
  7849. map[m].jexp=100;
  7850. break;
  7851. case MF_BEXP:
  7852. map[m].bexp=100;
  7853. break;
  7854. case MF_NOVENDING:
  7855. map[m].flag.novending=0;
  7856. break;
  7857. case MF_LOADEVENT:
  7858. map[m].flag.loadevent=0;
  7859. break;
  7860. case MF_NOCHAT:
  7861. map[m].flag.nochat=0;
  7862. break;
  7863. case MF_PARTYLOCK:
  7864. map[m].flag.partylock=0;
  7865. break;
  7866. case MF_GUILDLOCK:
  7867. map[m].flag.guildlock=0;
  7868. break;
  7869. }
  7870. }
  7871. return 0;
  7872. }
  7873. int buildin_pvpon(struct script_state *st)
  7874. {
  7875. int m,i,users;
  7876. char *str;
  7877. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7878. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7879. m = map_mapname2mapid(str);
  7880. if(m >= 0 && !map[m].flag.pvp) {
  7881. map[m].flag.pvp = 1;
  7882. clif_send0199(m,1);
  7883. if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
  7884. return 0;
  7885. pl_allsd = map_getallusers(&users);
  7886. for(i=0;i<users;i++)
  7887. {
  7888. if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
  7889. {
  7890. pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
  7891. pl_sd->pvp_rank=0;
  7892. pl_sd->pvp_lastusers=0;
  7893. pl_sd->pvp_point=5;
  7894. pl_sd->pvp_won = 0;
  7895. pl_sd->pvp_lost = 0;
  7896. }
  7897. }
  7898. }
  7899. return 0;
  7900. }
  7901. int buildin_pvpoff(struct script_state *st)
  7902. {
  7903. int m,i,users;
  7904. char *str;
  7905. struct map_session_data *pl_sd=NULL, **pl_allsd;
  7906. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7907. m = map_mapname2mapid(str);
  7908. if(m >= 0 && map[m].flag.pvp) { //fixed Lupus
  7909. map[m].flag.pvp = 0;
  7910. clif_send0199(m,0);
  7911. if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
  7912. return 0;
  7913. pl_allsd = map_getallusers(&users);
  7914. for(i=0;i<users;i++)
  7915. {
  7916. if((pl_sd=pl_allsd[i]) && m == pl_sd->bl.m)
  7917. {
  7918. clif_pvpset(pl_sd,0,0,2);
  7919. if(pl_sd->pvp_timer != UINT_MAX) {
  7920. delete_timer(pl_sd->pvp_timer,pc_calc_pvprank_timer);
  7921. pl_sd->pvp_timer = -1;
  7922. }
  7923. }
  7924. }
  7925. }
  7926. return 0;
  7927. }
  7928. int buildin_gvgon(struct script_state *st)
  7929. {
  7930. int m;
  7931. char *str;
  7932. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7933. m = map_mapname2mapid(str);
  7934. if(m >= 0 && !map[m].flag.gvg) {
  7935. map[m].flag.gvg = 1;
  7936. clif_send0199(m,3);
  7937. }
  7938. return 0;
  7939. }
  7940. int buildin_gvgoff(struct script_state *st)
  7941. {
  7942. int m;
  7943. char *str;
  7944. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  7945. m = map_mapname2mapid(str);
  7946. if(m >= 0 && map[m].flag.gvg) {
  7947. map[m].flag.gvg = 0;
  7948. clif_send0199(m,0);
  7949. }
  7950. return 0;
  7951. }
  7952. /*==========================================
  7953. * Shows an emoticon on top of the player/npc
  7954. * emotion emotion#, <target: 0 - NPC, 1 - PC>
  7955. *------------------------------------------
  7956. */
  7957. //Optional second parameter added by [Skotlex]
  7958. int buildin_emotion(struct script_state *st)
  7959. {
  7960. int type;
  7961. int player=0;
  7962. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  7963. if(type < 0 || type > 100)
  7964. return 0;
  7965. if( st->end>st->start+3 )
  7966. player=conv_num(st,& (st->stack->stack_data[st->start+3]));
  7967. if (player) {
  7968. struct map_session_data *sd = script_rid2sd(st);
  7969. if (sd)
  7970. clif_emotion(&sd->bl,type);
  7971. } else
  7972. clif_emotion(map_id2bl(st->oid),type);
  7973. return 0;
  7974. }
  7975. static int buildin_maprespawnguildid_sub_pc(DBKey key, void *data, va_list ap)
  7976. {
  7977. int m=va_arg(ap,int);
  7978. int g_id=va_arg(ap,int);
  7979. int flag=va_arg(ap,int);
  7980. struct map_session_data *sd = (TBL_PC*)data;
  7981. if(!sd || sd->bl.m != m)
  7982. return 0;
  7983. if(
  7984. (sd->status.guild_id == g_id && flag&1) || //Warp out owners
  7985. (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders
  7986. (sd->status.guild_id == 0) // Warp out players not in guild [Valaris]
  7987. )
  7988. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
  7989. return 1;
  7990. }
  7991. static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
  7992. {
  7993. struct mob_data *md=(struct mob_data *)bl;
  7994. if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
  7995. status_kill(bl);
  7996. return 0;
  7997. }
  7998. int buildin_maprespawnguildid(struct script_state *st)
  7999. {
  8000. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8001. int g_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8002. int flag=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8003. int m=map_mapname2mapid(mapname);
  8004. if(m == -1)
  8005. return 0;
  8006. //Catch ALL players (in case some are 'between maps' on execution time)
  8007. map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag);
  8008. if (flag&4) //Remove script mobs.
  8009. map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB);
  8010. return 0;
  8011. }
  8012. int buildin_agitstart(struct script_state *st)
  8013. {
  8014. if(agit_flag==1) return 0; // Agit already Start.
  8015. agit_flag=1;
  8016. guild_agit_start();
  8017. return 0;
  8018. }
  8019. int buildin_agitend(struct script_state *st)
  8020. {
  8021. if(agit_flag==0) return 0; // Agit already End.
  8022. agit_flag=0;
  8023. guild_agit_end();
  8024. return 0;
  8025. }
  8026. /*==========================================
  8027. * Returns whether woe is on or off. // choice script
  8028. *------------------------------------------
  8029. */
  8030. int buildin_agitcheck(struct script_state *st)
  8031. {
  8032. push_val(st->stack,C_INT,agit_flag);
  8033. return 0;
  8034. }
  8035. int buildin_flagemblem(struct script_state *st)
  8036. {
  8037. int g_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8038. if(g_id < 0) return 0;
  8039. // printf("Script.c: [FlagEmblem] GuildID=%d, Emblem=%d.\n", g->guild_id, g->emblem_id);
  8040. ((struct npc_data *)map_id2bl(st->oid))->u.scr.guild_id = g_id;
  8041. return 0;
  8042. }
  8043. int buildin_getcastlename(struct script_state *st)
  8044. {
  8045. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8046. struct guild_castle *gc=NULL;
  8047. int i;
  8048. for(i=0;i<MAX_GUILDCASTLE;i++){
  8049. if( (gc=guild_castle_search(i)) != NULL ){
  8050. if(strcmp(mapname,gc->map_name)==0){
  8051. break;
  8052. }
  8053. }
  8054. }
  8055. if(gc)
  8056. push_str(st->stack,C_CONSTSTR,gc->castle_name);
  8057. else
  8058. push_str(st->stack,C_CONSTSTR,"");
  8059. return 0;
  8060. }
  8061. int buildin_getcastledata(struct script_state *st)
  8062. {
  8063. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8064. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8065. char *event=NULL;
  8066. struct guild_castle *gc;
  8067. int i,j;
  8068. if( st->end>st->start+4 && index==0){
  8069. for(i=0,j=-1;i<MAX_GUILDCASTLE;i++)
  8070. if( (gc=guild_castle_search(i)) != NULL &&
  8071. strcmp(mapname,gc->map_name)==0 )
  8072. j=i;
  8073. if(j>=0){
  8074. event=conv_str(st,& (st->stack->stack_data[st->start+4]));
  8075. check_event(st, event);
  8076. guild_addcastleinfoevent(j,17,event);
  8077. }
  8078. }
  8079. for(i=0;i<MAX_GUILDCASTLE;i++){
  8080. if( (gc=guild_castle_search(i)) != NULL ){
  8081. if(strcmp(mapname,gc->map_name)==0){
  8082. switch(index){
  8083. case 0: for(j=1;j<26;j++) guild_castledataload(gc->castle_id,j); break; // Initialize[AgitInit]
  8084. case 1: push_val(st->stack,C_INT,gc->guild_id); break;
  8085. case 2: push_val(st->stack,C_INT,gc->economy); break;
  8086. case 3: push_val(st->stack,C_INT,gc->defense); break;
  8087. case 4: push_val(st->stack,C_INT,gc->triggerE); break;
  8088. case 5: push_val(st->stack,C_INT,gc->triggerD); break;
  8089. case 6: push_val(st->stack,C_INT,gc->nextTime); break;
  8090. case 7: push_val(st->stack,C_INT,gc->payTime); break;
  8091. case 8: push_val(st->stack,C_INT,gc->createTime); break;
  8092. case 9: push_val(st->stack,C_INT,gc->visibleC); break;
  8093. case 10:
  8094. case 11:
  8095. case 12:
  8096. case 13:
  8097. case 14:
  8098. case 15:
  8099. case 16:
  8100. case 17:
  8101. push_val(st->stack,C_INT,gc->guardian[index-10].visible); break;
  8102. case 18:
  8103. case 19:
  8104. case 20:
  8105. case 21:
  8106. case 22:
  8107. case 23:
  8108. case 24:
  8109. case 25:
  8110. push_val(st->stack,C_INT,gc->guardian[index-18].hp); break;
  8111. default:
  8112. push_val(st->stack,C_INT,0); break;
  8113. }
  8114. return 0;
  8115. }
  8116. }
  8117. }
  8118. push_val(st->stack,C_INT,0);
  8119. return 0;
  8120. }
  8121. int buildin_setcastledata(struct script_state *st)
  8122. {
  8123. char *mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8124. int index=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8125. int value=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8126. struct guild_castle *gc;
  8127. int i;
  8128. for(i=0;i<MAX_GUILDCASTLE;i++){
  8129. if( (gc=guild_castle_search(i)) != NULL ){
  8130. if(strcmp(mapname,gc->map_name)==0){
  8131. // Save Data byself First
  8132. switch(index){
  8133. case 1: gc->guild_id = value; break;
  8134. case 2: gc->economy = value; break;
  8135. case 3: gc->defense = value; break;
  8136. case 4: gc->triggerE = value; break;
  8137. case 5: gc->triggerD = value; break;
  8138. case 6: gc->nextTime = value; break;
  8139. case 7: gc->payTime = value; break;
  8140. case 8: gc->createTime = value; break;
  8141. case 9: gc->visibleC = value; break;
  8142. case 10:
  8143. case 11:
  8144. case 12:
  8145. case 13:
  8146. case 14:
  8147. case 15:
  8148. case 16:
  8149. case 17:
  8150. gc->guardian[index-10].visible = value; break;
  8151. case 18:
  8152. case 19:
  8153. case 20:
  8154. case 21:
  8155. case 22:
  8156. case 23:
  8157. case 24:
  8158. case 25:
  8159. gc->guardian[index-18].hp = value;
  8160. if (gc->guardian[index-18].id)
  8161. { //Update this mob's HP.
  8162. struct block_list *bl = map_id2bl(gc->guardian[index-18].id);
  8163. if (!bl)
  8164. { //Wrong target?
  8165. gc->guardian[index-18].id = 0;
  8166. break;
  8167. }
  8168. if (value < 1) {
  8169. status_kill(bl);
  8170. break;
  8171. }
  8172. status_set_hp(bl, value, 0);
  8173. }
  8174. break;
  8175. default: return 0;
  8176. }
  8177. guild_castledatasave(gc->castle_id,index,value);
  8178. return 0;
  8179. }
  8180. }
  8181. }
  8182. return 0;
  8183. }
  8184. /* =====================================================================
  8185. * ギルド情報を要求する
  8186. * ---------------------------------------------------------------------
  8187. */
  8188. int buildin_requestguildinfo(struct script_state *st)
  8189. {
  8190. int guild_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8191. char *event=NULL;
  8192. if( st->end>st->start+3 ){
  8193. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8194. check_event(st, event);
  8195. }
  8196. if(guild_id>0)
  8197. guild_npc_request_info(guild_id,event);
  8198. return 0;
  8199. }
  8200. /* =====================================================================
  8201. * カードの数を得る
  8202. * ---------------------------------------------------------------------
  8203. */
  8204. int buildin_getequipcardcnt(struct script_state *st)
  8205. {
  8206. int i,num;
  8207. struct map_session_data *sd;
  8208. int c=MAX_SLOTS;
  8209. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8210. sd=script_rid2sd(st);
  8211. i=pc_checkequip(sd,equip[num-1]);
  8212. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8213. {
  8214. push_val(st->stack,C_INT,0);
  8215. return 0;
  8216. }
  8217. do{
  8218. if(sd->status.inventory[i].card[c-1] &&
  8219. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8220. push_val(st->stack,C_INT,(c));
  8221. return 0;
  8222. }
  8223. }while(c--);
  8224. push_val(st->stack,C_INT,0);
  8225. return 0;
  8226. }
  8227. /* ================================================================
  8228. * カード取り外し成功
  8229. * ----------------------------------------------------------------
  8230. */
  8231. int buildin_successremovecards(struct script_state *st)
  8232. {
  8233. int i,j,num,cardflag=0,flag;
  8234. struct map_session_data *sd;
  8235. struct item item_tmp;
  8236. int c=MAX_SLOTS;
  8237. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8238. sd=script_rid2sd(st);
  8239. i=pc_checkequip(sd,equip[num-1]);
  8240. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8241. return 0;
  8242. do{
  8243. if(sd->status.inventory[i].card[c-1] &&
  8244. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8245. cardflag = 1;
  8246. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8247. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8248. item_tmp.attribute=0;
  8249. for (j = 0; j < MAX_SLOTS; j++)
  8250. item_tmp.card[j]=0;
  8251. //Logs items, got from (N)PC scripts [Lupus]
  8252. if(log_config.enable_logs&0x40)
  8253. log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
  8254. if((flag=pc_additem(sd,&item_tmp,1))){ // 持てないならドロップ
  8255. clif_additem(sd,0,0,flag);
  8256. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8257. }
  8258. }
  8259. }while(c--);
  8260. if(cardflag == 1){ // カードを取り除いたアイテム所得
  8261. flag=0;
  8262. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8263. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8264. item_tmp.attribute=sd->status.inventory[i].attribute;
  8265. //Logs items, got from (N)PC scripts [Lupus]
  8266. if(log_config.enable_logs&0x40)
  8267. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8268. for (j = 0; j < MAX_SLOTS; j++)
  8269. item_tmp.card[j]=0;
  8270. pc_delitem(sd,i,1,0);
  8271. //Logs items, got from (N)PC scripts [Lupus]
  8272. if(log_config.enable_logs&0x40)
  8273. log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
  8274. if((flag=pc_additem(sd,&item_tmp,1))){ // もてないならドロップ
  8275. clif_additem(sd,0,0,flag);
  8276. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8277. }
  8278. clif_misceffect(&sd->bl,3);
  8279. return 0;
  8280. }
  8281. return 0;
  8282. }
  8283. /* ================================================================
  8284. * カード取り外し失敗 slot,type
  8285. * type=0: 両方損失、1:カード損失、2:武具損失、3:損失無し
  8286. * ----------------------------------------------------------------
  8287. */
  8288. int buildin_failedremovecards(struct script_state *st)
  8289. {
  8290. int i,j,num,cardflag=0,flag,typefail;
  8291. struct map_session_data *sd;
  8292. struct item item_tmp;
  8293. int c=MAX_SLOTS;
  8294. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8295. typefail=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8296. sd=script_rid2sd(st);
  8297. i=pc_checkequip(sd,equip[num-1]);
  8298. if(itemdb_isspecial(sd->status.inventory[i].card[0]))
  8299. return 0;
  8300. do{
  8301. if(sd->status.inventory[i].card[c-1] &&
  8302. itemdb_type(sd->status.inventory[i].card[c-1]) == IT_CARD){ // [Celest]
  8303. cardflag = 1;
  8304. if(typefail == 2){ // 武具のみ損失なら、カードは受け取らせる
  8305. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].card[c-1];
  8306. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=0;
  8307. item_tmp.attribute=0;
  8308. for (j = 0; j < MAX_SLOTS; j++)
  8309. item_tmp.card[j]=0;
  8310. //Logs items, got from (N)PC scripts [Lupus]
  8311. if(log_config.enable_logs&0x40)
  8312. log_pick_pc(sd, "N", item_tmp.nameid, 1, NULL);
  8313. if((flag=pc_additem(sd,&item_tmp,1))){
  8314. clif_additem(sd,0,0,flag);
  8315. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8316. }
  8317. }
  8318. }
  8319. }while(c--);
  8320. if(cardflag == 1){
  8321. if(typefail == 0 || typefail == 2){ // 武具損失
  8322. //Logs items, got from (N)PC scripts [Lupus]
  8323. if(log_config.enable_logs&0x40)
  8324. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8325. pc_delitem(sd,i,1,0);
  8326. clif_misceffect(&sd->bl,2);
  8327. return 0;
  8328. }
  8329. if(typefail == 1){ // カードのみ損失(武具を返す)
  8330. flag=0;
  8331. item_tmp.id=0,item_tmp.nameid=sd->status.inventory[i].nameid;
  8332. item_tmp.equip=0,item_tmp.identify=1,item_tmp.refine=sd->status.inventory[i].refine;
  8333. item_tmp.attribute=sd->status.inventory[i].attribute;
  8334. //Logs items, got from (N)PC scripts [Lupus]
  8335. if(log_config.enable_logs&0x40)
  8336. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -1, &sd->status.inventory[i]);
  8337. for (j = 0; j < MAX_SLOTS; j++)
  8338. item_tmp.card[j]=0;
  8339. pc_delitem(sd,i,1,0);
  8340. //Logs items, got from (N)PC scripts [Lupus]
  8341. if(log_config.enable_logs&0x40)
  8342. log_pick_pc(sd, "N", item_tmp.nameid, 1, &item_tmp);
  8343. if((flag=pc_additem(sd,&item_tmp,1))){
  8344. clif_additem(sd,0,0,flag);
  8345. map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
  8346. }
  8347. }
  8348. clif_misceffect(&sd->bl,2);
  8349. return 0;
  8350. }
  8351. return 0;
  8352. }
  8353. /* ================================================================
  8354. * mapwarp "<from map>","<to map>",<x>,<y>,<type>,<ID for Type>;
  8355. * type: 0=everyone, 1=guild, 2=party; [Reddozen]
  8356. * improved by [Lance]
  8357. * ================================================================
  8358. */
  8359. int buildin_mapwarp(struct script_state *st) // Added by RoVeRT
  8360. {
  8361. int x,y,m,check_val=0,check_ID=0,i=0;
  8362. struct guild *g = NULL;
  8363. struct party_data *p = NULL;
  8364. char *str;
  8365. char *mapname;
  8366. unsigned int index;
  8367. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8368. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8369. x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8370. y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8371. if(st->end > st->start+7){
  8372. check_val=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8373. check_ID=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8374. }
  8375. if( (m=map_mapname2mapid(mapname))< 0)
  8376. return 0;
  8377. if(!(index=mapindex_name2id(str)))
  8378. return 0;
  8379. switch(check_val){
  8380. case 1:
  8381. g = guild_search(check_ID);
  8382. if (g){
  8383. for( i=0; i < g->max_member; i++)
  8384. {
  8385. if(g->member[i].sd && g->member[i].sd->bl.m==m){
  8386. pc_setpos(g->member[i].sd,index,x,y,3);
  8387. }
  8388. }
  8389. }
  8390. break;
  8391. case 2:
  8392. p = party_search(check_ID);
  8393. if(p){
  8394. for(i=0;i<MAX_PARTY; i++){
  8395. if(p->data[i].sd && p->data[i].sd->bl.m == m){
  8396. pc_setpos(p->data[i].sd,index,x,y,3);
  8397. }
  8398. }
  8399. }
  8400. break;
  8401. default:
  8402. map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y);
  8403. break;
  8404. }
  8405. return 0;
  8406. }
  8407. int buildin_cmdothernpc(struct script_state *st) // Added by RoVeRT
  8408. {
  8409. char *npc,*command;
  8410. npc=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8411. command=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8412. npc_command(map_id2sd(st->rid),npc,command);
  8413. return 0;
  8414. }
  8415. int buildin_inittimer(struct script_state *st) // Added by RoVeRT
  8416. {
  8417. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8418. // nd->lastaction=nd->timer=gettick();
  8419. npc_do_ontimer(st->oid, 1);
  8420. return 0;
  8421. }
  8422. int buildin_stoptimer(struct script_state *st) // Added by RoVeRT
  8423. {
  8424. // struct npc_data *nd=(struct npc_data*)map_id2bl(st->oid);
  8425. // nd->lastaction=nd->timer=-1;
  8426. npc_do_ontimer(st->oid, 0);
  8427. return 0;
  8428. }
  8429. int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
  8430. {
  8431. char *event=va_arg(ap,char *);
  8432. if(strcmp(event,((struct mob_data *)bl)->npc_event)==0)
  8433. return 1;
  8434. return 0;
  8435. }
  8436. int buildin_mobcount(struct script_state *st) // Added by RoVeRT
  8437. {
  8438. char *mapname,*event;
  8439. int m;
  8440. mapname=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8441. event=conv_str(st,& (st->stack->stack_data[st->start+3]));
  8442. check_event(st, event);
  8443. if( (m=map_mapname2mapid(mapname))<0 ) {
  8444. push_val(st->stack,C_INT,-1);
  8445. return 0;
  8446. }
  8447. push_val(st->stack,C_INT,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event));
  8448. return 0;
  8449. }
  8450. int buildin_marriage(struct script_state *st)
  8451. {
  8452. char *partner=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8453. struct map_session_data *sd=script_rid2sd(st);
  8454. struct map_session_data *p_sd=map_nick2sd(partner);
  8455. if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
  8456. push_val(st->stack,C_INT,0);
  8457. return 0;
  8458. }
  8459. push_val(st->stack,C_INT,1);
  8460. return 0;
  8461. }
  8462. int buildin_wedding_effect(struct script_state *st)
  8463. {
  8464. struct map_session_data *sd=script_rid2sd(st);
  8465. struct block_list *bl;
  8466. if(sd==NULL) {
  8467. bl=map_id2bl(st->oid);
  8468. } else
  8469. bl=&sd->bl;
  8470. clif_wedding_effect(bl);
  8471. return 0;
  8472. }
  8473. int buildin_divorce(struct script_state *st)
  8474. {
  8475. struct map_session_data *sd=script_rid2sd(st);
  8476. if(sd==NULL || pc_divorce(sd) < 0){
  8477. push_val(st->stack,C_INT,0);
  8478. return 0;
  8479. }
  8480. push_val(st->stack,C_INT,1);
  8481. return 0;
  8482. }
  8483. int buildin_ispartneron(struct script_state *st)
  8484. {
  8485. struct map_session_data *sd=script_rid2sd(st);
  8486. struct map_session_data *p_sd=NULL;
  8487. if(sd==NULL || !pc_ismarried(sd) ||
  8488. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8489. push_val(st->stack,C_INT,0);
  8490. return 0;
  8491. }
  8492. push_val(st->stack,C_INT,1);
  8493. return 0;
  8494. }
  8495. int buildin_getpartnerid(struct script_state *st)
  8496. {
  8497. struct map_session_data *sd=script_rid2sd(st);
  8498. if (sd == NULL) {
  8499. push_val(st->stack,C_INT,0);
  8500. return 0;
  8501. }
  8502. push_val(st->stack,C_INT,sd->status.partner_id);
  8503. return 0;
  8504. }
  8505. int buildin_getchildid(struct script_state *st)
  8506. {
  8507. struct map_session_data *sd=script_rid2sd(st);
  8508. if (sd == NULL) {
  8509. push_val(st->stack,C_INT,0);
  8510. return 0;
  8511. }
  8512. push_val(st->stack,C_INT,sd->status.child);
  8513. return 0;
  8514. }
  8515. int buildin_getmotherid(struct script_state *st)
  8516. {
  8517. struct map_session_data *sd=script_rid2sd(st);
  8518. if (sd == NULL) {
  8519. push_val(st->stack,C_INT,0);
  8520. return 0;
  8521. }
  8522. push_val(st->stack,C_INT,sd->status.mother);
  8523. return 0;
  8524. }
  8525. int buildin_getfatherid(struct script_state *st)
  8526. {
  8527. struct map_session_data *sd=script_rid2sd(st);
  8528. if (sd == NULL) {
  8529. push_val(st->stack,C_INT,0);
  8530. return 0;
  8531. }
  8532. push_val(st->stack,C_INT,sd->status.father);
  8533. return 0;
  8534. }
  8535. int buildin_warppartner(struct script_state *st)
  8536. {
  8537. int x,y;
  8538. unsigned short mapindex;
  8539. char *str;
  8540. struct map_session_data *sd=script_rid2sd(st);
  8541. struct map_session_data *p_sd=NULL;
  8542. if(sd==NULL || !pc_ismarried(sd) ||
  8543. (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
  8544. push_val(st->stack,C_INT,0);
  8545. return 0;
  8546. }
  8547. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8548. x=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8549. y=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8550. mapindex = mapindex_name2id(str);
  8551. if (mapindex) {
  8552. pc_setpos(p_sd,mapindex,x,y,0);
  8553. push_val(st->stack,C_INT,1);
  8554. } else
  8555. push_val(st->stack,C_INT,0);
  8556. return 0;
  8557. }
  8558. /*================================================
  8559. * Script for Displaying MOB Information [Valaris]
  8560. *------------------------------------------------
  8561. */
  8562. int buildin_strmobinfo(struct script_state *st)
  8563. {
  8564. int num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8565. int class_=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8566. if((class_>=0 && class_<=1000) || class_ >2000)
  8567. return 0;
  8568. switch (num) {
  8569. case 1:
  8570. push_str(st->stack,C_CONSTSTR,mob_db(class_)->name);
  8571. break;
  8572. case 2:
  8573. push_str(st->stack,C_CONSTSTR,mob_db(class_)->jname);
  8574. break;
  8575. case 3:
  8576. push_val(st->stack,C_INT,mob_db(class_)->lv);
  8577. break;
  8578. case 4:
  8579. push_val(st->stack,C_INT,mob_db(class_)->status.max_hp);
  8580. break;
  8581. case 5:
  8582. push_val(st->stack,C_INT,mob_db(class_)->status.max_sp);
  8583. break;
  8584. case 6:
  8585. push_val(st->stack,C_INT,mob_db(class_)->base_exp);
  8586. break;
  8587. case 7:
  8588. push_val(st->stack,C_INT,mob_db(class_)->job_exp);
  8589. break;
  8590. default:
  8591. push_val(st->stack,C_INT,0);
  8592. break;
  8593. }
  8594. return 0;
  8595. }
  8596. /*==========================================
  8597. * Summon guardians [Valaris]
  8598. *------------------------------------------
  8599. */
  8600. int buildin_guardian(struct script_state *st)
  8601. {
  8602. int class_=0,amount=1,x=0,y=0,guardian=0;
  8603. char *str,*map,*event="";
  8604. map =conv_str(st,& (st->stack->stack_data[st->start+2]));
  8605. x =conv_num(st,& (st->stack->stack_data[st->start+3]));
  8606. y =conv_num(st,& (st->stack->stack_data[st->start+4]));
  8607. str =conv_str(st,& (st->stack->stack_data[st->start+5]));
  8608. class_=conv_num(st,& (st->stack->stack_data[st->start+6]));
  8609. amount=conv_num(st,& (st->stack->stack_data[st->start+7]));
  8610. event=conv_str(st,& (st->stack->stack_data[st->start+8]));
  8611. if( st->end>st->start+9 )
  8612. guardian=conv_num(st,& (st->stack->stack_data[st->start+9]));
  8613. check_event(st, event);
  8614. mob_spawn_guardian(map_id2sd(st->rid),map,x,y,str,class_,amount,event,guardian);
  8615. return 0;
  8616. }
  8617. /*================================================
  8618. * Script for Displaying Guardian Info [Valaris]
  8619. *------------------------------------------------
  8620. */
  8621. int buildin_guardianinfo(struct script_state *st)
  8622. {
  8623. int guardian=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8624. struct map_session_data *sd=script_rid2sd(st);
  8625. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  8626. if (guardian < 0 || guardian >= MAX_GUARDIANS || gc==NULL)
  8627. {
  8628. push_val(st->stack,C_INT,-1);
  8629. return 0;
  8630. }
  8631. if(gc->guardian[guardian].visible)
  8632. push_val(st->stack,C_INT,gc->guardian[guardian].hp);
  8633. else push_val(st->stack,C_INT,-1);
  8634. return 0;
  8635. }
  8636. /*==========================================
  8637. * IDからItem名
  8638. *------------------------------------------
  8639. */
  8640. int buildin_getitemname(struct script_state *st)
  8641. {
  8642. int item_id=0;
  8643. struct item_data *i_data;
  8644. char *item_name;
  8645. struct script_data *data;
  8646. data=&(st->stack->stack_data[st->start+2]);
  8647. get_val(st,data);
  8648. if( data->type==C_STR || data->type==C_CONSTSTR ){
  8649. const char *name=conv_str(st,data);
  8650. struct item_data *item_data = itemdb_searchname(name);
  8651. if( item_data )
  8652. item_id=item_data->nameid;
  8653. }else
  8654. item_id=conv_num(st,data);
  8655. i_data = itemdb_exists(item_id);
  8656. if (i_data == NULL)
  8657. {
  8658. push_str(st->stack,C_CONSTSTR,"null");
  8659. return 0;
  8660. }
  8661. item_name=(char *)aMallocA(ITEM_NAME_LENGTH*sizeof(char));
  8662. memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
  8663. push_str(st->stack,C_STR,item_name);
  8664. return 0;
  8665. }
  8666. /*==========================================
  8667. * Returns number of slots an item has. [Skotlex]
  8668. *------------------------------------------
  8669. */
  8670. int buildin_getitemslots(struct script_state *st)
  8671. {
  8672. int item_id;
  8673. struct item_data *i_data;
  8674. item_id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8675. i_data = itemdb_exists(item_id);
  8676. if (i_data)
  8677. push_val(st->stack,C_INT,i_data->slot);
  8678. else
  8679. push_val(st->stack,C_INT,-1);
  8680. return 0;
  8681. }
  8682. /*==========================================
  8683. * Returns some values of an item [Lupus]
  8684. * Price, Weight, etc...
  8685. getiteminfo(itemID,n), where n
  8686. 0 value_buy;
  8687. 1 value_sell;
  8688. 2 type;
  8689. 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
  8690. if = 0, then monsters don't drop it at all (rare or a quest item)
  8691. if = 10000, then this item is sold in NPC shops only
  8692. 4 sex;
  8693. 5 equip;
  8694. 6 weight;
  8695. 7 atk;
  8696. 8 def;
  8697. 9 range;
  8698. 10 slot;
  8699. 11 look;
  8700. 12 elv;
  8701. 13 wlv;
  8702. *------------------------------------------
  8703. */
  8704. int buildin_getiteminfo(struct script_state *st)
  8705. {
  8706. int item_id,n;
  8707. int *item_arr;
  8708. struct item_data *i_data;
  8709. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8710. n = conv_num(st,& (st->stack->stack_data[st->start+3]));
  8711. i_data = itemdb_exists(item_id);
  8712. if (i_data && n>=0 && n<14) {
  8713. item_arr = (int*)&i_data->value_buy;
  8714. push_val(st->stack,C_INT,item_arr[n]);
  8715. } else
  8716. push_val(st->stack,C_INT,-1);
  8717. return 0;
  8718. }
  8719. /*==========================================
  8720. * Returns value from equipped item slot n [Lupus]
  8721. getequipcardid(num,slot)
  8722. where
  8723. num = eqip position slot
  8724. slot = 0,1,2,3 (Card Slot N)
  8725. This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
  8726. it's useful when you want to check item cards or if it's signed
  8727. Useful for such quests as "Sign this refined item with players name" etc
  8728. Hat[0] +4 -> Player's Hat[0] +4
  8729. *------------------------------------------
  8730. */
  8731. int buildin_getequipcardid(struct script_state *st)
  8732. {
  8733. int i,num,slot;
  8734. struct map_session_data *sd;
  8735. num=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8736. slot=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8737. sd=script_rid2sd(st);
  8738. i=pc_checkequip(sd,equip[num-1]);
  8739. if(i >= 0 && slot>=0 && slot<4)
  8740. push_val(st->stack,C_INT,sd->status.inventory[i].card[slot]);
  8741. else
  8742. push_val(st->stack,C_INT,0);
  8743. return 0;
  8744. }
  8745. /*==========================================
  8746. * petskillbonus [Valaris] //Rewritten by [Skotlex]
  8747. *------------------------------------------
  8748. */
  8749. int buildin_petskillbonus(struct script_state *st)
  8750. {
  8751. struct pet_data *pd;
  8752. struct map_session_data *sd=script_rid2sd(st);
  8753. if(sd==NULL || sd->pd==NULL)
  8754. return 0;
  8755. pd=sd->pd;
  8756. if (pd->bonus)
  8757. { //Clear previous bonus
  8758. if (pd->bonus->timer != -1)
  8759. delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
  8760. } else //init
  8761. pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
  8762. pd->bonus->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8763. pd->bonus->val=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8764. pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8765. pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
  8766. if (pd->state.skillbonus == 1)
  8767. pd->state.skillbonus=0; // waiting state
  8768. // wait for timer to start
  8769. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  8770. pd->bonus->timer=-1;
  8771. else
  8772. pd->bonus->timer=add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
  8773. return 0;
  8774. }
  8775. /*==========================================
  8776. * pet looting [Valaris] //Rewritten by [Skotlex]
  8777. *------------------------------------------
  8778. */
  8779. int buildin_petloot(struct script_state *st)
  8780. {
  8781. int max;
  8782. struct pet_data *pd;
  8783. struct map_session_data *sd=script_rid2sd(st);
  8784. if(sd==NULL || sd->pd==NULL)
  8785. return 0;
  8786. max=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8787. if(max < 1)
  8788. max = 1; //Let'em loot at least 1 item.
  8789. else if (max > MAX_PETLOOT_SIZE)
  8790. max = MAX_PETLOOT_SIZE;
  8791. pd = sd->pd;
  8792. if (pd->loot != NULL)
  8793. { //Release whatever was there already and reallocate memory
  8794. pet_lootitem_drop(pd, pd->msd);
  8795. aFree(pd->loot->item);
  8796. }
  8797. else
  8798. pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
  8799. pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
  8800. pd->loot->max=max;
  8801. pd->loot->count = 0;
  8802. pd->loot->weight = 0;
  8803. return 0;
  8804. }
  8805. /*==========================================
  8806. * PCの所持品情報読み取り
  8807. *------------------------------------------
  8808. */
  8809. int buildin_getinventorylist(struct script_state *st)
  8810. {
  8811. struct map_session_data *sd=script_rid2sd(st);
  8812. unsigned char card_var[NAME_LENGTH];
  8813. int i,j=0,k;
  8814. if(!sd) return 0;
  8815. for(i=0;i<MAX_INVENTORY;i++){
  8816. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
  8817. pc_setreg(sd,add_str("@inventorylist_id")+(j<<24),sd->status.inventory[i].nameid);
  8818. pc_setreg(sd,add_str("@inventorylist_amount")+(j<<24),sd->status.inventory[i].amount);
  8819. pc_setreg(sd,add_str("@inventorylist_equip")+(j<<24),sd->status.inventory[i].equip);
  8820. pc_setreg(sd,add_str("@inventorylist_refine")+(j<<24),sd->status.inventory[i].refine);
  8821. pc_setreg(sd,add_str("@inventorylist_identify")+(j<<24),sd->status.inventory[i].identify);
  8822. pc_setreg(sd,add_str("@inventorylist_attribute")+(j<<24),sd->status.inventory[i].attribute);
  8823. for (k = 0; k < MAX_SLOTS; k++)
  8824. {
  8825. sprintf(card_var, "@inventorylist_card%d",k+1);
  8826. pc_setreg(sd,add_str(card_var)+(j<<24),sd->status.inventory[i].card[k]);
  8827. }
  8828. j++;
  8829. }
  8830. }
  8831. pc_setreg(sd,add_str("@inventorylist_count"),j);
  8832. return 0;
  8833. }
  8834. int buildin_getskilllist(struct script_state *st)
  8835. {
  8836. struct map_session_data *sd=script_rid2sd(st);
  8837. int i,j=0;
  8838. if(!sd) return 0;
  8839. for(i=0;i<MAX_SKILL;i++){
  8840. if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
  8841. pc_setreg(sd,add_str("@skilllist_id")+(j<<24),sd->status.skill[i].id);
  8842. pc_setreg(sd,add_str("@skilllist_lv")+(j<<24),sd->status.skill[i].lv);
  8843. pc_setreg(sd,add_str("@skilllist_flag")+(j<<24),sd->status.skill[i].flag);
  8844. j++;
  8845. }
  8846. }
  8847. pc_setreg(sd,add_str("@skilllist_count"),j);
  8848. return 0;
  8849. }
  8850. int buildin_clearitem(struct script_state *st)
  8851. {
  8852. struct map_session_data *sd=script_rid2sd(st);
  8853. int i;
  8854. if(sd==NULL) return 0;
  8855. for (i=0; i<MAX_INVENTORY; i++) {
  8856. if (sd->status.inventory[i].amount) {
  8857. //Logs items, got from (N)PC scripts [Lupus]
  8858. if(log_config.enable_logs&0x40)
  8859. log_pick_pc(sd, "N", sd->status.inventory[i].nameid, -sd->status.inventory[i].amount, &sd->status.inventory[i]);
  8860. pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
  8861. }
  8862. }
  8863. return 0;
  8864. }
  8865. /*==========================================
  8866. Disguise Player (returns Mob/NPC ID if success, 0 on fail) [Lupus]
  8867. *------------------------------------------
  8868. */
  8869. int buildin_disguise(struct script_state *st)
  8870. {
  8871. struct map_session_data *sd=script_rid2sd(st);
  8872. int id;
  8873. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  8874. if (!mobdb_checkid(id) && !npcdb_checkid(id)) {
  8875. push_val(st->stack,C_INT,0);
  8876. return 0;
  8877. }
  8878. pc_disguise(sd, id);
  8879. push_val(st->stack,C_INT,id);
  8880. return 0;
  8881. }
  8882. /*==========================================
  8883. Undisguise Player (returns 1 if success, 0 on fail) [Lupus]
  8884. *------------------------------------------
  8885. */
  8886. int buildin_undisguise(struct script_state *st)
  8887. {
  8888. struct map_session_data *sd=script_rid2sd(st);
  8889. if (sd->disguise) {
  8890. pc_disguise(sd, 0);
  8891. push_val(st->stack,C_INT,0);
  8892. } else {
  8893. push_val(st->stack,C_INT,1);
  8894. }
  8895. return 0;
  8896. }
  8897. /*==========================================
  8898. * NPCクラスチェンジ
  8899. * classは変わりたいclass
  8900. * typeは通常0なのかな?
  8901. *------------------------------------------
  8902. */
  8903. int buildin_classchange(struct script_state *st)
  8904. {
  8905. int _class,type;
  8906. struct block_list *bl=map_id2bl(st->oid);
  8907. if(bl==NULL) return 0;
  8908. _class=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8909. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8910. clif_class_change(bl,_class,type);
  8911. return 0;
  8912. }
  8913. /*==========================================
  8914. * NPCから発生するエフェクト
  8915. *------------------------------------------
  8916. */
  8917. int buildin_misceffect(struct script_state *st)
  8918. {
  8919. int type;
  8920. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  8921. if(st->oid && st->oid != fake_nd->bl.id) {
  8922. struct block_list *bl = map_id2bl(st->oid);
  8923. if (bl)
  8924. clif_misceffect2(bl,type);
  8925. } else{
  8926. struct map_session_data *sd=script_rid2sd(st);
  8927. if(sd)
  8928. clif_misceffect2(&sd->bl,type);
  8929. }
  8930. return 0;
  8931. }
  8932. /*==========================================
  8933. * サウンドエフェクト
  8934. *------------------------------------------
  8935. */
  8936. int buildin_soundeffect(struct script_state *st)
  8937. {
  8938. // Redundn
  8939. struct map_session_data *sd=script_rid2sd(st);
  8940. char *name;
  8941. int type=0;
  8942. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8943. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8944. if(sd){
  8945. if(!st->rid)
  8946. clif_soundeffect(sd,map_id2bl(st->oid),name,type);
  8947. else{
  8948. clif_soundeffect(sd,&sd->bl,name,type);
  8949. }
  8950. }
  8951. return 0;
  8952. }
  8953. int soundeffect_sub(struct block_list* bl,va_list ap)
  8954. {
  8955. char *name;
  8956. int type;
  8957. nullpo_retr(0, bl);
  8958. nullpo_retr(0, ap);
  8959. name = va_arg(ap,char *);
  8960. type = va_arg(ap,int);
  8961. clif_soundeffect((struct map_session_data *)bl, bl, name, type);
  8962. return 0;
  8963. }
  8964. int buildin_soundeffectall(struct script_state *st)
  8965. {
  8966. // [Lance] - Improved.
  8967. char *name, *map = NULL;
  8968. struct block_list *bl;
  8969. int type, coverage, x0, y0, x1, y1;
  8970. name=conv_str(st,& (st->stack->stack_data[st->start+2]));
  8971. type=conv_num(st,& (st->stack->stack_data[st->start+3]));
  8972. coverage=conv_num(st,& (st->stack->stack_data[st->start+4]));
  8973. if(!st->rid)
  8974. bl = map_id2bl(st->oid);
  8975. else
  8976. bl = &(script_rid2sd(st)->bl);
  8977. if(bl){
  8978. if(coverage < 23){
  8979. clif_soundeffectall(bl,name,type,coverage);
  8980. }else {
  8981. if(st->end > st->start+9){
  8982. map=conv_str(st,& (st->stack->stack_data[st->start+5]));
  8983. x0 = conv_num(st,& (st->stack->stack_data[st->start+6]));
  8984. y0 = conv_num(st,& (st->stack->stack_data[st->start+7]));
  8985. x1 = conv_num(st,& (st->stack->stack_data[st->start+8]));
  8986. y1 = conv_num(st,& (st->stack->stack_data[st->start+9]));
  8987. map_foreachinarea(soundeffect_sub,map_mapname2mapid(map),x0,y0,x1,y1,BL_PC,name,type);
  8988. } else {
  8989. ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
  8990. }
  8991. }
  8992. }
  8993. return 0;
  8994. }
  8995. /*==========================================
  8996. * pet status recovery [Valaris] / Rewritten by [Skotlex]
  8997. *------------------------------------------
  8998. */
  8999. int buildin_petrecovery(struct script_state *st)
  9000. {
  9001. struct pet_data *pd;
  9002. struct map_session_data *sd=script_rid2sd(st);
  9003. if(sd==NULL || sd->pd==NULL)
  9004. return 0;
  9005. pd=sd->pd;
  9006. if (pd->recovery)
  9007. { //Halt previous bonus
  9008. if (pd->recovery->timer != -1)
  9009. delete_timer(pd->recovery->timer, pet_recovery_timer);
  9010. } else //Init
  9011. pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
  9012. pd->recovery->type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9013. pd->recovery->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9014. pd->recovery->timer=-1;
  9015. return 0;
  9016. }
  9017. /*==========================================
  9018. * pet healing [Valaris] //Rewritten by [Skotlex]
  9019. *------------------------------------------
  9020. */
  9021. int buildin_petheal(struct script_state *st)
  9022. {
  9023. struct pet_data *pd;
  9024. struct map_session_data *sd=script_rid2sd(st);
  9025. if(sd==NULL || sd->pd==NULL)
  9026. return 0;
  9027. pd=sd->pd;
  9028. if (pd->s_skill)
  9029. { //Clear previous skill
  9030. if (pd->s_skill->timer != -1)
  9031. {
  9032. if (pd->s_skill->id)
  9033. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  9034. else
  9035. delete_timer(pd->s_skill->timer, pet_heal_timer);
  9036. }
  9037. } else //init memory
  9038. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  9039. pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
  9040. //Use the lv as the amount to heal
  9041. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9042. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9043. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9044. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9045. //Use delay as initial offset to avoid skill/heal exploits
  9046. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  9047. pd->s_skill->timer=-1;
  9048. else
  9049. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
  9050. return 0;
  9051. }
  9052. /*==========================================
  9053. * pet attack skills [Valaris] //Rewritten by [Skotlex]
  9054. *------------------------------------------
  9055. */
  9056. int buildin_petskillattack(struct script_state *st)
  9057. {
  9058. struct pet_data *pd;
  9059. struct map_session_data *sd=script_rid2sd(st);
  9060. if(sd==NULL || sd->pd==NULL)
  9061. return 0;
  9062. pd=sd->pd;
  9063. if (pd->a_skill == NULL)
  9064. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  9065. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9066. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9067. pd->a_skill->div_ = 0;
  9068. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9069. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9070. return 0;
  9071. }
  9072. /*==========================================
  9073. * pet attack skills [Valaris]
  9074. *------------------------------------------
  9075. */
  9076. int buildin_petskillattack2(struct script_state *st)
  9077. {
  9078. struct pet_data *pd;
  9079. struct map_session_data *sd=script_rid2sd(st);
  9080. if(sd==NULL || sd->pd==NULL)
  9081. return 0;
  9082. pd=sd->pd;
  9083. if (pd->a_skill == NULL)
  9084. pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
  9085. pd->a_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9086. pd->a_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9087. pd->a_skill->div_ = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9088. pd->a_skill->rate=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9089. pd->a_skill->bonusrate=conv_num(st,& (st->stack->stack_data[st->start+6]));
  9090. return 0;
  9091. }
  9092. /*==========================================
  9093. * pet support skills [Skotlex]
  9094. *------------------------------------------
  9095. */
  9096. int buildin_petskillsupport(struct script_state *st)
  9097. {
  9098. struct pet_data *pd;
  9099. struct map_session_data *sd=script_rid2sd(st);
  9100. if(sd==NULL || sd->pd==NULL)
  9101. return 0;
  9102. pd=sd->pd;
  9103. if (pd->s_skill)
  9104. { //Clear previous skill
  9105. if (pd->s_skill->timer != -1)
  9106. {
  9107. if (pd->s_skill->id)
  9108. delete_timer(pd->s_skill->timer, pet_skill_support_timer);
  9109. else
  9110. delete_timer(pd->s_skill->timer, pet_heal_timer);
  9111. }
  9112. } else //init memory
  9113. pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
  9114. pd->s_skill->id=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9115. pd->s_skill->lv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9116. pd->s_skill->delay=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9117. pd->s_skill->hp=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9118. pd->s_skill->sp=conv_num(st,& (st->stack->stack_data[st->start+6]));
  9119. //Use delay as initial offset to avoid skill/heal exploits
  9120. if (battle_config.pet_equip_required && pd->pet.equip == 0)
  9121. pd->s_skill->timer=-1;
  9122. else
  9123. pd->s_skill->timer=add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
  9124. return 0;
  9125. }
  9126. /*==========================================
  9127. * Scripted skill effects [Celest]
  9128. *------------------------------------------
  9129. */
  9130. int buildin_skilleffect(struct script_state *st)
  9131. {
  9132. struct map_session_data *sd;
  9133. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9134. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9135. sd=script_rid2sd(st);
  9136. clif_skill_nodamage(&sd->bl,&sd->bl,skillid,skilllv,1);
  9137. return 0;
  9138. }
  9139. /*==========================================
  9140. * NPC skill effects [Valaris]
  9141. *------------------------------------------
  9142. */
  9143. int buildin_npcskilleffect(struct script_state *st)
  9144. {
  9145. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9146. int skillid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9147. int skilllv=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9148. int x=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9149. int y=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9150. clif_skill_poseffect(&nd->bl,skillid,skilllv,x,y,gettick());
  9151. return 0;
  9152. }
  9153. /*==========================================
  9154. * Special effects [Valaris]
  9155. *------------------------------------------
  9156. */
  9157. int buildin_specialeffect(struct script_state *st)
  9158. {
  9159. struct block_list *bl=map_id2bl(st->oid);
  9160. if(bl==NULL)
  9161. return 0;
  9162. clif_specialeffect(bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  9163. return 0;
  9164. }
  9165. int buildin_specialeffect2(struct script_state *st)
  9166. {
  9167. struct map_session_data *sd=script_rid2sd(st);
  9168. if(sd==NULL)
  9169. return 0;
  9170. clif_specialeffect(&sd->bl,conv_num(st,& (st->stack->stack_data[st->start+2])), ((st->end > st->start+3)?conv_num(st,& (st->stack->stack_data[st->start+3])):AREA));
  9171. return 0;
  9172. }
  9173. /*==========================================
  9174. * Nude [Valaris]
  9175. *------------------------------------------
  9176. */
  9177. int buildin_nude(struct script_state *st)
  9178. {
  9179. struct map_session_data *sd=script_rid2sd(st);
  9180. int i,calcflag=0;
  9181. if(sd==NULL)
  9182. return 0;
  9183. for(i=0;i<11;i++)
  9184. if(sd->equip_index[i] >= 0) {
  9185. if(!calcflag)
  9186. calcflag=1;
  9187. pc_unequipitem(sd,sd->equip_index[i],2);
  9188. }
  9189. if(calcflag)
  9190. status_calc_pc(sd,0);
  9191. return 0;
  9192. }
  9193. /*==========================================
  9194. * gmcommand [MouseJstr]
  9195. *
  9196. * suggested on the forums...
  9197. * splitted into atcommand & charcommand by [Skotlex]
  9198. *------------------------------------------
  9199. */
  9200. int buildin_atcommand(struct script_state *st)
  9201. {
  9202. struct map_session_data *sd=NULL;
  9203. char *cmd;
  9204. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9205. if (st->rid)
  9206. sd = script_rid2sd(st);
  9207. if (sd){
  9208. if(cmd[0] != atcommand_symbol){
  9209. cmd += strlen(sd->status.name);
  9210. while(*cmd != atcommand_symbol && *cmd != 0)
  9211. cmd++;
  9212. }
  9213. atcommand_sub(sd->fd, sd, cmd, 99);
  9214. } else { //Use a dummy character.
  9215. struct map_session_data dummy_sd;
  9216. struct block_list *bl = NULL;
  9217. malloc_set(&dummy_sd, 0, sizeof(struct map_session_data));
  9218. if (st->oid) bl = map_id2bl(st->oid);
  9219. if (bl) {
  9220. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9221. if (bl->type == BL_NPC)
  9222. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9223. }
  9224. if(cmd[0] != atcommand_symbol){
  9225. cmd += strlen(dummy_sd.status.name);
  9226. while(*cmd != atcommand_symbol && *cmd != 0)
  9227. cmd++;
  9228. }
  9229. atcommand_sub(0, &dummy_sd, cmd, 99);
  9230. }
  9231. return 0;
  9232. }
  9233. int buildin_charcommand(struct script_state *st)
  9234. {
  9235. struct map_session_data *sd=NULL;
  9236. char *cmd;
  9237. cmd = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9238. if (st->rid)
  9239. sd = script_rid2sd(st);
  9240. if (sd){
  9241. if(cmd[0] != charcommand_symbol){
  9242. cmd += strlen(sd->status.name);
  9243. while(*cmd != charcommand_symbol && *cmd != 0)
  9244. cmd++;
  9245. }
  9246. charcommand_sub(sd->fd, sd, cmd,99);
  9247. } else { //Use a dummy character.
  9248. struct map_session_data dummy_sd;
  9249. struct block_list *bl = NULL;
  9250. malloc_set(&dummy_sd, 0, sizeof(struct map_session_data));
  9251. if (st->oid) bl = map_id2bl(st->oid);
  9252. if (bl) {
  9253. memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
  9254. if (bl->type == BL_NPC)
  9255. strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
  9256. }
  9257. if(cmd[0] != charcommand_symbol){
  9258. cmd += strlen(dummy_sd.status.name);
  9259. while(*cmd != charcommand_symbol && *cmd != 0)
  9260. cmd++;
  9261. }
  9262. charcommand_sub(0, &dummy_sd, cmd, 99);
  9263. }
  9264. return 0;
  9265. }
  9266. /*==========================================
  9267. * Displays a message for the player only (like system messages like "you got an apple" )
  9268. *------------------------------------------
  9269. */
  9270. int buildin_dispbottom(struct script_state *st)
  9271. {
  9272. struct map_session_data *sd=script_rid2sd(st);
  9273. char *message;
  9274. message=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9275. if(sd)
  9276. clif_disp_onlyself(sd,message,(int)strlen(message));
  9277. return 0;
  9278. }
  9279. /*==========================================
  9280. * All The Players Full Recovery
  9281. (HP/SP full restore and resurrect if need)
  9282. *------------------------------------------
  9283. */
  9284. int buildin_recovery(struct script_state *st)
  9285. {
  9286. struct map_session_data *sd, **all_sd;
  9287. int i = 0, users;
  9288. all_sd = map_getallusers(&users);
  9289. for (i = 0; i < users; i++)
  9290. {
  9291. sd = all_sd[i];
  9292. if(pc_isdead(sd))
  9293. status_revive(&sd->bl, 100, 100);
  9294. else
  9295. status_percent_heal(&sd->bl, 100, 100);
  9296. clif_displaymessage(sd->fd,"You have been recovered!");
  9297. }
  9298. return 0;
  9299. }
  9300. /*==========================================
  9301. * Get your pet info: getpetinfo(n)
  9302. * n -> 0:pet_id 1:pet_class 2:pet_name
  9303. 3:friendly 4:hungry
  9304. *------------------------------------------
  9305. */
  9306. int buildin_getpetinfo(struct script_state *st)
  9307. {
  9308. struct map_session_data *sd=script_rid2sd(st);
  9309. struct pet_data *pd;
  9310. int type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9311. if(sd && sd->status.pet_id && sd->pd){
  9312. pd = sd->pd;
  9313. switch(type){
  9314. case 0:
  9315. push_val(st->stack,C_INT,sd->status.pet_id);
  9316. break;
  9317. case 1:
  9318. push_val(st->stack,C_INT,pd->pet.class_);
  9319. break;
  9320. case 2:
  9321. if(pd->pet.name)
  9322. push_str(st->stack,C_CONSTSTR,pd->pet.name);
  9323. else
  9324. push_str(st->stack,C_CONSTSTR,"null");
  9325. break;
  9326. case 3:
  9327. push_val(st->stack,C_INT,pd->pet.intimate);
  9328. break;
  9329. case 4:
  9330. push_val(st->stack,C_INT,pd->pet.hungry);
  9331. break;
  9332. default:
  9333. push_val(st->stack,C_INT,0);
  9334. break;
  9335. }
  9336. }else{
  9337. push_val(st->stack,C_INT,0);
  9338. }
  9339. return 0;
  9340. }
  9341. /*==========================================
  9342. * Shows wether your inventory(and equips) contain
  9343. selected card or not.
  9344. checkequipedcard(4001);
  9345. *------------------------------------------
  9346. */
  9347. int buildin_checkequipedcard(struct script_state *st)
  9348. {
  9349. struct map_session_data *sd=script_rid2sd(st);
  9350. int n,i,c=0;
  9351. c=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9352. if(sd){
  9353. for(i=0;i<MAX_INVENTORY;i++){
  9354. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount){
  9355. for(n=0;n<MAX_SLOTS;n++){
  9356. if(sd->status.inventory[i].card[n]==c){
  9357. push_val(st->stack,C_INT,1);
  9358. return 0;
  9359. }
  9360. }
  9361. }
  9362. }
  9363. }
  9364. push_val(st->stack,C_INT,0);
  9365. return 0;
  9366. }
  9367. int buildin_jump_zero(struct script_state *st) {
  9368. int sel;
  9369. sel=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9370. if(!sel) {
  9371. int pos;
  9372. if( st->stack->stack_data[st->start+3].type!=C_POS ){
  9373. ShowError("script: jump_zero: not label !\n");
  9374. st->state=END;
  9375. return 0;
  9376. }
  9377. pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9378. st->pos=pos;
  9379. st->state=GOTO;
  9380. // printf("script: jump_zero: jumpto : %d\n",pos);
  9381. } else {
  9382. // printf("script: jump_zero: fail\n");
  9383. }
  9384. return 0;
  9385. }
  9386. int buildin_select(struct script_state *st)
  9387. {
  9388. char *buf;
  9389. int len,i,max = 1;
  9390. struct map_session_data *sd;
  9391. sd=script_rid2sd(st);
  9392. nullpo_retr(0, sd);
  9393. if(sd->state.menu_or_input==0){
  9394. st->state=RERUNLINE;
  9395. sd->state.menu_or_input=1;
  9396. for(i=st->start+2,len=16;i<st->end;i++){
  9397. conv_str(st,& (st->stack->stack_data[i]));
  9398. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9399. }
  9400. buf=(char *)aMalloc((len+1)*sizeof(char));
  9401. buf[0]=0;
  9402. for(i=st->start+2,len=0;i<st->end;i++){
  9403. strcat(buf,st->stack->stack_data[i].u.str);
  9404. strcat(buf,":");
  9405. }
  9406. for(i=0; (unsigned int)i < strlen(buf); i++){
  9407. if(buf[i] == ':')
  9408. max++;
  9409. }
  9410. sd->max_menu = max;
  9411. clif_scriptmenu(sd,st->oid,buf);
  9412. aFree(buf);
  9413. } else if(sd->npc_menu==0xff){
  9414. sd->state.menu_or_input=0;
  9415. st->state=END;
  9416. } else {
  9417. //Skip empty menu entries which weren't displayed on the client (Skotlex)
  9418. for(i=st->start+2;i< (st->start+2+sd->npc_menu) && sd->npc_menu < (st->end-st->start-2);i++) {
  9419. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  9420. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  9421. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  9422. }
  9423. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  9424. sd->state.menu_or_input=0;
  9425. push_val(st->stack,C_INT,sd->npc_menu);
  9426. }
  9427. return 0;
  9428. }
  9429. int buildin_prompt(struct script_state *st)
  9430. {
  9431. char *buf;
  9432. int len,i,max = 1;
  9433. struct map_session_data *sd;
  9434. sd=script_rid2sd(st);
  9435. nullpo_retr(0, sd);
  9436. if(sd->state.menu_or_input==0){
  9437. st->state=RERUNLINE;
  9438. sd->state.menu_or_input=1;
  9439. for(i=st->start+2,len=16;i<st->end;i++){
  9440. conv_str(st,& (st->stack->stack_data[i]));
  9441. len+=(int)strlen(st->stack->stack_data[i].u.str)+1;
  9442. }
  9443. buf=(char *)aMalloc((len+1)*sizeof(char));
  9444. buf[0]=0;
  9445. for(i=st->start+2,len=0;i<st->end;i++){
  9446. strcat(buf,st->stack->stack_data[i].u.str);
  9447. strcat(buf,":");
  9448. }
  9449. for(i=0; (unsigned int)i < strlen(buf); i++){
  9450. if(buf[i] == ':')
  9451. max++;
  9452. }
  9453. sd->max_menu = max;
  9454. clif_scriptmenu(sd,st->oid,buf);
  9455. aFree(buf);
  9456. } else {
  9457. if(sd->npc_menu != 0xff){
  9458. //Skip empty menu entries which weren't displayed on the client (Skotlex)
  9459. for(i=st->start+2;i< (st->start+2+sd->npc_menu) && sd->npc_menu < (st->end-st->start-2);i++) {
  9460. conv_str(st,& (st->stack->stack_data[i])); // we should convert variables to strings before access it [jA1983] [EoE]
  9461. if((int)strlen(st->stack->stack_data[i].u.str) < 1)
  9462. sd->npc_menu++; //Empty selection which wasn't displayed on the client.
  9463. }
  9464. }
  9465. pc_setreg(sd,add_str("@menu"),sd->npc_menu);
  9466. sd->state.menu_or_input=0;
  9467. push_val(st->stack,C_INT,sd->npc_menu);
  9468. }
  9469. return 0;
  9470. }
  9471. /*==========================================
  9472. * GetMapMobs
  9473. returns mob counts on a set map:
  9474. e.g. GetMapMobs("prontera.gat")
  9475. use "this" - for player's map
  9476. *------------------------------------------
  9477. */
  9478. int buildin_getmapmobs(struct script_state *st)
  9479. {
  9480. char *str=NULL;
  9481. int m=-1,bx,by,i;
  9482. int count=0,c;
  9483. struct block_list *bl;
  9484. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9485. if(strcmp(str,"this")==0){
  9486. struct map_session_data *sd=script_rid2sd(st);
  9487. if(sd)
  9488. m=sd->bl.m;
  9489. else{
  9490. push_val(st->stack,C_INT,-1);
  9491. return 0;
  9492. }
  9493. }else
  9494. m=map_mapname2mapid(str);
  9495. if(m < 0){
  9496. push_val(st->stack,C_INT,-1);
  9497. return 0;
  9498. }
  9499. for(by=0;by<=(map[m].ys-1)/BLOCK_SIZE;by++){
  9500. for(bx=0;bx<=(map[m].xs-1)/BLOCK_SIZE;bx++){
  9501. bl = map[m].block_mob[bx+by*map[m].bxs];
  9502. c = map[m].block_mob_count[bx+by*map[m].bxs];
  9503. for(i=0;i<c && bl;i++,bl=bl->next){
  9504. if(bl->x>=0 && bl->x<=map[m].xs-1 && bl->y>=0 && bl->y<=map[m].ys-1)
  9505. count++;
  9506. }
  9507. }
  9508. }
  9509. push_val(st->stack,C_INT,count);
  9510. return 0;
  9511. }
  9512. /*==========================================
  9513. * movenpc [MouseJstr]
  9514. *------------------------------------------
  9515. */
  9516. int buildin_movenpc(struct script_state *st)
  9517. {
  9518. TBL_NPC *nd = NULL;
  9519. char *npc;
  9520. int x,y;
  9521. short m;
  9522. npc = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9523. x = conv_num(st,& (st->stack->stack_data[st->start+3]));
  9524. y = conv_num(st,& (st->stack->stack_data[st->start+4]));
  9525. if ((nd = npc_name2id(npc)) == NULL)
  9526. return -1;
  9527. if ((m=nd->bl.m) < 0 || nd->bl.prev == NULL)
  9528. return -1; //Not on a map.
  9529. if (x < 0) x = 0;
  9530. else if (x >= map[m].xs) x = map[m].xs-1;
  9531. if (y < 0) y = 0;
  9532. else if (y >= map[m].ys) y = map[m].ys-1;
  9533. map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9534. map_moveblock(&nd->bl, x, y, gettick());
  9535. map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl);
  9536. return 0;
  9537. }
  9538. /*==========================================
  9539. * message [MouseJstr]
  9540. *------------------------------------------
  9541. */
  9542. int buildin_message(struct script_state *st)
  9543. {
  9544. struct map_session_data *sd;
  9545. char *msg,*player;
  9546. struct map_session_data *pl_sd = NULL;
  9547. sd = script_rid2sd(st);
  9548. player = conv_str(st,& (st->stack->stack_data[st->start+2]));
  9549. msg = conv_str(st,& (st->stack->stack_data[st->start+3]));
  9550. if((pl_sd=map_nick2sd((char *) player)) == NULL)
  9551. return 0;
  9552. clif_displaymessage(pl_sd->fd, msg);
  9553. return 0;
  9554. }
  9555. /*==========================================
  9556. * npctalk (sends message to surrounding
  9557. * area) [Valaris]
  9558. *------------------------------------------
  9559. */
  9560. int buildin_npctalk(struct script_state *st)
  9561. {
  9562. char *str;
  9563. char message[255];
  9564. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9565. str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  9566. if(nd) {
  9567. memcpy(message, nd->name, NAME_LENGTH);
  9568. strcat(message," : ");
  9569. strncat(message,str, 254); //Prevent overflow possibility. [Skotlex]
  9570. clif_message(&(nd->bl), message);
  9571. }
  9572. return 0;
  9573. }
  9574. /*==========================================
  9575. * hasitems (checks to see if player has any
  9576. * items on them, if so will return a 1)
  9577. * [Valaris]
  9578. *------------------------------------------
  9579. */
  9580. int buildin_hasitems(struct script_state *st)
  9581. {
  9582. int i;
  9583. struct map_session_data *sd;
  9584. sd=script_rid2sd(st);
  9585. for(i=0; i<MAX_INVENTORY; i++) {
  9586. if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) {
  9587. push_val(st->stack,C_INT,1);
  9588. return 0;
  9589. }
  9590. }
  9591. push_val(st->stack,C_INT,0);
  9592. return 0;
  9593. }
  9594. // change npc walkspeed [Valaris]
  9595. int buildin_npcspeed(struct script_state *st)
  9596. {
  9597. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9598. int x=0;
  9599. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9600. if(nd) {
  9601. nd->speed=x;
  9602. }
  9603. return 0;
  9604. }
  9605. // make an npc walk to a position [Valaris]
  9606. int buildin_npcwalkto(struct script_state *st)
  9607. {
  9608. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9609. int x=0,y=0;
  9610. x=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9611. y=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9612. if(nd) {
  9613. unit_walktoxy(&nd->bl,x,y,0);
  9614. }
  9615. return 0;
  9616. }
  9617. // stop an npc's movement [Valaris]
  9618. int buildin_npcstop(struct script_state *st)
  9619. {
  9620. struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
  9621. if(nd) {
  9622. unit_stop_walking(&nd->bl,1);
  9623. }
  9624. return 0;
  9625. }
  9626. /*==========================================
  9627. * getlook char info. getlook(arg)
  9628. *------------------------------------------
  9629. */
  9630. int buildin_getlook(struct script_state *st){
  9631. int type,val;
  9632. struct map_session_data *sd;
  9633. sd=script_rid2sd(st);
  9634. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9635. val=-1;
  9636. switch(type){
  9637. case LOOK_HAIR: //1
  9638. val=sd->status.hair;
  9639. break;
  9640. case LOOK_WEAPON: //2
  9641. val=sd->status.weapon;
  9642. break;
  9643. case LOOK_HEAD_BOTTOM: //3
  9644. val=sd->status.head_bottom;
  9645. break;
  9646. case LOOK_HEAD_TOP: //4
  9647. val=sd->status.head_top;
  9648. break;
  9649. case LOOK_HEAD_MID: //5
  9650. val=sd->status.head_mid;
  9651. break;
  9652. case LOOK_HAIR_COLOR: //6
  9653. val=sd->status.hair_color;
  9654. break;
  9655. case LOOK_CLOTHES_COLOR: //7
  9656. val=sd->status.clothes_color;
  9657. break;
  9658. case LOOK_SHIELD: //8
  9659. val=sd->status.shield;
  9660. break;
  9661. case LOOK_SHOES: //9
  9662. break;
  9663. }
  9664. push_val(st->stack,C_INT,val);
  9665. return 0;
  9666. }
  9667. /*==========================================
  9668. * get char save point. argument: 0- map name, 1- x, 2- y
  9669. *------------------------------------------
  9670. */
  9671. int buildin_getsavepoint(struct script_state *st)
  9672. {
  9673. int x,y,type;
  9674. char *mapname;
  9675. struct map_session_data *sd;
  9676. sd=script_rid2sd(st);
  9677. type=conv_num(st,& (st->stack->stack_data[st->start+2]));
  9678. x=sd->status.save_point.x;
  9679. y=sd->status.save_point.y;
  9680. switch(type){
  9681. case 0:
  9682. mapname=(char *) aMallocA((MAP_NAME_LENGTH+1)*sizeof(char));
  9683. memcpy(mapname, mapindex_id2name(sd->status.save_point.map), MAP_NAME_LENGTH);
  9684. mapname[MAP_NAME_LENGTH]='\0';
  9685. push_str(st->stack,C_STR,mapname);
  9686. break;
  9687. case 1:
  9688. push_val(st->stack,C_INT,x);
  9689. break;
  9690. case 2:
  9691. push_val(st->stack,C_INT,y);
  9692. break;
  9693. default:
  9694. push_val(st->stack,C_INT,0);
  9695. break;
  9696. }
  9697. return 0;
  9698. }
  9699. /*==========================================
  9700. * Get position for char/npc/pet/mob objects. Added by Lorky
  9701. *
  9702. * int getMapXY(MapName$,MaxX,MapY,type,[CharName$]);
  9703. * where type:
  9704. * MapName$ - String variable for output map name
  9705. * MapX - Integer variable for output coord X
  9706. * MapY - Integer variable for output coord Y
  9707. * type - type of object
  9708. * 0 - Character coord
  9709. * 1 - NPC coord
  9710. * 2 - Pet coord
  9711. * 3 - Mob coord (not released)
  9712. * 4 - Homun coord
  9713. * CharName$ - Name object. If miss or "this" the current object
  9714. *
  9715. * Return:
  9716. * 0 - success
  9717. * -1 - some error, MapName$,MapX,MapY contains unknown value.
  9718. *------------------------------------------
  9719. */
  9720. int buildin_getmapxy(struct script_state *st){
  9721. struct block_list *bl = NULL;
  9722. struct map_session_data *sd=NULL;
  9723. int num;
  9724. char *name;
  9725. char prefix;
  9726. int x,y,type;
  9727. char mapname[MAP_NAME_LENGTH+1];
  9728. malloc_set(mapname, 0, sizeof(mapname));
  9729. if( st->stack->stack_data[st->start+2].type!=C_NAME ){
  9730. ShowWarning("script: buildin_getmapxy: not mapname variable\n");
  9731. push_val(st->stack,C_INT,-1);
  9732. return 1;
  9733. }
  9734. if( st->stack->stack_data[st->start+3].type!=C_NAME ){
  9735. ShowWarning("script: buildin_getmapxy: not mapx variable\n");
  9736. push_val(st->stack,C_INT,-1);
  9737. return 1;
  9738. }
  9739. if( st->stack->stack_data[st->start+4].type!=C_NAME ){
  9740. ShowWarning("script: buildin_getmapxy: not mapy variable\n");
  9741. push_val(st->stack,C_INT,-1);
  9742. return 1;
  9743. }
  9744. //??????????? >>> Possible needly check function parameters on C_STR,C_INT,C_INT <<< ???????????//
  9745. type=conv_num(st,& (st->stack->stack_data[st->start+5]));
  9746. switch (type){
  9747. case 0: //Get Character Position
  9748. if( st->end>st->start+6 )
  9749. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9750. else
  9751. sd=script_rid2sd(st);
  9752. if (sd)
  9753. bl = &sd->bl;
  9754. break;
  9755. case 1: //Get NPC Position
  9756. if( st->end > st->start+6 )
  9757. {
  9758. struct npc_data *nd;
  9759. nd=npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9760. if (nd)
  9761. bl = &nd->bl;
  9762. } else //In case the origin is not an npc?
  9763. bl=map_id2bl(st->oid);
  9764. break;
  9765. case 2: //Get Pet Position
  9766. if(st->end>st->start+6)
  9767. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9768. else
  9769. sd=script_rid2sd(st);
  9770. if (sd && sd->pd)
  9771. bl = &sd->pd->bl;
  9772. break;
  9773. case 3: //Get Mob Position
  9774. break; //Not supported?
  9775. case 4: //Get Homun Position
  9776. if(st->end>st->start+6)
  9777. sd=map_nick2sd(conv_str(st,& (st->stack->stack_data[st->start+6])));
  9778. else
  9779. sd=script_rid2sd(st);
  9780. if (sd && sd->hd)
  9781. bl = &sd->hd->bl;
  9782. break;
  9783. }
  9784. if (!bl) { //No object found.
  9785. push_val(st->stack,C_INT,-1);
  9786. return 0;
  9787. }
  9788. x= bl->x;
  9789. y= bl->y;
  9790. memcpy(mapname, map[bl->m].name, MAP_NAME_LENGTH);
  9791. //Set MapName$
  9792. num=st->stack->stack_data[st->start+2].u.num;
  9793. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9794. prefix=*name;
  9795. if(not_server_variable(prefix))
  9796. sd=script_rid2sd(st);
  9797. else
  9798. sd=NULL;
  9799. set_reg(st,sd,num,name,(void*)mapname,st->stack->stack_data[st->start+2].ref);
  9800. //Set MapX
  9801. num=st->stack->stack_data[st->start+3].u.num;
  9802. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9803. prefix=*name;
  9804. if(not_server_variable(prefix))
  9805. sd=script_rid2sd(st);
  9806. else
  9807. sd=NULL;
  9808. set_reg(st,sd,num,name,(void*)x,st->stack->stack_data[st->start+3].ref);
  9809. //Set MapY
  9810. num=st->stack->stack_data[st->start+4].u.num;
  9811. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  9812. prefix=*name;
  9813. if(not_server_variable(prefix))
  9814. sd=script_rid2sd(st);
  9815. else
  9816. sd=NULL;
  9817. set_reg(st,sd,num,name,(void*)y,st->stack->stack_data[st->start+4].ref);
  9818. //Return Success value
  9819. push_val(st->stack,C_INT,0);
  9820. return 0;
  9821. }
  9822. /*==========================================
  9823. * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
  9824. *------------------------------------------
  9825. */
  9826. int buildin_logmes(struct script_state *st)
  9827. {
  9828. if (log_config.npc <= 0 ) return 0;
  9829. conv_str(st,& (st->stack->stack_data[st->start+2]));
  9830. log_npc(script_rid2sd(st),st->stack->stack_data[st->start+2].u.str);
  9831. return 0;
  9832. }
  9833. int buildin_summon(struct script_state *st)
  9834. {
  9835. int _class, timeout=0;
  9836. char *str,*event="";
  9837. struct map_session_data *sd;
  9838. struct mob_data *md;
  9839. int tick = gettick();
  9840. sd=script_rid2sd(st);
  9841. if (!sd) return 0;
  9842. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  9843. _class=conv_num(st,& (st->stack->stack_data[st->start+3]));
  9844. if( st->end>st->start+4 )
  9845. timeout=conv_num(st,& (st->stack->stack_data[st->start+4]));
  9846. if( st->end>st->start+5 ){
  9847. event=conv_str(st,& (st->stack->stack_data[st->start+5]));
  9848. check_event(st, event);
  9849. }
  9850. clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
  9851. md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event);
  9852. if (md) {
  9853. md->master_id=sd->bl.id;
  9854. md->special_state.ai=1;
  9855. md->deletetimer = add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0);
  9856. mob_spawn (md); //Now it is ready for spawning.
  9857. clif_misceffect2(&md->bl,344);
  9858. sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
  9859. }
  9860. return 0;
  9861. }
  9862. /*==========================================
  9863. * Checks whether it is daytime/nighttime
  9864. *------------------------------------------
  9865. */
  9866. int buildin_isnight(struct script_state *st)
  9867. {
  9868. push_val(st->stack,C_INT, (night_flag == 1));
  9869. return 0;
  9870. }
  9871. int buildin_isday(struct script_state *st)
  9872. {
  9873. push_val(st->stack,C_INT, (night_flag == 0));
  9874. return 0;
  9875. }
  9876. /*================================================
  9877. * Check whether another item/card has been
  9878. * equipped - used for 2/15's cards patch [celest]
  9879. *------------------------------------------------
  9880. */
  9881. // leave this here, just in case
  9882. #if 0
  9883. int buildin_isequipped(struct script_state *st)
  9884. {
  9885. struct map_session_data *sd;
  9886. int i, j, k, id = 1;
  9887. int ret = -1;
  9888. sd = script_rid2sd(st);
  9889. for (i=0; id!=0; i++) {
  9890. int flag = 0;
  9891. FETCH (i+2, id) else id = 0;
  9892. if (id <= 0)
  9893. continue;
  9894. for (j=0; j<EQI_MAX; j++) {
  9895. int index;
  9896. index = sd->equip_index[j];
  9897. if(index < 0) continue;
  9898. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9899. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9900. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9901. if(!sd->inventory_data[index])
  9902. continue;
  9903. if(itemdb_type(id) != IT_CARD) { //Non card
  9904. if (sd->inventory_data[index]->nameid != id)
  9905. continue;
  9906. flag = 1;
  9907. break;
  9908. } else { //Card
  9909. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9910. continue;
  9911. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9912. if (sd->status.inventory[index].card[k] == id)
  9913. {
  9914. flag = 1;
  9915. break;
  9916. }
  9917. }
  9918. }
  9919. if (flag) break;
  9920. }
  9921. if (ret == -1)
  9922. ret = flag;
  9923. else
  9924. ret &= flag;
  9925. if (!ret) break;
  9926. }
  9927. push_val(st->stack,C_INT,ret);
  9928. return 0;
  9929. }
  9930. #endif
  9931. /*================================================
  9932. * Check how many items/cards in the list are
  9933. * equipped - used for 2/15's cards patch [celest]
  9934. *------------------------------------------------
  9935. */
  9936. int buildin_isequippedcnt(struct script_state *st)
  9937. {
  9938. struct map_session_data *sd;
  9939. int i, j, k, id = 1;
  9940. int ret = 0;
  9941. sd = script_rid2sd(st);
  9942. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9943. push_val(st->stack,C_INT,0);
  9944. return 0;
  9945. }
  9946. for (i=0; id!=0; i++) {
  9947. FETCH (i+2, id) else id = 0;
  9948. if (id <= 0)
  9949. continue;
  9950. for (j=0; j<EQI_MAX; j++) {
  9951. int index;
  9952. index = sd->equip_index[j];
  9953. if(index < 0) continue;
  9954. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  9955. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  9956. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  9957. if(!sd->inventory_data[index])
  9958. continue;
  9959. if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
  9960. if (sd->inventory_data[index]->nameid == id)
  9961. ret+= sd->status.inventory[index].amount;
  9962. } else { //Count cards.
  9963. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  9964. continue; //No cards
  9965. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  9966. if (sd->status.inventory[index].card[k] == id)
  9967. ret++; //[Lupus]
  9968. }
  9969. }
  9970. }
  9971. }
  9972. push_val(st->stack,C_INT,ret);
  9973. return 0;
  9974. }
  9975. /*================================================
  9976. * Check whether another card has been
  9977. * equipped - used for 2/15's cards patch [celest]
  9978. * -- Items checked cannot be reused in another
  9979. * card set to prevent exploits
  9980. *------------------------------------------------
  9981. */
  9982. int buildin_isequipped(struct script_state *st)
  9983. {
  9984. struct map_session_data *sd;
  9985. int i, j, k, id = 1;
  9986. int index, flag;
  9987. int ret = -1;
  9988. //Original hash to reverse it when full check fails.
  9989. unsigned int setitem_hash = 0, setitem_hash2 = 0;
  9990. sd = script_rid2sd(st);
  9991. if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
  9992. push_val(st->stack,C_INT,0);
  9993. return 0;
  9994. }
  9995. setitem_hash = sd->setitem_hash;
  9996. setitem_hash2 = sd->setitem_hash2;
  9997. for (i=0; id!=0; i++)
  9998. {
  9999. FETCH (i+2, id) else id = 0;
  10000. if (id <= 0)
  10001. continue;
  10002. flag = 0;
  10003. for (j=0; j<EQI_MAX; j++)
  10004. {
  10005. index = sd->equip_index[j];
  10006. if(index < 0) continue;
  10007. if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
  10008. if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
  10009. if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
  10010. if(!sd->inventory_data[index])
  10011. continue;
  10012. if (itemdb_type(id) != IT_CARD) {
  10013. if (sd->inventory_data[index]->nameid != id)
  10014. continue;
  10015. flag = 1;
  10016. break;
  10017. } else { //Cards
  10018. if (sd->inventory_data[index]->slot == 0 ||
  10019. itemdb_isspecial(sd->status.inventory[index].card[0]))
  10020. continue;
  10021. for (k = 0; k < sd->inventory_data[index]->slot; k++)
  10022. { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
  10023. unsigned int hash = 0;
  10024. if (sd->status.inventory[index].card[k] != id)
  10025. continue;
  10026. hash = 1<<((j<5?j:j-5)*4 + k);
  10027. // check if card is already used by another set
  10028. if ((j<5?sd->setitem_hash:sd->setitem_hash2) & hash)
  10029. continue;
  10030. // We have found a match
  10031. flag = 1;
  10032. // Set hash so this card cannot be used by another
  10033. if (j<5)
  10034. sd->setitem_hash |= hash;
  10035. else
  10036. sd->setitem_hash2 |= hash;
  10037. break;
  10038. }
  10039. }
  10040. if (flag) break; //Card found
  10041. }
  10042. if (ret == -1)
  10043. ret = flag;
  10044. else
  10045. ret &= flag;
  10046. if (!ret) break;
  10047. }
  10048. if (!ret)
  10049. { //When check fails, restore original hash values. [Skotlex]
  10050. sd->setitem_hash = setitem_hash;
  10051. sd->setitem_hash2 = setitem_hash2;
  10052. }
  10053. push_val(st->stack,C_INT,ret);
  10054. return 0;
  10055. }
  10056. /*================================================
  10057. * Check how many given inserted cards in the CURRENT
  10058. * weapon - used for 2/15's cards patch [Lupus]
  10059. *------------------------------------------------
  10060. */
  10061. int buildin_cardscnt(struct script_state *st)
  10062. {
  10063. struct map_session_data *sd;
  10064. int i, k, id = 1;
  10065. int ret = 0;
  10066. int index;
  10067. sd = script_rid2sd(st);
  10068. for (i=0; id!=0; i++) {
  10069. FETCH (i+2, id) else id = 0;
  10070. if (id <= 0)
  10071. continue;
  10072. index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
  10073. if(index < 0) continue;
  10074. if(!sd->inventory_data[index])
  10075. continue;
  10076. if(itemdb_type(id) != IT_CARD) {
  10077. if (sd->inventory_data[index]->nameid == id)
  10078. ret+= sd->status.inventory[index].amount;
  10079. } else {
  10080. if (itemdb_isspecial(sd->status.inventory[index].card[0]))
  10081. continue;
  10082. for(k=0; k<sd->inventory_data[index]->slot; k++) {
  10083. if (sd->status.inventory[index].card[k] == id)
  10084. ret++;
  10085. }
  10086. }
  10087. }
  10088. push_val(st->stack,C_INT,ret);
  10089. // push_val(st->stack,C_INT,current_equip_item_index);
  10090. return 0;
  10091. }
  10092. /*=======================================================
  10093. * Returns the refined number of the current item, or an
  10094. * item with inventory index specified
  10095. *-------------------------------------------------------
  10096. */
  10097. int buildin_getrefine(struct script_state *st)
  10098. {
  10099. struct map_session_data *sd;
  10100. if ((sd = script_rid2sd(st))!= NULL)
  10101. push_val(st->stack, C_INT, sd->status.inventory[current_equip_item_index].refine);
  10102. else
  10103. push_val(st->stack,C_INT,0);
  10104. return 0;
  10105. }
  10106. /*=======================================================
  10107. * Allows 2 Parents to adopt a character as a Baby
  10108. *-------------------------------------------------------
  10109. */
  10110. int buildin_adopt(struct script_state *st)
  10111. {
  10112. int ret;
  10113. char *parent1 = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10114. char *parent2 = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10115. char *child = conv_str(st,& (st->stack->stack_data[st->start+4]));
  10116. struct map_session_data *p1_sd = map_nick2sd(parent1);
  10117. struct map_session_data *p2_sd = map_nick2sd(parent2);
  10118. struct map_session_data *c_sd = map_nick2sd(child);
  10119. if (!p1_sd || !p2_sd || !c_sd ||
  10120. p1_sd->status.base_level < 70 ||
  10121. p2_sd->status.base_level < 70)
  10122. return 0;
  10123. ret = pc_adoption(p1_sd, p2_sd, c_sd);
  10124. push_val(st->stack, C_INT, ret);
  10125. return 0;
  10126. }
  10127. /*=======================================================
  10128. * Day/Night controls
  10129. *-------------------------------------------------------
  10130. */
  10131. int buildin_night(struct script_state *st)
  10132. {
  10133. if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
  10134. return 0;
  10135. }
  10136. int buildin_day(struct script_state *st)
  10137. {
  10138. if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
  10139. return 0;
  10140. }
  10141. //=======================================================
  10142. // Unequip [Spectre]
  10143. //-------------------------------------------------------
  10144. int buildin_unequip(struct script_state *st)
  10145. {
  10146. int i;
  10147. size_t num;
  10148. struct map_session_data *sd;
  10149. num = conv_num(st,& (st->stack->stack_data[st->start+2])) - 1;
  10150. sd=script_rid2sd(st);
  10151. if(sd!=NULL && num<10)
  10152. {
  10153. i=pc_checkequip(sd,equip[num]);
  10154. pc_unequipitem(sd,i,2);
  10155. return 0;
  10156. }
  10157. return 0;
  10158. }
  10159. int buildin_equip(struct script_state *st)
  10160. {
  10161. int nameid=0,i;
  10162. struct map_session_data *sd;
  10163. struct item_data *item_data;
  10164. sd = script_rid2sd(st);
  10165. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10166. if((item_data = itemdb_exists(nameid)) == NULL)
  10167. {
  10168. if(battle_config.error_log)
  10169. ShowError("wrong item ID : equipitem(%i)\n",nameid);
  10170. return 1;
  10171. }
  10172. for(i=0;i<MAX_INVENTORY && sd->status.inventory[i].nameid!=nameid;i++);
  10173. if(i==MAX_INVENTORY) return 0;
  10174. pc_equipitem(sd,i,item_data->equip);
  10175. return 0;
  10176. }
  10177. int buildin_autoequip(struct script_state *st){
  10178. int nameid, flag;
  10179. struct item_data *item_data;
  10180. nameid=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10181. flag=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10182. if(nameid>=500 && (item_data = itemdb_search(nameid)) != NULL){
  10183. item_data->flag.autoequip = flag>0?1:0;
  10184. }
  10185. return 0;
  10186. }
  10187. int buildin_setbattleflag(struct script_state *st){
  10188. char *flag, *value;
  10189. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10190. value = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10191. if (battle_set_value(flag, value) == 0)
  10192. ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag);
  10193. else
  10194. ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value);
  10195. return 0;
  10196. }
  10197. int buildin_getbattleflag(struct script_state *st){
  10198. char *flag;
  10199. flag = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10200. push_val(st->stack,C_INT,battle_get_value(flag));
  10201. return 0;
  10202. }
  10203. //=======================================================
  10204. // strlen [Valaris]
  10205. //-------------------------------------------------------
  10206. int buildin_getstrlen(struct script_state *st) {
  10207. char *str = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10208. int len = (str) ? (int)strlen(str) : 0;
  10209. push_val(st->stack,C_INT,len);
  10210. return 0;
  10211. }
  10212. //=======================================================
  10213. // isalpha [Valaris]
  10214. //-------------------------------------------------------
  10215. int buildin_charisalpha(struct script_state *st) {
  10216. char *str=conv_str(st,& (st->stack->stack_data[st->start+2]));
  10217. int pos=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10218. int val = ( str && pos>0 && (unsigned int)pos<strlen(str) ) ? ISALPHA( str[pos] ) : 0;
  10219. push_val(st->stack,C_INT,val);
  10220. return 0;
  10221. }
  10222. // [Lance]
  10223. int buildin_fakenpcname(struct script_state *st)
  10224. {
  10225. char *name;
  10226. char *newname;
  10227. int look;
  10228. name = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10229. newname = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10230. look = conv_num(st,& (st->stack->stack_data[st->start+4]));
  10231. if(look > 32767 || look < -32768) {
  10232. ShowError("buildin_fakenpcname: Invalid look value %d\n",look);
  10233. return 1; // Safety measure to prevent runtime errors
  10234. }
  10235. npc_changename(name,newname,(short)look);
  10236. return 0;
  10237. }
  10238. int buildin_atoi(struct script_state *st) {
  10239. char *value;
  10240. value = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10241. push_val(st->stack, C_INT, atoi(value));
  10242. return 0;
  10243. }
  10244. //-----------------------------------------------------------------------//
  10245. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA START //
  10246. //-----------------------------------------------------------------------//
  10247. int buildin_compare(struct script_state *st) {
  10248. char *message;
  10249. char *cmpstring;
  10250. int j;
  10251. message = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10252. cmpstring = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10253. for (j = 0; message[j]; j++)
  10254. message[j] = TOLOWER(message[j]);
  10255. for (j = 0; cmpstring[j]; j++)
  10256. cmpstring[j] = TOLOWER(cmpstring[j]);
  10257. push_val(st->stack,C_INT,(strstr(message,cmpstring) != NULL));
  10258. return 0;
  10259. }
  10260. //-----------------------------------------------------------------------//
  10261. // BRING STRSTR TO SCRIPTING ENGINE - LORDALFA END //
  10262. //-----------------------------------------------------------------------//
  10263. // [zBuffer] List of mathematics commands --->
  10264. int buildin_sqrt(struct script_state *st){
  10265. double i, a;
  10266. i = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10267. a = sqrt(i);
  10268. push_val(st->stack, C_INT, (int)a);
  10269. return 0;
  10270. }
  10271. int buildin_pow(struct script_state *st){
  10272. double i, a, b;
  10273. a = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10274. b = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10275. i = pow(a,b);
  10276. push_val(st->stack, C_INT, (int)i);
  10277. return 0;
  10278. }
  10279. int buildin_distance(struct script_state *st){
  10280. int x0, y0, x1, y1;
  10281. x0 = conv_num(st, &(st->stack->stack_data[st->start+2]));
  10282. y0 = conv_num(st, &(st->stack->stack_data[st->start+3]));
  10283. x1 = conv_num(st, &(st->stack->stack_data[st->start+4]));
  10284. y1 = conv_num(st, &(st->stack->stack_data[st->start+5]));
  10285. push_val(st->stack, C_INT, distance(x0-x1, y0-y1));
  10286. return 0;
  10287. }
  10288. int buildin_checkcell(struct script_state *st){
  10289. int m;
  10290. char *map = conv_str(st, &(st->stack->stack_data[st->start+2]));
  10291. m = mapindex_name2id(map);
  10292. if(m){
  10293. push_val(st->stack, C_INT, map_getcell(m, conv_num(st, &(st->stack->stack_data[st->start+3])), conv_num(st, &(st->stack->stack_data[st->start+4])),conv_num(st, &(st->stack->stack_data[st->start+5]))));
  10294. } else {
  10295. push_val(st->stack, C_INT, 0);
  10296. }
  10297. return 0;
  10298. }
  10299. // <--- [zBuffer] List of mathematics commands
  10300. // [zBuffer] List of dynamic var commands --->
  10301. void setd_sub(struct script_state *st, struct map_session_data *sd, char *varname, int elem, void *value, struct linkdb_node **ref)
  10302. {
  10303. set_reg(st, sd, add_str(varname)+(elem<<24), varname, value, ref);
  10304. return;
  10305. }
  10306. int buildin_setd(struct script_state *st)
  10307. {
  10308. struct map_session_data *sd=NULL;
  10309. char varname[100], *buffer;
  10310. char *value;
  10311. int elem;
  10312. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10313. value = conv_str(st, & (st->stack->stack_data[st->start+3]));
  10314. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10315. elem = 0;
  10316. if(st->rid)
  10317. sd = script_rid2sd(st);
  10318. if(varname[strlen(varname)-1] != '$') {
  10319. setd_sub(st,sd, varname, elem, (void *)atoi(value),NULL);
  10320. } else {
  10321. setd_sub(st,sd, varname, elem, (void *)value,NULL);
  10322. }
  10323. return 0;
  10324. }
  10325. int buildin_query_sql(struct script_state *st) {
  10326. #ifndef TXT_ONLY
  10327. char *name = NULL, *query;
  10328. int num, i = 0,j, nb_rows;
  10329. struct { char * dst_var_name; char type; } row[32];
  10330. struct map_session_data *sd = (st->rid)? script_rid2sd(st) : NULL;
  10331. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10332. strcpy(tmp_sql, query);
  10333. if(mysql_query(&mmysql_handle,tmp_sql)){
  10334. ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
  10335. ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
  10336. push_val(st->stack,C_INT,0);
  10337. return 1;
  10338. }
  10339. // If some data was returned
  10340. if((sql_res = mysql_store_result(&mmysql_handle))){
  10341. // Count the number of rows to store
  10342. nb_rows = mysql_num_fields(sql_res);
  10343. // Can't store more row than variable
  10344. if (nb_rows > st->end - (st->start+3))
  10345. nb_rows = st->end - (st->start+3);
  10346. if (!nb_rows)
  10347. {
  10348. push_val(st->stack,C_INT,0);
  10349. return 0; // Nothing to store
  10350. }
  10351. if (nb_rows > 32)
  10352. {
  10353. ShowWarning("buildin_query_sql: too many rows!\n");
  10354. push_val(st->stack,C_INT,0);
  10355. return 1;
  10356. }
  10357. malloc_set(row, 0, sizeof(row));
  10358. // Verify argument types
  10359. for(j=0; j < nb_rows; j++)
  10360. {
  10361. if(st->stack->stack_data[st->start+3+j].type != C_NAME){
  10362. ShowWarning("buildin_query_sql: Parameter %d is not a variable!\n", j);
  10363. push_val(st->stack,C_INT,0);
  10364. return 0;
  10365. } else {
  10366. // Store type of variable (string = 0/int = 1)
  10367. num=st->stack->stack_data[st->start+3+j].u.num;
  10368. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10369. if(name[strlen(name)-1] != '$') {
  10370. row[j].type = 1;
  10371. }
  10372. row[j].dst_var_name = name;
  10373. }
  10374. }
  10375. // Store data
  10376. while(i<128 && (sql_row = mysql_fetch_row(sql_res))){
  10377. for(j=0; j < nb_rows; j++)
  10378. {
  10379. if (row[j].type == 1)
  10380. setd_sub(st,sd, row[j].dst_var_name, i, (void *)atoi(sql_row[j]),st->stack->stack_data[st->start+3+j].ref);
  10381. else
  10382. setd_sub(st,sd, row[j].dst_var_name, i, (void *)sql_row[j],st->stack->stack_data[st->start+3+j].ref);
  10383. }
  10384. i++;
  10385. }
  10386. // Free data
  10387. mysql_free_result(sql_res);
  10388. }
  10389. push_val(st->stack, C_INT, i);
  10390. #else
  10391. //for TXT version, we always return -1
  10392. push_val(st->stack, C_INT, -1);
  10393. #endif
  10394. return 0;
  10395. }
  10396. //Allows escaping of a given string.
  10397. int buildin_escape_sql(struct script_state *st) {
  10398. char *t_query, *query;
  10399. query = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10400. t_query = aMallocA((strlen(query)*2+1)*sizeof(char));
  10401. jstrescapecpy(t_query,query);
  10402. push_str(st->stack,C_STR,t_query);
  10403. return 0;
  10404. }
  10405. int buildin_getd (struct script_state *st)
  10406. {
  10407. char varname[100], *buffer;
  10408. //struct script_data dat;
  10409. int elem;
  10410. buffer = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10411. if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
  10412. elem = 0;
  10413. /*dat.type=C_NAME;
  10414. dat.u.num=add_str(varname)+(elem<<24);
  10415. get_val(st,&dat);
  10416. if(dat.type == C_INT)
  10417. push_val(st->stack, C_INT, dat.u.num);
  10418. else if(dat.type == C_CONSTSTR){
  10419. buffer = aStrdup((char *)dat.u.str);
  10420. // dat.u.str holds the actual pointer to the data, must be duplicated.
  10421. // It will be freed later. Tested.
  10422. push_str(st->stack, C_STR, buffer);
  10423. }*/
  10424. // Push the 'pointer' so it's more flexible [Lance]
  10425. push_val(st->stack,C_NAME,
  10426. (elem<<24) | add_str(varname));
  10427. return 0;
  10428. }
  10429. // <--- [zBuffer] List of dynamic var commands
  10430. // Pet stat [Lance]
  10431. int buildin_petstat(struct script_state *st){
  10432. struct map_session_data *sd = NULL;
  10433. struct pet_data *pd;
  10434. char *tmp;
  10435. int flag = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10436. sd = script_rid2sd(st);
  10437. if(!sd || !sd->status.pet_id || !sd->pd){
  10438. if(flag == 2)
  10439. push_str(st->stack, C_CONSTSTR, "");
  10440. else
  10441. push_val(st->stack, C_INT, 0);
  10442. return 0;
  10443. }
  10444. pd = sd->pd;
  10445. switch(flag){
  10446. case 1:
  10447. push_val(st->stack, C_INT, (int)pd->pet.class_);
  10448. break;
  10449. case 2:
  10450. tmp = aStrdup(pd->pet.name);
  10451. push_str(st->stack, C_STR, tmp);
  10452. break;
  10453. case 3:
  10454. push_val(st->stack, C_INT, (int)pd->pet.level);
  10455. break;
  10456. case 4:
  10457. push_val(st->stack, C_INT, (int)pd->pet.hungry);
  10458. break;
  10459. case 5:
  10460. push_val(st->stack, C_INT, (int)pd->pet.intimate);
  10461. break;
  10462. default:
  10463. push_val(st->stack, C_INT, 0);
  10464. break;
  10465. }
  10466. return 0;
  10467. }
  10468. int buildin_callshop(struct script_state *st)
  10469. {
  10470. struct map_session_data *sd = NULL;
  10471. struct npc_data *nd;
  10472. char *shopname;
  10473. int flag = 0;
  10474. sd = script_rid2sd(st);
  10475. if (!sd) {
  10476. push_val(st->stack,C_INT,0);
  10477. return 0;
  10478. }
  10479. shopname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10480. if( st->end>st->start+3 )
  10481. flag = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10482. nd = npc_name2id(shopname);
  10483. if (!nd || nd->bl.type!=BL_NPC || nd->bl.subtype!=SHOP) {
  10484. ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)", shopname);
  10485. push_val(st->stack,C_INT,0);
  10486. return 1;
  10487. }
  10488. switch (flag) {
  10489. case 1: //Buy window
  10490. npc_buysellsel(sd,nd->bl.id,0);
  10491. break;
  10492. case 2: //Sell window
  10493. npc_buysellsel(sd,nd->bl.id,1);
  10494. break;
  10495. default: //Show menu
  10496. clif_npcbuysell(sd,nd->bl.id);
  10497. break;
  10498. }
  10499. sd->npc_shopid = nd->bl.id;
  10500. push_val(st->stack,C_INT,1);
  10501. return 0;
  10502. }
  10503. #ifndef MAX_SHOPITEM
  10504. #define MAX_SHOPITEM 100
  10505. #endif
  10506. int buildin_npcshopitem(struct script_state *st)
  10507. {
  10508. struct npc_data *nd= NULL;
  10509. int n = 0;
  10510. int i = 3;
  10511. int amount;
  10512. char* npcname = conv_str(st, & (st->stack->stack_data[st->start + 2]));
  10513. nd = npc_name2id(npcname);
  10514. if(nd && nd->bl.subtype==SHOP){
  10515. amount = ((st->end-2)/2)+1;
  10516. // st->end - 2 = nameid + value # ... / 2 = number of items ... + 1 to end it
  10517. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10518. sizeof(nd->u.shop_item[0]) * amount);
  10519. // Reset sell list.
  10520. malloc_set(nd->u.shop_item, 0, sizeof(nd->u.shop_item[0]) * amount);
  10521. n = 0;
  10522. while (st->end > st->start + i) {
  10523. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10524. i++;
  10525. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10526. i++;
  10527. n++;
  10528. }
  10529. map_addiddb(&nd->bl);
  10530. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10531. } else {
  10532. ShowError("buildin_npcshopitem: shop not found.\n");
  10533. }
  10534. return 0;
  10535. }
  10536. int buildin_npcshopadditem(struct script_state *st) {
  10537. struct npc_data *nd=NULL;
  10538. int n = 0;
  10539. int i = 3;
  10540. int amount;
  10541. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10542. nd = npc_name2id(npcname);
  10543. if (nd && nd->bl.subtype==SHOP){
  10544. amount = ((st->end-2)/2)+1;
  10545. while (nd->u.shop_item[n].nameid && n < MAX_SHOPITEM)
  10546. n++;
  10547. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10548. sizeof(nd->u.shop_item[0]) * (amount+n));
  10549. while(st->end > st->start + i){
  10550. nd->u.shop_item[n].nameid = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10551. i++;
  10552. nd->u.shop_item[n].value = conv_num(st, & (st->stack->stack_data[st->start+i]));
  10553. i++;
  10554. n++;
  10555. }
  10556. // Marks the last of our stuff..
  10557. nd->u.shop_item[n].value = 0;
  10558. nd->u.shop_item[n].nameid = 0;
  10559. map_addiddb(&nd->bl);
  10560. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10561. } else {
  10562. ShowError("buildin_npcshopadditem: shop not found.\n");
  10563. }
  10564. return 0;
  10565. }
  10566. int buildin_npcshopdelitem(struct script_state *st)
  10567. {
  10568. struct npc_data *nd=NULL;
  10569. int n=0;
  10570. int i=3;
  10571. int size = 0;
  10572. char* npcname = conv_str(st, & (st->stack->stack_data[st->start+2]));
  10573. nd = npc_name2id(npcname);
  10574. if (nd && nd->bl.subtype==SHOP) {
  10575. while (nd->u.shop_item[size].nameid)
  10576. size++;
  10577. while (st->end > st->start+i) {
  10578. for(n=0;nd->u.shop_item[n].nameid && n < MAX_SHOPITEM;n++) {
  10579. if (nd->u.shop_item[n].nameid == conv_num(st, & (st->stack->stack_data[st->start+i]))) {
  10580. // We're moving 1 extra empty block. Junk data is eliminated later.
  10581. memmove(&nd->u.shop_item[n], &nd->u.shop_item[n+1], sizeof(nd->u.shop_item[0])*(size-n));
  10582. }
  10583. }
  10584. i++;
  10585. }
  10586. size = 0;
  10587. while (nd->u.shop_item[size].nameid)
  10588. size++;
  10589. nd = (struct npc_data *)aRealloc(nd,sizeof(struct npc_data) +
  10590. sizeof(nd->u.shop_item[0]) * (size+1));
  10591. map_addiddb(&nd->bl);
  10592. nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
  10593. } else {
  10594. ShowError("buildin_npcshopdelitem: shop not found.\n");
  10595. }
  10596. return 0;
  10597. }
  10598. /*==========================================
  10599. * Returns some values of an item [Lupus]
  10600. * Price, Weight, etc...
  10601. setiteminfo(itemID,"{new item bonus script}");
  10602. *------------------------------------------
  10603. */
  10604. int buildin_setitemscript(struct script_state *st)
  10605. {
  10606. int item_id;
  10607. char *script;
  10608. struct item_data *i_data;
  10609. item_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10610. script = conv_str(st,& (st->stack->stack_data[st->start+3]));
  10611. i_data = itemdb_exists(item_id);
  10612. if (i_data && script!=NULL && script[0]=='{') {
  10613. if(i_data->script!=NULL)
  10614. script_free_code(i_data->script);
  10615. i_data->script = parse_script(script, "script_setitemscript", 0, 0);
  10616. push_val(st->stack,C_INT,1);
  10617. } else
  10618. push_val(st->stack,C_INT,0);
  10619. return 0;
  10620. }
  10621. /* Work In Progress [Lupus]
  10622. int buildin_addmonsterdrop(struct script_state *st)
  10623. {
  10624. int class_,item_id,chance;
  10625. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10626. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10627. chance=conv_num(st,& (st->stack->stack_data[st->start+4]));
  10628. if(class_>1000 && item_id>500 && chance>0) {
  10629. push_val(st->stack,C_INT,1);
  10630. } else {
  10631. push_val(st->stack,C_INT,0);
  10632. }
  10633. }
  10634. int buildin_delmonsterdrop(struct script_state *st)
  10635. {
  10636. int class_,item_id;
  10637. class_=conv_num(st,& (st->stack->stack_data[st->start+2]));
  10638. item_id=conv_num(st,& (st->stack->stack_data[st->start+3]));
  10639. if(class_>1000 && item_id>500) {
  10640. push_val(st->stack,C_INT,1);
  10641. } else {
  10642. push_val(st->stack,C_INT,0);
  10643. }
  10644. }
  10645. */
  10646. /*==========================================
  10647. * Returns some values of a monster [Lupus]
  10648. * Name, Level, race, size, etc...
  10649. getmonsterinfo(monsterID,queryIndex);
  10650. *------------------------------------------
  10651. */
  10652. int buildin_getmonsterinfo(struct script_state *st)
  10653. {
  10654. struct mob_db *mob;
  10655. int mob_id;
  10656. mob_id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  10657. if (!mobdb_checkid(mob_id)) {
  10658. ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i", mob_id);
  10659. push_val(st->stack, C_INT, -1);
  10660. return -1;
  10661. }
  10662. mob = mob_db(mob_id);
  10663. switch ( conv_num(st,& (st->stack->stack_data[st->start+3])) ) {
  10664. case 0: //Name
  10665. push_str(st->stack,C_CONSTSTR,mob->jname);
  10666. break;
  10667. case 1: //Lvl
  10668. push_val(st->stack,C_INT, mob->lv);
  10669. break;
  10670. case 2: //MaxHP
  10671. push_val(st->stack,C_INT, mob->status.max_hp);
  10672. break;
  10673. case 3: //Base EXP
  10674. push_val(st->stack,C_INT, mob->base_exp);
  10675. break;
  10676. case 4: //Job EXP
  10677. push_val(st->stack,C_INT, mob->job_exp);
  10678. break;
  10679. case 5: //Atk1
  10680. push_val(st->stack,C_INT, mob->status.rhw.atk);
  10681. break;
  10682. case 6: //Atk2
  10683. push_val(st->stack,C_INT, mob->status.rhw.atk2);
  10684. break;
  10685. case 7: //Def
  10686. push_val(st->stack,C_INT, mob->status.def);
  10687. break;
  10688. case 8: //Mdef
  10689. push_val(st->stack,C_INT, mob->status.mdef);
  10690. break;
  10691. case 9: //Str
  10692. push_val(st->stack,C_INT, mob->status.str);
  10693. break;
  10694. case 10: //Agi
  10695. push_val(st->stack,C_INT, mob->status.agi);
  10696. break;
  10697. case 11: //Vit
  10698. push_val(st->stack,C_INT, mob->status.vit);
  10699. break;
  10700. case 12: //Int
  10701. push_val(st->stack,C_INT, mob->status.int_);
  10702. break;
  10703. case 13: //Dex
  10704. push_val(st->stack,C_INT, mob->status.dex);
  10705. break;
  10706. case 14: //Luk
  10707. push_val(st->stack,C_INT, mob->status.luk);
  10708. break;
  10709. case 15: //Range
  10710. push_val(st->stack,C_INT, mob->status.rhw.range);
  10711. break;
  10712. case 16: //Range2
  10713. push_val(st->stack,C_INT, mob->range2);
  10714. break;
  10715. case 17: //Range3
  10716. push_val(st->stack,C_INT, mob->range3);
  10717. break;
  10718. case 18: //Size
  10719. push_val(st->stack,C_INT, mob->status.size);
  10720. break;
  10721. case 19: //Race
  10722. push_val(st->stack,C_INT, mob->status.race);
  10723. break;
  10724. case 20: //Element
  10725. push_val(st->stack,C_INT, mob->status.def_ele);
  10726. break;
  10727. case 21: //Mode
  10728. push_val(st->stack,C_INT, mob->status.mode);
  10729. break;
  10730. default: //wrong Index
  10731. push_val(st->stack,C_INT,-1);
  10732. }
  10733. return 0;
  10734. }
  10735. int buildin_checkvending(struct script_state *st){ // check vending [Nab4]
  10736. struct map_session_data *sd = NULL;
  10737. if(st->end > st->start + 2)
  10738. sd = map_nick2sd(conv_str(st,&st->stack->stack_data[st->start+2]));
  10739. else
  10740. sd = script_rid2sd(st);
  10741. if(sd)
  10742. push_val(st->stack, C_INT, (sd->vender_id != 0));
  10743. else
  10744. push_val(st->stack, C_INT, 0);
  10745. return 0;
  10746. }
  10747. int buildin_checkchatting(struct script_state *st){ // check chatting [Marka]
  10748. struct map_session_data *sd = NULL;
  10749. if(st->end > st->start + 2)
  10750. sd = map_nick2sd(conv_str(st,&st->stack->stack_data[st->start+2]));
  10751. else
  10752. sd = script_rid2sd(st);
  10753. if(sd)
  10754. push_val(st->stack, C_INT, (sd->chatID != 0));
  10755. else
  10756. push_val(st->stack, C_INT, 0);
  10757. return 0;
  10758. }
  10759. int axtoi(char *hexStg) {
  10760. int n = 0; // position in string
  10761. int m = 0; // position in digit[] to shift
  10762. int count; // loop index
  10763. int intValue = 0; // integer value of hex string
  10764. int digit[11]; // hold values to convert
  10765. while (n < 10) {
  10766. if (hexStg[n]=='\0')
  10767. break;
  10768. if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
  10769. digit[n] = hexStg[n] & 0x0f; //convert to int
  10770. else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
  10771. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10772. else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
  10773. digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
  10774. else break;
  10775. n++;
  10776. }
  10777. count = n;
  10778. m = n - 1;
  10779. n = 0;
  10780. while(n < count) {
  10781. // digit[n] is value of hex digit at position n
  10782. // (m << 2) is the number of positions to shift
  10783. // OR the bits into return value
  10784. intValue = intValue | (digit[n] << (m << 2));
  10785. m--; // adjust the position to set
  10786. n++; // next digit to process
  10787. }
  10788. return (intValue);
  10789. }
  10790. // [Lance] Hex string to integer converter
  10791. int buildin_axtoi(struct script_state *st)
  10792. {
  10793. char *hex = conv_str(st,& (st->stack->stack_data[st->start+2]));
  10794. push_val(st->stack, C_INT, axtoi(hex));
  10795. return 0;
  10796. }
  10797. // [zBuffer] List of player cont commands --->
  10798. int buildin_rid2name(struct script_state *st){
  10799. struct block_list *bl = NULL;
  10800. int rid = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10801. if((bl = map_id2bl(rid))){
  10802. switch(bl->type){
  10803. case BL_MOB:
  10804. push_str(st->stack,C_CONSTSTR,((TBL_MOB*)bl)->name);
  10805. break;
  10806. case BL_PC:
  10807. push_str(st->stack,C_CONSTSTR,((TBL_PC*)bl)->status.name);
  10808. break;
  10809. case BL_NPC:
  10810. push_str(st->stack,C_CONSTSTR,((TBL_NPC*)bl)->exname);
  10811. break;
  10812. case BL_PET:
  10813. push_str(st->stack,C_CONSTSTR,((TBL_PET*)bl)->pet.name);
  10814. break;
  10815. case BL_HOM:
  10816. push_str(st->stack,C_CONSTSTR,((TBL_HOM*)bl)->homunculus.name);
  10817. break;
  10818. default:
  10819. ShowError("buildin_rid2name: BL type unknown.\n");
  10820. push_str(st->stack,C_CONSTSTR,"");
  10821. break;
  10822. }
  10823. } else {
  10824. ShowError("buildin_rid2name: invalid RID\n");
  10825. push_str(st->stack,C_CONSTSTR,"(null)");
  10826. }
  10827. return 0;
  10828. }
  10829. int buildin_pcblockmove(struct script_state *st){
  10830. int id, flag;
  10831. struct map_session_data *sd = NULL;
  10832. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10833. flag = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10834. if(id)
  10835. sd = map_id2sd(id);
  10836. else
  10837. sd = script_rid2sd(st);
  10838. if(sd)
  10839. sd->state.blockedmove = flag > 0;
  10840. return 0;
  10841. }
  10842. int buildin_pcfollow(struct script_state *st) {
  10843. int id, targetid;
  10844. struct map_session_data *sd = NULL;
  10845. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10846. targetid = conv_num(st, & (st->stack->stack_data[st->start + 3]));
  10847. if(id)
  10848. sd = map_id2sd(id);
  10849. else
  10850. sd = script_rid2sd(st);
  10851. if(sd)
  10852. pc_follow(sd, targetid);
  10853. return 0;
  10854. }
  10855. int buildin_pcstopfollow(struct script_state *st) {
  10856. int id;
  10857. struct map_session_data *sd = NULL;
  10858. id = conv_num(st, & (st->stack->stack_data[st->start + 2]));
  10859. if(id)
  10860. sd = map_id2sd(id);
  10861. else
  10862. sd = script_rid2sd(st);
  10863. if(sd)
  10864. pc_stop_following(sd);
  10865. return 0;
  10866. }
  10867. // <--- [zBuffer] List of player cont commands
  10868. // [zBuffer] List of mob control commands --->
  10869. int buildin_mobspawn(struct script_state *st){
  10870. int class_,x,y,id;
  10871. char *str,*map;
  10872. // Who?
  10873. str =conv_str(st,& (st->stack->stack_data[st->start+2]));
  10874. // What?
  10875. class_ =conv_num(st,& (st->stack->stack_data[st->start+3]));
  10876. // Where?
  10877. map =conv_str(st,& (st->stack->stack_data[st->start+4]));
  10878. x =conv_num(st,& (st->stack->stack_data[st->start+5]));
  10879. y =conv_num(st,& (st->stack->stack_data[st->start+6]));
  10880. id = mob_once_spawn(map_id2sd(st->rid),map,x,y,str,class_,1,"");
  10881. push_val(st->stack,C_INT,id);
  10882. return 0;
  10883. }
  10884. int buildin_mobremove(struct script_state *st) {
  10885. int id;
  10886. struct block_list *bl = NULL;
  10887. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10888. bl = map_id2bl(id);
  10889. if (bl && bl->type == BL_MOB)
  10890. unit_free(bl,0);
  10891. return 0;
  10892. }
  10893. int buildin_getmobdata(struct script_state *st) {
  10894. int num, id;
  10895. char *name;
  10896. struct mob_data *md = NULL;
  10897. struct map_session_data *sd = st->rid?map_id2sd(st->rid):NULL;
  10898. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10899. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB || st->stack->stack_data[st->start+3].type!=C_NAME ){
  10900. ShowWarning("buildin_getmobdata: Error in argument!\n");
  10901. return -1;
  10902. }
  10903. num=st->stack->stack_data[st->start+3].u.num;
  10904. name=(char *)(str_buf+str_data[num&0x00ffffff].str);
  10905. setd_sub(st,sd,name,0,(void *)(int)md->class_,st->stack->stack_data[st->start+3].ref);
  10906. setd_sub(st,sd,name,1,(void *)(int)md->level,st->stack->stack_data[st->start+3].ref);
  10907. setd_sub(st,sd,name,2,(void *)(int)md->status.hp,st->stack->stack_data[st->start+3].ref);
  10908. setd_sub(st,sd,name,3,(void *)(int)md->status.max_hp,st->stack->stack_data[st->start+3].ref);
  10909. setd_sub(st,sd,name,4,(void *)(int)md->master_id,st->stack->stack_data[st->start+3].ref);
  10910. setd_sub(st,sd,name,5,(void *)(int)md->bl.m,st->stack->stack_data[st->start+3].ref);
  10911. setd_sub(st,sd,name,6,(void *)(int)md->bl.x,st->stack->stack_data[st->start+3].ref);
  10912. setd_sub(st,sd,name,7,(void *)(int)md->bl.y,st->stack->stack_data[st->start+3].ref);
  10913. setd_sub(st,sd,name,8,(void *)(int)md->status.speed,st->stack->stack_data[st->start+3].ref);
  10914. setd_sub(st,sd,name,9,(void *)(int)md->status.mode,st->stack->stack_data[st->start+3].ref);
  10915. setd_sub(st,sd,name,10,(void *)(int)md->special_state.ai,st->stack->stack_data[st->start+3].ref);
  10916. setd_sub(st,sd,name,11,(void *)(int)md->sc.option,st->stack->stack_data[st->start+3].ref);
  10917. setd_sub(st,sd,name,12,(void *)(int)md->vd->sex,st->stack->stack_data[st->start+3].ref);
  10918. setd_sub(st,sd,name,13,(void *)(int)md->vd->class_,st->stack->stack_data[st->start+3].ref);
  10919. setd_sub(st,sd,name,14,(void *)(int)md->vd->hair_style,st->stack->stack_data[st->start+3].ref);
  10920. setd_sub(st,sd,name,15,(void *)(int)md->vd->hair_color,st->stack->stack_data[st->start+3].ref);
  10921. setd_sub(st,sd,name,16,(void *)(int)md->vd->head_bottom,st->stack->stack_data[st->start+3].ref);
  10922. setd_sub(st,sd,name,17,(void *)(int)md->vd->head_mid,st->stack->stack_data[st->start+3].ref);
  10923. setd_sub(st,sd,name,18,(void *)(int)md->vd->head_top,st->stack->stack_data[st->start+3].ref);
  10924. setd_sub(st,sd,name,19,(void *)(int)md->vd->cloth_color,st->stack->stack_data[st->start+3].ref);
  10925. setd_sub(st,sd,name,20,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10926. setd_sub(st,sd,name,21,(void *)(int)md->vd->weapon,st->stack->stack_data[st->start+3].ref);
  10927. setd_sub(st,sd,name,22,(void *)(int)md->vd->shield,st->stack->stack_data[st->start+3].ref);
  10928. setd_sub(st,sd,name,23,(void *)(int)md->ud.dir,st->stack->stack_data[st->start+3].ref);
  10929. setd_sub(st,sd,name,24,(void *)(int)md->state.killer,st->stack->stack_data[st->start+3].ref);
  10930. setd_sub(st,sd,name,25,(void *)(int)md->callback_flag,st->stack->stack_data[st->start+3].ref);
  10931. setd_sub(st,sd,name,26,(void *)(int)md->state.no_random_walk, st->stack->stack_data[st->start+3].ref);
  10932. return 0;
  10933. }
  10934. int buildin_setmobdata(struct script_state *st){
  10935. int id, value, value2;
  10936. struct mob_data *md = NULL;
  10937. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  10938. value = conv_num(st, & (st->stack->stack_data[st->start+3]));
  10939. value2 = conv_num(st, & (st->stack->stack_data[st->start+4]));
  10940. if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){
  10941. ShowWarning("buildin_setmobdata: Error in argument!\n");
  10942. return -1;
  10943. }
  10944. switch(value){
  10945. case 0:
  10946. md->class_ = (short)value2;
  10947. break;
  10948. case 1:
  10949. md->level = (unsigned short)value2;
  10950. break;
  10951. case 2:
  10952. md->status.hp = (unsigned int)value2;
  10953. break;
  10954. case 3:
  10955. md->status.max_hp = (unsigned int)value2;
  10956. break;
  10957. case 4:
  10958. md->master_id = value2;
  10959. break;
  10960. case 5:
  10961. md->bl.m = (short)value2;
  10962. break;
  10963. case 6:
  10964. md->bl.x = (short)value2;
  10965. break;
  10966. case 7:
  10967. md->bl.y = (short)value2;
  10968. break;
  10969. case 8:
  10970. md->status.speed = (unsigned short)value2;
  10971. break;
  10972. case 9:
  10973. md->status.mode = (unsigned short)value2;
  10974. break;
  10975. case 10:
  10976. md->special_state.ai = (unsigned int)value2;
  10977. break;
  10978. case 11:
  10979. md->sc.option = (unsigned short)value2;
  10980. break;
  10981. case 12:
  10982. md->vd->sex = (char)value2;
  10983. break;
  10984. case 13:
  10985. md->vd->class_ = (unsigned short)value2;
  10986. break;
  10987. case 14:
  10988. md->vd->hair_style = (unsigned short)value2;
  10989. break;
  10990. case 15:
  10991. md->vd->hair_color = (unsigned short)value2;
  10992. break;
  10993. case 16:
  10994. md->vd->head_bottom = (unsigned short)value2;
  10995. break;
  10996. case 17:
  10997. md->vd->head_mid = (unsigned short)value2;
  10998. break;
  10999. case 18:
  11000. md->vd->head_top = (unsigned short)value2;
  11001. break;
  11002. case 19:
  11003. md->vd->cloth_color = (unsigned short)value2;
  11004. break;
  11005. case 20:
  11006. md->vd->shield = (unsigned short)value2;
  11007. break;
  11008. case 21:
  11009. md->vd->weapon = (unsigned short)value2;
  11010. break;
  11011. case 22:
  11012. md->vd->shield = (unsigned short)value2;
  11013. break;
  11014. case 23:
  11015. md->ud.dir = (unsigned char)value2;
  11016. break;
  11017. case 24:
  11018. md->state.killer = value2>0?1:0;
  11019. break;
  11020. case 25:
  11021. md->callback_flag = (short)value2;
  11022. break;
  11023. case 26:
  11024. md->state.no_random_walk = value2>0?1:0;
  11025. break;
  11026. default:
  11027. ShowError("buildin_setmobdata: argument id is not identified.");
  11028. return -1;
  11029. }
  11030. return 0;
  11031. }
  11032. int buildin_mobassist(struct script_state *st) {
  11033. int id;
  11034. char *target;
  11035. struct mob_data *md = NULL;
  11036. struct block_list *bl = NULL;
  11037. struct unit_data *ud;
  11038. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11039. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11040. if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) {
  11041. md = (struct mob_data *)map_id2bl(id);
  11042. if(md && md->bl.type == BL_MOB) {
  11043. ud = unit_bl2ud(bl);
  11044. md->master_id = bl->id;
  11045. md->state.killer = 1;
  11046. mob_convertslave(md);
  11047. if (ud) {
  11048. if (ud->target)
  11049. md->target_id = ud->target;
  11050. else if (ud->skilltarget)
  11051. md->target_id = ud->skilltarget;
  11052. if(md->target_id)
  11053. unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
  11054. }
  11055. }
  11056. }
  11057. return 0;
  11058. }
  11059. int buildin_mobattach(struct script_state *st){
  11060. int id;
  11061. struct mob_data *md = NULL;
  11062. struct npc_data *nd = NULL;
  11063. char *npcname = NULL;
  11064. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11065. if(st->end > st->start + 3){
  11066. npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11067. }
  11068. if(npcname)
  11069. nd = npc_name2id(npcname);
  11070. else
  11071. nd = (struct npc_data *)map_id2bl(st->oid);
  11072. if(nd)
  11073. if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB)
  11074. md->nd = nd;
  11075. return 0;
  11076. }
  11077. int buildin_unitwalk(struct script_state *st){
  11078. int id,x,y = 0;
  11079. struct block_list *bl = NULL;
  11080. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11081. x = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11082. if(st->end > st->start+4)
  11083. y = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11084. bl = map_id2bl(id);
  11085. if(bl){
  11086. if(y)
  11087. push_val(st->stack,C_INT,unit_walktoxy(bl,x,y,0)); // We'll use harder calculations.
  11088. else
  11089. push_val(st->stack,C_INT,unit_walktobl(bl,map_id2bl(x),65025,1));
  11090. } else {
  11091. push_val(st->stack,C_INT,0);
  11092. }
  11093. return 0;
  11094. }
  11095. int buildin_unitkill(struct script_state *st){
  11096. struct block_list *bl = map_id2bl(conv_num(st, & (st->stack->stack_data[st->start+2])));
  11097. if(bl)
  11098. status_kill(bl);
  11099. return 0;
  11100. }
  11101. int buildin_unitwarp(struct script_state *st){
  11102. int id,x,y,m = 0;
  11103. char *map;
  11104. struct block_list *bl = NULL;
  11105. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11106. map = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11107. x = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11108. y = conv_num(st, & (st->stack->stack_data[st->start+5]));
  11109. bl = map_id2bl(id);
  11110. m = map_mapname2mapid(map);
  11111. if(m && bl){
  11112. push_val(st->stack,C_INT,unit_warp(bl, m, (short)x, (short)y, 0));
  11113. } else {
  11114. push_val(st->stack,C_INT,0);
  11115. }
  11116. return 0;
  11117. }
  11118. int buildin_unitattack(struct script_state *st) {
  11119. int id = 0, actiontype = 0;
  11120. char *target = NULL;
  11121. struct map_session_data *sd = NULL;
  11122. struct block_list *bl = NULL, *tbl = NULL;
  11123. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11124. target = conv_str(st, & (st->stack->stack_data[st->start+3]));
  11125. if(st->end > st->start + 4)
  11126. actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
  11127. sd = map_nick2sd(target);
  11128. if(!sd)
  11129. tbl = map_id2bl(atoi(target));
  11130. else
  11131. tbl = &sd->bl;
  11132. if((bl = map_id2bl(id))){
  11133. switch (bl->type) {
  11134. case BL_PC:
  11135. clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick());
  11136. push_val(st->stack,C_INT,1);
  11137. return 0;
  11138. case BL_MOB:
  11139. ((TBL_MOB *)bl)->state.killer = 1;
  11140. ((TBL_MOB *)bl)->target_id = tbl->id;
  11141. break;
  11142. case BL_PET:
  11143. ((TBL_PET *)bl)->target_id = tbl->id;
  11144. break;
  11145. }
  11146. push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
  11147. } else {
  11148. push_val(st->stack,C_INT,0);
  11149. }
  11150. return 0;
  11151. }
  11152. int buildin_unitstop(struct script_state *st) {
  11153. int id;
  11154. struct block_list *bl = NULL;
  11155. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11156. bl = map_id2bl(id);
  11157. if(bl){
  11158. unit_stop_attack(bl);
  11159. unit_stop_walking(bl,0);
  11160. if(bl->type == BL_MOB)
  11161. ((TBL_MOB *)bl)->target_id = 0;
  11162. }
  11163. return 0;
  11164. }
  11165. int buildin_unittalk(struct script_state *st)
  11166. {
  11167. char *str;
  11168. int id;
  11169. char message[255];
  11170. struct block_list *bl = NULL;
  11171. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11172. str=conv_str(st,& (st->stack->stack_data[st->start+3]));
  11173. bl = map_id2bl(id);
  11174. if(bl) {
  11175. memcpy(message, status_get_name(bl), NAME_LENGTH);
  11176. strcat(message," : ");
  11177. strncat(message,str, 228); //Prevent overflow possibility. [Skotlex]
  11178. clif_message(bl, message);
  11179. if(bl->type == BL_PC)
  11180. clif_displaymessage(((TBL_PC*)bl)->fd, message);
  11181. }
  11182. return 0;
  11183. }
  11184. int buildin_unitemote(struct script_state *st) {
  11185. int id, emo;
  11186. struct block_list *bl= NULL;
  11187. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11188. emo = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11189. if((bl = map_id2bl(id)))
  11190. clif_emotion(bl,emo);
  11191. return 0;
  11192. }
  11193. int buildin_unitdeadsit(struct script_state *st){
  11194. int id, action;
  11195. struct block_list *bl = NULL;
  11196. id = conv_num(st, & (st->stack->stack_data[st->start+2]));
  11197. action = conv_num(st, & (st->stack->stack_data[st->start+3]));
  11198. if((bl = map_id2bl(id))){
  11199. if(action > -1 && action < 4){
  11200. unsigned char buf[61] = "";
  11201. struct view_data *vd = status_get_viewdata(bl);
  11202. if (vd) vd->dead_sit = action;
  11203. WBUFW(buf, 0) = 0x8a;
  11204. WBUFL(buf, 2) = bl->id;
  11205. WBUFB(buf,26) = (unsigned char)action;
  11206. clif_send(buf, 61, bl, AREA);
  11207. }else {
  11208. ShowError("buildin_unitdeadsit: Invalid action.\n");
  11209. report_src(st);
  11210. }
  11211. }else{
  11212. ShowError("buildin_unitdeadsit: Target is not found.\n");
  11213. report_src(st);
  11214. }
  11215. return 0;
  11216. }
  11217. int buildin_unitskilluseid (struct script_state *st)
  11218. {
  11219. int id,skid,sklv;
  11220. struct block_list *bl = NULL;
  11221. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11222. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  11223. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  11224. if ((bl = map_id2bl(id)))
  11225. unit_skilluse_id(bl,(st->end>st->start+5)?conv_num(st,& (st->stack->stack_data[st->start+5])):bl->id,skid,sklv);
  11226. return 0;
  11227. }
  11228. int buildin_unitskillusepos(struct script_state *st)
  11229. {
  11230. int skid,sklv,x,y,id;
  11231. struct block_list *bl = NULL;
  11232. id = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11233. skid=conv_num(st,& (st->stack->stack_data[st->start+3]));
  11234. sklv=conv_num(st,& (st->stack->stack_data[st->start+4]));
  11235. x=conv_num(st,& (st->stack->stack_data[st->start+5]));
  11236. y=conv_num(st,& (st->stack->stack_data[st->start+6]));
  11237. if ((bl=map_id2bl(id)))
  11238. unit_skilluse_pos(bl,x,y,skid,sklv);
  11239. return 0;
  11240. }
  11241. // <--- [zBuffer] List of mob control commands
  11242. // sleep <mili sec>
  11243. int buildin_sleep(struct script_state *st) {
  11244. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11245. struct map_session_data *sd = map_id2sd(st->rid);
  11246. if(sd && sd->npc_id == st->oid) {
  11247. sd->npc_id = 0;
  11248. }
  11249. st->rid = 0;
  11250. if(tick <= 0) {
  11251. // 何もしない
  11252. } else if( !st->sleep.tick ) {
  11253. // 初回実行
  11254. st->state = RERUNLINE;
  11255. st->sleep.tick = tick;
  11256. } else {
  11257. // 続行
  11258. st->sleep.tick = 0;
  11259. }
  11260. return 0;
  11261. }
  11262. // sleep2 <mili sec>
  11263. int buildin_sleep2(struct script_state *st) {
  11264. int tick = conv_num(st,& (st->stack->stack_data[st->start+2]));
  11265. if( tick <= 0 ) {
  11266. // 0ms の待機時間を指定された
  11267. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11268. } else if( !st->sleep.tick ) {
  11269. // 初回実行時
  11270. st->state = RERUNLINE;
  11271. st->sleep.tick = tick;
  11272. } else {
  11273. push_val(st->stack,C_INT,map_id2sd(st->rid) != NULL);
  11274. st->sleep.tick = 0;
  11275. }
  11276. return 0;
  11277. }
  11278. /*==========================================
  11279. * 指定NPCの全てのsleepを再開する
  11280. *------------------------------------------
  11281. */
  11282. int buildin_awake(struct script_state *st)
  11283. {
  11284. struct npc_data *nd;
  11285. struct linkdb_node *node = (struct linkdb_node *)sleep_db;
  11286. nd = npc_name2id(conv_str(st,& (st->stack->stack_data[st->start+2])));
  11287. if(nd == NULL)
  11288. return 0;
  11289. while( node ) {
  11290. if( (int)node->key == nd->bl.id) {
  11291. struct script_state *tst = node->data;
  11292. struct map_session_data *sd = map_id2sd(tst->rid);
  11293. if( tst->sleep.timer == -1 ) {
  11294. node = node->next;
  11295. continue;
  11296. }
  11297. if((sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd))
  11298. { //Cancel Execution
  11299. tst->state=END;
  11300. tst->rid = 0;
  11301. }
  11302. delete_timer(tst->sleep.timer, run_script_timer);
  11303. node = script_erase_sleepdb(node);
  11304. tst->sleep.timer = -1;
  11305. tst->sleep.tick = 0;
  11306. run_script_main(tst);
  11307. } else {
  11308. node = node->next;
  11309. }
  11310. }
  11311. return 0;
  11312. }
  11313. // getvariableofnpc(<param>, <npc name>);
  11314. int buildin_getvariableofnpc(struct script_state *st)
  11315. {
  11316. if( st->stack->stack_data[st->start+2].type != C_NAME ) {
  11317. // 第一引数が変数名じゃない
  11318. printf("getvariableofnpc: param not name\n");
  11319. push_val(st->stack,C_INT,0);
  11320. } else {
  11321. int num = st->stack->stack_data[st->start+2].u.num;
  11322. char *var_name = str_buf+str_data[num&0x00ffffff].str;
  11323. char *npc_name = conv_str(st,& (st->stack->stack_data[st->start+3]));
  11324. struct npc_data *nd = npc_name2id(npc_name);
  11325. if( var_name[0] != '.' || var_name[1] == '@' ) {
  11326. // ' 変数以外はダメ
  11327. printf("getvariableofnpc: invalid scope %s\n", var_name);
  11328. push_val(st->stack,C_INT,0);
  11329. } else if( nd == NULL || nd->bl.subtype != SCRIPT || !nd->u.scr.script) {
  11330. // NPC が見つからない or SCRIPT以外のNPC
  11331. printf("getvariableofnpc: can't find npc %s\n", npc_name);
  11332. push_val(st->stack,C_INT,0);
  11333. } else {
  11334. push_val2(st->stack,C_NAME,num, &nd->u.scr.script->script_vars );
  11335. }
  11336. }
  11337. return 0;
  11338. }
  11339. // [blackhole89] --->
  11340. // Set a warp portal.
  11341. int buildin_warpportal(struct script_state *st){
  11342. struct skill_unit_group *group;
  11343. unsigned short mapindex;
  11344. long spx,spy,tpx,tpy;
  11345. struct block_list *bl=map_id2bl(st->oid);
  11346. nullpo_retr(0,bl);
  11347. spx=conv_num(st, & (st->stack->stack_data[st->start+2]));
  11348. spy=conv_num(st, & (st->stack->stack_data[st->start+3]));
  11349. mapindex = mapindex_name2id((char*)conv_str(st,& (st->stack->stack_data[st->start+4])));
  11350. printf("mapindex: %d\n",mapindex);
  11351. tpx=conv_num(st, & (st->stack->stack_data[st->start+5]));
  11352. tpy=conv_num(st, & (st->stack->stack_data[st->start+6]));
  11353. if(!mapindex) return 0;
  11354. if((group=skill_unitsetting(bl,AL_WARP,4,spx,spy,1))==NULL) {
  11355. return 0;
  11356. }
  11357. group->val2=(tpx<<16)|tpy;
  11358. group->val3 = mapindex;
  11359. return 0;
  11360. }
  11361. // <-- [blackhole89]