- PawnPlus [ Prvi Deo >> DinamiÄni stringovi ] -
Šta je PawnPlus?PawnPlus je plugin koji omogućava asihrone radnje u PAWN jeziku, ujedno ima i dosta korisnih stvari poput YSF library-a.
Prvi Deo tutorialaPlaniram da ovaj tutorial ima više delova jer je
PawnPlus previše kompleksan tako da ne mogu sve u jednom napisati a da vi to razumete.
ZaÅ¡to baÅ¡ dinamiÄni stringovi za prvi deo?Zato Å¡to mi je to najviÅ¡e traženo po inboxu, privatnim porukama, samo Å¡to sova iz Harry Potera ne krene da mi donosi pisma kroz prozor.
InstalacijaZa poÄetak odete na
ovaj (https://github.com/IllidanS4/PawnPlus/releases/latest) link i preuzmete .so/.dll i .inc fajlove (kao za svaki drugi library).
Kada ste instalirali, .so/.dll fajl prebacite u
plugins folder i dodate ih u
server.cfg a include dodate u
include folder.
IncludingPotrebno je da ovaj kod dodate tamo gde su vam svi include-i:
[pawn]#include <PawnPlus>[/pawn]
Mislim da red nije bitan, bitno je samo pre nego što se bilo šta iz
PawnPlus-a koristi da bude included.
PrilagoÄ'avanje native-aPre nego Å¡to bilo gde krenemo, moram da napomenem da recimo imate
inputtext u
OnDialogResponse callbacku, Vi taj string ne možete da koristite u
PawnPlus dinamiÄnim stringovima jer
PawnPlus ima svoje tagove za stringove (
ConstAmxString i
ConstString ) ili recimo ako želite da unutar
CreateDynamic3DTextLabel-a koristite dinamiÄne stringove, vi taj native morate da prilagodite, veoma je jednostavno:
Prvo uÄ'emo u include fajl odakle taj native potiÄe, u ovom sluÄaju
streamer.inc, pritisnite
CTRL + F i kucajte
CreateDynamic3DTextLabel i
ENTER, kada ste našli
native, jednostavno ga celog prekopirajte:
[pawn]native STREAMER_TAG_3D_TEXT_LABEL:CreateDynamic3DTextLabel(const text[], color, Float:x, Float:y, Float:z, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = STREAMER_3D_TEXT_LABEL_SD, STREAMER_TAG_AREA:areaid = STREAMER_TAG_AREA:-1, priority = 0);[/pawn]
Ja imam obiÄaj da ga stavim
iznad main() funkcije tj
ispod include-a.
Sada kada smo ga kopirali treba da prilagodimo taj native, kako?
Kao što možete videti u ovom native-u na prvom mestu se nalazi
const text[] argument, umesto njega ćemo staviti
ConstAmxString:string (bitan je
tag ConstAmxString), zatim
preimenujemo native, na primer ja ću da ga nazovem
pp_CreateDynamic3DTextLabel, sada poslednji korak pre samog
semi-colona stavimo
= ime_originalnog_nativea, ovako bi trebalo da izgleda krajnji rezultat:
[pawn]native STREAMER_TAG_3D_TEXT_LABEL:pp_CreateDynamic3DTextLabel(ConstAmxString:string, color, Float:x, Float:y, Float:z, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = STREAMER_3D_TEXT_LABEL_SD, STREAMER_TAG_AREA:areaid = STREAMER_TAG_AREA:-1, priority = 0) = CreateDynamic3DTextLabel;[/pawn]
Sada konaÄno možemo da kreiramo dinamiÄne labele pomoću dinamiÄnih stringova, kako to izgleda:
[pawn]new playerName[MAX_PLAYER_NAME + 1];
GetPlayerName(playerid, playerName, sizeof(playerName));
new String:string = str_format("www.balkan-samp.com\nVaš username: %s", playerName);
pp_CreateDynamic3DTextLabel(string, 0xFF0000FF, 0.0, 0.0, 3.0, 30.0, playerid, INVALID_VEHICLE_ID, 1, -1, -1, -1, 25.0, -1, 0);[/pawn]
Isto sve radite i za
ShowPlayerDialog (kažem
ShowPlayerDialog zato što su tu najveći stringovi ugl), ali vi recimo ne morate
const caption[] da prebacite u
ConstAmxString nego samo
const info[].
Kao što vidite, nigde nema
1024 stringova nit bilo kakvih problema, na primer
/adminhelp dialog, admin level 1 može imati 256 dužinu svih komandi zajedno a vi pravite 2048 za sluÄaj da je admin level 7 ( Äast izuzetcima ).
To je to?!Naravno da ne, ima joÅ¡ dosta da se radi sa dinamiÄnim stringovima, na primer:
[pawn]native String:str_new(const str[], str_create_mode:mode=str_preserve);
native String:str_new_arr(const arr[], size=sizeof(arr), str_create_mode:mode=str_preserve);
native String:str_new_static(const str[], str_create_mode:mode=str_preserve, size=sizeof(str));
native String:str_new_buf(size);
native AmxString:str_addr(StringTag:str);
native ConstAmxString:str_addr_const(ConstStringTag:str);
native AmxStringBuffer:str_buf_addr(StringTag:str);
native String:str_acquire(StringTag:str);
native String:str_release(StringTag:str);
native str_delete(StringTag:str);
native bool:str_valid(ConstStringTag:str);
native String:str_clone(ConstStringTag:str);
native str_len(ConstStringTag:str);
native str_get(ConstStringTag:str, buffer[], size=sizeof(buffer), start=0, end=cellmax);
native str_getc(ConstStringTag:str, pos);
native str_setc(StringTag:str, pos, value);
native str_cmp(ConstStringTag:str1, ConstStringTag:str2);
native bool:str_empty(ConstStringTag:str);
native bool:str_eq(ConstStringTag:str1, ConstStringTag:str2);
native str_findc(ConstStringTag:str, value, offset=0);
native str_find(ConstStringTag:str, ConstStringTag:value, offset=0);
native String:str_cat(ConstStringTag:str1, ConstStringTag:str2);
native String:str_sub(ConstStringTag:str, start=0, end=cellmax);
native String:str_val(AnyTag:value, TagTag:tag_id=tagof(value));
native String:str_val_arr(const AnyTag:value[], size=sizeof(value), TagTag:tag_id=tagof(value));
native String:str_val_var(ConstVariantTag:value);
native List:str_split(ConstStringTag:str, const delims[]);
native List:str_split_s(ConstStringTag:str, ConstStringTag:delims);
native String:str_join(List:list, const delim[]);
native String:str_join_s(List:list, ConstStringTag:delim);
native String:str_to_lower(ConstStringTag:str);
native String:str_to_upper(ConstStringTag:str);
native String:str_set(StringTag:target, StringTag:other);
native String:str_append(StringTag:target, StringTag:other);
native String:str_ins(StringTag:target, StringTag:other, pos);
native String:str_del(StringTag:target, start=0, end=cellmax);
native String:str_clear(StringTag:str);
native String:str_resize(StringTag:str, size, padding=0);
native String:str_set_to_lower(StringTag:str);
native String:str_set_to_upper(StringTag:str);
native String:str_format(const format[], AnyTag:...);
native String:str_format_s(ConstStringTag:format, AnyTag:...);
native String:str_set_format(StringTag:target, const format[], AnyTag:...);
native String:str_set_format_s(StringTag:target, ConstStringTag:format, AnyTag:...);
native String:str_append_format(StringTag:target, const format[], AnyTag:...);
native String:str_append_format_s(StringTag:target, ConstStringTag:format, AnyTag:...);
native bool:str_match(ConstStringTag:str, const pattern[], &pos=0, regex_options:options=regex_default);
native bool:str_match_s(ConstStringTag:str, ConstStringTag:pattern, &pos=0, regex_options:options=regex_default);
native List:str_extract(ConstStringTag:str, const pattern[], &pos=0, regex_options:options=regex_default);
native List:str_extract_s(ConstStringTag:str, ConstStringTag:pattern, &pos=0, regex_options:options=regex_default);
native String:str_replace(ConstStringTag:str, const pattern[], const replacement[], &pos=0, regex_options:options=regex_default);
native String:str_replace_s(ConstStringTag:str, ConstStringTag:pattern, ConstStringTag:replacement, &pos=0, regex_options:options=regex_default);
native String:str_replace_list(ConstStringTag:str, const pattern[], List:replacement, &pos=0, regex_options:options=regex_default);
native String:str_replace_list_s(ConstStringTag:str, ConstStringTag:pattern, List:replacement, &pos=0, regex_options:options=regex_default);
native String:str_replace_func(ConstStringTag:str, const pattern[], const function[], &pos=0, regex_options:options=regex_default, const additional_format[]="", AnyTag:...);
native String:str_replace_func_s(ConstStringTag:str, ConstStringTag:pattern, const function[], &pos=0, regex_options:options=regex_default, const additional_format[]="", AnyTag:...);
native String:str_replace_expr(ConstStringTag:str, const pattern[], Expression:expr, &pos=0, regex_options:options=regex_default);
native String:str_replace_expr_s(ConstStringTag:str, ConstStringTag:pattern, Expression:expr, &pos=0, regex_options:options=regex_default);
native String:str_set_replace(StringTag:target, ConstStringTag:str, const pattern[], const replacement[], &pos=0, regex_options:options=regex_default);
native String:str_set_replace_s(StringTag:target, ConstStringTag:str, ConstStringTag:pattern, ConstStringTag:replacement, &pos=0, regex_options:options=regex_default);
native String:str_set_replace_list(StringTag:target, ConstStringTag:str, const pattern[], List:replacement, &pos=0, regex_options:options=regex_default);
native String:str_set_replace_list_s(StringTag:target, ConstStringTag:str, ConstStringTag:pattern, List:replacement, &pos=0, regex_options:options=regex_default);
native String:str_set_replace_func(StringTag:target, ConstStringTag:str, const pattern[], const function[], &pos=0, regex_options:options=regex_default, const additional_format[]="", AnyTag:...);
native String:str_set_replace_func_s(StringTag:target, ConstStringTag:str, ConstStringTag:pattern, const function[], &pos=0, regex_options:options=regex_default, const additional_format[]="", AnyTag:...);
native String:str_set_replace_expr(StringTag:target, ConstStringTag:str, const pattern[], Expression:expr, &pos=0, regex_options:options=regex_default);
native String:str_set_replace_expr_s(StringTag:target, ConstStringTag:str, ConstStringTag:pattern, Expression:expr, &pos=0, regex_options:options=regex_default);[/pawn]
U sledećem tutorialu ide Regular Expression koji koristi C++ syntaxu tako da naoštrite Vaše znanje iz C++ regex-a na stackoverflowu i regexr.com (http://regexr.com) sajtu :D
NAPOMENA: Ovaj tutorial nije toliko detaljan jer se većina funkcija koristi isto kao native samo su tu zbog razliÄitih tagova, možda bude nastavak i tutoriala za stringove jer ima joÅ¡ dosta toga Å¡to nisam objasnio, ovo vam je dovoljno da vas drži zauzetim do sledećeg tutoriala, lep pozdrav! :D