Jump to content

script Zamena dvou charu mezi sebou


ffredyk

Recommended Posts

  • Majitel

Vytvoreno pod zadosti na ICQ..

#include 

#define PRVNICHAR "Y"
#define DRUHEJCHAR "I"

public OnPlayerText(playerid, text[])
{
new str[255];
ChangeChar:
if(strfind(text,PRVNICHAR,true))
{
	new pos = strfind(text,PRVNICHAR,true);
	strdel(str,pos,pos+1);
	strins(str,DRUHEJCHAR,pos);
	goto ChangeChar;
}
else if(strfind(text,DRUHEJCHAR,true))
{
	new pos = strfind(text,DRUHEJCHAR,true);
	strdel(str,pos,pos+1);
	strins(str,PRVNICHAR,pos);
	goto ChangeChar;
}
}

Link to comment
Share on other sites

sak to je kravina

To neni k tomu :) to jsou funkce treba pro slozity scripty.

A tech funkci na upravu stringu je hafo :d

 

* Strcmp: Compare two strings to check if they are the same.

* Strtok: Get the next word/parameter in a string.

* Strdel: Delete part of a string.

* Strins: Insert text into a string.

* Strlen: Get the length of the string.

* Strmid: Extract part of a string into another string.

* Strpack: Pack a string into a destination.

* Strval: Convert a string into an integer.

* Strcat: Concatenate two strings into a destination reference.

Link to comment
Share on other sites

  • Majitel

Nic smazu to .. Nefunguje to a sem linej to cely prekopavat :d Dosli sme k zaveru, ze aby to fungovalo zcela spravne je zapotrebi minimalne 4 podminek a oddelenou detekci a prepsani pismen.. to je prace na dlouho a ja sem v tuhle chvili lenoch :d

Link to comment
Share on other sites

Nic smazu to .. Nefunguje to a sem linej to cely prekopavat :d Dosli sme k zaveru, ze aby to fungovalo zcela spravne je zapotrebi minimalne 4 podminek a oddelenou detekci a prepsani pismen.. to je prace na dlouho a ja sem v tuhle chvili lenoch :d

A ceho chces dosahnout? :d Nepochopil jsem vyznam toho scriptu :d

Link to comment
Share on other sites

Guest [HQW]MASTER

tak mi skus povedat preco mi pise daku chybu ze strtok na riadku ktory ani nemam v mode :d a robi mi to ia na jednom pc na 2. mam rovnake pawno a tam mi to nepise :d

Link to comment
Share on other sites

  • 1 year later...
No nechcem zakladať nové téma na to aby som sem dal script ktorý po mne chcel kamoš, tak ho dávam sem

 

 

stock ChangeChar(str[],char1,char2){
new len = strlen(str);
for(new i; i < len+1;i++){
if(str[i] == char1) str[i] = char2;
}
}

 

potom iba

public OnPlayerText(playerid,text[]){

ChangeChar(text,'i','y');

return 1;

}

Upozorňujem, znak musíte dať do ' ' čiže napríklad 'e'

 

pekny scriptik :)

zide sa obcas :p

Link to comment
Share on other sites

Kvér, děláš hrozně neodlehčený scripty... Jde to napsat bez tý proměny.. Navít bez těch zbytečnejch závorek..

stock ChangeChar(str[],char1,char2){
   for(new i; i < (strlen(str) +1); i++) if(str[i] == char1) str[i] = char2;
}

Jinak promiň, že se ti hrabu ve scriptu :d

Link to comment
Share on other sites

Roox nebol by som si istý... testoval som rýchlosti

 

    public OnGameModeInit()
   {
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
new STR[128] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
print("TEST START");
new time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar(STR,'A','B');
}
print(STR);
printf("ChangeChar by QWER %d",GetTickCount()-time);
format(STR,128,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar2(STR,'A','B');
}
print(STR);
printf("ChangeChar by Roox %d",GetTickCount()-time);


           return true;
   }


stock ChangeChar2(str[],char1,char2){
   for(new i; i < (strlen(str) +1); i++) if(str[i] == char1) str[i] = char2;
}
stock ChangeChar(str[],char1,char2){
new len = strlen(str);
for(new i; i < len+1;i++){
if(str[i] == char1) str[i] = char2;
}
}

 

[19] TEST START
[19] BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
[19] ChangeChar by QWER 14
[19] BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
[19] ChangeChar by Roox 35

Moje je viac ako 2x rýchlejšie ako tvoje...

Link to comment
Share on other sites

 

Roox nebol by som si istý... testoval som rýchlosti

 

    public OnGameModeInit()
   {
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
new STR[128] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
print("TEST START");
new time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar(STR,'A','B');
}
print(STR);
printf("ChangeChar by QWER %d",GetTickCount()-time);
format(STR,128,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar2(STR,'A','B');
}
print(STR);
printf("ChangeChar by Roox %d",GetTickCount()-time);


           return true;
   }


