Which ? (PAWN Public ws New Public) -
ProRakNet - 25.04.2016
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;
}
Re: Which ? (PAWN Public ws New Public) -
CodeStyle175 - 25.04.2016
Point for creating new function is to use it many places, but when its used in one place there isnt need for that.
Re: Which ? (PAWN Public ws New Public) -
iKevin - 25.04.2016
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
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.
Re: Which ? (PAWN Public ws New Public) -
ProRakNet - 25.04.2016
Thanks..
Re: Which ? (PAWN Public ws New Public) -
ProRakNet - 25.04.2016
Quote:
Originally Posted by KevinExec
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.
|
![](https://pbs.twimg.com/profile_images/2597368729/22D8F984A.jpg)
No such thing, remove it from your mind.
Re: Which ? (PAWN Public ws New Public) -
CodeStyle175 - 25.04.2016
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;
}
Re: Which ? (PAWN Public ws New Public) -
Mauzen - 25.04.2016
Quote:
Originally Posted by CodeStyle175
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.
Re: Which ? (PAWN Public ws New Public) -
introzen - 26.04.2016
Quote:
Originally Posted by ProRakNet
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(playerid, newstate, oldstate)
{
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.
Re: Which ? (PAWN Public ws New Public) -
ProRakNet - 26.04.2016
Quote:
Originally Posted by introzen
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(playerid, newstate, oldstate)
{
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..