Which ? (PAWN Public ws New Public)
#1

Hi.
Which is more reliable / efficient / useful / faster ?

Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
// Something(Codes)
}
return 1;
}
Code:
public BlahBlahBlah(playerid)
{
if(IsPlayerInAnyVehicle(playerid)){
// Something(Codes)
}
return 1;
}
Reply
#2

Point for creating new function is to use it many places, but when its used in one place there isnt need for that.
Reply
#3

The one you call "PAWN public" is not a PAWN public, but it's a forward like BlahBlahBlah would be.

In your a_samp.inc, there's the forward for your "PAWN public"
Code:
forward OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
And for your BlahBlahBlah callback, you'd need also a forward, like this
Code:
forward BlahBlahBlah(playerid);
So, it's always the same.








Quote:
Originally Posted by CodeStyle175
View Post
Point for creating new function is to use it many places, but when its used in one place there isnt need for that.
This guy doesn't know what a callback is, so I doubt you'll be able to explain him what a function is out of nowhere.
Reply
#4

Thanks..
Reply
#5

Quote:
Originally Posted by KevinExec
View Post
The one you call "PAWN public" is not a PAWN public, but it's a forward like BlahBlahBlah would be.

In your a_samp.inc, there's the forward for your "PAWN public"
Code:
forward OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
And for your BlahBlahBlah callback, you'd need also a forward, like this
Code:
forward BlahBlahBlah(playerid);
So, it's always the same.










This guy doesn't know what a callback is, so I doubt you'll be able to explain him what a function is out of nowhere.

No such thing, remove it from your mind.
Reply
#6

KevinExec is stupid retard. When you use it, its called function, stupid fuck.
Public native doesnt have point, when its not called by anyway in the system.
For calling function, you have to use Timer.

SetTimer("ddd",5000,true); //So its called every 5sec
forward ddd();
public ddd(){
//code
return 1;
}
Reply
#7

Quote:
Originally Posted by CodeStyle175
View Post
Point for creating new function is to use it many places, but when its used in one place there isnt need for that.
Mainly, yes, but in some cases it can be a good idea to create a new function even if you use it just once. Functions should be kept as small as possible, large functions, hundreds of lines long, usually make the script harder to read. I know many people here dont care about having a clean script, but I use to split large functions rather than having a monolithic monster-function. Hooked callbacks are a good way to do that, the performance costs for that can be neglected in PAWN.
Reply
#8

Quote:
Originally Posted by ProRakNet
View Post
Hi.
Which is more reliable / efficient / useful / faster ?
What you're dealing with here is a native callback versus a function. In this case, when the player state changes. The function must be called by you in the script. Do realize that callbacks are regular functions aswell, but set to be called on some events by the SA-MP developer team.

And example of this would be the following.

PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
        
TaxiOrDestroy(playerid); //Call your function
    
}
    return 
1;

PHP Code:
TaxiOrDestroy(playerid) {
    new 
vehicleid GetPlayerVehicleID(playerid);
    new 
vehicle GetVehicleModel(vehicleid);
    if(
vehicle == 420) return SendClientMessage(playerid, -1"Welcome to the taxi.");;
    
DestroyVehicle(vehicleid);
    
SendClientMessage(playerid, -1"This is not a taxi. Destroying the vehicle.");
    return 
1;

Also, never use public on your own functions unless they need to be called at run time.
Reply
#9

Quote:
Originally Posted by introzen
View Post
What you're dealing with here is a native callback versus a function. In this case, when the player state changes. The function must be called by you in the script. Do realize that callbacks are regular functions aswell, but set to be called on some events by the SA-MP developer team.

And example of this would be the following.

PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
        
TaxiOrDestroy(playerid); //Call your function
    
}
    return 
1;

PHP Code:
TaxiOrDestroy(playerid) {
    new 
vehicleid GetPlayerVehicleID(playerid);
    new 
vehicle GetVehicleModel(vehicleid);
    if(
vehicle == 420) return SendClientMessage(playerid, -1"Welcome to the taxi.");;
    
DestroyVehicle(vehicleid);
    
SendClientMessage(playerid, -1"This is not a taxi. Destroying the vehicle.");
    return 
1;

Also, never use public on your own functions unless they need to be called at run time.
it is okay, i figured it out. Thanks for the explanation and examples.
i am grateful to everyone who helped ! Have a nice day..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)