stock ChangeChar2(str[],char1,char2){
   for(new i; i < (strlen(str) +1); i++) if(str[i] == char1) str[i] = char2;
}
stock ChangeChar(str[],char1,char2){
new len = strlen(str);
for(new i; i < len+1;i++){
if(str[i] == char1) str[i] = char2;
}
}

 

[19] TEST START
[19] BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
[19] ChangeChar by QWER 14
[19] BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
[19] ChangeChar by Roox 35

Moje je viac ako 2x rýchlejšie ako tvoje...

 

Tak to je kravina.. Rychlostně by to mělo být úplně stejné (Udělej test znovu při stále stejném výkonu procesoru a operační paměti) a to moje odlehčuje 32 bitovou proměnnou..

Link to comment
Share on other sites

Tie zátvorky píšem lebo sa mi to pri Funkciách páči :d ale publicy to je na kope... xD

 

 

BTW Ja som netestoval RAM ale CPU... tvoje musí stále počítať počet znakov v stringu moje nie... moje to má pekne uložené...

 

 

EDIT teraz som to dal 10x opakovať a výsledok je jasný

[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 11
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 31
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 31
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32
[19] ChangeChar by QWER 12
[19] ChangeChar by Roox 32

 

SCRIPT

    public OnGameModeInit()
   {
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
new STR[128],time;
print("TEST START");
for(new x; x < 10;x++){
 format(STR,128,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
 time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar(STR,'A','B');
}
printf("ChangeChar by QWER %d",GetTickCount()-time);
format(STR,128,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
time = GetTickCount();
for(new i ; i < 1000;i++){
ChangeChar2(STR,'A','B');
}
printf("ChangeChar by Roox %d",GetTickCount()-time);
}

           return true;
   }


stock ChangeChar2(str[],char1,char2){
   for(new i; i < (strlen(str) +1); i++) if(str[i] == char1) str[i] = char2;
}
stock ChangeChar(str[],char1,char2){
new len = strlen(str);
for(new i; i < len+1;i++){
if(str[i] == char1) str[i] = char2;
}
}

 

:p

Link to comment
Share on other sites

To je zas pravda, ale je důležité se rozhodnout, jestli radši zatěžovat RAM a nebo CPU, protože třeba rozdíl nějakých 16 ms hráč nemá šanci poznat..

Link to comment
Share on other sites

áno, ale je to môj zvyk kebyže to stále robia ľudia ako ty že radšej obetujú CPU miesto RAM (ram je omnoho lacnejšia a je jej "viac") tak by to dopadlo asi takto

if(GetVehicleModel(GetPlayerVehicleID(playerid))   == 593 ||   //Dodo
  GetVehicleModel(GetPlayerVehicleID(playerid))   == 592 ||   //Andromada
  GetVehicleModel(GetPlayerVehicleID(playerid))   == 577 ||   //AT400
  GetVehicleModel(GetPlayerVehicleID(playerid))   == 563 ||   //Raindance
  GetVehicleModel(GetPlayerVehicleID(playerid))   == 553 ||   //Nevada
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 548 ||   //Cargobob
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 520 ||   //Hydra
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 519 ||   //Shamal
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 513 ||   //Stuntplane
  GetVehicleModel(GetPlayerVehicleID(playerid))   == 512 ||   //Cropduster
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 511 ||   //Beagle
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 497 ||   //Police Maverick
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 488 ||   //SAN News Maverick
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 487 ||   //Maverick
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 476 ||   //Rustler
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 469 ||   //Sparrow
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 460 ||   //Skimmer
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 447 ||   //Seasparrow
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 425 ||   //Hunter
  GetVehicleModel(GetPlayerVehicleID(playerid))  == 417)      //Leviathan

Radšej uprednostním aby to žralo viac RAM ako kebyže má každých 5 sekúnd na 0,5 sekundy "zamrznúť" (lagnuť) server... ;)

Link to comment
Share on other sites

Tak tohle je pěkná kravina. RAM není vždy levnější než procesor. V případě, že máš notebook, nebo 2 sloty a jeden obsazenej 16GB RAM a potřebuješ obsadit druhej... Za to si koupíš dva procesory..

Link to comment
Share on other sites

lol pongo ake by nice ? to som teraz napísal... ani som to neskúšal lebo viem na 100% že to pôjde...

 

 

Tak tohle je pěkná kravina. RAM není vždy levnější než procesor. V případě, že máš notebook, nebo 2 sloty a jeden obsazenej 16GB RAM a potřebuješ obsadit druhej... Za to si koupíš dva procesory..

ale kto by na ntb hosťoval server ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...