12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769 |
- // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
- // For more information, see LICENCE in the main folder
- //#define DEBUG_DISP
- //#define DEBUG_DISASM
- //#define DEBUG_RUN
- //#define DEBUG_HASH
- //#define DEBUG_DUMP_STACK
- #include "../common/cbasetypes.h"
- #include "../common/malloc.h"
- #include "../common/md5calc.h"
- #include "../common/nullpo.h"
- #include "../common/random.h"
- #include "../common/showmsg.h"
- #include "../common/socket.h"
- #include "../common/strlib.h"
- #include "../common/timer.h"
- #include "../common/utils.h"
- #include "map.h"
- #include "path.h"
- #include "clif.h"
- #include "chrif.h"
- #include "itemdb.h"
- #include "pc.h"
- #include "status.h"
- #include "storage.h"
- #include "mob.h"
- #include "npc.h"
- #include "pet.h"
- #include "mapreg.h"
- #include "homunculus.h"
- #include "instance.h"
- #include "mercenary.h"
- #include "intif.h"
- #include "skill.h"
- #include "status.h"
- #include "chat.h"
- #include "battle.h"
- #include "battleground.h"
- #include "party.h"
- #include "guild.h"
- #include "atcommand.h"
- #include "log.h"
- #include "unit.h"
- #include "pet.h"
- #include "mail.h"
- #include "script.h"
- #include "quest.h"
- #include "elemental.h"
- #include "../config/core.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #ifndef WIN32
- #include <sys/time.h>
- #endif
- #include <time.h>
- #include <setjmp.h>
- #include <errno.h>
- #ifdef BETA_THREAD_TEST
- #include "../common/atomic.h"
- #include "../common/spinlock.h"
- #include "../common/thread.h"
- #include "../common/mutex.h"
- #endif
- ///////////////////////////////////////////////////////////////////////////////
- //## TODO possible enhancements: [FlavioJS]
- // - 'callfunc' supporting labels in the current npc "::LabelName"
- // - 'callfunc' supporting labels in other npcs "NpcName::LabelName"
- // - 'function FuncName;' function declarations reverting to global functions
- // if local label isn't found
- // - join callfunc and callsub's functionality
- // - remove dynamic allocation in add_word()
- // - remove GETVALUE / SETVALUE
- // - clean up the set_reg / set_val / setd_sub mess
- // - detect invalid label references at parse-time
- //
- // struct script_state* st;
- //
- /// Returns the script_data at the target index
- #define script_getdata(st,i) ( &((st)->stack->stack_data[(st)->start + (i)]) )
- /// Returns if the stack contains data at the target index
- #define script_hasdata(st,i) ( (st)->end > (st)->start + (i) )
- /// Returns the index of the last data in the stack
- #define script_lastdata(st) ( (st)->end - (st)->start - 1 )
- /// Pushes an int into the stack
- #define script_pushint(st,val) push_val((st)->stack, C_INT, (val))
- /// Pushes a string into the stack (script engine frees it automatically)
- #define script_pushstr(st,val) push_str((st)->stack, C_STR, (val))
- /// Pushes a copy of a string into the stack
- #define script_pushstrcopy(st,val) push_str((st)->stack, C_STR, aStrdup(val))
- /// Pushes a constant string into the stack (must never change or be freed)
- #define script_pushconststr(st,val) push_str((st)->stack, C_CONSTSTR, (val))
- /// Pushes a nil into the stack
- #define script_pushnil(st) push_val((st)->stack, C_NOP, 0)
- /// Pushes a copy of the data in the target index
- #define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i))
- #define script_isstring(st,i) data_isstring(script_getdata(st,i))
- #define script_isint(st,i) data_isint(script_getdata(st,i))
- #define script_getnum(st,val) conv_num(st, script_getdata(st,val))
- #define script_getstr(st,val) conv_str(st, script_getdata(st,val))
- #define script_getref(st,val) ( script_getdata(st,val)->ref )
- // Returns name of currently running function
- #define script_getfuncname(st) ( st->funcname )
- // Note: "top" functions/defines use indexes relative to the top of the stack
- // -1 is the index of the data at the top
- /// Returns the script_data at the target index relative to the top of the stack
- #define script_getdatatop(st,i) ( &((st)->stack->stack_data[(st)->stack->sp + (i)]) )
- /// Pushes a copy of the data in the target index relative to the top of the stack
- #define script_pushcopytop(st,i) push_copy((st)->stack, (st)->stack->sp + (i))
- /// Removes the range of values [start,end[ relative to the top of the stack
- #define script_removetop(st,start,end) ( pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) )
- //
- // struct script_data* data;
- //
- /// Returns if the script data is a string
- #define data_isstring(data) ( (data)->type == C_STR || (data)->type == C_CONSTSTR )
- /// Returns if the script data is an int
- #define data_isint(data) ( (data)->type == C_INT )
- /// Returns if the script data is a reference
- #define data_isreference(data) ( (data)->type == C_NAME )
- /// Returns if the script data is a label
- #define data_islabel(data) ( (data)->type == C_POS )
- /// Returns if the script data is an internal script function label
- #define data_isfunclabel(data) ( (data)->type == C_USERFUNC_POS )
- /// Returns if this is a reference to a constant
- #define reference_toconstant(data) ( str_data[reference_getid(data)].type == C_INT )
- /// Returns if this a reference to a param
- #define reference_toparam(data) ( str_data[reference_getid(data)].type == C_PARAM )
- /// Returns if this a reference to a variable
- //##TODO confirm it's C_NAME [FlavioJS]
- #define reference_tovariable(data) ( str_data[reference_getid(data)].type == C_NAME )
- /// Returns the unique id of the reference (id and index)
- #define reference_getuid(data) ( (data)->u.num )
- /// Returns the id of the reference
- #define reference_getid(data) ( (int32)(reference_getuid(data) & 0x00ffffff) )
- /// Returns the array index of the reference
- #define reference_getindex(data) ( (int32)(((uint32)(reference_getuid(data) & 0xff000000)) >> 24) )
- /// Returns the name of the reference
- #define reference_getname(data) ( str_buf + str_data[reference_getid(data)].str )
- /// Returns the linked list of uid-value pairs of the reference (can be NULL)
- #define reference_getref(data) ( (data)->ref )
- /// Returns the value of the constant
- #define reference_getconstant(data) ( str_data[reference_getid(data)].val )
- /// Returns the type of param
- #define reference_getparamtype(data) ( str_data[reference_getid(data)].val )
- /// Composes the uid of a reference from the id and the index
- #define reference_uid(id,idx) ( (int32)((((uint32)(id)) & 0x00ffffff) | (((uint32)(idx)) << 24)) )
- #define not_server_variable(prefix) ( (prefix) != '$' && (prefix) != '.' && (prefix) != '\'')
- #define not_array_variable(prefix) ( (prefix) != '$' && (prefix) != '@' && (prefix) != '.' && (prefix) != '\'' )
- #define is_string_variable(name) ( (name)[strlen(name) - 1] == '$' )
- #define FETCH(n, t) \
- if( script_hasdata(st,n) ) \
- (t)=script_getnum(st,n);
- /// Maximum amount of elements in script arrays
- #define SCRIPT_MAX_ARRAYSIZE 128
- #define SCRIPT_CMD_SUCCESS 0 ///when a buildin cmd was correctly done
- #define SCRIPT_CMD_FAILURE 1 ///when an errors appear in cmd, show_debug will follow
- #define SCRIPT_BLOCK_SIZE 512
- enum { LABEL_NEXTLINE=1,LABEL_START };
- /// temporary buffer for passing around compiled bytecode
- /// @see add_scriptb, set_label, parse_script
- static unsigned char* script_buf = NULL;
- static int script_pos = 0, script_size = 0;
- static inline int GETVALUE(const unsigned char* buf, int i)
- {
- return (int)MakeDWord(MakeWord(buf[i], buf[i+1]), MakeWord(buf[i+2], 0));
- }
- static inline void SETVALUE(unsigned char* buf, int i, int n)
- {
- buf[i] = GetByte(n, 0);
- buf[i+1] = GetByte(n, 1);
- buf[i+2] = GetByte(n, 2);
- }
- // String buffer structures.
- // str_data stores string information
- static struct str_data_struct {
- enum c_op type;
- int str;
- int backpatch;
- int label;
- int (*func)(struct script_state *st);
- int val;
- int next;
- } *str_data = NULL;
- static int str_data_size = 0; // size of the data
- static int str_num = LABEL_START; // next id to be assigned
- // str_buf holds the strings themselves
- static char *str_buf;
- static int str_size = 0; // size of the buffer
- static int str_pos = 0; // next position to be assigned
- // Using a prime number for SCRIPT_HASH_SIZE should give better distributions
- #define SCRIPT_HASH_SIZE 1021
- int str_hash[SCRIPT_HASH_SIZE];
- // Specifies which string hashing method to use
- //#define SCRIPT_HASH_DJB2
- //#define SCRIPT_HASH_SDBM
- #define SCRIPT_HASH_ELF
- static DBMap* scriptlabel_db=NULL; // const char* label_name -> int script_pos
- static DBMap* userfunc_db=NULL; // const char* func_name -> struct script_code*
- static int parse_options=0;
- DBMap* script_get_label_db(void){ return scriptlabel_db; }
- DBMap* script_get_userfunc_db(void){ return userfunc_db; }
- // important buildin function references for usage in scripts
- static int buildin_set_ref = 0;
- static int buildin_callsub_ref = 0;
- static int buildin_callfunc_ref = 0;
- static int buildin_getelementofarray_ref = 0;
- // Caches compiled autoscript item code.
- // Note: This is not cleared when reloading itemdb.
- static DBMap* autobonus_db=NULL; // char* script -> char* bytecode
- struct Script_Config script_config = {
- 1, // warn_func_mismatch_argtypes
- 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
- 0, INT_MAX, // input_min_value/input_max_value
- "OnPCDieEvent", //die_event_name
- "OnPCKillEvent", //kill_pc_event_name
- "OnNPCKillEvent", //kill_mob_event_name
- "OnPCLoginEvent", //login_event_name
- "OnPCLogoutEvent", //logout_event_name
- "OnPCLoadMapEvent", //loadmap_event_name
- "OnPCBaseLvUpEvent", //baselvup_event_name
- "OnPCJobLvUpEvent", //joblvup_event_name
- "OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
- "OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area)
- };
- static jmp_buf error_jump;
- static char* error_msg;
- static const char* error_pos;
- static int error_report; // if the error should produce output
- // Used by disp_warning_message
- static const char* parser_current_src;
- static const char* parser_current_file;
- static int parser_current_line;
- // for advanced scripting support ( nested if, switch, while, for, do-while, function, etc )
- // [Eoe / jA 1080, 1081, 1094, 1164]
- enum curly_type {
- TYPE_NULL = 0,
- TYPE_IF,
- TYPE_SWITCH,
- TYPE_WHILE,
- TYPE_FOR,
- TYPE_DO,
- TYPE_USERFUNC,
- TYPE_ARGLIST // function argument list
- };
- enum e_arglist
- {
- ARGLIST_UNDEFINED = 0,
- ARGLIST_NO_PAREN = 1,
- ARGLIST_PAREN = 2,
- };
- static struct {
- struct {
- enum curly_type type;
- int index;
- int count;
- int flag;
- struct linkdb_node *case_label;
- } curly[256]; // Information right parenthesis
- int curly_count; // The number of right brackets
- int index; // Number of the syntax used in the script
- } syntax;
- const char* parse_curly_close(const char* p);
- const char* parse_syntax_close(const char* p);
- const char* parse_syntax_close_sub(const char* p,int* flag);
- const char* parse_syntax(const char* p);
- static int parse_syntax_for_flag = 0;
- extern int current_equip_item_index; //for New CARDS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
- int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
- int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
- int potion_target=0;
- c_op get_com(unsigned char *script,int *pos);
- int get_num(unsigned char *script,int *pos);
- typedef struct script_function {
- int (*func)(struct script_state *st);
- const char *name;
- const char *arg;
- } script_function;
- extern script_function buildin_func[];
- static struct linkdb_node* sleep_db;// int oid -> struct script_state*
- #ifdef BETA_THREAD_TEST
- /**
- * MySQL Query Slave
- **/
- static SPIN_LOCK queryThreadLock;
- static rAthread queryThread = NULL;
- static ramutex queryThreadMutex = NULL;
- static racond queryThreadCond = NULL;
- static volatile int32 queryThreadTerminate = 0;
- struct queryThreadEntry {
- bool ok;
- bool type; /* main db or log db? */
- struct script_state *st;
- };
- /* Ladies and Gentleman the Manager! */
- struct {
- struct queryThreadEntry **entry;/* array of structs */
- int count;
- int timer;/* used to receive processed entries */
- } queryThreadData;
- #endif
- /*==========================================
- * (Only those needed) local declaration prototype
- *------------------------------------------*/
- const char* parse_subexpr(const char* p,int limit);
- int run_func(struct script_state *st);
- int script_instancegetid(struct script_state *st);
- enum {
- MF_NOMEMO, //0
- MF_NOTELEPORT,
- MF_NOSAVE,
- MF_NOBRANCH,
- MF_NOPENALTY,
- MF_NOZENYPENALTY,
- MF_PVP,
- MF_PVP_NOPARTY,
- MF_PVP_NOGUILD,
- MF_GVG,
- MF_GVG_NOPARTY, //10
- MF_NOTRADE,
- MF_NOSKILL,
- MF_NOWARP,
- MF_PARTYLOCK,
- MF_NOICEWALL,
- MF_SNOW,
- MF_FOG,
- MF_SAKURA,
- MF_LEAVES,
- /**
- * No longer available, keeping here just in case it's back someday. [Ind]
- **/
- //MF_RAIN, //20
- // 21 free
- MF_NOGO = 22,
- MF_CLOUDS,
- MF_CLOUDS2,
- MF_FIREWORKS,
- MF_GVG_CASTLE,
- MF_GVG_DUNGEON,
- MF_NIGHTENABLED,
- MF_NOBASEEXP,
- MF_NOJOBEXP, //30
- MF_NOMOBLOOT,
- MF_NOMVPLOOT,
- MF_NORETURN,
- MF_NOWARPTO,
- MF_NIGHTMAREDROP,
- MF_RESTRICTED,
- MF_NOCOMMAND,
- MF_NODROP,
- MF_JEXP,
- MF_BEXP, //40
- MF_NOVENDING,
- MF_LOADEVENT,
- MF_NOCHAT,
- MF_NOEXPPENALTY,
- MF_GUILDLOCK,
- MF_TOWN,
- MF_AUTOTRADE,
- MF_ALLOWKS,
- MF_MONSTER_NOTELEPORT,
- MF_PVP_NOCALCRANK, //50
- MF_BATTLEGROUND,
- MF_RESET,
- MF_CHANNELAUTOJOIN,
- MF_NOUSECART,
- MF_NOITEMCONSUMPTION,
- MF_SUMSTARTMIRACLE,
- MF_NOMINEEFFECT,
- MF_NOLOCKON,
- MF_NOTOMB,
- MF_SKILL_DAMAGE //60
- };
- const char* script_op2name(int op)
- {
- #define RETURN_OP_NAME(type) case type: return #type
- switch( op )
- {
- RETURN_OP_NAME(C_NOP);
- RETURN_OP_NAME(C_POS);
- RETURN_OP_NAME(C_INT);
- RETURN_OP_NAME(C_PARAM);
- RETURN_OP_NAME(C_FUNC);
- RETURN_OP_NAME(C_STR);
- RETURN_OP_NAME(C_CONSTSTR);
- RETURN_OP_NAME(C_ARG);
- RETURN_OP_NAME(C_NAME);
- RETURN_OP_NAME(C_EOL);
- RETURN_OP_NAME(C_RETINFO);
- RETURN_OP_NAME(C_USERFUNC);
- RETURN_OP_NAME(C_USERFUNC_POS);
- // operators
- RETURN_OP_NAME(C_OP3);
- RETURN_OP_NAME(C_LOR);
- RETURN_OP_NAME(C_LAND);
- RETURN_OP_NAME(C_LE);
- RETURN_OP_NAME(C_LT);
- RETURN_OP_NAME(C_GE);
- RETURN_OP_NAME(C_GT);
- RETURN_OP_NAME(C_EQ);
- RETURN_OP_NAME(C_NE);
- RETURN_OP_NAME(C_XOR);
- RETURN_OP_NAME(C_OR);
- RETURN_OP_NAME(C_AND);
- RETURN_OP_NAME(C_ADD);
- RETURN_OP_NAME(C_SUB);
- RETURN_OP_NAME(C_MUL);
- RETURN_OP_NAME(C_DIV);
- RETURN_OP_NAME(C_MOD);
- RETURN_OP_NAME(C_NEG);
- RETURN_OP_NAME(C_LNOT);
- RETURN_OP_NAME(C_NOT);
- RETURN_OP_NAME(C_R_SHIFT);
- RETURN_OP_NAME(C_L_SHIFT);
- default:
- ShowDebug("script_op2name: unexpected op=%d\n", op);
- return "???";
- }
- #undef RETURN_OP_NAME
- }
- #ifdef DEBUG_DUMP_STACK
- static void script_dump_stack(struct script_state* st)
- {
- int i;
- ShowMessage("\tstart = %d\n", st->start);
- ShowMessage("\tend = %d\n", st->end);
- ShowMessage("\tdefsp = %d\n", st->stack->defsp);
- ShowMessage("\tsp = %d\n", st->stack->sp);
- for( i = 0; i < st->stack->sp; ++i )
- {
- struct script_data* data = &st->stack->stack_data[i];
- ShowMessage("\t[%d] %s", i, script_op2name(data->type));
- switch( data->type )
- {
- case C_INT:
- case C_POS:
- ShowMessage(" %d\n", data->u.num);
- break;
- case C_STR:
- case C_CONSTSTR:
- ShowMessage(" \"%s\"\n", data->u.str);
- break;
- case C_NAME:
- ShowMessage(" \"%s\" (id=%d ref=%p subtype=%s)\n", reference_getname(data), data->u.num, data->ref, script_op2name(str_data[data->u.num].type));
- break;
- case C_RETINFO:
- {
- struct script_retinfo* ri = data->u.ri;
- ShowMessage(" %p {var_function=%p, script=%p, pos=%d, nargs=%d, defsp=%d}\n", ri, ri->var_function, ri->script, ri->pos, ri->nargs, ri->defsp);
- }
- break;
- default:
- ShowMessage("\n");
- break;
- }
- }
- }
- #endif
- /// Reports on the console the src of a script error.
- static void script_reportsrc(struct script_state *st)
- {
- struct block_list* bl;
- if( st->oid == 0 )
- return; //Can't report source.
- bl = map_id2bl(st->oid);
- if( bl == NULL )
- return;
- switch( bl->type )
- {
- case BL_NPC:
- if( bl->m >= 0 )
- ShowDebug("Source (NPC): %s at %s (%d,%d)\n", ((struct npc_data *)bl)->name, map[bl->m].name, bl->x, bl->y);
- else
- ShowDebug("Source (NPC): %s (invisible/not on a map)\n", ((struct npc_data *)bl)->name);
- break;
- default:
- if( bl->m >= 0 )
- ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map[bl->m].name, bl->x, bl->y);
- else
- ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl));
- break;
- }
- }
- /// Reports on the console information about the script data.
- static void script_reportdata(struct script_data* data)
- {
- if( data == NULL )
- return;
- switch( data->type )
- {
- case C_NOP:// no value
- ShowDebug("Data: nothing (nil)\n");
- break;
- case C_INT:// number
- ShowDebug("Data: number value=%d\n", data->u.num);
- break;
- case C_STR:
- case C_CONSTSTR:// string
- if( data->u.str )
- {
- ShowDebug("Data: string value=\"%s\"\n", data->u.str);
- }
- else
- {
- ShowDebug("Data: string value=NULL\n");
- }
- break;
- case C_NAME:// reference
- if( reference_tovariable(data) )
- {// variable
- const char* name = reference_getname(data);
- if( not_array_variable(*name) )
- ShowDebug("Data: variable name='%s'\n", name);
- else
- ShowDebug("Data: variable name='%s' index=%d\n", name, reference_getindex(data));
- }
- else if( reference_toconstant(data) )
- {// constant
- ShowDebug("Data: constant name='%s' value=%d\n", reference_getname(data), reference_getconstant(data));
- }
- else if( reference_toparam(data) )
- {// param
- ShowDebug("Data: param name='%s' type=%d\n", reference_getname(data), reference_getparamtype(data));
- }
- else
- {// ???
- ShowDebug("Data: reference name='%s' type=%s\n", reference_getname(data), script_op2name(data->type));
- ShowDebug("Please report this!!! - str_data.type=%s\n", script_op2name(str_data[reference_getid(data)].type));
- }
- break;
- case C_POS:// label
- ShowDebug("Data: label pos=%d\n", data->u.num);
- break;
- default:
- ShowDebug("Data: %s\n", script_op2name(data->type));
- break;
- }
- }
- /// Reports on the console information about the current built-in function.
- static void script_reportfunc(struct script_state* st)
- {
- int i, params, id;
- struct script_data* data;
- if( !script_hasdata(st,0) )
- {// no stack
- return;
- }
- data = script_getdata(st,0);
- if( !data_isreference(data) || str_data[reference_getid(data)].type != C_FUNC )
- {// script currently not executing a built-in function or corrupt stack
- return;
- }
- id = reference_getid(data);
- params = script_lastdata(st)-1;
- if( params > 0 )
- {
- ShowDebug("Function: %s (%d parameter%s):\n", get_str(id), params, ( params == 1 ) ? "" : "s");
- for( i = 2; i <= script_lastdata(st); i++ )
- {
- script_reportdata(script_getdata(st,i));
- }
- }
- else
- {
- ShowDebug("Function: %s (no parameters)\n", get_str(id));
- }
- }
- /*==========================================
- * Output error message
- *------------------------------------------*/
- static void disp_error_message2(const char *mes,const char *pos,int report)
- {
- error_msg = aStrdup(mes);
- error_pos = pos;
- error_report = report;
- longjmp( error_jump, 1 );
- }
- #define disp_error_message(mes,pos) disp_error_message2(mes,pos,1)
- static void disp_warning_message(const char *mes, const char *pos) {
- script_warning(parser_current_src,parser_current_file,parser_current_line,mes,pos);
- }
- /// Checks event parameter validity
- static void check_event(struct script_state *st, const char *evt)
- {
- if( evt && evt[0] && !stristr(evt, "::On") )
- {
- ShowWarning("NPC event parameter deprecated! Please use 'NPCNAME::OnEVENT' instead of '%s'.\n", evt);
- script_reportsrc(st);
- }
- }
- /*==========================================
- * Hashes the input string
- *------------------------------------------*/
- static unsigned int calc_hash(const char* p)
- {
- unsigned int h;
- #if defined(SCRIPT_HASH_DJB2)
- h = 5381;
- while( *p ) // hash*33 + c
- h = ( h << 5 ) + h + ((unsigned char)TOLOWER(*p++));
- #elif defined(SCRIPT_HASH_SDBM)
- h = 0;
- while( *p ) // hash*65599 + c
- h = ( h << 6 ) + ( h << 16 ) - h + ((unsigned char)TOLOWER(*p++));
- #elif defined(SCRIPT_HASH_ELF) // UNIX ELF hash
- h = 0;
- while( *p ){
- unsigned int g;
- h = ( h << 4 ) + ((unsigned char)TOLOWER(*p++));
- g = h & 0xF0000000;
- if( g )
- {
- h ^= g >> 24;
- h &= ~g;
- }
- }
- #else // athena hash
- h = 0;
- while( *p )
- h = ( h << 1 ) + ( h >> 3 ) + ( h >> 5 ) + ( h >> 8 ) + (unsigned char)TOLOWER(*p++);
- #endif
- return h % SCRIPT_HASH_SIZE;
- }
- /*==========================================
- * str_data manipulation functions
- *------------------------------------------*/
- /// Looks up string using the provided id.
- const char* get_str(int id)
- {
- Assert( id >= LABEL_START && id < str_size );
- return str_buf+str_data[id].str;
- }
- /// Returns the uid of the string, or -1.
- static int search_str(const char* p)
- {
- int i;
- for( i = str_hash[calc_hash(p)]; i != 0; i = str_data[i].next )
- if( strcasecmp(get_str(i),p) == 0 )
- return i;
- return -1;
- }
- /// Stores a copy of the string and returns its id.
- /// If an identical string is already present, returns its id instead.
- int add_str(const char* p)
- {
- int i, h;
- int len;
- h = calc_hash(p);
- if( str_hash[h] == 0 )
- {// empty bucket, add new node here
- str_hash[h] = str_num;
- }
- else
- {// scan for end of list, or occurence of identical string
- for( i = str_hash[h]; ; i = str_data[i].next )
- {
- if( strcasecmp(get_str(i),p) == 0 )
- return i; // string already in list
- if( str_data[i].next == 0 )
- break; // reached the end
- }
- // append node to end of list
- str_data[i].next = str_num;
- }
- // grow list if neccessary
- if( str_num >= str_data_size )
- {
- str_data_size += 128;
- RECREATE(str_data,struct str_data_struct,str_data_size);
- memset(str_data + (str_data_size - 128), '\0', 128);
- }
- len=(int)strlen(p);
- // grow string buffer if neccessary
- while( str_pos+len+1 >= str_size )
- {
- str_size += 256;
- RECREATE(str_buf,char,str_size);
- memset(str_buf + (str_size - 256), '\0', 256);
- }
- safestrncpy(str_buf+str_pos, p, len+1);
- str_data[str_num].type = C_NOP;
- str_data[str_num].str = str_pos;
- str_data[str_num].next = 0;
- str_data[str_num].func = NULL;
- str_data[str_num].backpatch = -1;
- str_data[str_num].label = -1;
- str_pos += len+1;
- return str_num++;
- }
- /// Appends 1 byte to the script buffer.
- static void add_scriptb(int a)
- {
- if( script_pos+1 >= script_size )
- {
- script_size += SCRIPT_BLOCK_SIZE;
- RECREATE(script_buf,unsigned char,script_size);
- }
- script_buf[script_pos++] = (uint8)(a);
- }
- /// Appends a c_op value to the script buffer.
- /// The value is variable-length encoded into 8-bit blocks.
- /// The encoding scheme is ( 01?????? )* 00??????, LSB first.
- /// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
- static void add_scriptc(int a)
- {
- while( a >= 0x40 )
- {
- add_scriptb((a&0x3f)|0x40);
- a = (a - 0x40) >> 6;
- }
- add_scriptb(a);
- }
- /// Appends an integer value to the script buffer.
- /// The value is variable-length encoded into 8-bit blocks.
- /// The encoding scheme is ( 11?????? )* 10??????, LSB first.
- /// All blocks but the last hold 7 bits of data, topmost bit is always 1 (carries).
- static void add_scripti(int a)
- {
- while( a >= 0x40 )
- {
- add_scriptb((a&0x3f)|0xc0);
- a = (a - 0x40) >> 6;
- }
- add_scriptb(a|0x80);
- }
- /// Appends a str_data object (label/function/variable/integer) to the script buffer.
- ///
- /// @param l The id of the str_data entry
- // Maximum up to 16M
- static void add_scriptl(int l)
- {
- int backpatch = str_data[l].backpatch;
- switch(str_data[l].type){
- case C_POS:
- case C_USERFUNC_POS:
- add_scriptc(C_POS);
- add_scriptb(str_data[l].label);
- add_scriptb(str_data[l].label>>8);
- add_scriptb(str_data[l].label>>16);
- break;
- case C_NOP:
- case C_USERFUNC:
- // Embedded data backpatch there is a possibility of label
- add_scriptc(C_NAME);
- str_data[l].backpatch = script_pos;
- add_scriptb(backpatch);
- add_scriptb(backpatch>>8);
- add_scriptb(backpatch>>16);
- break;
- case C_INT:
- add_scripti(abs(str_data[l].val));
- if( str_data[l].val < 0 ) //Notice that this is negative, from jA (Rayce)
- add_scriptc(C_NEG);
- break;
- default: // assume C_NAME
- add_scriptc(C_NAME);
- add_scriptb(l);
- add_scriptb(l>>8);
- add_scriptb(l>>16);
- break;
- }
- }
- /*==========================================
- * Resolve the label
- *------------------------------------------*/
- void set_label(int l,int pos, const char* script_pos)
- {
- int i,next;
- if(str_data[l].type==C_INT || str_data[l].type==C_PARAM || str_data[l].type==C_FUNC)
- { //Prevent overwriting constants values, parameters and built-in functions [Skotlex]
- disp_error_message("set_label: invalid label name",script_pos);
- return;
- }
- if(str_data[l].label!=-1){
- disp_error_message("set_label: dup label ",script_pos);
- return;
- }
- str_data[l].type=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
- str_data[l].label=pos;
- for(i=str_data[l].backpatch;i>=0 && i!=0x00ffffff;){
- next=GETVALUE(script_buf,i);
- script_buf[i-1]=(str_data[l].type == C_USERFUNC ? C_USERFUNC_POS : C_POS);
- SETVALUE(script_buf,i,pos);
- i=next;
- }
- }
- /// Skips spaces and/or comments.
- const char* skip_space(const char* p)
- {
- if( p == NULL )
- return NULL;
- for(;;)
- {
- while( ISSPACE(*p) )
- ++p;
- if( *p == '/' && p[1] == '/' )
- {// line comment
- while(*p && *p!='\n')
- ++p;
- }
- else if( *p == '/' && p[1] == '*' )
- {// block comment
- p += 2;
- for(;;)
- {
- if( *p == '\0' ) {
- disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
- return p;
- }
- if( *p == '*' && p[1] == '/' )
- {// end of block comment
- p += 2;
- break;
- }
- ++p;
- }
- }
- else
- break;
- }
- return p;
- }
- /// Skips a word.
- /// A word consists of undercores and/or alphanumeric characters,
- /// and valid variable prefixes/postfixes.
- static
- const char* skip_word(const char* p)
- {
- // prefix
- switch( *p )
- {
- case '@':// temporary char variable
- ++p; break;
- case '#':// account variable
- p += ( p[1] == '#' ? 2 : 1 ); break;
- case '\'':// instance variable
- ++p; break;
- case '.':// npc variable
- p += ( p[1] == '@' ? 2 : 1 ); break;
- case '$':// global variable
- p += ( p[1] == '@' ? 2 : 1 ); break;
- }
- while( ISALNUM(*p) || *p == '_' )
- ++p;
- // postfix
- if( *p == '$' )// string
- p++;
- return p;
- }
- /// Adds a word to str_data.
- /// @see skip_word
- /// @see add_str
- static
- int add_word(const char* p)
- {
- char* word;
- int len;
- int i;
- // Check for a word
- len = skip_word(p) - p;
- if( len == 0 )
- disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alphanumeric characters, and valid variable prefixes/postfixes.", p);
- // Duplicate the word
- word = (char*)aMalloc(len+1);
- memcpy(word, p, len);
- word[len] = 0;
- // add the word
- i = add_str(word);
- aFree(word);
- return i;
- }
- /// Parses a function call.
- /// The argument list can have parenthesis or not.
- /// The number of arguments is checked.
- static
- const char* parse_callfunc(const char* p, int require_paren, int is_custom)
- {
- const char* p2;
- const char* arg=NULL;
- int func;
- func = add_word(p);
- if( str_data[func].type == C_FUNC ){
- // buildin function
- add_scriptl(func);
- add_scriptc(C_ARG);
- arg = buildin_func[str_data[func].val].arg;
- } else if( str_data[func].type == C_USERFUNC || str_data[func].type == C_USERFUNC_POS ){
- // script defined function
- add_scriptl(buildin_callsub_ref);
- add_scriptc(C_ARG);
- add_scriptl(func);
- arg = buildin_func[str_data[buildin_callsub_ref].val].arg;
- if( *arg == 0 )
- disp_error_message("parse_callfunc: callsub has no arguments, please review its definition",p);
- if( *arg != '*' )
- ++arg; // count func as argument
- } else {
- #ifdef SCRIPT_CALLFUNC_CHECK
- const char* name = get_str(func);
- if( !is_custom && strdb_get(userfunc_db, name) == NULL ) {
- #endif
- disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p);
- #ifdef SCRIPT_CALLFUNC_CHECK
- } else {;
- add_scriptl(buildin_callfunc_ref);
- add_scriptc(C_ARG);
- add_scriptc(C_STR);
- while( *name ) add_scriptb(*name ++);
- add_scriptb(0);
- arg = buildin_func[str_data[buildin_callfunc_ref].val].arg;
- if( *arg != '*' ) ++ arg;
- }
- #endif
- }
- p = skip_word(p);
- p = skip_space(p);
- syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
- syntax.curly[syntax.curly_count].count = 0;
- if( *p == ';' )
- {// <func name> ';'
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- } else if( *p == '(' && *(p2=skip_space(p+1)) == ')' )
- {// <func name> '(' ')'
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
- p = p2;
- /*
- } else if( 0 && require_paren && *p != '(' )
- {// <func name>
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- */
- } else
- {// <func name> <arg list>
- if( require_paren ){
- if( *p != '(' )
- disp_error_message("need '('",p);
- ++p; // skip '('
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
- } else if( *p == '(' ){
- syntax.curly[syntax.curly_count].flag = ARGLIST_UNDEFINED;
- } else {
- syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- }
- ++syntax.curly_count;
- while( *arg ) {
- p2=parse_subexpr(p,-1);
- if( p == p2 )
- break; // not an argument
- if( *arg != '*' )
- ++arg; // next argument
- p=skip_space(p2);
- if( *arg == 0 || *p != ',' )
- break; // no more arguments
- ++p; // skip comma
- }
- --syntax.curly_count;
- }
- if( *arg && *arg != '?' && *arg != '*' )
- disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script_config.warn_func_mismatch_paramnum);
- if( syntax.curly[syntax.curly_count].type != TYPE_ARGLIST )
- disp_error_message("parse_callfunc: DEBUG last curly is not an argument list",p);
- if( syntax.curly[syntax.curly_count].flag == ARGLIST_PAREN ){
- if( *p != ')' )
- disp_error_message("parse_callfunc: expected ')' to close argument list",p);
- ++p;
- }
- add_scriptc(C_FUNC);
- return p;
- }
- /// Processes end of logical script line.
- /// @param first When true, only fix up scheduling data is initialized
- /// @param p Script position for error reporting in set_label
- static void parse_nextline(bool first, const char* p)
- {
- if( !first )
- {
- add_scriptc(C_EOL); // mark end of line for stack cleanup
- set_label(LABEL_NEXTLINE, script_pos, p); // fix up '-' labels
- }
- // initialize data for new '-' label fix up scheduling
- str_data[LABEL_NEXTLINE].type = C_NOP;
- str_data[LABEL_NEXTLINE].backpatch = -1;
- str_data[LABEL_NEXTLINE].label = -1;
- }
- /// Parse a variable assignment using the direct equals operator
- /// @param p script position where the function should run from
- /// @return NULL if not a variable assignment, the new position otherwise
- const char* parse_variable(const char* p) {
- int i, j, word;
- c_op type = C_NOP;
- const char *p2 = NULL;
- const char *var = p;
- // skip the variable where applicable
- p = skip_word(p);
- p = skip_space(p);
- if( p == NULL ) {// end of the line or invalid buffer
- return NULL;
- }
- if( *p == '[' ) {// array variable so process the array as appropriate
- for( p2 = p, i = 0, j = 1; p; ++ i ) {
- if( *p ++ == ']' && --(j) == 0 ) break;
- if( *p == '[' ) ++ j;
- }
- if( !(p = skip_space(p)) ) {// end of line or invalid characters remaining
- disp_error_message("Missing right expression or closing bracket for variable.", p);
- }
- }
- if( type == C_NOP &&
- !( ( p[0] == '=' && p[1] != '=' && (type = C_EQ) ) // =
- || ( p[0] == '+' && p[1] == '=' && (type = C_ADD) ) // +=
- || ( p[0] == '-' && p[1] == '=' && (type = C_SUB) ) // -=
- || ( p[0] == '^' && p[1] == '=' && (type = C_XOR) ) // ^=
- || ( p[0] == '|' && p[1] == '=' && (type = C_OR ) ) // |=
- || ( p[0] == '&' && p[1] == '=' && (type = C_AND) ) // &=
- || ( p[0] == '*' && p[1] == '=' && (type = C_MUL) ) // *=
- || ( p[0] == '/' && p[1] == '=' && (type = C_DIV) ) // /=
- || ( p[0] == '%' && p[1] == '=' && (type = C_MOD) ) // %=
- || ( p[0] == '~' && p[1] == '=' && (type = C_NOT) ) // ~=
- || ( p[0] == '+' && p[1] == '+' && (type = C_ADD_PP) ) // ++
- || ( p[0] == '-' && p[1] == '-' && (type = C_SUB_PP) ) // --
- || ( p[0] == '<' && p[1] == '<' && p[2] == '=' && (type = C_L_SHIFT) ) // <<=
- || ( p[0] == '>' && p[1] == '>' && p[2] == '=' && (type = C_R_SHIFT) ) // >>=
- ) )
- {// failed to find a matching operator combination so invalid
- return NULL;
- }
- switch( type ) {
- case C_EQ: {// incremental modifier
- p = skip_space( &p[1] );
- }
- break;
- case C_L_SHIFT:
- case C_R_SHIFT: {// left or right shift modifier
- p = skip_space( &p[3] );
- }
- break;
- default: {// normal incremental command
- p = skip_space( &p[2] );
- }
- }
- if( p == NULL ) {// end of line or invalid buffer
- return NULL;
- }
- // push the set function onto the stack
- add_scriptl(buildin_set_ref);
- add_scriptc(C_ARG);
- // always append parenthesis to avoid errors
- syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
- syntax.curly[syntax.curly_count].count = 0;
- syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
- // increment the total curly count for the position in the script
- ++ syntax.curly_count;
- // parse the variable currently being modified
- word = add_word(var);
- if( str_data[word].type == C_FUNC || str_data[word].type == C_USERFUNC || str_data[word].type == C_USERFUNC_POS )
- {// cannot assign a variable which exists as a function or label
- disp_error_message("Cannot modify a variable which has the same name as a function or label.", p);
- }
- if( p2 ) {// process the variable index
- const char* p3 = NULL;
- // push the getelementofarray method into the stack
- add_scriptl(buildin_getelementofarray_ref);
- add_scriptc(C_ARG);
- add_scriptl(word);
- // process the sub-expression for this assignment
- p3 = parse_subexpr(p2 + 1, 1);
- p3 = skip_space(p3);
- if( *p3 != ']' ) {// closing parenthesis is required for this script
- disp_error_message("Missing closing ']' parenthesis for the variable assignment.", p3);
- }
- // push the closing function stack operator onto the stack
- add_scriptc(C_FUNC);
- p3 ++;
- } else {// simply push the variable or value onto the stack
- add_scriptl(word);
- }
- if( type != C_EQ )
- add_scriptc(C_REF);
- if( type == C_ADD_PP || type == C_SUB_PP ) {// incremental operator for the method
- add_scripti(1);
- add_scriptc(type == C_ADD_PP ? C_ADD : C_SUB);
- } else {// process the value as an expression
- p = parse_subexpr(p, -1);
- if( type != C_EQ )
- {// push the type of modifier onto the stack
- add_scriptc(type);
- }
- }
- // decrement the curly count for the position within the script
- -- syntax.curly_count;
- // close the script by appending the function operator
- add_scriptc(C_FUNC);
- // push the buffer from the method
- return p;
- }
- /*==========================================
- * Analysis section
- *------------------------------------------*/
- const char* parse_simpleexpr(const char *p)
- {
- long long i;
- p=skip_space(p);
- if(*p==';' || *p==',')
- disp_error_message("parse_simpleexpr: unexpected end of expression",p);
- if(*p=='('){
- if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST )
- ++syntax.curly[i].count;
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
- if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST &&
- syntax.curly[i].flag == ARGLIST_UNDEFINED && --syntax.curly[i].count == 0
- ){
- if( *p == ',' ){
- syntax.curly[i].flag = ARGLIST_PAREN;
- return p;
- } else
- syntax.curly[i].flag = ARGLIST_NO_PAREN;
- }
- if( *p != ')' )
- disp_error_message("parse_simpleexpr: unmatched ')'",p);
- ++p;
- } else if(ISDIGIT(*p) || ((*p=='-' || *p=='+') && ISDIGIT(p[1]))){
- char *np;
- while(*p == '0' && ISDIGIT(p[1])) p++;
- i=strtoll(p,&np,0);
- if( i < INT_MIN ) {
- i = INT_MIN;
- disp_warning_message("parse_simpleexpr: underflow detected, capping value to INT_MIN",p);
- } else if( i > INT_MAX ) {
- i = INT_MAX;
- disp_warning_message("parse_simpleexpr: overflow detected, capping value to INT_MAX",p);
- }
- add_scripti((int)i);
- p=np;
- } else if(*p=='"'){
- add_scriptc(C_STR);
- p++;
- while( *p && *p != '"' ){
- if( (unsigned char)p[-1] <= 0x7e && *p == '\\' )
- {
- char buf[8];
- size_t len = skip_escaped_c(p) - p;
- size_t n = sv_unescape_c(buf, p, len);
- if( n != 1 )
- ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf);
- p += len;
- add_scriptb(*buf);
- continue;
- }
- else if( *p == '\n' )
- disp_error_message("parse_simpleexpr: unexpected newline @ string",p);
- add_scriptb(*p++);
- }
- if(!*p)
- disp_error_message("parse_simpleexpr: unexpected eof @ string",p);
- add_scriptb(0);
- p++; //'"'
- } else {
- int l;
- const char* pv;
- // label , register , function etc
- if(skip_word(p)==p)
- disp_error_message("parse_simpleexpr: unexpected character",p);
- l=add_word(p);
- if( str_data[l].type == C_FUNC || str_data[l].type == C_USERFUNC || str_data[l].type == C_USERFUNC_POS)
- return parse_callfunc(p,1,0);
- #ifdef SCRIPT_CALLFUNC_CHECK
- else {
- const char* name = get_str(l);
- if( strdb_get(userfunc_db,name) != NULL ) {
- return parse_callfunc(p,1,1);
- }
- }
- #endif
- if( (pv = parse_variable(p)) )
- {// successfully processed a variable assignment
- return pv;
- }
- p=skip_word(p);
- if( *p == '[' ){
- // array(name[i] => getelementofarray(name,i) )
- add_scriptl(buildin_getelementofarray_ref);
- add_scriptc(C_ARG);
- add_scriptl(l);
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
- if( *p != ']' )
- disp_error_message("parse_simpleexpr: unmatched ']'",p);
- ++p;
- add_scriptc(C_FUNC);
- }else
- add_scriptl(l);
- }
- return p;
- }
- /*==========================================
- * Analysis of the expression
- *------------------------------------------*/
- const char* parse_subexpr(const char* p,int limit)
- {
- int op,opl,len;
- const char* tmpp;
- p=skip_space(p);
- if( *p == '-' ){
- tmpp = skip_space(p+1);
- if( *tmpp == ';' || *tmpp == ',' ){
- add_scriptl(LABEL_NEXTLINE);
- p++;
- return p;
- }
- }
- if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
- p=parse_subexpr(p+1,10);
- add_scriptc(op);
- } else
- p=parse_simpleexpr(p);
- p=skip_space(p);
- while((
- (op=C_OP3,opl=0,len=1,*p=='?') ||
- (op=C_ADD,opl=8,len=1,*p=='+') ||
- (op=C_SUB,opl=8,len=1,*p=='-') ||
- (op=C_MUL,opl=9,len=1,*p=='*') ||
- (op=C_DIV,opl=9,len=1,*p=='/') ||
- (op=C_MOD,opl=9,len=1,*p=='%') ||
- (op=C_LAND,opl=2,len=2,*p=='&' && p[1]=='&') ||
- (op=C_AND,opl=6,len=1,*p=='&') ||
- (op=C_LOR,opl=1,len=2,*p=='|' && p[1]=='|') ||
- (op=C_OR,opl=5,len=1,*p=='|') ||
- (op=C_XOR,opl=4,len=1,*p=='^') ||
- (op=C_EQ,opl=3,len=2,*p=='=' && p[1]=='=') ||
- (op=C_NE,opl=3,len=2,*p=='!' && p[1]=='=') ||
- (op=C_R_SHIFT,opl=7,len=2,*p=='>' && p[1]=='>') ||
- (op=C_GE,opl=3,len=2,*p=='>' && p[1]=='=') ||
- (op=C_GT,opl=3,len=1,*p=='>') ||
- (op=C_L_SHIFT,opl=7,len=2,*p=='<' && p[1]=='<') ||
- (op=C_LE,opl=3,len=2,*p=='<' && p[1]=='=') ||
- (op=C_LT,opl=3,len=1,*p=='<')) && opl>limit){
- p+=len;
- if(op == C_OP3) {
- p=parse_subexpr(p,-1);
- p=skip_space(p);
- if( *(p++) != ':')
- disp_error_message("parse_subexpr: expected ':'", p-1);
- p=parse_subexpr(p,-1);
- } else {
- p=parse_subexpr(p,opl);
- }
- add_scriptc(op);
- p=skip_space(p);
- }
- return p; /* return first untreated operator */
- }
- /*==========================================
- * Evaluation of the expression
- *------------------------------------------*/
- const char* parse_expr(const char *p)
- {
- switch(*p){
- case ')': case ';': case ':': case '[': case ']':
- case '}':
- disp_error_message("parse_expr: unexpected character",p);
- }
- p=parse_subexpr(p,-1);
- return p;
- }
- /*==========================================
- * Analysis of the line
- *------------------------------------------*/
- const char* parse_line(const char* p)
- {
- const char* p2;
- p=skip_space(p);
- if(*p==';') {
- //Close decision for if(); for(); while();
- p = parse_syntax_close(p + 1);
- return p;
- }
- if(*p==')' && parse_syntax_for_flag)
- return p+1;
- p = skip_space(p);
- if(p[0] == '{') {
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- syntax.curly[syntax.curly_count].count = -1;
- syntax.curly[syntax.curly_count].index = -1;
- syntax.curly_count++;
- return p + 1;
- } else if(p[0] == '}') {
- return parse_curly_close(p);
- }
- // Syntax-related processing
- p2 = parse_syntax(p);
- if(p2 != NULL)
- return p2;
- // attempt to process a variable assignment
- p2 = parse_variable(p);
- if( p2 != NULL )
- {// variable assignment processed so leave the method
- return parse_syntax_close(p2 + 1);
- }
- p = parse_callfunc(p,0,0);
- p = skip_space(p);
- if(parse_syntax_for_flag) {
- if( *p != ')' )
- disp_error_message("parse_line: expected ')'",p);
- } else {
- if( *p != ';' )
- disp_error_message("parse_line: expected ';'",p);
- }
- //Binding decision for if(), for(), while()
- p = parse_syntax_close(p+1);
- return p;
- }
- // { ... } Closing process
- const char* parse_curly_close(const char* p)
- {
- if(syntax.curly_count <= 0) {
- disp_error_message("parse_curly_close: unexpected string",p);
- return p + 1;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_NULL) {
- syntax.curly_count--;
- //Close decision if, for , while
- p = parse_syntax_close(p + 1);
- return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_SWITCH) {
- //Closing switch()
- int pos = syntax.curly_count-1;
- char label[256];
- int l;
- // Remove temporary variables
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Go to the end pointer unconditionally
- sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // You are here labeled
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos, p);
- if(syntax.curly[pos].flag) {
- //Exists default
- sprintf(label,"goto __SW%x_DEF;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- // Label end
- sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos, p);
- linkdb_final(&syntax.curly[pos].case_label); // free the list of case label
- syntax.curly_count--;
- //Closing decision if, for , while
- p = parse_syntax_close(p + 1);
- return p;
- } else {
- disp_error_message("parse_curly_close: unexpected string",p);
- return p + 1;
- }
- }
- // Syntax-related processing
- // break, case, continue, default, do, for, function,
- // if, switch, while ? will handle this internally.
- const char* parse_syntax(const char* p)
- {
- const char *p2 = skip_word(p);
- switch(*p) {
- case 'B':
- case 'b':
- if(p2 - p == 5 && !strncasecmp(p,"break",5)) {
- // break Processing
- char label[256];
- int pos = syntax.curly_count - 1;
- while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_FIN;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_SWITCH) {
- sprintf(label,"goto __SW%x_FIN;",syntax.curly[pos].index);
- break;
- }
- pos--;
- }
- if(pos < 0) {
- disp_error_message("parse_syntax: unexpected 'break'",p);
- } else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- p = skip_space(p2);
- if(*p != ';')
- disp_error_message("parse_syntax: expected ';'",p);
- // Closing decision if, for , while
- p = parse_syntax_close(p + 1);
- return p;
- }
- break;
- case 'c':
- case 'C':
- if(p2 - p == 4 && !strncasecmp(p,"case",4)) {
- //Processing case
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
- disp_error_message("parse_syntax: unexpected 'case' ",p);
- return p+1;
- } else {
- char label[256];
- int l,v;
- char *np;
- if(syntax.curly[pos].count != 1) {
- //Jump for FALLTHRU
- sprintf(label,"goto __SW%x_%xJ;",syntax.curly[pos].index,syntax.curly[pos].count);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // You are here labeled
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos, p);
- }
- //Decision statement switch
- p = skip_space(p2);
- if(p == p2) {
- disp_error_message("parse_syntax: expected a space ' '",p);
- }
- // check whether case label is integer or not
- v = strtol(p,&np,0);
- if(np == p) { //Check for constants
- p2 = skip_word(p);
- v = p2-p; // length of word at p2
- memcpy(label,p,v);
- label[v]='\0';
- if( !script_get_constant(label, &v) )
- disp_error_message("parse_syntax: 'case' label is not an integer",p);
- p = skip_word(p);
- } else { //Numeric value
- if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
- p++;
- p = skip_word(p);
- if(np != p)
- disp_error_message("parse_syntax: 'case' label is not an integer",np);
- }
- p = skip_space(p);
- if(*p != ':')
- disp_error_message("parse_syntax: expect ':'",p);
- sprintf(label,"if(%d != $@__SW%x_VAL) goto __SW%x_%x;",
- v,syntax.curly[pos].index,syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- // Bad I do not parse twice
- p2 = parse_line(label);
- parse_line(p2);
- syntax.curly_count--;
- if(syntax.curly[pos].count != 1) {
- // Label after the completion of FALLTHRU
- sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- }
- // check duplication of case label [Rayce]
- if(linkdb_search(&syntax.curly[pos].case_label, (void*)__64BPRTSIZE(v)) != NULL)
- disp_error_message("parse_syntax: dup 'case'",p);
- linkdb_insert(&syntax.curly[pos].case_label, (void*)__64BPRTSIZE(v), (void*)1);
- sprintf(label,"set $@__SW%x_VAL,0;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- syntax.curly[pos].count++;
- }
- return p + 1;
- } else if(p2 - p == 8 && !strncasecmp(p,"continue",8)) {
- // Processing continue
- char label[256];
- int pos = syntax.curly_count - 1;
- while(pos >= 0) {
- if(syntax.curly[pos].type == TYPE_DO) {
- sprintf(label,"goto __DO%x_NXT;",syntax.curly[pos].index);
- syntax.curly[pos].flag = 1; //Flag put the link for continue
- break;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
- break;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
- break;
- }
- pos--;
- }
- if(pos < 0) {
- disp_error_message("parse_syntax: unexpected 'continue'",p);
- } else {
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- }
- p = skip_space(p2);
- if(*p != ';')
- disp_error_message("parse_syntax: expected ';'",p);
- //Closing decision if, for , while
- p = parse_syntax_close(p + 1);
- return p;
- }
- break;
- case 'd':
- case 'D':
- if(p2 - p == 7 && !strncasecmp(p,"default",7)) {
- // Switch - default processing
- int pos = syntax.curly_count-1;
- if(pos < 0 || syntax.curly[pos].type != TYPE_SWITCH) {
- disp_error_message("parse_syntax: unexpected 'default'",p);
- } else if(syntax.curly[pos].flag) {
- disp_error_message("parse_syntax: dup 'default'",p);
- } else {
- char label[256];
- int l;
- // Put the label location
- p = skip_space(p2);
- if(*p != ':') {
- disp_error_message("parse_syntax: expected ':'",p);
- }
- sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- // Skip to the next link w/o condition
- sprintf(label,"goto __SW%x_%x;",syntax.curly[pos].index,syntax.curly[pos].count+1);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // The default label
- sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly[syntax.curly_count - 1].flag = 1;
- syntax.curly[pos].count++;
- }
- return p + 1;
- } else if(p2 - p == 2 && !strncasecmp(p,"do",2)) {
- int l;
- char label[256];
- p=skip_space(p2);
- syntax.curly[syntax.curly_count].type = TYPE_DO;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- // Label of the (do) form here
- sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count++;
- return p;
- }
- break;
- case 'f':
- case 'F':
- if(p2 - p == 3 && !strncasecmp(p,"for",3)) {
- int l;
- char label[256];
- int pos = syntax.curly_count;
- syntax.curly[syntax.curly_count].type = TYPE_FOR;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- syntax.curly_count++;
- p=skip_space(p2);
- if(*p != '(')
- disp_error_message("parse_syntax: expected '('",p);
- p++;
- // Execute the initialization statement
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
- // Form the start of label decision
- sprintf(label,"__FR%x_J",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- p=skip_space(p);
- if(*p == ';') {
- // For (; Because the pattern of always true ;)
- ;
- } else {
- // Skip to the end point if the condition is false
- sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- }
- if(*p != ';')
- disp_error_message("parse_syntax: expected ';'",p);
- p++;
- // Skip to the beginning of the loop
- sprintf(label,"goto __FR%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Labels to form the next loop
- sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- // Process the next time you enter the loop
- // A ')' last for; flag to be treated as'
- parse_syntax_for_flag = 1;
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- p=parse_line(p);
- syntax.curly_count--;
- parse_syntax_for_flag = 0;
- // Skip to the determination process conditions
- sprintf(label,"goto __FR%x_J;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Loop start labeling
- sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- return p;
- }
- else if( p2 - p == 8 && strncasecmp(p,"function",8) == 0 )
- {// internal script function
- const char *func_name;
- func_name = skip_space(p2);
- p = skip_word(func_name);
- if( p == func_name )
- disp_error_message("parse_syntax:function: function name is missing or invalid", p);
- p2 = skip_space(p);
- if( *p2 == ';' )
- {// function <name> ;
- // function declaration - just register the name
- int l;
- l = add_word(func_name);
- if( str_data[l].type == C_NOP )// register only, if the name was not used by something else
- str_data[l].type = C_USERFUNC;
- else if( str_data[l].type == C_USERFUNC )
- ; // already registered
- else
- disp_error_message("parse_syntax:function: function name is invalid", func_name);
- // Close condition of if, for, while
- p = parse_syntax_close(p2 + 1);
- return p;
- }
- else if(*p2 == '{')
- {// function <name> <line/block of code>
- char label[256];
- int l;
- syntax.curly[syntax.curly_count].type = TYPE_USERFUNC;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- ++syntax.curly_count;
- // Jump over the function code
- sprintf(label, "goto __FN%x_FIN;", syntax.curly[syntax.curly_count-1].index);
- syntax.curly[syntax.curly_count].type = TYPE_NULL;
- ++syntax.curly_count;
- parse_line(label);
- --syntax.curly_count;
- // Set the position of the function (label)
- l=add_word(func_name);
- if( str_data[l].type == C_NOP || str_data[l].type == C_USERFUNC )// register only, if the name was not used by something else
- {
- str_data[l].type = C_USERFUNC;
- set_label(l, script_pos, p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- strdb_iput(scriptlabel_db, get_str(l), script_pos);
- }
- else
- disp_error_message("parse_syntax:function: function name is invalid", func_name);
- return skip_space(p);
- }
- else
- {
- disp_error_message("expect ';' or '{' at function syntax",p);
- }
- }
- break;
- case 'i':
- case 'I':
- if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
- // If process
- char label[256];
- p=skip_space(p2);
- if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_IF;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
- syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- return p;
- }
- break;
- case 's':
- case 'S':
- if(p2 - p == 6 && !strncasecmp(p,"switch",6)) {
- // Processing of switch ()
- char label[256];
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_SWITCH;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(add_str("set"));
- add_scriptc(C_ARG);
- add_scriptl(add_str(label));
- p=parse_expr(p);
- p=skip_space(p);
- if(*p != '{') {
- disp_error_message("parse_syntax: expected '{'",p);
- }
- add_scriptc(C_FUNC);
- return p + 1;
- }
- break;
- case 'w':
- case 'W':
- if(p2 - p == 5 && !strncasecmp(p,"while",5)) {
- int l;
- char label[256];
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- syntax.curly[syntax.curly_count].type = TYPE_WHILE;
- syntax.curly[syntax.curly_count].count = 1;
- syntax.curly[syntax.curly_count].index = syntax.index++;
- syntax.curly[syntax.curly_count].flag = 0;
- // Form the start of label decision
- sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- // Skip to the end point if the condition is false
- sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
- syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- return p;
- }
- break;
- }
- return NULL;
- }
- const char* parse_syntax_close(const char *p) {
- // If (...) for (...) hoge (); as to make sure closed closed once again
- int flag;
- do {
- p = parse_syntax_close_sub(p,&flag);
- } while(flag);
- return p;
- }
- // Close judgment if, for, while, of do
- // flag == 1 : closed
- // flag == 0 : not closed
- const char* parse_syntax_close_sub(const char* p,int* flag)
- {
- char label[256];
- int pos = syntax.curly_count - 1;
- int l;
- *flag = 1;
- if(syntax.curly_count <= 0) {
- *flag = 0;
- return p;
- } else if(syntax.curly[pos].type == TYPE_IF) {
- const char *bp = p;
- const char *p2;
- // if-block and else-block end is a new line
- parse_nextline(false, p);
- // Skip to the last location if
- sprintf(label,"goto __IF%x_FIN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Put the label of the location
- sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly[pos].count++;
- p = skip_space(p);
- p2 = skip_word(p);
- if(!syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) {
- // else or else - if
- p = skip_space(p2);
- p2 = skip_word(p);
- if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
- // else - if
- p=skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- *flag = 0;
- return p;
- } else {
- // else
- if(!syntax.curly[pos].flag) {
- syntax.curly[pos].flag = 1;
- *flag = 0;
- return p;
- }
- }
- }
- // Close if
- syntax.curly_count--;
- // Put the label of the final location
- sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- if(syntax.curly[pos].flag == 1) {
- // Because the position of the pointer is the same if not else for this
- return bp;
- }
- return p;
- } else if(syntax.curly[pos].type == TYPE_DO) {
- int l;
- char label[256];
- const char *p2;
- if(syntax.curly[pos].flag) {
- // (Come here continue) to form the label here
- sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- }
- // Skip to the end point if the condition is false
- p = skip_space(p);
- p2 = skip_word(p);
- if(p2 - p != 5 || strncasecmp(p,"while",5))
- disp_error_message("parse_syntax: expected 'while'",p);
- p = skip_space(p2);
- if(*p != '(') {
- disp_error_message("need '('",p);
- }
- // do-block end is a new line
- parse_nextline(false, p);
- sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
- add_scriptc(C_ARG);
- p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
- add_scriptc(C_FUNC);
- // Skip to the starting point
- sprintf(label,"goto __DO%x_BGN;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Form label of the end point conditions
- sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- p = skip_space(p);
- if(*p != ';') {
- disp_error_message("parse_syntax: expected ';'",p);
- return p+1;
- }
- p++;
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[pos].type == TYPE_FOR) {
- // for-block end is a new line
- parse_nextline(false, p);
- // Skip to the next loop
- sprintf(label,"goto __FR%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // End for labeling
- sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[pos].type == TYPE_WHILE) {
- // while-block end is a new line
- parse_nextline(false, p);
- // Skip to the decision while
- sprintf(label,"goto __WL%x_NXT;",syntax.curly[pos].index);
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // End while labeling
- sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else if(syntax.curly[syntax.curly_count-1].type == TYPE_USERFUNC) {
- int pos = syntax.curly_count-1;
- char label[256];
- int l;
- // Back
- sprintf(label,"return;");
- syntax.curly[syntax.curly_count++].type = TYPE_NULL;
- parse_line(label);
- syntax.curly_count--;
- // Put the label of the location
- sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
- set_label(l,script_pos,p);
- syntax.curly_count--;
- return p;
- } else {
- *flag = 0;
- return p;
- }
- }
- /*==========================================
- * Added built-in functions
- *------------------------------------------*/
- static void add_buildin_func(void)
- {
- int i,n;
- const char* p;
- for( i = 0; buildin_func[i].func; i++ )
- {
- // arg must follow the pattern: (v|s|i|r|l)*\?*\*?
- // 'v' - value (either string or int or reference)
- // 's' - string
- // 'i' - int
- // 'r' - reference (of a variable)
- // 'l' - label
- // '?' - one optional parameter
- // '*' - unknown number of optional parameters
- p = buildin_func[i].arg;
- while( *p == 'v' || *p == 's' || *p == 'i' || *p == 'r' || *p == 'l' ) ++p;
- while( *p == '?' ) ++p;
- if( *p == '*' ) ++p;
- if( *p != 0){
- ShowWarning("add_buildin_func: ignoring function \"%s\" with invalid arg \"%s\".\n", buildin_func[i].name, buildin_func[i].arg);
- } else if( *skip_word(buildin_func[i].name) != 0 ){
- ShowWarning("add_buildin_func: ignoring function with invalid name \"%s\" (must be a word).\n", buildin_func[i].name);
- } else {
- n = add_str(buildin_func[i].name);
- str_data[n].type = C_FUNC;
- str_data[n].val = i;
- str_data[n].func = buildin_func[i].func;
- if (!strcmp(buildin_func[i].name, "set")) buildin_set_ref = n;
- else if (!strcmp(buildin_func[i].name, "callsub")) buildin_callsub_ref = n;
- else if (!strcmp(buildin_func[i].name, "callfunc")) buildin_callfunc_ref = n;
- else if( !strcmp(buildin_func[i].name, "getelementofarray") ) buildin_getelementofarray_ref = n;
- }
- }
- }
- /// Retrieves the value of a constant.
- bool script_get_constant(const char* name, int* value)
- {
- int n = search_str(name);
- if( n == -1 || str_data[n].type != C_INT )
- {// not found or not a constant
- return false;
- }
- value[0] = str_data[n].val;
- return true;
- }
- /// Creates new constant or parameter with given value.
- void script_set_constant(const char* name, int value, bool isparameter)
- {
- int n = add_str(name);
- if( str_data[n].type == C_NOP )
- {// new
- str_data[n].type = isparameter ? C_PARAM : C_INT;
- str_data[n].val = value;
- }
- else if( str_data[n].type == C_PARAM || str_data[n].type == C_INT )
- {// existing parameter or constant
- ShowError("script_set_constant: Attempted to overwrite existing %s '%s' (old value=%d, new value=%d).\n", ( str_data[n].type == C_PARAM ) ? "parameter" : "constant", name, str_data[n].val, value);
- }
- else
- {// existing name
- ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", isparameter ? "parameter" : "constant", name, script_op2name(str_data[n].type));
- }
- }
- /*==========================================
- * Reading constant databases
- * const.txt
- *------------------------------------------*/
- static void read_constdb(void)
- {
- FILE *fp;
- char line[1024],name[1024],val[1024];
- int type;
- sprintf(line, "%s/const.txt", db_path);
- fp=fopen(line, "r");
- if(fp==NULL){
- ShowError("can't read %s\n", line);
- return ;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0]=='/' && line[1]=='/')
- continue;
- type=0;
- if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
- sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
- script_set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
- }
- }
- fclose(fp);
- }
- /*==========================================
- * Display emplacement line of script
- *------------------------------------------*/
- static const char* script_print_line(StringBuf* buf, const char* p, const char* mark, int line)
- {
- int i;
- if( p == NULL || !p[0] ) return NULL;
- if( line < 0 )
- StringBuf_Printf(buf, "*% 5d : ", -line);
- else
- StringBuf_Printf(buf, " % 5d : ", line);
- for(i=0;p[i] && p[i] != '\n';i++){
- if(p + i != mark)
- StringBuf_Printf(buf, "%c", p[i]);
- else
- StringBuf_Printf(buf, "\'%c\'", p[i]);
- }
- StringBuf_AppendStr(buf, "\n");
- return p+i+(p[i] == '\n' ? 1 : 0);
- }
- void script_errorwarning_sub(StringBuf *buf, const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
- // Find the line where the error occurred
- int j;
- int line = start_line;
- const char *p;
- const char *linestart[5] = { NULL, NULL, NULL, NULL, NULL };
- for(p=src;p && *p;line++){
- const char *lineend=strchr(p,'\n');
- if(lineend==NULL || error_pos<lineend){
- break;
- }
- for( j = 0; j < 4; j++ ) {
- linestart[j] = linestart[j+1];
- }
- linestart[4] = p;
- p=lineend+1;
- }
- StringBuf_Printf(buf, "script error on %s line %d\n", file, line);
- StringBuf_Printf(buf, " %s\n", error_msg);
- for(j = 0; j < 5; j++ ) {
- script_print_line(buf, linestart[j], NULL, line + j - 5);
- }
- p = script_print_line(buf, p, error_pos, -line);
- for(j = 0; j < 5; j++) {
- p = script_print_line(buf, p, NULL, line + j + 1 );
- }
- }
- void script_error(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
- StringBuf buf;
- StringBuf_Init(&buf);
- StringBuf_AppendStr(&buf, "\a\n");
- script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
- ShowError("%s", StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- }
- void script_warning(const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos) {
- StringBuf buf;
- StringBuf_Init(&buf);
- script_errorwarning_sub(&buf, src, file, start_line, error_msg, error_pos);
- ShowWarning("%s", StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- }
- /*==========================================
- * Analysis of the script
- *------------------------------------------*/
- struct script_code* parse_script(const char *src,const char *file,int line,int options)
- {
- const char *p,*tmpp;
- int i;
- struct script_code* code = NULL;
- static int first=1;
- char end;
- bool unresolved_names = false;
- parser_current_src = src;
- parser_current_file = file;
- parser_current_line = line;
- if( src == NULL )
- return NULL;// empty script
- memset(&syntax,0,sizeof(syntax));
- if(first){
- add_buildin_func();
- read_constdb();
- first=0;
- }
- script_buf=(unsigned char *)aMalloc(SCRIPT_BLOCK_SIZE*sizeof(unsigned char));
- script_pos=0;
- script_size=SCRIPT_BLOCK_SIZE;
- parse_nextline(true, NULL);
- // who called parse_script is responsible for clearing the database after using it, but just in case... lets clear it here
- if( options&SCRIPT_USE_LABEL_DB )
- db_clear(scriptlabel_db);
- parse_options = options;
- if( setjmp( error_jump ) != 0 ) {
- //Restore program state when script has problems. [from jA]
- int i;
- const int size = ARRAYLENGTH(syntax.curly);
- if( error_report )
- script_error(src,file,line,error_msg,error_pos);
- aFree( error_msg );
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- for(i=LABEL_START;i<str_num;i++)
- if(str_data[i].type == C_NOP) str_data[i].type = C_NAME;
- for(i=0; i<size; i++)
- linkdb_final(&syntax.curly[i].case_label);
- return NULL;
- }
- parse_syntax_for_flag=0;
- p=src;
- p=skip_space(p);
- if( options&SCRIPT_IGNORE_EXTERNAL_BRACKETS )
- {// does not require brackets around the script
- if( *p == '\0' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
- {// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- return NULL;
- }
- end = '\0';
- }
- else
- {// requires brackets around the script
- if( *p != '{' )
- disp_error_message("not found '{'",p);
- p = skip_space(p+1);
- if( *p == '}' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
- {// empty script and can return NULL
- aFree( script_buf );
- script_pos = 0;
- script_size = 0;
- script_buf = NULL;
- return NULL;
- }
- end = '}';
- }
- // clear references of labels, variables and internal functions
- for(i=LABEL_START;i<str_num;i++){
- if(
- str_data[i].type==C_POS || str_data[i].type==C_NAME ||
- str_data[i].type==C_USERFUNC || str_data[i].type == C_USERFUNC_POS
- ){
- str_data[i].type=C_NOP;
- str_data[i].backpatch=-1;
- str_data[i].label=-1;
- }
- }
- while( syntax.curly_count != 0 || *p != end )
- {
- if( *p == '\0' )
- disp_error_message("unexpected end of script",p);
- // Special handling only label
- tmpp=skip_space(skip_word(p));
- if(*tmpp==':' && !(!strncasecmp(p,"default:",8) && p + 7 == tmpp)){
- i=add_word(p);
- set_label(i,script_pos,p);
- if( parse_options&SCRIPT_USE_LABEL_DB )
- strdb_iput(scriptlabel_db, get_str(i), script_pos);
- p=tmpp+1;
- p=skip_space(p);
- continue;
- }
- // All other lumped
- p=parse_line(p);
- p=skip_space(p);
- parse_nextline(false, p);
- }
- add_scriptc(C_NOP);
- // trim code to size
- script_size = script_pos;
- RECREATE(script_buf,unsigned char,script_pos);
- // default unknown references to variables
- for(i=LABEL_START;i<str_num;i++){
- if(str_data[i].type==C_NOP){
- int j,next;
- str_data[i].type=C_NAME;
- str_data[i].label=i;
- for(j=str_data[i].backpatch;j>=0 && j!=0x00ffffff;){
- next=GETVALUE(script_buf,j);
- SETVALUE(script_buf,j,i);
- j=next;
- }
- }
- else if( str_data[i].type == C_USERFUNC )
- {// 'function name;' without follow-up code
- ShowError("parse_script: function '%s' declared but not defined.\n", str_buf+str_data[i].str);
- unresolved_names = true;
- }
- }
- if( unresolved_names )
- {
- disp_error_message("parse_script: unresolved function references", p);
- }
- #ifdef DEBUG_DISP
- for(i=0;i<script_pos;i++){
- if((i&15)==0) ShowMessage("%04x : ",i);
- ShowMessage("%02x ",script_buf[i]);
- if((i&15)==15) ShowMessage("\n");
- }
- ShowMessage("\n");
- #endif
- #ifdef DEBUG_DISASM
- {
- int i = 0,j;
- while(i < script_pos) {
- c_op op = get_com(script_buf,&i);
- ShowMessage("%06x %s", i, script_op2name(op));
- j = i;
- switch(op) {
- case C_INT:
- ShowMessage(" %d", get_num(script_buf,&i));
- break;
- case C_POS:
- ShowMessage(" 0x%06x", *(int*)(script_buf+i)&0xffffff);
- i += 3;
- break;
- case C_NAME:
- j = (*(int*)(script_buf+i)&0xffffff);
- ShowMessage(" %s", ( j == 0xffffff ) ? "?? unknown ??" : get_str(j));
- i += 3;
- break;
- case C_STR:
- j = strlen(script_buf + i);
- ShowMessage(" %s", script_buf + i);
- i += j+1;
- break;
- }
- ShowMessage(CL_CLL"\n");
- }
- }
- #endif
- CREATE(code,struct script_code,1);
- code->script_buf = script_buf;
- code->script_size = script_size;
- code->script_vars = idb_alloc(DB_OPT_RELEASE_DATA);
- return code;
- }
- /// Returns the player attached to this script, identified by the rid.
- /// If there is no player attached, the script is terminated.
- TBL_PC *script_rid2sd(struct script_state *st)
- {
- TBL_PC *sd=map_id2sd(st->rid);
- if(!sd){
- ShowError("script_rid2sd: fatal error ! player not attached!\n");
- script_reportfunc(st);
- script_reportsrc(st);
- st->state = END;
- }
- return sd;
- }
- /// Dereferences a variable/constant, replacing it with a copy of the value.
- ///
- /// @param st Script state
- /// @param data Variable/constant
- void get_val(struct script_state* st, struct script_data* data)
- {
- const char* name;
- char prefix;
- char postfix;
- TBL_PC* sd = NULL;
- if( !data_isreference(data) )
- return;// not a variable/constant
- name = reference_getname(data);
- prefix = name[0];
- postfix = name[strlen(name) - 1];
- //##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS]
- if( !reference_toconstant(data) && not_server_variable(prefix) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {// needs player attached
- if( postfix == '$' )
- {// string variable
- ShowWarning("script:get_val: cannot access player variable '%s', defaulting to \"\"\n", name);
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- else
- {// integer variable
- ShowWarning("script:get_val: cannot access player variable '%s', defaulting to 0\n", name);
- data->type = C_INT;
- data->u.num = 0;
- }
- return;
- }
- }
- if( postfix == '$' )
- {// string variable
- switch( prefix )
- {
- case '@':
- data->u.str = pc_readregstr(sd, data->u.num);
- break;
- case '$':
- data->u.str = mapreg_readregstr(data->u.num);
- break;
- case '#':
- if( name[1] == '#' )
- data->u.str = pc_readaccountreg2str(sd, name);// global
- else
- data->u.str = pc_readaccountregstr(sd, name);// local
- break;
- case '.':
- {
- struct DBMap* n =
- data->ref ? *data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- st->script->script_vars;// npc variable
- if( n )
- data->u.str = (char*)idb_get(n,reference_getuid(data));
- else
- data->u.str = NULL;
- }
- break;
- case '\'':
- {
- int instance_id = script_instancegetid(st);
- if( instance_id )
- data->u.str = (char*)idb_get(instance_data[instance_id].vars,reference_getuid(data));
- else {
- ShowWarning("script:get_val: cannot access instance variable '%s', defaulting to \"\"\n", name);
- data->u.str = NULL;
- }
- }
- break;
- default:
- data->u.str = pc_readglobalreg_str(sd, name);
- break;
- }
- if( data->u.str == NULL || data->u.str[0] == '\0' )
- {// empty string
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- else
- {// duplicate string
- data->type = C_STR;
- data->u.str = aStrdup(data->u.str);
- }
- }
- else
- {// integer variable
- data->type = C_INT;
- if( reference_toconstant(data) )
- {
- data->u.num = reference_getconstant(data);
- }
- else if( reference_toparam(data) )
- {
- data->u.num = pc_readparam(sd, reference_getparamtype(data));
- }
- else
- switch( prefix )
- {
- case '@':
- data->u.num = pc_readreg(sd, data->u.num);
- break;
- case '$':
- data->u.num = mapreg_readreg(data->u.num);
- break;
- case '#':
- if( name[1] == '#' )
- data->u.num = pc_readaccountreg2(sd, name);// global
- else
- data->u.num = pc_readaccountreg(sd, name);// local
- break;
- case '.':
- {
- struct DBMap* n =
- data->ref ? *data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- st->script->script_vars;// npc variable
- if( n )
- data->u.num = (int)idb_iget(n,reference_getuid(data));
- else
- data->u.num = 0;
- }
- break;
- case '\'':
- {
- int instance_id = script_instancegetid(st);
- if( instance_id )
- data->u.num = (int)idb_iget(instance_data[instance_id].vars,reference_getuid(data));
- else {
- ShowWarning("script:get_val: cannot access instance variable '%s', defaulting to 0\n", name);
- data->u.num = 0;
- }
- }
- break;
- default:
- data->u.num = pc_readglobalreg(sd, name);
- break;
- }
- }
- return;
- }
- struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref);
- /// Retrieves the value of a reference identified by uid (variable, constant, param)
- /// The value is left in the top of the stack and needs to be removed manually.
- void* get_val2(struct script_state* st, int uid, struct DBMap** ref)
- {
- struct script_data* data;
- push_val2(st->stack, C_NAME, uid, ref);
- data = script_getdatatop(st, -1);
- get_val(st, data);
- return (data->type == C_INT ? (void*)__64BPRTSIZE(data->u.num) : (void*)__64BPRTSIZE(data->u.str));
- }
- /*==========================================
- * Stores the value of a script variable
- * Return value is 0 on fail, 1 on success.
- *------------------------------------------*/
- static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct DBMap** ref)
- {
- char prefix = name[0];
- if( is_string_variable(name) ) {// string variable
- const char* str = (const char*)value;
- switch (prefix) {
- case '@':
- return pc_setregstr(sd, num, str);
- case '$':
- return mapreg_setregstr(num, str);
- case '#':
- return (name[1] == '#') ?
- pc_setaccountreg2str(sd, name, str) :
- pc_setaccountregstr(sd, name, str);
- case '.':
- {
- struct DBMap* n;
- n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
- if( n ) {
- idb_remove(n, num);
- if (str[0]) idb_put(n, num, aStrdup(str));
- }
- }
- return 1;
- case '\'':
- {
- int instance_id = script_instancegetid(st);
- if( instance_id ) {
- idb_remove(instance_data[instance_id].vars, num);
- if( str[0] ) idb_put(instance_data[instance_id].vars, num, aStrdup(str));
- }
- return 1;
- }
- default:
- return pc_setglobalreg_str(sd, name, str);
- }
- } else {// integer variable
- int val = (int)__64BPRTSIZE(value);
- if(str_data[num&0x00ffffff].type == C_PARAM)
- {
- if( pc_setparam(sd, str_data[num&0x00ffffff].val, val) == 0 )
- {
- if( st != NULL )
- {
- ShowError("script:set_reg: failed to set param '%s' to %d.\n", name, val);
- script_reportsrc(st);
- st->state = END;
- }
- return 0;
- }
- return 1;
- }
- switch (prefix) {
- case '@':
- return pc_setreg(sd, num, val);
- case '$':
- return mapreg_setreg(num, val);
- case '#':
- return (name[1] == '#') ?
- pc_setaccountreg2(sd, name, val) :
- pc_setaccountreg(sd, name, val);
- case '.':
- {
- struct DBMap* n;
- n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
- if( n ) {
- idb_remove(n, num);
- if( val != 0 )
- idb_iput(n, num, val);
- }
- }
- return 1;
- case '\'':
- {
- int instance_id = script_instancegetid(st);
- if( instance_id ) {
- idb_remove(instance_data[instance_id].vars, num);
- if( val != 0 )
- idb_iput(instance_data[instance_id].vars, num, val);
- }
- return 1;
- }
- default:
- return pc_setglobalreg(sd, name, val);
- }
- }
- }
- int set_var(TBL_PC* sd, char* name, void* val)
- {
- return set_reg(NULL, sd, reference_uid(add_str(name),0), name, val, NULL);
- }
- void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct DBMap **ref)
- {
- set_reg(st, sd, reference_uid(add_str(varname),elem), varname, value, ref);
- }
- /// Converts the data to a string
- const char* conv_str(struct script_state* st, struct script_data* data)
- {
- char* p;
- get_val(st, data);
- if( data_isstring(data) )
- {// nothing to convert
- }
- else if( data_isint(data) )
- {// int -> string
- CREATE(p, char, ITEM_NAME_LENGTH);
- snprintf(p, ITEM_NAME_LENGTH, "%d", data->u.num);
- p[ITEM_NAME_LENGTH-1] = '\0';
- data->type = C_STR;
- data->u.str = p;
- }
- else if( data_isreference(data) )
- {// reference -> string
- //##TODO when does this happen (check get_val) [FlavioJS]
- data->type = C_CONSTSTR;
- data->u.str = reference_getname(data);
- }
- else
- {// unsupported data type
- ShowError("script:conv_str: cannot convert to string, defaulting to \"\"\n");
- script_reportdata(data);
- script_reportsrc(st);
- data->type = C_CONSTSTR;
- data->u.str = "";
- }
- return data->u.str;
- }
- /// Converts the data to an int
- int conv_num(struct script_state* st, struct script_data* data)
- {
- char* p;
- long num;
- get_val(st, data);
- if( data_isint(data) )
- {// nothing to convert
- }
- else if( data_isstring(data) )
- {// string -> int
- // the result does not overflow or underflow, it is capped instead
- // ex: 999999999999 is capped to INT_MAX (2147483647)
- p = data->u.str;
- errno = 0;
- num = strtol(data->u.str, NULL, 10);// change radix to 0 to support octal numbers "o377" and hex numbers "0xFF"
- if( errno == ERANGE
- #if LONG_MAX > INT_MAX
- || num < INT_MIN || num > INT_MAX
- #endif
- )
- {
- if( num <= INT_MIN )
- {
- num = INT_MIN;
- ShowError("script:conv_num: underflow detected, capping to %ld\n", num);
- }
- else//if( num >= INT_MAX )
- {
- num = INT_MAX;
- ShowError("script:conv_num: overflow detected, capping to %ld\n", num);
- }
- script_reportdata(data);
- script_reportsrc(st);
- }
- if( data->type == C_STR )
- aFree(p);
- data->type = C_INT;
- data->u.num = (int)num;
- }
- #if 0
- // FIXME this function is being used to retrieve the position of labels and
- // probably other stuff [FlavioJS]
- else
- {// unsupported data type
- ShowError("script:conv_num: cannot convert to number, defaulting to 0\n");
- script_reportdata(data);
- script_reportsrc(st);
- data->type = C_INT;
- data->u.num = 0;
- }
- #endif
- return data->u.num;
- }
- //
- // Stack operations
- //
- /// Increases the size of the stack
- void stack_expand(struct script_stack* stack)
- {
- stack->sp_max += 64;
- stack->stack_data = (struct script_data*)aRealloc(stack->stack_data,
- stack->sp_max * sizeof(stack->stack_data[0]) );
- memset(stack->stack_data + (stack->sp_max - 64), 0,
- 64 * sizeof(stack->stack_data[0]) );
- }
- /// Pushes a value into the stack
- #define push_val(stack,type,val) push_val2(stack, type, val, NULL)
- /// Pushes a value into the stack (with reference)
- struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = type;
- stack->stack_data[stack->sp].u.num = val;
- stack->stack_data[stack->sp].ref = ref;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a string into the stack
- struct script_data* push_str(struct script_stack* stack, enum c_op type, char* str)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = type;
- stack->stack_data[stack->sp].u.str = str;
- stack->stack_data[stack->sp].ref = NULL;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a retinfo into the stack
- struct script_data* push_retinfo(struct script_stack* stack, struct script_retinfo* ri, DBMap **ref)
- {
- if( stack->sp >= stack->sp_max )
- stack_expand(stack);
- stack->stack_data[stack->sp].type = C_RETINFO;
- stack->stack_data[stack->sp].u.ri = ri;
- stack->stack_data[stack->sp].ref = ref;
- stack->sp++;
- return &stack->stack_data[stack->sp-1];
- }
- /// Pushes a copy of the target position into the stack
- struct script_data* push_copy(struct script_stack* stack, int pos)
- {
- switch( stack->stack_data[pos].type )
- {
- case C_CONSTSTR:
- return push_str(stack, C_CONSTSTR, stack->stack_data[pos].u.str);
- break;
- case C_STR:
- return push_str(stack, C_STR, aStrdup(stack->stack_data[pos].u.str));
- break;
- case C_RETINFO:
- ShowFatalError("script:push_copy: can't create copies of C_RETINFO. Exiting...\n");
- exit(1);
- break;
- default:
- return push_val2(
- stack,stack->stack_data[pos].type,
- stack->stack_data[pos].u.num,
- stack->stack_data[pos].ref
- );
- break;
- }
- }
- /// Removes the values in indexes [start,end[ from the stack.
- /// Adjusts all stack pointers.
- void pop_stack(struct script_state* st, int start, int end)
- {
- struct script_stack* stack = st->stack;
- struct script_data* data;
- int i;
- if( start < 0 )
- start = 0;
- if( end > stack->sp )
- end = stack->sp;
- if( start >= end )
- return;// nothing to pop
- // free stack elements
- for( i = start; i < end; i++ )
- {
- data = &stack->stack_data[i];
- if( data->type == C_STR )
- aFree(data->u.str);
- if( data->type == C_RETINFO )
- {
- struct script_retinfo* ri = data->u.ri;
- if( ri->var_function )
- script_free_vars(ri->var_function);
- if( data->ref )
- aFree(data->ref);
- aFree(ri);
- }
- data->type = C_NOP;
- }
- // move the rest of the elements
- if( stack->sp > end )
- {
- memmove(&stack->stack_data[start], &stack->stack_data[end], sizeof(stack->stack_data[0])*(stack->sp - end));
- for( i = start + stack->sp - end; i < stack->sp; ++i )
- stack->stack_data[i].type = C_NOP;
- }
- // adjust stack pointers
- if( st->start > end ) st->start -= end - start;
- else if( st->start > start ) st->start = start;
- if( st->end > end ) st->end -= end - start;
- else if( st->end > start ) st->end = start;
- if( stack->defsp > end ) stack->defsp -= end - start;
- else if( stack->defsp > start ) stack->defsp = start;
- stack->sp -= end - start;
- }
- ///
- ///
- ///
- /*==========================================
- * Release script dependent variable, dependent variable of function
- *------------------------------------------*/
- void script_free_vars(struct DBMap* storage)
- {
- if( storage )
- {// destroy the storage construct containing the variables
- db_destroy(storage);
- }
- }
- void script_free_code(struct script_code* code)
- {
- script_free_vars( code->script_vars );
- aFree( code->script_buf );
- aFree( code );
- }
- /// Creates a new script state.
- ///
- /// @param script Script code
- /// @param pos Position in the code
- /// @param rid Who is running the script (attached player)
- /// @param oid Where the code is being run (npc 'object')
- /// @return Script state
- struct script_state* script_alloc_state(struct script_code* script, int pos, int rid, int oid)
- {
- struct script_state* st;
- CREATE(st, struct script_state, 1);
- st->stack = (struct script_stack*)aMalloc(sizeof(struct script_stack));
- st->stack->sp = 0;
- st->stack->sp_max = 64;
- CREATE(st->stack->stack_data, struct script_data, st->stack->sp_max);
- st->stack->defsp = st->stack->sp;
- st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
- st->state = RUN;
- st->script = script;
- //st->scriptroot = script;
- st->pos = pos;
- st->rid = rid;
- st->oid = oid;
- st->sleep.timer = INVALID_TIMER;
- st->npc_item_flag = battle_config.item_enabled_npc;
- return st;
- }
- /// Frees a script state.
- ///
- /// @param st Script state
- void script_free_state(struct script_state* st)
- {
- if(st->bk_st)
- {// backup was not restored
- ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- }
- if( st->sleep.timer != INVALID_TIMER )
- delete_timer(st->sleep.timer, run_script_timer);
- script_free_vars(st->stack->var_function);
- pop_stack(st, 0, st->stack->sp);
- aFree(st->stack->stack_data);
- aFree(st->stack);
- st->stack = NULL;
- st->pos = -1;
- aFree(st);
- }
- //
- // Main execution unit
- //
- /*==========================================
- * Read command
- *------------------------------------------*/
- c_op get_com(unsigned char *script,int *pos)
- {
- int i = 0, j = 0;
- if(script[*pos]>=0x80){
- return C_INT;
- }
- while(script[*pos]>=0x40){
- i=script[(*pos)++]<<j;
- j+=6;
- }
- return (c_op)(i+(script[(*pos)++]<<j));
- }
- /*==========================================
- * Income figures
- *------------------------------------------*/
- int get_num(unsigned char *script,int *pos)
- {
- int i,j;
- i=0; j=0;
- while(script[*pos]>=0xc0){
- i+=(script[(*pos)++]&0x7f)<<j;
- j+=6;
- }
- return i+((script[(*pos)++]&0x7f)<<j);
- }
- /*==========================================
- * Remove the value from the stack
- *------------------------------------------*/
- int pop_val(struct script_state* st)
- {
- if(st->stack->sp<=0)
- return 0;
- st->stack->sp--;
- get_val(st,&(st->stack->stack_data[st->stack->sp]));
- if(st->stack->stack_data[st->stack->sp].type==C_INT)
- return st->stack->stack_data[st->stack->sp].u.num;
- return 0;
- }
- /// Ternary operators
- /// test ? if_true : if_false
- void op_3(struct script_state* st, int op)
- {
- struct script_data* data;
- int flag = 0;
- data = script_getdatatop(st, -3);
- get_val(st, data);
- if( data_isstring(data) )
- flag = data->u.str[0];// "" -> false
- else if( data_isint(data) )
- flag = data->u.num;// 0 -> false
- else
- {
- ShowError("script:op_3: invalid data for the ternary operator test\n");
- script_reportdata(data);
- script_reportsrc(st);
- script_removetop(st, -3, 0);
- script_pushnil(st);
- return;
- }
- if( flag )
- script_pushcopytop(st, -2);
- else
- script_pushcopytop(st, -1);
- script_removetop(st, -4, -1);
- }
- /// Binary string operators
- /// s1 EQ s2 -> i
- /// s1 NE s2 -> i
- /// s1 GT s2 -> i
- /// s1 GE s2 -> i
- /// s1 LT s2 -> i
- /// s1 LE s2 -> i
- /// s1 ADD s2 -> s
- void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
- {
- int a = 0;
- switch(op){
- case C_EQ: a = (strcmp(s1,s2) == 0); break;
- case C_NE: a = (strcmp(s1,s2) != 0); break;
- case C_GT: a = (strcmp(s1,s2) > 0); break;
- case C_GE: a = (strcmp(s1,s2) >= 0); break;
- case C_LT: a = (strcmp(s1,s2) < 0); break;
- case C_LE: a = (strcmp(s1,s2) <= 0); break;
- case C_ADD:
- {
- char* buf = (char *)aMalloc((strlen(s1)+strlen(s2)+1)*sizeof(char));
- strcpy(buf, s1);
- strcat(buf, s2);
- script_pushstr(st, buf);
- return;
- }
- default:
- ShowError("script:op2_str: unexpected string operator %s\n", script_op2name(op));
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- script_pushint(st,a);
- }
- /// Binary number operators
- /// i OP i -> i
- void op_2num(struct script_state* st, int op, int i1, int i2)
- {
- int ret;
- double ret_double;
- switch( op )
- {
- case C_AND: ret = i1 & i2; break;
- case C_OR: ret = i1 | i2; break;
- case C_XOR: ret = i1 ^ i2; break;
- case C_LAND: ret = (i1 && i2); break;
- case C_LOR: ret = (i1 || i2); break;
- case C_EQ: ret = (i1 == i2); break;
- case C_NE: ret = (i1 != i2); break;
- case C_GT: ret = (i1 > i2); break;
- case C_GE: ret = (i1 >= i2); break;
- case C_LT: ret = (i1 < i2); break;
- case C_LE: ret = (i1 <= i2); break;
- case C_R_SHIFT: ret = i1>>i2; break;
- case C_L_SHIFT: ret = i1<<i2; break;
- case C_DIV:
- case C_MOD:
- if( i2 == 0 )
- {
- ShowError("script:op_2num: division by zero detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- else if( op == C_DIV )
- ret = i1 / i2;
- else//if( op == C_MOD )
- ret = i1 % i2;
- break;
- default:
- switch( op )
- {// operators that can overflow/underflow
- case C_ADD: ret = i1 + i2; ret_double = (double)i1 + (double)i2; break;
- case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
- case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
- default:
- ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- script_pushnil(st);
- return;
- }
- if( ret_double < (double)INT_MIN )
- {
- ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- ret = INT_MIN;
- }
- else if( ret_double > (double)INT_MAX )
- {
- ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script_op2name(op), i1, i2);
- script_reportsrc(st);
- ret = INT_MAX;
- }
- }
- script_pushint(st, ret);
- }
- /// Binary operators
- void op_2(struct script_state *st, int op)
- {
- struct script_data* left, leftref;
- struct script_data* right;
- leftref.type = C_NOP;
- left = script_getdatatop(st, -2);
- right = script_getdatatop(st, -1);
- if (st->op2ref) {
- if (data_isreference(left)) {
- leftref = *left;
- }
- st->op2ref = 0;
- }
- get_val(st, left);
- get_val(st, right);
- // automatic conversions
- switch( op )
- {
- case C_ADD:
- if( data_isint(left) && data_isstring(right) )
- {// convert int-string to string-string
- conv_str(st, left);
- }
- else if( data_isstring(left) && data_isint(right) )
- {// convert string-int to string-string
- conv_str(st, right);
- }
- break;
- }
- if( data_isstring(left) && data_isstring(right) )
- {// ss => op_2str
- op_2str(st, op, left->u.str, right->u.str);
- script_removetop(st, leftref.type == C_NOP ? -3 : -2, -1);// pop the two values before the top one
- if (leftref.type != C_NOP)
- {
- if (left->type == C_STR) // don't free C_CONSTSTR
- aFree(left->u.str);
- *left = leftref;
- }
- }
- else if( data_isint(left) && data_isint(right) )
- {// ii => op_2num
- int i1 = left->u.num;
- int i2 = right->u.num;
- script_removetop(st, leftref.type == C_NOP ? -2 : -1, 0);
- op_2num(st, op, i1, i2);
- if (leftref.type != C_NOP)
- *left = leftref;
- }
- else
- {// invalid argument
- ShowError("script:op_2: invalid data for operator %s\n", script_op2name(op));
- script_reportdata(left);
- script_reportdata(right);
- script_reportsrc(st);
- script_removetop(st, -2, 0);
- script_pushnil(st);
- st->state = END;
- }
- }
- /// Unary operators
- /// NEG i -> i
- /// NOT i -> i
- /// LNOT i -> i
- void op_1(struct script_state* st, int op)
- {
- struct script_data* data;
- int i1;
- data = script_getdatatop(st, -1);
- get_val(st, data);
- if( !data_isint(data) )
- {// not a number
- ShowError("script:op_1: argument is not a number (op=%s)\n", script_op2name(op));
- script_reportdata(data);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- i1 = data->u.num;
- script_removetop(st, -1, 0);
- switch( op )
- {
- case C_NEG: i1 = -i1; break;
- case C_NOT: i1 = ~i1; break;
- case C_LNOT: i1 = !i1; break;
- default:
- ShowError("script:op_1: unexpected operator %s i1=%d\n", script_op2name(op), i1);
- script_reportsrc(st);
- script_pushnil(st);
- st->state = END;
- return;
- }
- script_pushint(st, i1);
- }
- /// Checks the type of all arguments passed to a built-in function.
- ///
- /// @param st Script state whose stack arguments should be inspected.
- /// @param func Built-in function for which the arguments are intended.
- static void script_check_buildin_argtype(struct script_state* st, int func)
- {
- char type;
- int idx, invalid = 0;
- script_function* sf = &buildin_func[str_data[func].val];
- for( idx = 2; script_hasdata(st, idx); idx++ )
- {
- struct script_data* data = script_getdata(st, idx);
- type = sf->arg[idx-2];
- if( type == '?' || type == '*' )
- {// optional argument or unknown number of optional parameters ( no types are after this )
- break;
- }
- else if( type == 0 )
- {// more arguments than necessary ( should not happen, as it is checked before )
- ShowWarning("Found more arguments than necessary. unexpected arg type %s\n",script_op2name(data->type));
- invalid++;
- break;
- }
- else
- {
- const char* name = NULL;
- if( data_isreference(data) )
- {// get name for variables to determine the type they refer to
- name = reference_getname(data);
- }
- switch( type )
- {
- case 'v':
- if( !data_isstring(data) && !data_isint(data) && !data_isreference(data) )
- {// variant
- ShowWarning("Unexpected type for argument %d. Expected string, number or variable.\n", idx-1);
- script_reportdata(data);
- invalid++;
- }
- break;
- case 's':
- if( !data_isstring(data) && !( data_isreference(data) && is_string_variable(name) ) )
- {// string
- ShowWarning("Unexpected type for argument %d. Expected string.\n", idx-1);
- script_reportdata(data);
- invalid++;
- }
- break;
- case 'i':
- if( !data_isint(data) && !( data_isreference(data) && ( reference_toparam(data) || reference_toconstant(data) || !is_string_variable(name) ) ) )
- {// int ( params and constants are always int )
- ShowWarning("Unexpected type for argument %d. Expected number.\n", idx-1);
- script_reportdata(data);
- invalid++;
- }
- break;
- case 'r':
- if( !data_isreference(data) )
- {// variables
- ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script_op2name(data->type));
- script_reportdata(data);
- invalid++;
- }
- break;
- case 'l':
- if( !data_islabel(data) && !data_isfunclabel(data) )
- {// label
- ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script_op2name(data->type));
- script_reportdata(data);
- invalid++;
- }
- break;
- }
- }
- }
- if(invalid)
- {
- ShowDebug("Function: %s\n", get_str(func));
- script_reportsrc(st);
- }
- }
- /// Executes a buildin command.
- /// Stack: C_NAME(<command>) C_ARG <arg0> <arg1> ... <argN>
- int run_func(struct script_state *st)
- {
- struct script_data* data;
- int i,start_sp,end_sp,func;
- end_sp = st->stack->sp;// position after the last argument
- for( i = end_sp-1; i > 0 ; --i )
- if( st->stack->stack_data[i].type == C_ARG )
- break;
- if( i == 0 ) {
- ShowError("script:run_func: C_ARG not found. please report this!!!\n");
- st->state = END;
- script_reportsrc(st);
- return 1;
- }
- start_sp = i-1;// C_NAME of the command
- st->start = start_sp;
- st->end = end_sp;
- data = &st->stack->stack_data[st->start];
- if( data->type == C_NAME && str_data[data->u.num].type == C_FUNC ) {
- func = data->u.num;
- st->funcname = reference_getname(data);
- } else {
- ShowError("script:run_func: not a buildin command.\n");
- script_reportdata(data);
- script_reportsrc(st);
- st->state = END;
- return 1;
- }
- if( script_config.warn_func_mismatch_argtypes ) {
- script_check_buildin_argtype(st, func);
- }
- if(str_data[func].func) {
- if (str_data[func].func(st)) //Report error
- script_reportsrc(st);
- } else {
- ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(str_data[func].type));
- script_reportsrc(st);
- st->state = END;
- }
- // Stack's datum are used when re-running functions [Eoe]
- if( st->state == RERUNLINE )
- return 0;
- pop_stack(st, st->start, st->end);
- if( st->state == RETFUNC ) {// return from a user-defined function
- struct script_retinfo* ri;
- int olddefsp = st->stack->defsp;
- int nargs;
- pop_stack(st, st->stack->defsp, st->start);// pop distractions from the stack
- if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO )
- {
- ShowWarning("script:run_func: return without callfunc or callsub!\n");
- script_reportsrc(st);
- st->state = END;
- return 1;
- }
- script_free_vars( st->stack->var_function );
- ri = st->stack->stack_data[st->stack->defsp-1].u.ri;
- nargs = ri->nargs;
- st->pos = ri->pos;
- st->script = ri->script;
- st->stack->var_function = ri->var_function;
- st->stack->defsp = ri->defsp;
- memset(ri, 0, sizeof(struct script_retinfo));
- pop_stack(st, olddefsp-nargs-1, olddefsp);// pop arguments and retinfo
- st->state = GOTO;
- }
- return 0;
- }
- /*==========================================
- * script execution
- *------------------------------------------*/
- void run_script(struct script_code *rootscript,int pos,int rid,int oid)
- {
- struct script_state *st;
- if( rootscript == NULL || pos < 0 )
- return;
- // TODO In jAthena, this function can take over the pending script in the player. [FlavioJS]
- // It is unclear how that can be triggered, so it needs the be traced/checked in more detail.
- // NOTE At the time of this change, this function wasn't capable of taking over the script state because st->scriptroot was never set.
- st = script_alloc_state(rootscript, pos, rid, oid);
- run_script_main(st);
- }
- void script_stop_sleeptimers(int id)
- {
- struct script_state* st;
- for(;;)
- {
- st = (struct script_state*)linkdb_erase(&sleep_db,(void*)__64BPRTSIZE(id));
- if( st == NULL )
- break; // no more sleep timers
- script_free_state(st);
- }
- }
- /*==========================================
- * Delete the specified node from sleep_db
- *------------------------------------------*/
- struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n)
- {
- struct linkdb_node *retnode;
- if( n == NULL)
- return NULL;
- if( n->prev == NULL )
- sleep_db = n->next;
- else
- n->prev->next = n->next;
- if( n->next )
- n->next->prev = n->prev;
- retnode = n->next;
- aFree( n );
- return retnode; // The following; return retnode
- }
- /*==========================================
- * Timer function for sleep
- *------------------------------------------*/
- int run_script_timer(int tid, unsigned int tick, int id, intptr_t data)
- {
- struct script_state *st = (struct script_state *)data;
- struct linkdb_node *node = (struct linkdb_node *)sleep_db;
- TBL_PC *sd = map_id2sd(st->rid);
- if((sd && sd->status.char_id != id) || (st->rid && !sd))
- { //Character mismatch. Cancel execution.
- st->rid = 0;
- st->state = END;
- }
- while( node && st->sleep.timer != INVALID_TIMER ) {
- if( (int)__64BPRTSIZE(node->key) == st->oid && ((struct script_state *)node->data)->sleep.timer == st->sleep.timer ) {
- script_erase_sleepdb(node);
- st->sleep.timer = INVALID_TIMER;
- break;
- }
- node = node->next;
- }
- if(st->state != RERUNLINE)
- st->sleep.tick = 0;
- run_script_main(st);
- return 0;
- }
- /// Detaches script state from possibly attached character and restores it's previous script if any.
- ///
- /// @param st Script state to detach.
- /// @param dequeue_event Whether to schedule any queued events, when there was no previous script.
- static void script_detach_state(struct script_state* st, bool dequeue_event)
- {
- struct map_session_data* sd;
- if(st->rid && (sd = map_id2sd(st->rid))!=NULL) {
- sd->st = st->bk_st;
- sd->npc_id = st->bk_npcid;
- if(st->bk_st) {
- //Remove tag for removal.
- st->bk_st = NULL;
- st->bk_npcid = 0;
- } else if(dequeue_event) {
- #ifdef SECURE_NPCTIMEOUT
- /**
- * We're done with this NPC session, so we cancel the timer (if existent) and move on
- **/
- if( sd->npc_idle_timer != INVALID_TIMER ) {
- delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer);
- sd->npc_idle_timer = INVALID_TIMER;
- }
- #endif
- npc_event_dequeue(sd);
- }
- }
- else if(st->bk_st)
- {// rid was set to 0, before detaching the script state
- ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%d, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- script_reportsrc(st->bk_st);
- script_free_state(st->bk_st);
- st->bk_st = NULL;
- }
- }
- /// Attaches script state to possibly attached character and backups it's previous script, if any.
- ///
- /// @param st Script state to attach.
- static void script_attach_state(struct script_state* st)
- {
- struct map_session_data* sd;
- if(st->rid && (sd = map_id2sd(st->rid))!=NULL)
- {
- if(st!=sd->st)
- {
- if(st->bk_st)
- {// there is already a backup
- ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
- }
- st->bk_st = sd->st;
- st->bk_npcid = sd->npc_id;
- }
- sd->st = st;
- sd->npc_id = st->oid;
- sd->npc_item_flag = st->npc_item_flag; // load default.
- #ifdef SECURE_NPCTIMEOUT
- if( sd->npc_idle_timer == INVALID_TIMER )
- sd->npc_idle_timer = add_timer(gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
- sd->npc_idle_tick = gettick();
- #endif
- }
- }
- /*==========================================
- * The main part of the script execution
- *------------------------------------------*/
- void run_script_main(struct script_state *st)
- {
- int cmdcount = script_config.check_cmdcount;
- int gotocount = script_config.check_gotocount;
- TBL_PC *sd;
- struct script_stack *stack=st->stack;
- script_attach_state(st);
- if(st->state == RERUNLINE) {
- run_func(st);
- if(st->state == GOTO)
- st->state = RUN;
- } else if(st->state != END)
- st->state = RUN;
- while(st->state == RUN)
- {
- enum c_op c = get_com(st->script->script_buf,&st->pos);
- switch(c){
- case C_EOL:
- if( stack->defsp > stack->sp )
- ShowError("script:run_script_main: unexpected stack position (defsp=%d sp=%d). please report this!!!\n", stack->defsp, stack->sp);
- else
- pop_stack(st, stack->defsp, stack->sp);// pop unused stack data. (unused return value)
- break;
- case C_INT:
- push_val(stack,C_INT,get_num(st->script->script_buf,&st->pos));
- break;
- case C_POS:
- case C_NAME:
- push_val(stack,c,GETVALUE(st->script->script_buf,st->pos));
- st->pos+=3;
- break;
- case C_ARG:
- push_val(stack,c,0);
- break;
- case C_STR:
- push_str(stack,C_CONSTSTR,(char*)(st->script->script_buf+st->pos));
- while(st->script->script_buf[st->pos++]);
- break;
- case C_FUNC:
- run_func(st);
- if(st->state==GOTO){
- st->state = RUN;
- if( !st->freeloop && gotocount>0 && (--gotocount)<=0 ){
- ShowError("run_script: infinity loop !\n");
- script_reportsrc(st);
- st->state=END;
- }
- }
- break;
- case C_REF:
- st->op2ref = 1;
- break;
- case C_NEG:
- case C_NOT:
- case C_LNOT:
- op_1(st ,c);
- break;
- case C_ADD:
- case C_SUB:
- case C_MUL:
- case C_DIV:
- case C_MOD:
- case C_EQ:
- case C_NE:
- case C_GT:
- case C_GE:
- case C_LT:
- case C_LE:
- case C_AND:
- case C_OR:
- case C_XOR:
- case C_LAND:
- case C_LOR:
- case C_R_SHIFT:
- case C_L_SHIFT:
- op_2(st, c);
- break;
- case C_OP3:
- op_3(st, c);
- break;
- case C_NOP:
- st->state=END;
- break;
- default:
- ShowError("unknown command : %d @ %d\n",c,st->pos);
- st->state=END;
- break;
- }
- if( !st->freeloop && cmdcount>0 && (--cmdcount)<=0 ){
- ShowError("run_script: infinity loop !\n");
- script_reportsrc(st);
- st->state=END;
- }
- }
- if(st->sleep.tick > 0) {
- //Restore previous script
- script_detach_state(st, false);
- //Delay execution
- sd = map_id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish]
- st->sleep.charid = sd?sd->status.char_id:0;
- st->sleep.timer = add_timer(gettick()+st->sleep.tick,
- run_script_timer, st->sleep.charid, (intptr_t)st);
- linkdb_insert(&sleep_db, (void*)__64BPRTSIZE(st->oid), st);
- }
- else if(st->state != END && st->rid){
- //Resume later (st is already attached to player).
- if(st->bk_st) {
- ShowWarning("Unable to restore stack! Double continuation!\n");
- //Report BOTH scripts to see if that can help somehow.
- ShowDebug("Previous script (lost):\n");
- script_reportsrc(st->bk_st);
- ShowDebug("Current script:\n");
- script_reportsrc(st);
- script_free_state(st->bk_st);
- st->bk_st = NULL;
- }
- } else {
- //Dispose of script.
- if ((sd = map_id2sd(st->rid))!=NULL)
- { //Restore previous stack and save char.
- if(sd->state.using_fake_npc){
- clif_clearunit_single(sd->npc_id, CLR_OUTSIGHT, sd->fd);
- sd->state.using_fake_npc = 0;
- }
- //Restore previous script if any.
- script_detach_state(st, true);
- if (sd->state.reg_dirty&2)
- intif_saveregistry(sd,2);
- if (sd->state.reg_dirty&1)
- intif_saveregistry(sd,1);
- }
- script_free_state(st);
- st = NULL;
- }
- }
- int script_config_read(char *cfgName)
- {
- int i;
- char line[1024],w1[1024],w2[1024];
- FILE *fp;
- fp=fopen(cfgName,"r");
- if(fp==NULL){
- ShowError("File not found: %s\n", cfgName);
- return 1;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0] == '/' && line[1] == '/')
- continue;
- i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
- if(i!=2)
- continue;
- if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
- script_config.warn_func_mismatch_paramnum = config_switch(w2);
- }
- else if(strcmpi(w1,"check_cmdcount")==0) {
- script_config.check_cmdcount = config_switch(w2);
- }
- else if(strcmpi(w1,"check_gotocount")==0) {
- script_config.check_gotocount = config_switch(w2);
- }
- else if(strcmpi(w1,"input_min_value")==0) {
- script_config.input_min_value = config_switch(w2);
- }
- else if(strcmpi(w1,"input_max_value")==0) {
- script_config.input_max_value = config_switch(w2);
- }
- else if(strcmpi(w1,"warn_func_mismatch_argtypes")==0) {
- script_config.warn_func_mismatch_argtypes = config_switch(w2);
- }
- else if(strcmpi(w1,"import")==0){
- script_config_read(w2);
- }
- else {
- ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
- }
- }
- fclose(fp);
- return 0;
- }
- /**
- * @see DBApply
- */
- static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
- {
- struct script_code *code = db_data2ptr(data);
- if (code)
- script_free_code(code);
- return 0;
- }
- void script_run_autobonus(const char *autobonus, int id, int pos)
- {
- struct script_code *script = (struct script_code *)strdb_get(autobonus_db, autobonus);
- if( script )
- {
- current_equip_item_index = pos;
- run_script(script,0,id,0);
- }
- }
- void script_add_autobonus(const char *autobonus)
- {
- if( strdb_get(autobonus_db, autobonus) == NULL )
- {
- struct script_code *script = parse_script(autobonus, "autobonus", 0, 0);
- if( script )
- strdb_put(autobonus_db, autobonus, script);
- }
- }
- /// resets a temporary character array variable to given value
- void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value)
- {
- int key;
- uint8 idx;
- if( not_array_variable(varname[0]) || !not_server_variable(varname[0]) )
- {
- ShowError("script_cleararray_pc: Variable '%s' has invalid scope (char_id=%d).\n", varname, sd->status.char_id);
- return;
- }
- key = add_str(varname);
- if( is_string_variable(varname) )
- {
- for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ )
- {
- pc_setregstr(sd, reference_uid(key, idx), (const char*)value);
- }
- }
- else
- {
- for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ )
- {
- pc_setreg(sd, reference_uid(key, idx), (int)__64BPRTSIZE(value));
- }
- }
- }
- /// sets a temporary character array variable element idx to given value
- /// @param refcache Pointer to an int variable, which keeps a copy of the reference to varname and must be initialized to 0. Can be NULL if only one element is set.
- void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache)
- {
- int key;
- if( not_array_variable(varname[0]) || !not_server_variable(varname[0]) )
- {
- ShowError("script_setarray_pc: Variable '%s' has invalid scope (char_id=%d).\n", varname, sd->status.char_id);
- return;
- }
- if( idx >= SCRIPT_MAX_ARRAYSIZE )
- {
- ShowError("script_setarray_pc: Variable '%s' has invalid index '%d' (char_id=%d).\n", varname, (int)idx, sd->status.char_id);
- return;
- }
- key = ( refcache && refcache[0] ) ? refcache[0] : add_str(varname);
- if( is_string_variable(varname) )
- {
- pc_setregstr(sd, reference_uid(key, idx), (const char*)value);
- }
- else
- {
- pc_setreg(sd, reference_uid(key, idx), (int)__64BPRTSIZE(value));
- }
- if( refcache )
- {// save to avoid repeated add_str calls
- refcache[0] = key;
- }
- }
- #ifdef BETA_THREAD_TEST
- int buildin_query_sql_sub(struct script_state* st, Sql* handle);
- /* used to receive items the queryThread has already processed */
- int queryThread_timer(int tid, unsigned int tick, int id, intptr_t data) {
- int i, cursor = 0;
- bool allOk = true;
- EnterSpinLock(&queryThreadLock);
- for( i = 0; i < queryThreadData.count; i++ ) {
- struct queryThreadEntry *entry = queryThreadData.entry[i];
- if( !entry->ok ) {
- allOk = false;
- continue;
- }
- run_script_main(entry->st);
- entry->st = NULL;/* empty entries */
- aFree(entry);
- queryThreadData.entry[i] = NULL;
- }
- if( allOk ) {
- /* cancel the repeating timer -- it'll re-create itself when necessary, dont need to remain looping */
- delete_timer(queryThreadData.timer, queryThread_timer);
- queryThreadData.timer = INVALID_TIMER;
- }
- /* now lets clear the mess. */
- for( i = 0; i < queryThreadData.count; i++ ) {
- struct queryThreadEntry *entry = queryThreadData.entry[i];
- if( entry == NULL )
- continue;/* entry on hold */
- /* move */
- memmove(&queryThreadData.entry[cursor], &queryThreadData.entry[i], sizeof(struct queryThreadEntry*));
- cursor++;
- }
- queryThreadData.count = cursor;
- LeaveSpinLock(&queryThreadLock);
- return 0;
- }
- void queryThread_add(struct script_state *st, bool type) {
- int idx = 0;
- struct queryThreadEntry* entry = NULL;
- EnterSpinLock(&queryThreadLock);
- if( queryThreadData.count++ != 0 )
- RECREATE(queryThreadData.entry, struct queryThreadEntry* , queryThreadData.count);
- idx = queryThreadData.count-1;
- CREATE(queryThreadData.entry[idx],struct queryThreadEntry,1);
- entry = queryThreadData.entry[idx];
- entry->st = st;
- entry->ok = false;
- entry->type = type;
- if( queryThreadData.timer == INVALID_TIMER ) { /* start the receiver timer */
- queryThreadData.timer = add_timer_interval(gettick() + 100, queryThread_timer, 0, 0, 100);
- }
- LeaveSpinLock(&queryThreadLock);
- /* unlock the queryThread */
- racond_signal(queryThreadCond);
- }
- /* adds a new log to the queue */
- void queryThread_log(char * entry, int length) {
- int idx = logThreadData.count;
- EnterSpinLock(&queryThreadLock);
- if( logThreadData.count++ != 0 )
- RECREATE(logThreadData.entry, char* , logThreadData.count);
- CREATE(logThreadData.entry[idx], char, length + 1 );
- safestrncpy(logThreadData.entry[idx], entry, length + 1 );
- LeaveSpinLock(&queryThreadLock);
- /* unlock the queryThread */
- racond_signal(queryThreadCond);
- }
- /* queryThread_main */
- static void *queryThread_main(void *x) {
- Sql *queryThread_handle = Sql_Malloc();
- int i;
- if ( SQL_ERROR == Sql_Connect(queryThread_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) )
- exit(EXIT_FAILURE);
- if( strlen(default_codepage) > 0 )
- if ( SQL_ERROR == Sql_SetEncoding(queryThread_handle, default_codepage) )
- Sql_ShowDebug(queryThread_handle);
- if( log_config.sql_logs ) {
- logmysql_handle = Sql_Malloc();
- if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db_db) )
- exit(EXIT_FAILURE);
- if( strlen(default_codepage) > 0 )
- if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) )
- Sql_ShowDebug(logmysql_handle);
- }
- while( 1 ) {
- if(queryThreadTerminate > 0)
- break;
- EnterSpinLock(&queryThreadLock);
- /* mess with queryThreadData within the lock */
- for( i = 0; i < queryThreadData.count; i++ ) {
- struct queryThreadEntry *entry = queryThreadData.entry[i];
- if( entry->ok )
- continue;
- else if ( !entry->st || !entry->st->stack ) {
- entry->ok = true;/* dispose */
- continue;
- }
- buildin_query_sql_sub(entry->st, entry->type ? logmysql_handle : queryThread_handle);
- entry->ok = true;/* we're done with this */
- }
- /* also check for any logs in need to be sent */
- if( log_config.sql_logs ) {
- for( i = 0; i < logThreadData.count; i++ ) {
- if( SQL_ERROR == Sql_Query(logmysql_handle, logThreadData.entry[i]) )
- Sql_ShowDebug(logmysql_handle);
- aFree(logThreadData.entry[i]);
- }
- logThreadData.count = 0;
- }
- LeaveSpinLock(&queryThreadLock);
- ramutex_lock( queryThreadMutex );
- racond_wait( queryThreadCond, queryThreadMutex, -1 );
- ramutex_unlock( queryThreadMutex );
- }
- Sql_Free(queryThread_handle);
- if( log_config.sql_logs ) {
- Sql_Free(logmysql_handle);
- }
- return NULL;
- }
- #endif
- /*==========================================
- * Destructor
- *------------------------------------------*/
- int do_final_script() {
- int i;
- #ifdef DEBUG_HASH
- if (battle_config.etc_log)
- {
- FILE *fp = fopen("hash_dump.txt","wt");
- if(fp) {
- int count[SCRIPT_HASH_SIZE];
- int count2[SCRIPT_HASH_SIZE]; // number of buckets with a certain number of items
- int n=0;
- int min=INT_MAX,max=0,zero=0;
- double mean=0.0f;
- double median=0.0f;
- ShowNotice("Dumping script str hash information to hash_dump.txt\n");
- memset(count, 0, sizeof(count));
- fprintf(fp,"num : hash : data_name\n");
- fprintf(fp,"---------------------------------------------------------------\n");
- for(i=LABEL_START; i<str_num; i++) {
- unsigned int h = calc_hash(get_str(i));
- fprintf(fp,"%04d : %4u : %s\n",i,h, get_str(i));
- ++count[h];
- }
- fprintf(fp,"--------------------\n\n");
- memset(count2, 0, sizeof(count2));
- for(i=0; i<SCRIPT_HASH_SIZE; i++) {
- fprintf(fp," hash %3d = %d\n",i,count[i]);
- if(min > count[i])
- min = count[i]; // minimun count of collision
- if(max < count[i])
- max = count[i]; // maximun count of collision
- if(count[i] == 0)
- zero++;
- ++count2[count[i]];
- }
- fprintf(fp,"\n--------------------\n items : buckets\n--------------------\n");
- for( i=min; i <= max; ++i ){
- fprintf(fp," %5d : %7d\n",i,count2[i]);
- mean += 1.0f*i*count2[i]/SCRIPT_HASH_SIZE; // Note: this will always result in <nr labels>/<nr buckets>
- }
- for( i=min; i <= max; ++i ){
- n += count2[i];
- if( n*2 >= SCRIPT_HASH_SIZE )
- {
- if( SCRIPT_HASH_SIZE%2 == 0 && SCRIPT_HASH_SIZE/2 == n )
- median = (i+i+1)/2.0f;
- else
- median = i;
- break;
- }
- }
- fprintf(fp,"--------------------\n min = %d, max = %d, zero = %d\n mean = %lf, median = %lf\n",min,max,zero,mean,median);
- fclose(fp);
- }
- }
- #endif
- mapreg_final();
- db_destroy(scriptlabel_db);
- userfunc_db->destroy(userfunc_db, db_script_free_code_sub);
- autobonus_db->destroy(autobonus_db, db_script_free_code_sub);
- if(sleep_db) {
- struct linkdb_node *n = (struct linkdb_node *)sleep_db;
- while(n) {
- struct script_state *st = (struct script_state *)n->data;
- script_free_state(st);
- n = n->next;
- }
- linkdb_final(&sleep_db);
- }
- if (str_data)
- aFree(str_data);
- if (str_buf)
- aFree(str_buf);
- for( i = 0; i < atcmd_binding_count; i++ ) {
- aFree(atcmd_binding[i]);
- }
- if( atcmd_binding_count != 0 )
- aFree(atcmd_binding);
- #ifdef BETA_THREAD_TEST
- /* QueryThread */
- InterlockedIncrement(&queryThreadTerminate);
- racond_signal(queryThreadCond);
- rathread_wait(queryThread, NULL);
- // Destroy cond var and mutex.
- racond_destroy( queryThreadCond );
- ramutex_destroy( queryThreadMutex );
- /* Clear missing vars */
- for( i = 0; i < queryThreadData.count; i++ ) {
- aFree(queryThreadData.entry[i]);
- }
- aFree(queryThreadData.entry);
- for( i = 0; i < logThreadData.count; i++ ) {
- aFree(logThreadData.entry[i]);
- }
- aFree(logThreadData.entry);
- #endif
- return 0;
- }
- /*==========================================
- * Initialization
- *------------------------------------------*/
- int do_init_script() {
- userfunc_db=strdb_alloc(DB_OPT_DUP_KEY,0);
- scriptlabel_db=strdb_alloc(DB_OPT_DUP_KEY,50);
- autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
- mapreg_init();
- #ifdef BETA_THREAD_TEST
- CREATE(queryThreadData.entry, struct queryThreadEntry*, 1);
- queryThreadData.count = 0;
- CREATE(logThreadData.entry, char *, 1);
- logThreadData.count = 0;
- /* QueryThread Start */
- InitializeSpinLock(&queryThreadLock);
- queryThreadData.timer = INVALID_TIMER;
- queryThreadTerminate = 0;
- queryThreadMutex = ramutex_create();
- queryThreadCond = racond_create();
- queryThread = rathread_create(queryThread_main, NULL);
- if(queryThread == NULL){
- ShowFatalError("do_init_script: cannot spawn Query Thread.\n");
- exit(EXIT_FAILURE);
- }
- add_timer_func_list(queryThread_timer, "queryThread_timer");
- #endif
- return 0;
- }
- int script_reload() {
- int i;
- #ifdef BETA_THREAD_TEST
- /* we're reloading so any queries undergoing should be...exterminated. */
- EnterSpinLock(&queryThreadLock);
- for( i = 0; i < queryThreadData.count; i++ ) {
- aFree(queryThreadData.entry[i]);
- }
- queryThreadData.count = 0;
- if( queryThreadData.timer != INVALID_TIMER ) {
- delete_timer(queryThreadData.timer, queryThread_timer);
- queryThreadData.timer = INVALID_TIMER;
- }
- LeaveSpinLock(&queryThreadLock);
- #endif
- userfunc_db->clear(userfunc_db, db_script_free_code_sub);
- db_clear(scriptlabel_db);
- // @commands (script based)
- // Clear bindings
- for( i = 0; i < atcmd_binding_count; i++ ) {
- aFree(atcmd_binding[i]);
- }
- if( atcmd_binding_count != 0 )
- aFree(atcmd_binding);
- atcmd_binding_count = 0;
- if(sleep_db) {
- struct linkdb_node *n = (struct linkdb_node *)sleep_db;
- while(n) {
- struct script_state *st = (struct script_state *)n->data;
- script_free_state(st);
- n = n->next;
- }
- linkdb_final(&sleep_db);
- }
- mapreg_reload();
- return 0;
- }
- //-----------------------------------------------------------------------------
- // buildin functions
- //
- #define BUILDIN_DEF(x,args) { buildin_ ## x , #x , args }
- #define BUILDIN_DEF2(x,x2,args) { buildin_ ## x , x2 , args }
- #define BUILDIN_FUNC(x) int buildin_ ## x (struct script_state* st)
- /////////////////////////////////////////////////////////////////////
- // NPC interaction
- //
- /// Appends a message to the npc dialog.
- /// If a dialog doesn't exist yet, one is created.
- ///
- /// mes "<message>";
- BUILDIN_FUNC(mes)
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( !script_hasdata(st, 3) )
- {// only a single line detected in the script
- clif_scriptmes(sd, st->oid, script_getstr(st, 2));
- }
- else
- {// parse multiple lines as they exist
- int i;
- for( i = 2; script_hasdata(st, i); i++ )
- {
- // send the message to the client
- clif_scriptmes(sd, st->oid, script_getstr(st, i));
- }
- }
- st->mes_active = 1; // Invoking character has a NPC dialog box open.
- return SCRIPT_CMD_SUCCESS;
- }
- /// Displays the button 'next' in the npc dialog.
- /// The dialog text is cleared and the script continues when the button is pressed.
- ///
- /// next;
- BUILDIN_FUNC(next)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_WAIT;
- #endif
- st->state = STOP;
- clif_scriptnext(sd, st->oid);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Ends the script and displays the button 'close' on the npc dialog.
- /// The dialog is closed when the button is pressed.
- ///
- /// close;
- BUILDIN_FUNC(close)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( !st->mes_active ) {
- TBL_NPC* nd = map_id2nd(st->oid);
- st->state = END; // Keep backwards compatibility.
- ShowWarning("Incorrect use of 'close' command! (source:%s / path:%s)\n",nd?nd->name:"Unknown",nd?nd->path:"Unknown");
- } else {
- st->state = CLOSE;
- st->mes_active = 0;
- }
- clif_scriptclose(sd, st->oid);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Displays the button 'close' on the npc dialog.
- /// The dialog is closed and the script continues when the button is pressed.
- ///
- /// close2;
- BUILDIN_FUNC(close2)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- st->state = STOP;
- if( st->mes_active )
- st->mes_active = 0;
- clif_scriptclose(sd, st->oid);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Counts the number of valid and total number of options in 'str'
- /// If max_count > 0 the counting stops when that valid option is reached
- /// total is incremented for each option (NULL is supported)
- static int menu_countoptions(const char* str, int max_count, int* total)
- {
- int count = 0;
- int bogus_total;
- if( total == NULL )
- total = &bogus_total;
- ++(*total);
- // initial empty options
- while( *str == ':' )
- {
- ++str;
- ++(*total);
- }
- // count menu options
- while( *str != '\0' )
- {
- ++count;
- --max_count;
- if( max_count == 0 )
- break;
- while( *str != ':' && *str != '\0' )
- ++str;
- while( *str == ':' )
- {
- ++str;
- ++(*total);
- }
- }
- return count;
- }
- /// Displays a menu with options and goes to the target label.
- /// The script is stopped if cancel is pressed.
- /// Options with no text are not displayed in the client.
- ///
- /// Options can be grouped together, separated by the character ':' in the text:
- /// ex: menu "A:B:C",L_target;
- /// All these options go to the specified target label.
- ///
- /// The index of the selected option is put in the variable @menu.
- /// Indexes start with 1 and are consistent with grouped and empty options.
- /// ex: menu "A::B",-,"",L_Impossible,"C",-;
- /// // displays "A", "B" and "C", corresponding to indexes 1, 3 and 5
- ///
- /// NOTE: the client closes the npc dialog when cancel is pressed
- ///
- /// menu "<option_text>",<target_label>{,"<option_text>",<target_label>,...};
- BUILDIN_FUNC(menu)
- {
- int i;
- const char* text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_MENU;
- #endif
- // TODO detect multiple scripts waiting for input at the same time, and what to do when that happens
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
- struct script_data* data;
- if( script_lastdata(st) % 2 == 0 )
- {// argument count is not even (1st argument is at index 2)
- ShowError("script:menu: illegal number of arguments (%d).\n", (script_lastdata(st) - 1));
- st->state = END;
- return SCRIPT_CMD_FAILURE;
- }
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i < script_lastdata(st); i += 2 )
- {
- // menu options
- text = script_getstr(st, i);
- // target label
- data = script_getdata(st, i+1);
- if( !data_islabel(data) )
- {// not a label
- StringBuf_Destroy(&buf);
- ShowError("script:menu: argument #%d (from 1) is not a label or label not found.\n", i);
- script_reportdata(data);
- st->state = END;
- return SCRIPT_CMD_FAILURE;
- }
- // append option(s)
- if( text[0] == '\0' )
- continue;// empty string, ignore
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- /**
- * menus beyond this length crash the client (see bugreport:6402)
- **/
- if( StringBuf_Length(&buf) >= 2047 ) {
- struct npc_data * nd = map_id2nd(st->oid);
- char* menu;
- CREATE(menu, char, 2048);
- safestrncpy(menu, StringBuf_Value(&buf), 2047);
- ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf));
- clif_scriptmenu(sd, st->oid, menu);
- aFree(menu);
- } else
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- if( sd->npc_menu >= 0xff )
- {// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow
- ShowWarning("buildin_menu: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
- }
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- st->state = END;
- }
- else
- {// goto target label
- int menu = 0;
- sd->state.menu_or_input = 0;
- if( sd->npc_menu <= 0 )
- {
- ShowDebug("script:menu: unexpected selection (%d)\n", sd->npc_menu);
- st->state = END;
- return SCRIPT_CMD_FAILURE;
- }
- // get target label
- for( i = 2; i < script_lastdata(st); i += 2 )
- {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- if( sd->npc_menu > 0 )
- {// Invalid selection
- ShowDebug("script:menu: selection is out of range (%d pairs are missing?) - please report this\n", sd->npc_menu);
- st->state = END;
- return SCRIPT_CMD_FAILURE;
- }
- if( !data_islabel(script_getdata(st, i + 1)) )
- {// TODO remove this temporary crash-prevention code (fallback for multiple scripts requesting user input)
- ShowError("script:menu: unexpected data in label argument\n");
- script_reportdata(script_getdata(st, i + 1));
- st->state = END;
- return SCRIPT_CMD_FAILURE;
- }
- pc_setreg(sd, add_str("@menu"), menu);
- st->pos = script_getnum(st, i + 1);
- st->state = GOTO;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Displays a menu with options and returns the selected option.
- /// Behaves like 'menu' without the target labels.
- ///
- /// select(<option_text>{,<option_text>,...}) -> <selected_option>
- ///
- /// @see menu
- BUILDIN_FUNC(select)
- {
- int i;
- const char* text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_MENU;
- #endif
- if( sd->state.menu_or_input == 0 ) {
- struct StringBuf buf;
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i <= script_lastdata(st); ++i ) {
- text = script_getstr(st, i);
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- /**
- * menus beyond this length crash the client (see bugreport:6402)
- **/
- if( StringBuf_Length(&buf) >= 2047 ) {
- struct npc_data * nd = map_id2nd(st->oid);
- char* menu;
- CREATE(menu, char, 2048);
- safestrncpy(menu, StringBuf_Value(&buf), 2047);
- ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf));
- clif_scriptmenu(sd, st->oid, menu);
- aFree(menu);
- } else
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- if( sd->npc_menu >= 0xff ) {
- ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
- }
- } else if( sd->npc_menu == 0xff ) {// Cancel was pressed
- sd->state.menu_or_input = 0;
- st->state = END;
- } else {// return selected option
- int menu = 0;
- sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i ) {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- pc_setreg(sd, add_str("@menu"), menu);
- script_pushint(st, menu);
- st->state = RUN;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Displays a menu with options and returns the selected option.
- /// Behaves like 'menu' without the target labels, except when cancel is
- /// pressed.
- /// When cancel is pressed, the script continues and 255 is returned.
- ///
- /// prompt(<option_text>{,<option_text>,...}) -> <selected_option>
- ///
- /// @see menu
- BUILDIN_FUNC(prompt)
- {
- int i;
- const char *text;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_MENU;
- #endif
- if( sd->state.menu_or_input == 0 )
- {
- struct StringBuf buf;
- StringBuf_Init(&buf);
- sd->npc_menu = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- if( sd->npc_menu > 0 )
- StringBuf_AppendStr(&buf, ":");
- StringBuf_AppendStr(&buf, text);
- sd->npc_menu += menu_countoptions(text, 0, NULL);
- }
- st->state = RERUNLINE;
- sd->state.menu_or_input = 1;
- /**
- * menus beyond this length crash the client (see bugreport:6402)
- **/
- if( StringBuf_Length(&buf) >= 2047 ) {
- struct npc_data * nd = map_id2nd(st->oid);
- char* menu;
- CREATE(menu, char, 2048);
- safestrncpy(menu, StringBuf_Value(&buf), 2047);
- ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf));
- clif_scriptmenu(sd, st->oid, menu);
- aFree(menu);
- } else
- clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
- StringBuf_Destroy(&buf);
- if( sd->npc_menu >= 0xff )
- {
- ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
- script_reportsrc(st);
- }
- }
- else if( sd->npc_menu == 0xff )
- {// Cancel was pressed
- sd->state.menu_or_input = 0;
- pc_setreg(sd, add_str("@menu"), 0xff);
- script_pushint(st, 0xff);
- st->state = RUN;
- }
- else
- {// return selected option
- int menu = 0;
- sd->state.menu_or_input = 0;
- for( i = 2; i <= script_lastdata(st); ++i )
- {
- text = script_getstr(st, i);
- sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu);
- if( sd->npc_menu <= 0 )
- break;// entry found
- }
- pc_setreg(sd, add_str("@menu"), menu);
- script_pushint(st, menu);
- st->state = RUN;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /////////////////////////////////////////////////////////////////////
- // ...
- //
- /// Jumps to the target script label.
- ///
- /// goto <label>;
- BUILDIN_FUNC(goto)
- {
- if( !data_islabel(script_getdata(st,2)) )
- {
- ShowError("script:goto: not a label\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- st->pos = script_getnum(st,2);
- st->state = GOTO;
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * user-defined function call
- *------------------------------------------*/
- BUILDIN_FUNC(callfunc)
- {
- int i, j;
- struct script_retinfo* ri;
- struct script_code* scr;
- const char* str = script_getstr(st,2);
- DBMap **ref = NULL;
- scr = (struct script_code*)strdb_get(userfunc_db, str);
- if( !scr )
- {
- ShowError("script:callfunc: function not found! [%s]\n", str);
- st->state = END;
- return 1;
- }
- for( i = st->start+3, j = 0; i < st->end; i++, j++ )
- {
- struct script_data* data = push_copy(st->stack,i);
- if( data_isreference(data) && !data->ref )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' ) {
- if(!ref){
- ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
- ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
- }
- data->ref = ref;
- }
- }
- }
- CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri, ref);
- st->pos = 0;
- st->script = scr;
- st->stack->defsp = st->stack->sp;
- st->state = GOTO;
- st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * subroutine call
- *------------------------------------------*/
- BUILDIN_FUNC(callsub)
- {
- int i,j;
- struct script_retinfo* ri;
- int pos = script_getnum(st,2);
- DBMap **ref = NULL;
- if( !data_islabel(script_getdata(st,2)) && !data_isfunclabel(script_getdata(st,2)) )
- {
- ShowError("script:callsub: argument is not a label\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- for( i = st->start+3, j = 0; i < st->end; i++, j++ )
- {
- struct script_data* data = push_copy(st->stack,i);
- if( data_isreference(data) && !data->ref )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' && name[1] == '@' ) {
- if ( !ref ) {
- ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
- ref[0] = st->stack->var_function;
- }
- data->ref = ref;
- }
- }
- }
- CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
- push_retinfo(st->stack, ri, ref);
- st->pos = pos;
- st->stack->defsp = st->stack->sp;
- st->state = GOTO;
- st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Retrieves an argument provided to callfunc/callsub.
- /// If the argument doesn't exist
- ///
- /// getarg(<index>{,<default_value>}) -> <value>
- BUILDIN_FUNC(getarg)
- {
- struct script_retinfo* ri;
- int idx;
- if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO )
- {
- ShowError("script:getarg: no callfunc or callsub!\n");
- st->state = END;
- return 1;
- }
- ri = st->stack->stack_data[st->stack->defsp - 1].u.ri;
- idx = script_getnum(st,2);
- if( idx >= 0 && idx < ri->nargs )
- push_copy(st->stack, st->stack->defsp - 1 - ri->nargs + idx);
- else if( script_hasdata(st,3) )
- script_pushcopy(st, 3);
- else
- {
- ShowError("script:getarg: index (idx=%d) out of range (nargs=%d) and no default value found\n", idx, ri->nargs);
- st->state = END;
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns from the current function, optionaly returning a value from the functions.
- /// Don't use outside script functions.
- ///
- /// return;
- /// return <value>;
- BUILDIN_FUNC(return)
- {
- if( script_hasdata(st,2) )
- {// return value
- struct script_data* data;
- script_pushcopy(st, 2);
- data = script_getdatatop(st, -1);
- if( data_isreference(data) )
- {
- const char* name = reference_getname(data);
- if( name[0] == '.' && name[1] == '@' )
- {// scope variable
- if( !data->ref || data->ref == (DBMap**)&st->stack->var_function )
- get_val(st, data);// current scope, convert to value
- }
- else if( name[0] == '.' && !data->ref )
- {// script variable, link to current script
- data->ref = &st->script->script_vars;
- }
- }
- }
- else
- {// no return value
- script_pushnil(st);
- }
- st->state = RETFUNC;
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns a random number from 0 to <range>-1.
- /// Or returns a random number from <min> to <max>.
- /// If <min> is greater than <max>, their numbers are switched.
- /// rand(<range>) -> <int>
- /// rand(<min>,<max>) -> <int>
- BUILDIN_FUNC(rand)
- {
- int range;
- int min;
- int max;
- if( script_hasdata(st,3) )
- {// min,max
- min = script_getnum(st,2);
- max = script_getnum(st,3);
- if( max < min )
- swap(min, max);
- range = max - min + 1;
- }
- else
- {// range
- min = 0;
- range = script_getnum(st,2);
- }
- if( range <= 1 )
- script_pushint(st, min);
- else
- script_pushint(st, rnd()%range + min);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warp sd to str,x,y or Random or SavePoint/Save
- *------------------------------------------*/
- BUILDIN_FUNC(warp)
- {
- int ret;
- int x,y;
- const char* str;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- str = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if(strcmp(str,"Random")==0)
- ret = pc_randomwarp(sd,CLR_TELEPORT);
- else if(strcmp(str,"SavePoint")==0 || strcmp(str,"Save")==0)
- ret = pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT);
- else
- ret = pc_setpos(sd,mapindex_name2id(str),x,y,CLR_OUTSIGHT);
- if( ret ) {
- ShowError("buildin_warp: moving player '%s' to \"%s\",%d,%d failed.\n", sd->status.name, str, x, y);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warp a specified area
- *------------------------------------------*/
- static int buildin_areawarp_sub(struct block_list *bl,va_list ap)
- {
- int x2,y2,x3,y3;
- unsigned int index;
- index = va_arg(ap,unsigned int);
- x2 = va_arg(ap,int);
- y2 = va_arg(ap,int);
- x3 = va_arg(ap,int);
- y3 = va_arg(ap,int);
- if(index == 0)
- pc_randomwarp((TBL_PC *)bl,CLR_TELEPORT);
- else if(x3 && y3) {
- int max, tx, ty, j = 0;
- // choose a suitable max number of attempts
- if( (max = (y3-y2+1)*(x3-x2+1)*3) > 1000 )
- max = 1000;
- // find a suitable map cell
- do {
- tx = rnd()%(x3-x2+1)+x2;
- ty = rnd()%(y3-y2+1)+y2;
- j++;
- } while( map_getcell(index,tx,ty,CELL_CHKNOPASS) && j < max );
- pc_setpos((TBL_PC *)bl,index,tx,ty,CLR_OUTSIGHT);
- }
- else
- pc_setpos((TBL_PC *)bl,index,x2,y2,CLR_OUTSIGHT);
- return 0;
- }
- BUILDIN_FUNC(areawarp)
- {
- int16 m, x0,y0,x1,y1, x2,y2,x3=0,y3=0;
- unsigned int index;
- const char *str;
- const char *mapname;
- mapname = script_getstr(st,2);
- x0 = script_getnum(st,3);
- y0 = script_getnum(st,4);
- x1 = script_getnum(st,5);
- y1 = script_getnum(st,6);
- str = script_getstr(st,7);
- x2 = script_getnum(st,8);
- y2 = script_getnum(st,9);
- if( script_hasdata(st,10) && script_hasdata(st,11) ) { // Warp area to area
- if( (x3 = script_getnum(st,10)) < 0 || (y3 = script_getnum(st,11)) < 0 ){
- x3 = 0;
- y3 = 0;
- } else if( x3 && y3 ) {
- // normalize x3/y3 coordinates
- if( x3 < x2 ) swap(x3,x2);
- if( y3 < y2 ) swap(y3,y2);
- }
- }
- if( (m = map_mapname2mapid(mapname)) < 0 )
- return 0;
- if( strcmp(str,"Random") == 0 )
- index = 0;
- else if( !(index=mapindex_name2id(str)) )
- return 0;
- map_foreachinarea(buildin_areawarp_sub, m,x0,y0,x1,y1, BL_PC, index,x2,y2,x3,y3);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * areapercentheal <map>,<x1>,<y1>,<x2>,<y2>,<hp>,<sp>
- *------------------------------------------*/
- static int buildin_areapercentheal_sub(struct block_list *bl,va_list ap)
- {
- int hp, sp;
- hp = va_arg(ap, int);
- sp = va_arg(ap, int);
- pc_percentheal((TBL_PC *)bl,hp,sp);
- return 0;
- }
- BUILDIN_FUNC(areapercentheal)
- {
- int hp,sp,m;
- const char *mapname;
- int x0,y0,x1,y1;
- mapname=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- hp=script_getnum(st,7);
- sp=script_getnum(st,8);
- if( (m=map_mapname2mapid(mapname))< 0)
- return 0;
- map_foreachinarea(buildin_areapercentheal_sub,m,x0,y0,x1,y1,BL_PC,hp,sp);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * warpchar [LuzZza]
- * Useful for warp one player from
- * another player npc-session.
- * Using: warpchar "mapname",x,y,Char_ID;
- *------------------------------------------*/
- BUILDIN_FUNC(warpchar)
- {
- int x,y,a;
- const char *str;
- TBL_PC *sd;
- str=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- a=script_getnum(st,5);
- sd = map_charid2sd(a);
- if( sd == NULL )
- return 0;
- if(strcmp(str, "Random") == 0)
- pc_randomwarp(sd, CLR_TELEPORT);
- else
- if(strcmp(str, "SavePoint") == 0)
- pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT);
- else
- pc_setpos(sd, mapindex_name2id(str), x, y, CLR_TELEPORT);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warpparty - [Fredzilla] [Paradox924X]
- * Syntax: warpparty "to_mapname",x,y,Party_ID,{"from_mapname"};
- * If 'from_mapname' is specified, only the party members on that map will be warped
- *------------------------------------------*/
- BUILDIN_FUNC(warpparty)
- {
- TBL_PC *sd = NULL;
- TBL_PC *pl_sd;
- struct party_data* p;
- int type;
- int mapindex;
- int i;
- const char* str = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- int p_id = script_getnum(st,5);
- const char* str2 = NULL;
- if ( script_hasdata(st,6) )
- str2 = script_getstr(st,6);
- p = party_search(p_id);
- if(!p)
- return 0;
- type = ( strcmp(str,"Random")==0 ) ? 0
- : ( strcmp(str,"SavePointAll")==0 ) ? 1
- : ( strcmp(str,"SavePoint")==0 ) ? 2
- : ( strcmp(str,"Leader")==0 ) ? 3
- : 4;
- switch (type)
- {
- case 3:
- for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
- if (i == MAX_PARTY || !p->data[i].sd) //Leader not found / not online
- return 0;
- pl_sd = p->data[i].sd;
- mapindex = pl_sd->mapindex;
- x = pl_sd->bl.x;
- y = pl_sd->bl.y;
- break;
- case 4:
- mapindex = mapindex_name2id(str);
- break;
- case 2:
- //"SavePoint" uses save point of the currently attached player
- if (( sd = script_rid2sd(st) ) == NULL )
- return 0;
- default:
- mapindex = 0;
- break;
- }
- for (i = 0; i < MAX_PARTY; i++)
- {
- if( !(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id )
- continue;
- if( str2 && strcmp(str2, map[pl_sd->bl.m].name) != 0 )
- continue;
- if( pc_isdead(pl_sd) )
- continue;
- switch( type )
- {
- case 0: // Random
- if(!map[pl_sd->bl.m].flag.nowarp)
- pc_randomwarp(pl_sd,CLR_TELEPORT);
- break;
- case 1: // SavePointAll
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT);
- break;
- case 2: // SavePoint
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT);
- break;
- case 3: // Leader
- case 4: // m,x,y
- if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp)
- pc_setpos(pl_sd,mapindex,x,y,CLR_TELEPORT);
- break;
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warpguild - [Fredzilla]
- * Syntax: warpguild "mapname",x,y,Guild_ID;
- *------------------------------------------*/
- BUILDIN_FUNC(warpguild)
- {
- TBL_PC *sd = NULL;
- TBL_PC *pl_sd;
- struct guild* g;
- struct s_mapiterator* iter;
- int type;
- const char* str = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- int gid = script_getnum(st,5);
- g = guild_search(gid);
- if( g == NULL )
- return 0;
- type = ( strcmp(str,"Random")==0 ) ? 0
- : ( strcmp(str,"SavePointAll")==0 ) ? 1
- : ( strcmp(str,"SavePoint")==0 ) ? 2
- : 3;
- if( type == 2 && ( sd = script_rid2sd(st) ) == NULL )
- {// "SavePoint" uses save point of the currently attached player
- return 0;
- }
- iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
- {
- if( pl_sd->status.guild_id != gid )
- continue;
- switch( type )
- {
- case 0: // Random
- if(!map[pl_sd->bl.m].flag.nowarp)
- pc_randomwarp(pl_sd,CLR_TELEPORT);
- break;
- case 1: // SavePointAll
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,CLR_TELEPORT);
- break;
- case 2: // SavePoint
- if(!map[pl_sd->bl.m].flag.noreturn)
- pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT);
- break;
- case 3: // m,x,y
- if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp)
- pc_setpos(pl_sd,mapindex_name2id(str),x,y,CLR_TELEPORT);
- break;
- }
- }
- mapit_free(iter);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Force Heal a player (hp and sp)
- *------------------------------------------*/
- BUILDIN_FUNC(heal)
- {
- TBL_PC *sd;
- int hp,sp;
- sd = script_rid2sd(st);
- if (!sd) return 0;
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- status_heal(&sd->bl, hp, sp, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Heal a player by item (get vit bonus etc)
- *------------------------------------------*/
- BUILDIN_FUNC(itemheal)
- {
- TBL_PC *sd;
- int hp,sp;
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_hp = hp;
- potion_sp = sp;
- return 0;
- }
- sd = script_rid2sd(st);
- if (!sd) return 0;
- pc_itemheal(sd,sd->itemid,hp,sp);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(percentheal)
- {
- int hp,sp;
- TBL_PC* sd;
- hp=script_getnum(st,2);
- sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_per_hp = hp;
- potion_per_sp = sp;
- return 0;
- }
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- #ifdef RENEWAL
- if( sd->sc.data[SC_EXTREMITYFIST2] )
- sp = 0;
- #endif
- pc_percentheal(sd,hp,sp);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(jobchange)
- {
- int job, upper=-1;
- job=script_getnum(st,2);
- if( script_hasdata(st,3) )
- upper=script_getnum(st,3);
- if (pcdb_checkid(job))
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_jobchange(sd, job, upper);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(jobname)
- {
- int class_=script_getnum(st,2);
- script_pushconststr(st, (char*)job_name(class_));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Get input from the player.
- /// For numeric inputs the value is capped to the range [min,max]. Returns 1 if
- /// the value was higher than 'max', -1 if lower than 'min' and 0 otherwise.
- /// For string inputs it returns 1 if the string was longer than 'max', -1 is
- /// shorter than 'min' and 0 otherwise.
- ///
- /// input(<var>{,<min>{,<max>}}) -> <int>
- BUILDIN_FUNC(input)
- {
- TBL_PC* sd;
- struct script_data* data;
- int uid;
- const char* name;
- int min;
- int max;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- data = script_getdata(st,2);
- if( !data_isreference(data) ){
- ShowError("script:input: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- uid = reference_getuid(data);
- name = reference_getname(data);
- min = (script_hasdata(st,3) ? script_getnum(st,3) : script_config.input_min_value);
- max = (script_hasdata(st,4) ? script_getnum(st,4) : script_config.input_max_value);
- #ifdef SECURE_NPCTIMEOUT
- sd->npc_idle_type = NPCT_WAIT;
- #endif
- if( !sd->state.menu_or_input )
- { // first invocation, display npc input box
- sd->state.menu_or_input = 1;
- st->state = RERUNLINE;
- if( is_string_variable(name) )
- clif_scriptinputstr(sd,st->oid);
- else
- clif_scriptinput(sd,st->oid);
- }
- else
- { // take received text/value and store it in the designated variable
- sd->state.menu_or_input = 0;
- if( is_string_variable(name) )
- {
- int len = (int)strlen(sd->npc_str);
- set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
- script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
- }
- else
- {
- int amount = sd->npc_amount;
- set_reg(st, sd, uid, name, (void*)__64BPRTSIZE(cap_value(amount,min,max)), script_getref(st,2));
- script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
- }
- st->state = RUN;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- // declare the copyarray method here for future reference
- BUILDIN_FUNC(copyarray);
- /// Sets the value of a variable.
- /// The value is converted to the type of the variable.
- ///
- /// set(<variable>,<value>) -> <variable>
- BUILDIN_FUNC(set)
- {
- TBL_PC* sd = NULL;
- struct script_data* data;
- //struct script_data* datavalue;
- int num;
- const char* name;
- char prefix;
- data = script_getdata(st,2);
- //datavalue = script_getdata(st,3);
- if( !data_isreference(data) )
- {
- ShowError("script:set: not a variable\n");
- script_reportdata(script_getdata(st,2));
- st->state = END;
- return 1;
- }
- num = reference_getuid(data);
- name = reference_getname(data);
- prefix = *name;
- if( not_server_variable(prefix) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {
- ShowError("script:set: no player attached for player variable '%s'\n", name);
- return 0;
- }
- }
- #if 0
- if( data_isreference(datavalue) )
- {// the value being referenced is a variable
- const char* namevalue = reference_getname(datavalue);
- if( !not_array_variable(*namevalue) )
- {// array variable being copied into another array variable
- if( sd == NULL && not_server_variable(*namevalue) && !(sd = script_rid2sd(st)) )
- {// player must be attached in order to copy a player variable
- ShowError("script:set: no player attached for player variable '%s'\n", namevalue);
- return 0;
- }
- if( is_string_variable(namevalue) != is_string_variable(name) )
- {// non-matching array value types
- ShowWarning("script:set: two array variables do not match in type.\n");
- return 0;
- }
- // push the maximum number of array values to the stack
- push_val(st->stack, C_INT, SCRIPT_MAX_ARRAYSIZE);
- // call the copy array method directly
- return buildin_copyarray(st);
- }
- }
- #endif
- if( is_string_variable(name) )
- set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2));
- else
- set_reg(st,sd,num,name,(void*)__64BPRTSIZE(script_getnum(st,3)),script_getref(st,2));
- // return a copy of the variable reference
- script_pushcopy(st,2);
- return SCRIPT_CMD_SUCCESS;
- }
- /////////////////////////////////////////////////////////////////////
- /// Array variables
- ///
- /// Returns the size of the specified array
- static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref)
- {
- int32 ret = idx;
- if( isstring )
- {
- for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx )
- {
- char* str = (char*)get_val2(st, reference_uid(id, idx), ref);
- if( str && *str )
- ret = idx + 1;
- script_removetop(st, -1, 0);
- }
- }
- else
- {
- for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx )
- {
- int32 num = (int32)__64BPRTSIZE(get_val2(st, reference_uid(id, idx), ref));
- if( num )
- ret = idx + 1;
- script_removetop(st, -1, 0);
- }
- }
- return ret;
- }
- /// Sets values of an array, from the starting index.
- /// ex: setarray arr[1],1,2,3;
- ///
- /// setarray <array variable>,<value1>{,<value2>...};
- BUILDIN_FUNC(setarray)
- {
- struct script_data* data;
- const char* name;
- int32 start;
- int32 end;
- int32 id;
- int32 i;
- TBL_PC* sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:setarray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:setarray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- end = start + script_lastdata(st) - 2;
- if( end > SCRIPT_MAX_ARRAYSIZE )
- end = SCRIPT_MAX_ARRAYSIZE;
- if( is_string_variable(name) )
- {// string array
- for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data));
- }
- else
- {// int array
- for( i = 3; start < end; ++start, ++i )
- set_reg(st, sd, reference_uid(id, start), name, (void*)__64BPRTSIZE(script_getnum(st,i)), reference_getref(data));
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets count values of an array, from the starting index.
- /// ex: cleararray arr[0],0,1;
- ///
- /// cleararray <array variable>,<value>,<count>;
- BUILDIN_FUNC(cleararray)
- {
- struct script_data* data;
- const char* name;
- int32 start;
- int32 end;
- int32 id;
- void* v;
- TBL_PC* sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:cleararray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:cleararray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- if( is_string_variable(name) )
- v = (void*)script_getstr(st, 3);
- else
- v = (void*)__64BPRTSIZE(script_getnum(st, 3));
- end = start + script_getnum(st, 4);
- if( end > SCRIPT_MAX_ARRAYSIZE )
- end = SCRIPT_MAX_ARRAYSIZE;
- for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, v, script_getref(st,2));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Copies data from one array to another.
- /// ex: copyarray arr[0],arr[2],2;
- ///
- /// copyarray <destination array variable>,<source array variable>,<count>;
- BUILDIN_FUNC(copyarray)
- {
- struct script_data* data1;
- struct script_data* data2;
- const char* name1;
- const char* name2;
- int32 idx1;
- int32 idx2;
- int32 id1;
- int32 id2;
- void* v;
- int32 i;
- int32 count;
- TBL_PC* sd = NULL;
- data1 = script_getdata(st, 2);
- data2 = script_getdata(st, 3);
- if( !data_isreference(data1) || !data_isreference(data2) )
- {
- ShowError("script:copyarray: not a variable\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// not a variable
- }
- id1 = reference_getid(data1);
- id2 = reference_getid(data2);
- idx1 = reference_getindex(data1);
- idx2 = reference_getindex(data2);
- name1 = reference_getname(data1);
- name2 = reference_getname(data2);
- if( not_array_variable(*name1) || not_array_variable(*name2) )
- {
- ShowError("script:copyarray: illegal scope\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// not supported
- }
- if( is_string_variable(name1) != is_string_variable(name2) )
- {
- ShowError("script:copyarray: type mismatch\n");
- script_reportdata(data1);
- script_reportdata(data2);
- st->state = END;
- return 1;// data type mismatch
- }
- if( not_server_variable(*name1) || not_server_variable(*name2) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- count = script_getnum(st, 4);
- if( count > SCRIPT_MAX_ARRAYSIZE - idx1 )
- count = SCRIPT_MAX_ARRAYSIZE - idx1;
- if( count <= 0 || (id1 == id2 && idx1 == idx2) )
- return 0;// nothing to copy
- if( id1 == id2 && idx1 > idx2 )
- {// destination might be overlapping the source - copy in reverse order
- for( i = count - 1; i >= 0; --i )
- {
- v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2));
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
- script_removetop(st, -1, 0);
- }
- }
- else
- {// normal copy
- for( i = 0; i < count; ++i )
- {
- if( idx2 + i < SCRIPT_MAX_ARRAYSIZE )
- {
- v = get_val2(st, reference_uid(id2, idx2 + i), reference_getref(data2));
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, v, reference_getref(data1));
- script_removetop(st, -1, 0);
- }
- else// out of range - assume ""/0
- set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1));
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the size of the array.
- /// Assumes that everything before the starting index exists.
- /// ex: getarraysize(arr[3])
- ///
- /// getarraysize(<array variable>) -> <int>
- BUILDIN_FUNC(getarraysize)
- {
- struct script_data* data;
- const char* name;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:getarraysize: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not a variable
- }
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:getarraysize: illegal scope\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not supported
- }
- script_pushint(st, getarraysize(st, reference_getid(data), reference_getindex(data), is_string_variable(name), reference_getref(data)));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Deletes count or all the elements in an array, from the starting index.
- /// ex: deletearray arr[4],2;
- ///
- /// deletearray <array variable>;
- /// deletearray <array variable>,<count>;
- BUILDIN_FUNC(deletearray)
- {
- struct script_data* data;
- const char* name;
- int start;
- int end;
- int id;
- TBL_PC *sd = NULL;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:deletearray: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:deletearray: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- end = SCRIPT_MAX_ARRAYSIZE;
- if( start >= end )
- return 0;// nothing to free
- if( script_hasdata(st,3) )
- {
- int count = script_getnum(st, 3);
- if( count > end - start )
- count = end - start;
- if( count <= 0 )
- return 0;// nothing to free
- // move rest of the elements backward
- for( ; start + count < end; ++start )
- {
- void* v = get_val2(st, reference_uid(id, start + count), reference_getref(data));
- set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
- script_removetop(st, -1, 0);
- }
- }
- // clear the rest of the array
- if( is_string_variable(name) )
- {
- for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void *)"", reference_getref(data));
- }
- else
- {
- for( ; start < end; ++start )
- set_reg(st, sd, reference_uid(id, start), name, (void*)0, reference_getref(data));
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns a reference to the target index of the array variable.
- /// Equivalent to var[index].
- ///
- /// getelementofarray(<array variable>,<index>) -> <variable reference>
- BUILDIN_FUNC(getelementofarray)
- {
- struct script_data* data;
- const char* name;
- int32 id;
- int i;
- data = script_getdata(st, 2);
- if( !data_isreference(data) )
- {
- ShowError("script:getelementofarray: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:getelementofarray: illegal scope\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// not supported
- }
- i = script_getnum(st, 3);
- if( i < 0 || i >= SCRIPT_MAX_ARRAYSIZE )
- {
- ShowWarning("script:getelementofarray: index out of range (%d)\n", i);
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;// out of range
- }
- push_val2(st->stack, C_NAME, reference_uid(id, i), reference_getref(data));
- return SCRIPT_CMD_SUCCESS;
- }
- /////////////////////////////////////////////////////////////////////
- /// ...
- ///
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(setlook)
- {
- int type,val;
- TBL_PC* sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_changelook(sd,type,val);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(changelook)
- { // As setlook but only client side
- int type,val;
- TBL_PC* sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_changelook(&sd->bl,type,val);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(cutin)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_cutin(sd,script_getstr(st,2),script_getnum(st,3));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(viewpoint)
- {
- int type,x,y,id,color;
- TBL_PC* sd;
- type=script_getnum(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- id=script_getnum(st,5);
- color=script_getnum(st,6);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_viewpoint(sd,st->oid,type,x,y,id,color);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * countitem(nameID)
- * returns number of items in inventory
- *==========================================
- * countitem2(nameID,Identified,Refine,Attribute,Card0,Card1,Card2,Card3) [Lupus]
- * returns number of items that meet the conditions
- *------------------------------------------*/
- BUILDIN_FUNC(countitem)
- {
- int i, count = 0;
- struct item_data* id = NULL;
- struct script_data* data;
- TBL_PC* sd = script_rid2sd(st);
- if (!sd) {
- script_pushint(st,0);
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st, data); // Convert into value in case of a variable
- if( data_isstring(data) ) // item name
- id = itemdb_searchname(conv_str(st, data));
- else // item id
- id = itemdb_exists(conv_num(st, data));
- if( id == NULL ) {
- ShowError("buildin_countitem: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was
- script_pushint(st,0);
- return 1;
- }
- if(script_lastdata(st) == 2) { // For countitem() function
- int nameid = id->nameid;
- for(i = 0; i < MAX_INVENTORY; i++)
- if(sd->status.inventory[i].nameid == nameid)
- count += sd->status.inventory[i].amount;
- } else { // For countitem2() function
- int nameid, iden, ref, attr, c1, c2, c3, c4;
- nameid = id->nameid;
- iden = script_getnum(st,3);
- ref = script_getnum(st,4);
- attr = script_getnum(st,5);
- c1 = (short)script_getnum(st,6);
- c2 = (short)script_getnum(st,7);
- c3 = (short)script_getnum(st,8);
- c4 = (short)script_getnum(st,9);
- for(i = 0; i < MAX_INVENTORY; i++)
- if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] != NULL &&
- sd->status.inventory[i].amount > 0 && sd->status.inventory[i].nameid == nameid &&
- sd->status.inventory[i].identify == iden && sd->status.inventory[i].refine == ref &&
- sd->status.inventory[i].attribute == attr && sd->status.inventory[i].card[0] == c1 &&
- sd->status.inventory[i].card[1] == c2 && sd->status.inventory[i].card[2] == c3 &&
- sd->status.inventory[i].card[3] == c4 )
- count += sd->status.inventory[i].amount;
- }
- script_pushint(st,count);
- return SCRIPT_CMD_SUCCESS;
- }
- int checkweight_sub(TBL_PC *sd,int nbargs,int32 *eitemid,int32 *eamount)
- {
- struct item_data* id = NULL;
- int nameid,amount;
- uint16 amount2=0,slots,weight=0,i;
- slots = pc_inventoryblank(sd); //nb of empty slot
- for(i=0; i<nbargs; i++) {
- if(!eitemid[i])
- continue;
- id = itemdb_exists(eitemid[i]);
- if( id == NULL ) {
- ShowError("checkweight_sub: Invalid item '%d'.\n", eitemid[i]);
- return 0;
- }
- nameid = id->nameid;
- amount = eamount[i];
- if( amount < 1 ) {
- ShowError("checkweight_sub: Invalid amount '%d'.\n", eamount[i]);
- return 0;
- }
- weight += (id->weight)*amount; //total weight for all chk
- if( weight + sd->weight > sd->max_weight ) // too heavy
- return 0;
- switch( pc_checkadditem(sd, nameid, amount) ) {
- case CHKADDITEM_EXIST: // item is already in inventory, but there is still space for the requested amount
- break;
- case CHKADDITEM_NEW:
- if( itemdb_isstackable(nameid) )
- amount2++; // stackable
- else
- amount2 += amount; // non-stackable
- if( slots < amount2)
- return 0;
- break;
- case CHKADDITEM_OVERAMOUNT:
- return 0;
- }
- }
- return 1;
- }
- /*==========================================
- * Check if item with this amount can fit in inventory
- * Checking : weight, stack amount >32k, slots amount >(MAX_INVENTORY)
- * Return
- * 0 : fail
- * 1 : success (npc side only)
- *------------------------------------------*/
- BUILDIN_FUNC(checkweight)
- {
- struct map_session_data* sd;
- struct script_data* data;
- struct item_data* id = NULL;
- int32 nameid[SCRIPT_MAX_ARRAYSIZE], amount[SCRIPT_MAX_ARRAYSIZE];
- uint16 nbargs,i,j=0;
- if( ( sd = script_rid2sd(st) ) == NULL )
- return 0;
- nbargs = script_lastdata(st)+1;
- if(nbargs%2) {
- ShowError("buildin_checkweight: Invalid nb of args should be a multiple of 2.\n");
- script_pushint(st,0);
- return 1;
- }
- for(i=2; i<nbargs; i=i+2) {
- data = script_getdata(st,i);
- get_val(st, data); // Convert into value in case of a variable
- if( data_isstring(data) ) // item name
- id = itemdb_searchname(conv_str(st, data));
- else // item id
- id = itemdb_exists(conv_num(st, data));
- if( id == NULL ) {
- ShowError("buildin_checkweight: Invalid item '%s'.\n", script_getstr(st,i)); // returns string, regardless of what it was
- script_pushint(st,0);
- return 1;
- }
- nameid[j] = id->nameid;
- amount[j] = script_getnum(st,i+1);
- j++;
- }
- script_pushint(st,checkweight_sub(sd,(nbargs-2)/2,nameid,amount));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(checkweight2){
- //variable sub checkweight
- int32 nameid[SCRIPT_MAX_ARRAYSIZE], amount[SCRIPT_MAX_ARRAYSIZE], i;
- //variable for array parsing
- struct script_data* data_it;
- struct script_data* data_nb;
- const char* name_it;
- const char* name_nb;
- int32 id_it, id_nb;
- int32 idx_it, idx_nb;
- int nb_it, nb_nb; //array size
- TBL_PC *sd = script_rid2sd(st);
- nullpo_retr(1,sd);
- data_it = script_getdata(st, 2);
- data_nb = script_getdata(st, 3);
- if( !data_isreference(data_it) || !data_isreference(data_nb)) {
- ShowError("buildin_checkweight2: parameter not a variable\n");
- script_pushint(st,0);
- return 1;// not a variable
- }
- id_it = reference_getid(data_it);
- id_nb = reference_getid(data_nb);
- idx_it = reference_getindex(data_it);
- idx_nb = reference_getindex(data_nb);
- name_it = reference_getname(data_it);
- name_nb = reference_getname(data_nb);
- if( not_array_variable(*name_it) || not_array_variable(*name_nb)) {
- ShowError("buildin_checkweight2: illegal scope\n");
- script_pushint(st,0);
- return 1;// not supported
- }
- if(is_string_variable(name_it) || is_string_variable(name_nb)) {
- ShowError("buildin_checkweight2: illegal type, need int\n");
- script_pushint(st,0);
- return 1;// not supported
- }
- nb_it = getarraysize(st, id_it, idx_it, 0, reference_getref(data_it));
- nb_nb = getarraysize(st, id_nb, idx_nb, 0, reference_getref(data_nb));
- if(nb_it != nb_nb) {
- ShowError("buildin_checkweight2: Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb);
- script_pushint(st,0);
- return 1;
- }
- for(i=0; i<nb_it; i++) {
- nameid[i] = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_it,idx_it+i),reference_getref(data_it)));
- script_removetop(st, -1, 0);
- amount[i] = (int32)__64BPRTSIZE(get_val2(st,reference_uid(id_nb,idx_nb+i),reference_getref(data_nb)));
- script_removetop(st, -1, 0);
- } //end loop DO NOT break it prematurly we need to depop all stack
- script_pushint(st,checkweight_sub(sd,nb_it,nameid,amount)); //push result of sub to script
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * getitem <item id>,<amount>{,<account ID>};
- * getitem "<item name>",<amount>{,<account ID>};
- *
- * getitembound <item id>,<amount>,<type>{,<account ID>};
- * getitembound "<item id>",<amount>,<type>{,<account ID>};
- * Type:
- * 1 - Account Bound
- * 2 - Guild Bound
- * 3 - Party Bound
- * 4 - Character Bound
- *------------------------------------------*/
- BUILDIN_FUNC(getitem)
- {
- int nameid,amount,get_count,i,flag = 0;
- struct item it;
- TBL_PC *sd;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) {// "<item name>"
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data == NULL ){
- ShowError("buildin_getitem: Nonexistant item %s requested.\n", name);
- return 1; //No item created.
- }
- nameid=item_data->nameid;
- } else if( data_isint(data) ) {// <item id>
- nameid=conv_num(st,data);
- //Violet Box, Blue Box, etc - random item pick
- if( nameid < 0 ) {
- nameid = -nameid;
- flag = 1;
- }
- if( nameid <= 0 || !itemdb_exists(nameid) ){
- ShowError("buildin_getitem: Nonexistant item %d requested.\n", nameid);
- return 1; //No item created.
- }
- } else {
- ShowError("buildin_getitem: invalid data type for argument #1 (%d).", data->type);
- return 1;
- }
- // <amount>
- if( (amount=script_getnum(st,3)) <= 0)
- return 0; //return if amount <=0, skip the useles iteration
- memset(&it,0,sizeof(it));
- it.nameid=nameid;
- if(!flag)
- it.identify=1;
- else
- it.identify=itemdb_isidentified(nameid);
- if( !strcmp(script_getfuncname(st),"getitembound") ) {
- char bound = script_getnum(st,4);
- if( bound < 1 || bound > 4) { //Not a correct bound type
- ShowError("script_getitembound: Not a correct bound type! Type=%d\n",bound);
- return 1;
- }
- it.bound = bound;
- if( script_hasdata(st,5) )
- sd=map_id2sd(script_getnum(st,5));
- else
- sd=script_rid2sd(st); // Attached player
- } else if( script_hasdata(st,4) )
- sd=map_id2sd(script_getnum(st,4)); // <Account ID>
- else
- sd=script_rid2sd(st); // Attached player
- if( sd == NULL ) // no target
- return 0;
- //Check if it's stackable.
- if (!itemdb_isstackable(nameid))
- get_count = 1;
- else
- get_count = amount;
- for (i = 0; i < amount; i += get_count)
- {
- // if not pet egg
- if (!pet_create_egg(sd, nameid))
- {
- if ((flag = pc_additem(sd, &it, get_count, LOG_TYPE_SCRIPT)))
- {
- clif_additem(sd, 0, 0, flag);
- if( pc_candrop(sd,&it) )
- map_addflooritem(&it,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(getitem2)
- {
- int nameid,amount,get_count,i,flag = 0;
- int iden,ref,attr,c1,c2,c3,c4;
- char bound=0;
- struct item_data *item_data;
- struct item item_tmp;
- TBL_PC *sd;
- struct script_data *data;
- if( !strcmp(script_getfuncname(st),"getitembound2") ) {
- bound = script_getnum(st,11);
- if( bound < 1 || bound > 3) { //Not a correct bound type
- ShowError("script_getitembound2: Not a correct bound type! Type=%d\n",bound);
- return 1;
- }
- if( script_hasdata(st,12) )
- sd=map_id2sd(script_getnum(st,12));
- else
- sd=script_rid2sd(st); // Attached player
- } else if( script_hasdata(st,11) )
- sd=map_id2sd(script_getnum(st,11)); // <Account ID>
- else
- sd=script_rid2sd(st); // Attached player
- if( sd == NULL ) // no target
- return 0;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) {
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- nameid=item_data->nameid;
- else
- nameid=UNKNOWN_ITEM_ID;
- } else
- nameid=conv_num(st,data);
- amount=script_getnum(st,3);
- iden=script_getnum(st,4);
- ref=script_getnum(st,5);
- attr=script_getnum(st,6);
- c1=(short)script_getnum(st,7);
- c2=(short)script_getnum(st,8);
- c3=(short)script_getnum(st,9);
- c4=(short)script_getnum(st,10);
- if(nameid<0) { // Invalide nameid
- nameid = -nameid;
- flag = 1;
- }
- if(nameid > 0) {
- memset(&item_tmp,0,sizeof(item_tmp));
- item_data=itemdb_exists(nameid);
- if (item_data == NULL)
- return -1;
- if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR || item_data->type==IT_SHADOWGEAR ) {
- if(ref > MAX_REFINE) ref = MAX_REFINE;
- }
- else if(item_data->type==IT_PETEGG) {
- iden = 1;
- ref = 0;
- }
- else {
- iden = 1;
- ref = attr = 0;
- }
- item_tmp.nameid=nameid;
- if(!flag)
- item_tmp.identify=iden;
- else if(item_data->type==IT_WEAPON || item_data->type==IT_ARMOR || item_data->type==IT_SHADOWGEAR )
- item_tmp.identify=0;
- item_tmp.refine=ref;
- item_tmp.attribute=attr;
- item_tmp.card[0]=(short)c1;
- item_tmp.card[1]=(short)c2;
- item_tmp.card[2]=(short)c3;
- item_tmp.card[3]=(short)c4;
- item_tmp.bound=bound;
- //Check if it's stackable.
- if (!itemdb_isstackable(nameid))
- get_count = 1;
- else
- get_count = amount;
- for (i = 0; i < amount; i += get_count)
- {
- // if not pet egg
- if (!pet_create_egg(sd, nameid))
- {
- if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT)))
- {
- clif_additem(sd, 0, 0, flag);
- if( pc_candrop(sd,&item_tmp) )
- map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * rentitem <item id>,<seconds>
- * rentitem "<item name>",<seconds>
- *------------------------------------------*/
- BUILDIN_FUNC(rentitem)
- {
- struct map_session_data *sd;
- struct script_data *data;
- struct item it;
- int seconds;
- int nameid = 0, flag;
- data = script_getdata(st,2);
- get_val(st,data);
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( data_isstring(data) )
- {
- const char *name = conv_str(st,data);
- struct item_data *itd = itemdb_searchname(name);
- if( itd == NULL )
- {
- ShowError("buildin_rentitem: Nonexistant item %s requested.\n", name);
- return 1;
- }
- nameid = itd->nameid;
- }
- else if( data_isint(data) )
- {
- nameid = conv_num(st,data);
- if( nameid <= 0 || !itemdb_exists(nameid) )
- {
- ShowError("buildin_rentitem: Nonexistant item %d requested.\n", nameid);
- return 1;
- }
- }
- else
- {
- ShowError("buildin_rentitem: invalid data type for argument #1 (%d).\n", data->type);
- return 1;
- }
- seconds = script_getnum(st,3);
- memset(&it, 0, sizeof(it));
- it.nameid = nameid;
- it.identify = 1;
- it.expire_time = (unsigned int)(time(NULL) + seconds);
- it.bound = 0;
- if( (flag = pc_additem(sd, &it, 1, LOG_TYPE_SCRIPT)) )
- {
- clif_additem(sd, 0, 0, flag);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * gets an item with someone's name inscribed [Skotlex]
- * getinscribeditem item_num, character_name
- * Returned Qty is always 1, only works on equip-able
- * equipment
- *------------------------------------------*/
- BUILDIN_FUNC(getnameditem)
- {
- int nameid;
- struct item item_tmp;
- TBL_PC *sd, *tsd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if (sd == NULL)
- { //Player not attached!
- script_pushint(st,0);
- return 0;
- }
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data == NULL)
- { //Failed
- script_pushint(st,0);
- return 0;
- }
- nameid = item_data->nameid;
- }else
- nameid = conv_num(st,data);
- if(!itemdb_exists(nameid)/* || itemdb_isstackable(nameid)*/)
- { //Even though named stackable items "could" be risky, they are required for certain quests.
- script_pushint(st,0);
- return 0;
- }
- data=script_getdata(st,3);
- get_val(st,data);
- if( data_isstring(data) ) //Char Name
- tsd=map_nick2sd(conv_str(st,data));
- else //Char Id was given
- tsd=map_charid2sd(conv_num(st,data));
- if( tsd == NULL )
- { //Failed
- script_pushint(st,0);
- return 0;
- }
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid=nameid;
- item_tmp.amount=1;
- item_tmp.identify=1;
- item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
- item_tmp.card[2]=tsd->status.char_id;
- item_tmp.card[3]=tsd->status.char_id >> 16;
- if(pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) {
- script_pushint(st,0);
- return 0; //Failed to add item, we will not drop if they don't fit
- }
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * gets a random item ID from an item group [Skotlex]
- * groupranditem <group_num>{,<sub_group>};
- *------------------------------------------*/
- BUILDIN_FUNC(grouprandomitem)
- {
- script_pushint(st,itemdb_searchrandomid(script_getnum(st,2),script_getnum(st,3)));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(makeitem)
- {
- int nameid,amount,flag = 0;
- int x,y,m;
- const char *mapname;
- struct item item_tmp;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- nameid=item_data->nameid;
- else
- nameid=UNKNOWN_ITEM_ID;
- }else
- nameid=conv_num(st,data);
- amount=script_getnum(st,3);
- mapname =script_getstr(st,4);
- x =script_getnum(st,5);
- y =script_getnum(st,6);
- if(strcmp(mapname,"this")==0)
- {
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if (!sd) return 0; //Failed...
- m=sd->bl.m;
- } else
- m=map_mapname2mapid(mapname);
- if(nameid<0) {
- nameid = -nameid;
- flag = 1;
- }
- if(nameid > 0) {
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid=nameid;
- if(!flag)
- item_tmp.identify=1;
- else
- item_tmp.identify=itemdb_isidentified(nameid);
- map_addflooritem(&item_tmp,amount,m,x,y,0,0,0,4);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Counts / deletes the current item given by idx.
- /// Used by buildin_delitem_search
- /// Relies on all input data being already fully valid.
- static void buildin_delitem_delete(struct map_session_data* sd, int idx, int* amount, bool delete_items)
- {
- int delamount;
- struct item* inv = &sd->status.inventory[idx];
- delamount = ( amount[0] < inv->amount ) ? amount[0] : inv->amount;
- if( delete_items )
- {
- if( sd->inventory_data[idx]->type == IT_PETEGG && inv->card[0] == CARD0_PET )
- {// delete associated pet
- intif_delete_petdata(MakeDWord(inv->card[1], inv->card[2]));
- }
- pc_delitem(sd, idx, delamount, 0, 0, LOG_TYPE_SCRIPT);
- }
- amount[0]-= delamount;
- }
- /// Searches for item(s) and checks, if there is enough of them.
- /// Used by delitem and delitem2
- /// Relies on all input data being already fully valid.
- /// @param exact_match will also match item attributes and cards, not just name id
- /// @return true when all items could be deleted, false when there were not enough items to delete
- static bool buildin_delitem_search(struct map_session_data* sd, struct item* it, bool exact_match)
- {
- bool delete_items = false;
- int i, amount, important;
- struct item* inv;
- // prefer always non-equipped items
- it->equip = 0;
- // when searching for nameid only, prefer additionally
- if( !exact_match )
- {
- // non-refined items
- it->refine = 0;
- // card-less items
- memset(it->card, 0, sizeof(it->card));
- }
- for(;;)
- {
- amount = it->amount;
- important = 0;
- // 1st pass -- less important items / exact match
- for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ )
- {
- inv = &sd->status.inventory[i];
- if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid )
- {// wrong/invalid item
- continue;
- }
- if( inv->equip != it->equip || inv->refine != it->refine )
- {// not matching attributes
- important++;
- continue;
- }
- if( exact_match )
- {
- if( inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// not matching exact attributes
- continue;
- }
- }
- else
- {
- if( sd->inventory_data[i]->type == IT_PETEGG )
- {
- if( inv->card[0] == CARD0_PET && CheckForCharServer() )
- {// pet which cannot be deleted
- continue;
- }
- }
- else if( memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// named/carded item
- important++;
- continue;
- }
- }
- // count / delete item
- buildin_delitem_delete(sd, i, &amount, delete_items);
- }
- // 2nd pass -- any matching item
- if( amount == 0 || important == 0 )
- {// either everything was already consumed or no items were skipped
- ;
- }
- else for( i = 0; amount && i < ARRAYLENGTH(sd->status.inventory); i++ )
- {
- inv = &sd->status.inventory[i];
- if( !inv->nameid || !sd->inventory_data[i] || inv->nameid != it->nameid )
- {// wrong/invalid item
- continue;
- }
- if( sd->inventory_data[i]->type == IT_PETEGG && inv->card[0] == CARD0_PET && CheckForCharServer() )
- {// pet which cannot be deleted
- continue;
- }
- if( exact_match )
- {
- if( inv->refine != it->refine || inv->identify != it->identify || inv->attribute != it->attribute || memcmp(inv->card, it->card, sizeof(inv->card)) )
- {// not matching attributes
- continue;
- }
- }
- // count / delete item
- buildin_delitem_delete(sd, i, &amount, delete_items);
- }
- if( amount )
- {// not enough items
- return false;
- }
- else if( delete_items )
- {// we are done with the work
- return true;
- }
- else
- {// get rid of the items now
- delete_items = true;
- }
- }
- }
- /// Deletes items from the target/attached player.
- /// Prioritizes ordinary items.
- ///
- /// delitem <item id>,<amount>{,<account id>}
- /// delitem "<item name>",<amount>{,<account id>}
- BUILDIN_FUNC(delitem)
- {
- TBL_PC *sd;
- struct item it;
- struct script_data *data;
- if( script_hasdata(st,4) )
- {
- int account_id = script_getnum(st,4);
- sd = map_id2sd(account_id); // <account id>
- if( sd == NULL )
- {
- ShowError("script:delitem: player not found (AID=%d).\n", account_id);
- st->state = END;
- return 1;
- }
- }
- else
- {
- sd = script_rid2sd(st);// attached player
- if( sd == NULL )
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) )
- {
- const char* item_name = conv_str(st,data);
- struct item_data* id = itemdb_searchname(item_name);
- if( id == NULL )
- {
- ShowError("script:delitem: unknown item \"%s\".\n", item_name);
- st->state = END;
- return 1;
- }
- it.nameid = id->nameid;// "<item name>"
- }
- else
- {
- it.nameid = conv_num(st,data);// <item id>
- if( !itemdb_exists( it.nameid ) )
- {
- ShowError("script:delitem: unknown item \"%d\".\n", it.nameid);
- st->state = END;
- return 1;
- }
- }
- it.amount=script_getnum(st,3);
- if( it.amount <= 0 )
- return 0;// nothing to do
- if( buildin_delitem_search(sd, &it, false) )
- {// success
- return SCRIPT_CMD_SUCCESS;
- }
- ShowError("script:delitem: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid);
- st->state = END;
- st->mes_active = 0;
- clif_scriptclose(sd, st->oid);
- return SCRIPT_CMD_FAILURE;
- }
- /// Deletes items from the target/attached player.
- ///
- /// delitem2 <item id>,<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>}
- /// delitem2 "<Item name>",<amount>,<identify>,<refine>,<attribute>,<card1>,<card2>,<card3>,<card4>{,<account ID>}
- BUILDIN_FUNC(delitem2)
- {
- TBL_PC *sd;
- struct item it;
- struct script_data *data;
- if( script_hasdata(st,11) )
- {
- int account_id = script_getnum(st,11);
- sd = map_id2sd(account_id); // <account id>
- if( sd == NULL )
- {
- ShowError("script:delitem2: player not found (AID=%d).\n", account_id);
- st->state = END;
- return 1;
- }
- }
- else
- {
- sd = script_rid2sd(st);// attached player
- if( sd == NULL )
- return 0;
- }
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) )
- {
- const char* item_name = conv_str(st,data);
- struct item_data* id = itemdb_searchname(item_name);
- if( id == NULL )
- {
- ShowError("script:delitem2: unknown item \"%s\".\n", item_name);
- st->state = END;
- return 1;
- }
- it.nameid = id->nameid;// "<item name>"
- }
- else
- {
- it.nameid = conv_num(st,data);// <item id>
- if( !itemdb_exists( it.nameid ) )
- {
- ShowError("script:delitem: unknown item \"%d\".\n", it.nameid);
- st->state = END;
- return 1;
- }
- }
- it.amount=script_getnum(st,3);
- it.identify=script_getnum(st,4);
- it.refine=script_getnum(st,5);
- it.attribute=script_getnum(st,6);
- it.card[0]=(short)script_getnum(st,7);
- it.card[1]=(short)script_getnum(st,8);
- it.card[2]=(short)script_getnum(st,9);
- it.card[3]=(short)script_getnum(st,10);
- if( it.amount <= 0 )
- return 0;// nothing to do
- if( buildin_delitem_search(sd, &it, true) )
- {// success
- return SCRIPT_CMD_SUCCESS;
- }
- ShowError("script:delitem2: failed to delete %d items (AID=%d item_id=%d).\n", it.amount, sd->status.account_id, it.nameid);
- st->state = END;
- st->mes_active = 0;
- clif_scriptclose(sd, st->oid);
- return SCRIPT_CMD_FAILURE;
- }
- /*==========================================
- * Enables/Disables use of items while in an NPC [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(enableitemuse)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (sd)
- st->npc_item_flag = sd->npc_item_flag = 1;
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(disableitemuse)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (sd)
- st->npc_item_flag = sd->npc_item_flag = 0;
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns a character's specified stat.
- * Check pc_readparam for available options.
- *------------------------------------------*/
- BUILDIN_FUNC(readparam)
- {
- int type;
- TBL_PC *sd;
- type=script_getnum(st,2);
- if( script_hasdata(st,3) )
- sd=map_nick2sd(script_getstr(st,3));
- else
- sd=script_rid2sd(st);
- if(sd==NULL){
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,pc_readparam(sd,type));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Return charid identification
- * return by @num :
- * 0 : char_id
- * 1 : party_id
- * 2 : guild_id
- * 3 : account_id
- * 4 : bg_id
- *------------------------------------------*/
- BUILDIN_FUNC(getcharid)
- {
- int num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- if( script_hasdata(st,3) )
- sd=map_nick2sd(script_getstr(st,3));
- else
- sd=script_rid2sd(st);
- if(sd==NULL){
- script_pushint(st,0); //return 0, according docs
- return 0;
- }
- switch( num ) {
- case 0: script_pushint(st,sd->status.char_id); break;
- case 1: script_pushint(st,sd->status.party_id); break;
- case 2: script_pushint(st,sd->status.guild_id); break;
- case 3: script_pushint(st,sd->status.account_id); break;
- case 4: script_pushint(st,sd->bg_id); break;
- default:
- ShowError("buildin_getcharid: invalid parameter (%d).\n", num);
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * returns the GID of an NPC
- *------------------------------------------*/
- BUILDIN_FUNC(getnpcid)
- {
- int num = script_getnum(st,2);
- struct npc_data* nd = NULL;
- if( script_hasdata(st,3) )
- {// unique npc name
- if( ( nd = npc_name2id(script_getstr(st,3)) ) == NULL )
- {
- ShowError("buildin_getnpcid: No such NPC '%s'.\n", script_getstr(st,3));
- script_pushint(st,0);
- return 1;
- }
- }
- switch (num) {
- case 0:
- script_pushint(st,nd ? nd->bl.id : st->oid);
- break;
- default:
- ShowError("buildin_getnpcid: invalid parameter (%d).\n", num);
- script_pushint(st,0);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Return the name of the party_id
- * null if not found
- *------------------------------------------*/
- BUILDIN_FUNC(getpartyname)
- {
- int party_id;
- struct party_data* p;
- party_id = script_getnum(st,2);
- if( ( p = party_search(party_id) ) != NULL )
- {
- script_pushstrcopy(st,p->party.name);
- }
- else
- {
- script_pushconststr(st,"null");
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the information of the members of a party by type
- * @party_id, @type
- * return by @type :
- * - : nom des membres
- * 1 : char_id des membres
- * 2 : account_id des membres
- *------------------------------------------*/
- BUILDIN_FUNC(getpartymember)
- {
- struct party_data *p;
- int i,j=0,type=0;
- p=party_search(script_getnum(st,2));
- if( script_hasdata(st,3) )
- type=script_getnum(st,3);
- if(p!=NULL){
- for(i=0;i<MAX_PARTY;i++){
- if(p->party.member[i].account_id){
- switch (type) {
- case 2:
- mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id);
- break;
- case 1:
- mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id);
- break;
- default:
- mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name);
- }
- j++;
- }
- }
- }
- mapreg_setreg(add_str("$@partymembercount"),j);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Retrieves party leader. if flag is specified,
- * return some of the leader data. Otherwise, return name.
- *------------------------------------------*/
- BUILDIN_FUNC(getpartyleader)
- {
- int party_id, type = 0, i=0;
- struct party_data *p;
- party_id=script_getnum(st,2);
- if( script_hasdata(st,3) )
- type=script_getnum(st,3);
- p=party_search(party_id);
- if (p) //Search leader
- for(i = 0; i < MAX_PARTY && !p->party.member[i].leader; i++);
- if (!p || i == MAX_PARTY) { //leader not found
- if (type)
- script_pushint(st,-1);
- else
- script_pushconststr(st,"null");
- return 0;
- }
- switch (type) {
- case 1: script_pushint(st,p->party.member[i].account_id); break;
- case 2: script_pushint(st,p->party.member[i].char_id); break;
- case 3: script_pushint(st,p->party.member[i].class_); break;
- case 4: script_pushstrcopy(st,mapindex_id2name(p->party.member[i].map)); break;
- case 5: script_pushint(st,p->party.member[i].lv); break;
- default: script_pushstrcopy(st,p->party.member[i].name); break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Return the name of the @guild_id
- * null if not found
- *------------------------------------------*/
- BUILDIN_FUNC(getguildname)
- {
- int guild_id;
- struct guild* g;
- guild_id = script_getnum(st,2);
- if( ( g = guild_search(guild_id) ) != NULL )
- script_pushstrcopy(st,g->name);
- else
- script_pushconststr(st,"null");
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Return the name of the guild master of @guild_id
- * null if not found
- *------------------------------------------*/
- BUILDIN_FUNC(getguildmaster)
- {
- int guild_id;
- struct guild* g;
- guild_id = script_getnum(st,2);
- if( ( g = guild_search(guild_id) ) != NULL )
- script_pushstrcopy(st,g->member[0].name);
- else
- script_pushconststr(st,"null");
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getguildmasterid)
- {
- int guild_id;
- struct guild* g;
- guild_id = script_getnum(st,2);
- if( ( g = guild_search(guild_id) ) != NULL )
- script_pushint(st,g->member[0].char_id);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get char string information by type :
- * Return by @type :
- * 0 : char_name
- * 1 : party_name or ""
- * 2 : guild_name or ""
- * 3 : map_name
- * - : ""
- *------------------------------------------*/
- BUILDIN_FUNC(strcharinfo)
- {
- TBL_PC *sd;
- int num;
- struct guild* g;
- struct party_data* p;
- sd=script_rid2sd(st);
- if (!sd) { //Avoid crashing....
- script_pushconststr(st,"");
- return 0;
- }
- num=script_getnum(st,2);
- switch(num){
- case 0:
- script_pushstrcopy(st,sd->status.name);
- break;
- case 1:
- if( ( p = party_search(sd->status.party_id) ) != NULL ) {
- script_pushstrcopy(st,p->party.name);
- } else {
- script_pushconststr(st,"");
- }
- break;
- case 2:
- if( ( g = sd->guild ) != NULL ) {
- script_pushstrcopy(st,g->name);
- } else {
- script_pushconststr(st,"");
- }
- break;
- case 3:
- script_pushconststr(st,map[sd->bl.m].name);
- break;
- default:
- ShowWarning("buildin_strcharinfo: unknown parameter.\n");
- script_pushconststr(st,"");
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get npc string information by type
- * return by @type:
- * 0 : name
- * 1 : str#
- * 2 : #str
- * 3 : ::str
- * 4 : map name
- *------------------------------------------*/
- BUILDIN_FUNC(strnpcinfo)
- {
- TBL_NPC* nd;
- int num;
- char *buf,*name=NULL;
- nd = map_id2nd(st->oid);
- if (!nd) {
- script_pushconststr(st, "");
- return 0;
- }
- num = script_getnum(st,2);
- switch(num){
- case 0: // display name
- name = aStrdup(nd->name);
- break;
- case 1: // visible part of display name
- if((buf = strchr(nd->name,'#')) != NULL)
- {
- name = aStrdup(nd->name);
- name[buf - nd->name] = 0;
- } else // Return the name, there is no '#' present
- name = aStrdup(nd->name);
- break;
- case 2: // # fragment
- if((buf = strchr(nd->name,'#')) != NULL)
- name = aStrdup(buf+1);
- break;
- case 3: // unique name
- name = aStrdup(nd->exname);
- break;
- case 4: // map name
- name = aStrdup(map[nd->bl.m].name);
- break;
- }
- if(name)
- script_pushstr(st, name);
- else
- script_pushconststr(st, "");
- return SCRIPT_CMD_SUCCESS;
- }
- // aegis->athena slot position conversion table
- static unsigned int equip[] = {EQP_HEAD_TOP,EQP_ARMOR,EQP_HAND_L,EQP_HAND_R,EQP_GARMENT,EQP_SHOES,EQP_ACC_L,EQP_ACC_R,EQP_HEAD_MID,EQP_HEAD_LOW,EQP_COSTUME_HEAD_LOW,EQP_COSTUME_HEAD_MID,EQP_COSTUME_HEAD_TOP,EQP_COSTUME_GARMENT,EQP_AMMO,EQP_SHADOW_ARMOR,EQP_SHADOW_WEAPON,EQP_SHADOW_SHIELD,EQP_SHADOW_SHOES,EQP_SHADOW_ACC_R,EQP_SHADOW_ACC_L};
- /*==========================================
- * GetEquipID(Pos); Pos: 1-14
- *------------------------------------------*/
- BUILDIN_FUNC(getequipid)
- {
- int i, num;
- TBL_PC* sd;
- struct item_data* item;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
- {
- script_pushint(st,-1);
- return 0;
- }
- // get inventory position of item
- i = pc_checkequip(sd,equip[num]);
- if( i < 0 )
- {
- script_pushint(st,-1);
- return 0;
- }
- item = sd->inventory_data[i];
- if( item != 0 )
- script_pushint(st,item->nameid);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the equipement name at pos
- * return item jname or ""
- *------------------------------------------*/
- BUILDIN_FUNC(getequipname)
- {
- int i, num;
- TBL_PC* sd;
- struct item_data* item;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num = script_getnum(st,2) - 1;
- if( num < 0 || num >= ARRAYLENGTH(equip) )
- {
- script_pushconststr(st,"");
- return 0;
- }
- // get inventory position of item
- i = pc_checkequip(sd,equip[num]);
- if( i < 0 )
- {
- script_pushconststr(st,"");
- return 0;
- }
- item = sd->inventory_data[i];
- if( item != 0 )
- script_pushstrcopy(st,item->jname);
- else
- script_pushconststr(st,"");
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * getbrokenid [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(getbrokenid)
- {
- int i,num,id=0,brokencounter=0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num=script_getnum(st,2);
- for(i=0; i<MAX_INVENTORY; i++) {
- if(sd->status.inventory[i].attribute){
- brokencounter++;
- if(num==brokencounter){
- id=sd->status.inventory[i].nameid;
- break;
- }
- }
- }
- script_pushint(st,id);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * repair [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(repair)
- {
- int i,num;
- int repaircounter=0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num=script_getnum(st,2);
- for(i=0; i<MAX_INVENTORY; i++) {
- if(sd->status.inventory[i].attribute){
- repaircounter++;
- if(num==repaircounter){
- sd->status.inventory[i].attribute=0;
- clif_equiplist(sd);
- clif_produceeffect(sd, 0, sd->status.inventory[i].nameid);
- clif_misceffect(&sd->bl, 3);
- break;
- }
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * repairall
- *------------------------------------------*/
- BUILDIN_FUNC(repairall)
- {
- int i, repaircounter = 0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if(sd == NULL)
- return 0;
- for(i = 0; i < MAX_INVENTORY; i++)
- {
- if(sd->status.inventory[i].nameid && sd->status.inventory[i].attribute)
- {
- sd->status.inventory[i].attribute = 0;
- clif_produceeffect(sd,0,sd->status.inventory[i].nameid);
- repaircounter++;
- }
- }
- if(repaircounter)
- {
- clif_misceffect(&sd->bl, 3);
- clif_equiplist(sd);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Chk if player have something equiped at pos
- *------------------------------------------*/
- BUILDIN_FUNC(getequipisequiped)
- {
- int i = -1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0)
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Chk if the player have something equiped at pos
- * if so chk if this item ain't marked not refinable or rental
- * return (npc)
- * 1 : true
- * 0 : false
- *------------------------------------------*/
- BUILDIN_FUNC(getequipisenableref)
- {
- int i = -1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( num > 0 && num <= ARRAYLENGTH(equip) )
- i = pc_checkequip(sd,equip[num-1]);
- if( i >= 0 && sd->inventory_data[i] && !sd->inventory_data[i]->flag.no_refine && !sd->status.inventory[i].expire_time )
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the item refined value at pos
- * return (npc)
- * x : refine amount
- * 0 : false (not refined)
- *------------------------------------------*/
- BUILDIN_FUNC(getequiprefinerycnt)
- {
- int i = -1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0)
- script_pushint(st,sd->status.inventory[i].refine);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the weapon level value at pos
- * (pos should normally only be EQI_HAND_L or EQI_HAND_R)
- * return (npc)
- * x : weapon level
- * 0 : false
- *------------------------------------------*/
- BUILDIN_FUNC(getequipweaponlv)
- {
- int i = -1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && sd->inventory_data[i])
- script_pushint(st,sd->inventory_data[i]->wlv);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the item refine chance (from refine.txt) for item at pos
- * return (npc)
- * x : refine chance
- * 0 : false (max refine level or unequip..)
- *------------------------------------------*/
- BUILDIN_FUNC(getequippercentrefinery)
- {
- int i = -1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && sd->status.inventory[i].nameid && sd->status.inventory[i].refine < MAX_REFINE)
- script_pushint(st,status_get_refine_chance(itemdb_wlv(sd->status.inventory[i].nameid), (int)sd->status.inventory[i].refine));
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Refine +1 item at pos and log and display refine
- *------------------------------------------*/
- BUILDIN_FUNC(successrefitem)
- {
- int i=-1,num,ep;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- ep=sd->status.inventory[i].equip;
- //Logs items, got from (N)PC scripts [Lupus]
- log_pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i]);
- sd->status.inventory[i].refine++;
- pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below
- clif_refine(sd->fd,0,i,sd->status.inventory[i].refine);
- clif_delitem(sd,i,1,3);
- //Logs items, got from (N)PC scripts [Lupus]
- log_pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i]);
- clif_additem(sd,i,1,0);
- pc_equipitem(sd,i,ep);
- clif_misceffect(&sd->bl,3);
- if(sd->status.inventory[i].refine == MAX_REFINE &&
- sd->status.inventory[i].card[0] == CARD0_FORGE &&
- sd->status.char_id == (int)MakeDWord(sd->status.inventory[i].card[2],sd->status.inventory[i].card[3])
- ){ // Fame point system [DracoRPG]
- switch (sd->inventory_data[i]->wlv){
- case 1:
- pc_addfame(sd,1); // Success to refine to +10 a lv1 weapon you forged = +1 fame point
- break;
- case 2:
- pc_addfame(sd,25); // Success to refine to +10 a lv2 weapon you forged = +25 fame point
- break;
- case 3:
- pc_addfame(sd,1000); // Success to refine to +10 a lv3 weapon you forged = +1000 fame point
- break;
- }
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Show a failed Refine +1 attempt
- *------------------------------------------*/
- BUILDIN_FUNC(failedrefitem)
- {
- int i=-1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- sd->status.inventory[i].refine = 0;
- pc_unequipitem(sd,i,3); //recalculate bonus
- clif_refine(sd->fd,1,i,sd->status.inventory[i].refine); //notify client of failure
- pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT);
- clif_misceffect(&sd->bl,2); // display failure effect
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Downgrades an Equipment Part by -1 . [Masao]
- *------------------------------------------*/
- BUILDIN_FUNC(downrefitem)
- {
- int i = -1,num,ep,down = 1;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- num = script_getnum(st,2);
- if( script_hasdata(st, 3) )
- down = script_getnum(st, 3);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i = pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- ep = sd->status.inventory[i].equip;
- //Logs items, got from (N)PC scripts [Lupus]
- log_pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[i]);
- pc_unequipitem(sd,i,2); // status calc will happen in pc_equipitem() below
- sd->status.inventory[i].refine -= down;
- sd->status.inventory[i].refine = cap_value( sd->status.inventory[i].refine, 0, MAX_REFINE);
- clif_refine(sd->fd,2,i,sd->status.inventory[i].refine);
- clif_delitem(sd,i,1,3);
- //Logs items, got from (N)PC scripts [Lupus]
- log_pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[i]);
- clif_additem(sd,i,1,0);
- pc_equipitem(sd,i,ep);
- clif_misceffect(&sd->bl,2);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Delete the item equipped at pos.
- *------------------------------------------*/
- BUILDIN_FUNC(delequip)
- {
- int i=-1,num,ret=0;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0) {
- pc_unequipitem(sd,i,3); //recalculate bonus
- ret = !(pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT));
- }
- script_pushint(st,ret);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Break the item equipped at pos.
- *------------------------------------------*/
- BUILDIN_FUNC(breakequip)
- {
- int i=-1,num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i = pc_checkequip(sd,equip[num-1]);
- if (i >= 0) {
- sd->status.inventory[i].attribute = 1;
- pc_unequipitem(sd,i,3);
- clif_equiplist(sd);
- script_pushint(st,1);
- } else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(statusup)
- {
- int type;
- TBL_PC *sd;
- type=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_statusup(sd,type);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(statusup2)
- {
- int type,val;
- TBL_PC *sd;
- type=script_getnum(st,2);
- val=script_getnum(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_statusup2(sd,type,val);
- return SCRIPT_CMD_SUCCESS;
- }
- /// See 'doc/item_bonus.txt'
- ///
- /// bonus <bonus type>,<val1>;
- /// bonus2 <bonus type>,<val1>,<val2>;
- /// bonus3 <bonus type>,<val1>,<val2>,<val3>;
- /// bonus4 <bonus type>,<val1>,<val2>,<val3>,<val4>;
- /// bonus5 <bonus type>,<val1>,<val2>,<val3>,<val4>,<val5>;
- BUILDIN_FUNC(bonus)
- {
- int type;
- int val1;
- int val2 = 0;
- int val3 = 0;
- int val4 = 0;
- int val5 = 0;
- TBL_PC* sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- type = script_getnum(st,2);
- switch( type ) {
- case SP_AUTOSPELL:
- case SP_AUTOSPELL_WHENHIT:
- case SP_AUTOSPELL_ONSKILL:
- case SP_SKILL_ATK:
- case SP_SKILL_HEAL:
- case SP_SKILL_HEAL2:
- case SP_ADD_SKILL_BLOW:
- case SP_CASTRATE:
- case SP_ADDEFF_ONSKILL:
- case SP_SKILL_USE_SP_RATE:
- case SP_SKILL_COOLDOWN:
- case SP_SKILL_FIXEDCAST:
- case SP_SKILL_VARIABLECAST:
- case SP_VARCASTRATE:
- case SP_FIXCASTRATE:
- case SP_SKILL_USE_SP:
- // these bonuses support skill names
- data = script_getdata(st, 3);
- get_val(st, data); // Convert into value in case of a variable
- val1 = ( data_isstring(data) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- break;
- default:
- val1 = script_getnum(st,3);
- break;
- }
- switch( script_lastdata(st)-2 ) {
- case 1:
- pc_bonus(sd, type, val1);
- break;
- case 2:
- val2 = script_getnum(st,4);
- pc_bonus2(sd, type, val1, val2);
- break;
- case 3:
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- pc_bonus3(sd, type, val1, val2, val3);
- break;
- case 4:
- data = script_getdata(st, 4);
- get_val(st, data); // Convert into value in case of a variable
- if( type == SP_AUTOSPELL_ONSKILL && data_isstring(data) )
- val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name
- else
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- val4 = script_getnum(st,6);
- pc_bonus4(sd, type, val1, val2, val3, val4);
- break;
- case 5:
- data = script_getdata(st, 4);
- get_val(st, data); // Convert into value in case of a variable
- if( type == SP_AUTOSPELL_ONSKILL && data_isstring(data) )
- val2 = skill_name2id(script_getstr(st,4)); // 2nd value can be skill name
- else
- val2 = script_getnum(st,4);
- val3 = script_getnum(st,5);
- val4 = script_getnum(st,6);
- val5 = script_getnum(st,7);
- pc_bonus5(sd, type, val1, val2, val3, val4, val5);
- break;
- default:
- ShowDebug("buildin_bonus: unexpected number of arguments (%d)\n", (script_lastdata(st) - 1));
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(autobonus)
- {
- unsigned int dur;
- short rate;
- short atk_type = 0;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !bonus_script )
- return 0;
- if( script_hasdata(st,5) )
- atk_type = script_getnum(st,5);
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus,ARRAYLENGTH(sd->autobonus),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(autobonus2)
- {
- unsigned int dur;
- short rate;
- short atk_type = 0;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !bonus_script )
- return 0;
- if( script_hasdata(st,5) )
- atk_type = script_getnum(st,5);
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus2,ARRAYLENGTH(sd->autobonus2),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,false) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(autobonus3)
- {
- unsigned int dur;
- short rate,atk_type;
- TBL_PC* sd;
- const char *bonus_script, *other_script = NULL;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0; // no player attached
- if( sd->state.autobonus&sd->status.inventory[current_equip_item_index].equip )
- return 0;
- rate = script_getnum(st,3);
- dur = script_getnum(st,4);
- data = script_getdata(st, 5);
- get_val(st, data); // Convert into value in case of a variable
- atk_type = ( data_isstring(data) ? skill_name2id(script_getstr(st,5)) : script_getnum(st,5) );
- bonus_script = script_getstr(st,2);
- if( !rate || !dur || !atk_type || !bonus_script )
- return 0;
- if( script_hasdata(st,6) )
- other_script = script_getstr(st,6);
- if( pc_addautobonus(sd->autobonus3,ARRAYLENGTH(sd->autobonus3),
- bonus_script,rate,dur,atk_type,other_script,sd->status.inventory[current_equip_item_index].equip,true) )
- {
- script_add_autobonus(bonus_script);
- if( other_script )
- script_add_autobonus(other_script);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Changes the level of a player skill.
- /// <flag> defaults to 1
- /// <flag>=0 : set the level of the skill
- /// <flag>=1 : set the temporary level of the skill
- /// <flag>=2 : add to the level of the skill
- ///
- /// skill <skill id>,<level>,<flag>
- /// skill <skill id>,<level>
- /// skill "<skill name>",<level>,<flag>
- /// skill "<skill name>",<level>
- BUILDIN_FUNC(skill)
- {
- int id;
- int level;
- int flag = 1;
- TBL_PC* sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- id = ( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- if( script_hasdata(st,4) )
- flag = script_getnum(st,4);
- pc_skill(sd, id, level, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Changes the level of a player skill.
- /// like skill, but <flag> defaults to 2
- ///
- /// addtoskill <skill id>,<amount>,<flag>
- /// addtoskill <skill id>,<amount>
- /// addtoskill "<skill name>",<amount>,<flag>
- /// addtoskill "<skill name>",<amount>
- ///
- /// @see skill
- BUILDIN_FUNC(addtoskill)
- {
- int id;
- int level;
- int flag = 2;
- TBL_PC* sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- id = ( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- if( script_hasdata(st,4) )
- flag = script_getnum(st,4);
- pc_skill(sd, id, level, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Increases the level of a guild skill.
- ///
- /// guildskill <skill id>,<amount>;
- /// guildskill "<skill name>",<amount>;
- BUILDIN_FUNC(guildskill)
- {
- int id;
- int level;
- TBL_PC* sd;
- int i;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- id = ( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- level = script_getnum(st,3);
- for( i=0; i < level; i++ )
- guild_skillup(sd, id);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the level of the player skill.
- ///
- /// getskilllv(<skill id>) -> <level>
- /// getskilllv("<skill name>") -> <level>
- BUILDIN_FUNC(getskilllv)
- {
- int id;
- TBL_PC* sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- id = ( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- script_pushint(st, pc_checkskill(sd,id));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the level of the guild skill.
- ///
- /// getgdskilllv(<guild id>,<skill id>) -> <level>
- /// getgdskilllv(<guild id>,"<skill name>") -> <level>
- BUILDIN_FUNC(getgdskilllv)
- {
- int guild_id;
- uint16 skill_id;
- struct guild* g;
- struct script_data *data;
- guild_id = script_getnum(st,2);
- data = script_getdata(st, 3);
- get_val(st, data); // Convert into value in case of a variable
- skill_id = ( data_isstring(data) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- g = guild_search(guild_id);
- if( g == NULL )
- script_pushint(st, -1);
- else
- script_pushint(st, guild_checkskill(g,skill_id));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the 'basic_skill_check' setting.
- /// This config determines if the server checks the skill level of NV_BASIC
- /// before allowing the basic actions.
- ///
- /// basicskillcheck() -> <bool>
- BUILDIN_FUNC(basicskillcheck)
- {
- script_pushint(st, battle_config.basic_skill_check);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the GM level of the player.
- ///
- /// getgmlevel() -> <level>
- BUILDIN_FUNC(getgmlevel)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- script_pushint(st, pc_get_group_level(sd));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the group ID of the player.
- ///
- /// getgroupid() -> <int>
- BUILDIN_FUNC(getgroupid)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if (sd == NULL)
- return 1; // no player attached, report source
- script_pushint(st, pc_get_group_id(sd));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Terminates the execution of this script instance.
- ///
- /// end
- BUILDIN_FUNC(end)
- {
- TBL_PC* sd;
- sd = map_id2sd(st->rid);
- st->state = END;
- if( st->mes_active )
- st->mes_active = 0;
- if( sd )
- clif_scriptclose(sd, st->oid); // If a menu/select/prompt is active, close it.
- return SCRIPT_CMD_SUCCESS;
- }
- /// Checks if the player has that effect state (option).
- ///
- /// checkoption(<option>) -> <bool>
- BUILDIN_FUNC(checkoption)
- {
- int option;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- option = script_getnum(st,2);
- if( sd->sc.option&option )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Checks if the player is in that body state (opt1).
- ///
- /// checkoption1(<opt1>) -> <bool>
- BUILDIN_FUNC(checkoption1)
- {
- int opt1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- opt1 = script_getnum(st,2);
- if( sd->sc.opt1 == opt1 )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Checks if the player has that health state (opt2).
- ///
- /// checkoption2(<opt2>) -> <bool>
- BUILDIN_FUNC(checkoption2)
- {
- int opt2;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- opt2 = script_getnum(st,2);
- if( sd->sc.opt2&opt2 )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Changes the effect state (option) of the player.
- /// <flag> defaults to 1
- /// <flag>=0 : removes the option
- /// <flag>=other : adds the option
- ///
- /// setoption <option>,<flag>;
- /// setoption <option>;
- BUILDIN_FUNC(setoption)
- {
- int option;
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- option = script_getnum(st,2);
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- else if( !option ){// Request to remove everything.
- flag = 0;
- option = OPTION_FALCON|OPTION_RIDING;
- #ifndef NEW_CARTS
- option |= OPTION_CART;
- #endif
- }
- if( flag ){// Add option
- if( option&OPTION_WEDDING && !battle_config.wedding_modifydisplay )
- option &= ~OPTION_WEDDING;// Do not show the wedding sprites
- pc_setoption(sd, sd->sc.option|option);
- } else// Remove option
- pc_setoption(sd, sd->sc.option&~option);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns if the player has a cart.
- ///
- /// checkcart() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkcart)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_iscarton(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets the cart of the player.
- /// <type> defaults to 1
- /// <type>=0 : removes the cart
- /// <type>=1 : Normal cart
- /// <type>=2 : Wooden cart
- /// <type>=3 : Covered cart with flowers and ferns
- /// <type>=4 : Wooden cart with a Panda doll on the back
- /// <type>=5 : Normal cart with bigger wheels, a roof and a banner on the back
- ///
- /// setcart <type>;
- /// setcart;
- BUILDIN_FUNC(setcart)
- {
- int type = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- type = script_getnum(st,2);
- pc_setcart(sd, type);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns if the player has a falcon.
- ///
- /// checkfalcon() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkfalcon)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_isfalcon(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets if the player has a falcon or not.
- /// <flag> defaults to 1
- ///
- /// setfalcon <flag>;
- /// setfalcon;
- BUILDIN_FUNC(setfalcon)
- {
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- flag = script_getnum(st,2);
- pc_setfalcon(sd, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns if the player is riding.
- ///
- /// checkriding() -> <bool>
- ///
- /// @author Valaris
- BUILDIN_FUNC(checkriding)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_isriding(sd) || pc_isridingwug(sd) || pc_isridingdragon(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets if the player is riding.
- /// <flag> defaults to 1
- ///
- /// setriding <flag>;
- /// setriding;
- BUILDIN_FUNC(setriding)
- {
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- flag = script_getnum(st,2);
- pc_setriding(sd, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns if the player has a warg.
- ///
- /// checkwug() -> <bool>
- ///
- BUILDIN_FUNC(checkwug)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_iswug(sd) || pc_isridingwug(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns if the player is wearing MADO Gear.
- ///
- /// checkmadogear() -> <bool>
- ///
- BUILDIN_FUNC(checkmadogear)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( pc_ismadogear(sd) )
- script_pushint(st, 1);
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets if the player is riding MADO Gear.
- /// <flag> defaults to 1
- ///
- /// setmadogear <flag>;
- /// setmadogear;
- BUILDIN_FUNC(setmadogear)
- {
- int flag = 1;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- if( script_hasdata(st,2) )
- flag = script_getnum(st,2);
- pc_setmadogear(sd, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets the save point of the player.
- ///
- /// save "<map name>",<x>,<y>
- /// savepoint "<map name>",<x>,<y>
- BUILDIN_FUNC(savepoint)
- {
- int x;
- int y;
- short map;
- const char* str;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached, report source
- str = script_getstr(st, 2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- map = mapindex_name2id(str);
- if( map )
- pc_setsavepoint(sd, map, x, y);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * GetTimeTick(0: System Tick, 1: Time Second Tick)
- *------------------------------------------*/
- BUILDIN_FUNC(gettimetick) /* Asgard Version */
- {
- int type;
- time_t timer;
- struct tm *t;
- type=script_getnum(st,2);
- switch(type){
- case 2:
- //type 2:(Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC
- // from the system clock.)
- script_pushint(st,(int)time(NULL));
- break;
- case 1:
- //type 1:(Second Ticks: 0-86399, 00:00:00-23:59:59)
- time(&timer);
- t=localtime(&timer);
- script_pushint(st,((t->tm_hour)*3600+(t->tm_min)*60+t->tm_sec));
- break;
- case 0:
- default:
- //type 0:(System Ticks)
- script_pushint(st,gettick());
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * GetTime(Type);
- * 1: Sec 2: Min 3: Hour
- * 4: WeekDay 5: MonthDay 6: Month
- * 7: Year
- *------------------------------------------*/
- BUILDIN_FUNC(gettime) /* Asgard Version */
- {
- int type;
- time_t timer;
- struct tm *t;
- type=script_getnum(st,2);
- time(&timer);
- t=localtime(&timer);
- switch(type){
- case 1://Sec(0~59)
- script_pushint(st,t->tm_sec);
- break;
- case 2://Min(0~59)
- script_pushint(st,t->tm_min);
- break;
- case 3://Hour(0~23)
- script_pushint(st,t->tm_hour);
- break;
- case 4://WeekDay(0~6)
- script_pushint(st,t->tm_wday);
- break;
- case 5://MonthDay(01~31)
- script_pushint(st,t->tm_mday);
- break;
- case 6://Month(01~12)
- script_pushint(st,t->tm_mon+1);
- break;
- case 7://Year(20xx)
- script_pushint(st,t->tm_year+1900);
- break;
- case 8://Year Day(01~366)
- script_pushint(st,t->tm_yday+1);
- break;
- default://(format error)
- script_pushint(st,-1);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * GetTimeStr("TimeFMT", Length);
- *------------------------------------------*/
- BUILDIN_FUNC(gettimestr)
- {
- char *tmpstr;
- const char *fmtstr;
- int maxlen;
- time_t now = time(NULL);
- fmtstr=script_getstr(st,2);
- maxlen=script_getnum(st,3);
- tmpstr=(char *)aMalloc((maxlen+1)*sizeof(char));
- strftime(tmpstr,maxlen,fmtstr,localtime(&now));
- tmpstr[maxlen]='\0';
- script_pushstr(st,tmpstr);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Open player storage
- *------------------------------------------*/
- BUILDIN_FUNC(openstorage)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- storage_storageopen(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(guildopenstorage)
- {
- TBL_PC* sd;
- int ret;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- ret = storage_guild_storageopen(sd);
- script_pushint(st,ret);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Make player use a skill trought item usage
- *------------------------------------------*/
- /// itemskill <skill id>,<level>
- /// itemskill "<skill name>",<level>
- BUILDIN_FUNC(itemskill)
- {
- int id;
- int lv;
- TBL_PC* sd;
- struct script_data *data;
- sd = script_rid2sd(st);
- if( sd == NULL || sd->ud.skilltimer != INVALID_TIMER )
- return 0;
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- id = ( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- lv = script_getnum(st,3);
- sd->skillitem=id;
- sd->skillitemlv=lv;
- clif_item_skill(sd,id,lv);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Attempt to create an item
- *------------------------------------------*/
- BUILDIN_FUNC(produce)
- {
- int trigger;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- trigger=script_getnum(st,2);
- clif_skill_produce_mix_list(sd, -1, trigger);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(cooking)
- {
- int trigger;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- trigger=script_getnum(st,2);
- clif_cooking_list(sd, trigger, AM_PHARMACY, 1, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Create a pet
- *------------------------------------------*/
- BUILDIN_FUNC(makepet)
- {
- TBL_PC* sd;
- int id,pet_id;
- id=script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pet_id = search_petDB_index(id, PET_CLASS);
- if (pet_id < 0)
- pet_id = search_petDB_index(id, PET_EGG);
- if (pet_id >= 0 && sd) {
- sd->catch_target_class = pet_db[pet_id].class_;
- intif_create_pet(
- sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Give player exp base,job * quest_exp_rate/100
- *------------------------------------------*/
- BUILDIN_FUNC(getexp)
- {
- TBL_PC* sd;
- int base=0,job=0;
- double bonus;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- base=script_getnum(st,2);
- job =script_getnum(st,3);
- if(base<0 || job<0)
- return 0;
- // bonus for npc-given exp
- bonus = battle_config.quest_exp_rate / 100.;
- base = (int) cap_value(base * bonus, 0, INT_MAX);
- job = (int) cap_value(job * bonus, 0, INT_MAX);
- pc_gainexp(sd, NULL, base, job, true);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Gain guild exp [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(guildgetexp)
- {
- TBL_PC* sd;
- int exp;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- exp = script_getnum(st,2);
- if(exp < 0)
- return 0;
- if(sd && sd->status.guild_id > 0)
- guild_getexp (sd, exp);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Changes the guild master of a guild [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(guildchangegm)
- {
- TBL_PC *sd;
- int guild_id;
- const char *name;
- guild_id = script_getnum(st,2);
- name = script_getstr(st,3);
- sd=map_nick2sd(name);
- if (!sd)
- script_pushint(st,0);
- else
- script_pushint(st,guild_gm_change(guild_id, sd));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Spawn a monster :
- * *monster "<map name>",<x>,<y>,"<name to show>",<mob id>,<amount>{,"<event label>",<size>,<ai>};
- @mapn,x,y : location
- @str : monster name
- @class_ : mob_id
- @amount : nb to spawn
- @event : event to attach to mob
- *------------------------------------------*/
- BUILDIN_FUNC(monster)
- {
- const char* mapn = script_getstr(st,2);
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- const char* str = script_getstr(st,5);
- int class_ = script_getnum(st,6);
- int amount = script_getnum(st,7);
- const char* event = "";
- unsigned int size = SZ_SMALL;
- unsigned int ai = AI_NONE;
- struct map_session_data* sd;
- int16 m;
- int i;
- if (script_hasdata(st, 8)) {
- event = script_getstr(st, 8);
- check_event(st, event);
- }
- if (script_hasdata(st, 9)) {
- size = script_getnum(st, 9);
- if (size > 3) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_);
- return 1;
- }
- }
- if (script_hasdata(st, 10)) {
- ai = script_getnum(st, 10);
- if (ai >= AI_MAX) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_);
- return 1;
- }
- }
- if (class_ >= 0 && !mobdb_checkid(class_)) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
- return 1;
- }
- sd = map_id2sd(st->rid);
- if (sd && strcmp(mapn, "this") == 0)
- m = sd->bl.m;
- else
- m = map_mapname2mapid(mapn);
- for(i=0; i<amount; i++){ //not optimised
- int mobid = mob_once_spawn(sd, m, x, y, str, class_, 1, event, size, ai);
- mapreg_setreg(reference_uid(add_str("$@mobid"), i),mobid);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Request List of Monster Drops
- *------------------------------------------*/
- BUILDIN_FUNC(getmobdrops)
- {
- int class_ = script_getnum(st,2);
- int i, j = 0;
- struct mob_db *mob;
- if( !mobdb_checkid(class_) )
- {
- script_pushint(st, 0);
- return 0;
- }
- mob = mob_db(class_);
- for( i = 0; i < MAX_MOB_DROP; i++ )
- {
- if( mob->dropitem[i].nameid < 1 )
- continue;
- if( itemdb_exists(mob->dropitem[i].nameid) == NULL )
- continue;
- mapreg_setreg(reference_uid(add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid);
- mapreg_setreg(reference_uid(add_str("$@MobDrop_rate"), j), mob->dropitem[i].p);
- j++;
- }
- mapreg_setreg(add_str("$@MobDrop_count"), j);
- script_pushint(st, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Same as monster but randomize location in x0,x1,y0,y1 area
- *------------------------------------------*/
- BUILDIN_FUNC(areamonster)
- {
- const char* mapn = script_getstr(st,2);
- int x0 = script_getnum(st,3);
- int y0 = script_getnum(st,4);
- int x1 = script_getnum(st,5);
- int y1 = script_getnum(st,6);
- const char* str = script_getstr(st,7);
- int class_ = script_getnum(st,8);
- int amount = script_getnum(st,9);
- const char* event = "";
- unsigned int size = SZ_SMALL;
- unsigned int ai = AI_NONE;
- struct map_session_data* sd;
- int16 m;
- if (script_hasdata(st,10)) {
- event = script_getstr(st, 10);
- check_event(st, event);
- }
- if (script_hasdata(st, 11)) {
- size = script_getnum(st, 11);
- if (size > 3) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing size %d for monster class %d\n", size, class_);
- return 1;
- }
- }
- if (script_hasdata(st, 12)) {
- ai = script_getnum(st, 12);
- if (ai >= AI_MAX) {
- ShowWarning("buildin_monster: Attempted to spawn non-existing ai %d for monster class %d\n", ai, class_);
- return 1;
- }
- }
- sd = map_id2sd(st->rid);
- if (sd && strcmp(mapn, "this") == 0)
- m = sd->bl.m;
- else
- m = map_mapname2mapid(mapn);
- mob_once_spawn_area(sd, m, x0, y0, x1, y1, str, class_, amount, event, size, ai);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * KillMonster subcheck, verify if mob to kill ain't got an even to handle, could be force kill by allflag
- *------------------------------------------*/
- static int buildin_killmonster_sub_strip(struct block_list *bl,va_list ap)
- { //same fix but with killmonster instead - stripping events from mobs.
- TBL_MOB* md = (TBL_MOB*)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
- md->state.npc_killmonster = 1;
- if(!allflag){
- if(strcmp(event,md->npc_event)==0)
- status_kill(bl);
- }else{
- if(!md->spawn)
- status_kill(bl);
- }
- md->state.npc_killmonster = 0;
- return 0;
- }
- static int buildin_killmonster_sub(struct block_list *bl,va_list ap)
- {
- TBL_MOB* md = (TBL_MOB*)bl;
- char *event=va_arg(ap,char *);
- int allflag=va_arg(ap,int);
- if(!allflag){
- if(strcmp(event,md->npc_event)==0)
- status_kill(bl);
- }else{
- if(!md->spawn)
- status_kill(bl);
- }
- return 0;
- }
- BUILDIN_FUNC(killmonster)
- {
- const char *mapname,*event;
- int16 m,allflag=0;
- mapname=script_getstr(st,2);
- event=script_getstr(st,3);
- if(strcmp(event,"All")==0)
- allflag = 1;
- else
- check_event(st, event);
- if( (m=map_mapname2mapid(mapname))<0 )
- return 0;
- if( script_hasdata(st,4) ) {
- if ( script_getnum(st,4) == 1 ) {
- map_foreachinmap(buildin_killmonster_sub, m, BL_MOB, event ,allflag);
- return 0;
- }
- }
- map_freeblock_lock();
- map_foreachinmap(buildin_killmonster_sub_strip, m, BL_MOB, event ,allflag);
- map_freeblock_unlock();
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_killmonsterall_sub_strip(struct block_list *bl,va_list ap)
- { //Strips the event from the mob if it's killed the old method.
- struct mob_data *md;
- md = BL_CAST(BL_MOB, bl);
- if (md->npc_event[0])
- md->npc_event[0] = 0;
- status_kill(bl);
- return 0;
- }
- static int buildin_killmonsterall_sub(struct block_list *bl,va_list ap)
- {
- status_kill(bl);
- return 0;
- }
- BUILDIN_FUNC(killmonsterall)
- {
- const char *mapname;
- int16 m;
- mapname=script_getstr(st,2);
- if( (m = map_mapname2mapid(mapname))<0 )
- return 0;
- if( script_hasdata(st,3) ) {
- if ( script_getnum(st,3) == 1 ) {
- map_foreachinmap(buildin_killmonsterall_sub,m,BL_MOB);
- return 0;
- }
- }
- map_foreachinmap(buildin_killmonsterall_sub_strip,m,BL_MOB);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Creates a clone of a player.
- * clone map, x, y, event, char_id, master_id, mode, flag, duration
- *------------------------------------------*/
- BUILDIN_FUNC(clone)
- {
- TBL_PC *sd, *msd=NULL;
- int char_id,master_id=0,x,y, mode = 0, flag = 0, m;
- unsigned int duration = 0;
- const char *map,*event="";
- map=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- event=script_getstr(st,5);
- char_id=script_getnum(st,6);
- if( script_hasdata(st,7) )
- master_id=script_getnum(st,7);
- if( script_hasdata(st,8) )
- mode=script_getnum(st,8);
- if( script_hasdata(st,9) )
- flag=script_getnum(st,9);
- if( script_hasdata(st,10) )
- duration=script_getnum(st,10);
- check_event(st, event);
- m = map_mapname2mapid(map);
- if (m < 0) return 0;
- sd = map_charid2sd(char_id);
- if (master_id) {
- msd = map_charid2sd(master_id);
- if (msd)
- master_id = msd->bl.id;
- else
- master_id = 0;
- }
- if (sd) //Return ID of newly crafted clone.
- script_pushint(st,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
- else //Failed to create clone.
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(doevent)
- {
- const char* event = script_getstr(st,2);
- struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
- {
- return 0;
- }
- check_event(st, event);
- npc_event(sd, event, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(donpcevent)
- {
- const char* event = script_getstr(st,2);
- check_event(st, event);
- if( !npc_event_do(event) ) {
- struct npc_data * nd = map_id2nd(st->oid);
- ShowDebug("NPCEvent '%s' not found! (source: %s)\n",event,nd?nd->name:"Unknown");
- script_pushint(st, 0);
- } else
- script_pushint(st, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- /// for Aegis compatibility
- /// basically a specialized 'donpcevent', with the event specified as two arguments instead of one
- BUILDIN_FUNC(cmdothernpc) // Added by RoVeRT
- {
- const char* npc = script_getstr(st,2);
- const char* command = script_getstr(st,3);
- char event[EVENT_NAME_LENGTH];
- snprintf(event, sizeof(event), "%s::OnCommand%s", npc, command);
- check_event(st, event);
- npc_event_do(event);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(addtimer)
- {
- int tick = script_getnum(st,2);
- const char* event = script_getstr(st, 3);
- TBL_PC* sd;
- check_event(st, event);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_addeventtimer(sd,tick,event);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(deltimer)
- {
- const char *event;
- TBL_PC* sd;
- event=script_getstr(st, 2);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- check_event(st, event);
- pc_deleventtimer(sd,event);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(addtimercount)
- {
- const char *event;
- int tick;
- TBL_PC* sd;
- tick=script_getnum(st,2);
- event=script_getstr(st,3);
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- check_event(st, event);
- pc_addeventtimercount(sd,event,tick);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(initnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Attach
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- nd->u.scr.rid = sd->bl.id;
- }
- nd->u.scr.timertick = 0;
- npc_settimerevent_tick(nd,0);
- npc_timerevent_start(nd, st->rid);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(startnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd=(struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Attach
- {
- TBL_PC* sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- nd->u.scr.rid = sd->bl.id;
- }
- npc_timerevent_start(nd, st->rid);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(stopnpctimer)
- {
- struct npc_data *nd;
- int flag = 0;
- if( script_hasdata(st,3) )
- { //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
- flag = script_getnum(st,3);
- }
- else if( script_hasdata(st,2) )
- { //Check if argument is numeric (flag) or string (npc name)
- struct script_data *data;
- data = script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ) //NPC name
- nd = npc_name2id(conv_str(st, data));
- else if( data_isint(data) ) //Flag
- {
- nd = (struct npc_data *)map_id2bl(st->oid);
- flag = conv_num(st,data);
- }
- else
- {
- ShowError("initnpctimer: invalid argument type #1 (needs be int or string)).\n");
- return 1;
- }
- }
- else
- nd=(struct npc_data *)map_id2bl(st->oid);
- if( !nd )
- return 0;
- if( flag ) //Detach
- nd->u.scr.rid = 0;
- npc_timerevent_stop(nd);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(getnpctimer)
- {
- struct npc_data *nd;
- TBL_PC *sd;
- int type = script_getnum(st,2);
- int val = 0;
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,0);
- ShowError("getnpctimer: Invalid NPC.\n");
- return 1;
- }
- switch( type )
- {
- case 0: val = npc_gettimerevent_tick(nd); break;
- case 1:
- if( nd->u.scr.rid )
- {
- sd = map_id2sd(nd->u.scr.rid);
- if( !sd )
- {
- ShowError("buildin_getnpctimer: Attached player not found!\n");
- break;
- }
- val = (sd->npc_timer_id != INVALID_TIMER);
- }
- else
- val = (nd->u.scr.timerid != INVALID_TIMER);
- break;
- case 2: val = nd->u.scr.timeramount; break;
- }
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(setnpctimer)
- {
- int tick;
- struct npc_data *nd;
- tick = script_getnum(st,2);
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("setnpctimer: Invalid NPC.\n");
- return 1;
- }
- npc_settimerevent_tick(nd,tick);
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * attaches the player rid to the timer [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(attachnpctimer)
- {
- TBL_PC *sd;
- struct npc_data *nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("setnpctimer: Invalid NPC.\n");
- return 1;
- }
- if( script_hasdata(st,2) )
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if( !sd )
- {
- script_pushint(st,1);
- ShowWarning("attachnpctimer: Invalid player.\n");
- return 1;
- }
- nd->u.scr.rid = sd->bl.id;
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * detaches a player rid from the timer [Celest]
- *------------------------------------------*/
- BUILDIN_FUNC(detachnpctimer)
- {
- struct npc_data *nd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( !nd || nd->bl.type != BL_NPC )
- {
- script_pushint(st,1);
- ShowError("detachnpctimer: Invalid NPC.\n");
- return 1;
- }
- nd->u.scr.rid = 0;
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * To avoid "player not attached" script errors, this function is provided,
- * it checks if there is a player attached to the current script. [Skotlex]
- * If no, returns 0, if yes, returns the account_id of the attached player.
- *------------------------------------------*/
- BUILDIN_FUNC(playerattached)
- {
- if(st->rid == 0 || map_id2sd(st->rid) == NULL)
- script_pushint(st,0);
- else
- script_pushint(st,st->rid);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(announce)
- {
- const char *mes = script_getstr(st,2);
- int flag = script_getnum(st,3);
- const char *fontColor = script_hasdata(st,4) ? script_getstr(st,4) : NULL;
- int fontType = script_hasdata(st,5) ? script_getnum(st,5) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,6) ? script_getnum(st,6) : 12; // default fontSize
- int fontAlign = script_hasdata(st,7) ? script_getnum(st,7) : 0; // default fontAlign
- int fontY = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontY
- if (flag&0x0f) // Broadcast source or broadcast region defined
- {
- send_target target;
- struct block_list *bl = (flag&0x08) ? map_id2bl(st->oid) : (struct block_list *)script_rid2sd(st); // If bc_npc flag is set, use NPC as broadcast source
- if (bl == NULL)
- return 0;
- flag &= 0x07;
- target = (flag == 1) ? ALL_SAMEMAP :
- (flag == 2) ? AREA :
- (flag == 3) ? SELF :
- ALL_CLIENT;
- if (fontColor)
- clif_broadcast2(bl, mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, target);
- else
- clif_broadcast(bl, mes, (int)strlen(mes)+1, flag&0xf0, target);
- }
- else
- {
- if (fontColor)
- intif_broadcast2(mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY);
- else
- intif_broadcast(mes, (int)strlen(mes)+1, flag&0xf0);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- static int buildin_announce_sub(struct block_list *bl, va_list ap)
- {
- char *mes = va_arg(ap, char *);
- int len = va_arg(ap, int);
- int type = va_arg(ap, int);
- char *fontColor = va_arg(ap, char *);
- short fontType = (short)va_arg(ap, int);
- short fontSize = (short)va_arg(ap, int);
- short fontAlign = (short)va_arg(ap, int);
- short fontY = (short)va_arg(ap, int);
- if (fontColor)
- clif_broadcast2(bl, mes, len, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY, SELF);
- else
- clif_broadcast(bl, mes, len, type, SELF);
- return 0;
- }
- BUILDIN_FUNC(mapannounce)
- {
- const char *mapname = script_getstr(st,2);
- const char *mes = script_getstr(st,3);
- int flag = script_getnum(st,4);
- const char *fontColor = script_hasdata(st,5) ? script_getstr(st,5) : NULL;
- int fontType = script_hasdata(st,6) ? script_getnum(st,6) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,7) ? script_getnum(st,7) : 12; // default fontSize
- int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign
- int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY
- int16 m;
- if ((m = map_mapname2mapid(mapname)) < 0)
- return 0;
- map_foreachinmap(buildin_announce_sub, m, BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(areaannounce)
- {
- const char *mapname = script_getstr(st,2);
- int x0 = script_getnum(st,3);
- int y0 = script_getnum(st,4);
- int x1 = script_getnum(st,5);
- int y1 = script_getnum(st,6);
- const char *mes = script_getstr(st,7);
- int flag = script_getnum(st,8);
- const char *fontColor = script_hasdata(st,9) ? script_getstr(st,9) : NULL;
- int fontType = script_hasdata(st,10) ? script_getnum(st,10) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,11) ? script_getnum(st,11) : 12; // default fontSize
- int fontAlign = script_hasdata(st,12) ? script_getnum(st,12) : 0; // default fontAlign
- int fontY = script_hasdata(st,13) ? script_getnum(st,13) : 0; // default fontY
- int16 m;
- if ((m = map_mapname2mapid(mapname)) < 0)
- return 0;
- map_foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(getusers)
- {
- int flag, val = 0;
- struct map_session_data* sd;
- struct block_list* bl = NULL;
- flag = script_getnum(st,2);
- switch(flag&0x07)
- {
- case 0:
- if(flag&0x8)
- {// npc
- bl = map_id2bl(st->oid);
- }
- else if((sd = script_rid2sd(st))!=NULL)
- {// pc
- bl = &sd->bl;
- }
- if(bl)
- {
- val = map[bl->m].users;
- }
- break;
- case 1:
- val = map_getusers();
- break;
- default:
- ShowWarning("buildin_getusers: Unknown type %d.\n", flag);
- script_pushint(st,0);
- return 1;
- }
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Works like @WHO - displays all online users names in window
- *------------------------------------------*/
- BUILDIN_FUNC(getusersname)
- {
- TBL_PC *sd, *pl_sd;
- int /*disp_num=1,*/ group_level = 0;
- struct s_mapiterator* iter;
- sd = script_rid2sd(st);
- if (!sd) return 0;
- group_level = pc_get_group_level(sd);
- iter = mapit_getallusers();
- for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
- {
- if (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > group_level)
- continue; // skip hidden sessions
- /* Temporary fix for bugreport:1023.
- * Do not uncomment unless you want thousands of 'next' buttons.
- if((disp_num++)%10==0)
- clif_scriptnext(sd,st->oid);*/
- clif_scriptmes(sd,st->oid,pl_sd->status.name);
- }
- mapit_free(iter);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * getmapguildusers("mapname",guild ID) Returns the number guild members present on a map [Reddozen]
- *------------------------------------------*/
- BUILDIN_FUNC(getmapguildusers)
- {
- const char *str;
- int16 m;
- int gid;
- int i=0,c=0;
- struct guild *g = NULL;
- str=script_getstr(st,2);
- gid=script_getnum(st,3);
- if ((m = map_mapname2mapid(str)) < 0) { // map id on this server (m == -1 if not in actual map-server)
- script_pushint(st,-1);
- return 0;
- }
- g = guild_search(gid);
- if (g){
- for(i = 0; i < g->max_member; i++)
- {
- if (g->member[i].sd && g->member[i].sd->bl.m == m)
- c++;
- }
- }
- script_pushint(st,c);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(getmapusers)
- {
- const char *str;
- int16 m;
- str=script_getstr(st,2);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,map[m].users);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- static int buildin_getareausers_sub(struct block_list *bl,va_list ap)
- {
- int *users=va_arg(ap,int *);
- (*users)++;
- return 0;
- }
- BUILDIN_FUNC(getareausers)
- {
- const char *str;
- int16 m,x0,y0,x1,y1,users=0; //doubt we can have more then 32k users on
- str=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- map_foreachinarea(buildin_getareausers_sub,
- m,x0,y0,x1,y1,BL_PC,&users);
- script_pushint(st,users);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- static int buildin_getareadropitem_sub(struct block_list *bl,va_list ap)
- {
- int item=va_arg(ap,int);
- int *amount=va_arg(ap,int *);
- struct flooritem_data *drop=(struct flooritem_data *)bl;
- if(drop->item_data.nameid==item)
- (*amount)+=drop->item_data.amount;
- return 0;
- }
- BUILDIN_FUNC(getareadropitem)
- {
- const char *str;
- int16 m,x0,y0,x1,y1;
- int item,amount=0;
- struct script_data *data;
- str=script_getstr(st,2);
- x0=script_getnum(st,3);
- y0=script_getnum(st,4);
- x1=script_getnum(st,5);
- y1=script_getnum(st,6);
- data=script_getdata(st,7);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- item=UNKNOWN_ITEM_ID;
- if( item_data )
- item=item_data->nameid;
- }else
- item=conv_num(st,data);
- if( (m=map_mapname2mapid(str))< 0){
- script_pushint(st,-1);
- return 0;
- }
- map_foreachinarea(buildin_getareadropitem_sub,
- m,x0,y0,x1,y1,BL_ITEM,item,&amount);
- script_pushint(st,amount);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(enablenpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(disablenpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(hideoffnpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,2);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(hideonnpc)
- {
- const char *str;
- str=script_getstr(st,2);
- npc_enable(str,4);
- return SCRIPT_CMD_SUCCESS;
- }
- /* Starts a status effect on the target unit or on the attached player.
- *
- * sc_start <effect_id>,<duration>,<val1>{,<rate>,<flag>,{<unit_id>}};
- * sc_start2 <effect_id>,<duration>,<val1>,<val2>{,<rate,<flag>,{<unit_id>}};
- * sc_start4 <effect_id>,<duration>,<val1>,<val2>,<val3>,<val4>{,<rate,<flag>,{<unit_id>}};
- * <flag>
- * &1: Cannot be avoided (it has to start)
- * &2: Tick should not be reduced (by vit, luk, lv, etc)
- * &4: sc_data loaded, no value has to be altered.
- * &8: rate should not be reduced
- */
- BUILDIN_FUNC(sc_start)
- {
- TBL_NPC * nd = map_id2nd(st->oid);
- struct block_list* bl;
- enum sc_type type;
- int tick, val1, val2, val3, val4=0, rate, flag;
- char start_type;
- const char* command = script_getfuncname(st);
- if(strstr(command, "4"))
- start_type = 4;
- else if(strstr(command, "2"))
- start_type = 2;
- else
- start_type = 1;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- //If from NPC we make default flag 1 to be unavoidable
- if(nd && nd->bl.id == fake_nd->bl.id)
- flag = script_hasdata(st,5+start_type)?script_getnum(st,5+start_type):2;
- else
- flag = script_hasdata(st,5+start_type)?script_getnum(st,5+start_type):1;
- rate = script_hasdata(st,4+start_type)?min(script_getnum(st,4+start_type),10000):10000;
- if(script_hasdata(st,(6+start_type)))
- bl = map_id2bl(script_getnum(st,(6+start_type)));
- else
- bl = map_id2bl(st->rid);
- if(tick == 0 && val1 > 0 && type > SC_NONE && type < SC_MAX && status_sc2skill(type) != 0)
- {// When there isn't a duration specified, try to get it from the skill_db
- tick = skill_get_time(status_sc2skill(type), val1);
- }
- if(potion_flag == 1 && potion_target) { //skill.c set the flags before running the script, this is a potion-pitched effect.
- bl = map_id2bl(potion_target);
- tick /= 2;// Thrown potions only last half.
- val4 = 1;// Mark that this was a thrown sc_effect
- }
- if(!bl)
- return 0;
- switch(start_type) {
- case 1:
- status_change_start(bl, bl, type, rate, val1, 0, 0, val4, tick, flag);
- break;
- case 2:
- val2 = script_getnum(st,5);
- status_change_start(bl, bl, type, rate, val1, val2, 0, val4, tick, flag);
- break;
- case 4:
- val2 = script_getnum(st,5);
- val3 = script_getnum(st,6);
- val4 = script_getnum(st,7);
- status_change_start(bl, bl, type, rate, val1, val2, val3, val4, tick, flag);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Ends one or all status effects on the target unit or on the attached player.
- ///
- /// sc_end <effect_id>{,<unit_id>};
- BUILDIN_FUNC(sc_end)
- {
- struct block_list* bl;
- int type;
- type = script_getnum(st, 2);
- if (script_hasdata(st, 3))
- bl = map_id2bl(script_getnum(st, 3));
- else
- bl = map_id2bl(st->rid);
- if (potion_flag == 1 && potion_target) //##TODO how does this work [FlavioJS]
- bl = map_id2bl(potion_target);
- if (!bl)
- return 0;
- if (type >= 0 && type < SC_MAX)
- {
- struct status_change *sc = status_get_sc(bl);
- struct status_change_entry *sce = sc ? sc->data[type] : NULL;
- if (!sce)
- return 0;
- switch (type)
- {
- case SC_WEIGHT50:
- case SC_WEIGHT90:
- case SC_NOCHAT:
- case SC_PUSH_CART:
- return 0;
- default:
- break;
- }
- //This should help status_change_end force disabling the SC in case it has no limit.
- sce->val1 = sce->val2 = sce->val3 = sce->val4 = 0;
- status_change_end(bl, (sc_type)type, INVALID_TIMER);
- }
- else
- status_change_clear(bl, 3); // remove all effects
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * @FIXME atm will return reduced tick, 0 immune, 1 no tick
- *------------------------------------------*/
- BUILDIN_FUNC(getscrate)
- {
- struct block_list *bl;
- int type,rate;
- type=script_getnum(st,2);
- rate=script_getnum(st,3);
- if( script_hasdata(st,4) ) //get for the bl assigned
- bl = map_id2bl(script_getnum(st,4));
- else
- bl = map_id2bl(st->rid);
- if (bl)
- rate = status_get_sc_def(NULL,bl, (sc_type)type, 10000, 10000, 0);
- script_pushint(st,rate);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * getstatus <type>{, <info>};
- *------------------------------------------*/
- BUILDIN_FUNC(getstatus)
- {
- int id, type;
- struct map_session_data* sd = script_rid2sd(st);
- if( sd == NULL )
- {// no player attached
- return 0;
- }
- id = script_getnum(st, 2);
- type = script_hasdata(st, 3) ? script_getnum(st, 3) : 0;
- if( id <= SC_NONE || id >= SC_MAX )
- {// invalid status type given
- ShowWarning("script.c:getstatus: Invalid status type given (%d).\n", id);
- return 0;
- }
- if( sd->sc.count == 0 || !sd->sc.data[id] )
- {// no status is active
- script_pushint(st, 0);
- return 0;
- }
- switch( type )
- {
- case 1: script_pushint(st, sd->sc.data[id]->val1); break;
- case 2: script_pushint(st, sd->sc.data[id]->val2); break;
- case 3: script_pushint(st, sd->sc.data[id]->val3); break;
- case 4: script_pushint(st, sd->sc.data[id]->val4); break;
- case 5:
- {
- struct TimerData* timer = (struct TimerData*)get_timer(sd->sc.data[id]->timer);
- if( timer )
- {// return the amount of time remaining
- script_pushint(st, timer->tick - gettick());
- }
- }
- break;
- default: script_pushint(st, 1); break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(debugmes)
- {
- const char *str;
- str=script_getstr(st,2);
- ShowDebug("script debug : %d %d : %s\n",st->rid,st->oid,str);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *------------------------------------------*/
- BUILDIN_FUNC(catchpet)
- {
- int pet_id;
- TBL_PC *sd;
- pet_id= script_getnum(st,2);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pet_catch_process1(sd,pet_id);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * [orn]
- *------------------------------------------*/
- BUILDIN_FUNC(homunculus_evolution)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if(merc_is_hom_active(sd->hd))
- {
- if (sd->hd->homunculus.intimacy > 91000)
- merc_hom_evolution(sd->hd);
- else
- clif_emotion(&sd->hd->bl, E_SWT);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Checks for vaporized morph state
- * and deletes ITEMID_STRANGE_EMBRYO.
- *------------------------------------------*/
- BUILDIN_FUNC(homunculus_mutate)
- {
- int homun_id, m_class, m_id, i;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL || sd->hd == NULL )
- return 0;
- if(script_hasdata(st,2))
- homun_id = script_getnum(st,2);
- else
- homun_id = 6048 + (rnd() % 4);
- if( sd->hd->homunculus.vaporize == HOM_ST_MORPH ) {
- m_class = hom_class2mapid(sd->hd->homunculus.class_);
- m_id = hom_class2mapid(homun_id);
- i = pc_search_inventory(sd, ITEMID_STRANGE_EMBRYO);
- if ( m_class != -1 && m_id != -1 && m_class&HOM_EVO && m_id&HOM_S && sd->hd->homunculus.level >= 99 && i >= 0 ) {
- sd->hd->homunculus.vaporize = HOM_ST_REST; // Remove morph state.
- merc_call_homunculus(sd); // Respawn homunculus.
- hom_mutate(sd->hd, homun_id);
- pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_SCRIPT);
- script_pushint(st, 1);
- return 0;
- } else
- clif_emotion(&sd->bl, E_SWT);
- } else
- clif_emotion(&sd->bl, E_SWT);
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Puts homunculus into morph state
- * and gives ITEMID_STRANGE_EMBRYO.
- *------------------------------------------*/
- BUILDIN_FUNC(morphembryo)
- {
- struct item item_tmp;
- int m_class, i=0;
- TBL_PC *sd;
- sd = script_rid2sd(st);
- if( sd == NULL || sd->hd == NULL )
- return 0;
- if( merc_is_hom_active(sd->hd) ) {
- m_class = hom_class2mapid(sd->hd->homunculus.class_);
- if ( m_class != -1 && m_class&HOM_EVO && sd->hd->homunculus.level >= 99 ) {
- memset(&item_tmp, 0, sizeof(item_tmp));
- item_tmp.nameid = ITEMID_STRANGE_EMBRYO;
- item_tmp.identify = 1;
- if( item_tmp.nameid == 0 || (i = pc_additem(sd, &item_tmp, 1, LOG_TYPE_SCRIPT)) ) {
- clif_additem(sd, 0, 0, i);
- clif_emotion(&sd->bl, E_SWT); // Fail to avoid item drop exploit.
- } else {
- merc_hom_vaporize(sd, HOM_ST_MORPH);
- script_pushint(st, 1);
- return 0;
- }
- } else
- clif_emotion(&sd->hd->bl, E_SWT);
- } else
- clif_emotion(&sd->bl, E_SWT);
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- // [Zephyrus]
- BUILDIN_FUNC(homunculus_shuffle)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if(merc_is_hom_active(sd->hd))
- merc_hom_shuffle(sd->hd);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Check for homunculus state.
- * Return: -1 = No homunculus
- * 0 = Homunculus is active
- * 1 = Homunculus is vaporized (rest)
- * 2 = Homunculus is in morph state
- *------------------------------------------*/
- BUILDIN_FUNC(checkhomcall)
- {
- TBL_PC *sd = script_rid2sd(st);
- TBL_HOM *hd;
- if( sd == NULL )
- return 0;
- hd = sd->hd;
- if( !hd )
- script_pushint(st, -1);
- else
- script_pushint(st, hd->homunculus.vaporize);
- return SCRIPT_CMD_SUCCESS;
- }
- //These two functions bring the eA MAPID_* class functionality to scripts.
- BUILDIN_FUNC(eaclass)
- {
- int class_;
- if( script_hasdata(st,2) )
- class_ = script_getnum(st,2);
- else {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if (!sd) {
- script_pushint(st,-1);
- return 0;
- }
- class_ = sd->status.class_;
- }
- script_pushint(st,pc_jobid2mapid(class_));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(roclass)
- {
- int class_ =script_getnum(st,2);
- int sex;
- if( script_hasdata(st,3) )
- sex = script_getnum(st,3);
- else {
- TBL_PC *sd;
- if (st->rid && (sd=script_rid2sd(st)))
- sex = sd->status.sex;
- else
- sex = 1; //Just use male when not found.
- }
- script_pushint(st,pc_mapid2jobid(class_, sex));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Tells client to open a hatching window, used for pet incubator
- *------------------------------------------*/
- BUILDIN_FUNC(birthpet)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- if( sd->status.pet_id )
- {// do not send egg list, when you already have a pet
- return 0;
- }
- clif_sendegg(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Added - AppleGirl For Advanced Classes, (Updated for Cleaner Script Purposes)
- * @type
- * 1 : make like after rebirth
- * 2 : blvl,jlvl=1, skillpoint=0
- * 3 : don't reset skill, blvl=1
- * 4 : jlvl=0
- *------------------------------------------*/
- BUILDIN_FUNC(resetlvl)
- {
- TBL_PC *sd;
- int type=script_getnum(st,2);
- sd=script_rid2sd(st);
- if( sd == NULL )
- return 0;
- pc_resetlvl(sd,type);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Reset a player status point
- *------------------------------------------*/
- BUILDIN_FUNC(resetstatus)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- pc_resetstate(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * script command resetskill
- *------------------------------------------*/
- BUILDIN_FUNC(resetskill)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- pc_resetskill(sd,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Counts total amount of skill points.
- *------------------------------------------*/
- BUILDIN_FUNC(skillpointcount)
- {
- TBL_PC *sd;
- sd=script_rid2sd(st);
- script_pushint(st,sd->status.skill_point + pc_resetskill(sd,2));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(changebase)
- {
- TBL_PC *sd=NULL;
- int vclass;
- if( script_hasdata(st,3) )
- sd=map_id2sd(script_getnum(st,3));
- else
- sd=script_rid2sd(st);
- if(sd == NULL)
- return 0;
- vclass = script_getnum(st,2);
- if(vclass == JOB_WEDDING)
- {
- if (!battle_config.wedding_modifydisplay || //Do not show the wedding sprites
- sd->class_&JOBL_BABY //Baby classes screw up when showing wedding sprites. [Skotlex] They don't seem to anymore.
- )
- return 0;
- }
- if(!sd->disguise && vclass != sd->vd.class_) {
- status_set_viewdata(&sd->bl, vclass);
- //Updated client view. Base, Weapon and Cloth Colors.
- clif_changelook(&sd->bl,LOOK_BASE,sd->vd.class_);
- clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
- if (sd->vd.cloth_color)
- clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color);
- clif_skillinfoblock(sd);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Unequip all item and request for a changesex to char-serv
- *------------------------------------------*/
- BUILDIN_FUNC(changesex)
- {
- int i;
- TBL_PC *sd = NULL;
- sd = script_rid2sd(st);
- pc_resetskill(sd,4);
- // to avoid any problem with equipment and invalid sex, equipment is unequiped.
- for( i=0; i<EQI_MAX; i++ )
- if( sd->equip_index[i] >= 0 ) pc_unequipitem(sd, sd->equip_index[i], 3);
- chrif_changesex(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Works like 'announce' but outputs in the common chat window
- *------------------------------------------*/
- BUILDIN_FUNC(globalmes)
- {
- struct block_list *bl = map_id2bl(st->oid);
- struct npc_data *nd = (struct npc_data *)bl;
- const char *name=NULL,*mes;
- mes=script_getstr(st,2);
- if(mes==NULL) return 0;
- if(script_hasdata(st,3)){ // npc name to display
- name=script_getstr(st,3);
- } else {
- name=nd->name; //use current npc name
- }
- npc_globalmessage(name,mes); // broadcast to all players connected
- return SCRIPT_CMD_SUCCESS;
- }
- /////////////////////////////////////////////////////////////////////
- // NPC waiting room (chat room)
- //
- /// Creates a waiting room (chat room) for this npc.
- ///
- /// waitingroom "<title>",<limit>{,"<event>"{,<trigger>{,<zeny>{,<minlvl>{,<maxlvl>}}}}};
- BUILDIN_FUNC(waitingroom)
- {
- struct npc_data* nd;
- int pub = 1;
- const char* title = script_getstr(st, 2);
- int limit = script_getnum(st, 3);
- const char* ev = script_hasdata(st,4) ? script_getstr(st,4) : "";
- int trigger = script_hasdata(st,5) ? script_getnum(st,5) : limit;
- int zeny = script_hasdata(st,6) ? script_getnum(st,6) : 0;
- int minLvl = script_hasdata(st,7) ? script_getnum(st,7) : 1;
- int maxLvl = script_hasdata(st,8) ? script_getnum(st,8) : MAX_LEVEL;
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL )
- chat_createnpcchat(nd, title, limit, pub, trigger, ev, zeny, minLvl, maxLvl);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Removes the waiting room of the current or target npc.
- ///
- /// delwaitingroom "<npc_name>";
- /// delwaitingroom;
- BUILDIN_FUNC(delwaitingroom)
- {
- struct npc_data* nd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL )
- chat_deletenpcchat(nd);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Kicks all the players from the waiting room of the current or target npc.
- ///
- /// kickwaitingroomall "<npc_name>";
- /// kickwaitingroomall;
- BUILDIN_FUNC(waitingroomkickall)
- {
- struct npc_data* nd;
- struct chat_data* cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_npckickall(cd);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Enables the waiting room event of the current or target npc.
- ///
- /// enablewaitingroomevent "<npc_name>";
- /// enablewaitingroomevent;
- BUILDIN_FUNC(enablewaitingroomevent)
- {
- struct npc_data* nd;
- struct chat_data* cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_enableevent(cd);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Disables the waiting room event of the current or target npc.
- ///
- /// disablewaitingroomevent "<npc_name>";
- /// disablewaitingroomevent;
- BUILDIN_FUNC(disablewaitingroomevent)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL )
- chat_disableevent(cd);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns info on the waiting room of the current or target npc.
- /// Returns -1 if the type unknown
- /// <type>=0 : current number of users
- /// <type>=1 : maximum number of users allowed
- /// <type>=2 : the number of users that trigger the event
- /// <type>=3 : if the trigger is disabled
- /// <type>=4 : the title of the waiting room
- /// <type>=5 : the password of the waiting room
- /// <type>=16 : the name of the waiting room event
- /// <type>=32 : if the waiting room is full
- /// <type>=33 : if there are enough users to trigger the event
- ///
- /// getwaitingroomstate(<type>,"<npc_name>") -> <info>
- /// getwaitingroomstate(<type>) -> <info>
- BUILDIN_FUNC(getwaitingroomstate)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- int type;
- type = script_getnum(st,2);
- if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st, 3));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- {
- script_pushint(st, -1);
- return 0;
- }
- switch(type)
- {
- case 0: script_pushint(st, cd->users); break;
- case 1: script_pushint(st, cd->limit); break;
- case 2: script_pushint(st, cd->trigger&0x7f); break;
- case 3: script_pushint(st, ((cd->trigger&0x80)!=0)); break;
- case 4: script_pushstrcopy(st, cd->title); break;
- case 5: script_pushstrcopy(st, cd->pass); break;
- case 16: script_pushstrcopy(st, cd->npc_event);break;
- case 32: script_pushint(st, (cd->users >= cd->limit)); break;
- case 33: script_pushint(st, (cd->users >= cd->trigger)); break;
- default: script_pushint(st, -1); break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Warps the trigger or target amount of players to the target map and position.
- /// Players are automatically removed from the waiting room.
- /// Those waiting the longest will get warped first.
- /// The target map can be "Random" for a random position in the current map,
- /// and "SavePoint" for the savepoint map+position.
- /// The map flag noteleport of the current map is only considered when teleporting to the savepoint.
- ///
- /// The id's of the teleported players are put into the array $@warpwaitingpc[]
- /// The total number of teleported players is put into $@warpwaitingpcnum
- ///
- /// warpwaitingpc "<map name>",<x>,<y>,<number of players>;
- /// warpwaitingpc "<map name>",<x>,<y>;
- BUILDIN_FUNC(warpwaitingpc)
- {
- int x;
- int y;
- int i;
- int n;
- const char* map_name;
- struct npc_data* nd;
- struct chat_data* cd;
- TBL_PC* sd;
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd=(struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- return 0;
- map_name = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- n = cd->trigger&0x7f;
- if( script_hasdata(st,5) )
- n = script_getnum(st,5);
- for( i = 0; i < n && cd->users > 0; i++ )
- {
- sd = cd->usersd[0];
- if( strcmp(map_name,"SavePoint") == 0 && map[sd->bl.m].flag.noteleport )
- {// can't teleport on this map
- break;
- }
- if( cd->zeny )
- {// fee set
- if( (uint32)sd->status.zeny < cd->zeny )
- {// no zeny to cover set fee
- break;
- }
- pc_payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL);
- }
- mapreg_setreg(reference_uid(add_str("$@warpwaitingpc"), i), sd->bl.id);
- if( strcmp(map_name,"Random") == 0 )
- pc_randomwarp(sd,CLR_TELEPORT);
- else if( strcmp(map_name,"SavePoint") == 0 )
- pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, CLR_TELEPORT);
- else
- pc_setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT);
- }
- mapreg_setreg(add_str("$@warpwaitingpcnum"), i);
- return SCRIPT_CMD_SUCCESS;
- }
- /////////////////////////////////////////////////////////////////////
- // ...
- //
- /// Detaches a character from a script.
- ///
- /// @param st Script state to detach the character from.
- static void script_detach_rid(struct script_state* st)
- {
- if(st->rid)
- {
- script_detach_state(st, false);
- st->rid = 0;
- }
- }
- /*=========================================================================
- * Attaches a set of RIDs to the current script. [digitalhamster]
- * addrid(<type>{,<flag>{,<parameters>}});
- * <type>:
- * 0 : All players in the server.
- * 1 : All players in the map of the invoking player, or the invoking NPC if no player is attached.
- * 2 : Party members of a specified party ID.
- * [ Parameters: <party id> ]
- * 3 : Guild members of a specified guild ID.
- * [ Parameters: <guild id> ]
- * 4 : All players in a specified area of the map of the invoking player (or NPC).
- * [ Parameters: <x0>,<y0>,<x1>,<y1> ]
- * Account ID: The specified account ID.
- * <flag>:
- * 0 : Players are always attached. (default)
- * 1 : Players currently running another script will not be attached.
- *-------------------------------------------------------------------------*/
- static int buildin_addrid_sub(struct block_list *bl,va_list ap)
- {
- int forceflag;
- struct map_session_data *sd = (TBL_PC *)bl;
- struct script_state* st;
- st=va_arg(ap,struct script_state*);
- forceflag=va_arg(ap,int);
- if(!forceflag||!sd->st)
- if(sd->status.account_id!=st->rid)
- run_script(st->script,st->pos,sd->status.account_id,st->oid);
- return 0;
- }
- BUILDIN_FUNC(addrid)
- {
- struct s_mapiterator* iter;
- struct block_list *bl;
- TBL_PC *sd;
- if(st->rid<1){
- st->state = END;
- bl=map_id2bl(st->oid);
- } else
- bl=map_id2bl(st->rid); //if run without rid it'd error,also oid if npc, else rid for map
- iter = mapit_getallusers();
- switch(script_getnum(st,2)){
- case 0:
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)){
- if(!script_getnum(st,3)||!sd->st)
- if(sd->status.account_id!=st->rid) //attached player already runs.
- run_script(st->script,st->pos,sd->status.account_id,st->oid);
- }
- break;
- case 1:
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)){
- if(!script_getnum(st,3)||!sd->st)
- if((sd->bl.m == bl->m)&&(sd->status.account_id!=st->rid))
- run_script(st->script,st->pos,sd->status.account_id,st->oid);
- }
- break;
- case 2:
- if(script_getnum(st,4)==0){
- script_pushint(st,0);
- return 0;
- }
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)){
- if(!script_getnum(st,3)||!sd->st)
- if((sd->status.account_id!=st->rid)&&(sd->status.party_id==script_getnum(st,4))) //attached player already runs.
- run_script(st->script,st->pos,sd->status.account_id,st->oid);
- }
- break;
- case 3:
- if(script_getnum(st,4)==0){
- script_pushint(st,0);
- return 0;
- }
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)){
- if(!script_getnum(st,3)||!sd->st)
- if((sd->status.account_id!=st->rid)&&(sd->status.guild_id==script_getnum(st,4))) //attached player already runs.
- run_script(st->script,st->pos,sd->status.account_id,st->oid);
- }
- break;
- case 4:
- map_foreachinarea(buildin_addrid_sub,
- bl->m,script_getnum(st,4),script_getnum(st,5),script_getnum(st,6),script_getnum(st,7),BL_PC,
- st,script_getnum(st,3));//4-x0 , 5-y0 , 6-x1, 7-y1
- break;
- default:
- if((map_id2sd(script_getnum(st,2)))==NULL){ // Player not found.
- script_pushint(st,0);
- return 0;
- }
- if(!script_getnum(st,3)||!map_id2sd(script_getnum(st,2))->st) {
- run_script(st->script,st->pos,script_getnum(st,2),st->oid);
- script_pushint(st,1);
- }
- return 0;
- }
- mapit_free(iter);
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Attach sd char id to script and detach current one if any
- *------------------------------------------*/
- BUILDIN_FUNC(attachrid)
- {
- int rid = script_getnum(st,2);
- if (map_id2sd(rid) != NULL) {
- script_detach_rid(st);
- st->rid = rid;
- script_attach_state(st);
- script_pushint(st,1);
- } else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Detach script to rid
- *------------------------------------------*/
- BUILDIN_FUNC(detachrid)
- {
- script_detach_rid(st);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Chk if account connected, (and charid from account if specified)
- *------------------------------------------*/
- BUILDIN_FUNC(isloggedin)
- {
- TBL_PC* sd = map_id2sd(script_getnum(st,2));
- if (script_hasdata(st,3) && sd &&
- sd->status.char_id != script_getnum(st,3))
- sd = NULL;
- push_val(st->stack,C_INT,sd!=NULL);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- *
- *------------------------------------------*/
- BUILDIN_FUNC(setmapflagnosave)
- {
- int16 m,x,y;
- unsigned short mapindex;
- const char *str,*str2;
- str=script_getstr(st,2);
- str2=script_getstr(st,3);
- x=script_getnum(st,4);
- y=script_getnum(st,5);
- m = map_mapname2mapid(str);
- mapindex = mapindex_name2id(str2);
- if(m >= 0 && mapindex) {
- map[m].flag.nosave=1;
- map[m].save.map=mapindex;
- map[m].save.x=x;
- map[m].save.y=y;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getmapflag)
- {
- int16 m,i;
- const char *str;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: script_pushint(st,map[m].flag.nomemo); break;
- case MF_NOTELEPORT: script_pushint(st,map[m].flag.noteleport); break;
- case MF_NOSAVE: script_pushint(st,map[m].flag.nosave); break;
- case MF_NOBRANCH: script_pushint(st,map[m].flag.nobranch); break;
- case MF_NOPENALTY: script_pushint(st,map[m].flag.noexppenalty); break;
- case MF_NOZENYPENALTY: script_pushint(st,map[m].flag.nozenypenalty); break;
- case MF_PVP: script_pushint(st,map[m].flag.pvp); break;
- case MF_PVP_NOPARTY: script_pushint(st,map[m].flag.pvp_noparty); break;
- case MF_PVP_NOGUILD: script_pushint(st,map[m].flag.pvp_noguild); break;
- case MF_GVG: script_pushint(st,map[m].flag.gvg); break;
- case MF_GVG_NOPARTY: script_pushint(st,map[m].flag.gvg_noparty); break;
- case MF_NOTRADE: script_pushint(st,map[m].flag.notrade); break;
- case MF_NOSKILL: script_pushint(st,map[m].flag.noskill); break;
- case MF_NOWARP: script_pushint(st,map[m].flag.nowarp); break;
- case MF_PARTYLOCK: script_pushint(st,map[m].flag.partylock); break;
- case MF_NOICEWALL: script_pushint(st,map[m].flag.noicewall); break;
- case MF_SNOW: script_pushint(st,map[m].flag.snow); break;
- case MF_FOG: script_pushint(st,map[m].flag.fog); break;
- case MF_SAKURA: script_pushint(st,map[m].flag.sakura); break;
- case MF_LEAVES: script_pushint(st,map[m].flag.leaves); break;
- case MF_NOGO: script_pushint(st,map[m].flag.nogo); break;
- case MF_CLOUDS: script_pushint(st,map[m].flag.clouds); break;
- case MF_CLOUDS2: script_pushint(st,map[m].flag.clouds2); break;
- case MF_FIREWORKS: script_pushint(st,map[m].flag.fireworks); break;
- case MF_GVG_CASTLE: script_pushint(st,map[m].flag.gvg_castle); break;
- case MF_GVG_DUNGEON: script_pushint(st,map[m].flag.gvg_dungeon); break;
- case MF_NIGHTENABLED: script_pushint(st,map[m].flag.nightenabled); break;
- case MF_NOBASEEXP: script_pushint(st,map[m].flag.nobaseexp); break;
- case MF_NOJOBEXP: script_pushint(st,map[m].flag.nojobexp); break;
- case MF_NOMOBLOOT: script_pushint(st,map[m].flag.nomobloot); break;
- case MF_NOMVPLOOT: script_pushint(st,map[m].flag.nomvploot); break;
- case MF_NORETURN: script_pushint(st,map[m].flag.noreturn); break;
- case MF_NOWARPTO: script_pushint(st,map[m].flag.nowarpto); break;
- case MF_NIGHTMAREDROP: script_pushint(st,map[m].flag.pvp_nightmaredrop); break;
- case MF_RESTRICTED: script_pushint(st,map[m].flag.restricted); break;
- case MF_NOCOMMAND: script_pushint(st,map[m].nocommand); break;
- case MF_NODROP: script_pushint(st,map[m].flag.nodrop); break;
- case MF_JEXP: script_pushint(st,map[m].adjust.jexp); break;
- case MF_BEXP: script_pushint(st,map[m].adjust.bexp); break;
- case MF_NOVENDING: script_pushint(st,map[m].flag.novending); break;
- case MF_LOADEVENT: script_pushint(st,map[m].flag.loadevent); break;
- case MF_NOCHAT: script_pushint(st,map[m].flag.nochat); break;
- case MF_NOEXPPENALTY: script_pushint(st,map[m].flag.noexppenalty ); break;
- case MF_GUILDLOCK: script_pushint(st,map[m].flag.guildlock); break;
- case MF_TOWN: script_pushint(st,map[m].flag.town); break;
- case MF_AUTOTRADE: script_pushint(st,map[m].flag.autotrade); break;
- case MF_ALLOWKS: script_pushint(st,map[m].flag.allowks); break;
- case MF_MONSTER_NOTELEPORT: script_pushint(st,map[m].flag.monster_noteleport); break;
- case MF_PVP_NOCALCRANK: script_pushint(st,map[m].flag.pvp_nocalcrank); break;
- case MF_BATTLEGROUND: script_pushint(st,map[m].flag.battleground); break;
- case MF_RESET: script_pushint(st,map[m].flag.reset); break;
- case MF_CHANNELAUTOJOIN: script_pushint(st,map[m].flag.chmautojoin); break;
- case MF_NOUSECART: script_pushint(st,map[m].flag.nousecart); break;
- case MF_NOITEMCONSUMPTION: script_pushint(st,map[m].flag.noitemconsumption); break;
- case MF_SUMSTARTMIRACLE: script_pushint(st,map[m].flag.nosumstarmiracle); break;
- case MF_NOMINEEFFECT: script_pushint(st,map[m].flag.nomineeffect); break;
- case MF_NOLOCKON: script_pushint(st,map[m].flag.nolockon); break;
- case MF_NOTOMB: script_pushint(st,map[m].flag.notomb); break;
- #ifdef ADJUST_SKILL_DAMAGE
- case MF_SKILL_DAMAGE:
- {
- int ret_val=0, type=0;
- FETCH(4,type);
- switch (type) {
- case 1: ret_val = map[m].adjust.damage.pc; break;
- case 2: ret_val = map[m].adjust.damage.mob; break;
- case 3: ret_val = map[m].adjust.damage.boss; break;
- case 4: ret_val = map[m].adjust.damage.other; break;
- case 5: ret_val = map[m].adjust.damage.caster; break;
- default: ret_val = map[m].flag.skill_damage; break;
- }
- script_pushint(st,ret_val); break;
- } break;
- #endif
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* pvp timer handling */
- static int script_mapflag_pvp_sub(struct block_list *bl,va_list ap) {
- TBL_PC* sd = (TBL_PC*)bl;
- if (sd->pvp_timer == INVALID_TIMER) {
- sd->pvp_timer = add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id, 0);
- sd->pvp_rank = 0;
- sd->pvp_lastusers = 0;
- sd->pvp_point = 5;
- sd->pvp_won = 0;
- sd->pvp_lost = 0;
- }
- clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
- clif_maptypeproperty2(&sd->bl,SELF);
- return 0;
- }
- BUILDIN_FUNC(setmapflag)
- {
- int16 m,i;
- const char *str;
- int val=0;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- FETCH(4,val);
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: map[m].flag.nomemo = 1; break;
- case MF_NOTELEPORT: map[m].flag.noteleport = 1; break;
- case MF_NOSAVE: map[m].flag.nosave = 1; break;
- case MF_NOBRANCH: map[m].flag.nobranch = 1; break;
- case MF_NOPENALTY: map[m].flag.noexppenalty = 1; map[m].flag.nozenypenalty = 1; break;
- case MF_NOZENYPENALTY: map[m].flag.nozenypenalty = 1; break;
- case MF_PVP:
- map[m].flag.pvp = 1;
- if( !battle_config.pk_mode ) {
- map_foreachinmap(script_mapflag_pvp_sub,m,BL_PC);
- }
- break;
- case MF_PVP_NOPARTY: map[m].flag.pvp_noparty = 1; break;
- case MF_PVP_NOGUILD: map[m].flag.pvp_noguild = 1; break;
- case MF_GVG: {
- struct block_list bl;
- map[m].flag.gvg = 1;
- clif_map_property_mapall(m, MAPPROPERTY_AGITZONE);
- bl.type = BL_NUL;
- bl.m = m;
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- }
- break;
- case MF_GVG_NOPARTY: map[m].flag.gvg_noparty = 1; break;
- case MF_NOTRADE: map[m].flag.notrade = 1; break;
- case MF_NOSKILL: map[m].flag.noskill = 1; break;
- case MF_NOWARP: map[m].flag.nowarp = 1; break;
- case MF_PARTYLOCK: map[m].flag.partylock = 1; break;
- case MF_NOICEWALL: map[m].flag.noicewall = 1; break;
- case MF_SNOW: map[m].flag.snow = 1; break;
- case MF_FOG: map[m].flag.fog = 1; break;
- case MF_SAKURA: map[m].flag.sakura = 1; break;
- case MF_LEAVES: map[m].flag.leaves = 1; break;
- case MF_NOGO: map[m].flag.nogo = 1; break;
- case MF_CLOUDS: map[m].flag.clouds = 1; break;
- case MF_CLOUDS2: map[m].flag.clouds2 = 1; break;
- case MF_FIREWORKS: map[m].flag.fireworks = 1; break;
- case MF_GVG_CASTLE: map[m].flag.gvg_castle = 1; break;
- case MF_GVG_DUNGEON: map[m].flag.gvg_dungeon = 1; break;
- case MF_NIGHTENABLED: map[m].flag.nightenabled = 1; break;
- case MF_NOBASEEXP: map[m].flag.nobaseexp = 1; break;
- case MF_NOJOBEXP: map[m].flag.nojobexp = 1; break;
- case MF_NOMOBLOOT: map[m].flag.nomobloot = 1; break;
- case MF_NOMVPLOOT: map[m].flag.nomvploot = 1; break;
- case MF_NORETURN: map[m].flag.noreturn = 1; break;
- case MF_NOWARPTO: map[m].flag.nowarpto = 1; break;
- case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop = 1; break;
- case MF_RESTRICTED:
- map[m].zone |= 1<<(val+1);
- map[m].flag.restricted=1;
- break;
- case MF_NOCOMMAND: map[m].nocommand = (val <= 0) ? 100 : val; break;
- case MF_NODROP: map[m].flag.nodrop = 1; break;
- case MF_JEXP: map[m].adjust.jexp = (val <= 0) ? 100 : val; break;
- case MF_BEXP: map[m].adjust.bexp = (val <= 0) ? 100 : val; break;
- case MF_NOVENDING: map[m].flag.novending = 1; break;
- case MF_LOADEVENT: map[m].flag.loadevent = 1; break;
- case MF_NOCHAT: map[m].flag.nochat = 1; break;
- case MF_NOEXPPENALTY: map[m].flag.noexppenalty = 1; break;
- case MF_GUILDLOCK: map[m].flag.guildlock = 1; break;
- case MF_TOWN: map[m].flag.town = 1; break;
- case MF_AUTOTRADE: map[m].flag.autotrade = 1; break;
- case MF_ALLOWKS: map[m].flag.allowks = 1; break;
- case MF_MONSTER_NOTELEPORT: map[m].flag.monster_noteleport = 1; break;
- case MF_PVP_NOCALCRANK: map[m].flag.pvp_nocalcrank = 1; break;
- case MF_BATTLEGROUND: map[m].flag.battleground = (val <= 0 || val > 2) ? 1 : val; break;
- case MF_RESET: map[m].flag.reset = 1; break;
- case MF_CHANNELAUTOJOIN: map[m].flag.chmautojoin = 1 ; break;
- case MF_NOUSECART: map[m].flag.nousecart = 1 ; break;
- case MF_NOITEMCONSUMPTION: map[m].flag.noitemconsumption = 1 ; break;
- case MF_SUMSTARTMIRACLE: map[m].flag.nosumstarmiracle = 1 ; break;
- case MF_NOMINEEFFECT: map[m].flag.nomineeffect = 1 ; break;
- case MF_NOLOCKON: map[m].flag.nolockon = 1 ; break;
- case MF_NOTOMB: map[m].flag.notomb = 1; break;
- #ifdef ADJUST_SKILL_DAMAGE
- case MF_SKILL_DAMAGE:
- {
- int type=0;
- FETCH(5,type);
- switch (type) {
- case 1: map[m].adjust.damage.pc = val; break;
- case 2: map[m].adjust.damage.mob = val; break;
- case 3: map[m].adjust.damage.boss = val; break;
- case 4: map[m].adjust.damage.other = val; break;
- case 5: map[m].adjust.damage.caster = val; break;
- }
- map[m].flag.skill_damage = 1;
- } break;
- #endif
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(removemapflag)
- {
- int16 m,i;
- const char *str;
- int val=0;
- str=script_getstr(st,2);
- i=script_getnum(st,3);
- FETCH(4,val);
- m = map_mapname2mapid(str);
- if(m >= 0) {
- switch(i) {
- case MF_NOMEMO: map[m].flag.nomemo = 0; break;
- case MF_NOTELEPORT: map[m].flag.noteleport = 0; break;
- case MF_NOSAVE: map[m].flag.nosave = 0; break;
- case MF_NOBRANCH: map[m].flag.nobranch = 0; break;
- case MF_NOPENALTY: map[m].flag.noexppenalty = 0; map[m].flag.nozenypenalty = 0; break;
- case MF_NOZENYPENALTY: map[m].flag.nozenypenalty = 0; break;
- case MF_PVP: {
- struct block_list bl;
- bl.type = BL_NUL;
- bl.m = m;
- map[m].flag.pvp = 0;
- clif_map_property_mapall(m, MAPPROPERTY_NOTHING);
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- }
- break;
- case MF_PVP_NOPARTY: map[m].flag.pvp_noparty = 0; break;
- case MF_PVP_NOGUILD: map[m].flag.pvp_noguild = 0; break;
- case MF_GVG: {
- struct block_list bl;
- bl.type = BL_NUL;
- bl.m = m;
- map[m].flag.gvg = 0;
- clif_map_property_mapall(m, MAPPROPERTY_NOTHING);
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- }
- break;
- case MF_GVG_NOPARTY: map[m].flag.gvg_noparty = 0; break;
- case MF_NOTRADE: map[m].flag.notrade = 0; break;
- case MF_NOSKILL: map[m].flag.noskill = 0; break;
- case MF_NOWARP: map[m].flag.nowarp = 0; break;
- case MF_PARTYLOCK: map[m].flag.partylock = 0; break;
- case MF_NOICEWALL: map[m].flag.noicewall = 0; break;
- case MF_SNOW: map[m].flag.snow = 0; break;
- case MF_FOG: map[m].flag.fog = 0; break;
- case MF_SAKURA: map[m].flag.sakura = 0; break;
- case MF_LEAVES: map[m].flag.leaves = 0; break;
- case MF_NOGO: map[m].flag.nogo = 0; break;
- case MF_CLOUDS: map[m].flag.clouds = 0; break;
- case MF_CLOUDS2: map[m].flag.clouds2 = 0; break;
- case MF_FIREWORKS: map[m].flag.fireworks = 0; break;
- case MF_GVG_CASTLE: map[m].flag.gvg_castle = 0; break;
- case MF_GVG_DUNGEON: map[m].flag.gvg_dungeon = 0; break;
- case MF_NIGHTENABLED: map[m].flag.nightenabled = 0; break;
- case MF_NOBASEEXP: map[m].flag.nobaseexp = 0; break;
- case MF_NOJOBEXP: map[m].flag.nojobexp = 0; break;
- case MF_NOMOBLOOT: map[m].flag.nomobloot = 0; break;
- case MF_NOMVPLOOT: map[m].flag.nomvploot = 0; break;
- case MF_NORETURN: map[m].flag.noreturn = 0; break;
- case MF_NOWARPTO: map[m].flag.nowarpto = 0; break;
- case MF_NIGHTMAREDROP: map[m].flag.pvp_nightmaredrop = 0; break;
- case MF_RESTRICTED:
- map[m].zone ^= 1<<(val+1);
- if (map[m].zone == 0){
- map[m].flag.restricted=0;
- }
- break;
- case MF_NOCOMMAND: map[m].nocommand = 0; break;
- case MF_NODROP: map[m].flag.nodrop = 0; break;
- case MF_JEXP: map[m].adjust.jexp = 0; break;
- case MF_BEXP: map[m].adjust.bexp = 0; break;
- case MF_NOVENDING: map[m].flag.novending = 0; break;
- case MF_LOADEVENT: map[m].flag.loadevent = 0; break;
- case MF_NOCHAT: map[m].flag.nochat = 0; break;
- case MF_NOEXPPENALTY: map[m].flag.noexppenalty = 0; break;
- case MF_GUILDLOCK: map[m].flag.guildlock = 0; break;
- case MF_TOWN: map[m].flag.town = 0; break;
- case MF_AUTOTRADE: map[m].flag.autotrade = 0; break;
- case MF_ALLOWKS: map[m].flag.allowks = 0; break;
- case MF_MONSTER_NOTELEPORT: map[m].flag.monster_noteleport = 0; break;
- case MF_PVP_NOCALCRANK: map[m].flag.pvp_nocalcrank = 0; break;
- case MF_BATTLEGROUND: map[m].flag.battleground = 0; break;
- case MF_RESET: map[m].flag.reset = 0; break;
- case MF_CHANNELAUTOJOIN: map[m].flag.chmautojoin = 0 ; break;
- case MF_NOUSECART: map[m].flag.nousecart = 0 ; break;
- case MF_NOITEMCONSUMPTION: map[m].flag.noitemconsumption = 0 ; break;
- case MF_SUMSTARTMIRACLE: map[m].flag.nosumstarmiracle = 0 ; break;
- case MF_NOMINEEFFECT: map[m].flag.nomineeffect = 0 ; break;
- case MF_NOLOCKON: map[m].flag.nolockon = 0 ; break;
- case MF_NOTOMB: map[m].flag.notomb = 0; break;
- #ifdef ADJUST_SKILL_DAMAGE
- case MF_SKILL_DAMAGE:
- {
- map[m].flag.skill_damage = 0;
- memset(&map[m].adjust.damage,0,sizeof(map[m].adjust.damage));
- } break;
- #endif
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pvpon)
- {
- int16 m;
- const char *str;
- TBL_PC* sd = NULL;
- struct s_mapiterator* iter;
- struct block_list bl;
- str = script_getstr(st,2);
- m = map_mapname2mapid(str);
- if( m < 0 || map[m].flag.pvp )
- return 0; // nothing to do
- map[m].flag.pvp = 1;
- clif_map_property_mapall(m, MAPPROPERTY_FREEPVPZONE);
- bl.type = BL_NUL;
- bl.m = m;
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
- return 0;
- iter = mapit_getallusers();
- for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
- {
- if( sd->bl.m != m || sd->pvp_timer != INVALID_TIMER )
- continue; // not applicable
- sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
- sd->pvp_rank = 0;
- sd->pvp_lastusers = 0;
- sd->pvp_point = 5;
- sd->pvp_won = 0;
- sd->pvp_lost = 0;
- }
- mapit_free(iter);
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_pvpoff_sub(struct block_list *bl,va_list ap)
- {
- TBL_PC* sd = (TBL_PC*)bl;
- clif_pvpset(sd, 0, 0, 2);
- if (sd->pvp_timer != INVALID_TIMER) {
- delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
- sd->pvp_timer = INVALID_TIMER;
- }
- return 0;
- }
- BUILDIN_FUNC(pvpoff)
- {
- int16 m;
- const char *str;
- struct block_list bl;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m < 0 || !map[m].flag.pvp)
- return 0; //fixed Lupus
- map[m].flag.pvp = 0;
- clif_map_property_mapall(m, MAPPROPERTY_NOTHING);
- bl.type = BL_NUL;
- bl.m = m;
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- if(battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris]
- return 0;
- map_foreachinmap(buildin_pvpoff_sub, m, BL_PC);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(gvgon)
- {
- int16 m;
- const char *str;
- struct block_list bl;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m >= 0 && !map[m].flag.gvg) {
- map[m].flag.gvg = 1;
- clif_map_property_mapall(m, MAPPROPERTY_AGITZONE);
- bl.type = BL_NUL;
- bl.m = m;
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(gvgoff)
- {
- int16 m;
- const char *str;
- str=script_getstr(st,2);
- m = map_mapname2mapid(str);
- if(m >= 0 && map[m].flag.gvg) {
- struct block_list bl;
- map[m].flag.gvg = 0;
- clif_map_property_mapall(m, MAPPROPERTY_NOTHING);
- bl.type = BL_NUL;
- bl.m = m;
- clif_maptypeproperty2(&bl,ALL_SAMEMAP);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Shows an emoticon on top of the player/npc
- * emotion emotion#, <target: 0 - NPC, 1 - PC>, <NPC/PC name>
- *------------------------------------------*/
- //Optional second parameter added by [Skotlex]
- BUILDIN_FUNC(emotion)
- {
- int type;
- int player=0;
- type=script_getnum(st,2);
- if(type < 0 || type > 100)
- return 0;
- if( script_hasdata(st,3) )
- player=script_getnum(st,3);
- if (player) {
- TBL_PC *sd = NULL;
- if( script_hasdata(st,4) )
- sd = map_nick2sd(script_getstr(st,4));
- else
- sd = script_rid2sd(st);
- if (sd)
- clif_emotion(&sd->bl,type);
- } else
- if( script_hasdata(st,4) )
- {
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
- if(nd)
- clif_emotion(&nd->bl,type);
- }
- else
- clif_emotion(map_id2bl(st->oid),type);
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
- {
- int16 m=va_arg(ap,int);
- int g_id=va_arg(ap,int);
- int flag=va_arg(ap,int);
- if(!sd || sd->bl.m != m)
- return 0;
- if(
- (sd->status.guild_id == g_id && flag&1) || //Warp out owners
- (sd->status.guild_id != g_id && flag&2) || //Warp out outsiders
- (sd->status.guild_id == 0 && flag&2) // Warp out players not in guild
- )
- pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,CLR_TELEPORT);
- return 1;
- }
- static int buildin_maprespawnguildid_sub_mob(struct block_list *bl,va_list ap)
- {
- struct mob_data *md=(struct mob_data *)bl;
- if(!md->guardian_data && md->class_ != MOBID_EMPERIUM)
- status_kill(bl);
- return 0;
- }
- /*
- * Function to kick guild members out of a map and to their save points.
- * m : mapid
- * g_id : owner guild id
- * flag & 1 : Warp out owners
- * flag & 2 : Warp out outsiders
- * flag & 4 : reserved for mobs
- * */
- BUILDIN_FUNC(maprespawnguildid)
- {
- const char *mapname=script_getstr(st,2);
- int g_id=script_getnum(st,3);
- int flag=script_getnum(st,4);
- int16 m=map_mapname2mapid(mapname);
- if(m == -1)
- return 0;
- //Catch ALL players (in case some are 'between maps' on execution time)
- map_foreachpc(buildin_maprespawnguildid_sub_pc,m,g_id,flag);
- if (flag&4) //Remove script mobs.
- map_foreachinmap(buildin_maprespawnguildid_sub_mob,m,BL_MOB);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(agitstart)
- {
- if(agit_flag==1) return SCRIPT_CMD_SUCCESS; // Agit already Start.
- agit_flag=1;
- guild_agit_start();
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(agitend)
- {
- if(agit_flag==0) return SCRIPT_CMD_SUCCESS; // Agit already End.
- agit_flag=0;
- guild_agit_end();
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(agitstart2)
- {
- if(agit2_flag==1) return SCRIPT_CMD_SUCCESS; // Agit2 already Start.
- agit2_flag=1;
- guild_agit2_start();
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(agitend2)
- {
- if(agit2_flag==0) return SCRIPT_CMD_SUCCESS; // Agit2 already End.
- agit2_flag=0;
- guild_agit2_end();
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns whether woe is on or off. // choice script
- *------------------------------------------*/
- BUILDIN_FUNC(agitcheck)
- {
- script_pushint(st,agit_flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns whether woese is on or off. // choice script
- *------------------------------------------*/
- BUILDIN_FUNC(agitcheck2)
- {
- script_pushint(st,agit2_flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Sets the guild_id of this npc.
- ///
- /// flagemblem <guild_id>;
- BUILDIN_FUNC(flagemblem)
- {
- TBL_NPC* nd;
- int g_id = script_getnum(st,2);
- if(g_id < 0) return 0;
- nd = (TBL_NPC*)map_id2nd(st->oid);
- if( nd == NULL ) {
- ShowError("script:flagemblem: npc %d not found\n", st->oid);
- } else if( nd->subtype != SCRIPT ) {
- ShowError("script:flagemblem: unexpected subtype %d for npc %d '%s'\n", nd->subtype, st->oid, nd->exname);
- } else {
- bool changed = ( nd->u.scr.guild_id != g_id )?true:false;
- nd->u.scr.guild_id = g_id;
- clif_guild_emblem_area(&nd->bl);
- /* guild flag caching */
- if( g_id ) /* adding a id */
- guild_flag_add(nd);
- else if( changed ) /* removing a flag */
- guild_flag_remove(nd);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getcastlename)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- const char* name = (gc) ? gc->castle_name : "";
- script_pushstrcopy(st,name);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getcastledata)
- {
- const char *mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int index = script_getnum(st,3);
- struct guild_castle *gc = guild_mapname2gc(mapname);
- if (gc == NULL) {
- script_pushint(st,0);
- ShowWarning("buildin_setcastledata: guild castle for map '%s' not found\n", mapname);
- return 1;
- }
- switch (index) {
- case 1:
- script_pushint(st,gc->guild_id); break;
- case 2:
- script_pushint(st,gc->economy); break;
- case 3:
- script_pushint(st,gc->defense); break;
- case 4:
- script_pushint(st,gc->triggerE); break;
- case 5:
- script_pushint(st,gc->triggerD); break;
- case 6:
- script_pushint(st,gc->nextTime); break;
- case 7:
- script_pushint(st,gc->payTime); break;
- case 8:
- script_pushint(st,gc->createTime); break;
- case 9:
- script_pushint(st,gc->visibleC); break;
- default:
- if (index > 9 && index <= 9+MAX_GUARDIANS) {
- script_pushint(st,gc->guardian[index-10].visible);
- break;
- }
- script_pushint(st,0);
- ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(setcastledata)
- {
- const char *mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int index = script_getnum(st,3);
- int value = script_getnum(st,4);
- struct guild_castle *gc = guild_mapname2gc(mapname);
- if (gc == NULL) {
- ShowWarning("buildin_setcastledata: guild castle for map '%s' not found\n", mapname);
- return 1;
- }
- if (index <= 0 || index > 9+MAX_GUARDIANS) {
- ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
- return 1;
- }
- guild_castledatasave(gc->castle_id, index, value);
- return SCRIPT_CMD_SUCCESS;
- }
- /* =====================================================================
- * ---------------------------------------------------------------------*/
- BUILDIN_FUNC(requestguildinfo)
- {
- int guild_id=script_getnum(st,2);
- const char *event=NULL;
- if( script_hasdata(st,3) ){
- event=script_getstr(st,3);
- check_event(st, event);
- }
- if(guild_id>0)
- guild_npc_request_info(guild_id,event);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns the number of cards that have been compounded onto the specified equipped item.
- /// getequipcardcnt(<equipment slot>);
- BUILDIN_FUNC(getequipcardcnt)
- {
- int i=-1,j,num;
- TBL_PC *sd;
- int count;
- num=script_getnum(st,2);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i]) {
- script_pushint(st,0);
- return 0;
- }
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- {
- script_pushint(st,0);
- return 0;
- }
- count = 0;
- for( j = 0; j < sd->inventory_data[i]->slot; j++ )
- if( sd->status.inventory[i].card[j] && itemdb_type(sd->status.inventory[i].card[j]) == IT_CARD )
- count++;
- script_pushint(st,count);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Removes all cards from the item found in the specified equipment slot of the invoking character,
- /// and give them to the character. If any cards were removed in this manner, it will also show a success effect.
- /// successremovecards <slot>;
- BUILDIN_FUNC(successremovecards) {
- int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
- int num = script_getnum(st,2);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i]) {
- return 0;
- }
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- return 0;
- for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c ) {
- if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD ) {// extract this card from the item
- int flag;
- struct item item_tmp;
- memset(&item_tmp,0,sizeof(item_tmp));
- cardflag = 1;
- item_tmp.nameid = sd->status.inventory[i].card[c];
- item_tmp.identify = 1;
- if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ // get back the cart in inventory
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- if(cardflag == 1) {//if card was remove remplace item with no card
- int flag;
- struct item item_tmp;
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid = sd->status.inventory[i].nameid;
- item_tmp.identify = 1;
- item_tmp.refine = sd->status.inventory[i].refine;
- item_tmp.attribute = sd->status.inventory[i].attribute;
- item_tmp.expire_time = sd->status.inventory[i].expire_time;
- item_tmp.bound = sd->status.inventory[i].bound;
- for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++)
- item_tmp.card[j]=sd->status.inventory[i].card[j];
- pc_delitem(sd,i,1,0,3,LOG_TYPE_SCRIPT);
- if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){ //chk if can be spawn in inventory otherwise put on floor
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- clif_misceffect(&sd->bl,3);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Removes all cards from the item found in the specified equipment slot of the invoking character.
- /// failedremovecards <slot>, <type>;
- /// <type>=0 : will destroy both the item and the cards.
- /// <type>=1 : will keep the item, but destroy the cards.
- /// <type>=2 : will keep the cards, but destroy the item.
- /// <type>=? : will just display the failure effect.
- BUILDIN_FUNC(failedremovecards) {
- int i=-1,j,c,cardflag=0;
- TBL_PC* sd = script_rid2sd(st);
- int num = script_getnum(st,2);
- int typefail = script_getnum(st,3);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if (i < 0 || !sd->inventory_data[i])
- return 0;
- if(itemdb_isspecial(sd->status.inventory[i].card[0]))
- return 0;
- for( c = sd->inventory_data[i]->slot - 1; c >= 0; --c ) {
- if( sd->status.inventory[i].card[c] && itemdb_type(sd->status.inventory[i].card[c]) == IT_CARD ) {
- cardflag = 1;
- if(typefail == 2) {// add cards to inventory, clear
- int flag;
- struct item item_tmp;
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid = sd->status.inventory[i].card[c];
- item_tmp.identify = 1;
- if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- }
- if(cardflag == 1) {
- if(typefail == 0 || typefail == 2){ // destroy the item
- pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT);
- }
- if(typefail == 1){ // destroy the card
- int flag;
- struct item item_tmp;
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid = sd->status.inventory[i].nameid;
- item_tmp.identify = 1;
- item_tmp.refine = sd->status.inventory[i].refine;
- item_tmp.attribute = sd->status.inventory[i].attribute;
- item_tmp.expire_time = sd->status.inventory[i].expire_time;
- item_tmp.bound = sd->status.inventory[i].bound;
- for (j = sd->inventory_data[i]->slot; j < MAX_SLOTS; j++)
- item_tmp.card[j]=sd->status.inventory[i].card[j];
- pc_delitem(sd,i,1,0,2,LOG_TYPE_SCRIPT);
- if((flag=pc_additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT))){
- clif_additem(sd,0,0,flag);
- map_addflooritem(&item_tmp,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- clif_misceffect(&sd->bl,2);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* ================================================================
- * mapwarp "<from map>","<to map>",<x>,<y>,<type>,<ID for Type>;
- * type: 0=everyone, 1=guild, 2=party; [Reddozen]
- * improved by [Lance]
- * ================================================================*/
- BUILDIN_FUNC(mapwarp) // Added by RoVeRT
- {
- int x,y,m,check_val=0,check_ID=0,i=0;
- struct guild *g = NULL;
- struct party_data *p = NULL;
- const char *str;
- const char *mapname;
- unsigned int index;
- mapname=script_getstr(st,2);
- str=script_getstr(st,3);
- x=script_getnum(st,4);
- y=script_getnum(st,5);
- if(script_hasdata(st,7)){
- check_val=script_getnum(st,6);
- check_ID=script_getnum(st,7);
- }
- if((m=map_mapname2mapid(mapname))< 0)
- return 0;
- if(!(index=mapindex_name2id(str)))
- return 0;
- switch(check_val){
- case 1:
- g = guild_search(check_ID);
- if (g){
- for( i=0; i < g->max_member; i++)
- {
- if(g->member[i].sd && g->member[i].sd->bl.m==m){
- pc_setpos(g->member[i].sd,index,x,y,CLR_TELEPORT);
- }
- }
- }
- break;
- case 2:
- p = party_search(check_ID);
- if(p){
- for(i=0;i<MAX_PARTY; i++){
- if(p->data[i].sd && p->data[i].sd->bl.m == m){
- pc_setpos(p->data[i].sd,index,x,y,CLR_TELEPORT);
- }
- }
- }
- break;
- default:
- map_foreachinmap(buildin_areawarp_sub,m,BL_PC,index,x,y,0,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_mobcount_sub(struct block_list *bl,va_list ap) // Added by RoVeRT
- {
- char *event=va_arg(ap,char *);
- struct mob_data *md = ((struct mob_data *)bl);
- if( md->status.hp > 0 && (!event || strcmp(event,md->npc_event) == 0) )
- return 1;
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mobcount) // Added by RoVeRT
- {
- const char *mapname,*event;
- int16 m;
- mapname=script_getstr(st,2);
- event=script_getstr(st,3);
- if( strcmp(event, "all") == 0 )
- event = NULL;
- else
- check_event(st, event);
- if( strcmp(mapname, "this") == 0 ) {
- struct map_session_data *sd = script_rid2sd(st);
- if( sd )
- m = sd->bl.m;
- else {
- script_pushint(st,-1);
- return 0;
- }
- }
- else if( (m = map_mapname2mapid(mapname)) < 0 ) {
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,map_foreachinmap(buildin_mobcount_sub, m, BL_MOB, event));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(marriage)
- {
- const char *partner=script_getstr(st,2);
- TBL_PC *sd=script_rid2sd(st);
- TBL_PC *p_sd=map_nick2sd(partner);
- if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(wedding_effect)
- {
- TBL_PC *sd=script_rid2sd(st);
- struct block_list *bl;
- if(sd==NULL) {
- bl=map_id2bl(st->oid);
- } else
- bl=&sd->bl;
- clif_wedding_effect(bl);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(divorce)
- {
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || pc_divorce(sd) < 0){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(ispartneron)
- {
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || !pc_ismarried(sd) ||
- map_charid2sd(sd->status.partner_id) == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getpartnerid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.partner_id);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getchildid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.child);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getmotherid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.mother);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getfatherid)
- {
- TBL_PC *sd=script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.father);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(warppartner)
- {
- int x,y;
- unsigned short mapindex;
- const char *str;
- TBL_PC *sd=script_rid2sd(st);
- TBL_PC *p_sd=NULL;
- if(sd==NULL || !pc_ismarried(sd) ||
- (p_sd=map_charid2sd(sd->status.partner_id)) == NULL) {
- script_pushint(st,0);
- return 0;
- }
- str=script_getstr(st,2);
- x=script_getnum(st,3);
- y=script_getnum(st,4);
- mapindex = mapindex_name2id(str);
- if (mapindex) {
- pc_setpos(p_sd,mapindex,x,y,CLR_OUTSIGHT);
- script_pushint(st,1);
- } else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*================================================
- * Script for Displaying MOB Information [Valaris]
- *------------------------------------------------*/
- BUILDIN_FUNC(strmobinfo)
- {
- int num=script_getnum(st,2);
- int class_=script_getnum(st,3);
- if(!mobdb_checkid(class_))
- {
- if (num < 3) //requested a string
- script_pushconststr(st,"");
- else
- script_pushint(st,0);
- return 0;
- }
- switch (num) {
- case 1: script_pushstrcopy(st,mob_db(class_)->name); break;
- case 2: script_pushstrcopy(st,mob_db(class_)->jname); break;
- case 3: script_pushint(st,mob_db(class_)->lv); break;
- case 4: script_pushint(st,mob_db(class_)->status.max_hp); break;
- case 5: script_pushint(st,mob_db(class_)->status.max_sp); break;
- case 6: script_pushint(st,mob_db(class_)->base_exp); break;
- case 7: script_pushint(st,mob_db(class_)->job_exp); break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Summon guardians [Valaris]
- * guardian("<map name>",<x>,<y>,"<name to show>",<mob id>{,"<event label>"}{,<guardian index>}) -> <id>
- *------------------------------------------*/
- BUILDIN_FUNC(guardian)
- {
- int class_=0,x=0,y=0,guardian=0;
- const char *str,*map,*evt="";
- struct script_data *data;
- bool has_index = false;
- map =script_getstr(st,2);
- x =script_getnum(st,3);
- y =script_getnum(st,4);
- str =script_getstr(st,5);
- class_=script_getnum(st,6);
- if( script_hasdata(st,8) )
- {// "<event label>",<guardian index>
- evt=script_getstr(st,7);
- guardian=script_getnum(st,8);
- has_index = true;
- } else if( script_hasdata(st,7) ){
- data=script_getdata(st,7);
- get_val(st,data);
- if( data_isstring(data) )
- {// "<event label>"
- evt=script_getstr(st,7);
- } else if( data_isint(data) )
- {// <guardian index>
- guardian=script_getnum(st,7);
- has_index = true;
- } else {
- ShowError("script:guardian: invalid data type for argument #6 (from 1)\n");
- script_reportdata(data);
- return 1;
- }
- }
- check_event(st, evt);
- script_pushint(st, mob_spawn_guardian(map,x,y,str,class_,evt,guardian,has_index));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Invisible Walls [Zephyrus]
- *------------------------------------------*/
- BUILDIN_FUNC(setwall)
- {
- const char *map, *name;
- int x, y, m, size, dir;
- bool shootable;
- map = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- size = script_getnum(st,5);
- dir = script_getnum(st,6);
- shootable = script_getnum(st,7);
- name = script_getstr(st,8);
- if( (m = map_mapname2mapid(map)) < 0 )
- return 0; // Invalid Map
- map_iwall_set(m, x, y, size, dir, shootable, name);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(delwall)
- {
- const char *name = script_getstr(st,2);
- map_iwall_remove(name);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Retrieves various information about the specified guardian.
- ///
- /// guardianinfo("<map_name>", <index>, <type>) -> <value>
- /// type: 0 - whether it is deployed or not
- /// 1 - maximum hp
- /// 2 - current hp
- ///
- BUILDIN_FUNC(guardianinfo)
- {
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
- int id = script_getnum(st,3);
- int type = script_getnum(st,4);
- struct guild_castle* gc = guild_mapname2gc(mapname);
- struct mob_data* gd;
- if( gc == NULL || id < 0 || id >= MAX_GUARDIANS )
- {
- script_pushint(st,-1);
- return 0;
- }
- if( type == 0 )
- script_pushint(st, gc->guardian[id].visible);
- else
- if( !gc->guardian[id].visible )
- script_pushint(st,-1);
- else
- if( (gd = map_id2md(gc->guardian[id].id)) == NULL )
- script_pushint(st,-1);
- else
- {
- if ( type == 1 ) script_pushint(st,gd->status.max_hp);
- else if( type == 2 ) script_pushint(st,gd->status.hp);
- else
- script_pushint(st,-1);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get the item name by item_id or null
- *------------------------------------------*/
- BUILDIN_FUNC(getitemname)
- {
- int item_id=0;
- struct item_data *i_data;
- char *item_name;
- struct script_data *data;
- data=script_getdata(st,2);
- get_val(st,data);
- if( data_isstring(data) ){
- const char *name=conv_str(st,data);
- struct item_data *item_data = itemdb_searchname(name);
- if( item_data )
- item_id=item_data->nameid;
- }else
- item_id=conv_num(st,data);
- i_data = itemdb_exists(item_id);
- if (i_data == NULL)
- {
- script_pushconststr(st,"null");
- return 0;
- }
- item_name=(char *)aMalloc(ITEM_NAME_LENGTH*sizeof(char));
- memcpy(item_name, i_data->jname, ITEM_NAME_LENGTH);
- script_pushstr(st,item_name);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns number of slots an item has. [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(getitemslots)
- {
- int item_id;
- struct item_data *i_data;
- item_id=script_getnum(st,2);
- i_data = itemdb_exists(item_id);
- if (i_data)
- script_pushint(st,i_data->slot);
- else
- script_pushint(st,-1);
- return SCRIPT_CMD_SUCCESS;
- }
- // TODO: add matk here if needed/once we get rid of RENEWAL
- /*==========================================
- * Returns some values of an item [Lupus]
- * Price, Weight, etc...
- getiteminfo(itemID,n), where n
- 0 value_buy;
- 1 value_sell;
- 2 type;
- 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
- if = 0, then monsters don't drop it at all (rare or a quest item)
- if = -1, then this item is sold in NPC shops only
- 4 sex;
- 5 equip;
- 6 weight;
- 7 atk;
- 8 def;
- 9 range;
- 10 slot;
- 11 look;
- 12 elv;
- 13 wlv;
- 14 view id
- *------------------------------------------*/
- BUILDIN_FUNC(getiteminfo)
- {
- int item_id,n;
- int *item_arr;
- struct item_data *i_data;
- item_id = script_getnum(st,2);
- n = script_getnum(st,3);
- i_data = itemdb_exists(item_id);
- if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
- script_pushint(st,item_arr[n]);
- } else
- script_pushint(st,-1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Set some values of an item [Lupus]
- * Price, Weight, etc...
- setiteminfo(itemID,n,Value), where n
- 0 value_buy;
- 1 value_sell;
- 2 type;
- 3 maxchance = Max drop chance of this item e.g. 1 = 0.01% , etc..
- if = 0, then monsters don't drop it at all (rare or a quest item)
- if = -1, then this item is sold in NPC shops only
- 4 sex;
- 5 equip;
- 6 weight;
- 7 atk;
- 8 def;
- 9 range;
- 10 slot;
- 11 look;
- 12 elv;
- 13 wlv;
- 14 view id
- * Returns Value or -1 if the wrong field's been set
- *------------------------------------------*/
- BUILDIN_FUNC(setiteminfo)
- {
- int item_id,n,value;
- int *item_arr;
- struct item_data *i_data;
- item_id = script_getnum(st,2);
- n = script_getnum(st,3);
- value = script_getnum(st,4);
- i_data = itemdb_exists(item_id);
- if (i_data && n>=0 && n<=14) {
- item_arr = (int*)&i_data->value_buy;
- item_arr[n] = value;
- script_pushint(st,value);
- } else
- script_pushint(st,-1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns value from equipped item slot n [Lupus]
- getequipcardid(num,slot)
- where
- num = eqip position slot
- slot = 0,1,2,3 (Card Slot N)
- This func returns CARD ID, 255,254,-255 (for card 0, if the item is produced)
- it's useful when you want to check item cards or if it's signed
- Useful for such quests as "Sign this refined item with players name" etc
- Hat[0] +4 -> Player's Hat[0] +4
- *------------------------------------------*/
- BUILDIN_FUNC(getequipcardid)
- {
- int i=-1,num,slot;
- TBL_PC *sd;
- num=script_getnum(st,2);
- slot=script_getnum(st,3);
- sd=script_rid2sd(st);
- if (num > 0 && num <= ARRAYLENGTH(equip))
- i=pc_checkequip(sd,equip[num-1]);
- if(i >= 0 && slot>=0 && slot<4)
- script_pushint(st,sd->status.inventory[i].card[slot]);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * petskillbonus [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petskillbonus)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->bonus)
- { //Clear previous bonus
- if (pd->bonus->timer != INVALID_TIMER)
- delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
- } else //init
- pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
- pd->bonus->type=script_getnum(st,2);
- pd->bonus->val=script_getnum(st,3);
- pd->bonus->duration=script_getnum(st,4);
- pd->bonus->delay=script_getnum(st,5);
- if (pd->state.skillbonus == 1)
- pd->state.skillbonus=0; // waiting state
- // wait for timer to start
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->bonus->timer = INVALID_TIMER;
- else
- pd->bonus->timer = add_timer(gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet looting [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petloot)
- {
- int max;
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- max=script_getnum(st,2);
- if(max < 1)
- max = 1; //Let'em loot at least 1 item.
- else if (max > MAX_PETLOOT_SIZE)
- max = MAX_PETLOOT_SIZE;
- pd = sd->pd;
- if (pd->loot != NULL)
- { //Release whatever was there already and reallocate memory
- pet_lootitem_drop(pd, pd->master);
- aFree(pd->loot->item);
- }
- else
- pd->loot = (struct pet_loot *)aMalloc(sizeof(struct pet_loot));
- pd->loot->item = (struct item *)aCalloc(max,sizeof(struct item));
- pd->loot->max=max;
- pd->loot->count = 0;
- pd->loot->weight = 0;
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Set arrays with info of all sd inventory :
- * @inventorylist_id, @inventorylist_amount, @inventorylist_equip,
- * @inventorylist_refine, @inventorylist_identify, @inventorylist_attribute,
- * @inventorylist_card(0..3), @inventorylist_expire
- * @inventorylist_count = scalar
- *------------------------------------------*/
- BUILDIN_FUNC(getinventorylist)
- {
- TBL_PC *sd=script_rid2sd(st);
- char card_var[NAME_LENGTH];
- int i,j=0,k;
- if(!sd) return 0;
- for(i=0;i<MAX_INVENTORY;i++){
- if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
- pc_setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
- for (k = 0; k < MAX_SLOTS; k++)
- {
- sprintf(card_var, "@inventorylist_card%d",k+1);
- pc_setreg(sd,reference_uid(add_str(card_var), j),sd->status.inventory[i].card[k]);
- }
- pc_setreg(sd,reference_uid(add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time);
- pc_setreg(sd,reference_uid(add_str("@inventorylist_bound"), j),sd->status.inventory[i].bound);
- j++;
- }
- }
- pc_setreg(sd,add_str("@inventorylist_count"),j);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getskilllist)
- {
- TBL_PC *sd=script_rid2sd(st);
- int i,j=0;
- if(!sd) return 0;
- for(i=0;i<MAX_SKILL;i++){
- if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
- pc_setreg(sd,reference_uid(add_str("@skilllist_id"), j),sd->status.skill[i].id);
- pc_setreg(sd,reference_uid(add_str("@skilllist_lv"), j),sd->status.skill[i].lv);
- pc_setreg(sd,reference_uid(add_str("@skilllist_flag"), j),sd->status.skill[i].flag);
- j++;
- }
- }
- pc_setreg(sd,add_str("@skilllist_count"),j);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(clearitem)
- {
- TBL_PC *sd=script_rid2sd(st);
- int i;
- if(sd==NULL) return 0;
- for (i=0; i<MAX_INVENTORY; i++) {
- if (sd->status.inventory[i].amount) {
- pc_delitem(sd, i, sd->status.inventory[i].amount, 0, 0, LOG_TYPE_SCRIPT);
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Disguise Player (returns Mob/NPC ID if success, 0 on fail)
- *------------------------------------------*/
- BUILDIN_FUNC(disguise)
- {
- int id;
- TBL_PC* sd = script_rid2sd(st);
- if (sd == NULL) return 0;
- id = script_getnum(st,2);
- if (mobdb_checkid(id) || npcdb_checkid(id)) {
- pc_disguise(sd, id);
- script_pushint(st,id);
- } else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Undisguise Player (returns 1 if success, 0 on fail)
- *------------------------------------------*/
- BUILDIN_FUNC(undisguise)
- {
- TBL_PC* sd = script_rid2sd(st);
- if (sd == NULL) return 0;
- if (sd->disguise) {
- pc_disguise(sd, 0);
- script_pushint(st,0);
- } else {
- script_pushint(st,1);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Transform a bl to another _class,
- * @type unused
- *------------------------------------------*/
- BUILDIN_FUNC(classchange)
- {
- int _class,type;
- struct block_list *bl=map_id2bl(st->oid);
- if(bl==NULL) return 0;
- _class=script_getnum(st,2);
- type=script_getnum(st,3);
- clif_class_change(bl,_class,type);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Display an effect
- *------------------------------------------*/
- BUILDIN_FUNC(misceffect)
- {
- int type;
- type=script_getnum(st,2);
- if(st->oid && st->oid != fake_nd->bl.id) {
- struct block_list *bl = map_id2bl(st->oid);
- if (bl)
- clif_specialeffect(bl,type,AREA);
- } else{
- TBL_PC *sd=script_rid2sd(st);
- if(sd)
- clif_specialeffect(&sd->bl,type,AREA);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Play a BGM on a single client [Rikter/Yommy]
- *------------------------------------------*/
- BUILDIN_FUNC(playBGM)
- {
- const char* name;
- struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) != NULL ) {
- name = script_getstr(st,2);
- clif_playBGM(sd, name);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- static int playBGM_sub(struct block_list* bl,va_list ap)
- {
- const char* name = va_arg(ap,const char*);
- clif_playBGM(BL_CAST(BL_PC, bl), name);
- return 0;
- }
- static int playBGM_foreachpc_sub(struct map_session_data* sd, va_list args)
- {
- const char* name = va_arg(args, const char*);
- clif_playBGM(sd, name);
- return 0;
- }
- /*==========================================
- * Play a BGM on multiple client [Rikter/Yommy]
- *------------------------------------------*/
- BUILDIN_FUNC(playBGMall)
- {
- const char* name;
- name = script_getstr(st,2);
- if( script_hasdata(st,7) ) {// specified part of map
- const char* map = script_getstr(st,3);
- int x0 = script_getnum(st,4);
- int y0 = script_getnum(st,5);
- int x1 = script_getnum(st,6);
- int y1 = script_getnum(st,7);
- map_foreachinarea(playBGM_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name);
- }
- else if( script_hasdata(st,3) ) {// entire map
- const char* map = script_getstr(st,3);
- map_foreachinmap(playBGM_sub, map_mapname2mapid(map), BL_PC, name);
- }
- else {// entire server
- map_foreachpc(&playBGM_foreachpc_sub, name);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Play a .wav sound for sd
- *------------------------------------------*/
- BUILDIN_FUNC(soundeffect)
- {
- TBL_PC* sd = script_rid2sd(st);
- const char* name = script_getstr(st,2);
- int type = script_getnum(st,3);
- if(sd) {
- clif_soundeffect(sd,&sd->bl,name,type);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- int soundeffect_sub(struct block_list* bl,va_list ap)
- {
- char* name = va_arg(ap,char*);
- int type = va_arg(ap,int);
- clif_soundeffect((TBL_PC *)bl, bl, name, type);
- return 0;
- }
- /*==========================================
- * Play a sound effect (.wav) on multiple clients
- * soundeffectall "<filepath>",<type>{,"<map name>"}{,<x0>,<y0>,<x1>,<y1>};
- *------------------------------------------*/
- BUILDIN_FUNC(soundeffectall)
- {
- struct block_list* bl;
- const char* name;
- int type;
- bl = (st->rid) ? &(script_rid2sd(st)->bl) : map_id2bl(st->oid);
- if (!bl)
- return 0;
- name = script_getstr(st,2);
- type = script_getnum(st,3);
- //FIXME: enumerating map squares (map_foreach) is slower than enumerating the list of online players (map_foreachpc?) [ultramage]
- if(!script_hasdata(st,4))
- { // area around
- clif_soundeffectall(bl, name, type, AREA);
- }
- else
- if(!script_hasdata(st,5))
- { // entire map
- const char* map = script_getstr(st,4);
- map_foreachinmap(soundeffect_sub, map_mapname2mapid(map), BL_PC, name, type);
- }
- else
- if(script_hasdata(st,8))
- { // specified part of map
- const char* map = script_getstr(st,4);
- int x0 = script_getnum(st,5);
- int y0 = script_getnum(st,6);
- int x1 = script_getnum(st,7);
- int y1 = script_getnum(st,8);
- map_foreachinarea(soundeffect_sub, map_mapname2mapid(map), x0, y0, x1, y1, BL_PC, name, type);
- }
- else
- {
- ShowError("buildin_soundeffectall: insufficient arguments for specific area broadcast.\n");
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet status recovery [Valaris] / Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petrecovery)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->recovery)
- { //Halt previous bonus
- if (pd->recovery->timer != INVALID_TIMER)
- delete_timer(pd->recovery->timer, pet_recovery_timer);
- } else //Init
- pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
- pd->recovery->type = (sc_type)script_getnum(st,2);
- pd->recovery->delay = script_getnum(st,3);
- pd->recovery->timer = INVALID_TIMER;
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet healing [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- BUILDIN_FUNC(petheal)
- {
- struct pet_data *pd;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->s_skill)
- { //Clear previous skill
- if (pd->s_skill->timer != INVALID_TIMER)
- {
- if (pd->s_skill->id)
- delete_timer(pd->s_skill->timer, pet_skill_support_timer);
- else
- delete_timer(pd->s_skill->timer, pet_heal_timer);
- }
- } else //init memory
- pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
- pd->s_skill->id=0; //This id identifies that it IS petheal rather than pet_skillsupport
- //Use the lv as the amount to heal
- pd->s_skill->lv=script_getnum(st,2);
- pd->s_skill->delay=script_getnum(st,3);
- pd->s_skill->hp=script_getnum(st,4);
- pd->s_skill->sp=script_getnum(st,5);
- //Use delay as initial offset to avoid skill/heal exploits
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->s_skill->timer = INVALID_TIMER;
- else
- pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet attack skills [Valaris] //Rewritten by [Skotlex]
- *------------------------------------------*/
- /// petskillattack <skill id>,<level>,<rate>,<bonusrate>
- /// petskillattack "<skill name>",<level>,<rate>,<bonusrate>
- BUILDIN_FUNC(petskillattack)
- {
- struct pet_data *pd;
- struct script_data *data;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->a_skill == NULL)
- pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- pd->a_skill->id=( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->a_skill->lv=script_getnum(st,3);
- pd->a_skill->div_ = 0;
- pd->a_skill->rate=script_getnum(st,4);
- pd->a_skill->bonusrate=script_getnum(st,5);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet attack skills [Valaris]
- *------------------------------------------*/
- /// petskillattack2 <skill id>,<level>,<div>,<rate>,<bonusrate>
- /// petskillattack2 "<skill name>",<level>,<div>,<rate>,<bonusrate>
- BUILDIN_FUNC(petskillattack2)
- {
- struct pet_data *pd;
- struct script_data *data;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->a_skill == NULL)
- pd->a_skill = (struct pet_skill_attack *)aMalloc(sizeof(struct pet_skill_attack));
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- pd->a_skill->id=( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->a_skill->lv=script_getnum(st,3);
- pd->a_skill->div_ = script_getnum(st,4);
- pd->a_skill->rate=script_getnum(st,5);
- pd->a_skill->bonusrate=script_getnum(st,6);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * pet support skills [Skotlex]
- *------------------------------------------*/
- /// petskillsupport <skill id>,<level>,<delay>,<hp>,<sp>
- /// petskillsupport "<skill name>",<level>,<delay>,<hp>,<sp>
- BUILDIN_FUNC(petskillsupport)
- {
- struct pet_data *pd;
- struct script_data *data;
- TBL_PC *sd=script_rid2sd(st);
- if(sd==NULL || sd->pd==NULL)
- return 0;
- pd=sd->pd;
- if (pd->s_skill)
- { //Clear previous skill
- if (pd->s_skill->timer != INVALID_TIMER)
- {
- if (pd->s_skill->id)
- delete_timer(pd->s_skill->timer, pet_skill_support_timer);
- else
- delete_timer(pd->s_skill->timer, pet_heal_timer);
- }
- } else //init memory
- pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- pd->s_skill->id=( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- pd->s_skill->lv=script_getnum(st,3);
- pd->s_skill->delay=script_getnum(st,4);
- pd->s_skill->hp=script_getnum(st,5);
- pd->s_skill->sp=script_getnum(st,6);
- //Use delay as initial offset to avoid skill/heal exploits
- if (battle_config.pet_equip_required && pd->pet.equip == 0)
- pd->s_skill->timer = INVALID_TIMER;
- else
- pd->s_skill->timer = add_timer(gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Scripted skill effects [Celest]
- *------------------------------------------*/
- /// skilleffect <skill id>,<level>
- /// skilleffect "<skill name>",<level>
- BUILDIN_FUNC(skilleffect)
- {
- TBL_PC *sd;
- uint16 skill_id, skill_lv;
- struct script_data *data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- skill_id=( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- skill_lv=script_getnum(st,3);
- sd=script_rid2sd(st);
- clif_skill_nodamage(&sd->bl,&sd->bl,skill_id,skill_lv,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * NPC skill effects [Valaris]
- *------------------------------------------*/
- /// npcskilleffect <skill id>,<level>,<x>,<y>
- /// npcskilleffect "<skill name>",<level>,<x>,<y>
- BUILDIN_FUNC(npcskilleffect)
- {
- struct block_list *bl= map_id2bl(st->oid);
- uint16 skill_id, skill_lv;
- int x, y;
- struct script_data *data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- skill_id=( data_isstring(data) ? skill_name2id(script_getstr(st,2)) : script_getnum(st,2) );
- skill_lv=script_getnum(st,3);
- x=script_getnum(st,4);
- y=script_getnum(st,5);
- if (bl)
- clif_skill_poseffect(bl,skill_id,skill_lv,x,y,gettick());
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Special effects [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(specialeffect)
- {
- struct block_list *bl=map_id2bl(st->oid);
- int type = script_getnum(st,2);
- enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
- if(bl==NULL)
- return 0;
- if( script_hasdata(st,4) )
- {
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
- if(nd)
- clif_specialeffect(&nd->bl, type, target);
- }
- else
- {
- if (target == SELF) {
- TBL_PC *sd=script_rid2sd(st);
- if (sd)
- clif_specialeffect_single(bl,type,sd->fd);
- } else {
- clif_specialeffect(bl, type, target);
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(specialeffect2)
- {
- TBL_PC *sd=script_rid2sd(st);
- int type = script_getnum(st,2);
- enum send_target target = script_hasdata(st,3) ? (send_target)script_getnum(st,3) : AREA;
- if( script_hasdata(st,4) )
- sd = map_nick2sd(script_getstr(st,4));
- if (sd)
- clif_specialeffect(&sd->bl, type, target);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Nude [Valaris]
- *------------------------------------------*/
- BUILDIN_FUNC(nude)
- {
- TBL_PC *sd = script_rid2sd(st);
- int i, calcflag = 0;
- if( sd == NULL )
- return 0;
- for( i = 0 ; i < EQI_MAX; i++ ) {
- if( sd->equip_index[ i ] >= 0 ) {
- if( !calcflag )
- calcflag = 1;
- pc_unequipitem( sd , sd->equip_index[ i ] , 2);
- }
- }
- if( calcflag )
- status_calc_pc(sd,0);
- return SCRIPT_CMD_SUCCESS;
- }
- int atcommand_sub(struct script_state* st,int type){
- TBL_PC dummy_sd;
- TBL_PC* sd;
- int fd;
- const char* cmd;
- cmd = script_getstr(st,2);
- if (st->rid) {
- sd = script_rid2sd(st);
- fd = sd->fd;
- } else { //Use a dummy character.
- sd = &dummy_sd;
- fd = 0;
- memset(&dummy_sd, 0, sizeof(TBL_PC));
- if (st->oid)
- {
- struct block_list* bl = map_id2bl(st->oid);
- memcpy(&dummy_sd.bl, bl, sizeof(struct block_list));
- if (bl->type == BL_NPC)
- safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH);
- }
- }
- if (!is_atcommand(fd, sd, cmd, type)) {
- ShowWarning("script: buildin_atcommand: failed to execute command '%s'\n", cmd);
- script_reportsrc(st);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * gmcommand [MouseJstr]
- *------------------------------------------*/
- BUILDIN_FUNC(atcommand) {
- return atcommand_sub(st,0);
- }
- /*==========================================
- * Displays a message for the player only (like system messages like "you got an apple" )
- *------------------------------------------*/
- BUILDIN_FUNC(dispbottom)
- {
- TBL_PC *sd=script_rid2sd(st);
- const char *message;
- message=script_getstr(st,2);
- if(sd)
- clif_disp_onlyself(sd,message,(int)strlen(message));
- return SCRIPT_CMD_SUCCESS;
- }
- /*===================================
- * Heal portion of recovery command
- *-----------------------------------*/
- int recovery_sub(struct map_session_data* sd, int revive)
- {
- if(revive&(1|4) && pc_isdead(sd)) {
- status_revive(&sd->bl, 100, 100);
- clif_displaymessage(sd->fd,msg_txt(sd,16)); // You've been revived!
- clif_specialeffect(&sd->bl, 77, AREA);
- } else if(revive&(1|2) && !pc_isdead(sd)) {
- status_percent_heal(&sd->bl, 100, 100);
- clif_displaymessage(sd->fd,msg_txt(sd,680)); // You have been recovered!
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*=========================================================================
- * Fully Recover a Character's HP/SP - [Capuche] & [Akinari]
- * recovery <type>{,<option>,<revive_flag>{,<map name>}};
- * <type> determines <option>:
- * 0 : char_id
- * 1 : party_id
- * 2 : guild_id
- * 3 : map_name
- * 4 : all characters
- * <revive_flag>:
- * 1 : Revive and heal all players (default)
- * 2 : Heal living players only
- * 4 : Revive dead players only
- * <map name>:
- * for types 1-2 : map_name (null = all maps)
- *-------------------------------------------------------------------------*/
- BUILDIN_FUNC(recovery)
- {
- TBL_PC *sd;
- int map = 0, type = 0, revive = 1;
- type = script_getnum(st,2);
- if(script_hasdata(st,4))
- revive = script_getnum(st,4);
- switch(type) {
- case 0:
- if(script_hasdata(st,3))
- sd=map_charid2sd(script_getnum(st,3));
- else if((sd = script_rid2sd(st)) == NULL)
- return 0; //If we don't have sd by now, bail out
- recovery_sub(sd, revive);
- break;
- case 1:
- {
- struct party_data* p;
- struct map_session_data* pl_sd;
- //When no party given, we use invoker party
- int p_id = 0, i;
- if(script_hasdata(st,5)) {//Bad maps shouldn't cause issues
- map = map_mapname2mapid(script_getstr(st,5));
- if(map < 1) { //But we'll check anyways
- ShowDebug("recovery: bad map name given (%s)\n", script_getstr(st,5));
- return 1;
- }
- }
- if(script_hasdata(st,3))
- p_id = script_getnum(st,3);
- else if((sd = script_rid2sd(st)))
- p_id = sd->status.party_id;
- p = party_search(p_id);
- if(p == NULL)
- return 0;
- for (i = 0; i < MAX_PARTY; i++) {
- if((!(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id)
- || (map && pl_sd->bl.m != map))
- continue;
- recovery_sub(pl_sd, revive);
- }
- break;
- }
- case 2:
- {
- struct guild* g;
- struct map_session_data* pl_sd;
- //When no guild given, we use invoker guild
- int g_id = 0, i;
- if(script_hasdata(st,5)) {//Bad maps shouldn't cause issues
- map = map_mapname2mapid(script_getstr(st,5));
- if(map < 1) { //But we'll check anyways
- ShowDebug("recovery: bad map name given (%s)\n", script_getstr(st,5));
- return 1;
- }
- }
- if(script_hasdata(st,3))
- g_id = script_getnum(st,3);
- else if((sd = script_rid2sd(st)))
- g_id = sd->status.guild_id;
- g = guild_search(g_id);
- if(g == NULL)
- return 0;
- for (i = 0; i < MAX_GUILD; i++) {
- if((!(pl_sd = g->member[i].sd) || pl_sd->status.guild_id != g_id)
- || (map && pl_sd->bl.m != map))
- continue;
- recovery_sub(pl_sd, revive);
- }
- break;
- }
- case 3:
- if(script_hasdata(st,3))
- map = map_mapname2mapid(script_getstr(st,3));
- else if((sd = script_rid2sd(st)))
- map = sd->bl.m;
- if(map < 1)
- return 1; //No sd and no map given - return
- case 4:
- {
- struct s_mapiterator *iter;
- struct script_data *data = script_getdata(st, 3);
- get_val(st, data); // Convert into value in case of a variable
- if(script_hasdata(st,3) && !data_isstring(data))
- revive = script_getnum(st,3); // recovery 4,<revive_flag>;
- iter = mapit_getallusers();
- for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) {
- if(type == 3 && sd->bl.m != map)
- continue;
- recovery_sub(sd, revive);
- }
- mapit_free(iter);
- break;
- }
- default:
- ShowWarning("script: buildin_recovery: Invalid type %d\n", type);
- script_pushint(st,-1);
- return 1;
- }
- script_pushint(st,1); //Successfully executed without errors
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get your pet info: getpetinfo(n)
- * n -> 0:pet_id 1:pet_class 2:pet_name
- * 3:friendly 4:hungry, 5: rename flag.6:level
- *------------------------------------------*/
- BUILDIN_FUNC(getpetinfo)
- {
- TBL_PC *sd=script_rid2sd(st);
- TBL_PET *pd;
- int type=script_getnum(st,2);
- if(!sd || !sd->pd) {
- if (type == 2)
- script_pushconststr(st,"null");
- else
- script_pushint(st,0);
- return 0;
- }
- pd = sd->pd;
- switch(type){
- case 0: script_pushint(st,pd->pet.pet_id); break;
- case 1: script_pushint(st,pd->pet.class_); break;
- case 2: script_pushstrcopy(st,pd->pet.name); break;
- case 3: script_pushint(st,pd->pet.intimate); break;
- case 4: script_pushint(st,pd->pet.hungry); break;
- case 5: script_pushint(st,pd->pet.rename_flag); break;
- case 6: script_pushint(st,(int)pd->pet.level); break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get your homunculus info: gethominfo(n)
- * n -> 0:hom_id 1:class 2:name
- * 3:friendly 4:hungry, 5: rename flag.
- * 6: level
- *------------------------------------------*/
- BUILDIN_FUNC(gethominfo)
- {
- TBL_PC *sd=script_rid2sd(st);
- TBL_HOM *hd;
- int type=script_getnum(st,2);
- hd = sd?sd->hd:NULL;
- if(!hd) {
- if (type == 2)
- script_pushconststr(st,"null");
- else
- script_pushint(st,0);
- return 0;
- }
- switch(type){
- case 0: script_pushint(st,hd->homunculus.hom_id); break;
- case 1: script_pushint(st,hd->homunculus.class_); break;
- case 2: script_pushstrcopy(st,hd->homunculus.name); break;
- case 3: script_pushint(st,hd->homunculus.intimacy); break;
- case 4: script_pushint(st,hd->homunculus.hunger); break;
- case 5: script_pushint(st,hd->homunculus.rename_flag); break;
- case 6: script_pushint(st,hd->homunculus.level); break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Retrieves information about character's mercenary
- /// getmercinfo <type>[,<char id>];
- BUILDIN_FUNC(getmercinfo)
- {
- int type, char_id;
- struct map_session_data* sd;
- struct mercenary_data* md;
- type = script_getnum(st,2);
- if( script_hasdata(st,3) )
- {
- char_id = script_getnum(st,3);
- if( ( sd = map_charid2sd(char_id) ) == NULL )
- {
- ShowError("buildin_getmercinfo: No such character (char_id=%d).\n", char_id);
- script_pushnil(st);
- return 1;
- }
- }
- else
- {
- if( ( sd = script_rid2sd(st) ) == NULL )
- {
- script_pushnil(st);
- return 0;
- }
- }
- md = ( sd->status.mer_id && sd->md ) ? sd->md : NULL;
- switch( type )
- {
- case 0: script_pushint(st,md ? md->mercenary.mercenary_id : 0); break;
- case 1: script_pushint(st,md ? md->mercenary.class_ : 0); break;
- case 2:
- if( md )
- script_pushstrcopy(st,md->db->name);
- else
- script_pushconststr(st,"");
- break;
- case 3: script_pushint(st,md ? mercenary_get_faith(md) : 0); break;
- case 4: script_pushint(st,md ? mercenary_get_calls(md) : 0); break;
- case 5: script_pushint(st,md ? md->mercenary.kill_count : 0); break;
- case 6: script_pushint(st,md ? mercenary_get_lifetime(md) : 0); break;
- case 7: script_pushint(st,md ? md->db->lv : 0); break;
- default:
- ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id);
- script_pushnil(st);
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Shows wether your inventory(and equips) contain
- selected card or not.
- checkequipedcard(4001);
- *------------------------------------------*/
- BUILDIN_FUNC(checkequipedcard)
- {
- TBL_PC *sd=script_rid2sd(st);
- if(sd){
- int n,i,c=0;
- c=script_getnum(st,2);
- for(i=0;i<MAX_INVENTORY;i++){
- if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount && sd->inventory_data[i]){
- if (itemdb_isspecial(sd->status.inventory[i].card[0]))
- continue;
- for(n=0;n<sd->inventory_data[i]->slot;n++){
- if(sd->status.inventory[i].card[n]==c){
- script_pushint(st,1);
- return 0;
- }
- }
- }
- }
- }
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(jump_zero)
- {
- int sel;
- sel=script_getnum(st,2);
- if(!sel) {
- int pos;
- if( !data_islabel(script_getdata(st,3)) ){
- ShowError("script: jump_zero: not label !\n");
- st->state=END;
- return 1;
- }
- pos=script_getnum(st,3);
- st->pos=pos;
- st->state=GOTO;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * movenpc [MouseJstr]
- *------------------------------------------*/
- BUILDIN_FUNC(movenpc)
- {
- TBL_NPC *nd = NULL;
- const char *npc;
- int x,y;
- npc = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if ((nd = npc_name2id(npc)) == NULL)
- return -1;
- if (script_hasdata(st,5))
- nd->ud.dir = script_getnum(st,5) % 8;
- npc_movenpc(nd, x, y);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * message [MouseJstr]
- *------------------------------------------*/
- BUILDIN_FUNC(message)
- {
- const char *msg,*player;
- TBL_PC *pl_sd = NULL;
- player = script_getstr(st,2);
- msg = script_getstr(st,3);
- if((pl_sd=map_nick2sd((char *) player)) == NULL)
- return 0;
- clif_displaymessage(pl_sd->fd, msg);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * npctalk (sends message to surrounding area)
- *------------------------------------------*/
- BUILDIN_FUNC(npctalk)
- {
- const char* str;
- char name[NAME_LENGTH], message[256];
- struct npc_data* nd = (struct npc_data *)map_id2bl(st->oid);
- str = script_getstr(st,2);
- if(nd)
- {
- safestrncpy(name, nd->name, sizeof(name));
- strtok(name, "#"); // discard extra name identifier if present
- safesnprintf(message, sizeof(message), "%s : %s", name, str);
- clif_disp_overhead(&nd->bl, message);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- // change npc walkspeed [Valaris]
- BUILDIN_FUNC(npcspeed)
- {
- struct npc_data* nd;
- int speed;
- speed = script_getnum(st,2);
- nd =(struct npc_data *)map_id2bl(st->oid);
- if( nd ) {
- nd->speed = speed;
- nd->ud.state.speed_changed = 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- // make an npc walk to a position [Valaris]
- BUILDIN_FUNC(npcwalkto)
- {
- struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
- int x=0,y=0;
- x=script_getnum(st,2);
- y=script_getnum(st,3);
- if(nd) {
- if (!nd->status.hp) {
- status_calc_npc(nd, true);
- } else {
- status_calc_npc(nd, false);
- }
- unit_walktoxy(&nd->bl,x,y,0);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- // stop an npc's movement [Valaris]
- BUILDIN_FUNC(npcstop)
- {
- struct npc_data *nd=(struct npc_data *)map_id2bl(st->oid);
- if(nd) {
- unit_stop_walking(&nd->bl,1|4);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * getlook char info. getlook(arg)
- *------------------------------------------*/
- BUILDIN_FUNC(getlook)
- {
- int type,val;
- TBL_PC *sd;
- sd=script_rid2sd(st);
- type=script_getnum(st,2);
- val=-1;
- switch(type) {
- case LOOK_HAIR: val=sd->status.hair; break; //1
- case LOOK_WEAPON: val=sd->status.weapon; break; //2
- case LOOK_HEAD_BOTTOM: val=sd->status.head_bottom; break; //3
- case LOOK_HEAD_TOP: val=sd->status.head_top; break; //4
- case LOOK_HEAD_MID: val=sd->status.head_mid; break; //5
- case LOOK_HAIR_COLOR: val=sd->status.hair_color; break; //6
- case LOOK_CLOTHES_COLOR: val=sd->status.clothes_color; break; //7
- case LOOK_SHIELD: val=sd->status.shield; break; //8
- case LOOK_SHOES: break; //9
- case LOOK_ROBE: val=sd->status.robe; break; //12
- }
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * get char save point. argument: 0- map name, 1- x, 2- y
- *------------------------------------------*/
- BUILDIN_FUNC(getsavepoint)
- {
- TBL_PC* sd;
- int type;
- sd = script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- type = script_getnum(st,2);
- switch(type) {
- case 0: script_pushstrcopy(st,mapindex_id2name(sd->status.save_point.map)); break;
- case 1: script_pushint(st,sd->status.save_point.x); break;
- case 2: script_pushint(st,sd->status.save_point.y); break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Get position for char/npc/pet/mob objects. Added by Lorky
- *
- * int getMapXY(MapName$,MapX,MapY,type,[CharName$]);
- * where type:
- * MapName$ - String variable for output map name
- * MapX - Integer variable for output coord X
- * MapY - Integer variable for output coord Y
- * type - type of object
- * 0 - Character coord
- * 1 - NPC coord
- * 2 - Pet coord
- * 3 - Mob coord (not released)
- * 4 - Homun coord
- * 5 - Mercenary coord
- * 6 - Elemental coord
- * CharName$ - Name object. If miss or "this" the current object
- *
- * Return:
- * 0 - success
- * -1 - some error, MapName$,MapX,MapY contains unknown value.
- *------------------------------------------*/
- BUILDIN_FUNC(getmapxy)
- {
- struct block_list *bl = NULL;
- TBL_PC *sd=NULL;
- int num;
- const char *name;
- char prefix;
- int x,y,type;
- char mapname[MAP_NAME_LENGTH];
- if( !data_isreference(script_getdata(st,2)) ){
- ShowWarning("script: buildin_getmapxy: not mapname variable\n");
- script_pushint(st,-1);
- return 1;
- }
- if( !data_isreference(script_getdata(st,3)) ){
- ShowWarning("script: buildin_getmapxy: not mapx variable\n");
- script_pushint(st,-1);
- return 1;
- }
- if( !data_isreference(script_getdata(st,4)) ){
- ShowWarning("script: buildin_getmapxy: not mapy variable\n");
- script_pushint(st,-1);
- return 1;
- }
- // Possible needly check function parameters on C_STR,C_INT,C_INT
- type=script_getnum(st,5);
- switch (type){
- case 0: //Get Character Position
- if( script_hasdata(st,6) )
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd)
- bl = &sd->bl;
- break;
- case 1: //Get NPC Position
- if( script_hasdata(st,6) )
- {
- struct npc_data *nd;
- nd=npc_name2id(script_getstr(st,6));
- if (nd)
- bl = &nd->bl;
- } else //In case the origin is not an npc?
- bl=map_id2bl(st->oid);
- break;
- case 2: //Get Pet Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->pd)
- bl = &sd->pd->bl;
- break;
- case 3: //Get Mob Position
- break; //Not supported?
- case 4: //Get Homun Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->hd)
- bl = &sd->hd->bl;
- break;
- case 5: //Get Mercenary Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->md)
- bl = &sd->md->bl;
- break;
- case 6: //Get Elemental Position
- if(script_hasdata(st,6))
- sd=map_nick2sd(script_getstr(st,6));
- else
- sd=script_rid2sd(st);
- if (sd && sd->ed)
- bl = &sd->ed->bl;
- break;
- default:
- ShowWarning("script: buildin_getmapxy: Invalid type %d\n", type);
- script_pushint(st,-1);
- return 1;
- }
- if (!bl) { //No object found.
- script_pushint(st,-1);
- return 0;
- }
- x= bl->x;
- y= bl->y;
- safestrncpy(mapname, map[bl->m].name, MAP_NAME_LENGTH);
- //Set MapName$
- num=st->stack->stack_data[st->start+2].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2));
- //Set MapX
- num=st->stack->stack_data[st->start+3].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)__64BPRTSIZE(x),script_getref(st,3));
- //Set MapY
- num=st->stack->stack_data[st->start+4].u.num;
- name=get_str(num&0x00ffffff);
- prefix=*name;
- if(not_server_variable(prefix))
- sd=script_rid2sd(st);
- else
- sd=NULL;
- set_reg(st,sd,num,name,(void*)__64BPRTSIZE(y),script_getref(st,4));
- //Return Success value
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Allows player to write NPC logs (i.e. Bank NPC, etc) [Lupus]
- *------------------------------------------*/
- BUILDIN_FUNC(logmes)
- {
- const char *str;
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 1;
- str = script_getstr(st,2);
- log_npc(sd,str);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(summon)
- {
- int _class, timeout=0;
- const char *str,*event="";
- TBL_PC *sd;
- struct mob_data *md;
- int tick = gettick();
- sd=script_rid2sd(st);
- if (!sd) return 0;
- str =script_getstr(st,2);
- _class=script_getnum(st,3);
- if( script_hasdata(st,4) )
- timeout=script_getnum(st,4);
- if( script_hasdata(st,5) ){
- event=script_getstr(st,5);
- check_event(st, event);
- }
- clif_skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
- md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event, SZ_SMALL, AI_NONE);
- if (md) {
- md->master_id=sd->bl.id;
- md->special_state.ai = AI_ATTACK;
- if( md->deletetimer != INVALID_TIMER )
- delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = add_timer(tick+(timeout>0?timeout:60000),mob_timer_delete,md->bl.id,0);
- mob_spawn (md); //Now it is ready for spawning.
- clif_specialeffect(&md->bl,344,AREA);
- sc_start4(NULL,&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Checks whether it is daytime/nighttime
- *------------------------------------------*/
- BUILDIN_FUNC(isnight)
- {
- script_pushint(st,(night_flag == 1));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(isday)
- {
- script_pushint(st,(night_flag == 0));
- return SCRIPT_CMD_SUCCESS;
- }
- /*================================================
- * Check how many items/cards in the list are
- * equipped - used for 2/15's cards patch [celest]
- *------------------------------------------------*/
- BUILDIN_FUNC(isequippedcnt)
- {
- TBL_PC *sd;
- int i, j, k, id = 1;
- int ret = 0;
- sd = script_rid2sd(st);
- if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
- script_pushint(st,0);
- return 0;
- }
- for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
- for (j=0; j<EQI_MAX; j++) {
- int index;
- index = sd->equip_index[j];
- if(index < 0) continue;
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
- if(!sd->inventory_data[index])
- continue;
- if (itemdb_type(id) != IT_CARD) { //No card. Count amount in inventory.
- if (sd->inventory_data[index]->nameid == id)
- ret+= sd->status.inventory[index].amount;
- } else { //Count cards.
- if (itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue; //No cards
- for(k=0; k<sd->inventory_data[index]->slot; k++) {
- if (sd->status.inventory[index].card[k] == id)
- ret++; //[Lupus]
- }
- }
- }
- }
- script_pushint(st,ret);
- return SCRIPT_CMD_SUCCESS;
- }
- /*================================================
- * Check whether another card has been
- * equipped - used for 2/15's cards patch [celest]
- * -- Items checked cannot be reused in another
- * card set to prevent exploits
- *------------------------------------------------*/
- BUILDIN_FUNC(isequipped)
- {
- TBL_PC *sd;
- int i, j, k, id = 1;
- int index, flag;
- int ret = -1;
- //Original hash to reverse it when full check fails.
- unsigned int setitem_hash = 0, setitem_hash2 = 0;
- sd = script_rid2sd(st);
- if (!sd) { //If the player is not attached it is a script error anyway... but better prevent the map server from crashing...
- script_pushint(st,0);
- return 0;
- }
- setitem_hash = sd->bonus.setitem_hash;
- setitem_hash2 = sd->bonus.setitem_hash2;
- for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
- flag = 0;
- for (j=0; j<EQI_MAX; j++) {
- index = sd->equip_index[j];
- if(index < 0) continue;
- if(j == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index) continue;
- if(j == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index) continue;
- if(j == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index)) continue;
- if(!sd->inventory_data[index])
- continue;
- if (itemdb_type(id) != IT_CARD) {
- if (sd->inventory_data[index]->nameid != id)
- continue;
- flag = 1;
- break;
- } else { //Cards
- if (sd->inventory_data[index]->slot == 0 ||
- itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue;
- for (k = 0; k < sd->inventory_data[index]->slot; k++)
- { //New hash system which should support up to 4 slots on any equipment. [Skotlex]
- unsigned int hash = 0;
- if (sd->status.inventory[index].card[k] != id)
- continue;
- hash = 1<<((j<5?j:j-5)*4 + k);
- // check if card is already used by another set
- if ( ( j < 5 ? sd->bonus.setitem_hash : sd->bonus.setitem_hash2 ) & hash)
- continue;
- // We have found a match
- flag = 1;
- // Set hash so this card cannot be used by another
- if (j<5)
- sd->bonus.setitem_hash |= hash;
- else
- sd->bonus.setitem_hash2 |= hash;
- break;
- }
- }
- if (flag) break; //Card found
- }
- if (ret == -1)
- ret = flag;
- else
- ret &= flag;
- if (!ret) break;
- }
- if (!ret) {//When check fails, restore original hash values. [Skotlex]
- sd->bonus.setitem_hash = setitem_hash;
- sd->bonus.setitem_hash2 = setitem_hash2;
- }
- script_pushint(st,ret);
- return SCRIPT_CMD_SUCCESS;
- }
- /*================================================
- * Check how many given inserted cards in the CURRENT
- * weapon - used for 2/15's cards patch [Lupus]
- *------------------------------------------------*/
- BUILDIN_FUNC(cardscnt)
- {
- TBL_PC *sd;
- int i, k, id = 1;
- int ret = 0;
- int index;
- sd = script_rid2sd(st);
- for (i=0; id!=0; i++) {
- FETCH (i+2, id) else id = 0;
- if (id <= 0)
- continue;
- index = current_equip_item_index; //we get CURRENT WEAPON inventory index from status.c [Lupus]
- if(index < 0) continue;
- if(!sd->inventory_data[index])
- continue;
- if(itemdb_type(id) != IT_CARD) {
- if (sd->inventory_data[index]->nameid == id)
- ret+= sd->status.inventory[index].amount;
- } else {
- if (itemdb_isspecial(sd->status.inventory[index].card[0]))
- continue;
- for(k=0; k<sd->inventory_data[index]->slot; k++) {
- if (sd->status.inventory[index].card[k] == id)
- ret++;
- }
- }
- }
- script_pushint(st,ret);
- // script_pushint(st,current_equip_item_index);
- return SCRIPT_CMD_SUCCESS;
- }
- /*=======================================================
- * Returns the refined number of the current item, or an
- * item with inventory index specified
- *-------------------------------------------------------*/
- BUILDIN_FUNC(getrefine)
- {
- TBL_PC *sd;
- if ((sd = script_rid2sd(st))!= NULL)
- script_pushint(st,sd->status.inventory[current_equip_item_index].refine);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /*=======================================================
- * Day/Night controls
- *-------------------------------------------------------*/
- BUILDIN_FUNC(night)
- {
- if (night_flag != 1) map_night_timer(night_timer_tid, 0, 0, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(day)
- {
- if (night_flag != 0) map_day_timer(day_timer_tid, 0, 0, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // Unequip [Spectre]
- //-------------------------------------------------------
- BUILDIN_FUNC(unequip)
- {
- int i;
- size_t num;
- TBL_PC *sd;
- num = script_getnum(st,2);
- sd = script_rid2sd(st);
- if( sd != NULL && num >= 1 && num <= ARRAYLENGTH(equip) )
- {
- i = pc_checkequip(sd,equip[num-1]);
- if (i >= 0)
- pc_unequipitem(sd,i,1|2);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(equip)
- {
- int nameid=0,i;
- TBL_PC *sd;
- struct item_data *item_data;
- sd = script_rid2sd(st);
- nameid=script_getnum(st,2);
- if((item_data = itemdb_exists(nameid)) == NULL)
- {
- ShowError("wrong item ID : equipitem(%i)\n",nameid);
- return 1;
- }
- ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid );
- if( i < MAX_INVENTORY )
- pc_equipitem(sd,i,item_data->equip);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(autoequip)
- {
- int nameid, flag;
- struct item_data *item_data;
- nameid=script_getnum(st,2);
- flag=script_getnum(st,3);
- if( ( item_data = itemdb_exists(nameid) ) == NULL )
- {
- ShowError("buildin_autoequip: Invalid item '%d'.\n", nameid);
- return SCRIPT_CMD_FAILURE;
- }
- if( !itemdb_isequip2(item_data) )
- {
- ShowError("buildin_autoequip: Item '%d' cannot be equipped.\n", nameid);
- return SCRIPT_CMD_FAILURE;
- }
- item_data->flag.autoequip = flag>0?1:0;
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(setbattleflag)
- {
- const char *flag, *value;
- flag = script_getstr(st,2);
- value = script_getstr(st,3); // HACK: Retrieve number as string (auto-converted) for battle_set_value
- if (battle_set_value(flag, value) == 0)
- ShowWarning("buildin_setbattleflag: unknown battle_config flag '%s'\n",flag);
- else
- ShowInfo("buildin_setbattleflag: battle_config flag '%s' is now set to '%s'.\n",flag,value);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getbattleflag)
- {
- const char *flag;
- flag = script_getstr(st,2);
- script_pushint(st,battle_get_value(flag));
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // strlen [Valaris]
- //-------------------------------------------------------
- BUILDIN_FUNC(getstrlen)
- {
- const char *str = script_getstr(st,2);
- int len = (str) ? (int)strlen(str) : 0;
- script_pushint(st,len);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // isalpha [Valaris]
- //-------------------------------------------------------
- BUILDIN_FUNC(charisalpha)
- {
- const char *str=script_getstr(st,2);
- int pos=script_getnum(st,3);
- int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISALPHA( str[pos] ) != 0 : 0;
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // charisupper <str>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(charisupper)
- {
- const char *str = script_getstr(st,2);
- int pos = script_getnum(st,3);
- int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISUPPER( str[pos] ) : 0;
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // charislower <str>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(charislower)
- {
- const char *str = script_getstr(st,2);
- int pos = script_getnum(st,3);
- int val = ( str && pos >= 0 && (unsigned int)pos < strlen(str) ) ? ISLOWER( str[pos] ) : 0;
- script_pushint(st,val);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // charat <str>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(charat) {
- const char *str = script_getstr(st,2);
- int pos = script_getnum(st,3);
- if( pos >= 0 && (unsigned int)pos < strlen(str) ) {
- char output[2];
- output[0] = str[pos];
- output[1] = '\0';
- script_pushstrcopy(st, output);
- } else
- script_pushconststr(st, "");
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // setchar <string>, <char>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(setchar)
- {
- const char *str = script_getstr(st,2);
- const char *c = script_getstr(st,3);
- int index = script_getnum(st,4);
- char *output = aStrdup(str);
- if(index >= 0 && index < strlen(output))
- output[index] = *c;
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // insertchar <string>, <char>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(insertchar)
- {
- const char *str = script_getstr(st,2);
- const char *c = script_getstr(st,3);
- int index = script_getnum(st,4);
- char *output;
- size_t len = strlen(str);
- if(index < 0)
- index = 0;
- else if(index > len)
- index = len;
- output = (char*)aMalloc(len + 2);
- memcpy(output, str, index);
- output[index] = c[0];
- memcpy(&output[index+1], &str[index], len - index);
- output[len+1] = '\0';
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // delchar <string>, <index>
- //-------------------------------------------------------
- BUILDIN_FUNC(delchar)
- {
- const char *str = script_getstr(st,2);
- int index = script_getnum(st,3);
- char *output;
- size_t len = strlen(str);
- if(index < 0 || index > len) {
- //return original
- output = aStrdup(str);
- script_pushstr(st, output);
- return 0;
- }
- output = (char*)aMalloc(len);
- memcpy(output, str, index);
- memcpy(&output[index], &str[index+1], len - index);
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // strtoupper <str>
- //-------------------------------------------------------
- BUILDIN_FUNC(strtoupper)
- {
- const char *str = script_getstr(st,2);
- char *output = aStrdup(str);
- char *cursor = output;
- while (*cursor != '\0') {
- *cursor = TOUPPER(*cursor);
- cursor++;
- }
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // strtolower <str>
- //-------------------------------------------------------
- BUILDIN_FUNC(strtolower)
- {
- const char *str = script_getstr(st,2);
- char *output = aStrdup(str);
- char *cursor = output;
- while (*cursor != '\0') {
- *cursor = TOLOWER(*cursor);
- cursor++;
- }
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // substr <str>, <start>, <end>
- //-------------------------------------------------------
- BUILDIN_FUNC(substr)
- {
- const char *str = script_getstr(st,2);
- char *output;
- int start = script_getnum(st,3);
- int end = script_getnum(st,4);
- int len = 0;
- if(start >= 0 && end < strlen(str) && start <= end) {
- len = end - start + 1;
- output = (char*)aMalloc(len + 1);
- memcpy(output, &str[start], len);
- } else
- output = (char*)aMalloc(1);
- output[len] = '\0';
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // explode <dest_string_array>, <str>, <delimiter>
- // Note: delimiter is limited to 1 char
- //-------------------------------------------------------
- BUILDIN_FUNC(explode)
- {
- struct script_data* data = script_getdata(st, 2);
- const char *str = script_getstr(st,3);
- const char delimiter = script_getstr(st, 4)[0];
- int32 id;
- size_t len = strlen(str);
- int i = 0, j = 0;
- int start;
- char *temp;
- const char* name;
- TBL_PC* sd = NULL;
- temp = (char*)aMalloc(len + 1);
- if( !data_isreference(data) )
- {
- ShowError("script:explode: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:explode: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( !is_string_variable(name) )
- {
- ShowError("script:explode: not string array\n");
- script_reportdata(data);
- st->state = END;
- return 1;// data type mismatch
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- while(str[i] != '\0') {
- if(str[i] == delimiter && start < SCRIPT_MAX_ARRAYSIZE-1) { //break at delimiter but ignore after reaching last array index
- temp[j] = '\0';
- set_reg(st, sd, reference_uid(id, start++), name, (void*)temp, reference_getref(data));
- j = 0;
- ++i;
- } else {
- temp[j++] = str[i++];
- }
- }
- //set last string
- temp[j] = '\0';
- set_reg(st, sd, reference_uid(id, start), name, (void*)temp, reference_getref(data));
- aFree(temp);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // implode <string_array>
- // implode <string_array>, <glue>
- //-------------------------------------------------------
- BUILDIN_FUNC(implode)
- {
- struct script_data* data = script_getdata(st, 2);
- const char *glue = NULL, *name, *temp;
- int32 glue_len = 0, array_size, id;
- size_t len = 0;
- int i, k = 0;
- TBL_PC* sd = NULL;
- char *output;
- if( !data_isreference(data) )
- {
- ShowError("script:implode: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:implode: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( !is_string_variable(name) )
- {
- ShowError("script:implode: not string array\n");
- script_reportdata(data);
- st->state = END;
- return 1;// data type mismatch
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- //count chars
- array_size = getarraysize(st, id, reference_getindex(data), is_string_variable(name), reference_getref(data)) - 1;
- if(array_size == -1) //empty array check (AmsTaff)
- {
- ShowWarning("script:implode: array length = 0\n");
- output = (char*)aMalloc(sizeof(char)*5);
- sprintf(output,"%s","NULL");
- } else {
- for(i = 0; i <= array_size; ++i) {
- temp = (char*) get_val2(st, reference_uid(id, i), reference_getref(data));
- len += strlen(temp);
- script_removetop(st, -1, 0);
- }
- //allocate mem
- if( script_hasdata(st,3) ) {
- glue = script_getstr(st,3);
- glue_len = strlen(glue);
- len += glue_len * (array_size);
- }
- output = (char*)aMalloc(len + 1);
- //build output
- for(i = 0; i < array_size; ++i) {
- temp = (char*) get_val2(st, reference_uid(id, i), reference_getref(data));
- len = strlen(temp);
- memcpy(&output[k], temp, len);
- k += len;
- if(glue_len != 0) {
- memcpy(&output[k], glue, glue_len);
- k += glue_len;
- }
- script_removetop(st, -1, 0);
- }
- temp = (char*) get_val2(st, reference_uid(id, array_size), reference_getref(data));
- len = strlen(temp);
- memcpy(&output[k], temp, len);
- k += len;
- script_removetop(st, -1, 0);
- output[k] = '\0';
- }
- script_pushstr(st, output);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // sprintf(<format>, ...);
- // Implements C sprintf, except format %n. The resulting string is
- // returned, instead of being saved in variable by reference.
- //-------------------------------------------------------
- BUILDIN_FUNC(sprintf)
- {
- unsigned int len, argc = 0, arg = 0, buf2_len = 0;
- const char* format;
- char* p;
- char* q;
- char* buf = NULL;
- char* buf2 = NULL;
- struct script_data* data;
- StringBuf final_buf;
- // Fetch init data
- format = script_getstr(st, 2);
- argc = script_lastdata(st)-2;
- len = strlen(format);
- // Skip parsing, where no parsing is required.
- if(len==0){
- script_pushconststr(st,"");
- return 0;
- }
- // Pessimistic alloc
- CREATE(buf, char, len+1);
- // Need not be parsed, just solve stuff like %%.
- if(argc==0){
- memcpy(buf,format,len+1);
- script_pushstrcopy(st, buf);
- aFree(buf);
- return 0;
- }
- safestrncpy(buf, format, len+1);
- // Issue sprintf for each parameter
- StringBuf_Init(&final_buf);
- q = buf;
- while((p = strchr(q, '%'))!=NULL){
- if(p!=q){
- len = p-q+1;
- if(buf2_len<len){
- RECREATE(buf2, char, len);
- buf2_len = len;
- }
- safestrncpy(buf2, q, len);
- StringBuf_AppendStr(&final_buf, buf2);
- q = p;
- }
- p = q+1;
- if(*p=='%'){ // %%
- StringBuf_AppendStr(&final_buf, "%");
- q+=2;
- continue;
- }
- if(*p=='n'){ // %n
- ShowWarning("buildin_sprintf: Format %%n not supported! Skipping...\n");
- script_reportsrc(st);
- q+=2;
- continue;
- }
- if(arg>=argc){
- ShowError("buildin_sprintf: Not enough arguments passed!\n");
- if(buf) aFree(buf);
- if(buf2) aFree(buf2);
- StringBuf_Destroy(&final_buf);
- script_pushconststr(st,"");
- return 1;
- }
- if((p = strchr(q+1, '%'))==NULL){
- p = strchr(q, 0); // EOS
- }
- len = p-q+1;
- if(buf2_len<len){
- RECREATE(buf2, char, len);
- buf2_len = len;
- }
- safestrncpy(buf2, q, len);
- q = p;
- // Note: This assumes the passed value being the correct
- // type to the current format specifier. If not, the server
- // probably crashes or returns anything else, than expected,
- // but it would behave in normal code the same way so it's
- // the scripter's responsibility.
- data = script_getdata(st, arg+3);
- if(data_isstring(data)){ // String
- StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3));
- }else if(data_isint(data)){ // Number
- StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3));
- }else if(data_isreference(data)){ // Variable
- char* name = reference_getname(data);
- if(name[strlen(name)-1]=='$'){ // var Str
- StringBuf_Printf(&final_buf, buf2, script_getstr(st, arg+3));
- }else{ // var Int
- StringBuf_Printf(&final_buf, buf2, script_getnum(st, arg+3));
- }
- }else{ // Unsupported type
- ShowError("buildin_sprintf: Unknown argument type!\n");
- if(buf) aFree(buf);
- if(buf2) aFree(buf2);
- StringBuf_Destroy(&final_buf);
- script_pushconststr(st,"");
- return 1;
- }
- arg++;
- }
- // Append anything left
- if(*q){
- StringBuf_AppendStr(&final_buf, q);
- }
- // Passed more, than needed
- if(arg<argc){
- ShowWarning("buildin_sprintf: Unused arguments passed.\n");
- script_reportsrc(st);
- }
- script_pushstrcopy(st, StringBuf_Value(&final_buf));
- if(buf) aFree(buf);
- if(buf2) aFree(buf2);
- StringBuf_Destroy(&final_buf);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // sscanf(<str>, <format>, ...);
- // Implements C sscanf.
- //-------------------------------------------------------
- BUILDIN_FUNC(sscanf){
- unsigned int argc, arg = 0, len;
- struct script_data* data;
- struct map_session_data* sd = NULL;
- const char* str;
- const char* format;
- const char* p;
- const char* q;
- char* buf = NULL;
- char* buf_p;
- char* ref_str = NULL;
- int ref_int;
- // Get data
- str = script_getstr(st, 2);
- format = script_getstr(st, 3);
- argc = script_lastdata(st)-3;
- len = strlen(format);
- CREATE(buf, char, len*2+1);
- // Issue sscanf for each parameter
- *buf = 0;
- q = format;
- while((p = strchr(q, '%'))){
- if(p!=q){
- strncat(buf, q, (size_t)(p-q));
- q = p;
- }
- p = q+1;
- if(*p=='*' || *p=='%'){ // Skip
- strncat(buf, q, 2);
- q+=2;
- continue;
- }
- if(arg>=argc){
- ShowError("buildin_sscanf: Not enough arguments passed!\n");
- script_pushint(st, -1);
- if(buf) aFree(buf);
- if(ref_str) aFree(ref_str);
- return 1;
- }
- if((p = strchr(q+1, '%'))==NULL){
- p = strchr(q, 0); // EOS
- }
- len = p-q;
- strncat(buf, q, len);
- q = p;
- // Validate output
- data = script_getdata(st, arg+4);
- if(!data_isreference(data) || !reference_tovariable(data)){
- ShowError("buildin_sscanf: Target argument is not a variable!\n");
- script_pushint(st, -1);
- if(buf) aFree(buf);
- if(ref_str) aFree(ref_str);
- return 1;
- }
- buf_p = reference_getname(data);
- if(not_server_variable(*buf_p) && (sd = script_rid2sd(st))==NULL){
- script_pushint(st, -1);
- if(buf) aFree(buf);
- if(ref_str) aFree(ref_str);
- return 0;
- }
- // Save value if any
- if(buf_p[strlen(buf_p)-1]=='$'){ // String
- if(ref_str==NULL){
- CREATE(ref_str, char, strlen(str)+1);
- }
- if(sscanf(str, buf, ref_str)==0){
- break;
- }
- set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data));
- } else { // Number
- if(sscanf(str, buf, &ref_int)==0){
- break;
- }
- set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)__64BPRTSIZE(ref_int), reference_getref(data));
- }
- arg++;
- // Disable used format (%... -> %*...)
- buf_p = strchr(buf, 0);
- memmove(buf_p-len+2, buf_p-len+1, len);
- *(buf_p-len+1) = '*';
- }
- script_pushint(st, arg);
- if(buf) aFree(buf);
- if(ref_str) aFree(ref_str);
- return SCRIPT_CMD_SUCCESS;
- }
- //=======================================================
- // strpos(<haystack>, <needle>)
- // strpos(<haystack>, <needle>, <offset>)
- //
- // Implements PHP style strpos. Adapted from code from
- // http://www.daniweb.com/code/snippet313.html, Dave Sinkula
- //-------------------------------------------------------
- BUILDIN_FUNC(strpos) {
- const char *haystack = script_getstr(st,2);
- const char *needle = script_getstr(st,3);
- int i;
- size_t len;
- if( script_hasdata(st,4) )
- i = script_getnum(st,4);
- else
- i = 0;
- if (needle[0] == '\0') {
- script_pushint(st, -1);
- return 0;
- }
- len = strlen(haystack);
- for ( ; i < len; ++i ) {
- if ( haystack[i] == *needle ) {
- // matched starting char -- loop through remaining chars
- const char *h, *n;
- for ( h = &haystack[i], n = needle; *h && *n; ++h, ++n ) {
- if ( *h != *n ) {
- break;
- }
- }
- if ( !*n ) { // matched all of 'needle' to null termination
- script_pushint(st, i);
- return 0;
- }
- }
- }
- script_pushint(st, -1);
- return SCRIPT_CMD_SUCCESS;
- }
- //===============================================================
- // replacestr <input>, <search>, <replace>{, <usecase>{, <count>}}
- //
- // Note: Finds all instances of <search> in <input> and replaces
- // with <replace>. If specified will only replace as many
- // instances as specified in <count>. By default will be case
- // sensitive.
- //---------------------------------------------------------------
- BUILDIN_FUNC(replacestr)
- {
- const char *input = script_getstr(st, 2);
- const char *find = script_getstr(st, 3);
- const char *replace = script_getstr(st, 4);
- size_t inputlen = strlen(input);
- size_t findlen = strlen(find);
- struct StringBuf output;
- bool usecase = true;
- int count = 0;
- int numFinds = 0;
- int i = 0, f = 0;
- if(findlen == 0) {
- ShowError("script:replacestr: Invalid search length.\n");
- st->state = END;
- return 1;
- }
- if(script_hasdata(st, 5)) {
- struct script_data *data = script_getdata(st, 5);
- get_val(st, data); // Convert into value in case of a variable
- if( !data_isstring(data) )
- usecase = script_getnum(st, 5) != 0;
- else {
- ShowError("script:replacestr: Invalid usecase value. Expected int got string\n");
- st->state = END;
- return 1;
- }
- }
- if(script_hasdata(st, 6)) {
- count = script_getnum(st, 6);
- if(count == 0) {
- ShowError("script:replacestr: Invalid count value. Expected int got string\n");
- st->state = END;
- return 1;
- }
- }
- StringBuf_Init(&output);
- for(; i < inputlen; i++) {
- if(count && count == numFinds) { //found enough, stop looking
- break;
- }
- for(f = 0; f <= findlen; f++) {
- if(f == findlen) { //complete match
- numFinds++;
- StringBuf_AppendStr(&output, replace);
- i += findlen - 1;
- break;
- } else {
- if(usecase) {
- if((i + f) > inputlen || input[i + f] != find[f]) {
- StringBuf_Printf(&output, "%c", input[i]);
- break;
- }
- } else {
- if(((i + f) > inputlen || input[i + f] != find[f]) && TOUPPER(input[i+f]) != TOUPPER(find[f])) {
- StringBuf_Printf(&output, "%c", input[i]);
- break;
- }
- }
- }
- }
- }
- //append excess after enough found
- if(i < inputlen)
- StringBuf_AppendStr(&output, &(input[i]));
- script_pushstrcopy(st, StringBuf_Value(&output));
- StringBuf_Destroy(&output);
- return SCRIPT_CMD_SUCCESS;
- }
- //========================================================
- // countstr <input>, <search>{, <usecase>}
- //
- // Note: Counts the number of times <search> occurs in
- // <input>. By default will be case sensitive.
- //--------------------------------------------------------
- BUILDIN_FUNC(countstr)
- {
- const char *input = script_getstr(st, 2);
- const char *find = script_getstr(st, 3);
- size_t inputlen = strlen(input);
- size_t findlen = strlen(find);
- bool usecase = true;
- int numFinds = 0;
- int i = 0, f = 0;
- if(findlen == 0) {
- ShowError("script:countstr: Invalid search length.\n");
- st->state = END;
- return 1;
- }
- if(script_hasdata(st, 4)) {
- struct script_data *data;
- data = script_getdata(st, 4);
- get_val(st, data); // Convert into value in case of a variable
- if( !data_isstring(data) )
- usecase = script_getnum(st, 4) != 0;
- else {
- ShowError("script:countstr: Invalid usecase value. Expected int got string\n");
- st->state = END;
- return 1;
- }
- }
- for(; i < inputlen; i++) {
- for(f = 0; f <= findlen; f++) {
- if(f == findlen) { //complete match
- numFinds++;
- i += findlen - 1;
- break;
- } else {
- if(usecase) {
- if((i + f) > inputlen || input[i + f] != find[f]) {
- break;
- }
- } else {
- if(((i + f) > inputlen || input[i + f] != find[f]) && TOUPPER(input[i+f]) != TOUPPER(find[f])) {
- break;
- }
- }
- }
- }
- }
- script_pushint(st, numFinds);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Changes the display name and/or display class of the npc.
- /// Returns 0 is successful, 1 if the npc does not exist.
- ///
- /// setnpcdisplay("<npc name>", "<new display name>", <new class id>, <new size>) -> <int>
- /// setnpcdisplay("<npc name>", "<new display name>", <new class id>) -> <int>
- /// setnpcdisplay("<npc name>", "<new display name>") -> <int>
- /// setnpcdisplay("<npc name>", <new class id>) -> <int>
- BUILDIN_FUNC(setnpcdisplay)
- {
- const char* name;
- const char* newname = NULL;
- int class_ = -1, size = -1;
- struct script_data* data;
- struct npc_data* nd;
- name = script_getstr(st,2);
- data = script_getdata(st,3);
- if( script_hasdata(st,4) )
- class_ = script_getnum(st,4);
- if( script_hasdata(st,5) )
- size = script_getnum(st,5);
- get_val(st, data);
- if( data_isstring(data) )
- newname = conv_str(st,data);
- else if( data_isint(data) )
- class_ = conv_num(st,data);
- else
- {
- ShowError("script:setnpcdisplay: expected string or number\n");
- script_reportdata(data);
- return 1;
- }
- nd = npc_name2id(name);
- if( nd == NULL )
- {// not found
- script_pushint(st,1);
- return 0;
- }
- // update npc
- if( newname )
- npc_setdisplayname(nd, newname);
- if( size != -1 && size != (int)nd->size )
- nd->size = size;
- else
- size = -1;
- if( class_ != -1 && nd->class_ != class_ )
- npc_setclass(nd, class_);
- else if( size != -1 )
- { // Required to update the visual size
- clif_clearunit_area(&nd->bl, CLR_OUTSIGHT);
- clif_spawn(&nd->bl);
- }
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(atoi)
- {
- const char *value;
- value = script_getstr(st,2);
- script_pushint(st,atoi(value));
- return SCRIPT_CMD_SUCCESS;
- }
- // case-insensitive substring search [lordalfa]
- BUILDIN_FUNC(compare)
- {
- const char *message;
- const char *cmpstring;
- message = script_getstr(st,2);
- cmpstring = script_getstr(st,3);
- script_pushint(st,(stristr(message,cmpstring) != NULL));
- return SCRIPT_CMD_SUCCESS;
- }
- // [zBuffer] List of mathematics commands --->
- BUILDIN_FUNC(sqrt)
- {
- double i, a;
- i = script_getnum(st,2);
- a = sqrt(i);
- script_pushint(st,(int)a);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pow)
- {
- double i, a, b;
- a = script_getnum(st,2);
- b = script_getnum(st,3);
- i = pow(a,b);
- script_pushint(st,(int)i);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(distance)
- {
- int x0, y0, x1, y1;
- x0 = script_getnum(st,2);
- y0 = script_getnum(st,3);
- x1 = script_getnum(st,4);
- y1 = script_getnum(st,5);
- script_pushint(st,distance_xy(x0,y0,x1,y1));
- return SCRIPT_CMD_SUCCESS;
- }
- // <--- [zBuffer] List of mathematics commands
- BUILDIN_FUNC(md5)
- {
- const char *tmpstr;
- char *md5str;
- tmpstr = script_getstr(st,2);
- md5str = (char *)aMalloc((32+1)*sizeof(char));
- MD5_String(tmpstr, md5str);
- script_pushstr(st, md5str);
- return SCRIPT_CMD_SUCCESS;
- }
- // [zBuffer] List of dynamic var commands --->
- BUILDIN_FUNC(setd)
- {
- TBL_PC *sd=NULL;
- char varname[100];
- const char *buffer;
- int elem;
- buffer = script_getstr(st, 2);
- if(sscanf(buffer, "%99[^[][%d]", varname, &elem) < 2)
- elem = 0;
- if( not_server_variable(*varname) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- {
- ShowError("script:setd: no player attached for player variable '%s'\n", buffer);
- return 0;
- }
- }
- if( is_string_variable(varname) ) {
- setd_sub(st, sd, varname, elem, (void *)script_getstr(st, 3), NULL);
- } else {
- setd_sub(st, sd, varname, elem, (void *)__64BPRTSIZE(script_getnum(st, 3)), NULL);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- int buildin_query_sql_sub(struct script_state* st, Sql* handle)
- {
- int i, j;
- TBL_PC* sd = NULL;
- const char* query;
- struct script_data* data;
- const char* name;
- int max_rows = SCRIPT_MAX_ARRAYSIZE; // maximum number of rows
- int num_vars;
- int num_cols;
- // check target variables
- for( i = 3; script_hasdata(st,i); ++i ) {
- data = script_getdata(st, i);
- if( data_isreference(data) ) { // it's a variable
- name = reference_getname(data);
- if( not_server_variable(*name) && sd == NULL ) { // requires a player
- sd = script_rid2sd(st);
- if( sd == NULL ) { // no player attached
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- }
- if( not_array_variable(*name) )
- max_rows = 1;// not an array, limit to one row
- } else {
- ShowError("script:query_sql: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;
- }
- }
- num_vars = i - 3;
- // Execute the query
- query = script_getstr(st,2);
- if( SQL_ERROR == Sql_QueryStr(handle, query) ) {
- Sql_ShowDebug(handle);
- script_pushint(st, 0);
- return 1;
- }
- if( Sql_NumRows(handle) == 0 ) { // No data received
- Sql_FreeResult(handle);
- script_pushint(st, 0);
- return 0;
- }
- // Count the number of columns to store
- num_cols = Sql_NumColumns(handle);
- if( num_vars < num_cols ) {
- ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars));
- script_reportsrc(st);
- } else if( num_vars > num_cols ) {
- ShowWarning("script:query_sql: Too many variables (%u extra).\n", (unsigned int)(num_vars-num_cols));
- script_reportsrc(st);
- }
- // Store data
- for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i ) {
- for( j = 0; j < num_vars; ++j ) {
- char* str = NULL;
- if( j < num_cols )
- Sql_GetData(handle, j, &str, NULL);
- data = script_getdata(st, j+3);
- name = reference_getname(data);
- if( is_string_variable(name) )
- setd_sub(st, sd, name, i, (void *)(str?str:""), reference_getref(data));
- else
- setd_sub(st, sd, name, i, (void *)__64BPRTSIZE((str?atoi(str):0)), reference_getref(data));
- }
- }
- if( i == max_rows && max_rows < Sql_NumRows(handle) ) {
- ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle));
- script_reportsrc(st);
- }
- // Free data
- Sql_FreeResult(handle);
- script_pushint(st, i);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(query_sql) {
- #ifdef BETA_THREAD_TEST
- if( st->state != RERUNLINE ) {
- queryThread_add(st,false);
- st->state = RERUNLINE;/* will continue when the query is finished running. */
- } else
- st->state = RUN;
- return 0;
- #else
- return buildin_query_sql_sub(st, mmysql_handle);
- #endif
- }
- BUILDIN_FUNC(query_logsql) {
- if( !log_config.sql_logs ) {// logmysql_handle == NULL
- ShowWarning("buildin_query_logsql: SQL logs are disabled, query '%s' will not be executed.\n", script_getstr(st,2));
- script_pushint(st,-1);
- return 1;
- }
- #ifdef BETA_THREAD_TEST
- if( st->state != RERUNLINE ) {
- queryThread_add(st,true);
- st->state = RERUNLINE;/* will continue when the query is finished running. */
- } else
- st->state = RUN;
- return 0;
- #else
- return buildin_query_sql_sub(st, logmysql_handle);
- #endif
- }
- //Allows escaping of a given string.
- BUILDIN_FUNC(escape_sql)
- {
- const char *str;
- char *esc_str;
- size_t len;
- str = script_getstr(st,2);
- len = strlen(str);
- esc_str = (char*)aMalloc(len*2+1);
- Sql_EscapeStringLen(mmysql_handle, esc_str, str, len);
- script_pushstr(st, esc_str);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(getd)
- {
- char varname[100];
- const char *buffer;
- int elem;
- buffer = script_getstr(st, 2);
- if(sscanf(buffer, "%[^[][%d]", varname, &elem) < 2)
- elem = 0;
- // Push the 'pointer' so it's more flexible [Lance]
- push_val(st->stack, C_NAME, reference_uid(add_str(varname), elem));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(callshop)
- {
- TBL_PC *sd = NULL;
- struct npc_data *nd;
- const char *shopname;
- int flag = 0;
- sd = script_rid2sd(st);
- if (!sd) {
- script_pushint(st,0);
- return 0;
- }
- shopname = script_getstr(st, 2);
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- nd = npc_name2id(shopname);
- if( !nd || nd->bl.type != BL_NPC || (nd->subtype != SHOP && nd->subtype != CASHSHOP && nd->subtype != ITEMSHOP && nd->subtype != POINTSHOP) )
- {
- ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)\n", shopname);
- script_pushint(st,0);
- return 1;
- }
- if( nd->subtype == SHOP || nd->subtype == ITEMSHOP || nd->subtype == POINTSHOP )
- {
- // flag the user as using a valid script call for opening the shop (for floating NPCs)
- sd->state.callshop = 1;
- switch( flag )
- {
- case 1: npc_buysellsel(sd,nd->bl.id,0); break; //Buy window
- case 2: npc_buysellsel(sd,nd->bl.id,1); break; //Sell window
- default: clif_npcbuysell(sd,nd->bl.id); break; //Show menu
- }
- }
- else
- clif_cashshop_show(sd, nd);
- sd->npc_shopid = nd->bl.id;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(npcshopitem)
- {
- const char* npcname = script_getstr(st, 2);
- struct npc_data* nd = npc_name2id(npcname);
- int n, i;
- int amount;
- if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP && nd->subtype != ITEMSHOP && nd->subtype != POINTSHOP ) )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- // get the count of new entries
- amount = (script_lastdata(st)-2)/2;
- // generate new shop item list
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, amount);
- for( n = 0, i = 3; n < amount; n++, i+=2 )
- {
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
- nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
- }
- nd->u.shop.count = n;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(npcshopadditem)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- int n, i;
- int amount;
- if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP && nd->subtype != ITEMSHOP && nd->subtype != POINTSHOP ) )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- // get the count of new entries
- amount = (script_lastdata(st)-2)/2;
- // append new items to existing shop item list
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, nd->u.shop.count+amount);
- for( n = nd->u.shop.count, i = 3; n < nd->u.shop.count+amount; n++, i+=2 )
- {
- nd->u.shop.shop_item[n].nameid = script_getnum(st,i);
- nd->u.shop.shop_item[n].value = script_getnum(st,i+1);
- }
- nd->u.shop.count = n;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(npcshopdelitem)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- unsigned int nameid;
- int n, i;
- int amount;
- int size;
- if( !nd || ( nd->subtype != SHOP && nd->subtype != CASHSHOP && nd->subtype != ITEMSHOP && nd->subtype != POINTSHOP ) )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- amount = script_lastdata(st)-2;
- size = nd->u.shop.count;
- // remove specified items from the shop item list
- for( i = 3; i < 3 + amount; i++ )
- {
- nameid = script_getnum(st,i);
- ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == nameid );
- if( n < size )
- {
- memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n));
- size--;
- }
- }
- RECREATE(nd->u.shop.shop_item, struct npc_item_list, size);
- nd->u.shop.count = size;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- //Sets a script to attach to a shop npc.
- BUILDIN_FUNC(npcshopattach)
- {
- const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
- int flag = 1;
- if( script_hasdata(st,3) )
- flag = script_getnum(st,3);
- if( !nd || nd->subtype != SHOP )
- { //Not found.
- script_pushint(st,0);
- return 0;
- }
- if (flag)
- nd->master_nd = ((struct npc_data *)map_id2bl(st->oid));
- else
- nd->master_nd = NULL;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns some values of an item [Lupus]
- * Price, Weight, etc...
- setitemscript(itemID,"{new item bonus script}",[n]);
- Where n:
- 0 - script
- 1 - Equip script
- 2 - Unequip script
- *------------------------------------------*/
- BUILDIN_FUNC(setitemscript)
- {
- int item_id,n=0;
- const char *script;
- struct item_data *i_data;
- struct script_code **dstscript;
- item_id = script_getnum(st,2);
- script = script_getstr(st,3);
- if( script_hasdata(st,4) )
- n=script_getnum(st,4);
- i_data = itemdb_exists(item_id);
- if (!i_data || script==NULL || ( script[0] && script[0]!='{' )) {
- script_pushint(st,0);
- return 0;
- }
- switch (n) {
- case 2:
- dstscript = &i_data->unequip_script;
- break;
- case 1:
- dstscript = &i_data->equip_script;
- break;
- default:
- dstscript = &i_data->script;
- break;
- }
- if(*dstscript)
- script_free_code(*dstscript);
- *dstscript = script[0] ? parse_script(script, "script_setitemscript", 0, 0) : NULL;
- script_pushint(st,1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*=======================================================
- * Add or Update a mob drop temporarily [Akinari]
- * Original Idea By: [Lupus]
- *
- * addmonsterdrop <mob_id or name>,<item_id>,<rate>;
- *
- * If given an item the mob already drops, the rate
- * is updated to the new rate. Rate cannot exceed 10000
- * Returns 1 if succeeded (added/updated a mob drop)
- *-------------------------------------------------------*/
- BUILDIN_FUNC(addmonsterdrop)
- {
- struct mob_db *mob;
- struct script_data *data;
- int item_id,rate,i,c = 0;
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- if(data_isstring(data))
- mob = mob_db(mobdb_searchname(script_getstr(st,2)));
- else
- mob = mob_db(script_getnum(st,2));
- item_id=script_getnum(st,3);
- rate=script_getnum(st,4);
- if(!itemdb_exists(item_id)){
- ShowError("addmonsterdrop: Nonexistant item %d requested.\n", item_id );
- return 1;
- }
- if(mob) { //We got a valid monster, check for available drop slot
- for(i = 0; i < MAX_MOB_DROP; i++) {
- if(mob->dropitem[i].nameid) {
- if(mob->dropitem[i].nameid == item_id) { //If it equals item_id we update that drop
- c = i;
- break;
- }
- continue;
- }
- if(!c) //Accept first available slot only
- c = i;
- }
- if(c) { //Fill in the slot with the item and rate
- mob->dropitem[c].nameid = item_id;
- mob->dropitem[c].p = (rate > 10000)?10000:rate;
- script_pushint(st,1);
- } else //No place to put the new drop
- script_pushint(st,0);
- } else {
- ShowWarning("addmonsterdrop: bad mob id given %d\n",script_getnum(st,2));
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*=======================================================
- * Delete a mob drop temporarily [Akinari]
- * Original Idea By: [Lupus]
- *
- * delmonsterdrop <mob_id or name>,<item_id>;
- *
- * Returns 1 if succeeded (deleted a mob drop)
- *-------------------------------------------------------*/
- BUILDIN_FUNC(delmonsterdrop)
- {
- struct mob_db *mob;
- struct script_data *data;
- int item_id,i;
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- if(data_isstring(data))
- mob = mob_db(mobdb_searchname(script_getstr(st,2)));
- else
- mob = mob_db(script_getnum(st,2));
- item_id=script_getnum(st,3);
- if(!itemdb_exists(item_id)){
- ShowError("delmonsterdrop: Nonexistant item %d requested.\n", item_id );
- return 1;
- }
- if(mob) { //We got a valid monster, check for item drop on monster
- for(i = 0; i < MAX_MOB_DROP; i++) {
- if(mob->dropitem[i].nameid == item_id) {
- mob->dropitem[i].nameid = 0;
- mob->dropitem[i].p = 0;
- script_pushint(st,1);
- return 0;
- }
- }
- //No drop on that monster
- script_pushint(st,0);
- } else {
- ShowWarning("delmonsterdrop: bad mob id given %d\n",script_getnum(st,2));
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns some values of a monster [Lupus]
- * Name, Level, race, size, etc...
- getmonsterinfo(monsterID,queryIndex);
- *------------------------------------------*/
- BUILDIN_FUNC(getmonsterinfo)
- {
- struct mob_db *mob;
- int mob_id;
- mob_id = script_getnum(st,2);
- if (!mobdb_checkid(mob_id)) {
- //ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i\n", mob_id);
- if ( !script_getnum(st,3) ) //requested a string
- script_pushconststr(st,"null");
- else
- script_pushint(st,-1);
- return -1;
- }
- mob = mob_db(mob_id);
- switch ( script_getnum(st,3) ) {
- case 0: script_pushstrcopy(st,mob->jname); break;
- case 1: script_pushint(st,mob->lv); break;
- case 2: script_pushint(st,mob->status.max_hp); break;
- case 3: script_pushint(st,mob->base_exp); break;
- case 4: script_pushint(st,mob->job_exp); break;
- case 5: script_pushint(st,mob->status.rhw.atk); break;
- case 6: script_pushint(st,mob->status.rhw.atk2); break;
- case 7: script_pushint(st,mob->status.def); break;
- case 8: script_pushint(st,mob->status.mdef); break;
- case 9: script_pushint(st,mob->status.str); break;
- case 10: script_pushint(st,mob->status.agi); break;
- case 11: script_pushint(st,mob->status.vit); break;
- case 12: script_pushint(st,mob->status.int_); break;
- case 13: script_pushint(st,mob->status.dex); break;
- case 14: script_pushint(st,mob->status.luk); break;
- case 15: script_pushint(st,mob->status.rhw.range); break;
- case 16: script_pushint(st,mob->range2); break;
- case 17: script_pushint(st,mob->range3); break;
- case 18: script_pushint(st,mob->status.size); break;
- case 19: script_pushint(st,mob->status.race); break;
- case 20: script_pushint(st,mob->status.def_ele); break;
- case 21: script_pushint(st,mob->status.mode); break;
- case 22: script_pushint(st,mob->mexp); break;
- default: script_pushint(st,-1); //wrong Index
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(checkvending) // check vending [Nab4]
- {
- TBL_PC *sd = NULL;
- if(script_hasdata(st,2))
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if(sd)
- script_pushint(st, sd->state.autotrade ? 2 : sd->state.vending);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(checkchatting) // check chatting [Marka]
- {
- TBL_PC *sd = NULL;
- if(script_hasdata(st,2))
- sd = map_nick2sd(script_getstr(st,2));
- else
- sd = script_rid2sd(st);
- if(sd)
- script_pushint(st,(sd->chatID != 0));
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(checkidle)
- {
- TBL_PC *sd = NULL;
- if (script_hasdata(st, 2))
- sd = map_nick2sd(script_getstr(st, 2));
- else
- sd = script_rid2sd(st);
- if (sd)
- script_pushint(st, DIFF_TICK(last_tick, sd->idletime));
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(searchitem)
- {
- struct script_data* data = script_getdata(st, 2);
- const char *itemname = script_getstr(st,3);
- struct item_data *items[MAX_SEARCH];
- int count;
- char* name;
- int32 start;
- int32 id;
- int32 i;
- TBL_PC* sd = NULL;
- if ((items[0] = itemdb_exists(atoi(itemname))))
- count = 1;
- else {
- count = itemdb_searchname_array(items, ARRAYLENGTH(items), itemname);
- if (count > MAX_SEARCH) count = MAX_SEARCH;
- }
- if (!count) {
- script_pushint(st, 0);
- return 0;
- }
- if( !data_isreference(data) )
- {
- ShowError("script:searchitem: not a variable\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not a variable
- }
- id = reference_getid(data);
- start = reference_getindex(data);
- name = reference_getname(data);
- if( not_array_variable(*name) )
- {
- ShowError("script:searchitem: illegal scope\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- if( not_server_variable(*name) )
- {
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;// no player attached
- }
- if( is_string_variable(name) )
- {// string array
- ShowError("script:searchitem: not an integer array reference\n");
- script_reportdata(data);
- st->state = END;
- return 1;// not supported
- }
- for( i = 0; i < count; ++start, ++i )
- {// Set array
- void* v = (void*)__64BPRTSIZE((int)items[i]->nameid);
- set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
- }
- script_pushint(st, count);
- return SCRIPT_CMD_SUCCESS;
- }
- int axtoi(const char *hexStg)
- {
- int n = 0; // position in string
- int16 m = 0; // position in digit[] to shift
- int count; // loop index
- int intValue = 0; // integer value of hex string
- int digit[11]; // hold values to convert
- while (n < 10) {
- if (hexStg[n]=='\0')
- break;
- if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
- digit[n] = hexStg[n] & 0x0f; //convert to int
- else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
- digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
- else break;
- n++;
- }
- count = n;
- m = n - 1;
- n = 0;
- while(n < count) {
- // digit[n] is value of hex digit at position n
- // (m << 2) is the number of positions to shift
- // OR the bits into return value
- intValue = intValue | (digit[n] << (m << 2));
- m--; // adjust the position to set
- n++; // next digit to process
- }
- return (intValue);
- }
- // [Lance] Hex string to integer converter
- BUILDIN_FUNC(axtoi)
- {
- const char *hex = script_getstr(st,2);
- script_pushint(st,axtoi(hex));
- return SCRIPT_CMD_SUCCESS;
- }
- // [zBuffer] List of player cont commands --->
- BUILDIN_FUNC(rid2name)
- {
- struct block_list *bl = NULL;
- int rid = script_getnum(st,2);
- if((bl = map_id2bl(rid)))
- {
- switch(bl->type) {
- case BL_MOB: script_pushstrcopy(st,((TBL_MOB*)bl)->name); break;
- case BL_PC: script_pushstrcopy(st,((TBL_PC*)bl)->status.name); break;
- case BL_NPC: script_pushstrcopy(st,((TBL_NPC*)bl)->exname); break;
- case BL_PET: script_pushstrcopy(st,((TBL_PET*)bl)->pet.name); break;
- case BL_HOM: script_pushstrcopy(st,((TBL_HOM*)bl)->homunculus.name); break;
- case BL_MER: script_pushstrcopy(st,((TBL_MER*)bl)->db->name); break;
- default:
- ShowError("buildin_rid2name: BL type unknown.\n");
- script_pushconststr(st,"");
- break;
- }
- } else {
- ShowError("buildin_rid2name: invalid RID\n");
- script_pushconststr(st,"(null)");
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pcblockmove)
- {
- int id, flag;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- flag = script_getnum(st,3);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- sd->state.blockedmove = flag > 0;
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pcfollow)
- {
- int id, targetid;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- targetid = script_getnum(st,3);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- pc_follow(sd, targetid);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pcstopfollow)
- {
- int id;
- TBL_PC *sd = NULL;
- id = script_getnum(st,2);
- if(id)
- sd = map_id2sd(id);
- else
- sd = script_rid2sd(st);
- if(sd)
- pc_stop_following(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- // <--- [zBuffer] List of player cont commands
- // [zBuffer] List of mob control commands --->
- /// Makes the unit walk to target position or map
- /// Returns if it was successfull
- ///
- /// unitwalk(<unit_id>,<x>,<y>) -> <bool>
- /// unitwalk(<unit_id>,<target_id>) -> <bool>
- BUILDIN_FUNC(unitwalk)
- {
- struct block_list* bl;
- bl = map_id2bl(script_getnum(st,2));
- if( bl == NULL )
- script_pushint(st, 0);
- else if( script_hasdata(st,4) ) {
- int x = script_getnum(st,3);
- int y = script_getnum(st,4);
- if( script_pushint(st, unit_can_reach_pos(bl,x,y,0)) )
- add_timer(gettick()+50, unit_delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF)); // Need timer to avoid mismatches
- } else {
- struct block_list* tbl = map_id2bl(script_getnum(st,3));
- if( tbl == NULL ) {
- ShowError("script:unitwalk: bad target destination\n");
- script_pushint(st, 0);
- return 1;
- }
- else if (script_pushint(st, unit_can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, 0, NULL, NULL)))
- add_timer(gettick()+50, unit_delay_walktobl_timer, bl->id, tbl->id); // Need timer to avoid mismatches
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Kills the unit
- ///
- /// unitkill <unit_id>;
- BUILDIN_FUNC(unitkill)
- {
- struct block_list* bl = map_id2bl(script_getnum(st,2));
- if( bl != NULL )
- status_kill(bl);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Warps the unit to the target position in the target map
- /// Returns if it was successfull
- ///
- /// unitwarp(<unit_id>,"<map name>",<x>,<y>) -> <bool>
- BUILDIN_FUNC(unitwarp)
- {
- int unit_id;
- int map;
- short x;
- short y;
- struct block_list* bl;
- const char *mapname;
- unit_id = script_getnum(st,2);
- mapname = script_getstr(st, 3);
- x = (short)script_getnum(st,4);
- y = (short)script_getnum(st,5);
- if (!unit_id) //Warp the script's runner
- bl = map_id2bl(st->rid);
- else
- bl = map_id2bl(unit_id);
- if( strcmp(mapname,"this") == 0 )
- map = bl?bl->m:-1;
- else
- map = map_mapname2mapid(mapname);
- if( map >= 0 && bl != NULL )
- script_pushint(st, unit_warp(bl,map,x,y,CLR_OUTSIGHT));
- else
- script_pushint(st, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit attack the target.
- /// If the unit is a player and <action type> is not 0, it does a continuous
- /// attack instead of a single attack.
- /// Returns if the request was successful.
- ///
- /// unitattack(<unit_id>,"<target name>"{,<action type>}) -> <bool>
- /// unitattack(<unit_id>,<target_id>{,<action type>}) -> <bool>
- BUILDIN_FUNC(unitattack)
- {
- struct block_list* unit_bl;
- struct block_list* target_bl = NULL;
- struct script_data* data;
- int actiontype = 0;
- // get unit
- unit_bl = map_id2bl(script_getnum(st,2));
- if( unit_bl == NULL ) {
- script_pushint(st, 0);
- return 0;
- }
- data = script_getdata(st, 3);
- get_val(st, data);
- if( data_isstring(data) )
- {
- TBL_PC* sd = map_nick2sd(conv_str(st, data));
- if( sd != NULL )
- target_bl = &sd->bl;
- } else
- target_bl = map_id2bl(conv_num(st, data));
- // request the attack
- if( target_bl == NULL )
- {
- script_pushint(st, 0);
- return 0;
- }
- // get actiontype
- if( script_hasdata(st,4) )
- actiontype = script_getnum(st,4);
- switch( unit_bl->type )
- {
- case BL_PC:
- clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick());
- script_pushint(st, 1);
- return 0;
- case BL_MOB:
- ((TBL_MOB *)unit_bl)->target_id = target_bl->id;
- break;
- case BL_PET:
- ((TBL_PET *)unit_bl)->target_id = target_bl->id;
- break;
- default:
- ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
- script_pushint(st, 0);
- return 1;
- }
- script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit stop attacking and moving
- ///
- /// unitstop <unit_id>;
- BUILDIN_FUNC(unitstop)
- {
- int unit_id;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- {
- unit_stop_attack(bl);
- unit_stop_walking(bl,4);
- if( bl->type == BL_MOB )
- ((TBL_MOB*)bl)->target_id = 0;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit say the message
- ///
- /// unittalk <unit_id>,"<message>";
- BUILDIN_FUNC(unittalk)
- {
- int unit_id;
- const char* message;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- message = script_getstr(st, 3);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- {
- struct StringBuf sbuf;
- StringBuf_Init(&sbuf);
- StringBuf_Printf(&sbuf, "%s : %s", status_get_name(bl), message);
- clif_disp_overhead(bl, StringBuf_Value(&sbuf));
- StringBuf_Destroy(&sbuf);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit do an emotion
- ///
- /// unitemote <unit_id>,<emotion>;
- ///
- /// @see e_* in const.txt
- BUILDIN_FUNC(unitemote)
- {
- int unit_id;
- int emotion;
- struct block_list* bl;
- unit_id = script_getnum(st,2);
- emotion = script_getnum(st,3);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- clif_emotion(bl, emotion);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit cast the skill on the target or self if no target is specified
- ///
- /// unitskilluseid <unit_id>,<skill_id>,<skill_lv>{,<target_id>};
- /// unitskilluseid <unit_id>,"<skill name>",<skill_lv>{,<target_id>};
- BUILDIN_FUNC(unitskilluseid)
- {
- int unit_id;
- uint16 skill_id;
- uint16 skill_lv;
- int target_id;
- struct block_list* bl;
- struct script_data *data;
- unit_id = script_getnum(st,2);
- data = script_getdata(st, 3);
- get_val(st, data); // Convert into value in case of a variable
- skill_id = ( data_isstring(data) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- skill_lv = script_getnum(st,4);
- target_id = ( script_hasdata(st,5) ? script_getnum(st,5) : unit_id );
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- unit_skilluse_id(bl, target_id, skill_id, skill_lv);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Makes the unit cast the skill on the target position.
- ///
- /// unitskillusepos <unit_id>,<skill_id>,<skill_lv>,<target_x>,<target_y>;
- /// unitskillusepos <unit_id>,"<skill name>",<skill_lv>,<target_x>,<target_y>;
- BUILDIN_FUNC(unitskillusepos)
- {
- int unit_id;
- uint16 skill_id;
- uint16 skill_lv;
- int skill_x;
- int skill_y;
- struct block_list* bl;
- struct script_data *data;
- unit_id = script_getnum(st,2);
- data = script_getdata(st, 3);
- get_val(st, data); // Convert into value in case of a variable
- skill_id = ( data_isstring(data) ? skill_name2id(script_getstr(st,3)) : script_getnum(st,3) );
- skill_lv = script_getnum(st,4);
- skill_x = script_getnum(st,5);
- skill_y = script_getnum(st,6);
- bl = map_id2bl(unit_id);
- if( bl != NULL )
- unit_skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv);
- return SCRIPT_CMD_SUCCESS;
- }
- // <--- [zBuffer] List of mob control commands
- /// Pauses the execution of the script, detaching the player
- ///
- /// sleep <mili seconds>;
- BUILDIN_FUNC(sleep)
- {
- int ticks;
- ticks = script_getnum(st,2);
- // detach the player
- script_detach_rid(st);
- if( ticks <= 0 )
- {// do nothing
- }
- else if( st->sleep.tick == 0 )
- {// sleep for the target amount of time
- st->state = RERUNLINE;
- st->sleep.tick = ticks;
- }
- else
- {// sleep time is over
- st->state = RUN;
- st->sleep.tick = 0;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Pauses the execution of the script, keeping the player attached
- /// Returns if a player is still attached
- ///
- /// sleep2(<mili secconds>) -> <bool>
- BUILDIN_FUNC(sleep2)
- {
- int ticks;
- ticks = script_getnum(st,2);
- if( ticks <= 0 )
- {// do nothing
- script_pushint(st, (map_id2sd(st->rid)!=NULL));
- }
- else if( !st->sleep.tick )
- {// sleep for the target amount of time
- st->state = RERUNLINE;
- st->sleep.tick = ticks;
- }
- else
- {// sleep time is over
- st->state = RUN;
- st->sleep.tick = 0;
- script_pushint(st, (map_id2sd(st->rid)!=NULL));
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Awakes all the sleep timers of the target npc
- ///
- /// awake "<npc name>";
- BUILDIN_FUNC(awake)
- {
- struct npc_data* nd;
- struct linkdb_node *node = (struct linkdb_node *)sleep_db;
- nd = npc_name2id(script_getstr(st, 2));
- if( nd == NULL ) {
- ShowError("awake: NPC \"%s\" not found\n", script_getstr(st, 2));
- return 1;
- }
- while( node )
- {
- if( (int)__64BPRTSIZE(node->key) == nd->bl.id )
- {// sleep timer for the npc
- struct script_state* tst = (struct script_state*)node->data;
- TBL_PC* sd = map_id2sd(tst->rid);
- if( tst->sleep.timer == INVALID_TIMER )
- {// already awake ???
- node = node->next;
- continue;
- }
- if( (sd && sd->status.char_id != tst->sleep.charid) || (tst->rid && !sd))
- {// char not online anymore / another char of the same account is online - Cancel execution
- tst->state = END;
- tst->rid = 0;
- }
- delete_timer(tst->sleep.timer, run_script_timer);
- node = script_erase_sleepdb(node);
- tst->sleep.timer = INVALID_TIMER;
- if(tst->state != RERUNLINE)
- tst->sleep.tick = 0;
- run_script_main(tst);
- }
- else
- {
- node = node->next;
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /// Returns a reference to a variable of the target NPC.
- /// Returns 0 if an error occurs.
- ///
- /// getvariableofnpc(<variable>, "<npc name>") -> <reference>
- BUILDIN_FUNC(getvariableofnpc)
- {
- struct script_data* data;
- const char* name;
- struct npc_data* nd;
- data = script_getdata(st,2);
- if( !data_isreference(data) )
- {// Not a reference (aka varaible name)
- ShowError("script:getvariableofnpc: not a variable\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- name = reference_getname(data);
- if( *name != '.' || name[1] == '@' )
- {// not a npc variable
- ShowError("script:getvariableofnpc: invalid scope (not npc variable)\n");
- script_reportdata(data);
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- nd = npc_name2id(script_getstr(st,3));
- if( nd == NULL || nd->subtype != SCRIPT || nd->u.scr.script == NULL )
- {// NPC not found or has no script
- ShowError("script:getvariableofnpc: can't find npc %s\n", script_getstr(st,3));
- script_pushnil(st);
- st->state = END;
- return 1;
- }
- push_val2(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars );
- return SCRIPT_CMD_SUCCESS;
- }
- /// Opens a warp portal.
- /// Has no "portal opening" effect/sound, it opens the portal immediately.
- ///
- /// warpportal <source x>,<source y>,"<target map>",<target x>,<target y>;
- ///
- /// @author blackhole89
- BUILDIN_FUNC(warpportal)
- {
- int spx;
- int spy;
- unsigned short mapindex;
- int tpx;
- int tpy;
- struct skill_unit_group* group;
- struct block_list* bl;
- bl = map_id2bl(st->oid);
- if( bl == NULL )
- {
- ShowError("script:warpportal: npc is needed\n");
- return 1;
- }
- spx = script_getnum(st,2);
- spy = script_getnum(st,3);
- mapindex = mapindex_name2id(script_getstr(st, 4));
- tpx = script_getnum(st,5);
- tpy = script_getnum(st,6);
- if( mapindex == 0 )
- return 0;// map not found
- group = skill_unitsetting(bl, AL_WARP, 4, spx, spy, 0);
- if( group == NULL )
- return 0;// failed
- group->val1 = (group->val1<<16)|(short)0;
- group->val2 = (tpx<<16) | tpy;
- group->val3 = mapindex;
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(openmail)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- mail_openmail(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(openauction)
- {
- TBL_PC* sd;
- sd = script_rid2sd(st);
- if( sd == NULL )
- return 0;
- clif_Auction_openwindow(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Retrieves the value of the specified flag of the specified cell.
- ///
- /// checkcell("<map name>",<x>,<y>,<type>) -> <bool>
- ///
- /// @see cell_chk* constants in const.txt for the types
- BUILDIN_FUNC(checkcell)
- {
- int16 m = map_mapname2mapid(script_getstr(st,2));
- int16 x = script_getnum(st,3);
- int16 y = script_getnum(st,4);
- cell_chk type = (cell_chk)script_getnum(st,5);
- script_pushint(st, map_getcell(m, x, y, type));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Modifies flags of cells in the specified area.
- ///
- /// setcell "<map name>",<x1>,<y1>,<x2>,<y2>,<type>,<flag>;
- ///
- /// @see cell_* constants in const.txt for the types
- BUILDIN_FUNC(setcell)
- {
- int16 m = map_mapname2mapid(script_getstr(st,2));
- int16 x1 = script_getnum(st,3);
- int16 y1 = script_getnum(st,4);
- int16 x2 = script_getnum(st,5);
- int16 y2 = script_getnum(st,6);
- cell_t type = (cell_t)script_getnum(st,7);
- bool flag = (bool)script_getnum(st,8);
- int x,y;
- if( x1 > x2 ) swap(x1,x2);
- if( y1 > y2 ) swap(y1,y2);
- for( y = y1; y <= y2; ++y )
- for( x = x1; x <= x2; ++x )
- map_setcell(m, x, y, type, flag);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Mercenary Commands
- *------------------------------------------*/
- BUILDIN_FUNC(mercenary_create)
- {
- struct map_session_data *sd;
- int class_, contract_time;
- if( (sd = script_rid2sd(st)) == NULL || sd->md || sd->status.mer_id != 0 )
- return 0;
- class_ = script_getnum(st,2);
- if( !merc_class(class_) )
- return 0;
- contract_time = script_getnum(st,3);
- merc_create(sd, class_, contract_time);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_heal)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int hp, sp;
- if( sd == NULL || sd->md == NULL )
- return 0;
- hp = script_getnum(st,2);
- sp = script_getnum(st,3);
- status_heal(&sd->md->bl, hp, sp, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_sc_start)
- {
- struct map_session_data *sd = script_rid2sd(st);
- enum sc_type type;
- int tick, val1;
- if( sd == NULL || sd->md == NULL )
- return 0;
- type = (sc_type)script_getnum(st,2);
- tick = script_getnum(st,3);
- val1 = script_getnum(st,4);
- status_change_start(NULL, &sd->md->bl, type, 10000, val1, 0, 0, 0, tick, 2);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_get_calls)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- script_pushint(st,sd->status.arch_calls);
- break;
- case SPEAR_MERC_GUILD:
- script_pushint(st,sd->status.spear_calls);
- break;
- case SWORD_MERC_GUILD:
- script_pushint(st,sd->status.sword_calls);
- break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_set_calls)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild, value, *calls;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- value = script_getnum(st,3);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- calls = &sd->status.arch_calls;
- break;
- case SPEAR_MERC_GUILD:
- calls = &sd->status.spear_calls;
- break;
- case SWORD_MERC_GUILD:
- calls = &sd->status.sword_calls;
- break;
- default:
- return 0; // Invalid Guild
- }
- *calls += value;
- *calls = cap_value(*calls, 0, INT_MAX);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_get_faith)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- script_pushint(st,sd->status.arch_faith);
- break;
- case SPEAR_MERC_GUILD:
- script_pushint(st,sd->status.spear_faith);
- break;
- case SWORD_MERC_GUILD:
- script_pushint(st,sd->status.sword_faith);
- break;
- default:
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(mercenary_set_faith)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int guild, value, *calls;
- if( sd == NULL )
- return 0;
- guild = script_getnum(st,2);
- value = script_getnum(st,3);
- switch( guild )
- {
- case ARCH_MERC_GUILD:
- calls = &sd->status.arch_faith;
- break;
- case SPEAR_MERC_GUILD:
- calls = &sd->status.spear_faith;
- break;
- case SWORD_MERC_GUILD:
- calls = &sd->status.sword_faith;
- break;
- default:
- return 0; // Invalid Guild
- }
- *calls += value;
- *calls = cap_value(*calls, 0, INT_MAX);
- if( mercenary_get_guild(sd->md) == guild )
- clif_mercenary_updatestatus(sd,SP_MERCFAITH);
- return SCRIPT_CMD_SUCCESS;
- }
- /*------------------------------------------
- * Book Reading
- *------------------------------------------*/
- BUILDIN_FUNC(readbook)
- {
- struct map_session_data *sd;
- int book_id, page;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- book_id = script_getnum(st,2);
- page = script_getnum(st,3);
- clif_readbook(sd->fd, book_id, page);
- return SCRIPT_CMD_SUCCESS;
- }
- /******************
- Questlog script commands
- *******************/
- BUILDIN_FUNC(setquest)
- {
- struct map_session_data *sd = script_rid2sd(st);
- nullpo_ret(sd);
- quest_add(sd, script_getnum(st, 2));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(erasequest)
- {
- struct map_session_data *sd = script_rid2sd(st);
- nullpo_ret(sd);
- quest_delete(sd, script_getnum(st, 2));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(completequest)
- {
- struct map_session_data *sd = script_rid2sd(st);
- nullpo_ret(sd);
- quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(changequest)
- {
- struct map_session_data *sd = script_rid2sd(st);
- nullpo_ret(sd);
- quest_change(sd, script_getnum(st, 2),script_getnum(st, 3));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(checkquest)
- {
- struct map_session_data *sd = script_rid2sd(st);
- quest_check_type type = HAVEQUEST;
- nullpo_ret(sd);
- if( script_hasdata(st, 3) )
- type = (quest_check_type)script_getnum(st, 3);
- script_pushint(st, quest_check(sd, script_getnum(st, 2), type));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(showevent)
- {
- TBL_PC *sd = script_rid2sd(st);
- struct npc_data *nd = map_id2nd(st->oid);
- int state, color;
- if( sd == NULL || nd == NULL )
- return 0;
- state = script_getnum(st, 2);
- color = script_getnum(st, 3);
- if( color < 0 || color > 3 )
- color = 0; // set default color
- clif_quest_show_event(sd, &nd->bl, state, color);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * BattleGround System
- *------------------------------------------*/
- BUILDIN_FUNC(waitingroom2bg)
- {
- struct npc_data *nd;
- struct chat_data *cd;
- const char *map_name, *ev = "", *dev = "";
- int x, y, i, mapindex = 0, bg_id, n;
- struct map_session_data *sd;
- if( script_hasdata(st,7) )
- nd = npc_name2id(script_getstr(st,7));
- else
- nd = (struct npc_data *)map_id2bl(st->oid);
- if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL )
- {
- script_pushint(st,0);
- return 0;
- }
- map_name = script_getstr(st,2);
- if( strcmp(map_name,"-") != 0 )
- {
- mapindex = mapindex_name2id(map_name);
- if( mapindex == 0 )
- { // Invalid Map
- script_pushint(st,0);
- return 0;
- }
- }
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- ev = script_getstr(st,5); // Logout Event
- dev = script_getstr(st,6); // Die Event
- if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 )
- { // Creation failed
- script_pushint(st,0);
- return 0;
- }
- n = cd->users;
- for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) )
- mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), sd->bl.id);
- else
- mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), 0);
- }
- mapreg_setreg(add_str("$@arenamembersnum"), i);
- script_pushint(st,bg_id);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(waitingroom2bg_single)
- {
- const char* map_name;
- struct npc_data *nd;
- struct chat_data *cd;
- struct map_session_data *sd;
- int x, y, mapindex, bg_id;
- bg_id = script_getnum(st,2);
- map_name = script_getstr(st,3);
- if( (mapindex = mapindex_name2id(map_name)) == 0 )
- return 0; // Invalid Map
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- nd = npc_name2id(script_getstr(st,6));
- if( nd == NULL || (cd = (struct chat_data *)map_id2bl(nd->chat_id)) == NULL || cd->users <= 0 )
- return 0;
- if( (sd = cd->usersd[0]) == NULL )
- return 0;
- if( bg_team_join(bg_id, sd) )
- {
- pc_setpos(sd, mapindex, x, y, CLR_TELEPORT);
- script_pushint(st,1);
- }
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_team_setxy)
- {
- struct battleground_data *bg;
- int bg_id;
- bg_id = script_getnum(st,2);
- if( (bg = bg_team_search(bg_id)) == NULL )
- return 0;
- bg->x = script_getnum(st,3);
- bg->y = script_getnum(st,4);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_warp)
- {
- int x, y, mapindex, bg_id;
- const char* map_name;
- bg_id = script_getnum(st,2);
- map_name = script_getstr(st,3);
- if( (mapindex = mapindex_name2id(map_name)) == 0 )
- return 0; // Invalid Map
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- bg_team_warp(bg_id, mapindex, x, y);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_monster)
- {
- int class_ = 0, x = 0, y = 0, bg_id = 0;
- const char *str,*map, *evt="";
- bg_id = script_getnum(st,2);
- map = script_getstr(st,3);
- x = script_getnum(st,4);
- y = script_getnum(st,5);
- str = script_getstr(st,6);
- class_ = script_getnum(st,7);
- if( script_hasdata(st,8) ) evt = script_getstr(st,8);
- check_event(st, evt);
- script_pushint(st, mob_spawn_bg(map,x,y,str,class_,evt,bg_id));
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_monster_set_team)
- {
- struct mob_data *md;
- struct block_list *mbl;
- int id = script_getnum(st,2),
- bg_id = script_getnum(st,3);
- if( id == 0 || (mbl = map_id2bl(id)) == NULL || mbl->type != BL_MOB )
- return 0;
- md = (TBL_MOB *)mbl;
- md->bg_id = bg_id;
- mob_stop_attack(md);
- mob_stop_walking(md, 0);
- md->target_id = md->attacked_id = 0;
- clif_charnameack(0, &md->bl);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_leave)
- {
- struct map_session_data *sd = script_rid2sd(st);
- if( sd == NULL || !sd->bg_id )
- return 0;
- bg_team_leave(sd,0);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_destroy)
- {
- int bg_id = script_getnum(st,2);
- bg_team_delete(bg_id);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_getareausers)
- {
- const char *str;
- int16 m, x0, y0, x1, y1;
- int bg_id;
- int i = 0, c = 0;
- struct battleground_data *bg = NULL;
- struct map_session_data *sd;
- bg_id = script_getnum(st,2);
- str = script_getstr(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL || (m = map_mapname2mapid(str)) < 0 )
- {
- script_pushint(st,0);
- return 0;
- }
- x0 = script_getnum(st,4);
- y0 = script_getnum(st,5);
- x1 = script_getnum(st,6);
- y1 = script_getnum(st,7);
- for( i = 0; i < MAX_BG_MEMBERS; i++ )
- {
- if( (sd = bg->members[i].sd) == NULL )
- continue;
- if( sd->bl.m != m || sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1 )
- continue;
- c++;
- }
- script_pushint(st,c);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_updatescore)
- {
- const char *str;
- int16 m;
- str = script_getstr(st,2);
- if( (m = map_mapname2mapid(str)) < 0 )
- return 0;
- map[m].bgscore_lion = script_getnum(st,3);
- map[m].bgscore_eagle = script_getnum(st,4);
- clif_bg_updatescore(m);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(bg_get_data)
- {
- struct battleground_data *bg;
- int bg_id = script_getnum(st,2),
- type = script_getnum(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL )
- {
- script_pushint(st,0);
- return 0;
- }
- switch( type )
- {
- case 0: script_pushint(st, bg->count); break;
- default:
- ShowError("script:bg_get_data: unknown data identifier %d\n", type);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Instancing System
- *------------------------------------------*/
- //Returns an Instance ID
- //Checks NPC first, then if player is attached we check party
- int script_instancegetid(struct script_state* st)
- {
- short instance_id = 0;
- struct npc_data *nd;
- if( (nd = map_id2nd(st->oid)) && nd->instance_id > 0 )
- instance_id = nd->instance_id;
- else {
- struct map_session_data *sd;
- struct party_data *p;
- if( (sd = script_rid2sd(st)) != NULL && sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id )
- instance_id = p->instance_id;
- }
- return instance_id;
- }
- /*==========================================
- * Creates the instance
- * Returns Instance ID if created successfully
- *------------------------------------------*/
- BUILDIN_FUNC(instance_create)
- {
- struct map_session_data *sd;
- if((sd = script_rid2sd(st)) == NULL)
- return -1;
- script_pushint(st,instance_create(sd->status.party_id, script_getstr(st, 2)));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Destroys an instance (unofficial)
- * Officially instances are only destroyed by timeout
- *
- * instance_destroy {<instance_id>};
- *------------------------------------------*/
- BUILDIN_FUNC(instance_destroy)
- {
- short instance_id;
- if( script_hasdata(st,2) )
- instance_id = script_getnum(st,2);
- else
- instance_id = script_instancegetid(st);
- if( instance_id <= 0 || instance_id >= MAX_MAP_PER_SERVER ) {
- ShowError("script:instance_destroy: Trying to destroy invalid instance %d.\n", instance_id);
- return 0;
- }
- instance_destroy(instance_id);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warps player to instance
- * Results:
- * 0: Success
- * 1: Character not in party
- * 2: Party doesn't have instance
- * 3: Other errors (instance not in DB, instance doesn't match with party, etc.)
- *------------------------------------------*/
- BUILDIN_FUNC(instance_enter)
- {
- struct map_session_data *sd;
- if((sd = script_rid2sd(st)) != NULL)
- script_pushint(st,instance_enter(sd,script_getstr(st, 2)));
- else
- return 1;
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns the name of a duplicated NPC
- *
- * instance_npcname <npc_name>{,<instance_id>};
- * <npc_name> is the full name of an NPC.
- *------------------------------------------*/
- BUILDIN_FUNC(instance_npcname)
- {
- const char *str;
- short instance_id = 0;
- struct npc_data *nd;
- str = script_getstr(st,2);
- if( script_hasdata(st,3) )
- instance_id = script_getnum(st,3);
- else
- instance_id = script_instancegetid(st);
- if( instance_id && (nd = npc_name2id(str)) != NULL ) {
- static char npcname[NAME_LENGTH];
- snprintf(npcname, sizeof(npcname), "dup_%d_%d", instance_id, nd->bl.id);
- script_pushconststr(st,npcname);
- } else {
- ShowError("script:instance_npcname: invalid instance NPC (instance_id: %d, NPC name: \"%s\".)\n", instance_id, str);
- st->state = END;
- return 1;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns the name of a duplicated map
- *
- * instance_mapname <map_name>{,<instance_id>};
- *------------------------------------------*/
- BUILDIN_FUNC(instance_mapname)
- {
- const char *str;
- int16 m;
- short instance_id = 0;
- str = script_getstr(st,2);
- if( script_hasdata(st,3) )
- instance_id = script_getnum(st,3);
- else
- instance_id = script_instancegetid(st);
- // Check that instance mapname is a valid map
- if(!instance_id || (m = instance_mapname2mapid(str,instance_id)) < 0)
- script_pushconststr(st, "");
- else
- script_pushconststr(st, map[m].name);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Returns an Instance ID
- *------------------------------------------*/
- BUILDIN_FUNC(instance_id)
- {
- short instance_id;
- instance_id = script_instancegetid(st);
- if(!instance_id) {
- //ShowError("script:instance_id: No instance attached to NPC or player");
- script_pushint(st, 0);
- return 1;
- }
- script_pushint(st, instance_id);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Warps all players inside an instance
- *
- * instance_warpall <map_name>,<x>,<y>{,<instance_id>};
- *------------------------------------------*/
- BUILDIN_FUNC(instance_warpall)
- {
- struct party_data *p;
- struct map_session_data *pl_sd;
- int16 m, i;
- short instance_id;
- const char *mapn;
- int x, y;
- mapn = script_getstr(st,2);
- x = script_getnum(st,3);
- y = script_getnum(st,4);
- if( script_hasdata(st,5) )
- instance_id = script_getnum(st,5);
- else
- instance_id = script_instancegetid(st);
- if( !instance_id || (m = map_mapname2mapid(mapn)) < 0 || (m = instance_mapname2mapid(map[m].name,instance_id)) < 0)
- return 0;
- if( !(p = party_search(instance_data[instance_id].party_id)) )
- return 0;
- for( i = 0; i < MAX_PARTY; i++ )
- if( (pl_sd = p->data[i].sd) && map[pl_sd->bl.m].instance_id == instance_id ) pc_setpos(pl_sd,map_id2index(m),x,y,CLR_TELEPORT);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Broadcasts to all maps inside an instance
- *
- * instance_announce <instance id>,"<text>",<flag>{,<fontColor>{,<fontType>{,<fontSize>{,<fontAlign>{,<fontY>}}}}};
- * Using -1 for <instance id> will auto-detect the id.
- *------------------------------------------*/
- BUILDIN_FUNC(instance_announce) {
- int instance_id = script_getnum(st,2);
- const char *mes = script_getstr(st,3);
- int flag = script_getnum(st,4);
- const char *fontColor = script_hasdata(st,5) ? script_getstr(st,5) : NULL;
- int fontType = script_hasdata(st,6) ? script_getnum(st,6) : 0x190; // default fontType (FW_NORMAL)
- int fontSize = script_hasdata(st,7) ? script_getnum(st,7) : 12; // default fontSize
- int fontAlign = script_hasdata(st,8) ? script_getnum(st,8) : 0; // default fontAlign
- int fontY = script_hasdata(st,9) ? script_getnum(st,9) : 0; // default fontY
- int i;
- if( instance_id == -1 ) {
- instance_id = script_instancegetid(st);
- }
- if( !instance_id && &instance_data[instance_id] != NULL)
- return true;
- for( i = 0; i < instance_data[instance_id].cnt_map; i++ )
- map_foreachinmap(buildin_announce_sub, instance_data[instance_id].map[i].m, BL_PC,
- mes, strlen(mes)+1, flag&0xf0, fontColor, fontType, fontSize, fontAlign, fontY);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * instance_check_party [malufett]
- * Values:
- * party_id : Party ID of the invoking character. [Required Parameter]
- * amount : Amount of needed Partymembers for the Instance. [Optional Parameter]
- * min : Minimum Level needed to join the Instance. [Optional Parameter]
- * max : Maxium Level allowed to join the Instance. [Optional Parameter]
- * Example: instance_check_party (getcharid(1){,amount}{,min}{,max});
- * Example 2: instance_check_party (getcharid(1),1,1,99);
- *------------------------------------------*/
- BUILDIN_FUNC(instance_check_party)
- {
- struct map_session_data *pl_sd;
- int amount, min, max, i, party_id, c = 0;
- struct party_data *p = NULL;
- amount = script_hasdata(st,3) ? script_getnum(st,3) : 1; // Amount of needed Partymembers for the Instance.
- min = script_hasdata(st,4) ? script_getnum(st,4) : 1; // Minimum Level needed to join the Instance.
- max = script_hasdata(st,5) ? script_getnum(st,5) : MAX_LEVEL; // Maxium Level allowed to join the Instance.
- if( min < 1 || min > MAX_LEVEL) {
- ShowError("script:check_party: Invalid min level, %d\n", min);
- return 1;
- } else if( max < 1 || max > MAX_LEVEL) {
- ShowError("script:check_party: Invalid max level, %d\n", max);
- return 1;
- }
- if( script_hasdata(st,2) )
- party_id = script_getnum(st,2);
- else return 0;
- if( !(p = party_search(party_id)) ) {
- script_pushint(st, 0); // Returns false if party does not exist.
- return 0;
- }
- for( i = 0; i < MAX_PARTY; i++ )
- if( (pl_sd = p->data[i].sd) )
- if(map_id2bl(pl_sd->bl.id)) {
- if(pl_sd->status.base_level < min) {
- script_pushint(st, 0);
- return 0;
- } else if(pl_sd->status.base_level > max) {
- script_pushint(st, 0);
- return 0;
- }
- c++;
- }
- if(c < amount)
- script_pushint(st, 0); // Not enough Members in the Party to join Instance.
- else
- script_pushint(st, 1);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Custom Fonts
- *------------------------------------------*/
- BUILDIN_FUNC(setfont)
- {
- struct map_session_data *sd = script_rid2sd(st);
- int font = script_getnum(st,2);
- if( sd == NULL )
- return 0;
- if( sd->user_font != font )
- sd->user_font = font;
- else
- sd->user_font = 0;
- clif_font(sd);
- return SCRIPT_CMD_SUCCESS;
- }
- static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
- {
- TBL_MOB* md = (TBL_MOB*)bl;
- struct block_list *tbl;
- int mobid = va_arg(ap,int);
- uint16 skill_id = va_arg(ap,int);
- uint16 skill_lv = va_arg(ap,int);
- int casttime = va_arg(ap,int);
- int cancel = va_arg(ap,int);
- int emotion = va_arg(ap,int);
- int target = va_arg(ap,int);
- if( md->class_ != mobid )
- return 0;
- // 0:self, 1:target, 2:master, default:random
- switch( target )
- {
- case 0: tbl = map_id2bl(md->bl.id); break;
- case 1: tbl = map_id2bl(md->target_id); break;
- case 2: tbl = map_id2bl(md->master_id); break;
- default:tbl = battle_getenemy(&md->bl, DEFAULT_ENEMY_TYPE(md),skill_get_range2(&md->bl, skill_id, skill_lv)); break;
- }
- if( !tbl )
- return 0;
- if( md->ud.skilltimer != INVALID_TIMER ) // Cancel the casting skill.
- unit_skillcastcancel(bl,0);
- if( skill_get_casttype(skill_id) == CAST_GROUND )
- unit_skilluse_pos2(&md->bl, tbl->x, tbl->y, skill_id, skill_lv, casttime, cancel);
- else
- unit_skilluse_id2(&md->bl, tbl->id, skill_id, skill_lv, casttime, cancel);
- clif_emotion(&md->bl, emotion);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * areamobuseskill "Map Name",<x>,<y>,<range>,<Mob ID>,"Skill Name"/<Skill ID>,<Skill Lv>,<Cast Time>,<Cancelable>,<Emotion>,<Target Type>;
- *------------------------------------------*/
- BUILDIN_FUNC(areamobuseskill)
- {
- struct block_list center;
- struct script_data *data;
- int16 m;
- int range,mobid,skill_id,skill_lv,casttime,emotion,target,cancel;
- if( (m = map_mapname2mapid(script_getstr(st,2))) < 0 ) {
- ShowError("areamobuseskill: invalid map name.\n");
- return 0;
- }
- center.m = m;
- center.x = script_getnum(st,3);
- center.y = script_getnum(st,4);
- range = script_getnum(st,5);
- mobid = script_getnum(st,6);
- data = script_getdata(st, 7);
- get_val(st, data); // Convert into value in case of a variable
- skill_id = ( data_isstring(data) ? skill_name2id(script_getstr(st,7)) : script_getnum(st,7) );
- if( (skill_lv = script_getnum(st,8)) > battle_config.mob_max_skilllvl )
- skill_lv = battle_config.mob_max_skilllvl;
- casttime = script_getnum(st,9);
- cancel = script_getnum(st,10);
- emotion = script_getnum(st,11);
- target = script_getnum(st,12);
- map_foreachinrange(buildin_mobuseskill_sub, ¢er, range, BL_MOB, mobid, skill_id, skill_lv, casttime, cancel, emotion, target);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(progressbar)
- {
- struct map_session_data * sd = script_rid2sd(st);
- const char * color;
- unsigned int second;
- if( !st || !sd )
- return 0;
- st->state = STOP;
- color = script_getstr(st,2);
- second = script_getnum(st,3);
- sd->progressbar.npc_id = st->oid;
- sd->progressbar.timeout = gettick() + second*1000;
- clif_progressbar(sd, strtol(color, (char **)NULL, 0), second);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(pushpc)
- {
- uint8 dir;
- int cells, dx, dy;
- struct map_session_data* sd;
- if((sd = script_rid2sd(st))==NULL)
- {
- return 0;
- }
- dir = script_getnum(st,2);
- cells = script_getnum(st,3);
- if(dir>7)
- {
- ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir);
- script_reportsrc(st);
- dir%= 8; // trim spin-over
- }
- if(!cells)
- {// zero distance
- return 0;
- }
- else if(cells<0)
- {// pushing backwards
- dir = (dir+4)%8; // turn around
- cells = -cells;
- }
- dx = dirx[dir];
- dy = diry[dir];
- unit_blown(&sd->bl, dx, dy, cells, 0);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Invokes buying store preparation window
- /// buyingstore <slots>;
- BUILDIN_FUNC(buyingstore)
- {
- struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
- {
- return 0;
- }
- if( npc_isnear(&sd->bl) ) {
- char output[150];
- sprintf(output, msg_txt(sd,662), battle_config.min_npc_vendchat_distance);
- clif_displaymessage(sd->fd, output);
- return 0;
- }
- buyingstore_setup(sd, script_getnum(st,2));
- return SCRIPT_CMD_SUCCESS;
- }
- /// Invokes search store info window
- /// searchstores <uses>,<effect>;
- BUILDIN_FUNC(searchstores)
- {
- unsigned short effect;
- unsigned int uses;
- struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
- {
- return 0;
- }
- uses = script_getnum(st,2);
- effect = script_getnum(st,3);
- if( !uses )
- {
- ShowError("buildin_searchstores: Amount of uses cannot be zero.\n");
- return 1;
- }
- if( effect > 1 )
- {
- ShowError("buildin_searchstores: Invalid effect id %hu, specified.\n", effect);
- return 1;
- }
- searchstore_open(sd, uses, effect);
- return SCRIPT_CMD_SUCCESS;
- }
- /// Displays a number as large digital clock.
- /// showdigit <value>[,<type>];
- BUILDIN_FUNC(showdigit)
- {
- unsigned int type = 0;
- int value;
- struct map_session_data* sd;
- if( ( sd = script_rid2sd(st) ) == NULL )
- {
- return 0;
- }
- value = script_getnum(st,2);
- if( script_hasdata(st,3) )
- {
- type = script_getnum(st,3);
- if( type > 3 )
- {
- ShowError("buildin_showdigit: Invalid type %u.\n", type);
- return 1;
- }
- }
- clif_showdigit(sd, (unsigned char)type, value);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * Rune Knight
- **/
- BUILDIN_FUNC(makerune) {
- TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- clif_skill_produce_mix_list(sd,RK_RUNEMASTERY,24);
- sd->itemid = script_getnum(st,2);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * checkdragon() returns 1 if mounting a dragon or 0 otherwise.
- **/
- BUILDIN_FUNC(checkdragon) {
- TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( pc_isridingdragon(sd) )
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * setdragon({optional Color}) returns 1 on success or 0 otherwise
- * - Toggles the dragon on a RK if he can mount;
- * @param Color - when not provided uses the green dragon;
- * - 1 : Green Dragon
- * - 2 : Brown Dragon
- * - 3 : Gray Dragon
- * - 4 : Blue Dragon
- * - 5 : Red Dragon
- **/
- BUILDIN_FUNC(setdragon) {
- TBL_PC* sd;
- int color = script_hasdata(st,2) ? script_getnum(st,2) : 0;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( !pc_checkskill(sd,RK_DRAGONTRAINING) || (sd->class_&MAPID_THIRDMASK) != MAPID_RUNE_KNIGHT )
- script_pushint(st,0);//Doesn't have the skill or it's not a Rune Knight
- else if ( pc_isridingdragon(sd) ) {//Is mounted; release
- pc_setoption(sd, sd->sc.option&~OPTION_DRAGON);
- script_pushint(st,1);
- } else {//Not mounted; Mount now.
- unsigned int option = OPTION_DRAGON1;
- if( color ) {
- option = ( color == 1 ? OPTION_DRAGON1 :
- color == 2 ? OPTION_DRAGON2 :
- color == 3 ? OPTION_DRAGON3 :
- color == 4 ? OPTION_DRAGON4 :
- color == 5 ? OPTION_DRAGON5 : 0);
- if( !option ) {
- ShowWarning("script_setdragon: Unknown Color %d used; changing to green (1)\n",color);
- option = OPTION_DRAGON1;
- }
- }
- pc_setoption(sd, sd->sc.option|option);
- script_pushint(st,1);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * ismounting() returns 1 if mounting a new mount or 0 otherwise
- **/
- BUILDIN_FUNC(ismounting) {
- TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( sd->sc.option&OPTION_MOUNTING )
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * setmounting() returns 1 on success or 0 otherwise
- * - Toggles new mounts on a player when he can mount
- * - Will fail if the player is mounting a non-new mount, e.g. dragon, peco, wug, etc.
- * - Will unmount the player is he is already mounting
- **/
- BUILDIN_FUNC(setmounting) {
- TBL_PC* sd;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- if( sd->sc.option&(OPTION_WUGRIDER|OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR) )
- script_pushint(st,0);//can't mount with one of these
- else {
- if( sd->sc.option&OPTION_MOUNTING )
- pc_setoption(sd, sd->sc.option&~OPTION_MOUNTING);//release mount
- else
- pc_setoption(sd, sd->sc.option|OPTION_MOUNTING);//mount
- script_pushint(st,1);//in both cases, return 1.
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * Retrieves quantity of arguments provided to callfunc/callsub.
- * getargcount() -> amount of arguments received in a function
- **/
- BUILDIN_FUNC(getargcount) {
- struct script_retinfo* ri;
- if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp - 1].type != C_RETINFO ) {
- ShowError("script:getargcount: used out of function or callsub label!\n");
- st->state = END;
- return 1;
- }
- ri = st->stack->stack_data[st->stack->defsp - 1].u.ri;
- script_pushint(st, ri->nargs);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * getcharip(<account ID>/<character ID>/<character name>)
- **/
- BUILDIN_FUNC(getcharip)
- {
- struct map_session_data* sd = NULL;
- /* check if a character name is specified */
- if( script_hasdata(st, 2) )
- {
- struct script_data *data;
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- if (data_isstring(data))
- sd = map_nick2sd(script_getstr(st, 2));
- else if (data_isint(data) || script_getnum(st, 2))
- {
- int id = 0;
- id = script_getnum(st, 2);
- sd = (map_id2sd(id) ? map_id2sd(id) : map_charid2sd(id));
- }
- }
- else
- sd = script_rid2sd(st);
- /* check for sd and IP */
- if (!sd || !session[sd->fd]->client_addr)
- {
- script_pushconststr(st, "");
- return 0;
- }
- /* return the client ip_addr converted for output */
- if (sd && sd->fd && session[sd->fd])
- {
- /* initiliaze */
- const char *ip_addr = NULL;
- uint32 ip;
- /* set ip, ip_addr and convert to ip and push str */
- ip = session[sd->fd]->client_addr;
- ip_addr = ip2str(ip, NULL);
- script_pushstrcopy(st, ip_addr);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * is_function(<function name>) -> 1 if function exists, 0 otherwise
- **/
- BUILDIN_FUNC(is_function) {
- const char* str = script_getstr(st,2);
- if( strdb_exists(userfunc_db, str) )
- script_pushint(st,1);
- else
- script_pushint(st,0);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * get_revision() -> retrieves the current svn revision (if available)
- **/
- BUILDIN_FUNC(get_revision) {
- const char *svn = get_svn_revision();
- if ( svn[0] != UNKNOWN_VERSION )
- script_pushint(st,atoi(svn));
- else
- script_pushint(st,-1); //unknown
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * freeloop(<toggle>) -> toggles this script instance's looping-check ability
- **/
- BUILDIN_FUNC(freeloop) {
- if( script_getnum(st,2) )
- st->freeloop = 1;
- else
- st->freeloop = 0;
- script_pushint(st, st->freeloop);
- return SCRIPT_CMD_SUCCESS;
- }
- /**
- * @commands (script based)
- **/
- BUILDIN_FUNC(bindatcmd) {
- const char* atcmd;
- const char* eventName;
- int i, level = 0, level2 = 0;
- bool create = false;
- atcmd = script_getstr(st,2);
- eventName = script_getstr(st,3);
- if( *atcmd == atcommand_symbol || *atcmd == charcommand_symbol )
- atcmd++;
- if( script_hasdata(st,4) ) level = script_getnum(st,4);
- if( script_hasdata(st,5) ) level2 = script_getnum(st,5);
- if( atcmd_binding_count == 0 ) {
- CREATE(atcmd_binding,struct atcmd_binding_data*,1);
- create = true;
- } else {
- ARR_FIND(0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command,atcmd) == 0);
- if( i < atcmd_binding_count ) {/* update existent entry */
- safestrncpy(atcmd_binding[i]->npc_event, eventName, 50);
- atcmd_binding[i]->level = level;
- atcmd_binding[i]->level2 = level2;
- } else
- create = true;
- }
- if( create ) {
- i = atcmd_binding_count;
- if( atcmd_binding_count++ != 0 )
- RECREATE(atcmd_binding,struct atcmd_binding_data*,atcmd_binding_count);
- CREATE(atcmd_binding[i],struct atcmd_binding_data,1);
- safestrncpy(atcmd_binding[i]->command, atcmd, 50);
- safestrncpy(atcmd_binding[i]->npc_event, eventName, 50);
- atcmd_binding[i]->level = level;
- atcmd_binding[i]->level2 = level2;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(unbindatcmd) {
- const char* atcmd;
- int i = 0;
- atcmd = script_getstr(st, 2);
- if( *atcmd == atcommand_symbol || *atcmd == charcommand_symbol )
- atcmd++;
- if( atcmd_binding_count == 0 ) {
- script_pushint(st, 0);
- return 0;
- }
- ARR_FIND(0, atcmd_binding_count, i, strcmp(atcmd_binding[i]->command, atcmd) == 0);
- if( i < atcmd_binding_count ) {
- int cursor = 0;
- aFree(atcmd_binding[i]);
- atcmd_binding[i] = NULL;
- /* compact the list now that we freed a slot somewhere */
- for( i = 0, cursor = 0; i < atcmd_binding_count; i++ ) {
- if( atcmd_binding[i] == NULL )
- continue;
- if( cursor != i ) {
- memmove(&atcmd_binding[cursor], &atcmd_binding[i], sizeof(struct atcmd_binding_data*));
- }
- cursor++;
- }
- if( (atcmd_binding_count = cursor) == 0 )
- aFree(atcmd_binding);
- script_pushint(st, 1);
- } else
- script_pushint(st, 0);/* not found */
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(useatcmd) {
- return atcommand_sub(st,3);
- }
- BUILDIN_FUNC(checkre)
- {
- int num;
- num=script_getnum(st,2);
- switch(num){
- case 0:
- #ifdef RENEWAL
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- case 1:
- #ifdef RENEWAL_CAST
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- case 2:
- #ifdef RENEWAL_DROP
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- case 3:
- #ifdef RENEWAL_EXP
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- case 4:
- #ifdef RENEWAL_LVDMG
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- case 5:
- #ifdef RENEWAL_ASPD
- script_pushint(st, 1);
- #else
- script_pushint(st, 0);
- #endif
- break;
- default:
- ShowWarning("buildin_checkre: unknown parameter.\n");
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* getrandgroupitem <group_id>,<quantity>{,<sub_group>} */
- BUILDIN_FUNC(getrandgroupitem) {
- TBL_PC* sd;
- int i, get_count = 0, flag;
- uint16 nameid, group = script_getnum(st,2), qty = script_getnum(st,3);
- uint8 sub_group = script_getnum(st,4);
- struct item item_tmp;
- if (!( sd = script_rid2sd(st)))
- return SCRIPT_CMD_SUCCESS;
- if (!group) {
- ShowError("getrandgroupitem: Invalid group id (%d)!\n",script_getnum(st,2));
- return SCRIPT_CMD_FAILURE;
- }
- if ((nameid = itemdb_searchrandomid(group,sub_group)) == UNKNOWN_ITEM_ID) {
- return SCRIPT_CMD_FAILURE; //ensure valid itemid
- }
- memset(&item_tmp,0,sizeof(item_tmp));
- item_tmp.nameid = nameid;
- item_tmp.identify = itemdb_isidentified(nameid);
- if (!qty)
- qty = itemdb_get_randgroupitem_count(group,sub_group,nameid);
- //Check if it's stackable.
- if (!itemdb_isstackable(nameid)) {
- item_tmp.amount = 1;
- get_count = qty;
- }
- else {
- item_tmp.amount = qty;
- get_count = 1;
- }
- for (i = 0; i < get_count; i++) {
- // if not pet egg
- if (!pet_create_egg(sd, nameid)) {
- if ((flag = pc_additem(sd,&item_tmp,item_tmp.amount,LOG_TYPE_SCRIPT))) {
- clif_additem(sd,0,0,flag);
- if (pc_candrop(sd,&item_tmp))
- map_addflooritem(&item_tmp,item_tmp.amount,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
- }
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* getgroupitem <group_id>;
- * Gives item(s) to the attached player based on item group contents
- */
- BUILDIN_FUNC(getgroupitem) {
- TBL_PC *sd;
- int group_id = script_getnum(st,2);
-
- if (!(sd = script_rid2sd(st)))
- return SCRIPT_CMD_SUCCESS;
-
- if (itemdb_pc_get_itemgroup(group_id,sd->itemid,sd)) {
- ShowError("getgroupitem: Invalid group id '%d' specified.",group_id);
- return SCRIPT_CMD_FAILURE;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* cleanmap <map_name>;
- * cleanarea <map_name>, <x0>, <y0>, <x1>, <y1>; */
- static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap)
- {
- nullpo_ret(bl);
- map_clearflooritem(bl);
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(cleanmap)
- {
- const char *map;
- int16 m = -1;
- int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0;
- map = script_getstr(st, 2);
- m = map_mapname2mapid(map);
- if (!m)
- return 1;
- if ((script_lastdata(st) - 2) < 4) {
- map_foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM);
- } else {
- x0 = script_getnum(st, 3);
- y0 = script_getnum(st, 4);
- x1 = script_getnum(st, 5);
- y1 = script_getnum(st, 6);
- if (x0 > 0 && y0 > 0 && x1 > 0 && y1 > 0) {
- map_foreachinarea(atcommand_cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM);
- } else {
- ShowError("cleanarea: invalid coordinate defined!\n");
- return 1;
- }
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* Cast a skill on the attached player.
- * npcskill <skill id>, <skill lvl>, <stat point>, <NPC level>;
- * npcskill "<skill name>", <skill lvl>, <stat point>, <NPC level>; */
- BUILDIN_FUNC(npcskill)
- {
- uint16 skill_id;
- unsigned short skill_level;
- unsigned int stat_point;
- unsigned int npc_level;
- struct npc_data *nd;
- struct map_session_data *sd;
- struct script_data *data;
-
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- skill_id = data_isstring(data) ? skill_name2id(script_getstr(st, 2)) : script_getnum(st, 2);
- skill_level = script_getnum(st, 3);
- stat_point = script_getnum(st, 4);
- npc_level = script_getnum(st, 5);
- sd = script_rid2sd(st);
- nd = (struct npc_data *)map_id2bl(sd->npc_id);
- if (stat_point > battle_config.max_third_parameter) {
- ShowError("npcskill: stat point exceeded maximum of %d.\n",battle_config.max_third_parameter );
- return 1;
- }
- if (npc_level > MAX_LEVEL) {
- ShowError("npcskill: level exceeded maximum of %d.\n", MAX_LEVEL);
- return 1;
- }
- if (sd == NULL || nd == NULL) { //ain't possible, but I don't trust people.
- return 1;
- }
- nd->level = npc_level;
- nd->stat_point = stat_point;
- if (!nd->status.hp) {
- status_calc_npc(nd, true);
- } else {
- status_calc_npc(nd, false);
- }
- if (skill_get_inf(skill_id)&INF_GROUND_SKILL) {
- unit_skilluse_pos(&nd->bl, sd->bl.x, sd->bl.y, skill_id, skill_level);
- } else {
- unit_skilluse_id(&nd->bl, sd->bl.id, skill_id, skill_level);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* Consumes an item.
- * consumeitem <item id>;
- * consumeitem "<item name>"; */
- BUILDIN_FUNC(consumeitem)
- {
- TBL_NPC *nd;
- TBL_PC *sd;
- struct script_data *data;
- struct item_data *item_data;
- nullpo_retr( 1, ( sd = script_rid2sd( st ) ) );
- nullpo_retr( 1, ( nd = (TBL_NPC *)map_id2bl( sd->npc_id ) ) );
- data = script_getdata( st, 2 );
- get_val( st, data );
- if( data_isstring( data ) ){
- const char *name = conv_str( st, data );
- if( ( item_data = itemdb_searchname( name ) ) == NULL ){
- ShowError( "buildin_consumeitem: Nonexistant item %s requested.\n", name );
- return 1;
- }
- }else if( data_isint( data ) ){
- int nameid = conv_num( st, data );
- if( ( item_data = itemdb_exists( nameid ) ) == NULL ){
- ShowError("buildin_consumeitem: Nonexistant item %d requested.\n", nameid );
- return 1;
- }
- }else{
- ShowError("buildin_consumeitem: invalid data type for argument #1 (%d).", data->type );
- return 1;
- }
- run_script( item_data->script, 0, sd->bl.id, nd->bl.id );
- return SCRIPT_CMD_SUCCESS;
- }
- /*=======================================================
- * Make a player sit/stand.
- * sit {"<character name>"};
- * stand {"<character name>"};
- * Note: Use readparam(Sitting) which returns 1 or 0 (sitting or standing).
- *-------------------------------------------------------*/
- BUILDIN_FUNC(sit)
- {
- TBL_PC *sd;
- if( script_hasdata(st, 2) )
- sd = map_nick2sd(script_getstr(st, 2));
- else
- sd = script_rid2sd(st);
- if( sd == NULL)
- return 0;
- if( !pc_issit(sd) ) {
- unit_stop_walking(&sd->bl, 1|4);
- pc_setsit(sd);
- skill_sit(sd, 1);
- clif_sitting(&sd->bl);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- BUILDIN_FUNC(stand)
- {
- TBL_PC *sd;
- if( script_hasdata(st, 2) )
- sd = map_nick2sd(script_getstr(st, 2));
- else
- sd = script_rid2sd(st);
- if( sd == NULL)
- return 0;
- if( pc_issit(sd) ) {
- pc_setstand(sd);
- skill_sit(sd, 0);
- clif_standing(&sd->bl);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * countbound {<type>};
- * Creates an array of bounded item IDs
- * Returns amount of items found
- * Type:
- * 1 - Account Bound
- * 2 - Guild Bound
- * 3 - Party Bound
- *------------------------------------------*/
- BUILDIN_FUNC(countbound)
- {
- int i, type, j=0, k=0;
- TBL_PC *sd;
- if( (sd = script_rid2sd(st)) == NULL )
- return 0;
- type = script_hasdata(st,2)?script_getnum(st,2):0;
- for(i=0;i<MAX_INVENTORY;i++){
- if(sd->status.inventory[i].nameid > 0 && (
- (!type && sd->status.inventory[i].bound > 0) ||
- (type && sd->status.inventory[i].bound == type)
- )) {
- pc_setreg(sd,reference_uid(add_str("@bound_items"), k),sd->status.inventory[i].nameid);
- k++;
- j += sd->status.inventory[i].amount;
- }
- }
- script_pushint(st,j);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_create "<party name>"{,<char id>{,<item share>{,<item share type>}}};
- * <item share>: 0-Each Take. 1-Party Share
- * <item share type>: 0-Each Take. 1-Even Share
- * Return values:
- * -3 - party name is exist
- * -2 - player is in party already
- * -1 - player is not found
- * 0 - unknown error
- * 1 - success, will return party id $@party_create_id
- *------------------------------------------*/
- BUILDIN_FUNC(party_create)
- {
- char party_name[NAME_LENGTH];
- int item1 = 0, item2 = 0;
- TBL_PC *sd;
- if( (!script_hasdata(st,3) && !(sd = script_rid2sd(st))) || (script_hasdata(st,3) && !(sd = map_charid2sd(script_getnum(st,3)))) ) {
- script_pushint(st,-1);
- return 0;
- }
- if( sd->status.party_id ) {
- script_pushint(st,-2);
- return 0;
- }
- safestrncpy(party_name,script_getstr(st,2),NAME_LENGTH);
- trim(party_name);
- if( party_searchname(party_name) ) {
- script_pushint(st,-3);
- return 0;
- }
- if( script_getnum(st,4) )
- item1 = 1;
- if( script_getnum(st,5) )
- item2 = 1;
- party_create_byscript = 1;
- script_pushint(st,party_create(sd,party_name,item1,item2));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_addmember <party id>,<char id>;
- * Adds player to specified party
- * Return values:
- * -4 - party is full
- * -3 - party is not found
- * -2 - player is in party already
- * -1 - player is not found
- * 0 - unknown error
- * 1 - success
- *------------------------------------------*/
- BUILDIN_FUNC(party_addmember)
- {
- int party_id = script_getnum(st,2);
- TBL_PC *sd;
- struct party_data *party;
- if( !(sd = map_charid2sd(script_getnum(st,3))) ) {
- script_pushint(st,-1);
- return 0;
- }
- if( sd->status.party_id ) {
- script_pushint(st,-2);
- return 0;
- }
- if( !(party = party_search(party_id)) ) {
- script_pushint(st,-3);
- return 0;
- }
- if( party->party.count >= MAX_PARTY ) {
- script_pushint(st,-4);
- return 0;
- }
- sd->party_invite = party_id;
- script_pushint(st,party_add_member(party_id,sd));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_delmember {<char id>,<party_id>};
- * Removes player from his/her party. If party_id and char_id is empty
- * remove the invoker from his/her party
- * Return values:
- * -3 - player is not in party
- * -2 - party is not found
- * -1 - player is not found
- * 0 - unknown error
- * 1 - success
- *------------------------------------------*/
- BUILDIN_FUNC(party_delmember)
- {
- TBL_PC *sd = NULL;
- if( !script_hasdata(st,2) && !script_hasdata(st,3) && !(sd = script_rid2sd(st)) ) {
- script_pushint(st,-1);
- return 0;
- }
- if( sd || (script_getnum(st,2) && (sd = map_charid2sd(script_getnum(st,2)))) )
- script_pushint(st,party_removemember2(sd,0,0));
- else
- script_pushint(st,party_removemember2(NULL,script_getnum(st,2),script_getnum(st,3)));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_changeleader <party id>,<char id>;
- * Can change party leader even the leader is not online
- * Return values:
- * -4 - player is party leader already
- * -3 - player is not in this party
- * -2 - player is not found
- * -1 - party is not found
- * 0 - unknown error
- * 1 - success
- *------------------------------------------*/
- BUILDIN_FUNC(party_changeleader)
- {
- int i, party_id = script_getnum(st,2);
- TBL_PC *sd = NULL;
- TBL_PC *tsd = NULL;
- struct party_data *party = NULL;
- if( !(party = party_search(party_id)) ) {
- script_pushint(st,-1);
- return 0;
- }
- if( !(tsd = map_charid2sd(script_getnum(st,3))) ) {
- script_pushint(st,-2);
- return 0;
- }
- if( tsd->status.party_id != party_id ) {
- script_pushint(st,-3);
- return 0;
- }
- ARR_FIND(0,MAX_PARTY,i,party->party.member[i].leader);
- if( i >= MAX_PARTY ) { //this is should impossible!
- script_pushint(st,0);
- return 0;
- }
- if( party->data[i].sd == tsd ) {
- script_pushint(st,-4);
- return 0;
- }
- script_pushint(st,party_changeleader(sd,tsd,party));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_changeoption <party id>,<option>,<flag>;
- * Return values:
- * -1 - party is not found
- * 0 - invalid option
- * 1 - success
- *------------------------------------------*/
- BUILDIN_FUNC(party_changeoption)
- {
- struct party_data *party;
- if( !(party = party_search(script_getnum(st,2))) ) {
- script_pushint(st,-1);
- return 0;
- }
- script_pushint(st,party_setoption(party,script_getnum(st,3),script_getnum(st,4)));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * party_destroy <party id>;
- * Destroys party with party id.
- * Return values:
- * 0 - failed
- * 1 - success
- *------------------------------------------*/
- BUILDIN_FUNC(party_destroy)
- {
- int i;
- struct party_data *party;
- if( !(party = party_search(script_getnum(st,2))) ) {
- script_pushint(st,0);
- return 0;
- }
- ARR_FIND(0,MAX_PARTY,i,party->party.member[i].leader);
- if( i >= MAX_PARTY || !party->data[i].sd ) { //leader not online
- int j;
- for( j = 0; j < MAX_PARTY; j++ ) {
- TBL_PC *sd = party->data[j].sd;
- if(sd)
- party_member_withdraw(party->party.party_id,sd->status.account_id,sd->status.char_id);
- else if( party->party.member[j].char_id )
- intif_party_leave(party->party.party_id,party->party.member[j].account_id,party->party.member[j].char_id);
- }
- party_broken(party->party.party_id);
- script_pushint(st,1);
- }
- else //leader leave = party broken
- script_pushint(st,party_leave(party->data[i].sd));
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Checks if a player's client version meets a required version or date.
- * @type :
- * 0 - check by version number
- * 1 - check by date
- * @return true/false
- *------------------------------------------*/
- BUILDIN_FUNC(is_clientver) {
- TBL_PC *sd = NULL;
- int type = script_getnum(st,2);
- int data = script_getnum(st,3);
- int ret = 0;
- if (script_hasdata(st,4))
- sd = map_charid2sd(script_getnum(st,4));
- else
- sd = script_rid2sd(st);
- if (sd == NULL) {
- script_pushint(st,0);
- return 0;
- }
- switch(type){
- case 0:
- ret = (sd->packet_ver >= data)?1:0;
- break;
- case 1:
- ret = (sd->packet_ver >= date2version(data))?1:0;
- break;
- }
- script_pushint(st,ret);
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Retrieves server definitions.
- * (see @type in const.txt)
- *------------------------------------------*/
- BUILDIN_FUNC(getserverdef) {
- int type = script_getnum(st,2);
- switch(type){
- case 0: script_pushint(st,PACKETVER); break;
- case 1: script_pushint(st,MAX_LEVEL); break;
- case 2: script_pushint(st,MAX_STORAGE); break;
- case 3: script_pushint(st,MAX_INVENTORY); break;
- case 4: script_pushint(st,MAX_ZENY); break;
- case 5: script_pushint(st,MAX_PARTY); break;
- case 6: script_pushint(st,MAX_GUILD); break;
- case 7: script_pushint(st,MAX_GUILDLEVEL); break;
- case 8: script_pushint(st,MAX_GUILD_STORAGE); break;
- case 9: script_pushint(st,MAX_BG_MEMBERS); break;
- case 10: script_pushint(st,VIP_SCRIPT); break;
- case 11: script_pushint(st,MIN_STORAGE); break;
- default:
- ShowWarning("buildin_getserverdef: unknown type %d.\n", type);
- script_pushint(st,0);
- break;
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /* Returns various information about a player's VIP status.
- * vip_status <type>,{"<character name>"};
- * Note: VIP System needs to be enabled.
- */
- BUILDIN_FUNC(vip_status) {
- #ifdef VIP_ENABLE
- TBL_PC *sd;
- char vip_str[26];
- time_t now = time(NULL);
- int type = script_getnum(st, 2);
- if (script_hasdata(st, 3))
- sd = map_nick2sd(script_getstr(st, 3));
- else
- sd = script_rid2sd(st);
- if (sd == NULL)
- return 0;
- switch(type) {
- case 1: // Get VIP status.
- script_pushint(st, pc_isvip(sd));
- break;
- case 2: // Get VIP expire date.
- if (pc_isvip(sd)) {
- time_t viptime = sd->vip.time;
- strftime(vip_str, 24, "%Y-%m-%d %H:%M", localtime(&viptime));
- vip_str[25] = '\0';
- script_pushstrcopy(st, vip_str);
- } else
- script_pushint(st, 0);
- break;
- case 3: // Get remaining time.
- if (pc_isvip(sd)) {
- time_t viptime_remain = sd->vip.time - now;
- int year=0,month=0,day=0,hour=0,min=0,sec=0;
- split_time(viptime_remain,&year,&month,&day,&hour,&min,&sec);
- safesnprintf(vip_str,sizeof(vip_str),"%d-%d-%d %d:%d",year,month,day,hour,min);
- script_pushstrcopy(st, vip_str);
- } else
- script_pushint(st, 0);
- break;
- }
- #else
- script_pushint(st, 0);
- #endif
- return SCRIPT_CMD_SUCCESS;
- }
- /* Adds or removes VIP time in minutes.
- * vip_time <time in mn>,{"<character name>"};
- * If time < 0 remove time, else add time.
- * Note: VIP System needs to be enabled.
- */
- BUILDIN_FUNC(vip_time) {
- #ifdef VIP_ENABLE //would be a pain for scripting npc otherwise
- TBL_PC *sd;
- int viptime = script_getnum(st, 2) * 60; // Convert since it's given in minutes.
- if (script_hasdata(st, 3))
- sd = map_nick2sd(script_getstr(st, 3));
- else
- sd = script_rid2sd(st);
- if (sd == NULL)
- return 0;
- chrif_req_login_operation(sd->status.account_id, sd->status.name, 6, viptime, 7, 0);
- #endif
- return SCRIPT_CMD_SUCCESS;
- }
- /*==========================================
- * Turns a player into a monster and grants SC attribute effect. [malufett/Hercules]
- * montransform <monster name/ID>, <duration>, <sc type>, <val1>, <val2>, <val3>, <val4>;
- *------------------------------------------*/
- BUILDIN_FUNC(montransform) {
- TBL_PC *sd;
- enum sc_type type;
- char msg[CHAT_SIZE_MAX];
- int tick, mob_id, val1, val2, val3, val4;
- struct script_data *data;
- if( (sd = script_rid2sd(st)) == NULL )
- return 1;
- data = script_getdata(st, 2);
- get_val(st, data); // Convert into value in case of a variable
- if( data_isstring(data) )
- mob_id = mobdb_searchname(script_getstr(st, 2));
- else
- mob_id = mobdb_checkid(script_getnum(st, 2));
- tick = script_getnum(st, 3);
- type = (sc_type)script_getnum(st, 4);
- val1 = val2 = val3 = val4 = 0;
- if (mob_id == 0) {
- if( data_isstring(data) )
- ShowWarning("buildin_montransform: Attempted to use non-existing monster '%s'.\n", script_getstr(st, 2));
- else
- ShowWarning("buildin_montransform: Attempted to use non-existing monster of ID '%d'.\n", script_getnum(st, 2));
- return 0;
- }
- if (mob_id == MOBID_EMPERIUM) {
- ShowWarning("buildin_montransform: Monster 'Emperium' cannot be used.\n");
- return 0;
- }
- if (!(type > SC_NONE && type < SC_MAX)) {
- ShowWarning("buildin_montransform: Unsupported status change id %d\n", type);
- return 0;
- }
- if (script_hasdata(st, 5))
- val1 = script_getnum(st, 5);
- if (script_hasdata(st, 6))
- val2 = script_getnum(st, 6);
- if (script_hasdata(st, 7))
- val3 = script_getnum(st, 7);
- if (script_hasdata(st, 8))
- val4 = script_getnum(st, 8);
- if (tick != 0) {
- struct mob_db *monster = mob_db(mob_id);
- if (battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
- clif_displaymessage(sd->fd, msg_txt(sd,1500)); // Transforming into monster is not allowed in Guild Wars.
- return 0;
- }
- if (sd->disguise){
- clif_displaymessage(sd->fd, msg_txt(sd,1498)); // Cannot transform into monster while in disguise.
- return 0;
- }
- sprintf(msg, msg_txt(sd,1497), monster->name); // Traaaansformation-!! %s form!!
- clif_disp_overhead(&sd->bl, msg);
- status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER); // Clear previous
- sc_start2(NULL, &sd->bl, SC_MONSTER_TRANSFORM, 100, mob_id, type, tick);
- sc_start4(NULL, &sd->bl, type, 100, val1, val2, val3, val4, tick);
- }
- return SCRIPT_CMD_SUCCESS;
- }
- /** [Cydh]
- * bonus_script "<script code>",<duration>{,<flag>{,<type>{,<status_icon>{,<char_id>}}}};
- * @param "script code"
- * @param duration
- * @param flag
- * @param char_id
- **/
- BUILDIN_FUNC(bonus_script) {
- uint8 i, flag = 0;
- int16 icon = SI_BLANK;
- uint32 dur;
- char type = 0;
- TBL_PC* sd;
- const char *script_str = NULL;
- struct script_code *script = NULL;
- if (script_hasdata(st,7))
- sd = map_charid2sd(script_getnum(st,7));
- else
- sd = script_rid2sd(st);
- if (sd == NULL)
- return 0;
-
- script_str = script_getstr(st,2);
- dur = 1000 * abs(script_getnum(st,3));
- FETCH(4,flag);
- FETCH(5,type);
- FETCH(6,icon);
- if (!strlen(script_str) || !dur) {
- //ShowWarning("buildin_bonus_script: Invalid value(s). Skipping...\n");
- return 0;
- }
- //Skip duplicate entry
- ARR_FIND(0,MAX_PC_BONUS_SCRIPT,i,&sd->bonus_script[i] && sd->bonus_script[i].script_str && strcmp(sd->bonus_script[i].script_str,script_str) == 0);
- if (i < MAX_PC_BONUS_SCRIPT) {
- //ShowWarning("buildin_bonus_script: Duplicate entry with bonus '%d'. Skipping...\n",i);
- return 0;
- }
- if (!(script = parse_script(script_str,"bonus_script",0,1))) {
- //ShowWarning("buildin_bonus_script: Failed to parse script '%s'. Skipping...\n",script_str);
- return 0;
- }
- //Find the empty slot
- ARR_FIND(0,MAX_PC_BONUS_SCRIPT,i,!sd->bonus_script[i].script);
- if (i >= MAX_PC_BONUS_SCRIPT) {
- ShowWarning("buildin_itemscript: Maximum script_bonus is reached (max: %d). Skipping...\n",MAX_PC_BONUS_SCRIPT);
- return 0;
- }
- //Add the script data
- memcpy(sd->bonus_script[i].script_str,script_str,strlen(script_str)+1);
- sd->bonus_script[i].script = script;
- sd->bonus_script[i].tick = gettick() + dur;
- sd->bonus_script[i].flag = flag;
- sd->bonus_script[i].type = type;
- sd->bonus_script[i].icon = icon;
- if (sd->bonus_script[i].icon != SI_BLANK) //Gives status icon if exist
- clif_status_change(&sd->bl,sd->bonus_script[i].icon,1,dur,1,0,0);
- status_calc_pc(sd,false);
- return SCRIPT_CMD_SUCCESS;
- }
- #include "../custom/script.inc"
- // declarations that were supposed to be exported from npc_chat.c
- #ifdef PCRE_SUPPORT
- BUILDIN_FUNC(defpattern);
- BUILDIN_FUNC(activatepset);
- BUILDIN_FUNC(deactivatepset);
- BUILDIN_FUNC(deletepset);
- #endif
- /// script command definitions
- /// for an explanation on args, see add_buildin_func
- struct script_function buildin_func[] = {
- // NPC interaction
- BUILDIN_DEF(mes,"s*"),
- BUILDIN_DEF(next,""),
- BUILDIN_DEF(close,""),
- BUILDIN_DEF(close2,""),
- BUILDIN_DEF(menu,"sl*"),
- BUILDIN_DEF(select,"s*"), //for future jA script compatibility
- BUILDIN_DEF(prompt,"s*"),
- //
- BUILDIN_DEF(goto,"l"),
- BUILDIN_DEF(callsub,"l*"),
- BUILDIN_DEF(callfunc,"s*"),
- BUILDIN_DEF(return,"?"),
- BUILDIN_DEF(getarg,"i?"),
- BUILDIN_DEF(jobchange,"i?"),
- BUILDIN_DEF(jobname,"i"),
- BUILDIN_DEF(input,"r??"),
- BUILDIN_DEF(warp,"sii"),
- BUILDIN_DEF(areawarp,"siiiisii??"),
- BUILDIN_DEF(warpchar,"siii"), // [LuzZza]
- BUILDIN_DEF(warpparty,"siii?"), // [Fredzilla] [Paradox924X]
- BUILDIN_DEF(warpguild,"siii"), // [Fredzilla]
- BUILDIN_DEF(setlook,"ii"),
- BUILDIN_DEF(changelook,"ii"), // Simulates but don't Store it
- BUILDIN_DEF(set,"rv"),
- BUILDIN_DEF(setarray,"rv*"),
- BUILDIN_DEF(cleararray,"rvi"),
- BUILDIN_DEF(copyarray,"rri"),
- BUILDIN_DEF(getarraysize,"r"),
- BUILDIN_DEF(deletearray,"r?"),
- BUILDIN_DEF(getelementofarray,"ri"),
- BUILDIN_DEF(getitem,"vi?"),
- BUILDIN_DEF(rentitem,"vi"),
- BUILDIN_DEF(getitem2,"viiiiiiii?"),
- BUILDIN_DEF(getnameditem,"vv"),
- BUILDIN_DEF2(grouprandomitem,"groupranditem","i?"),
- BUILDIN_DEF(makeitem,"visii"),
- BUILDIN_DEF(delitem,"vi?"),
- BUILDIN_DEF(delitem2,"viiiiiiii?"),
- BUILDIN_DEF2(enableitemuse,"enable_items",""),
- BUILDIN_DEF2(disableitemuse,"disable_items",""),
- BUILDIN_DEF(cutin,"si"),
- BUILDIN_DEF(viewpoint,"iiiii"),
- BUILDIN_DEF(heal,"ii"),
- BUILDIN_DEF(itemheal,"ii"),
- BUILDIN_DEF(percentheal,"ii"),
- BUILDIN_DEF(rand,"i?"),
- BUILDIN_DEF(countitem,"v"),
- BUILDIN_DEF2(countitem,"countitem2","viiiiiii"),
- BUILDIN_DEF(checkweight,"vi*"),
- BUILDIN_DEF(checkweight2,"rr"),
- BUILDIN_DEF(readparam,"i?"),
- BUILDIN_DEF(getcharid,"i?"),
- BUILDIN_DEF(getnpcid,"i?"),
- BUILDIN_DEF(getpartyname,"i"),
- BUILDIN_DEF(getpartymember,"i?"),
- BUILDIN_DEF(getpartyleader,"i?"),
- BUILDIN_DEF(getguildname,"i"),
- BUILDIN_DEF(getguildmaster,"i"),
- BUILDIN_DEF(getguildmasterid,"i"),
- BUILDIN_DEF(strcharinfo,"i"),
- BUILDIN_DEF(strnpcinfo,"i"),
- BUILDIN_DEF(getequipid,"i"),
- BUILDIN_DEF(getequipname,"i"),
- BUILDIN_DEF(getbrokenid,"i"), // [Valaris]
- BUILDIN_DEF(repair,"i"), // [Valaris]
- BUILDIN_DEF(repairall,""),
- BUILDIN_DEF(getequipisequiped,"i"),
- BUILDIN_DEF(getequipisenableref,"i"),
- BUILDIN_DEF(getequiprefinerycnt,"i"),
- BUILDIN_DEF(getequipweaponlv,"i"),
- BUILDIN_DEF(getequippercentrefinery,"i"),
- BUILDIN_DEF(successrefitem,"i"),
- BUILDIN_DEF(failedrefitem,"i"),
- BUILDIN_DEF(downrefitem,"i?"),
- BUILDIN_DEF(statusup,"i"),
- BUILDIN_DEF(statusup2,"ii"),
- BUILDIN_DEF(bonus,"iv"),
- BUILDIN_DEF2(bonus,"bonus2","ivi"),
- BUILDIN_DEF2(bonus,"bonus3","ivii"),
- BUILDIN_DEF2(bonus,"bonus4","ivvii"),
- BUILDIN_DEF2(bonus,"bonus5","ivviii"),
- BUILDIN_DEF(autobonus,"sii??"),
- BUILDIN_DEF(autobonus2,"sii??"),
- BUILDIN_DEF(autobonus3,"siiv?"),
- BUILDIN_DEF(skill,"vi?"),
- BUILDIN_DEF(addtoskill,"vi?"), // [Valaris]
- BUILDIN_DEF(guildskill,"vi"),
- BUILDIN_DEF(getskilllv,"v"),
- BUILDIN_DEF(getgdskilllv,"iv"),
- BUILDIN_DEF(basicskillcheck,""),
- BUILDIN_DEF(getgmlevel,""),
- BUILDIN_DEF(getgroupid,""),
- BUILDIN_DEF(end,""),
- BUILDIN_DEF(checkoption,"i"),
- BUILDIN_DEF(setoption,"i?"),
- BUILDIN_DEF(setcart,"?"),
- BUILDIN_DEF(checkcart,""),
- BUILDIN_DEF(setfalcon,"?"),
- BUILDIN_DEF(checkfalcon,""),
- BUILDIN_DEF(setriding,"?"),
- BUILDIN_DEF(checkriding,""),
- BUILDIN_DEF(checkwug,""),
- BUILDIN_DEF(checkmadogear,""),
- BUILDIN_DEF(setmadogear,"?"),
- BUILDIN_DEF2(savepoint,"save","sii"),
- BUILDIN_DEF(savepoint,"sii"),
- BUILDIN_DEF(gettimetick,"i"),
- BUILDIN_DEF(gettime,"i"),
- BUILDIN_DEF(gettimestr,"si"),
- BUILDIN_DEF(openstorage,""),
- BUILDIN_DEF(guildopenstorage,""),
- BUILDIN_DEF(itemskill,"vi"),
- BUILDIN_DEF(produce,"i"),
- BUILDIN_DEF(cooking,"i"),
- BUILDIN_DEF(monster,"siisii???"),
- BUILDIN_DEF(getmobdrops,"i"),
- BUILDIN_DEF(areamonster,"siiiisii???"),
- BUILDIN_DEF(killmonster,"ss?"),
- BUILDIN_DEF(killmonsterall,"s?"),
- BUILDIN_DEF(clone,"siisi????"),
- BUILDIN_DEF(doevent,"s"),
- BUILDIN_DEF(donpcevent,"s"),
- BUILDIN_DEF(cmdothernpc,"ss"),
- BUILDIN_DEF(addtimer,"is"),
- BUILDIN_DEF(deltimer,"s"),
- BUILDIN_DEF(addtimercount,"is"),
- BUILDIN_DEF(initnpctimer,"??"),
- BUILDIN_DEF(stopnpctimer,"??"),
- BUILDIN_DEF(startnpctimer,"??"),
- BUILDIN_DEF(setnpctimer,"i?"),
- BUILDIN_DEF(getnpctimer,"i?"),
- BUILDIN_DEF(attachnpctimer,"?"), // attached the player id to the npc timer [Celest]
- BUILDIN_DEF(detachnpctimer,"?"), // detached the player id from the npc timer [Celest]
- BUILDIN_DEF(playerattached,""), // returns id of the current attached player. [Skotlex]
- BUILDIN_DEF(announce,"si?????"),
- BUILDIN_DEF(mapannounce,"ssi?????"),
- BUILDIN_DEF(areaannounce,"siiiisi?????"),
- BUILDIN_DEF(getusers,"i"),
- BUILDIN_DEF(getmapguildusers,"si"),
- BUILDIN_DEF(getmapusers,"s"),
- BUILDIN_DEF(getareausers,"siiii"),
- BUILDIN_DEF(getareadropitem,"siiiiv"),
- BUILDIN_DEF(enablenpc,"s"),
- BUILDIN_DEF(disablenpc,"s"),
- BUILDIN_DEF(hideoffnpc,"s"),
- BUILDIN_DEF(hideonnpc,"s"),
- BUILDIN_DEF(sc_start,"iii???"),
- BUILDIN_DEF2(sc_start,"sc_start2","iiii???"),
- BUILDIN_DEF2(sc_start,"sc_start4","iiiiii???"),
- BUILDIN_DEF(sc_end,"i?"),
- BUILDIN_DEF(getstatus, "i?"),
- BUILDIN_DEF(getscrate,"ii?"),
- BUILDIN_DEF(debugmes,"s"),
- BUILDIN_DEF2(catchpet,"pet","i"),
- BUILDIN_DEF2(birthpet,"bpet",""),
- BUILDIN_DEF(resetlvl,"i"),
- BUILDIN_DEF(resetstatus,""),
- BUILDIN_DEF(resetskill,""),
- BUILDIN_DEF(skillpointcount,""),
- BUILDIN_DEF(changebase,"i?"),
- BUILDIN_DEF(changesex,""),
- BUILDIN_DEF(waitingroom,"si?????"),
- BUILDIN_DEF(delwaitingroom,"?"),
- BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"),
- BUILDIN_DEF(enablewaitingroomevent,"?"),
- BUILDIN_DEF(disablewaitingroomevent,"?"),
- BUILDIN_DEF2(enablewaitingroomevent,"enablearena",""), // Added by RoVeRT
- BUILDIN_DEF2(disablewaitingroomevent,"disablearena",""), // Added by RoVeRT
- BUILDIN_DEF(getwaitingroomstate,"i?"),
- BUILDIN_DEF(warpwaitingpc,"sii?"),
- BUILDIN_DEF(attachrid,"i"),
- BUILDIN_DEF(addrid,"i?????"),
- BUILDIN_DEF(detachrid,""),
- BUILDIN_DEF(isloggedin,"i?"),
- BUILDIN_DEF(setmapflagnosave,"ssii"),
- BUILDIN_DEF(getmapflag,"si?"),
- BUILDIN_DEF(setmapflag,"si??"),
- BUILDIN_DEF(removemapflag,"si?"),
- BUILDIN_DEF(pvpon,"s"),
- BUILDIN_DEF(pvpoff,"s"),
- BUILDIN_DEF(gvgon,"s"),
- BUILDIN_DEF(gvgoff,"s"),
- BUILDIN_DEF(emotion,"i??"),
- BUILDIN_DEF(maprespawnguildid,"sii"),
- BUILDIN_DEF(agitstart,""), // <Agit>
- BUILDIN_DEF(agitend,""),
- BUILDIN_DEF(agitcheck,""), // <Agitcheck>
- BUILDIN_DEF(flagemblem,"i"), // Flag Emblem
- BUILDIN_DEF(getcastlename,"s"),
- BUILDIN_DEF(getcastledata,"si"),
- BUILDIN_DEF(setcastledata,"sii"),
- BUILDIN_DEF(requestguildinfo,"i?"),
- BUILDIN_DEF(getequipcardcnt,"i"),
- BUILDIN_DEF(successremovecards,"i"),
- BUILDIN_DEF(failedremovecards,"ii"),
- BUILDIN_DEF(marriage,"s"),
- BUILDIN_DEF2(wedding_effect,"wedding",""),
- BUILDIN_DEF(divorce,""),
- BUILDIN_DEF(ispartneron,""),
- BUILDIN_DEF(getpartnerid,""),
- BUILDIN_DEF(getchildid,""),
- BUILDIN_DEF(getmotherid,""),
- BUILDIN_DEF(getfatherid,""),
- BUILDIN_DEF(warppartner,"sii"),
- BUILDIN_DEF(getitemname,"v"),
- BUILDIN_DEF(getitemslots,"i"),
- BUILDIN_DEF(makepet,"i"),
- BUILDIN_DEF(getexp,"ii"),
- BUILDIN_DEF(getinventorylist,""),
- BUILDIN_DEF(getskilllist,""),
- BUILDIN_DEF(clearitem,""),
- BUILDIN_DEF(classchange,"ii"),
- BUILDIN_DEF(misceffect,"i"),
- BUILDIN_DEF(playBGM,"s"),
- BUILDIN_DEF(playBGMall,"s?????"),
- BUILDIN_DEF(soundeffect,"si"),
- BUILDIN_DEF(soundeffectall,"si?????"), // SoundEffectAll [Codemaster]
- BUILDIN_DEF(strmobinfo,"ii"), // display mob data [Valaris]
- BUILDIN_DEF(guardian,"siisi??"), // summon guardians
- BUILDIN_DEF(guardianinfo,"sii"), // display guardian data [Valaris]
- BUILDIN_DEF(petskillbonus,"iiii"), // [Valaris]
- BUILDIN_DEF(petrecovery,"ii"), // [Valaris]
- BUILDIN_DEF(petloot,"i"), // [Valaris]
- BUILDIN_DEF(petheal,"iiii"), // [Valaris]
- BUILDIN_DEF(petskillattack,"viii"), // [Skotlex]
- BUILDIN_DEF(petskillattack2,"viiii"), // [Valaris]
- BUILDIN_DEF(petskillsupport,"viiii"), // [Skotlex]
- BUILDIN_DEF(skilleffect,"vi"), // skill effect [Celest]
- BUILDIN_DEF(npcskilleffect,"viii"), // npc skill effect [Valaris]
- BUILDIN_DEF(specialeffect,"i??"), // npc skill effect [Valaris]
- BUILDIN_DEF(specialeffect2,"i??"), // skill effect on players[Valaris]
- BUILDIN_DEF(nude,""), // nude command [Valaris]
- BUILDIN_DEF(mapwarp,"ssii??"), // Added by RoVeRT
- BUILDIN_DEF(atcommand,"s"), // [MouseJstr]
- BUILDIN_DEF2(atcommand,"charcommand","s"), // [MouseJstr]
- BUILDIN_DEF(movenpc,"sii?"), // [MouseJstr]
- BUILDIN_DEF(message,"ss"), // [MouseJstr]
- BUILDIN_DEF(npctalk,"s"), // [Valaris]
- BUILDIN_DEF(mobcount,"ss"),
- BUILDIN_DEF(getlook,"i"),
- BUILDIN_DEF(getsavepoint,"i"),
- BUILDIN_DEF(npcspeed,"i"), // [Valaris]
- BUILDIN_DEF(npcwalkto,"ii"), // [Valaris]
- BUILDIN_DEF(npcstop,""), // [Valaris]
- BUILDIN_DEF(getmapxy,"rrri?"), //by Lorky [Lupus]
- BUILDIN_DEF(checkoption1,"i"),
- BUILDIN_DEF(checkoption2,"i"),
- BUILDIN_DEF(guildgetexp,"i"),
- BUILDIN_DEF(guildchangegm,"is"),
- BUILDIN_DEF(logmes,"s"), //this command actls as MES but rints info into LOG file either SQL/TXT [Lupus]
- BUILDIN_DEF(summon,"si??"), // summons a slave monster [Celest]
- BUILDIN_DEF(isnight,""), // check whether it is night time [Celest]
- BUILDIN_DEF(isday,""), // check whether it is day time [Celest]
- BUILDIN_DEF(isequipped,"i*"), // check whether another item/card has been equipped [Celest]
- BUILDIN_DEF(isequippedcnt,"i*"), // check how many items/cards are being equipped [Celest]
- BUILDIN_DEF(cardscnt,"i*"), // check how many items/cards are being equipped in the same arm [Lupus]
- BUILDIN_DEF(getrefine,""), // returns the refined number of the current item, or an item with index specified [celest]
- BUILDIN_DEF(night,""), // sets the server to night time
- BUILDIN_DEF(day,""), // sets the server to day time
- #ifdef PCRE_SUPPORT
- BUILDIN_DEF(defpattern,"iss"), // Define pattern to listen for [MouseJstr]
- BUILDIN_DEF(activatepset,"i"), // Activate a pattern set [MouseJstr]
- BUILDIN_DEF(deactivatepset,"i"), // Deactive a pattern set [MouseJstr]
- BUILDIN_DEF(deletepset,"i"), // Delete a pattern set [MouseJstr]
- #endif
- BUILDIN_DEF(dispbottom,"s"), //added from jA [Lupus]
- BUILDIN_DEF(getusersname,""),
- BUILDIN_DEF(recovery,"i???"),
- BUILDIN_DEF(getpetinfo,"i"),
- BUILDIN_DEF(gethominfo,"i"),
- BUILDIN_DEF(getmercinfo,"i?"),
- BUILDIN_DEF(checkequipedcard,"i"),
- BUILDIN_DEF(jump_zero,"il"), //for future jA script compatibility
- BUILDIN_DEF(globalmes,"s?"), //end jA addition
- BUILDIN_DEF(unequip,"i"), // unequip command [Spectre]
- BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris]
- BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris]
- BUILDIN_DEF(charat,"si"),
- BUILDIN_DEF(setchar,"ssi"),
- BUILDIN_DEF(insertchar,"ssi"),
- BUILDIN_DEF(delchar,"si"),
- BUILDIN_DEF(strtoupper,"s"),
- BUILDIN_DEF(strtolower,"s"),
- BUILDIN_DEF(charisupper, "si"),
- BUILDIN_DEF(charislower, "si"),
- BUILDIN_DEF(substr,"sii"),
- BUILDIN_DEF(explode, "rss"),
- BUILDIN_DEF(implode, "r?"),
- BUILDIN_DEF(sprintf,"s*"), // [Mirei]
- BUILDIN_DEF(sscanf,"ss*"), // [Mirei]
- BUILDIN_DEF(strpos,"ss?"),
- BUILDIN_DEF(replacestr,"sss??"),
- BUILDIN_DEF(countstr,"ss?"),
- BUILDIN_DEF(setnpcdisplay,"sv??"),
- BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine.
- BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info
- BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info
- BUILDIN_DEF(getequipcardid,"ii"), //[Lupus] returns CARD ID or other info from CARD slot N of equipped item
- // [zBuffer] List of mathematics commands --->
- BUILDIN_DEF(sqrt,"i"),
- BUILDIN_DEF(pow,"ii"),
- BUILDIN_DEF(distance,"iiii"),
- // <--- [zBuffer] List of mathematics commands
- BUILDIN_DEF(md5,"s"),
- // [zBuffer] List of dynamic var commands --->
- BUILDIN_DEF(getd,"s"),
- BUILDIN_DEF(setd,"sv"),
- BUILDIN_DEF(callshop,"s?"), // [Skotlex]
- BUILDIN_DEF(npcshopitem,"sii*"), // [Lance]
- BUILDIN_DEF(npcshopadditem,"sii*"),
- BUILDIN_DEF(npcshopdelitem,"si*"),
- BUILDIN_DEF(npcshopattach,"s?"),
- BUILDIN_DEF(equip,"i"),
- BUILDIN_DEF(autoequip,"ii"),
- BUILDIN_DEF(setbattleflag,"si"),
- BUILDIN_DEF(getbattleflag,"s"),
- BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus
- BUILDIN_DEF(disguise,"i"), //disguise player. Lupus
- BUILDIN_DEF(undisguise,""), //undisguise player. Lupus
- BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus
- BUILDIN_DEF(addmonsterdrop,"vii"), //Akinari [Lupus]
- BUILDIN_DEF(delmonsterdrop,"vi"), //Akinari [Lupus]
- BUILDIN_DEF(axtoi,"s"),
- BUILDIN_DEF(query_sql,"s*"),
- BUILDIN_DEF(query_logsql,"s*"),
- BUILDIN_DEF(escape_sql,"v"),
- BUILDIN_DEF(atoi,"s"),
- // [zBuffer] List of player cont commands --->
- BUILDIN_DEF(rid2name,"i"),
- BUILDIN_DEF(pcfollow,"ii"),
- BUILDIN_DEF(pcstopfollow,"i"),
- BUILDIN_DEF(pcblockmove,"ii"),
- // <--- [zBuffer] List of player cont commands
- // [zBuffer] List of mob control commands --->
- BUILDIN_DEF(unitwalk,"ii?"),
- BUILDIN_DEF(unitkill,"i"),
- BUILDIN_DEF(unitwarp,"isii"),
- BUILDIN_DEF(unitattack,"iv?"),
- BUILDIN_DEF(unitstop,"i"),
- BUILDIN_DEF(unittalk,"is"),
- BUILDIN_DEF(unitemote,"ii"),
- BUILDIN_DEF(unitskilluseid,"ivi?"), // originally by Qamera [Celest]
- BUILDIN_DEF(unitskillusepos,"iviii"), // [Celest]
- // <--- [zBuffer] List of mob control commands
- BUILDIN_DEF(sleep,"i"),
- BUILDIN_DEF(sleep2,"i"),
- BUILDIN_DEF(awake,"s"),
- BUILDIN_DEF(getvariableofnpc,"rs"),
- BUILDIN_DEF(warpportal,"iisii"),
- BUILDIN_DEF2(homunculus_evolution,"homevolution",""), //[orn]
- BUILDIN_DEF2(homunculus_mutate,"hommutate","?"),
- BUILDIN_DEF(morphembryo,""),
- BUILDIN_DEF2(homunculus_shuffle,"homshuffle",""), //[Zephyrus]
- BUILDIN_DEF(checkhomcall,""),
- BUILDIN_DEF(eaclass,"?"), //[Skotlex]
- BUILDIN_DEF(roclass,"i?"), //[Skotlex]
- BUILDIN_DEF(checkvending,"?"),
- BUILDIN_DEF(checkchatting,"?"),
- BUILDIN_DEF(checkidle,"?"),
- BUILDIN_DEF(openmail,""),
- BUILDIN_DEF(openauction,""),
- BUILDIN_DEF(checkcell,"siii"),
- BUILDIN_DEF(setcell,"siiiiii"),
- BUILDIN_DEF(setwall,"siiiiis"),
- BUILDIN_DEF(delwall,"s"),
- BUILDIN_DEF(searchitem,"rs"),
- BUILDIN_DEF(mercenary_create,"ii"),
- BUILDIN_DEF(mercenary_heal,"ii"),
- BUILDIN_DEF(mercenary_sc_start,"iii"),
- BUILDIN_DEF(mercenary_get_calls,"i"),
- BUILDIN_DEF(mercenary_get_faith,"i"),
- BUILDIN_DEF(mercenary_set_calls,"ii"),
- BUILDIN_DEF(mercenary_set_faith,"ii"),
- BUILDIN_DEF(readbook,"ii"),
- BUILDIN_DEF(setfont,"i"),
- BUILDIN_DEF(areamobuseskill,"siiiiviiiii"),
- BUILDIN_DEF(progressbar,"si"),
- BUILDIN_DEF(pushpc,"ii"),
- BUILDIN_DEF(buyingstore,"i"),
- BUILDIN_DEF(searchstores,"ii"),
- BUILDIN_DEF(showdigit,"i?"),
- // WoE SE
- BUILDIN_DEF(agitstart2,""),
- BUILDIN_DEF(agitend2,""),
- BUILDIN_DEF(agitcheck2,""),
- // BattleGround
- BUILDIN_DEF(waitingroom2bg,"siiss?"),
- BUILDIN_DEF(waitingroom2bg_single,"isiis"),
- BUILDIN_DEF(bg_team_setxy,"iii"),
- BUILDIN_DEF(bg_warp,"isii"),
- BUILDIN_DEF(bg_monster,"isiisi?"),
- BUILDIN_DEF(bg_monster_set_team,"ii"),
- BUILDIN_DEF(bg_leave,""),
- BUILDIN_DEF(bg_destroy,"i"),
- BUILDIN_DEF(areapercentheal,"siiiiii"),
- BUILDIN_DEF(bg_get_data,"ii"),
- BUILDIN_DEF(bg_getareausers,"isiiii"),
- BUILDIN_DEF(bg_updatescore,"sii"),
- // Instancing
- BUILDIN_DEF(instance_create,"s"),
- BUILDIN_DEF(instance_destroy,"?"),
- BUILDIN_DEF(instance_id,""),
- BUILDIN_DEF(instance_enter,"s"),
- BUILDIN_DEF(instance_npcname,"s?"),
- BUILDIN_DEF(instance_mapname,"s?"),
- BUILDIN_DEF(instance_warpall,"sii?"),
- BUILDIN_DEF(instance_announce,"isi?????"),
- BUILDIN_DEF(instance_check_party,"i???"),
- /**
- * 3rd-related
- **/
- BUILDIN_DEF(makerune,"i"),
- BUILDIN_DEF(checkdragon,""),//[Ind]
- BUILDIN_DEF(setdragon,"?"),//[Ind]
- BUILDIN_DEF(ismounting,""),//[Ind]
- BUILDIN_DEF(setmounting,""),//[Ind]
- BUILDIN_DEF(checkre,"i"),
- /**
- * rAthena and beyond!
- **/
- BUILDIN_DEF(getargcount,""),
- BUILDIN_DEF(getcharip,"?"),
- BUILDIN_DEF(is_function,"s"),
- BUILDIN_DEF(get_revision,""),
- BUILDIN_DEF(freeloop,"i"),
- BUILDIN_DEF(getrandgroupitem,"ii?"),
- BUILDIN_DEF(cleanmap,"s"),
- BUILDIN_DEF2(cleanmap,"cleanarea","siiii"),
- BUILDIN_DEF(npcskill,"viii"),
- BUILDIN_DEF(consumeitem,"v"),
- BUILDIN_DEF(delequip,"i"),
- BUILDIN_DEF(breakequip,"i"),
- BUILDIN_DEF(sit,"?"),
- BUILDIN_DEF(stand,"?"),
- //@commands (script based)
- BUILDIN_DEF(bindatcmd, "ss??"),
- BUILDIN_DEF(unbindatcmd, "s"),
- BUILDIN_DEF(useatcmd, "s"),
- //Quest Log System [Inkfish]
- BUILDIN_DEF(setquest, "i"),
- BUILDIN_DEF(erasequest, "i"),
- BUILDIN_DEF(completequest, "i"),
- BUILDIN_DEF(checkquest, "i?"),
- BUILDIN_DEF(changequest, "ii"),
- BUILDIN_DEF(showevent, "ii"),
- //Bound items [Xantara] & [Akinari]
- BUILDIN_DEF2(getitem,"getitembound","vii?"),
- BUILDIN_DEF2(getitem2,"getitembound2","viiiiiiiii?"),
- BUILDIN_DEF(countbound, "?"),
- // Party related
- BUILDIN_DEF(party_create,"s???"),
- BUILDIN_DEF(party_addmember,"ii"),
- BUILDIN_DEF(party_delmember,"??"),
- BUILDIN_DEF(party_changeleader,"ii"),
- BUILDIN_DEF(party_changeoption,"iii"),
- BUILDIN_DEF(party_destroy,"i"),
- BUILDIN_DEF(is_clientver,"ii?"),
- BUILDIN_DEF(getserverdef,"i"),
- BUILDIN_DEF2(montransform, "transform", "vii????"), // Monster Transform [malufett/Hercules]
- BUILDIN_DEF(vip_status,"i?"),
- BUILDIN_DEF(vip_time,"i?"),
- BUILDIN_DEF(bonus_script,"si????"),
- BUILDIN_DEF(getgroupitem,"i"),
- #include "../custom/script_def.inc"
- {NULL,NULL,NULL},
- };
|