new pos = strfind(cmdtext, " "); new id = strval(cmdtext[pos+1]); // ... nightmare of spaces, missing values, and crashes His first version without sscanf worked sometimes . But if a player typed /givecash 5 1000 – fine. If they typed /givecash 5 1000 – crash. If they typed /givecash 5 – crash. If they typed /givecash hello 500 – crash.
new cmd[32], id, cash; if(sscanf(cmdtext, "s[32]dd", cmd, id, cash)) return SendClientMessage(playerid, -1, "Usage: /givecash [ID] [amount]"); if(strcmp(cmd, "/givecash", true) == 0) GivePlayerMoney(id, cash); GivePlayerMoney(playerid, -cash); return 1; samp sscanf
He downloaded the plugin ( sscanf.dll on Windows, sscanf.so on Linux) and the include file. He added #include <sscanf2> to his script. new pos = strfind(cmdtext, " "); new id
Alex was 16 and proud. He had just set up his first SAMP roleplay server. Players could type /givecash [ID] [amount] to share money. His code looked simple: If they typed /givecash 5 1000 – crash