[Include] Extra Functions [Last Update: 10.04.2009 15:07 (GMT-1)]
#1

File Description:
It's just some library I created untill I get a better idea to complete.
It contains functions that can be usefull for all.
Here are the functions list (these is actually the native comments to add the functions to the pawn listbox. These functions are not natives, just stocks)
I would also like to say "I'm sorry". I know someone has just released a library like this one. I'm not trying to create some competition...
My vision of this Include, is to turn it into something that can be useful for all the SAMP pawn scripters. That can only be done with your contribution to the library.


Stock List:
------- STRING USEFULL FUNCTIONS ---------
native string_token(str[], idx);
native string_delim_token(str[], delim, idx);
native string_replace_chars(str[], char, newchar);
native string_contains_char(str[], char);
native string_contains_string(str[], str2[]);
native string_pack_strings(str[][128], delim, totalstrings);
native string_length(str[]);
native string_insert(destination[], string[]);

------- USEFULL PLAYER FUNCTIONS ----------
native player_getName(playerid);
native player_transferMoney(playerid, targetid, ammount);
native player_kill(playerid);
native player_sendToClassSelection(playerid);
native player_resetStuff(playerid);
native player_explode(playerid);
native player_kick(playerid, reason[]);
native player_ban(playerid, reason[]);
native player_kick(playerid, reason[]);
native player_removeHealth(playerid, Float:health);
native player_giveHealth(playerid, Float:health);
native player_giveHealthBoost(playerid, Floatercentage); // Percentage Ex: 0.25 = 25% health

------- USEFULL VEHICLE FUNCTIONS ---------
native vehicle_fix(vehicleid);
native vehicle_kill(vehicleid);
native vehicle_clear(vehicleid);
native vehicle_lock(vehicleid);
native vehicle_unlock(vehicleid);
native vehicle_bootPassengers(vehicleid);

------- USEFULL SERVER FUNCTIONS ----------
native SendDeathMessageToAll(playerid, killerid, reason);
native SendConnectMessageToAll(playerid);
native SendDisconnectMessageToAll(playerid);
native KickRegularPlayers();
native KickAll();


Download Link: Last Updated on 10.04.09 (15.07 GMT -1)

Previous Version Downloads: 21

Library Credits:
I created all functions by myself, without looking at anyone else's scripts.
Since the original release, some stocks have been modified with the help of the library contibutors, so they do deserve a big credit aswell.

Contibutors:
- Weirdosport


Update Log:
10.04.09 13:15 GMT-1:
- fixed: «vehicle_bootPassengers(vehicleid)»
- updated: «SendDeathMessageToAll(playerid, killerid, reason)»
- updated: «player_getName(playerid)»

10.04.09 15:07 GMT-1:
- added: «KickRegularPlayers()»
- removed: «string_reset()»

- updated: All array sizes to 128, to increase performance and server stability
- updated: «string_insert()» - It is now the same has strcat


Other Notes:
In order to turn this library into a great collection of functions, we need your contribution!
Feel free to modify or add a new stock function to the library.
Don't forget to post the changes you did to the library and get it posted in the official file! (You only need to post the stock function. Use the «pawn» tags)
Reply
#2

Looks pretty useful, will try and test it a bit if I get chance, nice job!
Reply
#3

I shall now inspect them, and comment (I may add the the comment several times...)

First thing: stock vehicle_bootPassengers(vehicleid)

The vehicleid is never used during this stock, I think the code will boot every passenger on the server.

Second Thing: I don't know if it's a big deal, but in vehicle_fix and vehicle_kill you use integers instead of Floats. If this were compiled it would complain but as it's an include you'd never know!

Third thing: This is trivial but: (I suspect you already knew this but forgot to do it as you used in one of the other cases!)

pawn Код:
case 10, 11, 12, 13:
could be:
case 10 .. 12
Fourth Thing: In "player_giveHealthBoost" is the percentage a number between 0 and 1?

Fifth Thing: You use strings of size [256]. They do not need to be this big, click HERE to see why!

Sixth Thing: GetPlayerName(playerid, result, 256); --> GetPlayerName(playerid, result, sizeof(result));

Seventh Thing: Just for the record, what is this for?:

pawn Код:
stock string_reset(){
    new strresult[256];
    return strresult;
}
Eighth Thing: string_insert(str[], str2[]) ---> This is already covered by Strcat. Click HERE.

Ninth Thing: What was wrong with strlen?:

pawn Код:
stock string_length(str[]){
    return(strlen(str));
}
Tenth (and final) Thing: I'm not going into the string stuff as i'm not 100% familiar with it, but it looks promising. I like the look of string_replace_chars, just thinking of funny things I could do with it >.>

Note: Don't get me wrong, this is a really good include, i'm just finding anything that could be improved!
Reply
#4

Thanks weirdosport.
I will fix the stocks and update the file tomorow. Its true I didn't test some of them.

@six thing
pawn Код:
GetPlayerName(playerid, result, 256); --> GetPlayerName(playerid, result, sizeof(result));
Both stuff are correct, cause the Array size is 256. I would use sizeof if I didn't knew the array size.
The stock worked for me, I tested it.
Reply
#5

Quote:
Originally Posted by -zriptarusk
Thanks weirdosport.
I will fix the stocks and update the file tomorow. Its true I didn't test some of them.

@six thing
pawn Код:
GetPlayerName(playerid, result, 256); --> GetPlayerName(playerid, result, sizeof(result));
Both stuff are correct, cause the Array size is 256. I would use sizeof if I didn't knew the array size.
The stock worked for me, I tested it.
I usually don't care about array sizes, but for player names i usually drop it down to 28 because thats the highest it could possibly be, and it speeds up the script a bit. So id change result[256] to result[28] just to get that little millisecond back. but it does look like a really nice include.
Reply
#6

Pastebin?
Reply
#7

Use [MAX_PLAYER_NAME] rather than [28] and [256], that way you're covered if the Max name length were ever to change.
Reply
#8

Quote:
Originally Posted by Gijsmin (Spot-Host.co.uk)
Pastebin?
The library can be downloaded from solidfiles.com
The link is at the topics first post.

Solidfiles.com is a good file hosting service. You can download the library from there.
The file will be updated regulary, so keep tunned.

Feel free to contribute
Reply
#9

I changed the list of things... some of them are questions. I am still concerned by the use of strings of size [256]. This size is unnecessary for several reasons, many of which are listed in this post HERE.
Reply
#10

Quote:
Originally Posted by Weirdosport
I changed the list of things... some of them are questions. I am still concerned by the use of strings of size [256]. This size is unnecessary for several reasons, many of which are listed in this post HERE.
strcat vs string_insert
Theres no difference. Just like string_length.
It's useful for a first time scripter, so he/she doesn't have to look for those weird names like strcat. I didn't even know string_insert was already covered by strcat. Never used it before in C; C++ or Pawn.

I'm updating the «string» sizes.
I didn't knew max input was 128. Ill post an update soon

Quote:

Second Thing: I don't know if it's a big deal, but in vehicle_fix and vehicle_kill you use integers instead of Floats. If this were compiled it would complain but as it's an include you'd never know!

In all programming languages: 1000 = 1000.0 = 1000.0000 = 1000.0000000
If you call that function somewhere in one of your gamemodes, it will not give you any kind of warning or error.

Quote:

Seventh Thing: Just for the record, what is this for?:

No idea, it just returns a new «string». I'm going to remove that in the next version

Quote:

Fourth Thing: In "player_giveHealthBoost" is the percentage a number between 0 and 1?

There is a comment next to the function, which you can see in Pawno IDE, telling you that is a percentage (0.25 = 25%)

Reply
#11

Short for String catenation, just joins one string to another. Not using format it's probably more efficient, as format has to distinguish between strings variables and floats etc in an attempt to convert it all into a string.

If anything I think strlen() is easier because it's shorter and more widely used :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)